Skip to content

Commit ed2f72d

Browse files
committed
fix evm abi interpreter
1 parent 5c26f15 commit ed2f72d

File tree

3 files changed

+58
-54
lines changed

3 files changed

+58
-54
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dashboard-creator-server",
33
"private": false,
4-
"version": "3.2.4",
4+
"version": "3.2.5",
55
"license": "MIT",
66
"main": "src/server.ts",
77
"engines": {

src/components/dapp-analytics/dapp-analytics.controller.ts

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -656,30 +656,30 @@ const extractInkAbiEvents = function (
656656
contractAbi: IInkAbi,
657657
): IAbiEventsOutputContractEvent[] {
658658
// Extract events
659-
const events: IAbiEventsOutputContractEvent[] = contractAbi.spec.events.map(
660-
(event: IInkAbiEvent) => ({
659+
const events: IAbiEventsOutputContractEvent[] =
660+
contractAbi.spec.events.map((event: IInkAbiEvent) => ({
661661
name: event.label,
662662
args: event.args.map((arg: IInkAbiArg) => ({
663663
name: arg.label,
664664
type: resolveInkType(arg.type.type, contractAbi.types),
665665
})),
666-
}),
667-
);
666+
})) || [];
668667
return events;
669668
};
670669

671670
const extractEvmAbiEvents = function (
672671
abi: IEvmAbi,
673672
): IAbiEventsOutputContractEvent[] {
674-
const events: IAbiEventsOutputContractEvent[] = abi
675-
.filter((item) => item.type === 'event')
676-
.map((event: IEvmEventAbiItem) => ({
677-
name: event.name!,
678-
args: event.inputs!.map((input) => ({
679-
name: input.name,
680-
type: resolveEvmType(input.type),
681-
})),
682-
}));
673+
const events: IAbiEventsOutputContractEvent[] =
674+
abi
675+
.filter((item) => item.type === 'event')
676+
.map((event: IEvmEventAbiItem) => ({
677+
name: event.name!,
678+
args: event.inputs!.map((input) => ({
679+
name: input.name,
680+
type: resolveEvmType(input.type),
681+
})),
682+
})) || [];
683683

684684
return events;
685685
};
@@ -688,46 +688,48 @@ const extractInkAbiFunctions = function (
688688
contractAbi: IInkAbi,
689689
): IAbiCallsOutputContractCall[] {
690690
// Extract messages (calls) that mutate the blockchain state
691-
const calls: IAbiCallsOutputContractCall[] = contractAbi.spec.messages
692-
.filter((message: IInkAbiMessage) => message.mutates)
693-
.map((message: IInkAbiMessage) => ({
694-
name: message.label,
695-
selector: message.selector,
696-
args: message.args.map((arg: IInkAbiArg) => ({
697-
name: arg.label,
698-
type: resolveInkType(arg.type.type, contractAbi.types),
699-
})),
700-
}));
691+
const calls: IAbiCallsOutputContractCall[] =
692+
contractAbi.spec.messages
693+
.filter((message: IInkAbiMessage) => message.mutates)
694+
.map((message: IInkAbiMessage) => ({
695+
name: message.label,
696+
selector: message.selector,
697+
args: message.args.map((arg: IInkAbiArg) => ({
698+
name: arg.label,
699+
type: resolveInkType(arg.type.type, contractAbi.types),
700+
})),
701+
})) || [];
701702
return calls;
702703
};
703704

704705
const extractEvmAbiFunctions = function (
705706
abi: IEvmAbi,
706707
): IAbiCallsOutputContractCall[] {
707-
const calls: IAbiCallsOutputContractCall[] = abi
708-
.filter(
709-
(item) =>
710-
item.type === 'function' &&
711-
item.stateMutability !== 'view' &&
712-
item.stateMutability !== 'pure',
713-
)
714-
.map((func: IEvmFunctionAbiItem) => {
715-
const functionSignature = `${func.name}(${func
716-
.inputs!.map((input) => input.type)
717-
.join(',')})`;
718-
const selector = ethers
719-
.keccak256(ethers.toUtf8Bytes(functionSignature))
720-
.slice(0, 10);
721-
// TODO: jrojek, prevent selector calculation every time the method is called
722-
return {
723-
name: func.name!,
724-
selector: selector,
725-
args: func.inputs!.map((input) => ({
726-
name: input.name,
727-
type: resolveEvmType(input.type),
728-
})),
729-
};
730-
});
708+
const calls: IAbiCallsOutputContractCall[] =
709+
abi
710+
.filter(
711+
(item) =>
712+
item.type === 'function' &&
713+
item.stateMutability !== 'view' &&
714+
item.stateMutability !== 'pure',
715+
)
716+
.map((func: IEvmFunctionAbiItem) => {
717+
const functionSignature = `${func.name}(${func
718+
.inputs!.map((input) => input.type)
719+
.join(',')})`;
720+
const selector = ethers
721+
.keccak256(ethers.toUtf8Bytes(functionSignature))
722+
.slice(0, 10);
723+
// TODO: jrojek, prevent selector calculation every time the method is called
724+
return {
725+
name: func.name!,
726+
selector: selector,
727+
args: func.inputs!.map((input) => ({
728+
name: input.name,
729+
type: resolveEvmType(input.type),
730+
})),
731+
};
732+
}) || [];
731733

732734
return calls;
733735
};

src/components/dapp-analytics/helpers/utils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { IInkAbi, IEvmAbi } from '../abi.interface';
2-
import logger from '@core/utils/logger';
3-
41
const isSubstrateAbi = (abi: any): boolean => {
52
return (
63
abi &&
@@ -15,9 +12,14 @@ const isEvmAbi = (abi: any): boolean => {
1512
abi &&
1613
Array.isArray(abi) &&
1714
abi.every((item) =>
18-
['function', 'event', 'constructor', 'fallback', 'receive'].includes(
19-
item.type,
20-
),
15+
[
16+
'function',
17+
'event',
18+
'constructor',
19+
'fallback',
20+
'receive',
21+
'error',
22+
].includes(item.type),
2123
)
2224
);
2325
};

0 commit comments

Comments
 (0)