Merge pull request #891 from shocknet/assets_liabilities
assets and liabilities
This commit is contained in:
commit
f0418fb389
20 changed files with 843 additions and 11 deletions
|
|
@ -998,6 +998,28 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.GetAssetsAndLiabilities) throw new Error('method: GetAssetsAndLiabilities is not implemented')
|
||||
app.post('/api/admin/assets/liabilities', async (req, res) => {
|
||||
const info: Types.RequestInfo = { rpcName: 'GetAssetsAndLiabilities', batch: false, nostr: false, batchSize: 0}
|
||||
const stats: Types.RequestStats = { startMs:req.startTimeMs || 0, start:req.startTime || 0n, parse: process.hrtime.bigint(), guard: 0n, validate: 0n, handle: 0n }
|
||||
let authCtx: Types.AuthContext = {}
|
||||
try {
|
||||
if (!methods.GetAssetsAndLiabilities) throw new Error('method: GetAssetsAndLiabilities is not implemented')
|
||||
const authContext = await opts.AdminAuthGuard(req.headers['authorization'])
|
||||
authCtx = authContext
|
||||
stats.guard = process.hrtime.bigint()
|
||||
const request = req.body
|
||||
const error = Types.AssetsAndLiabilitiesReqValidate(request)
|
||||
stats.validate = process.hrtime.bigint()
|
||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)
|
||||
const query = req.query
|
||||
const params = req.params
|
||||
const response = await methods.GetAssetsAndLiabilities({rpcName:'GetAssetsAndLiabilities', ctx:authContext , req: request})
|
||||
stats.handle = process.hrtime.bigint()
|
||||
res.json({status: 'OK', ...response})
|
||||
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.GetBundleMetrics) throw new Error('method: GetBundleMetrics is not implemented')
|
||||
app.post('/api/reports/bundle', async (req, res) => {
|
||||
const info: Types.RequestInfo = { rpcName: 'GetBundleMetrics', batch: false, nostr: false, batchSize: 0}
|
||||
|
|
|
|||
|
|
@ -357,6 +357,20 @@ export default (params: ClientParams) => ({
|
|||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
GetAssetsAndLiabilities: async (request: Types.AssetsAndLiabilitiesReq): Promise<ResultError | ({ status: 'OK' }& Types.AssetsAndLiabilities)> => {
|
||||
const auth = await params.retrieveAdminAuth()
|
||||
if (auth === null) throw new Error('retrieveAdminAuth() returned null')
|
||||
let finalRoute = '/api/admin/assets/liabilities'
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
const result = data
|
||||
if(!params.checkResult) return { status: 'OK', ...result }
|
||||
const error = Types.AssetsAndLiabilitiesValidate(result)
|
||||
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
GetBundleMetrics: async (request: Types.LatestBundleMetricReq): Promise<ResultError | ({ status: 'OK' }& Types.BundleMetrics)> => {
|
||||
const auth = await params.retrieveMetricsAuth()
|
||||
if (auth === null) throw new Error('retrieveMetricsAuth() returned null')
|
||||
|
|
|
|||
|
|
@ -275,6 +275,21 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ
|
|||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
GetAssetsAndLiabilities: async (request: Types.AssetsAndLiabilitiesReq): Promise<ResultError | ({ status: 'OK' }& Types.AssetsAndLiabilities)> => {
|
||||
const auth = await params.retrieveNostrAdminAuth()
|
||||
if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null')
|
||||
const nostrRequest: NostrRequest = {}
|
||||
nostrRequest.body = request
|
||||
const data = await send(params.pubDestination, {rpcName:'GetAssetsAndLiabilities',authIdentifier:auth, ...nostrRequest })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
const result = data
|
||||
if(!params.checkResult) return { status: 'OK', ...result }
|
||||
const error = Types.AssetsAndLiabilitiesValidate(result)
|
||||
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
},
|
||||
GetBundleMetrics: async (request: Types.LatestBundleMetricReq): Promise<ResultError | ({ status: 'OK' }& Types.BundleMetrics)> => {
|
||||
const auth = await params.retrieveNostrMetricsAuth()
|
||||
if (auth === null) throw new Error('retrieveNostrMetricsAuth() returned null')
|
||||
|
|
|
|||
|
|
@ -735,6 +735,22 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
|||
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
||||
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
||||
break
|
||||
case 'GetAssetsAndLiabilities':
|
||||
try {
|
||||
if (!methods.GetAssetsAndLiabilities) throw new Error('method: GetAssetsAndLiabilities is not implemented')
|
||||
const authContext = await opts.NostrAdminAuthGuard(req.appId, req.authIdentifier)
|
||||
stats.guard = process.hrtime.bigint()
|
||||
authCtx = authContext
|
||||
const request = req.body
|
||||
const error = Types.AssetsAndLiabilitiesReqValidate(request)
|
||||
stats.validate = process.hrtime.bigint()
|
||||
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback)
|
||||
const response = await methods.GetAssetsAndLiabilities({rpcName:'GetAssetsAndLiabilities', ctx:authContext , req: request})
|
||||
stats.handle = process.hrtime.bigint()
|
||||
res({status: 'OK', ...response})
|
||||
opts.metricsCallback([{ ...info, ...stats, ...authContext }])
|
||||
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e }
|
||||
break
|
||||
case 'GetBundleMetrics':
|
||||
try {
|
||||
if (!methods.GetBundleMetrics) throw new Error('method: GetBundleMetrics is not implemented')
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ export type RequestMetric = AuthContext & RequestInfo & RequestStats & { error?:
|
|||
export type AdminContext = {
|
||||
admin_id: string
|
||||
}
|
||||
export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetAdminInvoiceSwapQuotes_Input | GetAdminTransactionSwapQuotes_Input | GetInviteLinkState_Input | GetSeed_Input | ListAdminInvoiceSwaps_Input | ListAdminTxSwaps_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input | PayAdminInvoiceSwap_Input | PayAdminTransactionSwap_Input | RefundAdminInvoiceSwap_Input | UpdateChannelPolicy_Input
|
||||
export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetAdminInvoiceSwapQuotes_Output | GetAdminTransactionSwapQuotes_Output | GetInviteLinkState_Output | GetSeed_Output | ListAdminInvoiceSwaps_Output | ListAdminTxSwaps_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output | PayAdminInvoiceSwap_Output | PayAdminTransactionSwap_Output | RefundAdminInvoiceSwap_Output | UpdateChannelPolicy_Output
|
||||
export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetAdminInvoiceSwapQuotes_Input | GetAdminTransactionSwapQuotes_Input | GetAssetsAndLiabilities_Input | GetInviteLinkState_Input | GetSeed_Input | ListAdminInvoiceSwaps_Input | ListAdminTxSwaps_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input | PayAdminInvoiceSwap_Input | PayAdminTransactionSwap_Input | RefundAdminInvoiceSwap_Input | UpdateChannelPolicy_Input
|
||||
export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetAdminInvoiceSwapQuotes_Output | GetAdminTransactionSwapQuotes_Output | GetAssetsAndLiabilities_Output | GetInviteLinkState_Output | GetSeed_Output | ListAdminInvoiceSwaps_Output | ListAdminTxSwaps_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output | PayAdminInvoiceSwap_Output | PayAdminTransactionSwap_Output | RefundAdminInvoiceSwap_Output | UpdateChannelPolicy_Output
|
||||
export type AppContext = {
|
||||
app_id: string
|
||||
}
|
||||
|
|
@ -117,6 +117,9 @@ export type GetAppUserLNURLInfo_Output = ResultError | ({ status: 'OK' } & Lnurl
|
|||
export type GetAppsMetrics_Input = {rpcName:'GetAppsMetrics', req: AppsMetricsRequest}
|
||||
export type GetAppsMetrics_Output = ResultError | ({ status: 'OK' } & AppsMetrics)
|
||||
|
||||
export type GetAssetsAndLiabilities_Input = {rpcName:'GetAssetsAndLiabilities', req: AssetsAndLiabilitiesReq}
|
||||
export type GetAssetsAndLiabilities_Output = ResultError | ({ status: 'OK' } & AssetsAndLiabilities)
|
||||
|
||||
export type GetBundleMetrics_Input = {rpcName:'GetBundleMetrics', req: LatestBundleMetricReq}
|
||||
export type GetBundleMetrics_Output = ResultError | ({ status: 'OK' } & BundleMetrics)
|
||||
|
||||
|
|
@ -375,6 +378,7 @@ export type ServerMethods = {
|
|||
GetAppUser?: (req: GetAppUser_Input & {ctx: AppContext }) => Promise<AppUser>
|
||||
GetAppUserLNURLInfo?: (req: GetAppUserLNURLInfo_Input & {ctx: AppContext }) => Promise<LnurlPayInfoResponse>
|
||||
GetAppsMetrics?: (req: GetAppsMetrics_Input & {ctx: MetricsContext }) => Promise<AppsMetrics>
|
||||
GetAssetsAndLiabilities?: (req: GetAssetsAndLiabilities_Input & {ctx: AdminContext }) => Promise<AssetsAndLiabilities>
|
||||
GetBundleMetrics?: (req: GetBundleMetrics_Input & {ctx: MetricsContext }) => Promise<BundleMetrics>
|
||||
GetDebitAuthorizations?: (req: GetDebitAuthorizations_Input & {ctx: UserContext }) => Promise<DebitAuthorizations>
|
||||
GetErrorStats?: (req: GetErrorStats_Input & {ctx: MetricsContext }) => Promise<ErrorStats>
|
||||
|
|
@ -481,6 +485,14 @@ export const enumCheckSingleMetricType = (e?: SingleMetricType): boolean => {
|
|||
for (const v in SingleMetricType) if (e === v) return true
|
||||
return false
|
||||
}
|
||||
export enum TrackedOperationType {
|
||||
ROOT = 'ROOT',
|
||||
USER = 'USER',
|
||||
}
|
||||
export const enumCheckTrackedOperationType = (e?: TrackedOperationType): boolean => {
|
||||
for (const v in TrackedOperationType) if (e === v) return true
|
||||
return false
|
||||
}
|
||||
export enum UserOperationType {
|
||||
INCOMING_INVOICE = 'INCOMING_INVOICE',
|
||||
INCOMING_TX = 'INCOMING_TX',
|
||||
|
|
@ -929,6 +941,105 @@ export const AppsMetricsRequestValidate = (o?: AppsMetricsRequest, opts: AppsMet
|
|||
return null
|
||||
}
|
||||
|
||||
export type AssetOperation = {
|
||||
amount: number
|
||||
tracked?: TrackedOperation
|
||||
ts: number
|
||||
}
|
||||
export type AssetOperationOptionalField = 'tracked'
|
||||
export const AssetOperationOptionalFields: AssetOperationOptionalField[] = ['tracked']
|
||||
export type AssetOperationOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: AssetOperationOptionalField[]
|
||||
amount_CustomCheck?: (v: number) => boolean
|
||||
tracked_Options?: TrackedOperationOptions
|
||||
ts_CustomCheck?: (v: number) => boolean
|
||||
}
|
||||
export const AssetOperationValidate = (o?: AssetOperation, opts: AssetOperationOptions = {}, path: string = 'AssetOperation::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.amount !== 'number') return new Error(`${path}.amount: is not a number`)
|
||||
if (opts.amount_CustomCheck && !opts.amount_CustomCheck(o.amount)) return new Error(`${path}.amount: custom check failed`)
|
||||
|
||||
if (typeof o.tracked === 'object' || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('tracked')) {
|
||||
const trackedErr = TrackedOperationValidate(o.tracked, opts.tracked_Options, `${path}.tracked`)
|
||||
if (trackedErr !== null) return trackedErr
|
||||
}
|
||||
|
||||
|
||||
if (typeof o.ts !== 'number') return new Error(`${path}.ts: is not a number`)
|
||||
if (opts.ts_CustomCheck && !opts.ts_CustomCheck(o.ts)) return new Error(`${path}.ts: custom check failed`)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type AssetsAndLiabilities = {
|
||||
liquidity_providers: LiquidityAssetProvider[]
|
||||
lnds: LndAssetProvider[]
|
||||
users_balance: number
|
||||
}
|
||||
export const AssetsAndLiabilitiesOptionalFields: [] = []
|
||||
export type AssetsAndLiabilitiesOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: []
|
||||
liquidity_providers_ItemOptions?: LiquidityAssetProviderOptions
|
||||
liquidity_providers_CustomCheck?: (v: LiquidityAssetProvider[]) => boolean
|
||||
lnds_ItemOptions?: LndAssetProviderOptions
|
||||
lnds_CustomCheck?: (v: LndAssetProvider[]) => boolean
|
||||
users_balance_CustomCheck?: (v: number) => boolean
|
||||
}
|
||||
export const AssetsAndLiabilitiesValidate = (o?: AssetsAndLiabilities, opts: AssetsAndLiabilitiesOptions = {}, path: string = 'AssetsAndLiabilities::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 (!Array.isArray(o.liquidity_providers)) return new Error(`${path}.liquidity_providers: is not an array`)
|
||||
for (let index = 0; index < o.liquidity_providers.length; index++) {
|
||||
const liquidity_providersErr = LiquidityAssetProviderValidate(o.liquidity_providers[index], opts.liquidity_providers_ItemOptions, `${path}.liquidity_providers[${index}]`)
|
||||
if (liquidity_providersErr !== null) return liquidity_providersErr
|
||||
}
|
||||
if (opts.liquidity_providers_CustomCheck && !opts.liquidity_providers_CustomCheck(o.liquidity_providers)) return new Error(`${path}.liquidity_providers: custom check failed`)
|
||||
|
||||
if (!Array.isArray(o.lnds)) return new Error(`${path}.lnds: is not an array`)
|
||||
for (let index = 0; index < o.lnds.length; index++) {
|
||||
const lndsErr = LndAssetProviderValidate(o.lnds[index], opts.lnds_ItemOptions, `${path}.lnds[${index}]`)
|
||||
if (lndsErr !== null) return lndsErr
|
||||
}
|
||||
if (opts.lnds_CustomCheck && !opts.lnds_CustomCheck(o.lnds)) return new Error(`${path}.lnds: custom check failed`)
|
||||
|
||||
if (typeof o.users_balance !== 'number') return new Error(`${path}.users_balance: is not a number`)
|
||||
if (opts.users_balance_CustomCheck && !opts.users_balance_CustomCheck(o.users_balance)) return new Error(`${path}.users_balance: custom check failed`)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type AssetsAndLiabilitiesReq = {
|
||||
limit_invoices?: number
|
||||
limit_payments?: number
|
||||
limit_providers?: number
|
||||
}
|
||||
export type AssetsAndLiabilitiesReqOptionalField = 'limit_invoices' | 'limit_payments' | 'limit_providers'
|
||||
export const AssetsAndLiabilitiesReqOptionalFields: AssetsAndLiabilitiesReqOptionalField[] = ['limit_invoices', 'limit_payments', 'limit_providers']
|
||||
export type AssetsAndLiabilitiesReqOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: AssetsAndLiabilitiesReqOptionalField[]
|
||||
limit_invoices_CustomCheck?: (v?: number) => boolean
|
||||
limit_payments_CustomCheck?: (v?: number) => boolean
|
||||
limit_providers_CustomCheck?: (v?: number) => boolean
|
||||
}
|
||||
export const AssetsAndLiabilitiesReqValidate = (o?: AssetsAndLiabilitiesReq, opts: AssetsAndLiabilitiesReqOptions = {}, path: string = 'AssetsAndLiabilitiesReq::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 ((o.limit_invoices || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('limit_invoices')) && typeof o.limit_invoices !== 'number') return new Error(`${path}.limit_invoices: is not a number`)
|
||||
if (opts.limit_invoices_CustomCheck && !opts.limit_invoices_CustomCheck(o.limit_invoices)) return new Error(`${path}.limit_invoices: custom check failed`)
|
||||
|
||||
if ((o.limit_payments || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('limit_payments')) && typeof o.limit_payments !== 'number') return new Error(`${path}.limit_payments: is not a number`)
|
||||
if (opts.limit_payments_CustomCheck && !opts.limit_payments_CustomCheck(o.limit_payments)) return new Error(`${path}.limit_payments: custom check failed`)
|
||||
|
||||
if ((o.limit_providers || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('limit_providers')) && typeof o.limit_providers !== 'number') return new Error(`${path}.limit_providers: is not a number`)
|
||||
if (opts.limit_providers_CustomCheck && !opts.limit_providers_CustomCheck(o.limit_providers)) return new Error(`${path}.limit_providers: custom check failed`)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type AuthApp = {
|
||||
app: Application
|
||||
auth_token: string
|
||||
|
|
@ -2358,6 +2469,33 @@ export const LinkNPubThroughTokenRequestValidate = (o?: LinkNPubThroughTokenRequ
|
|||
return null
|
||||
}
|
||||
|
||||
export type LiquidityAssetProvider = {
|
||||
pubkey: string
|
||||
tracked?: TrackedLiquidityProvider
|
||||
}
|
||||
export type LiquidityAssetProviderOptionalField = 'tracked'
|
||||
export const LiquidityAssetProviderOptionalFields: LiquidityAssetProviderOptionalField[] = ['tracked']
|
||||
export type LiquidityAssetProviderOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: LiquidityAssetProviderOptionalField[]
|
||||
pubkey_CustomCheck?: (v: string) => boolean
|
||||
tracked_Options?: TrackedLiquidityProviderOptions
|
||||
}
|
||||
export const LiquidityAssetProviderValidate = (o?: LiquidityAssetProvider, opts: LiquidityAssetProviderOptions = {}, path: string = 'LiquidityAssetProvider::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.pubkey !== 'string') return new Error(`${path}.pubkey: is not a string`)
|
||||
if (opts.pubkey_CustomCheck && !opts.pubkey_CustomCheck(o.pubkey)) return new Error(`${path}.pubkey: custom check failed`)
|
||||
|
||||
if (typeof o.tracked === 'object' || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('tracked')) {
|
||||
const trackedErr = TrackedLiquidityProviderValidate(o.tracked, opts.tracked_Options, `${path}.tracked`)
|
||||
if (trackedErr !== null) return trackedErr
|
||||
}
|
||||
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type LiveDebitRequest = {
|
||||
debit: LiveDebitRequest_debit
|
||||
npub: string
|
||||
|
|
@ -2434,6 +2572,33 @@ export const LiveUserOperationValidate = (o?: LiveUserOperation, opts: LiveUserO
|
|||
return null
|
||||
}
|
||||
|
||||
export type LndAssetProvider = {
|
||||
pubkey: string
|
||||
tracked?: TrackedLndProvider
|
||||
}
|
||||
export type LndAssetProviderOptionalField = 'tracked'
|
||||
export const LndAssetProviderOptionalFields: LndAssetProviderOptionalField[] = ['tracked']
|
||||
export type LndAssetProviderOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: LndAssetProviderOptionalField[]
|
||||
pubkey_CustomCheck?: (v: string) => boolean
|
||||
tracked_Options?: TrackedLndProviderOptions
|
||||
}
|
||||
export const LndAssetProviderValidate = (o?: LndAssetProvider, opts: LndAssetProviderOptions = {}, path: string = 'LndAssetProvider::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.pubkey !== 'string') return new Error(`${path}.pubkey: is not a string`)
|
||||
if (opts.pubkey_CustomCheck && !opts.pubkey_CustomCheck(o.pubkey)) return new Error(`${path}.pubkey: custom check failed`)
|
||||
|
||||
if (typeof o.tracked === 'object' || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('tracked')) {
|
||||
const trackedErr = TrackedLndProviderValidate(o.tracked, opts.tracked_Options, `${path}.tracked`)
|
||||
if (trackedErr !== null) return trackedErr
|
||||
}
|
||||
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type LndChannels = {
|
||||
open_channels: OpenChannel[]
|
||||
}
|
||||
|
|
@ -4230,6 +4395,140 @@ export const SingleMetricReqValidate = (o?: SingleMetricReq, opts: SingleMetricR
|
|||
return null
|
||||
}
|
||||
|
||||
export type TrackedLiquidityProvider = {
|
||||
balance: number
|
||||
invoices: AssetOperation[]
|
||||
payments: AssetOperation[]
|
||||
}
|
||||
export const TrackedLiquidityProviderOptionalFields: [] = []
|
||||
export type TrackedLiquidityProviderOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: []
|
||||
balance_CustomCheck?: (v: number) => boolean
|
||||
invoices_ItemOptions?: AssetOperationOptions
|
||||
invoices_CustomCheck?: (v: AssetOperation[]) => boolean
|
||||
payments_ItemOptions?: AssetOperationOptions
|
||||
payments_CustomCheck?: (v: AssetOperation[]) => boolean
|
||||
}
|
||||
export const TrackedLiquidityProviderValidate = (o?: TrackedLiquidityProvider, opts: TrackedLiquidityProviderOptions = {}, path: string = 'TrackedLiquidityProvider::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.balance !== 'number') return new Error(`${path}.balance: is not a number`)
|
||||
if (opts.balance_CustomCheck && !opts.balance_CustomCheck(o.balance)) return new Error(`${path}.balance: custom check failed`)
|
||||
|
||||
if (!Array.isArray(o.invoices)) return new Error(`${path}.invoices: is not an array`)
|
||||
for (let index = 0; index < o.invoices.length; index++) {
|
||||
const invoicesErr = AssetOperationValidate(o.invoices[index], opts.invoices_ItemOptions, `${path}.invoices[${index}]`)
|
||||
if (invoicesErr !== null) return invoicesErr
|
||||
}
|
||||
if (opts.invoices_CustomCheck && !opts.invoices_CustomCheck(o.invoices)) return new Error(`${path}.invoices: custom check failed`)
|
||||
|
||||
if (!Array.isArray(o.payments)) return new Error(`${path}.payments: is not an array`)
|
||||
for (let index = 0; index < o.payments.length; index++) {
|
||||
const paymentsErr = AssetOperationValidate(o.payments[index], opts.payments_ItemOptions, `${path}.payments[${index}]`)
|
||||
if (paymentsErr !== null) return paymentsErr
|
||||
}
|
||||
if (opts.payments_CustomCheck && !opts.payments_CustomCheck(o.payments)) return new Error(`${path}.payments: custom check failed`)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type TrackedLndProvider = {
|
||||
channels_balance: number
|
||||
confirmed_balance: number
|
||||
incoming_tx: AssetOperation[]
|
||||
invoices: AssetOperation[]
|
||||
outgoing_tx: AssetOperation[]
|
||||
payments: AssetOperation[]
|
||||
unconfirmed_balance: number
|
||||
}
|
||||
export const TrackedLndProviderOptionalFields: [] = []
|
||||
export type TrackedLndProviderOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: []
|
||||
channels_balance_CustomCheck?: (v: number) => boolean
|
||||
confirmed_balance_CustomCheck?: (v: number) => boolean
|
||||
incoming_tx_ItemOptions?: AssetOperationOptions
|
||||
incoming_tx_CustomCheck?: (v: AssetOperation[]) => boolean
|
||||
invoices_ItemOptions?: AssetOperationOptions
|
||||
invoices_CustomCheck?: (v: AssetOperation[]) => boolean
|
||||
outgoing_tx_ItemOptions?: AssetOperationOptions
|
||||
outgoing_tx_CustomCheck?: (v: AssetOperation[]) => boolean
|
||||
payments_ItemOptions?: AssetOperationOptions
|
||||
payments_CustomCheck?: (v: AssetOperation[]) => boolean
|
||||
unconfirmed_balance_CustomCheck?: (v: number) => boolean
|
||||
}
|
||||
export const TrackedLndProviderValidate = (o?: TrackedLndProvider, opts: TrackedLndProviderOptions = {}, path: string = 'TrackedLndProvider::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.channels_balance !== 'number') return new Error(`${path}.channels_balance: is not a number`)
|
||||
if (opts.channels_balance_CustomCheck && !opts.channels_balance_CustomCheck(o.channels_balance)) return new Error(`${path}.channels_balance: custom check failed`)
|
||||
|
||||
if (typeof o.confirmed_balance !== 'number') return new Error(`${path}.confirmed_balance: is not a number`)
|
||||
if (opts.confirmed_balance_CustomCheck && !opts.confirmed_balance_CustomCheck(o.confirmed_balance)) return new Error(`${path}.confirmed_balance: custom check failed`)
|
||||
|
||||
if (!Array.isArray(o.incoming_tx)) return new Error(`${path}.incoming_tx: is not an array`)
|
||||
for (let index = 0; index < o.incoming_tx.length; index++) {
|
||||
const incoming_txErr = AssetOperationValidate(o.incoming_tx[index], opts.incoming_tx_ItemOptions, `${path}.incoming_tx[${index}]`)
|
||||
if (incoming_txErr !== null) return incoming_txErr
|
||||
}
|
||||
if (opts.incoming_tx_CustomCheck && !opts.incoming_tx_CustomCheck(o.incoming_tx)) return new Error(`${path}.incoming_tx: custom check failed`)
|
||||
|
||||
if (!Array.isArray(o.invoices)) return new Error(`${path}.invoices: is not an array`)
|
||||
for (let index = 0; index < o.invoices.length; index++) {
|
||||
const invoicesErr = AssetOperationValidate(o.invoices[index], opts.invoices_ItemOptions, `${path}.invoices[${index}]`)
|
||||
if (invoicesErr !== null) return invoicesErr
|
||||
}
|
||||
if (opts.invoices_CustomCheck && !opts.invoices_CustomCheck(o.invoices)) return new Error(`${path}.invoices: custom check failed`)
|
||||
|
||||
if (!Array.isArray(o.outgoing_tx)) return new Error(`${path}.outgoing_tx: is not an array`)
|
||||
for (let index = 0; index < o.outgoing_tx.length; index++) {
|
||||
const outgoing_txErr = AssetOperationValidate(o.outgoing_tx[index], opts.outgoing_tx_ItemOptions, `${path}.outgoing_tx[${index}]`)
|
||||
if (outgoing_txErr !== null) return outgoing_txErr
|
||||
}
|
||||
if (opts.outgoing_tx_CustomCheck && !opts.outgoing_tx_CustomCheck(o.outgoing_tx)) return new Error(`${path}.outgoing_tx: custom check failed`)
|
||||
|
||||
if (!Array.isArray(o.payments)) return new Error(`${path}.payments: is not an array`)
|
||||
for (let index = 0; index < o.payments.length; index++) {
|
||||
const paymentsErr = AssetOperationValidate(o.payments[index], opts.payments_ItemOptions, `${path}.payments[${index}]`)
|
||||
if (paymentsErr !== null) return paymentsErr
|
||||
}
|
||||
if (opts.payments_CustomCheck && !opts.payments_CustomCheck(o.payments)) return new Error(`${path}.payments: custom check failed`)
|
||||
|
||||
if (typeof o.unconfirmed_balance !== 'number') return new Error(`${path}.unconfirmed_balance: is not a number`)
|
||||
if (opts.unconfirmed_balance_CustomCheck && !opts.unconfirmed_balance_CustomCheck(o.unconfirmed_balance)) return new Error(`${path}.unconfirmed_balance: custom check failed`)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type TrackedOperation = {
|
||||
amount: number
|
||||
ts: number
|
||||
type: TrackedOperationType
|
||||
}
|
||||
export const TrackedOperationOptionalFields: [] = []
|
||||
export type TrackedOperationOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: []
|
||||
amount_CustomCheck?: (v: number) => boolean
|
||||
ts_CustomCheck?: (v: number) => boolean
|
||||
type_CustomCheck?: (v: TrackedOperationType) => boolean
|
||||
}
|
||||
export const TrackedOperationValidate = (o?: TrackedOperation, opts: TrackedOperationOptions = {}, path: string = 'TrackedOperation::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.amount !== 'number') return new Error(`${path}.amount: is not a number`)
|
||||
if (opts.amount_CustomCheck && !opts.amount_CustomCheck(o.amount)) return new Error(`${path}.amount: custom check failed`)
|
||||
|
||||
if (typeof o.ts !== 'number') return new Error(`${path}.ts: is not a number`)
|
||||
if (opts.ts_CustomCheck && !opts.ts_CustomCheck(o.ts)) return new Error(`${path}.ts: custom check failed`)
|
||||
|
||||
if (!enumCheckTrackedOperationType(o.type)) return new Error(`${path}.type: is not a valid TrackedOperationType`)
|
||||
if (opts.type_CustomCheck && !opts.type_CustomCheck(o.type)) return new Error(`${path}.type: custom check failed`)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type TransactionSwapQuote = {
|
||||
chain_fee_sats: number
|
||||
completed_at_unix: number
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue