|
|
|
@ -13,12 +13,14 @@ class TxRunner { |
|
|
|
|
this.blockNumber = 0 |
|
|
|
|
this.runAsync = true |
|
|
|
|
if (executionContext.isVM()) { |
|
|
|
|
this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block.
|
|
|
|
|
//this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block.
|
|
|
|
|
this.blockNumber = 1 // The VM is running in Homestead mode, which started at this block.
|
|
|
|
|
this.runAsync = false // We have to run like this cause the VM Event Manager does not support running multiple txs at the same time.
|
|
|
|
|
} |
|
|
|
|
this.pendingTxs = {} |
|
|
|
|
this.vmaccounts = vmaccounts |
|
|
|
|
this.queusTxs = [] |
|
|
|
|
this.blocks = [] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rawRun (args, confirmationCb, gasEstimationForceSend, promptCb, cb) { |
|
|
|
@ -115,11 +117,16 @@ class TxRunner { |
|
|
|
|
header: { |
|
|
|
|
timestamp: timestamp || (new Date().getTime() / 1000 | 0), |
|
|
|
|
number: self.blockNumber, |
|
|
|
|
coinbase: coinbases[self.blockNumber % coinbases.length], |
|
|
|
|
difficulty: difficulties[self.blockNumber % difficulties.length], |
|
|
|
|
gasLimit: new BN(gasLimit, 10).imuln(2) |
|
|
|
|
// coinbase: coinbases[self.blockNumber % coinbases.length],
|
|
|
|
|
// difficulty: difficulties[self.blockNumber % difficulties.length],
|
|
|
|
|
// coinbase: coinbases[0],
|
|
|
|
|
//difficulty: difficulties[0],
|
|
|
|
|
coinbase: coinbases[0], |
|
|
|
|
// gasLimit: new BN(gasLimit, 10).imuln(200),
|
|
|
|
|
gasLimit: new BN("5000000").imuln(1) |
|
|
|
|
}, |
|
|
|
|
transactions: [], |
|
|
|
|
transactions: [tx], |
|
|
|
|
//transactions: [],
|
|
|
|
|
uncleHeaders: [] |
|
|
|
|
}) |
|
|
|
|
if (!useCall) { |
|
|
|
@ -128,17 +135,90 @@ class TxRunner { |
|
|
|
|
executionContext.vm().stateManager.checkpoint(() => {}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
executionContext.vm().runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (err, result) { |
|
|
|
|
if (useCall) { |
|
|
|
|
executionContext.vm().stateManager.revert(function () {}) |
|
|
|
|
} |
|
|
|
|
err = err ? err.message : err |
|
|
|
|
if (result) { |
|
|
|
|
result.status = '0x' + result.vm.exception.toString(16) |
|
|
|
|
} |
|
|
|
|
callback(err, { |
|
|
|
|
result: result, |
|
|
|
|
transactionHash: ethJSUtil.bufferToHex(Buffer.from(tx.hash())) |
|
|
|
|
//block.transactions.push(tx);
|
|
|
|
|
|
|
|
|
|
this.checkpointAndCommit(() => { |
|
|
|
|
|
|
|
|
|
//executionContext.vm().blockchain.getLatestBlock((a, b) => {
|
|
|
|
|
|
|
|
|
|
// console.dir("b.hash()")
|
|
|
|
|
// console.dir(b.hash())
|
|
|
|
|
// console.dir(b.hash().length)
|
|
|
|
|
// console.dir(b.hash().toString('hex'))
|
|
|
|
|
// console.dir(b.hash().toString('hex').length)
|
|
|
|
|
|
|
|
|
|
// block.header.parentHash = b.hash()
|
|
|
|
|
|
|
|
|
|
// block.header.parentHash = b.hash().toString('hex')
|
|
|
|
|
|
|
|
|
|
//block.header.parentHash = Buffer.from(b.hash(), 'hex')
|
|
|
|
|
//block.header.parentHash = "4599f6765f1d5a50Bf1E3DBFa14A72dF"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// block.header.parentHash = b.hash()
|
|
|
|
|
// block.header.difficulty = block.header.canonicalDifficulty(b)
|
|
|
|
|
|
|
|
|
|
//executionContext.vm().runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (err, result) {
|
|
|
|
|
executionContext.vm().runBlock({block: block, generate: true, skipBlockValidation: true, skipBalance: false}, function (err, results) { |
|
|
|
|
console.dir("-- runBlock result") |
|
|
|
|
console.dir(err) |
|
|
|
|
//console.dir(results)
|
|
|
|
|
let result = results.results[0] |
|
|
|
|
console.dir(result) |
|
|
|
|
if (useCall) { |
|
|
|
|
executionContext.vm().stateManager.revert(function () {}) |
|
|
|
|
} |
|
|
|
|
err = err ? err.message : err |
|
|
|
|
if (result) { |
|
|
|
|
result.status = '0x' + result.vm.exception.toString(16) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//executionContext.vm().blockchain.putBlock(block, (err, savedBlock) => {
|
|
|
|
|
|
|
|
|
|
executionContext.addBlock(block) |
|
|
|
|
executionContext.trackTx("0x" + tx.hash().toString('hex'), block) |
|
|
|
|
|
|
|
|
|
// result.blockHash = "0x" + block.hash().toString('hex')
|
|
|
|
|
// result.blockNumber = "0x" + block.header.number.toString('hex')
|
|
|
|
|
|
|
|
|
|
callback(err, { |
|
|
|
|
result: result, |
|
|
|
|
transactionHash: ethJSUtil.bufferToHex(Buffer.from(tx.hash())) |
|
|
|
|
}) |
|
|
|
|
//})
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
//})
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
checkpointAndCommit (cb) { |
|
|
|
|
console.dir("------------------------") |
|
|
|
|
console.dir("------------------------") |
|
|
|
|
console.dir("------------------------") |
|
|
|
|
console.dir("------------------------") |
|
|
|
|
console.dir("------------------------") |
|
|
|
|
console.dir("------------------------") |
|
|
|
|
console.dir(executionContext.vm().stateManager._checkpointCount) |
|
|
|
|
console.dir("------------------------") |
|
|
|
|
console.dir("------------------------") |
|
|
|
|
console.dir("------------------------") |
|
|
|
|
console.dir("------------------------") |
|
|
|
|
console.dir("------------------------") |
|
|
|
|
console.dir("------------------------") |
|
|
|
|
if (executionContext.vm().stateManager._checkpointCount > 0) { |
|
|
|
|
return executionContext.vm().stateManager.commit(() => { |
|
|
|
|
cb() |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
executionContext.vm().stateManager.checkpoint(() => { |
|
|
|
|
executionContext.vm().stateManager.commit(() => { |
|
|
|
|
cb() |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|