|
|
@ -1,21 +1,30 @@ |
|
|
|
const async = require('async') |
|
|
|
import { waterfall } from 'async' |
|
|
|
const { BN, privateToAddress, isValidPrivate, stripHexPrefix, toChecksumAddress } = require('ethereumjs-util') |
|
|
|
import { BN, privateToAddress, isValidPrivate, toChecksumAddress } from 'ethereumjs-util' |
|
|
|
const crypto = require('crypto') |
|
|
|
import { stripHexPrefix } from 'ethjs-util' |
|
|
|
const { EventEmitter } = require('events') |
|
|
|
import { randomBytes } from 'crypto' |
|
|
|
|
|
|
|
import { EventEmitter } from 'events' |
|
|
|
const TxRunner = require('./execution/txRunner') |
|
|
|
|
|
|
|
const txHelper = require('./execution/txHelper') |
|
|
|
import { TxRunner } from './execution/txRunner' |
|
|
|
const EventManager = require('./eventManager') |
|
|
|
import { sortAbiFunction, getFallbackInterface, getReceiveInterface, inputParametersDeclarationToString } from './execution/txHelper' |
|
|
|
const defaultExecutionContext = require('./execution/execution-context') |
|
|
|
import { EventManager } from './eventManager' |
|
|
|
const { resultToRemixTx } = require('./helpers/txResultHelper') |
|
|
|
import { ExecutionContext } from './execution/execution-context' |
|
|
|
|
|
|
|
import { resultToRemixTx } from './helpers/txResultHelper' |
|
|
|
module.exports = class UniversalDApp { |
|
|
|
|
|
|
|
|
|
|
|
export class UniversalDApp { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
events |
|
|
|
|
|
|
|
event |
|
|
|
|
|
|
|
executionContext |
|
|
|
|
|
|
|
config |
|
|
|
|
|
|
|
txRunner |
|
|
|
|
|
|
|
accounts |
|
|
|
|
|
|
|
transactionContextAPI |
|
|
|
|
|
|
|
|
|
|
|
constructor (config, executionContext) { |
|
|
|
constructor (config, executionContext) { |
|
|
|
this.events = new EventEmitter() |
|
|
|
this.events = new EventEmitter() |
|
|
|
this.event = new EventManager() |
|
|
|
this.event = new EventManager() |
|
|
|
// has a default for now for backwards compatability
|
|
|
|
// has a default for now for backwards compatability
|
|
|
|
this.executionContext = executionContext || defaultExecutionContext |
|
|
|
this.executionContext = executionContext || new ExecutionContext() |
|
|
|
this.config = config |
|
|
|
this.config = config |
|
|
|
|
|
|
|
|
|
|
|
this.txRunner = new TxRunner({}, { |
|
|
|
this.txRunner = new TxRunner({}, { |
|
|
@ -97,7 +106,7 @@ module.exports = class UniversalDApp { |
|
|
|
} |
|
|
|
} |
|
|
|
let privateKey |
|
|
|
let privateKey |
|
|
|
do { |
|
|
|
do { |
|
|
|
privateKey = crypto.randomBytes(32) |
|
|
|
privateKey = randomBytes(32) |
|
|
|
} while (!isValidPrivate(privateKey)) |
|
|
|
} while (!isValidPrivate(privateKey)) |
|
|
|
this._addAccount(privateKey, '0x56BC75E2D63100000') |
|
|
|
this._addAccount(privateKey, '0x56BC75E2D63100000') |
|
|
|
cb(null, '0x' + privateToAddress(privateKey).toString('hex')) |
|
|
|
cb(null, '0x' + privateToAddress(privateKey).toString('hex')) |
|
|
@ -247,22 +256,22 @@ module.exports = class UniversalDApp { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getABI (contract) { |
|
|
|
getABI (contract) { |
|
|
|
return txHelper.sortAbiFunction(contract.abi) |
|
|
|
return sortAbiFunction(contract.abi) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getFallbackInterface (contractABI) { |
|
|
|
getFallbackInterface (contractABI) { |
|
|
|
return txHelper.getFallbackInterface(contractABI) |
|
|
|
return getFallbackInterface(contractABI) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getReceiveInterface (contractABI) { |
|
|
|
getReceiveInterface (contractABI) { |
|
|
|
return txHelper.getReceiveInterface(contractABI) |
|
|
|
return getReceiveInterface(contractABI) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getInputs (funABI) { |
|
|
|
getInputs (funABI) { |
|
|
|
if (!funABI.inputs) { |
|
|
|
if (!funABI.inputs) { |
|
|
|
return '' |
|
|
|
return '' |
|
|
|
} |
|
|
|
} |
|
|
|
return txHelper.inputParametersDeclarationToString(funABI.inputs) |
|
|
|
return inputParametersDeclarationToString(funABI.inputs) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -309,7 +318,7 @@ module.exports = class UniversalDApp { |
|
|
|
|
|
|
|
|
|
|
|
runTx (args, confirmationCb, continueCb, promptCb, cb) { |
|
|
|
runTx (args, confirmationCb, continueCb, promptCb, cb) { |
|
|
|
const self = this |
|
|
|
const self = this |
|
|
|
async.waterfall([ |
|
|
|
waterfall([ |
|
|
|
function getGasLimit (next) { |
|
|
|
function getGasLimit (next) { |
|
|
|
if (self.transactionContextAPI.getGasLimit) { |
|
|
|
if (self.transactionContextAPI.getGasLimit) { |
|
|
|
return self.transactionContextAPI.getGasLimit(next) |
|
|
|
return self.transactionContextAPI.getGasLimit(next) |
|
|
|