Commit 7199ad85 authored by Ethen Pociask's avatar Ethen Pociask

[indexer.client] Working withdrawal lookup client

parent 6c03aeba
...@@ -30,8 +30,9 @@ type Api struct { ...@@ -30,8 +30,9 @@ type Api struct {
const ( const (
MetricsNamespace = "op_indexer" MetricsNamespace = "op_indexer"
DepositsPath = "/api/v0/deposits/{address:%s}" addressParam = "{address:%s}"
WithdrawalsPath = "/api/v0/withdrawals/{address:%s}" DepositsPath = "/api/v0/deposits/"
WithdrawalsPath = "/api/v0/withdrawals/"
) )
func chiMetricsMiddleware(rec metrics.HTTPRecorder) func(http.Handler) http.Handler { func chiMetricsMiddleware(rec metrics.HTTPRecorder) func(http.Handler) http.Handler {
...@@ -51,8 +52,8 @@ func NewApi(logger log.Logger, bv database.BridgeTransfersView, serverConfig con ...@@ -51,8 +52,8 @@ func NewApi(logger log.Logger, bv database.BridgeTransfersView, serverConfig con
apiRouter.Use(middleware.Recoverer) apiRouter.Use(middleware.Recoverer)
apiRouter.Use(middleware.Heartbeat("/healthz")) apiRouter.Use(middleware.Heartbeat("/healthz"))
apiRouter.Get(fmt.Sprintf(DepositsPath, ethereumAddressRegex), h.L1DepositsHandler) apiRouter.Get(fmt.Sprintf(DepositsPath + addressParam, ethereumAddressRegex), h.L1DepositsHandler)
apiRouter.Get(fmt.Sprintf(WithdrawalsPath, ethereumAddressRegex), h.L2WithdrawalsHandler) apiRouter.Get(fmt.Sprintf(WithdrawalsPath + addressParam, ethereumAddressRegex), h.L2WithdrawalsHandler)
return &Api{log: logger, Router: apiRouter, metricsRegistry: mr, serverConfig: serverConfig, metricsConfig: metricsConfig} return &Api{log: logger, Router: apiRouter, metricsRegistry: mr, serverConfig: serverConfig, metricsConfig: metricsConfig}
} }
......
...@@ -68,7 +68,7 @@ func (ic *IndexerClient) GetAllWithdrawalsByAddress(l2Address string) ([]databas ...@@ -68,7 +68,7 @@ func (ic *IndexerClient) GetAllWithdrawalsByAddress(l2Address string) ([]databas
func (ic *IndexerClient) GetWithdrawalsByAddress(l2Address string, cursor string) (*database.L2BridgeWithdrawalsResponse, error) { func (ic *IndexerClient) GetWithdrawalsByAddress(l2Address string, cursor string) (*database.L2BridgeWithdrawalsResponse, error) {
var wResponse *database.L2BridgeWithdrawalsResponse var wResponse *database.L2BridgeWithdrawalsResponse
endpoint := fmt.Sprintf(ic.cfg.URL+api.WithdrawalsPath+urlParams, l2Address, cursor, ic.cfg.PaginationLimit) endpoint := fmt.Sprintf(ic.cfg.URL+api.WithdrawalsPath+l2Address+urlParams, cursor, ic.cfg.PaginationLimit)
resp, err := ic.c.Get(endpoint) resp, err := ic.c.Get(endpoint)
if err != nil { if err != nil {
return nil, err return nil, err
......
package client
import "testing"
func Test_Client(t *testing.T) {
cfg := &Config{
PaginationLimit: 100,
URL: "https://localhost:8080",
}
ic, err := DialIndexerClient(cfg, nil)
if err != nil {
t.Fatal(err)
}
// Get all withdrawals by address
withdrawals, err := ic.GetAllWithdrawalsByAddress("0xC64c9c88F28072F9DAa60d371acc08cB5FDb9952")
if err != nil {
t.Fatal(err)
}
t.Logf("withdrawals: %+v", withdrawals)
}
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"context" "context"
"os" "os"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/opio" "github.com/ethereum-optimism/optimism/op-service/opio"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
...@@ -22,6 +23,7 @@ func main() { ...@@ -22,6 +23,7 @@ func main() {
cancel() cancel()
}() }()
oplog.SetupDefaults()
app := newCli(GitCommit, GitDate) app := newCli(GitCommit, GitDate)
if err := app.RunContext(ctx, os.Args); err != nil { if err := app.RunContext(ctx, os.Args); err != nil {
log.Error("application failed", "err", err) log.Error("application failed", "err", err)
......
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