Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function decodeLogParameters(log: Log, abi: Abi): DecodedLog {
// first find the matching signature
const matchingSignature = _.find(
abi,
abiSignature =>
abiSignature.type === 'event' &&
!abiSignature.anonymous &&
encodeEventSignature(abiSignature) === log.topics[ 0 ]
);
if (!matchingSignature) {
throw new Error('found abi but failed to find matching event signature');
}
const parameters = decodeLog(matchingSignature.inputs, log.data, log.topics);
return {
...log,
ethercast: {
eventName: matchingSignature.name || '',
parameters
}
};
}
payload = await receipt.logs.map( log => {
if (log.address == spankbank.address) {
const topics = (log.topics.length > 1) ? log.topics.slice(1) : []
return abi.decodeLog(inputs, log.data, topics)
}
})
}
export const LogParser = (log: Log | string, abi: any) => {
if (typeof log === 'string') return log
if (!abi) throw new Error('ABI Missed')
if (abi.length === undefined) throw new Error('ABI must be type of array')
const topics =
abi.filter((input: { indexed: boolean }) => input.indexed).length ===
log.topics.length
? log.topics
: log.topics.slice(1)
const decodedLogs = ABICoder.decodeLog(abi, log.data || '', topics)
return { ...log, decodedLogs }
}
const decode = (inputs, rawLog) => {
const [,
firstInput,
secondInput,
] = rawLog.topics;
const decoded = {
...abi.decodeLog(inputs, rawLog.data, [
firstInput,
secondInput,
]),
blockNumber: rawLog.blockNumber,
};
return decoded;
};
function decodeLogItemArgs(def, log) {
return normalizeDecodedOutput(
def.inputs,
abiEncoder.decodeLog(
def.inputs,
log.data,
log.topics.slice(1)));
}
.map(log => {
const logABI = constructor.events[log.topics[0]];
if (logABI == null) return null;
const copy = Utils.merge({}, log);
copy.event = logABI.name;
copy.topics = logABI.anonymous ? copy.topics : copy.topics.slice(1);
if (copy.data === "0x") copy.data = "";
let logArgs;
try {
logArgs = abi.decodeLog(logABI.inputs, copy.data, copy.topics);
copy.args = reformat.numbers.call(
constructor,
logArgs,
logABI.inputs
);
} catch (_) {
return null;
}
delete copy.data;
delete copy.topics;
return copy;
})
.filter(log => log != null);
if (logABI == null) {
return null;
}
const copy = Utils.merge({}, log);
copy.event = logABI.name;
copy.topics = logABI.anonymous ? copy.topics : copy.topics.slice(1);
if (copy.data === "0x") {
copy.data = "";
}
let logArgs;
try {
logArgs = abi.decodeLog(logABI.inputs, copy.data, copy.topics);
} catch (_) {
return null;
}
copy.args = reformat.numbers.call(constructor, logArgs, logABI.inputs);
delete copy.data;
delete copy.topics;
return copy;
})
.filter(log => log != null);
exports.LogParser = (log, abi) => {
if (typeof log === 'string')
return log;
if (!abi)
throw new Error('ABI Missed');
const decodedLogs = ABICoder.decodeLog(abi, log.data || '', log.topics || []);
return Object.assign({}, log, { decodedLogs });
};
return eventLogs.map(log => {
log.event = eventAbi.name
log.args = abi.decodeLog(eventAbi.inputs, log.data, log.topics.slice(1))
return log
})
}
tryParseLog(log: Log): null | EventLog {
if (log.topics.length === 0) {
return null
}
const contractMapping = this.addressMapping.get(log.address)
if (contractMapping == null) {
return null
}
const logSignature = log.topics[0]
const matchedAbi = contractMapping.logMapping.get(logSignature)
if (matchedAbi == null) {
return null
}
const returnValues = abi.decodeLog(matchedAbi.inputs || [], log.data || '', log.topics.slice(1))
delete (returnValues as any).__length__
Object.keys(returnValues).forEach((key) => {
if (Number.parseInt(key, 10) >= 0) {
delete (returnValues as any)[key]
}
})
const logEvent: EventLog & { signature: string } = {
address: log.address,
blockHash: log.blockHash,
blockNumber: log.blockNumber,
logIndex: log.logIndex,
transactionIndex: log.transactionIndex,
transactionHash: log.transactionHash,
returnValues,
event: matchedAbi.name!,