From e4062a0d373a6990857d77d6139112f11524fc1e Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 26 Feb 2024 10:45:04 +0900 Subject: [PATCH 1/6] Rename: getTransaction -> getTransactionByHash --- __tests__/ain.test.ts | 8 ++++---- src/ain.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/__tests__/ain.test.ts b/__tests__/ain.test.ts index 1689557..ad11a81 100644 --- a/__tests__/ain.test.ts +++ b/__tests__/ain.test.ts @@ -535,8 +535,8 @@ describe('ain-js', function() { }) }); - it('getTransaction for sendTransaction with isDryrun = true', async function () { - const tx = await ain.getTransaction(targetTxHash); + it('getTransactionByHash for sendTransaction with isDryrun = true', async function () { + const tx = await ain.getTransactionByHash(targetTxHash); expect(tx).toStrictEqual(null); // The tx is NOT in the blockchain. }); @@ -553,8 +553,8 @@ describe('ain-js', function() { }) }); - it('getTransaction for sendTransaction', async function () { - const tx = await ain.getTransaction(targetTxHash); + it('getTransactionByHash for sendTransaction', async function () { + const tx = await ain.getTransactionByHash(targetTxHash); expect(tx.transaction.tx_body.operation).toStrictEqual(targetTx); }); diff --git a/src/ain.ts b/src/ain.ts index 05b69c2..04e449e 100755 --- a/src/ain.ts +++ b/src/ain.ts @@ -129,7 +129,7 @@ export default class Ain { * @param {string} transactionHash The transaction hash. * @returns {Promise} */ - getTransaction(transactionHash: string): Promise { + getTransactionByHash(transactionHash: string): Promise { return this.provider.send('ain_getTransactionByHash', { hash: transactionHash }); } From ffed4f567c53343da2258fa5b104995c2b2ab12d Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 26 Feb 2024 11:32:26 +0900 Subject: [PATCH 2/6] Add getTransactionByBlockHashAndIndex() method --- __tests__/ain.test.ts | 7 +++++++ src/ain.ts | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/__tests__/ain.test.ts b/__tests__/ain.test.ts index ad11a81..240492f 100644 --- a/__tests__/ain.test.ts +++ b/__tests__/ain.test.ts @@ -781,6 +781,13 @@ describe('ain-js', function() { expect(thrownError.code).toEqual(30401); expect(thrownError.message).toEqual('Invalid batch transaction format.'); }); + + it('getTransactionByBlockHashAndIndex', async function () { + // TODO(platfowner): Migrate to getLastBlock(). + const genesisBlockHash = '0x31075a91beeea98fe8030c848d40b592411f2533c77d347d7937be84eae83745'; + const tx = await ain.getTransactionByBlockHashAndIndex(genesisBlockHash, 0); + expect(tx).not.toBeNull(); + }); }); describe('Database', function() { diff --git a/src/ain.ts b/src/ain.ts index 04e449e..acf9595 100755 --- a/src/ain.ts +++ b/src/ain.ts @@ -133,6 +133,15 @@ export default class Ain { return this.provider.send('ain_getTransactionByHash', { hash: transactionHash }); } + /** + * Fetches a transaction's information with a block hash and an index. + * @param {string} transactionHash The transaction hash. + * @returns {Promise} + */ + getTransactionByBlockHashAndIndex(blockHash: string, index: Number): Promise { + return this.provider.send('ain_getTransactionByBlockHashAndIndex', { block_hash: blockHash, index }); + } + /** * Fetches a blockchain app's state usage information with an app name. * @param {string} appName The blockchain app name. From 5f4cac8ecc3d3f9b96ffaca957f7109d05f10644 Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 26 Feb 2024 11:50:12 +0900 Subject: [PATCH 3/6] Add getTransactionByBlockNumberAndIndex() method --- __tests__/ain.test.ts | 6 ++++++ src/ain.ts | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/__tests__/ain.test.ts b/__tests__/ain.test.ts index 240492f..fee08f7 100644 --- a/__tests__/ain.test.ts +++ b/__tests__/ain.test.ts @@ -788,6 +788,12 @@ describe('ain-js', function() { const tx = await ain.getTransactionByBlockHashAndIndex(genesisBlockHash, 0); expect(tx).not.toBeNull(); }); + + it('getTransactionByBlockNumberAndIndex', async function () { + const genesisBlockNumber = 0; + const tx = await ain.getTransactionByBlockNumberAndIndex(genesisBlockNumber, 0); + expect(tx).not.toBeNull(); + }); }); describe('Database', function() { diff --git a/src/ain.ts b/src/ain.ts index acf9595..28de9f5 100755 --- a/src/ain.ts +++ b/src/ain.ts @@ -141,6 +141,15 @@ export default class Ain { getTransactionByBlockHashAndIndex(blockHash: string, index: Number): Promise { return this.provider.send('ain_getTransactionByBlockHashAndIndex', { block_hash: blockHash, index }); } + + /** + * Fetches a transaction's information with a block hash and an index. + * @param {string} transactionHash The transaction hash. + * @returns {Promise} + */ + getTransactionByBlockNumberAndIndex(blockNumber: Number, index: Number): Promise { + return this.provider.send('ain_getTransactionByBlockNumberAndIndex', { block_number: blockNumber, index }); + } /** * Fetches a blockchain app's state usage information with an app name. From 876094d41939caf314de65d41eb62170a3e62074 Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 26 Feb 2024 11:59:04 +0900 Subject: [PATCH 4/6] Add getPendingTransactions() method --- __tests__/ain.test.ts | 5 +++++ src/ain.ts | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/__tests__/ain.test.ts b/__tests__/ain.test.ts index fee08f7..73e78e9 100644 --- a/__tests__/ain.test.ts +++ b/__tests__/ain.test.ts @@ -782,6 +782,11 @@ describe('ain-js', function() { expect(thrownError.message).toEqual('Invalid batch transaction format.'); }); + it('getPendingTransactions', async function () { + const txs = await ain.getPendingTransactions(); + expect(txs).not.toBeNull(); + }); + it('getTransactionByBlockHashAndIndex', async function () { // TODO(platfowner): Migrate to getLastBlock(). const genesisBlockHash = '0x31075a91beeea98fe8030c848d40b592411f2533c77d347d7937be84eae83745'; diff --git a/src/ain.ts b/src/ain.ts index 28de9f5..ace2e8e 100755 --- a/src/ain.ts +++ b/src/ain.ts @@ -124,6 +124,13 @@ export default class Ain { {[byHash ? 'hash' : 'number']: blockHashOrBlockNumber}); } + /** + * Fetches pending transaction. + * @returns {Promise} + */ + getPendingTransactions(): Promise { + return this.provider.send('ain_getPendingTransactions', {}); + } /** * Fetches a transaction's information with a transaction hash. * @param {string} transactionHash The transaction hash. @@ -135,7 +142,8 @@ export default class Ain { /** * Fetches a transaction's information with a block hash and an index. - * @param {string} transactionHash The transaction hash. + * @param {string} blockHash The block hash. + * @param {number} index The transaction index in the block * @returns {Promise} */ getTransactionByBlockHashAndIndex(blockHash: string, index: Number): Promise { @@ -144,7 +152,8 @@ export default class Ain { /** * Fetches a transaction's information with a block hash and an index. - * @param {string} transactionHash The transaction hash. + * @param {string} blockNumber The block number. + * @param {number} index The transaction index in the block * @returns {Promise} */ getTransactionByBlockNumberAndIndex(blockNumber: Number, index: Number): Promise { From 99bd536d713bc1523185db28d7df83cf897cb124 Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 26 Feb 2024 12:05:53 +0900 Subject: [PATCH 5/6] Add getTransactionPoolSizeUtilization() method --- __tests__/ain.test.ts | 5 +++++ src/ain.ts | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/__tests__/ain.test.ts b/__tests__/ain.test.ts index 73e78e9..79493b5 100644 --- a/__tests__/ain.test.ts +++ b/__tests__/ain.test.ts @@ -787,6 +787,11 @@ describe('ain-js', function() { expect(txs).not.toBeNull(); }); + it('getTransactionPoolSizeUtilization', async function () { + const txs = await ain.getTransactionPoolSizeUtilization(); + expect(txs).not.toBeNull(); + }); + it('getTransactionByBlockHashAndIndex', async function () { // TODO(platfowner): Migrate to getLastBlock(). const genesisBlockHash = '0x31075a91beeea98fe8030c848d40b592411f2533c77d347d7937be84eae83745'; diff --git a/src/ain.ts b/src/ain.ts index ace2e8e..be0f7aa 100755 --- a/src/ain.ts +++ b/src/ain.ts @@ -131,6 +131,15 @@ export default class Ain { getPendingTransactions(): Promise { return this.provider.send('ain_getPendingTransactions', {}); } + + /** + * Fetches transaction pool size utilization. + * @returns {Promise} + */ + getTransactionPoolSizeUtilization(): Promise { + return this.provider.send('ain_getTransactionPoolSizeUtilization', {}); + } + /** * Fetches a transaction's information with a transaction hash. * @param {string} transactionHash The transaction hash. From bd8d90dfdc30dd219d8eef5b337256391711eefc Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 26 Feb 2024 12:34:34 +0900 Subject: [PATCH 6/6] Update test with getBlock() method call --- __tests__/ain.test.ts | 6 +++--- src/ain.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/__tests__/ain.test.ts b/__tests__/ain.test.ts index 79493b5..7a34292 100644 --- a/__tests__/ain.test.ts +++ b/__tests__/ain.test.ts @@ -793,9 +793,9 @@ describe('ain-js', function() { }); it('getTransactionByBlockHashAndIndex', async function () { - // TODO(platfowner): Migrate to getLastBlock(). - const genesisBlockHash = '0x31075a91beeea98fe8030c848d40b592411f2533c77d347d7937be84eae83745'; - const tx = await ain.getTransactionByBlockHashAndIndex(genesisBlockHash, 0); + const genesisBlockNumber = 0; + const genesisBlock = await ain.getBlock(genesisBlockNumber); + const tx = await ain.getTransactionByBlockHashAndIndex(genesisBlock.hash, 0); expect(tx).not.toBeNull(); }); diff --git a/src/ain.ts b/src/ain.ts index be0f7aa..d2abcfb 100755 --- a/src/ain.ts +++ b/src/ain.ts @@ -126,17 +126,17 @@ export default class Ain { /** * Fetches pending transaction. - * @returns {Promise} + * @returns {Promise} */ - getPendingTransactions(): Promise { + getPendingTransactions(): Promise { return this.provider.send('ain_getPendingTransactions', {}); } /** * Fetches transaction pool size utilization. - * @returns {Promise} + * @returns {Promise} */ - getTransactionPoolSizeUtilization(): Promise { + getTransactionPoolSizeUtilization(): Promise { return this.provider.send('ain_getTransactionPoolSizeUtilization', {}); }