Skip to content

Commit

Permalink
Merge branch '1.x' into dependencies/updating-of-eth-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
nivida committed Nov 26, 2019
2 parents 8856943 + e914ec3 commit 59967b5
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ 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)
- ``getPendingTransactions`` added to web3-eth package (#3239)

### Changed

Expand Down
82 changes: 82 additions & 0 deletions docs/web3-eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,89 @@ Example
"input": "0x57cb2fc4"
}
------------------------------------------------------------------------------

.. _eth-getpendingtransactions:

getPendingTransactions
======================

.. code-block:: javascript
web3.eth.getPendingTransactions([, callback])
Returns a list of pending transactions.

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

1. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second.


.. _eth-getpendingtransactions-return:

-------
Returns
-------


``Promise<object[]>`` - Array of pending transactions:

- ``hash`` 32 Bytes - ``String``: Hash of the transaction.
- ``nonce`` - ``Number``: The number of transactions made by the sender prior to this one.
- ``blockHash`` 32 Bytes - ``String``: Hash of the block where this transaction was in. ``null`` when its pending.
- ``blockNumber`` - ``Number``: Block number where this transaction was in. ``null`` when its pending.
- ``transactionIndex`` - ``Number``: Integer of the transactions index position in the block. ``null`` when its pending.
- ``from`` - ``String``: Address of the sender.
- ``to`` - ``String``: Address of the receiver. ``null`` when its a contract creation transaction.
- ``value`` - ``String``: Value transferred in :ref:`wei <what-is-wei>`.
- ``gasPrice`` - ``String``: The wei per unit of gas provided by the sender in :ref:`wei <what-is-wei>`.
- ``gas`` - ``Number``: Gas provided by the sender.
- ``input`` - ``String``: The data sent along with the transaction.



-------
Example
-------

.. code-block:: javascript
web3.eth.getPendingTransactions().then(console.log);
> [
{
hash: '0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b',
nonce: 2,
blockHash: '0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46',
blockNumber: 3,
transactionIndex: 0,
from: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
to: '0x6295ee1b4f6dd65047762f924ecd367c17eabf8f',
value: '123450000000000000',
gas: 314159,
gasPrice: '2000000000000',
input: '0x57cb2fc4'
v: '0x3d',
r: '0xaabc9ddafffb2ae0bac4107697547d22d9383667d9e97f5409dd6881ce08f13f',
s: '0x69e43116be8f842dcd4a0b2f760043737a59534430b762317db21d9ac8c5034'
},....,{
hash: '0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b',
nonce: 3,
blockHash: '0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46',
blockNumber: 4,
transactionIndex: 0,
from: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
to: '0x6295ee1b4f6dd65047762f924ecd367c17eabf8f',
value: '123450000000000000',
gas: 314159,
gasPrice: '2000000000000',
input: '0x57cb2fc4'
v: '0x3d',
r: '0xaabc9ddafffb2ae0bac4107697547d22d9383667d9e97f5409dd6881ce08f13f',
s: '0x69e43116be8f842dcd4a0b2f760043737a59534430b762317db21d9ac8c5034'
}
]
------------------------------------------------------------------------------

Expand Down
23 changes: 18 additions & 5 deletions packages/web3-eth-abi/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ ABICoder.prototype.encodeEventSignature = function (functionName) {
* Should be used to encode plain param
*
* @method encodeParameter
* @param {String} type
* @param {Object} param
*
* @param {String|Object} type
* @param {any} param
*
* @return {String} encoded plain param
*/
ABICoder.prototype.encodeParameter = function (type, param) {
Expand All @@ -88,12 +90,23 @@ ABICoder.prototype.encodeParameter = function (type, param) {
* Should be used to encode list of params
*
* @method encodeParameters
* @param {Array} types
* @param {Array} params
*
* @param {Array<String|Object>} types
* @param {Array<any>} params
*
* @return {String} encoded list of params
*/
ABICoder.prototype.encodeParameters = function (types, params) {
return ethersAbiCoder.encode(this.mapTypes(types), params);
return ethersAbiCoder.encode(
this.mapTypes(types),
params.map(function (param) {
if (utils.isBN(param) || utils.isBigNumber(param)) {
return param.toString(10);
}

return param;
})
);
};

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/web3-eth/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@ var Eth = function Eth() {
inputFormatter: [formatter.inputAddressFormatter, formatter.inputStorageKeysFormatter, formatter.inputDefaultBlockNumberFormatter],
outputFormatter: formatter.outputProofFormatter
}),
new Method({
name: 'getPendingTransactions',
call: 'eth_pendingTransactions',
params: 0,
outputFormatter: formatter.outputTransactionFormatter
}),

// subscriptions
new Subscriptions({
Expand Down
24 changes: 23 additions & 1 deletion test/abi.encodeParameter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var chai = require('chai');
var assert = chai.assert;
var BN = require('bn.js');
var BigNumber = require('bignumber.js');
var coder = require('../packages/web3-eth-abi');


Expand Down Expand Up @@ -305,7 +307,17 @@ describe('lib/solidity/coder', function () {
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000120' +
'000000000000000000000000000000000000000000000000000000000000000f' +
'74657374696e672074657374696e670000000000000000000000000000000000' })
'74657374696e672074657374696e670000000000000000000000000000000000' });
test({
type: 'uint256',
value: new BN(42),
expected: '000000000000000000000000000000000000000000000000000000000000002a'
});
test({
type: 'uint256',
value: new BigNumber(42),
expected: '000000000000000000000000000000000000000000000000000000000000002a'
});
});
});

Expand Down Expand Up @@ -656,6 +668,16 @@ describe('lib/solidity/coder', function () {
'bc00000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000001' +
'de00000000000000000000000000000000000000000000000000000000000000' })
test({
types: ['uint256', 'uint256'],
values: [new BN(42), new BN(42)],
expected: '000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000002a'
});
test({
types: ['uint256', 'uint256'],
values: [new BigNumber(42), new BigNumber(42)],
expected: '000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000002a'
});
});
});

Expand Down
44 changes: 44 additions & 0 deletions test/eth.getPendingTransactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var testMethod = require('./helpers/test.method.js');

var unformattedTx = {
"hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"nonce":"0x5",
"blockHash": "0x6fd9e2a26ab",
"blockNumber": "0x15df",
"transactionIndex": "0x1",
"from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
"to":"0x85f43d8a49eeb85d32cf465507dd71d507100c1d",
"value":"0x7f110",
"gas": "0x7f110",
"gasPrice":"0x09184e72a000",
"input":"0x603880600c6000396000f30060"
};

var result = [unformattedTx, unformattedTx];

var formattedTx = {
"hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"nonce":5,
"blockHash": "0x6fd9e2a26ab",
"blockNumber": 5599,
"transactionIndex": 1,
"from":"0x407D73d8a49eeb85D32Cf465507dd71d507100c1", // checksum address
"to":"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d", // checksum address
"value": '520464',
"gas": 520464,
"gasPrice": '10000000000000',
"input":"0x603880600c6000396000f30060"
};

var formattedResult = [formattedTx, formattedTx];

var tests = [{
args: [],
formattedArgs: [],
result: result,
formattedResult: formattedResult,
call: 'eth_pendingTransactions'
}];

testMethod.runTests('eth', 'getPendingTransactions', tests);

0 comments on commit 59967b5

Please sign in to comment.