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
dc53a3ba
Unverified
Commit
dc53a3ba
authored
Mar 14, 2022
by
Matthew Slipper
Committed by
GitHub
Mar 14, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2326 from cfromknecht/teleportr-api-fixes
minor teleportr API fixes
parents
ccd98811
cf45bc81
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
8 deletions
+83
-8
server.go
go/teleportr/api/server.go
+7
-7
db.go
go/teleportr/db/db.go
+1
-1
db_test.go
go/teleportr/db/db_test.go
+75
-0
No files found.
go/teleportr/api/server.go
View file @
dc53a3ba
...
@@ -279,7 +279,7 @@ func (s *Server) HandleStatus(
...
@@ -279,7 +279,7 @@ func (s *Server) HandleStatus(
balanceAfterMaxDeposit
:=
new
(
big
.
Int
)
.
Add
(
balanceAfterMaxDeposit
:=
new
(
big
.
Int
)
.
Add
(
curBalance
,
maxDepositAmount
,
curBalance
,
maxDepositAmount
,
)
)
isAvailable
:=
cur
Balance
.
Cmp
(
balanceAfterMaxDeposit
)
>=
0
isAvailable
:=
max
Balance
.
Cmp
(
balanceAfterMaxDeposit
)
>=
0
resp
:=
StatusResponse
{
resp
:=
StatusResponse
{
CurrentBalanceWei
:
curBalance
.
String
(),
CurrentBalanceWei
:
curBalance
.
String
(),
...
@@ -395,7 +395,7 @@ type RPCTeleport struct {
...
@@ -395,7 +395,7 @@ type RPCTeleport struct {
TxHash
string
`json:"tx_hash"`
TxHash
string
`json:"tx_hash"`
BlockNumber
string
`json:"block_number"`
BlockNumber
string
`json:"block_number"`
BlockTimestamp
string
`json:"block_timestamp_unix"`
BlockTimestamp
string
`json:"block_timestamp_unix"`
Disbursement
*
RPCDisbursement
`json:"disbursement
,omitempty
"`
Disbursement
*
RPCDisbursement
`json:"disbursement"`
}
}
func
makeRPCTeleport
(
teleport
*
db
.
Teleport
)
RPCTeleport
{
func
makeRPCTeleport
(
teleport
*
db
.
Teleport
)
RPCTeleport
{
...
@@ -407,7 +407,7 @@ func makeRPCTeleport(teleport *db.Teleport) RPCTeleport {
...
@@ -407,7 +407,7 @@ func makeRPCTeleport(teleport *db.Teleport) RPCTeleport {
BlockNumber
:
strconv
.
FormatUint
(
teleport
.
Deposit
.
BlockNumber
,
10
),
BlockNumber
:
strconv
.
FormatUint
(
teleport
.
Deposit
.
BlockNumber
,
10
),
BlockTimestamp
:
strconv
.
FormatInt
(
teleport
.
Deposit
.
BlockTimestamp
.
Unix
(),
10
),
BlockTimestamp
:
strconv
.
FormatInt
(
teleport
.
Deposit
.
BlockTimestamp
.
Unix
(),
10
),
}
}
if
rpcT
eleport
.
Disbursement
!=
nil
{
if
t
eleport
.
Disbursement
!=
nil
{
rpcTeleport
.
Disbursement
=
&
RPCDisbursement
{
rpcTeleport
.
Disbursement
=
&
RPCDisbursement
{
TxHash
:
teleport
.
Disbursement
.
TxnHash
.
String
(),
TxHash
:
teleport
.
Disbursement
.
TxnHash
.
String
(),
BlockNumber
:
strconv
.
FormatUint
(
teleport
.
Disbursement
.
BlockNumber
,
10
),
BlockNumber
:
strconv
.
FormatUint
(
teleport
.
Disbursement
.
BlockNumber
,
10
),
...
@@ -426,10 +426,10 @@ type RPCDisbursement struct {
...
@@ -426,10 +426,10 @@ type RPCDisbursement struct {
}
}
type
TrackResponse
struct
{
type
TrackResponse
struct
{
CurrentBlockNumber
string
`json:"current_block_number"`
CurrentBlockNumber
string
`json:"current_block_number"`
ConfirmationsRequired
string
`json:"confirmations_required"`
ConfirmationsRequired
string
`json:"confirmations_required"`
ConfirmationsRemaining
string
`json:"confirmations_remaining"`
ConfirmationsRemaining
string
`json:"confirmations_remaining"`
Teleport
RPCTeleport
Teleport
RPCTeleport
`json:"teleport"`
}
}
func
(
s
*
Server
)
HandleTrack
(
func
(
s
*
Server
)
HandleTrack
(
...
...
go/teleportr/db/db.go
View file @
dc53a3ba
...
@@ -147,7 +147,7 @@ func (c Config) WithoutDB() string {
...
@@ -147,7 +147,7 @@ func (c Config) WithoutDB() string {
// sslMode retuns "enabled" if EnableSSL is true, otherwise returns "disabled".
// sslMode retuns "enabled" if EnableSSL is true, otherwise returns "disabled".
func
(
c
Config
)
sslMode
()
string
{
func
(
c
Config
)
sslMode
()
string
{
if
c
.
EnableSSL
{
if
c
.
EnableSSL
{
return
"
enabl
e"
return
"
requir
e"
}
}
return
"disable"
return
"disable"
}
}
...
...
go/teleportr/db/db_test.go
View file @
dc53a3ba
...
@@ -495,3 +495,78 @@ func TestDeletePendingTx(t *testing.T) {
...
@@ -495,3 +495,78 @@ func TestDeletePendingTx(t *testing.T) {
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
err
)
require
.
Nil
(
t
,
pendingTxs
)
require
.
Nil
(
t
,
pendingTxs
)
}
}
// TestLoadTeleports asserts that LoadTeleportByDepositHash and
// LoadTeleportsByAddress are able to query for a spcific deposit in various
// stages through the teleport process.
func
TestLoadTeleports
(
t
*
testing
.
T
)
{
t
.
Parallel
()
d
:=
newDatabase
(
t
)
defer
d
.
Close
()
address
:=
common
.
HexToAddress
(
"0x01"
)
amount
:=
big
.
NewInt
(
1000
)
depTxnHash
:=
common
.
HexToHash
(
"0x0d01"
)
depBlockNumber
:=
uint64
(
1
)
disTxnHash
:=
common
.
HexToHash
(
"0x0e01"
)
disBlockNumber
:=
uint64
(
2
)
// Insert deposit.
deposit1
:=
db
.
Deposit
{
ID
:
1
,
Address
:
address
,
Amount
:
amount
,
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
depTxnHash
,
BlockNumber
:
depBlockNumber
,
BlockTimestamp
:
testTimestamp
,
},
}
err
:=
d
.
UpsertDeposits
([]
db
.
Deposit
{
deposit1
},
0
)
require
.
Nil
(
t
,
err
)
// The same, undisbursed teleport should be retruned by hash and address.
expTeleport
:=
db
.
Teleport
{
Deposit
:
deposit1
,
Disbursement
:
nil
,
}
teleport
,
err
:=
d
.
LoadTeleportByDepositHash
(
depTxnHash
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
teleport
)
require
.
Equal
(
t
,
expTeleport
,
*
teleport
)
teleports
,
err
:=
d
.
LoadTeleportsByAddress
(
address
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
[]
db
.
Teleport
{
expTeleport
},
teleports
)
// Insert a disbursement for the above deposit.
err
=
d
.
UpsertDisbursement
(
1
,
disTxnHash
,
disBlockNumber
,
testTimestamp
,
true
,
)
require
.
Nil
(
t
,
err
)
// The now-complete teleport should be returned from both queries.
expTeleport
=
db
.
Teleport
{
Deposit
:
deposit1
,
Disbursement
:
&
db
.
Disbursement
{
Success
:
true
,
ConfirmationInfo
:
db
.
ConfirmationInfo
{
TxnHash
:
disTxnHash
,
BlockNumber
:
disBlockNumber
,
BlockTimestamp
:
testTimestamp
,
},
},
}
teleport
,
err
=
d
.
LoadTeleportByDepositHash
(
depTxnHash
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
teleport
)
require
.
Equal
(
t
,
expTeleport
,
*
teleport
)
teleports
,
err
=
d
.
LoadTeleportsByAddress
(
address
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
[]
db
.
Teleport
{
expTeleport
},
teleports
)
}
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