wire: Export (read|write)(VarInt|VarBytes).
This commit is contained in:
parent
f4d551c08d
commit
c17ff82061
18 changed files with 91 additions and 91 deletions
|
@ -118,7 +118,7 @@ var blockOne = MsgBlock{
|
|||
// a single byte variable length integer.
|
||||
func BenchmarkWriteVarInt1(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
writeVarInt(ioutil.Discard, 0, 1)
|
||||
WriteVarInt(ioutil.Discard, 0, 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ func BenchmarkWriteVarInt1(b *testing.B) {
|
|||
// a three byte variable length integer.
|
||||
func BenchmarkWriteVarInt3(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
writeVarInt(ioutil.Discard, 0, 65535)
|
||||
WriteVarInt(ioutil.Discard, 0, 65535)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ func BenchmarkWriteVarInt3(b *testing.B) {
|
|||
// a five byte variable length integer.
|
||||
func BenchmarkWriteVarInt5(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
writeVarInt(ioutil.Discard, 0, 4294967295)
|
||||
WriteVarInt(ioutil.Discard, 0, 4294967295)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ func BenchmarkWriteVarInt5(b *testing.B) {
|
|||
// a nine byte variable length integer.
|
||||
func BenchmarkWriteVarInt9(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
writeVarInt(ioutil.Discard, 0, 18446744073709551615)
|
||||
WriteVarInt(ioutil.Discard, 0, 18446744073709551615)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ func BenchmarkWriteVarInt9(b *testing.B) {
|
|||
func BenchmarkReadVarInt1(b *testing.B) {
|
||||
buf := []byte{0x01}
|
||||
for i := 0; i < b.N; i++ {
|
||||
readVarInt(bytes.NewReader(buf), 0)
|
||||
ReadVarInt(bytes.NewReader(buf), 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ func BenchmarkReadVarInt1(b *testing.B) {
|
|||
func BenchmarkReadVarInt3(b *testing.B) {
|
||||
buf := []byte{0x0fd, 0xff, 0xff}
|
||||
for i := 0; i < b.N; i++ {
|
||||
readVarInt(bytes.NewReader(buf), 0)
|
||||
ReadVarInt(bytes.NewReader(buf), 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ func BenchmarkReadVarInt3(b *testing.B) {
|
|||
func BenchmarkReadVarInt5(b *testing.B) {
|
||||
buf := []byte{0xfe, 0xff, 0xff, 0xff, 0xff}
|
||||
for i := 0; i < b.N; i++ {
|
||||
readVarInt(bytes.NewReader(buf), 0)
|
||||
ReadVarInt(bytes.NewReader(buf), 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ func BenchmarkReadVarInt5(b *testing.B) {
|
|||
func BenchmarkReadVarInt9(b *testing.B) {
|
||||
buf := []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
|
||||
for i := 0; i < b.N; i++ {
|
||||
readVarInt(bytes.NewReader(buf), 0)
|
||||
ReadVarInt(bytes.NewReader(buf), 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -323,8 +323,8 @@ func writeElements(w io.Writer, elements ...interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// readVarInt reads a variable length integer from r and returns it as a uint64.
|
||||
func readVarInt(r io.Reader, pver uint32) (uint64, error) {
|
||||
// ReadVarInt reads a variable length integer from r and returns it as a uint64.
|
||||
func ReadVarInt(r io.Reader, pver uint32) (uint64, error) {
|
||||
var b [8]byte
|
||||
_, err := io.ReadFull(r, b[0:1])
|
||||
if err != nil {
|
||||
|
@ -345,7 +345,7 @@ func readVarInt(r io.Reader, pver uint32) (uint64, error) {
|
|||
// encoded using fewer bytes.
|
||||
min := uint64(0x100000000)
|
||||
if rv < min {
|
||||
return 0, messageError("readVarInt", fmt.Sprintf(
|
||||
return 0, messageError("ReadVarInt", fmt.Sprintf(
|
||||
errNonCanonicalVarInt, rv, discriminant, min))
|
||||
}
|
||||
|
||||
|
@ -360,7 +360,7 @@ func readVarInt(r io.Reader, pver uint32) (uint64, error) {
|
|||
// encoded using fewer bytes.
|
||||
min := uint64(0x10000)
|
||||
if rv < min {
|
||||
return 0, messageError("readVarInt", fmt.Sprintf(
|
||||
return 0, messageError("ReadVarInt", fmt.Sprintf(
|
||||
errNonCanonicalVarInt, rv, discriminant, min))
|
||||
}
|
||||
|
||||
|
@ -375,7 +375,7 @@ func readVarInt(r io.Reader, pver uint32) (uint64, error) {
|
|||
// encoded using fewer bytes.
|
||||
min := uint64(0xfd)
|
||||
if rv < min {
|
||||
return 0, messageError("readVarInt", fmt.Sprintf(
|
||||
return 0, messageError("ReadVarInt", fmt.Sprintf(
|
||||
errNonCanonicalVarInt, rv, discriminant, min))
|
||||
}
|
||||
|
||||
|
@ -386,9 +386,9 @@ func readVarInt(r io.Reader, pver uint32) (uint64, error) {
|
|||
return rv, nil
|
||||
}
|
||||
|
||||
// writeVarInt serializes val to w using a variable number of bytes depending
|
||||
// WriteVarInt serializes val to w using a variable number of bytes depending
|
||||
// on its value.
|
||||
func writeVarInt(w io.Writer, pver uint32, val uint64) error {
|
||||
func WriteVarInt(w io.Writer, pver uint32, val uint64) error {
|
||||
if val < 0xfd {
|
||||
_, err := w.Write([]byte{uint8(val)})
|
||||
return err
|
||||
|
@ -447,7 +447,7 @@ func VarIntSerializeSize(val uint64) int {
|
|||
// maximum block payload size since it helps protect against memory exhaustion
|
||||
// attacks and forced panics through malformed messages.
|
||||
func ReadVarString(r io.Reader, pver uint32) (string, error) {
|
||||
count, err := readVarInt(r, pver)
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -473,7 +473,7 @@ func ReadVarString(r io.Reader, pver uint32) (string, error) {
|
|||
// the length of the string followed by the bytes that represent the string
|
||||
// itself.
|
||||
func WriteVarString(w io.Writer, pver uint32, str string) error {
|
||||
err := writeVarInt(w, pver, uint64(len(str)))
|
||||
err := WriteVarInt(w, pver, uint64(len(str)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -484,17 +484,17 @@ func WriteVarString(w io.Writer, pver uint32, str string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// readVarBytes reads a variable length byte array. A byte array is encoded
|
||||
// ReadVarBytes reads a variable length byte array. A byte array is encoded
|
||||
// as a varInt containing the length of the array followed by the bytes
|
||||
// themselves. An error is returned if the length is greater than the
|
||||
// passed maxAllowed parameter which helps protect against memory exhuastion
|
||||
// attacks and forced panics thorugh malformed messages. The fieldName
|
||||
// parameter is only used for the error message so it provides more context in
|
||||
// the error.
|
||||
func readVarBytes(r io.Reader, pver uint32, maxAllowed uint32,
|
||||
func ReadVarBytes(r io.Reader, pver uint32, maxAllowed uint32,
|
||||
fieldName string) ([]byte, error) {
|
||||
|
||||
count, err := readVarInt(r, pver)
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ func readVarBytes(r io.Reader, pver uint32, maxAllowed uint32,
|
|||
if count > uint64(maxAllowed) {
|
||||
str := fmt.Sprintf("%s is larger than the max allowed size "+
|
||||
"[count %d, max %d]", fieldName, count, maxAllowed)
|
||||
return nil, messageError("readVarBytes", str)
|
||||
return nil, messageError("ReadVarBytes", str)
|
||||
}
|
||||
|
||||
b := make([]byte, count)
|
||||
|
@ -516,11 +516,11 @@ func readVarBytes(r io.Reader, pver uint32, maxAllowed uint32,
|
|||
return b, nil
|
||||
}
|
||||
|
||||
// writeVarInt serializes a variable length byte array to w as a varInt
|
||||
// WriteVarBytes serializes a variable length byte array to w as a varInt
|
||||
// containing the number of bytes, followed by the bytes themselves.
|
||||
func writeVarBytes(w io.Writer, pver uint32, bytes []byte) error {
|
||||
func WriteVarBytes(w io.Writer, pver uint32, bytes []byte) error {
|
||||
slen := uint64(len(bytes))
|
||||
err := writeVarInt(w, pver, slen)
|
||||
err := WriteVarInt(w, pver, slen)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -285,11 +285,11 @@ func TestVarIntWire(t *testing.T) {
|
|||
var buf bytes.Buffer
|
||||
err := wire.TstWriteVarInt(&buf, test.pver, test.in)
|
||||
if err != nil {
|
||||
t.Errorf("writeVarInt #%d error %v", i, err)
|
||||
t.Errorf("WriteVarInt #%d error %v", i, err)
|
||||
continue
|
||||
}
|
||||
if !bytes.Equal(buf.Bytes(), test.buf) {
|
||||
t.Errorf("writeVarInt #%d\n got: %s want: %s", i,
|
||||
t.Errorf("WriteVarInt #%d\n got: %s want: %s", i,
|
||||
spew.Sdump(buf.Bytes()), spew.Sdump(test.buf))
|
||||
continue
|
||||
}
|
||||
|
@ -298,11 +298,11 @@ func TestVarIntWire(t *testing.T) {
|
|||
rbuf := bytes.NewReader(test.buf)
|
||||
val, err := wire.TstReadVarInt(rbuf, test.pver)
|
||||
if err != nil {
|
||||
t.Errorf("readVarInt #%d error %v", i, err)
|
||||
t.Errorf("ReadVarInt #%d error %v", i, err)
|
||||
continue
|
||||
}
|
||||
if val != test.out {
|
||||
t.Errorf("readVarInt #%d\n got: %d want: %d", i,
|
||||
t.Errorf("ReadVarInt #%d\n got: %d want: %d", i,
|
||||
val, test.out)
|
||||
continue
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ func TestVarIntWireErrors(t *testing.T) {
|
|||
w := newFixedWriter(test.max)
|
||||
err := wire.TstWriteVarInt(w, test.pver, test.in)
|
||||
if err != test.writeErr {
|
||||
t.Errorf("writeVarInt #%d wrong error got: %v, want: %v",
|
||||
t.Errorf("WriteVarInt #%d wrong error got: %v, want: %v",
|
||||
i, err, test.writeErr)
|
||||
continue
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ func TestVarIntWireErrors(t *testing.T) {
|
|||
r := newFixedReader(test.max, test.buf)
|
||||
_, err = wire.TstReadVarInt(r, test.pver)
|
||||
if err != test.readErr {
|
||||
t.Errorf("readVarInt #%d wrong error got: %v, want: %v",
|
||||
t.Errorf("ReadVarInt #%d wrong error got: %v, want: %v",
|
||||
i, err, test.readErr)
|
||||
continue
|
||||
}
|
||||
|
@ -398,12 +398,12 @@ func TestVarIntNonCanonical(t *testing.T) {
|
|||
rbuf := bytes.NewReader(test.in)
|
||||
val, err := wire.TstReadVarInt(rbuf, test.pver)
|
||||
if _, ok := err.(*wire.MessageError); !ok {
|
||||
t.Errorf("readVarInt #%d (%s) unexpected error %v", i,
|
||||
t.Errorf("ReadVarInt #%d (%s) unexpected error %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
if val != 0 {
|
||||
t.Errorf("readVarInt #%d (%s)\n got: %d want: 0", i,
|
||||
t.Errorf("ReadVarInt #%d (%s)\n got: %d want: 0", i,
|
||||
test.name, val)
|
||||
continue
|
||||
}
|
||||
|
@ -603,11 +603,11 @@ func TestVarBytesWire(t *testing.T) {
|
|||
var buf bytes.Buffer
|
||||
err := wire.TstWriteVarBytes(&buf, test.pver, test.in)
|
||||
if err != nil {
|
||||
t.Errorf("writeVarBytes #%d error %v", i, err)
|
||||
t.Errorf("WriteVarBytes #%d error %v", i, err)
|
||||
continue
|
||||
}
|
||||
if !bytes.Equal(buf.Bytes(), test.buf) {
|
||||
t.Errorf("writeVarBytes #%d\n got: %s want: %s", i,
|
||||
t.Errorf("WriteVarBytes #%d\n got: %s want: %s", i,
|
||||
spew.Sdump(buf.Bytes()), spew.Sdump(test.buf))
|
||||
continue
|
||||
}
|
||||
|
@ -617,11 +617,11 @@ func TestVarBytesWire(t *testing.T) {
|
|||
val, err := wire.TstReadVarBytes(rbuf, test.pver,
|
||||
wire.MaxMessagePayload, "test payload")
|
||||
if err != nil {
|
||||
t.Errorf("readVarBytes #%d error %v", i, err)
|
||||
t.Errorf("ReadVarBytes #%d error %v", i, err)
|
||||
continue
|
||||
}
|
||||
if !bytes.Equal(buf.Bytes(), test.buf) {
|
||||
t.Errorf("readVarBytes #%d\n got: %s want: %s", i,
|
||||
t.Errorf("ReadVarBytes #%d\n got: %s want: %s", i,
|
||||
val, test.buf)
|
||||
continue
|
||||
}
|
||||
|
@ -659,7 +659,7 @@ func TestVarBytesWireErrors(t *testing.T) {
|
|||
w := newFixedWriter(test.max)
|
||||
err := wire.TstWriteVarBytes(w, test.pver, test.in)
|
||||
if err != test.writeErr {
|
||||
t.Errorf("writeVarBytes #%d wrong error got: %v, want: %v",
|
||||
t.Errorf("WriteVarBytes #%d wrong error got: %v, want: %v",
|
||||
i, err, test.writeErr)
|
||||
continue
|
||||
}
|
||||
|
@ -669,7 +669,7 @@ func TestVarBytesWireErrors(t *testing.T) {
|
|||
_, err = wire.TstReadVarBytes(r, test.pver,
|
||||
wire.MaxMessagePayload, "test payload")
|
||||
if err != test.readErr {
|
||||
t.Errorf("readVarBytes #%d wrong error got: %v, want: %v",
|
||||
t.Errorf("ReadVarBytes #%d wrong error got: %v, want: %v",
|
||||
i, err, test.readErr)
|
||||
continue
|
||||
}
|
||||
|
@ -701,7 +701,7 @@ func TestVarBytesOverflowErrors(t *testing.T) {
|
|||
_, err := wire.TstReadVarBytes(rbuf, test.pver,
|
||||
wire.MaxMessagePayload, "test payload")
|
||||
if reflect.TypeOf(err) != reflect.TypeOf(test.err) {
|
||||
t.Errorf("readVarBytes #%d wrong error got: %v, "+
|
||||
t.Errorf("ReadVarBytes #%d wrong error got: %v, "+
|
||||
"want: %v", i, err, reflect.TypeOf(test.err))
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -51,28 +51,28 @@ func TstWriteElement(w io.Writer, element interface{}) error {
|
|||
return writeElement(w, element)
|
||||
}
|
||||
|
||||
// TstReadVarInt makes the internal readVarInt function available to the
|
||||
// TstReadVarInt makes the internal ReadVarInt function available to the
|
||||
// test package.
|
||||
func TstReadVarInt(r io.Reader, pver uint32) (uint64, error) {
|
||||
return readVarInt(r, pver)
|
||||
return ReadVarInt(r, pver)
|
||||
}
|
||||
|
||||
// TstWriteVarInt makes the internal writeVarInt function available to the
|
||||
// TstWriteVarInt makes the internal WriteVarInt function available to the
|
||||
// test package.
|
||||
func TstWriteVarInt(w io.Writer, pver uint32, val uint64) error {
|
||||
return writeVarInt(w, pver, val)
|
||||
return WriteVarInt(w, pver, val)
|
||||
}
|
||||
|
||||
// TstReadVarBytes makes the internal readVarBytes function available to the
|
||||
// TstReadVarBytes makes the internal ReadVarBytes function available to the
|
||||
// test package.
|
||||
func TstReadVarBytes(r io.Reader, pver uint32, maxAllowed uint32, fieldName string) ([]byte, error) {
|
||||
return readVarBytes(r, pver, maxAllowed, fieldName)
|
||||
return ReadVarBytes(r, pver, maxAllowed, fieldName)
|
||||
}
|
||||
|
||||
// TstWriteVarBytes makes the internal writeVarBytes function available to the
|
||||
// TstWriteVarBytes makes the internal WriteVarBytes function available to the
|
||||
// test package.
|
||||
func TstWriteVarBytes(w io.Writer, pver uint32, bytes []byte) error {
|
||||
return writeVarBytes(w, pver, bytes)
|
||||
return WriteVarBytes(w, pver, bytes)
|
||||
}
|
||||
|
||||
// TstReadNetAddress makes the internal readNetAddress function available to
|
||||
|
|
|
@ -58,7 +58,7 @@ func (msg *MsgAddr) ClearAddresses() {
|
|||
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
||||
// This is part of the Message interface implementation.
|
||||
func (msg *MsgAddr) BtcDecode(r io.Reader, pver uint32) error {
|
||||
count, err := readVarInt(r, pver)
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ func (msg *MsgAddr) BtcEncode(w io.Writer, pver uint32) error {
|
|||
return messageError("MsgAddr.BtcEncode", str)
|
||||
}
|
||||
|
||||
err := writeVarInt(w, pver, uint64(count))
|
||||
err := WriteVarInt(w, pver, uint64(count))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ func (alert *Alert) Serialize(w io.Writer, pver uint32) error {
|
|||
"[count %v, max %v]", count, maxCountSetCancel)
|
||||
return messageError("Alert.Serialize", str)
|
||||
}
|
||||
err = writeVarInt(w, pver, uint64(count))
|
||||
err = WriteVarInt(w, pver, uint64(count))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ func (alert *Alert) Serialize(w io.Writer, pver uint32) error {
|
|||
"[count %v, max %v]", count, maxCountSetSubVer)
|
||||
return messageError("Alert.Serialize", str)
|
||||
}
|
||||
err = writeVarInt(w, pver, uint64(count))
|
||||
err = WriteVarInt(w, pver, uint64(count))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ func (alert *Alert) Deserialize(r io.Reader, pver uint32) error {
|
|||
// SetCancel: first read a VarInt that contains
|
||||
// count - the number of Cancel IDs, then
|
||||
// iterate count times and read them
|
||||
count, err := readVarInt(r, pver)
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ func (alert *Alert) Deserialize(r io.Reader, pver uint32) error {
|
|||
|
||||
// SetSubVer: similar to SetCancel
|
||||
// but read count number of sub-version strings
|
||||
count, err = readVarInt(r, pver)
|
||||
count, err = ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -343,7 +343,7 @@ type MsgAlert struct {
|
|||
func (msg *MsgAlert) BtcDecode(r io.Reader, pver uint32) error {
|
||||
var err error
|
||||
|
||||
msg.SerializedPayload, err = readVarBytes(r, pver, MaxMessagePayload,
|
||||
msg.SerializedPayload, err = ReadVarBytes(r, pver, MaxMessagePayload,
|
||||
"alert serialized payload")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -354,7 +354,7 @@ func (msg *MsgAlert) BtcDecode(r io.Reader, pver uint32) error {
|
|||
msg.Payload = nil
|
||||
}
|
||||
|
||||
msg.Signature, err = readVarBytes(r, pver, MaxMessagePayload,
|
||||
msg.Signature, err = ReadVarBytes(r, pver, MaxMessagePayload,
|
||||
"alert signature")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -386,11 +386,11 @@ func (msg *MsgAlert) BtcEncode(w io.Writer, pver uint32) error {
|
|||
if slen == 0 {
|
||||
return messageError("MsgAlert.BtcEncode", "empty serialized payload")
|
||||
}
|
||||
err = writeVarBytes(w, pver, serializedpayload)
|
||||
err = WriteVarBytes(w, pver, serializedpayload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = writeVarBytes(w, pver, msg.Signature)
|
||||
err = WriteVarBytes(w, pver, msg.Signature)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ func (msg *MsgBlock) BtcDecode(r io.Reader, pver uint32) error {
|
|||
return err
|
||||
}
|
||||
|
||||
txCount, err := readVarInt(r, pver)
|
||||
txCount, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ func (msg *MsgBlock) DeserializeTxLoc(r *bytes.Buffer) ([]TxLoc, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
txCount, err := readVarInt(r, 0)
|
||||
txCount, err := ReadVarInt(r, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ func (msg *MsgBlock) BtcEncode(w io.Writer, pver uint32) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = writeVarInt(w, pver, uint64(len(msg.Transactions)))
|
||||
err = WriteVarInt(w, pver, uint64(len(msg.Transactions)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func (msg *MsgFilterAdd) BtcDecode(r io.Reader, pver uint32) error {
|
|||
}
|
||||
|
||||
var err error
|
||||
msg.Data, err = readVarBytes(r, pver, MaxFilterAddDataSize,
|
||||
msg.Data, err = ReadVarBytes(r, pver, MaxFilterAddDataSize,
|
||||
"filteradd data")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -60,7 +60,7 @@ func (msg *MsgFilterAdd) BtcEncode(w io.Writer, pver uint32) error {
|
|||
return messageError("MsgFilterAdd.BtcEncode", str)
|
||||
}
|
||||
|
||||
err := writeVarBytes(w, pver, msg.Data)
|
||||
err := WriteVarBytes(w, pver, msg.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ func (msg *MsgFilterLoad) BtcDecode(r io.Reader, pver uint32) error {
|
|||
}
|
||||
|
||||
var err error
|
||||
msg.Filter, err = readVarBytes(r, pver, MaxFilterLoadFilterSize,
|
||||
msg.Filter, err = ReadVarBytes(r, pver, MaxFilterLoadFilterSize,
|
||||
"filterload filter size")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -101,7 +101,7 @@ func (msg *MsgFilterLoad) BtcEncode(w io.Writer, pver uint32) error {
|
|||
return messageError("MsgFilterLoad.BtcEncode", str)
|
||||
}
|
||||
|
||||
err := writeVarBytes(w, pver, msg.Filter)
|
||||
err := WriteVarBytes(w, pver, msg.Filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ func (msg *MsgGetBlocks) BtcDecode(r io.Reader, pver uint32) error {
|
|||
}
|
||||
|
||||
// Read num block locator hashes and limit to max.
|
||||
count, err := readVarInt(r, pver)
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ func (msg *MsgGetBlocks) BtcEncode(w io.Writer, pver uint32) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = writeVarInt(w, pver, uint64(count))
|
||||
err = WriteVarInt(w, pver, uint64(count))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ func (msg *MsgGetData) AddInvVect(iv *InvVect) error {
|
|||
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
||||
// This is part of the Message interface implementation.
|
||||
func (msg *MsgGetData) BtcDecode(r io.Reader, pver uint32) error {
|
||||
count, err := readVarInt(r, pver)
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func (msg *MsgGetData) BtcEncode(w io.Writer, pver uint32) error {
|
|||
return messageError("MsgGetData.BtcEncode", str)
|
||||
}
|
||||
|
||||
err := writeVarInt(w, pver, uint64(count))
|
||||
err := WriteVarInt(w, pver, uint64(count))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ func (msg *MsgGetHeaders) BtcDecode(r io.Reader, pver uint32) error {
|
|||
}
|
||||
|
||||
// Read num block locator hashes and limit to max.
|
||||
count, err := readVarInt(r, pver)
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ func (msg *MsgGetHeaders) BtcEncode(w io.Writer, pver uint32) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = writeVarInt(w, pver, uint64(count))
|
||||
err = WriteVarInt(w, pver, uint64(count))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ func (msg *MsgHeaders) AddBlockHeader(bh *BlockHeader) error {
|
|||
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
||||
// This is part of the Message interface implementation.
|
||||
func (msg *MsgHeaders) BtcDecode(r io.Reader, pver uint32) error {
|
||||
count, err := readVarInt(r, pver)
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func (msg *MsgHeaders) BtcDecode(r io.Reader, pver uint32) error {
|
|||
return err
|
||||
}
|
||||
|
||||
txCount, err := readVarInt(r, pver)
|
||||
txCount, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func (msg *MsgHeaders) BtcEncode(w io.Writer, pver uint32) error {
|
|||
return messageError("MsgHeaders.BtcEncode", str)
|
||||
}
|
||||
|
||||
err := writeVarInt(w, pver, uint64(count))
|
||||
err := WriteVarInt(w, pver, uint64(count))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ func (msg *MsgHeaders) BtcEncode(w io.Writer, pver uint32) error {
|
|||
// of transactions on header messages. This is really just an
|
||||
// artifact of the way the original implementation serializes
|
||||
// block headers, but it is required.
|
||||
err = writeVarInt(w, pver, 0)
|
||||
err = WriteVarInt(w, pver, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ func (msg *MsgInv) AddInvVect(iv *InvVect) error {
|
|||
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
||||
// This is part of the Message interface implementation.
|
||||
func (msg *MsgInv) BtcDecode(r io.Reader, pver uint32) error {
|
||||
count, err := readVarInt(r, pver)
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func (msg *MsgInv) BtcEncode(w io.Writer, pver uint32) error {
|
|||
return messageError("MsgInv.BtcEncode", str)
|
||||
}
|
||||
|
||||
err := writeVarInt(w, pver, uint64(count))
|
||||
err := WriteVarInt(w, pver, uint64(count))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ func (msg *MsgMerkleBlock) BtcDecode(r io.Reader, pver uint32) error {
|
|||
}
|
||||
|
||||
// Read num block locator hashes and limit to max.
|
||||
count, err := readVarInt(r, pver)
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ func (msg *MsgMerkleBlock) BtcDecode(r io.Reader, pver uint32) error {
|
|||
msg.AddTxHash(&sha)
|
||||
}
|
||||
|
||||
msg.Flags, err = readVarBytes(r, pver, maxFlagsPerMerkleBlock,
|
||||
msg.Flags, err = ReadVarBytes(r, pver, maxFlagsPerMerkleBlock,
|
||||
"merkle block flags size")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -120,7 +120,7 @@ func (msg *MsgMerkleBlock) BtcEncode(w io.Writer, pver uint32) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = writeVarInt(w, pver, uint64(numHashes))
|
||||
err = WriteVarInt(w, pver, uint64(numHashes))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ func (msg *MsgMerkleBlock) BtcEncode(w io.Writer, pver uint32) error {
|
|||
}
|
||||
}
|
||||
|
||||
err = writeVarBytes(w, pver, msg.Flags)
|
||||
err = WriteVarBytes(w, pver, msg.Flags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func (msg *MsgNotFound) AddInvVect(iv *InvVect) error {
|
|||
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
||||
// This is part of the Message interface implementation.
|
||||
func (msg *MsgNotFound) BtcDecode(r io.Reader, pver uint32) error {
|
||||
count, err := readVarInt(r, pver)
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func (msg *MsgNotFound) BtcEncode(w io.Writer, pver uint32) error {
|
|||
return messageError("MsgNotFound.BtcEncode", str)
|
||||
}
|
||||
|
||||
err := writeVarInt(w, pver, uint64(count))
|
||||
err := WriteVarInt(w, pver, uint64(count))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -250,7 +250,7 @@ func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32) error {
|
|||
}
|
||||
msg.Version = int32(binary.LittleEndian.Uint32(buf[:]))
|
||||
|
||||
count, err := readVarInt(r, pver)
|
||||
count, err := ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ func (msg *MsgTx) BtcDecode(r io.Reader, pver uint32) error {
|
|||
msg.TxIn[i] = &ti
|
||||
}
|
||||
|
||||
count, err = readVarInt(r, pver)
|
||||
count, err = ReadVarInt(r, pver)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -339,7 +339,7 @@ func (msg *MsgTx) BtcEncode(w io.Writer, pver uint32) error {
|
|||
}
|
||||
|
||||
count := uint64(len(msg.TxIn))
|
||||
err = writeVarInt(w, pver, count)
|
||||
err = WriteVarInt(w, pver, count)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ func (msg *MsgTx) BtcEncode(w io.Writer, pver uint32) error {
|
|||
}
|
||||
|
||||
count = uint64(len(msg.TxOut))
|
||||
err = writeVarInt(w, pver, count)
|
||||
err = WriteVarInt(w, pver, count)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -515,7 +515,7 @@ func readTxIn(r io.Reader, pver uint32, version int32, ti *TxIn) error {
|
|||
}
|
||||
ti.PreviousOutPoint = op
|
||||
|
||||
ti.SignatureScript, err = readVarBytes(r, pver, MaxMessagePayload,
|
||||
ti.SignatureScript, err = ReadVarBytes(r, pver, MaxMessagePayload,
|
||||
"transaction input signature script")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -539,7 +539,7 @@ func writeTxIn(w io.Writer, pver uint32, version int32, ti *TxIn) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = writeVarBytes(w, pver, ti.SignatureScript)
|
||||
err = WriteVarBytes(w, pver, ti.SignatureScript)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -564,7 +564,7 @@ func readTxOut(r io.Reader, pver uint32, version int32, to *TxOut) error {
|
|||
}
|
||||
to.Value = int64(binary.LittleEndian.Uint64(buf[:]))
|
||||
|
||||
to.PkScript, err = readVarBytes(r, pver, MaxMessagePayload,
|
||||
to.PkScript, err = ReadVarBytes(r, pver, MaxMessagePayload,
|
||||
"transaction output public key script")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -583,7 +583,7 @@ func writeTxOut(w io.Writer, pver uint32, version int32, to *TxOut) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = writeVarBytes(w, pver, to.PkScript)
|
||||
err = WriteVarBytes(w, pver, to.PkScript)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -309,7 +309,7 @@ func TestVersionWireErrors(t *testing.T) {
|
|||
var newUAVarIntBuf bytes.Buffer
|
||||
err := wire.TstWriteVarInt(&newUAVarIntBuf, pver, uint64(len(newUA)))
|
||||
if err != nil {
|
||||
t.Errorf("writeVarInt: error %v", err)
|
||||
t.Errorf("WriteVarInt: error %v", err)
|
||||
}
|
||||
|
||||
// Make a new buffer big enough to hold the base version plus the new
|
||||
|
|
Loading…
Add table
Reference in a new issue