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
939fbbcf
Commit
939fbbcf
authored
May 08, 2020
by
whisker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix setConsensusThreshold bug
parent
2f6c9600
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
33 deletions
+64
-33
exec.go
plugin/dapp/x2Ethereum/executor/exec.go
+28
-0
keeper.go
plugin/dapp/x2Ethereum/executor/oracle/keeper.go
+4
-4
x2ethereumaction.go
plugin/dapp/x2Ethereum/executor/x2ethereumaction.go
+32
-29
No files found.
plugin/dapp/x2Ethereum/executor/exec.go
View file @
939fbbcf
package
executor
import
(
"errors"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types"
x2ethereumtypes
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
...
...
@@ -18,6 +19,9 @@ import (
// 本端在验证该类型的请求合理后铸币,并生成相同数额的token
func
(
x
*
x2ethereum
)
Exec_Eth2Chain33
(
payload
*
x2ethereumtypes
.
Eth2Chain33
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
,
defaultCon
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
if
payload
.
ValidatorAddress
==
""
{
payload
.
ValidatorAddress
=
address
.
PubKeyToAddr
(
tx
.
Signature
.
Pubkey
)
}
...
...
@@ -27,6 +31,9 @@ func (x *x2ethereum) Exec_Eth2Chain33(payload *x2ethereumtypes.Eth2Chain33, tx *
// 将因ethereum端锁定的eth或者erc20而在chain33端生成的token返还
func
(
x
*
x2ethereum
)
Exec_WithdrawEth
(
payload
*
x2ethereumtypes
.
Eth2Chain33
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
,
defaultCon
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
if
payload
.
ValidatorAddress
==
""
{
payload
.
ValidatorAddress
=
address
.
PubKeyToAddr
(
tx
.
Signature
.
Pubkey
)
}
...
...
@@ -39,6 +46,9 @@ func (x *x2ethereum) Exec_WithdrawEth(payload *x2ethereumtypes.Eth2Chain33, tx *
// WithdrawChain33类型的交易是Chain33侧将本端生成的token返还到Ethereum端
func
(
x
*
x2ethereum
)
Exec_WithdrawChain33
(
payload
*
x2ethereumtypes
.
Chain33ToEth
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
,
defaultCon
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
return
action
.
procMsgBurn
(
payload
,
defaultCon
)
}
...
...
@@ -46,12 +56,18 @@ func (x *x2ethereum) Exec_WithdrawChain33(payload *x2ethereumtypes.Chain33ToEth,
// 在本端锁定一定数额的token,然后在ethereum端生成相同数额的token
func
(
x
*
x2ethereum
)
Exec_Chain33ToEth
(
payload
*
x2ethereumtypes
.
Chain33ToEth
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
,
defaultCon
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
return
action
.
procMsgLock
(
payload
,
defaultCon
)
}
// 转账功能
func
(
x
*
x2ethereum
)
Exec_Transfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
,
defaultCon
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
return
action
.
procMsgTransfer
(
payload
,
defaultCon
)
}
...
...
@@ -62,6 +78,9 @@ func (x *x2ethereum) Exec_AddValidator(payload *x2ethereumtypes.MsgValidator, tx
err
:=
checkTxSignBySpecificAddr
(
tx
,
x2ethereumtypes
.
X2ethereumAdmin
)
if
err
==
nil
{
action
,
defaultCon
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
return
action
.
procAddValidator
(
payload
,
defaultCon
)
}
return
nil
,
err
...
...
@@ -72,6 +91,9 @@ func (x *x2ethereum) Exec_RemoveValidator(payload *x2ethereumtypes.MsgValidator,
err
:=
checkTxSignBySpecificAddr
(
tx
,
x2ethereumtypes
.
X2ethereumAdmin
)
if
err
==
nil
{
action
,
defaultCon
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
return
action
.
procRemoveValidator
(
payload
,
defaultCon
)
}
return
nil
,
err
...
...
@@ -82,6 +104,9 @@ func (x *x2ethereum) Exec_ModifyPower(payload *x2ethereumtypes.MsgValidator, tx
err
:=
checkTxSignBySpecificAddr
(
tx
,
x2ethereumtypes
.
X2ethereumAdmin
)
if
err
==
nil
{
action
,
defaultCon
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
return
action
.
procModifyValidator
(
payload
,
defaultCon
)
}
return
nil
,
err
...
...
@@ -92,6 +117,9 @@ func (x *x2ethereum) Exec_SetConsensusThreshold(payload *x2ethereumtypes.MsgCons
err
:=
checkTxSignBySpecificAddr
(
tx
,
x2ethereumtypes
.
X2ethereumAdmin
)
if
err
==
nil
{
action
,
_
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
return
action
.
procMsgSetConsensusThreshold
(
payload
)
}
return
nil
,
err
...
...
plugin/dapp/x2Ethereum/executor/oracle/keeper.go
View file @
939fbbcf
...
...
@@ -21,11 +21,11 @@ type Keeper struct {
ConsensusThreshold
int64
}
func
NewKeeper
(
db
dbm
.
KV
,
ConsensusThreshold
int64
)
Keeper
{
if
ConsensusThreshold
<=
0
||
ConsensusThreshold
>
1
{
panic
(
types
.
ErrMinimumConsensusNeededInvalid
)
func
NewKeeper
(
db
dbm
.
KV
,
ConsensusThreshold
int64
)
*
Keeper
{
if
ConsensusThreshold
<=
0
||
ConsensusThreshold
>
1
00
{
return
nil
}
return
Keeper
{
return
&
Keeper
{
db
:
db
,
ConsensusThreshold
:
ConsensusThreshold
,
}
...
...
plugin/dapp/x2Ethereum/executor/x2ethereumaction.go
View file @
939fbbcf
...
...
@@ -86,10 +86,13 @@ func newAction(a *x2ethereum, tx *chain33types.Transaction, index int32) (*actio
ConsensusThreshold
=
mc
.
NowConsensusThreshold
}
oracleKeeper
:=
oracle
.
NewKeeper
(
a
.
GetStateDB
(),
ConsensusThreshold
)
if
oracleKeeper
==
nil
{
return
nil
,
true
}
elog
.
Info
(
"newAction"
,
"newAction"
,
"done"
)
return
&
action
{
a
.
GetAPI
(),
a
.
GetCoinsAccount
(),
a
.
GetStateDB
(),
hash
,
fromaddr
,
a
.
GetBlockTime
(),
a
.
GetHeight
(),
index
,
address
.
ExecAddress
(
string
(
tx
.
Execer
)),
ethbridge
.
NewKeeper
(
&
oracleKeeper
,
a
.
GetStateDB
())},
defaultCon
a
.
GetBlockTime
(),
a
.
GetHeight
(),
index
,
address
.
ExecAddress
(
string
(
tx
.
Execer
)),
ethbridge
.
NewKeeper
(
oracleKeeper
,
a
.
GetStateDB
())},
defaultCon
}
// ethereum ---> chain33
...
...
@@ -189,19 +192,19 @@ func (a *action) procMsgEth2Chain33(ethBridgeClaim *types2.Eth2Chain33, defaultC
execlog
:=
&
chain33types
.
ReceiptLog
{
Ty
:
types2
.
TyEth2Chain33Log
,
Log
:
chain33types
.
Encode
(
&
types2
.
ReceiptEth2Chain33
{
EthereumChainID
:
msgEthBridgeClaim
.
EthereumChainID
,
BridgeContractAddress
:
msgEthBridgeClaim
.
BridgeContractAddress
,
Nonce
:
msgEthBridgeClaim
.
Nonce
,
LocalCoinSymbol
:
msgEthBridgeClaim
.
LocalCoinSymbol
,
LocalCoinExec
:
msgEthBridgeClaim
.
LocalCoinExec
,
TokenContractAddress
:
msgEthBridgeClaim
.
TokenContractAddress
,
EthereumSender
:
msgEthBridgeClaim
.
EthereumSender
,
Chain33Receiver
:
msgEthBridgeClaim
.
Chain33Receiver
,
ValidatorAddress
:
msgEthBridgeClaim
.
ValidatorAddress
,
Amount
:
msgEthBridgeClaim
.
Amount
,
ClaimType
:
msgEthBridgeClaim
.
ClaimType
,
XTxHash
:
a
.
txhash
,
XHeight
:
uint64
(
a
.
height
),
ProphecyID
:
ID
,
Decimals
:
msgEthBridgeClaim
.
Decimals
,
Nonce
:
msgEthBridgeClaim
.
Nonce
,
LocalCoinSymbol
:
msgEthBridgeClaim
.
LocalCoinSymbol
,
LocalCoinExec
:
msgEthBridgeClaim
.
LocalCoinExec
,
TokenContractAddress
:
msgEthBridgeClaim
.
TokenContractAddress
,
EthereumSender
:
msgEthBridgeClaim
.
EthereumSender
,
Chain33Receiver
:
msgEthBridgeClaim
.
Chain33Receiver
,
ValidatorAddress
:
msgEthBridgeClaim
.
ValidatorAddress
,
Amount
:
msgEthBridgeClaim
.
Amount
,
ClaimType
:
msgEthBridgeClaim
.
ClaimType
,
XTxHash
:
a
.
txhash
,
XHeight
:
uint64
(
a
.
height
),
ProphecyID
:
ID
,
Decimals
:
msgEthBridgeClaim
.
Decimals
,
})}
receipt
.
Logs
=
append
(
receipt
.
Logs
,
execlog
)
...
...
@@ -401,19 +404,19 @@ func (a *action) procWithdrawEth(withdrawEth *types2.Eth2Chain33, defaultCon boo
execlog
:=
&
chain33types
.
ReceiptLog
{
Ty
:
types2
.
TyWithdrawEthLog
,
Log
:
chain33types
.
Encode
(
&
types2
.
ReceiptEth2Chain33
{
EthereumChainID
:
msgWithdrawEth
.
EthereumChainID
,
BridgeContractAddress
:
msgWithdrawEth
.
BridgeContractAddress
,
Nonce
:
msgWithdrawEth
.
Nonce
,
LocalCoinSymbol
:
msgWithdrawEth
.
LocalCoinSymbol
,
LocalCoinExec
:
msgWithdrawEth
.
LocalCoinExec
,
TokenContractAddress
:
msgWithdrawEth
.
TokenContractAddress
,
EthereumSender
:
msgWithdrawEth
.
EthereumSender
,
Chain33Receiver
:
msgWithdrawEth
.
Chain33Receiver
,
ValidatorAddress
:
msgWithdrawEth
.
ValidatorAddress
,
Amount
:
msgWithdrawEth
.
Amount
,
ClaimType
:
msgWithdrawEth
.
ClaimType
,
XTxHash
:
a
.
txhash
,
XHeight
:
uint64
(
a
.
height
),
ProphecyID
:
ID
,
Decimals
:
msgWithdrawEth
.
Decimals
,
Nonce
:
msgWithdrawEth
.
Nonce
,
LocalCoinSymbol
:
msgWithdrawEth
.
LocalCoinSymbol
,
LocalCoinExec
:
msgWithdrawEth
.
LocalCoinExec
,
TokenContractAddress
:
msgWithdrawEth
.
TokenContractAddress
,
EthereumSender
:
msgWithdrawEth
.
EthereumSender
,
Chain33Receiver
:
msgWithdrawEth
.
Chain33Receiver
,
ValidatorAddress
:
msgWithdrawEth
.
ValidatorAddress
,
Amount
:
msgWithdrawEth
.
Amount
,
ClaimType
:
msgWithdrawEth
.
ClaimType
,
XTxHash
:
a
.
txhash
,
XHeight
:
uint64
(
a
.
height
),
ProphecyID
:
ID
,
Decimals
:
msgWithdrawEth
.
Decimals
,
})}
receipt
.
Logs
=
append
(
receipt
.
Logs
,
execlog
)
...
...
@@ -582,8 +585,8 @@ func (a *action) procMsgSetConsensusThreshold(msgSetConsensusThreshold *types2.M
}
setConsensusThreshold
:=
&
types2
.
ReceiptSetConsensusThreshold
{
PreConsensusThreshold
:
int64
(
preConsensusNeeded
*
100
)
,
NowConsensusThreshold
:
int64
(
nowConsensusNeeded
*
100
)
,
PreConsensusThreshold
:
preConsensusNeeded
,
NowConsensusThreshold
:
nowConsensusNeeded
,
XTxHash
:
a
.
txhash
,
XHeight
:
uint64
(
a
.
height
),
}
...
...
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