remove old code

pull/1/head
Iuri Matias 7 years ago
parent 0d2a7d3530
commit ccd7ad028e
  1. 95
      src/universal-dapp.js

@ -261,99 +261,4 @@ UniversalDApp.prototype.runTx = function (args, cb) {
], cb)
}
UniversalDApp.prototype.runTx = function (args, cb) {
var self = this
var tx = { to: args.to, data: args.data.dataHex, useCall: args.useCall, from: args.from, value: args.value }
var payLoad = { funAbi: args.data.funAbi, funArgs: args.data.funArgs, contractBytecode: args.data.contractBytecode, contractName: args.data.contractName } // contains decoded parameters
var pipeline = [queryGasLimit]
if (!args.value) {
pipeline.push(queryValue)
}
if (!args.from) {
pipeline.push(queryAddress)
}
pipeline.push(runTransaction)
var env = { self, tx, payLoad }
execute(pipeline, env, cb)
}
function execute (pipeline, env, callback) {
function next (err, env) {
if (err) return callback(err)
var step = pipeline.shift()
if (step) step(env, next)
else callback(null, env.result)
}
next(null, env)
}
function queryGasLimit (env, next) {
var { self, tx } = env
tx.gasLimit = 3000000
if (self.transactionContextAPI.getGasLimit) {
self.transactionContextAPI.getGasLimit(function (err, ret) {
if (err) return next(err)
tx.gasLimit = ret
next(null, env)
})
} else next(null, env)
}
function queryValue (env, next) {
var { self, tx } = env
tx.value = 0
if (tx.useCall) return next(null, env)
if (self.transactionContextAPI.getValue) {
self.transactionContextAPI.getValue(function (err, ret) {
if (err) return next(err)
tx.value = ret
next(null, env)
})
} else next(null, env)
}
function queryAddress (env, next) {
var { self, tx } = env
if (self.transactionContextAPI.getAddress) {
self.transactionContextAPI.getAddress(function (err, ret) {
if (err) return next(err)
tx.from = ret
next(null, env)
})
} else {
self.getAccounts(function (err, ret) {
if (err) return next(err)
if (ret.length === 0) return next('No accounts available')
if (executionContext.isVM() && !self.accounts[ret[0]]) {
return next('Invalid account selected')
}
tx.from = ret[0]
next(null, env)
})
}
}
function runTransaction (env, next) {
var { self, tx, payLoad } = env
var timestamp = Date.now()
self.event.trigger('initiatingTransaction', [timestamp, tx, payLoad])
self.txRunner.rawRun(tx, function (error, result) {
if (!tx.useCall) {
self.event.trigger('transactionExecuted', [error, tx.from, tx.to, tx.data, false, result, timestamp, payLoad])
} else {
self.event.trigger('callExecuted', [error, tx.from, tx.to, tx.data, true, result, timestamp, payLoad])
}
if (error) {
if (typeof (error) !== 'string') {
if (error.message) error = error.message
else {
try { error = 'error: ' + JSON.stringify(error) } catch (e) {}
}
}
}
env.result = result
next(error, env)
})
}
module.exports = UniversalDApp

Loading…
Cancel
Save