Commit 8d67ffb1 authored by Ethen Pociask's avatar Ethen Pociask

[indexer.docs] Remove client and redundant submodule

parent 9a954c5d
package api
import (
"encoding/json"
"fmt"
"net/http"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum/go-ethereum/common"
)
// Client defines the methods for interfacing with the indexer API.
type Client struct {
url string
c *http.Client
}
// NewClient creates a client that uses the given RPC client.
func NewClient(c *http.Client, url string) *Client {
return &Client{
url: url,
c: c,
}
}
// Close closes the underlying RPC connection.
func (ec *Client) Close() {
ec.c.CloseIdleConnections()
}
// GetDepositsByAddress returns all associated (L1->L2) deposits for a provided L1 address.
func (ic *Client) GetDepositsByAddress(addr common.Address) ([]*database.L1BridgeDepositWithTransactionHashes, error) {
var deposits []*database.L1BridgeDepositWithTransactionHashes
resp, err := ic.c.Get(ic.url + depositPath + addr.Hex())
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
if err := json.NewDecoder(resp.Body).Decode(&deposits); err != nil {
return nil, err
}
return deposits, nil
}
// GetWithdrawalsByAddress returns all associated (L2->L1) withdrawals for a provided L2 address.
func (ic *Client) GetWithdrawalsByAddress(addr common.Address) ([]*database.L2BridgeWithdrawalWithTransactionHashes, error) {
var withdrawals []*database.L2BridgeWithdrawalWithTransactionHashes
resp, err := ic.c.Get(ic.url + depositPath + addr.Hex())
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
if err := json.NewDecoder(resp.Body).Decode(&withdrawals); err != nil {
return nil, err
}
return withdrawals, nil
}
......@@ -280,10 +280,4 @@ func TestE2EBridgeTransfersL2ToL1MessagePasserReceive(t *testing.T) {
require.NoError(t, err)
require.Equal(t, proveReceipt.TxHash, aliceWithdrawals[0].ProvenL1TransactionHash)
require.Equal(t, finalizeReceipt.TxHash, aliceWithdrawals[0].FinalizedL1TransactionHash)
// (3) Test API query for L2ToL1MessagePasser withdrawals
respWithdrawals, err := testSuite.Client.GetWithdrawalsByAddress(aliceAddr)
require.NoError(t, err)
require.Equal(t, proveReceipt.TxHash, respWithdrawals[0].ProvenL1TransactionHash)
require.Equal(t, finalizeReceipt.TxHash, respWithdrawals[0].FinalizedL1TransactionHash)
}
Subproject commit 74cfb77e308dd188d2f58864aaf44963ae6b88b1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment