Skip to content

Commit

Permalink
Add decimal field in InvoiceCurrency (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenlu authored Jul 23, 2024
1 parent 8290fa7 commit 752db16
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions uma/protocol/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type InvoiceCurrency struct {

// Symbol is the symbol of the currency (eg. $ for USD).
Symbol string `tlv:"2"`

// Decimals is the number of digits after the decimal point for display on the sender side
Decimals uint8 `tlv:"3"`
}

func (c *InvoiceCurrency) MarshalTLV() ([]byte, error) {
Expand Down
9 changes: 5 additions & 4 deletions uma/test/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,10 @@ func TestUMAInvoiceTLVAndBech32(t *testing.T) {
InvoiceUUID: "c7c07fec-cf00-431c-916f-6c13fc4b69f9",
Amount: 1000,
ReceivingCurrency: umaprotocol.InvoiceCurrency{
Code: "USD",
Name: "US Dollar",
Symbol: "$",
Code: "USD",
Name: "US Dollar",
Symbol: "$",
Decimals: 2,
},
Expiration: 1000000,
IsSubjectToTravelRule: true,
Expand Down Expand Up @@ -308,7 +309,7 @@ func TestUMAInvoiceTLVAndBech32(t *testing.T) {

bech32String, err := invoice2.ToBech32String()
require.NoError(t, err)
require.Equal(t, "uma1qqxzgen0daqxyctj9e3k7mgpy33nwcesxanx2cedvdnrqvpdxsenzced8ycnve3dxe3nzvmxvv6xyd3evcusypp3xqcrqqcnqqp4256yqyy425eqg3hkcmrpwgpqzfqyqucnqvpsxqcrqpgpqyrpkcm0d4cxc6tpde3k2w3393jk6ctfdsarqtrwv9kk2w3squpnqt3npvy9v32jf9ryj32ypswxsar5wpen5te0v4uxzmtsd3jjucm0d5hkxctvd33xzcmtvsyhx6t8deshgatjv5sjy5ff", bech32String)
require.Equal(t, "uma1qqxzgen0daqxyctj9e3k7mgpy33nwcesxanx2cedvdnrqvpdxsenzced8ycnve3dxe3nzvmxvv6xyd3evcusypp3xqcrqqckqqp4256yqyy425eqg3hkcmrpwgpqzfqrqyeqgpe3xqcrqvpsxqzszqgxrd3k7mtsd35kzmnrv5arztr9d4skjmp6xqkxuctdv5arqpcrxqhrxzcg2ez4yj2xf9z5grqudp68gurn8ghj7etcv9khqmr99e3k7mf0vdskcmrzv93kkeqfwd5kwmnpw36hyegy0tgay", bech32String)

invoice3, err := umaprotocol.FromBech32String(bech32String)
require.NoError(t, err)
Expand Down
7 changes: 4 additions & 3 deletions uma/test/uma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,9 +814,10 @@ func TestUMAInvoice(t *testing.T) {
"[email protected]",
100000,
umaprotocol.InvoiceCurrency{
Code: "USD",
Name: "US Dollar",
Symbol: "$",
Code: "USD",
Name: "US Dollar",
Symbol: "$",
Decimals: 2,
},
1721081249,
"https://vasp2.com/api/lnurl/payreq/$foo",
Expand Down

0 comments on commit 752db16

Please sign in to comment.