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
c81da8fa
Commit
c81da8fa
authored
Sep 13, 2023
by
Will Cory
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚧
feat(indexer): Implement hardcoded tx
parent
acde10db
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
147 deletions
+84
-147
api_test.go
indexer/api/api_test.go
+39
-3
common.go
indexer/api/routes/common.go
+0
-26
deposits.go
indexer/api/routes/deposits.go
+22
-47
withdrawals.go
indexer/api/routes/withdrawals.go
+23
-71
No files found.
indexer/api/api_test.go
View file @
c81da8fa
package
api
import
(
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/ethereum-optimism/optimism/indexer/api/routes"
"github.com/ethereum-optimism/optimism/indexer/config"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// MockBridgeTransfersView mocks the BridgeTransfersView interface
...
...
@@ -70,6 +73,8 @@ func (mbv *MockBridgeTransfersView) L1BridgeDepositsByAddress(address common.Add
{
L1BridgeDeposit
:
deposit
,
L1TransactionHash
:
common
.
HexToHash
(
"0x123"
),
L2TransactionHash
:
common
.
HexToHash
(
"0x555"
),
L1BlockHash
:
common
.
HexToHash
(
"0x456"
),
},
},
},
nil
...
...
@@ -81,6 +86,9 @@ func (mbv *MockBridgeTransfersView) L2BridgeWithdrawalsByAddress(address common.
{
L2BridgeWithdrawal
:
withdrawal
,
L2TransactionHash
:
common
.
HexToHash
(
"0x789"
),
L2BlockHash
:
common
.
HexToHash
(
"0x456"
),
ProvenL1TransactionHash
:
common
.
HexToHash
(
"0x123"
),
FinalizedL1TransactionHash
:
common
.
HexToHash
(
"0x123"
),
},
},
},
nil
...
...
@@ -107,6 +115,17 @@ func TestL1BridgeDepositsHandler(t *testing.T) {
api
.
Router
.
ServeHTTP
(
responseRecorder
,
request
)
assert
.
Equal
(
t
,
http
.
StatusOK
,
responseRecorder
.
Code
)
var
resp
routes
.
DepositResponse
err
=
json
.
Unmarshal
(
responseRecorder
.
Body
.
Bytes
(),
&
resp
)
assert
.
Nil
(
t
,
err
)
require
.
Len
(
t
,
resp
.
Items
,
1
)
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
L1BlockHash
,
common
.
HexToHash
(
"0x456"
)
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
L1TxHash
,
common
.
HexToHash
(
"0x123"
)
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
Timestamp
,
deposit
.
Tx
.
Timestamp
)
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
L2TxHash
,
common
.
HexToHash
(
"555"
)
.
String
())
}
func
TestL2BridgeWithdrawalsByAddressHandler
(
t
*
testing
.
T
)
{
...
...
@@ -118,5 +137,22 @@ func TestL2BridgeWithdrawalsByAddressHandler(t *testing.T) {
responseRecorder
:=
httptest
.
NewRecorder
()
api
.
Router
.
ServeHTTP
(
responseRecorder
,
request
)
assert
.
Equal
(
t
,
http
.
StatusOK
,
responseRecorder
.
Code
)
var
resp
routes
.
WithdrawalResponse
err
=
json
.
Unmarshal
(
responseRecorder
.
Body
.
Bytes
(),
&
resp
)
assert
.
Nil
(
t
,
err
)
require
.
Len
(
t
,
resp
.
Items
,
1
)
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
Guid
,
withdrawal
.
TransactionWithdrawalHash
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
L2BlockHash
,
common
.
HexToHash
(
"0x456"
)
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
From
,
withdrawal
.
Tx
.
FromAddress
.
String
())
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
]
.
ProofTransactionHash
,
common
.
HexToHash
(
"0x123"
)
.
String
())
assert
.
Equal
(
t
,
resp
.
Items
[
0
]
.
ClaimTransactionHash
,
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/routes/common.go
View file @
c81da8fa
...
...
@@ -7,32 +7,6 @@ import (
"github.com/ethereum/go-ethereum/log"
)
// lazily typing numbers fixme
type
Transaction
struct
{
Timestamp
uint64
`json:"timestamp"`
TransactionHash
string
`json:"transactionHash"`
}
type
Block
struct
{
BlockNumber
int64
`json:"number"`
BlockHash
string
`json:"hash"`
// ParentBlockHash string `json:"parentHash"`
}
type
Extensions
struct
{
OptimismBridgeAddress
string
`json:"OptimismBridgeAddress"`
}
type
TokenInfo
struct
{
// TODO lazily typing ints go through them all with fine tooth comb once api is up
ChainId
int
`json:"chainId"`
Address
string
`json:"address"`
Name
string
`json:"name"`
Symbol
string
`json:"symbol"`
Decimals
int
`json:"decimals"`
Extensions
Extensions
`json:"extensions"`
}
func
jsonResponse
(
w
http
.
ResponseWriter
,
logger
log
.
Logger
,
data
interface
{},
statusCode
int
)
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
jsonData
,
err
:=
json
.
Marshal
(
data
)
...
...
indexer/api/routes/deposits.go
View file @
c81da8fa
...
...
@@ -13,13 +13,13 @@ type DepositItem struct {
Guid
string
`json:"guid"`
From
string
`json:"from"`
To
string
`json:"to"`
// TODO could consider OriginTx to be more generic to handling L2 to L2 deposits
// this seems more clear today though
Tx
Transaction
`json:"Tx
"`
Block
Block
`json:"Block"`
Timestamp
uint64
`json:"timestamp"`
L1TxHash
string
`json:"L1TxHash"`
L2TxHash
string
`json:"L2TxHash
"`
L1BlockHash
string
`json:"Block"`
Amount
string
`json:"amount"`
L1Token
TokenInfo
`json:"l1Token"`
L2Token
TokenInfo
`json:"l2Token"`
L1Token
Address
string
`json:"l1Token"`
L2Token
Address
string
`json:"l2Token"`
}
type
DepositResponse
struct
{
...
...
@@ -28,47 +28,22 @@ type DepositResponse struct {
Items
[]
DepositItem
`json:"items"`
}
// TODO this is original spec but maybe include the l2 block info too for the relayed tx
// FIXME make a pure function that returns a struct instead of newWithdrawalResponse
func
newDepositResponse
(
deposits
*
database
.
L1BridgeDepositsResponse
)
DepositResponse
{
items
:=
make
([]
DepositItem
,
len
(
deposits
.
Deposits
))
for
_
,
deposit
:=
range
deposits
.
Deposits
{
for
i
,
deposit
:=
range
deposits
.
Deposits
{
item
:=
DepositItem
{
Guid
:
deposit
.
L1BridgeDeposit
.
TransactionSourceHash
.
String
(),
Block
:
Block
{
BlockNumber
:
420420
,
// TODO
BlockHash
:
"0x420"
,
// TODO
},
Tx
:
Transaction
{
TransactionHash
:
"0x420"
,
// TODO
L1BlockHash
:
deposit
.
L1BlockHash
.
String
(),
Timestamp
:
deposit
.
L1BridgeDeposit
.
Tx
.
Timestamp
,
},
L1TxHash
:
deposit
.
L1TransactionHash
.
String
(),
L2TxHash
:
deposit
.
L2TransactionHash
.
String
(),
From
:
deposit
.
L1BridgeDeposit
.
Tx
.
FromAddress
.
String
(),
To
:
deposit
.
L1BridgeDeposit
.
Tx
.
ToAddress
.
String
(),
Amount
:
deposit
.
L1BridgeDeposit
.
Tx
.
Amount
.
String
(),
L1Token
:
TokenInfo
{
ChainId
:
1
,
Address
:
deposit
.
L1BridgeDeposit
.
TokenPair
.
LocalTokenAddress
.
String
(),
Name
:
"TODO"
,
Symbol
:
"TODO"
,
Decimals
:
420
,
Extensions
:
Extensions
{
OptimismBridgeAddress
:
"0x420"
,
// TODO
},
},
L2Token
:
TokenInfo
{
ChainId
:
10
,
Address
:
deposit
.
L1BridgeDeposit
.
TokenPair
.
RemoteTokenAddress
.
String
(),
Name
:
"TODO"
,
Symbol
:
"TODO"
,
Decimals
:
420
,
Extensions
:
Extensions
{
OptimismBridgeAddress
:
"0x420"
,
// TODO
},
},
L1TokenAddress
:
deposit
.
L1BridgeDeposit
.
TokenPair
.
LocalTokenAddress
.
String
(),
L2TokenAddress
:
deposit
.
L1BridgeDeposit
.
TokenPair
.
RemoteTokenAddress
.
String
(),
}
items
=
append
(
items
,
item
)
items
[
i
]
=
item
}
return
DepositResponse
{
...
...
indexer/api/routes/withdrawals.go
View file @
c81da8fa
...
...
@@ -9,31 +9,18 @@ import (
"github.com/go-chi/chi/v5"
)
type
Proof
struct
{
TransactionHash
string
`json:"transactionHash"`
BlockTimestamp
uint64
`json:"blockTimestamp"`
BlockNumber
int
`json:"blockNumber"`
}
type
Claim
struct
{
TransactionHash
string
`json:"transactionHash"`
BlockTimestamp
uint64
`json:"blockTimestamp"`
BlockNumber
int
`json:"blockNumber"`
}
type
WithdrawalItem
struct
{
Guid
string
`json:"guid"`
Tx
Transaction
`json:"Tx"`
Block
Block
`json:"Block"`
From
string
`json:"from"`
To
string
`json:"to"`
TransactionHash
string
`json:"transactionHash"`
Timestamp
uint64
`json:"timestamp"`
L2BlockHash
string
`json:"l2BlockHash"`
Amount
string
`json:"amount"`
Proof
Proof
`json:"proof"`
Claim
Claim
`json:"claim"`
WithdrawalState
string
`json:"withdrawalState"`
L1Token
TokenInfo
`json:"l1Token"`
L2Token
TokenInfo
`json:"l2Token"`
ProofTransactionHash
string
`json:"proof"`
ClaimTransactionHash
string
`json:"claim"`
L1TokenAddress
string
`json:"l1Token"`
L2TokenAddress
string
`json:"l2Token"`
}
type
WithdrawalResponse
struct
{
...
...
@@ -45,55 +32,20 @@ type WithdrawalResponse struct {
// FIXME make a pure function that returns a struct instead of newWithdrawalResponse
func
newWithdrawalResponse
(
withdrawals
*
database
.
L2BridgeWithdrawalsResponse
)
WithdrawalResponse
{
items
:=
make
([]
WithdrawalItem
,
len
(
withdrawals
.
Withdrawals
))
for
_
,
withdrawal
:=
range
withdrawals
.
Withdrawals
{
for
i
,
withdrawal
:=
range
withdrawals
.
Withdrawals
{
item
:=
WithdrawalItem
{
Guid
:
withdrawal
.
L2BridgeWithdrawal
.
TransactionWithdrawalHash
.
String
(),
Block
:
Block
{
BlockNumber
:
420420
,
// TODO
BlockHash
:
"0x420"
,
// TODO
},
Tx
:
Transaction
{
TransactionHash
:
"0x420"
,
// TODO
Timestamp
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
Timestamp
,
},
L2BlockHash
:
withdrawal
.
L2BlockHash
.
String
(),
From
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
FromAddress
.
String
(),
To
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
ToAddress
.
String
(),
TransactionHash
:
withdrawal
.
L2TransactionHash
.
String
(),
Amount
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
Amount
.
String
(),
Proof
:
Proof
{
TransactionHash
:
withdrawal
.
ProvenL1TransactionHash
.
String
(),
BlockTimestamp
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
Timestamp
,
BlockNumber
:
420
,
// TODO Block struct instead
},
Claim
:
Claim
{
TransactionHash
:
withdrawal
.
FinalizedL1TransactionHash
.
String
(),
BlockTimestamp
:
withdrawal
.
L2BridgeWithdrawal
.
Tx
.
Timestamp
,
// Using L2 timestamp for now, might need adjustment
BlockNumber
:
420
,
// TODO block struct
},
WithdrawalState
:
"COMPLETE"
,
// TODO
L1Token
:
TokenInfo
{
ChainId
:
1
,
Address
:
withdrawal
.
L2BridgeWithdrawal
.
TokenPair
.
RemoteTokenAddress
.
String
(),
Name
:
"Example"
,
// TODO
Symbol
:
"EXAMPLE"
,
// TODO
Decimals
:
18
,
// TODO
Extensions
:
Extensions
{
OptimismBridgeAddress
:
"0x636Af16bf2f682dD3109e60102b8E1A089FedAa8"
,
},
},
L2Token
:
TokenInfo
{
ChainId
:
10
,
Address
:
withdrawal
.
L2BridgeWithdrawal
.
TokenPair
.
LocalTokenAddress
.
String
(),
Name
:
"Example"
,
// TODO
Symbol
:
"EXAMPLE"
,
// TODO
Decimals
:
18
,
// TODO
Extensions
:
Extensions
{
OptimismBridgeAddress
:
"0x36Af16bf2f682dD3109e60102b8E1A089FedAa86"
,
},
},
ProofTransactionHash
:
withdrawal
.
ProvenL1TransactionHash
.
String
(),
ClaimTransactionHash
:
withdrawal
.
FinalizedL1TransactionHash
.
String
(),
L1TokenAddress
:
withdrawal
.
L2BridgeWithdrawal
.
TokenPair
.
RemoteTokenAddress
.
String
(),
L2TokenAddress
:
withdrawal
.
L2BridgeWithdrawal
.
TokenPair
.
LocalTokenAddress
.
String
(),
}
items
=
append
(
items
,
item
)
items
[
i
]
=
item
}
return
WithdrawalResponse
{
...
...
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