Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] process log from another contract #43

Open
everdreamsoft opened this issue Jul 17, 2019 · 0 comments
Open

[Question] process log from another contract #43

everdreamsoft opened this issue Jul 17, 2019 · 0 comments

Comments

@everdreamsoft
Copy link

Hello !

I'm trying to register events triggered by a contract to another contract. Basically it would like to register ERC721 transfer generated by a linked contract

 public function processLog(FilterChange $filterChange) {

if ($filterChange->address->hexVal() !== $this->contractAddress) {
            return null;
       }

 if (is_array($filterChange->topics)) {
            $topic = $filterChange->topics[0]->hexVal();
            if (isset($this->events[$topic])) { //todo investigate here
                $transaction = $this->eth->eth_getTransactionByHash($filterChange->transactionHash);
                // We have a relevant event.
                $event = new EmittedEvent($this->events[$topic], $filterChange, $transaction);
                // Process onEventName handler.
                if (method_exists($this, $event->getHandler())) {
                    call_user_func([$this, $event->getHandler()], $event);
                }
                return $event;
            }
        }
        return null;
    }

I changed this method to inject tracked contracts list on order to delegate the call process log

This way

  public function processLog(FilterChange $filterChange, $otherTrackedContracts = null) {

        if ($filterChange->address->hexVal() !== $this->contractAddress) {

            if (isset($otherTrackedContracts[$filterChange->address->hexVal()])){
                $matchingContract = $otherTrackedContracts[$filterChange->address->hexVal()];
                return $matchingContract->processLog($filterChange);

            }
            return null;
        }

        if (is_array($filterChange->topics)) {
            $topic = $filterChange->topics[0]->hexVal();
            if (isset($this->events[$topic])) { //todo investigate here
                $transaction = $this->eth->eth_getTransactionByHash($filterChange->transactionHash);
                // We have a relevant event.
                $event = new EmittedEvent($this->events[$topic], $filterChange, $transaction);
                // Process onEventName handler.
                if (method_exists($this, $event->getHandler())) {
                    call_user_func([$this, $event->getHandler()], $event);
                }
                return $event;
            }
        }
        return null;
    }

Is there a better way ? Running this code I'm getting an issue later processing other events while parsing the ABI.
Not sure it's related but I wonder if this this hack is the cause.

Thanks
Shaban

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants