From 441bc4ca2c2c8522e28209eefafa78e25a8f4f16 Mon Sep 17 00:00:00 2001 From: Scott Twiname Date: Wed, 8 Nov 2023 10:53:36 +1300 Subject: [PATCH 1/2] Fix transaction getter being removed when cloning object --- .../node/src/ethereum/api.ethereum.test.ts | 27 +++++++++++++++++++ packages/node/src/ethereum/api.ethereum.ts | 16 +++++------ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/packages/node/src/ethereum/api.ethereum.test.ts b/packages/node/src/ethereum/api.ethereum.test.ts index a992c731d7..2a7da07414 100644 --- a/packages/node/src/ethereum/api.ethereum.test.ts +++ b/packages/node/src/ethereum/api.ethereum.test.ts @@ -73,6 +73,10 @@ describe('Api.ethereum', () => { it('should have the ability to get receipts via transactions from all types', () => { expect(typeof blockData.transactions[0].receipt).toEqual('function'); expect(typeof blockData.logs[0].transaction.receipt).toEqual('function'); + expect(typeof blockData.logs[0].transaction.from).toEqual('string'); + expect(typeof blockData.transactions[81].logs[0].transaction.from).toEqual( + 'string', + ); expect( typeof blockData.transactions[81].logs[0].transaction.receipt, ).toEqual('function'); @@ -89,6 +93,17 @@ describe('Api.ethereum', () => { expect(parsedTx.logs[0].args).toBeTruthy(); }); + it('Should decode transaction data and not clone object', async () => { + const tx = blockData.transactions.find( + (e) => + e.hash === + '0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc', + ); + const parsedTx = await ethApi.parseTransaction(tx, ds); + + expect(parsedTx).toBe(tx); + }); + it('Should return raw logs, if decode fails', async () => { // not Erc721 const tx = blockData.transactions.find( @@ -101,6 +116,18 @@ describe('Api.ethereum', () => { expect(parsedLog).toBeTruthy(); }); + // This test is here to ensure getters aren't removed + it('Should not clone logs when parsing args', async () => { + const log = blockData.transactions.find( + (e) => + e.hash === + '0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc', + ).logs[1]; + + const parsedLog = await ethApi.parseLog(log, ds); + expect(parsedLog).toBe(log); + }); + it('Null filter support', async () => { const beamEndpoint = 'https://rpc.api.moonbeam.network'; ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter); diff --git a/packages/node/src/ethereum/api.ethereum.ts b/packages/node/src/ethereum/api.ethereum.ts index bc3a09bc7c..84aea68bc4 100644 --- a/packages/node/src/ethereum/api.ethereum.ts +++ b/packages/node/src/ethereum/api.ethereum.ts @@ -1,6 +1,7 @@ // Copyright 2020-2023 SubQuery Pte Ltd authors & contributors // SPDX-License-Identifier: GPL-3.0 +import assert from 'assert'; import fs from 'fs'; import http from 'http'; import https from 'https'; @@ -382,10 +383,10 @@ export class EthereumApi implements ApiWrapper { return log; } const iface = this.buildInterface(ds.options.abi, await loadAssets(ds)); - return { - ...log, - args: iface?.parseLog(log).args as T, - }; + + log.args = iface?.parseLog(log).args as T; + + return log; } catch (e) { logger.warn(`Failed to parse log data: ${e.message}`); return log; @@ -412,10 +413,9 @@ export class EthereumApi implements ApiWrapper { transaction.logs.map(async (log) => this.parseLog(log, ds)), )) as Array>); - return { - ...transaction, - args, - }; + transaction.args = args; + + return transaction; } catch (e) { logger.warn(`Failed to parse transaction data: ${e.message}`); return transaction; From 836435e2005b1e2891262c0173f9695150bd75ca Mon Sep 17 00:00:00 2001 From: Scott Twiname Date: Wed, 8 Nov 2023 10:56:05 +1300 Subject: [PATCH 2/2] Update changelog --- packages/node/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/node/CHANGELOG.md b/packages/node/CHANGELOG.md index 894e86546b..634b24bc92 100644 --- a/packages/node/CHANGELOG.md +++ b/packages/node/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed - Getting transaction receipts when accessing via a log handler +- transaction missing from log (#202) ## [3.3.0] - 2023-11-06 ### Added