From acb7ef7fbd3f4a83da0d66208aefeb74ef13aff6 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 10 Oct 2019 16:47:27 +0300 Subject: [PATCH] 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. --- pkg/vm/stack_item.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/vm/stack_item.go b/pkg/vm/stack_item.go index f06fc0a29..468453d7b 100644 --- a/pkg/vm/stack_item.go +++ b/pkg/vm/stack_item.go @@ -1,6 +1,7 @@ package vm import ( + "encoding/binary" "encoding/json" "fmt" "math/big" @@ -23,6 +24,10 @@ func makeStackItem(v interface{}) StackItem { return &BigIntegerItem{ value: big.NewInt(val), } + case uint8: + return &BigIntegerItem{ + value: big.NewInt(int64(val)), + } case uint16: return &BigIntegerItem{ value: big.NewInt(int64(val)), @@ -31,6 +36,14 @@ func makeStackItem(v interface{}) StackItem { return &BigIntegerItem{ 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: return &ByteArrayItem{ value: val,