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
|
|
|
|
|
2020-08-28 07:47:15 +00:00
|
|
|
import "github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
|
2020-05-18 07:42:44 +00:00
|
|
|
// Contract represents a Neo contract and is used in interop functions. It's
|
2020-07-15 11:39:20 +00:00
|
|
|
// a data structure that you can manipulate with using functions from
|
2020-05-18 07:42:44 +00:00
|
|
|
// this package. It's similar in function to the Contract class in the Neo .net
|
|
|
|
// framework.
|
2020-07-15 11:39:20 +00:00
|
|
|
type Contract struct {
|
2020-11-13 18:26:23 +00:00
|
|
|
Script []byte
|
|
|
|
Manifest []byte
|
2020-07-15 11:39:20 +00:00
|
|
|
}
|
2018-08-21 10:57:48 +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 (
|
|
|
|
AllowStates CallFlag = 1 << iota
|
|
|
|
AllowModifyStates
|
|
|
|
AllowCall
|
|
|
|
AllowNotify
|
|
|
|
ReadOnly = AllowStates | AllowCall | AllowNotify
|
|
|
|
All = ReadOnly | AllowModifyStates
|
|
|
|
NoneFlag CallFlag = 0
|
|
|
|
)
|
|
|
|
|
2020-05-18 07:42:44 +00:00
|
|
|
// Create creates a new contract using a set of input parameters:
|
|
|
|
// script contract's bytecode (limited in length by 1M)
|
2020-06-09 09:12:56 +00:00
|
|
|
// manifest contract's manifest (limited in length by 2 KiB)
|
2020-05-18 07:42:44 +00:00
|
|
|
// It returns this new created Contract when successful (and fails transaction
|
2020-06-10 11:07:26 +00:00
|
|
|
// if not). It uses `System.Contract.Create` syscall.
|
2020-09-08 10:41:47 +00:00
|
|
|
func Create(script []byte, manifest []byte) *Contract {
|
|
|
|
return &Contract{}
|
2018-08-22 07:51:35 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 11:07:26 +00:00
|
|
|
// Update updates script and manifest of the calling contract (that is the one that calls Update)
|
|
|
|
// to the new ones. Its parameters have exactly the same semantics as for
|
2020-05-18 07:42:44 +00:00
|
|
|
// Create. The old contract will be deleted by this call, if it has any storage
|
|
|
|
// associated it will be migrated to the new contract. New contract is returned.
|
2020-06-10 11:07:26 +00:00
|
|
|
// This function uses `System.Contract.Update` syscall.
|
2020-07-16 08:32:32 +00:00
|
|
|
func Update(script []byte, manifest []byte) {
|
|
|
|
return
|
2018-08-22 07:51:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 07:42:44 +00:00
|
|
|
// Destroy deletes calling contract (the one that calls Destroy) from the
|
|
|
|
// blockchain, so it's only possible to do that from the contract itself and
|
|
|
|
// not by any outside code. When contract is deleted all associated storage
|
2020-06-10 11:07:26 +00:00
|
|
|
// items are deleted too. This function uses `System.Contract.Destroy` syscall.
|
2020-05-18 07:42:44 +00:00
|
|
|
func Destroy() {}
|
2020-06-17 08:38:32 +00:00
|
|
|
|
|
|
|
// IsStandard checks if contract with provided hash is a standard signature/multisig contract.
|
|
|
|
// This function uses `System.Contract.IsStandard` syscall.
|
2020-08-28 07:47:15 +00:00
|
|
|
func IsStandard(h interop.Hash160) bool {
|
2020-06-17 08:38:32 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2020-06-17 08:38:32 +00:00
|
|
|
return nil
|
|
|
|
}
|
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.
|
|
|
|
func GetCallFlags() int64 {
|
|
|
|
return 0
|
|
|
|
}
|
2020-12-08 11:11:06 +00:00
|
|
|
|
|
|
|
// Call executes previously deployed blockchain contract with specified hash
|
|
|
|
// (20 bytes in BE form) using provided arguments.
|
|
|
|
// It returns whatever this contract returns. This function uses
|
|
|
|
// `System.Contract.Call` syscall.
|
|
|
|
func Call(scriptHash interop.Hash160, method string, args ...interface{}) interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
2020-12-08 12:37:03 +00:00
|
|
|
|
|
|
|
// CallEx executes previously deployed blockchain contract with specified hash
|
|
|
|
// (20 bytes in BE form) using provided arguments and call flags.
|
|
|
|
// It returns whatever this contract returns. This function uses
|
|
|
|
// `System.Contract.CallEx` syscall.
|
|
|
|
func CallEx(f CallFlag, scriptHash interop.Hash160, method string, args ...interface{}) interface{} {
|
|
|
|
return nil
|
|
|
|
}
|