Skip to content

Commit b26b1b9

Browse files
committed
Moved getContractAddress to utils.
1 parent 1c9c7b7 commit b26b1b9

File tree

5 files changed

+30
-20
lines changed

5 files changed

+30
-20
lines changed

dist/ethers-wallet.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
(function (Buffer){
33
'use strict';
44

5-
var rlp = require('rlp');
65
var scrypt = require('scrypt-js');
76

87
var Contract = require('./lib/contract.js');
@@ -26,13 +25,7 @@ utils.defineProperty(exportUtils, 'Buffer', Buffer);
2625
utils.defineProperty(exportUtils, 'sha3', utils.sha3);
2726
utils.defineProperty(exportUtils, 'sha256', utils.sha256);
2827

29-
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
30-
utils.defineProperty(exportUtils, 'getContractAddress', function(transaction) {
31-
return utils.getAddress('0x' + utils.sha3(rlp.encode([
32-
utils.hexOrBuffer(utils.getAddress(transaction.from)),
33-
utils.hexOrBuffer(utils.hexlify(transaction.nonce, 'nonce'))
34-
])).slice(12).toString('hex'));
35-
});
28+
utils.defineProperty(exportUtils, 'getContractAddress', utils.getContractAddress);
3629

3730
module.exports = Wallet;
3831

@@ -105,7 +98,7 @@ utils.defineProperty(Wallet, 'randomish', new Randomish());
10598
module.exports = Wallet;
10699

107100
}).call(this,require("buffer").Buffer)
108-
},{"./lib/contract.js":4,"./lib/providers.js":5,"./lib/randomish.js":6,"./lib/secret-storage.js":7,"./lib/signing-key.js":8,"./lib/units.js":9,"./lib/utils.js":10,"./lib/wallet.js":11,"buffer":41,"rlp":85,"scrypt-js":86}],2:[function(require,module,exports){
101+
},{"./lib/contract.js":4,"./lib/providers.js":5,"./lib/randomish.js":6,"./lib/secret-storage.js":7,"./lib/signing-key.js":8,"./lib/units.js":9,"./lib/utils.js":10,"./lib/wallet.js":11,"buffer":41,"scrypt-js":86}],2:[function(require,module,exports){
109102
(function (global,Buffer){
110103
'use strict';
111104

@@ -1698,6 +1691,8 @@ module.exports = {
16981691
(function (Buffer){
16991692
'use strict';
17001693

1694+
var rlp = require('rlp');
1695+
17011696
var BN = require('../node_modules/elliptic/node_modules/bn.js/lib/bn.js');
17021697
var hash = require('../node_modules/elliptic/node_modules/hash.js/lib/hash.js');
17031698

@@ -2010,6 +2005,14 @@ function getIcapAddress(address) {
20102005
return 'XE' + ibanChecksum('XE00' + base36) + base36;
20112006
}
20122007

2008+
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
2009+
function getContractAddress(transaction) {
2010+
return getAddress('0x' + sha3(rlp.encode([
2011+
hexOrBuffer(getAddress(transaction.from)),
2012+
hexOrBuffer(hexlify(transaction.nonce, 'nonce'))
2013+
])).slice(12).toString('hex'));
2014+
}
2015+
20132016
function cloneObject(object) {
20142017
var clone = {};
20152018
for (var key in object) { clone[key] = object[key]; }
@@ -2075,6 +2078,8 @@ module.exports = {
20752078
getAddress: getAddress,
20762079
getIcapAddress: getIcapAddress,
20772080

2081+
getContractAddress: getContractAddress,
2082+
20782083
cloneObject: cloneObject,
20792084

20802085
bnToBuffer: bnToBuffer,
@@ -2088,7 +2093,7 @@ module.exports = {
20882093
}
20892094

20902095
}).call(this,require("buffer").Buffer)
2091-
},{"../node_modules/elliptic/node_modules/bn.js/lib/bn.js":29,"../node_modules/elliptic/node_modules/hash.js/lib/hash.js":31,"buffer":41}],11:[function(require,module,exports){
2096+
},{"../node_modules/elliptic/node_modules/bn.js/lib/bn.js":29,"../node_modules/elliptic/node_modules/hash.js/lib/hash.js":31,"buffer":41,"rlp":85}],11:[function(require,module,exports){
20922097
(function (global,Buffer){
20932098
'use strict';
20942099

dist/ethers-wallet.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
var rlp = require('rlp');
43
var scrypt = require('scrypt-js');
54

65
var Contract = require('./lib/contract.js');
@@ -24,13 +23,7 @@ utils.defineProperty(exportUtils, 'Buffer', Buffer);
2423
utils.defineProperty(exportUtils, 'sha3', utils.sha3);
2524
utils.defineProperty(exportUtils, 'sha256', utils.sha256);
2625

27-
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
28-
utils.defineProperty(exportUtils, 'getContractAddress', function(transaction) {
29-
return utils.getAddress('0x' + utils.sha3(rlp.encode([
30-
utils.hexOrBuffer(utils.getAddress(transaction.from)),
31-
utils.hexOrBuffer(utils.hexlify(transaction.nonce, 'nonce'))
32-
])).slice(12).toString('hex'));
33-
});
26+
utils.defineProperty(exportUtils, 'getContractAddress', utils.getContractAddress);
3427

3528
module.exports = Wallet;
3629

lib/utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
var rlp = require('rlp');
4+
35
var BN = require('../node_modules/elliptic/node_modules/bn.js/lib/bn.js');
46
var hash = require('../node_modules/elliptic/node_modules/hash.js/lib/hash.js');
57

@@ -312,6 +314,14 @@ function getIcapAddress(address) {
312314
return 'XE' + ibanChecksum('XE00' + base36) + base36;
313315
}
314316

317+
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
318+
function getContractAddress(transaction) {
319+
return getAddress('0x' + sha3(rlp.encode([
320+
hexOrBuffer(getAddress(transaction.from)),
321+
hexOrBuffer(hexlify(transaction.nonce, 'nonce'))
322+
])).slice(12).toString('hex'));
323+
}
324+
315325
function cloneObject(object) {
316326
var clone = {};
317327
for (var key in object) { clone[key] = object[key]; }
@@ -377,6 +387,8 @@ module.exports = {
377387
getAddress: getAddress,
378388
getIcapAddress: getIcapAddress,
379389

390+
getContractAddress: getContractAddress,
391+
380392
cloneObject: cloneObject,
381393

382394
bnToBuffer: bnToBuffer,

package.json

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

0 commit comments

Comments
 (0)