Skip to content

Commit

Permalink
Merge pull request #970 from telosnetwork/969-unsupported-fragment-error
Browse files Browse the repository at this point in the history
#969 | unsupported fragment error better handled
  • Loading branch information
pmjanus authored Feb 6, 2025
2 parents 72f5469 + e974b35 commit 81a567d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
4 changes: 3 additions & 1 deletion src/components/TransactionTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ async function parseTransactions() {
const value = BigNumber.from(value_str);
const sighash = transaction.input.slice(0, 10);
const signature = abi[sighash] as string;
const name = signature.split('(')[0].replace('function ', '');
const name = typeof signature === 'string' ?
signature.split('(')[0].replace('function ', '') :
sighash;
transaction.parsedTransaction = {
name,
sighash,
Expand Down
3 changes: 1 addition & 2 deletions src/core/chains/EVMChainSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ export default abstract class EVMChainSettings implements ChainSettings {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
this.indexer.interceptors.response.use(function (response) {
if(response.data?.abi?.length > 0){
if(response.data?.abi){
for (const [key, value] of Object.entries(response.data.abi)) {
self.getContractManager().parser.addFunctionInterface(key, value);
self.getFragmentParser().addFunctionInterface(key, value);
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/lib/contract/ContractManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ export default class ContractManager {
if (data === '0x' || !data || !contract) {
return false;
}

const functionIface = await this.parser.getFunctionInterface(data);
if (!functionIface) {
return false;
}
if (contract.getInterface()) {
try {
let transaction = await contract.getInterface().parseTransaction({ data });
Expand All @@ -154,15 +159,12 @@ export default class ContractManager {
}
}
try {
const functionIface = await this.parser.getFunctionInterface(data);
if (functionIface) {
let transaction = functionIface.parseTransaction({ data });
if(!transfers){
return transaction;
}
transaction.transfers = await this.getTransfers(raw);
let transaction = functionIface.parseTransaction({ data });
if(!transfers){
return transaction;
}
transaction.transfers = await this.getTransfers(raw);
return transaction;
} catch (e) {
console.warn(`Unable to parse transaction data using abi for ${contract.address}: ${e}`);
}
Expand Down
20 changes: 6 additions & 14 deletions src/lib/contract/FragmentParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class FragmentParser {
this.eventInterfaces = events_overrides;
this.processing = [];
this.evmEndpoint = evmEndpoint;
this.id = Math.floor(Math.random() * 100);
}

async addEventInterface(hex, signature){
Expand All @@ -19,28 +20,19 @@ export default class FragmentParser {
this.eventInterfaces[hex] = signature;
}
async addFunctionInterface(hex, signature){
if (Object.prototype.hasOwnProperty.call(this.functionInterfaces, hex)) {
if (!signature) {
console.warn('indexer provides an incorrect abi value', { hex, signature });
return;
}
this.functionInterfaces[hex] = signature;
}

async getFunctionInterface(data) {
let prefix = data.toLowerCase().slice(0, 10);
if(prefix === '0x'){
return;
}
if (Object.prototype.hasOwnProperty.call(this.functionInterfaces, prefix)) {
return new ethers.utils.Interface([this.functionInterfaces[prefix]]);
let funcName = this.functionInterfaces[prefix];
if (typeof funcName === 'string') {
return new ethers.utils.Interface([funcName]);
}
if(this.processing.includes(data)){
await new Promise(resolve => setTimeout(resolve, 300));
let result = await this.getFunctionInterface(data);
return result;
}
this.processing.push(data);

this.functionInterfaces[prefix] = '';
return false;
}
async getEventInterface(data) {
Expand Down

0 comments on commit 81a567d

Please sign in to comment.