Commit 710cf55e authored by Iuri Matias's avatar Iuri Matias

simplify txRunner

parent facd5a47
...@@ -77,22 +77,21 @@ class TxRunner { ...@@ -77,22 +77,21 @@ class TxRunner {
} }
} }
execute (args, confirmationCb, gasEstimationForceSend, promptCb, callback) { execute(args, confirmationCb, gasEstimationForceSend, promptCb, callback) {
let data = args.data let data = args.data
if (data.slice(0, 2) !== '0x') { if (data.slice(0, 2) !== '0x') {
data = '0x' + data data = '0x' + data
} }
if (!this.executionContext.isVM()) { if (!this.executionContext.isVM()) {
this.runInNode(args.from, args.to, data, args.value, args.gasLimit, args.useCall, confirmationCb, gasEstimationForceSend, promptCb, callback) return this.runInNode(args.from, args.to, data, args.value, args.gasLimit, args.useCall, confirmationCb, gasEstimationForceSend, promptCb, callback)
} else { }
try { try {
this.runInVm(args.from, args.to, data, args.value, args.gasLimit, args.useCall, args.timestamp, callback) this.runInVm(args.from, args.to, data, args.value, args.gasLimit, args.useCall, args.timestamp, callback)
} catch (e) { } catch (e) {
callback(e, null) callback(e, null)
} }
} }
}
runInVm (from, to, data, value, gasLimit, useCall, timestamp, callback) { runInVm (from, to, data, value, gasLimit, useCall, timestamp, callback) {
const self = this const self = this
...@@ -228,9 +227,8 @@ async function tryTillReceiptAvailable (txhash, executionContext) { ...@@ -228,9 +227,8 @@ async function tryTillReceiptAvailable (txhash, executionContext) {
// Try again with a bit of delay if error or if result still null // Try again with a bit of delay if error or if result still null
await pause() await pause()
return resolve(await tryTillReceiptAvailable(txhash, executionContext)) return resolve(await tryTillReceiptAvailable(txhash, executionContext))
} else {
return resolve(receipt)
} }
return resolve(receipt)
}) })
}) })
} }
...@@ -242,21 +240,20 @@ async function tryTillTxAvailable (txhash, executionContext) { ...@@ -242,21 +240,20 @@ async function tryTillTxAvailable (txhash, executionContext) {
// Try again with a bit of delay if error or if result still null // Try again with a bit of delay if error or if result still null
await pause() await pause()
return resolve(await tryTillTxAvailable(txhash, executionContext)) return resolve(await tryTillTxAvailable(txhash, executionContext))
} else {
return resolve(tx)
} }
return resolve(tx)
}) })
}) })
} }
async function pause () { return new Promise((resolve, reject) => { setTimeout(resolve, 500) }) } async function pause () { return new Promise((resolve, reject) => { setTimeout(resolve, 500) }) }
function run (self, tx, stamp, confirmationCb, gasEstimationForceSend, promptCb, callback) { function run(self, tx, stamp, confirmationCb, gasEstimationForceSend, promptCb, callback) {
if (!self.runAsync && Object.keys(self.pendingTxs).length) { if (!self.runAsync && Object.keys(self.pendingTxs).length) {
self.queusTxs.push({ tx, stamp, callback }) return self.queusTxs.push({ tx, stamp, callback })
} else { }
self.pendingTxs[stamp] = tx self.pendingTxs[stamp] = tx
self.execute(tx, confirmationCb, gasEstimationForceSend, promptCb, function(error, result) { self.execute(tx, confirmationCb, gasEstimationForceSend, promptCb, function (error, result) {
delete self.pendingTxs[stamp] delete self.pendingTxs[stamp]
if (callback && typeof callback === 'function') callback(error, result) if (callback && typeof callback === 'function') callback(error, result)
if (self.queusTxs.length) { if (self.queusTxs.length) {
...@@ -264,7 +261,6 @@ function run (self, tx, stamp, confirmationCb, gasEstimationForceSend, promptCb, ...@@ -264,7 +261,6 @@ function run (self, tx, stamp, confirmationCb, gasEstimationForceSend, promptCb,
run(self, next.tx, next.stamp, next.callback) run(self, next.tx, next.stamp, next.callback)
} }
}) })
}
} }
module.exports = TxRunner module.exports = TxRunner
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment