From 0332f697ae9a5c2a3b209007765b368bf7b55ef3 Mon Sep 17 00:00:00 2001 From: wuxiaofei Date: Mon, 20 Jun 2022 18:39:58 +0800 Subject: [PATCH] fix bug addInvoice --- channeldb/invoices.go | 10 +++++----- cmd/lncli/cmd_invoice.go | 8 ++++---- lnrpc/invoicesrpc/addinvoice.go | 3 +++ tlv/record.go | 9 --------- zpay32/encode.go | 2 ++ 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/channeldb/invoices.go b/channeldb/invoices.go index 7cd4e9dcb8..e9e4ec16bf 100644 --- a/channeldb/invoices.go +++ b/channeldb/invoices.go @@ -1994,10 +1994,10 @@ func fetchInvoiceStateAMP(invoiceNum []byte, func deserializeInvoice(r io.Reader) (Invoice, error) { var ( preimageBytes [32]byte - value lnwire.UnitPrec11 + value uint64 cltvDelta uint32 expiry uint64 - amtPaid lnwire.UnitPrec11 + amtPaid uint64 state uint8 hodlInvoice uint8 @@ -2031,7 +2031,6 @@ func deserializeInvoice(r io.Reader) (Invoice, error) { // Invoice state. tlv.MakePrimitiveRecord(invStateType, &state), tlv.MakePrimitiveRecord(amtPaidType, &amtPaid), - tlv.MakePrimitiveRecord(assetIdType, &assetId), tlv.MakePrimitiveRecord(hodlInvoiceType, &hodlInvoice), @@ -2040,6 +2039,7 @@ func deserializeInvoice(r io.Reader) (Invoice, error) { invoiceAmpStateType, &i.AMPState, nil, ampStateEncoder, ampStateDecoder, ), + tlv.MakePrimitiveRecord(assetIdType, &assetId), ) if err != nil { return i, err @@ -2061,10 +2061,10 @@ func deserializeInvoice(r io.Reader) (Invoice, error) { i.Terms.PaymentPreimage = &preimage } - i.Terms.Value = (value) + i.Terms.Value = lnwire.UnitPrec11(value) i.Terms.FinalCltvDelta = int32(cltvDelta) i.Terms.Expiry = time.Duration(expiry) - i.AmtPaid = (amtPaid) + i.AmtPaid = lnwire.UnitPrec11(amtPaid) i.AssetId = assetId i.State = ContractState(state) diff --git a/cmd/lncli/cmd_invoice.go b/cmd/lncli/cmd_invoice.go index 95a20c70cd..66ca1e6cd3 100644 --- a/cmd/lncli/cmd_invoice.go +++ b/cmd/lncli/cmd_invoice.go @@ -34,10 +34,10 @@ var addInvoiceCommand = cli.Command{ "preimage. If not set, a random preimage will be " + "created.", }, - cli.Int64Flag{ - Name: "amt", - Usage: "the amt of satoshis in this invoice", - }, + //cli.Int64Flag{ + // Name: "amt", + // Usage: "the amt of satoshis in this invoice", + //}, cli.Int64Flag{ Name: "asset_id", Usage: "asset_id of this invoice", diff --git a/lnrpc/invoicesrpc/addinvoice.go b/lnrpc/invoicesrpc/addinvoice.go index 22563d34ee..4dd7a6faf8 100644 --- a/lnrpc/invoicesrpc/addinvoice.go +++ b/lnrpc/invoicesrpc/addinvoice.go @@ -272,6 +272,7 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig, if amtMSat > 0 { options = append(options, zpay32.Amount(amtMSat)) } + options = append(options, zpay32.AssetId(invoice.AssetId)) // If specified, add a fallback address to the payment request. if len(invoice.FallbackAddr) > 0 { @@ -440,10 +441,12 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig, } newInvoice := &channeldb.Invoice{ + AssetId: invoice.AssetId, CreationDate: creationDate, Memo: []byte(invoice.Memo), PaymentRequest: []byte(payReqString), Terms: channeldb.ContractTerm{ + AssetId: invoice.AssetId, FinalCltvDelta: int32(payReq.MinFinalCLTVExpiry()), Expiry: payReq.Expiry(), Value: amtMSat, diff --git a/tlv/record.go b/tlv/record.go index ce325016de..3807095687 100644 --- a/tlv/record.go +++ b/tlv/record.go @@ -124,15 +124,6 @@ func MakePrimitiveRecord(typ Type, val interface{}) Record { encoder = EUint64 decoder = DUint64 - //case *lnwire.UnitPrec11: - // staticSize = 8 - // encoder = EUint64 - // decoder = DUint64 - //case *lnwire.UnitPrec8: - // staticSize = 8 - // encoder = EUint64 - // decoder = DUint64 - case *[32]byte: staticSize = 32 encoder = EBytes32 diff --git a/zpay32/encode.go b/zpay32/encode.go index 0763c87526..252bca3e60 100644 --- a/zpay32/encode.go +++ b/zpay32/encode.go @@ -81,6 +81,8 @@ func (invoice *Invoice) Encode(signer MessageSigner) (string, error) { hrp:="ob" +getObdHrpPre(invoice.Net) if invoice.AssetId != nil { hrp+=strconv.Itoa(int(*invoice.AssetId))+":" + }else{ + panic("Invoice Encode err: AssetId nil") } if invoice.MilliSat != nil { aid:=uint32(0)