How to use the web3/lib/solidity/coder.js.decodeParams function in web3

To help you get started, we’ve selected a few web3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RequestNetwork / Request_SmartContracts / test / requestEthereumAccept.js View on Github external
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 = SolidityCoder.decodeParams(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;
}
github RequestNetwork / RequestVesting / test / withdrawVesting.js View on Github external
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 = SolidityCoder.decodeParams(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;
}
github RequestNetwork / Request_SmartContracts / test / requestEthereumDecline.js View on Github external
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 = SolidityCoder.decodeParams(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;
}
github RequestNetwork / Request_SmartContracts / test / requestEthereumCancel.js View on Github external
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 = SolidityCoder.decodeParams(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;
}
github RequestNetwork / Request_SmartContracts / test / requestEthereumWithdraw.js View on Github external
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 = SolidityCoder.decodeParams(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;
}
github trufflesuite / truffle-core / lib / testing / testrunner.js View on Github external
logs.forEach(function(log) {
      var event = self.known_events[log.topics[0]];

      if (event == null) {
        return;
      }

      var types = event.abi_entry.inputs.map(function(input) {
        return input.indexed == true ? null : input.type;
      }).filter(function(type) {
        return type != null;
      });
      var values = SolidityCoder.decodeParams(types, log.data.replace("0x", ""));
      var index = 0;

      var line = "    " + event.abi_entry.name + "(";
      line += event.abi_entry.inputs.map(function(input) {
        var value;
        if (input.indexed == true) {
          value = "";
        } else {
          value = values[index];
          index += 1;
        }

        return input.name + ": " + value.toString();
      }).join(", ");
      line += ")";
      self.logger.log(line);
github sc-forks / solidity-coverage / lib / coverageMap.js View on Github external
generate(events, pathPrefix) {
    for (let idx = 0; idx < events.length; idx++) {
      const event = JSON.parse(events[idx]);

      if (event.topics.filter(t => this.lineTopics.indexOf(t) >= 0).length > 0) {
        const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
        const canonicalContractPath = data[0];
        this.coverage[canonicalContractPath].l[data[1].toNumber()] += 1;
      } else if (event.topics.filter(t => this.functionTopics.indexOf(t) >= 0).length > 0) {
        const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
        const canonicalContractPath = data[0];
        this.coverage[canonicalContractPath].f[data[1].toNumber()] += 1;
      } else if (event.topics.filter(t => this.branchTopics.indexOf(t) >= 0).length > 0) {
        const data = SolidityCoder.decodeParams(['string', 'uint256', 'uint256'], event.data.replace('0x', ''));
        const canonicalContractPath = data[0];
        this.coverage[canonicalContractPath].b[data[1].toNumber()][data[2].toNumber()] += 1;
      } else if (event.topics.filter(t => this.statementTopics.indexOf(t) >= 0).length > 0) {
        const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
        const canonicalContractPath = data[0];
        this.coverage[canonicalContractPath].s[data[1].toNumber()] += 1;
      } else if (event.topics.filter(t => this.assertPreTopics.indexOf(t) >= 0).length > 0) {
        const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
        const canonicalContractPath = data[0];
        this.assertCoverage[canonicalContractPath][data[1].toNumber()].preEvents += 1;
      } else if (event.topics.filter(t => this.assertPostTopics.indexOf(t) >= 0).length > 0) {
        const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
        const canonicalContractPath = data[0];
        this.assertCoverage[canonicalContractPath][data[1].toNumber()].postEvents += 1;
      }
    }