You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
835 B
40 lines
835 B
6 years ago
|
import { AbiItemModel } from '../models/types';
|
||
|
import { AbiCoderClass } from '../abi/api';
|
||
|
|
||
|
export const decode = (
|
||
|
abiCoder: AbiCoderClass,
|
||
|
abiItemModel: AbiItemModel,
|
||
|
response: any,
|
||
|
) => {
|
||
|
let argumentTopics = response.topics;
|
||
|
|
||
|
if (!abiItemModel.anonymous) {
|
||
|
argumentTopics = response.topics.slice(1);
|
||
|
}
|
||
|
|
||
|
if (response.data === '0x') {
|
||
|
response.data = null;
|
||
|
}
|
||
|
|
||
|
response.returnValues = abiCoder.decodeLog(
|
||
|
abiItemModel.getInputs(),
|
||
|
response.data,
|
||
|
argumentTopics,
|
||
|
);
|
||
|
response.event = abiItemModel.name;
|
||
|
response.signature = abiItemModel.signature;
|
||
|
response.raw = {
|
||
|
data: response.data,
|
||
|
topics: response.topics,
|
||
|
};
|
||
|
|
||
|
if (abiItemModel.anonymous || !response.topics[0]) {
|
||
|
response.signature = null;
|
||
|
}
|
||
|
|
||
|
delete response.data;
|
||
|
delete response.topics;
|
||
|
|
||
|
return response;
|
||
|
};
|