Refactored checkBlockTag.

This commit is contained in:
Richard Moore 2018-03-05 02:52:53 -05:00
parent 8a26f38579
commit 3cdb6aad25
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
8 changed files with 43 additions and 76 deletions

@ -4082,8 +4082,8 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
case 'getStorageAt': case 'getStorageAt':
url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address; url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address;
url += '&position=' + utils.hexStripZeros(params.position); url += '&position=' + params.position;
url += '&tag=' + utils.hexStripZeros(params.blockTag) + apiKey; url += '&tag=' + params.blockTag + apiKey;
return Provider.fetchJSON(url, null, getJsonResult); return Provider.fetchJSON(url, null, getJsonResult);
case 'sendTransaction': case 'sendTransaction':
@ -4094,7 +4094,7 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
case 'getBlock': case 'getBlock':
if (params.blockTag) { if (params.blockTag) {
url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + utils.hexStripZeros(params.blockTag); url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + params.blockTag;
url += '&boolean=false'; url += '&boolean=false';
url += apiKey; url += apiKey;
return Provider.fetchJSON(url, null, getJsonResult); return Provider.fetchJSON(url, null, getJsonResult);
@ -4460,35 +4460,23 @@ utils.defineProperty(JsonRpcProvider.prototype, 'perform', function(method, para
return this.send('eth_gasPrice', []); return this.send('eth_gasPrice', []);
case 'getBalance': case 'getBalance':
var blockTag = params.blockTag; return this.send('eth_getBalance', [params.address, params.blockTag]);
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getBalance', [params.address, blockTag]);
case 'getTransactionCount': case 'getTransactionCount':
var blockTag = params.blockTag; return this.send('eth_getTransactionCount', [params.address, params.blockTag]);
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getTransactionCount', [params.address, blockTag]);
case 'getCode': case 'getCode':
var blockTag = params.blockTag; return this.send('eth_getCode', [params.address, params.blockTag]);
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getCode', [params.address, blockTag]);
case 'getStorageAt': case 'getStorageAt':
var position = params.position; return this.send('eth_getStorageAt', [params.address, params.position, params.blockTag]);
if (utils.isHexString(position)) { position = utils.hexStripZeros(position); }
var blockTag = params.blockTag;
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getStorageAt', [params.address, position, blockTag]);
case 'sendTransaction': case 'sendTransaction':
return this.send('eth_sendRawTransaction', [params.signedTransaction]); return this.send('eth_sendRawTransaction', [params.signedTransaction]);
case 'getBlock': case 'getBlock':
if (params.blockTag) { if (params.blockTag) {
var blockTag = params.blockTag; return this.send('eth_getBlockByNumber', [params.blockTag, false]);
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getBlockByNumber', [blockTag, false]);
} else if (params.blockHash) { } else if (params.blockHash) {
return this.send('eth_getBlockByHash', [params.blockHash, false]); return this.send('eth_getBlockByHash', [params.blockHash, false]);
} }
@ -4638,6 +4626,7 @@ var utils = (function() {
isHexString: convert.isHexString, isHexString: convert.isHexString,
concat: convert.concat, concat: convert.concat,
hexStripZeros: convert.hexStripZeros,
stripZeros: convert.stripZeros, stripZeros: convert.stripZeros,
namehash: require('../utils/namehash'), namehash: require('../utils/namehash'),
@ -4742,10 +4731,10 @@ function checkBlockTag(blockTag) {
} }
if (typeof(blockTag) === 'number') { if (typeof(blockTag) === 'number') {
return utils.hexlify(blockTag); return utils.hexStripZeros(utils.hexlify(blockTag));
} }
if (utils.isHexString(blockTag)) { return blockTag; } if (utils.isHexString(blockTag)) { return utils.hexStripZeros(blockTag); }
throw new Error('invalid blockTag'); throw new Error('invalid blockTag');
} }
@ -5272,7 +5261,7 @@ utils.defineProperty(Provider.prototype, 'getStorageAt', function(addressOrName,
var params = { var params = {
address: address, address: address,
blockTag: checkBlockTag(blockTag), blockTag: checkBlockTag(blockTag),
position: utils.hexlify(position), position: utils.hexStripZeros(utils.hexlify(position)),
}; };
return self.perform('getStorageAt', params).then(function(result) { return self.perform('getStorageAt', params).then(function(result) {
return utils.hexlify(result); return utils.hexlify(result);

File diff suppressed because one or more lines are too long

37
dist/ethers.js vendored

@ -9585,7 +9585,7 @@ uuid.unparse = unparse;
module.exports = uuid; module.exports = uuid;
},{"./rng":43}],45:[function(require,module,exports){ },{"./rng":43}],45:[function(require,module,exports){
module.exports={"version":"3.0.1"} module.exports={"version":"3.0.2"}
},{}],46:[function(require,module,exports){ },{}],46:[function(require,module,exports){
'use strict'; 'use strict';
@ -9733,8 +9733,8 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
case 'getStorageAt': case 'getStorageAt':
url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address; url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address;
url += '&position=' + utils.hexStripZeros(params.position); url += '&position=' + params.position;
url += '&tag=' + utils.hexStripZeros(params.blockTag) + apiKey; url += '&tag=' + params.blockTag + apiKey;
return Provider.fetchJSON(url, null, getJsonResult); return Provider.fetchJSON(url, null, getJsonResult);
case 'sendTransaction': case 'sendTransaction':
@ -9745,7 +9745,7 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
case 'getBlock': case 'getBlock':
if (params.blockTag) { if (params.blockTag) {
url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + utils.hexStripZeros(params.blockTag); url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + params.blockTag;
url += '&boolean=false'; url += '&boolean=false';
url += apiKey; url += apiKey;
return Provider.fetchJSON(url, null, getJsonResult); return Provider.fetchJSON(url, null, getJsonResult);
@ -10111,35 +10111,23 @@ utils.defineProperty(JsonRpcProvider.prototype, 'perform', function(method, para
return this.send('eth_gasPrice', []); return this.send('eth_gasPrice', []);
case 'getBalance': case 'getBalance':
var blockTag = params.blockTag; return this.send('eth_getBalance', [params.address, params.blockTag]);
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getBalance', [params.address, blockTag]);
case 'getTransactionCount': case 'getTransactionCount':
var blockTag = params.blockTag; return this.send('eth_getTransactionCount', [params.address, params.blockTag]);
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getTransactionCount', [params.address, blockTag]);
case 'getCode': case 'getCode':
var blockTag = params.blockTag; return this.send('eth_getCode', [params.address, params.blockTag]);
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getCode', [params.address, blockTag]);
case 'getStorageAt': case 'getStorageAt':
var position = params.position; return this.send('eth_getStorageAt', [params.address, params.position, params.blockTag]);
if (utils.isHexString(position)) { position = utils.hexStripZeros(position); }
var blockTag = params.blockTag;
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getStorageAt', [params.address, position, blockTag]);
case 'sendTransaction': case 'sendTransaction':
return this.send('eth_sendRawTransaction', [params.signedTransaction]); return this.send('eth_sendRawTransaction', [params.signedTransaction]);
case 'getBlock': case 'getBlock':
if (params.blockTag) { if (params.blockTag) {
var blockTag = params.blockTag; return this.send('eth_getBlockByNumber', [params.blockTag, false]);
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getBlockByNumber', [blockTag, false]);
} else if (params.blockHash) { } else if (params.blockHash) {
return this.send('eth_getBlockByHash', [params.blockHash, false]); return this.send('eth_getBlockByHash', [params.blockHash, false]);
} }
@ -10289,6 +10277,7 @@ var utils = (function() {
isHexString: convert.isHexString, isHexString: convert.isHexString,
concat: convert.concat, concat: convert.concat,
hexStripZeros: convert.hexStripZeros,
stripZeros: convert.stripZeros, stripZeros: convert.stripZeros,
namehash: require('../utils/namehash'), namehash: require('../utils/namehash'),
@ -10393,10 +10382,10 @@ function checkBlockTag(blockTag) {
} }
if (typeof(blockTag) === 'number') { if (typeof(blockTag) === 'number') {
return utils.hexlify(blockTag); return utils.hexStripZeros(utils.hexlify(blockTag));
} }
if (utils.isHexString(blockTag)) { return blockTag; } if (utils.isHexString(blockTag)) { return utils.hexStripZeros(blockTag); }
throw new Error('invalid blockTag'); throw new Error('invalid blockTag');
} }
@ -10923,7 +10912,7 @@ utils.defineProperty(Provider.prototype, 'getStorageAt', function(addressOrName,
var params = { var params = {
address: address, address: address,
blockTag: checkBlockTag(blockTag), blockTag: checkBlockTag(blockTag),
position: utils.hexlify(position), position: utils.hexStripZeros(utils.hexlify(position)),
}; };
return self.perform('getStorageAt', params).then(function(result) { return self.perform('getStorageAt', params).then(function(result) {
return utils.hexlify(result); return utils.hexlify(result);

6
dist/ethers.min.js vendored

File diff suppressed because one or more lines are too long

@ -1,6 +1,6 @@
{ {
"name": "ethers", "name": "ethers",
"version": "3.0.1", "version": "3.0.2",
"description": "Ethereum wallet library.", "description": "Ethereum wallet library.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

@ -134,8 +134,8 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
case 'getStorageAt': case 'getStorageAt':
url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address; url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address;
url += '&position=' + utils.hexStripZeros(params.position); url += '&position=' + params.position;
url += '&tag=' + utils.hexStripZeros(params.blockTag) + apiKey; url += '&tag=' + params.blockTag + apiKey;
return Provider.fetchJSON(url, null, getJsonResult); return Provider.fetchJSON(url, null, getJsonResult);
case 'sendTransaction': case 'sendTransaction':
@ -146,7 +146,7 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
case 'getBlock': case 'getBlock':
if (params.blockTag) { if (params.blockTag) {
url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + utils.hexStripZeros(params.blockTag); url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + params.blockTag;
url += '&boolean=false'; url += '&boolean=false';
url += apiKey; url += apiKey;
return Provider.fetchJSON(url, null, getJsonResult); return Provider.fetchJSON(url, null, getJsonResult);

@ -98,35 +98,23 @@ utils.defineProperty(JsonRpcProvider.prototype, 'perform', function(method, para
return this.send('eth_gasPrice', []); return this.send('eth_gasPrice', []);
case 'getBalance': case 'getBalance':
var blockTag = params.blockTag; return this.send('eth_getBalance', [params.address, params.blockTag]);
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getBalance', [params.address, blockTag]);
case 'getTransactionCount': case 'getTransactionCount':
var blockTag = params.blockTag; return this.send('eth_getTransactionCount', [params.address, params.blockTag]);
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getTransactionCount', [params.address, blockTag]);
case 'getCode': case 'getCode':
var blockTag = params.blockTag; return this.send('eth_getCode', [params.address, params.blockTag]);
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getCode', [params.address, blockTag]);
case 'getStorageAt': case 'getStorageAt':
var position = params.position; return this.send('eth_getStorageAt', [params.address, params.position, params.blockTag]);
if (utils.isHexString(position)) { position = utils.hexStripZeros(position); }
var blockTag = params.blockTag;
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getStorageAt', [params.address, position, blockTag]);
case 'sendTransaction': case 'sendTransaction':
return this.send('eth_sendRawTransaction', [params.signedTransaction]); return this.send('eth_sendRawTransaction', [params.signedTransaction]);
case 'getBlock': case 'getBlock':
if (params.blockTag) { if (params.blockTag) {
var blockTag = params.blockTag; return this.send('eth_getBlockByNumber', [params.blockTag, false]);
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
return this.send('eth_getBlockByNumber', [blockTag, false]);
} else if (params.blockHash) { } else if (params.blockHash) {
return this.send('eth_getBlockByHash', [params.blockHash, false]); return this.send('eth_getBlockByHash', [params.blockHash, false]);
} }

@ -21,6 +21,7 @@ var utils = (function() {
isHexString: convert.isHexString, isHexString: convert.isHexString,
concat: convert.concat, concat: convert.concat,
hexStripZeros: convert.hexStripZeros,
stripZeros: convert.stripZeros, stripZeros: convert.stripZeros,
namehash: require('../utils/namehash'), namehash: require('../utils/namehash'),
@ -125,10 +126,10 @@ function checkBlockTag(blockTag) {
} }
if (typeof(blockTag) === 'number') { if (typeof(blockTag) === 'number') {
return utils.hexlify(blockTag); return utils.hexStripZeros(utils.hexlify(blockTag));
} }
if (utils.isHexString(blockTag)) { return blockTag; } if (utils.isHexString(blockTag)) { return utils.hexStripZeros(blockTag); }
throw new Error('invalid blockTag'); throw new Error('invalid blockTag');
} }
@ -655,7 +656,7 @@ utils.defineProperty(Provider.prototype, 'getStorageAt', function(addressOrName,
var params = { var params = {
address: address, address: address,
blockTag: checkBlockTag(blockTag), blockTag: checkBlockTag(blockTag),
position: utils.hexlify(position), position: utils.hexStripZeros(utils.hexlify(position)),
}; };
return self.perform('getStorageAt', params).then(function(result) { return self.perform('getStorageAt', params).then(function(result) {
return utils.hexlify(result); return utils.hexlify(result);