ethereum-php icon indicating copy to clipboard operation
ethereum-php copied to clipboard

Fixes for event log and event handling

Open ynohtna92 opened this issue 4 years ago • 6 comments

These commits fix the following issues:

Ethereum.php does not handle eth_getLogs at all

Fixed by added an OR with the handling of eth_getFilterChanges as they return the same JSON-RPC array.

Event.php does not handle dynamic bytes properly

Fixed by correctly applying offsets for dynamic bytes. Decoded in accordance with https://docs.soliditylang.org/en/latest/abi-spec.html

SmartContract.php does not allow for processLog to disable event calls

Added bool to allow developers to disable event calls if they want to handle $event differently.

ynohtna92 avatar May 23 '21 06:05 ynohtna92

Sorry it takes so long. Currently redoing my CI so I hope I can continuer with this soon.

digitaldonkey avatar Jun 14 '21 08:06 digitaldonkey

image

I can see there is a eth_getLogs method (which does not necessarily mean that it is working well..). The approach to fix it is a little stange, as it is one of the generated functions. Can you provide test data for your case so that I may be able to write a unit test for it?

Can you do a micro-change, so that the new circleci pipeline gets triggered and we get a run with unit tests.

digitaldonkey avatar Jun 15 '21 18:06 digitaldonkey

// Using the Binance Smart Chain
$web3 = new Ethereum('https://bsc-dataseed4.binance.org/');

// ABI - https://bscscan.com/address/0x22663e2bbf6524dbbe1fb14a84eb689ca65ef367#code
$contractMeta = json_decode(file_get_contents(APP . '/config/contract_bsc.json'));
$contracts["Contract"] = new NFT(
    $contractMeta->abi,
    $contractMeta->address,
    $web3
);

$logs = $web3->eth_getLogs(new Filter(new EthBlockParam(7858017), new EthBlockParam(7858342), new EthBytes("0x22663e2bbf6524dbbe1fb14a84eb689ca65ef367"), null));

foreach($logs as $filterChange) {
    // Fails here
    $event = $contracts["Contract"]->processLog($filterChange, false);
    var_dump($event);
}

I found that it was failing on processing the logs after obtaining them because the eth_getLogs was not handled in your original code.

ynohtna92 avatar Jun 16 '21 09:06 ynohtna92

Sorry. Forgot to mention, that you need to pull the master branch to get the new CircleCi config

digitaldonkey avatar Jun 16 '21 10:06 digitaldonkey

Sorry. Forgot to mention, that you need to pull the master branch to get the new CircleCi config

Rebased.

ynohtna92 avatar Jun 16 '21 11:06 ynohtna92

Jay. It doesn't break anything :D I'm so happy to have a pipeline again. But I will need to understand what the difference between the original approach (screenshot) and your solution ist. It had been a while. Thank you for the test data. This will help.

digitaldonkey avatar Jun 16 '21 11:06 digitaldonkey