vm: move IntToBytes and BytesToInt to emit package
This commit is contained in:
parent
4d8a3a359b
commit
c821e1c4c8
6 changed files with 15 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
package vm
|
||||
package emit
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
|
@ -1,4 +1,4 @@
|
|||
package vm
|
||||
package emit
|
||||
|
||||
import (
|
||||
"math"
|
|
@ -13,6 +13,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/vm/emit"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
||||
"github.com/CityOfZion/neo-go/pkg/util"
|
||||
"github.com/CityOfZion/neo-go/pkg/vm/opcode"
|
||||
|
@ -196,7 +198,7 @@ func compareItems(t *testing.T, a, b StackItem) {
|
|||
case *BigIntegerItem:
|
||||
require.Equal(t, val, ac.value.Int64())
|
||||
case *ByteArrayItem:
|
||||
require.Equal(t, val, BytesToInt(ac.value).Int64())
|
||||
require.Equal(t, val, emit.BytesToInt(ac.value).Int64())
|
||||
case *BoolItem:
|
||||
if ac.value {
|
||||
require.Equal(t, val, int64(1))
|
||||
|
|
|
@ -3,6 +3,8 @@ package vm
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/vm/emit"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/io"
|
||||
)
|
||||
|
||||
|
@ -48,7 +50,7 @@ func serializeItemTo(item StackItem, w *io.BinWriter, seen map[StackItem]bool) {
|
|||
w.WriteBool(t.value)
|
||||
case *BigIntegerItem:
|
||||
w.WriteBytes([]byte{byte(integerT)})
|
||||
w.WriteVarBytes(IntToBytes(t.value))
|
||||
w.WriteVarBytes(emit.IntToBytes(t.value))
|
||||
case *InteropItem:
|
||||
w.Err = errors.New("not supported")
|
||||
case *ArrayItem, *StructItem:
|
||||
|
@ -106,7 +108,7 @@ func DecodeBinaryStackItem(r *io.BinReader) StackItem {
|
|||
return NewBoolItem(b)
|
||||
case integerT:
|
||||
data := r.ReadVarBytes()
|
||||
num := BytesToInt(data)
|
||||
num := emit.BytesToInt(data)
|
||||
return &BigIntegerItem{
|
||||
value: num,
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/vm/emit"
|
||||
)
|
||||
|
||||
// Stack implementation for the neo-go virtual machine. The stack implements
|
||||
|
@ -81,7 +83,7 @@ func (e *Element) BigInt() *big.Int {
|
|||
return big.NewInt(0)
|
||||
default:
|
||||
b := t.Value().([]uint8)
|
||||
return BytesToInt(b)
|
||||
return emit.BytesToInt(b)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
"fmt"
|
||||
"math/big"
|
||||
"reflect"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/vm/emit"
|
||||
)
|
||||
|
||||
// A StackItem represents the "real" value that is pushed on the stack.
|
||||
|
@ -142,7 +144,7 @@ func NewBigIntegerItem(value int) *BigIntegerItem {
|
|||
|
||||
// Bytes converts i to a slice of bytes.
|
||||
func (i *BigIntegerItem) Bytes() []byte {
|
||||
return IntToBytes(i.value)
|
||||
return emit.IntToBytes(i.value)
|
||||
}
|
||||
|
||||
// Value implements StackItem interface.
|
||||
|
|
Loading…
Reference in a new issue