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
80bcf665
Unverified
Commit
80bcf665
authored
Feb 16, 2021
by
Ralph Pichler
Committed by
GitHub
Feb 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
transaction: add support for deployments (#1265)
parent
f28ff0db
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
113 additions
and
25 deletions
+113
-25
cashout.go
pkg/settlement/swap/chequebook/cashout.go
+1
-1
cashout_test.go
pkg/settlement/swap/chequebook/cashout_test.go
+2
-2
chequebook.go
pkg/settlement/swap/chequebook/chequebook.go
+2
-2
chequebook_test.go
pkg/settlement/swap/chequebook/chequebook_test.go
+3
-3
factory.go
pkg/settlement/swap/chequebook/factory.go
+1
-1
factory_test.go
pkg/settlement/swap/chequebook/factory_test.go
+1
-1
transaction.go
pkg/settlement/swap/transaction/transaction.go
+24
-14
transaction_test.go
pkg/settlement/swap/transaction/transaction_test.go
+79
-1
No files found.
pkg/settlement/swap/chequebook/cashout.go
View file @
80bcf665
...
...
@@ -107,7 +107,7 @@ func (s *cashoutService) CashCheque(ctx context.Context, chequebook, recipient c
}
request
:=
&
transaction
.
TxRequest
{
To
:
chequebook
,
To
:
&
chequebook
,
Data
:
callData
,
GasPrice
:
nil
,
GasLimit
:
0
,
...
...
pkg/settlement/swap/chequebook/cashout_test.go
View file @
80bcf665
...
...
@@ -83,7 +83,7 @@ func TestCashout(t *testing.T) {
),
transactionmock
.
New
(
transactionmock
.
WithSendFunc
(
func
(
c
context
.
Context
,
request
*
transaction
.
TxRequest
)
(
common
.
Hash
,
error
)
{
if
request
.
To
!=
chequebookAddress
{
if
request
.
To
!=
nil
&&
*
request
.
To
!=
chequebookAddress
{
t
.
Fatalf
(
"sending to wrong contract. wanted %x, got %x"
,
chequebookAddress
,
request
.
To
)
}
if
request
.
Value
.
Cmp
(
big
.
NewInt
(
0
))
!=
0
{
...
...
@@ -222,7 +222,7 @@ func TestCashoutBounced(t *testing.T) {
),
transactionmock
.
New
(
transactionmock
.
WithSendFunc
(
func
(
c
context
.
Context
,
request
*
transaction
.
TxRequest
)
(
common
.
Hash
,
error
)
{
if
request
.
To
!=
chequebookAddress
{
if
request
.
To
!=
nil
&&
*
request
.
To
!=
chequebookAddress
{
t
.
Fatalf
(
"sending to wrong contract. wanted %x, got %x"
,
chequebookAddress
,
request
.
To
)
}
if
request
.
Value
.
Cmp
(
big
.
NewInt
(
0
))
!=
0
{
...
...
pkg/settlement/swap/chequebook/chequebook.go
View file @
80bcf665
...
...
@@ -139,7 +139,7 @@ func (s *service) Deposit(ctx context.Context, amount *big.Int) (hash common.Has
}
request
:=
&
transaction
.
TxRequest
{
To
:
s
.
erc20Address
,
To
:
&
s
.
erc20Address
,
Data
:
callData
,
GasPrice
:
nil
,
GasLimit
:
0
,
...
...
@@ -371,7 +371,7 @@ func (s *service) Withdraw(ctx context.Context, amount *big.Int) (hash common.Ha
}
request
:=
&
transaction
.
TxRequest
{
To
:
s
.
address
,
To
:
&
s
.
address
,
Data
:
callData
,
GasPrice
:
nil
,
GasLimit
:
0
,
...
...
pkg/settlement/swap/chequebook/chequebook_test.go
View file @
80bcf665
...
...
@@ -131,7 +131,7 @@ func TestChequebookDeposit(t *testing.T) {
backendmock
.
New
(),
transactionmock
.
New
(
transactionmock
.
WithSendFunc
(
func
(
c
context
.
Context
,
request
*
transaction
.
TxRequest
)
(
common
.
Hash
,
error
)
{
if
request
.
To
!=
erc20address
{
if
request
.
To
!=
nil
&&
*
request
.
To
!=
erc20address
{
t
.
Fatalf
(
"sending to wrong contract. wanted %x, got %x"
,
erc20address
,
request
.
To
)
}
if
request
.
Value
.
Cmp
(
big
.
NewInt
(
0
))
!=
0
{
...
...
@@ -502,7 +502,7 @@ func TestChequebookWithdraw(t *testing.T) {
backendmock
.
New
(),
transactionmock
.
New
(
transactionmock
.
WithSendFunc
(
func
(
c
context
.
Context
,
request
*
transaction
.
TxRequest
)
(
common
.
Hash
,
error
)
{
if
request
.
To
!=
address
{
if
request
.
To
!=
nil
&&
*
request
.
To
!=
address
{
t
.
Fatalf
(
"sending to wrong contract. wanted %x, got %x"
,
address
,
request
.
To
)
}
if
request
.
Value
.
Cmp
(
big
.
NewInt
(
0
))
!=
0
{
...
...
@@ -559,7 +559,7 @@ func TestChequebookWithdrawInsufficientFunds(t *testing.T) {
backendmock
.
New
(),
transactionmock
.
New
(
transactionmock
.
WithSendFunc
(
func
(
c
context
.
Context
,
request
*
transaction
.
TxRequest
)
(
common
.
Hash
,
error
)
{
if
request
.
To
!=
address
{
if
request
.
To
!=
nil
&&
*
request
.
To
!=
address
{
t
.
Fatalf
(
"sending to wrong contract. wanted %x, got %x"
,
address
,
request
.
To
)
}
if
request
.
Value
.
Cmp
(
big
.
NewInt
(
0
))
!=
0
{
...
...
pkg/settlement/swap/chequebook/factory.go
View file @
80bcf665
...
...
@@ -76,7 +76,7 @@ func (c *factory) Deploy(ctx context.Context, issuer common.Address, defaultHard
}
request
:=
&
transaction
.
TxRequest
{
To
:
c
.
address
,
To
:
&
c
.
address
,
Data
:
callData
,
GasPrice
:
nil
,
GasLimit
:
0
,
...
...
pkg/settlement/swap/chequebook/factory_test.go
View file @
80bcf665
...
...
@@ -188,7 +188,7 @@ func TestFactoryDeploy(t *testing.T) {
backendmock
.
New
(),
transactionmock
.
New
(
transactionmock
.
WithSendFunc
(
func
(
ctx
context
.
Context
,
request
*
transaction
.
TxRequest
)
(
txHash
common
.
Hash
,
err
error
)
{
if
request
.
To
!=
factoryAddress
{
if
request
.
To
!=
nil
&&
*
request
.
To
!=
factoryAddress
{
t
.
Fatalf
(
"sending to wrong address. wanted %x, got %x"
,
factoryAddress
,
request
.
To
)
}
if
request
.
Value
.
Cmp
(
big
.
NewInt
(
0
))
!=
0
{
...
...
pkg/settlement/swap/transaction/transaction.go
View file @
80bcf665
...
...
@@ -23,11 +23,11 @@ var (
// TxRequest describes a request for a transaction that can be executed.
type
TxRequest
struct
{
To
common
.
Address
// recipient of the transaction
Data
[]
byte
// transaction data
GasPrice
*
big
.
Int
// gas price or nil if suggested gas price should be used
GasLimit
uint64
// gas limit or 0 if it should be estimated
Value
*
big
.
Int
// amount of wei to send
To
*
common
.
Address
// recipient of the transaction
Data
[]
byte
// transaction data
GasPrice
*
big
.
Int
// gas price or nil if suggested gas price should be used
GasLimit
uint64
// gas limit or 0 if it should be estimated
Value
*
big
.
Int
// amount of wei to send
}
// Service is the service to send transactions. It takes care of gas price, gas limit and nonce management.
...
...
@@ -107,7 +107,7 @@ func prepareTransaction(ctx context.Context, request *TxRequest, from common.Add
if
request
.
GasLimit
==
0
{
gasLimit
,
err
=
backend
.
EstimateGas
(
ctx
,
ethereum
.
CallMsg
{
From
:
from
,
To
:
&
request
.
To
,
To
:
request
.
To
,
Data
:
request
.
Data
,
})
if
err
!=
nil
{
...
...
@@ -132,12 +132,22 @@ func prepareTransaction(ctx context.Context, request *TxRequest, from common.Add
return
nil
,
err
}
return
types
.
NewTransaction
(
nonce
,
request
.
To
,
request
.
Value
,
gasLimit
,
gasPrice
,
request
.
Data
,
),
nil
if
request
.
To
!=
nil
{
return
types
.
NewTransaction
(
nonce
,
*
request
.
To
,
request
.
Value
,
gasLimit
,
gasPrice
,
request
.
Data
,
),
nil
}
else
{
return
types
.
NewContractCreation
(
nonce
,
request
.
Value
,
gasLimit
,
gasPrice
,
request
.
Data
,
),
nil
}
}
pkg/settlement/swap/transaction/transaction_test.go
View file @
80bcf665
...
...
@@ -31,7 +31,7 @@ func TestTransactionSend(t *testing.T) {
nonce
:=
uint64
(
2
)
request
:=
&
transaction
.
TxRequest
{
To
:
recipient
,
To
:
&
recipient
,
Data
:
txData
,
Value
:
value
,
}
...
...
@@ -100,6 +100,84 @@ func TestTransactionSend(t *testing.T) {
}
}
func
TestTransactionDeploy
(
t
*
testing
.
T
)
{
logger
:=
logging
.
New
(
ioutil
.
Discard
,
0
)
signedTx
:=
types
.
NewContractCreation
(
0
,
big
.
NewInt
(
0
),
0
,
nil
,
nil
)
txData
:=
common
.
Hex2Bytes
(
"0xabcdee"
)
value
:=
big
.
NewInt
(
1
)
suggestedGasPrice
:=
big
.
NewInt
(
2
)
estimatedGasLimit
:=
uint64
(
3
)
nonce
:=
uint64
(
2
)
request
:=
&
transaction
.
TxRequest
{
To
:
nil
,
Data
:
txData
,
Value
:
value
,
}
transactionService
,
err
:=
transaction
.
NewService
(
logger
,
backendmock
.
New
(
backendmock
.
WithSendTransactionFunc
(
func
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
error
{
if
tx
!=
signedTx
{
t
.
Fatal
(
"not sending signed transaction"
)
}
return
nil
}),
backendmock
.
WithEstimateGasFunc
(
func
(
ctx
context
.
Context
,
call
ethereum
.
CallMsg
)
(
gas
uint64
,
err
error
)
{
if
call
.
To
!=
nil
{
t
.
Fatalf
(
"estimating with recipient. wanted nil, got %x"
,
call
.
To
)
}
if
!
bytes
.
Equal
(
call
.
Data
,
txData
)
{
t
.
Fatal
(
"estimating with wrong data"
)
}
return
estimatedGasLimit
,
nil
}),
backendmock
.
WithSuggestGasPriceFunc
(
func
(
ctx
context
.
Context
)
(
*
big
.
Int
,
error
)
{
return
suggestedGasPrice
,
nil
}),
backendmock
.
WithPendingNonceAtFunc
(
func
(
ctx
context
.
Context
,
account
common
.
Address
)
(
uint64
,
error
)
{
return
nonce
,
nil
}),
),
signermock
.
New
(
signermock
.
WithSignTxFunc
(
func
(
transaction
*
types
.
Transaction
)
(
*
types
.
Transaction
,
error
)
{
if
transaction
.
To
()
!=
nil
{
t
.
Fatalf
(
"signing transaction with recipient. wanted nil, got %x"
,
transaction
.
To
())
}
if
!
bytes
.
Equal
(
transaction
.
Data
(),
txData
)
{
t
.
Fatalf
(
"signing transaction with wrong data. wanted %x, got %x"
,
txData
,
transaction
.
Data
())
}
if
transaction
.
Value
()
.
Cmp
(
value
)
!=
0
{
t
.
Fatalf
(
"signing transaction with wrong value. wanted %d, got %d"
,
value
,
transaction
.
Value
())
}
if
transaction
.
Gas
()
!=
estimatedGasLimit
{
t
.
Fatalf
(
"signing transaction with wrong gas. wanted %d, got %d"
,
estimatedGasLimit
,
transaction
.
Gas
())
}
if
transaction
.
GasPrice
()
.
Cmp
(
suggestedGasPrice
)
!=
0
{
t
.
Fatalf
(
"signing transaction with wrong gasprice. wanted %d, got %d"
,
suggestedGasPrice
,
transaction
.
GasPrice
())
}
if
transaction
.
Nonce
()
!=
nonce
{
t
.
Fatalf
(
"signing transaction with wrong nonce. wanted %d, got %d"
,
nonce
,
transaction
.
Nonce
())
}
return
signedTx
,
nil
}),
),
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
txHash
,
err
:=
transactionService
.
Send
(
context
.
Background
(),
request
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
bytes
.
Equal
(
txHash
.
Bytes
(),
signedTx
.
Hash
()
.
Bytes
())
{
t
.
Fatal
(
"returning wrong transaction hash"
)
}
}
func
TestTransactionWaitForReceipt
(
t
*
testing
.
T
)
{
logger
:=
logging
.
New
(
ioutil
.
Discard
,
0
)
txHash
:=
common
.
HexToHash
(
"0xabcdee"
)
...
...
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