Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPendingTransactions implemented in web3-core-methods #2655

Merged
merged 5 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export AbstractGetTransactionFromBlockMethod from '../lib/methods/transaction/Ab
export AbstractObservedTransactionMethod from '../lib/methods/transaction/AbstractObservedTransactionMethod';
export EthSendTransactionMethod from './methods/transaction/EthSendTransactionMethod';
export GetTransactionMethod from './methods/transaction/GetTransactionMethod';
export GetPendingTransactionMethod from './methods/transaction/GetPendingTransactionMethod';
export GetTransactionByBlockHashAndIndexMethod from './methods/transaction/GetTransactionByBlockHashAndIndexMethod';
export GetTransactionByBlockNumberAndIndexMethod from './methods/transaction/GetTransactionByBlockNumberAndIndexMethod';
export GetTransactionReceiptMethod from './methods/transaction/GetTransactionReceiptMethod';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
This file is part of web3.js.

web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file GetPendingTransactionMethod.js
* @author Prince Sinha <sinhaprince013@gmail.com>
* @date 2018
*/

import AbstractMethod from '../../../lib/methods/AbstractMethod';

export default class GetPendingTransactionMethod extends AbstractMethod {
princesinha19 marked this conversation as resolved.
Show resolved Hide resolved
/**
* @param {Utils} utils
* @param {Object} formatters
* @param {AbstractWeb3Module} moduleInstance
*
* @constructor
*/
constructor(utils, formatters, moduleInstance) {
super('eth_pendingTransactions', 0, utils, formatters, moduleInstance);
nivida marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* This method will be executed after the RPC request.
*
* @method afterExecution
*
* @param {Object} response
*
* @returns {Object}
*/
afterExecution(response) {
princesinha19 marked this conversation as resolved.
Show resolved Hide resolved
if (response.length === 0) {
return 'No Pending Transactions !!';
princesinha19 marked this conversation as resolved.
Show resolved Hide resolved
} else {
return response;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {formatters} from 'web3-core-helpers';
import AbstractMethod from '../../../../lib/methods/AbstractMethod';
import GetPendingTransactionMethod from '../../../../src/methods/transaction/GetPendingTransactionMethod';

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

/**
* GetPendingTransactionMethod test
*/
describe('GetPendingTransactionMethodTest', () => {
let method;

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

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

expect(method.rpcMethod).toEqual('eth_pendingTransactions');

expect(method.parametersAmount).toEqual(0);

expect(method.utils).toEqual(null);

expect(method.formatters).toEqual(formatters);
});
});
2 changes: 2 additions & 0 deletions packages/web3-eth/src/factories/MethodFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
GetStorageAtMethod,
GetTransactionCountMethod,
GetTransactionMethod,
GetPendingTransactionMethod,
GetTransactionReceiptMethod,
GetWorkMethod,
IsMiningMethod,
Expand Down Expand Up @@ -85,6 +86,7 @@ export default class MethodFactory extends AbstractMethodFactory {
getBlockTransactionCount: GetBlockTransactionCountMethod,
getBlockUncleCount: GetBlockUncleCountMethod,
getTransaction: GetTransactionMethod,
getPendingTransactions: GetPendingTransactionMethod,
getTransactionFromBlock: GetTransactionFromBlockMethod,
getTransactionReceipt: GetTransactionReceiptMethod,
getTransactionCount: GetTransactionCountMethod,
Expand Down
2 changes: 2 additions & 0 deletions packages/web3-eth/tests/src/factories/MethodFactoryTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
GetStorageAtMethod,
GetTransactionCountMethod,
GetTransactionMethod,
GetPendingTransactionMethod,
GetTransactionReceiptMethod,
GetWorkMethod,
IsMiningMethod,
Expand Down Expand Up @@ -74,6 +75,7 @@ describe('MethodFactoryTest', () => {
getBlockTransactionCount: GetBlockTransactionCountMethod,
getBlockUncleCount: GetBlockUncleCountMethod,
getTransaction: GetTransactionMethod,
getPendingTransactions: GetPendingTransactionMethod,
getTransactionFromBlock: GetTransactionFromBlockMethod,
getTransactionReceipt: GetTransactionReceiptMethod,
getTransactionCount: GetTransactionCountMethod,
Expand Down