Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
decodeParams(message, abiCode, function_selector) {
const cutArr = function_selector.match(/(.+)\((.*)\)/);
console.log('abiCode', abiCode)
if (cutArr[2] !== '') {
const byteArray = TronWeb.utils.code.hexStr2byteArray(message);
const abi = abiCode.filter(({
name
}) => name === cutArr[1]);
return abi[0].inputs.map(({
name,
type
}, i) => {
let value;
const array = byteArray.filter((v, index) => index >= 32 * i && index < 32 * (i + 1));
if (type === 'address') {
value = TronWeb.address.fromHex('41' + TronWeb.utils.code.byteArray2hexStr(array.filter((v, i) => i > 11)));
} else if (type === 'trcToken') {
value = TronWeb.toDecimal('0x' + TronWeb.utils.code.byteArray2hexStr(array));
} else {
value = TronWeb.toDecimal('0x' + TronWeb.utils.code.byteArray2hexStr(array));
}
return abi[0].inputs.map(({name,type},i)=>{
let value;
const array = byteArray.filter((v,index)=>index >=32 * i && index< 32 * (i + 1));
if(type === 'address') {
value = TronWeb.address.fromHex('41'+TronWeb.utils.code.byteArray2hexStr(array.filter((v,i) => i>11)));
} else if(type === 'trcToken') {
value = TronWeb.toDecimal('0x'+TronWeb.utils.code.byteArray2hexStr(array));
} else {
value = TronWeb.toDecimal('0x'+TronWeb.utils.code.byteArray2hexStr(array));
}
return {name,type,value};
});
}else{
decodeParams(message,abiCode,function_selector) {
const cutArr = function_selector.match(/(.+)\((.*)\)/);
if(cutArr[2]!==''){
const byteArray = TronWeb.utils.code.hexStr2byteArray(message);
const abi = abiCode.filter(({name})=> name === cutArr[1]);
return abi[0].inputs.map(({name,type},i)=>{
let value;
const array = byteArray.filter((v,index)=>index >=32 * i && index< 32 * (i + 1));
if(type === 'address') {
value = TronWeb.address.fromHex('41'+TronWeb.utils.code.byteArray2hexStr(array.filter((v,i) => i>11)));
} else if(type === 'trcToken') {
value = TronWeb.toDecimal('0x'+TronWeb.utils.code.byteArray2hexStr(array));
} else {
value = TronWeb.toDecimal('0x'+TronWeb.utils.code.byteArray2hexStr(array));
}
return {name,type,value};
});
}else{
return [];
}
return abi[0].inputs.map(({
name,
type
}, i) => {
let value;
const array = byteArray.filter((v, index) => index >= 32 * i && index < 32 * (i + 1));
if (type === 'address') {
value = TronWeb.address.fromHex('41' + TronWeb.utils.code.byteArray2hexStr(array.filter((v, i) => i > 11)));
} else if (type === 'trcToken') {
value = TronWeb.toDecimal('0x' + TronWeb.utils.code.byteArray2hexStr(array));
} else {
value = TronWeb.toDecimal('0x' + TronWeb.utils.code.byteArray2hexStr(array));
}
return {
name,
type,
value
};
});
} else {