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
70770e1d
Unverified
Commit
70770e1d
authored
Sep 28, 2020
by
Ralph Pichler
Committed by
GitHub
Sep 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Swap ux improvements (#761)
parent
6b731c7f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
31 deletions
+47
-31
node.go
pkg/node/node.go
+2
-2
common_test.go
pkg/settlement/swap/chequebook/common_test.go
+7
-3
factory.go
pkg/settlement/swap/chequebook/factory.go
+13
-6
factory_test.go
pkg/settlement/swap/chequebook/factory_test.go
+11
-13
init.go
pkg/settlement/swap/chequebook/init.go
+14
-7
No files found.
pkg/node/node.go
View file @
70770e1d
...
...
@@ -182,11 +182,11 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
var
found
bool
factoryAddress
,
found
=
chequebook
.
DiscoverFactoryAddress
(
chainID
.
Int64
())
if
!
found
{
return
nil
,
errors
.
New
(
"no known factory address"
)
return
nil
,
errors
.
New
(
"no known factory address
for this network
"
)
}
logger
.
Infof
(
"using default factory address for chain id %d: %x"
,
chainID
,
factoryAddress
)
}
else
if
!
common
.
IsHexAddress
(
o
.
SwapFactoryAddress
)
{
return
nil
,
errors
.
New
(
"
invali
d factory address"
)
return
nil
,
errors
.
New
(
"
malforme
d factory address"
)
}
else
{
factoryAddress
=
common
.
HexToAddress
(
o
.
SwapFactoryAddress
)
logger
.
Infof
(
"using custom factory address: %x"
,
factoryAddress
)
...
...
pkg/settlement/swap/chequebook/common_test.go
View file @
70770e1d
...
...
@@ -163,7 +163,8 @@ func (m *chequeSignerMock) Sign(cheque *chequebook.Cheque) ([]byte, error) {
type
factoryMock
struct
{
erc20Address
func
(
ctx
context
.
Context
)
(
common
.
Address
,
error
)
deploy
func
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
)
(
common
.
Address
,
error
)
deploy
func
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
)
(
common
.
Hash
,
error
)
waitDeployed
func
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
common
.
Address
,
error
)
verifyBytecode
func
(
ctx
context
.
Context
)
error
verifyChequebook
func
(
ctx
context
.
Context
,
chequebook
common
.
Address
)
error
}
...
...
@@ -173,11 +174,14 @@ func (m *factoryMock) ERC20Address(ctx context.Context) (common.Address, error)
return
m
.
erc20Address
(
ctx
)
}
// Deploy deploys a new chequebook and returns once confirmed.
func
(
m
*
factoryMock
)
Deploy
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
)
(
common
.
Address
,
error
)
{
func
(
m
*
factoryMock
)
Deploy
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
)
(
common
.
Hash
,
error
)
{
return
m
.
deploy
(
ctx
,
issuer
,
defaultHardDepositTimeoutDuration
)
}
func
(
m
*
factoryMock
)
WaitDeployed
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
common
.
Address
,
error
)
{
return
m
.
waitDeployed
(
ctx
,
txHash
)
}
// VerifyBytecode checks that the factory is valid.
func
(
m
*
factoryMock
)
VerifyBytecode
(
ctx
context
.
Context
)
error
{
return
m
.
verifyBytecode
(
ctx
)
...
...
pkg/settlement/swap/chequebook/factory.go
View file @
70770e1d
...
...
@@ -27,8 +27,10 @@ var (
type
Factory
interface
{
// ERC20Address returns the token for which this factory deploys chequebooks.
ERC20Address
(
ctx
context
.
Context
)
(
common
.
Address
,
error
)
// Deploy deploys a new chequebook and returns once confirmed.
Deploy
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
)
(
common
.
Address
,
error
)
// Deploy deploys a new chequebook and returns once the transaction has been submitted.
Deploy
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
)
(
common
.
Hash
,
error
)
// WaitDeployed waits for the deployment transaction to confirm and returns the chequebook address
WaitDeployed
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
common
.
Address
,
error
)
// VerifyBytecode checks that the factory is valid.
VerifyBytecode
(
ctx
context
.
Context
)
error
// VerifyChequebook checks that the supplied chequebook has been deployed by this factory.
...
...
@@ -65,11 +67,11 @@ func NewFactory(backend Backend, transactionService TransactionService, address
},
nil
}
// Deploy deploys a new chequebook and returns once
confirm
ed.
func
(
c
*
factory
)
Deploy
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
)
(
common
.
Address
,
error
)
{
// Deploy deploys a new chequebook and returns once
the transaction has been submitt
ed.
func
(
c
*
factory
)
Deploy
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
)
(
common
.
Hash
,
error
)
{
callData
,
err
:=
c
.
ABI
.
Pack
(
"deploySimpleSwap"
,
issuer
,
big
.
NewInt
(
0
)
.
Set
(
defaultHardDepositTimeoutDuration
))
if
err
!=
nil
{
return
common
.
Address
{},
err
return
common
.
Hash
{},
err
}
request
:=
&
TxRequest
{
...
...
@@ -82,9 +84,14 @@ func (c *factory) Deploy(ctx context.Context, issuer common.Address, defaultHard
txHash
,
err
:=
c
.
transactionService
.
Send
(
ctx
,
request
)
if
err
!=
nil
{
return
common
.
Address
{},
err
return
common
.
Hash
{},
err
}
return
txHash
,
nil
}
// WaitDeployed waits for the deployment transaction to confirm and returns the chequebook address
func
(
c
*
factory
)
WaitDeployed
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
common
.
Address
,
error
)
{
receipt
,
err
:=
c
.
transactionService
.
WaitForReceipt
(
ctx
,
txHash
)
if
err
!=
nil
{
return
common
.
Address
{},
err
...
...
pkg/settlement/swap/chequebook/factory_test.go
View file @
70770e1d
...
...
@@ -225,7 +225,16 @@ func TestFactoryDeploy(t *testing.T) {
t
.
Fatal
(
err
)
}
chequebookAddress
,
err
:=
factory
.
Deploy
(
context
.
Background
(),
issuerAddress
,
defaultTimeout
)
txHash
,
err
:=
factory
.
Deploy
(
context
.
Background
(),
issuerAddress
,
defaultTimeout
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
txHash
!=
deployTransactionHash
{
t
.
Fatalf
(
"returning wrong transaction hash. wanted %x, got %x"
,
deployTransactionHash
,
txHash
)
}
chequebookAddress
,
err
:=
factory
.
WaitDeployed
(
context
.
Background
(),
txHash
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -237,23 +246,12 @@ func TestFactoryDeploy(t *testing.T) {
func
TestFactoryDeployReverted
(
t
*
testing
.
T
)
{
factoryAddress
:=
common
.
HexToAddress
(
"0xabcd"
)
issuerAddress
:=
common
.
HexToAddress
(
"0xefff"
)
defaultTimeout
:=
big
.
NewInt
(
1
)
deployTransactionHash
:=
common
.
HexToHash
(
"0xffff"
)
factory
,
err
:=
newTestFactory
(
t
,
factoryAddress
,
&
backendMock
{},
&
transactionServiceMock
{
send
:
func
(
ctx
context
.
Context
,
request
*
chequebook
.
TxRequest
)
(
txHash
common
.
Hash
,
err
error
)
{
if
request
.
To
!=
factoryAddress
{
t
.
Fatalf
(
"sending to wrong address. wanted %x, got %x"
,
factoryAddress
,
request
.
To
)
}
if
request
.
Value
.
Cmp
(
big
.
NewInt
(
0
))
!=
0
{
t
.
Fatal
(
"trying to send ether"
)
}
return
deployTransactionHash
,
nil
},
waitForReceipt
:
func
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
receipt
*
types
.
Receipt
,
err
error
)
{
if
txHash
!=
deployTransactionHash
{
t
.
Fatalf
(
"waiting for wrong transaction. wanted %x, got %x"
,
deployTransactionHash
,
txHash
)
...
...
@@ -268,7 +266,7 @@ func TestFactoryDeployReverted(t *testing.T) {
t
.
Fatal
(
err
)
}
_
,
err
=
factory
.
Deploy
(
context
.
Background
(),
issuerAddress
,
defaultTimeout
)
_
,
err
=
factory
.
WaitDeployed
(
context
.
Background
(),
deployTransactionHash
)
if
err
==
nil
{
t
.
Fatal
(
"returned failed chequebook deployment"
)
}
...
...
pkg/settlement/swap/chequebook/init.go
View file @
70770e1d
...
...
@@ -6,7 +6,7 @@ package chequebook
import
(
"context"
"
errors
"
"
fmt
"
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
...
...
@@ -41,6 +41,8 @@ func Init(
return
nil
,
err
}
logger
.
Info
(
"no chequebook found, deploying new one."
)
var
chequebookAddress
common
.
Address
err
=
stateStore
.
Get
(
chequebookKey
,
&
chequebookAddress
)
if
err
!=
nil
{
...
...
@@ -62,14 +64,19 @@ func Init(
}
if
balance
.
Cmp
(
big
.
NewInt
(
int64
(
swapInitialDeposit
)))
<
0
{
return
nil
,
errors
.
New
(
"insufficient token for initial deposit"
)
return
nil
,
fmt
.
Errorf
(
"insufficient token for initial deposit. Please make sure there is sufficient eth and bzz available on %x"
,
overlayEthAddress
)
}
}
// if we don't yet have a chequebook, deploy a new one
logger
.
Info
(
"deploying new chequebook"
)
txHash
,
err
:=
chequebookFactory
.
Deploy
(
ctx
,
overlayEthAddress
,
big
.
NewInt
(
0
))
if
err
!=
nil
{
return
nil
,
err
}
logger
.
Infof
(
"deploying new chequebook in transaction %x"
,
txHash
)
chequebookAddress
,
err
=
chequebookFactory
.
Deploy
(
ctx
,
overlayEthAddress
,
big
.
NewInt
(
0
)
)
chequebookAddress
,
err
=
chequebookFactory
.
WaitDeployed
(
ctx
,
txHash
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -88,19 +95,19 @@ func Init(
}
if
swapInitialDeposit
!=
0
{
logger
.
Info
(
"depositing into new chequebook"
)
logger
.
Infof
(
"depositing %d token into new chequebook"
,
swapInitialDeposit
)
depositHash
,
err
:=
chequebookService
.
Deposit
(
ctx
,
big
.
NewInt
(
int64
(
swapInitialDeposit
)))
if
err
!=
nil
{
return
nil
,
err
}
logger
.
Infof
(
"sent deposit transaction %x"
,
depositHash
)
err
=
chequebookService
.
WaitForDeposit
(
ctx
,
depositHash
)
if
err
!=
nil
{
return
nil
,
err
}
logger
.
Info
f
(
"deposited to chequebook %x in transaction %x"
,
chequebookAddress
,
depositHash
)
logger
.
Info
(
"successfully deposited to chequebook"
)
}
}
else
{
chequebookService
,
err
=
New
(
swapBackend
,
transactionService
,
chequebookAddress
,
erc20Address
,
overlayEthAddress
,
stateStore
,
chequeSigner
,
simpleSwapBindingFunc
,
erc20BindingFunc
)
...
...
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