tx swaps polish
This commit is contained in:
parent
e411b7aa7f
commit
f8fe946b40
13 changed files with 174 additions and 85 deletions
|
|
@ -1740,7 +1740,10 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
|
||||
### TransactionSwapQuote
|
||||
- __chain_fee_sats__: _number_
|
||||
- __completed_at_unix__: _number_
|
||||
- __expires_at_block_height__: _number_
|
||||
- __invoice_amount_sats__: _number_
|
||||
- __paid_at_unix__: _number_
|
||||
- __service_fee_sats__: _number_
|
||||
- __service_url__: _string_
|
||||
- __swap_fee_sats__: _number_
|
||||
|
|
@ -1754,13 +1757,13 @@ The nostr server will send back a message response, and inside the body there wi
|
|||
- __transaction_amount_sats__: _number_
|
||||
|
||||
### TxSwapOperation
|
||||
- __address_paid__: _string_
|
||||
- __address_paid__: _string_ *this field is optional
|
||||
- __failure_reason__: _string_ *this field is optional
|
||||
- __operation_payment__: _[UserOperation](#UserOperation)_ *this field is optional
|
||||
- __swap_operation_id__: _string_
|
||||
- __quote__: _[TransactionSwapQuote](#TransactionSwapQuote)_
|
||||
- __tx_id__: _string_ *this field is optional
|
||||
|
||||
### TxSwapsList
|
||||
- __quotes__: ARRAY of: _[TransactionSwapQuote](#TransactionSwapQuote)_
|
||||
- __swaps__: ARRAY of: _[TxSwapOperation](#TxSwapOperation)_
|
||||
|
||||
### UpdateChannelPolicyRequest
|
||||
|
|
|
|||
|
|
@ -717,7 +717,10 @@ type SingleMetricReq struct {
|
|||
}
|
||||
type TransactionSwapQuote struct {
|
||||
Chain_fee_sats int64 `json:"chain_fee_sats"`
|
||||
Completed_at_unix int64 `json:"completed_at_unix"`
|
||||
Expires_at_block_height int64 `json:"expires_at_block_height"`
|
||||
Invoice_amount_sats int64 `json:"invoice_amount_sats"`
|
||||
Paid_at_unix int64 `json:"paid_at_unix"`
|
||||
Service_fee_sats int64 `json:"service_fee_sats"`
|
||||
Service_url string `json:"service_url"`
|
||||
Swap_fee_sats int64 `json:"swap_fee_sats"`
|
||||
|
|
@ -731,14 +734,14 @@ type TransactionSwapRequest struct {
|
|||
Transaction_amount_sats int64 `json:"transaction_amount_sats"`
|
||||
}
|
||||
type TxSwapOperation struct {
|
||||
Address_paid string `json:"address_paid"`
|
||||
Failure_reason string `json:"failure_reason"`
|
||||
Operation_payment *UserOperation `json:"operation_payment"`
|
||||
Swap_operation_id string `json:"swap_operation_id"`
|
||||
Address_paid string `json:"address_paid"`
|
||||
Failure_reason string `json:"failure_reason"`
|
||||
Operation_payment *UserOperation `json:"operation_payment"`
|
||||
Quote *TransactionSwapQuote `json:"quote"`
|
||||
Tx_id string `json:"tx_id"`
|
||||
}
|
||||
type TxSwapsList struct {
|
||||
Quotes []TransactionSwapQuote `json:"quotes"`
|
||||
Swaps []TxSwapOperation `json:"swaps"`
|
||||
Swaps []TxSwapOperation `json:"swaps"`
|
||||
}
|
||||
type UpdateChannelPolicyRequest struct {
|
||||
Policy *ChannelPolicy `json:"policy"`
|
||||
|
|
|
|||
|
|
@ -4232,7 +4232,10 @@ export const SingleMetricReqValidate = (o?: SingleMetricReq, opts: SingleMetricR
|
|||
|
||||
export type TransactionSwapQuote = {
|
||||
chain_fee_sats: number
|
||||
completed_at_unix: number
|
||||
expires_at_block_height: number
|
||||
invoice_amount_sats: number
|
||||
paid_at_unix: number
|
||||
service_fee_sats: number
|
||||
service_url: string
|
||||
swap_fee_sats: number
|
||||
|
|
@ -4243,7 +4246,10 @@ export const TransactionSwapQuoteOptionalFields: [] = []
|
|||
export type TransactionSwapQuoteOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: []
|
||||
chain_fee_sats_CustomCheck?: (v: number) => boolean
|
||||
completed_at_unix_CustomCheck?: (v: number) => boolean
|
||||
expires_at_block_height_CustomCheck?: (v: number) => boolean
|
||||
invoice_amount_sats_CustomCheck?: (v: number) => boolean
|
||||
paid_at_unix_CustomCheck?: (v: number) => boolean
|
||||
service_fee_sats_CustomCheck?: (v: number) => boolean
|
||||
service_url_CustomCheck?: (v: string) => boolean
|
||||
swap_fee_sats_CustomCheck?: (v: number) => boolean
|
||||
|
|
@ -4257,9 +4263,18 @@ export const TransactionSwapQuoteValidate = (o?: TransactionSwapQuote, opts: Tra
|
|||
if (typeof o.chain_fee_sats !== 'number') return new Error(`${path}.chain_fee_sats: is not a number`)
|
||||
if (opts.chain_fee_sats_CustomCheck && !opts.chain_fee_sats_CustomCheck(o.chain_fee_sats)) return new Error(`${path}.chain_fee_sats: custom check failed`)
|
||||
|
||||
if (typeof o.completed_at_unix !== 'number') return new Error(`${path}.completed_at_unix: is not a number`)
|
||||
if (opts.completed_at_unix_CustomCheck && !opts.completed_at_unix_CustomCheck(o.completed_at_unix)) return new Error(`${path}.completed_at_unix: custom check failed`)
|
||||
|
||||
if (typeof o.expires_at_block_height !== 'number') return new Error(`${path}.expires_at_block_height: is not a number`)
|
||||
if (opts.expires_at_block_height_CustomCheck && !opts.expires_at_block_height_CustomCheck(o.expires_at_block_height)) return new Error(`${path}.expires_at_block_height: custom check failed`)
|
||||
|
||||
if (typeof o.invoice_amount_sats !== 'number') return new Error(`${path}.invoice_amount_sats: is not a number`)
|
||||
if (opts.invoice_amount_sats_CustomCheck && !opts.invoice_amount_sats_CustomCheck(o.invoice_amount_sats)) return new Error(`${path}.invoice_amount_sats: custom check failed`)
|
||||
|
||||
if (typeof o.paid_at_unix !== 'number') return new Error(`${path}.paid_at_unix: is not a number`)
|
||||
if (opts.paid_at_unix_CustomCheck && !opts.paid_at_unix_CustomCheck(o.paid_at_unix)) return new Error(`${path}.paid_at_unix: custom check failed`)
|
||||
|
||||
if (typeof o.service_fee_sats !== 'number') return new Error(`${path}.service_fee_sats: is not a number`)
|
||||
if (opts.service_fee_sats_CustomCheck && !opts.service_fee_sats_CustomCheck(o.service_fee_sats)) return new Error(`${path}.service_fee_sats: custom check failed`)
|
||||
|
||||
|
|
@ -4320,25 +4335,27 @@ export const TransactionSwapRequestValidate = (o?: TransactionSwapRequest, opts:
|
|||
}
|
||||
|
||||
export type TxSwapOperation = {
|
||||
address_paid: string
|
||||
address_paid?: string
|
||||
failure_reason?: string
|
||||
operation_payment?: UserOperation
|
||||
swap_operation_id: string
|
||||
quote: TransactionSwapQuote
|
||||
tx_id?: string
|
||||
}
|
||||
export type TxSwapOperationOptionalField = 'failure_reason' | 'operation_payment'
|
||||
export const TxSwapOperationOptionalFields: TxSwapOperationOptionalField[] = ['failure_reason', 'operation_payment']
|
||||
export type TxSwapOperationOptionalField = 'address_paid' | 'failure_reason' | 'operation_payment' | 'tx_id'
|
||||
export const TxSwapOperationOptionalFields: TxSwapOperationOptionalField[] = ['address_paid', 'failure_reason', 'operation_payment', 'tx_id']
|
||||
export type TxSwapOperationOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: TxSwapOperationOptionalField[]
|
||||
address_paid_CustomCheck?: (v: string) => boolean
|
||||
address_paid_CustomCheck?: (v?: string) => boolean
|
||||
failure_reason_CustomCheck?: (v?: string) => boolean
|
||||
operation_payment_Options?: UserOperationOptions
|
||||
swap_operation_id_CustomCheck?: (v: string) => boolean
|
||||
quote_Options?: TransactionSwapQuoteOptions
|
||||
tx_id_CustomCheck?: (v?: string) => boolean
|
||||
}
|
||||
export const TxSwapOperationValidate = (o?: TxSwapOperation, opts: TxSwapOperationOptions = {}, path: string = 'TxSwapOperation::root.'): Error | null => {
|
||||
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
|
||||
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
|
||||
|
||||
if (typeof o.address_paid !== 'string') return new Error(`${path}.address_paid: is not a string`)
|
||||
if ((o.address_paid || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('address_paid')) && typeof o.address_paid !== 'string') return new Error(`${path}.address_paid: is not a string`)
|
||||
if (opts.address_paid_CustomCheck && !opts.address_paid_CustomCheck(o.address_paid)) return new Error(`${path}.address_paid: custom check failed`)
|
||||
|
||||
if ((o.failure_reason || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('failure_reason')) && typeof o.failure_reason !== 'string') return new Error(`${path}.failure_reason: is not a string`)
|
||||
|
|
@ -4350,21 +4367,22 @@ export const TxSwapOperationValidate = (o?: TxSwapOperation, opts: TxSwapOperati
|
|||
}
|
||||
|
||||
|
||||
if (typeof o.swap_operation_id !== 'string') return new Error(`${path}.swap_operation_id: is not a string`)
|
||||
if (opts.swap_operation_id_CustomCheck && !opts.swap_operation_id_CustomCheck(o.swap_operation_id)) return new Error(`${path}.swap_operation_id: custom check failed`)
|
||||
const quoteErr = TransactionSwapQuoteValidate(o.quote, opts.quote_Options, `${path}.quote`)
|
||||
if (quoteErr !== null) return quoteErr
|
||||
|
||||
|
||||
if ((o.tx_id || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('tx_id')) && typeof o.tx_id !== 'string') return new Error(`${path}.tx_id: is not a string`)
|
||||
if (opts.tx_id_CustomCheck && !opts.tx_id_CustomCheck(o.tx_id)) return new Error(`${path}.tx_id: custom check failed`)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type TxSwapsList = {
|
||||
quotes: TransactionSwapQuote[]
|
||||
swaps: TxSwapOperation[]
|
||||
}
|
||||
export const TxSwapsListOptionalFields: [] = []
|
||||
export type TxSwapsListOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: []
|
||||
quotes_ItemOptions?: TransactionSwapQuoteOptions
|
||||
quotes_CustomCheck?: (v: TransactionSwapQuote[]) => boolean
|
||||
swaps_ItemOptions?: TxSwapOperationOptions
|
||||
swaps_CustomCheck?: (v: TxSwapOperation[]) => boolean
|
||||
}
|
||||
|
|
@ -4372,13 +4390,6 @@ export const TxSwapsListValidate = (o?: TxSwapsList, opts: TxSwapsListOptions =
|
|||
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
|
||||
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
|
||||
|
||||
if (!Array.isArray(o.quotes)) return new Error(`${path}.quotes: is not an array`)
|
||||
for (let index = 0; index < o.quotes.length; index++) {
|
||||
const quotesErr = TransactionSwapQuoteValidate(o.quotes[index], opts.quotes_ItemOptions, `${path}.quotes[${index}]`)
|
||||
if (quotesErr !== null) return quotesErr
|
||||
}
|
||||
if (opts.quotes_CustomCheck && !opts.quotes_CustomCheck(o.quotes)) return new Error(`${path}.quotes: custom check failed`)
|
||||
|
||||
if (!Array.isArray(o.swaps)) return new Error(`${path}.swaps: is not an array`)
|
||||
for (let index = 0; index < o.swaps.length; index++) {
|
||||
const swapsErr = TxSwapOperationValidate(o.swaps[index], opts.swaps_ItemOptions, `${path}.swaps[${index}]`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue