core: move GetScriptContainer to runtime
It also brings ToStackItem to Block and Transaction, previously this was avoided to separate block and transaction packages from VM. But turns out `transaction` depends on `stackitem` already, so this makes little sense (but can be shuffled in another way if needed). Context.Container is still a hash.Hashable because we have a number of occasions (header or MPT root verification) where there is no ToStackItem implementation possible. Maybe they can go with `nil` Container, but I don't want to have this risk for now.
This commit is contained in:
parent
cdb55740ea
commit
d70caf1da1
6 changed files with 52 additions and 53 deletions
|
@ -10,6 +10,10 @@ import (
|
|||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type itemable interface {
|
||||
ToStackItem() stackitem.Item
|
||||
}
|
||||
|
||||
const (
|
||||
// MaxEventNameLen is the maximum length of a name for event.
|
||||
MaxEventNameLen = 32
|
||||
|
@ -37,6 +41,17 @@ func GetEntryScriptHash(ic *interop.Context) error {
|
|||
return ic.VM.PushContextScriptHash(ic.VM.Istack().Len() - 1)
|
||||
}
|
||||
|
||||
// GetScriptContainer returns transaction or block that contains the script
|
||||
// being run.
|
||||
func GetScriptContainer(ic *interop.Context) error {
|
||||
c, ok := ic.Container.(itemable)
|
||||
if !ok {
|
||||
return errors.New("unknown script container")
|
||||
}
|
||||
ic.VM.Estack().PushItem(c.ToStackItem())
|
||||
return nil
|
||||
}
|
||||
|
||||
// Platform returns the name of the platform.
|
||||
func Platform(ic *interop.Context) error {
|
||||
ic.VM.Estack().PushItem(stackitem.NewByteArray([]byte("NEO")))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue