-
Notifications
You must be signed in to change notification settings - Fork 80
/
contract.go
52 lines (45 loc) · 1.94 KB
/
contract.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
Package contract provides functions to work with contracts.
*/
package contract
import (
"github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/neogointernal"
)
// 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 (
ReadStates CallFlag = 1 << iota
WriteStates
AllowCall
AllowNotify
States = ReadStates | WriteStates
ReadOnly = ReadStates | AllowCall
All = States | AllowCall | AllowNotify
NoneFlag CallFlag = 0
)
// 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
// `System.Contract.CreateMultisigAccount` syscall.
func CreateMultisigAccount(m int, pubs []interop.PublicKey) []byte {
return neogointernal.Syscall2("System.Contract.CreateMultisigAccount", m, pubs).([]byte)
}
// CreateStandardAccount calculates a script hash of the given public key.
// This function uses `System.Contract.CreateStandardAccount` syscall.
func CreateStandardAccount(pub interop.PublicKey) []byte {
return neogointernal.Syscall1("System.Contract.CreateStandardAccount", pub).([]byte)
}
// GetCallFlags returns the calling flags which execution context was created with.
// This function uses `System.Contract.GetCallFlags` syscall.
func GetCallFlags() CallFlag {
return neogointernal.Syscall0("System.Contract.GetCallFlags").(CallFlag)
}
// Call executes the previously deployed blockchain contract with the specified hash
// (20 bytes in BE form) using the provided arguments and call flags.
// It returns whatever this contract returns. This function uses
// `System.Contract.Call` syscall.
func Call(scriptHash interop.Hash160, method string, f CallFlag, args ...any) any {
return neogointernal.Syscall4("System.Contract.Call", scriptHash, method, f, args)
}