-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add RFQ event decoder #1909
Add RFQ event decoder #1909
Conversation
WalkthroughThe new Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 5
Configuration used: CodeRabbit UI
Files selected for processing (1)
- tools/rfqdecoder/main.go (1 hunks)
Additional comments: 1
tools/rfqdecoder/main.go (1)
- 29-32: The parser is initialized with an empty Ethereum address. Confirm that this is intentional and correct.
Please verify that initializing
fastbridge.NewParser
with an empty address is the intended behavior.
tools/rfqdecoder/main.go
Outdated
var rawRequest string | ||
flag.StringVar(&rawRequest, "r", "", "raw request") | ||
flag.Parse() | ||
if rawRequest == "" { | ||
panic("must provide raw request (use -r)") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The program panics if the raw request is not provided. Consider providing a user-friendly error message instead of panicking.
- panic("must provide raw request (use -r)")
+ fmt.Println("Error: Must provide raw request (use -r)")
+ os.Exit(1)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
var rawRequest string | |
flag.StringVar(&rawRequest, "r", "", "raw request") | |
flag.Parse() | |
if rawRequest == "" { | |
panic("must provide raw request (use -r)") | |
} | |
var rawRequest string | |
flag.StringVar(&rawRequest, "r", "", "raw request") | |
flag.Parse() | |
if rawRequest == "" { | |
fmt.Println("Error: Must provide raw request (use -r)") | |
os.Exit(1) | |
} |
tools/rfqdecoder/main.go
Outdated
if rawRequest[:2] == "0x" { | ||
rawRequest = rawRequest[2:] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stripping the "0x" prefix is done without checking the length of rawRequest
. Ensure rawRequest
is long enough before slicing.
+ if len(rawRequest) >= 2 && rawRequest[:2] == "0x" {
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
if rawRequest[:2] == "0x" { | |
rawRequest = rawRequest[2:] | |
} | |
if len(rawRequest) >= 2 && rawRequest[:2] == "0x" { | |
rawRequest = rawRequest[2:] | |
} |
tools/rfqdecoder/main.go
Outdated
log := types.Log{ | ||
Topics: []common.Hash{ | ||
common.HexToHash("0x120ea0364f36cdac7983bcfdd55270ca09d7f9b314a2ebc425a3b01ab1d6403a"), | ||
common.HexToHash("0xb7439e36b5527ac6298c2fd035a286d9df33c5352d96f08c48d4bf06f9df4afd"), | ||
common.HexToHash("0x0000000000000000000000005cf2cc2c71231c23cd5c5a008b9339da33f0fa57"), | ||
}, | ||
Data: requestBytes, | ||
} | ||
_, parsedEvent, ok := parser.ParseEvent(log) | ||
if !ok { | ||
panic("could not parse event") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded hashes in Topics
may not be flexible for different environments or contracts. Consider making these configurable.
Suggest refactoring to allow dynamic topic hashes based on the environment or contract address.
switch event := parsedEvent.(type) { | ||
case *fastbridge.FastBridgeBridgeRequested: | ||
handleBridgeRequested(event) | ||
default: | ||
panic("unknown event") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The switch statement only handles one event type and panics otherwise. This is not scalable for additional event types.
Refactor to support additional event types gracefully without panicking.
func handleBridgeRequested(event *fastbridge.FastBridgeBridgeRequested) { | ||
fmt.Println("BridgeRequested:") | ||
fmt.Printf("TransactionID: %s\n", hexutil.Encode(event.TransactionId[:])) | ||
fmt.Printf("Sender: %s\n", event.Sender.String()) | ||
fmt.Printf("OriginAmount: %s\n", event.OriginAmount.String()) | ||
fmt.Printf("DestAmount: %s\n", event.DestAmount.String()) | ||
fmt.Printf("OriginToken: %s\n", event.OriginToken.String()) | ||
fmt.Printf("DestToken: %s\n", event.DestToken.String()) | ||
fmt.Printf("SendChainGas: %v\n", event.SendChainGas) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handleBridgeRequested
function prints directly to stdout. Consider returning a structured object for better testability and flexibility.
Refactor to return a structured object instead of printing directly, allowing for easier testing and alternative output formats.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1909 +/- ##
===================================================
+ Coverage 51.22931% 51.65117% +0.42186%
===================================================
Files 397 409 +12
Lines 27129 28071 +942
Branches 307 307
===================================================
+ Hits 13898 14499 +601
- Misses 11881 12154 +273
- Partials 1350 1418 +68
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- tools/rfqdecoder/main.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- tools/rfqdecoder/main.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- tools/rfqdecoder/main.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- tools/rfqdecoder/main.go
LGTM @dwasse |
Description
Adds a lightweight CLI for decoding RFQ events.
Pass the
-d
flag to provide the raw event data to the script:Will return:
Metadata
Summary by CodeRabbit