Skip to content

Commit

Permalink
Merge pull request #36 from tokenguardio/dapp-analytics-dev
Browse files Browse the repository at this point in the history
Release 3.2.5
  • Loading branch information
rrozek authored Aug 20, 2024
2 parents 86347b1 + ed2f72d commit 17d4cca
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 54 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
96 changes: 49 additions & 47 deletions src/components/dapp-analytics/dapp-analytics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down
14 changes: 8 additions & 6 deletions src/components/dapp-analytics/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { IInkAbi, IEvmAbi } from '../abi.interface';
import logger from '@core/utils/logger';

const isSubstrateAbi = (abi: any): boolean => {
return (
abi &&
Expand All @@ -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),
)
);
};
Expand Down

0 comments on commit 17d4cca

Please sign in to comment.