https://github.com/ethereumjs/ethereumjs-vm/blob/master/docs/index.md
vm.runBlockchain
Processes blocks and adds them to the blockchain
处理区块并将其添加到区块链中
Parameters输入参数
-
blockchainBlockchain A blockchain that to process 一个处理的区块链
-
cbFunction the callback function 回调函数
VM
VM Class, new VM(opts) creates a new VM object
VM类,VM(opts)将创建一个VM对象,运行起来实现的感觉与ganache相似
Parameters输入参数
-
optsObject
-
opts.stateManagerStateManager aStateManagerinstance to use as the state store (Beta API) 用于状态存储的StateManager实例(还在实验阶段)其实这个就是区块上的state merkle-patricia树,用于存储区块上的所有账户的信息
-
opts.stateTrie a merkle-patricia-tree instance for the state tree (ignored if stateManager is passed) 用于状态树的一个merkle-patricia树(如果上面的stateManager已经传递,这个就可以忽略)
-
opts.blockchainBlockchain a blockchain object for storing/retrieving blocks (ignored if stateManager is passed) 为了存储/检索区块的区块链对象(如果上面的stateManager已经传递,这个就可以忽略)
-
opts.chain(String | Number) the chain the VM operates on [default: 'mainnet'] VM操作在那个链上(默认是mainnet链)
-
opts.hardforkString hardfork rules to be used [default: 'byzantium', supported: 'byzantium', 'constantinople' (will throw on unsupported)] 使用的硬分支规则(默认是byzantium',还支持'byzantium', 'constantinople',如果输入的是不支持的将抛出错误)
-
opts.activatePrecompilesBoolean create entries in the state tree for the precompiled contracts 为了预编译合约在状态树上创建条目,其实就是在state merkle-patricia树上手动添加一些账户的信息,就跟ganache一样,一开始就有可用的账户
-
opts.allowUnlimitedContractSizeBoolean allows unlimited contract sizes while debugging. By setting this totrue, the check for contract size limit of 24KB (see EIP-170) is bypassed. (default:false; ONLY set totrueduring debugging) 当调试时,允许不限制的合约大小。通过将其设置为true,来忽视合约大小设置为24KB的检查(细节看本博客ethereum/EIPs-170 Contract code size limit)。(默认为false,只在调试时设置为true)
-
opts.emitFreeLogsBoolean Changes the behavior of the LOG opcode, the gas cost of the opcode becomes zero and calling it using STATICCALL won't throw. (default:false; ONLY set totrueduring debugging) 改变日志操作吗的行为,gas开销的操作码变为0,使用STATICCALL操作码调用它将抛出错误(默认为false,只有在调试时设置为true)
-
vm.runBlock
Processes the block running all of the transactions it contains and updating the miner's account
处理区块,运行其中的所有交易并更新矿工账户
Parameters输入参数
-
opts -
cbrunBlock~callback callback 回调函数
runBlock~callback
Callback for runBlock method
runBlock的回调
Type: Function
Parameters输入参数
-
errorError an error that may have happened ornull 发生的错误或null -
resultsObject-
results.receiptsArray the receipts from the transactions in the block 区块中来自交易的receipt
-
results.resultsArray 返回结果
-
vm.runTx
Process a transaction. Run the vm. Transfers eth. Checks balances.
处理交易。运行虚拟机。交易eth。查看余额。
Parameters输入参数
-
opts-
opts.txTransaction aTransactionto run 运行的交易
-
opts.skipNonceBoolean skips the nonce check 跳过nonce检查
-
opts.skipBalanceBoolean skips the balance check 跳过余额检查
-
opts.blockBlock the block to which thetxbelongs, if no block is given a default one is created 交易属于的区块,如果没有,则创建一个默认块
-
-
cbrunTx~callback the callback 回调函数
runTx~callback
Callback for runTx method
runTx方法的回调
Type: Function
Parameters输入参数
-
errorError an error that may have happened ornull发生的错误或null -
resultsObject-
results.amountSpentBN the amount of ether used by this transaction as abignum 被这个交易使用的ether的数量,BN格式 -
results.gasUsedBN the amount of gas as abignumused by the transaction 被这个交易使用的gas,BN格式
-
results.gasRefundBN the amount of gas as abignumthat was refunded during the transaction (i.e.gasUsed = totalGasConsumed - gasRefund) 在交易中被退还的gas,BN格式(使用的gas = 总使用的gas - 退还的gas)
-
-
vmVM contains the results from running the code, if any, as described invm.runCode(params, cb) 虚拟机,如果存在,包含通过运行代码得到的结果,就像vm.runCode(params, cb)所说
vm.runCode
Runs EVM code
运行以太坊虚拟机代码
Parameters输入参数
-
optsObject-
opts.accountAccount theAccountthat the executing code belongs to. If omitted an empty account will be used 执行的代码属于的账户。如果省略则使用空账户
-
opts.addressBuffer the address of the account that is executing this code. The address should be aBufferof bytes. Defaults to0 执行这个代码的账户的地址。地址应该是字节的buffer格式。默认为0 -
opts.blockBlock theBlockthetxbelongs to. If omitted a blank block will be used 这个交易属于的区块。如果省略则使用一个黑块
-
opts.callerBuffer the address that ran this code. The address should be aBufferof 20bits. Defaults to0 运行这个代码的地址。这个地址应该为20bits的buffer格式,默认为0 -
opts.codeBuffer the EVM code to run given as aBuffer 以buffer格式给出的用来运行的以太坊虚拟机的代码 -
opts.dataBuffer the input data 输入的数据
-
opts.gasLimitBuffer the gas limit for the code 这个代码使用的gas的限制
-
opts.originBuffer the address where the call originated from. The address should be aBufferof 20bits. Defaults to0 这个调用起源的地址。这个地址应该为20bits的buffer格式,默认为0 -
opts.valueBuffer the value in ether that is being sent toopt.address. Defaults to0 被送给opt.address的ether。默认为0
-
-
cbrunCode~callback callback 回调函数
runCode~callback
Callback for runCode method
runCode方法的回调
Type: Function
Parameters输入参数
-
errorError an error that may have happened ornull发生的错误或null -
resultsObject-
results.gasBN the amount of gas left 剩下的gas数量
-
results.gasUsedBN the amount of gas as abignumthe code used to run 以bignum格式给出的这个代码用来运行的gas数量
-
results.gasRefundBN abignumcontaining the amount of gas to refund from deleting storage values从删除的存储值中得到包含退还的gas的数量的大数 -
results.selfdestructObject anObjectwith keys for accounts that have selfdestructed and values for balance transfer recipient accounts 包含自我毁灭的账户密钥和转移接收账户余额的值的对象
-
results.logsArray anArrayof logs that the contract emitted 合约发出的日志数组
-
results.exceptionNumber0if the contract encountered an exception,1otherwise 如果合约遇到了异常则为0,否则为1
-
results.exceptionErrorString aStringdescribing the exception if there was one 如果有异常则用来描述异常的字符串
-
results.returnBuffer aBuffercontaining the value that was returned by the contract 包含被合约返回的值的buffer
-
Event: beforeBlock
The beforeBlock event beforeBlock事件
Type: Object
Properties属性
-
blockBlock emits the block that is about to be processed 发出关于将要被处理的区块
Event: afterBlock
The afterBlock event afterBlock事件
Type: Object
Properties属性
-
resultObject emits the results of processing a block 发出处理的区块的结果
Event: beforeTx
The beforeTx event
Type: Object
Properties
-
txTransaction emits the Transaction that is about to be processed 发出将要被处理的交易
Event: afterTx
The afterTx event
Type: Object
Properties
-
resultObject result of the transaction 交易的结果
Event: step
The step event for trace output追踪输出的step事件
Type: Object
Properties
-
pcNumber representing the program counter 代表项目的计数
-
opcodeString the next opcode to be ran 下一个运行的操作码
-
gasLeftBN amount of gasLeft 剩下的gas数量
-
stackArray anArrayofBufferscontaining the stack 包含堆栈的Buffers数组
-
accountAccount theAccountwhich owns the code running 拥有运行代码的账户
-
addressBuffer the address of theaccount 账户的地址 -
depthNumber the current number of calls deep the contract is 合约所在的目前的调用深度数
-
memoryBuffer the memory of the VM as abuffer 虚拟机的内存 -
stateManagerStateManager aStateManagerinstance (Beta API) 一个StateManager实例