Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
6c03aeba
Unverified
Commit
6c03aeba
authored
Sep 18, 2023
by
Ethen Pociask
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[indexer.client] Client support for paginated withdrawal queries
parent
cf1f0b10
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
4 deletions
+93
-4
api.go
indexer/api/api.go
+4
-2
client.go
indexer/client/client.go
+87
-0
client.go
indexer/node/client.go
+2
-2
No files found.
indexer/api/api.go
View file @
6c03aeba
...
@@ -30,6 +30,8 @@ type Api struct {
...
@@ -30,6 +30,8 @@ type Api struct {
const
(
const
(
MetricsNamespace
=
"op_indexer"
MetricsNamespace
=
"op_indexer"
DepositsPath
=
"/api/v0/deposits/{address:%s}"
WithdrawalsPath
=
"/api/v0/withdrawals/{address:%s}"
)
)
func
chiMetricsMiddleware
(
rec
metrics
.
HTTPRecorder
)
func
(
http
.
Handler
)
http
.
Handler
{
func
chiMetricsMiddleware
(
rec
metrics
.
HTTPRecorder
)
func
(
http
.
Handler
)
http
.
Handler
{
...
@@ -49,8 +51,8 @@ func NewApi(logger log.Logger, bv database.BridgeTransfersView, serverConfig con
...
@@ -49,8 +51,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
(
"/api/v0/deposits/{address:%s}"
,
ethereumAddressRegex
),
h
.
L1DepositsHandler
)
apiRouter
.
Get
(
fmt
.
Sprintf
(
DepositsPath
,
ethereumAddressRegex
),
h
.
L1DepositsHandler
)
apiRouter
.
Get
(
fmt
.
Sprintf
(
"/api/v0/withdrawals/{address:%s}"
,
ethereumAddressRegex
),
h
.
L2WithdrawalsHandler
)
apiRouter
.
Get
(
fmt
.
Sprintf
(
WithdrawalsPath
,
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
}
}
}
...
...
indexer/client/client.go
0 → 100644
View file @
6c03aeba
package
client
import
(
"fmt"
"io/ioutil"
"net/http"
"encoding/json"
"github.com/ethereum-optimism/optimism/indexer/api"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum-optimism/optimism/indexer/node"
)
const
(
urlParams
=
"?cursor=%s&limit=%d"
defaultPagingLimit
=
100
)
// Config ... Indexer client config struct
type
Config
struct
{
PaginationLimit
int
URL
string
}
// IndexerClient ... Indexer client struct
type
IndexerClient
struct
{
cfg
*
Config
c
*
http
.
Client
m
node
.
Metricer
}
// DialIndexerClient ... Dials indexer API URL
func
DialIndexerClient
(
cfg
*
Config
,
m
node
.
Metricer
)
(
*
IndexerClient
,
error
)
{
if
cfg
.
PaginationLimit
==
0
{
cfg
.
PaginationLimit
=
defaultPagingLimit
}
c
:=
&
http
.
Client
{}
return
&
IndexerClient
{
cfg
:
cfg
,
c
:
c
,
m
:
m
},
nil
}
// GetAllWithdrawalsByAddress ... Gets all withdrawals by address
func
(
ic
*
IndexerClient
)
GetAllWithdrawalsByAddress
(
l2Address
string
)
([]
database
.
L2BridgeWithdrawalWithTransactionHashes
,
error
)
{
var
withdrawals
[]
database
.
L2BridgeWithdrawalWithTransactionHashes
cursor
:=
""
for
{
wResponse
,
err
:=
ic
.
GetWithdrawalsByAddress
(
l2Address
,
cursor
)
if
err
!=
nil
{
return
nil
,
err
}
withdrawals
=
append
(
withdrawals
,
wResponse
.
Withdrawals
...
)
if
!
wResponse
.
HasNextPage
{
break
}
cursor
=
wResponse
.
Cursor
}
return
withdrawals
,
nil
}
// GetWithdrawalsByAddress ... Gets a withdrawal response object provided an L2 address
func
(
ic
*
IndexerClient
)
GetWithdrawalsByAddress
(
l2Address
string
,
cursor
string
)
(
*
database
.
L2BridgeWithdrawalsResponse
,
error
)
{
var
wResponse
*
database
.
L2BridgeWithdrawalsResponse
endpoint
:=
fmt
.
Sprintf
(
ic
.
cfg
.
URL
+
api
.
WithdrawalsPath
+
urlParams
,
l2Address
,
cursor
,
ic
.
cfg
.
PaginationLimit
)
resp
,
err
:=
ic
.
c
.
Get
(
endpoint
)
if
err
!=
nil
{
return
nil
,
err
}
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to read response body: %w"
,
err
)
}
if
err
:=
json
.
Unmarshal
(
body
,
&
wResponse
);
err
!=
nil
{
return
nil
,
err
}
return
wResponse
,
nil
}
indexer/node/client.go
View file @
6c03aeba
...
@@ -48,7 +48,7 @@ func DialEthClient(rpcUrl string, metrics Metricer) (EthClient, error) {
...
@@ -48,7 +48,7 @@ func DialEthClient(rpcUrl string, metrics Metricer) (EthClient, error) {
return
nil
,
err
return
nil
,
err
}
}
client
:=
&
client
{
rpc
:
n
ewRPC
(
rpcClient
,
metrics
)}
client
:=
&
client
{
rpc
:
N
ewRPC
(
rpcClient
,
metrics
)}
return
client
,
nil
return
client
,
nil
}
}
...
@@ -207,7 +207,7 @@ type rpcClient struct {
...
@@ -207,7 +207,7 @@ type rpcClient struct {
metrics
Metricer
metrics
Metricer
}
}
func
n
ewRPC
(
client
*
rpc
.
Client
,
metrics
Metricer
)
RPC
{
func
N
ewRPC
(
client
*
rpc
.
Client
,
metrics
Metricer
)
RPC
{
return
&
rpcClient
{
client
,
metrics
}
return
&
rpcClient
{
client
,
metrics
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment