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
fe32ae5c
Unverified
Commit
fe32ae5c
authored
Nov 02, 2023
by
Hamdi Allam
Committed by
GitHub
Nov 02, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7945 from epociask/indexer.api.add_withdrawal_hash
fix(indexer.api): Add msg hash to withdrawal response
parents
e1c5bb1a
72872892
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
122 additions
and
47 deletions
+122
-47
generated.ts
indexer/api-ts/generated.ts
+3
-3
api_test.go
indexer/api/api_test.go
+2
-2
models.go
indexer/api/models/models.go
+52
-12
models_test.go
indexer/api/models/models_test.go
+64
-0
withdrawals.go
indexer/api/routes/withdrawals.go
+1
-30
No files found.
indexer/api-ts/generated.ts
View file @
fe32ae5c
...
...
@@ -34,12 +34,12 @@ export interface WithdrawalItem {
from
:
string
;
to
:
string
;
transactionHash
:
string
;
m
essageHash
:
string
;
crossDomainM
essageHash
:
string
;
timestamp
:
number
/* uint64 */
;
l2BlockHash
:
string
;
amount
:
string
;
proofTransaction
Hash
:
string
;
claimTransaction
Hash
:
string
;
l1ProvenTx
Hash
:
string
;
l1FinalizedTx
Hash
:
string
;
l1TokenAddress
:
string
;
l2TokenAddress
:
string
;
}
...
...
indexer/api/api_test.go
View file @
fe32ae5c
...
...
@@ -149,8 +149,8 @@ func TestL2BridgeWithdrawalsByAddressHandler(t *testing.T) {
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
To
,
withdrawal
.
Tx
.
ToAddress
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
TransactionHash
,
common
.
HexToHash
(
"0x789"
)
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
Amount
,
withdrawal
.
Tx
.
Amount
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
ProofTransaction
Hash
,
common
.
HexToHash
(
"0x123"
)
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
ClaimTransaction
Hash
,
common
.
HexToHash
(
"0x123"
)
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
L1ProvenTx
Hash
,
common
.
HexToHash
(
"0x123"
)
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
L1FinalizedTx
Hash
,
common
.
HexToHash
(
"0x123"
)
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
L1TokenAddress
,
withdrawal
.
TokenPair
.
RemoteTokenAddress
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
L2TokenAddress
,
withdrawal
.
TokenPair
.
LocalTokenAddress
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
Timestamp
,
withdrawal
.
Tx
.
Timestamp
)
...
...
indexer/api/models/models.go
View file @
fe32ae5c
package
models
import
(
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum/go-ethereum/common"
)
// DepositItem ... Deposit item model for API responses
type
DepositItem
struct
{
Guid
string
`json:"guid"`
...
...
@@ -23,18 +28,18 @@ type DepositResponse struct {
// WithdrawalItem ... Data model for API JSON response
type
WithdrawalItem
struct
{
Guid
string
`json:"guid"`
From
string
`json:"from"`
To
string
`json:"to"`
TransactionHash
string
`json:"transactionHash"`
MessageHash
string
`json:"m
essageHash"`
Timestamp
uint64
`json:"timestamp"`
L2BlockHash
string
`json:"l2BlockHash"`
Amount
string
`json:"amount"`
ProofTransactionHash
string
`json:"proofTransaction
Hash"`
ClaimTransactionHash
string
`json:"claimTransaction
Hash"`
L1TokenAddress
string
`json:"l1TokenAddress"`
L2TokenAddress
string
`json:"l2TokenAddress"`
Guid
string
`json:"guid"`
From
string
`json:"from"`
To
string
`json:"to"`
TransactionHash
string
`json:"transactionHash"`
CrossDomainMessageHash
string
`json:"crossDomainM
essageHash"`
Timestamp
uint64
`json:"timestamp"`
L2BlockHash
string
`json:"l2BlockHash"`
Amount
string
`json:"amount"`
L1ProvenTxHash
string
`json:"l1ProvenTx
Hash"`
L1FinalizedTxHash
string
`json:"l1FinalizedTx
Hash"`
L1TokenAddress
string
`json:"l1TokenAddress"`
L2TokenAddress
string
`json:"l2TokenAddress"`
}
// WithdrawalResponse ... Data model for API JSON response
...
...
@@ -43,3 +48,38 @@ type WithdrawalResponse struct {
HasNextPage
bool
`json:"hasNextPage"`
Items
[]
WithdrawalItem
`json:"items"`
}
// FIXME make a pure function that returns a struct instead of newWithdrawalResponse
// newWithdrawalResponse ... Converts a database.L2BridgeWithdrawalsResponse to an api.WithdrawalResponse
func
CreateWithdrawalResponse
(
withdrawals
*
database
.
L2BridgeWithdrawalsResponse
)
WithdrawalResponse
{
items
:=
make
([]
WithdrawalItem
,
len
(
withdrawals
.
Withdrawals
))
for
i
,
withdrawal
:=
range
withdrawals
.
Withdrawals
{
cdh
:=
withdrawal
.
L2BridgeWithdrawal
.
CrossDomainMessageHash
if
cdh
==
nil
{
// Zero value indicates that the withdrawal didn't have a cross domain message
cdh
=
&
common
.
Hash
{
0
}
}
item
:=
WithdrawalItem
{
Guid
:
withdrawal
.
L2BridgeWithdrawal
.
TransactionWithdrawalHash
.
String
(),
L2BlockHash
:
withdrawal
.
L2BlockHash
.
String
(),
Timestamp
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
Timestamp
,
From
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
FromAddress
.
String
(),
To
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
ToAddress
.
String
(),
TransactionHash
:
withdrawal
.
L2TransactionHash
.
String
(),
Amount
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
Amount
.
String
(),
CrossDomainMessageHash
:
cdh
.
String
(),
L1ProvenTxHash
:
withdrawal
.
ProvenL1TransactionHash
.
String
(),
L1FinalizedTxHash
:
withdrawal
.
FinalizedL1TransactionHash
.
String
(),
L1TokenAddress
:
withdrawal
.
L2BridgeWithdrawal
.
TokenPair
.
RemoteTokenAddress
.
String
(),
L2TokenAddress
:
withdrawal
.
L2BridgeWithdrawal
.
TokenPair
.
LocalTokenAddress
.
String
(),
}
items
[
i
]
=
item
}
return
WithdrawalResponse
{
Cursor
:
withdrawals
.
Cursor
,
HasNextPage
:
withdrawals
.
HasNextPage
,
Items
:
items
,
}
}
indexer/api/models/models_test.go
0 → 100644
View file @
fe32ae5c
package
models_test
import
(
"fmt"
"reflect"
"testing"
"github.com/ethereum-optimism/optimism/indexer/api/models"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
func
TestCreateWithdrawal
(
t
*
testing
.
T
)
{
// (1) Create a dummy database response object
cdh
:=
common
.
HexToHash
(
"0x2"
)
dbWithdrawals
:=
&
database
.
L2BridgeWithdrawalsResponse
{
Withdrawals
:
[]
database
.
L2BridgeWithdrawalWithTransactionHashes
{
{
L2BridgeWithdrawal
:
database
.
L2BridgeWithdrawal
{
TransactionWithdrawalHash
:
common
.
HexToHash
(
"0x1"
),
BridgeTransfer
:
database
.
BridgeTransfer
{
CrossDomainMessageHash
:
&
cdh
,
Tx
:
database
.
Transaction
{
FromAddress
:
common
.
HexToAddress
(
"0x3"
),
ToAddress
:
common
.
HexToAddress
(
"0x4"
),
Timestamp
:
5
,
},
TokenPair
:
database
.
TokenPair
{
LocalTokenAddress
:
common
.
HexToAddress
(
"0x6"
),
RemoteTokenAddress
:
common
.
HexToAddress
(
"0x7"
),
},
},
},
},
},
}
// (2) Create and validate response object
response
:=
models
.
CreateWithdrawalResponse
(
dbWithdrawals
)
require
.
NotEmpty
(
t
,
response
.
Items
)
require
.
Len
(
t
,
response
.
Items
,
1
)
// (3) Use reflection to check that all fields in WithdrawalItem are populated correctly
item
:=
response
.
Items
[
0
]
structType
:=
reflect
.
TypeOf
(
item
)
structVal
:=
reflect
.
ValueOf
(
item
)
fieldNum
:=
structVal
.
NumField
()
for
i
:=
0
;
i
<
fieldNum
;
i
++
{
field
:=
structVal
.
Field
(
i
)
fieldName
:=
structType
.
Field
(
i
)
.
Name
isSet
:=
field
.
IsValid
()
&&
!
field
.
IsZero
()
require
.
True
(
t
,
isSet
,
fmt
.
Sprintf
(
"%s in not set"
,
fieldName
))
}
}
indexer/api/routes/withdrawals.go
View file @
fe32ae5c
...
...
@@ -4,38 +4,9 @@ import (
"net/http"
"github.com/ethereum-optimism/optimism/indexer/api/models"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/go-chi/chi/v5"
)
// FIXME make a pure function that returns a struct instead of newWithdrawalResponse
// newWithdrawalResponse ... Converts a database.L2BridgeWithdrawalsResponse to an api.WithdrawalResponse
func
newWithdrawalResponse
(
withdrawals
*
database
.
L2BridgeWithdrawalsResponse
)
models
.
WithdrawalResponse
{
items
:=
make
([]
models
.
WithdrawalItem
,
len
(
withdrawals
.
Withdrawals
))
for
i
,
withdrawal
:=
range
withdrawals
.
Withdrawals
{
item
:=
models
.
WithdrawalItem
{
Guid
:
withdrawal
.
L2BridgeWithdrawal
.
TransactionWithdrawalHash
.
String
(),
L2BlockHash
:
withdrawal
.
L2BlockHash
.
String
(),
Timestamp
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
Timestamp
,
From
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
FromAddress
.
String
(),
To
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
ToAddress
.
String
(),
TransactionHash
:
withdrawal
.
L2TransactionHash
.
String
(),
Amount
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
Amount
.
String
(),
ProofTransactionHash
:
withdrawal
.
ProvenL1TransactionHash
.
String
(),
ClaimTransactionHash
:
withdrawal
.
FinalizedL1TransactionHash
.
String
(),
L1TokenAddress
:
withdrawal
.
L2BridgeWithdrawal
.
TokenPair
.
RemoteTokenAddress
.
String
(),
L2TokenAddress
:
withdrawal
.
L2BridgeWithdrawal
.
TokenPair
.
LocalTokenAddress
.
String
(),
}
items
[
i
]
=
item
}
return
models
.
WithdrawalResponse
{
Cursor
:
withdrawals
.
Cursor
,
HasNextPage
:
withdrawals
.
HasNextPage
,
Items
:
items
,
}
}
// L2WithdrawalsHandler ... Handles /api/v0/withdrawals/{address} GET requests
func
(
h
Routes
)
L2WithdrawalsHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
addressValue
:=
chi
.
URLParam
(
r
,
"address"
)
...
...
@@ -69,7 +40,7 @@ func (h Routes) L2WithdrawalsHandler(w http.ResponseWriter, r *http.Request) {
h
.
logger
.
Error
(
"Unable to read withdrawals from DB"
,
"err"
,
err
.
Error
())
return
}
response
:=
new
WithdrawalResponse
(
withdrawals
)
response
:=
models
.
Create
WithdrawalResponse
(
withdrawals
)
err
=
jsonResponse
(
w
,
response
,
http
.
StatusOK
)
if
err
!=
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