parser/internal/bytestring: return CompactSize reads as int rather than uint64
This commit is contained in:
parent
2d9cf24f74
commit
30370cd206
|
@ -79,7 +79,7 @@ func (s *String) ReadBytes(out *[]byte, n int) bool {
|
||||||
// ReadCompactSize reads and interprets a Bitcoin-custom compact integer
|
// ReadCompactSize reads and interprets a Bitcoin-custom compact integer
|
||||||
// encoding used for length-prefixing and count values. If the values fall
|
// encoding used for length-prefixing and count values. If the values fall
|
||||||
// outside the expected canonical ranges, it returns false.
|
// 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)
|
lenBytes := s.read(1)
|
||||||
if lenBytes == nil {
|
if lenBytes == nil {
|
||||||
return false
|
return false
|
||||||
|
@ -116,19 +116,19 @@ func (s *String) ReadCompactSize(size *uint64) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
*size = length
|
*size = int(length)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadCompactLengthPrefixed reads data prefixed by a CompactSize-encoded
|
// ReadCompactLengthPrefixed reads data prefixed by a CompactSize-encoded
|
||||||
// length field into out. It reports whether the read was successful.
|
// length field into out. It reports whether the read was successful.
|
||||||
func (s *String) ReadCompactLengthPrefixed(out *String) bool {
|
func (s *String) ReadCompactLengthPrefixed(out *String) bool {
|
||||||
var length uint64
|
var length int
|
||||||
if ok := s.ReadCompactSize(&length); !ok {
|
if ok := s.ReadCompactSize(&length); !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
v := s.read(int(length))
|
v := s.read(length)
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,7 +267,7 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var txInCount uint64
|
var txInCount int
|
||||||
if ok := s.ReadCompactSize(&txInCount); !ok {
|
if ok := s.ReadCompactSize(&txInCount); !ok {
|
||||||
return nil, errors.New("could not read tx_in_count")
|
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 {
|
if ok := s.ReadCompactSize(&txOutCount); !ok {
|
||||||
return nil, errors.New("could not read tx_out_count")
|
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 tx.version >= 4 {
|
||||||
if ok := s.ReadInt64(&tx.valueBalance); !ok {
|
if ok := s.ReadInt64(&tx.valueBalance); !ok {
|
||||||
return nil, errors.New("could not read valueBalance")
|
return nil, errors.New("could not read valueBalance")
|
||||||
}
|
}
|
||||||
|
|
||||||
var spendCount uint64
|
|
||||||
if ok := s.ReadCompactSize(&spendCount); !ok {
|
if ok := s.ReadCompactSize(&spendCount); !ok {
|
||||||
return nil, errors.New("could not read nShieldedSpend")
|
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 {
|
if ok := s.ReadCompactSize(&outputCount); !ok {
|
||||||
return nil, errors.New("could not read nShieldedOutput")
|
return nil, errors.New("could not read nShieldedOutput")
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if tx.version >= 2 {
|
if tx.version >= 2 {
|
||||||
var joinSplitCount uint64
|
var joinSplitCount int
|
||||||
if ok := s.ReadCompactSize(&joinSplitCount); !ok {
|
if ok := s.ReadCompactSize(&joinSplitCount); !ok {
|
||||||
return nil, errors.New("could not read nJoinSplit")
|
return nil, errors.New("could not read nJoinSplit")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue