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
15c55973
Commit
15c55973
authored
Aug 18, 2021
by
hezhengjun
Committed by
33cn
Aug 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simply evm gas estimate procedure
parent
9a2b1688
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
33 deletions
+22
-33
test-rpc.sh
plugin/dapp/evm/cmd/test/test-rpc.sh
+7
-19
exec.go
plugin/dapp/evm/executor/exec.go
+9
-3
query.go
plugin/dapp/evm/executor/query.go
+4
-7
evmcontract.proto
plugin/dapp/evm/proto/evmcontract.proto
+2
-4
evmcontract.pb.go
plugin/dapp/evm/types/evmcontract.pb.go
+0
-0
No files found.
plugin/dapp/evm/cmd/test/test-rpc.sh
View file @
15c55973
...
@@ -23,25 +23,13 @@ gas=0
...
@@ -23,25 +23,13 @@ gas=0
evm_SignTxAndEstimate
()
{
evm_SignTxAndEstimate
()
{
gas
=
0
gas
=
0
local
txHex
=
"
$1
"
local
txHex
=
"
$1
"
local
priKey
=
"
$2
"
local
from
=
$2
local
MAIN_HTTP
=
$3
local
MAIN_HTTP
=
$3
local
expire
=
"120s"
if
[
-n
"
$4
"
]
;
then
expire
=
$4
fi
local
req
=
'"method":"Chain33.SignRawTx","params":[{"privkey":"'
"
$priKey
"
'","txHex":"'
"
$txHex
"
'","expire":"'
"
$expire
"
'"}]'
signedTx
=
$(
curl
-ksd
"{
$req
}"
"
${
MAIN_HTTP
}
"
| jq
-r
".result"
)
if
[
"
$signedTx
"
!=
null
]
;
then
req
=
'{"method":"Chain33.Query","params":[{"execer":"evm","funcName":"EstimateGas","payload":{"tx":"'
${
txHex
}
'", "from":"'
${
from
}
'"}}]}'
req
=
'{"method":"Chain33.Query","params":[{"execer":"evm","funcName":"EstimateGas","payload":{"data":"'
${
signedTx
}
'"}}]}'
chain33_Http
"
$req
"
"
${
MAIN_HTTP
}
"
'(.result != null)'
"EstimateGas"
".result.gas"
chain33_Http
"
$req
"
"
${
MAIN_HTTP
}
"
'(.result != null)'
"EstimateGas"
".result.gas"
gas
=
$((
RETURN_RESP
+
10000
))
gas
=
$((
RETURN_RESP
+
10000
))
echo
"the estimate gas is =
${
gas
}
"
echo
"the estimate gas is =
${
gas
}
"
else
echo
"signedTx null error"
fi
}
}
#上述未签名交易使用以下指令进行创建
#上述未签名交易使用以下指令进行创建
...
@@ -49,7 +37,7 @@ evm_SignTxAndEstimate() {
...
@@ -49,7 +37,7 @@ evm_SignTxAndEstimate() {
function
evm_createContract
()
{
function
evm_createContract
()
{
expire
=
"120s"
expire
=
"120s"
tx
=
$(
curl
-ksd
'{"method":"evm.CreateDeployTx","params":[{"code":"'
${
erc20_code
}
'", "abi":"'
"
${
erc20_abi
}
"
'", "note": "deploy erc20", "alias": "zbc", "parameter": "constructor(zbc, zbc, 3300, '
${
evm_creatorAddr
}
')", "expire":"'
${
expire
}
'", "paraName":"'
"
${
paraName
}
"
'", "amount":0}]}'
"
${
MAIN_HTTP
}
"
| jq
-r
".result"
)
tx
=
$(
curl
-ksd
'{"method":"evm.CreateDeployTx","params":[{"code":"'
${
erc20_code
}
'", "abi":"'
"
${
erc20_abi
}
"
'", "note": "deploy erc20", "alias": "zbc", "parameter": "constructor(zbc, zbc, 3300, '
${
evm_creatorAddr
}
')", "expire":"'
${
expire
}
'", "paraName":"'
"
${
paraName
}
"
'", "amount":0}]}'
"
${
MAIN_HTTP
}
"
| jq
-r
".result"
)
evm_SignTxAndEstimate
"
${
tx
}
"
"
${
evm_creatorAddr
_key
}
"
"
$MAIN_HTTP
"
"
${
expire
}
"
evm_SignTxAndEstimate
"
${
tx
}
"
"
${
evm_creatorAddr
}
"
"
$MAIN_HTTP
"
echo
"evm_createContract :: the estimate gas is =
${
gas
}
"
echo
"evm_createContract :: the estimate gas is =
${
gas
}
"
tx
=
$(
curl
-ksd
'{"method":"evm.CreateDeployTx","params":[{"code":"'
${
erc20_code
}
'", "abi":"'
"
${
erc20_abi
}
"
'", "fee":'
${
gas
}
', "note": "deploy erc20", "alias": "zbc", "parameter": "constructor(zbc, zbc, 3300, '
${
evm_creatorAddr
}
')", "expire":"'
${
expire
}
'", "paraName":"'
"
${
paraName
}
"
'", "amount":0}]}'
"
${
MAIN_HTTP
}
"
| jq
-r
".result"
)
tx
=
$(
curl
-ksd
'{"method":"evm.CreateDeployTx","params":[{"code":"'
${
erc20_code
}
'", "abi":"'
"
${
erc20_abi
}
"
'", "fee":'
${
gas
}
', "note": "deploy erc20", "alias": "zbc", "parameter": "constructor(zbc, zbc, 3300, '
${
evm_creatorAddr
}
')", "expire":"'
${
expire
}
'", "paraName":"'
"
${
paraName
}
"
'", "amount":0}]}'
"
${
MAIN_HTTP
}
"
| jq
-r
".result"
)
...
@@ -96,7 +84,7 @@ function evm_transfer() {
...
@@ -96,7 +84,7 @@ function evm_transfer() {
expire
=
"120s"
expire
=
"120s"
tx
=
$(
curl
-ksd
'{"method":"evm.CreateCallTx","params":[{"abi":"'
"
${
erc20_abi
}
"
'", "note": "evm transfer rpc test", "parameter": "transfer('
${
evm_transferAddr
}
', 20)", "expire":"'
${
expire
}
'", "contractAddr":"'
"
${
evm_contractAddr
}
"
'", "paraName":"'
"
${
paraName
}
"
'"}]}'
"
${
MAIN_HTTP
}
"
| jq
-r
".result"
)
tx
=
$(
curl
-ksd
'{"method":"evm.CreateCallTx","params":[{"abi":"'
"
${
erc20_abi
}
"
'", "note": "evm transfer rpc test", "parameter": "transfer('
${
evm_transferAddr
}
', 20)", "expire":"'
${
expire
}
'", "contractAddr":"'
"
${
evm_contractAddr
}
"
'", "paraName":"'
"
${
paraName
}
"
'"}]}'
"
${
MAIN_HTTP
}
"
| jq
-r
".result"
)
evm_SignTxAndEstimate
"
${
tx
}
"
"
${
evm_creatorAddr
_key
}
"
"
$MAIN_HTTP
"
"
${
expire
}
"
evm_SignTxAndEstimate
"
${
tx
}
"
"
${
evm_creatorAddr
}
"
"
$MAIN_HTTP
"
# shellcheck disable=SC2090
# shellcheck disable=SC2090
tx
=
$(
curl
-ksd
'{"method":"evm.CreateCallTx","params":[{"abi":"'
"
${
erc20_abi
}
"
'", "fee":'
${
gas
}
', "note": "evm transfer rpc test", "parameter": "transfer('
${
evm_transferAddr
}
', 20)", "expire":"'
${
expire
}
'", "contractAddr":"'
"
${
evm_contractAddr
}
"
'", "paraName":"'
"
${
paraName
}
"
'"}]}'
"
${
MAIN_HTTP
}
"
| jq
-r
".result"
)
tx
=
$(
curl
-ksd
'{"method":"evm.CreateCallTx","params":[{"abi":"'
"
${
erc20_abi
}
"
'", "fee":'
${
gas
}
', "note": "evm transfer rpc test", "parameter": "transfer('
${
evm_transferAddr
}
', 20)", "expire":"'
${
expire
}
'", "contractAddr":"'
"
${
evm_contractAddr
}
"
'", "paraName":"'
"
${
paraName
}
"
'"}]}'
"
${
MAIN_HTTP
}
"
| jq
-r
".result"
)
...
...
plugin/dapp/evm/executor/exec.go
View file @
15c55973
...
@@ -25,7 +25,7 @@ import (
...
@@ -25,7 +25,7 @@ import (
func
(
evm
*
EVMExecutor
)
Exec
(
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
evm
*
EVMExecutor
)
Exec
(
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
evm
.
CheckInit
()
evm
.
CheckInit
()
// 先转换消息
// 先转换消息
msg
,
err
:=
evm
.
GetMessage
(
tx
,
index
)
msg
,
err
:=
evm
.
GetMessage
(
tx
,
index
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -190,14 +190,20 @@ func (evm *EVMExecutor) CheckInit() {
...
@@ -190,14 +190,20 @@ func (evm *EVMExecutor) CheckInit() {
}
}
// GetMessage 目前的交易中,如果是coins交易,金额是放在payload的,但是合约不行,需要修改Transaction结构
// GetMessage 目前的交易中,如果是coins交易,金额是放在payload的,但是合约不行,需要修改Transaction结构
func
(
evm
*
EVMExecutor
)
GetMessage
(
tx
*
types
.
Transaction
,
index
int
)
(
msg
*
common
.
Message
,
err
error
)
{
func
(
evm
*
EVMExecutor
)
GetMessage
(
tx
*
types
.
Transaction
,
index
int
,
fromPtr
*
common
.
Address
)
(
msg
*
common
.
Message
,
err
error
)
{
var
action
evmtypes
.
EVMContractAction
var
action
evmtypes
.
EVMContractAction
err
=
types
.
Decode
(
tx
.
Payload
,
&
action
)
err
=
types
.
Decode
(
tx
.
Payload
,
&
action
)
if
err
!=
nil
{
if
err
!=
nil
{
return
msg
,
err
return
msg
,
err
}
}
// 此处暂时不考虑消息发送签名的处理,chain33在mempool中对签名做了检查
// 此处暂时不考虑消息发送签名的处理,chain33在mempool中对签名做了检查
from
:=
getCaller
(
tx
)
var
from
common
.
Address
if
fromPtr
==
nil
{
from
=
getCaller
(
tx
)
}
else
{
from
=
*
fromPtr
}
to
:=
getReceiver
(
&
action
)
to
:=
getReceiver
(
&
action
)
if
to
==
nil
{
if
to
==
nil
{
return
msg
,
types
.
ErrInvalidAddress
return
msg
,
types
.
ErrInvalidAddress
...
...
plugin/dapp/evm/executor/query.go
View file @
15c55973
...
@@ -55,10 +55,10 @@ func (evm *EVMExecutor) Query_CheckAddrExists(in *evmtypes.CheckEVMAddrReq) (typ
...
@@ -55,10 +55,10 @@ func (evm *EVMExecutor) Query_CheckAddrExists(in *evmtypes.CheckEVMAddrReq) (typ
}
}
// Query_EstimateGas 此方法用来估算合约消耗的Gas,不能修改原有执行器的状态数据
// Query_EstimateGas 此方法用来估算合约消耗的Gas,不能修改原有执行器的状态数据
func
(
evm
*
EVMExecutor
)
Query_EstimateGas
(
txInfo
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
func
(
evm
*
EVMExecutor
)
Query_EstimateGas
(
req
*
evmtypes
.
EstimateEVMGasReq
)
(
types
.
Message
,
error
)
{
evm
.
CheckInit
()
evm
.
CheckInit
()
txBytes
,
err
:=
hex
.
DecodeString
(
txInfo
.
Data
)
txBytes
,
err
:=
hex
.
DecodeString
(
req
.
Tx
)
if
nil
!=
err
{
if
nil
!=
err
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -68,12 +68,9 @@ func (evm *EVMExecutor) Query_EstimateGas(txInfo *types.ReqString) (types.Messag
...
@@ -68,12 +68,9 @@ func (evm *EVMExecutor) Query_EstimateGas(txInfo *types.ReqString) (types.Messag
return
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
)
from
:=
evmCommon
.
StringToAddress
(
req
.
From
)
msg
,
err
:=
evm
.
GetMessage
(
&
tx
,
index
,
from
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
plugin/dapp/evm/proto/evmcontract.proto
View file @
15c55973
...
@@ -108,10 +108,8 @@ message CheckEVMAddrResp {
...
@@ -108,10 +108,8 @@ message CheckEVMAddrResp {
}
}
message
EstimateEVMGasReq
{
message
EstimateEVMGasReq
{
string
to
=
1
;
string
tx
=
1
;
bytes
para
=
2
;
string
from
=
2
;
string
caller
=
3
;
uint64
amount
=
4
;
}
}
message
EstimateEVMGasResp
{
message
EstimateEVMGasResp
{
uint64
gas
=
1
;
uint64
gas
=
1
;
...
...
plugin/dapp/evm/types/evmcontract.pb.go
View file @
15c55973
This diff is collapsed.
Click to expand it.
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