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
a9f2f570
Unverified
Commit
a9f2f570
authored
Mar 03, 2022
by
Conner Fromknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: use generic Teleport struct, remove CompletedTeleport
parent
bf1cc8f4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
38 deletions
+65
-38
db.go
go/teleportr/db/db.go
+61
-34
db_test.go
go/teleportr/db/db_test.go
+4
-4
No files found.
go/teleportr/db/db.go
View file @
a9f2f570
...
...
@@ -44,11 +44,12 @@ type Disbursement struct {
ConfirmationInfo
}
//
CompletedTeleport represents an L1 deposit that has been disbursed on L2. The
//
struct also hold info about the L1 and L2 txns involv
ed.
type
Completed
Teleport
struct
{
//
Teleport represents the combination of an L1 deposit and its disbursement on
//
L2. Disburment will be nil if the L2 disbursement has not occurr
ed.
type
Teleport
struct
{
Deposit
Disbursement
Disbursement
Disbursement
*
Disbursement
}
const
createDepositsTable
=
`
...
...
@@ -384,53 +385,79 @@ ORDER BY id DESC
// CompletedTeleports returns the set of all deposits that have also been
// disbursed.
func
(
d
*
Database
)
CompletedTeleports
()
([]
Completed
Teleport
,
error
)
{
func
(
d
*
Database
)
CompletedTeleports
()
([]
Teleport
,
error
)
{
rows
,
err
:=
d
.
conn
.
Query
(
completedTeleportsQuery
)
if
err
!=
nil
{
return
nil
,
err
}
defer
rows
.
Close
()
var
teleports
[]
Completed
Teleport
var
teleports
[]
Teleport
for
rows
.
Next
()
{
var
teleport
CompletedTeleport
teleport
,
err
:=
scanTeleport
(
rows
)
if
err
!=
nil
{
return
nil
,
err
}
teleports
=
append
(
teleports
,
teleport
)
}
if
err
:=
rows
.
Err
();
err
!=
nil
{
return
nil
,
err
}
return
teleports
,
nil
}
func
scanTeleport
(
rows
*
sql
.
Rows
)
(
Teleport
,
error
)
{
var
teleport
Teleport
var
addressStr
string
var
amountStr
string
var
depTxnHashStr
string
var
disTxnHashStr
string
err
=
rows
.
Scan
(
var
disTxnHashStr
*
string
var
disBlockNumber
*
uint64
var
disBlockTimestamp
*
time
.
Time
var
success
*
bool
err
:=
rows
.
Scan
(
&
teleport
.
ID
,
&
addressStr
,
&
amountStr
,
&
teleport
.
Disbursement
.
S
uccess
,
&
s
uccess
,
&
depTxnHashStr
,
&
teleport
.
Deposit
.
BlockNumber
,
&
teleport
.
Deposit
.
BlockTimestamp
,
&
disTxnHashStr
,
&
teleport
.
Disbursement
.
BlockNumber
,
&
teleport
.
Disbursement
.
BlockTimestamp
,
&
dis
BlockNumber
,
&
dis
BlockTimestamp
,
)
if
err
!=
nil
{
return
nil
,
err
return
Teleport
{}
,
err
}
amount
,
ok
:=
new
(
big
.
Int
)
.
SetString
(
amountStr
,
10
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"unable to parse amount %v"
,
amount
)
return
Teleport
{}
,
fmt
.
Errorf
(
"unable to parse amount %v"
,
amount
)
}
teleport
.
Address
=
common
.
HexToAddress
(
addressStr
)
teleport
.
Amount
=
amount
teleport
.
Deposit
.
TxnHash
=
common
.
HexToHash
(
depTxnHashStr
)
teleport
.
Deposit
.
BlockTimestamp
=
teleport
.
Deposit
.
BlockTimestamp
.
Local
()
teleport
.
Disbursement
.
TxnHash
=
common
.
HexToHash
(
disTxnHashStr
)
teleport
.
Disbursement
.
BlockTimestamp
=
teleport
.
Disbursement
.
BlockTimestamp
.
Local
()
teleports
=
append
(
teleports
,
teleport
)
hasDisbursement
:=
success
!=
nil
&&
disTxnHashStr
!=
nil
&&
disBlockNumber
!=
nil
&&
disBlockTimestamp
!=
nil
if
hasDisbursement
{
teleport
.
Disbursement
=
&
Disbursement
{
ConfirmationInfo
:
ConfirmationInfo
{
TxnHash
:
common
.
HexToHash
(
*
disTxnHashStr
),
BlockNumber
:
*
disBlockNumber
,
BlockTimestamp
:
disBlockTimestamp
.
Local
(),
},
Success
:
*
success
,
}
if
err
:=
rows
.
Err
();
err
!=
nil
{
return
nil
,
err
}
return
teleport
s
,
nil
return
teleport
,
nil
}
// PendingTx encapsulates the metadata stored about published disbursement txs.
...
...
go/teleportr/db/db_test.go
View file @
a9f2f570
...
...
@@ -301,7 +301,7 @@ func TestUpsertDisbursement(t *testing.T) {
)
require
.
Nil
(
t
,
err
)
expTeleports
:=
[]
db
.
Completed
Teleport
{
expTeleports
:=
[]
db
.
Teleport
{
{
Deposit
:
db
.
Deposit
{
ID
:
1
,
...
...
@@ -313,7 +313,7 @@ func TestUpsertDisbursement(t *testing.T) {
BlockTimestamp
:
testTimestamp
,
},
},
Disbursement
:
db
.
Disbursement
{
Disbursement
:
&
db
.
Disbursement
{
Success
:
false
,
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
tempDisTxnHash
,
...
...
@@ -334,7 +334,7 @@ func TestUpsertDisbursement(t *testing.T) {
err
=
d
.
UpsertDisbursement
(
1
,
disTxnHash
,
disBlockNumber
,
testTimestamp
,
true
)
require
.
Nil
(
t
,
err
)
expTeleports
=
[]
db
.
Completed
Teleport
{
expTeleports
=
[]
db
.
Teleport
{
{
Deposit
:
db
.
Deposit
{
ID
:
1
,
...
...
@@ -346,7 +346,7 @@ func TestUpsertDisbursement(t *testing.T) {
BlockTimestamp
:
testTimestamp
,
},
},
Disbursement
:
db
.
Disbursement
{
Disbursement
:
&
db
.
Disbursement
{
Success
:
true
,
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
disTxnHash
,
...
...
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