Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
deps - update provider-engine
Browse files Browse the repository at this point in the history
  • Loading branch information
kumavis committed Mar 15, 2016
1 parent 86f49db commit 043e680
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 42 deletions.
44 changes: 8 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down

0 comments on commit 043e680

Please sign in to comment.