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
Hide 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 {
...
@@ -44,11 +44,12 @@ type Disbursement struct {
ConfirmationInfo
ConfirmationInfo
}
}
//
CompletedTeleport represents an L1 deposit that has been disbursed on L2. The
//
Teleport represents the combination of an L1 deposit and its disbursement on
//
struct also hold info about the L1 and L2 txns involv
ed.
//
L2. Disburment will be nil if the L2 disbursement has not occurr
ed.
type
Completed
Teleport
struct
{
type
Teleport
struct
{
Deposit
Deposit
Disbursement
Disbursement
Disbursement
*
Disbursement
}
}
const
createDepositsTable
=
`
const
createDepositsTable
=
`
...
@@ -384,46 +385,19 @@ ORDER BY id DESC
...
@@ -384,46 +385,19 @@ ORDER BY id DESC
// CompletedTeleports returns the set of all deposits that have also been
// CompletedTeleports returns the set of all deposits that have also been
// disbursed.
// disbursed.
func
(
d
*
Database
)
CompletedTeleports
()
([]
Completed
Teleport
,
error
)
{
func
(
d
*
Database
)
CompletedTeleports
()
([]
Teleport
,
error
)
{
rows
,
err
:=
d
.
conn
.
Query
(
completedTeleportsQuery
)
rows
,
err
:=
d
.
conn
.
Query
(
completedTeleportsQuery
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
defer
rows
.
Close
()
defer
rows
.
Close
()
var
teleports
[]
Completed
Teleport
var
teleports
[]
Teleport
for
rows
.
Next
()
{
for
rows
.
Next
()
{
var
teleport
CompletedTeleport
teleport
,
err
:=
scanTeleport
(
rows
)
var
addressStr
string
var
amountStr
string
var
depTxnHashStr
string
var
disTxnHashStr
string
err
=
rows
.
Scan
(
&
teleport
.
ID
,
&
addressStr
,
&
amountStr
,
&
teleport
.
Disbursement
.
Success
,
&
depTxnHashStr
,
&
teleport
.
Deposit
.
BlockNumber
,
&
teleport
.
Deposit
.
BlockTimestamp
,
&
disTxnHashStr
,
&
teleport
.
Disbursement
.
BlockNumber
,
&
teleport
.
Disbursement
.
BlockTimestamp
,
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
amount
,
ok
:=
new
(
big
.
Int
)
.
SetString
(
amountStr
,
10
)
if
!
ok
{
return
nil
,
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
)
teleports
=
append
(
teleports
,
teleport
)
}
}
if
err
:=
rows
.
Err
();
err
!=
nil
{
if
err
:=
rows
.
Err
();
err
!=
nil
{
...
@@ -433,6 +407,59 @@ func (d *Database) CompletedTeleports() ([]CompletedTeleport, error) {
...
@@ -433,6 +407,59 @@ func (d *Database) CompletedTeleports() ([]CompletedTeleport, error) {
return
teleports
,
nil
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
var
disBlockNumber
*
uint64
var
disBlockTimestamp
*
time
.
Time
var
success
*
bool
err
:=
rows
.
Scan
(
&
teleport
.
ID
,
&
addressStr
,
&
amountStr
,
&
success
,
&
depTxnHashStr
,
&
teleport
.
Deposit
.
BlockNumber
,
&
teleport
.
Deposit
.
BlockTimestamp
,
&
disTxnHashStr
,
&
disBlockNumber
,
&
disBlockTimestamp
,
)
if
err
!=
nil
{
return
Teleport
{},
err
}
amount
,
ok
:=
new
(
big
.
Int
)
.
SetString
(
amountStr
,
10
)
if
!
ok
{
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
()
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
,
}
}
return
teleport
,
nil
}
// PendingTx encapsulates the metadata stored about published disbursement txs.
// PendingTx encapsulates the metadata stored about published disbursement txs.
type
PendingTx
struct
{
type
PendingTx
struct
{
// Txhash is the tx hash of the disbursement tx.
// Txhash is the tx hash of the disbursement tx.
...
...
go/teleportr/db/db_test.go
View file @
a9f2f570
...
@@ -301,7 +301,7 @@ func TestUpsertDisbursement(t *testing.T) {
...
@@ -301,7 +301,7 @@ func TestUpsertDisbursement(t *testing.T) {
)
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
expTeleports
:=
[]
db
.
Completed
Teleport
{
expTeleports
:=
[]
db
.
Teleport
{
{
{
Deposit
:
db
.
Deposit
{
Deposit
:
db
.
Deposit
{
ID
:
1
,
ID
:
1
,
...
@@ -313,7 +313,7 @@ func TestUpsertDisbursement(t *testing.T) {
...
@@ -313,7 +313,7 @@ func TestUpsertDisbursement(t *testing.T) {
BlockTimestamp
:
testTimestamp
,
BlockTimestamp
:
testTimestamp
,
},
},
},
},
Disbursement
:
db
.
Disbursement
{
Disbursement
:
&
db
.
Disbursement
{
Success
:
false
,
Success
:
false
,
ConfirmationInfo
:
db
.
ConfirmationInfo
{
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
tempDisTxnHash
,
TxnHash
:
tempDisTxnHash
,
...
@@ -334,7 +334,7 @@ func TestUpsertDisbursement(t *testing.T) {
...
@@ -334,7 +334,7 @@ func TestUpsertDisbursement(t *testing.T) {
err
=
d
.
UpsertDisbursement
(
1
,
disTxnHash
,
disBlockNumber
,
testTimestamp
,
true
)
err
=
d
.
UpsertDisbursement
(
1
,
disTxnHash
,
disBlockNumber
,
testTimestamp
,
true
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
expTeleports
=
[]
db
.
Completed
Teleport
{
expTeleports
=
[]
db
.
Teleport
{
{
{
Deposit
:
db
.
Deposit
{
Deposit
:
db
.
Deposit
{
ID
:
1
,
ID
:
1
,
...
@@ -346,7 +346,7 @@ func TestUpsertDisbursement(t *testing.T) {
...
@@ -346,7 +346,7 @@ func TestUpsertDisbursement(t *testing.T) {
BlockTimestamp
:
testTimestamp
,
BlockTimestamp
:
testTimestamp
,
},
},
},
},
Disbursement
:
db
.
Disbursement
{
Disbursement
:
&
db
.
Disbursement
{
Success
:
true
,
Success
:
true
,
ConfirmationInfo
:
db
.
ConfirmationInfo
{
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
disTxnHash
,
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