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
|
|
|
|
)
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// CreateMultisigAccount calculates a script hash of an m out of n multisignature
|
|
|
|
// script using the given m and a set of public keys bytes. This function uses
|
2021-02-18 17:38:13 +00:00
|
|
|
// `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
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// CreateStandardAccount calculates a script hash of the given public key.
|
2020-06-17 08:38:32 +00:00
|
|
|
// 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
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetCallFlags returns the calling flags which execution context was created with.
|
2020-07-16 09:13:55 +00:00
|
|
|
// 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
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// Call executes the previously deployed blockchain contract with the specified hash
|
|
|
|
// (20 bytes in BE form) using the provided arguments and call flags.
|
2020-12-08 12:37:03 +00:00
|
|
|
// It returns whatever this contract returns. This function uses
|
2020-12-29 10:44:07 +00:00
|
|
|
// `System.Contract.Call` syscall.
|
2023-04-03 10:34:24 +00:00
|
|
|
func Call(scriptHash interop.Hash160, method string, f CallFlag, args ...any) any {
|
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
|
|
|
}
|