forked from TrueCloudLab/neoneo-go
state: convert NEO balance to stack item directly
Avoid calling Append() that will reallocate the slice, we know the length of the slice exactly.
This commit is contained in:
parent
5c65d33439
commit
dede4fa7b1
1 changed files with 9 additions and 6 deletions
|
@ -91,15 +91,18 @@ func (s *NEOBalance) Bytes() []byte {
|
||||||
|
|
||||||
// ToStackItem implements stackitem.Convertible interface. It never returns an error.
|
// ToStackItem implements stackitem.Convertible interface. It never returns an error.
|
||||||
func (s *NEOBalance) ToStackItem() (stackitem.Item, error) {
|
func (s *NEOBalance) ToStackItem() (stackitem.Item, error) {
|
||||||
resItem, _ := s.NEP17Balance.ToStackItem()
|
var voteItem stackitem.Item
|
||||||
result := resItem.(*stackitem.Struct)
|
|
||||||
result.Append(stackitem.NewBigInteger(big.NewInt(int64(s.BalanceHeight))))
|
|
||||||
if s.VoteTo != nil {
|
if s.VoteTo != nil {
|
||||||
result.Append(stackitem.NewByteArray(s.VoteTo.Bytes()))
|
voteItem = stackitem.NewByteArray(s.VoteTo.Bytes())
|
||||||
} else {
|
} else {
|
||||||
result.Append(stackitem.Null{})
|
voteItem = stackitem.Null{}
|
||||||
}
|
}
|
||||||
return result, nil
|
return stackitem.NewStruct([]stackitem.Item{
|
||||||
|
stackitem.NewBigInteger(&s.Balance),
|
||||||
|
stackitem.NewBigInteger(big.NewInt(int64(s.BalanceHeight))),
|
||||||
|
voteItem,
|
||||||
|
}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromStackItem converts stackitem.Item to NEOBalance.
|
// FromStackItem converts stackitem.Item to NEOBalance.
|
||||||
|
|
Loading…
Reference in a new issue