From 992702dea142411e08e111817804207435103079 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Thu, 11 Nov 2021 21:05:44 +0530 Subject: [PATCH 01/13] eth_getTransactionsByBlockNumber and eth_getTransactionReceiptsByBlockNumber api dev --- etc/methods.yaml | 13 ++++++- lib/servers/database.d.ts | 2 + lib/servers/database.js | 64 ++++++++++++++++++++++++++++++ lib/servers/skeleton.d.ts | 2 + lib/servers/skeleton.js | 8 ++++ lib/web3.d.ts | 2 + src/servers/database.ts | 82 ++++++++++++++++++++++++++++++++++++++- src/servers/skeleton.ts | 15 ++++++- src/web3.ts | 8 ++++ 9 files changed, 193 insertions(+), 3 deletions(-) diff --git a/etc/methods.yaml b/etc/methods.yaml index 3e720f84..898f4049 100644 --- a/etc/methods.yaml +++ b/etc/methods.yaml @@ -211,7 +211,18 @@ eth_getTransactionByBlockNumberAndIndex: implementations: - etc/schema/functions/eth_getTransactionByBlockNumberAndIndex.sql - src/servers/skeleton.ts - +eth_getTransactionByBlockNumber: + status: ok + comment: + link: https://eth.wiki/json-rpc/API#eth_getTransactionByBlockNumber + implementations: + - src/servers/skeleton.ts +eth_getTransactionReceiptsByBlockNumber: + status: ok + comment: + link: https://eth.wiki/json-rpc/API#eth_getTransactionReceiptsByBlockNumber + implementations: + - src/servers/skeleton.ts eth_getTransactionByHash: status: wip comment: diff --git a/lib/servers/database.d.ts b/lib/servers/database.d.ts index 084c19de..f63f465b 100644 --- a/lib/servers/database.d.ts +++ b/lib/servers/database.d.ts @@ -21,10 +21,12 @@ export declare class DatabaseServer extends SkeletonServer { eth_getLogs(_request: any, filter: web3.FilterOptions): Promise; eth_getStorageAt(_request: any, address: web3.Data, key: web3.Quantity, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionByBlockHashAndIndex(_request: any, blockHash: web3.Data, transactionIndex: web3.Quantity): Promise; + eth_getTransactionsByBlockNumber(_request: any, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionByBlockNumberAndIndex(_request: any, blockNumber: web3.Quantity | web3.Tag, transactionIndex: web3.Quantity): Promise; eth_getTransactionByHash(_request: any, transactionHash: web3.Data): Promise; eth_getTransactionCount(_request: any, address: web3.Data, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionReceipt(_request: any, transactionHash: string): Promise; + eth_getTransactionReceiptsByBlockNumber(_request: any, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getUncleCountByBlockHash(_request: any, blockHash: web3.Data): Promise; eth_getUncleCountByBlockNumber(_request: any, blockNumber: web3.Quantity | web3.Tag): Promise; eth_newBlockFilter(_request: any): Promise; diff --git a/lib/servers/database.js b/lib/servers/database.js index b5c7dcc1..ef0a76a5 100644 --- a/lib/servers/database.js +++ b/lib/servers/database.js @@ -285,6 +285,36 @@ export class DatabaseServer extends SkeletonServer { return null; } } + async eth_getTransactionsByBlockNumber(_request, blockNumber) { + const blockNumber_ = parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()); + try { + const { rows, } = await this._query(`SELECT + b.id AS "blockNumber", + b.hash AS "blockHash", + t.index AS "transactionIndex", + t.hash AS "hash", + t.from AS "from", + t.to AS "to", + t.gas_limit AS "gas", + t.gas_price AS "gasPrice", + t.nonce AS "nonce", + t.value AS "value", + coalesce(t.input, '\\x'::bytea) AS "input", + t.v AS "v", + t.r AS "r", + t.s AS "s" + FROM transaction t + LEFT JOIN block b ON t.block = b.id + WHERE b.id = $1`, [blockNumber_]); + return !rows || !rows.length ? null : exportJSON(rows[0]); + } + catch (error) { + if (this.config.debug) { + console.debug('eth_getTransactionsByBlockNumber', error); + } + return null; + } + } async eth_getTransactionByBlockNumberAndIndex(_request, blockNumber, transactionIndex) { const blockNumber_ = parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()); const transactionIndex_ = parseInt(transactionIndex); @@ -340,6 +370,40 @@ export class DatabaseServer extends SkeletonServer { return null; } } + async eth_getTransactionReceiptsByBlockNumber(_request, blockNumber) { + const blockNumber_ = parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()); + try { + const { rows: [receipt], } = await this._query(`SELECT + b.id AS "blockNumber", + b.hash AS "blockHash", + t.index AS "transactionIndex", + t.hash AS "transactionHash", + t.from AS "from", + t.to AS "to", + t.gas_used AS "gasUsed", + 0::u256 AS "cumulativeGasUsed", -- TODO: tally? + CASE WHEN t.to IS NULL OR t.to = '\\x0000000000000000000000000000000000000000' THEN t.output + ELSE NULL + END AS "contractAddress", + NULL AS "logs", -- TODO: fetch event.id[] + repeat('\\000', 256)::bytea AS "logsBloom", + CASE WHEN t.status THEN 1 ELSE 0 END AS "status", + t.near_hash AS "nearTransactionHash", + t.near_receipt_hash AS "nearReceiptHash" + FROM transaction t + LEFT JOIN block b ON t.block = b.id + WHERE b.id = $1`, [blockNumber_]); + //assert(receipt, 'receipt is not null'); + receipt.logs = await this._fetchEvents(hexToBytes(receipt.transactionHash.toString())); + return exportJSON(receipt); + } + catch (error) { + if (this.config.debug) { + console.debug('eth_getTransactionReceiptsByBlockNumber', error); + } + return null; + } + } async eth_getUncleCountByBlockHash(_request, blockHash) { const blockHash_ = blockHash.startsWith('0x') ? hexToBytes(blockHash) diff --git a/lib/servers/skeleton.d.ts b/lib/servers/skeleton.d.ts index 079c58d1..f4c37a79 100644 --- a/lib/servers/skeleton.d.ts +++ b/lib/servers/skeleton.d.ts @@ -44,6 +44,8 @@ export declare abstract class SkeletonServer implements web3.Service { eth_getStorageAt(_request: any, _address: web3.Data, _key: web3.Quantity, _blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionByBlockHashAndIndex(_request: any, _blockHash: web3.Data, _transactionIndex: web3.Quantity): Promise; eth_getTransactionByBlockNumberAndIndex(_request: any, _blockNumber: web3.Quantity | web3.Tag, _transactionIndex: web3.Quantity): Promise; + eth_getTransactionsByBlockNumber(_request: any, _blockNumber: web3.Quantity | web3.Tag): Promise; + eth_getTransactionReceiptsByBlockNumber(_request: any, _blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionByHash(_request: any, _transactionHash: web3.Data): Promise; eth_getTransactionCount(_request: any, _address: web3.Data, _blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionReceipt(_request: any, _transactionHash: string): Promise; diff --git a/lib/servers/skeleton.js b/lib/servers/skeleton.js index 1e75c621..e394b756 100644 --- a/lib/servers/skeleton.js +++ b/lib/servers/skeleton.js @@ -173,6 +173,14 @@ export class SkeletonServer { unimplemented('eth_getTransactionByBlockNumberAndIndex'); return null; } + async eth_getTransactionsByBlockNumber(_request, _blockNumber) { + unimplemented('eth_getTransactionsByBlockNumber'); + return null; + } + async eth_getTransactionReceiptsByBlockNumber(_request, _blockNumber) { + unimplemented('eth_getTransactionReceiptsByBlockNumber'); + return null; + } async eth_getTransactionByHash(_request, _transactionHash) { unimplemented('eth_getTransactionByHash'); return null; diff --git a/lib/web3.d.ts b/lib/web3.d.ts index 711a2aef..8b956e65 100644 --- a/lib/web3.d.ts +++ b/lib/web3.d.ts @@ -77,6 +77,8 @@ export interface Service { eth_getProof(_request: any, address: Data, keys: Data[], blockNumber: Quantity | Tag): Promise; eth_getStorageAt(_request: any, address: Data, key: Quantity, blockNumber: Quantity | Tag): Promise; eth_getTransactionByBlockHashAndIndex(_request: any, blockHash: Data, transactionIndex: Quantity): Promise; + eth_getTransactionsByBlockNumber(_request: any, blockNumber: Quantity | Tag): Promise; + eth_getTransactionReceiptsByBlockNumber(_request: any, blockNumber: Quantity | Tag): Promise; eth_getTransactionByBlockNumberAndIndex(_request: any, blockNumber: Quantity | Tag, transactionIndex: Quantity): Promise; eth_getTransactionByHash(_request: any, transactionHash: Data): Promise; eth_getTransactionCount(_request: any, address: Data, blockNumber: Quantity | Tag): Promise; diff --git a/src/servers/database.ts b/src/servers/database.ts index b20d28fa..8db844a1 100644 --- a/src/servers/database.ts +++ b/src/servers/database.ts @@ -461,7 +461,45 @@ export class DatabaseServer extends SkeletonServer { return null; } } - + async eth_getTransactionsByBlockNumber( + _request: any, + blockNumber: web3.Quantity | web3.Tag + ): Promise { + const blockNumber_ = + parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()); + + try { + const { + rows, + } = await this._query( + `SELECT + b.id AS "blockNumber", + b.hash AS "blockHash", + t.index AS "transactionIndex", + t.hash AS "hash", + t.from AS "from", + t.to AS "to", + t.gas_limit AS "gas", + t.gas_price AS "gasPrice", + t.nonce AS "nonce", + t.value AS "value", + coalesce(t.input, '\\x'::bytea) AS "input", + t.v AS "v", + t.r AS "r", + t.s AS "s" + FROM transaction t + LEFT JOIN block b ON t.block = b.id + WHERE b.id = $1`, + [blockNumber_] + ); + return !rows || !rows.length ? null : exportJSON(rows[0]); + } catch (error) { + if (this.config.debug) { + console.debug('eth_getTransactionsByBlockNumber', error); + } + return null; + } + } async eth_getTransactionByBlockNumberAndIndex( _request: any, blockNumber: web3.Quantity | web3.Tag, @@ -546,7 +584,49 @@ export class DatabaseServer extends SkeletonServer { return null; } } + async eth_getTransactionReceiptsByBlockNumber( + _request: any, + blockNumber: web3.Quantity | web3.Tag + ): Promise { + const blockNumber_ = + parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()); + try { + const { + rows: [receipt], + } = await this._query( + `SELECT + b.id AS "blockNumber", + b.hash AS "blockHash", + t.index AS "transactionIndex", + t.hash AS "transactionHash", + t.from AS "from", + t.to AS "to", + t.gas_used AS "gasUsed", + 0::u256 AS "cumulativeGasUsed", -- TODO: tally? + CASE WHEN t.to IS NULL OR t.to = '\\x0000000000000000000000000000000000000000' THEN t.output + ELSE NULL + END AS "contractAddress", + NULL AS "logs", -- TODO: fetch event.id[] + repeat('\\000', 256)::bytea AS "logsBloom", + CASE WHEN t.status THEN 1 ELSE 0 END AS "status", + t.near_hash AS "nearTransactionHash", + t.near_receipt_hash AS "nearReceiptHash" + FROM transaction t + LEFT JOIN block b ON t.block = b.id + WHERE b.id = $1`, + [blockNumber_] + ); + //assert(receipt, 'receipt is not null'); + receipt.logs = await this._fetchEvents(hexToBytes(receipt.transactionHash.toString())); + return exportJSON(receipt); + } catch (error) { + if (this.config.debug) { + console.debug('eth_getTransactionReceiptsByBlockNumber', error); + } + return null; + } + } async eth_getUncleCountByBlockHash( _request: any, blockHash: web3.Data diff --git a/src/servers/skeleton.ts b/src/servers/skeleton.ts index 48ea97c3..02aad212 100644 --- a/src/servers/skeleton.ts +++ b/src/servers/skeleton.ts @@ -283,7 +283,20 @@ export abstract class SkeletonServer implements web3.Service { unimplemented('eth_getTransactionByBlockNumberAndIndex'); return null; } - + async eth_getTransactionsByBlockNumber( + _request: any, + _blockNumber: web3.Quantity | web3.Tag + ): Promise { + unimplemented('eth_getTransactionsByBlockNumber'); + return null; + } + async eth_getTransactionReceiptsByBlockNumber( + _request: any, + _blockNumber: web3.Quantity | web3.Tag + ): Promise { + unimplemented('eth_getTransactionReceiptsByBlockNumber'); + return null; + } async eth_getTransactionByHash( _request: any, _transactionHash: web3.Data diff --git a/src/web3.ts b/src/web3.ts index 0d569024..365626f1 100644 --- a/src/web3.ts +++ b/src/web3.ts @@ -140,6 +140,14 @@ export interface Service { blockHash: Data, transactionIndex: Quantity ): Promise; + eth_getTransactionsByBlockNumber( + _request: any, + blockNumber: Quantity | Tag, + ): Promise; + eth_getTransactionReceiptsByBlockNumber( + _request: any, + blockNumber: Quantity | Tag, + ): Promise; eth_getTransactionByBlockNumberAndIndex( _request: any, blockNumber: Quantity | Tag, From 51a620d7888197509d49dc0d328d2dc14cc8f5e9 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Thu, 18 Nov 2021 18:32:12 +0530 Subject: [PATCH 02/13] Bog fix for eth_getTransactionsByBlockNumber eth_getTransactionReceiptsByBlockNumber --- etc/methods.yaml | 6 +++--- lib/servers/database.js | 24 +++++++++++++++--------- src/servers/database.ts | 25 +++++++++++++------------ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/etc/methods.yaml b/etc/methods.yaml index 898f4049..34f7fce8 100644 --- a/etc/methods.yaml +++ b/etc/methods.yaml @@ -211,16 +211,16 @@ eth_getTransactionByBlockNumberAndIndex: implementations: - etc/schema/functions/eth_getTransactionByBlockNumberAndIndex.sql - src/servers/skeleton.ts -eth_getTransactionByBlockNumber: +eth_getTransactionsByBlockNumber: status: ok comment: - link: https://eth.wiki/json-rpc/API#eth_getTransactionByBlockNumber + link: implementations: - src/servers/skeleton.ts eth_getTransactionReceiptsByBlockNumber: status: ok comment: - link: https://eth.wiki/json-rpc/API#eth_getTransactionReceiptsByBlockNumber + link: implementations: - src/servers/skeleton.ts eth_getTransactionByHash: diff --git a/lib/servers/database.js b/lib/servers/database.js index 0a6ef6ad..6db7fd2a 100644 --- a/lib/servers/database.js +++ b/lib/servers/database.js @@ -287,7 +287,9 @@ export class DatabaseServer extends SkeletonServer { } } async eth_getTransactionsByBlockNumber(_request, blockNumber) { - const blockNumber_ = parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()); + const blockNumber_ = parseBlockSpec(blockNumber) != 0 + ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) + : parseBlockSpec(blockNumber); try { const { rows, } = await this._query(`SELECT b.id AS "blockNumber", @@ -307,7 +309,7 @@ export class DatabaseServer extends SkeletonServer { FROM transaction t LEFT JOIN block b ON t.block = b.id WHERE b.id = $1`, [blockNumber_]); - return !rows || !rows.length ? null : exportJSON(rows[0]); + return !rows || !rows.length ? null : exportJSON(rows); } catch (error) { if (this.config.debug) { @@ -372,9 +374,12 @@ export class DatabaseServer extends SkeletonServer { } } async eth_getTransactionReceiptsByBlockNumber(_request, blockNumber) { - const blockNumber_ = parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()); + const blockNumber_ = parseBlockSpec(blockNumber) != 0 + ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) + : parseBlockSpec(blockNumber); try { - const { rows: [receipt], } = await this._query(`SELECT + console.log(blockNumber_); + const { rows, } = await this._query(`SELECT b.id AS "blockNumber", b.hash AS "blockHash", t.index AS "transactionIndex", @@ -388,15 +393,16 @@ export class DatabaseServer extends SkeletonServer { END AS "contractAddress", NULL AS "logs", -- TODO: fetch event.id[] repeat('\\000', 256)::bytea AS "logsBloom", - CASE WHEN t.status THEN 1 ELSE 0 END AS "status", - t.near_hash AS "nearTransactionHash", - t.near_receipt_hash AS "nearReceiptHash" + CASE WHEN t.status THEN 1 ELSE 0 END AS "status" FROM transaction t LEFT JOIN block b ON t.block = b.id WHERE b.id = $1`, [blockNumber_]); //assert(receipt, 'receipt is not null'); - receipt.logs = await this._fetchEvents(hexToBytes(receipt.transactionHash.toString())); - return exportJSON(receipt); + //rows[0].logs = await this._fetchEvents(hexToBytes(receipt.transactionHash.toString())); + for (var i = 0; i < rows.length; i++) { + rows[i].logs = await this._fetchEvents(hexToBytes(rows[i].transactionHash.toString())); + } + return exportJSON(rows); } catch (error) { if (this.config.debug) { diff --git a/src/servers/database.ts b/src/servers/database.ts index 87d895ea..8bc0c206 100644 --- a/src/servers/database.ts +++ b/src/servers/database.ts @@ -469,8 +469,9 @@ export class DatabaseServer extends SkeletonServer { _request: any, blockNumber: web3.Quantity | web3.Tag ): Promise { - const blockNumber_ = - parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()); + const blockNumber_ = parseBlockSpec(blockNumber) != 0 + ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) + : parseBlockSpec(blockNumber); try { const { @@ -496,7 +497,7 @@ export class DatabaseServer extends SkeletonServer { WHERE b.id = $1`, [blockNumber_] ); - return !rows || !rows.length ? null : exportJSON(rows[0]); + return !rows || !rows.length ? null : exportJSON(rows); } catch (error) { if (this.config.debug) { console.debug('eth_getTransactionsByBlockNumber', error); @@ -592,11 +593,12 @@ export class DatabaseServer extends SkeletonServer { _request: any, blockNumber: web3.Quantity | web3.Tag ): Promise { - const blockNumber_ = - parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()); + const blockNumber_ = parseBlockSpec(blockNumber) != 0 + ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) + : parseBlockSpec(blockNumber); try { const { - rows: [receipt], + rows, } = await this._query( `SELECT b.id AS "blockNumber", @@ -612,18 +614,17 @@ export class DatabaseServer extends SkeletonServer { END AS "contractAddress", NULL AS "logs", -- TODO: fetch event.id[] repeat('\\000', 256)::bytea AS "logsBloom", - CASE WHEN t.status THEN 1 ELSE 0 END AS "status", - t.near_hash AS "nearTransactionHash", - t.near_receipt_hash AS "nearReceiptHash" + CASE WHEN t.status THEN 1 ELSE 0 END AS "status" FROM transaction t LEFT JOIN block b ON t.block = b.id WHERE b.id = $1`, [blockNumber_] ); //assert(receipt, 'receipt is not null'); - - receipt.logs = await this._fetchEvents(hexToBytes(receipt.transactionHash.toString())); - return exportJSON(receipt); + for(var i = 0;i Date: Thu, 18 Nov 2021 19:00:20 +0530 Subject: [PATCH 03/13] update lib --- lib/servers/database.d.ts | 2 ++ lib/servers/database.js | 2 -- lib/servers/skeleton.d.ts | 2 ++ lib/web3.d.ts | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/servers/database.d.ts b/lib/servers/database.d.ts index 4daf2ea3..55a674b7 100644 --- a/lib/servers/database.d.ts +++ b/lib/servers/database.d.ts @@ -24,10 +24,12 @@ export declare class DatabaseServer extends SkeletonServer { eth_getLogs(_request: Request, filter: web3.FilterOptions): Promise; eth_getStorageAt(_request: Request, address: web3.Data, key: web3.Quantity, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionByBlockHashAndIndex(_request: Request, blockHash: web3.Data, transactionIndex: web3.Quantity): Promise; + eth_getTransactionsByBlockNumber(_request: any, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionByBlockNumberAndIndex(_request: Request, blockNumber: web3.Quantity | web3.Tag, transactionIndex: web3.Quantity): Promise; eth_getTransactionByHash(_request: Request, transactionHash: web3.Data): Promise; eth_getTransactionCount(_request: Request, address: web3.Data, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionReceipt(_request: Request, transactionHash: string): Promise; + eth_getTransactionReceiptsByBlockNumber(_request: any, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getUncleCountByBlockHash(_request: Request, blockHash: web3.Data): Promise; eth_getUncleCountByBlockNumber(_request: Request, blockNumber: web3.Quantity | web3.Tag): Promise; eth_newBlockFilter(_request: Request): Promise; diff --git a/lib/servers/database.js b/lib/servers/database.js index 1c25a661..90121a7a 100644 --- a/lib/servers/database.js +++ b/lib/servers/database.js @@ -390,7 +390,6 @@ export class DatabaseServer extends SkeletonServer { ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) : parseBlockSpec(blockNumber); try { - console.log(blockNumber_); const { rows, } = await this._query(`SELECT b.id AS "blockNumber", b.hash AS "blockHash", @@ -410,7 +409,6 @@ export class DatabaseServer extends SkeletonServer { LEFT JOIN block b ON t.block = b.id WHERE b.id = $1`, [blockNumber_]); //assert(receipt, 'receipt is not null'); - //rows[0].logs = await this._fetchEvents(hexToBytes(receipt.transactionHash.toString())); for (var i = 0; i < rows.length; i++) { rows[i].logs = await this._fetchEvents(hexToBytes(rows[i].transactionHash.toString())); } diff --git a/lib/servers/skeleton.d.ts b/lib/servers/skeleton.d.ts index 93048958..ff7cb0d8 100644 --- a/lib/servers/skeleton.d.ts +++ b/lib/servers/skeleton.d.ts @@ -45,6 +45,8 @@ export declare abstract class SkeletonServer implements web3.Service { eth_getStorageAt(_request: Request, _address: web3.Data, _key: web3.Quantity, _blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionByBlockHashAndIndex(_request: Request, _blockHash: web3.Data, _transactionIndex: web3.Quantity): Promise; eth_getTransactionByBlockNumberAndIndex(_request: Request, _blockNumber: web3.Quantity | web3.Tag, _transactionIndex: web3.Quantity): Promise; + eth_getTransactionsByBlockNumber(_request: any, _blockNumber: web3.Quantity | web3.Tag): Promise; + eth_getTransactionReceiptsByBlockNumber(_request: any, _blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionByHash(_request: Request, _transactionHash: web3.Data): Promise; eth_getTransactionCount(_request: Request, _address: web3.Data, _blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionReceipt(_request: Request, _transactionHash: string): Promise; diff --git a/lib/web3.d.ts b/lib/web3.d.ts index 32911ab3..da109953 100644 --- a/lib/web3.d.ts +++ b/lib/web3.d.ts @@ -78,6 +78,8 @@ export interface Service { eth_getProof(_request: Request, address: Data, keys: Data[], blockNumber: Quantity | Tag): Promise; eth_getStorageAt(_request: Request, address: Data, key: Quantity, blockNumber: Quantity | Tag): Promise; eth_getTransactionByBlockHashAndIndex(_request: Request, blockHash: Data, transactionIndex: Quantity): Promise; + eth_getTransactionsByBlockNumber(_request: any, blockNumber: Quantity | Tag): Promise; + eth_getTransactionReceiptsByBlockNumber(_request: any, blockNumber: Quantity | Tag): Promise; eth_getTransactionByBlockNumberAndIndex(_request: Request, blockNumber: Quantity | Tag, transactionIndex: Quantity): Promise; eth_getTransactionByHash(_request: Request, transactionHash: Data): Promise; eth_getTransactionCount(_request: Request, address: Data, blockNumber: Quantity | Tag): Promise; From 6b5df19ee96a247adb0a998407dde2da71bb9310 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Fri, 19 Nov 2021 18:29:21 +0530 Subject: [PATCH 04/13] lint fix --- src/servers/database.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/servers/database.ts b/src/servers/database.ts index 8a7156d2..d9f5515e 100644 --- a/src/servers/database.ts +++ b/src/servers/database.ts @@ -628,7 +628,7 @@ export class DatabaseServer extends SkeletonServer { [blockNumber_] ); //assert(receipt, 'receipt is not null'); - for(var i = 0;i Date: Fri, 3 Dec 2021 14:56:06 +0530 Subject: [PATCH 05/13] comments removed --- lib/servers/database.js | 3 +-- src/servers/database.ts | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/servers/database.js b/lib/servers/database.js index 65240541..70572d22 100644 --- a/lib/servers/database.js +++ b/lib/servers/database.js @@ -400,8 +400,7 @@ export class DatabaseServer extends SkeletonServer { FROM transaction t LEFT JOIN block b ON t.block = b.id WHERE b.id = $1`, [blockNumber_]); - //assert(receipt, 'receipt is not null'); - for (var i = 0; i < rows.length; i++) { + for (let i = 0; i < rows.length; i++) { rows[i].logs = await this._fetchEvents(hexToBytes(rows[i].transactionHash.toString())); } return exportJSON(rows); diff --git a/src/servers/database.ts b/src/servers/database.ts index d9f5515e..c8f32042 100644 --- a/src/servers/database.ts +++ b/src/servers/database.ts @@ -627,7 +627,6 @@ export class DatabaseServer extends SkeletonServer { WHERE b.id = $1`, [blockNumber_] ); - //assert(receipt, 'receipt is not null'); for(let i = 0;i Date: Fri, 3 Dec 2021 17:02:58 +0530 Subject: [PATCH 06/13] added eth_getTransactionReceiptsByBlockNumber sql function and calling it from the js file for the result --- .docker/docker-entrypoint-initdb.d/init.txt | 28 +++++++++++++++++++ ...th_getTransactionReceiptsByBlockNumber.sql | 28 +++++++++++++++++++ lib/servers/database.js | 19 +------------ src/servers/database.ts | 21 ++------------ 4 files changed, 59 insertions(+), 37 deletions(-) create mode 100644 etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql diff --git a/.docker/docker-entrypoint-initdb.d/init.txt b/.docker/docker-entrypoint-initdb.d/init.txt index 0520f1d3..cdd3fec1 100644 --- a/.docker/docker-entrypoint-initdb.d/init.txt +++ b/.docker/docker-entrypoint-initdb.d/init.txt @@ -490,6 +490,34 @@ BEGIN RETURN result; END; $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; +DROP FUNCTION IF EXISTS eth_getTransactionReceiptsByBlockNumber(blockno) RESTRICT; + +CREATE FUNCTION eth_getTransactionReceiptsByBlockNumber(block_id blockno) RETURNS transaction_receipt AS $$ +DECLARE + result transaction_receipt; +BEGIN + SELECT + b.id AS "blockNumber", + b.hash AS "blockHash", + t.index AS "transactionIndex", + t.hash AS "transactionHash", + t.from AS "from", + t.to AS "to", + t.gas_used AS "gasUsed", + 0::u256 AS "cumulativeGasUsed", -- TODO: tally? + CASE WHEN t.to IS NULL OR t.to = '\\x0000000000000000000000000000000000000000' THEN t.output + ELSE NULL + END AS "contractAddress", + NULL AS "logs", -- TODO: fetch event.id[] + repeat('\\000', 256)::bytea AS "logsBloom", + CASE WHEN t.status THEN 1 ELSE 0 END AS "status" + FROM transaction t + LEFT JOIN block b ON t.block = b.id + WHERE b.id = block_id + INTO STRICT result; + RETURN result; +END; +$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; DROP FUNCTION IF EXISTS eth_getUncleByBlockHashAndIndex(hash, int) RESTRICT; CREATE FUNCTION eth_getUncleByBlockHashAndIndex(block_hash hash, uncle_index int) RETURNS block_result AS $$ diff --git a/etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql b/etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql new file mode 100644 index 00000000..759388b4 --- /dev/null +++ b/etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql @@ -0,0 +1,28 @@ +DROP FUNCTION IF EXISTS eth_getTransactionReceiptsByBlockNumber(blockno) RESTRICT; + +CREATE FUNCTION eth_getTransactionReceiptsByBlockNumber(block_id blockno) RETURNS transaction_receipt AS $$ +DECLARE + result transaction_receipt; +BEGIN + SELECT + b.id AS "blockNumber", + b.hash AS "blockHash", + t.index AS "transactionIndex", + t.hash AS "transactionHash", + t.from AS "from", + t.to AS "to", + t.gas_used AS "gasUsed", + 0::u256 AS "cumulativeGasUsed", -- TODO: tally? + CASE WHEN t.to IS NULL OR t.to = '\\x0000000000000000000000000000000000000000' THEN t.output + ELSE NULL + END AS "contractAddress", + NULL AS "logs", -- TODO: fetch event.id[] + repeat('\\000', 256)::bytea AS "logsBloom", + CASE WHEN t.status THEN 1 ELSE 0 END AS "status" + FROM transaction t + LEFT JOIN block b ON t.block = b.id + WHERE b.id = block_id + INTO STRICT result; + RETURN result; +END; +$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; diff --git a/lib/servers/database.js b/lib/servers/database.js index 70572d22..ba1b1f1e 100644 --- a/lib/servers/database.js +++ b/lib/servers/database.js @@ -382,24 +382,7 @@ export class DatabaseServer extends SkeletonServer { ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) : parseBlockSpec(blockNumber); try { - const { rows, } = await this._query(`SELECT - b.id AS "blockNumber", - b.hash AS "blockHash", - t.index AS "transactionIndex", - t.hash AS "transactionHash", - t.from AS "from", - t.to AS "to", - t.gas_used AS "gasUsed", - 0::u256 AS "cumulativeGasUsed", -- TODO: tally? - CASE WHEN t.to IS NULL OR t.to = '\\x0000000000000000000000000000000000000000' THEN t.output - ELSE NULL - END AS "contractAddress", - NULL AS "logs", -- TODO: fetch event.id[] - repeat('\\000', 256)::bytea AS "logsBloom", - CASE WHEN t.status THEN 1 ELSE 0 END AS "status" - FROM transaction t - LEFT JOIN block b ON t.block = b.id - WHERE b.id = $1`, [blockNumber_]); + const { rows } = await this._query('SELECT * FROM eth_getTransactionReceiptsByBlockNumber($1)', [blockNumber_]); for (let i = 0; i < rows.length; i++) { rows[i].logs = await this._fetchEvents(hexToBytes(rows[i].transactionHash.toString())); } diff --git a/src/servers/database.ts b/src/servers/database.ts index c8f32042..d7cf910a 100644 --- a/src/servers/database.ts +++ b/src/servers/database.ts @@ -605,26 +605,9 @@ export class DatabaseServer extends SkeletonServer { : parseBlockSpec(blockNumber); try { const { - rows, + rows } = await this._query( - `SELECT - b.id AS "blockNumber", - b.hash AS "blockHash", - t.index AS "transactionIndex", - t.hash AS "transactionHash", - t.from AS "from", - t.to AS "to", - t.gas_used AS "gasUsed", - 0::u256 AS "cumulativeGasUsed", -- TODO: tally? - CASE WHEN t.to IS NULL OR t.to = '\\x0000000000000000000000000000000000000000' THEN t.output - ELSE NULL - END AS "contractAddress", - NULL AS "logs", -- TODO: fetch event.id[] - repeat('\\000', 256)::bytea AS "logsBloom", - CASE WHEN t.status THEN 1 ELSE 0 END AS "status" - FROM transaction t - LEFT JOIN block b ON t.block = b.id - WHERE b.id = $1`, + 'SELECT * FROM eth_getTransactionReceiptsByBlockNumber($1)', [blockNumber_] ); for(let i = 0;i Date: Tue, 7 Dec 2021 10:52:23 +0530 Subject: [PATCH 07/13] added eth_getTransactionsByBlockNumber sql function and calling it from the js file for the result --- .docker/docker-entrypoint-initdb.d/init.txt | 29 +++++++++++++++++++ etc/schema.sql | 2 ++ .../eth_getTransactionsByBlockNumber.sql | 28 ++++++++++++++++++ lib/servers/database.js | 21 ++------------ src/servers/database.ts | 24 ++------------- 5 files changed, 65 insertions(+), 39 deletions(-) create mode 100644 etc/schema/functions/eth_getTransactionsByBlockNumber.sql diff --git a/.docker/docker-entrypoint-initdb.d/init.txt b/.docker/docker-entrypoint-initdb.d/init.txt index cdd3fec1..b8904465 100644 --- a/.docker/docker-entrypoint-initdb.d/init.txt +++ b/.docker/docker-entrypoint-initdb.d/init.txt @@ -518,6 +518,35 @@ BEGIN RETURN result; END; $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; +DROP FUNCTION IF EXISTS eth_getTransactionsByBlockNumber(blockno) RESTRICT; + +CREATE FUNCTION eth_getTransactionsByBlockNumber(block_id blockno) RETURNS transaction_result AS $$ +DECLARE + result transaction_result; +BEGIN + SELECT + b.id AS "blockNumber", + b.hash AS "blockHash", + t.index AS "transactionIndex", + t.hash AS "hash", + t.from AS "from", + t.to AS "to", + t.gas_limit AS "gas", + t.gas_price AS "gasPrice", + t.nonce AS "nonce", + t.value AS "value", + coalesce(t.input, '\\x'::bytea) AS "input", + t.v AS "v", + t.r AS "r", + t.s AS "s" + FROM transaction t + LEFT JOIN block b ON t.block = b.id + WHERE b.id = block_id + INTO STRICT result; + RETURN result; +END; +$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; + DROP FUNCTION IF EXISTS eth_getUncleByBlockHashAndIndex(hash, int) RESTRICT; CREATE FUNCTION eth_getUncleByBlockHashAndIndex(block_hash hash, uncle_index int) RETURNS block_result AS $$ diff --git a/etc/schema.sql b/etc/schema.sql index 15688fc8..bc4fa166 100644 --- a/etc/schema.sql +++ b/etc/schema.sql @@ -28,3 +28,5 @@ \i etc/schema/functions/eth_newFilter.sql \i etc/schema/functions/eth_newPendingTransactionFilter.sql \i etc/schema/functions/eth_uninstallFilter.sql +\i etc/schema/functions/eth_getTransactionsByBlockNumber.sql +\i etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql diff --git a/etc/schema/functions/eth_getTransactionsByBlockNumber.sql b/etc/schema/functions/eth_getTransactionsByBlockNumber.sql new file mode 100644 index 00000000..c0c7d851 --- /dev/null +++ b/etc/schema/functions/eth_getTransactionsByBlockNumber.sql @@ -0,0 +1,28 @@ +DROP FUNCTION IF EXISTS eth_getTransactionsByBlockNumber(blockno) RESTRICT; + +CREATE FUNCTION eth_getTransactionsByBlockNumber(block_id blockno) RETURNS transaction_result AS $$ +DECLARE + result transaction_result; +BEGIN + SELECT + b.id AS "blockNumber", + b.hash AS "blockHash", + t.index AS "transactionIndex", + t.hash AS "hash", + t.from AS "from", + t.to AS "to", + t.gas_limit AS "gas", + t.gas_price AS "gasPrice", + t.nonce AS "nonce", + t.value AS "value", + coalesce(t.input, '\\x'::bytea) AS "input", + t.v AS "v", + t.r AS "r", + t.s AS "s" + FROM transaction t + LEFT JOIN block b ON t.block = b.id + WHERE b.id = block_id + INTO STRICT result; + RETURN result; +END; +$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; diff --git a/lib/servers/database.js b/lib/servers/database.js index ba1b1f1e..a9303f37 100644 --- a/lib/servers/database.js +++ b/lib/servers/database.js @@ -293,24 +293,9 @@ export class DatabaseServer extends SkeletonServer { ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) : parseBlockSpec(blockNumber); try { - const { rows, } = await this._query(`SELECT - b.id AS "blockNumber", - b.hash AS "blockHash", - t.index AS "transactionIndex", - t.hash AS "hash", - t.from AS "from", - t.to AS "to", - t.gas_limit AS "gas", - t.gas_price AS "gasPrice", - t.nonce AS "nonce", - t.value AS "value", - coalesce(t.input, '\\x'::bytea) AS "input", - t.v AS "v", - t.r AS "r", - t.s AS "s" - FROM transaction t - LEFT JOIN block b ON t.block = b.id - WHERE b.id = $1`, [blockNumber_]); + const { rows, } = await this._query('SELECT * FROM eth_getTransactionsByBlockNumber($1)', [ + blockNumber_, + ]); return !rows || !rows.length ? null : exportJSON(rows); } catch (error) { diff --git a/src/servers/database.ts b/src/servers/database.ts index d7cf910a..c9df70c7 100644 --- a/src/servers/database.ts +++ b/src/servers/database.ts @@ -481,27 +481,9 @@ export class DatabaseServer extends SkeletonServer { try { const { rows, - } = await this._query( - `SELECT - b.id AS "blockNumber", - b.hash AS "blockHash", - t.index AS "transactionIndex", - t.hash AS "hash", - t.from AS "from", - t.to AS "to", - t.gas_limit AS "gas", - t.gas_price AS "gasPrice", - t.nonce AS "nonce", - t.value AS "value", - coalesce(t.input, '\\x'::bytea) AS "input", - t.v AS "v", - t.r AS "r", - t.s AS "s" - FROM transaction t - LEFT JOIN block b ON t.block = b.id - WHERE b.id = $1`, - [blockNumber_] - ); + } = await this._query('SELECT * FROM eth_getTransactionsByBlockNumber($1)', [ + blockNumber_, + ]); return !rows || !rows.length ? null : exportJSON(rows); } catch (error) { if (this.config.debug) { From 1f8877638c8cd09aab0939ee880c60bbb430f19a Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Thu, 9 Dec 2021 22:06:22 +0530 Subject: [PATCH 08/13] sorted non-standard methods in alphabetical order and updated query for the non-standard methods to handle multiple rows result --- .docker/docker-entrypoint-initdb.d/init.txt | 22 ++++--- etc/methods.yaml | 27 ++++---- etc/schema.sql | 5 +- ...th_getTransactionReceiptsByBlockNumber.sql | 14 ++-- .../eth_getTransactionsByBlockNumber.sql | 12 ++-- lib/servers/database.d.ts | 2 +- lib/servers/database.js | 34 +++++----- lib/servers/skeleton.d.ts | 4 +- lib/servers/skeleton.js | 16 ++--- lib/web3.d.ts | 4 +- src/servers/database.ts | 64 +++++++++++-------- src/servers/skeleton.ts | 31 +++++---- src/web3.ts | 17 ++--- 13 files changed, 138 insertions(+), 114 deletions(-) diff --git a/.docker/docker-entrypoint-initdb.d/init.txt b/.docker/docker-entrypoint-initdb.d/init.txt index b8904465..808c17c1 100644 --- a/.docker/docker-entrypoint-initdb.d/init.txt +++ b/.docker/docker-entrypoint-initdb.d/init.txt @@ -492,11 +492,12 @@ END; $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; DROP FUNCTION IF EXISTS eth_getTransactionReceiptsByBlockNumber(blockno) RESTRICT; -CREATE FUNCTION eth_getTransactionReceiptsByBlockNumber(block_id blockno) RETURNS transaction_receipt AS $$ +CREATE FUNCTION eth_getTransactionReceiptsByBlockNumber(block_id blockno) RETURNS setof transaction_receipt AS $$ DECLARE result transaction_receipt; BEGIN - SELECT + FOR result IN + SELECT b.id AS "blockNumber", b.hash AS "blockHash", t.index AS "transactionIndex", @@ -505,7 +506,7 @@ BEGIN t.to AS "to", t.gas_used AS "gasUsed", 0::u256 AS "cumulativeGasUsed", -- TODO: tally? - CASE WHEN t.to IS NULL OR t.to = '\\x0000000000000000000000000000000000000000' THEN t.output + CASE WHEN (t.to IS NULL OR t.to = '\x0000000000000000000000000000000000000000') AND length(t.output) = 20 THEN t.output ELSE NULL END AS "contractAddress", NULL AS "logs", -- TODO: fetch event.id[] @@ -514,17 +515,19 @@ BEGIN FROM transaction t LEFT JOIN block b ON t.block = b.id WHERE b.id = block_id - INTO STRICT result; - RETURN result; + LOOP + RETURN NEXT result; + END LOOP; END; $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; DROP FUNCTION IF EXISTS eth_getTransactionsByBlockNumber(blockno) RESTRICT; -CREATE FUNCTION eth_getTransactionsByBlockNumber(block_id blockno) RETURNS transaction_result AS $$ +CREATE FUNCTION eth_getTransactionsByBlockNumber(block_id blockno) RETURNS setof transaction_result AS $$ DECLARE result transaction_result; BEGIN - SELECT + FOR result IN + SELECT b.id AS "blockNumber", b.hash AS "blockHash", t.index AS "transactionIndex", @@ -542,8 +545,9 @@ BEGIN FROM transaction t LEFT JOIN block b ON t.block = b.id WHERE b.id = block_id - INTO STRICT result; - RETURN result; + LOOP + RETURN NEXT result; + END LOOP; END; $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; diff --git a/etc/methods.yaml b/etc/methods.yaml index 34f7fce8..b49c0a45 100644 --- a/etc/methods.yaml +++ b/etc/methods.yaml @@ -211,18 +211,7 @@ eth_getTransactionByBlockNumberAndIndex: implementations: - etc/schema/functions/eth_getTransactionByBlockNumberAndIndex.sql - src/servers/skeleton.ts -eth_getTransactionsByBlockNumber: - status: ok - comment: - link: - implementations: - - src/servers/skeleton.ts -eth_getTransactionReceiptsByBlockNumber: - status: ok - comment: - link: - implementations: - - src/servers/skeleton.ts + eth_getTransactionByHash: status: wip comment: @@ -246,6 +235,20 @@ eth_getTransactionReceipt: implementations: - src/servers/skeleton.ts +eth_getTransactionReceiptsByBlockNumber: + status: ok + comment: Non Standard Methods + link: + implementations: + - src/servers/skeleton.ts + +eth_getTransactionsByBlockNumber: + status: ok + comment: Non Standard Methods + link: + implementations: + - src/servers/skeleton.ts + eth_getUncleByBlockHashAndIndex: status: ok comment: diff --git a/etc/schema.sql b/etc/schema.sql index bc4fa166..90f9463d 100644 --- a/etc/schema.sql +++ b/etc/schema.sql @@ -20,6 +20,8 @@ \i etc/schema/functions/eth_getTransactionByHash.sql \i etc/schema/functions/eth_getTransactionCount.sql \i etc/schema/functions/eth_getTransactionReceipt.sql +\i etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql +\i etc/schema/functions/eth_getTransactionsByBlockNumber.sql \i etc/schema/functions/eth_getUncleByBlockHashAndIndex.sql \i etc/schema/functions/eth_getUncleByBlockNumberAndIndex.sql \i etc/schema/functions/eth_getUncleCountByBlockHash.sql @@ -28,5 +30,4 @@ \i etc/schema/functions/eth_newFilter.sql \i etc/schema/functions/eth_newPendingTransactionFilter.sql \i etc/schema/functions/eth_uninstallFilter.sql -\i etc/schema/functions/eth_getTransactionsByBlockNumber.sql -\i etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql + diff --git a/etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql b/etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql index 759388b4..aaa2064c 100644 --- a/etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql +++ b/etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql @@ -1,10 +1,11 @@ DROP FUNCTION IF EXISTS eth_getTransactionReceiptsByBlockNumber(blockno) RESTRICT; -CREATE FUNCTION eth_getTransactionReceiptsByBlockNumber(block_id blockno) RETURNS transaction_receipt AS $$ +CREATE FUNCTION eth_getTransactionReceiptsByBlockNumber(block_id blockno) RETURNS setof transaction_receipt AS $$ DECLARE result transaction_receipt; BEGIN - SELECT + FOR result IN + SELECT b.id AS "blockNumber", b.hash AS "blockHash", t.index AS "transactionIndex", @@ -13,7 +14,7 @@ BEGIN t.to AS "to", t.gas_used AS "gasUsed", 0::u256 AS "cumulativeGasUsed", -- TODO: tally? - CASE WHEN t.to IS NULL OR t.to = '\\x0000000000000000000000000000000000000000' THEN t.output + CASE WHEN (t.to IS NULL OR t.to = '\x0000000000000000000000000000000000000000') AND length(t.output) = 20 THEN t.output ELSE NULL END AS "contractAddress", NULL AS "logs", -- TODO: fetch event.id[] @@ -22,7 +23,8 @@ BEGIN FROM transaction t LEFT JOIN block b ON t.block = b.id WHERE b.id = block_id - INTO STRICT result; - RETURN result; + LOOP + RETURN NEXT result; + END LOOP; END; -$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; +$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; \ No newline at end of file diff --git a/etc/schema/functions/eth_getTransactionsByBlockNumber.sql b/etc/schema/functions/eth_getTransactionsByBlockNumber.sql index c0c7d851..a3ac5326 100644 --- a/etc/schema/functions/eth_getTransactionsByBlockNumber.sql +++ b/etc/schema/functions/eth_getTransactionsByBlockNumber.sql @@ -1,10 +1,11 @@ DROP FUNCTION IF EXISTS eth_getTransactionsByBlockNumber(blockno) RESTRICT; -CREATE FUNCTION eth_getTransactionsByBlockNumber(block_id blockno) RETURNS transaction_result AS $$ +CREATE FUNCTION eth_getTransactionsByBlockNumber(block_id blockno) RETURNS setof transaction_result AS $$ DECLARE result transaction_result; BEGIN - SELECT + FOR result IN + SELECT b.id AS "blockNumber", b.hash AS "blockHash", t.index AS "transactionIndex", @@ -22,7 +23,10 @@ BEGIN FROM transaction t LEFT JOIN block b ON t.block = b.id WHERE b.id = block_id - INTO STRICT result; - RETURN result; + LOOP + RETURN NEXT result; + END LOOP; END; + + $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; diff --git a/lib/servers/database.d.ts b/lib/servers/database.d.ts index fc27bc81..59b9b5e2 100644 --- a/lib/servers/database.d.ts +++ b/lib/servers/database.d.ts @@ -23,12 +23,12 @@ export declare class DatabaseServer extends SkeletonServer { eth_getLogs(_request: Request, filter: web3.FilterOptions): Promise; eth_getStorageAt(_request: Request, address: web3.Data, key: web3.Quantity, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionByBlockHashAndIndex(_request: Request, blockHash: web3.Data, transactionIndex: web3.Quantity): Promise; - eth_getTransactionsByBlockNumber(_request: any, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionByBlockNumberAndIndex(_request: Request, blockNumber: web3.Quantity | web3.Tag, transactionIndex: web3.Quantity): Promise; eth_getTransactionByHash(_request: Request, transactionHash: web3.Data): Promise; eth_getTransactionCount(_request: Request, address: web3.Data, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionReceipt(_request: Request, transactionHash: string): Promise; eth_getTransactionReceiptsByBlockNumber(_request: any, blockNumber: web3.Quantity | web3.Tag): Promise; + eth_getTransactionsByBlockNumber(_request: any, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getUncleCountByBlockHash(_request: Request, blockHash: web3.Data): Promise; eth_getUncleCountByBlockNumber(_request: Request, blockNumber: web3.Quantity | web3.Tag): Promise; eth_newBlockFilter(_request: Request): Promise; diff --git a/lib/servers/database.js b/lib/servers/database.js index a9303f37..e169a910 100644 --- a/lib/servers/database.js +++ b/lib/servers/database.js @@ -288,23 +288,6 @@ export class DatabaseServer extends SkeletonServer { return null; } } - async eth_getTransactionsByBlockNumber(_request, blockNumber) { - const blockNumber_ = parseBlockSpec(blockNumber) != 0 - ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) - : parseBlockSpec(blockNumber); - try { - const { rows, } = await this._query('SELECT * FROM eth_getTransactionsByBlockNumber($1)', [ - blockNumber_, - ]); - return !rows || !rows.length ? null : exportJSON(rows); - } - catch (error) { - if (this.config.debug) { - console.debug('eth_getTransactionsByBlockNumber', error); - } - return null; - } - } async eth_getTransactionByBlockNumberAndIndex(_request, blockNumber, transactionIndex) { const blockNumber_ = parseBlockSpec(blockNumber) != 0 ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) @@ -367,7 +350,7 @@ export class DatabaseServer extends SkeletonServer { ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) : parseBlockSpec(blockNumber); try { - const { rows } = await this._query('SELECT * FROM eth_getTransactionReceiptsByBlockNumber($1)', [blockNumber_]); + const { rows, } = await this._query('SELECT * FROM eth_getTransactionReceiptsByBlockNumber($1)', [blockNumber_]); for (let i = 0; i < rows.length; i++) { rows[i].logs = await this._fetchEvents(hexToBytes(rows[i].transactionHash.toString())); } @@ -380,6 +363,21 @@ export class DatabaseServer extends SkeletonServer { return null; } } + async eth_getTransactionsByBlockNumber(_request, blockNumber) { + const blockNumber_ = parseBlockSpec(blockNumber) != 0 + ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) + : parseBlockSpec(blockNumber); + try { + const { rows, } = await this._query('SELECT * FROM eth_getTransactionsByBlockNumber($1)', [blockNumber_]); + return !rows || !rows.length ? null : exportJSON(rows); + } + catch (error) { + if (this.config.debug) { + console.debug('eth_getTransactionsByBlockNumber', error); + } + return null; + } + } async eth_getUncleCountByBlockHash(_request, blockHash) { const blockHash_ = blockHash.startsWith('0x') ? hexToBytes(blockHash) diff --git a/lib/servers/skeleton.d.ts b/lib/servers/skeleton.d.ts index ff7cb0d8..b25a7899 100644 --- a/lib/servers/skeleton.d.ts +++ b/lib/servers/skeleton.d.ts @@ -45,11 +45,11 @@ export declare abstract class SkeletonServer implements web3.Service { eth_getStorageAt(_request: Request, _address: web3.Data, _key: web3.Quantity, _blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionByBlockHashAndIndex(_request: Request, _blockHash: web3.Data, _transactionIndex: web3.Quantity): Promise; eth_getTransactionByBlockNumberAndIndex(_request: Request, _blockNumber: web3.Quantity | web3.Tag, _transactionIndex: web3.Quantity): Promise; - eth_getTransactionsByBlockNumber(_request: any, _blockNumber: web3.Quantity | web3.Tag): Promise; - eth_getTransactionReceiptsByBlockNumber(_request: any, _blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionByHash(_request: Request, _transactionHash: web3.Data): Promise; eth_getTransactionCount(_request: Request, _address: web3.Data, _blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionReceipt(_request: Request, _transactionHash: string): Promise; + eth_getTransactionReceiptsByBlockNumber(_request: any, _blockNumber: web3.Quantity | web3.Tag): Promise; + eth_getTransactionsByBlockNumber(_request: any, _blockNumber: web3.Quantity | web3.Tag): Promise; eth_getUncleByBlockHashAndIndex(_request: Request, _blockHash: web3.Data, _uncleIndex: web3.Quantity): Promise; eth_getUncleByBlockNumberAndIndex(_request: Request, _blockNumber: web3.Quantity | web3.Tag, _uncleIndex: web3.Quantity): Promise; eth_getUncleCountByBlockHash(_request: Request, _blockHash: web3.Data): Promise; diff --git a/lib/servers/skeleton.js b/lib/servers/skeleton.js index 76f8e49f..b3cd5863 100644 --- a/lib/servers/skeleton.js +++ b/lib/servers/skeleton.js @@ -173,14 +173,6 @@ export class SkeletonServer { unimplemented('eth_getTransactionByBlockNumberAndIndex'); return null; } - async eth_getTransactionsByBlockNumber(_request, _blockNumber) { - unimplemented('eth_getTransactionsByBlockNumber'); - return null; - } - async eth_getTransactionReceiptsByBlockNumber(_request, _blockNumber) { - unimplemented('eth_getTransactionReceiptsByBlockNumber'); - return null; - } async eth_getTransactionByHash(_request, _transactionHash) { unimplemented('eth_getTransactionByHash'); return null; @@ -193,6 +185,14 @@ export class SkeletonServer { unimplemented('eth_getTransactionReceipt'); return null; } + async eth_getTransactionReceiptsByBlockNumber(_request, _blockNumber) { + unimplemented('eth_getTransactionReceiptsByBlockNumber'); + return null; + } + async eth_getTransactionsByBlockNumber(_request, _blockNumber) { + unimplemented('eth_getTransactionsByBlockNumber'); + return null; + } async eth_getUncleByBlockHashAndIndex(_request, _blockHash, _uncleIndex) { return null; // uncle blocks are never found } diff --git a/lib/web3.d.ts b/lib/web3.d.ts index da109953..228c1a13 100644 --- a/lib/web3.d.ts +++ b/lib/web3.d.ts @@ -78,12 +78,12 @@ export interface Service { eth_getProof(_request: Request, address: Data, keys: Data[], blockNumber: Quantity | Tag): Promise; eth_getStorageAt(_request: Request, address: Data, key: Quantity, blockNumber: Quantity | Tag): Promise; eth_getTransactionByBlockHashAndIndex(_request: Request, blockHash: Data, transactionIndex: Quantity): Promise; - eth_getTransactionsByBlockNumber(_request: any, blockNumber: Quantity | Tag): Promise; - eth_getTransactionReceiptsByBlockNumber(_request: any, blockNumber: Quantity | Tag): Promise; eth_getTransactionByBlockNumberAndIndex(_request: Request, blockNumber: Quantity | Tag, transactionIndex: Quantity): Promise; eth_getTransactionByHash(_request: Request, transactionHash: Data): Promise; eth_getTransactionCount(_request: Request, address: Data, blockNumber: Quantity | Tag): Promise; eth_getTransactionReceipt(_request: Request, transactionHash: string): Promise; + eth_getTransactionReceiptsByBlockNumber(_request: any, blockNumber: Quantity | Tag): Promise; + eth_getTransactionsByBlockNumber(_request: any, blockNumber: Quantity | Tag): Promise; eth_getUncleByBlockHashAndIndex(_request: Request, blockHash: Data, uncleIndex: Quantity): Promise; eth_getUncleByBlockNumberAndIndex(_request: Request, blockNumber: Quantity | Tag, uncleIndex: Quantity): Promise; eth_getUncleCountByBlockHash(_request: Request, blockHash: Data): Promise; diff --git a/src/servers/database.ts b/src/servers/database.ts index c9df70c7..ce1fe9d5 100644 --- a/src/servers/database.ts +++ b/src/servers/database.ts @@ -470,28 +470,7 @@ export class DatabaseServer extends SkeletonServer { return null; } } - async eth_getTransactionsByBlockNumber( - _request: any, - blockNumber: web3.Quantity | web3.Tag - ): Promise { - const blockNumber_ = parseBlockSpec(blockNumber) != 0 - ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) - : parseBlockSpec(blockNumber); - - try { - const { - rows, - } = await this._query('SELECT * FROM eth_getTransactionsByBlockNumber($1)', [ - blockNumber_, - ]); - return !rows || !rows.length ? null : exportJSON(rows); - } catch (error) { - if (this.config.debug) { - console.debug('eth_getTransactionsByBlockNumber', error); - } - return null; - } - } + async eth_getTransactionByBlockNumberAndIndex( _request: Request, blockNumber: web3.Quantity | web3.Tag, @@ -582,18 +561,21 @@ export class DatabaseServer extends SkeletonServer { _request: any, blockNumber: web3.Quantity | web3.Tag ): Promise { - const blockNumber_ = parseBlockSpec(blockNumber) != 0 - ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) - : parseBlockSpec(blockNumber); + const blockNumber_ = + parseBlockSpec(blockNumber) != 0 + ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) + : parseBlockSpec(blockNumber); try { const { - rows + rows, } = await this._query( 'SELECT * FROM eth_getTransactionReceiptsByBlockNumber($1)', [blockNumber_] ); - for(let i = 0;i { + const blockNumber_ = + parseBlockSpec(blockNumber) != 0 + ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) + : parseBlockSpec(blockNumber); + + try { + const { + rows, + } = await this._query( + 'SELECT * FROM eth_getTransactionsByBlockNumber($1)', + [blockNumber_] + ); + return !rows || !rows.length ? null : exportJSON(rows); + } catch (error) { + if (this.config.debug) { + console.debug('eth_getTransactionsByBlockNumber', error); + } + return null; + } + } + async eth_getUncleCountByBlockHash( _request: Request, blockHash: web3.Data diff --git a/src/servers/skeleton.ts b/src/servers/skeleton.ts index 577f922a..6fa0cd98 100644 --- a/src/servers/skeleton.ts +++ b/src/servers/skeleton.ts @@ -290,20 +290,7 @@ export abstract class SkeletonServer implements web3.Service { unimplemented('eth_getTransactionByBlockNumberAndIndex'); return null; } - async eth_getTransactionsByBlockNumber( - _request: any, - _blockNumber: web3.Quantity | web3.Tag - ): Promise { - unimplemented('eth_getTransactionsByBlockNumber'); - return null; - } - async eth_getTransactionReceiptsByBlockNumber( - _request: any, - _blockNumber: web3.Quantity | web3.Tag - ): Promise { - unimplemented('eth_getTransactionReceiptsByBlockNumber'); - return null; - } + async eth_getTransactionByHash( _request: Request, _transactionHash: web3.Data @@ -328,6 +315,22 @@ export abstract class SkeletonServer implements web3.Service { unimplemented('eth_getTransactionReceipt'); return null; } + + async eth_getTransactionReceiptsByBlockNumber( + _request: any, + _blockNumber: web3.Quantity | web3.Tag + ): Promise { + unimplemented('eth_getTransactionReceiptsByBlockNumber'); + return null; + } + + async eth_getTransactionsByBlockNumber( + _request: any, + _blockNumber: web3.Quantity | web3.Tag + ): Promise { + unimplemented('eth_getTransactionsByBlockNumber'); + return null; + } async eth_getUncleByBlockHashAndIndex( _request: Request, diff --git a/src/web3.ts b/src/web3.ts index 11f6c220..32655c77 100644 --- a/src/web3.ts +++ b/src/web3.ts @@ -148,14 +148,7 @@ export interface Service { blockHash: Data, transactionIndex: Quantity ): Promise; - eth_getTransactionsByBlockNumber( - _request: any, - blockNumber: Quantity | Tag, - ): Promise; - eth_getTransactionReceiptsByBlockNumber( - _request: any, - blockNumber: Quantity | Tag, - ): Promise; + eth_getTransactionByBlockNumberAndIndex( _request: Request, blockNumber: Quantity | Tag, @@ -174,6 +167,14 @@ export interface Service { _request: Request, transactionHash: string ): Promise; + eth_getTransactionReceiptsByBlockNumber( + _request: any, + blockNumber: Quantity | Tag, + ): Promise; + eth_getTransactionsByBlockNumber( + _request: any, + blockNumber: Quantity | Tag, + ): Promise; eth_getUncleByBlockHashAndIndex( _request: Request, blockHash: Data, From 13235bfbca9ed7956d98e5dc4f6d677d5fdeed8b Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Fri, 10 Dec 2021 00:01:53 +0530 Subject: [PATCH 09/13] code formating --- src/servers/database.ts | 2 +- src/servers/skeleton.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/servers/database.ts b/src/servers/database.ts index ce1fe9d5..d30fa3ae 100644 --- a/src/servers/database.ts +++ b/src/servers/database.ts @@ -610,7 +610,7 @@ export class DatabaseServer extends SkeletonServer { return null; } } - + async eth_getUncleCountByBlockHash( _request: Request, blockHash: web3.Data diff --git a/src/servers/skeleton.ts b/src/servers/skeleton.ts index 6fa0cd98..51628688 100644 --- a/src/servers/skeleton.ts +++ b/src/servers/skeleton.ts @@ -315,7 +315,7 @@ export abstract class SkeletonServer implements web3.Service { unimplemented('eth_getTransactionReceipt'); return null; } - + async eth_getTransactionReceiptsByBlockNumber( _request: any, _blockNumber: web3.Quantity | web3.Tag @@ -323,7 +323,7 @@ export abstract class SkeletonServer implements web3.Service { unimplemented('eth_getTransactionReceiptsByBlockNumber'); return null; } - + async eth_getTransactionsByBlockNumber( _request: any, _blockNumber: web3.Quantity | web3.Tag From 936d30a9272c042b70f5d9379ae6329d0d4b8b8d Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Fri, 10 Dec 2021 00:10:02 +0530 Subject: [PATCH 10/13] identation fixing --- src/web3.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/web3.ts b/src/web3.ts index 32655c77..137216b9 100644 --- a/src/web3.ts +++ b/src/web3.ts @@ -148,7 +148,7 @@ export interface Service { blockHash: Data, transactionIndex: Quantity ): Promise; - + eth_getTransactionByBlockNumberAndIndex( _request: Request, blockNumber: Quantity | Tag, @@ -169,11 +169,11 @@ export interface Service { ): Promise; eth_getTransactionReceiptsByBlockNumber( _request: any, - blockNumber: Quantity | Tag, + blockNumber: Quantity | Tag ): Promise; eth_getTransactionsByBlockNumber( _request: any, - blockNumber: Quantity | Tag, + blockNumber: Quantity | Tag ): Promise; eth_getUncleByBlockHashAndIndex( _request: Request, From 894d00279c7bb25e9c04d7c154f914f2244731df Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Tue, 21 Dec 2021 08:10:00 +0100 Subject: [PATCH 11/13] minor lint fixes --- .docker/docker-entrypoint-initdb.d/init.txt | 40 +++++++++---------- etc/methods.yaml | 6 ++- ...th_getTransactionReceiptsByBlockNumber.sql | 12 +++--- .../eth_getTransactionsByBlockNumber.sql | 4 +- src/web3.ts | 1 - 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/.docker/docker-entrypoint-initdb.d/init.txt b/.docker/docker-entrypoint-initdb.d/init.txt index ec203aac..f87f5fc0 100644 --- a/.docker/docker-entrypoint-initdb.d/init.txt +++ b/.docker/docker-entrypoint-initdb.d/init.txt @@ -44,7 +44,7 @@ CREATE TYPE block_result AS ( "size" int4, "gasLimit" int8, "gasUsed" int8, - "mixHash" hash, + "mixHash" hash, "timestamp" int4 ); DROP TYPE IF EXISTS filter_result CASCADE; @@ -133,6 +133,17 @@ CREATE TABLE filter ( addresses address[] NULL CHECK (array_length(addresses, 1) > 0), topics jsonb NULL ); +DROP TABLE IF EXISTS subscription CASCADE; + +CREATE TABLE subscription ( + sec_websocket_key varchar COLLATE "default", + id varchar COLLATE "default", + type varchar COLLATE "default", + ip varchar COLLATE "default", + filter jsonb NULL +); + +CREATE UNIQUE INDEX subscription_sec_websocket_key_type_filter_index_idx ON subscription (sec_websocket_key, type, filter); DROP TABLE IF EXISTS transaction CASCADE; CREATE TABLE transaction ( @@ -178,18 +189,6 @@ CREATE TABLE event ( CREATE UNIQUE INDEX event_transaction_index_idx ON event (transaction, index); DROP FUNCTION IF EXISTS eth_blockNumber() RESTRICT; -DROP TABLE IF EXISTS subscription CASCADE; - -CREATE TABLE subscription ( - sec_websocket_key varchar COLLATE "default", - id varchar COLLATE "default", - type varchar COLLATE "default", - ip varchar COLLATE "default", - filter jsonb NULL -); - -CREATE UNIQUE INDEX subscription_sec_websocket_key_type_filter_index_idx ON subscription (sec_websocket_key, type, filter); - CREATE FUNCTION eth_blockNumber() RETURNS blockno AS $$ DECLARE block_id blockno; @@ -234,7 +233,7 @@ BEGIN gas_limit, -- gasLimit gas_used, -- gasUsed repeat('\000', 32)::hash, -- mixHash - EXTRACT(EPOCH FROM timestamp) -- timestamp + COALESCE(EXTRACT(EPOCH FROM timestamp), 0)::int4 -- timestamp FROM block WHERE id = block_id LIMIT 1 @@ -507,11 +506,11 @@ END; $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; DROP FUNCTION IF EXISTS eth_getTransactionReceiptsByBlockNumber(blockno) RESTRICT; -CREATE FUNCTION eth_getTransactionReceiptsByBlockNumber(block_id blockno) RETURNS setof transaction_receipt AS $$ +CREATE FUNCTION eth_getTransactionReceiptsByBlockNumber(block_id blockno) RETURNS SETOF transaction_receipt AS $$ DECLARE result transaction_receipt; BEGIN - FOR result IN + FOR result IN SELECT b.id AS "blockNumber", b.hash AS "blockHash", @@ -530,14 +529,14 @@ BEGIN FROM transaction t LEFT JOIN block b ON t.block = b.id WHERE b.id = block_id - LOOP - RETURN NEXT result; - END LOOP; + LOOP + RETURN NEXT result; + END LOOP; END; $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; DROP FUNCTION IF EXISTS eth_getTransactionsByBlockNumber(blockno) RESTRICT; -CREATE FUNCTION eth_getTransactionsByBlockNumber(block_id blockno) RETURNS setof transaction_result AS $$ +CREATE FUNCTION eth_getTransactionsByBlockNumber(block_id blockno) RETURNS SETOF transaction_result AS $$ DECLARE result transaction_result; BEGIN @@ -565,7 +564,6 @@ BEGIN END LOOP; END; $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; - DROP FUNCTION IF EXISTS eth_getUncleByBlockHashAndIndex(hash, int) RESTRICT; CREATE FUNCTION eth_getUncleByBlockHashAndIndex(block_hash hash, uncle_index int) RETURNS block_result AS $$ diff --git a/etc/methods.yaml b/etc/methods.yaml index b49c0a45..bd2efb1f 100644 --- a/etc/methods.yaml +++ b/etc/methods.yaml @@ -237,16 +237,18 @@ eth_getTransactionReceipt: eth_getTransactionReceiptsByBlockNumber: status: ok - comment: Non Standard Methods + comment: Non Standard Method link: implementations: + - etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql - src/servers/skeleton.ts eth_getTransactionsByBlockNumber: status: ok - comment: Non Standard Methods + comment: Non Standard Method link: implementations: + - etc/schema/functions/eth_getTransactionsByBlockNumber.sql - src/servers/skeleton.ts eth_getUncleByBlockHashAndIndex: diff --git a/etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql b/etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql index aaa2064c..0ec00b1e 100644 --- a/etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql +++ b/etc/schema/functions/eth_getTransactionReceiptsByBlockNumber.sql @@ -1,10 +1,10 @@ DROP FUNCTION IF EXISTS eth_getTransactionReceiptsByBlockNumber(blockno) RESTRICT; -CREATE FUNCTION eth_getTransactionReceiptsByBlockNumber(block_id blockno) RETURNS setof transaction_receipt AS $$ +CREATE FUNCTION eth_getTransactionReceiptsByBlockNumber(block_id blockno) RETURNS SETOF transaction_receipt AS $$ DECLARE result transaction_receipt; BEGIN - FOR result IN + FOR result IN SELECT b.id AS "blockNumber", b.hash AS "blockHash", @@ -23,8 +23,8 @@ BEGIN FROM transaction t LEFT JOIN block b ON t.block = b.id WHERE b.id = block_id - LOOP - RETURN NEXT result; - END LOOP; + LOOP + RETURN NEXT result; + END LOOP; END; -$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; \ No newline at end of file +$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; diff --git a/etc/schema/functions/eth_getTransactionsByBlockNumber.sql b/etc/schema/functions/eth_getTransactionsByBlockNumber.sql index a3ac5326..ae770f76 100644 --- a/etc/schema/functions/eth_getTransactionsByBlockNumber.sql +++ b/etc/schema/functions/eth_getTransactionsByBlockNumber.sql @@ -1,6 +1,6 @@ DROP FUNCTION IF EXISTS eth_getTransactionsByBlockNumber(blockno) RESTRICT; -CREATE FUNCTION eth_getTransactionsByBlockNumber(block_id blockno) RETURNS setof transaction_result AS $$ +CREATE FUNCTION eth_getTransactionsByBlockNumber(block_id blockno) RETURNS SETOF transaction_result AS $$ DECLARE result transaction_result; BEGIN @@ -27,6 +27,4 @@ BEGIN RETURN NEXT result; END LOOP; END; - - $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; diff --git a/src/web3.ts b/src/web3.ts index 2d162c1e..fc8bbea8 100644 --- a/src/web3.ts +++ b/src/web3.ts @@ -149,7 +149,6 @@ export interface Service { blockHash: Data, transactionIndex: Quantity ): Promise; - eth_getTransactionByBlockNumberAndIndex( _request: Request, blockNumber: Quantity | Tag, From 32424c443e48db60e64849476e7b910bbe882c97 Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Tue, 21 Dec 2021 09:09:37 +0100 Subject: [PATCH 12/13] return set of transaction receipts and transaction results --- .docker/docker-entrypoint-initdb.d/init.txt | 2 +- etc/schema/functions/eth_getBlockByNumber.sql | 2 +- lib/servers/database.d.ts | 4 ++-- lib/servers/database.js | 8 ++++---- lib/servers/skeleton.d.ts | 4 ++-- lib/servers/skeleton.js | 4 ++-- lib/web3.d.ts | 4 ++-- src/servers/database.ts | 13 ++++++------- src/servers/skeleton.ts | 8 ++++---- src/web3.ts | 4 ++-- 10 files changed, 26 insertions(+), 27 deletions(-) diff --git a/.docker/docker-entrypoint-initdb.d/init.txt b/.docker/docker-entrypoint-initdb.d/init.txt index f87f5fc0..84bb5534 100644 --- a/.docker/docker-entrypoint-initdb.d/init.txt +++ b/.docker/docker-entrypoint-initdb.d/init.txt @@ -233,7 +233,7 @@ BEGIN gas_limit, -- gasLimit gas_used, -- gasUsed repeat('\000', 32)::hash, -- mixHash - COALESCE(EXTRACT(EPOCH FROM timestamp), 0)::int4 -- timestamp + EXTRACT(EPOCH FROM timestamp) -- timestamp FROM block WHERE id = block_id LIMIT 1 diff --git a/etc/schema/functions/eth_getBlockByNumber.sql b/etc/schema/functions/eth_getBlockByNumber.sql index e0242b6a..34ae7960 100644 --- a/etc/schema/functions/eth_getBlockByNumber.sql +++ b/etc/schema/functions/eth_getBlockByNumber.sql @@ -22,7 +22,7 @@ BEGIN gas_limit, -- gasLimit gas_used, -- gasUsed repeat('\000', 32)::hash, -- mixHash - COALESCE(EXTRACT(EPOCH FROM timestamp), 0)::int4 -- timestamp + EXTRACT(EPOCH FROM timestamp) -- timestamp FROM block WHERE id = block_id LIMIT 1 diff --git a/lib/servers/database.d.ts b/lib/servers/database.d.ts index 484cccdc..7096cd6d 100644 --- a/lib/servers/database.d.ts +++ b/lib/servers/database.d.ts @@ -27,8 +27,8 @@ export declare class DatabaseServer extends SkeletonServer { eth_getTransactionByHash(_request: Request, transactionHash: web3.Data): Promise; eth_getTransactionCount(_request: Request, address: web3.Data, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionReceipt(_request: Request, transactionHash: string): Promise; - eth_getTransactionReceiptsByBlockNumber(_request: any, blockNumber: web3.Quantity | web3.Tag): Promise; - eth_getTransactionsByBlockNumber(_request: any, blockNumber: web3.Quantity | web3.Tag): Promise; + eth_getTransactionReceiptsByBlockNumber(_request: any, blockNumber: web3.Quantity | web3.Tag): Promise; + eth_getTransactionsByBlockNumber(_request: any, blockNumber: web3.Quantity | web3.Tag): Promise; eth_getUncleCountByBlockHash(_request: Request, blockHash: web3.Data): Promise; eth_getUncleCountByBlockNumber(_request: Request, blockNumber: web3.Quantity | web3.Tag): Promise; eth_newBlockFilter(_request: Request): Promise; diff --git a/lib/servers/database.js b/lib/servers/database.js index 36500bf8..8ddb5029 100644 --- a/lib/servers/database.js +++ b/lib/servers/database.js @@ -345,13 +345,13 @@ export class DatabaseServer extends SkeletonServer { for (let i = 0; i < rows.length; i++) { rows[i].logs = await this._fetchEvents(hexToBytes(rows[i].transactionHash.toString())); } - return exportJSON(rows); + return rows.length == 0 ? [] : exportJSON(rows); } catch (error) { if (this.config.debug) { console.debug('eth_getTransactionReceiptsByBlockNumber', error); } - return null; + return []; } } async eth_getTransactionsByBlockNumber(_request, blockNumber) { @@ -360,13 +360,13 @@ export class DatabaseServer extends SkeletonServer { : parseBlockSpec(blockNumber); try { const { rows, } = await this._query('SELECT * FROM eth_getTransactionsByBlockNumber($1)', [blockNumber_]); - return !rows || !rows.length ? null : exportJSON(rows); + return rows.length == 0 ? [] : exportJSON(rows); } catch (error) { if (this.config.debug) { console.debug('eth_getTransactionsByBlockNumber', error); } - return null; + return []; } } async eth_getUncleCountByBlockHash(_request, blockHash) { diff --git a/lib/servers/skeleton.d.ts b/lib/servers/skeleton.d.ts index 0a65ed6f..85165de0 100644 --- a/lib/servers/skeleton.d.ts +++ b/lib/servers/skeleton.d.ts @@ -48,8 +48,8 @@ export declare abstract class SkeletonServer implements web3.Service { eth_getTransactionByHash(_request: Request, _transactionHash: web3.Data): Promise; eth_getTransactionCount(_request: Request, _address: web3.Data, _blockNumber: web3.Quantity | web3.Tag): Promise; eth_getTransactionReceipt(_request: Request, _transactionHash: string): Promise; - eth_getTransactionReceiptsByBlockNumber(_request: any, _blockNumber: web3.Quantity | web3.Tag): Promise; - eth_getTransactionsByBlockNumber(_request: any, _blockNumber: web3.Quantity | web3.Tag): Promise; + eth_getTransactionReceiptsByBlockNumber(_request: any, _blockNumber: web3.Quantity | web3.Tag): Promise; + eth_getTransactionsByBlockNumber(_request: any, _blockNumber: web3.Quantity | web3.Tag): Promise; eth_getUncleByBlockHashAndIndex(_request: Request, _blockHash: web3.Data, _uncleIndex: web3.Quantity): Promise; eth_getUncleByBlockNumberAndIndex(_request: Request, _blockNumber: web3.Quantity | web3.Tag, _uncleIndex: web3.Quantity): Promise; eth_getUncleCountByBlockHash(_request: Request, _blockHash: web3.Data): Promise; diff --git a/lib/servers/skeleton.js b/lib/servers/skeleton.js index c700faec..fd3053d9 100644 --- a/lib/servers/skeleton.js +++ b/lib/servers/skeleton.js @@ -187,11 +187,11 @@ export class SkeletonServer { } async eth_getTransactionReceiptsByBlockNumber(_request, _blockNumber) { unimplemented('eth_getTransactionReceiptsByBlockNumber'); - return null; + return []; } async eth_getTransactionsByBlockNumber(_request, _blockNumber) { unimplemented('eth_getTransactionsByBlockNumber'); - return null; + return []; } async eth_getUncleByBlockHashAndIndex(_request, _blockHash, _uncleIndex) { return null; // uncle blocks are never found diff --git a/lib/web3.d.ts b/lib/web3.d.ts index e0bd64e0..c9733e5e 100644 --- a/lib/web3.d.ts +++ b/lib/web3.d.ts @@ -83,8 +83,8 @@ export interface Service { eth_getTransactionByHash(_request: Request, transactionHash: Data): Promise; eth_getTransactionCount(_request: Request, address: Data, blockNumber: Quantity | Tag): Promise; eth_getTransactionReceipt(_request: Request, transactionHash: string): Promise; - eth_getTransactionReceiptsByBlockNumber(_request: any, blockNumber: Quantity | Tag): Promise; - eth_getTransactionsByBlockNumber(_request: any, blockNumber: Quantity | Tag): Promise; + eth_getTransactionReceiptsByBlockNumber(_request: any, blockNumber: Quantity | Tag): Promise; + eth_getTransactionsByBlockNumber(_request: any, blockNumber: Quantity | Tag): Promise; eth_getUncleByBlockHashAndIndex(_request: Request, blockHash: Data, uncleIndex: Quantity): Promise; eth_getUncleByBlockNumberAndIndex(_request: Request, blockNumber: Quantity | Tag, uncleIndex: Quantity): Promise; eth_getUncleCountByBlockHash(_request: Request, blockHash: Data): Promise; diff --git a/src/servers/database.ts b/src/servers/database.ts index 5cc1465f..0c516d0c 100644 --- a/src/servers/database.ts +++ b/src/servers/database.ts @@ -552,7 +552,7 @@ export class DatabaseServer extends SkeletonServer { async eth_getTransactionReceiptsByBlockNumber( _request: any, blockNumber: web3.Quantity | web3.Tag - ): Promise { + ): Promise { const blockNumber_ = parseBlockSpec(blockNumber) != 0 ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) @@ -569,24 +569,23 @@ export class DatabaseServer extends SkeletonServer { hexToBytes(rows[i].transactionHash.toString()) ); } - return exportJSON(rows); + return rows.length == 0 ? [] : exportJSON(rows); } catch (error) { if (this.config.debug) { console.debug('eth_getTransactionReceiptsByBlockNumber', error); } - return null; + return []; } } async eth_getTransactionsByBlockNumber( _request: any, blockNumber: web3.Quantity | web3.Tag - ): Promise { + ): Promise { const blockNumber_ = parseBlockSpec(blockNumber) != 0 ? parseBlockSpec(blockNumber) || (await this._fetchCurrentBlockID()) : parseBlockSpec(blockNumber); - try { const { rows, @@ -594,12 +593,12 @@ export class DatabaseServer extends SkeletonServer { 'SELECT * FROM eth_getTransactionsByBlockNumber($1)', [blockNumber_] ); - return !rows || !rows.length ? null : exportJSON(rows); + return rows.length == 0 ? [] : exportJSON(rows); } catch (error) { if (this.config.debug) { console.debug('eth_getTransactionsByBlockNumber', error); } - return null; + return []; } } diff --git a/src/servers/skeleton.ts b/src/servers/skeleton.ts index 64eaf8bc..87151cf0 100644 --- a/src/servers/skeleton.ts +++ b/src/servers/skeleton.ts @@ -319,17 +319,17 @@ export abstract class SkeletonServer implements web3.Service { async eth_getTransactionReceiptsByBlockNumber( _request: any, _blockNumber: web3.Quantity | web3.Tag - ): Promise { + ): Promise { unimplemented('eth_getTransactionReceiptsByBlockNumber'); - return null; + return []; } async eth_getTransactionsByBlockNumber( _request: any, _blockNumber: web3.Quantity | web3.Tag - ): Promise { + ): Promise { unimplemented('eth_getTransactionsByBlockNumber'); - return null; + return []; } async eth_getUncleByBlockHashAndIndex( diff --git a/src/web3.ts b/src/web3.ts index fc8bbea8..a9a051b4 100644 --- a/src/web3.ts +++ b/src/web3.ts @@ -170,11 +170,11 @@ export interface Service { eth_getTransactionReceiptsByBlockNumber( _request: any, blockNumber: Quantity | Tag - ): Promise; + ): Promise; eth_getTransactionsByBlockNumber( _request: any, blockNumber: Quantity | Tag - ): Promise; + ): Promise; eth_getUncleByBlockHashAndIndex( _request: Request, blockHash: Data, From 2749281bd63863202978fcdffec176f48ecb6bdb Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Tue, 21 Dec 2021 09:18:43 +0100 Subject: [PATCH 13/13] revert to the old timestamp def in eth_geBlockByNumber.sql --- .docker/docker-entrypoint-initdb.d/init.txt | 2 +- etc/schema/functions/eth_getBlockByNumber.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.docker/docker-entrypoint-initdb.d/init.txt b/.docker/docker-entrypoint-initdb.d/init.txt index b8110973..b7117683 100644 --- a/.docker/docker-entrypoint-initdb.d/init.txt +++ b/.docker/docker-entrypoint-initdb.d/init.txt @@ -233,7 +233,7 @@ BEGIN gas_limit, -- gasLimit gas_used, -- gasUsed repeat('\000', 32)::hash, -- mixHash - EXTRACT(EPOCH FROM timestamp) -- timestamp + COALESCE(EXTRACT(EPOCH FROM timestamp), 0)::int4 -- timestamp FROM block WHERE id = block_id LIMIT 1 diff --git a/etc/schema/functions/eth_getBlockByNumber.sql b/etc/schema/functions/eth_getBlockByNumber.sql index 7b384cdf..d2af2dfc 100644 --- a/etc/schema/functions/eth_getBlockByNumber.sql +++ b/etc/schema/functions/eth_getBlockByNumber.sql @@ -22,7 +22,7 @@ BEGIN gas_limit, -- gasLimit gas_used, -- gasUsed repeat('\000', 32)::hash, -- mixHash - EXTRACT(EPOCH FROM timestamp) -- timestamp + COALESCE(EXTRACT(EPOCH FROM timestamp), 0)::int4 -- timestamp FROM block WHERE id = block_id LIMIT 1