mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-02 03:54:26 +02:00
lnwire: add ChannelUpdate2
Add the new ChannelUpdate2 message and ensure that it implements the ChannelUpdate interface.
This commit is contained in:
@@ -2,8 +2,10 @@ package lnwire
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -49,3 +51,40 @@ func (m MilliSatoshi) String() string {
|
||||
}
|
||||
|
||||
// TODO(roasbeef): extend with arithmetic operations?
|
||||
|
||||
// Record returns a TLV record that can be used to encode/decode a MilliSatoshi
|
||||
// to/from a TLV stream.
|
||||
func (m *MilliSatoshi) Record() tlv.Record {
|
||||
return tlv.MakeDynamicRecord(
|
||||
0, m, tlv.SizeBigSize(m), encodeMilliSatoshis,
|
||||
decodeMilliSatoshis,
|
||||
)
|
||||
}
|
||||
|
||||
func encodeMilliSatoshis(w io.Writer, val interface{}, buf *[8]byte) error {
|
||||
if v, ok := val.(*MilliSatoshi); ok {
|
||||
bigSize := uint64(*v)
|
||||
|
||||
return tlv.EBigSize(w, &bigSize, buf)
|
||||
}
|
||||
|
||||
return tlv.NewTypeForEncodingErr(val, "lnwire.MilliSatoshi")
|
||||
}
|
||||
|
||||
func decodeMilliSatoshis(r io.Reader, val interface{}, buf *[8]byte,
|
||||
l uint64) error {
|
||||
|
||||
if v, ok := val.(*MilliSatoshi); ok {
|
||||
var bigSize uint64
|
||||
err := tlv.DBigSize(r, &bigSize, buf, l)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*v = MilliSatoshi(bigSize)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return tlv.NewTypeForDecodingErr(val, "lnwire.MilliSatoshi", l, l)
|
||||
}
|
||||
|
Reference in New Issue
Block a user