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
a6657fd5
Unverified
Commit
a6657fd5
authored
Sep 25, 2023
by
Ethen Pociask
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[indexer.client] Updated json response logic
parent
f43c24a8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
11 deletions
+14
-11
common.go
indexer/api/routes/common.go
+5
-7
deposits.go
indexer/api/routes/deposits.go
+4
-1
withdrawals.go
indexer/api/routes/withdrawals.go
+5
-3
No files found.
indexer/api/routes/common.go
View file @
a6657fd5
...
@@ -3,8 +3,6 @@ package routes
...
@@ -3,8 +3,6 @@ package routes
import
(
import
(
"encoding/json"
"encoding/json"
"net/http"
"net/http"
"github.com/ethereum/go-ethereum/log"
)
)
const
(
const
(
...
@@ -15,20 +13,20 @@ const (
...
@@ -15,20 +13,20 @@ const (
)
)
// jsonResponse ... Marshals and writes a JSON response provided arbitrary data
// jsonResponse ... Marshals and writes a JSON response provided arbitrary data
func
jsonResponse
(
w
http
.
ResponseWriter
,
logger
log
.
Logger
,
data
interface
{},
statusCode
int
)
{
func
jsonResponse
(
w
http
.
ResponseWriter
,
data
interface
{},
statusCode
int
)
error
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
jsonData
,
err
:=
json
.
Marshal
(
data
)
jsonData
,
err
:=
json
.
Marshal
(
data
)
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
InternalServerError
,
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
InternalServerError
,
http
.
StatusInternalServerError
)
logger
.
Error
(
"Failed to marshal JSON: %v"
,
err
)
return
err
return
}
}
w
.
WriteHeader
(
statusCode
)
w
.
WriteHeader
(
statusCode
)
_
,
err
=
w
.
Write
(
jsonData
)
_
,
err
=
w
.
Write
(
jsonData
)
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
InternalServerError
,
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
InternalServerError
,
http
.
StatusInternalServerError
)
logger
.
Error
(
"Failed to write JSON data"
,
err
)
return
err
return
}
}
return
nil
}
}
indexer/api/routes/deposits.go
View file @
a6657fd5
...
@@ -78,5 +78,8 @@ func (h Routes) L1DepositsHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -78,5 +78,8 @@ func (h Routes) L1DepositsHandler(w http.ResponseWriter, r *http.Request) {
response
:=
newDepositResponse
(
deposits
)
response
:=
newDepositResponse
(
deposits
)
jsonResponse
(
w
,
h
.
logger
,
response
,
http
.
StatusOK
)
err
=
jsonResponse
(
w
,
response
,
http
.
StatusOK
)
if
err
!=
nil
{
h
.
logger
.
Error
(
"Error writing response"
,
"err"
,
err
)
}
}
}
indexer/api/routes/withdrawals.go
View file @
a6657fd5
...
@@ -71,11 +71,13 @@ func (h Routes) L2WithdrawalsHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -71,11 +71,13 @@ func (h Routes) L2WithdrawalsHandler(w http.ResponseWriter, r *http.Request) {
withdrawals
,
err
:=
h
.
view
.
L2BridgeWithdrawalsByAddress
(
address
,
cursor
,
limit
)
withdrawals
,
err
:=
h
.
view
.
L2BridgeWithdrawalsByAddress
(
address
,
cursor
,
limit
)
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
"Internal server error reading withdrawals"
,
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
"Internal server error reading withdrawals"
,
http
.
StatusInternalServerError
)
h
.
logger
.
Error
(
"Unable to read withdrawals from DB"
)
h
.
logger
.
Error
(
"Unable to read withdrawals from DB"
,
"err"
,
err
.
Error
())
h
.
logger
.
Error
(
err
.
Error
())
return
return
}
}
response
:=
newWithdrawalResponse
(
withdrawals
)
response
:=
newWithdrawalResponse
(
withdrawals
)
jsonResponse
(
w
,
h
.
logger
,
response
,
http
.
StatusOK
)
err
=
jsonResponse
(
w
,
response
,
http
.
StatusOK
)
if
err
!=
nil
{
h
.
logger
.
Error
(
"Error writing response"
,
"err"
,
err
.
Error
())
}
}
}
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