From 752db1629ededb24335e72df71314d32fe18856c Mon Sep 17 00:00:00 2001 From: Zhen Lu Date: Tue, 23 Jul 2024 15:23:48 -0700 Subject: [PATCH] Add decimal field in InvoiceCurrency (#44) --- uma/protocol/invoice.go | 3 +++ uma/test/protocol_test.go | 9 +++++---- uma/test/uma_test.go | 7 ++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/uma/protocol/invoice.go b/uma/protocol/invoice.go index b719706..38ebecc 100644 --- a/uma/protocol/invoice.go +++ b/uma/protocol/invoice.go @@ -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) { diff --git a/uma/test/protocol_test.go b/uma/test/protocol_test.go index 8e09f3d..56bf9bb 100644 --- a/uma/test/protocol_test.go +++ b/uma/test/protocol_test.go @@ -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, @@ -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) diff --git a/uma/test/uma_test.go b/uma/test/uma_test.go index ae3101d..ff9b39f 100644 --- a/uma/test/uma_test.go +++ b/uma/test/uma_test.go @@ -814,9 +814,10 @@ func TestUMAInvoice(t *testing.T) { "$foo@bar.com", 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",