channeldb: update the Invoice struct to use lnwire.MilliSatoshi
This commit is contained in:
parent
063525c6e0
commit
251f8d650f
@ -8,10 +8,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"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
|
var pre [32]byte
|
||||||
if _, err := rand.Read(pre[:]); err != nil {
|
if _, err := rand.Read(pre[:]); err != nil {
|
||||||
@ -48,7 +48,7 @@ func TestInvoiceWorkflow(t *testing.T) {
|
|||||||
fakeInvoice.Memo = []byte("memo")
|
fakeInvoice.Memo = []byte("memo")
|
||||||
fakeInvoice.Receipt = []byte("recipt")
|
fakeInvoice.Receipt = []byte("recipt")
|
||||||
copy(fakeInvoice.Terms.PaymentPreimage[:], rev[:])
|
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
|
// Add the invoice to the database, this should suceed as there aren't
|
||||||
// any existing invoices within the database with the same payment
|
// any existing invoices within the database with the same payment
|
||||||
@ -99,7 +99,7 @@ func TestInvoiceWorkflow(t *testing.T) {
|
|||||||
|
|
||||||
// Add 100 random invoices.
|
// Add 100 random invoices.
|
||||||
const numInvoices = 10
|
const numInvoices = 10
|
||||||
amt := btcutil.Amount(1000)
|
amt := lnwire.NewMSatFromSatoshis(1000)
|
||||||
invoices := make([]*Invoice, numInvoices+1)
|
invoices := make([]*Invoice, numInvoices+1)
|
||||||
invoices[0] = dbInvoice2
|
invoices[0] = dbInvoice2
|
||||||
for i := 1; i < len(invoices)-1; i++ {
|
for i := 1; i < len(invoices)-1; i++ {
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
"github.com/boltdb/bolt"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/roasbeef/btcd/wire"
|
"github.com/roasbeef/btcd/wire"
|
||||||
"github.com/roasbeef/btcutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -54,9 +54,9 @@ type ContractTerm struct {
|
|||||||
// extended.
|
// extended.
|
||||||
PaymentPreimage [32]byte
|
PaymentPreimage [32]byte
|
||||||
|
|
||||||
// Value is the expected amount to be payed to an HTLC which can be
|
// Value is the expected amount of milli-satoshis to be payed to an
|
||||||
// satisfied by the above preimage.
|
// HTLC which can be satisfied by the above preimage.
|
||||||
Value btcutil.Amount
|
Value lnwire.MilliSatoshi
|
||||||
|
|
||||||
// Settled indicates if this particular contract term has been fully
|
// Settled indicates if this particular contract term has been fully
|
||||||
// settled by the payer.
|
// settled by the payer.
|
||||||
@ -376,7 +376,7 @@ func deserializeInvoice(r io.Reader) (*Invoice, error) {
|
|||||||
if _, err := io.ReadFull(r, scratch[:]); err != nil {
|
if _, err := io.ReadFull(r, scratch[:]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
invoice.Terms.Value = btcutil.Amount(byteOrder.Uint64(scratch[:]))
|
invoice.Terms.Value = lnwire.MilliSatoshi(byteOrder.Uint64(scratch[:]))
|
||||||
|
|
||||||
var settleByte [1]byte
|
var settleByte [1]byte
|
||||||
if _, err := io.ReadFull(r, settleByte[:]); err != nil {
|
if _, err := io.ReadFull(r, settleByte[:]); err != nil {
|
||||||
@ -402,5 +402,7 @@ func settleInvoice(invoices *bolt.Bucket, invoiceNum []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(roasbeef): add timestamp
|
||||||
|
|
||||||
return invoices.Put(invoiceNum[:], buf.Bytes())
|
return invoices.Put(invoiceNum[:], buf.Bytes())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user