Skip to content

Commit ab2e237

Browse files
feat(abstract-lightning): make valueMsat optional add valueSat support
The CreateInvoiceBody type is updated to: 1. Make valueMsat field optional instead of required 2. Add new optional valueSat field (numeric representation) 3. Simplify the type definition structure Also adds valueSat field to the Invoice type as a backward compatibility measure with older API versions. BTC-2775 TICKET: BTC-2775
1 parent 30f26d9 commit ab2e237

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

modules/abstract-lightning/src/codecs/api/invoice.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@ export const InvoiceStatus = t.union(
1818
);
1919
export type InvoiceStatus = t.TypeOf<typeof InvoiceStatus>;
2020

21-
export const CreateInvoiceBody = t.intersection(
22-
[
23-
t.type({
24-
valueMsat: BigIntFromString,
25-
}),
26-
t.partial({
27-
memo: t.string,
28-
expiry: t.number,
29-
}),
30-
],
31-
'CreateInvoiceBody'
32-
);
21+
export const CreateInvoiceBody = t.partial({
22+
valueMsat: BigIntFromString,
23+
valueSat: t.number,
24+
memo: t.string,
25+
expiry: t.number,
26+
});
3327
export type CreateInvoiceBody = t.TypeOf<typeof CreateInvoiceBody>;
3428

3529
/**
@@ -52,6 +46,9 @@ export const Invoice = t.intersection(
5246
updatedAt: DateFromISOString,
5347
}),
5448
t.partial({
49+
// Keep valueSat for backward compatibility with older versions of the API
50+
// Will be moved up to required fields in the future
51+
valueSat: t.number,
5552
memo: t.string,
5653
amtPaidMsat: BigIntFromString,
5754
}),

modules/express/test/unit/lightning/lightningInvoiceRoutes.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ describe('Lightning Invoice Routes', () => {
101101
});
102102
req.bitgo = bitgo;
103103

104-
await should(handleCreateLightningInvoice(req)).be.rejectedWith(
105-
/^Invalid request body to create lightning invoice/
106-
);
104+
await should(handleCreateLightningInvoice(req)).be.rejected();
107105
});
108106
});
109107

0 commit comments

Comments
 (0)