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
5d367b92
Commit
5d367b92
authored
Aug 16, 2021
by
hezhengjun
Committed by
33cn
Aug 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct gas estimate
parent
335ef569
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
30 deletions
+24
-30
query.go
plugin/dapp/evm/executor/query.go
+17
-28
message.go
plugin/dapp/evm/executor/vm/common/message.go
+5
-0
types.go
plugin/dapp/evm/types/types.go
+2
-2
No files found.
plugin/dapp/evm/executor/query.go
View file @
5d367b92
...
...
@@ -54,43 +54,32 @@ func (evm *EVMExecutor) Query_CheckAddrExists(in *evmtypes.CheckEVMAddrReq) (typ
}
// Query_EstimateGas 此方法用来估算合约消耗的Gas,不能修改原有执行器的状态数据
func
(
evm
*
EVMExecutor
)
Query_EstimateGas
(
in
*
evmtypes
.
EstimateEVMGasReq
)
(
types
.
Message
,
error
)
{
func
(
evm
*
EVMExecutor
)
Query_EstimateGas
(
tx
*
types
.
Transaction
)
(
types
.
Message
,
error
)
{
evm
.
CheckInit
()
var
(
caller
evmCommon
.
Address
)
cfg
:=
evm
.
GetAPI
()
.
GetConfig
()
// 如果未指定调用地址,则直接使用一个虚拟的地址发起调用
if
len
(
in
.
Caller
)
>
0
{
callAddr
:=
evmCommon
.
StringToAddress
(
in
.
Caller
)
if
callAddr
!=
nil
{
caller
=
*
callAddr
}
}
else
{
caller
=
evmCommon
.
ExecAddress
(
cfg
.
ExecName
(
evmtypes
.
ExecutorName
))
}
to
:=
evmCommon
.
StringToAddress
(
in
.
To
)
if
to
==
nil
{
to
=
evmCommon
.
StringToAddress
(
EvmAddress
)
index
:=
0
msg
,
err
:=
evm
.
GetMessage
(
tx
,
index
)
if
err
!=
nil
{
return
nil
,
err
}
msg
:=
evmCommon
.
NewMessage
(
caller
,
to
,
0
,
in
.
Amount
,
evmtypes
.
MaxGasLimit
,
1
,
nil
,
in
.
Para
,
"estimateGas"
)
txHash
:=
evmCommon
.
BigToHash
(
big
.
NewInt
(
evmtypes
.
MaxGasLimit
))
.
Bytes
()
receipt
,
err
:=
evm
.
innerExec
(
msg
,
txHash
,
1
,
evmtypes
.
MaxGasLimit
,
false
)
msg
.
SetGasLimit
(
evmtypes
.
MaxGasLimit
)
receipt
,
err
:=
evm
.
innerExec
(
msg
,
tx
.
Hash
(),
index
,
evmtypes
.
MaxGasLimit
,
true
)
if
err
!=
nil
{
return
nil
,
err
}
if
receipt
.
Ty
=
=
types
.
ExecOk
{
callData
:=
getCallReceipt
(
receipt
.
GetLogs
()
)
if
callData
!=
nil
{
result
:=
&
evmtypes
.
EstimateEVMGasResp
{}
result
.
Gas
=
callData
.
UsedGas
return
result
,
nil
}
if
receipt
.
Ty
!
=
types
.
ExecOk
{
return
nil
,
errors
.
New
(
"contract call error"
)
}
callData
:=
getCallReceipt
(
receipt
.
GetLogs
())
if
callData
==
nil
{
return
nil
,
errors
.
New
(
"nil receipt"
)
}
return
nil
,
errors
.
New
(
"contract call error"
)
result
:=
&
evmtypes
.
EstimateEVMGasResp
{}
result
.
Gas
=
callData
.
UsedGas
return
result
,
nil
}
// 从日志中查找调用结果
...
...
plugin/dapp/evm/executor/vm/common/message.go
View file @
5d367b92
...
...
@@ -54,6 +54,11 @@ func (m Message) Data() []byte { return m.data }
// GasLimit Gas限制
func
(
m
Message
)
GasLimit
()
uint64
{
return
m
.
gasLimit
}
// GasLimit Gas限制
func
(
m
Message
)
SetGasLimit
(
gasLimit
uint64
)
{
m
.
gasLimit
=
gasLimit
}
// Alias 合约别名
func
(
m
Message
)
Alias
()
string
{
return
m
.
alias
}
...
...
plugin/dapp/evm/types/types.go
View file @
5d367b92
...
...
@@ -27,8 +27,8 @@ const (
// TyLogEVMEventData 合约生成新的event日志数据
TyLogEVMEventData
=
605
// MaxGasLimit 最大Gas消耗上限
MaxGasLimit
=
10000000
// MaxGasLimit 最大Gas消耗上限
100
MaxGasLimit
=
(
100000000
*
100
)
)
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