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
f988b4e9
Commit
f988b4e9
authored
Jun 02, 2023
by
Hamdi Allam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
latest gorm tag changes
parent
819e591b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
13 deletions
+18
-13
blocks.go
indexer/database/blocks.go
+15
-9
bridge.go
indexer/database/bridge.go
+3
-4
No files found.
indexer/database/blocks.go
View file @
f988b4e9
...
...
@@ -2,6 +2,7 @@ package database
import
(
"database/sql"
"errors"
"math/big"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -15,7 +16,7 @@ import (
*/
type
BlockHeader
struct
{
Hash
common
.
Hash
`gorm:"serializer:json"`
Hash
common
.
Hash
`gorm:"
primaryKey;
serializer:json"`
ParentHash
common
.
Hash
`gorm:"serializer:json"`
Number
pgtype
.
Numeric
Timestamp
uint64
...
...
@@ -30,16 +31,16 @@ type L2BlockHeader struct {
// Marked when the proposed output is finalized on L1.
// All bedrock blocks will have `LegacyStateBatchIndex == NULL`
L1BlockHash
*
common
.
Hash
L1BlockHash
*
common
.
Hash
`gorm:"serializer:json"`
LegacyStateBatchIndex
sql
.
NullInt64
}
type
LegacyStateBatch
struct
{
Index
uint64
Root
common
.
Hash
Index
uint64
`gorm:"primaryKey"`
Root
common
.
Hash
`gorm:"serializer:json"`
Size
uint64
PrevTotal
uint64
L1BlockHash
common
.
Hash
L1BlockHash
common
.
Hash
`gorm:"serializer:json"`
}
type
BlocksView
interface
{
...
...
@@ -95,6 +96,8 @@ func (db *blocksDB) StoreLegacyStateBatch(stateBatch *LegacyStateBatch) error {
result
=
db
.
gorm
.
Where
(
"number BETWEEN ? AND ?"
,
&
startHeight
,
&
endHeight
)
.
Find
(
&
l2Headers
)
if
result
.
Error
!=
nil
{
return
result
.
Error
}
else
if
result
.
RowsAffected
!=
int64
(
stateBatch
.
Size
)
{
return
errors
.
New
(
"state batch size exceeds number of indexed l2 blocks"
)
}
for
_
,
header
:=
range
l2Headers
{
...
...
@@ -135,11 +138,14 @@ func (db *blocksDB) LatestL2BlockHeight() (*big.Int, error) {
func
(
db
*
blocksDB
)
MarkFinalizedL1RootForL2Block
(
l2Root
,
l1Root
common
.
Hash
)
error
{
var
l2Header
L2BlockHeader
result
:=
db
.
gorm
.
First
(
&
l2Header
,
"hash = ?"
,
l2Root
)
if
result
.
Error
==
nil
{
l2Header
.
L1BlockHash
=
&
l1Root
db
.
gorm
.
Save
(
&
l2Header
)
l2Header
.
Hash
=
l2Root
// set the primary key
result
:=
db
.
gorm
.
First
(
&
l2Header
)
if
result
.
Error
!=
nil
{
return
result
.
Error
}
l2Header
.
L1BlockHash
=
&
l1Root
result
=
db
.
gorm
.
Save
(
&
l2Header
)
return
result
.
Error
}
indexer/database/bridge.go
View file @
f988b4e9
...
...
@@ -25,7 +25,7 @@ type TokenPair struct {
}
type
Deposit
struct
{
GUID
string
GUID
string
`gorm:"primaryKey"`
InitiatedL1EventGUID
string
Tx
Transaction
`gorm:"embedded"`
...
...
@@ -38,7 +38,7 @@ type DepositWithTransactionHash struct {
}
type
Withdrawal
struct
{
GUID
string
GUID
string
`gorm:"primaryKey"`
InitiatedL2EventGUID
string
WithdrawalHash
common
.
Hash
`gorm:"serializer:json"`
...
...
@@ -92,11 +92,10 @@ func (db *bridgeDB) StoreDeposits(deposits []*Deposit) error {
func
(
db
*
bridgeDB
)
DepositsByAddress
(
address
common
.
Address
)
([]
*
DepositWithTransactionHash
,
error
)
{
// validate this query
depositsQuery
:=
db
.
gorm
.
Table
(
"deposits"
)
.
Where
(
"from_address = ?"
,
address
)
.
Select
(
"deposits.*"
)
depositsQuery
:=
db
.
gorm
.
Table
(
"deposits"
)
.
Where
(
&
Transaction
{
FromAddress
:
address
}
)
joinQuery
:=
depositsQuery
.
Joins
(
"left join l1_contract_events transaction_hash as l1_transaction_hash ON deposit.initiated_l1_event_guid = l1_contract_events.guid"
)
deposits
:=
[]
DepositWithTransactionHash
{}
result
:=
joinQuery
.
Scan
(
&
deposits
)
if
result
.
Error
!=
nil
{
return
nil
,
result
.
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