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
59965d2c
Commit
59965d2c
authored
Nov 12, 2021
by
hezhengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
both support unpack input,output and event via rpc
parent
eaa3aae3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
13 deletions
+18
-13
api.go
plugin/dapp/evm/executor/abi/api.go
+13
-8
query.go
plugin/dapp/evm/executor/query.go
+1
-1
query_test.go
plugin/dapp/evm/executor/query_test.go
+4
-4
No files found.
plugin/dapp/evm/executor/abi/api.go
View file @
59965d2c
...
...
@@ -177,8 +177,8 @@ func UnpackInput(data []byte, methodName, abiData string) (output []*Param, err
return
output
,
errors
.
New
(
"Not consistent method"
)
}
if
method
.
Inputs
.
LengthNonIndexed
()
=
=
0
{
return
output
,
err
if
len
(
data
[
4
:
])
%
32
!
=
0
{
return
output
,
err
ors
.
New
(
"UnpackOutputOrEvent: improperly formatted output"
)
}
values
,
err
:=
method
.
Inputs
.
UnpackValues
(
data
[
4
:
])
...
...
@@ -202,7 +202,8 @@ func UnpackInput(data []byte, methodName, abiData string) (output []*Param, err
return
}
func
UnpackOutputOrEvent
(
data
[]
byte
,
name
,
abiData
string
)
(
output
[]
*
Param
,
err
error
)
{
//同时支持input,output和event三种数据的unpack
func
UnpackAllTypes
(
data
[]
byte
,
name
,
abiData
string
)
(
output
[]
*
Param
,
err
error
)
{
if
len
(
data
)
==
0
{
log
.
Info
(
"Unpack"
,
"Data len"
,
0
,
"name"
,
name
)
return
output
,
err
...
...
@@ -216,16 +217,20 @@ func UnpackOutputOrEvent(data []byte, name, abiData string) (output []*Param, er
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"
)
if
len
(
data
)
%
32
==
0
{
values
,
err
=
method
.
Outputs
.
UnpackValues
(
data
)
arguments
=
method
.
Outputs
}
else
if
len
(
data
[
4
:
])
%
32
==
0
{
values
,
err
=
method
.
Inputs
.
UnpackValues
(
data
[
4
:
])
arguments
=
method
.
Inputs
}
else
{
return
output
,
errors
.
New
(
"UnpackAllTypes: improperly formatted data"
)
}
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
(
"Unpack
OutputOrEvent
: could not locate named method or event"
)
return
output
,
errors
.
New
(
"Unpack
AllTypes
: could not locate named method or event"
)
}
if
err
!=
nil
{
...
...
plugin/dapp/evm/executor/query.go
View file @
59965d2c
...
...
@@ -204,7 +204,7 @@ func (evm *EVMExecutor) Query_GetUnpackData(in *evmtypes.EvmGetUnpackDataReq) (t
return
nil
,
errors
.
New
(
"common.FromHex failed due to:"
+
err
.
Error
())
}
outputs
,
err
:=
evmAbi
.
Unpack
OutputOrEvent
(
data
,
in
.
Name
,
in
.
Abi
)
outputs
,
err
:=
evmAbi
.
Unpack
AllTypes
(
data
,
in
.
Name
,
in
.
Abi
)
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"unpack evm return error"
+
err
.
Error
())
}
...
...
plugin/dapp/evm/executor/query_test.go
View file @
59965d2c
...
...
@@ -40,7 +40,7 @@ func Test_UnpackEvent(t *testing.T) {
packData
,
err
:=
common
.
FromHex
(
"0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000098968100000000000000000000000000000000000000000000000000000000009896820000000000000000000000000000000000000000000000000000000000989683000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000c800000000000000000000000000000000000000000000000000000000000000c800000000000000000000000000000000000000000000000000000000000000c8"
)
assert
.
Equal
(
t
,
nil
,
err
)
outputs
,
err
:=
evmAbi
.
Unpack
OutputOrEvent
(
packData
,
"TransferToken"
,
abiStr
)
outputs
,
err
:=
evmAbi
.
Unpack
AllTypes
(
packData
,
"TransferToken"
,
abiStr
)
assert
.
Equal
(
t
,
nil
,
err
)
for
i
,
info
:=
range
outputs
{
fmt
.
Println
(
i
,
"th info = "
,
info
)
...
...
@@ -55,7 +55,7 @@ func Test_UnpackEventLock(t *testing.T) {
packData
,
err
:=
common
.
FromHex
(
"0x000000000000000000000000809b923eea05ad681a0ec1459e613cd7af7f5f1800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000001dcd650000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000014bc333839e37bc7faad0137abae2275030555101f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000034254590000000000000000000000000000000000000000000000000000000000"
)
assert
.
Equal
(
t
,
nil
,
err
)
outputs
,
err
:=
evmAbi
.
Unpack
OutputOrEvent
(
packData
,
"LogLock"
,
BridgeBankABI
)
outputs
,
err
:=
evmAbi
.
Unpack
AllTypes
(
packData
,
"LogLock"
,
BridgeBankABI
)
assert
.
Equal
(
t
,
nil
,
err
)
for
i
,
info
:=
range
outputs
{
fmt
.
Println
(
i
,
"th info = "
,
info
)
...
...
@@ -78,7 +78,7 @@ func Test_UnpackEventLockOfBridgevmxgo(t *testing.T) {
packData
,
err
:=
common
.
FromHex
(
"0x000000000000000000000000143b825fde7a42043b2cedef6b4c6f57c04d71b70000000000000000000000006fd2a3693c289b6c3c211f5d2f85ce145d1afaeb00000000000000000000000058b1edde0fc37c0f7f4a23d1c2df488ec5df0fe100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000001dcd6500000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000034554480000000000000000000000000000000000000000000000000000000000"
)
assert
.
Equal
(
t
,
nil
,
err
)
outputs
,
err
:=
evmAbi
.
Unpack
OutputOrEvent
(
packData
,
"LogLock"
,
BridgeBankABIBridgevmxgo
)
outputs
,
err
:=
evmAbi
.
Unpack
AllTypes
(
packData
,
"LogLock"
,
BridgeBankABIBridgevmxgo
)
assert
.
Equal
(
t
,
nil
,
err
)
for
i
,
info
:=
range
outputs
{
fmt
.
Println
(
i
,
"th info = "
,
info
)
...
...
@@ -101,7 +101,7 @@ func Test_UnpackInputLockOfBridgevmxgo(t *testing.T) {
//000000000000000000000000000000000000000000000000000000001dcd6500
assert
.
Equal
(
t
,
nil
,
err
)
outputs
,
err
:=
evmAbi
.
Unpack
Input
(
packData
,
"lock"
,
BridgeBankABIBridgevmxgo
)
outputs
,
err
:=
evmAbi
.
Unpack
AllTypes
(
packData
,
"lock"
,
BridgeBankABIBridgevmxgo
)
assert
.
Equal
(
t
,
nil
,
err
)
for
i
,
info
:=
range
outputs
{
fmt
.
Println
(
i
,
"th info = "
,
info
)
...
...
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