0

I am logging a specific event from a specific contract using nethereum. However, my event emits contract state (enum in solidity). My log processor shows 0 events instead of 2.

Solidity code snippet:

// event

event Transaction(address from, StateType contractState);

// function

    function submitProof
    (string memory clm_num, string memory lin_typ, string memory lin_st, string memory out_rsrv, string memory tot_paid, string memory date_post) public
    {
        ProofData memory inputTransaction;
        inputTransaction.claim_num = clm_num;
        inputTransaction.line_typ = lin_typ;
        inputTransaction.line_status = lin_st;
        inputTransaction.outstanding_rsrv = out_rsrv;
        inputTransaction.total_paid = tot_paid;
        inputTransaction.date_posted = date_post;
        inputTransaction.isDataPresent = true;

        if (contractState == StateType.ZeroState || contractState == StateType.RetrievedState) {
            cedeData = inputTransaction;
            contractState = StateType.CedeState;
        }
        else {
            if (cedeData.isDataPresent && contractState == StateType.CedeState) {
                verifiedData = inputTransaction;
                if (sha256(abi.encode(cedeData)) == sha256(abi.encode(verifiedData)))
                    contractState = StateType.AuditState;
            }
        }
        emit Transaction(msg.sender, contractState);
    }

Nethereum code snippet:

// event class

[Event("Transaction")]

        public class Transaction : IEventDTO
        {
            [Parameter("address", "from", 1, false)]
            public string Sender { get; set; }

            [Parameter("int", "contractState", 2, false)]
            public string ContractState { get; set; }
        }

// logic to log event

Log event using Nethereum

The logs show count 0 where I expect count to be 2. Also how to extract data from log to show that on UI? I couldn't find any extraction logic in Nethereum docs.

4
  • With all due respect, why is the last piece of code given as a screenshot instead of plain text which can be copy/pasted by those who may give you an answer? Apr 27, 2020 at 6:24
  • @goodvibration when i was trying to copy the last piece of code, it wasn't getting formatted properly. So I chose to upload a pic instead. Can you help me with the above query?
    – jatinw
    Apr 27, 2020 at 14:23
  • You can post a properly-formatted code snippet by using a line of 3 ticks at the beginning and a line of 3 ticks at the end. A tick looks like an "upper comma", and it is typically located at the top-left part of your keyboard. Apr 27, 2020 at 14:25
  • @fixanoid need help here
    – jatinw
    Apr 27, 2020 at 14:52

1 Answer 1

0

I believe the problem is you are assuming your StateType enum is represented as int while by the solidity docs enums are mapped to the uint8 type. Consider also the fact that before solidity 0.8 enums could have more than 256 members and were represented by the smallest integer type to cover the whole enum (uint8, uint16, uint32, etc). So the solution might be to change int type to the actual uint8 type representing your enum:

// event class
[Event("Transaction")]
    public class Transaction : IEventDTO
    {
        [Parameter("address", "from", 1, false)]
        public string Sender { get; set; }

        [Parameter("uint8", "contractState", 2, false)]
        public string ContractState { get; set; }
    }

Quick way to verify you expectations is to look into actual event logs of your contract transaction. While your original code is trying to find events with the first topic matching:

// keccak256("Transaction(address,int)")
0x58b12bad91411401e79e45608965d2150f9ccbea8da6766f587ab47feb89b899

the actual event signature should be:

// keccak256("Transaction(address,uint8)")
0xcaa7b1db9c296c18bcdecbb504bdabd1cf43c41dac630ab45f5d1f982fce410e

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.