custom abi overwrite
This commit is contained in:
@@ -24,6 +24,7 @@ export interface MainSettings {
|
||||
rate_monitoring: boolean;
|
||||
bp_logs: boolean;
|
||||
dsp_parser: boolean;
|
||||
allow_custom_abi: boolean;
|
||||
}
|
||||
|
||||
export interface IndexerConfigs {
|
||||
|
||||
+79
-13
@@ -5,11 +5,19 @@ import {Serialize} from "../addons/eosjs-native";
|
||||
import {hLog} from "../helpers/common_functions";
|
||||
import {Message} from "amqplib";
|
||||
import {parseDSPEvent} from "../modules/custom/dsp-parser";
|
||||
import {resolve, join} from "path";
|
||||
import {readdirSync, existsSync, readFileSync} from "fs";
|
||||
|
||||
const abi_remapping = {
|
||||
"_Bool": "bool"
|
||||
};
|
||||
|
||||
interface CustomAbiDef {
|
||||
abi: string;
|
||||
startingBlock: number;
|
||||
endingBlock: number;
|
||||
}
|
||||
|
||||
export default class DSPoolWorker extends HyperionWorker {
|
||||
|
||||
abi;
|
||||
@@ -31,6 +39,8 @@ export default class DSPoolWorker extends HyperionWorker {
|
||||
monitoringLoop: NodeJS.Timeout;
|
||||
actionDsCounter = 0;
|
||||
|
||||
customAbiMap: Map<string, CustomAbiDef[]> = new Map();
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
@@ -62,6 +72,8 @@ export default class DSPoolWorker extends HyperionWorker {
|
||||
}
|
||||
}, 1);
|
||||
|
||||
this.processCustomABI();
|
||||
|
||||
// Define Common Functions
|
||||
this.common = {
|
||||
attachActionExtras: this.attachActionExtras,
|
||||
@@ -69,6 +81,42 @@ export default class DSPoolWorker extends HyperionWorker {
|
||||
}
|
||||
}
|
||||
|
||||
processCustomABI() {
|
||||
if (this.conf.settings.allow_custom_abi) {
|
||||
|
||||
if (!this.customAbiMap) {
|
||||
this.customAbiMap = new Map<string, CustomAbiDef[]>();
|
||||
}
|
||||
|
||||
const dir = join(resolve(), "custom-abi", this.chain);
|
||||
if (existsSync(dir)) {
|
||||
const files = readdirSync(dir);
|
||||
for (const abiFile of files) {
|
||||
try {
|
||||
const [code, startingBlock, suffix] = abiFile.split("-");
|
||||
const endingBlock = suffix.split(".")[0];
|
||||
hLog(`Custom ABI for ${code} from ${startingBlock} up to ${endingBlock}`);
|
||||
const parsedAbi = readFileSync(join(dir, abiFile)).toString();
|
||||
const def: CustomAbiDef = {
|
||||
abi: parsedAbi,
|
||||
startingBlock: parseInt(startingBlock),
|
||||
endingBlock: parseInt(endingBlock)
|
||||
};
|
||||
|
||||
if (!this.customAbiMap.has(code)) {
|
||||
this.customAbiMap.set(code, [def]);
|
||||
} else {
|
||||
this.customAbiMap.get(code).push(def);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
hLog(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
attachActionExtras(self, action) {
|
||||
self.mLoader.processActionData(action);
|
||||
}
|
||||
@@ -132,24 +180,42 @@ export default class DSPoolWorker extends HyperionWorker {
|
||||
_status = false;
|
||||
}
|
||||
if (!_status) {
|
||||
const savedAbi = await this.fetchAbiHexAtBlockElastic(contract, block_num, false);
|
||||
if (savedAbi) {
|
||||
if (savedAbi[field + 's'].includes(type)) {
|
||||
if (savedAbi.abi_hex) {
|
||||
_status = AbiEOS.load_abi_hex(contract, savedAbi.abi_hex);
|
||||
|
||||
if (this.conf.settings.allow_custom_abi) {
|
||||
if (this.customAbiMap.has(contract)) {
|
||||
const list = this.customAbiMap.get(contract);
|
||||
const matchingAbi = list.find(entry => {
|
||||
return entry.startingBlock < block_num && entry.endingBlock > block_num;
|
||||
});
|
||||
if (matchingAbi.abi) {
|
||||
_status = AbiEOS.load_abi(contract, matchingAbi.abi);
|
||||
}
|
||||
if (_status) {
|
||||
try {
|
||||
resultType = AbiEOS['get_type_for_' + field](contract, type);
|
||||
_status = true;
|
||||
return [_status, resultType];
|
||||
} catch (e) {
|
||||
hLog(`(abieos/cached) >> ${e.message}`);
|
||||
_status = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!_status) {
|
||||
const savedAbi = await this.fetchAbiHexAtBlockElastic(contract, block_num, false);
|
||||
if (savedAbi) {
|
||||
if (savedAbi[field + 's'].includes(type)) {
|
||||
if (savedAbi.abi_hex) {
|
||||
_status = AbiEOS.load_abi_hex(contract, savedAbi.abi_hex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_status) {
|
||||
try {
|
||||
resultType = AbiEOS['get_type_for_' + field](contract, type);
|
||||
_status = true;
|
||||
return [_status, resultType];
|
||||
} catch (e) {
|
||||
hLog(`(abieos/cached) >> ${e.message}`);
|
||||
_status = false;
|
||||
}
|
||||
}
|
||||
|
||||
const currentAbi = await this.rpc.getRawAbi(contract);
|
||||
if (currentAbi.abi.byteLength > 0) {
|
||||
const abi_hex = Buffer.from(currentAbi.abi).toString('hex');
|
||||
|
||||
Reference in New Issue
Block a user