diff --git a/index.js b/index.js index c655385..98d7bb2 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,8 @@ const Transaction = require('ethereumjs-tx') const ProviderEngine = require('web3-provider-engine') const RpcSubprovider = require('web3-provider-engine/subproviders/rpc.js') -const HookedWalletSubprovider = require('web3-provider-engine/subproviders/hooked-wallet.js') +const PkHookedWalletSubprovider = require('web3-provider-engine/subproviders/hooked-wallet-ethtx.js') +const NonceSubprovider = require('web3-provider-engine/subproviders/nonce-tracker.js') module.exports = rpcWrapperEngine @@ -14,52 +15,23 @@ function rpcWrapperEngine(opts){ var privateKey = opts.privateKey var addresses = [opts.addressHex] - engine.addProvider(new HookedWalletSubprovider({ + engine.addProvider(new PkHookedWalletSubprovider({ getAccounts: function(cb){ cb(null, addresses) }, - signTransaction: function(txParams, cb){ - try { - // console.log('signing tx:', txParams) - var tx = new Transaction({ - nonce: txParams.nonce, - to: txParams.to, - value: txParams.value, - data: txParams.input, - gasPrice: txParams.gasPrice, - gasLimit: txParams.gas, - }) - tx.sign(privateKey) - var serializedTx = '0x'+tx.serialize().toString('hex') - - // deserialize and dump values to confirm configuration - var verifyTx = new Transaction(tx.serialize()) - console.log('signed transaction:', { - to: '0x'+verifyTx.to.toString('hex'), - from: '0x'+verifyTx.from.toString('hex'), - nonce: '0x'+verifyTx.nonce.toString('hex'), - value: (ethUtil.bufferToInt(verifyTx.value)/1e18)+' ether', - data: '0x'+verifyTx.data.toString('hex'), - gasPrice: '0x'+verifyTx.gasPrice.toString('hex'), - gasLimit: '0x'+verifyTx.gasLimit.toString('hex'), - }) - cb(null, serializedTx) - } catch (err) { - cb(err) - } + getPrivateKey: function(from, cb){ + cb(null, privateKey) }, })) + + // pending nonce + engine.addProvider(new NonceSubprovider()) // data source engine.addProvider(new RpcSubprovider({ rpcUrl: opts.rpcUrl, })) - // log new blocks - // engine.on('block', function(block){ - // console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex')) - // }) - // start polling engine.start() diff --git a/package.json b/package.json index 734e76e..f7cbe6d 100644 --- a/package.json +++ b/package.json @@ -5,16 +5,16 @@ "description": "", "main": "index.js", "dependencies": { - "body-parser": "^1.14.1", + "body-parser": "^1.15.0", "browserify": "^13.0.0", "cors": "^2.7.1", - "ethereumjs-tx": "^0.7.1", + "ethereumjs-tx": "^0.7.3", "ethereumjs-util": "^2.6.0", - "express": "^4.13.3", + "express": "^4.13.4", "h": "^0.1.0", - "request": "^2.66.0", - "web3": "^0.15.1", - "web3-provider-engine": "^3.3.0", + "request": "^2.69.0", + "web3": "^0.15.3", + "web3-provider-engine": "^7.0.0", "xtend": "^4.0.1" }, "devDependencies": {},