DVM 解释器,核心
包含了代码、状态、变量等信息。
解释、运行代码
存储临时数据
DVM_Interpreter
type DVM_Interpreter struct {
SCID string
SC *SmartContract
EntryPoint string
f Function
IP uint64 // current line number
ReturnValue Variable // Result of current function call
Locals map[string]Variable // all local variables
Chain_inputs *Blockchain_Input // all blockchain info is available here
State *Shared_State // all shared state between DVM is available here
RND *RND // this is initialized only once while invoking entrypoint
store *TX_Storage // mechanism to access a data store, can discard changes
}
区别于合约代码存储于交易上,持久化数据可另外存储,状态、临时变量可直接存放在解释器里。
Blockchain_Input
与链的结合(在智能合约里可用的和区块链有关的变量)
// this structure is all the inputs that are available to SC during execution
type Blockchain_Input struct {
SCID crypto.Key // current smart contract which is executing
BLID crypto.Key // BLID
TXID crypto.Key // current TXID under which TX
Signer address.Address // address which signed this
BL_HEIGHT uint64 // current chain height under which current tx is valid
BL_TOPOHEIGHT uint64 // current block topo height which can be used to uniquely pinpoint the block
}
Shared_State
共享状态
// all DVMs triggered by the first call, will share this structure
// sharing this structure means RND number attacks are not possible
// all storage state is shared, this means something similar to solidity delegatecall
// this is necessary to prevent number of attacks
type Shared_State struct {
Persistance bool // whether the results will be persistant or it's just a demo/test call
Chain_inputs *Blockchain_Input // all blockchain info is available here
DERO_Balance uint64 // DERO balance of this smart contract, this is loaded
// this includes any DERO that has arrived with this TX
DERO_Received uint64 // amount of DERO received with this TX
DERO_Transfer map[string]uint64 // any DERO that this TX wants to send OUT
// transfers are only processed after the contract has terminated successfully
RND *RND // this is initialized only once while invoking entrypoint
Store *TX_Storage // mechanism to access a data store, can discard changes
Monitor_recursion int64 // used to control recursion amount 64 calls are more than necessary
Monitor_lines_interpreted int64 // number of lines interpreted
Monitor_ops int64 // number of ops evaluated, for expressions, variables
}