|
2 | 2 | import * as t from 'io-ts'; |
3 | 3 | import { isIP } from 'net'; |
4 | 4 | import { NonEmptyString } from 'io-ts-types'; |
| 5 | +import { BigIntFromString } from 'io-ts-types/BigIntFromString'; |
| 6 | +import { DateFromISOString } from 'io-ts-types/DateFromISOString'; |
5 | 7 |
|
6 | 8 | export function getCodecPair<C extends t.Mixed>( |
7 | 9 | innerCodec: C |
@@ -193,3 +195,93 @@ export const BackupResponse = t.strict( |
193 | 195 | ); |
194 | 196 |
|
195 | 197 | export type BackupResponse = t.TypeOf<typeof BackupResponse>; |
| 198 | + |
| 199 | +export const InvoiceStatus = t.union( |
| 200 | + [ |
| 201 | + // Initial state. |
| 202 | + // Transitions to 'settled' or 'canceled' on LND notification. |
| 203 | + t.literal('open'), |
| 204 | + // Final state. |
| 205 | + t.literal('settled'), |
| 206 | + // Final state. |
| 207 | + t.literal('canceled'), |
| 208 | + ], |
| 209 | + 'InvoiceStatus' |
| 210 | +); |
| 211 | +export type InvoiceStatus = t.TypeOf<typeof InvoiceStatus>; |
| 212 | + |
| 213 | +export const CreateInvoiceBody = t.intersection( |
| 214 | + [ |
| 215 | + t.type({ |
| 216 | + valueMsat: BigIntFromString, |
| 217 | + }), |
| 218 | + t.partial({ |
| 219 | + memo: t.string, |
| 220 | + expiry: t.number, |
| 221 | + }), |
| 222 | + ], |
| 223 | + 'CreateInvoiceBody' |
| 224 | +); |
| 225 | +export type CreateInvoiceBody = t.TypeOf<typeof CreateInvoiceBody>; |
| 226 | + |
| 227 | +/** |
| 228 | + * A representation of the data tracked by the indexer for an invoice it has |
| 229 | + * created within lnd. |
| 230 | + */ |
| 231 | +export const Invoice = t.intersection( |
| 232 | + [ |
| 233 | + t.type({ |
| 234 | + valueMsat: BigIntFromString, |
| 235 | + paymentHash: t.string, |
| 236 | + /** The BOLT #11 encoded invoice string */ |
| 237 | + invoice: t.string, |
| 238 | + /** The public BitGo walletId to which this invoice belongs */ |
| 239 | + walletId: t.string, |
| 240 | + status: InvoiceStatus, |
| 241 | + /** A date in ISO format representing when this invoice expires. */ |
| 242 | + expiresAt: t.string, |
| 243 | + }), |
| 244 | + t.partial({ |
| 245 | + memo: t.string, |
| 246 | + }), |
| 247 | + ], |
| 248 | + 'Invoice' |
| 249 | +); |
| 250 | +export type Invoice = t.TypeOf<typeof Invoice>; |
| 251 | + |
| 252 | +export const InvoiceInfo = t.intersection( |
| 253 | + [ |
| 254 | + t.type({ |
| 255 | + valueMsat: BigIntFromString, |
| 256 | + paymentHash: t.string, |
| 257 | + invoice: t.string, |
| 258 | + walletId: t.string, |
| 259 | + status: InvoiceStatus, |
| 260 | + expiresAt: t.string, |
| 261 | + createdAt: t.string, |
| 262 | + updatedAt: t.string, |
| 263 | + }), |
| 264 | + t.partial({ |
| 265 | + /** |
| 266 | + * The number of millisats actually paid to this invoice, this may be greater |
| 267 | + * than the amount requested by the invoice, since lightning allows overpaying |
| 268 | + * (but not underpaying) invoices. |
| 269 | + */ |
| 270 | + amtPaidMsat: BigIntFromString, |
| 271 | + }), |
| 272 | + ], |
| 273 | + 'InvoiceInfo' |
| 274 | +); |
| 275 | +export type InvoiceInfo = t.TypeOf<typeof InvoiceInfo>; |
| 276 | + |
| 277 | +export const InvoiceQuery = t.partial( |
| 278 | + { |
| 279 | + status: InvoiceStatus, |
| 280 | + limit: t.string, |
| 281 | + startDate: DateFromISOString, |
| 282 | + endDate: DateFromISOString, |
| 283 | + }, |
| 284 | + 'InvoiceQuery' |
| 285 | +); |
| 286 | + |
| 287 | +export type InvoiceQuery = t.TypeOf<typeof InvoiceQuery>; |
0 commit comments