Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var event = null;
for (var i = 0; i < abi.length; i++) {
var item = abi[i];
if (item.type != "event") continue;
var signature = item.name + "(" + item.inputs.map(function(input) {return input.type;}).join(",") + ")";
var hash = web3.sha3(signature);
if (hash == log.topics[0]) {
event = item;
break;
}
}
if (event != null) {
var inputs = event.inputs.map(function(input) {return input.type;});
var data = abiUtils.decodeParameters(inputs, log.data.replace("0x", ""));
// Do something with the data. Depends on the log and what you're using the data for.
return {name:event.name , data:data};
}
return null;
}
const decodeOrderResult = result => {
// Exclude the indexed parameter "orderID"
return ABI.decodeParameters(
[
{ type: "address", name: "market" },
{ type: "bytes32", name: "nonceHash" },
{ type: "uint256[]", name: "DINs" },
{ type: "uint256[]", name: "quantities" }
],
result.receipt.logs[0].data
);
};
var event = null;
for (var i = 0; i < abi.length; i++) {
var item = abi[i];
if (item.type != "event") continue;
var signature = item.name + "(" + item.inputs.map(function(input) {return input.type;}).join(",") + ")";
var hash = web3.sha3(signature);
if (hash == log.topics[0]) {
event = item;
break;
}
}
if (event != null) {
var inputs = event.inputs.filter(function(input) {return !input.indexed;}).map(function(input) {return input.type;});
var data = abiUtils.decodeParameters(inputs, log.data.replace("0x", ""));
// Do something with the data. Depends on the log and what you're using the data for.
return {name:event.name , data:data};
}
return null;
}
function evaluate (source, call, { userHelpers = {}, ...options } = {}) {
// Get method ID
const methodId = call.transaction.data.substr(0, 10)
// Find method ABI
const method = call.abi.find((abi) =>
abi.type === 'function' &&
methodId === ABI.encodeFunctionSignature(abi))
// Decode parameters
const parameterValues = ABI.decodeParameters(
method.inputs,
'0x' + call.transaction.data.substr(10)
)
const parameters = method.inputs.reduce((parameters, input) =>
Object.assign(
parameters, {
[input.name]: {
type: input.type,
value: parameterValues[input.name]
}
}
), {})
const availableHelpers = { ...defaultHelpers, ...userHelpers }
// Get additional options
Contract.prototype._decodeMethodReturn = function (outputs, returnValues) {
if (!returnValues) {
return null;
}
returnValues = returnValues.length >= 2 ? returnValues.slice(2) : returnValues;
var result = abi.decodeParameters(outputs, returnValues);
if (result.__length__ === 1) {
return result[0];
} else {
delete result.__length__;
return result;
}
};
export default async function(ledger: AssetLedger) {
const attrs = {
to: ledger.id,
data: encodeFunctionCall(abi, []),
};
const res = await ledger.provider.send({
method: 'eth_call',
params: [attrs, 'latest'],
});
return decodeParameters(abi.outputs, res.result)[0];
}
export function parseResult({ abi }: ContractQueryOptions, { result }: RpcResponse) {
return decodeParameters(abi.outputs, result);
}
const decodeParameters = (names, types, data) => {
const ret = {};
if (names.length && names.length === types.length) {
const result = Abi.decodeParameters(types, data);
for (let i = 0; types.length > i; i += 1) {
if (undefined !== result[i]) {
ret[names[i]] = result[i];
}
}
}
return ret;
};
const decodeParameters = (names, types, data) => {
const ret = {}
if (names.length && names.length === types.length) {
const result = Abi.decodeParameters(types, data)
for (let i = 0; types.length > i; i += 1) {
if (undefined !== result[i]) {
ret[names[i]] = result[i]
}
}
}
return ret
}