Payload of HashXHistoryValue should be an array of uint32 representing "txnums" #54

Merged
moodyjon merged 2 commits from hashx_history_fix into master 2022-09-06 19:40:06 +02:00
Showing only changes of commit 4e11433325 - Show all commits

View file

@ -513,7 +513,7 @@ type HashXHistoryKey struct {
} }
type HashXHistoryValue struct { type HashXHistoryValue struct {
HashXes []uint16 `struct-while:"!_eof" json:"hashxes"` TxNums []uint32 `struct-while:"!_eof" json:"tx_nums"`
} }
func (k *HashXHistoryKey) String() string { func (k *HashXHistoryKey) String() string {
@ -538,10 +538,10 @@ func (k *HashXHistoryKey) PackKey() []byte {
} }
func (v *HashXHistoryValue) PackValue() []byte { func (v *HashXHistoryValue) PackValue() []byte {
n := len(v.HashXes) n := len(v.TxNums)
value := make([]byte, n*2) value := make([]byte, n*4)
for i, x := range v.HashXes { for i, x := range v.TxNums {
binary.BigEndian.PutUint16(value[i*2:], x) binary.BigEndian.PutUint32(value[i*4:], x)
} }
return value return value
@ -600,13 +600,13 @@ func HashXHistoryKeyUnpack(key []byte) *HashXHistoryKey {
} }
func HashXHistoryValueUnpack(value []byte) *HashXHistoryValue { func HashXHistoryValueUnpack(value []byte) *HashXHistoryValue {
n := len(value) / 2 n := len(value) / 4
hashxes := make([]uint16, n) txnums := make([]uint32, n)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
hashxes[i] = binary.BigEndian.Uint16(value[i*2:]) txnums[i] = binary.BigEndian.Uint32(value[i*4:])
} }
return &HashXHistoryValue{ return &HashXHistoryValue{
HashXes: hashxes, TxNums: txnums,
} }
} }