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
2fc7fa29
Unverified
Commit
2fc7fa29
authored
Aug 24, 2021
by
Ralph Pichler
Committed by
GitHub
Aug 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: remove use of some deprecated go-ethereum apis (#2421)
parent
0633417b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
135 deletions
+109
-135
signer_test.go
pkg/crypto/signer_test.go
+8
-1
sender_matcher_test.go
pkg/transaction/sender_matcher_test.go
+8
-1
transaction.go
pkg/transaction/transaction.go
+29
-50
transaction_test.go
pkg/transaction/transaction_test.go
+64
-83
No files found.
pkg/crypto/signer_test.go
View file @
2fc7fa29
...
@@ -103,7 +103,14 @@ func TestDefaultSignerSignTx(t *testing.T) {
...
@@ -103,7 +103,14 @@ func TestDefaultSignerSignTx(t *testing.T) {
chainID
:=
big
.
NewInt
(
10
)
chainID
:=
big
.
NewInt
(
10
)
tx
,
err
:=
signer
.
SignTx
(
types
.
NewTransaction
(
0
,
beneficiary
,
big
.
NewInt
(
0
),
21000
,
big
.
NewInt
(
1
),
[]
byte
{
1
}),
chainID
)
tx
,
err
:=
signer
.
SignTx
(
types
.
NewTx
(
&
types
.
LegacyTx
{
Nonce
:
0
,
To
:
&
beneficiary
,
Value
:
big
.
NewInt
(
0
),
Gas
:
21000
,
GasPrice
:
big
.
NewInt
(
1
),
Data
:
[]
byte
{
1
},
}),
chainID
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
...
pkg/transaction/sender_matcher_test.go
View file @
2fc7fa29
...
@@ -24,7 +24,14 @@ func TestMatchesSender(t *testing.T) {
...
@@ -24,7 +24,14 @@ func TestMatchesSender(t *testing.T) {
nonce
:=
uint64
(
2
)
nonce
:=
uint64
(
2
)
trx
:=
common
.
HexToAddress
(
"0x1"
)
.
Bytes
()
trx
:=
common
.
HexToAddress
(
"0x1"
)
.
Bytes
()
signedTx
:=
types
.
NewTransaction
(
nonce
,
recipient
,
value
,
estimatedGasLimit
,
suggestedGasPrice
,
txData
)
signedTx
:=
types
.
NewTx
(
&
types
.
LegacyTx
{
Nonce
:
nonce
,
To
:
&
recipient
,
Value
:
value
,
Gas
:
estimatedGasLimit
,
GasPrice
:
suggestedGasPrice
,
Data
:
txData
,
})
t
.
Run
(
"fail to retrieve tx from backend"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"fail to retrieve tx from backend"
,
func
(
t
*
testing
.
T
)
{
txByHash
:=
backendmock
.
WithTransactionByHashFunc
(
func
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
*
types
.
Transaction
,
bool
,
error
)
{
txByHash
:=
backendmock
.
WithTransactionByHashFunc
(
func
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
*
types
.
Transaction
,
bool
,
error
)
{
...
...
pkg/transaction/transaction.go
View file @
2fc7fa29
...
@@ -142,7 +142,7 @@ func (t *transactionService) Send(ctx context.Context, request *TxRequest) (txHa
...
@@ -142,7 +142,7 @@ func (t *transactionService) Send(ctx context.Context, request *TxRequest) (txHa
return
common
.
Hash
{},
err
return
common
.
Hash
{},
err
}
}
tx
,
err
:=
prepareTransaction
(
ctx
,
request
,
t
.
sender
,
t
.
backend
,
nonce
)
tx
,
err
:=
t
.
prepareTransaction
(
ctx
,
request
,
nonce
)
if
err
!=
nil
{
if
err
!=
nil
{
return
common
.
Hash
{},
err
return
common
.
Hash
{},
err
}
}
...
@@ -243,11 +243,11 @@ func (t *transactionService) StoredTransaction(txHash common.Hash) (*StoredTrans
...
@@ -243,11 +243,11 @@ func (t *transactionService) StoredTransaction(txHash common.Hash) (*StoredTrans
}
}
// prepareTransaction creates a signable transaction based on a request.
// prepareTransaction creates a signable transaction based on a request.
func
prepareTransaction
(
ctx
context
.
Context
,
request
*
TxRequest
,
from
common
.
Address
,
backend
Backend
,
nonce
uint64
)
(
tx
*
types
.
Transaction
,
err
error
)
{
func
(
t
*
transactionService
)
prepareTransaction
(
ctx
context
.
Context
,
request
*
TxRequest
,
nonce
uint64
)
(
tx
*
types
.
Transaction
,
err
error
)
{
var
gasLimit
uint64
var
gasLimit
uint64
if
request
.
GasLimit
==
0
{
if
request
.
GasLimit
==
0
{
gasLimit
,
err
=
backend
.
EstimateGas
(
ctx
,
ethereum
.
CallMsg
{
gasLimit
,
err
=
t
.
backend
.
EstimateGas
(
ctx
,
ethereum
.
CallMsg
{
From
:
from
,
From
:
t
.
sender
,
To
:
request
.
To
,
To
:
request
.
To
,
Data
:
request
.
Data
,
Data
:
request
.
Data
,
})
})
...
@@ -263,7 +263,7 @@ func prepareTransaction(ctx context.Context, request *TxRequest, from common.Add
...
@@ -263,7 +263,7 @@ func prepareTransaction(ctx context.Context, request *TxRequest, from common.Add
var
gasPrice
*
big
.
Int
var
gasPrice
*
big
.
Int
if
request
.
GasPrice
==
nil
{
if
request
.
GasPrice
==
nil
{
gasPrice
,
err
=
backend
.
SuggestGasPrice
(
ctx
)
gasPrice
,
err
=
t
.
backend
.
SuggestGasPrice
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -271,24 +271,14 @@ func prepareTransaction(ctx context.Context, request *TxRequest, from common.Add
...
@@ -271,24 +271,14 @@ func prepareTransaction(ctx context.Context, request *TxRequest, from common.Add
gasPrice
=
request
.
GasPrice
gasPrice
=
request
.
GasPrice
}
}
if
request
.
To
!=
nil
{
return
types
.
NewTx
(
&
types
.
LegacyTx
{
return
types
.
NewTransaction
(
Nonce
:
nonce
,
nonce
,
To
:
request
.
To
,
*
request
.
To
,
Value
:
request
.
Value
,
request
.
Value
,
Gas
:
gasLimit
,
gasLimit
,
GasPrice
:
gasPrice
,
gasPrice
,
Data
:
request
.
Data
,
request
.
Data
,
}),
nil
),
nil
}
return
types
.
NewContractCreation
(
nonce
,
request
.
Value
,
gasLimit
,
gasPrice
,
request
.
Data
,
),
nil
}
}
func
(
t
*
transactionService
)
nonceKey
()
string
{
func
(
t
*
transactionService
)
nonceKey
()
string
{
...
@@ -382,25 +372,14 @@ func (t *transactionService) ResendTransaction(ctx context.Context, txHash commo
...
@@ -382,25 +372,14 @@ func (t *transactionService) ResendTransaction(ctx context.Context, txHash commo
return
err
return
err
}
}
var
tx
*
types
.
Transaction
tx
:=
types
.
NewTx
(
&
types
.
LegacyTx
{
if
storedTransaction
.
To
!=
nil
{
Nonce
:
storedTransaction
.
Nonce
,
tx
=
types
.
NewTransaction
(
To
:
storedTransaction
.
To
,
storedTransaction
.
Nonce
,
Value
:
storedTransaction
.
Value
,
*
storedTransaction
.
To
,
Gas
:
storedTransaction
.
GasLimit
,
storedTransaction
.
Value
,
GasPrice
:
storedTransaction
.
GasPrice
,
storedTransaction
.
GasLimit
,
Data
:
storedTransaction
.
Data
,
storedTransaction
.
GasPrice
,
})
storedTransaction
.
Data
,
)
}
else
{
tx
=
types
.
NewContractCreation
(
storedTransaction
.
Nonce
,
storedTransaction
.
Value
,
storedTransaction
.
GasLimit
,
storedTransaction
.
GasPrice
,
storedTransaction
.
Data
,
)
}
signedTx
,
err
:=
t
.
signer
.
SignTx
(
tx
,
t
.
chainID
)
signedTx
,
err
:=
t
.
signer
.
SignTx
(
tx
,
t
.
chainID
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -433,14 +412,14 @@ func (t *transactionService) CancelTransaction(ctx context.Context, originalTxHa
...
@@ -433,14 +412,14 @@ func (t *transactionService) CancelTransaction(ctx context.Context, originalTxHa
return
common
.
Hash
{},
ErrGasPriceTooLow
return
common
.
Hash
{},
ErrGasPriceTooLow
}
}
signedTx
,
err
:=
t
.
signer
.
SignTx
(
types
.
NewT
ransaction
(
signedTx
,
err
:=
t
.
signer
.
SignTx
(
types
.
NewT
x
(
&
types
.
AccessListTx
{
storedTransaction
.
Nonce
,
Nonce
:
storedTransaction
.
Nonce
,
t
.
sender
,
To
:
&
t
.
sender
,
big
.
NewInt
(
0
),
Value
:
big
.
NewInt
(
0
),
21000
,
Gas
:
21000
,
gasPrice
,
GasPrice
:
gasPrice
,
[]
byte
{},
Data
:
[]
byte
{},
),
t
.
chainID
)
}
),
t
.
chainID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
common
.
Hash
{},
err
return
common
.
Hash
{},
err
}
}
...
...
pkg/transaction/transaction_test.go
View file @
2fc7fa29
...
@@ -82,7 +82,14 @@ func TestTransactionSend(t *testing.T) {
...
@@ -82,7 +82,14 @@ func TestTransactionSend(t *testing.T) {
chainID
:=
big
.
NewInt
(
5
)
chainID
:=
big
.
NewInt
(
5
)
t
.
Run
(
"send"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"send"
,
func
(
t
*
testing
.
T
)
{
signedTx
:=
types
.
NewTransaction
(
nonce
,
recipient
,
value
,
estimatedGasLimit
,
suggestedGasPrice
,
txData
)
signedTx
:=
types
.
NewTx
(
&
types
.
LegacyTx
{
Nonce
:
nonce
,
To
:
&
recipient
,
Value
:
value
,
Gas
:
estimatedGasLimit
,
GasPrice
:
suggestedGasPrice
,
Data
:
txData
,
})
request
:=
&
transaction
.
TxRequest
{
request
:=
&
transaction
.
TxRequest
{
To
:
&
recipient
,
To
:
&
recipient
,
Data
:
txData
,
Data
:
txData
,
...
@@ -193,7 +200,14 @@ func TestTransactionSend(t *testing.T) {
...
@@ -193,7 +200,14 @@ func TestTransactionSend(t *testing.T) {
})
})
t
.
Run
(
"send_no_nonce"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"send_no_nonce"
,
func
(
t
*
testing
.
T
)
{
signedTx
:=
types
.
NewTransaction
(
nonce
,
recipient
,
value
,
estimatedGasLimit
,
suggestedGasPrice
,
txData
)
signedTx
:=
types
.
NewTx
(
&
types
.
LegacyTx
{
Nonce
:
nonce
,
To
:
&
recipient
,
Value
:
value
,
Gas
:
estimatedGasLimit
,
GasPrice
:
suggestedGasPrice
,
Data
:
txData
,
})
request
:=
&
transaction
.
TxRequest
{
request
:=
&
transaction
.
TxRequest
{
To
:
&
recipient
,
To
:
&
recipient
,
Data
:
txData
,
Data
:
txData
,
...
@@ -256,7 +270,14 @@ func TestTransactionSend(t *testing.T) {
...
@@ -256,7 +270,14 @@ func TestTransactionSend(t *testing.T) {
t
.
Run
(
"send_skipped_nonce"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"send_skipped_nonce"
,
func
(
t
*
testing
.
T
)
{
nextNonce
:=
nonce
+
5
nextNonce
:=
nonce
+
5
signedTx
:=
types
.
NewTransaction
(
nextNonce
,
recipient
,
value
,
estimatedGasLimit
,
suggestedGasPrice
,
txData
)
signedTx
:=
types
.
NewTx
(
&
types
.
LegacyTx
{
Nonce
:
nextNonce
,
To
:
&
recipient
,
Value
:
value
,
Gas
:
estimatedGasLimit
,
GasPrice
:
suggestedGasPrice
,
Data
:
txData
,
})
request
:=
&
transaction
.
TxRequest
{
request
:=
&
transaction
.
TxRequest
{
To
:
&
recipient
,
To
:
&
recipient
,
Data
:
txData
,
Data
:
txData
,
...
@@ -319,58 +340,6 @@ func TestTransactionSend(t *testing.T) {
...
@@ -319,58 +340,6 @@ func TestTransactionSend(t *testing.T) {
t
.
Fatalf
(
"did not store nonce correctly. wanted %d, got %d"
,
nextNonce
+
1
,
storedNonce
)
t
.
Fatalf
(
"did not store nonce correctly. wanted %d, got %d"
,
nextNonce
+
1
,
storedNonce
)
}
}
})
})
t
.
Run
(
"deploy"
,
func
(
t
*
testing
.
T
)
{
signedTx
:=
types
.
NewContractCreation
(
nonce
,
value
,
estimatedGasLimit
,
suggestedGasPrice
,
txData
)
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
}),
),
signerMockForTransaction
(
signedTx
,
sender
,
chainID
,
t
),
storemock
.
NewStateStore
(),
chainID
,
monitormock
.
New
(),
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
transactionService
.
Close
()
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
)
{
func
TestTransactionWaitForReceipt
(
t
*
testing
.
T
)
{
...
@@ -444,7 +413,14 @@ func TestTransactionResend(t *testing.T) {
...
@@ -444,7 +413,14 @@ func TestTransactionResend(t *testing.T) {
store
:=
storemock
.
NewStateStore
()
store
:=
storemock
.
NewStateStore
()
defer
store
.
Close
()
defer
store
.
Close
()
signedTx
:=
types
.
NewTransaction
(
nonce
,
recipient
,
value
,
gasLimit
,
gasPrice
,
data
)
signedTx
:=
types
.
NewTx
(
&
types
.
LegacyTx
{
Nonce
:
nonce
,
To
:
&
recipient
,
Value
:
value
,
Gas
:
gasLimit
,
GasPrice
:
gasPrice
,
Data
:
data
,
})
err
:=
store
.
Put
(
transaction
.
StoredTransactionKey
(
signedTx
.
Hash
()),
transaction
.
StoredTransaction
{
err
:=
store
.
Put
(
transaction
.
StoredTransactionKey
(
signedTx
.
Hash
()),
transaction
.
StoredTransaction
{
Nonce
:
nonce
,
Nonce
:
nonce
,
...
@@ -496,7 +472,14 @@ func TestTransactionCancel(t *testing.T) {
...
@@ -496,7 +472,14 @@ func TestTransactionCancel(t *testing.T) {
store
:=
storemock
.
NewStateStore
()
store
:=
storemock
.
NewStateStore
()
defer
store
.
Close
()
defer
store
.
Close
()
signedTx
:=
types
.
NewTransaction
(
nonce
,
recipient
,
value
,
gasLimit
,
gasPrice
,
data
)
signedTx
:=
types
.
NewTx
(
&
types
.
LegacyTx
{
Nonce
:
nonce
,
To
:
&
recipient
,
Value
:
value
,
Gas
:
gasLimit
,
GasPrice
:
gasPrice
,
Data
:
data
,
})
err
:=
store
.
Put
(
transaction
.
StoredTransactionKey
(
signedTx
.
Hash
()),
transaction
.
StoredTransaction
{
err
:=
store
.
Put
(
transaction
.
StoredTransactionKey
(
signedTx
.
Hash
()),
transaction
.
StoredTransaction
{
Nonce
:
nonce
,
Nonce
:
nonce
,
To
:
&
recipient
,
To
:
&
recipient
,
...
@@ -510,14 +493,14 @@ func TestTransactionCancel(t *testing.T) {
...
@@ -510,14 +493,14 @@ func TestTransactionCancel(t *testing.T) {
}
}
t
.
Run
(
"ok"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"ok"
,
func
(
t
*
testing
.
T
)
{
cancelTx
:=
types
.
NewT
ransaction
(
cancelTx
:=
types
.
NewT
x
(
&
types
.
LegacyTx
{
nonce
,
Nonce
:
nonce
,
recipient
,
To
:
&
recipient
,
big
.
NewInt
(
0
),
Value
:
big
.
NewInt
(
0
),
21000
,
Gas
:
21000
,
new
(
big
.
Int
)
.
Add
(
gasPrice
,
big
.
NewInt
(
1
)),
GasPrice
:
new
(
big
.
Int
)
.
Add
(
gasPrice
,
big
.
NewInt
(
1
)),
[]
byte
{},
Data
:
[]
byte
{},
)
}
)
transactionService
,
err
:=
transaction
.
NewService
(
logger
,
transactionService
,
err
:=
transaction
.
NewService
(
logger
,
backendmock
.
New
(
backendmock
.
New
(
...
@@ -550,15 +533,14 @@ func TestTransactionCancel(t *testing.T) {
...
@@ -550,15 +533,14 @@ func TestTransactionCancel(t *testing.T) {
t
.
Run
(
"custom gas price"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"custom gas price"
,
func
(
t
*
testing
.
T
)
{
customGasPrice
:=
big
.
NewInt
(
5
)
customGasPrice
:=
big
.
NewInt
(
5
)
cancelTx
:=
types
.
NewTx
(
&
types
.
LegacyTx
{
cancelTx
:=
types
.
NewTransaction
(
Nonce
:
nonce
,
nonce
,
To
:
&
recipient
,
recipient
,
Value
:
big
.
NewInt
(
0
),
big
.
NewInt
(
0
),
Gas
:
21000
,
21000
,
GasPrice
:
customGasPrice
,
customGasPrice
,
Data
:
[]
byte
{},
[]
byte
{},
})
)
transactionService
,
err
:=
transaction
.
NewService
(
logger
,
transactionService
,
err
:=
transaction
.
NewService
(
logger
,
backendmock
.
New
(
backendmock
.
New
(
...
@@ -592,15 +574,14 @@ func TestTransactionCancel(t *testing.T) {
...
@@ -592,15 +574,14 @@ func TestTransactionCancel(t *testing.T) {
t
.
Run
(
"too low gas price"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"too low gas price"
,
func
(
t
*
testing
.
T
)
{
customGasPrice
:=
big
.
NewInt
(
0
)
customGasPrice
:=
big
.
NewInt
(
0
)
cancelTx
:=
types
.
NewTx
(
&
types
.
LegacyTx
{
cancelTx
:=
types
.
NewTransaction
(
Nonce
:
nonce
,
nonce
,
To
:
&
recipient
,
recipient
,
Value
:
big
.
NewInt
(
0
),
big
.
NewInt
(
0
),
Gas
:
21000
,
21000
,
GasPrice
:
customGasPrice
,
customGasPrice
,
Data
:
[]
byte
{},
[]
byte
{},
})
)
transactionService
,
err
:=
transaction
.
NewService
(
logger
,
transactionService
,
err
:=
transaction
.
NewService
(
logger
,
backendmock
.
New
(
backendmock
.
New
(
...
...
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