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
a7904920
Commit
a7904920
authored
May 15, 2020
by
whisker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor contract code
parent
10c40fd2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
333 additions
and
819 deletions
+333
-819
commands.go
plugin/dapp/x2Ethereum/commands/commands.go
+69
-11
chain33.go
plugin/dapp/x2Ethereum/ebrelayer/relayer/chain33/chain33.go
+0
-5
claim.go
plugin/dapp/x2Ethereum/executor/ethbridge/claim.go
+0
-66
keeper.go
plugin/dapp/x2Ethereum/executor/ethbridge/keeper.go
+0
-252
exec.go
plugin/dapp/x2Ethereum/executor/exec.go
+54
-21
exec_local.go
plugin/dapp/x2Ethereum/executor/exec_local.go
+0
-0
keeper.go
plugin/dapp/x2Ethereum/executor/oracle/keeper.go
+0
-252
prophecy.go
plugin/dapp/x2Ethereum/executor/oracle/prophecy.go
+0
-140
prophecy.go
plugin/dapp/x2Ethereum/executor/prophecy.go
+116
-0
query.go
plugin/dapp/x2Ethereum/executor/query.go
+44
-46
x2ethereum.go
plugin/dapp/x2Ethereum/executor/x2ethereum.go
+2
-2
x2ethereumaction.go
plugin/dapp/x2Ethereum/executor/x2ethereumaction.go
+0
-0
x2ethereumdb.go
plugin/dapp/x2Ethereum/executor/x2ethereumdb.go
+0
-0
x2ethereum.proto
plugin/dapp/x2Ethereum/proto/x2ethereum.proto
+8
-9
const.go
plugin/dapp/x2Ethereum/types/const.go
+10
-9
oracle.pb.go
plugin/dapp/x2Ethereum/types/oracle.pb.go
+1
-2
utils.go
plugin/dapp/x2Ethereum/types/utils.go
+15
-0
x2ethereum.go
plugin/dapp/x2Ethereum/types/x2ethereum.go
+14
-4
x2ethereum.pb.go
plugin/dapp/x2Ethereum/types/x2ethereum.pb.go
+0
-0
No files found.
plugin/dapp/x2Ethereum/commands/commands.go
View file @
a7904920
...
@@ -37,6 +37,8 @@ func Cmd() *cobra.Command {
...
@@ -37,6 +37,8 @@ func Cmd() *cobra.Command {
CreateRawModifyValidatorTxCmd
(),
CreateRawModifyValidatorTxCmd
(),
CreateRawSetConsensusTxCmd
(),
CreateRawSetConsensusTxCmd
(),
CreateTransferCmd
(),
CreateTransferCmd
(),
CreateTokenTransferExecCmd
(),
CreateTokenWithdrawCmd
(),
queryCmd
(),
queryCmd
(),
queryRelayerBalanceCmd
(),
queryRelayerBalanceCmd
(),
)
)
...
@@ -73,9 +75,6 @@ func addEth2Chain33Flags(cmd *cobra.Command) {
...
@@ -73,9 +75,6 @@ func addEth2Chain33Flags(cmd *cobra.Command) {
cmd
.
Flags
()
.
StringP
(
"csymbol"
,
"t"
,
""
,
"token symbol in chain33"
)
cmd
.
Flags
()
.
StringP
(
"csymbol"
,
"t"
,
""
,
"token symbol in chain33"
)
_
=
cmd
.
MarkFlagRequired
(
"csymbol"
)
_
=
cmd
.
MarkFlagRequired
(
"csymbol"
)
cmd
.
Flags
()
.
StringP
(
"cexec"
,
"e"
,
""
,
"chain execer in chain33"
)
_
=
cmd
.
MarkFlagRequired
(
"cexec"
)
cmd
.
Flags
()
.
StringP
(
"tcontract"
,
"q"
,
""
,
"token contract address in ethereum"
)
cmd
.
Flags
()
.
StringP
(
"tcontract"
,
"q"
,
""
,
"token contract address in ethereum"
)
_
=
cmd
.
MarkFlagRequired
(
"tcontract"
)
_
=
cmd
.
MarkFlagRequired
(
"tcontract"
)
...
@@ -101,7 +100,6 @@ func Eth2Chain33(cmd *cobra.Command, args []string) {
...
@@ -101,7 +100,6 @@ func Eth2Chain33(cmd *cobra.Command, args []string) {
bcontract
,
_
:=
cmd
.
Flags
()
.
GetString
(
"bcontract"
)
bcontract
,
_
:=
cmd
.
Flags
()
.
GetString
(
"bcontract"
)
nonce
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"nonce"
)
nonce
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"nonce"
)
csymbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"csymbol"
)
csymbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"csymbol"
)
cexec
,
_
:=
cmd
.
Flags
()
.
GetString
(
"cexec"
)
tcontract
,
_
:=
cmd
.
Flags
()
.
GetString
(
"tcontract"
)
tcontract
,
_
:=
cmd
.
Flags
()
.
GetString
(
"tcontract"
)
sender
,
_
:=
cmd
.
Flags
()
.
GetString
(
"sender"
)
sender
,
_
:=
cmd
.
Flags
()
.
GetString
(
"sender"
)
receiver
,
_
:=
cmd
.
Flags
()
.
GetString
(
"receiver"
)
receiver
,
_
:=
cmd
.
Flags
()
.
GetString
(
"receiver"
)
...
@@ -120,8 +118,7 @@ func Eth2Chain33(cmd *cobra.Command, args []string) {
...
@@ -120,8 +118,7 @@ func Eth2Chain33(cmd *cobra.Command, args []string) {
EthereumChainID
:
ethid
,
EthereumChainID
:
ethid
,
BridgeContractAddress
:
bcontract
,
BridgeContractAddress
:
bcontract
,
Nonce
:
nonce
,
Nonce
:
nonce
,
LocalCoinSymbol
:
csymbol
,
IssuerDotSymbol
:
csymbol
,
LocalCoinExec
:
cexec
,
TokenContractAddress
:
tcontract
,
TokenContractAddress
:
tcontract
,
EthereumSender
:
sender
,
EthereumSender
:
sender
,
Chain33Receiver
:
receiver
,
Chain33Receiver
:
receiver
,
...
@@ -145,6 +142,10 @@ func CreateRawWithdrawEthTxCmd() *cobra.Command {
...
@@ -145,6 +142,10 @@ func CreateRawWithdrawEthTxCmd() *cobra.Command {
}
}
addEth2Chain33Flags
(
cmd
)
addEth2Chain33Flags
(
cmd
)
cmd
.
Flags
()
.
StringP
(
"exec"
,
"e"
,
""
,
"exec name token or coins"
)
_
=
cmd
.
MarkFlagRequired
(
"exec"
)
return
cmd
return
cmd
}
}
...
@@ -153,7 +154,6 @@ func WithdrawEth(cmd *cobra.Command, args []string) {
...
@@ -153,7 +154,6 @@ func WithdrawEth(cmd *cobra.Command, args []string) {
bcontract
,
_
:=
cmd
.
Flags
()
.
GetString
(
"bcontract"
)
bcontract
,
_
:=
cmd
.
Flags
()
.
GetString
(
"bcontract"
)
nonce
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"nonce"
)
nonce
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"nonce"
)
csymbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"csymbol"
)
csymbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"csymbol"
)
cexec
,
_
:=
cmd
.
Flags
()
.
GetString
(
"cexec"
)
tcontract
,
_
:=
cmd
.
Flags
()
.
GetString
(
"tcontract"
)
tcontract
,
_
:=
cmd
.
Flags
()
.
GetString
(
"tcontract"
)
sender
,
_
:=
cmd
.
Flags
()
.
GetString
(
"sender"
)
sender
,
_
:=
cmd
.
Flags
()
.
GetString
(
"sender"
)
receiver
,
_
:=
cmd
.
Flags
()
.
GetString
(
"receiver"
)
receiver
,
_
:=
cmd
.
Flags
()
.
GetString
(
"receiver"
)
...
@@ -172,8 +172,7 @@ func WithdrawEth(cmd *cobra.Command, args []string) {
...
@@ -172,8 +172,7 @@ func WithdrawEth(cmd *cobra.Command, args []string) {
EthereumChainID
:
ethid
,
EthereumChainID
:
ethid
,
BridgeContractAddress
:
bcontract
,
BridgeContractAddress
:
bcontract
,
Nonce
:
nonce
,
Nonce
:
nonce
,
LocalCoinSymbol
:
csymbol
,
IssuerDotSymbol
:
csymbol
,
LocalCoinExec
:
cexec
,
TokenContractAddress
:
tcontract
,
TokenContractAddress
:
tcontract
,
EthereumSender
:
sender
,
EthereumSender
:
sender
,
Chain33Receiver
:
receiver
,
Chain33Receiver
:
receiver
,
...
@@ -236,7 +235,7 @@ func burn(cmd *cobra.Command, args []string) {
...
@@ -236,7 +235,7 @@ func burn(cmd *cobra.Command, args []string) {
TokenContract
:
contract
,
TokenContract
:
contract
,
EthereumReceiver
:
receiver
,
EthereumReceiver
:
receiver
,
Amount
:
types3
.
TrimZeroAndDot
(
strconv
.
FormatFloat
(
amount
*
1e8
,
'f'
,
4
,
64
)),
Amount
:
types3
.
TrimZeroAndDot
(
strconv
.
FormatFloat
(
amount
*
1e8
,
'f'
,
4
,
64
)),
LocalCoin
Symbol
:
csymbol
,
IssuerDot
Symbol
:
csymbol
,
Decimals
:
decimal
,
Decimals
:
decimal
,
}
}
...
@@ -255,6 +254,9 @@ func CreateRawChain33ToEthTxCmd() *cobra.Command {
...
@@ -255,6 +254,9 @@ func CreateRawChain33ToEthTxCmd() *cobra.Command {
addChain33ToEthFlags
(
cmd
)
addChain33ToEthFlags
(
cmd
)
cmd
.
Flags
()
.
StringP
(
"exec"
,
"e"
,
""
,
"exec name token or coins"
)
_
=
cmd
.
MarkFlagRequired
(
"exec"
)
return
cmd
return
cmd
}
}
...
@@ -280,7 +282,7 @@ func lock(cmd *cobra.Command, args []string) {
...
@@ -280,7 +282,7 @@ func lock(cmd *cobra.Command, args []string) {
TokenContract
:
contract
,
TokenContract
:
contract
,
EthereumReceiver
:
receiver
,
EthereumReceiver
:
receiver
,
Amount
:
strconv
.
FormatFloat
(
amount
*
1e8
,
'f'
,
4
,
64
),
Amount
:
strconv
.
FormatFloat
(
amount
*
1e8
,
'f'
,
4
,
64
),
LocalCoin
Symbol
:
csymbol
,
IssuerDot
Symbol
:
csymbol
,
Decimals
:
decimal
,
Decimals
:
decimal
,
}
}
...
@@ -319,6 +321,62 @@ func addTransferFlags(cmd *cobra.Command) {
...
@@ -319,6 +321,62 @@ func addTransferFlags(cmd *cobra.Command) {
}
}
// CreateTokenTransferExecCmd create raw transfer tx
func
CreateTokenTransferExecCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"send_exec"
,
Short
:
"Create a token send to executor transaction"
,
Run
:
createTokenSendToExec
,
}
addCreateTokenSendToExecFlags
(
cmd
)
return
cmd
}
func
addCreateTokenSendToExecFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"exec"
,
"e"
,
""
,
"receiver executor address"
)
cmd
.
MarkFlagRequired
(
"exec"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0
,
"transaction amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"transaction note info"
)
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
""
,
"token symbol"
)
cmd
.
MarkFlagRequired
(
"symbol"
)
}
func
createTokenSendToExec
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
commands
.
CreateAssetSendToExec
(
cmd
,
args
,
types3
.
X2ethereumX
)
}
// CreateTokenWithdrawCmd create raw withdraw tx
func
CreateTokenWithdrawCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"withdrawfromexec"
,
Short
:
"Create a token withdraw transaction"
,
Run
:
createTokenWithdraw
,
}
addCreateTokenWithdrawFlags
(
cmd
)
return
cmd
}
func
addCreateTokenWithdrawFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"exec"
,
"e"
,
""
,
"execer withdrawn from"
)
cmd
.
MarkFlagRequired
(
"exec"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0
,
"withdraw amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"transaction note info"
)
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
""
,
"token symbol"
)
cmd
.
MarkFlagRequired
(
"symbol"
)
}
func
createTokenWithdraw
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
commands
.
CreateAssetWithdraw
(
cmd
,
args
,
types3
.
X2ethereumX
)
}
// AddValidator
// AddValidator
func
CreateRawAddValidatorTxCmd
()
*
cobra
.
Command
{
func
CreateRawAddValidatorTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
...
...
plugin/dapp/x2Ethereum/ebrelayer/relayer/chain33/chain33.go
View file @
a7904920
...
@@ -200,11 +200,6 @@ func (chain33Relayer *Chain33Relayer) onNewHeightProc(currentHeight int64) {
...
@@ -200,11 +200,6 @@ func (chain33Relayer *Chain33Relayer) onNewHeightProc(currentHeight int64) {
_
=
chain33Types
.
Decode
(
tx
.
Payload
,
&
ss
)
_
=
chain33Types
.
Decode
(
tx
.
Payload
,
&
ss
)
actionName
:=
ss
.
GetActionName
()
actionName
:=
ss
.
GetActionName
()
if
relayerTx
.
BurnAction
==
actionName
||
relayerTx
.
LockAction
==
actionName
{
if
relayerTx
.
BurnAction
==
actionName
||
relayerTx
.
LockAction
==
actionName
{
if
actionName
==
relayerTx
.
BurnAction
{
actionName
=
actionName
+
"-burn"
}
else
{
actionName
=
actionName
+
"-lock"
}
relayerLog
.
Debug
(
"^_^ ^_^ Processing chain33 tx receipt"
,
"ActionName"
,
actionName
,
"fromAddr"
,
tx
.
From
(),
"exec"
,
string
(
tx
.
Execer
))
relayerLog
.
Debug
(
"^_^ ^_^ Processing chain33 tx receipt"
,
"ActionName"
,
actionName
,
"fromAddr"
,
tx
.
From
(),
"exec"
,
string
(
tx
.
Execer
))
actionEvent
:=
getOracleClaimType
(
actionName
)
actionEvent
:=
getOracleClaimType
(
actionName
)
if
err
:=
chain33Relayer
.
handleBurnLockMsg
(
actionEvent
,
TxReceipts
.
ReceiptData
[
i
],
tx
.
Hash
());
nil
!=
err
{
if
err
:=
chain33Relayer
.
handleBurnLockMsg
(
actionEvent
,
TxReceipts
.
ReceiptData
[
i
],
tx
.
Hash
());
nil
!=
err
{
...
...
plugin/dapp/x2Ethereum/executor/ethbridge/claim.go
deleted
100644 → 0
View file @
10c40fd2
package
ethbridge
import
(
"errors"
"fmt"
"strconv"
"github.com/golang/protobuf/proto"
log
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
)
var
(
//日志
elog
=
log
.
New
(
"module"
,
"ethbridge"
)
)
func
NewOracleClaimContent
(
chain33Receiver
string
,
amount
string
,
claimType
,
decimals
int64
)
types
.
OracleClaimContent
{
return
types
.
OracleClaimContent
{
Chain33Receiver
:
chain33Receiver
,
Amount
:
amount
,
ClaimType
:
claimType
,
Decimals
:
decimals
,
}
}
func
NewClaim
(
id
string
,
validatorAddress
string
,
content
string
)
types
.
OracleClaim
{
return
types
.
OracleClaim
{
ID
:
id
,
ValidatorAddress
:
validatorAddress
,
Content
:
content
,
}
}
//通过ethchain33结构构造一个OracleClaim结构,包括生成唯一的ID
func
CreateOracleClaimFromEthClaim
(
ethClaim
types
.
Eth2Chain33
)
(
types
.
OracleClaim
,
error
)
{
if
ethClaim
.
ClaimType
!=
int64
(
types
.
LOCK_CLAIM_TYPE
)
&&
ethClaim
.
ClaimType
!=
int64
(
types
.
BURN_CLAIM_TYPE
)
{
return
types
.
OracleClaim
{},
types
.
ErrInvalidClaimType
}
oracleID
:=
strconv
.
Itoa
(
int
(
ethClaim
.
EthereumChainID
))
+
strconv
.
Itoa
(
int
(
ethClaim
.
Nonce
))
+
ethClaim
.
EthereumSender
+
ethClaim
.
TokenContractAddress
if
ethClaim
.
ClaimType
==
int64
(
types
.
LOCK_CLAIM_TYPE
)
{
oracleID
=
oracleID
+
"lock"
}
else
if
ethClaim
.
ClaimType
==
int64
(
types
.
BURN_CLAIM_TYPE
)
{
oracleID
=
oracleID
+
"burn"
}
claimContent
:=
NewOracleClaimContent
(
ethClaim
.
Chain33Receiver
,
ethClaim
.
Amount
,
ethClaim
.
ClaimType
,
ethClaim
.
Decimals
)
claimBytes
,
err
:=
proto
.
Marshal
(
&
claimContent
)
if
err
!=
nil
{
return
types
.
OracleClaim
{},
err
}
claimString
:=
string
(
claimBytes
)
claim
:=
NewClaim
(
oracleID
,
ethClaim
.
ValidatorAddress
,
claimString
)
return
claim
,
nil
}
func
CreateOracleClaimFromOracleString
(
oracleClaimString
string
)
(
types
.
OracleClaimContent
,
error
)
{
var
oracleClaimContent
types
.
OracleClaimContent
bz
:=
[]
byte
(
oracleClaimString
)
if
err
:=
proto
.
Unmarshal
(
bz
,
&
oracleClaimContent
);
err
!=
nil
{
return
types
.
OracleClaimContent
{},
errors
.
New
(
fmt
.
Sprintf
(
"failed to parse claim: %s"
,
err
.
Error
()))
}
return
oracleClaimContent
,
nil
}
plugin/dapp/x2Ethereum/executor/ethbridge/keeper.go
deleted
100644 → 0
View file @
10c40fd2
package
ethbridge
import
(
"strconv"
"github.com/golang/protobuf/proto"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common/address"
dbm
"github.com/33cn/chain33/common/db"
types2
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/executor/oracle"
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
)
type
Keeper
struct
{
oracleKeeper
oracle
.
OracleKeeper
db
dbm
.
KV
}
func
NewKeeper
(
oracleKeeper
oracle
.
OracleKeeper
,
db
dbm
.
KV
)
Keeper
{
return
Keeper
{
oracleKeeper
:
oracleKeeper
,
db
:
db
,
}
}
// 处理接收到的ethchain33请求
func
(
k
Keeper
)
ProcessClaim
(
claim
types
.
Eth2Chain33
)
(
*
types
.
ProphecyStatus
,
error
)
{
oracleClaim
,
err
:=
CreateOracleClaimFromEthClaim
(
claim
)
if
err
!=
nil
{
elog
.
Error
(
"CreateEthClaimFromOracleString"
,
"CreateOracleClaimFromOracleString error"
,
err
)
return
nil
,
err
}
status
,
err
:=
k
.
oracleKeeper
.
ProcessClaim
(
oracleClaim
)
if
err
!=
nil
{
return
nil
,
err
}
return
status
,
nil
}
// 处理经过审核的关于Lock的claim
func
(
k
Keeper
)
ProcessSuccessfulClaimForLock
(
claim
,
execAddr
,
tokenSymbol
,
tokenAddress
string
,
accDB
*
account
.
DB
)
(
*
types2
.
Receipt
,
error
)
{
var
receipt
*
types2
.
Receipt
oracleClaim
,
err
:=
CreateOracleClaimFromOracleString
(
claim
)
if
err
!=
nil
{
elog
.
Error
(
"CreateEthClaimFromOracleString"
,
"CreateOracleClaimFromOracleString error"
,
err
)
return
nil
,
err
}
receiverAddress
:=
oracleClaim
.
Chain33Receiver
if
oracleClaim
.
ClaimType
==
int64
(
types
.
LOCK_CLAIM_TYPE
)
{
//铸币到相关的tokenSymbolBank账户下
amount
,
_
:=
strconv
.
ParseInt
(
types
.
TrimZeroAndDot
(
oracleClaim
.
Amount
),
10
,
64
)
receipt
,
err
=
accDB
.
Mint
(
execAddr
,
amount
)
if
err
!=
nil
{
return
nil
,
err
}
r
,
err
:=
accDB
.
ExecDeposit
(
receiverAddress
,
execAddr
,
amount
)
if
err
!=
nil
{
return
nil
,
err
}
receipt
.
KV
=
append
(
receipt
.
KV
,
r
.
KV
...
)
receipt
.
Logs
=
append
(
receipt
.
Logs
,
r
.
Logs
...
)
return
receipt
,
nil
}
return
nil
,
types
.
ErrInvalidClaimType
}
// 处理经过审核的关于Burn的claim
func
(
k
Keeper
)
ProcessSuccessfulClaimForBurn
(
claim
,
execAddr
,
tokenSymbol
string
,
accDB
*
account
.
DB
)
(
*
types2
.
Receipt
,
error
)
{
receipt
:=
new
(
types2
.
Receipt
)
oracleClaim
,
err
:=
CreateOracleClaimFromOracleString
(
claim
)
if
err
!=
nil
{
elog
.
Error
(
"CreateEthClaimFromOracleString"
,
"CreateOracleClaimFromOracleString error"
,
err
)
return
nil
,
err
}
senderAddr
:=
oracleClaim
.
Chain33Receiver
if
oracleClaim
.
ClaimType
==
int64
(
types
.
BURN_CLAIM_TYPE
)
{
amount
,
_
:=
strconv
.
ParseInt
(
types
.
TrimZeroAndDot
(
oracleClaim
.
Amount
),
10
,
64
)
receipt
,
err
=
accDB
.
ExecTransfer
(
address
.
ExecAddress
(
tokenSymbol
),
senderAddr
,
execAddr
,
amount
)
if
err
!=
nil
{
return
nil
,
err
}
return
receipt
,
nil
}
return
nil
,
types
.
ErrInvalidClaimType
}
// ProcessBurn processes the burn of bridged coins from the given sender
func
(
k
Keeper
)
ProcessBurn
(
address
,
execAddr
,
amount
,
tokenAddress
string
,
d
int64
,
accDB
*
account
.
DB
)
(
*
types2
.
Receipt
,
error
)
{
var
a
int64
a
,
_
=
strconv
.
ParseInt
(
types
.
TrimZeroAndDot
(
amount
),
10
,
64
)
receipt
,
err
:=
accDB
.
ExecWithdraw
(
execAddr
,
address
,
a
)
if
err
!=
nil
{
return
nil
,
err
}
r
,
err
:=
accDB
.
Burn
(
execAddr
,
a
)
if
err
!=
nil
{
return
nil
,
err
}
receipt
.
KV
=
append
(
receipt
.
KV
,
r
.
KV
...
)
receipt
.
Logs
=
append
(
receipt
.
Logs
,
r
.
Logs
...
)
return
receipt
,
nil
}
// ProcessLock processes the lockup of cosmos coins from the given sender
// accDB = mavl-coins-bty-addr
func
(
k
Keeper
)
ProcessLock
(
address
,
to
,
execAddr
,
amount
string
,
accDB
*
account
.
DB
)
(
*
types2
.
Receipt
,
error
)
{
// 转到 mavl-coins-bty-execAddr:addr
a
,
_
:=
strconv
.
ParseInt
(
types
.
TrimZeroAndDot
(
amount
),
10
,
64
)
receipt
,
err
:=
accDB
.
ExecTransfer
(
address
,
to
,
execAddr
,
a
)
if
err
!=
nil
{
return
nil
,
err
}
return
receipt
,
nil
}
// 对于相同的地址该如何处理?
// 现有方案是相同地址就报错
func
(
k
Keeper
)
ProcessAddValidator
(
address
string
,
power
int64
)
(
*
types2
.
Receipt
,
error
)
{
receipt
:=
new
(
types2
.
Receipt
)
validatorMaps
,
err
:=
k
.
oracleKeeper
.
GetValidatorArray
()
if
err
!=
nil
&&
err
!=
types2
.
ErrNotFound
{
return
nil
,
err
}
if
validatorMaps
==
nil
{
validatorMaps
=
new
(
types
.
ValidatorList
)
}
elog
.
Info
(
"ProcessLogInValidator"
,
"pre validatorMaps"
,
validatorMaps
,
"Add Address"
,
address
,
"Add power"
,
power
)
var
totalPower
int64
for
_
,
p
:=
range
validatorMaps
.
Validators
{
if
p
.
Address
!=
address
{
totalPower
+=
p
.
Power
}
else
{
return
nil
,
types
.
ErrAddressExists
}
}
vs
:=
append
(
validatorMaps
.
Validators
,
&
types
.
MsgValidator
{
Address
:
address
,
Power
:
power
,
})
validatorMaps
.
Validators
=
vs
v
,
_
:=
proto
.
Marshal
(
validatorMaps
)
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types2
.
KeyValue
{
Key
:
types
.
CalValidatorMapsPrefix
(),
Value
:
v
})
totalPower
+=
power
totalP
:=
types
.
ReceiptQueryTotalPower
{
TotalPower
:
totalPower
,
}
totalPBytes
,
_
:=
proto
.
Marshal
(
&
totalP
)
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types2
.
KeyValue
{
Key
:
types
.
CalLastTotalPowerPrefix
(),
Value
:
totalPBytes
})
return
receipt
,
nil
}
func
(
k
Keeper
)
ProcessRemoveValidator
(
address
string
)
(
*
types2
.
Receipt
,
error
)
{
var
exist
bool
receipt
:=
new
(
types2
.
Receipt
)
validatorMaps
,
err
:=
k
.
oracleKeeper
.
GetValidatorArray
()
if
err
!=
nil
{
return
nil
,
err
}
elog
.
Info
(
"ProcessLogOutValidator"
,
"pre validatorMaps"
,
validatorMaps
,
"Delete Address"
,
address
)
var
totalPower
int64
validatorRes
:=
new
(
types
.
ValidatorList
)
for
_
,
p
:=
range
validatorMaps
.
Validators
{
if
address
!=
p
.
Address
{
v
:=
append
(
validatorRes
.
Validators
,
p
)
validatorRes
.
Validators
=
v
totalPower
+=
p
.
Power
}
else
{
exist
=
true
continue
}
}
if
!
exist
{
return
nil
,
types
.
ErrAddressNotExist
}
v
,
_
:=
proto
.
Marshal
(
validatorRes
)
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types2
.
KeyValue
{
Key
:
types
.
CalValidatorMapsPrefix
(),
Value
:
v
})
totalP
:=
types
.
ReceiptQueryTotalPower
{
TotalPower
:
totalPower
,
}
totalPBytes
,
_
:=
proto
.
Marshal
(
&
totalP
)
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types2
.
KeyValue
{
Key
:
types
.
CalLastTotalPowerPrefix
(),
Value
:
totalPBytes
})
return
receipt
,
nil
}
//这里的power指的是修改后的power
func
(
k
Keeper
)
ProcessModifyValidator
(
address
string
,
power
int64
)
(
*
types2
.
Receipt
,
error
)
{
var
exist
bool
receipt
:=
new
(
types2
.
Receipt
)
validatorMaps
,
err
:=
k
.
oracleKeeper
.
GetValidatorArray
()
if
err
!=
nil
{
return
nil
,
err
}
elog
.
Info
(
"ProcessModifyValidator"
,
"pre validatorMaps"
,
validatorMaps
,
"Modify Address"
,
address
,
"Modify power"
,
power
)
var
totalPower
int64
for
index
,
p
:=
range
validatorMaps
.
Validators
{
if
address
!=
p
.
Address
{
totalPower
+=
p
.
Power
}
else
{
validatorMaps
.
Validators
[
index
]
.
Power
=
power
exist
=
true
totalPower
+=
power
}
}
if
!
exist
{
return
nil
,
types
.
ErrAddressNotExist
}
v
,
_
:=
proto
.
Marshal
(
validatorMaps
)
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types2
.
KeyValue
{
Key
:
types
.
CalValidatorMapsPrefix
(),
Value
:
v
})
totalP
:=
types
.
ReceiptQueryTotalPower
{
TotalPower
:
totalPower
,
}
totalPBytes
,
_
:=
proto
.
Marshal
(
&
totalP
)
receipt
.
KV
=
append
(
receipt
.
KV
,
&
types2
.
KeyValue
{
Key
:
types
.
CalLastTotalPowerPrefix
(),
Value
:
totalPBytes
})
return
receipt
,
nil
}
func
(
k
*
Keeper
)
ProcessSetConsensusNeeded
(
ConsensusThreshold
int64
)
(
int64
,
int64
,
error
)
{
preCon
:=
k
.
oracleKeeper
.
GetConsensusThreshold
()
k
.
oracleKeeper
.
SetConsensusThreshold
(
ConsensusThreshold
)
nowCon
:=
k
.
oracleKeeper
.
GetConsensusThreshold
()
elog
.
Info
(
"ProcessSetConsensusNeeded"
,
"pre ConsensusThreshold"
,
preCon
,
"now ConsensusThreshold"
,
nowCon
)
return
preCon
,
nowCon
,
nil
}
plugin/dapp/x2Ethereum/executor/exec.go
View file @
a7904920
...
@@ -2,10 +2,12 @@ package executor
...
@@ -2,10 +2,12 @@ package executor
import
(
import
(
"errors"
"errors"
"github.com/33cn/chain33/system/dapp"
manTy
"github.com/33cn/chain33/system/dapp/manage/types"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
x2e
thereumtypes
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
x2e
Ty
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
)
)
/*
/*
...
@@ -13,12 +15,12 @@ import (
...
@@ -13,12 +15,12 @@ import (
* 关键数据上链(statedb)并生成交易回执(log)
* 关键数据上链(statedb)并生成交易回执(log)
*/
*/
//---------------- Ethereum
--> Chain33(eth/erc20)
-------------------//
//---------------- Ethereum
(eth/erc20) --> Chain33
-------------------//
// Eth2Chain33类型的交易是Ethereum侧锁定一定金额的eth或者erc20到合约中
// Eth2Chain33类型的交易是Ethereum侧锁定一定金额的eth或者erc20到合约中
// 然后relayer端订阅到该消息后向chain33发送该类型消息
// 然后relayer端订阅到该消息后向chain33发送该类型消息
// 本端在验证该类型的请求合理后铸币,并生成相同数额的token
// 本端在验证该类型的请求合理后铸币,并生成相同数额的token
func
(
x
*
x2ethereum
)
Exec_Eth2Chain33
(
payload
*
x2ethereumtypes
.
Eth2Chain33
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
x
*
x2ethereum
)
Exec_Eth2Chain33
_lock
(
payload
*
x2eTy
.
Eth2Chain33
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
return
nil
,
errors
.
New
(
"Create Action Error"
)
...
@@ -26,22 +28,23 @@ func (x *x2ethereum) Exec_Eth2Chain33(payload *x2ethereumtypes.Eth2Chain33, tx *
...
@@ -26,22 +28,23 @@ func (x *x2ethereum) Exec_Eth2Chain33(payload *x2ethereumtypes.Eth2Chain33, tx *
payload
.
ValidatorAddress
=
address
.
PubKeyToAddr
(
tx
.
Signature
.
Pubkey
)
payload
.
ValidatorAddress
=
address
.
PubKeyToAddr
(
tx
.
Signature
.
Pubkey
)
return
action
.
proc
MsgEth2Chain33
(
payload
)
return
action
.
proc
Eth2Chain33_lock
(
payload
)
}
}
//---------------- Chain33(eth/erc20)------> Ethereum -------------------//
// WithdrawChain33类型的交易是将Eth端因Chain33端锁定所生成的token返还给Chain33端(Burn)
// WithdrawChain33类型的交易是将Eth端因Chain33端锁定所生成的token返还给Chain33端(Burn)
func
(
x
*
x2ethereum
)
Exec_
WithdrawChain33
(
payload
*
x2ethereumtypes
.
Chain33ToEth
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
x
*
x2ethereum
)
Exec_
Chain33ToEth_burn
(
payload
*
x2eTy
.
Chain33ToEth
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
}
return
action
.
proc
MsgB
urn
(
payload
)
return
action
.
proc
Chain33ToEth_b
urn
(
payload
)
}
}
//---------------- Chain33(eth/erc20) --> Ethereum-------------------//
//---------------- Chain33(eth/erc20) --> Ethereum-------------------//
// 将因ethereum端锁定的eth或者erc20而在chain33端生成的token返还
// 将因ethereum端锁定的eth或者erc20而在chain33端生成的token返还
func
(
x
*
x2ethereum
)
Exec_
WithdrawEth
(
payload
*
x2ethereumtypes
.
Eth2Chain33
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
x
*
x2ethereum
)
Exec_
Eth2Chain33_burn
(
payload
*
x2eTy
.
Eth2Chain33
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
return
nil
,
errors
.
New
(
"Create Action Error"
)
...
@@ -49,17 +52,17 @@ func (x *x2ethereum) Exec_WithdrawEth(payload *x2ethereumtypes.Eth2Chain33, tx *
...
@@ -49,17 +52,17 @@ func (x *x2ethereum) Exec_WithdrawEth(payload *x2ethereumtypes.Eth2Chain33, tx *
payload
.
ValidatorAddress
=
address
.
PubKeyToAddr
(
tx
.
Signature
.
Pubkey
)
payload
.
ValidatorAddress
=
address
.
PubKeyToAddr
(
tx
.
Signature
.
Pubkey
)
return
action
.
proc
WithdrawEth
(
payload
)
return
action
.
proc
Eth2Chain33_burn
(
payload
)
}
}
// Chain33ToEth类型的交易是Chain33侧在本端发出申请
// Chain33ToEth类型的交易是Chain33侧在本端发出申请
// 在本端锁定一定数额的token,然后在ethereum端生成相同数额的token
// 在本端锁定一定数额的token,然后在ethereum端生成相同数额的token
func
(
x
*
x2ethereum
)
Exec_Chain33ToEth
(
payload
*
x2ethereumtypes
.
Chain33ToEth
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
x
*
x2ethereum
)
Exec_Chain33ToEth
_lock
(
payload
*
x2eTy
.
Chain33ToEth
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
}
return
action
.
proc
MsgL
ock
(
payload
)
return
action
.
proc
Chain33ToEth_l
ock
(
payload
)
}
}
// 转账功能
// 转账功能
...
@@ -71,11 +74,34 @@ func (x *x2ethereum) Exec_Transfer(payload *types.AssetsTransfer, tx *types.Tran
...
@@ -71,11 +74,34 @@ func (x *x2ethereum) Exec_Transfer(payload *types.AssetsTransfer, tx *types.Tran
return
action
.
procMsgTransfer
(
payload
)
return
action
.
procMsgTransfer
(
payload
)
}
}
func
(
x
*
x2ethereum
)
Exec_TransferToExec
(
payload
*
types
.
AssetsTransferToExec
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
if
!
x2eTy
.
IsExecAddrMatch
(
payload
.
ExecName
,
tx
.
GetRealToAddr
())
{
return
nil
,
types
.
ErrToAddrNotSameToExecAddr
}
return
action
.
procMsgTransferToExec
(
payload
)
}
func
(
x
*
x2ethereum
)
Exec_WithdrawFromExec
(
payload
*
types
.
AssetsWithdraw
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
return
nil
,
errors
.
New
(
"Create Action Error"
)
}
if
dapp
.
IsDriverAddress
(
tx
.
GetRealToAddr
(),
x
.
GetHeight
())
||
x2eTy
.
IsExecAddrMatch
(
payload
.
ExecName
,
tx
.
GetRealToAddr
())
{
return
action
.
procMsgWithDrawFromExec
(
payload
)
}
return
nil
,
errors
.
New
(
"tx error"
)
}
//--------------------------合约管理员账户操作-------------------------//
//--------------------------合约管理员账户操作-------------------------//
// AddValidator是为了增加validator
// AddValidator是为了增加validator
func
(
x
*
x2ethereum
)
Exec_AddValidator
(
payload
*
x2ethereumtypes
.
MsgValidator
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
x
*
x2ethereum
)
Exec_AddValidator
(
payload
*
x2eTy
.
MsgValidator
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
err
:=
checkTxSignBySpecificAddr
(
tx
,
x2ethereumtypes
.
X2ethereumAdmin
)
confManager
:=
types
.
ConfSub
(
x
.
GetAPI
()
.
GetConfig
(),
manTy
.
ManageX
)
.
GStrList
(
"superManager"
)
err
:=
checkTxSignBySpecificAddr
(
tx
,
confManager
)
if
err
==
nil
{
if
err
==
nil
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
if
action
==
nil
{
...
@@ -87,8 +113,9 @@ func (x *x2ethereum) Exec_AddValidator(payload *x2ethereumtypes.MsgValidator, tx
...
@@ -87,8 +113,9 @@ func (x *x2ethereum) Exec_AddValidator(payload *x2ethereumtypes.MsgValidator, tx
}
}
// RemoveValidator是为了移除某一个validator
// RemoveValidator是为了移除某一个validator
func
(
x
*
x2ethereum
)
Exec_RemoveValidator
(
payload
*
x2ethereumtypes
.
MsgValidator
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
x
*
x2ethereum
)
Exec_RemoveValidator
(
payload
*
x2eTy
.
MsgValidator
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
err
:=
checkTxSignBySpecificAddr
(
tx
,
x2ethereumtypes
.
X2ethereumAdmin
)
confManager
:=
types
.
ConfSub
(
x
.
GetAPI
()
.
GetConfig
(),
manTy
.
ManageX
)
.
GStrList
(
"superManager"
)
err
:=
checkTxSignBySpecificAddr
(
tx
,
confManager
)
if
err
==
nil
{
if
err
==
nil
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
if
action
==
nil
{
...
@@ -100,8 +127,9 @@ func (x *x2ethereum) Exec_RemoveValidator(payload *x2ethereumtypes.MsgValidator,
...
@@ -100,8 +127,9 @@ func (x *x2ethereum) Exec_RemoveValidator(payload *x2ethereumtypes.MsgValidator,
}
}
// ModifyPower是为了修改某个validator的power
// ModifyPower是为了修改某个validator的power
func
(
x
*
x2ethereum
)
Exec_ModifyPower
(
payload
*
x2ethereumtypes
.
MsgValidator
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
x
*
x2ethereum
)
Exec_ModifyPower
(
payload
*
x2eTy
.
MsgValidator
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
err
:=
checkTxSignBySpecificAddr
(
tx
,
x2ethereumtypes
.
X2ethereumAdmin
)
confManager
:=
types
.
ConfSub
(
x
.
GetAPI
()
.
GetConfig
(),
manTy
.
ManageX
)
.
GStrList
(
"superManager"
)
err
:=
checkTxSignBySpecificAddr
(
tx
,
confManager
)
if
err
==
nil
{
if
err
==
nil
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
if
action
==
nil
{
...
@@ -113,8 +141,9 @@ func (x *x2ethereum) Exec_ModifyPower(payload *x2ethereumtypes.MsgValidator, tx
...
@@ -113,8 +141,9 @@ func (x *x2ethereum) Exec_ModifyPower(payload *x2ethereumtypes.MsgValidator, tx
}
}
// SetConsensusThreshold是为了修改对validator所提供的claim达成共识的阈值
// SetConsensusThreshold是为了修改对validator所提供的claim达成共识的阈值
func
(
x
*
x2ethereum
)
Exec_SetConsensusThreshold
(
payload
*
x2ethereumtypes
.
MsgConsensusThreshold
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
func
(
x
*
x2ethereum
)
Exec_SetConsensusThreshold
(
payload
*
x2eTy
.
MsgConsensusThreshold
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
err
:=
checkTxSignBySpecificAddr
(
tx
,
x2ethereumtypes
.
X2ethereumAdmin
)
confManager
:=
types
.
ConfSub
(
x
.
GetAPI
()
.
GetConfig
(),
manTy
.
ManageX
)
.
GStrList
(
"superManager"
)
err
:=
checkTxSignBySpecificAddr
(
tx
,
confManager
)
if
err
==
nil
{
if
err
==
nil
{
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
action
:=
newAction
(
x
,
tx
,
int32
(
index
))
if
action
==
nil
{
if
action
==
nil
{
...
@@ -125,11 +154,15 @@ func (x *x2ethereum) Exec_SetConsensusThreshold(payload *x2ethereumtypes.MsgCons
...
@@ -125,11 +154,15 @@ func (x *x2ethereum) Exec_SetConsensusThreshold(payload *x2ethereumtypes.MsgCons
return
nil
,
err
return
nil
,
err
}
}
func
checkTxSignBySpecificAddr
(
tx
*
types
.
Transaction
,
addr
string
)
error
{
func
checkTxSignBySpecificAddr
(
tx
*
types
.
Transaction
,
addr
s
[]
string
)
error
{
signAddr
:=
address
.
PubKeyToAddr
(
tx
.
Signature
.
Pubkey
)
signAddr
:=
address
.
PubKeyToAddr
(
tx
.
Signature
.
Pubkey
)
if
signAddr
!=
addr
{
for
_
,
addr
:=
range
addrs
{
return
x2ethereumtypes
.
ErrInvalidAdminAddress
if
signAddr
==
addr
{
continue
}
return
x2eTy
.
ErrInvalidAdminAddress
}
}
if
tx
.
CheckSign
()
==
false
{
if
tx
.
CheckSign
()
==
false
{
return
types
.
ErrSign
return
types
.
ErrSign
}
}
...
...
plugin/dapp/x2Ethereum/executor/exec_local.go
View file @
a7904920
This diff is collapsed.
Click to expand it.
plugin/dapp/x2Ethereum/executor/oracle/keeper.go
deleted
100644 → 0
View file @
10c40fd2
package
oracle
import
(
"strings"
"github.com/golang/protobuf/proto"
dbm
"github.com/33cn/chain33/common/db"
log
"github.com/33cn/chain33/common/log/log15"
types2
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
)
var
(
//日志
olog
=
log
.
New
(
"module"
,
"oracle"
)
)
type
OracleKeeper
struct
{
db
dbm
.
KV
// 通过审核的最低阈值
ConsensusThreshold
int64
}
func
NewOracleKeeper
(
db
dbm
.
KV
,
ConsensusThreshold
int64
)
*
OracleKeeper
{
if
ConsensusThreshold
<=
0
||
ConsensusThreshold
>
100
{
return
nil
}
return
&
OracleKeeper
{
db
:
db
,
ConsensusThreshold
:
ConsensusThreshold
,
}
}
func
(
k
*
OracleKeeper
)
GetProphecy
(
id
string
)
(
*
types
.
ReceiptEthProphecy
,
error
)
{
if
id
==
""
{
return
NewEmptyProphecy
(),
types
.
ErrInvalidIdentifier
}
bz
,
err
:=
k
.
db
.
Get
(
types
.
CalProphecyPrefix
(
id
))
if
err
!=
nil
&&
err
!=
types2
.
ErrNotFound
{
return
NewEmptyProphecy
(),
types
.
ErrProphecyGet
}
else
if
err
==
types2
.
ErrNotFound
{
return
NewEmptyProphecy
(),
types
.
ErrProphecyNotFound
}
var
dbProphecy
types
.
ReceiptEthProphecy
err
=
proto
.
Unmarshal
(
bz
,
&
dbProphecy
)
if
err
!=
nil
{
return
NewEmptyProphecy
(),
types2
.
ErrUnmarshal
}
return
&
dbProphecy
,
nil
}
// setProphecy saves a prophecy with an initial claim
func
(
k
*
OracleKeeper
)
setProphecy
(
prophecy
*
types
.
ReceiptEthProphecy
)
error
{
err
:=
k
.
checkProphecy
(
prophecy
)
if
err
!=
nil
{
return
err
}
bz
,
err
:=
k
.
db
.
Get
(
types
.
CalProphecyPrefix
(
prophecy
.
ID
))
if
err
!=
nil
&&
err
!=
types2
.
ErrNotFound
{
return
types
.
ErrProphecyGet
}
var
dbProphecy
types
.
ReceiptEthProphecy
if
err
!=
types2
.
ErrNotFound
{
err
=
proto
.
Unmarshal
(
bz
,
&
dbProphecy
)
if
err
!=
nil
{
return
types2
.
ErrUnmarshal
}
}
dbProphecy
=
*
prophecy
serializedProphecyBytes
,
err
:=
proto
.
Marshal
(
&
dbProphecy
)
if
err
!=
nil
{
return
types2
.
ErrMarshal
}
err
=
k
.
db
.
Set
(
types
.
CalProphecyPrefix
(
prophecy
.
ID
),
serializedProphecyBytes
)
if
err
!=
nil
{
return
types
.
ErrSetKV
}
return
nil
}
func
(
k
*
OracleKeeper
)
checkProphecy
(
prophecy
*
types
.
ReceiptEthProphecy
)
error
{
if
prophecy
.
ID
==
""
{
return
types
.
ErrInvalidIdentifier
}
if
len
(
prophecy
.
ClaimValidators
)
==
0
{
return
types
.
ErrNoClaims
}
return
nil
}
func
(
k
*
OracleKeeper
)
ProcessClaim
(
claim
types
.
OracleClaim
)
(
*
types
.
ProphecyStatus
,
error
)
{
activeValidator
:=
k
.
checkActiveValidator
(
claim
.
ValidatorAddress
)
if
!
activeValidator
{
return
nil
,
types
.
ErrInvalidValidator
}
if
strings
.
TrimSpace
(
claim
.
Content
)
==
""
{
return
nil
,
types
.
ErrInvalidClaim
}
var
claimContent
types
.
OracleClaimContent
err
:=
proto
.
Unmarshal
([]
byte
(
claim
.
Content
),
&
claimContent
)
if
err
!=
nil
{
return
nil
,
types2
.
ErrUnmarshal
}
prophecy
,
err
:=
k
.
GetProphecy
(
claim
.
ID
)
if
err
!=
nil
{
if
err
!=
types
.
ErrProphecyNotFound
{
return
nil
,
err
}
prophecy
=
NewProphecy
(
claim
.
ID
)
}
else
{
var
exist
bool
for
_
,
vc
:=
range
prophecy
.
ValidatorClaims
{
if
vc
.
Claim
==
claim
.
Content
{
exist
=
true
}
}
if
!
exist
{
prophecy
.
Status
.
Text
=
types
.
EthBridgeStatus_FailedStatusText
return
nil
,
types
.
ErrClaimInconsist
}
if
prophecy
.
Status
.
Text
==
types
.
EthBridgeStatus_FailedStatusText
{
return
nil
,
types
.
ErrProphecyFinalized
}
for
_
,
vc
:=
range
prophecy
.
ValidatorClaims
{
if
vc
.
Validator
==
claim
.
ValidatorAddress
&&
vc
.
Claim
!=
""
{
return
nil
,
types
.
ErrDuplicateMessage
}
}
}
AddClaim
(
prophecy
,
claim
.
ValidatorAddress
,
claim
.
Content
)
prophecy
,
err
=
k
.
processCompletion
(
prophecy
,
claimContent
.
ClaimType
)
if
err
!=
nil
{
return
nil
,
err
}
err
=
k
.
setProphecy
(
prophecy
)
if
err
!=
nil
{
return
nil
,
err
}
return
prophecy
.
Status
,
nil
}
func
(
k
*
OracleKeeper
)
checkActiveValidator
(
validatorAddress
string
)
bool
{
validatorMap
,
err
:=
k
.
GetValidatorArray
()
if
err
!=
nil
{
return
false
}
for
_
,
v
:=
range
validatorMap
.
Validators
{
if
v
.
Address
==
validatorAddress
{
return
true
}
}
return
false
}
// 计算该prophecy是否达标
func
(
k
*
OracleKeeper
)
processCompletion
(
prophecy
*
types
.
ReceiptEthProphecy
,
claimType
int64
)
(
*
types
.
ReceiptEthProphecy
,
error
)
{
address2power
:=
make
(
map
[
string
]
int64
)
validatorArrays
,
err
:=
k
.
GetValidatorArray
()
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
validator
:=
range
validatorArrays
.
Validators
{
address2power
[
validator
.
Address
]
=
validator
.
Power
}
highestClaim
,
highestClaimPower
,
totalClaimsPower
:=
FindHighestClaim
(
prophecy
,
address2power
)
totalPower
,
err
:=
k
.
GetLastTotalPower
()
if
err
!=
nil
{
return
nil
,
err
}
highestConsensusRatio
:=
highestClaimPower
*
100
remainingPossibleClaimPower
:=
totalPower
-
totalClaimsPower
highestPossibleClaimPower
:=
highestClaimPower
+
remainingPossibleClaimPower
highestPossibleConsensusRatio
:=
highestPossibleClaimPower
*
100
olog
.
Info
(
"processCompletion"
,
"highestConsensusRatio"
,
highestConsensusRatio
/
totalPower
,
"ConsensusThreshold"
,
k
.
ConsensusThreshold
,
"highestPossibleConsensusRatio"
,
highestPossibleConsensusRatio
/
totalPower
)
if
highestConsensusRatio
>=
k
.
ConsensusThreshold
*
totalPower
{
prophecy
.
Status
.
Text
=
types
.
EthBridgeStatus_SuccessStatusText
prophecy
.
Status
.
FinalClaim
=
highestClaim
}
else
if
highestPossibleConsensusRatio
<
k
.
ConsensusThreshold
*
totalPower
{
prophecy
.
Status
.
Text
=
types
.
EthBridgeStatus_FailedStatusText
}
return
prophecy
,
nil
}
// Load the last total validator power.
func
(
k
*
OracleKeeper
)
GetLastTotalPower
()
(
int64
,
error
)
{
b
,
err
:=
k
.
db
.
Get
(
types
.
CalLastTotalPowerPrefix
())
if
err
!=
nil
&&
err
!=
types2
.
ErrNotFound
{
return
0
,
err
}
else
if
err
==
types2
.
ErrNotFound
{
return
0
,
nil
}
var
powers
types
.
ReceiptQueryTotalPower
err
=
proto
.
Unmarshal
(
b
,
&
powers
)
if
err
!=
nil
{
return
0
,
types2
.
ErrUnmarshal
}
return
powers
.
TotalPower
,
nil
}
// Set the last total validator power.
func
(
k
*
OracleKeeper
)
SetLastTotalPower
()
error
{
var
totalPower
int64
validatorArrays
,
err
:=
k
.
GetValidatorArray
()
if
err
!=
nil
{
return
err
}
for
_
,
validator
:=
range
validatorArrays
.
Validators
{
totalPower
+=
validator
.
Power
}
totalP
:=
types
.
ReceiptQueryTotalPower
{
TotalPower
:
totalPower
,
}
totalPBytes
,
_
:=
proto
.
Marshal
(
&
totalP
)
err
=
k
.
db
.
Set
(
types
.
CalLastTotalPowerPrefix
(),
totalPBytes
)
if
err
!=
nil
{
return
types
.
ErrSetKV
}
return
nil
}
func
(
k
*
OracleKeeper
)
GetValidatorArray
()
(
*
types
.
ValidatorList
,
error
)
{
validatorsBytes
,
err
:=
k
.
db
.
Get
(
types
.
CalValidatorMapsPrefix
())
if
err
!=
nil
{
return
nil
,
err
}
var
validatorArrays
types
.
ValidatorList
err
=
proto
.
Unmarshal
(
validatorsBytes
,
&
validatorArrays
)
if
err
!=
nil
{
return
nil
,
types2
.
ErrUnmarshal
}
return
&
validatorArrays
,
nil
}
func
(
k
*
OracleKeeper
)
SetConsensusThreshold
(
ConsensusThreshold
int64
)
{
k
.
ConsensusThreshold
=
ConsensusThreshold
olog
.
Info
(
"SetConsensusNeeded"
,
"nowConsensusNeeded"
,
k
.
ConsensusThreshold
)
return
}
func
(
k
*
OracleKeeper
)
GetConsensusThreshold
()
int64
{
return
k
.
ConsensusThreshold
}
plugin/dapp/x2Ethereum/executor/oracle/prophecy.go
deleted
100644 → 0
View file @
10c40fd2
package
oracle
import
(
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
)
func
NewProphecy
(
id
string
)
*
types
.
ReceiptEthProphecy
{
status
:=
new
(
types
.
ProphecyStatus
)
status
.
Text
=
types
.
EthBridgeStatus_PendingStatusText
return
&
types
.
ReceiptEthProphecy
{
ID
:
id
,
Status
:
status
,
ClaimValidators
:
*
new
([]
*
types
.
ClaimValidators
),
ValidatorClaims
:
*
new
([]
*
types
.
ValidatorClaims
),
}
}
func
NewEmptyProphecy
()
*
types
.
ReceiptEthProphecy
{
return
NewProphecy
(
""
)
}
//
//type DBProphecy struct {
// ID string `json:"id"`
// Status Status `json:"status"`
// ClaimValidators []byte `json:"claim_validators"`
// ValidatorClaims []byte `json:"validator_claims"`
//}
//
//// SerializeForDB serializes a prophecy into a DBProphecy
//func (prophecy Prophecy) SerializeForDB() (DBProphecy, error) {
// claimValidators, err := json.Marshal(prophecy.ClaimValidators)
// if err != nil {
// return DBProphecy{}, err
// }
//
// validatorClaims, err := json.Marshal(prophecy.ValidatorClaims)
// if err != nil {
// return DBProphecy{}, err
// }
//
// return DBProphecy{
// ID: prophecy.ID,
// Status: prophecy.Status,
// ClaimValidators: claimValidators,
// ValidatorClaims: validatorClaims,
// }, nil
//}
//
//// DeserializeFromDB deserializes a DBProphecy into a prophecy
//func (dbProphecy DBProphecy) DeserializeFromDB() (Prophecy, error) {
// claimValidators := new([]*types.ClaimValidators)
// err := json.Unmarshal(dbProphecy.ClaimValidators, &claimValidators)
// if err != nil {
// return Prophecy{}, err
// }
//
// validatorClaims := new([]*types.ValidatorClaims)
// err = json.Unmarshal(dbProphecy.ValidatorClaims, &validatorClaims)
// if err != nil {
// return Prophecy{}, err
// }
//
// return Prophecy{
// ID: dbProphecy.ID,
// Status: dbProphecy.Status,
// ClaimValidators: *claimValidators,
// ValidatorClaims: *validatorClaims,
// }, nil
//}
// AddClaim adds a given claim to this prophecy
func
AddClaim
(
prophecy
*
types
.
ReceiptEthProphecy
,
validator
string
,
claim
string
)
{
claimValidators
:=
new
(
types
.
StringMap
)
if
len
(
prophecy
.
ClaimValidators
)
==
0
{
prophecy
.
ClaimValidators
=
append
(
prophecy
.
ClaimValidators
,
&
types
.
ClaimValidators
{
Claim
:
claim
,
Validators
:
&
types
.
StringMap
{
Validators
:
[]
string
{
validator
},
},
})
}
else
{
for
index
,
cv
:=
range
prophecy
.
ClaimValidators
{
if
cv
.
Claim
==
claim
{
claimValidators
=
cv
.
Validators
prophecy
.
ClaimValidators
[
index
]
.
Validators
=
types
.
AddToStringMap
(
claimValidators
,
validator
)
break
}
}
}
//todo
// validator不可能相同?
//if len(prophecy.ValidatorClaims) == 0 {
// prophecy.ValidatorClaims = append(prophecy.ValidatorClaims, &types.ValidatorClaims{
// Validator: validator,
// Claim: claim,
// })
//} else {
// for index, vc := range prophecy.ValidatorClaims {
// if vc.Validator == validator {
// prophecy.ValidatorClaims[index].Claim = claim
// break
// } else {
// prophecy.ValidatorClaims = append(prophecy.ValidatorClaims, &types.ValidatorClaims{
// Validator: validator,
// Claim: claim,
// })
// }
// }
//}
prophecy
.
ValidatorClaims
=
append
(
prophecy
.
ValidatorClaims
,
&
types
.
ValidatorClaims
{
Validator
:
validator
,
Claim
:
claim
,
})
}
// 遍历该prophecy所有claim,找出获得最多票数的claim
func
FindHighestClaim
(
prophecy
*
types
.
ReceiptEthProphecy
,
validators
map
[
string
]
int64
)
(
string
,
int64
,
int64
)
{
totalClaimsPower
:=
int64
(
0
)
highestClaimPower
:=
int64
(
-
1
)
highestClaim
:=
""
for
_
,
claimValidators
:=
range
prophecy
.
ClaimValidators
{
claimPower
:=
int64
(
0
)
for
_
,
validatorAddr
:=
range
claimValidators
.
Validators
.
Validators
{
validatorPower
:=
validators
[
validatorAddr
]
claimPower
+=
validatorPower
}
totalClaimsPower
+=
claimPower
if
claimPower
>
highestClaimPower
{
highestClaimPower
=
claimPower
highestClaim
=
claimValidators
.
Claim
}
}
return
highestClaim
,
highestClaimPower
,
totalClaimsPower
}
plugin/dapp/x2Ethereum/executor/prophecy.go
0 → 100644
View file @
a7904920
package
executor
import
(
"errors"
"fmt"
"github.com/33cn/chain33/types"
x2eTy
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
"strconv"
)
func
NewProphecy
(
id
string
)
*
x2eTy
.
ReceiptEthProphecy
{
status
:=
new
(
x2eTy
.
ProphecyStatus
)
status
.
Text
=
x2eTy
.
EthBridgeStatus_PendingStatusText
return
&
x2eTy
.
ReceiptEthProphecy
{
ID
:
id
,
Status
:
status
,
ClaimValidators
:
*
new
([]
*
x2eTy
.
ClaimValidators
),
ValidatorClaims
:
*
new
([]
*
x2eTy
.
ValidatorClaims
),
}
}
// AddClaim adds a given claim to this prophecy
func
AddClaim
(
prophecy
*
x2eTy
.
ReceiptEthProphecy
,
validator
string
,
claim
string
)
{
claimValidators
:=
new
(
x2eTy
.
StringMap
)
if
len
(
prophecy
.
ClaimValidators
)
==
0
{
prophecy
.
ClaimValidators
=
append
(
prophecy
.
ClaimValidators
,
&
x2eTy
.
ClaimValidators
{
Claim
:
claim
,
Validators
:
&
x2eTy
.
StringMap
{
Validators
:
[]
string
{
validator
},
},
})
}
else
{
for
index
,
cv
:=
range
prophecy
.
ClaimValidators
{
if
cv
.
Claim
==
claim
{
claimValidators
=
cv
.
Validators
prophecy
.
ClaimValidators
[
index
]
.
Validators
=
x2eTy
.
AddToStringMap
(
claimValidators
,
validator
)
break
}
}
}
prophecy
.
ValidatorClaims
=
append
(
prophecy
.
ValidatorClaims
,
&
x2eTy
.
ValidatorClaims
{
Validator
:
validator
,
Claim
:
claim
,
})
}
// 遍历该prophecy所有claim,找出获得最多票数的claim
func
FindHighestClaim
(
prophecy
*
x2eTy
.
ReceiptEthProphecy
,
validators
map
[
string
]
int64
)
(
string
,
int64
,
int64
)
{
totalClaimsPower
:=
int64
(
0
)
highestClaimPower
:=
int64
(
-
1
)
highestClaim
:=
""
for
_
,
claimValidators
:=
range
prophecy
.
ClaimValidators
{
claimPower
:=
int64
(
0
)
for
_
,
validatorAddr
:=
range
claimValidators
.
Validators
.
Validators
{
validatorPower
:=
validators
[
validatorAddr
]
claimPower
+=
validatorPower
}
totalClaimsPower
+=
claimPower
if
claimPower
>
highestClaimPower
{
highestClaimPower
=
claimPower
highestClaim
=
claimValidators
.
Claim
}
}
return
highestClaim
,
highestClaimPower
,
totalClaimsPower
}
func
NewOracleClaimContent
(
chain33Receiver
string
,
amount
string
,
claimType
,
decimals
int64
)
x2eTy
.
OracleClaimContent
{
return
x2eTy
.
OracleClaimContent
{
Chain33Receiver
:
chain33Receiver
,
Amount
:
amount
,
ClaimType
:
claimType
,
Decimals
:
decimals
,
}
}
func
NewClaim
(
id
string
,
validatorAddress
string
,
content
string
)
x2eTy
.
OracleClaim
{
return
x2eTy
.
OracleClaim
{
ID
:
id
,
ValidatorAddress
:
validatorAddress
,
Content
:
content
,
}
}
//通过ethchain33结构构造一个OracleClaim结构,包括生成唯一的ID
func
CreateOracleClaimFromEthClaim
(
ethClaim
x2eTy
.
Eth2Chain33
)
(
x2eTy
.
OracleClaim
,
error
)
{
if
ethClaim
.
ClaimType
!=
int64
(
x2eTy
.
LOCK_CLAIM_TYPE
)
&&
ethClaim
.
ClaimType
!=
int64
(
x2eTy
.
BURN_CLAIM_TYPE
)
{
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
.
LOCK_CLAIM_TYPE
)
{
oracleID
=
oracleID
+
"lock"
}
else
if
ethClaim
.
ClaimType
==
int64
(
x2eTy
.
BURN_CLAIM_TYPE
)
{
oracleID
=
oracleID
+
"burn"
}
claimContent
:=
NewOracleClaimContent
(
ethClaim
.
Chain33Receiver
,
ethClaim
.
Amount
,
ethClaim
.
ClaimType
,
ethClaim
.
Decimals
)
claimBytes
:=
types
.
Encode
(
&
claimContent
)
claimString
:=
string
(
claimBytes
)
claim
:=
NewClaim
(
oracleID
,
ethClaim
.
ValidatorAddress
,
claimString
)
return
claim
,
nil
}
func
CreateOracleClaimFromOracleString
(
oracleClaimString
string
)
(
x2eTy
.
OracleClaimContent
,
error
)
{
var
oracleClaimContent
x2eTy
.
OracleClaimContent
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
oracleClaimContent
,
nil
}
plugin/dapp/x2Ethereum/executor/query.go
View file @
a7904920
...
@@ -4,25 +4,23 @@ import (
...
@@ -4,25 +4,23 @@ import (
"strconv"
"strconv"
"strings"
"strings"
"github.com/golang/protobuf/proto"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
types2
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
x2eTy
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
)
)
func
(
x
*
x2ethereum
)
Query_GetEthProphecy
(
in
*
types2
.
QueryEthProphecyParams
)
(
types
.
Message
,
error
)
{
func
(
x
*
x2ethereum
)
Query_GetEthProphecy
(
in
*
x2eTy
.
QueryEthProphecyParams
)
(
types
.
Message
,
error
)
{
prophecyKey
:=
types2
.
CalProphecyPrefix
(
in
.
ID
)
prophecyKey
:=
x2eTy
.
CalProphecyPrefix
(
in
.
ID
)
var
dbProphecy
types2
.
ReceiptEthProphecy
var
dbProphecy
x2eTy
.
ReceiptEthProphecy
val
,
err
:=
x
.
GetStateDB
()
.
Get
(
prophecyKey
)
val
,
err
:=
x
.
GetStateDB
()
.
Get
(
prophecyKey
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
err
=
proto
.
Unmarshal
(
val
,
&
dbProphecy
)
err
=
types
.
Decode
(
val
,
&
dbProphecy
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
types
.
ErrUnmarshal
return
nil
,
types
.
ErrUnmarshal
}
}
...
@@ -30,28 +28,28 @@ func (x *x2ethereum) Query_GetEthProphecy(in *types2.QueryEthProphecyParams) (ty
...
@@ -30,28 +28,28 @@ func (x *x2ethereum) Query_GetEthProphecy(in *types2.QueryEthProphecyParams) (ty
return
&
dbProphecy
,
nil
return
&
dbProphecy
,
nil
}
}
func
(
x
*
x2ethereum
)
Query_GetValidators
(
in
*
types2
.
QueryValidatorsParams
)
(
types
.
Message
,
error
)
{
func
(
x
*
x2ethereum
)
Query_GetValidators
(
in
*
x2eTy
.
QueryValidatorsParams
)
(
types
.
Message
,
error
)
{
validatorsKey
:=
types2
.
CalValidatorMapsPrefix
()
validatorsKey
:=
x2eTy
.
CalValidatorMapsPrefix
()
var
v
types2
.
ValidatorList
var
v
x2eTy
.
ValidatorList
vBytes
,
err
:=
x
.
GetStateDB
()
.
Get
(
validatorsKey
)
vBytes
,
err
:=
x
.
GetStateDB
()
.
Get
(
validatorsKey
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"Query_GetValidators"
,
"GetValidators Err"
,
err
)
elog
.
Error
(
"Query_GetValidators"
,
"GetValidators Err"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
err
=
proto
.
Unmarshal
(
vBytes
,
&
v
)
err
=
types
.
Decode
(
vBytes
,
&
v
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
types
.
ErrUnmarshal
return
nil
,
types
.
ErrUnmarshal
}
}
if
in
.
Validator
!=
""
{
if
in
.
Validator
!=
""
{
validatorsRes
:=
new
(
types2
.
ReceiptQueryValidator
)
validatorsRes
:=
new
(
x2eTy
.
ReceiptQueryValidator
)
for
_
,
vv
:=
range
v
.
Validators
{
for
_
,
vv
:=
range
v
.
Validators
{
if
vv
.
Address
==
in
.
Validator
{
if
vv
.
Address
==
in
.
Validator
{
val
:=
make
([]
*
types2
.
MsgValidator
,
1
)
val
:=
make
([]
*
x2eTy
.
MsgValidator
,
1
)
val
[
0
]
=
vv
val
[
0
]
=
vv
validatorsRes
=
&
types2
.
ReceiptQueryValidator
{
validatorsRes
=
&
x2eTy
.
ReceiptQueryValidator
{
Validators
:
val
,
Validators
:
val
,
TotalPower
:
vv
.
Power
,
TotalPower
:
vv
.
Power
,
}
}
...
@@ -59,9 +57,9 @@ func (x *x2ethereum) Query_GetValidators(in *types2.QueryValidatorsParams) (type
...
@@ -59,9 +57,9 @@ func (x *x2ethereum) Query_GetValidators(in *types2.QueryValidatorsParams) (type
}
}
}
}
// 未知的地址
// 未知的地址
return
nil
,
types2
.
ErrInvalidValidator
return
nil
,
x2eTy
.
ErrInvalidValidator
}
else
{
}
else
{
validatorsRes
:=
new
(
types2
.
ReceiptQueryValidator
)
validatorsRes
:=
new
(
x2eTy
.
ReceiptQueryValidator
)
var
totalPower
int64
var
totalPower
int64
for
_
,
vv
:=
range
v
.
Validators
{
for
_
,
vv
:=
range
v
.
Validators
{
totalPower
+=
vv
.
Power
totalPower
+=
vv
.
Power
...
@@ -72,44 +70,44 @@ func (x *x2ethereum) Query_GetValidators(in *types2.QueryValidatorsParams) (type
...
@@ -72,44 +70,44 @@ func (x *x2ethereum) Query_GetValidators(in *types2.QueryValidatorsParams) (type
}
}
}
}
func
(
x
*
x2ethereum
)
Query_GetTotalPower
(
in
*
types2
.
QueryTotalPowerParams
)
(
types
.
Message
,
error
)
{
func
(
x
*
x2ethereum
)
Query_GetTotalPower
(
in
*
x2eTy
.
QueryTotalPowerParams
)
(
types
.
Message
,
error
)
{
totalPower
:=
&
types2
.
ReceiptQueryTotalPower
{}
totalPower
:=
&
x2eTy
.
ReceiptQueryTotalPower
{}
totalPowerKey
:=
types2
.
CalLastTotalPowerPrefix
()
totalPowerKey
:=
x2eTy
.
CalLastTotalPowerPrefix
()
totalPowerBytes
,
err
:=
x
.
GetStateDB
()
.
Get
(
totalPowerKey
)
totalPowerBytes
,
err
:=
x
.
GetStateDB
()
.
Get
(
totalPowerKey
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"Query_GetTotalPower"
,
"GetTotalPower Err"
,
err
)
elog
.
Error
(
"Query_GetTotalPower"
,
"GetTotalPower Err"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
err
=
proto
.
Unmarshal
(
totalPowerBytes
,
totalPower
)
err
=
types
.
Decode
(
totalPowerBytes
,
totalPower
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
types
.
ErrUnmarshal
return
nil
,
types
.
ErrUnmarshal
}
}
return
totalPower
,
nil
return
totalPower
,
nil
}
}
func
(
x
*
x2ethereum
)
Query_GetConsensusThreshold
(
in
*
types2
.
QueryConsensusThresholdParams
)
(
types
.
Message
,
error
)
{
func
(
x
*
x2ethereum
)
Query_GetConsensusThreshold
(
in
*
x2eTy
.
QueryConsensusThresholdParams
)
(
types
.
Message
,
error
)
{
consensus
:=
&
types2
.
ReceiptQueryConsensusThreshold
{}
consensus
:=
&
x2eTy
.
ReceiptQueryConsensusThreshold
{}
consensusKey
:=
types2
.
CalConsensusThresholdPrefix
()
consensusKey
:=
x2eTy
.
CalConsensusThresholdPrefix
()
consensusBytes
,
err
:=
x
.
GetStateDB
()
.
Get
(
consensusKey
)
consensusBytes
,
err
:=
x
.
GetStateDB
()
.
Get
(
consensusKey
)
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"Query_GetConsensusNeeded"
,
"GetConsensusNeeded Err"
,
err
)
elog
.
Error
(
"Query_GetConsensusNeeded"
,
"GetConsensusNeeded Err"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
err
=
proto
.
Unmarshal
(
consensusBytes
,
consensus
)
err
=
types
.
Decode
(
consensusBytes
,
consensus
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
types
.
ErrUnmarshal
return
nil
,
types
.
ErrUnmarshal
}
}
return
consensus
,
nil
return
consensus
,
nil
}
}
func
(
x
*
x2ethereum
)
Query_GetSymbolTotalAmountByTxType
(
in
*
types2
.
QuerySymbolAssetsByTxTypeParams
)
(
types
.
Message
,
error
)
{
func
(
x
*
x2ethereum
)
Query_GetSymbolTotalAmountByTxType
(
in
*
x2eTy
.
QuerySymbolAssetsByTxTypeParams
)
(
types
.
Message
,
error
)
{
symbolAmount
:=
&
types2
.
ReceiptQuerySymbolAssets
{}
symbolAmount
:=
&
x2eTy
.
ReceiptQuerySymbolAssets
{}
if
in
.
TokenAddr
!=
""
{
if
in
.
TokenAddr
!=
""
{
var
r
types2
.
ReceiptQuerySymbolAssetsByTxType
var
r
x2eTy
.
ReceiptQuerySymbolAssetsByTxType
symbolAmountKey
:=
types2
.
CalTokenSymbolTotalLockOrBurnAmount
(
in
.
TokenSymbol
,
in
.
TokenAddr
,
types2
.
DirectionType
[
in
.
Direction
],
in
.
TxType
)
symbolAmountKey
:=
x2eTy
.
CalTokenSymbolTotalLockOrBurnAmount
(
in
.
TokenSymbol
,
in
.
TokenAddr
,
x2eTy
.
DirectionType
[
in
.
Direction
],
in
.
TxType
)
totalAmountBytes
,
err
:=
x
.
GetLocalDB
()
.
Get
(
symbolAmountKey
)
totalAmountBytes
,
err
:=
x
.
GetLocalDB
()
.
Get
(
symbolAmountKey
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -121,23 +119,23 @@ func (x *x2ethereum) Query_GetSymbolTotalAmountByTxType(in *types2.QuerySymbolAs
...
@@ -121,23 +119,23 @@ func (x *x2ethereum) Query_GetSymbolTotalAmountByTxType(in *types2.QuerySymbolAs
return
nil
,
types
.
ErrUnmarshal
return
nil
,
types
.
ErrUnmarshal
}
}
r
.
TotalAmount
=
types2
.
TrimZeroAndDot
(
strconv
.
FormatFloat
(
types2
.
Toeth
(
r
.
TotalAmount
,
in
.
Decimal
),
'f'
,
4
,
64
))
r
.
TotalAmount
=
x2eTy
.
TrimZeroAndDot
(
strconv
.
FormatFloat
(
x2eTy
.
Toeth
(
r
.
TotalAmount
,
in
.
Decimal
),
'f'
,
4
,
64
))
symbolAmount
.
Res
=
append
(
symbolAmount
.
Res
,
&
r
)
symbolAmount
.
Res
=
append
(
symbolAmount
.
Res
,
&
r
)
}
else
{
}
else
{
tokenAddressesBytes
,
err
:=
x
.
GetLocalDB
()
.
Get
(
types2
.
CalTokenSymbolToTokenAddress
(
in
.
TokenSymbol
))
tokenAddressesBytes
,
err
:=
x
.
GetLocalDB
()
.
Get
(
x2eTy
.
CalTokenSymbolToTokenAddress
(
in
.
TokenSymbol
))
if
err
!=
nil
&&
err
!=
types
.
ErrNotFound
{
if
err
!=
nil
&&
err
!=
types
.
ErrNotFound
{
return
nil
,
err
return
nil
,
err
}
}
var
tokenAddresses
types2
.
ReceiptTokenToTokenAddress
var
tokenAddresses
x2eTy
.
ReceiptTokenToTokenAddress
err
=
types
.
Decode
(
tokenAddressesBytes
,
&
tokenAddresses
)
err
=
types
.
Decode
(
tokenAddressesBytes
,
&
tokenAddresses
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
for
_
,
addr
:=
range
tokenAddresses
.
TokenAddress
{
for
_
,
addr
:=
range
tokenAddresses
.
TokenAddress
{
var
r
types2
.
ReceiptQuerySymbolAssetsByTxType
var
r
x2eTy
.
ReceiptQuerySymbolAssetsByTxType
symbolAmountKey
:=
types2
.
CalTokenSymbolTotalLockOrBurnAmount
(
in
.
TokenSymbol
,
addr
,
types2
.
DirectionType
[
in
.
Direction
],
in
.
TxType
)
symbolAmountKey
:=
x2eTy
.
CalTokenSymbolTotalLockOrBurnAmount
(
in
.
TokenSymbol
,
addr
,
x2eTy
.
DirectionType
[
in
.
Direction
],
in
.
TxType
)
totalAmountBytes
,
err
:=
x
.
GetLocalDB
()
.
Get
(
symbolAmountKey
)
totalAmountBytes
,
err
:=
x
.
GetLocalDB
()
.
Get
(
symbolAmountKey
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -149,7 +147,7 @@ func (x *x2ethereum) Query_GetSymbolTotalAmountByTxType(in *types2.QuerySymbolAs
...
@@ -149,7 +147,7 @@ func (x *x2ethereum) Query_GetSymbolTotalAmountByTxType(in *types2.QuerySymbolAs
return
nil
,
types
.
ErrUnmarshal
return
nil
,
types
.
ErrUnmarshal
}
}
r
.
TotalAmount
=
types2
.
TrimZeroAndDot
(
strconv
.
FormatFloat
(
types2
.
Toeth
(
r
.
TotalAmount
,
in
.
Decimal
),
'f'
,
4
,
64
))
r
.
TotalAmount
=
x2eTy
.
TrimZeroAndDot
(
strconv
.
FormatFloat
(
x2eTy
.
Toeth
(
r
.
TotalAmount
,
in
.
Decimal
),
'f'
,
4
,
64
))
symbolAmount
.
Res
=
append
(
symbolAmount
.
Res
,
&
r
)
symbolAmount
.
Res
=
append
(
symbolAmount
.
Res
,
&
r
)
}
}
...
@@ -158,46 +156,46 @@ func (x *x2ethereum) Query_GetSymbolTotalAmountByTxType(in *types2.QuerySymbolAs
...
@@ -158,46 +156,46 @@ func (x *x2ethereum) Query_GetSymbolTotalAmountByTxType(in *types2.QuerySymbolAs
return
symbolAmount
,
nil
return
symbolAmount
,
nil
}
}
func
(
x
*
x2ethereum
)
Query_GetRelayerBalance
(
in
*
types2
.
QueryRelayerBalance
)
(
types
.
Message
,
error
)
{
func
(
x
*
x2ethereum
)
Query_GetRelayerBalance
(
in
*
x2eTy
.
QueryRelayerBalance
)
(
types
.
Message
,
error
)
{
symbolAmount
:=
&
types2
.
ReceiptQueryRelayerBalance
{}
symbolAmount
:=
&
x2eTy
.
ReceiptQueryRelayerBalance
{}
// 要查询特定的tokenAddr
// 要查询特定的tokenAddr
if
in
.
TokenAddr
!=
""
{
if
in
.
TokenAddr
!=
""
{
accDB
,
err
:=
account
.
NewAccountDB
(
x
.
GetAPI
()
.
GetConfig
(),
types2
.
X2ethereumX
,
strings
.
ToLower
(
in
.
TokenSymbol
+
in
.
TokenAddr
),
x
.
GetStateDB
())
accDB
,
err
:=
account
.
NewAccountDB
(
x
.
GetAPI
()
.
GetConfig
(),
x2eTy
.
X2ethereumX
,
strings
.
ToLower
(
in
.
TokenSymbol
+
in
.
TokenAddr
),
x
.
GetStateDB
())
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
acc
:=
accDB
.
LoadExecAccount
(
in
.
Address
,
address
.
ExecAddress
(
types2
.
X2ethereumX
))
acc
:=
accDB
.
LoadExecAccount
(
in
.
Address
,
address
.
ExecAddress
(
x2eTy
.
X2ethereumX
))
res
:=
new
(
types2
.
ReceiptQueryRelayerBalanceForOneToken
)
res
:=
new
(
x2eTy
.
ReceiptQueryRelayerBalanceForOneToken
)
res
.
TokenAddr
=
in
.
TokenAddr
res
.
TokenAddr
=
in
.
TokenAddr
res
.
TokenSymbol
=
in
.
TokenSymbol
res
.
TokenSymbol
=
in
.
TokenSymbol
res
.
Balance
=
types2
.
TrimZeroAndDot
(
strconv
.
FormatFloat
(
float64
(
acc
.
Balance
)
/
1e8
,
'f'
,
4
,
64
))
res
.
Balance
=
x2eTy
.
TrimZeroAndDot
(
strconv
.
FormatFloat
(
float64
(
acc
.
Balance
)
/
1e8
,
'f'
,
4
,
64
))
symbolAmount
.
Res
=
append
(
symbolAmount
.
Res
,
res
)
symbolAmount
.
Res
=
append
(
symbolAmount
.
Res
,
res
)
}
else
{
}
else
{
tokenAddressesBytes
,
err
:=
x
.
GetLocalDB
()
.
Get
(
types2
.
CalTokenSymbolToTokenAddress
(
in
.
TokenSymbol
))
tokenAddressesBytes
,
err
:=
x
.
GetLocalDB
()
.
Get
(
x2eTy
.
CalTokenSymbolToTokenAddress
(
in
.
TokenSymbol
))
if
err
!=
nil
&&
err
!=
types
.
ErrNotFound
{
if
err
!=
nil
&&
err
!=
types
.
ErrNotFound
{
return
nil
,
err
return
nil
,
err
}
}
var
tokenAddresses
types2
.
ReceiptTokenToTokenAddress
var
tokenAddresses
x2eTy
.
ReceiptTokenToTokenAddress
err
=
types
.
Decode
(
tokenAddressesBytes
,
&
tokenAddresses
)
err
=
types
.
Decode
(
tokenAddressesBytes
,
&
tokenAddresses
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
for
_
,
addr
:=
range
tokenAddresses
.
TokenAddress
{
for
_
,
addr
:=
range
tokenAddresses
.
TokenAddress
{
accDB
,
err
:=
account
.
NewAccountDB
(
x
.
GetAPI
()
.
GetConfig
(),
types2
.
X2ethereumX
,
strings
.
ToLower
(
in
.
TokenSymbol
+
addr
),
x
.
GetStateDB
())
accDB
,
err
:=
account
.
NewAccountDB
(
x
.
GetAPI
()
.
GetConfig
(),
x2eTy
.
X2ethereumX
,
strings
.
ToLower
(
in
.
TokenSymbol
+
addr
),
x
.
GetStateDB
())
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
acc
:=
accDB
.
LoadExecAccount
(
in
.
Address
,
address
.
ExecAddress
(
types2
.
X2ethereumX
))
acc
:=
accDB
.
LoadExecAccount
(
in
.
Address
,
address
.
ExecAddress
(
x2eTy
.
X2ethereumX
))
res
:=
new
(
types2
.
ReceiptQueryRelayerBalanceForOneToken
)
res
:=
new
(
x2eTy
.
ReceiptQueryRelayerBalanceForOneToken
)
res
.
TokenAddr
=
addr
res
.
TokenAddr
=
addr
res
.
TokenSymbol
=
in
.
TokenSymbol
res
.
TokenSymbol
=
in
.
TokenSymbol
res
.
Balance
=
types2
.
TrimZeroAndDot
(
strconv
.
FormatFloat
(
float64
(
acc
.
Balance
)
/
1e8
,
'f'
,
4
,
64
))
res
.
Balance
=
x2eTy
.
TrimZeroAndDot
(
strconv
.
FormatFloat
(
float64
(
acc
.
Balance
)
/
1e8
,
'f'
,
4
,
64
))
symbolAmount
.
Res
=
append
(
symbolAmount
.
Res
,
res
)
symbolAmount
.
Res
=
append
(
symbolAmount
.
Res
,
res
)
}
}
}
}
...
...
plugin/dapp/x2Ethereum/executor/x2ethereum.go
View file @
a7904920
...
@@ -4,7 +4,7 @@ import (
...
@@ -4,7 +4,7 @@ import (
log
"github.com/33cn/chain33/common/log/log15"
log
"github.com/33cn/chain33/common/log/log15"
drivers
"github.com/33cn/chain33/system/dapp"
drivers
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
x2e
thereumtypes
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
x2e
Ty
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
)
)
/*
/*
...
@@ -17,7 +17,7 @@ var (
...
@@ -17,7 +17,7 @@ var (
elog
=
log
.
New
(
"module"
,
"x2ethereum.executor"
)
elog
=
log
.
New
(
"module"
,
"x2ethereum.executor"
)
)
)
var
driverName
=
x2e
thereumtypes
.
X2ethereumX
var
driverName
=
x2e
Ty
.
X2ethereumX
// Init register dapp
// Init register dapp
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
...
...
plugin/dapp/x2Ethereum/executor/x2ethereumaction.go
View file @
a7904920
This diff is collapsed.
Click to expand it.
plugin/dapp/x2Ethereum/executor/x2ethereumdb.go
0 → 100644
View file @
a7904920
This diff is collapsed.
Click to expand it.
plugin/dapp/x2Ethereum/proto/x2ethereum.proto
View file @
a7904920
...
@@ -21,8 +21,10 @@ message X2ethereumAction {
...
@@ -21,8 +21,10 @@ message X2ethereumAction {
MsgValidator
modifyPower
=
7
;
MsgValidator
modifyPower
=
7
;
MsgConsensusThreshold
setConsensusThreshold
=
8
;
MsgConsensusThreshold
setConsensusThreshold
=
8
;
AssetsTransfer
transfer
=
9
;
AssetsTransfer
transfer
=
9
;
AssetsTransferToExec
transferToExec
=
10
;
AssetsWithdraw
withdraw
=
11
;
}
}
int32
ty
=
1
0
;
int32
ty
=
1
2
;
}
}
message
MsgConsensusThreshold
{
message
MsgConsensusThreshold
{
...
@@ -39,8 +41,7 @@ message Eth2Chain33 {
...
@@ -39,8 +41,7 @@ message Eth2Chain33 {
int64
EthereumChainID
=
1
;
int64
EthereumChainID
=
1
;
string
BridgeContractAddress
=
2
;
string
BridgeContractAddress
=
2
;
int64
Nonce
=
3
;
int64
Nonce
=
3
;
string
localCoinSymbol
=
4
;
string
IssuerDotSymbol
=
4
;
string
localCoinExec
=
5
;
string
TokenContractAddress
=
6
;
string
TokenContractAddress
=
6
;
string
EthereumSender
=
7
;
string
EthereumSender
=
7
;
string
Chain33Receiver
=
8
;
string
Chain33Receiver
=
8
;
...
@@ -64,8 +65,7 @@ message Chain33ToEth {
...
@@ -64,8 +65,7 @@ message Chain33ToEth {
string
Chain33Sender
=
2
;
string
Chain33Sender
=
2
;
string
EthereumReceiver
=
3
;
string
EthereumReceiver
=
3
;
string
Amount
=
4
;
string
Amount
=
4
;
string
localCoinSymbol
=
5
;
string
IssuerDotSymbol
=
5
;
string
localCoinExec
=
6
;
int64
Decimals
=
7
;
int64
Decimals
=
7
;
}
}
...
@@ -74,9 +74,8 @@ message ReceiptEth2Chain33 {
...
@@ -74,9 +74,8 @@ message ReceiptEth2Chain33 {
int64
EthereumChainID
=
1
;
int64
EthereumChainID
=
1
;
string
BridgeContractAddress
=
2
;
string
BridgeContractAddress
=
2
;
int64
Nonce
=
3
;
int64
Nonce
=
3
;
string
localCoinSymbol
=
4
;
string
IssuerDotSymbol
=
4
;
string
localCoinExec
=
5
;
string
TokenAddress
=
5
;
string
TokenContractAddress
=
6
;
string
EthereumSender
=
7
;
string
EthereumSender
=
7
;
string
Chain33Receiver
=
8
;
string
Chain33Receiver
=
8
;
string
ValidatorAddress
=
9
;
string
ValidatorAddress
=
9
;
...
@@ -93,7 +92,7 @@ message ReceiptChain33ToEth {
...
@@ -93,7 +92,7 @@ message ReceiptChain33ToEth {
string
Chain33Sender
=
2
;
string
Chain33Sender
=
2
;
string
EthereumReceiver
=
3
;
string
EthereumReceiver
=
3
;
string
Amount
=
4
;
string
Amount
=
4
;
string
Eth
Symbol
=
5
;
string
IssuerDot
Symbol
=
5
;
int64
Decimals
=
6
;
int64
Decimals
=
6
;
}
}
...
...
plugin/dapp/x2Ethereum/types/const.go
View file @
a7904920
...
@@ -27,6 +27,8 @@ const (
...
@@ -27,6 +27,8 @@ const (
TySetConsensusThresholdLog
TySetConsensusThresholdLog
TyProphecyLog
TyProphecyLog
TyTransferLog
TyTransferLog
TyTransferToExecLog
TyWithdrawFromExecLog
)
)
// action类型id和name,这些常量可以自定义修改
// action类型id和name,这些常量可以自定义修改
...
@@ -41,20 +43,22 @@ const (
...
@@ -41,20 +43,22 @@ const (
TyModifyPowerAction
TyModifyPowerAction
TySetConsensusThresholdAction
TySetConsensusThresholdAction
TyTransferAction
TyTransferAction
TyTransferToExecAction
TyWithdrawFromExecAction
NameEth2Chain33Action
=
"Eth2Chain33"
NameEth2Chain33Action
=
"Eth2Chain33
_lock
"
NameWithdrawEthAction
=
"
WithdrawEth
"
NameWithdrawEthAction
=
"
Eth2Chain33_burn
"
NameWithdrawChain33Action
=
"
WithdrawChain33
"
NameWithdrawChain33Action
=
"
Chain33ToEth_burn
"
NameChain33ToEthAction
=
"Chain33ToEth"
NameChain33ToEthAction
=
"Chain33ToEth
_lock
"
NameAddValidatorAction
=
"AddValidator"
NameAddValidatorAction
=
"AddValidator"
NameRemoveValidatorAction
=
"RemoveValidator"
NameRemoveValidatorAction
=
"RemoveValidator"
NameModifyPowerAction
=
"ModifyPower"
NameModifyPowerAction
=
"ModifyPower"
NameSetConsensusThresholdAction
=
"SetConsensusThreshold"
NameSetConsensusThresholdAction
=
"SetConsensusThreshold"
NameTransferAction
=
"Transfer"
NameTransferAction
=
"Transfer"
NameTransferToExecAction
=
"TransferToExec"
NameWithdrawFromExecAction
=
"WithdrawFromExec"
)
)
const
ModuleName
=
"ETH"
const
DefaultConsensusNeeded
=
int64
(
70
)
const
DefaultConsensusNeeded
=
int64
(
70
)
const
(
const
(
...
@@ -76,9 +80,6 @@ const (
...
@@ -76,9 +80,6 @@ const (
FuncQueryRelayerBalance
=
"GetRelayerBalance"
FuncQueryRelayerBalance
=
"GetRelayerBalance"
)
)
//设置合约管理员地址
const
X2ethereumAdmin
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
const
(
const
(
LOCK_CLAIM_TYPE
=
int32
(
1
)
LOCK_CLAIM_TYPE
=
int32
(
1
)
BURN_CLAIM_TYPE
=
int32
(
2
)
BURN_CLAIM_TYPE
=
int32
(
2
)
...
...
plugin/dapp/x2Ethereum/types/oracle.pb.go
View file @
a7904920
...
@@ -5,9 +5,8 @@ package types
...
@@ -5,9 +5,8 @@ package types
import
(
import
(
fmt
"fmt"
fmt
"fmt"
math
"math"
proto
"github.com/golang/protobuf/proto"
proto
"github.com/golang/protobuf/proto"
math
"math"
)
)
// Reference imports to suppress errors if they are not otherwise used.
// Reference imports to suppress errors if they are not otherwise used.
...
...
plugin/dapp/x2Ethereum/types/utils.go
View file @
a7904920
...
@@ -2,7 +2,9 @@ package types
...
@@ -2,7 +2,9 @@ package types
import
(
import
(
"encoding/binary"
"encoding/binary"
"errors"
"fmt"
"fmt"
"github.com/33cn/chain33/common/address"
"math"
"math"
"math/big"
"math/big"
"strings"
"strings"
...
@@ -102,3 +104,16 @@ func CheckPower(power int64) bool {
...
@@ -102,3 +104,16 @@ func CheckPower(power int64) bool {
}
}
return
true
return
true
}
}
func
DivideDot
(
in
string
)
(
left
,
right
string
,
err
error
)
{
if
strings
.
Contains
(
in
,
"."
)
{
ss
:=
strings
.
Split
(
in
,
"."
)
return
ss
[
0
],
ss
[
1
],
nil
}
return
""
,
""
,
errors
.
New
(
"Divide error"
)
}
func
IsExecAddrMatch
(
name
string
,
to
string
)
bool
{
toaddr
:=
address
.
ExecAddress
(
name
)
return
toaddr
==
to
}
plugin/dapp/x2Ethereum/types/x2ethereum.go
View file @
a7904920
...
@@ -27,6 +27,8 @@ var (
...
@@ -27,6 +27,8 @@ var (
NameModifyPowerAction
:
TyModifyPowerAction
,
NameModifyPowerAction
:
TyModifyPowerAction
,
NameSetConsensusThresholdAction
:
TySetConsensusThresholdAction
,
NameSetConsensusThresholdAction
:
TySetConsensusThresholdAction
,
NameTransferAction
:
TyTransferAction
,
NameTransferAction
:
TyTransferAction
,
NameTransferToExecAction
:
TyTransferToExecAction
,
NameWithdrawFromExecAction
:
TyWithdrawFromExecAction
,
}
}
//定义log的id和具体log类型及名称,填入具体自定义log类型
//定义log的id和具体log类型及名称,填入具体自定义log类型
logMap
=
map
[
int64
]
*
types
.
LogInfo
{
logMap
=
map
[
int64
]
*
types
.
LogInfo
{
...
@@ -40,6 +42,8 @@ var (
...
@@ -40,6 +42,8 @@ var (
TySetConsensusThresholdLog
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptSetConsensusThreshold
{}),
Name
:
"LogSetConsensusThreshold"
},
TySetConsensusThresholdLog
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptSetConsensusThreshold
{}),
Name
:
"LogSetConsensusThreshold"
},
TyProphecyLog
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptEthProphecy
{}),
Name
:
"LogEthProphecy"
},
TyProphecyLog
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptEthProphecy
{}),
Name
:
"LogEthProphecy"
},
TyTransferLog
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogTransfer"
},
TyTransferLog
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptAccountTransfer
{}),
Name
:
"LogTransfer"
},
TyTransferToExecLog
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptExecAccountTransfer
{}),
Name
:
"LogTokenExecTransfer"
},
TyWithdrawFromExecLog
:
{
Ty
:
reflect
.
TypeOf
(
types
.
ReceiptExecAccountTransfer
{}),
Name
:
"LogTokenExecWithdraw"
},
}
}
tlog
=
log
.
New
(
"module"
,
"x2ethereum.types"
)
tlog
=
log
.
New
(
"module"
,
"x2ethereum.types"
)
)
)
...
@@ -106,13 +110,13 @@ func (x x2ethereumType) ActionName(tx *types.Transaction) string {
...
@@ -106,13 +110,13 @@ func (x x2ethereumType) ActionName(tx *types.Transaction) string {
// GetActionName get action name
// GetActionName get action name
func
(
action
*
X2EthereumAction
)
GetActionName
()
string
{
func
(
action
*
X2EthereumAction
)
GetActionName
()
string
{
if
action
.
Ty
==
TyEth2Chain33Action
&&
action
.
GetEth2Chain33
()
!=
nil
{
if
action
.
Ty
==
TyEth2Chain33Action
&&
action
.
GetEth2Chain33
()
!=
nil
{
return
"Eth2Chain33"
return
"Eth2Chain33
_lock
"
}
else
if
action
.
Ty
==
TyWithdrawEthAction
&&
action
.
GetWithdrawEth
()
!=
nil
{
}
else
if
action
.
Ty
==
TyWithdrawEthAction
&&
action
.
GetWithdrawEth
()
!=
nil
{
return
"
WithdrawEth
"
return
"
Eth2Chain33_burn
"
}
else
if
action
.
Ty
==
TyWithdrawChain33Action
&&
action
.
GetWithdrawChain33
()
!=
nil
{
}
else
if
action
.
Ty
==
TyWithdrawChain33Action
&&
action
.
GetWithdrawChain33
()
!=
nil
{
return
"
WithdrawChain33
"
return
"
Chain33ToEth_burn
"
}
else
if
action
.
Ty
==
TyChain33ToEthAction
&&
action
.
GetChain33ToEth
()
!=
nil
{
}
else
if
action
.
Ty
==
TyChain33ToEthAction
&&
action
.
GetChain33ToEth
()
!=
nil
{
return
"Chain33ToEth"
return
"Chain33ToEth
_lock
"
}
else
if
action
.
Ty
==
TyAddValidatorAction
&&
action
.
GetAddValidator
()
!=
nil
{
}
else
if
action
.
Ty
==
TyAddValidatorAction
&&
action
.
GetAddValidator
()
!=
nil
{
return
"AddValidator"
return
"AddValidator"
}
else
if
action
.
Ty
==
TyRemoveValidatorAction
&&
action
.
GetRemoveValidator
()
!=
nil
{
}
else
if
action
.
Ty
==
TyRemoveValidatorAction
&&
action
.
GetRemoveValidator
()
!=
nil
{
...
@@ -121,6 +125,12 @@ func (action *X2EthereumAction) GetActionName() string {
...
@@ -121,6 +125,12 @@ func (action *X2EthereumAction) GetActionName() string {
return
"ModifyPower"
return
"ModifyPower"
}
else
if
action
.
Ty
==
TySetConsensusThresholdAction
&&
action
.
GetSetConsensusThreshold
()
!=
nil
{
}
else
if
action
.
Ty
==
TySetConsensusThresholdAction
&&
action
.
GetSetConsensusThreshold
()
!=
nil
{
return
"SetConsensusThreshold"
return
"SetConsensusThreshold"
}
else
if
action
.
Ty
==
TyTransferAction
&&
action
.
GetTransfer
()
!=
nil
{
return
"Transfer"
}
else
if
action
.
Ty
==
TyTransferToExecAction
&&
action
.
GetTransferToExec
()
!=
nil
{
return
"TransferToExec"
}
else
if
action
.
Ty
==
TyWithdrawFromExecAction
&&
action
.
GetWithdraw
()
!=
nil
{
return
"WithdrawFromExec"
}
}
return
"unknown-x2ethereum"
return
"unknown-x2ethereum"
}
}
plugin/dapp/x2Ethereum/types/x2ethereum.pb.go
View file @
a7904920
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment