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
91f9d67f
Commit
91f9d67f
authored
May 22, 2020
by
whisker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix golint bug
parent
fb2fd411
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
82 additions
and
226 deletions
+82
-226
commands.go
plugin/dapp/x2Ethereum/commands/commands.go
+0
-136
parser.go
plugin/dapp/x2Ethereum/ebrelayer/ethtxs/parser.go
+4
-4
exec.go
plugin/dapp/x2Ethereum/executor/exec.go
+8
-11
exec_test.go
plugin/dapp/x2Ethereum/executor/exec_test.go
+47
-44
prophecy.go
plugin/dapp/x2Ethereum/executor/prophecy.go
+4
-5
query.go
plugin/dapp/x2Ethereum/executor/query.go
+3
-2
x2ethereumdb.go
plugin/dapp/x2Ethereum/executor/x2ethereumdb.go
+2
-3
plugin.go
plugin/dapp/x2Ethereum/plugin.go
+1
-1
const.go
plugin/dapp/x2Ethereum/types/const.go
+4
-4
utils.go
plugin/dapp/x2Ethereum/types/utils.go
+0
-7
x2ethereum.go
plugin/dapp/x2Ethereum/types/x2ethereum.go
+9
-9
No files found.
plugin/dapp/x2Ethereum/commands/commands.go
View file @
91f9d67f
...
...
@@ -28,8 +28,6 @@ func Cmd() *cobra.Command {
Args
:
cobra
.
MinimumNArgs
(
1
),
}
cmd
.
AddCommand
(
CreateRawEth2Chain33TxCmd
(),
CreateRawWithdrawEthTxCmd
(),
CreateRawWithdrawChain33TxCmd
(),
CreateRawChain33ToEthTxCmd
(),
CreateRawAddValidatorTxCmd
(),
...
...
@@ -50,140 +48,6 @@ func Cmd() *cobra.Command {
return
cmd
}
// Eth2Chain33
func
CreateRawEth2Chain33TxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"create"
,
Short
:
"Create a Eth2Chain33 && lock a erc20 and mint a token in chain33"
,
Run
:
Eth2Chain33
,
}
addEth2Chain33Flags
(
cmd
)
return
cmd
}
func
addEth2Chain33Flags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Int64
(
"ethid"
,
0
,
"the ethereum chain ID which send asset to chain33"
)
_
=
cmd
.
MarkFlagRequired
(
"ethid"
)
cmd
.
Flags
()
.
StringP
(
"bcontract"
,
"b"
,
""
,
"BridgeContractAddress"
)
_
=
cmd
.
MarkFlagRequired
(
"bcontract"
)
cmd
.
Flags
()
.
Int64
(
"nonce"
,
0
,
"the nonce for this tx in ethereum"
)
_
=
cmd
.
MarkFlagRequired
(
"nonce"
)
cmd
.
Flags
()
.
StringP
(
"csymbol"
,
"t"
,
""
,
"token symbol in chain33"
)
_
=
cmd
.
MarkFlagRequired
(
"csymbol"
)
cmd
.
Flags
()
.
StringP
(
"tcontract"
,
"q"
,
""
,
"token contract address in ethereum"
)
_
=
cmd
.
MarkFlagRequired
(
"tcontract"
)
cmd
.
Flags
()
.
StringP
(
"sender"
,
"s"
,
""
,
"ethereum sender address"
)
_
=
cmd
.
MarkFlagRequired
(
"sender"
)
cmd
.
Flags
()
.
StringP
(
"receiver"
,
"r"
,
""
,
"chain33 receiver address"
)
_
=
cmd
.
MarkFlagRequired
(
"cExec"
)
cmd
.
Flags
()
.
StringP
(
"validator"
,
"v"
,
""
,
"validator address"
)
_
=
cmd
.
MarkFlagRequired
(
"validator"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
float64
(
0
),
"the amount of this contract want to lock"
)
_
=
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
Int64
(
"claimtype"
,
0
,
"the type of this claim,lock=1,burn=2"
)
_
=
cmd
.
MarkFlagRequired
(
"claimtype"
)
}
func
Eth2Chain33
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
ethid
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"ethid"
)
bcontract
,
_
:=
cmd
.
Flags
()
.
GetString
(
"bcontract"
)
nonce
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"nonce"
)
csymbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"csymbol"
)
tcontract
,
_
:=
cmd
.
Flags
()
.
GetString
(
"tcontract"
)
sender
,
_
:=
cmd
.
Flags
()
.
GetString
(
"sender"
)
receiver
,
_
:=
cmd
.
Flags
()
.
GetString
(
"receiver"
)
validator
,
_
:=
cmd
.
Flags
()
.
GetString
(
"validator"
)
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
claimtype
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"claimtype"
)
nodeAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"node_addr"
)
decimal
,
err
:=
utils
.
GetDecimalsFromNode
(
tcontract
,
nodeAddr
)
if
err
!=
nil
{
fmt
.
Println
(
"get decimal error"
)
return
}
params
:=
&
types3
.
Eth2Chain33
{
EthereumChainID
:
ethid
,
BridgeContractAddress
:
bcontract
,
Nonce
:
nonce
,
IssuerDotSymbol
:
csymbol
,
TokenContractAddress
:
tcontract
,
EthereumSender
:
sender
,
Chain33Receiver
:
receiver
,
ValidatorAddress
:
validator
,
Amount
:
strconv
.
FormatFloat
(
amount
*
1e8
,
'f'
,
4
,
64
),
ClaimType
:
claimtype
,
Decimals
:
decimal
,
}
payLoad
:=
types
.
MustPBToJSON
(
params
)
createTx
(
cmd
,
payLoad
,
types3
.
NameEth2Chain33Action
)
}
// WithdrawEth
func
CreateRawWithdrawEthTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"withdraweth"
,
Short
:
"withdraw a tx && burn erc20 back to chain33"
,
Run
:
WithdrawEth
,
}
addEth2Chain33Flags
(
cmd
)
return
cmd
}
func
WithdrawEth
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
ethid
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"ethid"
)
bcontract
,
_
:=
cmd
.
Flags
()
.
GetString
(
"bcontract"
)
nonce
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"nonce"
)
csymbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"csymbol"
)
tcontract
,
_
:=
cmd
.
Flags
()
.
GetString
(
"tcontract"
)
sender
,
_
:=
cmd
.
Flags
()
.
GetString
(
"sender"
)
receiver
,
_
:=
cmd
.
Flags
()
.
GetString
(
"receiver"
)
validator
,
_
:=
cmd
.
Flags
()
.
GetString
(
"validator"
)
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
claimtype
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"claimtype"
)
nodeAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"node_addr"
)
decimal
,
err
:=
utils
.
GetDecimalsFromNode
(
tcontract
,
nodeAddr
)
if
err
!=
nil
{
fmt
.
Println
(
"get decimal error"
)
return
}
params
:=
&
types3
.
Eth2Chain33
{
EthereumChainID
:
ethid
,
BridgeContractAddress
:
bcontract
,
Nonce
:
nonce
,
IssuerDotSymbol
:
csymbol
,
TokenContractAddress
:
tcontract
,
EthereumSender
:
sender
,
Chain33Receiver
:
receiver
,
ValidatorAddress
:
validator
,
Amount
:
strconv
.
FormatFloat
(
amount
*
1e8
,
'f'
,
4
,
64
),
ClaimType
:
claimtype
,
Decimals
:
decimal
,
}
payLoad
:=
types
.
MustPBToJSON
(
params
)
createTx
(
cmd
,
payLoad
,
types3
.
NameWithdrawEthAction
)
}
// Burn
func
CreateRawWithdrawChain33TxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
...
...
plugin/dapp/x2Ethereum/ebrelayer/ethtxs/parser.go
View file @
91f9d67f
...
...
@@ -50,8 +50,8 @@ func LogLockToEthBridgeClaim(event *events.LockEvent, ethereumChainID int64, bri
}
witnessClaim
.
Amount
=
event
.
Value
.
String
()
witnessClaim
.
ClaimType
=
types
.
L
OCK_CLAIM_TYPE
witnessClaim
.
ChainName
=
types
.
L
OCK_CLAIM
witnessClaim
.
ClaimType
=
types
.
L
ockClaimType
witnessClaim
.
ChainName
=
types
.
L
ockClaim
witnessClaim
.
Decimal
=
decimal
return
witnessClaim
,
nil
...
...
@@ -72,8 +72,8 @@ func LogBurnToEthBridgeClaim(event *events.BurnEvent, ethereumChainID int64, bri
witnessClaim
.
EthereumSender
=
event
.
OwnerFrom
.
String
()
witnessClaim
.
Chain33Receiver
=
string
(
recipient
)
witnessClaim
.
Amount
=
event
.
Amount
.
String
()
witnessClaim
.
ClaimType
=
types
.
B
URN_CLAIM_TYPE
witnessClaim
.
ChainName
=
types
.
B
URN_CLAIM
witnessClaim
.
ClaimType
=
types
.
B
urnClaimType
witnessClaim
.
ChainName
=
types
.
B
urnClaim
witnessClaim
.
Decimal
=
decimal
return
witnessClaim
,
nil
...
...
plugin/dapp/x2Ethereum/executor/exec.go
View file @
91f9d67f
...
...
@@ -18,9 +18,7 @@ import (
//---------------- Ethereum(eth/erc20) --> Chain33-------------------//
// Eth2Chain33类型的交易是Ethereum侧锁定一定金额的eth或者erc20到合约中
// 然后relayer端订阅到该消息后向chain33发送该类型消息
// 本端在验证该类型的请求合理后铸币,并生成相同数额的token
// 在chain33上为ETH/ERC20铸币
func
(
x
*
x2ethereum
)
Exec_Eth2Chain33Lock
(
payload
*
x2eTy
.
Eth2Chain33
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
...
...
@@ -33,7 +31,7 @@ func (x *x2ethereum) Exec_Eth2Chain33Lock(payload *x2eTy.Eth2Chain33, tx *types.
}
//---------------- Chain33(eth/erc20)------> Ethereum -------------------//
//
WithdrawChain33类型的交易是将Eth端因Chain33端锁定所生成的token返还给Chain33端(Burn)
//
在chain33端将铸的币销毁,返还给eth
func
(
x
*
x2ethereum
)
Exec_Chain33ToEthBurn
(
payload
*
x2eTy
.
Chain33ToEth
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
...
...
@@ -42,9 +40,8 @@ func (x *x2ethereum) Exec_Chain33ToEthBurn(payload *x2eTy.Chain33ToEth, tx *type
return
action
.
procChain33ToEth_burn
(
payload
)
}
//---------------- Chain33(eth/erc20) --> Ethereum-------------------//
// 将因ethereum端锁定的eth或者erc20而在chain33端生成的token返还
//---------------- Ethereum (bty) --> Chain33-------------------//
// 在eth端将铸的bty币销毁,返还给chain33
func
(
x
*
x2ethereum
)
Exec_Eth2Chain33Burn
(
payload
*
x2eTy
.
Eth2Chain33
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
...
...
@@ -56,8 +53,8 @@ func (x *x2ethereum) Exec_Eth2Chain33Burn(payload *x2eTy.Eth2Chain33, tx *types.
return
action
.
procEth2Chain33_burn
(
payload
)
}
//
Chain33ToEth类型的交易是Chain33侧在本端发出申请
// 在
本端锁定一定数额的token,然后在ethereum端生成相同数额的token
//
---------------- Chain33 --> Ethereum (bty) -------------------//
// 在
ethereum 上为 chain33 铸币
func
(
x
*
x2ethereum
)
Exec_Chain33ToEthLock
(
payload
*
x2eTy
.
Chain33ToEth
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
...
...
@@ -161,7 +158,7 @@ func checkTxSignBySpecificAddr(tx *types.Transaction, addrs []string) error {
for
_
,
addr
:=
range
addrs
{
if
signAddr
==
addr
{
exist
=
true
continue
break
}
}
...
...
@@ -169,7 +166,7 @@ func checkTxSignBySpecificAddr(tx *types.Transaction, addrs []string) error {
return
x2eTy
.
ErrInvalidAdminAddress
}
if
tx
.
CheckSign
()
==
false
{
if
!
tx
.
CheckSign
()
{
return
types
.
ErrSign
}
return
nil
...
...
plugin/dapp/x2Ethereum/executor/exec_test.go
View file @
91f9d67f
...
...
@@ -29,7 +29,6 @@ var (
chain33Receiver
=
"1BqP2vHkYNjSgdnTqm7pGbnphLhtEhuJFi"
bridgeContractAddress
=
"0xC4cE93a5699c68241fc2fB503Fb0f21724A624BB"
symbol
=
"eth"
coinExec
=
"x2ethereum"
tokenContractAddress
=
"0x0000000000000000000000000000000000000000"
ethereumAddr
=
"0x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
addValidator1
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
...
...
@@ -172,22 +171,21 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
EthereumChainID
:
0
,
BridgeContractAddress
:
bridgeContractAddress
,
Nonce
:
0
,
LocalCoinSymbol
:
symbol
,
LocalCoinExec
:
coinExec
,
IssuerDotSymbol
:
symbol
,
TokenContractAddress
:
tokenContractAddress
,
EthereumSender
:
ethereumAddr
,
Chain33Receiver
:
chain33Receiver
,
ValidatorAddress
:
addValidator1
,
Amount
:
"10"
,
ClaimType
:
int64
(
types2
.
L
OCK_CLAIM_TYPE
),
ClaimType
:
int64
(
types2
.
L
ockClaimType
),
}
receipt
,
err
:=
x
.
action
.
proc
MsgEth2Chain33
(
payload
)
receipt
,
err
:=
x
.
action
.
proc
Eth2Chain33_lock
(
payload
)
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
payload
.
ValidatorAddress
=
addValidator2
receipt
,
err
=
x
.
action
.
proc
MsgEth2Chain33
(
payload
)
receipt
,
err
=
x
.
action
.
proc
Eth2Chain33_lock
(
payload
)
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
...
...
@@ -197,21 +195,25 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x
.
query_GetEthProphecy
(
"000x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
,
types2
.
EthBridgeStatus_SuccessStatusText
)
x
.
query_GetSymbolTotalAmountByTxType
(
symbol
,
1
,
"lock"
,
10
)
payload
.
Amount
=
"3"
payload
.
Nonce
=
1
payload
.
ClaimType
=
int64
(
types2
.
BURN_CLAIM_TYPE
)
payload
.
ValidatorAddress
=
addValidator1
receipt
,
err
=
x
.
action
.
procWithdrawEth
(
payload
)
payload1
:=
&
types2
.
Chain33ToEth
{
TokenContract
:
tokenContractAddress
,
Chain33Sender
:
addValidator1
,
EthereumReceiver
:
ethereumAddr
,
Amount
:
"3"
,
IssuerDotSymbol
:
"coins.bty"
,
Decimals
:
8
,
}
receipt
,
err
=
x
.
action
.
procChain33ToEth_burn
(
payload1
)
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
payload
.
ValidatorAddress
=
addValidator2
payload
.
Amount
=
"2"
receipt
,
err
=
x
.
action
.
procWithdrawEth
(
payload
)
payload1
.
Amount
=
"2"
_
,
err
=
x
.
action
.
procChain33ToEth_burn
(
payload1
)
x
.
Equal
(
err
,
types2
.
ErrClaimInconsist
)
payload
.
Amount
=
"3"
receipt
,
err
=
x
.
action
.
proc
WithdrawEth
(
payload
)
payload
1
.
Amount
=
"3"
receipt
,
err
=
x
.
action
.
proc
Chain33ToEth_burn
(
payload1
)
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
...
...
@@ -219,23 +221,25 @@ func (x *suiteX2Ethereum) Test_4_Eth2Chain33() {
x
.
query_GetSymbolTotalAmount
(
symbol
,
1
,
7
)
x
.
query_GetSymbolTotalAmountByTxType
(
symbol
,
1
,
"withdraw"
,
3
)
payload
.
Amount
=
"10"
payload
.
Nonce
=
2
payload
.
ValidatorAddress
=
addValidator1
receipt
,
err
=
x
.
action
.
procWithdrawEth
(
payload
)
payload
.
ValidatorAddress
=
addValidator2
receipt
,
err
=
x
.
action
.
procWithdrawEth
(
payload
)
x
.
Equal
(
types
.
ErrNoBalance
,
err
)
//
payload.Amount = "10"
//
payload.Nonce = 2
//
payload.ValidatorAddress = addValidator1
//receipt, err = x.action.procChain33ToEth_burn
(payload)
//
payload.ValidatorAddress = addValidator2
//receipt, err = x.action.procChain33ToEth_burn
(payload)
//
x.Equal(types.ErrNoBalance, err)
payload
.
Amount
=
"1"
payload
.
Nonce
=
3
payload
.
ClaimType
=
int64
(
types2
.
L
OCK_CLAIM_TYPE
)
payload
.
ClaimType
=
int64
(
types2
.
L
ockClaimType
)
payload
.
ValidatorAddress
=
addValidator1
receipt
,
err
=
x
.
action
.
procMsgEth2Chain33
(
payload
)
receipt
,
err
=
x
.
action
.
procEth2Chain33_lock
(
payload
)
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
payload
.
ValidatorAddress
=
addValidator2
receipt
,
err
=
x
.
action
.
procMsgEth2Chain33
(
payload
)
receipt
,
err
=
x
.
action
.
procEth2Chain33_lock
(
payload
)
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
x
.
query_GetEthProphecy
(
"030x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
,
types2
.
EthBridgeStatus_SuccessStatusText
)
...
...
@@ -248,32 +252,31 @@ func (x *suiteX2Ethereum) Test_5_Chain33ToEth() {
Chain33Sender
:
addValidator1
,
EthereumReceiver
:
ethereumAddr
,
Amount
:
"5"
,
LocalCoinSymbol
:
"bty"
,
LocalCoinExec
:
coinExec
,
IssuerDotSymbol
:
"coins.bty"
,
}
receipt
,
err
:=
x
.
action
.
proc
MsgL
ock
(
msgLock
)
receipt
,
err
:=
x
.
action
.
proc
Chain33ToEth_l
ock
(
msgLock
)
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
x
.
query_GetSymbolTotalAmount
(
"bty"
,
2
,
5
)
x
.
query_GetSymbolTotalAmountByTxType
(
"bty"
,
2
,
"lock"
,
5
)
msgLock
.
Amount
=
"4"
receipt
,
err
=
x
.
action
.
procMsgB
urn
(
msgLock
)
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
x
.
query_GetSymbolTotalAmount
(
"bty"
,
2
,
1
)
x
.
query_GetSymbolTotalAmountByTxType
(
"bty"
,
2
,
"withdraw"
,
4
)
receipt
,
err
=
x
.
action
.
procMsgB
urn
(
msgLock
)
x
.
Equal
(
err
,
types
.
ErrNoBalance
)
msgLock
.
Amount
=
"1"
receipt
,
err
=
x
.
action
.
procMsgB
urn
(
msgLock
)
x
.
NoError
(
err
)
x
.
setDb
(
receipt
)
//
msgLock.Amount = "4"
//receipt, err = x.action.procEth2Chain33_b
urn(msgLock)
//
x.NoError(err)
//
x.setDb(receipt)
//
//
x.query_GetSymbolTotalAmount("bty", 2, 1)
//
x.query_GetSymbolTotalAmountByTxType("bty", 2, "withdraw", 4)
//
//receipt, err = x.action.procEth2Chain33_b
urn(msgLock)
//
x.Equal(err, types.ErrNoBalance)
//
//
msgLock.Amount = "1"
//receipt, err = x.action.procEth2Chain33_b
urn(msgLock)
//
x.NoError(err)
//
x.setDb(receipt)
x
.
query_GetSymbolTotalAmount
(
"bty"
,
2
,
0
)
x
.
query_GetSymbolTotalAmountByTxType
(
"bty"
,
2
,
"withdraw"
,
5
)
...
...
plugin/dapp/x2Ethereum/executor/prophecy.go
View file @
91f9d67f
package
executor
import
(
"errors"
"fmt"
"strconv"
...
...
@@ -88,13 +87,13 @@ func NewClaim(id string, validatorAddress string, content string) x2eTy.OracleCl
//通过ethchain33结构构造一个OracleClaim结构,包括生成唯一的ID
func
CreateOracleClaimFromEthClaim
(
ethClaim
x2eTy
.
Eth2Chain33
)
(
x2eTy
.
OracleClaim
,
error
)
{
if
ethClaim
.
ClaimType
!=
int64
(
x2eTy
.
L
OCK_CLAIM_TYPE
)
&&
ethClaim
.
ClaimType
!=
int64
(
x2eTy
.
BURN_CLAIM_TYPE
)
{
if
ethClaim
.
ClaimType
!=
int64
(
x2eTy
.
L
ockClaimType
)
&&
ethClaim
.
ClaimType
!=
int64
(
x2eTy
.
BurnClaimType
)
{
return
x2eTy
.
OracleClaim
{},
x2eTy
.
ErrInvalidClaimType
}
oracleID
:=
strconv
.
Itoa
(
int
(
ethClaim
.
EthereumChainID
))
+
strconv
.
Itoa
(
int
(
ethClaim
.
Nonce
))
+
ethClaim
.
EthereumSender
+
ethClaim
.
TokenContractAddress
if
ethClaim
.
ClaimType
==
int64
(
x2eTy
.
L
OCK_CLAIM_TYPE
)
{
if
ethClaim
.
ClaimType
==
int64
(
x2eTy
.
L
ockClaimType
)
{
oracleID
=
oracleID
+
"lock"
}
else
if
ethClaim
.
ClaimType
==
int64
(
x2eTy
.
B
URN_CLAIM_TYPE
)
{
}
else
if
ethClaim
.
ClaimType
==
int64
(
x2eTy
.
B
urnClaimType
)
{
oracleID
=
oracleID
+
"burn"
}
claimContent
:=
NewOracleClaimContent
(
ethClaim
.
Chain33Receiver
,
ethClaim
.
Amount
,
ethClaim
.
ClaimType
,
ethClaim
.
Decimals
)
...
...
@@ -110,7 +109,7 @@ func CreateOracleClaimFromOracleString(oracleClaimString string) (x2eTy.OracleCl
bz
:=
[]
byte
(
oracleClaimString
)
if
err
:=
types
.
Decode
(
bz
,
&
oracleClaimContent
);
err
!=
nil
{
return
x2eTy
.
OracleClaimContent
{},
errors
.
New
(
fmt
.
Sprintf
(
"failed to parse claim: %s"
,
err
.
Error
()
))
return
x2eTy
.
OracleClaimContent
{},
fmt
.
Errorf
(
"failed to parse claim: %s"
,
err
.
Error
(
))
}
return
oracleClaimContent
,
nil
...
...
plugin/dapp/x2Ethereum/executor/query.go
View file @
91f9d67f
...
...
@@ -57,7 +57,8 @@ func (x *x2ethereum) Query_GetValidators(in *x2eTy.QueryValidatorsParams) (types
}
// 未知的地址
return
nil
,
x2eTy
.
ErrInvalidValidator
}
else
{
}
validatorsRes
:=
new
(
x2eTy
.
ReceiptQueryValidator
)
var
totalPower
int64
for
_
,
vv
:=
range
v
.
Validators
{
...
...
@@ -66,7 +67,7 @@ func (x *x2ethereum) Query_GetValidators(in *x2eTy.QueryValidatorsParams) (types
validatorsRes
.
Validators
=
v
.
Validators
validatorsRes
.
TotalPower
=
totalPower
return
validatorsRes
,
nil
}
}
func
(
x
*
x2ethereum
)
Query_GetTotalPower
(
in
*
x2eTy
.
QueryTotalPowerParams
)
(
types
.
Message
,
error
)
{
...
...
plugin/dapp/x2Ethereum/executor/x2ethereumdb.go
View file @
91f9d67f
...
...
@@ -37,7 +37,7 @@ func (o *Oracle) ProcessSuccessfulClaimForLock(claim, execAddr string, accDB *ac
receiverAddress
:=
oracleClaim
.
Chain33Receiver
if
oracleClaim
.
ClaimType
==
int64
(
x2eTy
.
L
OCK_CLAIM_TYPE
)
{
if
oracleClaim
.
ClaimType
==
int64
(
x2eTy
.
L
ockClaimType
)
{
//铸币到相关的tokenSymbolBank账户下
amount
,
_
:=
strconv
.
ParseInt
(
x2eTy
.
TrimZeroAndDot
(
oracleClaim
.
Amount
),
10
,
64
)
...
...
@@ -62,7 +62,7 @@ func (o *Oracle) ProcessSuccessfulClaimForBurn(claim, execAddr, tokenSymbol stri
senderAddr
:=
oracleClaim
.
Chain33Receiver
if
oracleClaim
.
ClaimType
==
int64
(
x2eTy
.
B
URN_CLAIM_TYPE
)
{
if
oracleClaim
.
ClaimType
==
int64
(
x2eTy
.
B
urnClaimType
)
{
amount
,
_
:=
strconv
.
ParseInt
(
x2eTy
.
TrimZeroAndDot
(
oracleClaim
.
Amount
),
10
,
64
)
receipt
,
err
=
accDB
.
ExecTransfer
(
address
.
ExecAddress
(
tokenSymbol
),
senderAddr
,
execAddr
,
amount
)
if
err
!=
nil
{
...
...
@@ -441,7 +441,6 @@ func (o *Oracle) GetValidatorArray() (*x2eTy.ValidatorList, error) {
func
(
o
*
Oracle
)
SetConsensusThreshold
(
ConsensusThreshold
int64
)
{
o
.
consensusThreshold
=
ConsensusThreshold
elog
.
Info
(
"SetConsensusNeeded"
,
"nowConsensusNeeded"
,
o
.
consensusThreshold
)
return
}
func
(
o
*
Oracle
)
GetConsensusThreshold
()
int64
{
...
...
plugin/dapp/x2Ethereum/plugin.go
View file @
91f9d67f
package
x2
E
thereum
package
x2
e
thereum
import
(
"github.com/33cn/chain33/pluginmgr"
...
...
plugin/dapp/x2Ethereum/types/const.go
View file @
91f9d67f
...
...
@@ -64,8 +64,8 @@ const DefaultConsensusNeeded = int64(70)
const
(
DirEth2Chain33
=
"eth2chain33"
DirChain33ToEth
=
"chain33toeth"
L
OCK_CLAIM
=
"lock"
B
URN_CLAIM
=
"burn"
L
ockClaim
=
"lock"
B
urnClaim
=
"burn"
)
var
DirectionType
=
[
3
]
string
{
""
,
DirEth2Chain33
,
DirChain33ToEth
}
...
...
@@ -81,6 +81,6 @@ const (
)
const
(
L
OCK_CLAIM_TYPE
=
int32
(
1
)
B
URN_CLAIM_TYPE
=
int32
(
2
)
L
ockClaimType
=
int32
(
1
)
B
urnClaimType
=
int32
(
2
)
)
plugin/dapp/x2Ethereum/types/utils.go
View file @
91f9d67f
...
...
@@ -9,13 +9,6 @@ import (
"strings"
"github.com/33cn/chain33/common/address"
log
"github.com/33cn/chain33/common/log/log15"
)
var
(
//日志
clog
=
log
.
New
(
"module"
,
"common"
)
)
func
Float64ToBytes
(
float
float64
)
[]
byte
{
...
...
plugin/dapp/x2Ethereum/types/x2ethereum.go
View file @
91f9d67f
...
...
@@ -67,38 +67,38 @@ func InitExecutor(cfg *types.Chain33Config) {
types
.
RegistorExecutor
(
X2ethereumX
,
NewType
(
cfg
))
}
type
x
2ethereumType
struct
{
type
X
2ethereumType
struct
{
types
.
ExecTypeBase
}
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
x
2ethereumType
{
c
:=
&
x
2ethereumType
{}
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
X
2ethereumType
{
c
:=
&
X
2ethereumType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
func
(
x
*
x
2ethereumType
)
GetName
()
string
{
func
(
x
*
X
2ethereumType
)
GetName
()
string
{
return
X2ethereumX
}
// GetPayload 获取合约action结构
func
(
x
*
x
2ethereumType
)
GetPayload
()
types
.
Message
{
func
(
x
*
X
2ethereumType
)
GetPayload
()
types
.
Message
{
return
&
X2EthereumAction
{}
}
// GeTypeMap 获取合约action的id和name信息
func
(
x
*
x
2ethereumType
)
GetTypeMap
()
map
[
string
]
int32
{
func
(
x
*
X
2ethereumType
)
GetTypeMap
()
map
[
string
]
int32
{
return
actionMap
}
// GetLogMap 获取合约log相关信息
func
(
x
*
x
2ethereumType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
func
(
x
*
X
2ethereumType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
return
logMap
}
// ActionName get PrivacyType action name
func
(
x
x
2ethereumType
)
ActionName
(
tx
*
types
.
Transaction
)
string
{
func
(
x
X
2ethereumType
)
ActionName
(
tx
*
types
.
Transaction
)
string
{
var
action
X2EthereumAction
err
:=
types
.
Decode
(
tx
.
Payload
,
&
action
)
if
err
!=
nil
{
...
...
@@ -137,7 +137,7 @@ func (action *X2EthereumAction) GetActionName() string {
}
// CreateTx token 创建合约
func
(
x
*
x
2ethereumType
)
CreateTx
(
action
string
,
msg
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
func
(
x
*
X
2ethereumType
)
CreateTx
(
action
string
,
msg
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
tx
,
err
:=
x
.
ExecTypeBase
.
CreateTx
(
action
,
msg
)
if
err
!=
nil
{
tlog
.
Error
(
"token CreateTx failed"
,
"err"
,
err
,
"action"
,
action
,
"msg"
,
string
(
msg
))
...
...
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