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
7b6d3277
Commit
7b6d3277
authored
May 29, 2020
by
hezhengjun
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'x2eth_200507' of github.com:zhengjunhe/plugin into x2eth_200507
parents
b290939c
2cefc412
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
651 additions
and
674 deletions
+651
-674
docker-compose.sh
build/docker-compose.sh
+4
-0
chain33_test.go
...dapp/x2Ethereum/ebrelayer/relayer/chain33/chain33_test.go
+250
-0
pubilc_sync.go
...ebrelayer/relayer/chain33/transceiver/sync/pubilc_sync.go
+5
-0
ethereum_test.go
...pp/x2Ethereum/ebrelayer/relayer/ethereum/ethereum_test.go
+0
-0
build.sh
plugin/dapp/x2ethereum/cmd/build.sh
+6
-1
RopstenTest.sh
plugin/dapp/x2ethereum/cmd/build/RopstenTest.sh
+10
-22
allRelayerTest.sh
plugin/dapp/x2ethereum/cmd/build/allRelayerTest.sh
+24
-37
perf_test.sh
plugin/dapp/x2ethereum/cmd/build/perf_test.sh
+29
-15
testcase.sh
plugin/dapp/x2ethereum/cmd/build/testcase.sh
+3
-0
chain33RelayerCmd.go
plugin/dapp/x2ethereum/ebcli/chain33RelayerCmd.go
+0
-18
command.go
plugin/dapp/x2ethereum/ebcli/command.go
+31
-3
ethereumRelayerCmd.go
plugin/dapp/x2ethereum/ebcli/ethereumRelayerCmd.go
+0
-104
setupTestEnv.go
...ethereum/ebrelayer/ethcontract/test/setup/setupTestEnv.go
+54
-0
auxiliary.go
plugin/dapp/x2ethereum/ebrelayer/ethtxs/auxiliary.go
+0
-40
deploy.go
plugin/dapp/x2ethereum/ebrelayer/ethtxs/deploy.go
+2
-2
utils.go
plugin/dapp/x2ethereum/ebrelayer/ethtxs/utils.go
+0
-15
account.go
plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/account.go
+4
-5
chain33.go
plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/chain33.go
+8
-30
account.go
plugin/dapp/x2ethereum/ebrelayer/relayer/ethereum/account.go
+23
-83
ethereum.go
...in/dapp/x2ethereum/ebrelayer/relayer/ethereum/ethereum.go
+17
-59
manager.go
plugin/dapp/x2ethereum/ebrelayer/relayer/manager.go
+54
-74
config.pb.go
plugin/dapp/x2ethereum/ebrelayer/types/config.pb.go
+0
-0
relayer.proto
plugin/dapp/x2ethereum/ebrelayer/types/protos/relayer.proto
+6
-3
relayer.pb.go
plugin/dapp/x2ethereum/ebrelayer/types/relayer.pb.go
+0
-0
exec_test.go
plugin/dapp/x2ethereum/executor/exec_test.go
+8
-8
x2ethereumaction.go
plugin/dapp/x2ethereum/executor/x2ethereumaction.go
+24
-24
allRelayerTest.sh
plugin/dapp/x2ethereum/testsh/allRelayerTest.sh
+12
-24
bridgeBankTest.sh
plugin/dapp/x2ethereum/testsh/bridgeBankTest.sh
+13
-21
ebrelayerTest.sh
plugin/dapp/x2ethereum/testsh/ebrelayerTest.sh
+17
-35
publicTest.sh
plugin/dapp/x2ethereum/testsh/publicTest.sh
+37
-32
x2ethereumTest.sh
plugin/dapp/x2ethereum/testsh/x2ethereumTest.sh
+10
-19
No files found.
build/docker-compose.sh
View file @
7b6d3277
...
...
@@ -115,6 +115,10 @@ function base_init() {
#autonomy
sed
-i
$sedfix
's/^useBalance=.*/useBalance=true/g'
chain33.toml
sed
-i
$sedfix
's/^total="16htvcBNS.*/total="1Q9sQwothzM1gKSzkVZ8Dt1tqKX1uzSagx"/g'
chain33.toml
if
[
"
$DAPP
"
==
"x2Ethereum"
]
;
then
sed
-i
$sedfix
's/^enableReduceLocaldb=.*/enableReduceLocaldb=false/g'
chain33.toml
fi
}
function
start
()
{
...
...
plugin/dapp/x2Ethereum/ebrelayer/relayer/chain33/chain33_test.go
0 → 100644
View file @
7b6d3277
package
chain33
import
(
"context"
"encoding/hex"
"flag"
"fmt"
"os"
"os/signal"
"sync"
"sync/atomic"
"syscall"
"testing"
"time"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/ebrelayer/ethcontract/generated"
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/ebrelayer/ethcontract/test/setup"
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/ebrelayer/ethtxs"
syncTx
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/ebrelayer/relayer/chain33/transceiver/sync"
ebTypes
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/ebrelayer/types"
relayerTypes
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/ebrelayer/types"
tml
"github.com/BurntSushi/toml"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/suite"
// 需要显示引用系统插件,以加载系统内置合约
"github.com/33cn/chain33/client/mocks"
_
"github.com/33cn/chain33/system"
"github.com/stretchr/testify/mock"
)
var
(
configPath
=
flag
.
String
(
"f"
,
"./../../relayer.toml"
,
"configfile"
)
chainTestCfg
=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
privateKeyStr
=
"0x3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
accountAddr
=
"0x92c8b16afd6d423652559c6e266cbe1c29bfd84f"
passphrase
=
"123456hzj"
test
=
"0ac3050aa3020a0a7832657468657265756d126d60671a690a2a3078303030303030303030303030303030303030303030303030303030303030303030303030303030301a2a307830633035626135633233306664616135303362353337303261663139363265303864306336306266220831303030303030302a0365746838121a6e080112210320bbac09528e19c55b0f89cb37ab265e7e856b1a8c388780322dbbfd194b52ba1a473045022100c403d9a6e531292336b44d52e4f4dbb9b8ab1e16335383954583728b909478da022031d8a29efcbcea8df648c4054f3c09ab1ab7a330797cf79fd891a3d9336922e920a08d0628e0f193f60530a1d7ad93e5ebc28e253a22314c7538586d537459765777664e716951336e4e4b33345239466648346b5270425612ce0208021a5e0802125a0a2b10c0d59294bb192222313271796f6361794e46374c7636433971573461767873324537553431664b536676122b10a0c88c94bb192222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a55080f12510a291080ade2042222313271796f6361794e46374c7636433971573461767873324537553431664b53667612242222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a92010867128d010a2a3078303030303030303030303030303030303030303030303030303030303030303030303030303030301222313271796f6361794e46374c7636433971573461767873324537553431664b5366761a2a307830633035626135633233306664616135303362353337303261663139363265303864306336306266220831303030303030302a03657468301220c4092a207a38e1da7de4444f2d34c7488293f3a2e01ce2561e720e9bbef355e83755ad833220e68d8418f69d5f18278a53dca53b101f26f76883337a60a5754d5f6d94e42e3c400148c409"
)
type
suiteChain33Relayer
struct
{
suite
.
Suite
chain33Relayer
*
Relayer4Chain33
sim
*
backends
.
SimulatedBackend
x2EthContracts
*
ethtxs
.
X2EthContracts
x2EthDeployInfo
*
ethtxs
.
X2EthDeployInfo
para
*
ethtxs
.
DeployPara
}
func
TestRunSuiteX2Ethereum
(
t
*
testing
.
T
)
{
log
:=
new
(
suiteChain33Relayer
)
suite
.
Run
(
t
,
log
)
}
func
(
r
*
suiteChain33Relayer
)
SetupSuite
()
{
r
.
deployContracts
()
r
.
chain33Relayer
=
r
.
newChain33Relayer
()
}
func
(
r
*
suiteChain33Relayer
)
Test_1_ImportPrivateKey
()
{
addr
,
err
:=
r
.
chain33Relayer
.
ImportPrivateKey
(
passphrase
,
privateKeyStr
)
r
.
NoError
(
err
)
r
.
Equal
(
addr
,
accountAddr
)
time
.
Sleep
(
50
*
time
.
Millisecond
)
addr
,
err
=
r
.
chain33Relayer
.
GetAccountAddr
()
r
.
NoError
(
err
)
r
.
Equal
(
addr
,
accountAddr
)
key
,
_
,
_
:=
r
.
chain33Relayer
.
GetAccount
(
"123"
)
r
.
NotEqual
(
key
,
privateKeyStr
)
key
,
_
,
_
=
r
.
chain33Relayer
.
GetAccount
(
passphrase
)
r
.
Equal
(
key
,
privateKeyStr
)
}
func
(
r
*
suiteChain33Relayer
)
Test_2_HandleRequest
()
{
body
,
err
:=
hex
.
DecodeString
(
test
)
r
.
NoError
(
err
)
r
.
chain33Relayer
.
statusCheckedIndex
=
1220
err
=
syncTx
.
HandleRequest
(
body
)
r
.
NoError
(
err
)
//time.Sleep(50 * time.Second)
time
.
Sleep
(
50
*
time
.
Millisecond
)
}
func
(
r
*
suiteChain33Relayer
)
Test_3_QueryTxhashRelay2Eth
()
{
ret
:=
r
.
chain33Relayer
.
QueryTxhashRelay2Eth
()
r
.
NotEmpty
(
ret
)
}
func
(
r
*
suiteChain33Relayer
)
Test_4_StoreAccountWithNewPassphase
()
{
err
:=
r
.
chain33Relayer
.
StoreAccountWithNewPassphase
(
passphrase
,
passphrase
)
r
.
NoError
(
err
)
}
func
(
r
*
suiteChain33Relayer
)
Test_5_getEthTxhash
()
{
txIndex
:=
atomic
.
LoadInt64
(
&
r
.
chain33Relayer
.
totalTx4Chain33ToEth
)
hash
,
err
:=
r
.
chain33Relayer
.
getEthTxhash
(
txIndex
)
r
.
NoError
(
err
)
r
.
Equal
(
hash
.
String
(),
"0x6fa087c7a2a8a4421f6e269fbc6c0838e99fa59d5760155a71cd7eb1c01aafad"
)
}
func
(
r
*
suiteChain33Relayer
)
Test_7_RestorePrivateKeys
()
{
//err := r.chain33Relayer.RestorePrivateKeys("123") // 不会报错
//r.Error(err)
go
func
()
{
time
.
Sleep
(
1
*
time
.
Millisecond
)
<-
r
.
chain33Relayer
.
unlock
}()
err
:=
r
.
chain33Relayer
.
RestorePrivateKeys
(
passphrase
)
r
.
NoError
(
err
)
}
func
(
r
*
suiteChain33Relayer
)
newChain33Relayer
()
*
Relayer4Chain33
{
cfg
:=
initCfg
(
*
configPath
)
cfg
.
SyncTxConfig
.
Chain33Host
=
"http://127.0.0.1:8801"
cfg
.
BridgeRegistry
=
r
.
x2EthDeployInfo
.
BridgeRegistry
.
Address
.
String
()
cfg
.
SyncTxConfig
.
PushBind
=
"127.0.0.1:60000"
cfg
.
SyncTxConfig
.
FetchHeightPeriodMs
=
50
cfg
.
SyncTxConfig
.
Dbdriver
=
"memdb"
db
:=
dbm
.
NewDB
(
"relayer_db_service"
,
cfg
.
SyncTxConfig
.
Dbdriver
,
cfg
.
SyncTxConfig
.
DbPath
,
cfg
.
SyncTxConfig
.
DbCache
)
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
relayer
:=
&
Relayer4Chain33
{
rpcLaddr
:
cfg
.
SyncTxConfig
.
Chain33Host
,
fetchHeightPeriodMs
:
cfg
.
SyncTxConfig
.
FetchHeightPeriodMs
,
unlock
:
make
(
chan
int
),
db
:
db
,
ctx
:
ctx
,
}
err
:=
relayer
.
setStatusCheckedIndex
(
1
)
r
.
NoError
(
err
)
relayer
.
ethBackend
=
r
.
sim
relayer
.
bridgeRegistryAddr
=
r
.
para
.
Deployer
relayer
.
totalTx4Chain33ToEth
=
relayer
.
getTotalTxAmount2Eth
()
relayer
.
statusCheckedIndex
=
relayer
.
getStatusCheckedIndex
()
r
.
Equal
(
relayer
.
statusCheckedIndex
,
int64
(
1
))
syncCfg
:=
&
ebTypes
.
SyncTxReceiptConfig
{
Chain33Host
:
cfg
.
SyncTxConfig
.
Chain33Host
,
PushHost
:
cfg
.
SyncTxConfig
.
PushHost
,
PushName
:
cfg
.
SyncTxConfig
.
PushName
,
PushBind
:
cfg
.
SyncTxConfig
.
PushBind
,
StartSyncHeight
:
cfg
.
SyncTxConfig
.
StartSyncHeight
,
StartSyncSequence
:
cfg
.
SyncTxConfig
.
StartSyncSequence
,
StartSyncHash
:
cfg
.
SyncTxConfig
.
StartSyncHash
,
}
_
=
syncCfg
go
r
.
syncProc
(
syncCfg
)
var
wg
sync
.
WaitGroup
ch
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
ch
,
syscall
.
SIGTERM
)
go
func
()
{
<-
ch
cancel
()
wg
.
Wait
()
os
.
Exit
(
0
)
}()
return
relayer
}
func
(
r
*
suiteChain33Relayer
)
deployContracts
()
{
ctx
:=
context
.
Background
()
var
backend
bind
.
ContractBackend
backend
,
r
.
para
=
setup
.
PrepareTestEnvironment
()
r
.
sim
=
backend
.
(
*
backends
.
SimulatedBackend
)
balance
,
_
:=
r
.
sim
.
BalanceAt
(
ctx
,
r
.
para
.
Deployer
,
nil
)
fmt
.
Println
(
"deployer addr,"
,
r
.
para
.
Deployer
.
String
(),
"balance ="
,
balance
.
String
())
/////////////////////////EstimateGas///////////////////////////
callMsg
:=
ethereum
.
CallMsg
{
From
:
r
.
para
.
Deployer
,
Data
:
common
.
FromHex
(
generated
.
BridgeBankBin
),
}
gas
,
err
:=
r
.
sim
.
EstimateGas
(
ctx
,
callMsg
)
r
.
NoError
(
err
)
fmt
.
Printf
(
"
\n
The estimated gas=%d
\n
"
,
gas
)
////////////////////////////////////////////////////
r
.
x2EthContracts
,
r
.
x2EthDeployInfo
,
err
=
ethtxs
.
DeployAndInit
(
backend
,
r
.
para
)
r
.
NoError
(
err
)
r
.
sim
.
Commit
()
}
func
(
r
*
suiteChain33Relayer
)
syncProc
(
syncCfg
*
ebTypes
.
SyncTxReceiptConfig
)
{
var
ret
=
types
.
ReplySubTxReceipt
{
IsOk
:
true
}
var
he
=
types
.
Header
{
Height
:
10000
}
mockapi
:=
&
mocks
.
QueueProtocolAPI
{}
// 这里对需要mock的方法打桩,Close是必须的,其它方法根据需要
mockapi
.
On
(
"Close"
)
.
Return
()
mockapi
.
On
(
"AddSubscribeTxReceipt"
,
mock
.
Anything
)
.
Return
(
&
ret
,
nil
)
mockapi
.
On
(
"GetLastHeader"
,
mock
.
Anything
)
.
Return
(
&
he
,
nil
)
mockapi
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chainTestCfg
,
nil
)
mock33
:=
testnode
.
New
(
""
,
mockapi
)
defer
mock33
.
Close
()
rpcCfg
:=
mock33
.
GetCfg
()
.
RPC
// 这里必须设置监听端口,默认的是无效值
rpcCfg
.
JrpcBindAddr
=
"127.0.0.1:8801"
mock33
.
GetRPC
()
.
Listen
()
fmt
.
Println
(
"Pls unlock or import private key for Chain33 relayer"
)
<-
r
.
chain33Relayer
.
unlock
fmt
.
Println
(
"Chain33 relayer starts to run..."
)
r
.
chain33Relayer
.
syncTxReceipts
=
syncTx
.
StartSyncTxReceipt
(
syncCfg
,
r
.
chain33Relayer
.
db
)
r
.
chain33Relayer
.
lastHeight4Tx
=
r
.
chain33Relayer
.
loadLastSyncHeight
()
r
.
chain33Relayer
.
oracleInstance
=
r
.
x2EthContracts
.
Oracle
timer
:=
time
.
NewTicker
(
time
.
Duration
(
r
.
chain33Relayer
.
fetchHeightPeriodMs
)
*
time
.
Millisecond
)
for
{
select
{
case
<-
timer
.
C
:
height
:=
r
.
chain33Relayer
.
getCurrentHeight
()
relayerLog
.
Debug
(
"syncProc"
,
"getCurrentHeight"
,
height
)
r
.
chain33Relayer
.
onNewHeightProc
(
height
)
case
<-
r
.
chain33Relayer
.
ctx
.
Done
()
:
timer
.
Stop
()
return
}
}
}
func
initCfg
(
path
string
)
*
relayerTypes
.
RelayerConfig
{
var
cfg
relayerTypes
.
RelayerConfig
if
_
,
err
:=
tml
.
DecodeFile
(
path
,
&
cfg
);
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
-
1
)
}
return
&
cfg
}
plugin/dapp/x2Ethereum/ebrelayer/relayer/chain33/transceiver/sync/pubilc_sync.go
0 → 100644
View file @
7b6d3277
package
sync
func
HandleRequest
(
body
[]
byte
)
error
{
return
handleRequest
(
body
)
}
plugin/dapp/x2Ethereum/ebrelayer/relayer/ethereum/ethereum_test.go
0 → 100644
View file @
7b6d3277
This diff is collapsed.
Click to expand it.
plugin/dapp/x2ethereum/cmd/build.sh
View file @
7b6d3277
#!/bin/sh
#!/usr/bin/env bash
# 官方ci集成脚本
strpwd
=
$(
pwd
)
strcmd
=
${
strpwd
##*dapp/
}
...
...
@@ -11,9 +12,13 @@ FLAG=$2
# shellcheck disable=SC2086,1072
go build
-i
${
FLAG
}
-v
-o
"
${
OUT_DIR
}
/ebrelayer"
"
${
SRC_EBRELAYER
}
"
# shellcheck disable=SC2086,1072
go build
-i
${
FLAG
}
-v
-o
"
${
OUT_DIR
}
/ebcli_A"
"
${
SRC_EBCLI
}
"
# shellcheck disable=SC2086,1072
go build
-i
${
FLAG
}
-v
-o
"
${
OUT_DIR
}
/ebcli_B"
-ldflags
"-X
${
SRC_EBCLI
}
/buildflags.RPCAddr=http://localhost:9902"
"
${
SRC_EBCLI
}
"
# shellcheck disable=SC2086,1072
go build
-i
${
FLAG
}
-v
-o
"
${
OUT_DIR
}
/ebcli_C"
-ldflags
"-X
${
SRC_EBCLI
}
/buildflags.RPCAddr=http://localhost:9903"
"
${
SRC_EBCLI
}
"
# shellcheck disable=SC2086,1072
go build
-i
${
FLAG
}
-v
-o
"
${
OUT_DIR
}
/ebcli_D"
-ldflags
"-X
${
SRC_EBCLI
}
/buildflags.RPCAddr=http://localhost:9904"
"
${
SRC_EBCLI
}
"
cp
../ebrelayer/relayer.toml
"
${
OUT_DIR
}
/relayer.toml"
...
...
plugin/dapp/x2ethereum/cmd/build/RopstenTest.sh
View file @
7b6d3277
...
...
@@ -14,14 +14,11 @@ CLIC="./ebcli_C"
CLID
=
"./ebcli_D"
chain33SenderAddr
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
chain33SenderAddrKey
=
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
# validatorsAddr=["0x92c8b16afd6d423652559c6e266cbe1c29bfd84f", "0x0df9a824699bc5878232c9e612fe1a5346a5a368", "0xcb074cb21cdddf3ce9c3c0a7ac4497d633c9d9f1", "0xd9dab021e74ecf475788ed7b61356056b2095830"]
ethValidatorAddrKeyA
=
"3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
ethValidatorAddrKeyB
=
"a5f3063552f4483cfc20ac4f40f45b798791379862219de9e915c64722c1d400"
ethValidatorAddrKeyC
=
"bbf5e65539e9af0eb0cfac30bad475111054b09c11d668fc0731d54ea777471e"
ethValidatorAddrKeyD
=
"c9fa31d7984edf81b8ef3b40c761f1847f6fcd5711ab2462da97dc458f1f896b"
# 新增地址 chain33 需要导入地址 转入 10 bty当收费费
chain33Validator1
=
"1GTxrmuWiXavhcvsaH5w9whgVxUrWsUMdV"
chain33Validator2
=
"155ooMPBTF8QQsGAknkK7ei5D78rwDEFe6"
...
...
@@ -31,11 +28,11 @@ chain33ValidatorKey1="0xd627968e445f2a41c92173225791bae1ba42126ae96c32f28f97ff8f
chain33ValidatorKey2
=
"0x9d539bc5fd084eb7fe86ad631dba9aa086dba38418725c38d9751459f567da66"
chain33ValidatorKey3
=
"0x0a6671f101e30a2cc2d79d77436b62cdf2664ed33eb631a9c9e3f3dd348a23be"
chain33ValidatorKey4
=
"0x3818b257b05ee75b6e43ee0e3cfc2d8502342cf67caed533e3756966690b62a5"
ethReceiverAddr1
=
"0xa4ea64a583f6e51c3799335b28a8f0529570a635"
ethReceiverAddrKey1
=
"355b876d7cbcb930d5dfab767f66336ce327e082cbaa1877210c1bae89b1df71"
ethReceiverAddr2
=
"0x0c05ba5c230fdaa503b53702af1962e08d0c60bf"
ethReceiverAddrKey2
=
"9dc6df3a8ab139a54d8a984f54958ae0661f880229bf3bdbb886b87d58b56a08"
maturityDegree
=
10
tokenAddrBty
=
""
...
...
@@ -93,7 +90,7 @@ function StartRelayerAndDeploy() {
kill_ebrelayer
"./A/ebrelayer"
# 修改 relayer.toml 配置文件
updata_relayer_toml_ropston
${
BridgeRegistry
}
${
maturityDegree
}
"./A/relayer.toml"
updata_relayer_toml_ropston
"
${
BridgeRegistry
}
"
${
maturityDegree
}
"./A/relayer.toml"
updata_all_relayer_toml2
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
...
...
@@ -128,7 +125,7 @@ function InitChain33Vilators() {
# query Validators
totalPower
=
$(${
Chain33Cli
}
send x2ethereum query totalpower
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv | jq .totalPower |
sed
's/\"//g'
)
check_number 100
${
totalPower
}
check_number 100
"
${
totalPower
}
"
# cions 转帐到 x2ethereum 合约地址
hash
=
$(${
Chain33Cli
}
send coins send_exec
-e
x2ethereum
-a
200
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
...
...
@@ -183,15 +180,6 @@ function EthImportKey() {
result
=
$(${
CLID
}
relayer ethereum import_chain33privatekey
-k
"
${
chain33ValidatorKey4
}
"
)
cli_ret
"
${
result
}
"
"import_chain33privatekey"
result
=
$(${
CLIA
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyA
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekey"
result
=
$(${
CLIB
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyB
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekeyB"
result
=
$(${
CLIC
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyC
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekeyC"
result
=
$(${
CLID
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyD
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekeyD"
result
=
$(${
CLIA
}
relayer chain33 import_privatekey
-k
"
${
ethValidatorAddrKeyA
}
"
)
cli_ret
"
${
result
}
"
"A relayer chain33 import_privatekey"
result
=
$(${
CLIB
}
relayer chain33 import_privatekey
-k
"
${
ethValidatorAddrKeyB
}
"
)
...
...
@@ -217,7 +205,7 @@ function TestChain33ToEthAssets() {
cli_ret
"
${
result
}
"
"balance"
".balance"
"0"
# chain33 lock bty
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
5
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr1
}
-q
${
tokenAddrBty
}
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
5
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr1
}
-q
"
${
tokenAddrBty
}
"
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
3
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
@@ -286,7 +274,7 @@ function TestETH2Chain33Assets() {
cli_ret
"
${
result
}
"
"balance"
".balance"
"0"
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
$(
echo
"
${
balance
}
+0.1"
| bc
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"
$(
echo
"
${
balance
}
+0.1"
| bc
)
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
...
...
@@ -331,7 +319,7 @@ function TestETH2Chain33Erc20() {
balance_ret
"
${
result
}
"
"100"
# chain33 burn 100
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
100
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
${
tokenAddr
}
-k
"
${
chain33Validator1
}
"
)
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
100
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
"
${
tokenAddr
}
"
-k
"
${
chain33Validator1
}
"
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
3
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
@@ -368,7 +356,7 @@ function TestChain33ToEthAssetsKill() {
kill_ebrelayerD
# chain33 lock bty
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
1.41
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
${
tokenAddrBty
}
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
1.41
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
"
${
tokenAddrBty
}
"
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
3
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
@@ -423,7 +411,7 @@ function TestETH2Chain33AssetsKill() {
cli_ret
"
${
result
}
"
"lock"
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
bridgeBankAddr
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
$(
echo
"
${
balance
}
+0.133"
| bc
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"
$(
echo
"
${
balance
}
+0.133"
| bc
)
"
# eth 等待 10 个区块
eth_block_wait
$((
maturityDegree
+
3
))
https://ropsten-rpc.linkpool.io/
...
...
@@ -459,7 +447,7 @@ function TestETH2Chain33AssetsKill() {
start_ebrelayerD
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
$(
echo
"
${
balance
}
+0.133"
| bc
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"
$(
echo
"
${
balance
}
+0.133"
| bc
)
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
...
...
@@ -515,7 +503,7 @@ function TestETH2Chain33Erc20Kill() {
kill_ebrelayerD
# chain33 burn 100
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
100
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
${
tokenAddr
}
-k
"
${
chain33Validator1
}
"
)
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
100
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
"
${
tokenAddr
}
"
-k
"
${
chain33Validator1
}
"
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
3
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
plugin/dapp/x2ethereum/cmd/build/allRelayerTest.sh
View file @
7b6d3277
...
...
@@ -11,21 +11,16 @@ CLIB="./ebcli_B"
CLIC
=
"./ebcli_C"
CLID
=
"./ebcli_D"
#docker_chain33_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' build_chain33_1)
#Chain33Cli="$GOPATH/src/github.com/33cn/plugin/build/chain33-cli --rpc_laddr http://${docker_chain33_ip}:8801"
docker_chain33_ip
=
""
Chain33Cli
=
""
Chain33Cli
=
"docker exec
${
NODE3
}
/root/chain33-cli"
chain33SenderAddr
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
chain33SenderAddrKey
=
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
# validatorsAddr=["0x92c8b16afd6d423652559c6e266cbe1c29bfd84f", "0x0df9a824699bc5878232c9e612fe1a5346a5a368", "0xcb074cb21cdddf3ce9c3c0a7ac4497d633c9d9f1", "0xd9dab021e74ecf475788ed7b61356056b2095830"]
ethValidatorAddrKeyA
=
"3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
ethValidatorAddrKeyB
=
"a5f3063552f4483cfc20ac4f40f45b798791379862219de9e915c64722c1d400"
ethValidatorAddrKeyC
=
"bbf5e65539e9af0eb0cfac30bad475111054b09c11d668fc0731d54ea777471e"
ethValidatorAddrKeyD
=
"c9fa31d7984edf81b8ef3b40c761f1847f6fcd5711ab2462da97dc458f1f896b"
# 新增地址 chain33 需要导入地址 转入 10 bty当收费费
chain33Validator1
=
"1GTxrmuWiXavhcvsaH5w9whgVxUrWsUMdV"
chain33Validator2
=
"155ooMPBTF8QQsGAknkK7ei5D78rwDEFe6"
...
...
@@ -35,11 +30,11 @@ chain33ValidatorKey1="0xd627968e445f2a41c92173225791bae1ba42126ae96c32f28f97ff8f
chain33ValidatorKey2
=
"0x9d539bc5fd084eb7fe86ad631dba9aa086dba38418725c38d9751459f567da66"
chain33ValidatorKey3
=
"0x0a6671f101e30a2cc2d79d77436b62cdf2664ed33eb631a9c9e3f3dd348a23be"
chain33ValidatorKey4
=
"0x3818b257b05ee75b6e43ee0e3cfc2d8502342cf67caed533e3756966690b62a5"
ethReceiverAddr1
=
"0xa4ea64a583f6e51c3799335b28a8f0529570a635"
ethReceiverAddrKey1
=
"355b876d7cbcb930d5dfab767f66336ce327e082cbaa1877210c1bae89b1df71"
ethReceiverAddr2
=
"0x0c05ba5c230fdaa503b53702af1962e08d0c60bf"
ethReceiverAddrKey2
=
"9dc6df3a8ab139a54d8a984f54958ae0661f880229bf3bdbb886b87d58b56a08"
maturityDegree
=
10
tokenAddrBty
=
""
tokenAddr
=
""
...
...
@@ -54,20 +49,20 @@ function start_ebrelayerC() {
start_ebrelayer
"./C/ebrelayer"
"./C/ebrelayer.log"
${
CLIC
}
relayer unlock
-p
123456hzj
sleep
5
eth_block_wait
1
sleep
1
eth_block_wait
$((
maturityDegree
+
2
))
sleep
1
0
}
function
start_ebrelayerD
()
{
start_ebrelayer
"./D/ebrelayer"
"./D/ebrelayer.log"
${
CLID
}
relayer unlock
-p
123456hzj
sleep
5
eth_block_wait
1
sleep
1
eth_block_wait
$((
maturityDegree
+
2
))
sleep
1
0
}
function
InitAndDeploy
()
{
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
result
=
$(${
CLIA
}
relayer set_pwd
-
n
123456hzj
-o
kk
)
result
=
$(${
CLIA
}
relayer set_pwd
-
p
123456hzj
)
cli_ret
"
${
result
}
"
"set_pwd"
result
=
$(${
CLIA
}
relayer unlock
-p
123456hzj
)
...
...
@@ -83,12 +78,12 @@ function EthImportKey() {
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
# 重启 ebrelayer 并解锁
for
name
in
A B C D
;
do
start_ebrelayer
"./
"
$name
"/ebrelayer"
"./"
$name
"
/ebrelayer.log"
start_ebrelayer
"./
$name
/ebrelayer"
"./
$name
/ebrelayer.log"
# 导入测试地址私钥
CLI
=
"./ebcli_
$name
"
result
=
$(${
CLI
}
relayer set_pwd
-
n
123456hzj
-o
kk
)
result
=
$(${
CLI
}
relayer set_pwd
-
p
123456hzj
)
result
=
$(${
CLI
}
relayer unlock
-p
123456hzj
)
cli_ret
"
${
result
}
"
"unlock"
...
...
@@ -103,15 +98,6 @@ function EthImportKey() {
result
=
$(${
CLID
}
relayer ethereum import_chain33privatekey
-k
"
${
chain33ValidatorKey4
}
"
)
cli_ret
"
${
result
}
"
"import_chain33privatekey"
result
=
$(${
CLIA
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyA
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekey"
result
=
$(${
CLIB
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyB
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekeyB"
result
=
$(${
CLIC
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyC
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekeyC"
result
=
$(${
CLID
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyD
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekeyD"
result
=
$(${
CLIA
}
relayer chain33 import_privatekey
-k
"
${
ethValidatorAddrKeyA
}
"
)
cli_ret
"
${
result
}
"
"A relayer chain33 import_privatekey"
result
=
$(${
CLIB
}
relayer chain33 import_privatekey
-k
"
${
ethValidatorAddrKeyB
}
"
)
...
...
@@ -150,7 +136,7 @@ function StartRelayerAndDeploy() {
kill_ebrelayer
"./A/ebrelayer"
# 修改 relayer.toml 配置文件
updata_relayer_toml
${
BridgeRegistry
}
${
maturityDegree
}
"./A/relayer.toml"
updata_relayer_toml
"
${
BridgeRegistry
}
"
${
maturityDegree
}
"./A/relayer.toml"
updata_all_relayer_toml2
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
...
...
@@ -185,7 +171,7 @@ function InitChain33Vilators() {
# query Validators
totalPower
=
$(${
Chain33Cli
}
send x2ethereum query totalpower
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv | jq .totalPower |
sed
's/\"//g'
)
check_number 100
${
totalPower
}
check_number 100
"
${
totalPower
}
"
# cions 转帐到 x2ethereum 合约地址
hash
=
$(${
Chain33Cli
}
send coins send_exec
-e
x2ethereum
-a
200
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
...
...
@@ -228,7 +214,7 @@ function TestChain33ToEthAssets() {
cli_ret
"
${
result
}
"
"balance"
".balance"
"0"
# chain33 lock bty
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
5
-t
coins.bty
-r
${
ethReceiverAddr1
}
-q
${
tokenAddrBty
}
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
5
-t
coins.bty
-r
${
ethReceiverAddr1
}
-q
"
${
tokenAddrBty
}
"
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
2
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
@@ -297,7 +283,7 @@ function TestETH2Chain33Assets() {
cli_ret
"
${
result
}
"
"balance"
".balance"
"0"
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
$(
echo
"
${
balance
}
+0.1"
| bc
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"
$(
echo
"
${
balance
}
+0.1"
| bc
)
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
...
...
@@ -341,7 +327,7 @@ function TestETH2Chain33Erc20() {
balance_ret
"
${
result
}
"
"100"
# chain33 burn 100
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
100
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
${
tokenAddr
}
-k
"
${
chain33Validator1
}
"
)
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
100
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
"
${
tokenAddr
}
"
-k
"
${
chain33Validator1
}
"
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
2
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
@@ -368,32 +354,32 @@ function TestChain33ToEthAssetsKill() {
tokenAddrBty
=
$(
cli_ret
"
${
result
}
"
"token4chain33"
".addr"
)
fi
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr1
}
"
-t
"
coins.bty
"
)
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr1
}
"
-t
"
${
tokenAddrBty
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"0"
kill_ebrelayerC
kill_ebrelayerD
# chain33 lock bty
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
5
-t
bty
-r
${
ethReceiverAddr2
}
-q
${
tokenAddrBty
}
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
5
-t
coins.bty
-r
${
ethReceiverAddr2
}
-q
"
${
tokenAddrBty
}
"
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
2
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
eth_block_wait
$((
maturityDegree
+
2
))
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
-t
"
coins.bty
"
)
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
-t
"
${
tokenAddrBty
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"0"
start_ebrelayerC
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
-t
"
coins.bty
"
)
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
-t
"
${
tokenAddrBty
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"5"
# eth burn
result
=
$(${
CLIA
}
relayer ethereum burn
-m
5
-k
"
${
ethReceiverAddrKey2
}
"
-r
"
${
chain33Validator1
}
"
-t
"
${
tokenAddrBty
}
"
)
cli_ret
"
${
result
}
"
"burn"
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
-t
"
coins.bty
"
)
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
-t
"
${
tokenAddrBty
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"0"
# eth 等待 10 个区块
...
...
@@ -466,7 +452,7 @@ function TestETH2Chain33AssetsKill() {
start_ebrelayerD
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
$(
echo
"
${
balance
}
+0.1"
| bc
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"
$(
echo
"
${
balance
}
+0.1"
| bc
)
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
...
...
@@ -522,7 +508,7 @@ function TestETH2Chain33Erc20Kill() {
kill_ebrelayerD
# chain33 burn 100
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
100
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
${
tokenAddr
}
-k
"
${
chain33Validator1
}
"
)
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
100
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
"
${
tokenAddr
}
"
-k
"
${
chain33Validator1
}
"
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
2
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
@@ -532,6 +518,7 @@ function TestETH2Chain33Erc20Kill() {
eth_block_wait 2
start_ebrelayerC
start_ebrelayerD
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
-t
"
${
tokenAddr
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"100"
...
...
@@ -565,9 +552,9 @@ function AllRelayerMainTest() {
TestETH2Chain33Erc20
# kill relayer and start relayer
# TestChain33ToEthAssetsKill
# TestETH2Chain33AssetsKill
# TestETH2Chain33Erc20Kill
#
TestChain33ToEthAssetsKill
#
TestETH2Chain33AssetsKill
#
TestETH2Chain33Erc20Kill
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
plugin/dapp/x2ethereum/cmd/build/perf_test.sh
View file @
7b6d3277
#!/usr/bin/env bash
# shellcheck disable=SC2128
# shellcheck source=/dev/null
# shellcheck disable=SC2178
set
-x
source
"./publicTest.sh"
...
...
@@ -9,8 +12,6 @@ Chain33_CLI=""
Ethsender
=
"0xa4ea64a583f6e51c3799335b28a8f0529570a635"
ethSender0PrivateKey
=
"3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
privateKeys[0]
=
"8656d2bc732a8a816a461ba5e2d8aac7c7f85c26a813df30d5327210465eb230"
privateKeys[1]
=
"3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
privateKeys[2]
=
"1385016736f7379884763f4a39811d1391fa156a7ca017be6afffa52bb327695"
...
...
@@ -28,6 +29,8 @@ ethAddress[5]="0xA4Ea64a583F6e51C3799335b28a8F0529570A635"
ethAddress[6]
=
"0x0C05bA5c230fDaA503b53702aF1962e08D0C60BF"
maturityDegree
=
10
tokenAddr
=
""
tokenAddrBty
=
""
loop_send_lock_eth
()
{
#while 遍历数组
...
...
@@ -39,7 +42,8 @@ loop_send_lock_eth() {
while
[[
i
-lt
${#
privateKeys
[@]
}
]]
;
do
preEthBalance[
$i
]=
$(
curl
-ksd
'{"jsonrpc":"2.0","method":"eth_getBalance","params":["'
${
ethAddress
[i]
}
'", "latest"],"id":1}'
http://localhost:7545 | jq
-r
".result"
)
ethTxHash
=
$(${
CLIA
}
relayer ethereum lock-async
-m
1
-k
"
${
privateKeys
[i]
}
"
-r
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
echo
${
i
}
"lock-async tx hash:"
${
ethTxHash
}
echo
${
i
}
"lock-async tx hash:"
"
${
ethTxHash
}
"
# shellcheck disable=SC2219
let
i++
done
...
...
@@ -49,11 +53,12 @@ loop_send_lock_eth() {
while
[[
i
-lt
${#
privateKeys
[@]
}
]]
;
do
nowEthBalance
=
$(
curl
-ksd
'{"jsonrpc":"2.0","method":"eth_getBalance","params":["'
${
ethAddress
[i]
}
'", "latest"],"id":1}'
http://localhost:7545 | jq
-r
".result"
)
res
=
$((
preEthBalance[i]
-
nowEthBalance
))
echo
${
i
}
"preBalance"
${
preEthBalance
[i]
}
"nowBalance"
${
nowEthBalance
}
"diff"
${
res
}
echo
${
i
}
"preBalance"
"
${
preEthBalance
[i]
}
"
"nowBalance"
"
${
nowEthBalance
}
"
"diff"
${
res
}
if
[[
$res
-le
100000000000000000
]]
;
then
echo
-e
"
${
RED
}
error number, expect greater than 100000000000000000, get
${
res
}${
NOC
}
"
exit
1
fi
# shellcheck disable=SC2219
let
i++
done
...
...
@@ -72,7 +77,8 @@ loop_send_burn_eth() {
while
[[
i
-lt
${#
privateKeys
[@]
}
]]
;
do
preEthBalance[
$i
]=
$(
curl
-ksd
'{"jsonrpc":"2.0","method":"eth_getBalance","params":["'
${
ethAddress
[i]
}
'", "latest"],"id":1}'
http://localhost:7545 | jq
-r
".result"
)
ethTxHash
=
$(${
Chain33_CLI
}
send x2ethereum burn
-a
1
-r
${
ethAddress
[i]
}
-t
eth
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
echo
${
i
}
"burn chain33 tx hash:"
${
ethTxHash
}
echo
${
i
}
"burn chain33 tx hash:"
"
${
ethTxHash
}
"
# shellcheck disable=SC2219
let
i++
done
...
...
@@ -82,11 +88,12 @@ loop_send_burn_eth() {
while
[[
i
-lt
${#
privateKeys
[@]
}
]]
;
do
nowEthBalance
=
$(
curl
-ksd
'{"jsonrpc":"2.0","method":"eth_getBalance","params":["'
${
ethAddress
[i]
}
'", "latest"],"id":1}'
http://localhost:7545 | jq
-r
".result"
)
res
=
$((
nowEthBalance
-
preEthBalance[i]
))
echo
${
i
}
"preBalance"
${
preEthBalance
[i]
}
"nowBalance"
${
nowEthBalance
}
"diff"
${
res
}
echo
${
i
}
"preBalance"
"
${
preEthBalance
[i]
}
"
"nowBalance"
"
${
nowEthBalance
}
"
"diff"
${
res
}
if
[[
$res
-gt
1000000000000000000
]]
;
then
echo
-e
"
${
RED
}
error number, expect greater than 1000000000000000000, get
${
res
}${
NOC
}
"
exit
1
fi
# shellcheck disable=SC2219
let
i++
done
nowChain33Balance
=
$(${
Chain33_CLI
}
x2ethereum balance
-s
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
-t
eth | jq
".res"
| jq
".[]"
| jq
".balance"
|
sed
's/\"//g'
)
...
...
@@ -106,7 +113,8 @@ loop_send_lock_bty() {
while
[[
i
-lt
${#
privateKeys
[@]
}
]]
;
do
preEthBalance[
$i
]=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethAddress
[i]
}
"
-t
"
${
tokenAddrBty
}
"
| jq
-r
".balance"
)
ethTxHash
=
$(${
Chain33_CLI
}
send x2ethereum lock
-q
"
${
tokenAddrBty
}
"
-a
1
-r
${
ethAddress
[i]
}
-t
coins.bty
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
echo
${
i
}
"lock chain33 tx hash:"
${
ethTxHash
}
echo
${
i
}
"lock chain33 tx hash:"
"
${
ethTxHash
}
"
# shellcheck disable=SC2219
let
i++
done
...
...
@@ -116,8 +124,9 @@ loop_send_lock_bty() {
while
[[
i
-lt
${#
privateKeys
[@]
}
]]
;
do
nowEthBalance
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethAddress
[i]
}
"
-t
"
${
tokenAddrBty
}
"
| jq
-r
".balance"
)
res
=
$((
nowEthBalance
-
preEthBalance[i]
))
echo
${
i
}
"preBalance"
${
preEthBalance
[i]
}
"nowBalance"
${
nowEthBalance
}
"diff"
${
res
}
echo
${
i
}
"preBalance"
"
${
preEthBalance
[i]
}
"
"nowBalance"
"
${
nowEthBalance
}
"
"diff"
${
res
}
check_number
"
${
res
}
"
1
# shellcheck disable=SC2219
let
i++
done
nowChain33Balance
=
$(${
Chain33_CLI
}
account balance
-a
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
-e
x2ethereum | jq
-r
".balance"
|
sed
's/\"//g'
)
...
...
@@ -139,7 +148,8 @@ loop_send_burn_bty() {
preEthBalance[
$i
]=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethAddress
[i]
}
"
-t
"
${
tokenAddrBty
}
"
| jq
-r
".balance"
)
approveTxHash
=
$(${
CLIA
}
relayer ethereum approve
-m
1
-k
"
${
privateKeys
[i]
}
"
-t
"
${
tokenAddrBty
}
"
)
ethTxHash
=
$(${
CLIA
}
relayer ethereum burn-async
-m
1
-k
"
${
privateKeys
[i]
}
"
-r
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
-t
"
${
tokenAddrBty
}
"
)
echo
${
i
}
"burn-async tx hash:"
${
ethTxHash
}
echo
${
i
}
"burn-async tx hash:"
"
${
ethTxHash
}
"
# shellcheck disable=SC2219
let
i++
done
...
...
@@ -149,8 +159,9 @@ loop_send_burn_bty() {
while
[[
i
-lt
${#
privateKeys
[@]
}
]]
;
do
nowEthBalance
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethAddress
[i]
}
"
-t
"
${
tokenAddrBty
}
"
| jq
-r
".balance"
)
res
=
$((
preEthBalance[i]
-
nowEthBalance
))
echo
${
i
}
"preBalance"
${
preEthBalance
[i]
}
"nowBalance"
${
nowEthBalance
}
"diff"
${
res
}
echo
${
i
}
"preBalance"
"
${
preEthBalance
[i]
}
"
"nowBalance"
"
${
nowEthBalance
}
"
"diff"
${
res
}
check_number
"
${
res
}
"
1
# shellcheck disable=SC2219
let
i++
done
nowChain33Balance
=
$(${
Chain33_CLI
}
account balance
-a
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
-e
x2ethereum | jq
-r
".balance"
|
sed
's/\"//g'
)
...
...
@@ -170,11 +181,12 @@ loop_send_lock_erc20() {
preEthBalance
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
Ethsender
}
"
-t
"
${
tokenAddr
}
"
| jq
-r
".balance"
)
approveTxHash
=
$(${
CLIA
}
relayer ethereum approve
-m
10
-k
"
${
privateKeys
[5]
}
"
-t
"
${
tokenAddr
}
"
)
echo
${
i
}
"lock-async erc20 approve tx hash:"
${
approveTxHash
}
echo
${
i
}
"lock-async erc20 approve tx hash:"
"
${
approveTxHash
}
"
while
[[
i
-lt
${#
privateKeys
[@]
}
]]
;
do
ethTxHash
=
$(${
CLIA
}
relayer ethereum lock-async
-m
1
-k
"
${
privateKeys
[5]
}
"
-r
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
-t
"
${
tokenAddr
}
"
)
echo
${
i
}
"lock-async erc20 tx hash:"
${
ethTxHash
}
echo
${
i
}
"lock-async erc20 tx hash:"
"
${
ethTxHash
}
"
# shellcheck disable=SC2219
let
i++
done
...
...
@@ -182,7 +194,7 @@ loop_send_lock_erc20() {
nowEthBalance
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
Ethsender
}
"
-t
"
${
tokenAddr
}
"
| jq
-r
".balance"
)
res
=
$((
preEthBalance
-
nowEthBalance
))
echo
${
i
}
"preBalance"
${
preEthBalance
}
"nowBalance"
${
nowEthBalance
}
"diff"
${
res
}
echo
${
i
}
"preBalance"
"
${
preEthBalance
}
"
"nowBalance"
"
${
nowEthBalance
}
"
"diff"
${
res
}
check_number
"
${
diff
}
"
7
nowChain33Balance
=
$(${
Chain33_CLI
}
x2ethereum balance
-s
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
-t
testc | jq
".res"
| jq
".[]"
| jq
".balance"
|
sed
's/\"//g'
)
...
...
@@ -202,7 +214,8 @@ loop_send_burn_erc20() {
while
[[
i
-lt
${#
privateKeys
[@]
}
]]
;
do
preEthBalance[i]
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethAddress
[i]
}
"
-t
"
${
tokenAddr
}
"
| jq
-r
".balance"
)
ethTxHash
=
$(${
Chain33_CLI
}
send x2ethereum burn
-a
1
-r
${
ethAddress
[i]
}
-t
testc
-q
"
${
tokenAddr
}
"
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
echo
${
i
}
"burn chain33 tx hash:"
${
ethTxHash
}
echo
${
i
}
"burn chain33 tx hash:"
"
${
ethTxHash
}
"
# shellcheck disable=SC2219
let
i++
done
...
...
@@ -212,8 +225,9 @@ loop_send_burn_erc20() {
while
[[
i
-lt
${#
privateKeys
[@]
}
]]
;
do
nowEthBalance
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethAddress
[i]
}
"
-t
"
${
tokenAddr
}
"
| jq
-r
".balance"
)
res
=
$((
nowEthBalance
-
preEthBalance[i]
))
echo
${
i
}
"preBalance"
${
preEthBalance
[i]
}
"nowBalance"
${
nowEthBalance
}
"diff"
${
res
}
echo
${
i
}
"preBalance"
"
${
preEthBalance
[i]
}
"
"nowBalance"
"
${
nowEthBalance
}
"
"diff"
${
res
}
check_number
"
${
res
}
"
1
# shellcheck disable=SC2219
let
i++
done
...
...
plugin/dapp/x2ethereum/cmd/build/testcase.sh
View file @
7b6d3277
#!/usr/bin/env bash
# shellcheck disable=SC2128
# shellcheck source=/dev/null
source
"./allRelayerTest.sh"
source
"./perf_test.sh"
...
...
plugin/dapp/x2ethereum/ebcli/chain33RelayerCmd.go
View file @
7b6d3277
...
...
@@ -21,7 +21,6 @@ func Chain33RelayerCmd() *cobra.Command {
ImportPrivateKeyCmd
(),
ShowValidatorAddrCmd
(),
ShowTxsHashCmd
(),
ShowChain33RelayerStatusCmd
(),
)
return
cmd
...
...
@@ -94,20 +93,3 @@ func showChain33Relayer2EthTxs(cmd *cobra.Command, args []string) {
fmt
.
Println
(
hash
)
}
}
func
ShowChain33RelayerStatusCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"status"
,
Short
:
"show chain33-relayer status"
,
Run
:
showChain33RelayerStatus
,
}
return
cmd
}
func
showChain33RelayerStatus
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
var
res
ebTypes
.
RelayerRunStatus
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Manager.ShowChain33RelayerStatus"
,
nil
,
&
res
)
ctx
.
Run
()
}
plugin/dapp/x2ethereum/ebcli/command.go
View file @
7b6d3277
...
...
@@ -20,6 +20,7 @@ func RelayerCmd() *cobra.Command {
cmd
.
AddCommand
(
SetPwdCmd
(),
ChangePwdCmd
(),
LockCmd
(),
UnlockCmd
(),
Chain33RelayerCmd
(),
...
...
@@ -41,6 +42,33 @@ func SetPwdCmd() *cobra.Command {
}
func
addSetPwdFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"password"
,
"p"
,
""
,
"password,[8-30]letter and digit"
)
cmd
.
MarkFlagRequired
(
"password"
)
}
func
setPwd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
newPwd
,
_
:=
cmd
.
Flags
()
.
GetString
(
"password"
)
params
:=
relayerTypes
.
ReqSetPasswd
{
Passphase
:
newPwd
,
}
var
res
rpctypes
.
Reply
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Manager.SetPassphase"
,
params
,
&
res
)
ctx
.
Run
()
}
// ChangePwdCmd set password
func
ChangePwdCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"change_pwd"
,
Short
:
"Change password"
,
Run
:
changePwd
,
}
addChangePwdFlags
(
cmd
)
return
cmd
}
func
addChangePwdFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"old"
,
"o"
,
""
,
"old password"
)
cmd
.
MarkFlagRequired
(
"old"
)
...
...
@@ -48,16 +76,16 @@ func addSetPwdFlags(cmd *cobra.Command) {
cmd
.
MarkFlagRequired
(
"new"
)
}
func
set
Pwd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
change
Pwd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
oldPwd
,
_
:=
cmd
.
Flags
()
.
GetString
(
"old"
)
newPwd
,
_
:=
cmd
.
Flags
()
.
GetString
(
"new"
)
params
:=
relayerTypes
.
Req
Set
Passwd
{
params
:=
relayerTypes
.
Req
Change
Passwd
{
OldPassphase
:
oldPwd
,
NewPassphase
:
newPwd
,
}
var
res
rpctypes
.
Reply
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Manager.
Set
Passphase"
,
params
,
&
res
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Manager.
Change
Passphase"
,
params
,
&
res
)
ctx
.
Run
()
}
...
...
plugin/dapp/x2ethereum/ebcli/ethereumRelayerCmd.go
View file @
7b6d3277
...
...
@@ -23,12 +23,10 @@ func EthereumRelayerCmd() *cobra.Command {
cmd
.
AddCommand
(
ImportChain33PrivateKeyCmd
(),
ImportEthValidatorPrivateKeyCmd
(),
GenEthPrivateKeyCmd
(),
ShowValidatorsAddrCmd
(),
ShowChain33TxsHashCmd
(),
ShowEthereumTxsHashCmd
(),
ShowEthRelayerStatusCmd
(),
IsValidatorActiveCmd
(),
ShowOperatorCmd
(),
DeployContrctsCmd
(),
...
...
@@ -36,7 +34,6 @@ func EthereumRelayerCmd() *cobra.Command {
//////auxiliary///////
CreateBridgeTokenCmd
(),
CreateEthereumTokenCmd
(),
MakeNewProphecyClaimCmd
(),
GetBalanceCmd
(),
IsProphecyPendingCmd
(),
MintErc20Cmd
(),
...
...
@@ -80,26 +77,6 @@ func importChain33Privatekey(cmd *cobra.Command, args []string) {
ctx
.
Run
()
}
func
ImportEthValidatorPrivateKeyCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"import_ethprivatekey"
,
Short
:
"import ethereum's validator private key "
,
Run
:
importEthValidtorPrivatekey
,
}
addImportPrivateKeyFlags
(
cmd
)
return
cmd
}
func
importEthValidtorPrivatekey
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
privateKey
,
_
:=
cmd
.
Flags
()
.
GetString
(
"key"
)
params
:=
privateKey
var
res
rpctypes
.
Reply
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Manager.ImportEthValidatorPrivateKey"
,
params
,
&
res
)
ctx
.
Run
()
}
func
GenEthPrivateKeyCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"create_eth_key"
,
...
...
@@ -181,23 +158,6 @@ func showEthTxs(cmd *cobra.Command, args []string) {
}
}
func
ShowEthRelayerStatusCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"status"
,
Short
:
"show ethereum-relayer status"
,
Run
:
showEthRelayerStatus
,
}
return
cmd
}
func
showEthRelayerStatus
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
var
res
ebTypes
.
RelayerRunStatus
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Manager.ShowEthRelayerStatus"
,
nil
,
&
res
)
ctx
.
Run
()
}
func
IsValidatorActiveCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"active"
,
...
...
@@ -607,70 +567,6 @@ func ShowBridgeRegistryAddr(cmd *cobra.Command, args []string) {
ctx
.
Run
()
}
func
MakeNewProphecyClaimCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"prophecy"
,
Short
:
"Make New Prophecy Claim"
,
Run
:
MakeNewProphecyClaim
,
}
MakeNewProphecyClaimFlags
(
cmd
)
return
cmd
}
func
MakeNewProphecyClaimFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uint32P
(
"claim"
,
"c"
,
uint32
(
1
),
"claim type, 1 denote burn, and 2 denotes lock"
)
_
=
cmd
.
MarkFlagRequired
(
"claim"
)
cmd
.
Flags
()
.
StringP
(
"chain33Sender"
,
"a"
,
""
,
"Chain33Sender"
)
_
=
cmd
.
MarkFlagRequired
(
"chain33Sender"
)
cmd
.
Flags
()
.
StringP
(
"token"
,
"t"
,
""
,
"token address,optional, nil for ETH"
)
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
""
,
"token symbol"
)
_
=
cmd
.
MarkFlagRequired
(
"symbol"
)
cmd
.
Flags
()
.
StringP
(
"ethReceiver"
,
"r"
,
""
,
"eth Receiver"
)
_
=
cmd
.
MarkFlagRequired
(
"ethReceiver"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"m"
,
0
,
"amount"
)
_
=
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
StringP
(
"hash"
,
"i"
,
""
,
"chain33 tx hash"
)
_
=
cmd
.
MarkFlagRequired
(
"hash"
)
}
func
MakeNewProphecyClaim
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
claimType
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"claim"
)
if
claimType
!=
uint32
(
1
)
&&
claimType
!=
uint32
(
2
)
{
fmt
.
Println
(
"Wrong claim type"
)
return
}
chain33Sender
,
_
:=
cmd
.
Flags
()
.
GetString
(
"chain33Sender"
)
tokenAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"token"
)
symbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
ethReceiver
,
_
:=
cmd
.
Flags
()
.
GetString
(
"ethReceiver"
)
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
txhash
,
_
:=
cmd
.
Flags
()
.
GetString
(
"hash"
)
nodeAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"node_addr"
)
d
,
err
:=
utils
.
GetDecimalsFromNode
(
tokenAddr
,
nodeAddr
)
if
err
!=
nil
{
fmt
.
Println
(
"get decimals error"
)
return
}
realAmount
:=
types
.
ToWei
(
amount
,
d
)
para
:=
ebTypes
.
NewProphecyClaim
{
ClaimType
:
claimType
,
Chain33Sender
:
chain33Sender
,
TokenAddr
:
tokenAddr
,
Symbol
:
symbol
,
EthReceiver
:
ethReceiver
,
Amount
:
realAmount
.
String
(),
TxHash
:
txhash
,
}
var
res
rpctypes
.
Reply
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Manager.MakeNewProphecyClaim"
,
para
,
&
res
)
ctx
.
Run
()
}
func
GetBalanceCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"balance"
,
...
...
plugin/dapp/x2ethereum/ebrelayer/ethcontract/test/setup/setupTestEnv.go
View file @
7b6d3277
...
...
@@ -53,3 +53,57 @@ func PrepareTestEnv() (bind.ContractBackend, *ethtxs.DeployPara) {
return
sim
,
para
}
func
PrepareTestEnvironment
()
(
bind
.
ContractBackend
,
*
ethtxs
.
DeployPara
)
{
var
deployerPrivateKey
=
"8656d2bc732a8a816a461ba5e2d8aac7c7f85c26a813df30d5327210465eb230"
var
ethValidatorAddrKeyA
=
"3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
var
ethValidatorAddrKeyB
=
"a5f3063552f4483cfc20ac4f40f45b798791379862219de9e915c64722c1d400"
var
ethValidatorAddrKeyC
=
"bbf5e65539e9af0eb0cfac30bad475111054b09c11d668fc0731d54ea777471e"
var
ethValidatorAddrKeyD
=
"c9fa31d7984edf81b8ef3b40c761f1847f6fcd5711ab2462da97dc458f1f896b"
genesiskey
,
_
:=
crypto
.
HexToECDSA
(
deployerPrivateKey
)
alloc
:=
make
(
core
.
GenesisAlloc
)
genesisAddr
:=
crypto
.
PubkeyToAddress
(
genesiskey
.
PublicKey
)
genesisAccount
:=
core
.
GenesisAccount
{
Balance
:
big
.
NewInt
(
10000000000
*
10000
),
PrivateKey
:
crypto
.
FromECDSA
(
genesiskey
),
}
alloc
[
genesisAddr
]
=
genesisAccount
ethValidatorAddrKey
:=
make
([]
string
,
0
)
ethValidatorAddrKey
=
append
(
ethValidatorAddrKey
,
ethValidatorAddrKeyA
)
ethValidatorAddrKey
=
append
(
ethValidatorAddrKey
,
ethValidatorAddrKeyB
)
ethValidatorAddrKey
=
append
(
ethValidatorAddrKey
,
ethValidatorAddrKeyC
)
ethValidatorAddrKey
=
append
(
ethValidatorAddrKey
,
ethValidatorAddrKeyD
)
var
InitValidators
[]
common
.
Address
var
ValidatorPriKey
[]
*
ecdsa
.
PrivateKey
for
_
,
v
:=
range
ethValidatorAddrKey
{
key
,
_
:=
crypto
.
HexToECDSA
(
v
)
addr
:=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
InitValidators
=
append
(
InitValidators
,
addr
)
ValidatorPriKey
=
append
(
ValidatorPriKey
,
key
)
account
:=
core
.
GenesisAccount
{
Balance
:
big
.
NewInt
(
100000000
*
100
),
PrivateKey
:
crypto
.
FromECDSA
(
key
),
}
alloc
[
addr
]
=
account
}
gasLimit
:=
uint64
(
100000000
)
sim
:=
backends
.
NewSimulatedBackend
(
alloc
,
gasLimit
)
InitPowers
:=
[]
*
big
.
Int
{
big
.
NewInt
(
80
),
big
.
NewInt
(
10
),
big
.
NewInt
(
10
),
big
.
NewInt
(
10
)}
para
:=
&
ethtxs
.
DeployPara
{
DeployPrivateKey
:
genesiskey
,
Deployer
:
genesisAddr
,
Operator
:
genesisAddr
,
InitValidators
:
InitValidators
,
ValidatorPriKey
:
ValidatorPriKey
,
InitPowers
:
InitPowers
,
}
return
sim
,
para
}
plugin/dapp/x2ethereum/ebrelayer/ethtxs/auxiliary.go
View file @
7b6d3277
...
...
@@ -2,7 +2,6 @@ package ethtxs
import
(
"context"
"crypto/ecdsa"
"errors"
"math/big"
...
...
@@ -442,42 +441,3 @@ func LockEthErc20AssetAsync(ownerPrivateKeyStr, tokenAddrStr, chain33Receiver st
}
return
tx
.
Hash
()
.
String
(),
nil
}
/////////////////NewProphecyClaim////////////////
func
MakeNewProphecyClaim
(
newProphecyClaimPara
*
NewProphecyClaimPara
,
backend
bind
.
ContractBackend
,
privateKey
*
ecdsa
.
PrivateKey
,
transactor
common
.
Address
,
x2EthContracts
*
X2EthContracts
)
(
string
,
error
)
{
var
prepareDone
bool
authVali
,
err
:=
PrepareAuth
(
backend
,
privateKey
,
transactor
)
if
nil
!=
err
{
return
""
,
err
}
prepareDone
=
true
defer
func
()
{
if
err
!=
nil
&&
prepareDone
{
_
,
_
=
revokeNonce
(
transactor
)
}
}()
amount
:=
newProphecyClaimPara
.
Amount
ethReceiver
:=
newProphecyClaimPara
.
EthReceiver
// Generate rawHash using ProphecyClaim data
claimID
:=
crypto
.
Keccak256Hash
(
newProphecyClaimPara
.
Txhash
,
newProphecyClaimPara
.
Chain33Sender
,
newProphecyClaimPara
.
EthReceiver
.
Bytes
(),
newProphecyClaimPara
.
TokenAddr
.
Bytes
(),
amount
.
Bytes
())
// Sign the hash using the active validator's private key
signature
,
err
:=
SignClaim4Eth
(
claimID
,
privateKey
)
if
nil
!=
err
{
return
""
,
err
}
tx
,
err
:=
x2EthContracts
.
Oracle
.
NewOracleClaim
(
authVali
,
newProphecyClaimPara
.
ClaimType
,
newProphecyClaimPara
.
Chain33Sender
,
ethReceiver
,
newProphecyClaimPara
.
TokenAddr
,
newProphecyClaimPara
.
Symbol
,
amount
,
claimID
,
signature
)
if
nil
!=
err
{
return
""
,
err
}
err
=
waitEthTxFinished
(
backend
.
(
*
ethclient
.
Client
),
tx
.
Hash
(),
"MakeNewProphecyClaim"
)
if
nil
!=
err
{
return
""
,
err
}
return
tx
.
Hash
()
.
String
(),
nil
}
plugin/dapp/x2ethereum/ebrelayer/ethtxs/deploy.go
View file @
7b6d3277
...
...
@@ -165,9 +165,9 @@ func DeployAndInit(backend bind.ContractBackend, para *DeployPara) (*X2EthContra
/////////////////////////////////////
sim
,
isSim
:=
backend
.
(
*
backends
.
SimulatedBackend
)
if
isSim
{
fmt
.
Print
(
"Use the simulator"
)
fmt
.
Print
ln
(
"Use the simulator"
)
}
else
{
fmt
.
Print
(
"Use the actual Ethereum"
)
fmt
.
Print
ln
(
"Use the actual Ethereum"
)
}
x2EthContracts
.
Valset
,
deployInfo
.
Valset
,
err
=
DeployValset
(
backend
,
para
.
DeployPrivateKey
,
para
.
Deployer
,
para
.
Operator
,
para
.
InitValidators
,
para
.
InitPowers
)
...
...
plugin/dapp/x2ethereum/ebrelayer/ethtxs/utils.go
View file @
7b6d3277
...
...
@@ -7,8 +7,6 @@ import (
"math/big"
"sync"
"time"
ebrelayerTypes
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/types"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -65,19 +63,6 @@ func prefixMessage(message common.Hash, key *ecdsa.PrivateKey) ([]byte, []byte)
return
sig
,
prefixed
}
// LoadSender : uses the validator's private key to load the validator's address
func
LoadSender
(
privateKey
*
ecdsa
.
PrivateKey
)
(
address
common
.
Address
,
err
error
)
{
// Parse public key
publicKey
:=
privateKey
.
Public
()
publicKeyECDSA
,
ok
:=
publicKey
.
(
*
ecdsa
.
PublicKey
)
if
!
ok
{
return
common
.
Address
{},
ebrelayerTypes
.
ErrPublicKeyType
}
fromAddress
:=
crypto
.
PubkeyToAddress
(
*
publicKeyECDSA
)
return
fromAddress
,
nil
}
func
getNonce
(
sender
common
.
Address
,
backend
bind
.
ContractBackend
)
(
*
big
.
Int
,
error
)
{
if
nonceMutex
,
exist
:=
addr2Nonce
[
sender
];
exist
{
nonceMutex
.
rw
.
Lock
()
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/account.go
View file @
7b6d3277
...
...
@@ -75,7 +75,7 @@ func (chain33Relayer *Relayer4Chain33) StoreAccountWithNewPassphase(newPassphras
accountInfo
,
err
:=
chain33Relayer
.
db
.
Get
(
chain33AccountKey
)
if
nil
!=
err
{
relayerLog
.
Info
(
"StoreAccountWithNewPassphase"
,
"pls check account is created already, err"
,
err
)
return
nil
return
err
}
ethAccount
:=
&
x2ethTypes
.
Account4Relayer
{}
if
err
:=
chain33Types
.
Decode
(
accountInfo
,
ethAccount
);
nil
!=
err
{
...
...
@@ -114,7 +114,6 @@ func (chain33Relayer *Relayer4Chain33) RestorePrivateKeys(passphrase string) err
return
nil
}
func
(
chain33Relayer
*
Relayer4Chain33
)
UpdatePrivateKey
(
Passphrase
,
privateKey
string
)
error
{
return
nil
}
//func (chain33Relayer *Relayer4Chain33) UpdatePrivateKey(Passphrase, privateKey string) error {
// return nil
//}
plugin/dapp/x2ethereum/ebrelayer/relayer/chain33/chain33.go
View file @
7b6d3277
...
...
@@ -32,14 +32,14 @@ import (
var
relayerLog
=
log
.
New
(
"module"
,
"chain33_relayer"
)
type
Relayer4Chain33
struct
{
syncTxReceipts
*
syncTx
.
TxReceipts
ethBackend
bind
.
ContractBackend
rpcLaddr
string
//用户向指定的blockchain节点进行rpc调用
fetchHeightPeriodMs
int64
db
dbm
.
DB
lastHeight4Tx
int64
//等待被处理的具有相应的交易回执的高度
matDegree
int32
//成熟度 heightSync2App matDegress height
passphase
string
syncTxReceipts
*
syncTx
.
TxReceipts
ethBackend
bind
.
ContractBackend
rpcLaddr
string
//用户向指定的blockchain节点进行rpc调用
fetchHeightPeriodMs
int64
db
dbm
.
DB
lastHeight4Tx
int64
//等待被处理的具有相应的交易回执的高度
matDegree
int32
//成熟度 heightSync2App matDegress height
//
passphase string
privateKey4Ethereum
*
ecdsa
.
PrivateKey
ethSender
ethCommon
.
Address
bridgeRegistryAddr
ethCommon
.
Address
...
...
@@ -49,7 +49,6 @@ type Relayer4Chain33 struct {
ctx
context
.
Context
rwLock
sync
.
RWMutex
unlock
chan
int
status
int32
}
// StartChain33Relayer : initializes a relayer which witnesses events on the chain33 network and relays them to Ethereum
...
...
@@ -85,32 +84,11 @@ func StartChain33Relayer(ctx context.Context, syncTxConfig *ebTypes.SyncTxConfig
return
relayer
}
func
(
chain33Relayer
*
Relayer4Chain33
)
SetPassphase
(
passphase
string
)
{
chain33Relayer
.
rwLock
.
Lock
()
chain33Relayer
.
passphase
=
passphase
chain33Relayer
.
rwLock
.
Unlock
()
}
func
(
chain33Relayer
*
Relayer4Chain33
)
QueryTxhashRelay2Eth
()
ebTypes
.
Txhashes
{
txhashs
:=
utils
.
QueryTxhashes
([]
byte
(
chain33ToEthBurnLockTxHashPrefix
),
chain33Relayer
.
db
)
return
ebTypes
.
Txhashes
{
Txhash
:
txhashs
}
}
func
(
chain33Relayer
*
Relayer4Chain33
)
GetRunningStatus
()
(
relayerRunStatus
*
ebTypes
.
RelayerRunStatus
)
{
relayerRunStatus
=
&
ebTypes
.
RelayerRunStatus
{}
chain33Relayer
.
rwLock
.
RLock
()
relayerRunStatus
.
Status
=
chain33Relayer
.
status
chain33Relayer
.
rwLock
.
RUnlock
()
if
relayerRunStatus
.
Status
==
ebTypes
.
StatusPending
{
if
nil
==
chain33Relayer
.
privateKey4Ethereum
{
relayerRunStatus
.
Details
=
"Ethereum's private key not imported"
}
return
}
relayerRunStatus
.
Details
=
"Running"
return
}
func
(
chain33Relayer
*
Relayer4Chain33
)
syncProc
(
syncCfg
*
ebTypes
.
SyncTxReceiptConfig
)
{
_
,
_
=
fmt
.
Fprintln
(
os
.
Stdout
,
"Pls unlock or import private key for Chain33 relayer"
)
<-
chain33Relayer
.
unlock
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/ethereum/account.go
View file @
7b6d3277
...
...
@@ -23,7 +23,6 @@ import (
)
var
(
ethAccountKey
=
[]
byte
(
"EthAccount4EthRelayer"
)
chain33AccountKey
=
[]
byte
(
"Chain33Account4EthRelayer"
)
start
=
int
(
1
)
)
...
...
@@ -38,42 +37,31 @@ type Key struct {
}
func
(
ethRelayer
*
Relayer4Ethereum
)
NewAccount
(
passphrase
string
)
(
privateKeystr
,
addr
string
,
err
error
)
{
var
privateKey
*
ecdsa
.
PrivateKey
privateKey
,
privateKeystr
,
addr
,
err
=
newKeyAndStore
(
ethRelayer
.
db
,
crand
.
Reader
,
passphrase
)
_
,
privateKeystr
,
addr
,
err
=
newKeyAndStore
(
ethRelayer
.
db
,
crand
.
Reader
,
passphrase
)
if
err
!=
nil
{
return
""
,
""
,
err
}
ethRelayer
.
SetPrivateKey4Ethereum
(
privateKey
)
return
}
func
(
ethRelayer
*
Relayer4Ethereum
)
GetAccount
(
passphrase
string
)
(
privateKey
,
addr
string
,
err
error
)
{
accountInfo
,
err
:=
ethRelayer
.
db
.
Get
(
eth
AccountKey
)
accountInfo
,
err
:=
ethRelayer
.
db
.
Get
(
chain33
AccountKey
)
if
nil
!=
err
{
return
""
,
""
,
err
}
eth
Account
:=
&
x2ethTypes
.
Account4Relayer
{}
if
err
:=
chain33Types
.
Decode
(
accountInfo
,
eth
Account
);
nil
!=
err
{
Chain33
Account
:=
&
x2ethTypes
.
Account4Relayer
{}
if
err
:=
chain33Types
.
Decode
(
accountInfo
,
Chain33
Account
);
nil
!=
err
{
return
""
,
""
,
err
}
decryptered
:=
wcom
.
CBCDecrypterPrivkey
([]
byte
(
passphrase
),
eth
Account
.
Privkey
)
decryptered
:=
wcom
.
CBCDecrypterPrivkey
([]
byte
(
passphrase
),
Chain33
Account
.
Privkey
)
privateKey
=
chain33Common
.
ToHex
(
decryptered
)
addr
=
eth
Account
.
Addr
addr
=
Chain33
Account
.
Addr
return
}
func
(
ethRelayer
*
Relayer4Ethereum
)
GetValidatorAddr
()
(
validators
x2ethTypes
.
ValidatorAddr4EthRelayer
,
err
error
)
{
var
ethAccountAddr
string
var
chain33AccountAddr
string
accountInfo
,
err
:=
ethRelayer
.
db
.
Get
(
ethAccountKey
)
if
nil
==
err
{
ethAccount
:=
&
x2ethTypes
.
Account4Relayer
{}
if
err
:=
chain33Types
.
Decode
(
accountInfo
,
ethAccount
);
nil
==
err
{
ethAccountAddr
=
ethAccount
.
Addr
}
}
accountInfo
,
err
=
ethRelayer
.
db
.
Get
(
chain33AccountKey
)
accountInfo
,
err
:=
ethRelayer
.
db
.
Get
(
chain33AccountKey
)
if
nil
==
err
{
ethAccount
:=
&
x2ethTypes
.
Account4Relayer
{}
if
err
:=
chain33Types
.
Decode
(
accountInfo
,
ethAccount
);
nil
==
err
{
...
...
@@ -81,40 +69,22 @@ func (ethRelayer *Relayer4Ethereum) GetValidatorAddr() (validators x2ethTypes.Va
}
}
if
0
==
len
(
chain33AccountAddr
)
&&
0
==
len
(
ethAccountAddr
)
{
if
0
==
len
(
chain33AccountAddr
)
{
return
x2ethTypes
.
ValidatorAddr4EthRelayer
{},
x2ethTypes
.
ErrNoValidatorConfigured
}
validators
=
x2ethTypes
.
ValidatorAddr4EthRelayer
{
EthValidator
:
ethAccountAddr
,
Chain33Validator
:
chain33AccountAddr
,
}
return
}
func
(
ethRelayer
*
Relayer4Ethereum
)
RestorePrivateKeys
(
passPhase
string
)
(
err
error
)
{
accountInfo
,
err
:=
ethRelayer
.
db
.
Get
(
ethAccountKey
)
if
nil
==
err
{
ethAccount
:=
&
x2ethTypes
.
Account4Relayer
{}
if
err
:=
chain33Types
.
Decode
(
accountInfo
,
ethAccount
);
nil
==
err
{
decryptered
:=
wcom
.
CBCDecrypterPrivkey
([]
byte
(
passPhase
),
ethAccount
.
Privkey
)
privateKey
,
err
:=
crypto
.
ToECDSA
(
decryptered
)
if
nil
!=
err
{
errInfo
:=
fmt
.
Sprintf
(
"Failed to ToECDSA due to:%s"
,
err
.
Error
())
relayerLog
.
Info
(
"RestorePrivateKeys"
,
"Failed to ToECDSA:"
,
err
.
Error
())
return
errors
.
New
(
errInfo
)
}
ethRelayer
.
rwLock
.
Lock
()
ethRelayer
.
privateKey4Ethereum
=
privateKey
ethRelayer
.
rwLock
.
Unlock
()
}
}
accountInfo
,
err
=
ethRelayer
.
db
.
Get
(
chain33AccountKey
)
accountInfo
,
err
:=
ethRelayer
.
db
.
Get
(
chain33AccountKey
)
if
nil
==
err
{
eth
Account
:=
&
x2ethTypes
.
Account4Relayer
{}
if
err
:=
chain33Types
.
Decode
(
accountInfo
,
eth
Account
);
nil
==
err
{
decryptered
:=
wcom
.
CBCDecrypterPrivkey
([]
byte
(
passPhase
),
eth
Account
.
Privkey
)
Chain33
Account
:=
&
x2ethTypes
.
Account4Relayer
{}
if
err
:=
chain33Types
.
Decode
(
accountInfo
,
Chain33
Account
);
nil
==
err
{
decryptered
:=
wcom
.
CBCDecrypterPrivkey
([]
byte
(
passPhase
),
Chain33
Account
.
Privkey
)
var
driver
secp256k1
.
Driver
priKey
,
err
:=
driver
.
PrivKeyFromBytes
(
decryptered
)
if
nil
!=
err
{
...
...
@@ -128,7 +98,7 @@ func (ethRelayer *Relayer4Ethereum) RestorePrivateKeys(passPhase string) (err er
}
}
if
ethRelayer
.
privateKey4Ethereum
!=
nil
&&
nil
!=
ethRelayer
.
privateKey4Chain33
{
if
nil
!=
ethRelayer
.
privateKey4Chain33
{
ethRelayer
.
unlockchan
<-
start
}
...
...
@@ -136,20 +106,20 @@ func (ethRelayer *Relayer4Ethereum) RestorePrivateKeys(passPhase string) (err er
}
func
(
ethRelayer
*
Relayer4Ethereum
)
StoreAccountWithNewPassphase
(
newPassphrase
,
oldPassphrase
string
)
error
{
accountInfo
,
err
:=
ethRelayer
.
db
.
Get
(
eth
AccountKey
)
accountInfo
,
err
:=
ethRelayer
.
db
.
Get
(
chain33
AccountKey
)
if
nil
!=
err
{
relayerLog
.
Info
(
"StoreAccountWithNewPassphase"
,
"pls check account is created already, err"
,
err
)
return
nil
return
err
}
eth
Account
:=
&
x2ethTypes
.
Account4Relayer
{}
if
err
:=
chain33Types
.
Decode
(
accountInfo
,
eth
Account
);
nil
!=
err
{
Chain33
Account
:=
&
x2ethTypes
.
Account4Relayer
{}
if
err
:=
chain33Types
.
Decode
(
accountInfo
,
Chain33
Account
);
nil
!=
err
{
return
err
}
decryptered
:=
wcom
.
CBCDecrypterPrivkey
([]
byte
(
oldPassphrase
),
eth
Account
.
Privkey
)
decryptered
:=
wcom
.
CBCDecrypterPrivkey
([]
byte
(
oldPassphrase
),
Chain33
Account
.
Privkey
)
encryptered
:=
wcom
.
CBCEncrypterPrivkey
([]
byte
(
newPassphrase
),
decryptered
)
eth
Account
.
Privkey
=
encryptered
encodedInfo
:=
chain33Types
.
Encode
(
eth
Account
)
return
ethRelayer
.
db
.
SetSync
(
eth
AccountKey
,
encodedInfo
)
Chain33
Account
.
Privkey
=
encryptered
encodedInfo
:=
chain33Types
.
Encode
(
Chain33
Account
)
return
ethRelayer
.
db
.
SetSync
(
chain33
AccountKey
,
encodedInfo
)
}
func
(
ethRelayer
*
Relayer4Ethereum
)
ImportChain33PrivateKey
(
passphrase
,
privateKeyStr
string
)
error
{
...
...
@@ -164,9 +134,7 @@ func (ethRelayer *Relayer4Ethereum) ImportChain33PrivateKey(passphrase, privateK
}
ethRelayer
.
privateKey4Chain33
=
priKey
if
nil
!=
ethRelayer
.
privateKey4Ethereum
{
ethRelayer
.
unlockchan
<-
start
}
ethRelayer
.
unlockchan
<-
start
addr
,
err
:=
pubKeyToAddress4Bty
(
priKey
.
PubKey
()
.
Bytes
())
if
nil
!=
err
{
return
err
...
...
@@ -181,33 +149,6 @@ func (ethRelayer *Relayer4Ethereum) ImportChain33PrivateKey(passphrase, privateK
return
ethRelayer
.
db
.
SetSync
(
chain33AccountKey
,
encodedInfo
)
}
func
(
ethRelayer
*
Relayer4Ethereum
)
ImportEthValidatorPrivateKey
(
passphrase
,
privateKeyStr
string
)
error
{
privateKeySli
,
err
:=
chain33Common
.
FromHex
(
privateKeyStr
)
if
nil
!=
err
{
return
err
}
privateKeyECDSA
,
err
:=
crypto
.
ToECDSA
(
privateKeySli
)
if
nil
!=
err
{
errInfo
:=
fmt
.
Sprintf
(
"Failed to ToECDSA due to:%s"
,
err
.
Error
())
relayerLog
.
Info
(
"RestorePrivateKeys"
,
"Failed to ToECDSA:"
,
err
.
Error
())
return
errors
.
New
(
errInfo
)
}
ethRelayer
.
rwLock
.
Lock
()
ethRelayer
.
privateKey4Ethereum
=
privateKeyECDSA
ethRelayer
.
rwLock
.
Unlock
()
if
nil
!=
ethRelayer
.
privateKey4Chain33
{
ethRelayer
.
unlockchan
<-
start
}
Encryptered
:=
wcom
.
CBCEncrypterPrivkey
([]
byte
(
passphrase
),
privateKeySli
)
ethAccount
:=
&
x2ethTypes
.
Account4Relayer
{
Privkey
:
Encryptered
,
Addr
:
crypto
.
PubkeyToAddress
(
privateKeyECDSA
.
PublicKey
)
.
String
(),
}
encodedInfo
:=
chain33Types
.
Encode
(
ethAccount
)
return
ethRelayer
.
db
.
SetSync
(
ethAccountKey
,
encodedInfo
)
}
//checksum: first four bytes of double-SHA256.
func
checksum
(
input
[]
byte
)
(
cksum
[
4
]
byte
)
{
h
:=
sha256
.
New
()
...
...
@@ -266,8 +207,7 @@ func newKeyAndStore(db dbm.DB, rand io.Reader, passphrase string) (privateKey *e
Privkey
:
Encryptered
,
Addr
:
key
.
Address
.
Hex
(),
}
encodedInfo
:=
chain33Types
.
Encode
(
ethAccount
)
_
=
db
.
SetSync
(
ethAccountKey
,
encodedInfo
)
_
=
db
privateKeyStr
=
chain33Common
.
ToHex
(
privateKeyBytes
)
addr
=
ethAccount
.
Addr
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/ethereum/ethereum.go
View file @
7b6d3277
...
...
@@ -39,15 +39,12 @@ import (
)
type
Relayer4Ethereum
struct
{
provider
string
clientChainID
*
big
.
Int
bridgeRegistryAddr
common
.
Address
//validatorName string
db
dbm
.
DB
//passphase string
provider
string
clientChainID
*
big
.
Int
bridgeRegistryAddr
common
.
Address
db
dbm
.
DB
rwLock
sync
.
RWMutex
privateKey4Chain33
chain33Crypto
.
PrivKey
privateKey4Ethereum
*
ecdsa
.
PrivateKey
ethValidator
common
.
Address
totalTx4Eth2Chain33
int64
totalTx4Chain33ToEth
int64
...
...
@@ -56,7 +53,6 @@ type Relayer4Ethereum struct {
maturityDegree
int32
fetchHeightPeriodMs
int32
eventLogIndex
ebTypes
.
EventLogIndex
status
int32
backend
bind
.
ContractBackend
bridgeBankAddr
common
.
Address
bridgeBankSub
ethereum
.
Subscription
...
...
@@ -88,7 +84,6 @@ func StartEthereumRelayer(rpcURL2Chain33 string, db dbm.DB, provider, registryAd
db
:
db
,
unlockchan
:
make
(
chan
int
,
2
),
rpcURL2Chain33
:
rpcURL2Chain33
,
status
:
ebTypes
.
StatusPending
,
bridgeRegistryAddr
:
common
.
HexToAddress
(
registryAddress
),
deployInfo
:
deploy
,
maturityDegree
:
degree
,
...
...
@@ -112,34 +107,6 @@ func StartEthereumRelayer(rpcURL2Chain33 string, db dbm.DB, provider, registryAd
return
relayer
}
func
(
ethRelayer
*
Relayer4Ethereum
)
SetPrivateKey4Ethereum
(
privateKey4Ethereum
*
ecdsa
.
PrivateKey
)
{
ethRelayer
.
rwLock
.
Lock
()
defer
ethRelayer
.
rwLock
.
Unlock
()
ethRelayer
.
privateKey4Ethereum
=
privateKey4Ethereum
if
ethRelayer
.
privateKey4Chain33
!=
nil
{
ethRelayer
.
unlockchan
<-
start
}
}
func
(
ethRelayer
*
Relayer4Ethereum
)
GetRunningStatus
()
(
relayerRunStatus
*
ebTypes
.
RelayerRunStatus
)
{
relayerRunStatus
=
&
ebTypes
.
RelayerRunStatus
{}
ethRelayer
.
rwLock
.
RLock
()
relayerRunStatus
.
Status
=
ethRelayer
.
status
ethRelayer
.
rwLock
.
RUnlock
()
if
relayerRunStatus
.
Status
==
ebTypes
.
StatusPending
{
if
nil
==
ethRelayer
.
privateKey4Ethereum
{
relayerRunStatus
.
Details
=
"Ethereum's private key not imported"
}
if
nil
==
ethRelayer
.
privateKey4Chain33
{
relayerRunStatus
.
Details
+=
"
\n
Chain33's private key not imported"
}
return
}
relayerRunStatus
.
Details
=
"Running"
return
}
func
(
ethRelayer
*
Relayer4Ethereum
)
recoverDeployPara
()
(
err
error
)
{
if
nil
==
ethRelayer
.
deployInfo
{
return
nil
...
...
@@ -162,24 +129,24 @@ func (ethRelayer *Relayer4Ethereum) recoverDeployPara() (err error) {
func
(
ethRelayer
*
Relayer4Ethereum
)
DeployContrcts
()
(
bridgeRegistry
string
,
err
error
)
{
bridgeRegistry
=
""
if
nil
==
ethRelayer
.
deployInfo
{
return
bridgeRegistry
,
errors
.
New
(
"
N
o deploy info configured yet"
)
return
bridgeRegistry
,
errors
.
New
(
"
n
o deploy info configured yet"
)
}
deployPrivateKey
,
err
:=
crypto
.
ToECDSA
(
common
.
FromHex
(
ethRelayer
.
deployInfo
.
DeployerPrivateKey
))
if
nil
!=
err
{
return
bridgeRegistry
,
err
}
if
len
(
ethRelayer
.
deployInfo
.
ValidatorsAddr
)
!=
len
(
ethRelayer
.
deployInfo
.
InitPowers
)
{
return
bridgeRegistry
,
errors
.
New
(
"
N
ot same number for validator address and power"
)
return
bridgeRegistry
,
errors
.
New
(
"
n
ot same number for validator address and power"
)
}
if
len
(
ethRelayer
.
deployInfo
.
ValidatorsAddr
)
<
3
{
return
bridgeRegistry
,
errors
.
New
(
"
T
he number of validator must be not less than 3"
)
return
bridgeRegistry
,
errors
.
New
(
"
t
he number of validator must be not less than 3"
)
}
nilAddr
:=
common
.
Address
{}
//已经设置了注册合约地址,说明已经部署了相关的合约,不再重复部署
if
ethRelayer
.
bridgeRegistryAddr
!=
nilAddr
{
return
bridgeRegistry
,
errors
.
New
(
"
C
ontract deployed already"
)
return
bridgeRegistry
,
errors
.
New
(
"
c
ontract deployed already"
)
}
var
validators
[]
common
.
Address
...
...
@@ -232,7 +199,7 @@ func (ethRelayer *Relayer4Ethereum) GetBalance(tokenAddr, owner string) (string,
func
(
ethRelayer
*
Relayer4Ethereum
)
ShowBridgeBankAddr
()
(
string
,
error
)
{
if
nil
==
ethRelayer
.
x2EthDeployInfo
{
return
""
,
errors
.
New
(
"
T
he relayer is not started yes"
)
return
""
,
errors
.
New
(
"
t
he relayer is not started yes"
)
}
return
ethRelayer
.
x2EthDeployInfo
.
BridgeBank
.
Address
.
String
(),
nil
...
...
@@ -240,7 +207,7 @@ func (ethRelayer *Relayer4Ethereum) ShowBridgeBankAddr() (string, error) {
func
(
ethRelayer
*
Relayer4Ethereum
)
ShowBridgeRegistryAddr
()
(
string
,
error
)
{
if
nil
==
ethRelayer
.
x2EthDeployInfo
{
return
""
,
errors
.
New
(
"
T
he relayer is not started yes"
)
return
""
,
errors
.
New
(
"
t
he relayer is not started yes"
)
}
return
ethRelayer
.
x2EthDeployInfo
.
BridgeRegistry
.
Address
.
String
(),
nil
...
...
@@ -262,10 +229,6 @@ func (ethRelayer *Relayer4Ethereum) IsProphecyPending(claimID [32]byte) (bool, e
return
ethtxs
.
IsProphecyPending
(
claimID
,
ethRelayer
.
ethValidator
,
ethRelayer
.
x2EthContracts
.
Chain33Bridge
)
}
func
(
ethRelayer
*
Relayer4Ethereum
)
MakeNewProphecyClaim
(
newProphecyClaimPara
*
ethtxs
.
NewProphecyClaimPara
)
(
string
,
error
)
{
return
ethtxs
.
MakeNewProphecyClaim
(
newProphecyClaimPara
,
ethRelayer
.
backend
,
ethRelayer
.
privateKey4Ethereum
,
ethRelayer
.
ethValidator
,
ethRelayer
.
x2EthContracts
)
}
func
(
ethRelayer
*
Relayer4Ethereum
)
CreateBridgeToken
(
symbol
string
)
(
string
,
error
)
{
return
ethtxs
.
CreateBridgeToken
(
symbol
,
ethRelayer
.
backend
,
ethRelayer
.
operatorInfo
,
ethRelayer
.
x2EthDeployInfo
,
ethRelayer
.
x2EthContracts
)
}
...
...
@@ -370,12 +333,7 @@ func (ethRelayer *Relayer4Ethereum) proc() {
continueFailCount
:=
int32
(
0
)
for
range
ethRelayer
.
unlockchan
{
relayerLog
.
Info
(
"Received ethRelayer.unlockchan"
)
if
nil
!=
ethRelayer
.
privateKey4Ethereum
&&
nil
!=
ethRelayer
.
privateKey4Chain33
&&
nilAddr
!=
ethRelayer
.
bridgeRegistryAddr
{
ethRelayer
.
ethValidator
,
err
=
ethtxs
.
LoadSender
(
ethRelayer
.
privateKey4Ethereum
)
if
nil
!=
err
{
errinfo
:=
fmt
.
Sprintf
(
"Failed to load validator for ethereum due to:%s"
,
err
.
Error
())
panic
(
errinfo
)
}
if
nil
!=
ethRelayer
.
privateKey4Chain33
&&
nilAddr
!=
ethRelayer
.
bridgeRegistryAddr
{
relayerLog
.
Info
(
"Ethereum relayer starts to run..."
)
ethRelayer
.
prePareSubscribeEvent
()
//向bridgeBank订阅事件
...
...
@@ -592,14 +550,14 @@ func (ethRelayer *Relayer4Ethereum) filterLogEventsProc(logchan chan<- types.Log
relayerLog
.
Info
(
title
,
"received logs with number"
,
len
(
logs
),
"start height"
,
query
.
FromBlock
.
String
(),
"stop height"
,
query
.
ToBlock
.
String
())
for
_
,
log
:=
range
logs
{
relayerLog
.
Info
(
title
,
"received log with topics"
,
log
.
Topics
[
0
]
.
Hex
(),
"BlockNumber"
,
log
.
BlockNumber
)
if
_
,
exist
:=
eventSig
[
log
.
Topics
[
0
]
.
Hex
()];
!
exist
{
for
_
,
log
v
:=
range
logs
{
relayerLog
.
Info
(
title
,
"received log with topics"
,
log
v
.
Topics
[
0
]
.
Hex
(),
"BlockNumber"
,
logv
.
BlockNumber
)
if
_
,
exist
:=
eventSig
[
log
v
.
Topics
[
0
]
.
Hex
()];
!
exist
{
continue
}
logchan
<-
log
relayerLog
.
Info
(
title
,
"get unprocessed log with topic:"
,
log
.
Topics
[
0
]
.
String
(),
"BlockNumber"
,
log
.
BlockNumber
)
logchan
<-
log
v
relayerLog
.
Info
(
title
,
"get unprocessed log with topic:"
,
log
v
.
Topics
[
0
]
.
String
(),
"BlockNumber"
,
log
v
.
BlockNumber
)
}
if
query
.
ToBlock
.
Int64
()
==
curHeight
{
...
...
plugin/dapp/x2ethereum/ebrelayer/relayer/manager.go
View file @
7b6d3277
...
...
@@ -3,7 +3,6 @@ package relayer
import
(
"errors"
"fmt"
"math/big"
"strconv"
"sync"
"sync/atomic"
...
...
@@ -12,13 +11,11 @@ import (
"github.com/33cn/chain33/common/log/log15"
rpctypes
"github.com/33cn/chain33/rpc/types"
chain33Types
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/ethtxs"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/relayer/chain33"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/relayer/ethereum"
relayerTypes
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/types"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/ebrelayer/utils"
"github.com/33cn/plugin/plugin/dapp/x2ethereum/types"
"github.com/ethereum/go-ethereum/common"
lru
"github.com/hashicorp/golang-lru"
)
...
...
@@ -66,6 +63,52 @@ func NewRelayerManager(chain33Relayer *chain33.Relayer4Chain33, ethRelayer *ethe
func
(
manager
*
Manager
)
SetPassphase
(
setPasswdReq
relayerTypes
.
ReqSetPasswd
,
result
*
interface
{})
error
{
manager
.
mtx
.
Lock
()
defer
manager
.
mtx
.
Unlock
()
// 第一次设置密码的时候才使用 后面用 ChangePasswd
if
EncryptEnable
==
manager
.
encryptFlag
{
return
errors
.
New
(
"passphase alreade exists"
)
}
// 密码合法性校验
if
!
utils
.
IsValidPassWord
(
setPasswdReq
.
Passphase
)
{
return
chain33Types
.
ErrInvalidPassWord
}
//使用密码生成passwdhash用于下次密码的验证
newBatch
:=
manager
.
store
.
NewBatch
(
true
)
err
:=
manager
.
store
.
SetPasswordHash
(
setPasswdReq
.
Passphase
,
newBatch
)
if
err
!=
nil
{
mlog
.
Error
(
"SetPassphase"
,
"SetPasswordHash err"
,
err
)
return
err
}
//设置钱包加密标志位
err
=
manager
.
store
.
SetEncryptionFlag
(
newBatch
)
if
err
!=
nil
{
mlog
.
Error
(
"SetPassphase"
,
"SetEncryptionFlag err"
,
err
)
return
err
}
err
=
newBatch
.
Write
()
if
err
!=
nil
{
mlog
.
Error
(
"ProcWalletSetPasswd newBatch.Write"
,
"err"
,
err
)
return
err
}
manager
.
passphase
=
setPasswdReq
.
Passphase
atomic
.
StoreInt64
(
&
manager
.
encryptFlag
,
EncryptEnable
)
*
result
=
rpctypes
.
Reply
{
IsOk
:
true
,
Msg
:
"Succeed to set passphase"
,
}
return
nil
}
func
(
manager
*
Manager
)
ChangePassphase
(
setPasswdReq
relayerTypes
.
ReqChangePasswd
,
result
*
interface
{})
error
{
manager
.
mtx
.
Lock
()
defer
manager
.
mtx
.
Unlock
()
if
setPasswdReq
.
OldPassphase
==
setPasswdReq
.
NewPassphase
{
return
errors
.
New
(
"the old password is the same as the new one"
)
}
// 新密码合法性校验
if
!
utils
.
IsValidPassWord
(
setPasswdReq
.
NewPassphase
)
{
return
chain33Types
.
ErrInvalidPassWord
...
...
@@ -80,16 +123,16 @@ func (manager *Manager) SetPassphase(setPasswdReq relayerTypes.ReqSetPasswd, res
}()
// 钱包已经加密需要验证oldpass的正确性
if
len
(
manager
.
passphase
)
==
0
&&
manager
.
encryptFlag
==
1
{
if
len
(
manager
.
passphase
)
==
0
&&
manager
.
encryptFlag
==
EncryptEnable
{
isok
:=
manager
.
store
.
VerifyPasswordHash
(
setPasswdReq
.
OldPassphase
)
if
!
isok
{
mlog
.
Error
(
"
Set
Passphase Verify Oldpasswd fail!"
)
mlog
.
Error
(
"
Change
Passphase Verify Oldpasswd fail!"
)
return
chain33Types
.
ErrVerifyOldpasswdFail
}
}
if
len
(
manager
.
passphase
)
!=
0
&&
setPasswdReq
.
OldPassphase
!=
manager
.
passphase
{
mlog
.
Error
(
"
Set
Passphase Oldpass err!"
)
mlog
.
Error
(
"
Change
Passphase Oldpass err!"
)
return
chain33Types
.
ErrVerifyOldpasswdFail
}
...
...
@@ -97,25 +140,25 @@ func (manager *Manager) SetPassphase(setPasswdReq relayerTypes.ReqSetPasswd, res
newBatch
:=
manager
.
store
.
NewBatch
(
true
)
err
:=
manager
.
store
.
SetPasswordHash
(
setPasswdReq
.
NewPassphase
,
newBatch
)
if
err
!=
nil
{
mlog
.
Error
(
"
Set
Passphase"
,
"SetPasswordHash err"
,
err
)
mlog
.
Error
(
"
Change
Passphase"
,
"SetPasswordHash err"
,
err
)
return
err
}
//设置钱包加密标志位
err
=
manager
.
store
.
SetEncryptionFlag
(
newBatch
)
if
err
!=
nil
{
mlog
.
Error
(
"
Set
Passphase"
,
"SetEncryptionFlag err"
,
err
)
mlog
.
Error
(
"
Change
Passphase"
,
"SetEncryptionFlag err"
,
err
)
return
err
}
err
=
manager
.
ethRelayer
.
StoreAccountWithNewPassphase
(
setPasswdReq
.
NewPassphase
,
setPasswdReq
.
OldPassphase
)
if
err
!=
nil
{
mlog
.
Error
(
"
Set
Passphase"
,
"StoreAccountWithNewPassphase err"
,
err
)
mlog
.
Error
(
"
Change
Passphase"
,
"StoreAccountWithNewPassphase err"
,
err
)
return
err
}
err
=
manager
.
chain33Relayer
.
StoreAccountWithNewPassphase
(
setPasswdReq
.
NewPassphase
,
setPasswdReq
.
OldPassphase
)
if
err
!=
nil
{
mlog
.
Error
(
"
Set
Passphase"
,
"StoreAccountWithNewPassphase err"
,
err
)
mlog
.
Error
(
"
Change
Passphase"
,
"StoreAccountWithNewPassphase err"
,
err
)
return
err
}
...
...
@@ -129,7 +172,7 @@ func (manager *Manager) SetPassphase(setPasswdReq relayerTypes.ReqSetPasswd, res
*
result
=
rpctypes
.
Reply
{
IsOk
:
true
,
Msg
:
"Succeed to
set
passphase"
,
Msg
:
"Succeed to
change
passphase"
,
}
return
nil
}
...
...
@@ -239,23 +282,6 @@ func (manager *Manager) ImportChain33PrivateKey4EthRelayer(privateKey string, re
return
nil
}
//为ethrelayer导入chain33私钥,为向chain33发送交易时进行签名使用
func
(
manager
*
Manager
)
ImportEthValidatorPrivateKey
(
privateKey
string
,
result
*
interface
{})
error
{
manager
.
mtx
.
Lock
()
defer
manager
.
mtx
.
Unlock
()
if
err
:=
manager
.
checkPermission
();
nil
!=
err
{
return
err
}
if
err
:=
manager
.
ethRelayer
.
ImportEthValidatorPrivateKey
(
manager
.
passphase
,
privateKey
);
nil
!=
err
{
return
err
}
*
result
=
rpctypes
.
Reply
{
IsOk
:
true
,
Msg
:
"Succeed to import ethereum private key for validator"
,
}
return
nil
}
//显示在chain33中以验证人validator身份进行登录的地址
func
(
manager
*
Manager
)
ShowChain33RelayerValidator
(
param
interface
{},
result
*
interface
{})
error
{
manager
.
mtx
.
Lock
()
...
...
@@ -459,38 +485,6 @@ func (manager *Manager) LockEthErc20Asset(lockEthErc20Asset relayerTypes.LockEth
return
nil
}
func
(
manager
*
Manager
)
MakeNewProphecyClaim
(
newProphecyClaim
relayerTypes
.
NewProphecyClaim
,
result
*
interface
{})
error
{
manager
.
mtx
.
Lock
()
defer
manager
.
mtx
.
Unlock
()
if
err
:=
manager
.
checkPermission
();
nil
!=
err
{
return
err
}
var
tokenAddress
common
.
Address
if
""
!=
newProphecyClaim
.
TokenAddr
{
tokenAddress
=
common
.
HexToAddress
(
newProphecyClaim
.
TokenAddr
)
}
bn
:=
big
.
NewInt
(
1
)
bn
,
_
=
bn
.
SetString
(
types
.
TrimZeroAndDot
(
newProphecyClaim
.
Amount
),
10
)
newProphecyClaimPara
:=
&
ethtxs
.
NewProphecyClaimPara
{
ClaimType
:
uint8
(
newProphecyClaim
.
ClaimType
),
Chain33Sender
:
[]
byte
(
newProphecyClaim
.
Chain33Sender
),
TokenAddr
:
tokenAddress
,
EthReceiver
:
common
.
HexToAddress
(
newProphecyClaim
.
EthReceiver
),
Symbol
:
newProphecyClaim
.
Symbol
,
Amount
:
bn
,
Txhash
:
common
.
FromHex
(
newProphecyClaim
.
TxHash
),
}
txhash
,
err
:=
manager
.
ethRelayer
.
MakeNewProphecyClaim
(
newProphecyClaimPara
)
if
nil
!=
err
{
return
err
}
*
result
=
rpctypes
.
Reply
{
IsOk
:
true
,
Msg
:
fmt
.
Sprintf
(
"Tx:%s"
,
txhash
),
}
return
nil
}
func
(
manager
*
Manager
)
IsProphecyPending
(
claimID
[
32
]
byte
,
result
*
interface
{})
error
{
manager
.
mtx
.
Lock
()
defer
manager
.
mtx
.
Unlock
()
...
...
@@ -637,20 +631,6 @@ func (manager *Manager) checkPermission() error {
return
nil
}
func
(
manager
*
Manager
)
ShowEthRelayerStatus
(
param
interface
{},
result
*
interface
{})
error
{
manager
.
mtx
.
Lock
()
defer
manager
.
mtx
.
Unlock
()
*
result
=
manager
.
ethRelayer
.
GetRunningStatus
()
return
nil
}
func
(
manager
*
Manager
)
ShowChain33RelayerStatus
(
param
interface
{},
result
*
interface
{})
error
{
manager
.
mtx
.
Lock
()
defer
manager
.
mtx
.
Unlock
()
*
result
=
manager
.
chain33Relayer
.
GetRunningStatus
()
return
nil
}
func
(
manager
*
Manager
)
ShowEthRelayer2EthTxs
(
param
interface
{},
result
*
interface
{})
error
{
*
result
=
manager
.
ethRelayer
.
QueryTxhashRelay2Eth
()
return
nil
...
...
plugin/dapp/x2ethereum/ebrelayer/types/config.pb.go
View file @
7b6d3277
This diff is collapsed.
Click to expand it.
plugin/dapp/x2ethereum/ebrelayer/types/protos/relayer.proto
View file @
7b6d3277
...
...
@@ -11,19 +11,22 @@ message Account4Relayer {
}
message
ValidatorAddr4EthRelayer
{
string
ethValidator
=
1
;
string
chain33Validator
=
2
;
string
chain33Validator
=
1
;
}
message
Txhashes
{
repeated
string
txhash
=
1
;
}
message
Req
Set
Passwd
{
message
Req
Change
Passwd
{
string
oldPassphase
=
1
;
string
newPassphase
=
2
;
}
message
ReqSetPasswd
{
string
Passphase
=
1
;
}
message
Account4Show
{
string
privkey
=
1
;
string
addr
=
2
;
...
...
plugin/dapp/x2ethereum/ebrelayer/types/relayer.pb.go
View file @
7b6d3277
This diff is collapsed.
Click to expand it.
plugin/dapp/x2ethereum/executor/exec_test.go
View file @
7b6d3277
...
...
@@ -170,14 +170,14 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
payload
:=
&
types2
.
Eth2Chain33
{
EthereumChainID
:
0
,
BridgeContractAddress
:
bridgeContractAddress
,
Nonce
:
0
,
IssuerDotSymbol
:
symbol
,
TokenContractAddress
:
tokenContractAddress
,
EthereumSender
:
ethereumAddr
,
Chain33Receiver
:
chain33Receiver
,
ValidatorAddress
:
addValidator1
,
Amount
:
"10"
,
ClaimType
:
int64
(
types2
.
LockClaimType
),
Nonce
:
0
,
IssuerDotSymbol
:
symbol
,
TokenContractAddress
:
tokenContractAddress
,
EthereumSender
:
ethereumAddr
,
Chain33Receiver
:
chain33Receiver
,
ValidatorAddress
:
addValidator1
,
Amount
:
"10"
,
ClaimType
:
int64
(
types2
.
LockClaimType
),
}
receipt
,
err
:=
x
.
action
.
procEth2Chain33_lock
(
payload
)
...
...
plugin/dapp/x2ethereum/executor/x2ethereumaction.go
View file @
7b6d3277
...
...
@@ -92,18 +92,18 @@ func (a *action) procEth2Chain33_lock(ethBridgeClaim *x2eTy.Eth2Chain33) (*types
execlog
:=
&
types
.
ReceiptLog
{
Ty
:
x2eTy
.
TyEth2Chain33Log
,
Log
:
types
.
Encode
(
&
x2eTy
.
ReceiptEth2Chain33
{
EthereumChainID
:
ethBridgeClaim
.
EthereumChainID
,
BridgeContractAddress
:
ethBridgeClaim
.
BridgeContractAddress
,
Nonce
:
ethBridgeClaim
.
Nonce
,
IssuerDotSymbol
:
ethBridgeClaim
.
IssuerDotSymbol
,
EthereumSender
:
ethBridgeClaim
.
EthereumSender
,
Chain33Receiver
:
ethBridgeClaim
.
Chain33Receiver
,
ValidatorAddress
:
ethBridgeClaim
.
ValidatorAddress
,
Amount
:
ethBridgeClaim
.
Amount
,
ClaimType
:
ethBridgeClaim
.
ClaimType
,
XTxHash
:
a
.
txhash
,
XHeight
:
uint64
(
a
.
height
),
ProphecyID
:
ID
,
Decimals
:
ethBridgeClaim
.
Decimals
,
TokenAddress
:
ethBridgeClaim
.
TokenContractAddress
,
Nonce
:
ethBridgeClaim
.
Nonce
,
IssuerDotSymbol
:
ethBridgeClaim
.
IssuerDotSymbol
,
EthereumSender
:
ethBridgeClaim
.
EthereumSender
,
Chain33Receiver
:
ethBridgeClaim
.
Chain33Receiver
,
ValidatorAddress
:
ethBridgeClaim
.
ValidatorAddress
,
Amount
:
ethBridgeClaim
.
Amount
,
ClaimType
:
ethBridgeClaim
.
ClaimType
,
XTxHash
:
a
.
txhash
,
XHeight
:
uint64
(
a
.
height
),
ProphecyID
:
ID
,
Decimals
:
ethBridgeClaim
.
Decimals
,
TokenAddress
:
ethBridgeClaim
.
TokenContractAddress
,
})}
receipt
.
Logs
=
append
(
receipt
.
Logs
,
execlog
)
...
...
@@ -251,18 +251,18 @@ func (a *action) procEth2Chain33_burn(withdrawEth *x2eTy.Eth2Chain33) (*types.Re
execlog
:=
&
types
.
ReceiptLog
{
Ty
:
x2eTy
.
TyWithdrawEthLog
,
Log
:
types
.
Encode
(
&
x2eTy
.
ReceiptEth2Chain33
{
EthereumChainID
:
withdrawEth
.
EthereumChainID
,
BridgeContractAddress
:
withdrawEth
.
BridgeContractAddress
,
Nonce
:
withdrawEth
.
Nonce
,
IssuerDotSymbol
:
withdrawEth
.
IssuerDotSymbol
,
EthereumSender
:
withdrawEth
.
EthereumSender
,
Chain33Receiver
:
withdrawEth
.
Chain33Receiver
,
ValidatorAddress
:
withdrawEth
.
ValidatorAddress
,
Amount
:
withdrawEth
.
Amount
,
ClaimType
:
withdrawEth
.
ClaimType
,
XTxHash
:
a
.
txhash
,
XHeight
:
uint64
(
a
.
height
),
ProphecyID
:
ID
,
Decimals
:
withdrawEth
.
Decimals
,
TokenAddress
:
withdrawEth
.
TokenContractAddress
,
Nonce
:
withdrawEth
.
Nonce
,
IssuerDotSymbol
:
withdrawEth
.
IssuerDotSymbol
,
EthereumSender
:
withdrawEth
.
EthereumSender
,
Chain33Receiver
:
withdrawEth
.
Chain33Receiver
,
ValidatorAddress
:
withdrawEth
.
ValidatorAddress
,
Amount
:
withdrawEth
.
Amount
,
ClaimType
:
withdrawEth
.
ClaimType
,
XTxHash
:
a
.
txhash
,
XHeight
:
uint64
(
a
.
height
),
ProphecyID
:
ID
,
Decimals
:
withdrawEth
.
Decimals
,
TokenAddress
:
withdrawEth
.
TokenContractAddress
,
})}
receipt
.
Logs
=
append
(
receipt
.
Logs
,
execlog
)
...
...
plugin/dapp/x2ethereum/testsh/allRelayerTest.sh
View file @
7b6d3277
...
...
@@ -17,14 +17,11 @@ docker_chain33_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPA
Chain33Cli
=
"
$GOPATH
/src/github.com/33cn/plugin/build/chain33-cli --rpc_laddr http://
${
docker_chain33_ip
}
:8801"
chain33SenderAddr
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
chain33SenderAddrKey
=
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
# validatorsAddr=["0x92c8b16afd6d423652559c6e266cbe1c29bfd84f", "0x0df9a824699bc5878232c9e612fe1a5346a5a368", "0xcb074cb21cdddf3ce9c3c0a7ac4497d633c9d9f1", "0xd9dab021e74ecf475788ed7b61356056b2095830"]
ethValidatorAddrKeyA
=
"3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
ethValidatorAddrKeyB
=
"a5f3063552f4483cfc20ac4f40f45b798791379862219de9e915c64722c1d400"
ethValidatorAddrKeyC
=
"bbf5e65539e9af0eb0cfac30bad475111054b09c11d668fc0731d54ea777471e"
ethValidatorAddrKeyD
=
"c9fa31d7984edf81b8ef3b40c761f1847f6fcd5711ab2462da97dc458f1f896b"
# 新增地址 chain33 需要导入地址 转入 10 bty当收费费
chain33Validator1
=
"1GTxrmuWiXavhcvsaH5w9whgVxUrWsUMdV"
chain33Validator2
=
"155ooMPBTF8QQsGAknkK7ei5D78rwDEFe6"
...
...
@@ -34,16 +31,16 @@ chain33ValidatorKey1="0xd627968e445f2a41c92173225791bae1ba42126ae96c32f28f97ff8f
chain33ValidatorKey2
=
"0x9d539bc5fd084eb7fe86ad631dba9aa086dba38418725c38d9751459f567da66"
chain33ValidatorKey3
=
"0x0a6671f101e30a2cc2d79d77436b62cdf2664ed33eb631a9c9e3f3dd348a23be"
chain33ValidatorKey4
=
"0x3818b257b05ee75b6e43ee0e3cfc2d8502342cf67caed533e3756966690b62a5"
ethReceiverAddr1
=
"0xa4ea64a583f6e51c3799335b28a8f0529570a635"
ethReceiverAddrKey1
=
"355b876d7cbcb930d5dfab767f66336ce327e082cbaa1877210c1bae89b1df71"
ethReceiverAddr2
=
"0x0c05ba5c230fdaa503b53702af1962e08d0c60bf"
ethReceiverAddrKey2
=
"9dc6df3a8ab139a54d8a984f54958ae0661f880229bf3bdbb886b87d58b56a08"
maturityDegree
=
10
function
InitAndDeploy
()
{
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
result
=
$(${
CLIA
}
relayer set_pwd
-
n
123456hzj
-o
kk
)
result
=
$(${
CLIA
}
relayer set_pwd
-
p
123456hzj
)
cli_ret
"
${
result
}
"
"set_pwd"
result
=
$(${
CLIA
}
relayer unlock
-p
123456hzj
)
...
...
@@ -59,12 +56,12 @@ function EthImportKey() {
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
# 重启 ebrelayer 并解锁
for
name
in
A B C D
;
do
start_ebrelayer
"../build/
"
$name
"/ebrelayer"
"../build/"
$name
"
/ebrelayer.log"
start_ebrelayer
"../build/
$name
/ebrelayer"
"../build/
$name
/ebrelayer.log"
# 导入测试地址私钥
CLI
=
"../build/ebcli_
$name
"
result
=
$(${
CLI
}
relayer set_pwd
-
n
123456hzj
-o
kk
)
result
=
$(${
CLI
}
relayer set_pwd
-
p
123456hzj
)
#cli_ret "${result}" "set_pwd"
result
=
$(${
CLI
}
relayer unlock
-p
123456hzj
)
...
...
@@ -80,15 +77,6 @@ function EthImportKey() {
result
=
$(${
CLID
}
relayer ethereum import_chain33privatekey
-k
"
${
chain33ValidatorKey4
}
"
)
cli_ret
"
${
result
}
"
"import_chain33privatekey"
result
=
$(${
CLIA
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyA
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekey"
result
=
$(${
CLIB
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyB
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekeyB"
result
=
$(${
CLIC
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyC
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekeyC"
result
=
$(${
CLID
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyD
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekeyD"
result
=
$(${
CLIA
}
relayer chain33 import_privatekey
-k
"
${
ethValidatorAddrKeyA
}
"
)
cli_ret
"
${
result
}
"
"A relayer chain33 import_privatekey"
result
=
$(${
CLIB
}
relayer chain33 import_privatekey
-k
"
${
ethValidatorAddrKeyB
}
"
)
...
...
@@ -129,7 +117,7 @@ function StartRelayerAndDeploy() {
kill_ebrelayer
"../build/A/ebrelayer"
# 修改 relayer.toml 配置文件
updata_relayer_toml
${
BridgeRegistry
}
${
maturityDegree
}
"../build/A/relayer.toml"
updata_relayer_toml
"
${
BridgeRegistry
}
"
${
maturityDegree
}
"../build/A/relayer.toml"
updata_all_relayer_toml
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
...
...
@@ -164,7 +152,7 @@ function InitChain33Vilators() {
# query Validators
totalPower
=
$(${
Chain33Cli
}
send x2ethereum query totalpower
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv | jq .totalPower |
sed
's/\"//g'
)
check_number 100
${
totalPower
}
check_number 100
"
${
totalPower
}
"
# cions 转帐到 x2ethereum 合约地址
hash
=
$(${
Chain33Cli
}
send coins send_exec
-e
x2ethereum
-a
200
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
...
...
@@ -207,7 +195,7 @@ function TestChain33ToEthAssets() {
cli_ret
"
${
result
}
"
"balance"
".balance"
"0"
# chain33 lock bty
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
5
-t
coins.bty
-r
${
ethReceiverAddr1
}
-q
${
tokenAddr
}
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
5
-t
coins.bty
-r
${
ethReceiverAddr1
}
-q
"
${
tokenAddr
}
"
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
2
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
@@ -276,7 +264,7 @@ function TestETH2Chain33Assets() {
cli_ret
"
${
result
}
"
"balance"
".balance"
"0"
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
$(
echo
"
${
balance
}
+10"
| bc
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"
$(
echo
"
${
balance
}
+10"
| bc
)
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
...
...
@@ -320,7 +308,7 @@ function TestETH2Chain33Erc20() {
balance_ret
"
${
result
}
"
"100"
# chain33 burn 100
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
100
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
${
tokenAddr
}
-k
"
${
chain33Validator1
}
"
)
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
100
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
"
${
tokenAddr
}
"
-k
"
${
chain33Validator1
}
"
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
2
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
@@ -354,7 +342,7 @@ function TestChain33ToEthAssetsKill() {
kill_ebrelayerD
# chain33 lock bty
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
5
-t
bty
-r
${
ethReceiverAddr2
}
-q
${
tokenAddrBty
}
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
5
-t
bty
-r
${
ethReceiverAddr2
}
-q
"
${
tokenAddrBty
}
"
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
2
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
@@ -445,7 +433,7 @@ function TestETH2Chain33AssetsKill() {
start_ebrelayerD
result
=
$(${
CLIA
}
relayer ethereum balance
-o
"
${
ethReceiverAddr2
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
$(
echo
"
${
balance
}
+0.1"
| bc
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"
$(
echo
"
${
balance
}
+0.1"
| bc
)
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
...
...
@@ -501,7 +489,7 @@ function TestETH2Chain33Erc20Kill() {
kill_ebrelayerD
# chain33 burn 100
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
100
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
${
tokenAddr
}
-k
"
${
chain33Validator1
}
"
)
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
100
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
"
${
tokenAddr
}
"
-k
"
${
chain33Validator1
}
"
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
2
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
plugin/dapp/x2ethereum/testsh/bridgeBankTest.sh
View file @
7b6d3277
#!/usr/bin/env bash
# shellcheck disable=SC2128
# shellcheck source=/dev/null
set
-x
# 只启动 eth 这一端的测试
# 只启动一个 relayer 第一个地址权重设置超过2/3
...
...
@@ -9,18 +11,11 @@ CLI="../build/ebcli_A"
chain33SenderAddr
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
chain33SenderAddrKey
=
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
# 0x92C8b16aFD6d423652559C6E266cBE1c29Bfd84f
ethValidatorAddrKey
=
"3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
ethReceiverAddr1
=
"0xa4ea64a583f6e51c3799335b28a8f0529570a635"
ethReceiverAddrKey1
=
"355b876d7cbcb930d5dfab767f66336ce327e082cbaa1877210c1bae89b1df71"
ethReceiverAddr2
=
"0x0c05ba5c230fdaa503b53702af1962e08d0c60bf"
ethReceiverAddrKey2
=
"9dc6df3a8ab139a54d8a984f54958ae0661f880229bf3bdbb886b87d58b56a08"
ethReceiverAddr3
=
"0x1919203bA8b325278d28Fb8fFeac49F2CD881A4e"
#ethReceiverAddrKey3="62ca4122aac0e6f35bed02fc15c7ddbdaa07f2f2a1821c8b8210b891051e3ee9"
prophecyTx0
=
"0x112260c98aec81b3e235af47c355db720f60e751cce100fed6f334e1b1530bde"
prophecyTx1
=
"0x222260c98aec81b3e235af47c355db720f60e751cce100fed6f334e1b1530bde"
...
...
@@ -31,9 +26,9 @@ prophecyTx5="0x662260c98aec81b3e235af47c355db720f60e751cce100fed6f334e1b1530bde"
prophecyTx6
=
"0x772260c98aec81b3e235af47c355db720f60e751cce100fed6f334e1b1530bde"
InitAndDeploy
()
{
echo
"===========
$FUNCNAME
begin ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
result
=
$(${
CLI
}
relayer set_pwd
-
n
123456hzj
-o
kk
)
result
=
$(${
CLI
}
relayer set_pwd
-
p
123456hzj
)
cli_ret
"
${
result
}
"
"set_pwd"
result
=
$(${
CLI
}
relayer unlock
-p
123456hzj
)
...
...
@@ -45,17 +40,14 @@ InitAndDeploy() {
result
=
$(${
CLI
}
relayer ethereum import_chain33privatekey
-k
"
${
chain33SenderAddrKey
}
"
)
cli_ret
"
${
result
}
"
"import_chain33privatekey"
result
=
$(${
CLI
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKey
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekey"
echo
"===========
$FUNCNAME
end ==========="
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
# eth to chain33
# 在以太坊上锁定资产,然后在 chain33 上铸币,针对 erc20 资产
# 以太坊 brun 资产,balance 对比是否正确
TestETH2Chain33Erc20
()
{
echo
"===========
$FUNCNAME
begin ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
${
CLI
}
relayer unlock
-p
123456hzj
# token4erc20 在 chain33 上先有 token,同时 mint
...
...
@@ -116,11 +108,11 @@ TestETH2Chain33Erc20() {
result
=
$(${
CLI
}
relayer ethereum balance
-o
"
${
bridgeBankAddr
}
"
-t
"
${
tokenSymbol
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"0"
echo
"===========
$FUNCNAME
end ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
TestETH2Chain33Erc20_err
()
{
echo
"===========
$FUNCNAME
begin ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
${
CLI
}
relayer unlock
-p
123456hzj
# token4erc20 在 chain33 上先有 token,同时 mint
...
...
@@ -187,13 +179,13 @@ TestETH2Chain33Erc20_err() {
result
=
$(${
CLI
}
relayer ethereum balance
-o
"
${
bridgeBankAddr
}
"
-t
"
${
tokenSymbol
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"300"
echo
"===========
$FUNCNAME
end ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
# eth to chain33
# 在以太坊上锁定资产,然后在 chain33 上铸币,针对 eth 资产
TestETH2Chain33Assets
()
{
echo
"===========
$FUNCNAME
begin ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
${
CLI
}
relayer unlock
-p
123456hzj
result
=
$(${
CLI
}
relayer ethereum bridgeBankAddr
)
...
...
@@ -273,14 +265,14 @@ TestETH2Chain33Assets() {
result
=
$(${
CLI
}
relayer ethereum balance
-o
"
${
bridgeBankAddr
}
"
)
cli_ret
"
${
result
}
"
"balance"
".balance"
"0"
echo
"===========
$FUNCNAME
end ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
# chain33 to eth
# 在 chain33 上锁定资产,然后在以太坊上铸币
# chain33 brun 资产,balance 对比是否正确
TestChain33ToEthAssets
()
{
echo
"===========
$FUNCNAME
begin ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
result
=
$(${
CLI
}
relayer unlock
-p
123456hzj
)
# token4chain33 在 以太坊 上先有 bty
result
=
$(${
CLI
}
relayer ethereum token4chain33
-s
coins.bty
)
...
...
@@ -334,7 +326,7 @@ TestChain33ToEthAssets() {
result
=
$(${
CLI
}
relayer ethereum burn
-m
10
-k
"
${
ethReceiverAddrKey1
}
"
-r
"
${
chain33SenderAddr
}
"
-t
"
${
tokenAddr
}
"
)
cli_ret_err
"
${
result
}
"
echo
"===========
$FUNCNAME
end ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
main
()
{
...
...
plugin/dapp/x2ethereum/testsh/ebrelayerTest.sh
View file @
7b6d3277
#!/usr/bin/env bash
# shellcheck disable=SC2128
# shellcheck source=/dev/null
set
-x
# 只启动 eth 这一端的测试
...
...
@@ -6,9 +8,6 @@ set -x
source
"./publicTest.sh"
CLIA
=
"../build/ebcli_A"
CLIB
=
"../build/ebcli_B"
CLIC
=
"../build/ebcli_C"
CLID
=
"../build/ebcli_D"
tokenAddr
=
""
chain33SenderAddr
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
...
...
@@ -20,7 +19,7 @@ prophecyTx0="0x772260c98aec81b3e235af47c355db720f60e751cce100fed6f334e1b1530bde"
# 初始化部署合约
InitAndDeploy
()
{
echo
"===========
$FUNCNAME
begin ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
# 创建文件夹及拷贝
rm
-rf
'../build/A'
'../build/B'
'../build/C'
'../build/D'
mkdir
'../build/A'
'../build/B'
'../build/C'
'../build/D'
...
...
@@ -28,7 +27,7 @@ InitAndDeploy() {
cp
'../build/ebrelayer'
'../build/A/ebrelayer'
start_ebrelayer
"./../build/A/ebrelayer"
"./../build/A/ebrelayer.log"
result
=
$(${
CLIA
}
relayer set_pwd
-
n
123456hzj
-o
kk
)
result
=
$(${
CLIA
}
relayer set_pwd
-
p
123456hzj
)
cli_ret
"
${
result
}
"
"set_pwd"
result
=
$(${
CLIA
}
relayer unlock
-p
123456hzj
)
...
...
@@ -36,52 +35,47 @@ InitAndDeploy() {
result
=
$(${
CLIA
}
relayer ethereum deploy
)
cli_ret
"
${
result
}
"
"deploy"
echo
"===========
$FUNCNAME
end ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
# 初始化 B C D 文件夹下的文容
function
InitConfigFile
()
{
echo
"===========
$FUNCNAME
begin ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
# 获取 BridgeRegistry 地址
result
=
$(${
CLIA
}
relayer ethereum bridgeRegistry
)
BridgeRegistry
=
$(
cli_ret
"
${
result
}
"
"bridgeRegistry"
".addr"
)
port
=
9901
for
name
in
B C D
;
do
file
=
"../build/
"
$name
"
/relayer.toml"
file
=
"../build/
$name
/relayer.toml"
cp
'../build/relayer.toml'
"
${
file
}
"
cp
'../build/ebrelayer'
"../build/
"
$name
"
/ebrelayer"
cp
'../build/ebrelayer'
"../build/
$name
/ebrelayer"
# 删除配置文件中不需要的字段
for
deleteName
in
"BridgeRegistry"
"deployerPrivateKey"
"operatorAddr"
"validatorsAddr"
"initPowers"
"deployerPrivateKey"
"
\[
deploy
\]
"
;
do
for
deleteName
in
"BridgeRegistry"
"deployerPrivateKey"
"operatorAddr"
"validatorsAddr"
"initPowers"
"deployerPrivateKey"
"
deploy
"
;
do
delete_line
"
${
file
}
"
"
${
deleteName
}
"
done
# 在第 5 行后面 新增合约地址
sed
-i
'5 a BridgeRegistry="'
${
BridgeRegistry
}
'"'
"
${
file
}
"
sed
-i
'5 a BridgeRegistry="'
"
${
BridgeRegistry
}
"
'"'
"
${
file
}
"
# 替换端口
port
=
$((
port
+
1
))
sed
-i
's/localhost:9901/localhost:'
${
port
}
'/g'
"
${
file
}
"
done
echo
"===========
$FUNCNAME
end ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
# 启动 B C D 的 ebrelayer 服务,导入私钥
function
ImportCBDKey
()
{
echo
"===========
$FUNCNAME
begin ==========="
local
ethValidatorAddrKeyA
=
"3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
local
ethValidatorAddrKeyB
=
"a5f3063552f4483cfc20ac4f40f45b798791379862219de9e915c64722c1d400"
local
ethValidatorAddrKeyC
=
"bbf5e65539e9af0eb0cfac30bad475111054b09c11d668fc0731d54ea777471e"
local
ethValidatorAddrKeyD
=
"c9fa31d7984edf81b8ef3b40c761f1847f6fcd5711ab2462da97dc458f1f896b"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
for
name
in
B C D
;
do
start_ebrelayer
"./../build/
"
$name
"/ebrelayer"
"./../build/"
$name
"
/ebrelayer.log"
start_ebrelayer
"./../build/
$name
/ebrelayer"
"./../build/
$name
/ebrelayer.log"
# 导入测试地址私钥
CLI
=
"../build/ebcli_
$name
"
result
=
$(${
CLI
}
relayer set_pwd
-
n
123456hzj
-o
kk
)
result
=
$(${
CLI
}
relayer set_pwd
-
p
123456hzj
)
cli_ret
"
${
result
}
"
"set_pwd"
result
=
$(${
CLI
}
relayer unlock
-p
123456hzj
)
...
...
@@ -93,24 +87,12 @@ function ImportCBDKey() {
result
=
$(${
CLIA
}
relayer ethereum import_chain33privatekey
-k
"
${
chain33SenderAddrKey
}
"
)
cli_ret
"
${
result
}
"
"import_chain33privatekey"
result
=
$(${
CLIA
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyA
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekey"
result
=
$(${
CLIB
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyB
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekeyB"
result
=
$(${
CLIC
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyC
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekeyC"
result
=
$(${
CLID
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKeyD
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekeyD"
echo
"===========
$FUNCNAME
end ==========="
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
# chain33 到 eth,chian33 lock 100,必须 A B C D 中有三个都lock,才能成功
TestChain33ToEth
()
{
echo
"===========
$FUNCNAME
begin ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
# token4chain33 在 以太坊 上先有 bty
result
=
$(${
CLIA
}
relayer ethereum token4chain33
-s
coins.bty
)
tokenAddr
=
$(
cli_ret
"
${
result
}
"
"token4chain33"
".addr"
)
...
...
@@ -147,7 +129,7 @@ TestChain33ToEth() {
result
=
$(${
CLIA
}
relayer ethereum burn
-m
90
-k
"
${
ethReceiverAddrKey1
}
"
-r
"
${
chain33SenderAddr
}
"
-t
"
${
tokenAddr
}
"
)
cli_ret
"
${
result
}
"
"burn"
echo
"===========
$FUNCNAME
end ===========
"
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
}
main
()
{
...
...
plugin/dapp/x2ethereum/testsh/publicTest.sh
View file @
7b6d3277
#!/usr/bin/env bash
# shellcheck disable=SC2128
# shellcheck source=/dev/null
# shellcheck disable=SC2155
set
-x
set
-e
...
...
@@ -39,7 +40,7 @@ function cli_ret() {
msg
=
$(
echo
"
${
1
}
"
| jq
-r
"
${
jqMsg
}
"
)
if
[[
$#
-eq
4
]]
;
then
if
[
$(
echo
"
$msg
<
$4
"
| bc
)
-eq
1
]
||
[
$(
echo
"
$msg
>
$4
"
| bc
)
-eq
1
]
;
then
if
[
"
$(
echo
"
$msg
<
$4
"
| bc
)
"
-eq
1
]
||
[
"
$(
echo
"
$msg
>
$4
"
| bc
)
"
-eq
1
]
;
then
echo
-e
"
${
RED
}
The balance is not correct
${
NOC
}
"
exit
1
fi
...
...
@@ -58,7 +59,7 @@ function balance_ret() {
fi
local
balance
=
$(
echo
"
${
1
}
"
| jq
-r
".balance"
)
if
[
$(
echo
"
$balance
<
$2
"
| bc
)
-eq
1
]
||
[
$(
echo
"
$balance
>
$2
"
| bc
)
-eq
1
]
;
then
if
[
"
$(
echo
"
$balance
<
$2
"
| bc
)
"
-eq
1
]
||
[
"
$(
echo
"
$balance
>
$2
"
| bc
)
"
-eq
1
]
;
then
echo
-e
"
${
RED
}
The balance is not correct
${
NOC
}
"
exit
1
fi
...
...
@@ -115,6 +116,7 @@ function start_ebrelayer() {
nohup
"
${
1
}
"
>
"
${
2
}
"
2>&1 &
sleep
2
# shellcheck disable=SC2009
pid
=
$(
ps
-ef
|
grep
"
${
1
}
"
|
grep
-v
'grep'
|
awk
'{print $2}'
)
local
count
=
0
while
[
"
${
pid
}
"
==
""
]
;
do
...
...
@@ -127,6 +129,7 @@ function start_ebrelayer() {
exit
1
fi
# shellcheck disable=SC2009
pid
=
$(
ps
-ef
|
grep
"
${
1
}
"
|
grep
-v
'grep'
|
awk
'{print $2}'
)
done
}
...
...
@@ -162,7 +165,7 @@ function start_ebrelayer_and_setpwd_unlock() {
local
CLI
=
"./ebcli_
$1
"
local
count
=
0
while
true
;
do
result
=
$(${
CLI
}
relayer set_pwd
-
n
123456hzj
-o
kk
| jq
-r
.isOK
)
result
=
$(${
CLI
}
relayer set_pwd
-
p
123456hzj
| jq
-r
.isOK
)
if
[[
${
result
}
==
"true"
]]
;
then
break
fi
...
...
@@ -195,6 +198,7 @@ function start_ebrelayer_and_setpwd_unlock() {
# 杀死进程ebrelayer 进程 $1进程名称
function
kill_ebrelayer
()
{
# shellcheck disable=SC2009
pid
=
$(
ps
-ef
|
grep
"
${
1
}
"
|
grep
-v
'grep'
|
awk
'{print $2}'
)
if
[
"
${
pid
}
"
==
""
]
;
then
echo
"not find
${
1
}
pid"
...
...
@@ -202,6 +206,7 @@ function kill_ebrelayer() {
fi
kill
"
${
pid
}
"
# shellcheck disable=SC2009
pid
=
$(
ps
-ef
|
grep
"
${
1
}
"
|
grep
-v
'grep'
|
awk
'{print $2}'
)
if
[
"
${
pid
}
"
!=
""
]
;
then
echo
"kill
${
1
}
failed"
...
...
@@ -255,7 +260,7 @@ function check_tx() {
local
count
=
0
while
true
;
do
ty
=
$(${
CLI
}
tx query
-s
${
2
}
| jq .receipt.ty
)
ty
=
$(${
CLI
}
tx query
-s
"
${
2
}
"
| jq .receipt.ty
)
if
[[
${
ty
}
!=
""
]]
;
then
break
fi
...
...
@@ -271,7 +276,7 @@ function check_tx() {
set
-x
ty
=
$(${
CLI
}
tx query
-s
${
2
}
| jq .receipt.ty
)
ty
=
$(${
CLI
}
tx query
-s
"
${
2
}
"
| jq .receipt.ty
)
if
[[
${
ty
}
!=
2
]]
;
then
echo
-e
"
${
RED
}
check tx error, hash is
${
2
}${
NOC
}
"
exit
1
...
...
@@ -283,7 +288,7 @@ function check_number() {
echo
-e
"
${
RED
}
wrong check number parameters
${
NOC
}
"
exit
1
fi
if
[[
${
1
}
!=
${
2
}
]]
;
then
if
[[
${
1
}
!=
"
${
2
}
"
]]
;
then
echo
-e
"
${
RED
}
error number, expect
${
1
}
, get
${
2
}${
NOC
}
"
exit
1
fi
...
...
@@ -296,8 +301,8 @@ function check_addr() {
exit
1
fi
addr
=
$(
echo
${
1
}
| jq
-r
".acc.addr"
)
if
[[
${
addr
}
!=
${
2
}
]]
;
then
addr
=
$(
echo
"
${
1
}
"
| jq
-r
".acc.addr"
)
if
[[
${
addr
}
!=
"
${
2
}
"
]]
;
then
echo
-e
"
${
RED
}
error addr, expect
${
1
}
, get
${
2
}${
NOC
}
"
exit
1
fi
...
...
@@ -331,18 +336,18 @@ function updata_relayer_toml() {
exit
1
fi
local
line
=
$(
delete_line_show
${
file
}
"chain33Host"
)
local
line
=
$(
delete_line_show
"
${
file
}
"
"chain33Host"
)
# 在第 line 行后面 新增合约地址
sed
-i
''
${
line
}
' a chain33Host="http://'
${
chain33Host
}
':8801"'
"
${
file
}
"
sed
-i
''
"
${
line
}
"
' a chain33Host="http://'
"
${
chain33Host
}
"
':8801"'
"
${
file
}
"
line
=
$(
delete_line_show
${
file
}
"pushHost"
)
sed
-i
''
${
line
}
' a pushHost="http://'
${
pushHost
}
':20000"'
"
${
file
}
"
line
=
$(
delete_line_show
"
${
file
}
"
"pushHost"
)
sed
-i
''
"
${
line
}
"
' a pushHost="http://'
"
${
pushHost
}
"
':20000"'
"
${
file
}
"
line
=
$(
delete_line_show
${
file
}
"BridgeRegistry"
)
sed
-i
''
${
line
}
' a BridgeRegistry="'
${
BridgeRegistry
}
'"'
"
${
file
}
"
line
=
$(
delete_line_show
"
${
file
}
"
"BridgeRegistry"
)
sed
-i
''
"
${
line
}
"
' a BridgeRegistry="'
"
${
BridgeRegistry
}
"
'"'
"
${
file
}
"
sed
-i
's/EthMaturityDegree=10/'
EthMaturityDegree
=
${
maturityDegree
}
'/g'
"
${
file
}
"
sed
-i
's/maturityDegree=10/'
maturityDegree
=
${
maturityDegree
}
'/g'
"
${
file
}
"
sed
-i
's/EthMaturityDegree=10/'
EthMaturityDegree
=
"
${
maturityDegree
}
"
'/g'
"
${
file
}
"
sed
-i
's/maturityDegree=10/'
maturityDegree
=
"
${
maturityDegree
}
"
'/g'
"
${
file
}
"
#sed -i 's/#BridgeRegistry=\"0x40BFE5eD039A9a2Eb42ece2E2CA431bFa7Cf4c42\"/BridgeRegistry=\"'${BridgeRegistry}'\"/g' "../build/relayer.toml"
#sed -i 's/192.168.64.2/'${chain33Host}'/g' "../build/relayer.toml"
...
...
@@ -358,18 +363,18 @@ function updata_relayer_toml_ropston() {
local
chain33Host
=
127.0.0.1
local
pushHost
=
127.0.0.1
local
line
=
$(
delete_line_show
${
file
}
"chain33Host"
)
local
line
=
$(
delete_line_show
"
${
file
}
"
"chain33Host"
)
# 在第 line 行后面 新增合约地址
sed
-i
''
${
line
}
' a chain33Host="http://'
${
chain33Host
}
':8801"'
"
${
file
}
"
sed
-i
''
"
${
line
}
"
' a chain33Host="http://'
${
chain33Host
}
':8801"'
"
${
file
}
"
line
=
$(
delete_line_show
${
file
}
"pushHost"
)
sed
-i
''
${
line
}
' a pushHost="http://'
${
pushHost
}
':20000"'
"
${
file
}
"
line
=
$(
delete_line_show
"
${
file
}
"
"pushHost"
)
sed
-i
''
"
${
line
}
"
' a pushHost="http://'
${
pushHost
}
':20000"'
"
${
file
}
"
line
=
$(
delete_line_show
${
file
}
"BridgeRegistry"
)
sed
-i
''
${
line
}
' a BridgeRegistry="'
${
BridgeRegistry
}
'"'
"
${
file
}
"
line
=
$(
delete_line_show
"
${
file
}
"
"BridgeRegistry"
)
sed
-i
''
"
${
line
}
"
' a BridgeRegistry="'
"
${
BridgeRegistry
}
"
'"'
"
${
file
}
"
sed
-i
's/EthMaturityDegree=10/'
EthMaturityDegree
=
${
maturityDegree
}
'/g'
"
${
file
}
"
sed
-i
's/maturityDegree=10/'
maturityDegree
=
${
maturityDegree
}
'/g'
"
${
file
}
"
sed
-i
's/EthMaturityDegree=10/'
EthMaturityDegree
=
"
${
maturityDegree
}
"
'/g'
"
${
file
}
"
sed
-i
's/maturityDegree=10/'
maturityDegree
=
"
${
maturityDegree
}
"
'/g'
"
${
file
}
"
#sed -i 's/#BridgeRegistry=\"0x40BFE5eD039A9a2Eb42ece2E2CA431bFa7Cf4c42\"/BridgeRegistry=\"'${BridgeRegistry}'\"/g' "../build/relayer.toml"
#sed -i 's/192.168.64.2/'${chain33Host}'/g' "../build/relayer.toml"
...
...
@@ -383,12 +388,12 @@ function updata_all_relayer_toml() {
# local dockername=30
for
name
in
B C D
;
do
local
file
=
"../build/
"
$name
"
/relayer.toml"
local
file
=
"../build/
$name
/relayer.toml"
cp
'../build/A/relayer.toml'
"
${
file
}
"
cp
'../build/ebrelayer'
"../build/
"
$name
"
/ebrelayer"
cp
'../build/ebrelayer'
"../build/
$name
/ebrelayer"
# 删除配置文件中不需要的字段
for
deleteName
in
"deployerPrivateKey"
"operatorAddr"
"validatorsAddr"
"initPowers"
"deployerPrivateKey"
"
\[
deploy
\]
"
;
do
for
deleteName
in
"deployerPrivateKey"
"operatorAddr"
"validatorsAddr"
"initPowers"
"deployerPrivateKey"
"
deploy
"
;
do
delete_line
"
${
file
}
"
"
${
deleteName
}
"
done
...
...
@@ -421,12 +426,12 @@ function updata_all_relayer_toml2() {
# local dockername=30
for
name
in
B C D
;
do
local
file
=
"./
"
$name
"
/relayer.toml"
local
file
=
"./
$name
/relayer.toml"
cp
'./A/relayer.toml'
"
${
file
}
"
cp
'./ebrelayer'
"./
"
$name
"
/ebrelayer"
cp
'./ebrelayer'
"./
$name
/ebrelayer"
# 删除配置文件中不需要的字段
for
deleteName
in
"deployerPrivateKey"
"operatorAddr"
"validatorsAddr"
"initPowers"
"deployerPrivateKey"
"
\[
deploy
\]
"
;
do
for
deleteName
in
"deployerPrivateKey"
"operatorAddr"
"validatorsAddr"
"initPowers"
"deployerPrivateKey"
"
deploy
"
;
do
delete_line
"
${
file
}
"
"
${
deleteName
}
"
done
...
...
@@ -512,7 +517,7 @@ function eth_block_wait() {
if
[
"
${
url
}
"
==
""
]
;
then
cur_height
=
$(
curl
-ksd
'{"id":1,"jsonrpc":"2.0","method":"eth_blockNumber","params":[]}'
http://localhost:7545 | jq
-r
".result"
)
else
cur_height
=
$(
curl
-H
"Content-Type: application/json"
-X
POST
--data
'{"id":1,"jsonrpc":"2.0","method":"eth_blockNumber","params":[]}'
${
url
}
| jq
-r
".result"
)
cur_height
=
$(
curl
-H
"Content-Type: application/json"
-X
POST
--data
'{"id":1,"jsonrpc":"2.0","method":"eth_blockNumber","params":[]}'
"
${
url
}
"
| jq
-r
".result"
)
fi
local
expect
=
$((
cur_height
+
${
1
}
+
1
))
...
...
@@ -521,7 +526,7 @@ function eth_block_wait() {
if
[
"
${
url
}
"
==
""
]
;
then
new_height
=
$(
curl
-ksd
'{"id":1,"jsonrpc":"2.0","method":"eth_blockNumber","params":[]}'
http://localhost:7545 | jq
-r
".result"
)
else
new_height
=
$(
curl
-H
"Content-Type: application/json"
-X
POST
--data
'{"id":1,"jsonrpc":"2.0","method":"eth_blockNumber","params":[]}'
${
url
}
| jq
-r
".result"
)
new_height
=
$(
curl
-H
"Content-Type: application/json"
-X
POST
--data
'{"id":1,"jsonrpc":"2.0","method":"eth_blockNumber","params":[]}'
"
${
url
}
"
| jq
-r
".result"
)
fi
if
[[
${
new_height
}
-ge
${
expect
}
]]
;
then
...
...
plugin/dapp/x2ethereum/testsh/x2ethereumTest.sh
View file @
7b6d3277
...
...
@@ -16,26 +16,20 @@ tokenAddr=""
BridgeRegistry
=
""
chain33SenderAddr
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
chain33SenderAddrKey
=
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
ethValidatorAddrKey
=
"3fa21584ae2e4fd74db9b58e2386f5481607dfa4d7ba0617aaa7858e5025dc1e"
ethReceiverAddr1
=
"0xa4ea64a583f6e51c3799335b28a8f0529570a635"
ethReceiverAddrKey1
=
"355b876d7cbcb930d5dfab767f66336ce327e082cbaa1877210c1bae89b1df71"
ethReceiverAddr2
=
"0x0c05ba5c230fdaa503b53702af1962e08d0c60bf"
ethReceiverAddrKey2
=
"9dc6df3a8ab139a54d8a984f54958ae0661f880229bf3bdbb886b87d58b56a08"
ethReceiverAddr3
=
"0x1919203bA8b325278d28Fb8fFeac49F2CD881A4e"
ethReceiverAddrKey3
=
"62ca4122aac0e6f35bed02fc15c7ddbdaa07f2f2a1821c8b8210b891051e3ee9"
chain33Validator1
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
chain33Validator2
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
#0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01
chain33Validator3
=
"1BqP2vHkYNjSgdnTqm7pGbnphLhtEhuJFi"
BtyReceiever
=
"1BqP2vHkYNjSgdnTqm7pGbnphLhtEhuJFi"
ETHContractAddr
=
"0x0000000000000000000000000000000000000000"
maturityDegree
=
10
function
InitAndDeploy
()
{
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
result
=
$(${
CLI
}
relayer set_pwd
-
n
123456hzj
-o
kk
)
result
=
$(${
CLI
}
relayer set_pwd
-
p
123456hzj
)
cli_ret
"
${
result
}
"
"set_pwd"
result
=
$(${
CLI
}
relayer unlock
-p
123456hzj
)
...
...
@@ -49,16 +43,13 @@ function InitAndDeploy() {
function
EthImportKey
()
{
echo
-e
"
${
GRE
}
===========
$FUNCNAME
begin ===========
${
NOC
}
"
result
=
$(${
CLI
}
relayer set_pwd
-
n
123456hzj
-o
kk
)
result
=
$(${
CLI
}
relayer set_pwd
-
p
123456hzj
)
result
=
$(${
CLI
}
relayer unlock
-p
123456hzj
)
result
=
$(${
CLI
}
relayer ethereum import_chain33privatekey
-k
"
${
chain33SenderAddrKey
}
"
)
cli_ret
"
${
result
}
"
"import_chain33privatekey"
result
=
$(${
CLI
}
relayer ethereum import_ethprivatekey
-k
"
${
ethValidatorAddrKey
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekey"
result
=
$(${
CLI
}
relayer chain33 import_privatekey
-k
"
${
ethValidatorAddrKey
}
"
)
cli_ret
"
${
result
}
"
"import_ethprivatekey"
...
...
@@ -89,12 +80,12 @@ function StartRelayerAndDeploy() {
kill_ebrelayer
"../build/ebrelayer"
# 修改 relayer.toml 配置文件
updata_relayer_toml
${
BridgeRegistry
}
${
maturityDegree
}
"../build/relayer.toml"
updata_relayer_toml
"
${
BridgeRegistry
}
"
${
maturityDegree
}
"../build/relayer.toml"
# 重启 ebrelayer 并解锁
start_ebrelayer
"../build/ebrelayer"
"../build/ebrelayer.log"
${
CLI
}
relayer set_pwd
-
n
123456hzj
-o
kk
${
CLI
}
relayer set_pwd
-
p
123456hzj
${
CLI
}
relayer unlock
-p
123456hzj
echo
-e
"
${
GRE
}
===========
$FUNCNAME
end ===========
${
NOC
}
"
...
...
@@ -130,10 +121,10 @@ function InitChain33Vilators() {
# query Validators
totalPower
=
$(${
Chain33Cli
}
send x2ethereum query validators
-v
${
chain33Validator1
}
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv | jq .totalPower |
sed
's/\"//g'
)
check_number 87
${
totalPower
}
check_number 87
"
${
totalPower
}
"
totalPower
=
$(${
Chain33Cli
}
send x2ethereum query totalpower
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv | jq .totalPower |
sed
's/\"//g'
)
check_number 100
${
totalPower
}
check_number 100
"
${
totalPower
}
"
# cions 转帐到 x2ethereum 合约地址
hash
=
$(${
Chain33Cli
}
send coins send_exec
-e
x2ethereum
-a
200
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
...
...
@@ -161,7 +152,7 @@ function TestChain33ToEthAssets() {
cli_ret
"
${
result
}
"
"balance"
".balance"
"0"
# chain33 lock bty
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
5
-t
coins.bty
-r
${
ethReceiverAddr1
}
-q
${
tokenAddr
}
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
hash
=
$(${
Chain33Cli
}
send x2ethereum lock
-a
5
-t
coins.bty
-r
${
ethReceiverAddr1
}
-q
"
${
tokenAddr
}
"
-k
12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
2
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
@@ -323,7 +314,7 @@ function TestETH2Chain33Erc20() {
balance_ret
"
${
result
}
"
"100"
# chain33 burn 40
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
40
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
${
tokenAddr
}
-k
"
${
chain33SenderAddr
}
"
)
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
40
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
"
${
tokenAddr
}
"
-k
"
${
chain33SenderAddr
}
"
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
2
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
@@ -339,7 +330,7 @@ function TestETH2Chain33Erc20() {
cli_ret
"
${
result
}
"
"balance"
".balance"
"60"
# burn 60
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
60
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
${
tokenAddr
}
-k
"
${
chain33SenderAddr
}
"
)
hash
=
$(${
Chain33Cli
}
send x2ethereum burn
-a
60
-t
"
${
tokenSymbol
}
"
-r
${
ethReceiverAddr2
}
-q
"
${
tokenAddr
}
"
-k
"
${
chain33SenderAddr
}
"
)
block_wait
"
${
Chain33Cli
}
"
$((
maturityDegree
+
2
))
check_tx
"
${
Chain33Cli
}
"
"
${
hash
}
"
...
...
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