From ed2f72d57416c257523aaa6878ff087188b317d5 Mon Sep 17 00:00:00 2001 From: rrozek Date: Wed, 21 Aug 2024 01:21:14 +0200 Subject: [PATCH] fix evm abi interpreter --- package.json | 2 +- .../dapp-analytics.controller.ts | 96 ++++++++++--------- .../dapp-analytics/helpers/utils.ts | 14 +-- 3 files changed, 58 insertions(+), 54 deletions(-) diff --git a/package.json b/package.json index 8b36284..d4fb255 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "dashboard-creator-server", "private": false, - "version": "3.2.4", + "version": "3.2.5", "license": "MIT", "main": "src/server.ts", "engines": { diff --git a/src/components/dapp-analytics/dapp-analytics.controller.ts b/src/components/dapp-analytics/dapp-analytics.controller.ts index 0dcd40d..c26a26b 100644 --- a/src/components/dapp-analytics/dapp-analytics.controller.ts +++ b/src/components/dapp-analytics/dapp-analytics.controller.ts @@ -656,30 +656,30 @@ const extractInkAbiEvents = function ( contractAbi: IInkAbi, ): IAbiEventsOutputContractEvent[] { // Extract events - const events: IAbiEventsOutputContractEvent[] = contractAbi.spec.events.map( - (event: IInkAbiEvent) => ({ + const events: IAbiEventsOutputContractEvent[] = + contractAbi.spec.events.map((event: IInkAbiEvent) => ({ name: event.label, args: event.args.map((arg: IInkAbiArg) => ({ name: arg.label, type: resolveInkType(arg.type.type, contractAbi.types), })), - }), - ); + })) || []; return events; }; const extractEvmAbiEvents = function ( abi: IEvmAbi, ): IAbiEventsOutputContractEvent[] { - const events: IAbiEventsOutputContractEvent[] = abi - .filter((item) => item.type === 'event') - .map((event: IEvmEventAbiItem) => ({ - name: event.name!, - args: event.inputs!.map((input) => ({ - name: input.name, - type: resolveEvmType(input.type), - })), - })); + const events: IAbiEventsOutputContractEvent[] = + abi + .filter((item) => item.type === 'event') + .map((event: IEvmEventAbiItem) => ({ + name: event.name!, + args: event.inputs!.map((input) => ({ + name: input.name, + type: resolveEvmType(input.type), + })), + })) || []; return events; }; @@ -688,46 +688,48 @@ const extractInkAbiFunctions = function ( contractAbi: IInkAbi, ): IAbiCallsOutputContractCall[] { // Extract messages (calls) that mutate the blockchain state - const calls: IAbiCallsOutputContractCall[] = contractAbi.spec.messages - .filter((message: IInkAbiMessage) => message.mutates) - .map((message: IInkAbiMessage) => ({ - name: message.label, - selector: message.selector, - args: message.args.map((arg: IInkAbiArg) => ({ - name: arg.label, - type: resolveInkType(arg.type.type, contractAbi.types), - })), - })); + const calls: IAbiCallsOutputContractCall[] = + contractAbi.spec.messages + .filter((message: IInkAbiMessage) => message.mutates) + .map((message: IInkAbiMessage) => ({ + name: message.label, + selector: message.selector, + args: message.args.map((arg: IInkAbiArg) => ({ + name: arg.label, + type: resolveInkType(arg.type.type, contractAbi.types), + })), + })) || []; return calls; }; const extractEvmAbiFunctions = function ( abi: IEvmAbi, ): IAbiCallsOutputContractCall[] { - const calls: IAbiCallsOutputContractCall[] = abi - .filter( - (item) => - item.type === 'function' && - item.stateMutability !== 'view' && - item.stateMutability !== 'pure', - ) - .map((func: IEvmFunctionAbiItem) => { - const functionSignature = `${func.name}(${func - .inputs!.map((input) => input.type) - .join(',')})`; - const selector = ethers - .keccak256(ethers.toUtf8Bytes(functionSignature)) - .slice(0, 10); - // TODO: jrojek, prevent selector calculation every time the method is called - return { - name: func.name!, - selector: selector, - args: func.inputs!.map((input) => ({ - name: input.name, - type: resolveEvmType(input.type), - })), - }; - }); + const calls: IAbiCallsOutputContractCall[] = + abi + .filter( + (item) => + item.type === 'function' && + item.stateMutability !== 'view' && + item.stateMutability !== 'pure', + ) + .map((func: IEvmFunctionAbiItem) => { + const functionSignature = `${func.name}(${func + .inputs!.map((input) => input.type) + .join(',')})`; + const selector = ethers + .keccak256(ethers.toUtf8Bytes(functionSignature)) + .slice(0, 10); + // TODO: jrojek, prevent selector calculation every time the method is called + return { + name: func.name!, + selector: selector, + args: func.inputs!.map((input) => ({ + name: input.name, + type: resolveEvmType(input.type), + })), + }; + }) || []; return calls; }; diff --git a/src/components/dapp-analytics/helpers/utils.ts b/src/components/dapp-analytics/helpers/utils.ts index 88dd466..9a72423 100644 --- a/src/components/dapp-analytics/helpers/utils.ts +++ b/src/components/dapp-analytics/helpers/utils.ts @@ -1,6 +1,3 @@ -import { IInkAbi, IEvmAbi } from '../abi.interface'; -import logger from '@core/utils/logger'; - const isSubstrateAbi = (abi: any): boolean => { return ( abi && @@ -15,9 +12,14 @@ const isEvmAbi = (abi: any): boolean => { abi && Array.isArray(abi) && abi.every((item) => - ['function', 'event', 'constructor', 'fallback', 'receive'].includes( - item.type, - ), + [ + 'function', + 'event', + 'constructor', + 'fallback', + 'receive', + 'error', + ].includes(item.type), ) ); };