Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
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
vicotor
mybee
Commits
6463de45
Unverified
Commit
6463de45
authored
Nov 18, 2020
by
Ralph Pichler
Committed by
GitHub
Nov 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
retry balance check (#965)
parent
d1ec428a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
16 deletions
+47
-16
init.go
pkg/settlement/swap/chequebook/init.go
+47
-16
No files found.
pkg/settlement/swap/chequebook/init.go
View file @
6463de45
...
...
@@ -8,6 +8,7 @@ import (
"context"
"fmt"
"math/big"
"time"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -18,6 +19,51 @@ import (
const
chequebookKey
=
"chequebook"
func
checkBalance
(
ctx
context
.
Context
,
logger
logging
.
Logger
,
swapInitialDeposit
uint64
,
swapBackend
transaction
.
Backend
,
chainId
int64
,
overlayEthAddress
common
.
Address
,
erc20BindingFunc
ERC20BindingFunc
,
erc20Address
common
.
Address
,
backoffDuration
time
.
Duration
,
maxRetries
uint64
,
)
error
{
timeoutCtx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
backoffDuration
*
time
.
Duration
(
maxRetries
))
defer
cancel
()
erc20Token
,
err
:=
erc20BindingFunc
(
erc20Address
,
swapBackend
)
if
err
!=
nil
{
return
err
}
for
{
balance
,
err
:=
erc20Token
.
BalanceOf
(
&
bind
.
CallOpts
{
Context
:
timeoutCtx
,
},
overlayEthAddress
)
if
err
!=
nil
{
return
err
}
if
balance
.
Cmp
(
big
.
NewInt
(
int64
(
swapInitialDeposit
)))
<
0
{
logger
.
Warningf
(
"please make sure there is sufficient eth and bzz available on %x."
,
overlayEthAddress
)
if
chainId
==
5
{
logger
.
Warning
(
"on goerli you can get both goerli eth and goerli bzz from https://faucet.ethswarm.org."
)
}
select
{
case
<-
time
.
After
(
backoffDuration
)
:
case
<-
timeoutCtx
.
Done
()
:
return
fmt
.
Errorf
(
"insufficient token for initial deposit"
)
}
continue
}
return
nil
}
}
// Init initialises the chequebook service.
func
Init
(
ctx
context
.
Context
,
...
...
@@ -52,25 +98,10 @@ func Init(
logger
.
Info
(
"no chequebook found, deploying new one."
)
if
swapInitialDeposit
!=
0
{
er
c20Token
,
err
:=
erc20BindingFunc
(
erc20Address
,
swapBackend
)
er
r
=
checkBalance
(
ctx
,
logger
,
swapInitialDeposit
,
swapBackend
,
chainId
,
overlayEthAddress
,
erc20BindingFunc
,
erc20Address
,
20
*
time
.
Second
,
10
)
if
err
!=
nil
{
return
nil
,
err
}
balance
,
err
:=
erc20Token
.
BalanceOf
(
&
bind
.
CallOpts
{
Context
:
ctx
,
},
overlayEthAddress
)
if
err
!=
nil
{
return
nil
,
err
}
if
balance
.
Cmp
(
big
.
NewInt
(
int64
(
swapInitialDeposit
)))
<
0
{
logger
.
Warningf
(
"please make sure there is sufficient eth and bzz available on %x."
,
overlayEthAddress
)
if
chainId
==
5
{
logger
.
Warning
(
"on goerli you can get both goerli eth and goerli bzz from https://faucet.ethswarm.org."
)
}
return
nil
,
fmt
.
Errorf
(
"insufficient token for initial deposit"
)
}
}
// if we don't yet have a chequebook, deploy a new one
...
...
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