ethereumjs-connect
Advanced tools
Comparing version 2.2.0 to 2.3.0
62
index.js
@@ -20,3 +20,3 @@ /** | ||
version: "2.2.0", | ||
version: "2.3.0", | ||
@@ -30,3 +30,2 @@ debug: false, | ||
networkID: null, | ||
blockNumber: null, | ||
contracts: null, | ||
@@ -44,3 +43,2 @@ allContracts: null, | ||
networkID: null, | ||
blockNumber: null, | ||
contracts: null, | ||
@@ -81,6 +79,11 @@ allContracts: null, | ||
if (!isFunction(callback)) { | ||
this.rpc.gasPrice = parseInt(this.rpc.getGasPrice(), 16); | ||
var gasPrice = this.rpc.getGasPrice(); | ||
console.log('GAS PRICE:', gasPrice); | ||
if (!gasPrice) throw new Error("setGasPrice failed"); | ||
if (gasPrice.error) throw new Error(gasPrice.error); | ||
this.rpc.gasPrice = parseInt(gasPrice, 16); | ||
} else { | ||
this.rpc.getGasPrice(function (gasPrice) { | ||
if (!gasPrice || gasPrice.error) return callback(gasPrice); | ||
if (!gasPrice) return callback(new Error("setGasPrice failed")); | ||
if (gasPrice.error) return callback(new Error(gasPrice.error)); | ||
self.rpc.gasPrice = parseInt(gasPrice, 16); | ||
@@ -95,8 +98,10 @@ callback(null); | ||
if (!isFunction(callback)) { | ||
this.state.networkID = this.rpc.version(); | ||
var version = this.rpc.version(); | ||
if (version === null || version === undefined) throw new Error("setNetworkID failed"); | ||
if (version.error) throw new Error(version.error); | ||
this.state.networkID = version; | ||
} else { | ||
this.rpc.version(function (version) { | ||
if (version === null || version === undefined || version.error) { | ||
return callback(version); | ||
} | ||
if (version === null || version === undefined) return callback(new Error("setNetworkID failed")); | ||
if (version.error) return callback(new Error(version.error)); | ||
self.state.networkID = version; | ||
@@ -108,16 +113,25 @@ callback(null); | ||
setBlockNumber: function (callback) { | ||
setLatestBlock: function (callback) { | ||
var self = this; | ||
if (this.rpc.block !== null && this.rpc.block.number) { | ||
this.state.blockNumber = this.rpc.block.number; | ||
if (this.rpc.block !== null && this.rpc.block.number && this.rpc.block.timestamp) { | ||
if (isFunction(callback)) callback(null); | ||
} else { | ||
if (!isFunction(callback)) { | ||
this.rpc.block = {number: this.rpc.blockNumber()}; | ||
this.state.blockNumber = this.rpc.block.number; | ||
var blockNumber = this.rpc.blockNumber(); | ||
if (!blockNumber) throw new Error("setLatestBlock failed"); | ||
if (blockNumber.error) throw new Error(blockNumber.error); | ||
var block = this.rpc.getBlock(blockNumber, false); | ||
if (!block) throw new Error("setLatestBlock failed"); | ||
if (block.error) throw new Error(block.error); | ||
this.rpc.onNewBlock(block); | ||
} else { | ||
this.rpc.blockNumber(function (blockNumber) { | ||
self.rpc.block = {number: parseInt(blockNumber, 16)}; | ||
self.state.blockNumber = self.rpc.block.number; | ||
callback(null); | ||
if (!blockNumber) return callback(new Error("setLatestBlock failed")); | ||
if (blockNumber.error) return callback(new Error(blockNumber.error)); | ||
self.rpc.getBlock(blockNumber, false, function (block) { | ||
if (!block) return callback(new Error("setLatestBlock failed")); | ||
if (block.error) return callback(new Error(block.error)); | ||
self.rpc.onNewBlock(block); | ||
callback(null); | ||
}); | ||
}); | ||
@@ -145,5 +159,4 @@ } | ||
var coinbase = this.rpc.coinbase(); | ||
if (!coinbase || coinbase.error || coinbase === "0x") { | ||
throw new Error("[ethereumjs-connect] setCoinbase: coinbase not found"); | ||
} | ||
if (!coinbase) throw new Error("setCoinbase failed"); | ||
if (coinbase.error || coinbase === "0x") throw new Error(coinbase); | ||
this.state.coinbase = coinbase; | ||
@@ -153,5 +166,4 @@ this.state.from = this.state.from || coinbase; | ||
this.rpc.coinbase(function (coinbase) { | ||
if (!coinbase || coinbase.error || coinbase === "0x") { | ||
return callback(new Error("[ethereumjs-connect] setCoinbase: coinbase not found")); | ||
} | ||
if (!coinbase) return callback(new Error("setCoinbase failed")); | ||
if (coinbase.error || coinbase === "0x") return callback(new Error(coinbase)); | ||
self.state.coinbase = coinbase; | ||
@@ -193,3 +205,3 @@ self.state.from = self.state.from || coinbase; | ||
this.setNetworkID.bind(this), | ||
this.setBlockNumber.bind(this), | ||
this.setLatestBlock.bind(this), | ||
function (next) { | ||
@@ -223,3 +235,3 @@ self.setContracts(); | ||
this.setNetworkID(); | ||
this.setBlockNumber(); | ||
this.setLatestBlock(); | ||
this.setContracts(); | ||
@@ -226,0 +238,0 @@ this.setCoinbase(); |
{ | ||
"name": "ethereumjs-connect", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Basic Ethereum connection tasks", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1405462
25067