vm: hide GetContextScriptHash() method

After adding ScriptHashGetter interface to vm, there's no need in
GetContextScriptHash() to be exported.
This commit is contained in:
Anna Shaleva 2020-05-04 11:41:41 +03:00
parent 73167999cc
commit 5ece9922c1
5 changed files with 13 additions and 13 deletions

View file

@ -540,7 +540,7 @@ func contractMigrate(ic *interop.Context, v *vm.VM) error {
return err return err
} }
if contract.HasStorage() { if contract.HasStorage() {
hash := v.GetContextScriptHash(0) hash := v.GetCurrentScriptHash()
siMap, err := ic.DAO.GetStorageItems(hash) siMap, err := ic.DAO.GetStorageItems(hash)
if err != nil { if err != nil {
return err return err

View file

@ -292,7 +292,7 @@ func runtimeNotify(ic *interop.Context, v *vm.VM) error {
if err != nil { if err != nil {
item = vm.NewByteArrayItem([]byte(fmt.Sprintf("bad notification: %v", err))) item = vm.NewByteArrayItem([]byte(fmt.Sprintf("bad notification: %v", err)))
} }
ne := state.NotificationEvent{ScriptHash: v.GetContextScriptHash(0), Item: item} ne := state.NotificationEvent{ScriptHash: v.GetCurrentScriptHash(), Item: item}
ic.Notifications = append(ic.Notifications, ne) ic.Notifications = append(ic.Notifications, ne)
return nil return nil
} }
@ -301,7 +301,7 @@ func runtimeNotify(ic *interop.Context, v *vm.VM) error {
func runtimeLog(ic *interop.Context, v *vm.VM) error { func runtimeLog(ic *interop.Context, v *vm.VM) error {
msg := fmt.Sprintf("%q", v.Estack().Pop().Bytes()) msg := fmt.Sprintf("%q", v.Estack().Pop().Bytes())
ic.Log.Info("runtime log", ic.Log.Info("runtime log",
zap.Stringer("script", v.GetContextScriptHash(0)), zap.Stringer("script", v.GetCurrentScriptHash()),
zap.String("logs", msg)) zap.String("logs", msg))
return nil return nil
} }
@ -383,7 +383,7 @@ func storageGet(ic *interop.Context, v *vm.VM) error {
// storageGetContext returns storage context (scripthash). // storageGetContext returns storage context (scripthash).
func storageGetContext(ic *interop.Context, v *vm.VM) error { func storageGetContext(ic *interop.Context, v *vm.VM) error {
sc := &StorageContext{ sc := &StorageContext{
ScriptHash: v.GetContextScriptHash(0), ScriptHash: v.GetCurrentScriptHash(),
ReadOnly: false, ReadOnly: false,
} }
v.Estack().PushVal(vm.NewInteropItem(sc)) v.Estack().PushVal(vm.NewInteropItem(sc))
@ -393,7 +393,7 @@ func storageGetContext(ic *interop.Context, v *vm.VM) error {
// storageGetReadOnlyContext returns read-only context (scripthash). // storageGetReadOnlyContext returns read-only context (scripthash).
func storageGetReadOnlyContext(ic *interop.Context, v *vm.VM) error { func storageGetReadOnlyContext(ic *interop.Context, v *vm.VM) error {
sc := &StorageContext{ sc := &StorageContext{
ScriptHash: v.GetContextScriptHash(0), ScriptHash: v.GetCurrentScriptHash(),
ReadOnly: true, ReadOnly: true,
} }
v.Estack().PushVal(vm.NewInteropItem(sc)) v.Estack().PushVal(vm.NewInteropItem(sc))
@ -475,7 +475,7 @@ func contractDestroy(ic *interop.Context, v *vm.VM) error {
if ic.Trigger != trigger.Application { if ic.Trigger != trigger.Application {
return errors.New("can't destroy contract when not triggered by application") return errors.New("can't destroy contract when not triggered by application")
} }
hash := v.GetContextScriptHash(0) hash := v.GetCurrentScriptHash()
cs, err := ic.DAO.GetContractState(hash) cs, err := ic.DAO.GetContractState(hash)
if err != nil { if err != nil {
return nil return nil

View file

@ -69,7 +69,7 @@ func (cs *Contracts) GetNativeInterop(ic *interop.Context) func(uint32) *vm.Inte
// getNativeInterop returns native contract interop. // getNativeInterop returns native contract interop.
func getNativeInterop(ic *interop.Context, c interop.Contract) func(v *vm.VM) error { func getNativeInterop(ic *interop.Context, c interop.Contract) func(v *vm.VM) error {
return func(v *vm.VM) error { return func(v *vm.VM) error {
h := v.GetContextScriptHash(0) h := v.GetCurrentScriptHash()
if !h.Equals(c.Metadata().Hash) { if !h.Equals(c.Metadata().Hash) {
return errors.New("invalid hash") return errors.New("invalid hash")
} }

View file

@ -223,9 +223,9 @@ func (c *Context) String() string {
return "execution context" return "execution context"
} }
// GetContextScriptHash returns script hash of the invocation stack element // getContextScriptHash returns script hash of the invocation stack element
// number n. // number n.
func (v *VM) GetContextScriptHash(n int) util.Uint160 { func (v *VM) getContextScriptHash(n int) util.Uint160 {
element := v.Istack().Peek(n) element := v.Istack().Peek(n)
if element == nil { if element == nil {
return util.Uint160{} return util.Uint160{}
@ -238,7 +238,7 @@ func (v *VM) GetContextScriptHash(n int) util.Uint160 {
// PushContextScriptHash pushes to evaluation stack the script hash of the // PushContextScriptHash pushes to evaluation stack the script hash of the
// invocation stack element number n. // invocation stack element number n.
func (v *VM) PushContextScriptHash(n int) error { func (v *VM) PushContextScriptHash(n int) error {
h := v.GetContextScriptHash(n) h := v.getContextScriptHash(n)
v.Estack().PushVal(h.BytesBE()) v.Estack().PushVal(h.BytesBE())
return nil return nil
} }

View file

@ -1537,15 +1537,15 @@ func (v *VM) bytesToPublicKey(b []byte) *keys.PublicKey {
// GetCallingScriptHash implements ScriptHashGetter interface // GetCallingScriptHash implements ScriptHashGetter interface
func (v *VM) GetCallingScriptHash() util.Uint160 { func (v *VM) GetCallingScriptHash() util.Uint160 {
return v.GetContextScriptHash(1) return v.getContextScriptHash(1)
} }
// GetEntryScriptHash implements ScriptHashGetter interface // GetEntryScriptHash implements ScriptHashGetter interface
func (v *VM) GetEntryScriptHash() util.Uint160 { func (v *VM) GetEntryScriptHash() util.Uint160 {
return v.GetContextScriptHash(v.Istack().Len() - 1) return v.getContextScriptHash(v.Istack().Len() - 1)
} }
// GetCurrentScriptHash implements ScriptHashGetter interface // GetCurrentScriptHash implements ScriptHashGetter interface
func (v *VM) GetCurrentScriptHash() util.Uint160 { func (v *VM) GetCurrentScriptHash() util.Uint160 {
return v.GetContextScriptHash(0) return v.getContextScriptHash(0)
} }