Skip to content

Commit

Permalink
adding chainID in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Sep 13, 2024
1 parent 105120f commit 4ec267a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
21 changes: 19 additions & 2 deletions abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ import (
"github.com/ethereum/go-ethereum/core/types"
)

var ChainIDS = map[int64]string{
1: "Ethereum",
8453: "Base",
137: "Polygon",
10: "OP",
42161: "Arbitrum",
}

var ABI = `[
{
"type": "function",
Expand Down Expand Up @@ -75,7 +83,7 @@ func init() {
}
}

func handleLog(vLog *types.Log, w *wallet.Wallet, q *uploader.Queue, jackalContract string) {
func handleLog(vLog *types.Log, w *wallet.Wallet, q *uploader.Queue, chainID int64, jackalContract string) {
event := struct {
Sender common.Address
Merkle string
Expand Down Expand Up @@ -127,7 +135,7 @@ func handleLog(vLog *types.Log, w *wallet.Wallet, q *uploader.Queue, jackalContr
ProofInterval: 3600,
ProofType: 0,
MaxProofs: maxProofs,
Note: fmt.Sprintf("{\"memo\":\"Relayed from EVM for %s\"}", evmAddress),
Note: fmt.Sprintf("{\"memo\":\"Relayed from %s for %s\"}", chainRep(chainID), evmAddress),
Expires: abci.Response.LastBlockHeight + ((hours * 60 * 60) / 6),
},
}
Expand Down Expand Up @@ -171,3 +179,12 @@ func handleLog(vLog *types.Log, w *wallet.Wallet, q *uploader.Queue, jackalContr
log.Println(res.RawLog)
log.Println(res.TxHash)
}

func chainRep(id int64) string {
s := ChainIDS[id]
if len(s) == 0 {
return fmt.Sprintf("%d", id)
}

return s
}
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ func main() {
continue
}

bigChainID, err := client.ChainID(context.Background())
if err != nil {
log.Printf("Failed to get the chainID, retrying in 5 seconds: %v", err)
time.Sleep(5 * time.Second)
continue
}
chainID := bigChainID.Int64()

sub, logs, err = subscribeLogs(client, query)
if err != nil {
log.Printf("Failed to subscribe, retrying in 5 seconds: %v", err)
Expand Down Expand Up @@ -112,7 +120,7 @@ func main() {
// Process logs if receipt is available
for _, l := range receipt.Logs {
if l.Address.Hex() == contractAddress.Hex() {
handleLog(l, w, q, jackalContract)
handleLog(l, w, q, chainID, jackalContract)
}
}
} else {
Expand Down

0 comments on commit 4ec267a

Please sign in to comment.