From 251f8d650f1d27b11867d4a557295cb74afa7aa1 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 21 Aug 2017 22:51:19 -0700 Subject: [PATCH] channeldb: update the Invoice struct to use lnwire.MilliSatoshi --- channeldb/invoice_test.go | 8 ++++---- channeldb/invoices.go | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/channeldb/invoice_test.go b/channeldb/invoice_test.go index 599edab52..8f5746c80 100644 --- a/channeldb/invoice_test.go +++ b/channeldb/invoice_test.go @@ -8,10 +8,10 @@ import ( "time" "github.com/davecgh/go-spew/spew" - "github.com/roasbeef/btcutil" + "github.com/lightningnetwork/lnd/lnwire" ) -func randInvoice(value btcutil.Amount) (*Invoice, error) { +func randInvoice(value lnwire.MilliSatoshi) (*Invoice, error) { var pre [32]byte if _, err := rand.Read(pre[:]); err != nil { @@ -48,7 +48,7 @@ func TestInvoiceWorkflow(t *testing.T) { fakeInvoice.Memo = []byte("memo") fakeInvoice.Receipt = []byte("recipt") copy(fakeInvoice.Terms.PaymentPreimage[:], rev[:]) - fakeInvoice.Terms.Value = btcutil.Amount(10000) + fakeInvoice.Terms.Value = lnwire.NewMSatFromSatoshis(10000) // Add the invoice to the database, this should suceed as there aren't // any existing invoices within the database with the same payment @@ -99,7 +99,7 @@ func TestInvoiceWorkflow(t *testing.T) { // Add 100 random invoices. const numInvoices = 10 - amt := btcutil.Amount(1000) + amt := lnwire.NewMSatFromSatoshis(1000) invoices := make([]*Invoice, numInvoices+1) invoices[0] = dbInvoice2 for i := 1; i < len(invoices)-1; i++ { diff --git a/channeldb/invoices.go b/channeldb/invoices.go index b4d68addf..1add90879 100644 --- a/channeldb/invoices.go +++ b/channeldb/invoices.go @@ -8,8 +8,8 @@ import ( "time" "github.com/boltdb/bolt" + "github.com/lightningnetwork/lnd/lnwire" "github.com/roasbeef/btcd/wire" - "github.com/roasbeef/btcutil" ) var ( @@ -54,9 +54,9 @@ type ContractTerm struct { // extended. PaymentPreimage [32]byte - // Value is the expected amount to be payed to an HTLC which can be - // satisfied by the above preimage. - Value btcutil.Amount + // Value is the expected amount of milli-satoshis to be payed to an + // HTLC which can be satisfied by the above preimage. + Value lnwire.MilliSatoshi // Settled indicates if this particular contract term has been fully // settled by the payer. @@ -376,7 +376,7 @@ func deserializeInvoice(r io.Reader) (*Invoice, error) { if _, err := io.ReadFull(r, scratch[:]); err != nil { return nil, err } - invoice.Terms.Value = btcutil.Amount(byteOrder.Uint64(scratch[:])) + invoice.Terms.Value = lnwire.MilliSatoshi(byteOrder.Uint64(scratch[:])) var settleByte [1]byte if _, err := io.ReadFull(r, settleByte[:]); err != nil { @@ -402,5 +402,7 @@ func settleInvoice(invoices *bolt.Bucket, invoiceNum []byte) error { return nil } + // TODO(roasbeef): add timestamp + return invoices.Put(invoiceNum[:], buf.Bytes()) }