channeldb: update the Invoice struct to use lnwire.MilliSatoshi

This commit is contained in:
Olaoluwa Osuntokun 2017-08-21 22:51:19 -07:00
parent 063525c6e0
commit 251f8d650f
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 11 additions and 9 deletions

@ -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++ {

@ -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())
}