-
Notifications
You must be signed in to change notification settings - Fork 199
/
interface.go
132 lines (117 loc) · 4.53 KB
/
interface.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package vm
import (
"math/big"
"github.com/multiversx/mx-chain-core-go/data"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
)
// SystemSmartContract interface defines the function a system smart contract should have
type SystemSmartContract interface {
Execute(args *vmcommon.ContractCallInput) vmcommon.ReturnCode
CanUseContract() bool
SetNewGasCost(gasCost GasCost)
IsInterfaceNil() bool
}
// SystemSCContainerFactory defines the functionality to create a system smart contract container
type SystemSCContainerFactory interface {
CreateForGenesis() (SystemSCContainer, error)
Create() (SystemSCContainer, error)
IsInterfaceNil() bool
}
// SystemSCContainer defines a system smart contract holder data type with basic functionality
type SystemSCContainer interface {
Get(key []byte) (SystemSmartContract, error)
Add(key []byte, val SystemSmartContract) error
Replace(key []byte, val SystemSmartContract) error
Remove(key []byte)
Len() int
Keys() [][]byte
IsInterfaceNil() bool
}
// SystemEI defines the environment interface system smart contract can use
type SystemEI interface {
ExecuteOnDestContext(destination []byte, sender []byte, value *big.Int, input []byte) (*vmcommon.VMOutput, error)
DeploySystemSC(baseContract []byte, newAddress []byte, ownerAddress []byte, initFunction string, value *big.Int, input [][]byte) (vmcommon.ReturnCode, error)
Transfer(destination []byte, sender []byte, value *big.Int, input []byte, gasLimit uint64) error
SendGlobalSettingToAll(sender []byte, input []byte)
GetBalance(addr []byte) *big.Int
SetStorage(key []byte, value []byte)
SetStorageForAddress(address []byte, key []byte, value []byte)
AddReturnMessage(msg string)
AddLogEntry(entry *vmcommon.LogEntry)
GetStorage(key []byte) []byte
GetStorageFromAddress(address []byte, key []byte) []byte
Finish(value []byte)
UseGas(gasToConsume uint64) error
GasLeft() uint64
BlockChainHook() BlockchainHook
CryptoHook() vmcommon.CryptoHook
IsValidator(blsKey []byte) bool
StatusFromValidatorStatistics(blsKey []byte) string
CanUnJail(blsKey []byte) bool
IsBadRating(blsKey []byte) bool
CleanStorageUpdates()
GetTotalSentToUser(dest []byte) *big.Int
GetLogs() []*vmcommon.LogEntry
SetOwnerOperatingOnAccount(newOwner []byte) error
UpdateCodeDeployerAddress(scAddress string, newOwner []byte) error
IsInterfaceNil() bool
}
// EconomicsHandler defines the methods to get data from the economics component
type EconomicsHandler interface {
GenesisTotalSupply() *big.Int
IsInterfaceNil() bool
}
// ContextHandler defines the methods needed to execute system smart contracts
type ContextHandler interface {
SystemEI
GetContract(address []byte) (SystemSmartContract, error)
SetSystemSCContainer(scContainer SystemSCContainer) error
CreateVMOutput() *vmcommon.VMOutput
CleanCache()
SetSCAddress(addr []byte)
AddCode(addr []byte, code []byte)
AddTxValueToSmartContract(value *big.Int, scAddress []byte)
SetGasProvided(gasProvided uint64)
GetReturnMessage() string
}
// MessageSignVerifier is used to verify if message was signed with given public key
type MessageSignVerifier interface {
Verify(message []byte, signedMessage []byte, pubKey []byte) error
IsInterfaceNil() bool
}
// ArgumentsParser defines the functionality to parse transaction data into arguments and code for smart contracts
type ArgumentsParser interface {
ParseData(data string) (string, [][]byte, error)
IsInterfaceNil() bool
}
// NodesConfigProvider defines the functionality which is needed for nodes config in system smart contracts
type NodesConfigProvider interface {
MinNumberOfNodes() uint32
MinNumberOfNodesWithHysteresis() uint32
IsInterfaceNil() bool
}
// EpochNotifier can notify upon an epoch change and provide the current epoch
type EpochNotifier interface {
RegisterNotifyHandler(handler vmcommon.EpochSubscriberHandler)
CurrentEpoch() uint32
CheckEpoch(header data.HeaderHandler)
IsInterfaceNil() bool
}
// BlockchainHook is the interface for VM blockchain callbacks
type BlockchainHook interface {
GetStorageData(accountAddress []byte, index []byte) ([]byte, uint32, error)
CurrentNonce() uint64
CurrentRound() uint64
CurrentEpoch() uint32
GetUserAccount(address []byte) (vmcommon.UserAccountHandler, error)
GetCode(account vmcommon.UserAccountHandler) []byte
GetShardOfAddress(address []byte) uint32
IsSmartContract(address []byte) bool
IsPayable(sndAddress []byte, recvAddress []byte) (bool, error)
NumberOfShards() uint32
CurrentRandomSeed() []byte
Close() error
GetSnapshot() int
RevertToSnapshot(snapshot int) error
IsBuiltinFunctionName(functionName string) bool
}