/
parse_eth_tx.go
74 lines (61 loc) · 2.16 KB
/
parse_eth_tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// To compile:
// go build --ldflags '-extldflags "-Wl,--allow-multiple-definition"' -o parse_eth_tx
// Usage:
// ./parse_eth_tx -chainID=14 -ethRPC=wss://alfajores-forno.celo-testnet.org/ws -contractAddr=0x88505117CA88e7dd2eC6EA1E13f0948db2D50D56 -tx=0x20a1e7e491dd82b6b33db0820e88a96b58bac28d65770ea73af80e457745aab1
package main
import (
"context"
"flag"
"log"
"github.com/alephium/wormhole-fork/node/pkg/ethereum"
"github.com/alephium/wormhole-fork/node/pkg/vaa"
ethCommon "github.com/ethereum/go-ethereum/common"
"go.uber.org/zap"
)
var (
flagChainID = flag.Int("chainID", 2, "Wormhole chain ID")
flagEthRPC = flag.String("ethRPC", "http://localhost:8545", "Ethereum JSON-RPC endpoint")
flagContractAddr = flag.String("contractAddr", "0x98f3c9e6E3fAce36bAAd05FE09d375Ef1464288B", "Ethereum contract address")
flagTx = flag.String("tx", "", "Transaction to parse")
)
func main() {
flag.Parse()
if *flagTx == "" {
log.Fatal("No transaction specified")
}
chainID := vaa.ChainID(*flagChainID)
ctx := context.Background()
contractAddr := ethCommon.HexToAddress(*flagContractAddr)
ethConnector, err := ethereum.NewEthereumConnector(ctx, "", *flagEthRPC, contractAddr, zap.L())
if err != nil {
log.Fatalf("dialing eth client failed: %v", err)
}
transactionHash := ethCommon.HexToHash(*flagTx)
block, msgs, err := ethereum.MessageEventsForTransaction(ctx, ethConnector, contractAddr, chainID, transactionHash)
if err != nil {
log.Fatal(err)
}
if len(msgs) == 0 {
log.Fatal("No messages found")
}
for _, k := range msgs {
v := &vaa.VAA{
Version: vaa.SupportedVAAVersion,
GuardianSetIndex: 1,
Signatures: nil,
Timestamp: k.Timestamp,
Nonce: k.Nonce,
EmitterChain: k.EmitterChain,
TargetChain: k.TargetChain,
EmitterAddress: k.EmitterAddress,
Payload: k.Payload,
Sequence: k.Sequence,
ConsistencyLevel: k.ConsistencyLevel,
}
log.Println("------------------------------------------------------")
log.Printf("Block: %d", block)
log.Printf("Message ID: %s", v.MessageID())
log.Printf("Digest: %s", v.HexDigest())
log.Printf("VAA: %+v", v)
}
}