Updated parseTransaction to format parameters more meaningfully.
This commit is contained in:
parent
d8013cae37
commit
736b08e016
34
dist/ethers-wallet.js
vendored
34
dist/ethers-wallet.js
vendored
@ -2226,12 +2226,42 @@ utils.defineProperty(Wallet, 'parseTransaction', function(rawTransaction) {
|
|||||||
raw.push(signedTransaction[index]);
|
raw.push(signedTransaction[index]);
|
||||||
});
|
});
|
||||||
|
|
||||||
transaction.v = signedTransaction[6];
|
if (transaction.to) {
|
||||||
|
if (transaction.to.length === 0) {
|
||||||
|
delete transaction.to;
|
||||||
|
} else {
|
||||||
|
transaction.to = utils.getAddress('0x' + transaction.to.toString('hex'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
['gasPrice', 'gasLimit', 'nonce', 'value'].forEach(function(name) {
|
||||||
|
if (!transaction[name]) { return; }
|
||||||
|
if (transaction[name].length === 0) {
|
||||||
|
transaction[name] = new utils.BN(0);
|
||||||
|
} else {
|
||||||
|
transaction[name] = new utils.BN(transaction[name].toString('hex'), 16);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* @TODO: Maybe? In the future, all nonces stored as numbers? (obviously, major version change)
|
||||||
|
if (transaction.nonce) {
|
||||||
|
transaction.nonce = transaction.nonce.toNumber()
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (signedTransaction.length > 6 && signedTransaction[6].length === 1 &&
|
||||||
|
signedTransaction[7].length >= 1 && signedTransaction[7].length <= 32 &&
|
||||||
|
signedTransaction[8].length >= 1 && signedTransaction[7].length <= 32) {
|
||||||
|
|
||||||
|
transaction.v = signedTransaction[6][0];
|
||||||
transaction.r = signedTransaction[7];
|
transaction.r = signedTransaction[7];
|
||||||
transaction.s = signedTransaction[8];
|
transaction.s = signedTransaction[8];
|
||||||
|
|
||||||
var digest = utils.sha3(rlp.encode(raw));
|
var digest = utils.sha3(rlp.encode(raw));
|
||||||
transaction.from = SigningKey.recover(digest, transaction.r, transaction.s, transaction.v[0] - 27);
|
try {
|
||||||
|
transaction.from = SigningKey.recover(digest, transaction.r, transaction.s, transaction.v - 27);
|
||||||
|
} catch (error) { }
|
||||||
|
}
|
||||||
|
|
||||||
return transaction;
|
return transaction;
|
||||||
});
|
});
|
||||||
|
2
dist/ethers-wallet.min.js
vendored
2
dist/ethers-wallet.min.js
vendored
File diff suppressed because one or more lines are too long
@ -123,12 +123,42 @@ utils.defineProperty(Wallet, 'parseTransaction', function(rawTransaction) {
|
|||||||
raw.push(signedTransaction[index]);
|
raw.push(signedTransaction[index]);
|
||||||
});
|
});
|
||||||
|
|
||||||
transaction.v = signedTransaction[6];
|
if (transaction.to) {
|
||||||
|
if (transaction.to.length === 0) {
|
||||||
|
delete transaction.to;
|
||||||
|
} else {
|
||||||
|
transaction.to = utils.getAddress('0x' + transaction.to.toString('hex'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
['gasPrice', 'gasLimit', 'nonce', 'value'].forEach(function(name) {
|
||||||
|
if (!transaction[name]) { return; }
|
||||||
|
if (transaction[name].length === 0) {
|
||||||
|
transaction[name] = new utils.BN(0);
|
||||||
|
} else {
|
||||||
|
transaction[name] = new utils.BN(transaction[name].toString('hex'), 16);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* @TODO: Maybe? In the future, all nonces stored as numbers? (obviously, major version change)
|
||||||
|
if (transaction.nonce) {
|
||||||
|
transaction.nonce = transaction.nonce.toNumber()
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (signedTransaction.length > 6 && signedTransaction[6].length === 1 &&
|
||||||
|
signedTransaction[7].length >= 1 && signedTransaction[7].length <= 32 &&
|
||||||
|
signedTransaction[8].length >= 1 && signedTransaction[7].length <= 32) {
|
||||||
|
|
||||||
|
transaction.v = signedTransaction[6][0];
|
||||||
transaction.r = signedTransaction[7];
|
transaction.r = signedTransaction[7];
|
||||||
transaction.s = signedTransaction[8];
|
transaction.s = signedTransaction[8];
|
||||||
|
|
||||||
var digest = utils.sha3(rlp.encode(raw));
|
var digest = utils.sha3(rlp.encode(raw));
|
||||||
transaction.from = SigningKey.recover(digest, transaction.r, transaction.s, transaction.v[0] - 27);
|
try {
|
||||||
|
transaction.from = SigningKey.recover(digest, transaction.r, transaction.s, transaction.v - 27);
|
||||||
|
} catch (error) { }
|
||||||
|
}
|
||||||
|
|
||||||
return transaction;
|
return transaction;
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ethers-wallet",
|
"name": "ethers-wallet",
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"description": "Ethereum wallet library.",
|
"description": "Ethereum wallet library.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -22,6 +22,7 @@ module.exports = function(test) {
|
|||||||
|
|
||||||
test.equal(ethers, ethereumLib, 'invalid transaction');
|
test.equal(ethers, ethereumLib, 'invalid transaction');
|
||||||
|
|
||||||
|
// @TODO: More testing on parsed transaction.
|
||||||
test.equal(wallet.address, Wallet.parseTransaction(ethers).from, 'invalid parseTransaction');
|
test.equal(wallet.address, Wallet.parseTransaction(ethers).from, 'invalid parseTransaction');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user