Skip to content

Commit

Permalink
Merge pull request #2655 from princesinha19/pending_transaction
Browse files Browse the repository at this point in the history
getPendingTransactions implemented in web3-core-methods
  • Loading branch information
nivida authored Apr 8, 2019
2 parents 839283a + 414148e commit 441c309
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 0 deletions.
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 GetPendingTransactionsMethod from './methods/transaction/GetPendingTransactionsMethod';
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,36 @@
/*
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 GetPendingTransactionsMethod.js
* @author Prince Sinha <sinhaprince013@gmail.com>
* @date 2018
*/

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

export default class GetPendingTransactionsMethod extends AbstractMethod {
/**
* @param {Utils} utils
* @param {Object} formatters
* @param {AbstractWeb3Module} moduleInstance
*
* @constructor
*/
constructor(utils, formatters, moduleInstance) {
super('eth_pendingTransactions', 0, utils, formatters, moduleInstance);
}
}
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 GetPendingTransactionsMethod from '../../../../src/methods/transaction/GetPendingTransactionsMethod';

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

/**
* GetPendingTransactionsMethod test
*/
describe('GetPendingTransactionsMethodTest', () => {
let method;

beforeEach(() => {
method = new GetPendingTransactionsMethod(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,
GetPendingTransactionsMethod,
GetTransactionReceiptMethod,
GetWorkMethod,
IsMiningMethod,
Expand Down Expand Up @@ -85,6 +86,7 @@ export default class MethodFactory extends AbstractMethodFactory {
getBlockTransactionCount: GetBlockTransactionCountMethod,
getBlockUncleCount: GetBlockUncleCountMethod,
getTransaction: GetTransactionMethod,
getPendingTransactions: GetPendingTransactionsMethod,
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,
GetPendingTransactionsMethod,
GetTransactionReceiptMethod,
GetWorkMethod,
IsMiningMethod,
Expand Down Expand Up @@ -74,6 +75,7 @@ describe('MethodFactoryTest', () => {
getBlockTransactionCount: GetBlockTransactionCountMethod,
getBlockUncleCount: GetBlockUncleCountMethod,
getTransaction: GetTransactionMethod,
getPendingTransactions: GetPendingTransactionsMethod,
getTransactionFromBlock: GetTransactionFromBlockMethod,
getTransactionReceipt: GetTransactionReceiptMethod,
getTransactionCount: GetTransactionCountMethod,
Expand Down
2 changes: 2 additions & 0 deletions packages/web3-eth/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ export class Eth extends AbstractWeb3Module {
getWork(callback?: (error: Error, result: string[]) => void): Promise<string[]>;

submitWork(data: [string, string, string], callback?: (error: Error, result: boolean) => void): Promise<boolean>;

pendingTransactions(callback?: (error: Error, result: []) => void): Promise<[]>;
}

export interface Methods {
Expand Down
6 changes: 6 additions & 0 deletions packages/web3-eth/types/tests/eth.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,9 @@ eth.submitWork(
],
(error: Error, result: boolean) => {}
);

// $ExpectType Promise<[]>
eth.pendingTransactions();

// $ExpectType Promise<[]>
eth.pendingTransactions((error: Error, result: []) => {});

0 comments on commit 441c309

Please sign in to comment.