mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-03-13 11:55:05 +00:00
BIP0144+wire: add a MessageEncoding variant for serialization/deserialization
This commit modifies the existing wire.Message interface to introduce a new MessageEncoding variant which dictates the exact encoding to be used when serializing and deserializing messages. Such an option is now necessary due to the segwit soft-fork package, as btcd will need to be able to optionally encode transactions/blocks without witness data to un-upgraded peers. Two new functions have been introduced: ReadMessageWithEncodingN and WriteMessageWithEncodingN which wrap BtcDecode/BtcEncode with the desired encoding format.
This commit is contained in:
committed by
Dave Collins
parent
1b359e1131
commit
48abfdf87c
@@ -79,10 +79,11 @@ func TestBlockHeaderWire(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
in *BlockHeader // Data to encode
|
||||
out *BlockHeader // Expected decoded data
|
||||
buf []byte // Wire encoding
|
||||
pver uint32 // Protocol version for wire encoding
|
||||
in *BlockHeader // Data to encode
|
||||
out *BlockHeader // Expected decoded data
|
||||
buf []byte // Wire encoding
|
||||
pver uint32 // Protocol version for wire encoding
|
||||
enc MessageEncoding // Message encoding variant to use
|
||||
}{
|
||||
// Latest protocol version.
|
||||
{
|
||||
@@ -90,6 +91,7 @@ func TestBlockHeaderWire(t *testing.T) {
|
||||
baseBlockHdr,
|
||||
baseBlockHdrEncoded,
|
||||
ProtocolVersion,
|
||||
BaseEncoding,
|
||||
},
|
||||
|
||||
// Protocol version BIP0035Version.
|
||||
@@ -98,6 +100,7 @@ func TestBlockHeaderWire(t *testing.T) {
|
||||
baseBlockHdr,
|
||||
baseBlockHdrEncoded,
|
||||
BIP0035Version,
|
||||
BaseEncoding,
|
||||
},
|
||||
|
||||
// Protocol version BIP0031Version.
|
||||
@@ -106,6 +109,7 @@ func TestBlockHeaderWire(t *testing.T) {
|
||||
baseBlockHdr,
|
||||
baseBlockHdrEncoded,
|
||||
BIP0031Version,
|
||||
BaseEncoding,
|
||||
},
|
||||
|
||||
// Protocol version NetAddressTimeVersion.
|
||||
@@ -114,6 +118,7 @@ func TestBlockHeaderWire(t *testing.T) {
|
||||
baseBlockHdr,
|
||||
baseBlockHdrEncoded,
|
||||
NetAddressTimeVersion,
|
||||
BaseEncoding,
|
||||
},
|
||||
|
||||
// Protocol version MultipleAddressVersion.
|
||||
@@ -122,6 +127,7 @@ func TestBlockHeaderWire(t *testing.T) {
|
||||
baseBlockHdr,
|
||||
baseBlockHdrEncoded,
|
||||
MultipleAddressVersion,
|
||||
BaseEncoding,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -141,7 +147,7 @@ func TestBlockHeaderWire(t *testing.T) {
|
||||
}
|
||||
|
||||
buf.Reset()
|
||||
err = test.in.BtcEncode(&buf, pver)
|
||||
err = test.in.BtcEncode(&buf, pver, 0)
|
||||
if err != nil {
|
||||
t.Errorf("BtcEncode #%d error %v", i, err)
|
||||
continue
|
||||
@@ -167,7 +173,7 @@ func TestBlockHeaderWire(t *testing.T) {
|
||||
}
|
||||
|
||||
rbuf = bytes.NewReader(test.buf)
|
||||
err = bh.BtcDecode(rbuf, pver)
|
||||
err = bh.BtcDecode(rbuf, pver, test.enc)
|
||||
if err != nil {
|
||||
t.Errorf("BtcDecode #%d error %v", i, err)
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user