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
bc4974ec
Unverified
Commit
bc4974ec
authored
Aug 14, 2023
by
Ethen Pociask
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[indexer.client] Lightweight Indexer Client
parent
3a62bccd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
3 deletions
+84
-3
api.go
indexer/api/api.go
+12
-3
client.go
indexer/api/client.go
+72
-0
No files found.
indexer/api/api.go
View file @
bc4974ec
...
...
@@ -2,6 +2,7 @@ package api
import
(
"encoding/json"
"fmt"
"net/http"
"github.com/ethereum-optimism/optimism/indexer/database"
...
...
@@ -9,6 +10,14 @@ import (
"github.com/go-chi/chi/v5"
)
const
(
depositPath
=
"/api/v0/deposits/"
withdrawalPath
=
"/api/v0/withdrawals/"
healthzPath
=
"/healthz"
addressParam
=
"{address:.+}"
)
type
PaginationResponse
struct
{
// TODO type this better
Data
interface
{}
`json:"data"`
...
...
@@ -97,9 +106,9 @@ func NewApi(bv database.BridgeView) *Api {
// these regex are .+ because I wasn't sure what they should be
// don't want a regex for addresses because would prefer to validate the address
// with go-ethereum and throw a friendly error message
r
.
Get
(
"/api/v0/deposits/{address:.+}"
,
api
.
DepositsHandler
)
r
.
Get
(
"/api/v0/withdrawals/{address:.+}"
,
api
.
WithdrawalsHandler
)
r
.
Get
(
"/healthz"
,
api
.
HealthzHandler
)
r
.
Get
(
fmt
.
Sprintf
(
"%s%s"
,
depositPath
,
addressParam
)
,
api
.
DepositsHandler
)
r
.
Get
(
fmt
.
Sprintf
(
"%s%s"
,
withdrawalPath
,
addressParam
)
,
api
.
WithdrawalsHandler
)
r
.
Get
(
healthzPath
,
api
.
HealthzHandler
)
return
api
...
...
indexer/api/client.go
0 → 100644
View file @
bc4974ec
package
api
import
(
"encoding/json"
"fmt"
"net/http"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum-optimism/optimism/indexer/db"
"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
.
DepositWithTransactionHash
,
error
)
{
var
deposits
[]
*
database
.
DepositWithTransactionHash
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
)
(
*
db
.
PaginatedWithdrawals
,
error
)
{
var
deposits
*
db
.
PaginatedWithdrawals
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
}
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