Skip to content

Commit

Permalink
Merge pull request #32 from tokenguardio/dapp-analytics-dev
Browse files Browse the repository at this point in the history
fix types mapping for evm
  • Loading branch information
rrozek authored Aug 16, 2024
2 parents 1bbc45e + fdec6fc commit 58c9678
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-ecr-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# - name: Check out code
# uses: actions/checkout@v3
# - name: Run tests
# run: docker compose -f docker-compose.test.yml run server npm test
# run: docker compose -f docker-compose-test.yml run server npm test

build-push:
name: Build image and push to ECR(tokenguard-dev)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-ecr-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# - name: Check out code
# uses: actions/checkout@v3
# - name: Run tests
# run: docker compose -f docker-compose.test.yml run server npm test
# run: docker compose -f docker-compose-test.yml run server npm test

build-push:
name: Build and push to ECR(tokenguard-prod)
Expand Down
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.0",
"version": "3.2.1",
"license": "MIT",
"main": "src/server.ts",
"engines": {
Expand Down
11 changes: 5 additions & 6 deletions src/components/dapp-analytics/dapp-analytics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
IEvmEventAbiItem,
IEvmFunctionAbiItem,
} from './abi.interface';
import { resolveType } from './substrate-types.mapping';
import { resolveInkType, resolveEvmType } from './types.mapping';
import { docker, k8sApi } from 'server';
import { getCurrentBlock } from '@components/node-api/chainstate';
import { convertAndFormatNumbers } from './helpers/formatting';
Expand Down Expand Up @@ -660,7 +660,7 @@ const extractInkAbiEvents = function (
name: event.label,
args: event.args.map((arg: IInkAbiArg) => ({
name: arg.label,
type: resolveType(arg.type.type, contractAbi.types),
type: resolveInkType(arg.type.type, contractAbi.types),
})),
}),
);
Expand All @@ -676,7 +676,7 @@ const extractEvmAbiEvents = function (
name: event.name!,
args: event.inputs!.map((input) => ({
name: input.name,
type: input.type,
type: resolveEvmType(input.type),
})),
}));

Expand All @@ -694,7 +694,7 @@ const extractInkAbiFunctions = function (
selector: message.selector,
args: message.args.map((arg: IInkAbiArg) => ({
name: arg.label,
type: resolveType(arg.type.type, contractAbi.types),
type: resolveInkType(arg.type.type, contractAbi.types),
})),
}));
return calls;
Expand All @@ -715,7 +715,7 @@ const extractEvmAbiFunctions = function (
selector: '0x00000000', // jrojek TODO: calculate selector
args: func.inputs!.map((input) => ({
name: input.name,
type: input.type,
type: resolveEvmType(input.type),
})),
}));

Expand All @@ -736,7 +736,6 @@ export const getDappAbiEvents = async (
let dappEventsOutput: IAbiEventsOutput = { contracts: [] };

for (const contract of dapp.abis) {
logger.debug(`Contract ABI: ${JSON.stringify(contract.abi)}`);
if (isSubstrateAbi(contract.abi)) {
const dAppContract: IAbiEventsOutputContract = {
name: contract.name,
Expand Down
11 changes: 3 additions & 8 deletions src/components/dapp-analytics/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,15 @@ const isSubstrateAbi = (abi: any): boolean => {
};

const isEvmAbi = (abi: any): boolean => {
logger.debug(`isEvmAbi abi: ${JSON.stringify(abi)}`);
abi.forEach((item) => {
logger.debug(`isEvmAbi abi item.type: ${JSON.stringify(item.type)}`);
});
const isEvmAbi =
return (
abi &&
Array.isArray(abi) &&
abi.every((item) =>
['function', 'event', 'constructor', 'fallback', 'receive'].includes(
item.type,
),
);
logger.debug(`isEvmAbi isEvmAbi: ${isEvmAbi}`);
return isEvmAbi;
)
);
};

export { isSubstrateAbi, isEvmAbi };
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const substrateToPostgresTypeMap = {
i32: 'integer',
i64: 'integer',
i128: 'integer',
f32: 'float',
f64: 'float',
f32: 'number',
f64: 'number',
str: 'string',
bool: 'boolean',
};

function resolveType(typeId, types) {
function resolveInkType(typeId, types) {
const typeDef = types.find((t) => t.id === typeId);
if (!typeDef) {
throw new Error(`Type ID ${typeId} not found in ABI.`);
Expand All @@ -29,7 +29,7 @@ function resolveType(typeId, types) {
// Handle other types (e.g., composite, array, sequence, tuple, variant) if needed
const typeDefArray = typeDef.type.def.array;
if (typeDefArray) {
return resolveType(typeDefArray.type, types); // Simplified: assume the array elements have the same type
return resolveInkType(typeDefArray.type, types); // Simplified: assume the array elements have the same type
}

const typeDefComposite = typeDef.type.def.composite;
Expand All @@ -39,7 +39,7 @@ function resolveType(typeId, types) {

const typeDefSequence = typeDef.type.def.sequence;
if (typeDefSequence) {
return resolveType(typeDefSequence.type, types); // Simplified: assume sequence elements have the same type
return resolveInkType(typeDefSequence.type, types); // Simplified: assume sequence elements have the same type
}

const typeDefTuple = typeDef.type.def.tuple;
Expand All @@ -55,4 +55,27 @@ function resolveType(typeId, types) {
return 'string'; // Default type
}

export { resolveType };
const evmToPostgresTypeMap = {
uint8: 'integer',
uint16: 'integer',
uint32: 'integer',
uint64: 'integer',
uint128: 'integer',
uint256: 'integer',
int8: 'integer',
int16: 'integer',
int32: 'integer',
int64: 'integer',
int128: 'integer',
int256: 'integer',
bool: 'boolean',
address: 'string',
bytes: 'string',
string: 'string',
};

function resolveEvmType(type) {
return evmToPostgresTypeMap[type] || 'string';
}

export { resolveInkType, resolveEvmType };

0 comments on commit 58c9678

Please sign in to comment.