Skip to content

Commit

Permalink
Merge pull request #2367 from ethereum/issue/2356
Browse files Browse the repository at this point in the history
Custom TransactionSigner and eth-account module improvements.
  • Loading branch information
nivida authored Feb 27, 2019
2 parents 7f5a390 + 13eb73d commit dc03898
Show file tree
Hide file tree
Showing 72 changed files with 4,279 additions and 2,542 deletions.
48 changes: 46 additions & 2 deletions docs/include_package-core.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

options
=====================

Expand All @@ -23,6 +22,8 @@ Module Options

:ref:`transactionPollingTimeout <web3-module-transactionpollingtimeout>`

:ref:`transactionSigner <web3-module-transactionSigner>`

-------
Example
-------
Expand All @@ -38,7 +39,8 @@ Example
defaultGasPrice: 0,
transactionBlockTimeout: 50,
transactionConfirmationBlocks: 24,
transactionPollingTimeout: 480
transactionPollingTimeout: 480,
transactionSigner: new CustomTransactionSigner()
}
const web3 = new Web3('http://localhost:8545', options);
Expand Down Expand Up @@ -207,6 +209,48 @@ Returns

------------------------------------------------------------------------------


.. _web3-module-transactionSigner:

transactionSigner
=================

.. code-block:: javascript
web3.eth.transactionSigner
...
The ``transactionSigner`` property does provide us the possibility to customize the signing process
of the ``Eth`` module and the related sub-modules.

The interface of a ``TransactionSigner``:

.. code-block:: javascript
interface TransactionSigner {
sign(txObject: Transaction): Promise<SignedTransaction>
}
interface SignedTransaction {
messageHash: string,
v: string,
r: string,
s: string,
rawTransaction: string
}
-------
Returns
-------

``TransactionSigner``: A JavaScript class of type TransactionSigner.

------------------------------------------------------------------------------

setProvider
=====================

Expand Down
3 changes: 2 additions & 1 deletion docs/web3-eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,8 @@ signTransaction
web3.eth.signTransaction(transactionObject [, address] [, callback])
Signs a transaction. This account needs to be unlocked.
The method ``signTransaction`` signs a transaction with the private key of the given address.
This method does only work if you're connected to a Parity node.
----------
Parameters
Expand Down
116 changes: 116 additions & 0 deletions packages/web3-core-helpers/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 10 additions & 13 deletions packages/web3-core-method/lib/factories/AbstractMethodFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* @date 2018
*/

import SendRawTransactionMethod from '../../src/methods/transaction/SendRawTransactionMethod';
import GetTransactionCountMethod from '../../src/methods/account/GetTransactionCountMethod';
import ChainIdMethod from '../../src/methods/network/ChainIdMethod';

export default class AbstractMethodFactory {
/**
* @param {MethodModuleFactory} methodModuleFactory
Expand Down Expand Up @@ -89,25 +93,18 @@ export default class AbstractMethodFactory {
/* eslint-disable new-cap */
switch (method.Type) {
case 'CALL':
if (method.name === 'SignMethod') {
return new method(
this.utils,
this.formatters,
this.methodModuleFactory.accounts,
this.methodModuleFactory.createMessageSigner()
);
}

return new method(this.utils, this.formatters);
case 'SEND':
if (method.name === 'SendTransactionMethod') {
const transactionConfirmationWorkflow = this.methodModuleFactory.createTransactionConfirmationWorkflow();

return new method(
this.utils,
this.formatters,
this.methodModuleFactory.createTransactionConfirmationWorkflow(),
this.methodModuleFactory.accounts,
this.methodModuleFactory.createTransactionSigner(),
this.methodModuleFactory.createSendRawTransactionMethod()
transactionConfirmationWorkflow,
new SendRawTransactionMethod(this.utils, this.formatters, transactionConfirmationWorkflow),
new ChainIdMethod(this.utils, this.formatters),
new GetTransactionCountMethod(this.utils, this.formatters)
);
}

Expand Down
11 changes: 0 additions & 11 deletions packages/web3-core-method/lib/methods/AbstractMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,4 @@ export default class AbstractMethod {
isHash(parameter) {
return isString(parameter) && parameter.indexOf('0x') === 0;
}

/**
* Checks if accounts is defined and if wallet is not empty
*
* @method hasWallet
*
* @returns {Boolean}
*/
hasWallets() {
return this.accounts && this.accounts.wallet.length > 0;
}
}
Loading

0 comments on commit dc03898

Please sign in to comment.