-
Notifications
You must be signed in to change notification settings - Fork 3
fix(rpc): decode EVM logs from tx data + align receipt/nonce fields with cosmos/evm v0.6.0 #292
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
073776d
fix(rpc): decode evm logs from tx data; align receipt fields with cos…
puneet2019 00e8ac4
test(rpc): cover DecodeMsgLogs index-selection; document all-EVM tx i…
puneet2019 d95ff1c
test(rpc): use SafeUint64 in log test helper to clear golangci
puneet2019 abea684
fix(rpc): fill tx/block context in subscription and filter logs
puneet2019 d3230ef
test(rpc): assert expected BlockNumber to drop int64->uint64 cast (go…
puneet2019 256c6ee
style(rpc): drop redundant embedded TxResult selectors (golangci QF1008)
puneet2019 9cefe2d
test(rpc): e2e for EVM log-subscription / getFilterChanges rehydration
puneet2019 6b8ef7b
Merge branch 'main' into fix/rpc-evm-logs
puneet2019 a30fa21
test(rpc): assert receipt fields in GetTransactionReceipt
puneet2019 7a3155d
test(e2e): cover eth_subscribe("logs") WebSocket transport
puneet2019 c8f9c35
ci(e2e): pin actions/setup-go to a commit SHA (semgrep mutable-action…
puneet2019 4302090
test(e2e): assert finalized block context in log-subscription tests
puneet2019 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // Command wslogs exercises the eth_subscribe("logs") WebSocket transport | ||
| // end-to-end. It dials an EVM JSON-RPC WebSocket endpoint, subscribes to the | ||
| // logs of a single contract address, and prints the first matching log as JSON. | ||
| // | ||
| // It exists so the e2e suite can drive rpc/websockets.go subscribeLogs (which | ||
| // rehydrates logs from the finalized block result) over the real WS push path, | ||
| // using only the go-ethereum client that moca already depends on — no external | ||
| // websocket CLI (websocat/wscat) is installed or required. | ||
| // | ||
| // Usage: | ||
| // | ||
| // wslogs <ws-url> <contract-address> [timeoutSeconds] | ||
| // | ||
| // It prints "SUBSCRIBED" to stderr as soon as the subscription is live. Because | ||
| // eth_subscribe is future-only, the caller must emit the log-producing tx only | ||
| // after seeing that line. On the first matching log it writes the log as JSON to | ||
| // stdout and exits 0; on a subscription error, dial failure, or timeout it writes | ||
| // a message to stderr and exits 1. | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "strconv" | ||
| "time" | ||
|
|
||
| ethereum "github.com/ethereum/go-ethereum" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| ethtypes "github.com/ethereum/go-ethereum/core/types" | ||
| "github.com/ethereum/go-ethereum/ethclient" | ||
| ) | ||
|
|
||
| const defaultTimeoutSeconds = 40 | ||
|
|
||
| func main() { | ||
| if err := run(os.Args[1:]); err != nil { | ||
| fmt.Fprintln(os.Stderr, "wslogs:", err) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
|
|
||
| func run(args []string) error { | ||
| if len(args) < 2 { | ||
| return fmt.Errorf("usage: wslogs <ws-url> <contract-address> [timeoutSeconds]") | ||
| } | ||
| wsURL := args[0] | ||
| if !common.IsHexAddress(args[1]) { | ||
| return fmt.Errorf("invalid contract address: %q", args[1]) | ||
| } | ||
| addr := common.HexToAddress(args[1]) | ||
|
|
||
| timeoutSeconds := defaultTimeoutSeconds | ||
| if len(args) >= 3 { | ||
| n, err := strconv.Atoi(args[2]) | ||
| if err != nil || n <= 0 { | ||
| return fmt.Errorf("invalid timeout seconds: %q", args[2]) | ||
| } | ||
| timeoutSeconds = n | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeoutSeconds)*time.Second) | ||
| defer cancel() | ||
|
|
||
| client, err := ethclient.DialContext(ctx, wsURL) | ||
| if err != nil { | ||
| return fmt.Errorf("dial %s: %w", wsURL, err) | ||
| } | ||
| defer client.Close() | ||
|
|
||
| query := ethereum.FilterQuery{Addresses: []common.Address{addr}} | ||
| logs := make(chan ethtypes.Log) | ||
| sub, err := client.SubscribeFilterLogs(ctx, query, logs) | ||
| if err != nil { | ||
| return fmt.Errorf("subscribe filter logs on %s: %w", wsURL, err) | ||
| } | ||
| defer sub.Unsubscribe() | ||
|
|
||
| // The subscription is now live. Signal the caller so it emits the | ||
| // log-producing tx only now — eth_subscribe delivers future logs only. | ||
| fmt.Fprintln(os.Stderr, "SUBSCRIBED") | ||
|
|
||
| select { | ||
| case vLog := <-logs: | ||
| out, err := json.Marshal(vLog) | ||
| if err != nil { | ||
| return fmt.Errorf("marshal log: %w", err) | ||
| } | ||
| fmt.Println(string(out)) | ||
| return nil | ||
| case err := <-sub.Err(): | ||
| if err == nil { | ||
| return fmt.Errorf("subscription closed before any matching log arrived") | ||
| } | ||
| return fmt.Errorf("subscription error: %w", err) | ||
| case <-ctx.Done(): | ||
| return fmt.Errorf("timed out after %ds waiting for a matching log", timeoutSeconds) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.