|
|
|
@ -1,14 +1,13 @@ |
|
|
|
|
/* global prompt */ |
|
|
|
|
|
|
|
|
|
var $ = require('jquery'); |
|
|
|
|
var EthJSVM = require('ethereumjs-vm'); |
|
|
|
|
var ethJSUtil = require('ethereumjs-util'); |
|
|
|
|
var EthJSTX = require('ethereumjs-tx'); |
|
|
|
|
var ethJSABI = require('ethereumjs-abi'); |
|
|
|
|
var EthJSBlock = require('ethereumjs-block'); |
|
|
|
|
var BN = ethJSUtil.BN; |
|
|
|
|
|
|
|
|
|
function UniversalDApp (contracts, options, transactionDebugger) { |
|
|
|
|
function UniversalDApp (contracts, options, transactionDebugger, vm) { |
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
|
|
self.options = options || {}; |
|
|
|
@ -18,15 +17,13 @@ function UniversalDApp (contracts, options, transactionDebugger) { |
|
|
|
|
|
|
|
|
|
self.web3 = options.web3; |
|
|
|
|
self.transactionDebugger = transactionDebugger; |
|
|
|
|
transactionDebugger.addProvider('EXTERNAL', self.web3); |
|
|
|
|
|
|
|
|
|
if (options.mode === 'vm') { |
|
|
|
|
// FIXME: use `options.vm` or `self.vm` consistently
|
|
|
|
|
options.vm = true; |
|
|
|
|
|
|
|
|
|
self.accounts = {}; |
|
|
|
|
|
|
|
|
|
self.vm = new EthJSVM(null, null, { activatePrecompiles: true, enableHomestead: true }); |
|
|
|
|
transactionDebugger.addProvider('VM', self.vm); |
|
|
|
|
self.vm = vm; |
|
|
|
|
self.addAccount('3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511'); |
|
|
|
|
self.addAccount('2ac6c190b09897cd8987869cc7b918cfea07ee82038d492abce033c75c1b1d0c'); |
|
|
|
|
} else if (options.mode !== 'web3') { |
|
|
|
@ -355,7 +352,7 @@ UniversalDApp.prototype.getCallButton = function (args) { |
|
|
|
|
|
|
|
|
|
var getDebugTransaction = function (result) { |
|
|
|
|
var $debugTx = $('<div class="debugTx">'); |
|
|
|
|
var $button = $('<button class="debug">Debug Transaction</button>'); |
|
|
|
|
var $button = $('<button title="Launch Debugger" class="debug"><i class="fa fa-bug"></i></button>'); |
|
|
|
|
$button.click(function () { |
|
|
|
|
self.transactionDebugger.debug(result); |
|
|
|
|
}); |
|
|
|
@ -365,7 +362,7 @@ UniversalDApp.prototype.getCallButton = function (args) { |
|
|
|
|
|
|
|
|
|
var getDebugCall = function (result) { |
|
|
|
|
var $debugTx = $('<div class="debugCall">'); |
|
|
|
|
var $button = $('<button class="debug">Debug Call</button>'); |
|
|
|
|
var $button = $('<button title="Launch Debugger" class="debug"><i class="fa fa-bug"></i></button>'); |
|
|
|
|
$button.click(function () { |
|
|
|
|
self.transactionDebugger.debug(result); |
|
|
|
|
}); |
|
|
|
@ -666,7 +663,6 @@ UniversalDApp.prototype.runTx = function (data, args, cb) { |
|
|
|
|
|
|
|
|
|
var tx; |
|
|
|
|
if (!self.vm) { |
|
|
|
|
self.transactionDebugger.switchProvider('EXTERNAL'); |
|
|
|
|
tx = { |
|
|
|
|
from: self.options.getAddress ? self.options.getAddress() : self.web3.eth.accounts[0], |
|
|
|
|
to: to, |
|
|
|
@ -699,7 +695,6 @@ UniversalDApp.prototype.runTx = function (data, args, cb) { |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
try { |
|
|
|
|
self.transactionDebugger.switchProvider('VM'); |
|
|
|
|
var address = self.options.getAddress ? self.options.getAddress() : self.getAccounts()[0]; |
|
|
|
|
var account = self.accounts[address]; |
|
|
|
|
tx = new EthJSTX({ |
|
|
|
@ -720,9 +715,7 @@ UniversalDApp.prototype.runTx = function (data, args, cb) { |
|
|
|
|
uncleHeaders: [] |
|
|
|
|
}); |
|
|
|
|
self.vm.runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (err, result) { |
|
|
|
|
if (self.vm) { |
|
|
|
|
result.transactionHash = self.transactionDebugger.web3().releaseCurrentHash(); // used to keep track of the transaction
|
|
|
|
|
} |
|
|
|
|
result.transactionHash = self.transactionDebugger.web3().releaseCurrentHash(); // used to keep track of the transaction
|
|
|
|
|
cb(err, result); |
|
|
|
|
}); |
|
|
|
|
} catch (e) { |
|
|
|
|