mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 09:50:08 +01:00
Deprecate InvVect_* constants in favor of InvType*.
This commit changes the InvVect_* constants, which are not standard Go style, to the InvType*. In order to preserve backwards compatibility, it also adds a legacy.go file which maps the old public constant names to the new ones. Closes #1.
This commit is contained in:
parent
95ecbadb8e
commit
93d86305a2
12
invvect.go
12
invvect.go
@ -23,16 +23,16 @@ type InvType uint32
|
||||
|
||||
// These constants define the various supported inventory vector types.
|
||||
const (
|
||||
InvVect_Error InvType = 0
|
||||
InvVect_Tx InvType = 1
|
||||
InvVect_Block InvType = 2
|
||||
InvTypeError InvType = 0
|
||||
InvTypeTx InvType = 1
|
||||
InvTypeBlock InvType = 2
|
||||
)
|
||||
|
||||
// Map of service flags back to their constant names for pretty printing.
|
||||
var ivStrings = map[InvType]string{
|
||||
InvVect_Error: "ERROR",
|
||||
InvVect_Tx: "MSG_TX",
|
||||
InvVect_Block: "MSG_BLOCK",
|
||||
InvTypeError: "ERROR",
|
||||
InvTypeTx: "MSG_TX",
|
||||
InvTypeBlock: "MSG_BLOCK",
|
||||
}
|
||||
|
||||
// String returns the InvType in human-readable form.
|
||||
|
@ -18,9 +18,9 @@ func TestInvTypeStringer(t *testing.T) {
|
||||
in btcwire.InvType
|
||||
want string
|
||||
}{
|
||||
{btcwire.InvVect_Error, "ERROR"},
|
||||
{btcwire.InvVect_Tx, "MSG_TX"},
|
||||
{btcwire.InvVect_Block, "MSG_BLOCK"},
|
||||
{btcwire.InvTypeError, "ERROR"},
|
||||
{btcwire.InvTypeTx, "MSG_TX"},
|
||||
{btcwire.InvTypeBlock, "MSG_BLOCK"},
|
||||
{0xffffffff, "Unknown InvType (4294967295)"},
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ func TestInvTypeStringer(t *testing.T) {
|
||||
|
||||
// TestInvVect tests the InvVect API.
|
||||
func TestInvVect(t *testing.T) {
|
||||
ivType := btcwire.InvVect_Block
|
||||
ivType := btcwire.InvTypeBlock
|
||||
hash := btcwire.ShaHash{}
|
||||
|
||||
// Ensure we get the same payload and signature back out.
|
||||
@ -66,13 +66,13 @@ func TestInvVectWire(t *testing.T) {
|
||||
|
||||
// errInvVect is an inventory vector with an error.
|
||||
errInvVect := btcwire.InvVect{
|
||||
Type: btcwire.InvVect_Error,
|
||||
Type: btcwire.InvTypeError,
|
||||
Hash: btcwire.ShaHash{},
|
||||
}
|
||||
|
||||
// errInvVectEncoded is the wire encoded bytes of errInvVect.
|
||||
errInvVectEncoded := []byte{
|
||||
0x00, 0x00, 0x00, 0x00, // InvVect_Error
|
||||
0x00, 0x00, 0x00, 0x00, // InvTypeError
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
@ -81,13 +81,13 @@ func TestInvVectWire(t *testing.T) {
|
||||
|
||||
// txInvVect is an inventory vector representing a transaction.
|
||||
txInvVect := btcwire.InvVect{
|
||||
Type: btcwire.InvVect_Tx,
|
||||
Type: btcwire.InvTypeTx,
|
||||
Hash: *baseHash,
|
||||
}
|
||||
|
||||
// txInvVectEncoded is the wire encoded bytes of txInvVect.
|
||||
txInvVectEncoded := []byte{
|
||||
0x01, 0x00, 0x00, 0x00, // InvVect_Tx
|
||||
0x01, 0x00, 0x00, 0x00, // InvTypeTx
|
||||
0xdc, 0xe9, 0x69, 0x10, 0x94, 0xda, 0x23, 0xc7,
|
||||
0xe7, 0x67, 0x13, 0xd0, 0x75, 0xd4, 0xa1, 0x0b,
|
||||
0x79, 0x40, 0x08, 0xa6, 0x36, 0xac, 0xc2, 0x4b,
|
||||
@ -96,13 +96,13 @@ func TestInvVectWire(t *testing.T) {
|
||||
|
||||
// blockInvVect is an inventory vector representing a block.
|
||||
blockInvVect := btcwire.InvVect{
|
||||
Type: btcwire.InvVect_Block,
|
||||
Type: btcwire.InvTypeBlock,
|
||||
Hash: *baseHash,
|
||||
}
|
||||
|
||||
// blockInvVectEncoded is the wire encoded bytes of blockInvVect.
|
||||
blockInvVectEncoded := []byte{
|
||||
0x02, 0x00, 0x00, 0x00, // InvVect_Block
|
||||
0x02, 0x00, 0x00, 0x00, // InvTypeBlock
|
||||
0xdc, 0xe9, 0x69, 0x10, 0x94, 0xda, 0x23, 0xc7,
|
||||
0xe7, 0x67, 0x13, 0xd0, 0x75, 0xd4, 0xa1, 0x0b,
|
||||
0x79, 0x40, 0x08, 0xa6, 0x36, 0xac, 0xc2, 0x4b,
|
||||
|
14
legacy.go
Normal file
14
legacy.go
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2013 Conformal Systems LLC.
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package btcwire
|
||||
|
||||
// These constants are deprecated as they do not follow the standard Go style
|
||||
// guidelines and are only provided for backwards compatibility. Use the
|
||||
// InvType* constants instead.
|
||||
const (
|
||||
InvVect_Error InvType = InvTypeError
|
||||
InvVect_Tx InvType = InvTypeTx
|
||||
InvVect_Block InvType = InvTypeBlock
|
||||
)
|
@ -37,7 +37,7 @@ func TestGetData(t *testing.T) {
|
||||
|
||||
// Ensure inventory vectors are added properly.
|
||||
hash := btcwire.ShaHash{}
|
||||
iv := btcwire.NewInvVect(btcwire.InvVect_Block, &hash)
|
||||
iv := btcwire.NewInvVect(btcwire.InvTypeBlock, &hash)
|
||||
err := msg.AddInvVect(iv)
|
||||
if err != nil {
|
||||
t.Errorf("AddInvVect: %v", err)
|
||||
@ -77,8 +77,8 @@ func TestGetDataWire(t *testing.T) {
|
||||
t.Errorf("NewShaHashFromStr: %v", err)
|
||||
}
|
||||
|
||||
iv := btcwire.NewInvVect(btcwire.InvVect_Block, blockHash)
|
||||
iv2 := btcwire.NewInvVect(btcwire.InvVect_Tx, txHash)
|
||||
iv := btcwire.NewInvVect(btcwire.InvTypeBlock, blockHash)
|
||||
iv2 := btcwire.NewInvVect(btcwire.InvTypeTx, txHash)
|
||||
|
||||
// Empty MsgGetData message.
|
||||
NoInv := btcwire.NewMsgGetData()
|
||||
@ -92,12 +92,12 @@ func TestGetDataWire(t *testing.T) {
|
||||
MultiInv.AddInvVect(iv2)
|
||||
MultiInvEncoded := []byte{
|
||||
0x02, // Varint for number of inv vectors
|
||||
0x02, 0x00, 0x00, 0x00, // InvVect_Block
|
||||
0x02, 0x00, 0x00, 0x00, // InvTypeBlock
|
||||
0xdc, 0xe9, 0x69, 0x10, 0x94, 0xda, 0x23, 0xc7,
|
||||
0xe7, 0x67, 0x13, 0xd0, 0x75, 0xd4, 0xa1, 0x0b,
|
||||
0x79, 0x40, 0x08, 0xa6, 0x36, 0xac, 0xc2, 0x4b,
|
||||
0x26, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Block 203707 hash
|
||||
0x01, 0x00, 0x00, 0x00, // InvVect_Tx
|
||||
0x01, 0x00, 0x00, 0x00, // InvTypeTx
|
||||
0xf0, 0xfa, 0xcc, 0x7a, 0x48, 0x1b, 0xe7, 0xcf,
|
||||
0x42, 0xbd, 0x7f, 0xe5, 0x4f, 0x2c, 0x2a, 0xf8,
|
||||
0xef, 0x81, 0x9a, 0xdd, 0x93, 0xee, 0x55, 0x98,
|
||||
@ -235,14 +235,14 @@ func TestGetDataWireErrors(t *testing.T) {
|
||||
t.Errorf("NewShaHashFromStr: %v", err)
|
||||
}
|
||||
|
||||
iv := btcwire.NewInvVect(btcwire.InvVect_Block, blockHash)
|
||||
iv := btcwire.NewInvVect(btcwire.InvTypeBlock, blockHash)
|
||||
|
||||
// Base message used to induce errors.
|
||||
baseGetData := btcwire.NewMsgGetData()
|
||||
baseGetData.AddInvVect(iv)
|
||||
baseGetDataEncoded := []byte{
|
||||
0x02, // Varint for number of inv vectors
|
||||
0x02, 0x00, 0x00, 0x00, // InvVect_Block
|
||||
0x02, 0x00, 0x00, 0x00, // InvTypeBlock
|
||||
0xdc, 0xe9, 0x69, 0x10, 0x94, 0xda, 0x23, 0xc7,
|
||||
0xe7, 0x67, 0x13, 0xd0, 0x75, 0xd4, 0xa1, 0x0b,
|
||||
0x79, 0x40, 0x08, 0xa6, 0x36, 0xac, 0xc2, 0x4b,
|
||||
|
@ -37,7 +37,7 @@ func TestInv(t *testing.T) {
|
||||
|
||||
// Ensure inventory vectors are added properly.
|
||||
hash := btcwire.ShaHash{}
|
||||
iv := btcwire.NewInvVect(btcwire.InvVect_Block, &hash)
|
||||
iv := btcwire.NewInvVect(btcwire.InvTypeBlock, &hash)
|
||||
err := msg.AddInvVect(iv)
|
||||
if err != nil {
|
||||
t.Errorf("AddInvVect: %v", err)
|
||||
@ -77,8 +77,8 @@ func TestInvWire(t *testing.T) {
|
||||
t.Errorf("NewShaHashFromStr: %v", err)
|
||||
}
|
||||
|
||||
iv := btcwire.NewInvVect(btcwire.InvVect_Block, blockHash)
|
||||
iv2 := btcwire.NewInvVect(btcwire.InvVect_Tx, txHash)
|
||||
iv := btcwire.NewInvVect(btcwire.InvTypeBlock, blockHash)
|
||||
iv2 := btcwire.NewInvVect(btcwire.InvTypeTx, txHash)
|
||||
|
||||
// Empty inv message.
|
||||
NoInv := btcwire.NewMsgInv()
|
||||
@ -92,12 +92,12 @@ func TestInvWire(t *testing.T) {
|
||||
MultiInv.AddInvVect(iv2)
|
||||
MultiInvEncoded := []byte{
|
||||
0x02, // Varint for number of inv vectors
|
||||
0x02, 0x00, 0x00, 0x00, // InvVect_Block
|
||||
0x02, 0x00, 0x00, 0x00, // InvTypeBlock
|
||||
0xdc, 0xe9, 0x69, 0x10, 0x94, 0xda, 0x23, 0xc7,
|
||||
0xe7, 0x67, 0x13, 0xd0, 0x75, 0xd4, 0xa1, 0x0b,
|
||||
0x79, 0x40, 0x08, 0xa6, 0x36, 0xac, 0xc2, 0x4b,
|
||||
0x26, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Block 203707 hash
|
||||
0x01, 0x00, 0x00, 0x00, // InvVect_Tx
|
||||
0x01, 0x00, 0x00, 0x00, // InvTypeTx
|
||||
0xf0, 0xfa, 0xcc, 0x7a, 0x48, 0x1b, 0xe7, 0xcf,
|
||||
0x42, 0xbd, 0x7f, 0xe5, 0x4f, 0x2c, 0x2a, 0xf8,
|
||||
0xef, 0x81, 0x9a, 0xdd, 0x93, 0xee, 0x55, 0x98,
|
||||
@ -235,14 +235,14 @@ func TestInvWireErrors(t *testing.T) {
|
||||
t.Errorf("NewShaHashFromStr: %v", err)
|
||||
}
|
||||
|
||||
iv := btcwire.NewInvVect(btcwire.InvVect_Block, blockHash)
|
||||
iv := btcwire.NewInvVect(btcwire.InvTypeBlock, blockHash)
|
||||
|
||||
// Base inv message used to induce errors.
|
||||
baseInv := btcwire.NewMsgInv()
|
||||
baseInv.AddInvVect(iv)
|
||||
baseInvEncoded := []byte{
|
||||
0x02, // Varint for number of inv vectors
|
||||
0x02, 0x00, 0x00, 0x00, // InvVect_Block
|
||||
0x02, 0x00, 0x00, 0x00, // InvTypeBlock
|
||||
0xdc, 0xe9, 0x69, 0x10, 0x94, 0xda, 0x23, 0xc7,
|
||||
0xe7, 0x67, 0x13, 0xd0, 0x75, 0xd4, 0xa1, 0x0b,
|
||||
0x79, 0x40, 0x08, 0xa6, 0x36, 0xac, 0xc2, 0x4b,
|
||||
|
@ -37,7 +37,7 @@ func TestNotFound(t *testing.T) {
|
||||
|
||||
// Ensure inventory vectors are added properly.
|
||||
hash := btcwire.ShaHash{}
|
||||
iv := btcwire.NewInvVect(btcwire.InvVect_Block, &hash)
|
||||
iv := btcwire.NewInvVect(btcwire.InvTypeBlock, &hash)
|
||||
err := msg.AddInvVect(iv)
|
||||
if err != nil {
|
||||
t.Errorf("AddInvVect: %v", err)
|
||||
@ -77,8 +77,8 @@ func TestNotFoundWire(t *testing.T) {
|
||||
t.Errorf("NewShaHashFromStr: %v", err)
|
||||
}
|
||||
|
||||
iv := btcwire.NewInvVect(btcwire.InvVect_Block, blockHash)
|
||||
iv2 := btcwire.NewInvVect(btcwire.InvVect_Tx, txHash)
|
||||
iv := btcwire.NewInvVect(btcwire.InvTypeBlock, blockHash)
|
||||
iv2 := btcwire.NewInvVect(btcwire.InvTypeTx, txHash)
|
||||
|
||||
// Empty notfound message.
|
||||
NoInv := btcwire.NewMsgNotFound()
|
||||
@ -92,12 +92,12 @@ func TestNotFoundWire(t *testing.T) {
|
||||
MultiInv.AddInvVect(iv2)
|
||||
MultiInvEncoded := []byte{
|
||||
0x02, // Varint for number of inv vectors
|
||||
0x02, 0x00, 0x00, 0x00, // InvVect_Block
|
||||
0x02, 0x00, 0x00, 0x00, // InvTypeBlock
|
||||
0xdc, 0xe9, 0x69, 0x10, 0x94, 0xda, 0x23, 0xc7,
|
||||
0xe7, 0x67, 0x13, 0xd0, 0x75, 0xd4, 0xa1, 0x0b,
|
||||
0x79, 0x40, 0x08, 0xa6, 0x36, 0xac, 0xc2, 0x4b,
|
||||
0x26, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Block 203707 hash
|
||||
0x01, 0x00, 0x00, 0x00, // InvVect_Tx
|
||||
0x01, 0x00, 0x00, 0x00, // InvTypeTx
|
||||
0xf0, 0xfa, 0xcc, 0x7a, 0x48, 0x1b, 0xe7, 0xcf,
|
||||
0x42, 0xbd, 0x7f, 0xe5, 0x4f, 0x2c, 0x2a, 0xf8,
|
||||
0xef, 0x81, 0x9a, 0xdd, 0x93, 0xee, 0x55, 0x98,
|
||||
@ -235,14 +235,14 @@ func TestNotFoundWireErrors(t *testing.T) {
|
||||
t.Errorf("NewShaHashFromStr: %v", err)
|
||||
}
|
||||
|
||||
iv := btcwire.NewInvVect(btcwire.InvVect_Block, blockHash)
|
||||
iv := btcwire.NewInvVect(btcwire.InvTypeBlock, blockHash)
|
||||
|
||||
// Base message used to induce errors.
|
||||
baseNotFound := btcwire.NewMsgNotFound()
|
||||
baseNotFound.AddInvVect(iv)
|
||||
baseNotFoundEncoded := []byte{
|
||||
0x02, // Varint for number of inv vectors
|
||||
0x02, 0x00, 0x00, 0x00, // InvVect_Block
|
||||
0x02, 0x00, 0x00, 0x00, // InvTypeBlock
|
||||
0xdc, 0xe9, 0x69, 0x10, 0x94, 0xda, 0x23, 0xc7,
|
||||
0xe7, 0x67, 0x13, 0xd0, 0x75, 0xd4, 0xa1, 0x0b,
|
||||
0x79, 0x40, 0x08, 0xa6, 0x36, 0xac, 0xc2, 0x4b,
|
||||
|
Loading…
Reference in New Issue
Block a user