state: fix the way NEO balance is being serialized

Actually, our format is way better, but for preview2 compatibility we need to
use this one.
This commit is contained in:
Roman Khimov 2020-06-23 17:38:19 +03:00
parent c124d2bcdf
commit cd2dca0259

View file

@ -104,28 +104,20 @@ func (s *NEOBalanceState) DecodeBinary(r *io.BinReader) {
if r.Err != nil { if r.Err != nil {
return return
} }
s.fromStackItem(si) r.Err = s.fromStackItem(si)
} }
func (s *NEOBalanceState) toStackItem() stackitem.Item { func (s *NEOBalanceState) toStackItem() stackitem.Item {
result := s.NEP5BalanceState.toStackItem().(*stackitem.Struct) result := s.NEP5BalanceState.toStackItem().(*stackitem.Struct)
result.Append(stackitem.NewBigInteger(big.NewInt(int64(s.BalanceHeight)))) result.Append(stackitem.NewBigInteger(big.NewInt(int64(s.BalanceHeight))))
votes := make([]stackitem.Item, len(s.Votes)) result.Append(stackitem.NewByteArray(s.Votes.Bytes()))
for i, v := range s.Votes {
votes[i] = stackitem.NewByteArray(v.Bytes())
}
result.Append(stackitem.NewArray(votes))
return result return result
} }
func (s *NEOBalanceState) fromStackItem(item stackitem.Item) { func (s *NEOBalanceState) fromStackItem(item stackitem.Item) error {
structItem := item.Value().([]stackitem.Item) structItem := item.Value().([]stackitem.Item)
s.Balance = *structItem[0].Value().(*big.Int) s.Balance = *structItem[0].Value().(*big.Int)
s.BalanceHeight = uint32(structItem[1].Value().(*big.Int).Int64()) s.BalanceHeight = uint32(structItem[1].Value().(*big.Int).Int64())
votes := structItem[2].Value().([]stackitem.Item) s.Votes = make(keys.PublicKeys, 0)
s.Votes = make([]*keys.PublicKey, len(votes)) return s.Votes.DecodeBytes(structItem[2].Value().([]byte))
for i, v := range votes {
s.Votes[i] = new(keys.PublicKey)
s.Votes[i].DecodeBytes(v.Value().([]byte))
}
} }