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
15672d56
Commit
15672d56
authored
Nov 11, 2021
by
hezhengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more check for mint
parent
de15b6e6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
176 additions
and
11 deletions
+176
-11
dockerRelayerTestEvm.sh
plugin/dapp/bridgevmxgo/cmd/build/dockerRelayerTestEvm.sh
+16
-0
api.go
plugin/dapp/evm/executor/abi/api.go
+49
-0
query_test.go
plugin/dapp/evm/executor/query_test.go
+40
-0
evmxgo.go
plugin/dapp/evmxgo/executor/evmxgo.go
+3
-3
evmxgodb.go
plugin/dapp/evmxgo/executor/evmxgodb.go
+1
-1
parse.go
plugin/dapp/evmxgo/executor/parse.go
+59
-4
evmxgo.proto
plugin/dapp/evmxgo/proto/evmxgo.proto
+8
-3
evmxgo.pb.go
plugin/dapp/evmxgo/types/evmxgo.pb.go
+0
-0
No files found.
plugin/dapp/bridgevmxgo/cmd/build/dockerRelayerTestEvm.sh
View file @
15672d56
...
...
@@ -802,6 +802,21 @@ function updateConfig() {
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
}
function
configbridgevmxgoAddr
()
{
local
bridgevmxgoAddr
=
$1
tx
=
$(
curl
-s
--data-binary
'{"jsonrpc":"2.0","id":2,"method":"Chain33.CreateTransaction","params":[{"execer":"manage","actionName":"Modify","payload":{"key":"bridgevmxgo-contract-addr","value":"{\"address\":\"'
"
${
bridgevmxgoAddr
}
"
'\"}","op":"add","addr":""}}]}'
-H
'content-type:text/plain;'
"http://127.0.0.1:8901"
| jq
-r
".result"
)
if
[
"
${
tx
}
"
==
""
]
;
then
echo
-e
"
${
RED
}
update config create tx 1
${
NOC
}
"
exit
1
fi
sign
=
$(${
Chain33Cli
}
wallet sign
-k
"
$chain33ReceiverAddrKey
"
-d
"
${
tx
}
"
)
hash
=
$(${
Chain33Cli
}
wallet send
-d
"
${
sign
}
"
)
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
}
function
TestETH2EVMToChain33
()
{
# 查询 ETH 这端 bridgeBank 地址原来是 0
result
=
$(${
CLIA
}
ethereum balance
-o
"
${
ethBridgeBank
}
"
)
...
...
@@ -826,6 +841,7 @@ function TestETH2EVMToChain33() {
# is_equal "${result}" "4700000000"
updateConfig
"ETH"
"
${
chain33EthBridgeTokenAddr
}
"
configbridgevmxgoAddr
"
${
XgoChain33BridgeBank
}
"
${
EvmxgoBoss4xCLI
}
chain33 offline approve_erc20
-a
330000000000
-s
"
${
XgoChain33BridgeBank
}
"
-c
"
${
chain33EthBridgeTokenAddr
}
"
-k
"
${
chain33ReceiverAddrKey
}
"
-f
1
--chainID
"
${
chain33ID
}
"
chain33_offline_send_evm
"approve_erc20.txt"
...
...
plugin/dapp/evm/executor/abi/api.go
View file @
15672d56
package
abi
import
(
"bytes"
"errors"
"fmt"
"math/big"
...
...
@@ -153,6 +154,54 @@ func Unpack(data []byte, methodName, abiData string) (output []*Param, err error
return
}
func
UnpackInput
(
data
[]
byte
,
methodName
,
abiData
string
)
(
output
[]
*
Param
,
err
error
)
{
if
len
(
data
)
<=
4
{
log
.
Info
(
"UnpackInput"
,
"Data len is not correct"
,
len
(
data
),
"methodName"
,
methodName
)
return
output
,
err
}
// 解析ABI数据结构,获取本次调用的方法对象
abi
,
err
:=
JSON
(
strings
.
NewReader
(
abiData
))
if
err
!=
nil
{
return
output
,
err
}
var
method
Method
var
ok
bool
if
method
,
ok
=
abi
.
Methods
[
methodName
];
!
ok
{
return
output
,
fmt
.
Errorf
(
"function %v not exists"
,
methodName
)
}
if
bytes
.
Compare
(
method
.
ID
,
data
[
:
4
])
!=
0
{
log
.
Info
(
"UnpackInput"
,
"methodID is not consistent method.ID"
,
common
.
Bytes2Hex
(
method
.
ID
),
"data[:4]"
,
common
.
Bytes2Hex
(
data
[
:
4
]))
return
output
,
errors
.
New
(
"Not consistent method"
)
}
if
method
.
Inputs
.
LengthNonIndexed
()
==
0
{
return
output
,
err
}
values
,
err
:=
method
.
Inputs
.
UnpackValues
(
data
[
4
:
])
if
err
!=
nil
{
return
output
,
err
}
output
=
[]
*
Param
{}
for
i
,
v
:=
range
values
{
arg
:=
method
.
Inputs
[
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
}
func
UnpackOutputOrEvent
(
data
[]
byte
,
name
,
abiData
string
)
(
output
[]
*
Param
,
err
error
)
{
if
len
(
data
)
==
0
{
log
.
Info
(
"Unpack"
,
"Data len"
,
0
,
"name"
,
name
)
...
...
plugin/dapp/evm/executor/query_test.go
View file @
15672d56
...
...
@@ -2,6 +2,7 @@ package executor
import
(
"fmt"
"math/big"
"testing"
"github.com/33cn/chain33/common"
...
...
@@ -83,3 +84,42 @@ func Test_UnpackEventLockOfBridgevmxgo(t *testing.T) {
fmt
.
Println
(
i
,
"th info = "
,
info
)
}
}
//'lock(1BCGLhdcdthNutQowV2YShuuN9fJRRGLxu, 195ycckxqnxyaQeLYTQvgETr1vsEp4NYmP, 500000000)'
//"7750c9f0": "lock(address,address,uint256)",
func
Test_UnpackInputLockOfBridgevmxgo
(
t
*
testing
.
T
)
{
methodName
,
packDataOrigin
,
err
:=
evmAbi
.
Pack
(
"lock(1BCGLhdcdthNutQowV2YShuuN9fJRRGLxu, 195ycckxqnxyaQeLYTQvgETr1vsEp4NYmP, 500000000)"
,
BridgeBankABIBridgevmxgo
,
false
)
assert
.
Equal
(
t
,
nil
,
err
)
fmt
.
Println
(
"methodName"
,
methodName
)
fmt
.
Println
(
"packDataOrigin"
,
common
.
ToHex
(
packDataOrigin
))
//event TransferToken(address owner, address to, uint256 tokenId, uint256 amount);
packData
,
err
:=
common
.
FromHex
(
"0x7750c9f00000000000000000000000006fd2a3693c289b6c3c211f5d2f85ce145d1afaeb00000000000000000000000058b1edde0fc37c0f7f4a23d1c2df488ec5df0fe1000000000000000000000000000000000000000000000000000000001dcd6500"
)
//7750c9f0
//0000000000000000000000006fd2a3693c289b6c3c211f5d2f85ce145d1afaeb
//00000000000000000000000058b1edde0fc37c0f7f4a23d1c2df488ec5df0fe1
//000000000000000000000000000000000000000000000000000000001dcd6500
assert
.
Equal
(
t
,
nil
,
err
)
outputs
,
err
:=
evmAbi
.
UnpackInput
(
packData
,
"lock"
,
BridgeBankABIBridgevmxgo
)
assert
.
Equal
(
t
,
nil
,
err
)
for
i
,
info
:=
range
outputs
{
fmt
.
Println
(
i
,
"th info = "
,
info
)
}
correct
:=
0
for
_
,
para
:=
range
outputs
{
switch
para
.
Name
{
case
"_recipient"
:
assert
.
Equal
(
t
,
para
.
Value
,
"1BCGLhdcdthNutQowV2YShuuN9fJRRGLxu"
)
correct
++
case
"_amount"
:
assert
.
Equal
(
t
,
para
.
Value
.
(
*
big
.
Int
)
.
Int64
(),
int64
(
500000000
))
correct
++
case
"_token"
:
assert
.
Equal
(
t
,
para
.
Value
,
"195ycckxqnxyaQeLYTQvgETr1vsEp4NYmP"
)
correct
++
}
}
assert
.
Equal
(
t
,
correct
,
3
)
}
plugin/dapp/evmxgo/executor/evmxgo.go
View file @
15672d56
...
...
@@ -15,8 +15,9 @@ import (
*/
const
(
mintPrefix
=
"evmxgo-mint-"
evmxgoAssetsPrefix
=
"LODB-evmxgo-assets:"
mintPrefix
=
"evmxgo-mint-"
evmxgoAssetsPrefix
=
"LODB-evmxgo-assets:"
bridgevmxgoAddrPrefix
=
"bridgevmxgo-contract-addr"
)
var
(
...
...
@@ -199,4 +200,3 @@ func (e *evmxgo) getBalance(req *types.ReqBalance) ([]*types.Account, error) {
return
accounts
,
nil
}
}
plugin/dapp/evmxgo/executor/evmxgodb.go
View file @
15672d56
...
...
@@ -256,7 +256,7 @@ func (action *evmxgoAction) mint(mint *evmxgotypes.EvmxgoMint, tx2lock *types.Tr
return
nil
,
types
.
ErrInvalidParam
}
cfg
:=
action
.
api
.
GetConfig
()
if
err
:=
checkMintPara
(
mint
,
tx2lock
);
nil
!=
err
{
if
err
:=
checkMintPara
(
mint
,
tx2lock
,
action
.
db
);
nil
!=
err
{
return
nil
,
err
}
...
...
plugin/dapp/evmxgo/executor/parse.go
View file @
15672d56
package
executor
import
(
"encoding/json"
"errors"
"math/big"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types"
bridgevmxgo
"github.com/33cn/plugin/plugin/dapp/bridgevmxgo/contracts/generated"
...
...
@@ -16,32 +20,83 @@ const (
//solidity interface: function lock(address _recipient, address _token, uint256 _amount)
//铸币交易的接收人必须与发起lock交易时填写的接收地址一致
func
checkMintPara
(
mint
*
evmxgotypes
.
EvmxgoMint
,
tx2lock
*
types
.
Transaction
)
error
{
func
checkMintPara
(
mint
*
evmxgotypes
.
EvmxgoMint
,
tx2lock
*
types
.
Transaction
,
db
dbm
.
KV
)
error
{
bridgevmxgoConfig
,
err
:=
loadBridgevmxgoAddr
(
db
)
if
nil
!=
err
{
return
err
}
var
action
evmtypes
.
EVMContractAction
if
err
:=
types
.
Decode
(
tx2lock
.
Payload
,
&
action
);
nil
!=
err
{
return
err
}
//确认合约地址的正确性
if
action
.
ContractAddr
!=
bridgevmxgoConfig
.
Address
{
return
errors
.
New
(
"Not consistent bridgevmxgo address configured by manager"
)
}
unpack
,
err
:=
chain33Abi
.
Unpack
(
action
.
Para
,
LockMethod
,
bridgevmxgo
.
BridgeBankABI
)
unpack
,
err
:=
chain33Abi
.
Unpack
Input
(
action
.
Para
,
LockMethod
,
bridgevmxgo
.
BridgeBankABI
)
if
err
!=
nil
{
return
err
}
correct
:=
0
for
_
,
para
:=
range
unpack
{
switch
para
.
Name
{
case
"_recipient"
:
if
mint
.
Recipient
!=
para
.
Value
{
return
errors
.
New
(
"Not consitent recipient address"
)
}
correct
++
case
"_amount"
:
if
mint
.
Amount
!=
para
.
Value
{
if
mint
.
Amount
!=
para
.
Value
.
(
*
big
.
Int
)
.
Int64
()
{
return
errors
.
New
(
"Not consitent Amount"
)
}
correct
++
case
"_token"
:
if
mint
.
BridgeToken
!=
para
.
Value
{
return
errors
.
New
(
"Not consitent token Address"
)
}
correct
++
}
}
if
correct
!=
3
{
return
errors
.
New
(
"not check all the points: _recipient, _amount, _token"
)
}
return
nil
}
func
loadBridgevmxgoAddr
(
db
dbm
.
KV
)
(
*
evmxgotypes
.
BridgevmxgoConfig
,
error
)
{
key
:=
bridgevmxgoAddrPrefix
value
,
err
:=
getManageKey
(
key
,
db
)
if
err
!=
nil
{
elog
.
Info
(
"loadBridgevmxgoAddr"
,
"get db key"
,
"not found"
,
"key"
,
key
)
return
nil
,
err
}
if
value
==
nil
{
elog
.
Info
(
"loadBridgevmxgoAddr"
,
"get db key"
,
" found nil value"
,
"key"
,
key
)
return
nil
,
nil
}
elog
.
Info
(
"loadBridgevmxgoAddr"
,
"value"
,
string
(
value
))
var
item
types
.
ConfigItem
err
=
types
.
Decode
(
value
,
&
item
)
if
err
!=
nil
{
elog
.
Error
(
"loadBridgevmxgoAddr load loadEvmxgoMintConfig"
,
"Can't decode ConfigItem due to"
,
err
.
Error
())
return
nil
,
err
// types.ErrBadConfigValue
}
configValue
:=
item
.
GetArr
()
.
Value
if
len
(
configValue
)
<=
0
{
return
nil
,
evmxgotypes
.
ErrEvmxgoSymbolNotConfigValue
}
var
e
evmxgotypes
.
BridgevmxgoConfig
err
=
json
.
Unmarshal
([]
byte
(
configValue
[
0
]),
&
e
)
if
err
!=
nil
{
elog
.
Error
(
"loadBridgevmxgoAddr load"
,
"Can't decode token info due to:"
,
err
.
Error
())
return
nil
,
err
}
return
&
e
,
nil
}
plugin/dapp/evmxgo/proto/evmxgo.proto
View file @
15672d56
...
...
@@ -39,9 +39,14 @@ message Evmxgo {
// config mint synbol
message
EvmxgoMintConfig
{
string
address
=
1
;
int32
precision
=
2
;
string
introduction
=
3
;
string
address
=
1
;
int32
precision
=
2
;
string
introduction
=
3
;
}
// config bridgevmxgo contract address
message
BridgevmxgoConfig
{
string
address
=
1
;
}
// log
...
...
plugin/dapp/evmxgo/types/evmxgo.pb.go
View file @
15672d56
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