mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-30 09:33:36 +00:00
vm: support uint8 and uint64 in makeStackItem()
Convenience to avoid casts, uint64 is also a bit special in that it can't be converted to int64 without data loss.
This commit is contained in:
parent
6b70c5f2bd
commit
acb7ef7fbd
1 changed files with 13 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
package vm
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
@ -23,6 +24,10 @@ func makeStackItem(v interface{}) StackItem {
|
||||||
return &BigIntegerItem{
|
return &BigIntegerItem{
|
||||||
value: big.NewInt(val),
|
value: big.NewInt(val),
|
||||||
}
|
}
|
||||||
|
case uint8:
|
||||||
|
return &BigIntegerItem{
|
||||||
|
value: big.NewInt(int64(val)),
|
||||||
|
}
|
||||||
case uint16:
|
case uint16:
|
||||||
return &BigIntegerItem{
|
return &BigIntegerItem{
|
||||||
value: big.NewInt(int64(val)),
|
value: big.NewInt(int64(val)),
|
||||||
|
@ -31,6 +36,14 @@ func makeStackItem(v interface{}) StackItem {
|
||||||
return &BigIntegerItem{
|
return &BigIntegerItem{
|
||||||
value: big.NewInt(int64(val)),
|
value: big.NewInt(int64(val)),
|
||||||
}
|
}
|
||||||
|
case uint64:
|
||||||
|
b := make([]byte, 8)
|
||||||
|
binary.BigEndian.PutUint64(b, val)
|
||||||
|
bigInt := big.NewInt(0)
|
||||||
|
bigInt.SetBytes(b)
|
||||||
|
return &BigIntegerItem{
|
||||||
|
value: bigInt,
|
||||||
|
}
|
||||||
case []byte:
|
case []byte:
|
||||||
return &ByteArrayItem{
|
return &ByteArrayItem{
|
||||||
value: val,
|
value: val,
|
||||||
|
|
Loading…
Reference in a new issue