Skip to content

Commit

Permalink
Merge pull request #2616 from ethereum/issue/2612
Browse files Browse the repository at this point in the history
EthSendTransactionMethod simplified and fixed for local signing
  • Loading branch information
nivida authored Apr 1, 2019
2 parents 26987f6 + 0dd5f02 commit 60adc23
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 239 deletions.
10 changes: 3 additions & 7 deletions packages/web3-core-method/lib/factories/AbstractMethodFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import GetBlockByNumberMethod from '../../src/methods/block/GetBlockByNumberMeth
import GetTransactionReceiptMethod from '../../src/methods/transaction/GetTransactionReceiptMethod';
import TransactionObserver from '../../src/observers/TransactionObserver';
import GetTransactionCountMethod from '../../src/methods/account/GetTransactionCountMethod';
import SendRawTransactionMethod from '../../src/methods/transaction/SendRawTransactionMethod';
import ChainIdMethod from '../../src/methods/network/ChainIdMethod';

export default class AbstractMethodFactory {
Expand Down Expand Up @@ -101,19 +100,16 @@ export default class AbstractMethodFactory {
);
}

// TODO: Move this later to the eth module
// TODO: Move this to the eth module later.
if (method.Type === 'eth-send-transaction-method') {
const transactionObserver = this.createTransactionObserver(moduleInstance);

// eslint-disable-next-line new-cap
return new method(
this.utils,
this.formatters,
moduleInstance,
transactionObserver,
this.createTransactionObserver(moduleInstance),
new ChainIdMethod(this.utils, this.formatters, moduleInstance),
new GetTransactionCountMethod(this.utils, this.formatters, moduleInstance),
new SendRawTransactionMethod(this.utils, this.formatters, moduleInstance, transactionObserver)
new GetTransactionCountMethod(this.utils, this.formatters, moduleInstance)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,14 @@ export default class EthSendTransactionMethod extends SendTransactionMethod {
* @param {TransactionObserver} transactionObserver
* @param {ChainIdMethod} chainIdMethod
* @param {GetTransactionCountMethod} getTransactionCountMethod
* @param {SendRawTransactionMethod} sendRawTransactionMethod
*
* @constructor
*/
constructor(
utils,
formatters,
moduleInstance,
transactionObserver,
chainIdMethod,
getTransactionCountMethod,
sendRawTransactionMethod
) {
constructor(utils, formatters, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod) {
super(utils, formatters, moduleInstance, transactionObserver);

this.chainIdMethod = chainIdMethod;
this.getTransactionCountMethod = getTransactionCountMethod;
this.sendRawTransactionMethod = sendRawTransactionMethod;
}

/**
Expand All @@ -59,6 +49,19 @@ export default class EthSendTransactionMethod extends SendTransactionMethod {
return 'eth-send-transaction-method';
}

/**
* This method will be executed before the RPC request.
*
* @method beforeExecution
*
* @param {AbstractWeb3Module} moduleInstance - The module where the method is called from for example Eth.
*/
beforeExecution(moduleInstance) {
if (this.rpcMethod !== 'eth_sendRawTransaction') {
super.beforeExecution(moduleInstance);
}
}

/**
* Checks if gasPrice is set, sends the request and returns a PromiEvent Object
*
Expand Down Expand Up @@ -143,11 +146,10 @@ export default class EthSendTransactionMethod extends SendTransactionMethod {

const response = await this.moduleInstance.transactionSigner.sign(transaction, privateKey);

this.sendRawTransactionMethod.parameters = [response.rawTransaction];
this.sendRawTransactionMethod.callback = this.callback;
this.sendRawTransactionMethod.promiEvent = this.promiEvent;
this.parameters = [response.rawTransaction];
this.rpcMethod = 'eth_sendRawTransaction';

return this.sendRawTransactionMethod.execute();
return super.execute();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import GetBlockByNumberMethod from '../../../src/methods/block/GetBlockByNumberM
import {NewHeadsSubscription} from 'web3-core-subscriptions';
import ChainIdMethod from '../../../src/methods/network/ChainIdMethod';
import GetTransactionCountMethod from '../../../src/methods/account/GetTransactionCountMethod';
import SendRawTransactionMethod from '../../../src/methods/transaction/SendRawTransactionMethod';

// Mocks
jest.mock('AbstractWeb3Module');
Expand All @@ -20,7 +19,6 @@ jest.mock('../../../src/methods/transaction/GetTransactionReceiptMethod');
jest.mock('../../../src/observers/TransactionObserver');
jest.mock('../../../src/methods/network/ChainIdMethod');
jest.mock('../../../src/methods/account/GetTransactionCountMethod');
jest.mock('../../../src/methods/transaction/SendRawTransactionMethod');

/**
* AbstractMethodFactory test
Expand Down Expand Up @@ -122,8 +120,6 @@ describe('AbstractMethodFactoryTest', () => {
expect(ChainIdMethod).toHaveBeenCalledTimes(1);

expect(GetTransactionCountMethod).toHaveBeenCalledTimes(1);

expect(SendRawTransactionMethod).toHaveBeenCalledTimes(1);
});

it('calls createMethod with a socket provider and returns a object of type AbstractObservedTransactionMethod', () => {
Expand Down
Loading

0 comments on commit 60adc23

Please sign in to comment.