首次放到 git

This commit is contained in:
Luk.Lu
2018-10-09 23:03:05 +08:00
commit 16cca302b7
37 changed files with 4203 additions and 0 deletions

20
utils/contract-address.js Normal file
View File

@@ -0,0 +1,20 @@
var getAddress = require('./address').getAddress;
var convert = require('./convert');
var keccak256 = require('./keccak256');
var RLP = require('./rlp');
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
function getContractAddress(transaction) {
if (!transaction.from) { throw new Error('missing from address'); }
var nonce = transaction.nonce;
return getAddress('0x' + keccak256(RLP.encode([
getAddress(transaction.from),
convert.stripZeros(convert.hexlify(nonce, 'nonce'))
])).substring(26));
}
module.exports = {
getContractAddress: getContractAddress,
}