Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
张蕾
Geth-Modification
Commits
af96b664
Commit
af96b664
authored
Apr 30, 2019
by
gary rong
Committed by
Péter Szilágyi
Apr 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
internal/ethapi: estimate gas usage automatically (#19508)
parent
504f88b6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
8 deletions
+25
-8
api.go
internal/ethapi/api.go
+25
-8
No files found.
internal/ethapi/api.go
View file @
af96b664
...
@@ -1260,10 +1260,6 @@ type SendTxArgs struct {
...
@@ -1260,10 +1260,6 @@ type SendTxArgs struct {
// setDefaults is a helper function that fills in default values for unspecified tx fields.
// setDefaults is a helper function that fills in default values for unspecified tx fields.
func
(
args
*
SendTxArgs
)
setDefaults
(
ctx
context
.
Context
,
b
Backend
)
error
{
func
(
args
*
SendTxArgs
)
setDefaults
(
ctx
context
.
Context
,
b
Backend
)
error
{
if
args
.
Gas
==
nil
{
args
.
Gas
=
new
(
hexutil
.
Uint64
)
*
(
*
uint64
)(
args
.
Gas
)
=
90000
}
if
args
.
GasPrice
==
nil
{
if
args
.
GasPrice
==
nil
{
price
,
err
:=
b
.
SuggestPrice
(
ctx
)
price
,
err
:=
b
.
SuggestPrice
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -1296,15 +1292,37 @@ func (args *SendTxArgs) setDefaults(ctx context.Context, b Backend) error {
...
@@ -1296,15 +1292,37 @@ func (args *SendTxArgs) setDefaults(ctx context.Context, b Backend) error {
return
errors
.
New
(
`contract creation without any data provided`
)
return
errors
.
New
(
`contract creation without any data provided`
)
}
}
}
}
// Estimate the gas usage if necessary.
if
args
.
Gas
==
nil
{
// For backwards-compatibility reason, we try both input and data
// but input is preferred.
input
:=
args
.
Input
if
input
==
nil
{
input
=
args
.
Data
}
callArgs
:=
CallArgs
{
From
:
&
args
.
From
,
// From shouldn't be nil
To
:
args
.
To
,
GasPrice
:
args
.
GasPrice
,
Value
:
args
.
Value
,
Data
:
input
,
}
estimated
,
err
:=
DoEstimateGas
(
ctx
,
b
,
callArgs
,
rpc
.
PendingBlockNumber
,
b
.
RPCGasCap
())
if
err
!=
nil
{
return
err
}
args
.
Gas
=
&
estimated
log
.
Trace
(
"Estimate gas usage automatically"
,
"gas"
,
args
.
Gas
)
}
return
nil
return
nil
}
}
func
(
args
*
SendTxArgs
)
toTransaction
()
*
types
.
Transaction
{
func
(
args
*
SendTxArgs
)
toTransaction
()
*
types
.
Transaction
{
var
input
[]
byte
var
input
[]
byte
if
args
.
Data
!=
nil
{
if
args
.
Input
!=
nil
{
input
=
*
args
.
Data
}
else
if
args
.
Input
!=
nil
{
input
=
*
args
.
Input
input
=
*
args
.
Input
}
else
if
args
.
Data
!=
nil
{
input
=
*
args
.
Data
}
}
if
args
.
To
==
nil
{
if
args
.
To
==
nil
{
return
types
.
NewContractCreation
(
uint64
(
*
args
.
Nonce
),
(
*
big
.
Int
)(
args
.
Value
),
uint64
(
*
args
.
Gas
),
(
*
big
.
Int
)(
args
.
GasPrice
),
input
)
return
types
.
NewContractCreation
(
uint64
(
*
args
.
Nonce
),
(
*
big
.
Int
)(
args
.
Value
),
uint64
(
*
args
.
Gas
),
(
*
big
.
Int
)(
args
.
GasPrice
),
input
)
...
@@ -1334,7 +1352,6 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
...
@@ -1334,7 +1352,6 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
// SendTransaction creates a transaction for the given argument, sign it and submit it to the
// SendTransaction creates a transaction for the given argument, sign it and submit it to the
// transaction pool.
// transaction pool.
func
(
s
*
PublicTransactionPoolAPI
)
SendTransaction
(
ctx
context
.
Context
,
args
SendTxArgs
)
(
common
.
Hash
,
error
)
{
func
(
s
*
PublicTransactionPoolAPI
)
SendTransaction
(
ctx
context
.
Context
,
args
SendTxArgs
)
(
common
.
Hash
,
error
)
{
// Look up the wallet containing the requested signer
// Look up the wallet containing the requested signer
account
:=
accounts
.
Account
{
Address
:
args
.
From
}
account
:=
accounts
.
Account
{
Address
:
args
.
From
}
...
...
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