Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RPC types to have consistent status key #83

Open
alexlwn123 opened this issue Oct 22, 2024 · 4 comments
Open

Update RPC types to have consistent status key #83

alexlwn123 opened this issue Oct 22, 2024 · 4 comments
Labels
rust Requires modifying rust code

Comments

@alexlwn123
Copy link
Member

Currently, the subscribeLnReceive and subscribeLnPay functions return a status with the following types:

type LnPayState =
  | 'created'
  | 'canceled'
  | { funded: { block_height: number } }
  | { waiting_for_refund: { error_reason: string } }
  | 'awaiting_change'
  | { Success: { preimage: string } }
  | { refunded: { gateway_error: string } }
  | { unexpected_error: { error_message: string } }
  

type LnReceiveState =
  | 'created'
  | { waiting_for_payment: { invoice: string; timeout: number } }
  | { canceled: { reason: string } }
  | 'funded'
  | 'awaiting_funds'
  | 'claimed'

This makes pattern matching a bit ugly for the SDK because objects and strings are mixed.

Let's changes the types to have a consistent shape:

type LnPayState =
  | { status: 'created' }
  | { status: 'canceled' }
  | { status: 'funded'; block_height: number }
  | { status: 'waiting_for_refund'; error_reason: string }
  | { status: 'awaiting_change' }
  | { status: 'Success'; preimage: string }
  | { status: 'refunded'; gateway_error: string }
  | { status: 'unexpected_error'; error_message: string } 
  
type LnReceiveState =
  | { status: 'created' }
  | { status: 'waiting_for_payment'; invoice: string; timeout: number }
  | { status: 'canceled'; reason: string }
  | { status: 'funded' }
  | { status: 'awaiting_funds' }
  | { status: 'claimed' }
@alexlwn123 alexlwn123 added the rust Requires modifying rust code label Oct 22, 2024
@alexlwn123
Copy link
Member Author

@maan2003

@maan2003
Copy link
Member

this is not possible, because fedimint commits to the first json representation in the database :/

if we change it, fedimint client will become backwards incompatible

@alexlwn123
Copy link
Member Author

Could we just transform the shape before returning it to the caller?

If not, I'll just do that in the javascript

@maan2003
Copy link
Member

maan2003 commented Oct 25, 2024

should do it in javascript, I don't want yet another RpcLnPayState(MaybeLoading) in rust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust Requires modifying rust code
Projects
None yet
Development

No branches or pull requests

2 participants