loom-js icon indicating copy to clipboard operation
loom-js copied to clipboard

allEvents fails to capture both events emitted by solidity contract function

Open timothywangdev opened this issue 6 years ago • 7 comments

"loom-js": "^1.30.2" solidity ^0.4.23 latest loom installed from

curl https://raw.githubusercontent.com/loomnetwork/loom-sdk-documentation/master/scripts/get_loom.sh | sh
this.repSysInstance.events.allEvents().on('data', this.onEvent)

This one does not catch both events (Delegate, UpdateDelegation) emitted from a function. Only the first event emiited (UpdateDelegation) is caught.

We have to add the following code to make it work

this.repSysInstance.events.Delegate({},(error, event) => { ... }) 

Related to #82

It turned out using the above code did not work as well, we did a little experiment as follows:

  • solidity code
event Test(uint num);
function test(uint k) external {
        for (uint i = 0; i < k; i++) {
            emit Test(i);
        }
    }
  • truffle test script
let rv = await contract.test(2)
console.log(rv)
  • Contract event listener js script:
this.contract.events.Test({fromBlock: 0},
                                        (error, event) => {
                                          console.log(event)
                                        })

Results

Only one event received in our event listener yet 2 events showed up in the test script log:

{ tx: '0x32c257bb576102c8e1cfde8c96efb2cce36aebe14250ff4edf271b599a93e5bb',
  receipt: 
   { transactionHash: '0x32c257bb576102c8e1cfde8c96efb2cce36aebe14250ff4edf271b599a93e5bb',
     transactionIndex: 1,
     blockHash: '0x77338f1bd79aadf62bea957e7a6bd807a22dc5e6',
     blockNumber: 242421,
     contractAddress: '0x36d2b3675607f48e03dd3fdde3e34e5ad7d74397',
     gasUsed: 0,
     cumulativeGasUsed: 0,
     logs: [ [Object], [Object] ],
     status: '0x1' },
  logs: 
   [ { logIndex: 0,
       address: '0x36d2b3675607f48e03dd3fdde3e34e5ad7d74397',
       blockHash: '0x77338f1bd79aadf62bea957e7a6bd807a22dc5e6',
       blockNumber: 242421,
       transactionHash: '0x32c257bb576102c8e1cfde8c96efb2cce36aebe14250ff4edf271b599a93e5bb',
       transactionIndex: 1,
       type: 'mined',
       event: 'Test',
       args: [Object] },
     { logIndex: 1,
       address: '0x36d2b3675607f48e03dd3fdde3e34e5ad7d74397',
       blockHash: '0x77338f1bd79aadf62bea957e7a6bd807a22dc5e6',
       blockNumber: 242421,
       transactionHash: '0x32c257bb576102c8e1cfde8c96efb2cce36aebe14250ff4edf271b599a93e5bb',
       transactionIndex: 1,
       type: 'mined',
       event: 'Test',
       args: [Object] } ] }

timothywangdev avatar Nov 08 '18 18:11 timothywangdev

@timothywangdev what is the version of the loom sdk, loom version

eduardonunesp avatar Nov 09 '18 12:11 eduardonunesp

@eduardonunesp loom: 1.0.0+b478 "loom-truffle-provider": "^0.8.0" "web3": "^1.0.0-beta.33"

timothywangdev avatar Nov 09 '18 19:11 timothywangdev

Hello, I'm having the same issue. This function is really suspicious in LoomProvider.ts:

private _onWebSocketMessage(msgEvent: IChainEventArgs) {
    if (msgEvent.data && msgEvent.id !== '0') {
      log(`Socket message arrived ${JSON.stringify(msgEvent)}`)
      this.notificationCallbacks.forEach((callback: Function) => {
        const JSONRPCResult = {
          jsonrpc: '2.0',
          method: 'eth_subscription',
          params: {
            subscription: msgEvent.id,
            result: {
              transactionHash: bytesToHexAddrLC(msgEvent.transactionHashBytes),
              logIndex: '0x0',
              transactionIndex: '0x0',
              blockHash: '0x0',
              blockNumber: '0x0',
              address: msgEvent.contractAddress.local.toString(),
              type: 'mined',
              data: bytesToHexAddrLC(msgEvent.data),
              topics: msgEvent.topics
            }
          }
        }

        callback(JSONRPCResult)
      })
    }
  }

It also hardcodes blockNumber: '0x0' which leads to unexpected behaviour.

such avatar Nov 23 '18 10:11 such

Can we get some updates on the fix? Thanks. @eduardonunesp

timothywangdev avatar Nov 26 '18 18:11 timothywangdev

hey @timothywangdev we are heads down for our upcoming plasmachain launch, this is likely 2 weeks off. I'm sorry we are a bit swamped. Can you give us some background on what you are trying to build?

mattkanwisher avatar Nov 26 '18 19:11 mattkanwisher

Hi @timothywangdev thanks for your report, could you please confirm if the test add on this PR https://github.com/loomnetwork/loom-js/pull/194 is compatible with your issue

eduardonunesp avatar Jan 17 '19 14:01 eduardonunesp

https://github.com/loomnetwork/loomchain/issues/600

eduardonunesp avatar Sep 11 '19 00:09 eduardonunesp