mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-25 23:17:25 +00:00
vm: implement NEWMAP opcode
This commit is contained in:
parent
dac1f9367c
commit
df18da0ac9
2 changed files with 51 additions and 1 deletions
|
@ -193,3 +193,50 @@ func (i *ArrayItem) MarshalJSON() ([]byte, error) {
|
||||||
func (i *ArrayItem) String() string {
|
func (i *ArrayItem) String() string {
|
||||||
return "Array"
|
return "Array"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MapItem represents Map object.
|
||||||
|
type MapItem struct {
|
||||||
|
value map[interface{}]StackItem
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMapItem returns new MapItem object.
|
||||||
|
func NewMapItem() *MapItem {
|
||||||
|
return &MapItem{
|
||||||
|
value: make(map[interface{}]StackItem),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value implements StackItem interface.
|
||||||
|
func (i *MapItem) Value() interface{} {
|
||||||
|
return i.value
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON implements the json.Marshaler interface.
|
||||||
|
func (i *MapItem) String() string {
|
||||||
|
return "Map"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Has checks if map has specified key.
|
||||||
|
func (i *MapItem) Has(key StackItem) (ok bool) {
|
||||||
|
_, ok = i.value[toMapKey(key)]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add adds key-value pair to the map.
|
||||||
|
func (i *MapItem) Add(key, value StackItem) {
|
||||||
|
i.value[toMapKey(key)] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
// toMapKey converts StackItem so that it can be used as a map key.
|
||||||
|
func toMapKey(key StackItem) interface{} {
|
||||||
|
switch t := key.(type) {
|
||||||
|
case *BoolItem:
|
||||||
|
return t.value
|
||||||
|
case *BigIntegerItem:
|
||||||
|
return t.value.Int64()
|
||||||
|
case *ByteArrayItem:
|
||||||
|
return string(t.value)
|
||||||
|
default:
|
||||||
|
panic("wrong key type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -912,9 +912,12 @@ func (v *VM) execute(ctx *Context, op Instruction) {
|
||||||
}
|
}
|
||||||
v.estack.PushVal(sigok)
|
v.estack.PushVal(sigok)
|
||||||
|
|
||||||
case NEWMAP, HASKEY, KEYS, VALUES:
|
case HASKEY, KEYS, VALUES:
|
||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
|
|
||||||
|
case NEWMAP:
|
||||||
|
v.estack.Push(&Element{value: NewMapItem()})
|
||||||
|
|
||||||
// Cryptographic operations.
|
// Cryptographic operations.
|
||||||
case SHA1:
|
case SHA1:
|
||||||
b := v.estack.Pop().Bytes()
|
b := v.estack.Pop().Bytes()
|
||||||
|
|
Loading…
Reference in a new issue