Skip to content

Add API Implementation to HTTP Client#22

Open
taobig wants to merge 5 commits intoelliottech:mainfrom
taobig:feature/add_api_implement
Open

Add API Implementation to HTTP Client#22
taobig wants to merge 5 commits intoelliottech:mainfrom
taobig:feature/add_api_implement

Conversation

@taobig
Copy link

@taobig taobig commented Oct 12, 2025

  • Added AccountsByL1Address method to HTTPClient for querying account information using an L1 address.
  • Added GetTx method to HTTPClient for retrieving transaction details by hash or sequence index.

@taobig taobig force-pushed the feature/add_api_implement branch from 5292959 to 41f6a2b Compare October 12, 2025 13:31
@taobig taobig force-pushed the feature/add_api_implement branch from 41f6a2b to 6abaec7 Compare October 12, 2025 13:31
@chaoticpunk
Copy link
Contributor

https://github.com/elliottech/lighter-go/pull/22/files#diff-58375ba15a8f77629e996225e7d166bbb86d8af147fe1fdd9e0c8a8b2df77774R138-R154

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:

  • Only txHash is used
  • sequenceIndex is completely ignored

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
}

@taobig
Copy link
Author

taobig commented Oct 13, 2025

@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.

@taobig taobig force-pushed the feature/add_api_implement branch from 33972b5 to fd1619f Compare October 13, 2025 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants