Open
Conversation
5292959 to
41f6a2b
Compare
41f6a2b to
6abaec7
Compare
Contributor
|
I think the fixed code has some logical errors if-else if` stops after first true condition. if txHash != "" {
params["by"] = "hash"
params["value"] = txHash
} else if sequenceIndex != "" { // ← This gets skipped if txHash != ""
params["by"] = "sequence_index" // ← Never runs when both have values
params["value"] = sequenceIndex
}When both parameters have values:
Fixed Code: func (c *HTTPClient) GetTx(txHash, sequenceIndex string) (*TxInfo, error) {
// Check parameters first
if txHash == "" && sequenceIndex == "" {
return nil, fmt.Errorf("must provide either txHash or sequenceIndex")
}
if txHash != "" && sequenceIndex != "" {
return nil, fmt.Errorf("cannot provide both txHash and sequenceIndex")
}
result := &TxInfo{}
params := map[string]any{}
if txHash != "" {
params["by"] = "hash"
params["value"] = txHash
} else {
params["by"] = "sequence_index"
params["value"] = sequenceIndex
}
err := c.getAndParseL2HTTPResponse("api/v1/tx", params, result)
if err != nil {
return nil, err
}
return result, nil
} |
Author
|
@chaoticpunk I've updated the comments and emphasized how to use parameters in the code annotations. I don’t think it’s necessary to enforce a constraint at the code level that only one parameter can be passed. |
33972b5 to
fd1619f
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
AccountsByL1Addressmethod toHTTPClientfor querying account information using an L1 address.GetTxmethod toHTTPClientfor retrieving transaction details by hash or sequence index.