Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #308 from Zilliqa/feat/remove-get-pending-txn
Browse files Browse the repository at this point in the history
feat/remove-get-pending-txn
  • Loading branch information
bb111189 authored Jun 2, 2021
2 parents 5f847eb + c4e8a4a commit 51e03f4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 70 deletions.
13 changes: 13 additions & 0 deletions packages/zilliqa-js-blockchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,19 @@ for (const tx of batchResults) {
}
```

### `getTransactionStatus(txHash: string): Promise<RPCResponse<TransactionStatusObj>`

Returns the status of a specified transaction. This API is available from Zilliqa V7.0.0 onwards and supports all transaction statuses (unconfirmed, confirmed, and rejected).

**Parameters**
- `txHash`: `string` - Specified TX id to check for the status.

**Returns**

- `Promise<RPCResponse<TransactionStatusObj>` - Status code of the transaction. Refer to [GetTransactionStatus](https://dev.zilliqa.com/docs/apis/api-transaction-get-transaction-status) for the full list of status code.

*Note: This API is available only on https://api.zilliqa.com/. It is disabled for community-hosted or private-hosted seed nodes.*

### `getTxnBodiesForTxBlock(txBlock: number): Promise<RPCResponse<TransactionObj[], string>>`

Returns the validated transactions (in verbose form) included within a specified final transaction block.
Expand Down
27 changes: 0 additions & 27 deletions packages/zilliqa-js-blockchain/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import {
DsBlockObj,
GET_TX_ATTEMPTS,
TransactionStatusObj,
TransactionStatus,
PendingTxns,
Provider,
RPCMethod,
RPCResponse,
Expand Down Expand Up @@ -649,31 +647,6 @@ export class Blockchain implements ZilliqaModule {
return this.provider.send<string, string>(RPCMethod.GetMinimumGasPrice);
}

/**
* getPendingTxns
*
* Returns the pending status of all unvalidated Transactions.
*
*/
async getPendingTxns(): Promise<PendingTxns> {
try {
const response = await this.provider.send(RPCMethod.GetPendingTxns);
if (response.error) {
return Promise.reject(response.error);
}

if (response.result.Txns.length) {
response.result.Txns.forEach((txn: TransactionStatus) => {
txn.info = this.pendingErrorMap[txn.code];
});
}

return response.result;
} catch (err) {
throw err;
}
}

/**
* getBalance
*
Expand Down
31 changes: 0 additions & 31 deletions packages/zilliqa-js-blockchain/test/chain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,37 +308,6 @@ describe('Module: Blockchain', () => {
expect(result.statusMessage).toEqual('Confirmed');
});

it('should receive pending transaction list', async () => {
const responses = [
{
id: 1,
jsonrpc: '2.0',
result: {
Txns: [
{
code: 1,
TxnHash:
'ec5ef8110a285563d0104269081aa77820058067091a9b3f3ae70f38b94abda3',
},
],
},
},
].map((res) => [JSON.stringify(res)] as [string]);

fetch.mockResponses(...responses);
const result = await blockchain.getPendingTxns();
expect(result.Txns).toBeDefined();
// @ts-ignore
expect(result.Txns).toEqual([
{
code: 1,
TxnHash:
'ec5ef8110a285563d0104269081aa77820058067091a9b3f3ae70f38b94abda3',
info: 'Pending - Dispatched',
},
]);
});

it('should receive miner info', async () => {
const responses = [
{
Expand Down
2 changes: 0 additions & 2 deletions packages/zilliqa-js-core/src/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ export enum RPCMethod {
GetNumTxnsTxEpoch = 'GetNumTxnsTxEpoch',
GetNumTxnsDSEpoch = 'GetNumTxnsDSEpoch',
GetMinimumGasPrice = 'GetMinimumGasPrice',
GetPendingTxn = 'GetPendingTxn',
GetPendingTxns = 'GetPendingTxns',

// Contract-related methods
GetSmartContracts = 'GetSmartContracts',
Expand Down
10 changes: 0 additions & 10 deletions packages/zilliqa-js-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,22 +258,12 @@ export interface EventParam {
value: any;
}

export interface PendingTxns {
Txns: TransactionStatus[];
}

export interface TransactionStatus {
code: number;
TxnHash: string;
info: string;
}

export interface PendingTxnResult {
code: number;
confirmed: boolean;
pending: boolean;
}

export interface MinerInfo {
dscommittee: string[];
shards: ShardInfo[];
Expand Down

0 comments on commit 51e03f4

Please sign in to comment.