Skip to content

Commit

Permalink
Merge pull request #3285 from ethereum/issue/3283
Browse files Browse the repository at this point in the history
Make user supplied callback fire in accounts.signTransaction
  • Loading branch information
nivida authored Jan 6, 2020
2 parents 58f77a6 + e9c715c commit 0f7e3dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
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,8 +117,9 @@ 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)
- fix: export bloom functions on the index.js
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 = {
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

0 comments on commit 0f7e3dc

Please sign in to comment.