channeldb: use binary.Read/Write in invoices.go
Use binary.Read/Write in when reading and writing booleans in functions to serialize and deserialize invoices.
This commit is contained in:
parent
156772d04a
commit
3f6a58f967
@ -3,6 +3,7 @@ package channeldb
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
@ -343,11 +344,7 @@ func serializeInvoice(w io.Writer, i *Invoice) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var settleByte [1]byte
|
if err := binary.Write(w, byteOrder, i.Terms.Settled); err != nil {
|
||||||
if i.Terms.Settled {
|
|
||||||
settleByte[0] = 1
|
|
||||||
}
|
|
||||||
if _, err := w.Write(settleByte[:]); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,13 +398,9 @@ func deserializeInvoice(r io.Reader) (*Invoice, error) {
|
|||||||
}
|
}
|
||||||
invoice.Terms.Value = lnwire.MilliSatoshi(byteOrder.Uint64(scratch[:]))
|
invoice.Terms.Value = lnwire.MilliSatoshi(byteOrder.Uint64(scratch[:]))
|
||||||
|
|
||||||
var settleByte [1]byte
|
if err := binary.Read(r, byteOrder, &invoice.Terms.Settled); err != nil {
|
||||||
if _, err := io.ReadFull(r, settleByte[:]); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if settleByte[0] == 1 {
|
|
||||||
invoice.Terms.Settled = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return invoice, nil
|
return invoice, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user