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
c1cd62b7
Commit
c1cd62b7
authored
Nov 11, 2021
by
hezhengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support unpack both of event and output
parent
abde63ec
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
19 deletions
+67
-19
test-rpc.sh
plugin/dapp/evm/cmd/test/test-rpc.sh
+2
-2
api.go
plugin/dapp/evm/executor/abi/api.go
+49
-0
query.go
plugin/dapp/evm/executor/query.go
+1
-1
evmcontract.proto
plugin/dapp/evm/proto/evmcontract.proto
+1
-1
evmcontract.pb.go
plugin/dapp/evm/types/evmcontract.pb.go
+14
-15
No files found.
plugin/dapp/evm/cmd/test/test-rpc.sh
View file @
c1cd62b7
...
@@ -54,7 +54,7 @@ function evm_callQuery() {
...
@@ -54,7 +54,7 @@ function evm_callQuery() {
local
parameter
=
$1
local
parameter
=
$1
local
callerAddr
=
$2
local
callerAddr
=
$2
local
resok
=
$3
local
resok
=
$3
local
methodN
ame
=
$4
local
n
ame
=
$4
req
=
'{"method":"Chain33.Query","params":[{"execer":"evm","funcName":"GetPackData","payload":{"abi":"'
${
erc20_abi
}
'","parameter":"'
${
parameter
}
'"}}]}'
req
=
'{"method":"Chain33.Query","params":[{"execer":"evm","funcName":"GetPackData","payload":{"abi":"'
${
erc20_abi
}
'","parameter":"'
${
parameter
}
'"}}]}'
chain33_Http
"
$req
"
"
${
MAIN_HTTP
}
"
'(.result != null)'
"GetPackData"
".result.packData"
chain33_Http
"
$req
"
"
${
MAIN_HTTP
}
"
'(.result != null)'
"GetPackData"
".result.packData"
...
@@ -64,7 +64,7 @@ function evm_callQuery() {
...
@@ -64,7 +64,7 @@ function evm_callQuery() {
chain33_Http
"
$req
"
"
${
MAIN_HTTP
}
"
'(.result != null)'
"Query"
".result.rawData"
chain33_Http
"
$req
"
"
${
MAIN_HTTP
}
"
'(.result != null)'
"Query"
".result.rawData"
echo
"
$RETURN_RESP
"
echo
"
$RETURN_RESP
"
req
=
'{"method":"Chain33.Query","params":[{"execer":"evm","funcName":"GetUnpackData","payload":{"abi":"'
${
erc20_abi
}
'","
methodName":"'
${
methodN
ame
}
'","data":"'
${
RETURN_RESP
}
'"}}]}'
req
=
'{"method":"Chain33.Query","params":[{"execer":"evm","funcName":"GetUnpackData","payload":{"abi":"'
${
erc20_abi
}
'","
name":"'
${
n
ame
}
'","data":"'
${
RETURN_RESP
}
'"}}]}'
chain33_Http
"
$req
"
"
${
MAIN_HTTP
}
"
'(.result != null)'
"GetUnpackData"
".result.unpackData[0]"
chain33_Http
"
$req
"
"
${
MAIN_HTTP
}
"
'(.result != null)'
"GetUnpackData"
".result.unpackData[0]"
echo
"
$RETURN_RESP
"
echo
"
$RETURN_RESP
"
...
...
plugin/dapp/evm/executor/abi/api.go
View file @
c1cd62b7
...
@@ -153,6 +153,55 @@ func Unpack(data []byte, methodName, abiData string) (output []*Param, err error
...
@@ -153,6 +153,55 @@ func Unpack(data []byte, methodName, abiData string) (output []*Param, err error
return
return
}
}
func
UnpackOutputOrEvent
(
data
[]
byte
,
name
,
abiData
string
)
(
output
[]
*
Param
,
err
error
)
{
if
len
(
data
)
==
0
{
log
.
Info
(
"Unpack"
,
"Data len"
,
0
,
"name"
,
name
)
return
output
,
err
}
// 解析ABI数据结构,获取本次调用的方法对象
abi
,
err
:=
JSON
(
strings
.
NewReader
(
abiData
))
if
err
!=
nil
{
return
output
,
err
}
values
:=
[]
interface
{}{}
var
arguments
Arguments
if
method
,
ok
:=
abi
.
Methods
[
name
];
ok
{
if
len
(
data
)
%
32
!=
0
{
return
output
,
errors
.
New
(
"UnpackOutputOrEvent: improperly formatted output"
)
}
values
,
err
=
method
.
Outputs
.
UnpackValues
(
data
)
arguments
=
method
.
Outputs
}
else
if
event
,
ok
:=
abi
.
Events
[
name
];
ok
{
values
,
err
=
event
.
Inputs
.
UnpackValues
(
data
)
arguments
=
event
.
Inputs
}
else
{
return
output
,
errors
.
New
(
"UnpackOutputOrEvent: could not locate named method or event"
)
}
if
err
!=
nil
{
return
output
,
err
}
if
len
(
arguments
)
==
0
||
len
(
values
)
!=
len
(
arguments
)
{
return
output
,
errors
.
New
(
"wrong data to unpack"
)
}
output
=
[]
*
Param
{}
for
i
,
v
:=
range
values
{
arg
:=
arguments
[
i
]
pval
:=
&
Param
{
Name
:
arg
.
Name
,
Type
:
arg
.
Type
.
String
(),
Value
:
v
}
if
arg
.
Type
.
String
()
==
"address"
{
pval
.
Value
=
v
.
(
common
.
Hash160Address
)
.
ToAddress
()
.
String
()
log
.
Info
(
"Unpack address"
,
"address"
,
pval
.
Value
)
}
output
=
append
(
output
,
pval
)
}
return
}
// Param 返回值参数结构定义
// Param 返回值参数结构定义
type
Param
struct
{
type
Param
struct
{
// Name 参数名称
// Name 参数名称
...
...
plugin/dapp/evm/executor/query.go
View file @
c1cd62b7
...
@@ -204,7 +204,7 @@ func (evm *EVMExecutor) Query_GetUnpackData(in *evmtypes.EvmGetUnpackDataReq) (t
...
@@ -204,7 +204,7 @@ func (evm *EVMExecutor) Query_GetUnpackData(in *evmtypes.EvmGetUnpackDataReq) (t
return
nil
,
errors
.
New
(
"common.FromHex failed due to:"
+
err
.
Error
())
return
nil
,
errors
.
New
(
"common.FromHex failed due to:"
+
err
.
Error
())
}
}
outputs
,
err
:=
evmAbi
.
Unpack
(
data
,
in
.
Method
Name
,
in
.
Abi
)
outputs
,
err
:=
evmAbi
.
Unpack
OutputOrEvent
(
data
,
in
.
Name
,
in
.
Abi
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"unpack evm return error"
+
err
.
Error
())
return
nil
,
errors
.
New
(
"unpack evm return error"
+
err
.
Error
())
}
}
...
...
plugin/dapp/evm/proto/evmcontract.proto
View file @
c1cd62b7
...
@@ -202,7 +202,7 @@ message EvmGetPackDataRespose {
...
@@ -202,7 +202,7 @@ message EvmGetPackDataRespose {
message
EvmGetUnpackDataReq
{
message
EvmGetUnpackDataReq
{
string
abi
=
1
;
string
abi
=
1
;
string
methodName
=
2
;
string
name
=
2
;
string
data
=
3
;
string
data
=
3
;
}
}
...
...
plugin/dapp/evm/types/evmcontract.pb.go
View file @
c1cd62b7
...
@@ -1866,9 +1866,9 @@ type EvmGetUnpackDataReq struct {
...
@@ -1866,9 +1866,9 @@ type EvmGetUnpackDataReq struct {
sizeCache
protoimpl
.
SizeCache
sizeCache
protoimpl
.
SizeCache
unknownFields
protoimpl
.
UnknownFields
unknownFields
protoimpl
.
UnknownFields
Abi
string
`protobuf:"bytes,1,opt,name=abi,proto3" json:"abi,omitempty"`
Abi
string
`protobuf:"bytes,1,opt,name=abi,proto3" json:"abi,omitempty"`
MethodName
string
`protobuf:"bytes,2,opt,name=methodName,proto3" json:"methodN
ame,omitempty"`
Name
string
`protobuf:"bytes,2,opt,name=name,proto3" json:"n
ame,omitempty"`
Data
string
`protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
Data
string
`protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
}
}
func
(
x
*
EvmGetUnpackDataReq
)
Reset
()
{
func
(
x
*
EvmGetUnpackDataReq
)
Reset
()
{
...
@@ -1910,9 +1910,9 @@ func (x *EvmGetUnpackDataReq) GetAbi() string {
...
@@ -1910,9 +1910,9 @@ func (x *EvmGetUnpackDataReq) GetAbi() string {
return
""
return
""
}
}
func
(
x
*
EvmGetUnpackDataReq
)
Get
Method
Name
()
string
{
func
(
x
*
EvmGetUnpackDataReq
)
GetName
()
string
{
if
x
!=
nil
{
if
x
!=
nil
{
return
x
.
Method
Name
return
x
.
Name
}
}
return
""
return
""
}
}
...
@@ -2173,18 +2173,17 @@ var file_evmcontract_proto_rawDesc = []byte{
...
@@ -2173,18 +2173,17 @@ var file_evmcontract_proto_rawDesc = []byte{
0x61
,
0x6d
,
0x65
,
0x74
,
0x65
,
0x72
,
0x22
,
0x33
,
0x0a
,
0x15
,
0x45
,
0x76
,
0x6d
,
0x47
,
0x65
,
0x74
,
0x61
,
0x6d
,
0x65
,
0x74
,
0x65
,
0x72
,
0x22
,
0x33
,
0x0a
,
0x15
,
0x45
,
0x76
,
0x6d
,
0x47
,
0x65
,
0x74
,
0x50
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x61
,
0x52
,
0x65
,
0x73
,
0x70
,
0x6f
,
0x73
,
0x65
,
0x12
,
0x50
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x61
,
0x52
,
0x65
,
0x73
,
0x70
,
0x6f
,
0x73
,
0x65
,
0x12
,
0x1a
,
0x0a
,
0x08
,
0x70
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x61
,
0x18
,
0x01
,
0x20
,
0x01
,
0x28
,
0x1a
,
0x0a
,
0x08
,
0x70
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x61
,
0x18
,
0x01
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x08
,
0x70
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x61
,
0x22
,
0x
5b
,
0x0a
,
0x13
,
0x45
,
0x09
,
0x52
,
0x08
,
0x70
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x61
,
0x22
,
0x
4f
,
0x0a
,
0x13
,
0x45
,
0x76
,
0x6d
,
0x47
,
0x65
,
0x74
,
0x55
,
0x6e
,
0x70
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x61
,
0x52
,
0x76
,
0x6d
,
0x47
,
0x65
,
0x74
,
0x55
,
0x6e
,
0x70
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x61
,
0x52
,
0x65
,
0x71
,
0x12
,
0x10
,
0x0a
,
0x03
,
0x61
,
0x62
,
0x69
,
0x18
,
0x01
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x65
,
0x71
,
0x12
,
0x10
,
0x0a
,
0x03
,
0x61
,
0x62
,
0x69
,
0x18
,
0x01
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x03
,
0x61
,
0x62
,
0x69
,
0x12
,
0x1e
,
0x0a
,
0x0a
,
0x6d
,
0x65
,
0x74
,
0x68
,
0x6f
,
0x64
,
0x4e
,
0x61
,
0x03
,
0x61
,
0x62
,
0x69
,
0x12
,
0x12
,
0x0a
,
0x04
,
0x6e
,
0x61
,
0x6d
,
0x65
,
0x18
,
0x02
,
0x20
,
0x01
,
0x6d
,
0x65
,
0x18
,
0x02
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x0a
,
0x6d
,
0x65
,
0x74
,
0x68
,
0x6f
,
0x64
,
0x28
,
0x09
,
0x52
,
0x04
,
0x6e
,
0x61
,
0x6d
,
0x65
,
0x12
,
0x12
,
0x0a
,
0x04
,
0x64
,
0x61
,
0x74
,
0x61
,
0x4e
,
0x61
,
0x6d
,
0x65
,
0x12
,
0x12
,
0x0a
,
0x04
,
0x64
,
0x61
,
0x74
,
0x61
,
0x18
,
0x03
,
0x20
,
0x01
,
0x18
,
0x03
,
0x20
,
0x01
,
0x28
,
0x09
,
0x52
,
0x04
,
0x64
,
0x61
,
0x74
,
0x61
,
0x22
,
0x39
,
0x0a
,
0x17
,
0x28
,
0x09
,
0x52
,
0x04
,
0x64
,
0x61
,
0x74
,
0x61
,
0x22
,
0x39
,
0x0a
,
0x17
,
0x45
,
0x76
,
0x6d
,
0x47
,
0x45
,
0x76
,
0x6d
,
0x47
,
0x65
,
0x74
,
0x55
,
0x6e
,
0x70
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x61
,
0x65
,
0x74
,
0x55
,
0x6e
,
0x70
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x61
,
0x52
,
0x65
,
0x73
,
0x70
,
0x52
,
0x65
,
0x73
,
0x70
,
0x6f
,
0x73
,
0x65
,
0x12
,
0x1e
,
0x0a
,
0x0a
,
0x75
,
0x6e
,
0x70
,
0x61
,
0x63
,
0x6f
,
0x73
,
0x65
,
0x12
,
0x1e
,
0x0a
,
0x0a
,
0x75
,
0x6e
,
0x70
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x61
,
0x18
,
0x01
,
0x20
,
0x03
,
0x28
,
0x09
,
0x52
,
0x0a
,
0x75
,
0x6e
,
0x70
,
0x61
,
0x18
,
0x01
,
0x20
,
0x03
,
0x28
,
0x09
,
0x52
,
0x0a
,
0x75
,
0x6e
,
0x70
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x63
,
0x6b
,
0x44
,
0x61
,
0x74
,
0x61
,
0x42
,
0x0a
,
0x5a
,
0x08
,
0x2e
,
0x2e
,
0x2f
,
0x74
,
0x79
,
0x61
,
0x74
,
0x61
,
0x42
,
0x0a
,
0x5a
,
0x08
,
0x2e
,
0x2e
,
0x2f
,
0x74
,
0x79
,
0x70
,
0x65
,
0x73
,
0x62
,
0x70
,
0x65
,
0x73
,
0x62
,
0x06
,
0x70
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x33
,
0x06
,
0x70
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x33
,
}
}
var
(
var
(
...
...
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