Skip to content

Commit 3cdb6aa

Browse files
committed
Refactored checkBlockTag.
1 parent 8a26f38 commit 3cdb6aa

File tree

8 files changed

+43
-76
lines changed

8 files changed

+43
-76
lines changed

dist/ethers-providers.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,8 +4082,8 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
40824082

40834083
case 'getStorageAt':
40844084
url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address;
4085-
url += '&position=' + utils.hexStripZeros(params.position);
4086-
url += '&tag=' + utils.hexStripZeros(params.blockTag) + apiKey;
4085+
url += '&position=' + params.position;
4086+
url += '&tag=' + params.blockTag + apiKey;
40874087
return Provider.fetchJSON(url, null, getJsonResult);
40884088

40894089
case 'sendTransaction':
@@ -4094,7 +4094,7 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
40944094

40954095
case 'getBlock':
40964096
if (params.blockTag) {
4097-
url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + utils.hexStripZeros(params.blockTag);
4097+
url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + params.blockTag;
40984098
url += '&boolean=false';
40994099
url += apiKey;
41004100
return Provider.fetchJSON(url, null, getJsonResult);
@@ -4460,35 +4460,23 @@ utils.defineProperty(JsonRpcProvider.prototype, 'perform', function(method, para
44604460
return this.send('eth_gasPrice', []);
44614461

44624462
case 'getBalance':
4463-
var blockTag = params.blockTag;
4464-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
4465-
return this.send('eth_getBalance', [params.address, blockTag]);
4463+
return this.send('eth_getBalance', [params.address, params.blockTag]);
44664464

44674465
case 'getTransactionCount':
4468-
var blockTag = params.blockTag;
4469-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
4470-
return this.send('eth_getTransactionCount', [params.address, blockTag]);
4466+
return this.send('eth_getTransactionCount', [params.address, params.blockTag]);
44714467

44724468
case 'getCode':
4473-
var blockTag = params.blockTag;
4474-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
4475-
return this.send('eth_getCode', [params.address, blockTag]);
4469+
return this.send('eth_getCode', [params.address, params.blockTag]);
44764470

44774471
case 'getStorageAt':
4478-
var position = params.position;
4479-
if (utils.isHexString(position)) { position = utils.hexStripZeros(position); }
4480-
var blockTag = params.blockTag;
4481-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
4482-
return this.send('eth_getStorageAt', [params.address, position, blockTag]);
4472+
return this.send('eth_getStorageAt', [params.address, params.position, params.blockTag]);
44834473

44844474
case 'sendTransaction':
44854475
return this.send('eth_sendRawTransaction', [params.signedTransaction]);
44864476

44874477
case 'getBlock':
44884478
if (params.blockTag) {
4489-
var blockTag = params.blockTag;
4490-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
4491-
return this.send('eth_getBlockByNumber', [blockTag, false]);
4479+
return this.send('eth_getBlockByNumber', [params.blockTag, false]);
44924480
} else if (params.blockHash) {
44934481
return this.send('eth_getBlockByHash', [params.blockHash, false]);
44944482
}
@@ -4638,6 +4626,7 @@ var utils = (function() {
46384626
isHexString: convert.isHexString,
46394627

46404628
concat: convert.concat,
4629+
hexStripZeros: convert.hexStripZeros,
46414630
stripZeros: convert.stripZeros,
46424631

46434632
namehash: require('../utils/namehash'),
@@ -4742,10 +4731,10 @@ function checkBlockTag(blockTag) {
47424731
}
47434732

47444733
if (typeof(blockTag) === 'number') {
4745-
return utils.hexlify(blockTag);
4734+
return utils.hexStripZeros(utils.hexlify(blockTag));
47464735
}
47474736

4748-
if (utils.isHexString(blockTag)) { return blockTag; }
4737+
if (utils.isHexString(blockTag)) { return utils.hexStripZeros(blockTag); }
47494738

47504739
throw new Error('invalid blockTag');
47514740
}
@@ -5272,7 +5261,7 @@ utils.defineProperty(Provider.prototype, 'getStorageAt', function(addressOrName,
52725261
var params = {
52735262
address: address,
52745263
blockTag: checkBlockTag(blockTag),
5275-
position: utils.hexlify(position),
5264+
position: utils.hexStripZeros(utils.hexlify(position)),
52765265
};
52775266
return self.perform('getStorageAt', params).then(function(result) {
52785267
return utils.hexlify(result);

dist/ethers-providers.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ethers.js

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9585,7 +9585,7 @@ uuid.unparse = unparse;
95859585
module.exports = uuid;
95869586

95879587
},{"./rng":43}],45:[function(require,module,exports){
9588-
module.exports={"version":"3.0.1"}
9588+
module.exports={"version":"3.0.2"}
95899589
},{}],46:[function(require,module,exports){
95909590
'use strict';
95919591

@@ -9733,8 +9733,8 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
97339733

97349734
case 'getStorageAt':
97359735
url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address;
9736-
url += '&position=' + utils.hexStripZeros(params.position);
9737-
url += '&tag=' + utils.hexStripZeros(params.blockTag) + apiKey;
9736+
url += '&position=' + params.position;
9737+
url += '&tag=' + params.blockTag + apiKey;
97389738
return Provider.fetchJSON(url, null, getJsonResult);
97399739

97409740
case 'sendTransaction':
@@ -9745,7 +9745,7 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
97459745

97469746
case 'getBlock':
97479747
if (params.blockTag) {
9748-
url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + utils.hexStripZeros(params.blockTag);
9748+
url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + params.blockTag;
97499749
url += '&boolean=false';
97509750
url += apiKey;
97519751
return Provider.fetchJSON(url, null, getJsonResult);
@@ -10111,35 +10111,23 @@ utils.defineProperty(JsonRpcProvider.prototype, 'perform', function(method, para
1011110111
return this.send('eth_gasPrice', []);
1011210112

1011310113
case 'getBalance':
10114-
var blockTag = params.blockTag;
10115-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
10116-
return this.send('eth_getBalance', [params.address, blockTag]);
10114+
return this.send('eth_getBalance', [params.address, params.blockTag]);
1011710115

1011810116
case 'getTransactionCount':
10119-
var blockTag = params.blockTag;
10120-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
10121-
return this.send('eth_getTransactionCount', [params.address, blockTag]);
10117+
return this.send('eth_getTransactionCount', [params.address, params.blockTag]);
1012210118

1012310119
case 'getCode':
10124-
var blockTag = params.blockTag;
10125-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
10126-
return this.send('eth_getCode', [params.address, blockTag]);
10120+
return this.send('eth_getCode', [params.address, params.blockTag]);
1012710121

1012810122
case 'getStorageAt':
10129-
var position = params.position;
10130-
if (utils.isHexString(position)) { position = utils.hexStripZeros(position); }
10131-
var blockTag = params.blockTag;
10132-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
10133-
return this.send('eth_getStorageAt', [params.address, position, blockTag]);
10123+
return this.send('eth_getStorageAt', [params.address, params.position, params.blockTag]);
1013410124

1013510125
case 'sendTransaction':
1013610126
return this.send('eth_sendRawTransaction', [params.signedTransaction]);
1013710127

1013810128
case 'getBlock':
1013910129
if (params.blockTag) {
10140-
var blockTag = params.blockTag;
10141-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
10142-
return this.send('eth_getBlockByNumber', [blockTag, false]);
10130+
return this.send('eth_getBlockByNumber', [params.blockTag, false]);
1014310131
} else if (params.blockHash) {
1014410132
return this.send('eth_getBlockByHash', [params.blockHash, false]);
1014510133
}
@@ -10289,6 +10277,7 @@ var utils = (function() {
1028910277
isHexString: convert.isHexString,
1029010278

1029110279
concat: convert.concat,
10280+
hexStripZeros: convert.hexStripZeros,
1029210281
stripZeros: convert.stripZeros,
1029310282

1029410283
namehash: require('../utils/namehash'),
@@ -10393,10 +10382,10 @@ function checkBlockTag(blockTag) {
1039310382
}
1039410383

1039510384
if (typeof(blockTag) === 'number') {
10396-
return utils.hexlify(blockTag);
10385+
return utils.hexStripZeros(utils.hexlify(blockTag));
1039710386
}
1039810387

10399-
if (utils.isHexString(blockTag)) { return blockTag; }
10388+
if (utils.isHexString(blockTag)) { return utils.hexStripZeros(blockTag); }
1040010389

1040110390
throw new Error('invalid blockTag');
1040210391
}
@@ -10923,7 +10912,7 @@ utils.defineProperty(Provider.prototype, 'getStorageAt', function(addressOrName,
1092310912
var params = {
1092410913
address: address,
1092510914
blockTag: checkBlockTag(blockTag),
10926-
position: utils.hexlify(position),
10915+
position: utils.hexStripZeros(utils.hexlify(position)),
1092710916
};
1092810917
return self.perform('getStorageAt', params).then(function(result) {
1092910918
return utils.hexlify(result);

dist/ethers.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ethers",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"description": "Ethereum wallet library.",
55
"main": "index.js",
66
"scripts": {

providers/etherscan-provider.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
134134

135135
case 'getStorageAt':
136136
url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address;
137-
url += '&position=' + utils.hexStripZeros(params.position);
138-
url += '&tag=' + utils.hexStripZeros(params.blockTag) + apiKey;
137+
url += '&position=' + params.position;
138+
url += '&tag=' + params.blockTag + apiKey;
139139
return Provider.fetchJSON(url, null, getJsonResult);
140140

141141
case 'sendTransaction':
@@ -146,7 +146,7 @@ utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, pa
146146

147147
case 'getBlock':
148148
if (params.blockTag) {
149-
url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + utils.hexStripZeros(params.blockTag);
149+
url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + params.blockTag;
150150
url += '&boolean=false';
151151
url += apiKey;
152152
return Provider.fetchJSON(url, null, getJsonResult);

providers/json-rpc-provider.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,35 +98,23 @@ utils.defineProperty(JsonRpcProvider.prototype, 'perform', function(method, para
9898
return this.send('eth_gasPrice', []);
9999

100100
case 'getBalance':
101-
var blockTag = params.blockTag;
102-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
103-
return this.send('eth_getBalance', [params.address, blockTag]);
101+
return this.send('eth_getBalance', [params.address, params.blockTag]);
104102

105103
case 'getTransactionCount':
106-
var blockTag = params.blockTag;
107-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
108-
return this.send('eth_getTransactionCount', [params.address, blockTag]);
104+
return this.send('eth_getTransactionCount', [params.address, params.blockTag]);
109105

110106
case 'getCode':
111-
var blockTag = params.blockTag;
112-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
113-
return this.send('eth_getCode', [params.address, blockTag]);
107+
return this.send('eth_getCode', [params.address, params.blockTag]);
114108

115109
case 'getStorageAt':
116-
var position = params.position;
117-
if (utils.isHexString(position)) { position = utils.hexStripZeros(position); }
118-
var blockTag = params.blockTag;
119-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
120-
return this.send('eth_getStorageAt', [params.address, position, blockTag]);
110+
return this.send('eth_getStorageAt', [params.address, params.position, params.blockTag]);
121111

122112
case 'sendTransaction':
123113
return this.send('eth_sendRawTransaction', [params.signedTransaction]);
124114

125115
case 'getBlock':
126116
if (params.blockTag) {
127-
var blockTag = params.blockTag;
128-
if (utils.isHexString(blockTag)) { blockTag = utils.hexStripZeros(blockTag); }
129-
return this.send('eth_getBlockByNumber', [blockTag, false]);
117+
return this.send('eth_getBlockByNumber', [params.blockTag, false]);
130118
} else if (params.blockHash) {
131119
return this.send('eth_getBlockByHash', [params.blockHash, false]);
132120
}

providers/provider.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var utils = (function() {
2121
isHexString: convert.isHexString,
2222

2323
concat: convert.concat,
24+
hexStripZeros: convert.hexStripZeros,
2425
stripZeros: convert.stripZeros,
2526

2627
namehash: require('../utils/namehash'),
@@ -125,10 +126,10 @@ function checkBlockTag(blockTag) {
125126
}
126127

127128
if (typeof(blockTag) === 'number') {
128-
return utils.hexlify(blockTag);
129+
return utils.hexStripZeros(utils.hexlify(blockTag));
129130
}
130131

131-
if (utils.isHexString(blockTag)) { return blockTag; }
132+
if (utils.isHexString(blockTag)) { return utils.hexStripZeros(blockTag); }
132133

133134
throw new Error('invalid blockTag');
134135
}
@@ -655,7 +656,7 @@ utils.defineProperty(Provider.prototype, 'getStorageAt', function(addressOrName,
655656
var params = {
656657
address: address,
657658
blockTag: checkBlockTag(blockTag),
658-
position: utils.hexlify(position),
659+
position: utils.hexStripZeros(utils.hexlify(position)),
659660
};
660661
return self.perform('getStorageAt', params).then(function(result) {
661662
return utils.hexlify(result);

0 commit comments

Comments
 (0)