Skip to content

Commit ba62f5f

Browse files
committed
feat(sdk-core): add invoice codecs
BTC-0 TICKET: BTC-0
1 parent 4735a8f commit ba62f5f

File tree

1 file changed

+92
-0
lines changed
  • modules/sdk-core/src/bitgo/lightning

1 file changed

+92
-0
lines changed

modules/sdk-core/src/bitgo/lightning/codecs.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import * as t from 'io-ts';
33
import { isIP } from 'net';
44
import { NonEmptyString } from 'io-ts-types';
5+
import { BigIntFromString } from 'io-ts-types/BigIntFromString';
6+
import { DateFromISOString } from 'io-ts-types/DateFromISOString';
57

68
export function getCodecPair<C extends t.Mixed>(
79
innerCodec: C
@@ -193,3 +195,93 @@ export const BackupResponse = t.strict(
193195
);
194196

195197
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

Comments
 (0)