Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
link33
plugin
Commits
465913bc
Commit
465913bc
authored
Aug 17, 2021
by
hezhengjun
Committed by
33cn
Aug 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct gas estimate for command
parent
5d367b92
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
49 deletions
+32
-49
evm.go
plugin/dapp/evm/commands/evm.go
+13
-45
query.go
plugin/dapp/evm/executor/query.go
+17
-2
types.go
plugin/dapp/evm/types/types.go
+2
-2
No files found.
plugin/dapp/evm/commands/evm.go
View file @
465913bc
...
@@ -42,7 +42,7 @@ func EvmCmd() *cobra.Command {
...
@@ -42,7 +42,7 @@ func EvmCmd() *cobra.Command {
createContractCmd
(),
createContractCmd
(),
callContractCmd
(),
callContractCmd
(),
abiCmd
(),
abiCmd
(),
estimate
Contract
Cmd
(),
estimate
Gas
Cmd
(),
checkContractAddrCmd
(),
checkContractAddrCmd
(),
evmDebugCmd
(),
evmDebugCmd
(),
evmTransferCmd
(),
evmTransferCmd
(),
...
@@ -283,7 +283,6 @@ func createContract(cmd *cobra.Command, args []string) {
...
@@ -283,7 +283,6 @@ func createContract(cmd *cobra.Command, args []string) {
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
exector
),
Payload
:
types
.
Encode
(
&
action
),
Fee
:
0
,
To
:
action
.
ContractAddr
,
ChainID
:
chainID
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
exector
),
Payload
:
types
.
Encode
(
&
action
),
Fee
:
0
,
To
:
action
.
ContractAddr
,
ChainID
:
chainID
}
tx
.
Fee
,
_
=
tx
.
GetRealFee
(
cfg
.
GetMinTxFeeRate
())
tx
.
Fee
,
_
=
tx
.
GetRealFee
(
cfg
.
GetMinTxFeeRate
())
fmt
.
Println
(
"feeInt64 is"
,
feeInt64
)
if
tx
.
Fee
<
int64
(
feeInt64
)
{
if
tx
.
Fee
<
int64
(
feeInt64
)
{
tx
.
Fee
+=
int64
(
feeInt64
)
tx
.
Fee
+=
int64
(
feeInt64
)
}
}
...
@@ -499,38 +498,15 @@ func callAbi(cmd *cobra.Command, args []string) {
...
@@ -499,38 +498,15 @@ func callAbi(cmd *cobra.Command, args []string) {
}
}
}
}
func
estimateContract
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
estimateGas
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
input
,
_
:=
cmd
.
Flags
()
.
GetString
(
"input"
)
txStr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"tx"
)
name
,
_
:=
cmd
.
Flags
()
.
GetString
(
"exec"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
caller
,
_
:=
cmd
.
Flags
()
.
GetString
(
"caller"
)
txInfo
:=
&
types
.
ReqString
{
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
Data
:
txStr
,
path
,
_
:=
cmd
.
Flags
()
.
GetString
(
"path"
)
toAddr
:=
address
.
ExecAddress
(
"evm"
)
if
len
(
name
)
>
0
{
toAddr
=
address
.
ExecAddress
(
name
)
}
amountInt64
:=
uint64
(
amount
*
1e4
)
*
1e4
abiFileName
:=
path
+
name
+
".abi"
abiStr
,
err
:=
readFile
(
abiFileName
)
if
nil
!=
err
{
_
,
_
=
fmt
.
Fprintln
(
os
.
Stderr
,
"Can't read abi info, Pls set correct abi path and provide abi file as"
,
abiFileName
)
return
}
_
,
packedParameter
,
err
:=
evmAbi
.
Pack
(
input
,
abiStr
,
false
)
if
err
!=
nil
{
_
,
_
=
fmt
.
Fprintln
(
os
.
Stderr
,
"Failed to do para pack"
,
err
.
Error
())
return
}
}
var
estGasReq
=
evmtypes
.
EstimateEVMGasReq
{
To
:
toAddr
,
Para
:
packedParameter
,
Caller
:
caller
,
Amount
:
amountInt64
}
var
estGasResp
evmtypes
.
EstimateEVMGasResp
var
estGasResp
evmtypes
.
EstimateEVMGasResp
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
query
:=
sendQuery
(
rpcLaddr
,
"EstimateGas"
,
txInfo
,
&
estGasResp
)
query
:=
sendQuery
(
rpcLaddr
,
"EstimateGas"
,
&
estGasReq
,
&
estGasResp
)
if
query
{
if
query
{
fmt
.
Fprintf
(
os
.
Stdout
,
"gas cost estimate %v
\n
"
,
estGasResp
.
Gas
)
fmt
.
Fprintf
(
os
.
Stdout
,
"gas cost estimate %v
\n
"
,
estGasResp
.
Gas
)
}
else
{
}
else
{
...
@@ -538,27 +514,19 @@ func estimateContract(cmd *cobra.Command, args []string) {
...
@@ -538,27 +514,19 @@ func estimateContract(cmd *cobra.Command, args []string) {
}
}
}
}
func
addEstimateFlags
(
cmd
*
cobra
.
Command
)
{
func
addEstimateGasFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"input"
,
"i"
,
""
,
"input contract binary code"
)
cmd
.
Flags
()
.
StringP
(
"tx"
,
"x"
,
""
,
"tx string(should be signatured)"
)
cmd
.
MarkFlagRequired
(
"input"
)
_
=
cmd
.
MarkFlagRequired
(
"tx"
)
cmd
.
Flags
()
.
StringP
(
"exec"
,
"e"
,
""
,
"evm contract name (like user.evm.xxxxx)"
)
cmd
.
Flags
()
.
StringP
(
"caller"
,
"c"
,
""
,
"the caller address"
)
cmd
.
Flags
()
.
StringP
(
"path"
,
"t"
,
"./"
,
"abi path(optional), default to .(current directory)"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0
,
"the amount transfer to the contract (optional)"
)
}
}
// 估算合约消耗
// 估算合约消耗
func
estimate
Contract
Cmd
()
*
cobra
.
Command
{
func
estimate
Gas
Cmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"estimate"
,
Use
:
"estimate"
,
Short
:
"Estimate the gas cost of calling or creating a contract"
,
Short
:
"Estimate the gas cost of calling or creating a contract"
,
Run
:
estimate
Contract
,
Run
:
estimate
Gas
,
}
}
addEstimateFlags
(
cmd
)
addEstimate
Gas
Flags
(
cmd
)
return
cmd
return
cmd
}
}
...
...
plugin/dapp/evm/executor/query.go
View file @
465913bc
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
package
executor
package
executor
import
(
import
(
"encoding/hex"
"errors"
"errors"
"fmt"
"fmt"
"math/big"
"math/big"
...
@@ -54,11 +55,25 @@ func (evm *EVMExecutor) Query_CheckAddrExists(in *evmtypes.CheckEVMAddrReq) (typ
...
@@ -54,11 +55,25 @@ func (evm *EVMExecutor) Query_CheckAddrExists(in *evmtypes.CheckEVMAddrReq) (typ
}
}
// Query_EstimateGas 此方法用来估算合约消耗的Gas,不能修改原有执行器的状态数据
// Query_EstimateGas 此方法用来估算合约消耗的Gas,不能修改原有执行器的状态数据
func
(
evm
*
EVMExecutor
)
Query_EstimateGas
(
tx
*
types
.
Transaction
)
(
types
.
Message
,
error
)
{
func
(
evm
*
EVMExecutor
)
Query_EstimateGas
(
tx
Info
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
evm
.
CheckInit
()
evm
.
CheckInit
()
txBytes
,
err
:=
hex
.
DecodeString
(
txInfo
.
Data
)
if
nil
!=
err
{
return
nil
,
err
}
var
tx
types
.
Transaction
err
=
types
.
Decode
(
txBytes
,
&
tx
)
if
nil
!=
err
{
return
nil
,
err
}
if
nil
==
tx
.
Signature
{
return
nil
,
errors
.
New
(
"Tx should be signatured"
)
}
index
:=
0
index
:=
0
msg
,
err
:=
evm
.
GetMessage
(
tx
,
index
)
msg
,
err
:=
evm
.
GetMessage
(
&
tx
,
index
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
plugin/dapp/evm/types/types.go
View file @
465913bc
...
@@ -27,8 +27,8 @@ const (
...
@@ -27,8 +27,8 @@ const (
// TyLogEVMEventData 合约生成新的event日志数据
// TyLogEVMEventData 合约生成新的event日志数据
TyLogEVMEventData
=
605
TyLogEVMEventData
=
605
// MaxGasLimit 最大Gas消耗上限
100
// MaxGasLimit 最大Gas消耗上限
5
MaxGasLimit
=
(
100000000
*
100
)
MaxGasLimit
=
(
100000000
*
5
)
)
)
const
(
const
(
...
...
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