|
|
@ -1,6 +1,8 @@ |
|
|
|
const EventEmitter = require('events').EventEmitter |
|
|
|
const EventEmitter = require('events').EventEmitter |
|
|
|
const inherits = require('util').inherits |
|
|
|
const inherits = require('util').inherits |
|
|
|
|
|
|
|
const async = require('async') |
|
|
|
const ethUtil = require('ethereumjs-util') |
|
|
|
const ethUtil = require('ethereumjs-util') |
|
|
|
|
|
|
|
const EthQuery = require('eth-query') |
|
|
|
const LightwalletKeyStore = require('eth-lightwallet').keystore |
|
|
|
const LightwalletKeyStore = require('eth-lightwallet').keystore |
|
|
|
const clone = require('clone') |
|
|
|
const clone = require('clone') |
|
|
|
const extend = require('xtend') |
|
|
|
const extend = require('xtend') |
|
|
@ -197,35 +199,53 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone |
|
|
|
time: time, |
|
|
|
time: time, |
|
|
|
status: 'unconfirmed', |
|
|
|
status: 'unconfirmed', |
|
|
|
} |
|
|
|
} |
|
|
|
configManager.addTx(txData) |
|
|
|
|
|
|
|
console.log('addUnconfirmedTransaction:', txData) |
|
|
|
console.log('addUnconfirmedTransaction:', txData) |
|
|
|
|
|
|
|
|
|
|
|
// keep the onTxDoneCb around for after approval/denial (requires user interaction)
|
|
|
|
// keep the onTxDoneCb around for after approval/denial (requires user interaction)
|
|
|
|
// This onTxDoneCb fires completion to the Dapp's write operation.
|
|
|
|
// This onTxDoneCb fires completion to the Dapp's write operation.
|
|
|
|
self._unconfTxCbs[txId] = onTxDoneCb |
|
|
|
self._unconfTxCbs[txId] = onTxDoneCb |
|
|
|
|
|
|
|
|
|
|
|
// perform static analyis on the target contract code
|
|
|
|
|
|
|
|
var provider = self._ethStore._query.currentProvider |
|
|
|
var provider = self._ethStore._query.currentProvider |
|
|
|
if (txParams.to) { |
|
|
|
var query = new EthQuery(provider) |
|
|
|
provider.sendAsync({ id: 1, method: 'eth_getCode', params: [txParams.to, 'latest'] }, function (err, res) { |
|
|
|
|
|
|
|
if (err) return didComplete(err) |
|
|
|
// calculate metadata for tx
|
|
|
|
if (res.error) return didComplete(res.error) |
|
|
|
async.parallel([ |
|
|
|
var code = ethUtil.toBuffer(res.result) |
|
|
|
analyzeForDelegateCall, |
|
|
|
if (code !== '0x') { |
|
|
|
estimateGas, |
|
|
|
var ops = ethBinToOps(code) |
|
|
|
], didComplete) |
|
|
|
var containsDelegateCall = ops.some((op) => op.name === 'DELEGATECALL') |
|
|
|
|
|
|
|
txData.containsDelegateCall = containsDelegateCall |
|
|
|
// perform static analyis on the target contract code
|
|
|
|
didComplete() |
|
|
|
function analyzeForDelegateCall(cb){ |
|
|
|
} else { |
|
|
|
if (txParams.to) { |
|
|
|
didComplete() |
|
|
|
query.getCode(txParams.to, function (err, result) { |
|
|
|
} |
|
|
|
if (err) return cb(err) |
|
|
|
|
|
|
|
var code = ethUtil.toBuffer(result) |
|
|
|
|
|
|
|
if (code !== '0x') { |
|
|
|
|
|
|
|
var ops = ethBinToOps(code) |
|
|
|
|
|
|
|
var containsDelegateCall = ops.some((op) => op.name === 'DELEGATECALL') |
|
|
|
|
|
|
|
txData.containsDelegateCall = containsDelegateCall |
|
|
|
|
|
|
|
cb() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
cb() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
cb() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function estimateGas(cb){ |
|
|
|
|
|
|
|
query.estimateGas(txParams, function(err, result){ |
|
|
|
|
|
|
|
if (err) return cb(err) |
|
|
|
|
|
|
|
txData.estimatedGas = result |
|
|
|
|
|
|
|
cb() |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
|
|
|
|
didComplete() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function didComplete (err) { |
|
|
|
function didComplete (err) { |
|
|
|
if (err) return cb(err) |
|
|
|
if (err) return cb(err) |
|
|
|
|
|
|
|
configManager.addTx(txData) |
|
|
|
// signal update
|
|
|
|
// signal update
|
|
|
|
self._didUpdate() |
|
|
|
self._didUpdate() |
|
|
|
// signal completion of add tx
|
|
|
|
// signal completion of add tx
|
|
|
|