Browse Source

parser/internal/bytestring: return CompactSize reads as int rather than uint64

v2_protobufs
George Tankersley 6 years ago
parent
commit
30370cd206
  1. 8
      parser/internal/bytestring/bytestring.go
  2. 10
      parser/transaction.go

8
parser/internal/bytestring/bytestring.go

@ -79,7 +79,7 @@ func (s *String) ReadBytes(out *[]byte, n int) bool {
// ReadCompactSize reads and interprets a Bitcoin-custom compact integer
// encoding used for length-prefixing and count values. If the values fall
// outside the expected canonical ranges, it returns false.
func (s *String) ReadCompactSize(size *uint64) bool {
func (s *String) ReadCompactSize(size *int) bool {
lenBytes := s.read(1)
if lenBytes == nil {
return false
@ -116,19 +116,19 @@ func (s *String) ReadCompactSize(size *uint64) bool {
return false
}
*size = length
*size = int(length)
return true
}
// ReadCompactLengthPrefixed reads data prefixed by a CompactSize-encoded
// length field into out. It reports whether the read was successful.
func (s *String) ReadCompactLengthPrefixed(out *String) bool {
var length uint64
var length int
if ok := s.ReadCompactSize(&length); !ok {
return false
}
v := s.read(int(length))
v := s.read(length)
if v == nil {
return false
}

10
parser/transaction.go

@ -267,7 +267,7 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
}
}
var txInCount uint64
var txInCount int
if ok := s.ReadCompactSize(&txInCount); !ok {
return nil, errors.New("could not read tx_in_count")
}
@ -288,7 +288,7 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
}
}
var txOutCount uint64
var txOutCount int
if ok := s.ReadCompactSize(&txOutCount); !ok {
return nil, errors.New("could not read tx_out_count")
}
@ -315,12 +315,13 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
}
}
var spendCount, outputCount int
if tx.version >= 4 {
if ok := s.ReadInt64(&tx.valueBalance); !ok {
return nil, errors.New("could not read valueBalance")
}
var spendCount uint64
if ok := s.ReadCompactSize(&spendCount); !ok {
return nil, errors.New("could not read nShieldedSpend")
}
@ -337,7 +338,6 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
}
}
var outputCount uint64
if ok := s.ReadCompactSize(&outputCount); !ok {
return nil, errors.New("could not read nShieldedOutput")
}
@ -356,7 +356,7 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
}
if tx.version >= 2 {
var joinSplitCount uint64
var joinSplitCount int
if ok := s.ReadCompactSize(&joinSplitCount); !ok {
return nil, errors.New("could not read nJoinSplit")
}

Loading…
Cancel
Save