Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make user supplied callback fire in accounts.signTransaction #3285

Merged
merged 2 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Released with 1.0.0-beta.37 code base.
- ``eth_requestAccounts`` as ``requestAccounts`` added to web3-eth package (#3219)
- ``sha3Raw`` and ``soliditySha3Raw`` added to web3-utils package (#3226)
- ``eth_getProof`` as ``getProof`` added to web3-eth package (#3220)
- ``BN`` and ``BigNumber`` objects are now supported by the ``abi.encodeParameter(s)`` method (#3238)
- ``BN`` and ``BigNumber`` objects are now supported by the ``abi.encodeParameter(s)`` method (#3238)
- ``getPendingTransactions`` added to web3-eth package (#3239)
- Revert instruction handling added which can get activated with the ``handleRevert`` module property (#3248)
- The ``receipt`` does now exist as property on the error object for transaction related errors (#3259)
Expand All @@ -117,7 +117,8 @@ Released with 1.0.0-beta.37 code base.

### Fixed

- Fix user supplied callback not fired in eth.accounts.signTransaction (#3283)
- Fix minified bundle (#3256)
- ``defaultBlock`` property handling fixed (#3247)
- ``clearSubscriptions`` does no longer throw an error if no running subscriptions do exist (#3246)
- ``clearSubscriptions`` does no longer throw an error if no running subscriptions do exist (#3246)
- callback type definition for ``Accounts.signTransaction`` fixed (#3280)
9 changes: 4 additions & 5 deletions packages/web3-eth-accounts/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca
var _this = this,
error = false,
transactionOptions = {},
result,
hasTxSigningOptions = !!(tx && ((tx.chain && tx.hardfork) || tx.common));

callback = callback || function() {
Expand Down Expand Up @@ -235,7 +234,7 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca
var rawTransaction = '0x' + rlpEncoded;
var transactionHash = utils.keccak256(rawTransaction);

return {
var result = {
nivida marked this conversation as resolved.
Show resolved Hide resolved
messageHash: '0x' + Buffer.from(ethTx.hash(false)).toString('hex'),
v: '0x' + Buffer.from(ethTx.v).toString('hex'),
r: '0x' + Buffer.from(ethTx.r).toString('hex'),
Expand All @@ -244,13 +243,13 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca
transactionHash: transactionHash
};

callback(null, result);
return result;

} catch (e) {
callback(e);
return Promise.reject(e);
}

callback(null, result);
return result;
}


Expand Down
18 changes: 18 additions & 0 deletions test/e2e.method.signing.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ describe('transaction and message signing [ @E2E ]', function() {
assert(receipt.status === true);
});

it('accounts.signTransaction, (with callback, nonce not specified)', function(done){
const source = wallet[0].address;
const destination = wallet[1].address;

const txObject = {
to: destination,
value: web3.utils.toHex(web3.utils.toWei('0.1', 'ether')),
gasLimit: web3.utils.toHex(21000),
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')),
};

web3.eth.accounts.signTransaction(txObject, wallet[0].privateKey, async function(err, signed){
const receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction);
assert(receipt.status === true);
done();
});
});

it('accounts.signTransaction errors when common, chain and hardfork all defined', async function(){
const source = wallet[0].address;
const destination = wallet[1].address;
Expand Down