0

If I index a parameter or any number of parameters, some of the return values get swapped and/or corrupted.. I am not sure if any one else has ever seen this behavior before.

Non-indexed Event:

event ReportedFraud(
        uint256 fraudID,
        address bank,
        string accountNumber,
        string routingNumber,
        uint256 amount,
        uint256 fromID,
        uint256 time
    );

Correct Values Returned:

accountNumber: "123"
amount: "1"
bank: "0x10674178eAf18F06785b76fF689dcfa5175b098C"
fraudID: "1"
fromID: "0"
routingNumber: "456"
time: "1551236055"

Indexed Event:

event ReportedFraud(
    uint256 indexed fraudID,
    address bank,
    string accountNumber,
    string routingNumber,
    uint256 indexed amount,
    uint256 indexed fromID,
    uint256 time
);

Corrupted/Swapped Values Returned:

accountNumber: "123"
amount: "1"
bank: "0x10674178eAf18F06785b76fF689dcfa5175b098C"
fraudID: "51119459429513360686315515087327623333677688524449823590986145582251952174345"
fromID: "50000"
routingNumber: "456"
time: "1551236055"

Here is the web3js code calling the event from the blockchain.

fraudListen = () => {
  this.KYCinstance.events.ReportedFraud({ fromBlock:0 }, 
    (error, event) => {
      if (error) {
        console.log(error);
      }
      else {
        values = event.returnValues;

        var fraudID = document.createTextNode("Fraud ID: " + values.fraudID);
        var bank = document.createTextNode("Bank: " + values.bank);
        var accountNumber = document.createTextNode("Account Number: " + values.accountNumber);
        var routingNumber = document.createTextNode("Routing Number: " + values.routingNumber);
        var amount = document.createTextNode("Amount: " + values.amount);
        var fromID = document.createTextNode("From_ID: " + values.fromID)
        var time = document.createTextNode("Time: " + utils.timeConverter(values.fromID));

        var elements = [fraudID, bank, accountNumber, routingNumber, amount, fromID, time];

        fraudEvents = document.getElementById("fraudEvents");
        var divItem = document.createElement('div');
        divItem.setAttribute('class', "fraudEvent")

        for (var i = 0; i < elements.length; i++) {
          var listItem = document.createElement('ul');
          listItem.appendChild(elements[i]);
          divItem.appendChild(listItem);
        }

        fraudEvents.insertBefore(divItem, fraudEvents.firstChild);
        var linebreak = document.createElement('br');
        fraudEvents.insertBefore(linebreak, divItem);
      }
    });

  console.log('now listening for events');
}
  • "get swapped and/or corrupted" where (i.e., what tool are you using in order to display them)??? Most likely, you need to let that tool know of the fact that you've indexed them, since this is essentially an API-change in the perspective of this tool. Alternatively, whoever implemented this tool failed to handle both cases properly. In either case, we'll need to know what tool it is before saying anything further. – goodvibration 6 hours ago
  • web3js, nowhere in the documentation does it say that we need to account for indexed parameters when setting a simple listen event. its my understanding that indexed isn't supposed to be a hinderance and i've never encountered this before – 0TTT0 6 hours ago
  • Oh, so it's you who implemented the tool (via web3.js). Well, when you change the event prototype, you change the ABI of the contract. Have you used the new ABI for redeploying your new contract? – goodvibration 6 hours ago
  • Yes, I've been using Truffle as a development tool and redeploying when changes are made, the code reads directly from the Truffle artifacts ie(build) – 0TTT0 6 hours ago
  • Truffle is 5.0.0 . Solc is 0.5.0 – 0TTT0 6 hours ago

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.