Skip to content

Commit

Permalink
fixes abi error caused by attempting to parse Proxy events (celo-org#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecps authored May 5, 2020
1 parent 35eb696 commit 83ae8dd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
11 changes: 6 additions & 5 deletions analyzer/txtracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/celo-org/rosetta/celo/client/debug"
"github.com/celo-org/rosetta/celo/contract"
"github.com/celo-org/rosetta/db"
"github.com/celo-org/rosetta/internal/utils"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
)
Expand Down Expand Up @@ -185,14 +186,14 @@ func (tr *Tracer) TxLockedGoldTransfers(blockHeader *types.Header, tx *types.Tra
return nil, fmt.Errorf("can't get governanceAddress: %w", err)
}

transfers := make([]Operation, 0, len(receipt.Logs))
for _, eventLog := range receipt.Logs {
logs := utils.RemoveProxyLogs(receipt.Logs)

transfers := make([]Operation, 0, len(logs))
for _, eventLog := range logs {
if eventLog.Address == electionAddr {
eventName, eventRaw, ok, err := election.TryParseLog(*eventLog)
if err != nil {
tr.logger.Warn("Ignoring event: Error parsing election event", "err", err, "eventId", eventLog.Topics[0].Hex(), "tx", receipt.TxHash.Hex())
// return nil, fmt.Errorf("can't parse Election event: %w", err)
continue
return nil, fmt.Errorf("can't parse Election event: %w", err)
}
if !ok {
continue
Expand Down
27 changes: 26 additions & 1 deletion internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@

package utils

import "errors"
import (
"errors"

"github.com/ethereum/go-ethereum/core/types"
)

var ErrNotImplemented = errors.New("Not implemented")

var ProxyEventIds = []string{
"ab64f92ab780ecbf4f3866f57cee465ff36c89450dcce20237ca7a8d81fb7d13", // ImplementationSet(address)
"50146d0e3c60aa1d17a70635b05494f864e86144a2201275021014fbf08bafe2", // OwnerSet(address)
}

// RemoveProxyLogs filters out logs from Proxy events and returns a list
// of Logs that are safe to Parse using the implementation contract's abi.
func RemoveProxyLogs(logs []*types.Log) []*types.Log {
safeLogs := make([]*types.Log, 0, len(logs))
for _, log := range logs {
if len(log.Topics) > 0 {
for _, id := range ProxyEventIds {
if log.Topics[0].Hex() != id {
safeLogs = append(safeLogs, log)
}
}
}
}
return safeLogs
}

0 comments on commit 83ae8dd

Please sign in to comment.