|
| 1 | +import * as t from 'io-ts'; |
| 2 | +import { BigIntFromString } from 'io-ts-types/BigIntFromString'; |
| 3 | + |
| 4 | +// codecs for lightning wallet balance api |
| 5 | + |
| 6 | +export const LndAmount = t.strict( |
| 7 | + { |
| 8 | + sat: BigIntFromString, |
| 9 | + msat: BigIntFromString, |
| 10 | + }, |
| 11 | + 'LndAmount' |
| 12 | +); |
| 13 | + |
| 14 | +export type LndAmount = t.TypeOf<typeof LndAmount>; |
| 15 | + |
| 16 | +export const ChannelBalance = t.strict( |
| 17 | + { |
| 18 | + /** The balance on your side of the channel and what you the user can spend. */ |
| 19 | + localBalance: LndAmount, |
| 20 | + /** The balance on the other side of the channel, what your channel partner can controls. */ |
| 21 | + remoteBalance: LndAmount, |
| 22 | + /** Sum of local unsettled balances. */ |
| 23 | + unsettledLocalBalance: LndAmount, |
| 24 | + /** Sum of remote unsettled balances. */ |
| 25 | + unsettledRemoteBalance: LndAmount, |
| 26 | + /** Sum of local pending balances. */ |
| 27 | + pendingOpenLocalBalance: LndAmount, |
| 28 | + /** Sum of local remote balances. */ |
| 29 | + pendingOpenRemoteBalance: LndAmount, |
| 30 | + }, |
| 31 | + 'ChannelBalance' |
| 32 | +); |
| 33 | + |
| 34 | +export type ChannelBalance = t.TypeOf<typeof ChannelBalance>; |
| 35 | + |
| 36 | +export const LndWalletBalance = t.strict( |
| 37 | + { |
| 38 | + /** Total balance, confirmed and unconfirmed */ |
| 39 | + totalBalance: BigIntFromString, |
| 40 | + confirmedBalance: BigIntFromString, |
| 41 | + unconfirmedBalance: BigIntFromString, |
| 42 | + lockedBalance: BigIntFromString, |
| 43 | + reservedBalanceAnchorChan: BigIntFromString, |
| 44 | + }, |
| 45 | + 'LndWalletBalance' |
| 46 | +); |
| 47 | + |
| 48 | +export type LndWalletBalance = t.TypeOf<typeof LndWalletBalance>; |
| 49 | + |
| 50 | +/** |
| 51 | + The balances as returned from lnd. |
| 52 | +
|
| 53 | + Wallet Balance |
| 54 | + https://api.lightning.community/api/lnd/lightning/wallet-balance/index.html |
| 55 | +
|
| 56 | + Channel Balance |
| 57 | + https://api.lightning.community/api/lnd/lightning/channel-balance/index.html |
| 58 | + */ |
| 59 | +export const LndBalance = t.strict( |
| 60 | + { |
| 61 | + offchain: ChannelBalance, |
| 62 | + onchain: LndWalletBalance, |
| 63 | + totalLimboBalance: BigIntFromString, |
| 64 | + }, |
| 65 | + 'LndBalance' |
| 66 | +); |
| 67 | + |
| 68 | +export type LndBalance = t.TypeOf<typeof LndBalance>; |
| 69 | + |
| 70 | +export const LndGetBalancesResponse = t.strict( |
| 71 | + { |
| 72 | + inboundBalance: BigIntFromString, |
| 73 | + inboundPendingBalance: BigIntFromString, |
| 74 | + inboundUnsettledBalance: BigIntFromString, |
| 75 | + outboundBalance: BigIntFromString, |
| 76 | + outboundPendingBalance: BigIntFromString, |
| 77 | + outboundUnsettledBalance: BigIntFromString, |
| 78 | + // wallet balances, names forced by type in AbstractCoin |
| 79 | + spendableBalanceString: BigIntFromString, |
| 80 | + balanceString: BigIntFromString, |
| 81 | + confirmedBalanceString: BigIntFromString, |
| 82 | + }, |
| 83 | + 'LndGetBalancesResponse' |
| 84 | +); |
| 85 | + |
| 86 | +export type LndGetBalancesResponse = t.TypeOf<typeof LndGetBalancesResponse>; |
0 commit comments