Skip to content

Commit

Permalink
fix bug addInvoice
Browse files Browse the repository at this point in the history
  • Loading branch information
wxf4150 committed Jun 20, 2022
1 parent 8db9f62 commit 0332f69
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
10 changes: 5 additions & 5 deletions channeldb/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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),

Expand All @@ -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
Expand All @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions cmd/lncli/cmd_invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions lnrpc/invoicesrpc/addinvoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 0 additions & 9 deletions tlv/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions zpay32/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0332f69

Please sign in to comment.