Skip to content

Commit

Permalink
Merge branch '1.0' into issue/2468
Browse files Browse the repository at this point in the history
  • Loading branch information
nivida authored Apr 17, 2019
2 parents 3c0cb3a + 6fb8c14 commit 7499a1e
Show file tree
Hide file tree
Showing 33 changed files with 2,868 additions and 225 deletions.
8 changes: 5 additions & 3 deletions docs/web3-eth-accounts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Returns
- ``s`` - ``String``: Next 32 bytes of the signature
- ``v`` - ``String``: Recovery value + 27
- ``rawTransaction`` - ``String``: The RLP encoded transaction, ready to be send using :ref:`web3.eth.sendSignedTransaction <eth-sendsignedtransaction>`.

- ``transactionHash`` - ``String``: The transaction hash for the RLP encoded transaction.

-------
Example
Expand All @@ -182,7 +182,8 @@ Example
v: '0x25',
r: '0xc9cf86333bcb065d140032ecaab5d9281bde80f21b9687b3e94161de42d51895',
s: '0x727a108a0b8d101465414033c3f705a9c7b826e596766046ee1183dbc8aeaa68',
rawTransaction: '0xf869808504e3b29200831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca008025a0c9cf86333bcb065d140032ecaab5d9281bde80f21b9687b3e94161de42d51895a0727a108a0b8d101465414033c3f705a9c7b826e596766046ee1183dbc8aeaa68'
rawTransaction: '0xf869808504e3b29200831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca008025a0c9cf86333bcb065d140032ecaab5d9281bde80f21b9687b3e94161de42d51895a0727a108a0b8d101465414033c3f705a9c7b826e596766046ee1183dbc8aeaa68',
transactionHash: '0xde8db924885b0803d2edc335f745b2b8750c8848744905684c20b987443a9593'
}
web3.eth.accounts.signTransaction({
Expand All @@ -199,7 +200,8 @@ Example
r: '0x9ebb6ca057a0535d6186462bc0b465b561c94a295bdb0621fc19208ab149a9c',
s: '0x440ffd775ce91a833ab410777204d5341a6f9fa91216a6f3ee2c051fea6a0428',
v: '0x25',
rawTransaction: '0xf86a8086d55698372431831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca008025a009ebb6ca057a0535d6186462bc0b465b561c94a295bdb0621fc19208ab149a9ca0440ffd775ce91a833ab410777204d5341a6f9fa91216a6f3ee2c051fea6a0428'
rawTransaction: '0xf86a8086d55698372431831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca008025a009ebb6ca057a0535d6186462bc0b465b561c94a295bdb0621fc19208ab149a9ca0440ffd775ce91a833ab410777204d5341a6f9fa91216a6f3ee2c051fea6a0428',
transactionHash: '0xd8f64a42b57be0d565f385378db2f6bf324ce14a594afc05de90436e9ce01f60'
}
Expand Down
12 changes: 10 additions & 2 deletions docs/web3-eth-admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ getDataDirectory
admin.getDataDirectory([, callback])
Provides absolute path of the running node, which is used by the node to store all its databases.
The RPC method used is ``admin_datadir``.

----------
Parameters
Expand Down Expand Up @@ -114,6 +115,7 @@ getNodeInfo
admin.getNodeInfo([, callback])
This property can be queried for all the information known about the running node at the networking granularity..
The RPC method used is ``admin_nodeInfo``.

----------
Parameters
Expand Down Expand Up @@ -181,6 +183,7 @@ getPeers
admin.getPeers([, callback])
This will provide all the information known about the connected remote nodes at the networking granularity.
The RPC method used is ``admin_peers``.

----------
Parameters
Expand Down Expand Up @@ -258,6 +261,7 @@ setSolc
admin.setSolc(string, [, callback])
Sets the Solidity compiler path to be used by the node when invoking the eth_compileSolidity RPC method
The RPC method used is ``admin_setSolc``.

----------
Parameters
Expand Down Expand Up @@ -297,13 +301,14 @@ startRPC
admin.startRPC(host, port, cors, apis [, callback])
It starts an HTTP based JSON RPC API webserver to handle client requests. All the parameters are optional.
The RPC method used is ``admin_startRPC``.

----------
Parameters
----------

1. ``host`` - ``String`` - (optional) The network interface to open the listener socket on (defaults to "localhost").
2. ``port`` - ``string | number`` - (optional) The network port to open the listener socket on (defaults to 8545).
2. ``port`` - ``number`` - (optional) The network port to open the listener socket on (defaults to 8545).
3. ``cors`` - ``string`` - (optional) Cross-origin resource sharing header to use (defaults to "").
4. ``apis`` - ``string`` - (optional) API modules to offer over this interface (defaults to "eth,net,web3").
5. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second.
Expand Down Expand Up @@ -337,13 +342,14 @@ startWS
admin.startWS(host, port, cors, apis [, callback])
It starts an WebSocket based JSON RPC API webserver to handle client requests. All the parameters are optional.
The RPC method used is ``admin_startWS``.

----------
Parameters
----------

1. ``host`` - ``String`` - (optional) The network interface to open the listener socket on (defaults to "localhost").
2. ``port`` - ``string | number`` - (optional) The network port to open the listener socket on (defaults to 8545).
2. ``port`` - ``number`` - (optional) The network port to open the listener socket on (defaults to 8545).
3. ``cors`` - ``string`` - (optional) Cross-origin resource sharing header to use (defaults to "").
4. ``apis`` - ``string`` - (optional) API modules to offer over this interface (defaults to "eth,net,web3").
5. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second.
Expand Down Expand Up @@ -376,6 +382,7 @@ stopRPC
admin.stopRPC([, callback])
This method closes the currently open HTTP RPC endpoint. As the node can only have a single HTTP endpoint running, this method takes no parameters, returning a boolean whether the endpoint was closed or not.
The RPC method used is ``admin_stopRPC``.

----------
Parameters
Expand Down Expand Up @@ -410,6 +417,7 @@ stopWS
admin.stopWS([, callback])
This method closes the currently open WebSocket RPC endpoint. As the node can only have a single WebSocket endpoint running, this method takes no parameters, returning a boolean whether the endpoint was closed or not.
The RPC method used is ``admin_stopWS``.

----------
Parameters
Expand Down
6 changes: 5 additions & 1 deletion docs/web3-eth-miner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ setExtra
miner.setExtra(extraData, [, callback])
This method allows miner to set extra data during mining the block.
The RPC method used is ``miner_setExtra``.

----------
Parameters
Expand Down Expand Up @@ -70,7 +71,7 @@ setGasPrice
miner.setGasPrice(gasPrice, [, callback])
This method allows to set minimal accepted gas price during mining transactions. Any transactions that are below this limit will get excluded from the mining process.

The RPC method used is ``miner_setGasPrice``.
----------
Parameters
----------
Expand Down Expand Up @@ -113,6 +114,7 @@ setEtherBase
miner.setEtherBase(address, [, callback])
Sets etherbase, where mining reward will go.
The RPC method used is ``miner_setEtherbase``.

----------
Parameters
Expand Down Expand Up @@ -152,6 +154,7 @@ start
miner.start(miningThread, [, callback])
Start the CPU mining process with the given number of threads.
The RPC method used is ``miner_start``.

----------
Parameters
Expand Down Expand Up @@ -194,6 +197,7 @@ stop
miner.stop([callback])
Stop the CPU mining process.
The RPC method used is ``miner_stop``.

----------
Parameters
Expand Down
6 changes: 3 additions & 3 deletions docs/web3-eth-txpool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

.. include:: include_announcement.rst

===============
web3.eth.txpool
===============
==================
Web3 Txpool Module
==================


The ``web3-eth-txpool`` package gives you access to several non-standard RPC methods to inspect the contents of the transaction pool containing all the currently pending transactions as well as the ones queued for future processing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ export default class AbstractObservedTransactionMethod extends AbstractMethod {
return;
}

this.promiEvent.emit('confirmation', confirmations, this.afterExecution(receipt));
this.promiEvent.emit(
'confirmation',
confirmations,
this.formatters.outputTransactionFormatter(receipt)
);
},
(error) => {
this.handleError(error, receipt, confirmations);
Expand Down
1 change: 0 additions & 1 deletion packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,3 @@ export SetExtraMethod from './methods/miner/SetExtraMethod';
export SetGasPriceMethod from './methods/miner/SetGasPriceMethod';
export StartMinerMethod from './methods/miner/StartMinerMethod';
export StopMinerMethod from './methods/miner/StopMinerMethod';

Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,17 @@ export default class SendRawTransactionMethod extends AbstractObservedTransactio
constructor(utils, formatters, moduleInstance, transactionObserver) {
super('eth_sendRawTransaction', 1, utils, formatters, moduleInstance, transactionObserver);
}

/**
* This method will be executed after the RPC request.
*
* @method afterExecution
*
* @param {Object} response
*
* @returns {Object}
*/
afterExecution(response) {
return this.formatters.outputTransactionFormatter(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,17 @@ export default class SendTransactionMethod extends AbstractObservedTransactionMe
beforeExecution(moduleInstance) {
this.parameters[0] = this.formatters.inputTransactionFormatter(this.parameters[0], moduleInstance);
}

/**
* This method will be executed after the RPC request.
*
* @method afterExecution
*
* @param {Object} response
*
* @returns {Object}
*/
afterExecution(response) {
return this.formatters.outputTransactionFormatter(response);
}
}
17 changes: 2 additions & 15 deletions packages/web3-core-method/src/observers/TransactionObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default class TransactionObserver {

if (receipt) {
if (this.lastBlock) {
const block = await this.getBlockByNumber(this.increaseBlockNumber(this.lastBlock.number));
const block = await this.getBlockByNumber(this.lastBlock.number + 1);

if (block && this.isValidConfirmation(block)) {
this.lastBlock = block;
Expand All @@ -164,8 +164,8 @@ export default class TransactionObserver {
}

if (this.isConfirmed()) {
clearInterval(interval);
observer.complete();
clearInterval(interval);
}
}

Expand Down Expand Up @@ -269,17 +269,4 @@ export default class TransactionObserver {
isTimeoutTimeExceeded() {
return this.confirmationChecks === this.timeout;
}

/**
* Increases the blockNumber hash by one.
*
* @method increaseBlockNumber
*
* @param {String} blockNumber
*
* @returns {String}
*/
increaseBlockNumber(blockNumber) {
return '0x' + (parseInt(blockNumber, 16) + 1).toString(16);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {formatters} from 'web3-core-helpers';
import PromiEvent from '../../../../lib/PromiEvent';
import TransactionObserver from '../../../../src/observers/TransactionObserver';
import AbstractObservedTransactionMethod from '../../../../lib/methods/transaction/AbstractObservedTransactionMethod';

// Mocks
jest.mock('web3-core-helpers');
jest.mock('../../../../src/observers/TransactionObserver');

/**
Expand Down Expand Up @@ -43,7 +45,7 @@ describe('AbstractObservedTransactionMethodTest', () => {
'rpcMethod',
5,
{},
{},
formatters,
moduleInstanceMock,
transactionObserverMock
);
Expand All @@ -68,6 +70,8 @@ describe('AbstractObservedTransactionMethodTest', () => {
it('calls execute with event listeners and is emitting the expected values', (done) => {
providerMock.send.mockReturnValueOnce(Promise.resolve('transactionHash'));

formatters.outputTransactionFormatter.mockReturnValue({status: false});

observableMock.subscribe = jest.fn((next, error, complete) => {
next({confirmations: 0, receipt: {status: true}});

Expand All @@ -88,7 +92,11 @@ describe('AbstractObservedTransactionMethodTest', () => {

expect(transactionHashCallback).toHaveBeenCalledWith('transactionHash');

expect(confirmationCallback).toHaveBeenCalledWith(0, {status: true});
expect(confirmationCallback).toHaveBeenCalledWith(0, {status: false});

expect(formatters.outputTransactionFormatter).toHaveBeenNthCalledWith(1, {status: true});

expect(formatters.outputTransactionFormatter).toHaveBeenCalledTimes(1);

done();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import AbstractObservedTransactionMethod from '../../../../lib/methods/transaction/AbstractObservedTransactionMethod';
import SendRawTransactionMethod from '../../../../src/methods/transaction/SendRawTransactionMethod';
import {formatters} from 'web3-core-helpers';

// Mocks
jest.mock('web3-core-helpers');

/**
* SendRawTransactionMethod test
Expand All @@ -8,12 +12,20 @@ describe('SendRawTransactionMethodTest', () => {
let method;

beforeEach(() => {
method = new SendRawTransactionMethod(null, null, null, {});
method = new SendRawTransactionMethod(null, formatters, null, {});
});

it('constructor check', () => {
expect(method).toBeInstanceOf(AbstractObservedTransactionMethod);

expect(method.rpcMethod).toEqual('eth_sendRawTransaction');
});

it('calls afterExecution and returns the expected value', () => {
formatters.outputTransactionFormatter.mockReturnValueOnce({status: true});

expect(method.afterExecution({status: false})).toEqual({status: true});

expect(formatters.outputTransactionFormatter).toHaveBeenCalledWith({status: false});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {formatters} from 'web3-core-helpers';
jest.mock('web3-core-helpers');

/**
* SendRawTransactionMethod test
* SendTransactionMethod test
*/
describe('SendRawTransactionMethodTest', () => {
describe('SendTransactionMethodTest', () => {
let method;

beforeEach(() => {
Expand All @@ -32,4 +32,12 @@ describe('SendRawTransactionMethodTest', () => {

expect(formatters.inputTransactionFormatter).toHaveBeenCalledWith('tx', {});
});

it('calls afterExecution and returns the expected value', () => {
formatters.outputTransactionFormatter.mockReturnValueOnce({status: true});

expect(method.afterExecution({status: false})).toEqual({status: true});

expect(formatters.outputTransactionFormatter).toHaveBeenCalledWith({status: false});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ describe('TransactionObserverTest', () => {

providerMock.supportsSubscriptions.mockReturnValueOnce(false);

const receipt = {blockNumber: '0xa'};
const blockOne = {number: '0xa', hash: '0x0'};
const blockTwo = {number: '0xc', parentHash: '0x0'};
const receipt = {blockNumber: 1};
const blockOne = {number: 1, hash: '0x0'};
const blockTwo = {number: 2, parentHash: '0x0'};

getTransactionReceiptMethodMock.execute
.mockReturnValueOnce(Promise.resolve(receipt))
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('TransactionObserverTest', () => {

expect(getTransactionReceiptMethodMock.parameters).toEqual(['transactionHash']);

expect(getBlockByNumberMethodMock.parameters).toEqual(['0xb']);
expect(getBlockByNumberMethodMock.parameters).toEqual([2]);

done();
}
Expand All @@ -235,8 +235,8 @@ describe('TransactionObserverTest', () => {

providerMock.supportsSubscriptions.mockReturnValueOnce(false);

const receipt = {blockNumber: '0xa'};
const blockOne = {number: '0xa', hash: '0x0'};
const receipt = {blockNumber: 1};
const blockOne = {number: 1, hash: '0x0'};

getTransactionReceiptMethodMock.execute.mockReturnValueOnce(Promise.resolve(receipt));

Expand Down
Loading

0 comments on commit 7499a1e

Please sign in to comment.