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
bf1cc8f4
Unverified
Commit
bf1cc8f4
authored
Mar 03, 2022
by
Conner Fromknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: restructure Deposit and CompletedTelport w/ struct embeddings
parent
cdb61a31
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
90 deletions
+120
-90
small-deers-shout.md
.changeset/small-deers-shout.md
+5
-0
db.go
go/teleportr/db/db.go
+19
-18
db_test.go
go/teleportr/db/db_test.go
+88
-66
driver.go
go/teleportr/drivers/disburser/driver.go
+8
-6
No files found.
.changeset/small-deers-shout.md
0 → 100644
View file @
bf1cc8f4
---
'
@eth-optimism/teleportr'
:
patch
---
Restructure Deposit and CompletedTeleport to use struct embeddings
go/teleportr/db/db.go
View file @
bf1cc8f4
...
...
@@ -21,17 +21,6 @@ var (
ErrUnknownDeposit
=
errors
.
New
(
"unknown deposit"
)
)
// Deposit represents an event emitted from the TeleportrDeposit contract on L1,
// along with additional info about the tx that generated the event.
type
Deposit
struct
{
ID
uint64
TxnHash
common
.
Hash
BlockNumber
uint64
BlockTimestamp
time
.
Time
Address
common
.
Address
Amount
*
big
.
Int
}
// ConfirmationInfo holds metadata about a tx on either the L1 or L2 chain.
type
ConfirmationInfo
struct
{
TxnHash
common
.
Hash
...
...
@@ -39,15 +28,27 @@ type ConfirmationInfo struct {
BlockTimestamp
time
.
Time
}
// Deposit represents an event emitted from the TeleportrDeposit contract on L1,
// along with additional info about the tx that generated the event.
type
Deposit
struct
{
ID
uint64
Address
common
.
Address
Amount
*
big
.
Int
ConfirmationInfo
}
type
Disbursement
struct
{
Success
bool
ConfirmationInfo
}
// CompletedTeleport represents an L1 deposit that has been disbursed on L2. The
// struct also hold info about the L1 and L2 txns involved.
type
CompletedTeleport
struct
{
ID
uint64
Address
common
.
Address
Amount
*
big
.
Int
Success
bool
Deposit
ConfirmationInfo
Disbursement
ConfirmationInfo
Deposit
Disbursement
Disbursement
}
const
createDepositsTable
=
`
...
...
@@ -401,7 +402,7 @@ func (d *Database) CompletedTeleports() ([]CompletedTeleport, error) {
&
teleport
.
ID
,
&
addressStr
,
&
amountStr
,
&
teleport
.
Success
,
&
teleport
.
Disbursement
.
Success
,
&
depTxnHashStr
,
&
teleport
.
Deposit
.
BlockNumber
,
&
teleport
.
Deposit
.
BlockTimestamp
,
...
...
go/teleportr/db/db_test.go
View file @
bf1cc8f4
...
...
@@ -91,12 +91,14 @@ func TestUpsertDeposits(t *testing.T) {
defer
d
.
Close
()
deposit1
:=
db
.
Deposit
{
ID
:
1
,
TxnHash
:
common
.
HexToHash
(
"0xff01"
),
BlockNumber
:
1
,
BlockTimestamp
:
testTimestamp
,
Address
:
common
.
HexToAddress
(
"0xaa01"
),
Amount
:
big
.
NewInt
(
1
),
ID
:
1
,
Address
:
common
.
HexToAddress
(
"0xaa01"
),
Amount
:
big
.
NewInt
(
1
),
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
common
.
HexToHash
(
"0xff01"
),
BlockNumber
:
1
,
BlockTimestamp
:
testTimestamp
,
},
}
err
:=
d
.
UpsertDeposits
([]
db
.
Deposit
{
deposit1
},
0
)
...
...
@@ -107,12 +109,14 @@ func TestUpsertDeposits(t *testing.T) {
require
.
Equal
(
t
,
deposits
,
[]
db
.
Deposit
{
deposit1
})
deposit2
:=
db
.
Deposit
{
ID
:
1
,
TxnHash
:
common
.
HexToHash
(
"0xff02"
),
BlockNumber
:
2
,
BlockTimestamp
:
testTimestamp
,
Address
:
common
.
HexToAddress
(
"0xaa02"
),
Amount
:
big
.
NewInt
(
2
),
ID
:
1
,
Address
:
common
.
HexToAddress
(
"0xaa02"
),
Amount
:
big
.
NewInt
(
2
),
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
common
.
HexToHash
(
"0xff02"
),
BlockNumber
:
2
,
BlockTimestamp
:
testTimestamp
,
},
}
err
=
d
.
UpsertDeposits
([]
db
.
Deposit
{
deposit2
},
0
)
...
...
@@ -160,12 +164,14 @@ func TestUpsertDepositsRecordsLastProcessedBlock(t *testing.T) {
// Insert real deposit in block 3 with last processed at 4.
deposit
:=
db
.
Deposit
{
ID
:
0
,
TxnHash
:
common
.
HexToHash
(
"0xff03"
),
BlockNumber
:
3
,
BlockTimestamp
:
testTimestamp
,
Address
:
common
.
HexToAddress
(
"0xaa03"
),
Amount
:
big
.
NewInt
(
3
),
ID
:
0
,
Address
:
common
.
HexToAddress
(
"0xaa03"
),
Amount
:
big
.
NewInt
(
3
),
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
common
.
HexToHash
(
"0xff03"
),
BlockNumber
:
3
,
BlockTimestamp
:
testTimestamp
,
},
}
err
=
d
.
UpsertDeposits
([]
db
.
Deposit
{
deposit
},
4
)
require
.
Nil
(
t
,
err
)
...
...
@@ -190,28 +196,34 @@ func TestConfirmedDeposits(t *testing.T) {
require
.
Equal
(
t
,
int
(
0
),
len
(
deposits
))
deposit1
:=
db
.
Deposit
{
ID
:
1
,
TxnHash
:
common
.
HexToHash
(
"0xff01"
),
BlockNumber
:
1
,
BlockTimestamp
:
testTimestamp
,
Address
:
common
.
HexToAddress
(
"0xaa01"
),
Amount
:
big
.
NewInt
(
1
),
ID
:
1
,
Address
:
common
.
HexToAddress
(
"0xaa01"
),
Amount
:
big
.
NewInt
(
1
),
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
common
.
HexToHash
(
"0xff01"
),
BlockNumber
:
1
,
BlockTimestamp
:
testTimestamp
,
},
}
deposit2
:=
db
.
Deposit
{
ID
:
2
,
TxnHash
:
common
.
HexToHash
(
"0xff21"
),
BlockNumber
:
2
,
BlockTimestamp
:
testTimestamp
,
Address
:
common
.
HexToAddress
(
"0xaa21"
),
Amount
:
big
.
NewInt
(
2
),
ID
:
2
,
Address
:
common
.
HexToAddress
(
"0xaa21"
),
Amount
:
big
.
NewInt
(
2
),
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
common
.
HexToHash
(
"0xff21"
),
BlockNumber
:
2
,
BlockTimestamp
:
testTimestamp
,
},
}
deposit3
:=
db
.
Deposit
{
ID
:
3
,
TxnHash
:
common
.
HexToHash
(
"0xff22"
),
BlockNumber
:
2
,
BlockTimestamp
:
testTimestamp
,
Address
:
common
.
HexToAddress
(
"0xaa22"
),
Amount
:
big
.
NewInt
(
2
),
ID
:
3
,
Address
:
common
.
HexToAddress
(
"0xaa22"
),
Amount
:
big
.
NewInt
(
2
),
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
common
.
HexToHash
(
"0xff22"
),
BlockNumber
:
2
,
BlockTimestamp
:
testTimestamp
,
},
}
err
=
d
.
UpsertDeposits
([]
db
.
Deposit
{
...
...
@@ -269,12 +281,14 @@ func TestUpsertDisbursement(t *testing.T) {
// Now, insert a real deposit that we will disburse.
err
=
d
.
UpsertDeposits
([]
db
.
Deposit
{
{
ID
:
1
,
TxnHash
:
depTxnHash
,
BlockNumber
:
depBlockNumber
,
BlockTimestamp
:
testTimestamp
,
Address
:
address
,
Amount
:
amount
,
ID
:
1
,
Address
:
address
,
Amount
:
amount
,
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
depTxnHash
,
BlockNumber
:
depBlockNumber
,
BlockTimestamp
:
testTimestamp
,
},
},
},
0
)
require
.
Nil
(
t
,
err
)
...
...
@@ -289,19 +303,23 @@ func TestUpsertDisbursement(t *testing.T) {
expTeleports
:=
[]
db
.
CompletedTeleport
{
{
ID
:
1
,
Address
:
address
,
Amount
:
amount
,
Success
:
false
,
Deposit
:
db
.
ConfirmationInfo
{
TxnHash
:
depTxnHash
,
BlockNumber
:
depBlockNumber
,
BlockTimestamp
:
testTimestamp
,
Deposit
:
db
.
Deposit
{
ID
:
1
,
Address
:
address
,
Amount
:
amount
,
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
depTxnHash
,
BlockNumber
:
depBlockNumber
,
BlockTimestamp
:
testTimestamp
,
},
},
Disbursement
:
db
.
ConfirmationInfo
{
TxnHash
:
tempDisTxnHash
,
BlockNumber
:
tempDisBlockNumber
,
BlockTimestamp
:
testTimestamp
,
Disbursement
:
db
.
Disbursement
{
Success
:
false
,
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
tempDisTxnHash
,
BlockNumber
:
tempDisBlockNumber
,
BlockTimestamp
:
testTimestamp
,
},
},
},
}
...
...
@@ -318,19 +336,23 @@ func TestUpsertDisbursement(t *testing.T) {
expTeleports
=
[]
db
.
CompletedTeleport
{
{
ID
:
1
,
Address
:
address
,
Amount
:
amount
,
Success
:
true
,
Deposit
:
db
.
ConfirmationInfo
{
TxnHash
:
depTxnHash
,
BlockNumber
:
depBlockNumber
,
BlockTimestamp
:
testTimestamp
,
Deposit
:
db
.
Deposit
{
ID
:
1
,
Address
:
address
,
Amount
:
amount
,
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
depTxnHash
,
BlockNumber
:
depBlockNumber
,
BlockTimestamp
:
testTimestamp
,
},
},
Disbursement
:
db
.
ConfirmationInfo
{
TxnHash
:
disTxnHash
,
BlockNumber
:
disBlockNumber
,
BlockTimestamp
:
testTimestamp
,
Disbursement
:
db
.
Disbursement
{
Success
:
true
,
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
disTxnHash
,
BlockNumber
:
disBlockNumber
,
BlockTimestamp
:
testTimestamp
,
},
},
},
}
...
...
go/teleportr/drivers/disburser/driver.go
View file @
bf1cc8f4
...
...
@@ -509,12 +509,14 @@ func (d *Driver) ingestDeposits(
}
deposits
=
append
(
deposits
,
db
.
Deposit
{
ID
:
event
.
DepositId
.
Uint64
(),
TxnHash
:
event
.
Raw
.
TxHash
,
BlockNumber
:
event
.
Raw
.
BlockNumber
,
BlockTimestamp
:
time
.
Unix
(
int64
(
header
.
Time
),
0
),
Address
:
event
.
Emitter
,
Amount
:
event
.
Amount
,
ID
:
event
.
DepositId
.
Uint64
(),
Address
:
event
.
Emitter
,
Amount
:
event
.
Amount
,
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
event
.
Raw
.
TxHash
,
BlockNumber
:
event
.
Raw
.
BlockNumber
,
BlockTimestamp
:
time
.
Unix
(
int64
(
header
.
Time
),
0
),
},
})
}
err
=
events
.
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