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;
}
const overloadedTransferAbi = {
"constant": false,
"inputs": [
{ "name": "_to", "type": "address" },
{ "name": "_value", "type": "uint256" },
{ "name": "_data", "type": "bytes" }
],
"name": "transfer",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
const transferMethodTransactionDataA = web3Abi
.encodeFunctionCall( overloadedTransferAbi, [ fluorideAddrA,intAmountA, tradeId ]);
const transferMethodTransactionDataB = web3Abi
.encodeFunctionCall( overloadedTransferAbi, [ fluorideAddrB,intAmountB, tradeId ]);
const receiptPayA = await web3.eth
.sendTransaction({from: addrA, to: tokenA.address, data: transferMethodTransactionDataA, value: 0});
const receiptPayB = await web3.eth
.sendTransaction({from: addrB, to: tokenB.address, data: transferMethodTransactionDataB, value: 0});
const tokenABalA1 = await tokenA.balanceOf(addrA)
const tokenABalB1 = await tokenA.balanceOf(addrB)
const tokenBBalA1 = await tokenB.balanceOf(addrA)
const tokenBBalB1 = await tokenB.balanceOf(addrB)
// UPDATE SODIUM (this should be done by event relay/lithium)
const expectEventA = joinHex([fluorideAddrB/*, topic*/,tradeId])
const expectEventB = joinHex([fluorideAddrA/*, topic*/,tradeId])
const testDataA = [expectEventA,"2","3","4","5","6","7"]
before(async () => {
market = await StandardMarket.deployed();
registry = await DINRegistry.deployed();
orders = await Orders.deployed();
const registryUtils = await DINRegistryUtils.deployed();
// Register 2 new DINs to the merchant
const result = await registryUtils.selfRegisterDINs(2);
const logs = result.receipt.logs;
DIN1 = parseInt(ABI.decodeParameter("uint256", logs[0].topics[1]), 10);
DIN2 = parseInt(ABI.decodeParameter("uint256", logs[1].topics[1]), 10);
});
export default (signature, params = []) => {
const sigBytes = abi.encodeFunctionSignature(signature)
const types = signature.replace(')', '').split('(')[1]
// No params, return signature directly
if (types === '') {
return sigBytes
}
const paramBytes = abi.encodeParameters(types.split(','), params)
return `${sigBytes}${paramBytes.slice(2)}`
}
const encodeCalldata = (signature, params) => {
const sigBytes = ABI.encodeFunctionSignature(signature)
const types = signature.replace(')', '').split('(')[1]
// No params, return signature directly
if (types === '') {
return sigBytes
}
const paramBytes = ABI.encodeParameters(types.split(','), params)
return `${sigBytes}${paramBytes.slice(2)}`
}
function decodeTransferLog(log: Log): Transfer | null {
if (!log || !log.topics || !log.data) {
console.error('Invalid transfer log:', log)
return null
}
/**
* Decode using the parameter signture for an ERC20 Transfer event
* For unknown reasons, blockscout includes an extra unknown param in the log's topics list
* Including this unknown param in the input list or decoding won't work
*/
try {
// @ts-ignore
const decodedLog: any = Web3EthAbi.default.decodeLog(
[
{
indexed: true,
name: 'unknown',
type: 'address',
},
{
indexed: true,
name: 'from',
type: 'address',
},
{
indexed: true,
name: 'to',
type: 'address',
},
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
// makerQuantity.quantity,
// takerQuantity.quantity,
// ).call();
const policyManager = await getContract(
environment,
Contracts.PolicyManager,
policyManagerAddress,
);
const exchangeAddress =
environment.deployment.exchangeConfigs[Exchanges.MatchingMarket].exchange;
const result = await policyManager.methods
.preValidate(
web3EthAbi.encodeFunctionSignature(FunctionSignatures.takeOrder),
[
'0x0000000000000000000000000000000000000000', // orderAddresses[0],
tradingAddress.toString(), // orderAddresses[1],
makerQuantity.token.address.toString(), // orderAddresses[2],
takerQuantity.token.address.toString(), // orderAddresses[3],
exchangeAddress.toString(), // exchanges[exchangeIndex].exchange
],
[
makerQuantity.quantity.toString(), // orderValues[0],
takerQuantity.quantity.toString(), // orderValues[1],
fillTakerTokenAmount.quantity.toString(), // orderValues[6]
],
`0x${Number(id)
.toString(16)
.padStart(64, '0')}`, // identifier
)