2020-05-18 07:42:44 +00:00
|
|
|
/*
|
|
|
|
Package contract provides functions to work with contracts.
|
|
|
|
*/
|
2018-08-21 10:57:48 +00:00
|
|
|
package contract
|
|
|
|
|
2021-02-05 16:02:09 +00:00
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/neogointernal"
|
|
|
|
)
|
2020-08-28 07:47:15 +00:00
|
|
|
|
2020-12-08 12:37:03 +00:00
|
|
|
// CallFlag specifies valid call flags.
|
|
|
|
type CallFlag byte
|
|
|
|
|
|
|
|
// Using `smartcontract` package from compiled contract requires moderate
|
|
|
|
// compiler refactoring, thus all flags are mirrored here.
|
|
|
|
const (
|
2020-12-11 07:34:01 +00:00
|
|
|
ReadStates CallFlag = 1 << iota
|
|
|
|
WriteStates
|
2020-12-08 12:37:03 +00:00
|
|
|
AllowCall
|
|
|
|
AllowNotify
|
2020-12-11 07:34:01 +00:00
|
|
|
States = ReadStates | WriteStates
|
|
|
|
ReadOnly = ReadStates | AllowCall
|
|
|
|
All = States | AllowCall | AllowNotify
|
2020-12-08 12:37:03 +00:00
|
|
|
NoneFlag CallFlag = 0
|
|
|
|
)
|
|
|
|
|
2021-02-18 17:38:13 +00:00
|
|
|
// CreateMultisigAccount calculates script hash of an m out of n multisignature
|
|
|
|
// script using given m and a set of public keys bytes. This function uses
|
|
|
|
// `System.Contract.CreateMultisigAccount` syscall.
|
|
|
|
func CreateMultisigAccount(m int, pubs []interop.PublicKey) []byte {
|
2021-03-04 08:39:49 +00:00
|
|
|
return neogointernal.Syscall2("System.Contract.CreateMultisigAccount", m, pubs).([]byte)
|
2021-02-18 17:38:13 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 08:38:32 +00:00
|
|
|
// CreateStandardAccount calculates script hash of a given public key.
|
|
|
|
// This function uses `System.Contract.CreateStandardAccount` syscall.
|
2020-08-28 07:47:15 +00:00
|
|
|
func CreateStandardAccount(pub interop.PublicKey) []byte {
|
2021-02-05 16:02:09 +00:00
|
|
|
return neogointernal.Syscall1("System.Contract.CreateStandardAccount", pub).([]byte)
|
2020-06-17 08:38:32 +00:00
|
|
|
}
|
2020-07-16 09:13:55 +00:00
|
|
|
|
|
|
|
// GetCallFlags returns calling flags which execution context was created with.
|
|
|
|
// This function uses `System.Contract.GetCallFlags` syscall.
|
2021-03-04 10:09:03 +00:00
|
|
|
func GetCallFlags() CallFlag {
|
2021-03-04 15:12:56 +00:00
|
|
|
return neogointernal.Syscall0("System.Contract.GetCallFlags").(CallFlag)
|
2020-07-16 09:13:55 +00:00
|
|
|
}
|
2020-12-08 11:11:06 +00:00
|
|
|
|
|
|
|
// Call executes previously deployed blockchain contract with specified hash
|
2020-12-08 12:37:03 +00:00
|
|
|
// (20 bytes in BE form) using provided arguments and call flags.
|
|
|
|
// It returns whatever this contract returns. This function uses
|
2020-12-29 10:44:07 +00:00
|
|
|
// `System.Contract.Call` syscall.
|
|
|
|
func Call(scriptHash interop.Hash160, method string, f CallFlag, args ...interface{}) interface{} {
|
2021-02-05 16:02:09 +00:00
|
|
|
return neogointernal.Syscall4("System.Contract.Call", scriptHash, method, f, args)
|
2020-12-08 12:37:03 +00:00
|
|
|
}
|