Commit a7904920 authored by whisker's avatar whisker

refactor contract code

parent 10c40fd2
...@@ -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)),
LocalCoinSymbol: csymbol, IssuerDotSymbol: 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),
LocalCoinSymbol: csymbol, IssuerDotSymbol: 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{
......
...@@ -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 {
......
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
}
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
}
...@@ -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"
x2ethereumtypes "github.com/33cn/plugin/plugin/dapp/x2Ethereum/types" x2eTy "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.procMsgEth2Chain33(payload) return action.procEth2Chain33_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.procMsgBurn(payload) return action.procChain33ToEth_burn(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.procWithdrawEth(payload) return action.procEth2Chain33_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.procMsgLock(payload) return action.procChain33ToEth_lock(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, addrs []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
} }
......
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"strconv" "strconv"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
x2ethereumtypes "github.com/33cn/plugin/plugin/dapp/x2Ethereum/types" x2eTy "github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
) )
/* /*
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
* 非关键数据,本地存储(localDB), 用于辅助查询,效率高 * 非关键数据,本地存储(localDB), 用于辅助查询,效率高
*/ */
func (x *x2ethereum) ExecLocal_Eth2Chain33(payload *x2ethereumtypes.Eth2Chain33, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (x *x2ethereum) ExecLocal_Eth2Chain33_lock(payload *x2eTy.Eth2Chain33, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set, err := x.execLocal(receiptData) set, err := x.execLocal(receiptData)
if err != nil { if err != nil {
return set, err return set, err
...@@ -20,7 +20,7 @@ func (x *x2ethereum) ExecLocal_Eth2Chain33(payload *x2ethereumtypes.Eth2Chain33, ...@@ -20,7 +20,7 @@ func (x *x2ethereum) ExecLocal_Eth2Chain33(payload *x2ethereumtypes.Eth2Chain33,
return x.addAutoRollBack(tx, set.KV), nil return x.addAutoRollBack(tx, set.KV), nil
} }
func (x *x2ethereum) ExecLocal_WithdrawEth(payload *x2ethereumtypes.Eth2Chain33, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (x *x2ethereum) ExecLocal_Eth2Chain33_burn(payload *x2eTy.Eth2Chain33, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set, err := x.execLocal(receiptData) set, err := x.execLocal(receiptData)
if err != nil { if err != nil {
return set, err return set, err
...@@ -28,7 +28,7 @@ func (x *x2ethereum) ExecLocal_WithdrawEth(payload *x2ethereumtypes.Eth2Chain33, ...@@ -28,7 +28,7 @@ func (x *x2ethereum) ExecLocal_WithdrawEth(payload *x2ethereumtypes.Eth2Chain33,
return x.addAutoRollBack(tx, set.KV), nil return x.addAutoRollBack(tx, set.KV), nil
} }
func (x *x2ethereum) ExecLocal_WithdrawChain33(payload *x2ethereumtypes.Chain33ToEth, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (x *x2ethereum) ExecLocal_Chain33ToEth_burn(payload *x2eTy.Chain33ToEth, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set, err := x.execLocal(receiptData) set, err := x.execLocal(receiptData)
if err != nil { if err != nil {
return set, err return set, err
...@@ -36,7 +36,7 @@ func (x *x2ethereum) ExecLocal_WithdrawChain33(payload *x2ethereumtypes.Chain33T ...@@ -36,7 +36,7 @@ func (x *x2ethereum) ExecLocal_WithdrawChain33(payload *x2ethereumtypes.Chain33T
return x.addAutoRollBack(tx, set.KV), nil return x.addAutoRollBack(tx, set.KV), nil
} }
func (x *x2ethereum) ExecLocal_Chain33ToEth(payload *x2ethereumtypes.Chain33ToEth, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (x *x2ethereum) ExecLocal_Chain33ToEth_lock(payload *x2eTy.Chain33ToEth, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
set, err := x.execLocal(receiptData) set, err := x.execLocal(receiptData)
if err != nil { if err != nil {
return set, err return set, err
...@@ -44,25 +44,25 @@ func (x *x2ethereum) ExecLocal_Chain33ToEth(payload *x2ethereumtypes.Chain33ToEt ...@@ -44,25 +44,25 @@ func (x *x2ethereum) ExecLocal_Chain33ToEth(payload *x2ethereumtypes.Chain33ToEt
return x.addAutoRollBack(tx, set.KV), nil return x.addAutoRollBack(tx, set.KV), nil
} }
func (x *x2ethereum) ExecLocal_AddValidator(payload *x2ethereumtypes.MsgValidator, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (x *x2ethereum) ExecLocal_AddValidator(payload *x2eTy.MsgValidator, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
//implement code //implement code
return x.addAutoRollBack(tx, dbSet.KV), nil return x.addAutoRollBack(tx, dbSet.KV), nil
} }
func (x *x2ethereum) ExecLocal_RemoveValidator(payload *x2ethereumtypes.MsgValidator, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (x *x2ethereum) ExecLocal_RemoveValidator(payload *x2eTy.MsgValidator, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
//implement code //implement code
return x.addAutoRollBack(tx, dbSet.KV), nil return x.addAutoRollBack(tx, dbSet.KV), nil
} }
func (x *x2ethereum) ExecLocal_ModifyPower(payload *x2ethereumtypes.MsgValidator, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (x *x2ethereum) ExecLocal_ModifyPower(payload *x2eTy.MsgValidator, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
//implement code //implement code
return x.addAutoRollBack(tx, dbSet.KV), nil return x.addAutoRollBack(tx, dbSet.KV), nil
} }
func (x *x2ethereum) ExecLocal_SetConsensusThreshold(payload *x2ethereumtypes.MsgConsensusThreshold, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (x *x2ethereum) ExecLocal_SetConsensusThreshold(payload *x2eTy.MsgConsensusThreshold, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
//implement code //implement code
return x.addAutoRollBack(tx, dbSet.KV), nil return x.addAutoRollBack(tx, dbSet.KV), nil
...@@ -79,145 +79,145 @@ func (x *x2ethereum) execLocal(receiptData *types.ReceiptData) (*types.LocalDBSe ...@@ -79,145 +79,145 @@ func (x *x2ethereum) execLocal(receiptData *types.ReceiptData) (*types.LocalDBSe
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
for _, log := range receiptData.Logs { for _, log := range receiptData.Logs {
switch log.Ty { switch log.Ty {
case x2ethereumtypes.TyEth2Chain33Log: case x2eTy.TyEth2Chain33Log:
var receiptEth2Chain33 x2ethereumtypes.ReceiptEth2Chain33 var receiptEth2Chain33 x2eTy.ReceiptEth2Chain33
err := types.Decode(log.Log, &receiptEth2Chain33) err := types.Decode(log.Log, &receiptEth2Chain33)
if err != nil { if err != nil {
return nil, err return nil, err
} }
nb, err := x.GetLocalDB().Get(x2ethereumtypes.CalTokenSymbolTotalLockOrBurnAmount(receiptEth2Chain33.LocalCoinSymbol, receiptEth2Chain33.TokenContractAddress, x2ethereumtypes.DirEth2Chain33, "lock")) nb, err := x.GetLocalDB().Get(x2eTy.CalTokenSymbolTotalLockOrBurnAmount(receiptEth2Chain33.IssuerDotSymbol, receiptEth2Chain33.TokenAddress, x2eTy.DirEth2Chain33, "lock"))
if err != nil && err != types.ErrNotFound { if err != nil && err != types.ErrNotFound {
return nil, err return nil, err
} }
var now x2ethereumtypes.ReceiptQuerySymbolAssetsByTxType var now x2eTy.ReceiptQuerySymbolAssetsByTxType
err = types.Decode(nb, &now) err = types.Decode(nb, &now)
if err != nil { if err != nil {
return nil, err return nil, err
} }
preAmount, _ := strconv.ParseFloat(x2ethereumtypes.TrimZeroAndDot(now.TotalAmount), 64) preAmount, _ := strconv.ParseFloat(x2eTy.TrimZeroAndDot(now.TotalAmount), 64)
nowAmount, _ := strconv.ParseFloat(x2ethereumtypes.TrimZeroAndDot(receiptEth2Chain33.Amount), 64) nowAmount, _ := strconv.ParseFloat(x2eTy.TrimZeroAndDot(receiptEth2Chain33.Amount), 64)
TokenAssetsByTxTypeBytes := types.Encode(&x2ethereumtypes.ReceiptQuerySymbolAssetsByTxType{ TokenAssetsByTxTypeBytes := types.Encode(&x2eTy.ReceiptQuerySymbolAssetsByTxType{
TokenSymbol: receiptEth2Chain33.LocalCoinSymbol, TokenSymbol: receiptEth2Chain33.IssuerDotSymbol,
TxType: "lock", TxType: "lock",
TotalAmount: strconv.FormatFloat(preAmount+nowAmount, 'f', 4, 64), TotalAmount: strconv.FormatFloat(preAmount+nowAmount, 'f', 4, 64),
Direction: 1, Direction: 1,
}) })
dbSet.KV = append(dbSet.KV, &types.KeyValue{ dbSet.KV = append(dbSet.KV, &types.KeyValue{
Key: x2ethereumtypes.CalTokenSymbolTotalLockOrBurnAmount(receiptEth2Chain33.LocalCoinSymbol, receiptEth2Chain33.TokenContractAddress, x2ethereumtypes.DirEth2Chain33, "lock"), Key: x2eTy.CalTokenSymbolTotalLockOrBurnAmount(receiptEth2Chain33.IssuerDotSymbol, receiptEth2Chain33.TokenAddress, x2eTy.DirEth2Chain33, "lock"),
Value: TokenAssetsByTxTypeBytes, Value: TokenAssetsByTxTypeBytes,
}) })
nb, err = x.GetLocalDB().Get(x2ethereumtypes.CalTokenSymbolToTokenAddress(receiptEth2Chain33.LocalCoinSymbol)) nb, err = x.GetLocalDB().Get(x2eTy.CalTokenSymbolToTokenAddress(receiptEth2Chain33.IssuerDotSymbol))
if err != nil && err != types.ErrNotFound { if err != nil && err != types.ErrNotFound {
return nil, err return nil, err
} }
var t x2ethereumtypes.ReceiptTokenToTokenAddress var t x2eTy.ReceiptTokenToTokenAddress
err = types.Decode(nb, &t) err = types.Decode(nb, &t)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var exist bool var exist bool
for _, addr := range t.TokenAddress { for _, addr := range t.TokenAddress {
if addr == receiptEth2Chain33.TokenContractAddress { if addr == receiptEth2Chain33.TokenAddress {
exist = true exist = true
} }
} }
if !exist { if !exist {
t.TokenAddress = append(t.TokenAddress, receiptEth2Chain33.TokenContractAddress) t.TokenAddress = append(t.TokenAddress, receiptEth2Chain33.TokenAddress)
} }
TokenToTokenAddressBytes := types.Encode(&x2ethereumtypes.ReceiptTokenToTokenAddress{ TokenToTokenAddressBytes := types.Encode(&x2eTy.ReceiptTokenToTokenAddress{
TokenAddress: t.TokenAddress, TokenAddress: t.TokenAddress,
}) })
dbSet.KV = append(dbSet.KV, &types.KeyValue{ dbSet.KV = append(dbSet.KV, &types.KeyValue{
Key: x2ethereumtypes.CalTokenSymbolToTokenAddress(receiptEth2Chain33.LocalCoinSymbol), Key: x2eTy.CalTokenSymbolToTokenAddress(receiptEth2Chain33.IssuerDotSymbol),
Value: TokenToTokenAddressBytes, Value: TokenToTokenAddressBytes,
}) })
case x2ethereumtypes.TyWithdrawEthLog: case x2eTy.TyWithdrawEthLog:
var receiptEth2Chain33 x2ethereumtypes.ReceiptEth2Chain33 var receiptEth2Chain33 x2eTy.ReceiptEth2Chain33
err := types.Decode(log.Log, &receiptEth2Chain33) err := types.Decode(log.Log, &receiptEth2Chain33)
if err != nil { if err != nil {
return nil, err return nil, err
} }
nb, err := x.GetLocalDB().Get(x2ethereumtypes.CalTokenSymbolTotalLockOrBurnAmount(receiptEth2Chain33.LocalCoinSymbol, receiptEth2Chain33.TokenContractAddress, x2ethereumtypes.DirEth2Chain33, "withdraw")) nb, err := x.GetLocalDB().Get(x2eTy.CalTokenSymbolTotalLockOrBurnAmount(receiptEth2Chain33.IssuerDotSymbol, receiptEth2Chain33.TokenAddress, x2eTy.DirEth2Chain33, "withdraw"))
if err != nil && err != types.ErrNotFound { if err != nil && err != types.ErrNotFound {
return nil, err return nil, err
} }
var now x2ethereumtypes.ReceiptQuerySymbolAssetsByTxType var now x2eTy.ReceiptQuerySymbolAssetsByTxType
err = types.Decode(nb, &now) err = types.Decode(nb, &now)
if err != nil { if err != nil {
return nil, err return nil, err
} }
preAmount, _ := strconv.ParseFloat(x2ethereumtypes.TrimZeroAndDot(now.TotalAmount), 64) preAmount, _ := strconv.ParseFloat(x2eTy.TrimZeroAndDot(now.TotalAmount), 64)
nowAmount, _ := strconv.ParseFloat(x2ethereumtypes.TrimZeroAndDot(receiptEth2Chain33.Amount), 64) nowAmount, _ := strconv.ParseFloat(x2eTy.TrimZeroAndDot(receiptEth2Chain33.Amount), 64)
TokenAssetsByTxTypeBytes := types.Encode(&x2ethereumtypes.ReceiptQuerySymbolAssetsByTxType{ TokenAssetsByTxTypeBytes := types.Encode(&x2eTy.ReceiptQuerySymbolAssetsByTxType{
TokenSymbol: receiptEth2Chain33.LocalCoinSymbol, TokenSymbol: receiptEth2Chain33.IssuerDotSymbol,
TxType: "withdraw", TxType: "withdraw",
TotalAmount: strconv.FormatFloat(preAmount+nowAmount, 'f', 4, 64), TotalAmount: strconv.FormatFloat(preAmount+nowAmount, 'f', 4, 64),
Direction: 2, Direction: 2,
}) })
dbSet.KV = append(dbSet.KV, &types.KeyValue{ dbSet.KV = append(dbSet.KV, &types.KeyValue{
Key: x2ethereumtypes.CalTokenSymbolTotalLockOrBurnAmount(receiptEth2Chain33.LocalCoinSymbol, receiptEth2Chain33.TokenContractAddress, x2ethereumtypes.DirEth2Chain33, "withdraw"), Key: x2eTy.CalTokenSymbolTotalLockOrBurnAmount(receiptEth2Chain33.IssuerDotSymbol, receiptEth2Chain33.TokenAddress, x2eTy.DirEth2Chain33, "withdraw"),
Value: TokenAssetsByTxTypeBytes, Value: TokenAssetsByTxTypeBytes,
}) })
case x2ethereumtypes.TyChain33ToEthLog: case x2eTy.TyChain33ToEthLog:
var receiptChain33ToEth x2ethereumtypes.ReceiptChain33ToEth var receiptChain33ToEth x2eTy.ReceiptChain33ToEth
err := types.Decode(log.Log, &receiptChain33ToEth) err := types.Decode(log.Log, &receiptChain33ToEth)
if err != nil { if err != nil {
return nil, err return nil, err
} }
nb, err := x.GetLocalDB().Get(x2ethereumtypes.CalTokenSymbolTotalLockOrBurnAmount(receiptChain33ToEth.EthSymbol, receiptChain33ToEth.TokenContract, x2ethereumtypes.DirChain33ToEth, "lock")) nb, err := x.GetLocalDB().Get(x2eTy.CalTokenSymbolTotalLockOrBurnAmount(receiptChain33ToEth.IssuerDotSymbol, receiptChain33ToEth.TokenContract, x2eTy.DirChain33ToEth, "lock"))
if err != nil && err != types.ErrNotFound { if err != nil && err != types.ErrNotFound {
return nil, err return nil, err
} }
var now x2ethereumtypes.ReceiptQuerySymbolAssetsByTxType var now x2eTy.ReceiptQuerySymbolAssetsByTxType
err = types.Decode(nb, &now) err = types.Decode(nb, &now)
if err != nil { if err != nil {
return nil, err return nil, err
} }
preAmount, _ := strconv.ParseFloat(x2ethereumtypes.TrimZeroAndDot(now.TotalAmount), 64) preAmount, _ := strconv.ParseFloat(x2eTy.TrimZeroAndDot(now.TotalAmount), 64)
nowAmount, _ := strconv.ParseFloat(x2ethereumtypes.TrimZeroAndDot(receiptChain33ToEth.Amount), 64) nowAmount, _ := strconv.ParseFloat(x2eTy.TrimZeroAndDot(receiptChain33ToEth.Amount), 64)
TokenAssetsByTxTypeBytes := types.Encode(&x2ethereumtypes.ReceiptQuerySymbolAssetsByTxType{ TokenAssetsByTxTypeBytes := types.Encode(&x2eTy.ReceiptQuerySymbolAssetsByTxType{
TokenSymbol: receiptChain33ToEth.EthSymbol, TokenSymbol: receiptChain33ToEth.IssuerDotSymbol,
TxType: "lock", TxType: "lock",
TotalAmount: strconv.FormatFloat(preAmount+nowAmount, 'f', 4, 64), TotalAmount: strconv.FormatFloat(preAmount+nowAmount, 'f', 4, 64),
Direction: 1, Direction: 1,
}) })
dbSet.KV = append(dbSet.KV, &types.KeyValue{ dbSet.KV = append(dbSet.KV, &types.KeyValue{
Key: x2ethereumtypes.CalTokenSymbolTotalLockOrBurnAmount(receiptChain33ToEth.EthSymbol, receiptChain33ToEth.TokenContract, x2ethereumtypes.DirChain33ToEth, "lock"), Key: x2eTy.CalTokenSymbolTotalLockOrBurnAmount(receiptChain33ToEth.IssuerDotSymbol, receiptChain33ToEth.TokenContract, x2eTy.DirChain33ToEth, "lock"),
Value: TokenAssetsByTxTypeBytes, Value: TokenAssetsByTxTypeBytes,
}) })
case x2ethereumtypes.TyWithdrawChain33Log: case x2eTy.TyWithdrawChain33Log:
var receiptChain33ToEth x2ethereumtypes.ReceiptChain33ToEth var receiptChain33ToEth x2eTy.ReceiptChain33ToEth
err := types.Decode(log.Log, &receiptChain33ToEth) err := types.Decode(log.Log, &receiptChain33ToEth)
if err != nil { if err != nil {
return nil, err return nil, err
} }
nb, err := x.GetLocalDB().Get(x2ethereumtypes.CalTokenSymbolTotalLockOrBurnAmount(receiptChain33ToEth.EthSymbol, receiptChain33ToEth.TokenContract, x2ethereumtypes.DirChain33ToEth, "withdraw")) nb, err := x.GetLocalDB().Get(x2eTy.CalTokenSymbolTotalLockOrBurnAmount(receiptChain33ToEth.IssuerDotSymbol, receiptChain33ToEth.TokenContract, x2eTy.DirChain33ToEth, "withdraw"))
if err != nil && err != types.ErrNotFound { if err != nil && err != types.ErrNotFound {
return nil, err return nil, err
} }
var now x2ethereumtypes.ReceiptQuerySymbolAssetsByTxType var now x2eTy.ReceiptQuerySymbolAssetsByTxType
err = types.Decode(nb, &now) err = types.Decode(nb, &now)
if err != nil { if err != nil {
return nil, err return nil, err
} }
preAmount, _ := strconv.ParseFloat(x2ethereumtypes.TrimZeroAndDot(now.TotalAmount), 64) preAmount, _ := strconv.ParseFloat(x2eTy.TrimZeroAndDot(now.TotalAmount), 64)
nowAmount, _ := strconv.ParseFloat(x2ethereumtypes.TrimZeroAndDot(receiptChain33ToEth.Amount), 64) nowAmount, _ := strconv.ParseFloat(x2eTy.TrimZeroAndDot(receiptChain33ToEth.Amount), 64)
TokenAssetsByTxTypeBytes := types.Encode(&x2ethereumtypes.ReceiptQuerySymbolAssetsByTxType{ TokenAssetsByTxTypeBytes := types.Encode(&x2eTy.ReceiptQuerySymbolAssetsByTxType{
TokenSymbol: receiptChain33ToEth.EthSymbol, TokenSymbol: receiptChain33ToEth.IssuerDotSymbol,
TxType: "withdraw", TxType: "withdraw",
TotalAmount: strconv.FormatFloat(preAmount+nowAmount, 'f', 4, 64), TotalAmount: strconv.FormatFloat(preAmount+nowAmount, 'f', 4, 64),
Direction: 2, Direction: 2,
}) })
dbSet.KV = append(dbSet.KV, &types.KeyValue{ dbSet.KV = append(dbSet.KV, &types.KeyValue{
Key: x2ethereumtypes.CalTokenSymbolTotalLockOrBurnAmount(receiptChain33ToEth.EthSymbol, receiptChain33ToEth.TokenContract, x2ethereumtypes.DirChain33ToEth, "withdraw"), Key: x2eTy.CalTokenSymbolTotalLockOrBurnAmount(receiptChain33ToEth.IssuerDotSymbol, receiptChain33ToEth.TokenContract, x2eTy.DirChain33ToEth, "withdraw"),
Value: TokenAssetsByTxTypeBytes, Value: TokenAssetsByTxTypeBytes,
}) })
default: default:
......
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
}
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
}
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
}
...@@ -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)
} }
} }
......
...@@ -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"
x2ethereumtypes "github.com/33cn/plugin/plugin/dapp/x2Ethereum/types" x2eTy "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 = x2ethereumtypes.X2ethereumX var driverName = x2eTy.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) {
......
...@@ -4,49 +4,15 @@ import ( ...@@ -4,49 +4,15 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/golang/protobuf/proto"
"github.com/33cn/chain33/account" "github.com/33cn/chain33/account"
"github.com/33cn/chain33/client" "github.com/33cn/chain33/client"
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
dbm "github.com/33cn/chain33/common/db" dbm "github.com/33cn/chain33/common/db"
chain33types "github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/executor/ethbridge" x2eTy "github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
"github.com/33cn/plugin/plugin/dapp/x2Ethereum/executor/oracle"
types2 "github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
// stateDB存储KV:
// CalProphecyPrefix --> DBProphecy
// CalEth2Chain33Prefix -- > Eth2Chain33
// CalWithdrawEthPrefix -- > Eth2Chain33
// CalWithdrawChain33Prefix -- > Chain33ToEth
// CalChain33ToEthPrefix -- > Chain33ToEth
// CalValidatorMapsPrefix -- > MsgValidator maps
// CalLastTotalPowerPrefix -- > ReceiptQueryTotalPower
// CalConsensusThresholdPrefix -- > ReceiptSetConsensusThreshold
// CalTokenSymbolTotalAmountPrefix -- > ReceiptQuerySymbolAssets
// 当前存在一个问题:
// token的发行需要提前授权,所以账户模型该如何设计?
//
// 解决方案:
// 当eth-->chain33时,采用 mavl-x2ethereum-symbol的账户模型,但是这样的资产是无法提现的,是一个完全虚拟的资产
// 而在chain33-->eth时,采用 mavl-coins-bty 的账户模型(后续可以升级为mavl-token-symbol以支持多个token资产)
// token 合约转币到x2ethereum合约
// 个人账户地址 = mavl-token-symbol-execAddr:aliceAddr
// 不同币种账户地址 = mavl-token-symbol-execAddr
// eth -- > chain33:
// 在 mavl-token-symbol-execAddr 上铸币,然后转到 mavl-token-symbol-execAddr:addr 上
// withdraw 的时候先从mavl-coins-symbol-execAddr:addr 中withdraw到 mavl-token-symbol-execAddr,然后 burn
// chain33 -- > eth:
// 在 mavl-token-symbol-execAddr:addr 上withdraw到 mavl-token-symbol-execAddr 上,然后frozen住
// withdraw 的时候从 mavl-token-symbol-execAddr 上 deposit mavl-token-symbol-execAddr:addr
type action struct { type action struct {
api client.QueueProtocolAPI api client.QueueProtocolAPI
coinsAccount *account.DB coinsAccount *account.DB
...@@ -57,61 +23,28 @@ type action struct { ...@@ -57,61 +23,28 @@ type action struct {
height int64 height int64
index int32 index int32
execaddr string execaddr string
keeper ethbridge.Keeper oracle *Oracle
} }
func newAction(a *x2ethereum, tx *chain33types.Transaction, index int32) *action { func newAction(a *x2ethereum, tx *types.Transaction, index int32) *action {
hash := tx.Hash() hash := tx.Hash()
fromaddr := tx.From() fromaddr := tx.From()
oracleKeeper := oracle.NewOracleKeeper(a.GetStateDB(), types2.DefaultConsensusNeeded)
if oracleKeeper == nil {
return nil
}
elog.Info("newAction", "newAction", "done")
return &action{a.GetAPI(), a.GetCoinsAccount(), a.GetStateDB(), hash, fromaddr, 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())} a.GetBlockTime(), a.GetHeight(), index, address.ExecAddress(string(tx.Execer)), NewOracle(a.GetStateDB(), x2eTy.DefaultConsensusNeeded)}
} }
// ethereum ---> chain33 // ethereum ---> chain33
// lock // lock
func (a *action) procMsgEth2Chain33(ethBridgeClaim *types2.Eth2Chain33) (*chain33types.Receipt, error) { func (a *action) procEth2Chain33_lock(ethBridgeClaim *x2eTy.Eth2Chain33) (*types.Receipt, error) {
receipt := new(chain33types.Receipt) ethBridgeClaim.IssuerDotSymbol = strings.ToLower(ethBridgeClaim.IssuerDotSymbol)
ethBridgeClaim.LocalCoinSymbol = strings.ToLower(ethBridgeClaim.LocalCoinSymbol)
consensusNeededBytes, err := a.db.Get(types2.CalConsensusThresholdPrefix()) receipt, err := a.checkConsensusThreshold()
if err != nil {
if err == chain33types.ErrNotFound {
setConsensusThreshold := &types2.ReceiptQueryConsensusThreshold{ConsensusThreshold: types2.DefaultConsensusNeeded}
msgSetConsensusThresholdBytes, err := proto.Marshal(setConsensusThreshold)
if err != nil {
return nil, chain33types.ErrMarshal
}
receipt.KV = append(receipt.KV, &chain33types.KeyValue{
Key: types2.CalConsensusThresholdPrefix(),
Value: msgSetConsensusThresholdBytes,
})
consensusThreshold := &types2.ReceiptSetConsensusThreshold{
PreConsensusThreshold: int64(0),
NowConsensusThreshold: types2.DefaultConsensusNeeded,
XTxHash: a.txhash,
XHeight: uint64(a.height),
}
receipt.Logs = append(receipt.Logs, &chain33types.ReceiptLog{Ty: types2.TySetConsensusThresholdLog, Log: chain33types.Encode(consensusThreshold)})
} else {
return nil, err
}
} else {
var mc types2.ReceiptQueryConsensusThreshold
_ = proto.Unmarshal(consensusNeededBytes, &mc)
_, _, err = a.keeper.ProcessSetConsensusNeeded(mc.ConsensusThreshold)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
status, err := a.keeper.ProcessClaim(*ethBridgeClaim) status, err := a.oracle.ProcessClaim(*ethBridgeClaim)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -119,32 +52,33 @@ func (a *action) procMsgEth2Chain33(ethBridgeClaim *types2.Eth2Chain33) (*chain3 ...@@ -119,32 +52,33 @@ func (a *action) procMsgEth2Chain33(ethBridgeClaim *types2.Eth2Chain33) (*chain3
ID := strconv.Itoa(int(ethBridgeClaim.EthereumChainID)) + strconv.Itoa(int(ethBridgeClaim.Nonce)) + ethBridgeClaim.EthereumSender + ethBridgeClaim.TokenContractAddress + "lock" ID := strconv.Itoa(int(ethBridgeClaim.EthereumChainID)) + strconv.Itoa(int(ethBridgeClaim.Nonce)) + ethBridgeClaim.EthereumSender + ethBridgeClaim.TokenContractAddress + "lock"
//记录ethProphecy //记录ethProphecy
bz, err := a.db.Get(types2.CalProphecyPrefix(ID)) bz, err := a.db.Get(x2eTy.CalProphecyPrefix(ID))
if err != nil { if err != nil {
return nil, types2.ErrProphecyGet return nil, x2eTy.ErrProphecyGet
} }
var dbProphecy types2.ReceiptEthProphecy var dbProphecy x2eTy.ReceiptEthProphecy
err = proto.Unmarshal(bz, &dbProphecy) err = types.Decode(bz, &dbProphecy)
if err != nil { if err != nil {
return nil, chain33types.ErrUnmarshal return nil, types.ErrUnmarshal
} }
receipt.KV = append(receipt.KV, &chain33types.KeyValue{ receipt.KV = append(receipt.KV, &types.KeyValue{
Key: types2.CalProphecyPrefix(ID), Key: x2eTy.CalProphecyPrefix(ID),
Value: bz, Value: bz,
}) })
receipt.Logs = append(receipt.Logs, &chain33types.ReceiptLog{Ty: types2.TyProphecyLog, Log: chain33types.Encode(&dbProphecy)}) receipt.Logs = append(receipt.Logs, &types.ReceiptLog{Ty: x2eTy.TyProphecyLog, Log: types.Encode(&dbProphecy)})
if status.Text == types2.EthBridgeStatus_SuccessStatusText { if status.Text == x2eTy.EthBridgeStatus_SuccessStatusText {
// mavl-x2ethereum-eth // mavl-x2ethereum-eth+tokenAddress
// 这里为了区分相同tokensymbol不同tokenAddress做了级联处理 // 这里为了区分相同tokensymbol不同tokenAddress做了级联处理
accDB, err := account.NewAccountDB(a.api.GetConfig(), ethBridgeClaim.LocalCoinExec, strings.ToLower(ethBridgeClaim.LocalCoinSymbol+ethBridgeClaim.TokenContractAddress), a.db) _, symbol, _ := x2eTy.DivideDot(ethBridgeClaim.IssuerDotSymbol)
accDB, err := account.NewAccountDB(a.api.GetConfig(), x2eTy.X2ethereumX, strings.ToLower(symbol+ethBridgeClaim.TokenContractAddress), a.db)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "relay procMsgEth2Chain33,exec=%s,sym=%s", ethBridgeClaim.LocalCoinExec, ethBridgeClaim.LocalCoinSymbol) return nil, errors.Wrapf(err, "relay procMsgEth2Chain33,exec=%s,sym=%s", x2eTy.X2ethereumX, symbol)
} }
r, err := a.keeper.ProcessSuccessfulClaimForLock(status.FinalClaim, a.execaddr, ethBridgeClaim.LocalCoinSymbol, ethBridgeClaim.TokenContractAddress, accDB) r, err := a.oracle.ProcessSuccessfulClaimForLock(status.FinalClaim, a.execaddr, symbol, accDB)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -152,19 +86,15 @@ func (a *action) procMsgEth2Chain33(ethBridgeClaim *types2.Eth2Chain33) (*chain3 ...@@ -152,19 +86,15 @@ func (a *action) procMsgEth2Chain33(ethBridgeClaim *types2.Eth2Chain33) (*chain3
receipt.Logs = append(receipt.Logs, r.Logs...) receipt.Logs = append(receipt.Logs, r.Logs...)
//记录成功lock的日志 //记录成功lock的日志
msgEthBridgeClaimBytes, err := proto.Marshal(ethBridgeClaim) msgEthBridgeClaimBytes := types.Encode(ethBridgeClaim)
if err != nil {
return nil, chain33types.ErrMarshal
}
receipt.KV = append(receipt.KV, &chain33types.KeyValue{Key: types2.CalEth2Chain33Prefix(), Value: msgEthBridgeClaimBytes})
execlog := &chain33types.ReceiptLog{Ty: types2.TyEth2Chain33Log, Log: chain33types.Encode(&types2.ReceiptEth2Chain33{ receipt.KV = append(receipt.KV, &types.KeyValue{Key: x2eTy.CalEth2Chain33Prefix(), Value: msgEthBridgeClaimBytes})
execlog := &types.ReceiptLog{Ty: x2eTy.TyEth2Chain33Log, Log: types.Encode(&x2eTy.ReceiptEth2Chain33{
EthereumChainID: ethBridgeClaim.EthereumChainID, EthereumChainID: ethBridgeClaim.EthereumChainID,
BridgeContractAddress: ethBridgeClaim.BridgeContractAddress, BridgeContractAddress: ethBridgeClaim.BridgeContractAddress,
Nonce: ethBridgeClaim.Nonce, Nonce: ethBridgeClaim.Nonce,
LocalCoinSymbol: ethBridgeClaim.LocalCoinSymbol, IssuerDotSymbol: ethBridgeClaim.IssuerDotSymbol,
LocalCoinExec: ethBridgeClaim.LocalCoinExec,
TokenContractAddress: ethBridgeClaim.TokenContractAddress,
EthereumSender: ethBridgeClaim.EthereumSender, EthereumSender: ethBridgeClaim.EthereumSender,
Chain33Receiver: ethBridgeClaim.Chain33Receiver, Chain33Receiver: ethBridgeClaim.Chain33Receiver,
ValidatorAddress: ethBridgeClaim.ValidatorAddress, ValidatorAddress: ethBridgeClaim.ValidatorAddress,
...@@ -174,181 +104,106 @@ func (a *action) procMsgEth2Chain33(ethBridgeClaim *types2.Eth2Chain33) (*chain3 ...@@ -174,181 +104,106 @@ func (a *action) procMsgEth2Chain33(ethBridgeClaim *types2.Eth2Chain33) (*chain3
XHeight: uint64(a.height), XHeight: uint64(a.height),
ProphecyID: ID, ProphecyID: ID,
Decimals: ethBridgeClaim.Decimals, Decimals: ethBridgeClaim.Decimals,
TokenAddress: ethBridgeClaim.TokenContractAddress,
})} })}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
} }
receipt.Ty = chain33types.ExecOk receipt.Ty = types.ExecOk
return receipt, nil return receipt, nil
} }
// chain33 -> ethereum // chain33 -> ethereum
// 返还在chain33上生成的erc20代币 // 返还在chain33上生成的erc20代币
func (a *action) procMsgBurn(msgBurn *types2.Chain33ToEth) (*chain33types.Receipt, error) { func (a *action) procChain33ToEth_burn(msgBurn *x2eTy.Chain33ToEth) (*types.Receipt, error) {
msgBurn.LocalCoinExec = types2.X2ethereumX receipt, err := a.checkConsensusThreshold()
receipt := new(chain33types.Receipt)
consensusNeededBytes, err := a.db.Get(types2.CalConsensusThresholdPrefix())
if err != nil {
if err == chain33types.ErrNotFound {
setConsensusThreshold := &types2.ReceiptQueryConsensusThreshold{ConsensusThreshold: types2.DefaultConsensusNeeded}
msgSetConsensusThresholdBytes, err := proto.Marshal(setConsensusThreshold)
if err != nil { if err != nil {
return nil, chain33types.ErrMarshal
}
receipt.KV = append(receipt.KV, &chain33types.KeyValue{
Key: types2.CalConsensusThresholdPrefix(),
Value: msgSetConsensusThresholdBytes,
})
consensusThreshold := &types2.ReceiptSetConsensusThreshold{
PreConsensusThreshold: int64(0),
NowConsensusThreshold: types2.DefaultConsensusNeeded,
XTxHash: a.txhash,
XHeight: uint64(a.height),
}
receipt.Logs = append(receipt.Logs, &chain33types.ReceiptLog{Ty: types2.TySetConsensusThresholdLog, Log: chain33types.Encode(consensusThreshold)})
} else {
return nil, err return nil, err
} }
} else {
var mc types2.ReceiptQueryConsensusThreshold
_ = proto.Unmarshal(consensusNeededBytes, &mc)
_, _, err = a.keeper.ProcessSetConsensusNeeded(mc.ConsensusThreshold)
if err != nil {
return nil, err
}
}
accDB, err := account.NewAccountDB(a.api.GetConfig(), msgBurn.LocalCoinExec, strings.ToLower(msgBurn.LocalCoinSymbol+msgBurn.TokenContract), a.db) _, symbol, _ := x2eTy.DivideDot(msgBurn.IssuerDotSymbol)
accDB, err := account.NewAccountDB(a.api.GetConfig(), x2eTy.X2ethereumX, strings.ToLower(symbol+msgBurn.TokenContract), a.db)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "relay procMsgBurn,exec=%s,sym=%s", msgBurn.LocalCoinExec, msgBurn.LocalCoinSymbol) return nil, errors.Wrapf(err, "relay procMsgBurn,exec=%s,sym=%s", x2eTy.X2ethereumX, symbol)
} }
receipt, err = a.keeper.ProcessBurn(a.fromaddr, a.execaddr, msgBurn.Amount, msgBurn.TokenContract, msgBurn.Decimals, accDB) r, err := a.oracle.ProcessBurn(a.fromaddr, a.execaddr, msgBurn.Amount, msgBurn.TokenContract, msgBurn.Decimals, accDB)
if err != nil { if err != nil {
return nil, err return nil, err
} }
execlog := &chain33types.ReceiptLog{Ty: types2.TyWithdrawChain33Log, Log: chain33types.Encode(&types2.ReceiptChain33ToEth{ receipt.KV = append(receipt.KV, r.KV...)
TokenContract: msgBurn.TokenContract, receipt.Logs = append(receipt.Logs, r.Logs...)
execlog := &types.ReceiptLog{Ty: x2eTy.TyWithdrawChain33Log, Log: types.Encode(&x2eTy.ReceiptChain33ToEth{
Chain33Sender: a.fromaddr, Chain33Sender: a.fromaddr,
EthereumReceiver: msgBurn.EthereumReceiver, EthereumReceiver: msgBurn.EthereumReceiver,
Amount: msgBurn.Amount, Amount: msgBurn.Amount,
EthSymbol: msgBurn.LocalCoinSymbol, IssuerDotSymbol: msgBurn.IssuerDotSymbol,
Decimals: msgBurn.Decimals, Decimals: msgBurn.Decimals,
TokenContract: msgBurn.TokenContract,
})} })}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
msgBurnBytes, err := proto.Marshal(msgBurn) msgBurnBytes := types.Encode(msgBurn)
if err != nil {
return nil, chain33types.ErrMarshal receipt.KV = append(receipt.KV, &types.KeyValue{Key: x2eTy.CalWithdrawChain33Prefix(), Value: msgBurnBytes})
}
receipt.KV = append(receipt.KV, &chain33types.KeyValue{Key: types2.CalWithdrawChain33Prefix(), Value: msgBurnBytes})
receipt.Ty = chain33types.ExecOk receipt.Ty = types.ExecOk
return receipt, nil return receipt, nil
} }
func (a *action) procMsgLock(msgLock *types2.Chain33ToEth) (*chain33types.Receipt, error) { func (a *action) procChain33ToEth_lock(msgLock *x2eTy.Chain33ToEth) (*types.Receipt, error) {
msgLock.LocalCoinExec = types2.X2ethereumX receipt, err := a.checkConsensusThreshold()
receipt := new(chain33types.Receipt)
consensusNeededBytes, err := a.db.Get(types2.CalConsensusThresholdPrefix())
if err != nil {
if err == chain33types.ErrNotFound {
setConsensusThreshold := &types2.ReceiptQueryConsensusThreshold{ConsensusThreshold: types2.DefaultConsensusNeeded}
msgSetConsensusThresholdBytes, err := proto.Marshal(setConsensusThreshold)
if err != nil {
return nil, chain33types.ErrMarshal
}
receipt.KV = append(receipt.KV, &chain33types.KeyValue{
Key: types2.CalConsensusThresholdPrefix(),
Value: msgSetConsensusThresholdBytes,
})
consensusThreshold := &types2.ReceiptSetConsensusThreshold{
PreConsensusThreshold: int64(0),
NowConsensusThreshold: types2.DefaultConsensusNeeded,
XTxHash: a.txhash,
XHeight: uint64(a.height),
}
receipt.Logs = append(receipt.Logs, &chain33types.ReceiptLog{Ty: types2.TySetConsensusThresholdLog, Log: chain33types.Encode(consensusThreshold)})
} else {
return nil, err
}
} else {
var mc types2.ReceiptQueryConsensusThreshold
_ = proto.Unmarshal(consensusNeededBytes, &mc)
_, _, err = a.keeper.ProcessSetConsensusNeeded(mc.ConsensusThreshold)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
var accDB *account.DB
exec, symbol, _ := x2eTy.DivideDot(msgLock.IssuerDotSymbol)
if exec == "coins" {
accDB := account.NewCoinsAccount(a.api.GetConfig()) accDB := account.NewCoinsAccount(a.api.GetConfig())
accDB.SetDB(a.db) accDB.SetDB(a.db)
receipt, err = a.keeper.ProcessLock(a.fromaddr, address.ExecAddress(msgLock.LocalCoinSymbol), a.execaddr, msgLock.Amount, accDB) } else {
accDB, err = account.NewAccountDB(a.api.GetConfig(), exec, strings.ToLower(symbol), a.db)
}
r, err := a.oracle.ProcessLock(a.fromaddr, address.ExecAddress(symbol), a.execaddr, msgLock.Amount, accDB)
if err != nil { if err != nil {
return nil, err return nil, err
} }
execlog := &chain33types.ReceiptLog{Ty: types2.TyChain33ToEthLog, Log: chain33types.Encode(&types2.ReceiptChain33ToEth{ receipt.KV = append(receipt.KV, r.KV...)
TokenContract: msgLock.TokenContract, receipt.Logs = append(receipt.Logs, r.Logs...)
execlog := &types.ReceiptLog{Ty: x2eTy.TyChain33ToEthLog, Log: types.Encode(&x2eTy.ReceiptChain33ToEth{
Chain33Sender: a.fromaddr, Chain33Sender: a.fromaddr,
EthereumReceiver: msgLock.EthereumReceiver, EthereumReceiver: msgLock.EthereumReceiver,
Amount: msgLock.Amount, Amount: msgLock.Amount,
EthSymbol: msgLock.LocalCoinSymbol, IssuerDotSymbol: msgLock.IssuerDotSymbol,
Decimals: msgLock.Decimals, Decimals: msgLock.Decimals,
TokenContract: msgLock.TokenContract,
})} })}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
msgLockBytes, err := proto.Marshal(msgLock) msgLockBytes := types.Encode(msgLock)
if err != nil {
return nil, chain33types.ErrMarshal receipt.KV = append(receipt.KV, &types.KeyValue{Key: x2eTy.CalChain33ToEthPrefix(), Value: msgLockBytes})
}
receipt.KV = append(receipt.KV, &chain33types.KeyValue{Key: types2.CalChain33ToEthPrefix(), Value: msgLockBytes})
receipt.Ty = chain33types.ExecOk receipt.Ty = types.ExecOk
return receipt, nil return receipt, nil
} }
// ethereum -> chain33 // ethereum -> chain33
// burn // burn
func (a *action) procWithdrawEth(withdrawEth *types2.Eth2Chain33) (*chain33types.Receipt, error) { func (a *action) procEth2Chain33_burn(withdrawEth *x2eTy.Eth2Chain33) (*types.Receipt, error) {
elog.Info("procWithdrawEth", "receive a procWithdrawEth tx", "start") elog.Info("procWithdrawEth", "receive a procWithdrawEth tx", "start")
receipt := new(chain33types.Receipt)
consensusNeededBytes, err := a.db.Get(types2.CalConsensusThresholdPrefix()) receipt, err := a.checkConsensusThreshold()
if err != nil {
if err == chain33types.ErrNotFound {
setConsensusThreshold := &types2.ReceiptQueryConsensusThreshold{ConsensusThreshold: types2.DefaultConsensusNeeded}
msgSetConsensusThresholdBytes, err := proto.Marshal(setConsensusThreshold)
if err != nil {
return nil, chain33types.ErrMarshal
}
receipt.KV = append(receipt.KV, &chain33types.KeyValue{
Key: types2.CalConsensusThresholdPrefix(),
Value: msgSetConsensusThresholdBytes,
})
consensusThreshold := &types2.ReceiptSetConsensusThreshold{
PreConsensusThreshold: int64(0),
NowConsensusThreshold: types2.DefaultConsensusNeeded,
XTxHash: a.txhash,
XHeight: uint64(a.height),
}
receipt.Logs = append(receipt.Logs, &chain33types.ReceiptLog{Ty: types2.TySetConsensusThresholdLog, Log: chain33types.Encode(consensusThreshold)})
} else {
return nil, err
}
} else {
var mc types2.ReceiptQueryConsensusThreshold
_ = proto.Unmarshal(consensusNeededBytes, &mc)
_, _, err = a.keeper.ProcessSetConsensusNeeded(mc.ConsensusThreshold)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
status, err := a.keeper.ProcessClaim(*withdrawEth) status, err := a.oracle.ProcessClaim(*withdrawEth)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -356,46 +211,50 @@ func (a *action) procWithdrawEth(withdrawEth *types2.Eth2Chain33) (*chain33types ...@@ -356,46 +211,50 @@ func (a *action) procWithdrawEth(withdrawEth *types2.Eth2Chain33) (*chain33types
ID := strconv.Itoa(int(withdrawEth.EthereumChainID)) + strconv.Itoa(int(withdrawEth.Nonce)) + withdrawEth.EthereumSender + withdrawEth.TokenContractAddress + "burn" ID := strconv.Itoa(int(withdrawEth.EthereumChainID)) + strconv.Itoa(int(withdrawEth.Nonce)) + withdrawEth.EthereumSender + withdrawEth.TokenContractAddress + "burn"
//记录ethProphecy //记录ethProphecy
bz, err := a.db.Get(types2.CalProphecyPrefix(ID)) bz, err := a.db.Get(x2eTy.CalProphecyPrefix(ID))
if err != nil { if err != nil {
return nil, types2.ErrProphecyGet return nil, x2eTy.ErrProphecyGet
} }
var dbProphecy types2.ReceiptEthProphecy var dbProphecy x2eTy.ReceiptEthProphecy
err = proto.Unmarshal(bz, &dbProphecy) err = types.Decode(bz, &dbProphecy)
if err != nil { if err != nil {
return nil, chain33types.ErrUnmarshal return nil, types.ErrUnmarshal
} }
receipt.KV = append(receipt.KV, &chain33types.KeyValue{ receipt.KV = append(receipt.KV, &types.KeyValue{
Key: types2.CalProphecyPrefix(ID), Key: x2eTy.CalProphecyPrefix(ID),
Value: bz, Value: bz,
}) })
receipt.Logs = append(receipt.Logs, &chain33types.ReceiptLog{Ty: types2.TyProphecyLog, Log: chain33types.Encode(&dbProphecy)}) receipt.Logs = append(receipt.Logs, &types.ReceiptLog{Ty: x2eTy.TyProphecyLog, Log: types.Encode(&dbProphecy)})
if status.Text == types2.EthBridgeStatus_SuccessStatusText { if status.Text == x2eTy.EthBridgeStatus_SuccessStatusText {
var accDB *account.DB
exec, symbol, _ := x2eTy.DivideDot(withdrawEth.IssuerDotSymbol)
if exec == "coins" {
accDB := account.NewCoinsAccount(a.api.GetConfig()) accDB := account.NewCoinsAccount(a.api.GetConfig())
accDB.SetDB(a.db) accDB.SetDB(a.db)
r, err := a.keeper.ProcessSuccessfulClaimForBurn(status.FinalClaim, a.execaddr, withdrawEth.LocalCoinSymbol, accDB) } else {
accDB, err = account.NewAccountDB(a.api.GetConfig(), exec, strings.ToLower(symbol), a.db)
}
r, err := a.oracle.ProcessSuccessfulClaimForBurn(status.FinalClaim, a.execaddr, symbol, accDB)
if err != nil { if err != nil {
return nil, err return nil, err
} }
receipt.KV = append(receipt.KV, r.KV...) receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...) receipt.Logs = append(receipt.Logs, r.Logs...)
msgWithdrawEthBytes, err := proto.Marshal(withdrawEth) msgWithdrawEthBytes := types.Encode(withdrawEth)
if err != nil {
return nil, chain33types.ErrMarshal
}
receipt.KV = append(receipt.KV, &chain33types.KeyValue{Key: types2.CalWithdrawEthPrefix(), Value: msgWithdrawEthBytes})
execlog := &chain33types.ReceiptLog{Ty: types2.TyWithdrawEthLog, Log: chain33types.Encode(&types2.ReceiptEth2Chain33{ receipt.KV = append(receipt.KV, &types.KeyValue{Key: x2eTy.CalWithdrawEthPrefix(), Value: msgWithdrawEthBytes})
execlog := &types.ReceiptLog{Ty: x2eTy.TyWithdrawEthLog, Log: types.Encode(&x2eTy.ReceiptEth2Chain33{
EthereumChainID: withdrawEth.EthereumChainID, EthereumChainID: withdrawEth.EthereumChainID,
BridgeContractAddress: withdrawEth.BridgeContractAddress, BridgeContractAddress: withdrawEth.BridgeContractAddress,
Nonce: withdrawEth.Nonce, Nonce: withdrawEth.Nonce,
LocalCoinSymbol: withdrawEth.LocalCoinSymbol, IssuerDotSymbol: withdrawEth.IssuerDotSymbol,
LocalCoinExec: withdrawEth.LocalCoinExec,
TokenContractAddress: withdrawEth.TokenContractAddress,
EthereumSender: withdrawEth.EthereumSender, EthereumSender: withdrawEth.EthereumSender,
Chain33Receiver: withdrawEth.Chain33Receiver, Chain33Receiver: withdrawEth.Chain33Receiver,
ValidatorAddress: withdrawEth.ValidatorAddress, ValidatorAddress: withdrawEth.ValidatorAddress,
...@@ -405,111 +264,113 @@ func (a *action) procWithdrawEth(withdrawEth *types2.Eth2Chain33) (*chain33types ...@@ -405,111 +264,113 @@ func (a *action) procWithdrawEth(withdrawEth *types2.Eth2Chain33) (*chain33types
XHeight: uint64(a.height), XHeight: uint64(a.height),
ProphecyID: ID, ProphecyID: ID,
Decimals: withdrawEth.Decimals, Decimals: withdrawEth.Decimals,
TokenAddress: withdrawEth.TokenContractAddress,
})} })}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
} }
receipt.Ty = chain33types.ExecOk receipt.Ty = types.ExecOk
return receipt, nil return receipt, nil
} }
func (a *action) procMsgTransfer(msgTransfer *chain33types.AssetsTransfer) (*chain33types.Receipt, error) { func (a *action) procMsgTransfer(msgTransfer *types.AssetsTransfer) (*types.Receipt, error) {
token := msgTransfer.GetCointoken() token := msgTransfer.GetCointoken()
receipt := new(chain33types.Receipt)
consensusNeededBytes, err := a.db.Get(types2.CalConsensusThresholdPrefix()) receipt, err := a.checkConsensusThreshold()
if err != nil { if err != nil {
if err == chain33types.ErrNotFound { return nil, err
setConsensusThreshold := &types2.ReceiptQueryConsensusThreshold{ConsensusThreshold: types2.DefaultConsensusNeeded} }
msgSetConsensusThresholdBytes, err := proto.Marshal(setConsensusThreshold)
accDB, err := account.NewAccountDB(a.api.GetConfig(), x2eTy.X2ethereumX, token, a.db)
if err != nil { if err != nil {
return nil, chain33types.ErrMarshal return nil, err
} }
receipt.KV = append(receipt.KV, &chain33types.KeyValue{ r, err := accDB.ExecTransfer(a.fromaddr, msgTransfer.To, address.ExecAddress(x2eTy.X2ethereumX), msgTransfer.Amount)
Key: types2.CalConsensusThresholdPrefix(), if err != nil {
Value: msgSetConsensusThresholdBytes, return nil, err
})
consensusThreshold := &types2.ReceiptSetConsensusThreshold{
PreConsensusThreshold: int64(0),
NowConsensusThreshold: types2.DefaultConsensusNeeded,
XTxHash: a.txhash,
XHeight: uint64(a.height),
} }
receipt.Logs = append(receipt.Logs, &chain33types.ReceiptLog{Ty: types2.TySetConsensusThresholdLog, Log: chain33types.Encode(consensusThreshold)})
} else { receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
receipt.Ty = types.ExecOk
return receipt, nil
}
func (a *action) procMsgTransferToExec(msgTransferToExec *types.AssetsTransferToExec) (*types.Receipt, error) {
token := msgTransferToExec.GetCointoken()
receipt, err := a.checkConsensusThreshold()
if err != nil {
return nil, err return nil, err
} }
} else {
var mc types2.ReceiptQueryConsensusThreshold accDB, err := account.NewAccountDB(a.api.GetConfig(), x2eTy.X2ethereumX, token, a.db)
_ = proto.Unmarshal(consensusNeededBytes, &mc)
_, _, err = a.keeper.ProcessSetConsensusNeeded(mc.ConsensusThreshold)
if err != nil { if err != nil {
return nil, err return nil, err
} }
r, err := accDB.TransferToExec(a.fromaddr, address.ExecAddress(msgTransferToExec.ExecName), msgTransferToExec.Amount)
if err != nil {
return nil, err
} }
accDB, err := account.NewAccountDB(a.api.GetConfig(), types2.X2ethereumX, token, a.db) receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
return receipt, nil
}
func (a *action) procMsgWithDrawFromExec(msgWithdrawFromExec *types.AssetsWithdraw) (*types.Receipt, error) {
token := msgWithdrawFromExec.GetCointoken()
receipt, err := a.checkConsensusThreshold()
if err != nil { if err != nil {
return nil, err return nil, err
} }
receipt, err = accDB.ExecTransfer(a.fromaddr, msgTransfer.To, address.ExecAddress(types2.X2ethereumX), msgTransfer.Amount)
accDB, err := account.NewAccountDB(a.api.GetConfig(), x2eTy.X2ethereumX, token, a.db)
if err != nil { if err != nil {
return nil, err return nil, err
} }
receipt.Ty = chain33types.ExecOk r, err := accDB.TransferWithdraw(a.fromaddr, address.ExecAddress(msgWithdrawFromExec.ExecName), msgWithdrawFromExec.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 receipt, nil
} }
//需要一笔交易来注册validator //需要一笔交易来注册validator
//这里注册的validator的power之和可能不为1,需要在内部进行加权 //这里注册的validator的power之和可能不为1,需要在内部进行加权
//返回的回执中,KV包含所有validator的power值,Log中包含本次注册的validator的power值 //返回的回执中,KV包含所有validator的power值,Log中包含本次注册的validator的power值
func (a *action) procAddValidator(msgAddValidator *types2.MsgValidator) (*chain33types.Receipt, error) { func (a *action) procAddValidator(msgAddValidator *x2eTy.MsgValidator) (*types.Receipt, error) {
elog.Info("procAddValidator", "start", msgAddValidator) elog.Info("procAddValidator", "start", msgAddValidator)
receipt := new(chain33types.Receipt)
consensusNeededBytes, err := a.db.Get(types2.CalConsensusThresholdPrefix()) receipt, err := a.checkConsensusThreshold()
if err != nil {
if err == chain33types.ErrNotFound {
setConsensusThreshold := &types2.ReceiptQueryConsensusThreshold{ConsensusThreshold: types2.DefaultConsensusNeeded}
msgSetConsensusThresholdBytes, err := proto.Marshal(setConsensusThreshold)
if err != nil {
return nil, chain33types.ErrMarshal
}
receipt.KV = append(receipt.KV, &chain33types.KeyValue{
Key: types2.CalConsensusThresholdPrefix(),
Value: msgSetConsensusThresholdBytes,
})
consensusThreshold := &types2.ReceiptSetConsensusThreshold{
PreConsensusThreshold: int64(0),
NowConsensusThreshold: types2.DefaultConsensusNeeded,
XTxHash: a.txhash,
XHeight: uint64(a.height),
}
receipt.Logs = append(receipt.Logs, &chain33types.ReceiptLog{Ty: types2.TySetConsensusThresholdLog, Log: chain33types.Encode(consensusThreshold)})
} else {
return nil, err
}
} else {
var mc types2.ReceiptQueryConsensusThreshold
_ = proto.Unmarshal(consensusNeededBytes, &mc)
_, _, err = a.keeper.ProcessSetConsensusNeeded(mc.ConsensusThreshold)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
if !types2.CheckPower(msgAddValidator.Power) { if !x2eTy.CheckPower(msgAddValidator.Power) {
return nil, types2.ErrInvalidPower return nil, x2eTy.ErrInvalidPower
} }
receipt, err = a.keeper.ProcessAddValidator(msgAddValidator.Address, msgAddValidator.Power) r, err := a.oracle.ProcessAddValidator(msgAddValidator.Address, msgAddValidator.Power)
if err != nil { if err != nil {
return nil, err return nil, err
} }
execlog := &chain33types.ReceiptLog{Ty: types2.TyAddValidatorLog, Log: chain33types.Encode(&types2.ReceiptValidator{ receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
execlog := &types.ReceiptLog{Ty: x2eTy.TyAddValidatorLog, Log: types.Encode(&x2eTy.ReceiptValidator{
Address: msgAddValidator.Address, Address: msgAddValidator.Address,
Power: msgAddValidator.Power, Power: msgAddValidator.Power,
XTxHash: a.txhash, XTxHash: a.txhash,
...@@ -517,50 +378,25 @@ func (a *action) procAddValidator(msgAddValidator *types2.MsgValidator) (*chain3 ...@@ -517,50 +378,25 @@ func (a *action) procAddValidator(msgAddValidator *types2.MsgValidator) (*chain3
})} })}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
receipt.Ty = chain33types.ExecOk receipt.Ty = types.ExecOk
return receipt, nil return receipt, nil
} }
func (a *action) procRemoveValidator(msgRemoveValidator *types2.MsgValidator) (*chain33types.Receipt, error) { func (a *action) procRemoveValidator(msgRemoveValidator *x2eTy.MsgValidator) (*types.Receipt, error) {
receipt := new(chain33types.Receipt) receipt, err := a.checkConsensusThreshold()
consensusNeededBytes, err := a.db.Get(types2.CalConsensusThresholdPrefix())
if err != nil {
if err == chain33types.ErrNotFound {
setConsensusThreshold := &types2.ReceiptQueryConsensusThreshold{ConsensusThreshold: types2.DefaultConsensusNeeded}
msgSetConsensusThresholdBytes, err := proto.Marshal(setConsensusThreshold)
if err != nil { if err != nil {
return nil, chain33types.ErrMarshal
}
receipt.KV = append(receipt.KV, &chain33types.KeyValue{
Key: types2.CalConsensusThresholdPrefix(),
Value: msgSetConsensusThresholdBytes,
})
consensusThreshold := &types2.ReceiptSetConsensusThreshold{
PreConsensusThreshold: int64(0),
NowConsensusThreshold: types2.DefaultConsensusNeeded,
XTxHash: a.txhash,
XHeight: uint64(a.height),
}
receipt.Logs = append(receipt.Logs, &chain33types.ReceiptLog{Ty: types2.TySetConsensusThresholdLog, Log: chain33types.Encode(consensusThreshold)})
} else {
return nil, err return nil, err
} }
} else {
var mc types2.ReceiptQueryConsensusThreshold
_ = proto.Unmarshal(consensusNeededBytes, &mc)
_, _, err = a.keeper.ProcessSetConsensusNeeded(mc.ConsensusThreshold)
if err != nil {
return nil, err
}
}
receipt, err = a.keeper.ProcessRemoveValidator(msgRemoveValidator.Address) r, err := a.oracle.ProcessRemoveValidator(msgRemoveValidator.Address)
if err != nil { if err != nil {
return nil, err return nil, err
} }
execlog := &chain33types.ReceiptLog{Ty: types2.TyRemoveValidatorLog, Log: chain33types.Encode(&types2.ReceiptValidator{ receipt.KV = append(receipt.KV, r.KV...)
receipt.Logs = append(receipt.Logs, r.Logs...)
execlog := &types.ReceiptLog{Ty: x2eTy.TyRemoveValidatorLog, Log: types.Encode(&x2eTy.ReceiptValidator{
Address: msgRemoveValidator.Address, Address: msgRemoveValidator.Address,
Power: msgRemoveValidator.Power, Power: msgRemoveValidator.Power,
XTxHash: a.txhash, XTxHash: a.txhash,
...@@ -568,54 +404,26 @@ func (a *action) procRemoveValidator(msgRemoveValidator *types2.MsgValidator) (* ...@@ -568,54 +404,26 @@ func (a *action) procRemoveValidator(msgRemoveValidator *types2.MsgValidator) (*
})} })}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
receipt.Ty = chain33types.ExecOk receipt.Ty = types.ExecOk
return receipt, nil return receipt, nil
} }
func (a *action) procModifyValidator(msgModifyValidator *types2.MsgValidator) (*chain33types.Receipt, error) { func (a *action) procModifyValidator(msgModifyValidator *x2eTy.MsgValidator) (*types.Receipt, error) {
receipt := new(chain33types.Receipt) receipt, err := a.checkConsensusThreshold()
consensusNeededBytes, err := a.db.Get(types2.CalConsensusThresholdPrefix())
if err != nil {
if err == chain33types.ErrNotFound {
setConsensusThreshold := &types2.ReceiptQueryConsensusThreshold{ConsensusThreshold: types2.DefaultConsensusNeeded}
msgSetConsensusThresholdBytes, err := proto.Marshal(setConsensusThreshold)
if err != nil {
return nil, chain33types.ErrMarshal
}
receipt.KV = append(receipt.KV, &chain33types.KeyValue{
Key: types2.CalConsensusThresholdPrefix(),
Value: msgSetConsensusThresholdBytes,
})
consensusThreshold := &types2.ReceiptSetConsensusThreshold{
PreConsensusThreshold: int64(0),
NowConsensusThreshold: types2.DefaultConsensusNeeded,
XTxHash: a.txhash,
XHeight: uint64(a.height),
}
receipt.Logs = append(receipt.Logs, &chain33types.ReceiptLog{Ty: types2.TySetConsensusThresholdLog, Log: chain33types.Encode(consensusThreshold)})
} else {
return nil, err
}
} else {
var mc types2.ReceiptQueryConsensusThreshold
_ = proto.Unmarshal(consensusNeededBytes, &mc)
_, _, err = a.keeper.ProcessSetConsensusNeeded(mc.ConsensusThreshold)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
if !types2.CheckPower(msgModifyValidator.Power) { if !x2eTy.CheckPower(msgModifyValidator.Power) {
return nil, types2.ErrInvalidPower return nil, x2eTy.ErrInvalidPower
} }
receipt, err = a.keeper.ProcessModifyValidator(msgModifyValidator.Address, msgModifyValidator.Power) receipt, err = a.oracle.ProcessModifyValidator(msgModifyValidator.Address, msgModifyValidator.Power)
if err != nil { if err != nil {
return nil, err return nil, err
} }
execlog := &chain33types.ReceiptLog{Ty: types2.TyModifyPowerLog, Log: chain33types.Encode(&types2.ReceiptValidator{ execlog := &types.ReceiptLog{Ty: x2eTy.TyModifyPowerLog, Log: types.Encode(&x2eTy.ReceiptValidator{
Address: msgModifyValidator.Address, Address: msgModifyValidator.Address,
Power: msgModifyValidator.Power, Power: msgModifyValidator.Power,
XTxHash: a.txhash, XTxHash: a.txhash,
...@@ -623,38 +431,69 @@ func (a *action) procModifyValidator(msgModifyValidator *types2.MsgValidator) (* ...@@ -623,38 +431,69 @@ func (a *action) procModifyValidator(msgModifyValidator *types2.MsgValidator) (*
})} })}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
receipt.Ty = chain33types.ExecOk receipt.Ty = types.ExecOk
return receipt, nil return receipt, nil
} }
func (a *action) procMsgSetConsensusThreshold(msgSetConsensusThreshold *types2.MsgConsensusThreshold) (*chain33types.Receipt, error) { func (a *action) procMsgSetConsensusThreshold(msgSetConsensusThreshold *x2eTy.MsgConsensusThreshold) (*types.Receipt, error) {
receipt := new(chain33types.Receipt) receipt := new(types.Receipt)
if !types2.CheckPower(msgSetConsensusThreshold.ConsensusThreshold) { if !x2eTy.CheckPower(msgSetConsensusThreshold.ConsensusThreshold) {
return nil, types2.ErrInvalidPower return nil, x2eTy.ErrInvalidPower
} }
preConsensusNeeded, nowConsensusNeeded, err := a.keeper.ProcessSetConsensusNeeded(msgSetConsensusThreshold.ConsensusThreshold) preConsensusNeeded, nowConsensusNeeded, err := a.oracle.ProcessSetConsensusNeeded(msgSetConsensusThreshold.ConsensusThreshold)
if err != nil { if err != nil {
return nil, err return nil, err
} }
setConsensusThreshold := &types2.ReceiptSetConsensusThreshold{ setConsensusThreshold := &x2eTy.ReceiptSetConsensusThreshold{
PreConsensusThreshold: preConsensusNeeded, PreConsensusThreshold: preConsensusNeeded,
NowConsensusThreshold: nowConsensusNeeded, NowConsensusThreshold: nowConsensusNeeded,
XTxHash: a.txhash, XTxHash: a.txhash,
XHeight: uint64(a.height), XHeight: uint64(a.height),
} }
execlog := &chain33types.ReceiptLog{Ty: types2.TySetConsensusThresholdLog, Log: chain33types.Encode(setConsensusThreshold)} execlog := &types.ReceiptLog{Ty: x2eTy.TySetConsensusThresholdLog, Log: types.Encode(setConsensusThreshold)}
receipt.Logs = append(receipt.Logs, execlog) receipt.Logs = append(receipt.Logs, execlog)
msgSetConsensusThresholdBytes, err := proto.Marshal(&types2.ReceiptQueryConsensusThreshold{ msgSetConsensusThresholdBytes := types.Encode(&x2eTy.ReceiptQueryConsensusThreshold{
ConsensusThreshold: nowConsensusNeeded, ConsensusThreshold: nowConsensusNeeded,
}) })
receipt.KV = append(receipt.KV, &types.KeyValue{Key: x2eTy.CalConsensusThresholdPrefix(), Value: msgSetConsensusThresholdBytes})
receipt.Ty = types.ExecOk
return receipt, nil
}
func (a *action) checkConsensusThreshold() (*types.Receipt, error) {
receipt := new(types.Receipt)
consensusNeededBytes, err := a.db.Get(x2eTy.CalConsensusThresholdPrefix())
if err != nil { if err != nil {
return nil, chain33types.ErrMarshal if err == types.ErrNotFound {
} setConsensusThreshold := &x2eTy.ReceiptQueryConsensusThreshold{ConsensusThreshold: x2eTy.DefaultConsensusNeeded}
receipt.KV = append(receipt.KV, &chain33types.KeyValue{Key: types2.CalConsensusThresholdPrefix(), Value: msgSetConsensusThresholdBytes}) msgSetConsensusThresholdBytes := types.Encode(setConsensusThreshold)
receipt.Ty = chain33types.ExecOk receipt.KV = append(receipt.KV, &types.KeyValue{
Key: x2eTy.CalConsensusThresholdPrefix(),
Value: msgSetConsensusThresholdBytes,
})
consensusThreshold := &x2eTy.ReceiptSetConsensusThreshold{
PreConsensusThreshold: int64(0),
NowConsensusThreshold: x2eTy.DefaultConsensusNeeded,
XTxHash: a.txhash,
XHeight: uint64(a.height),
}
receipt.Logs = append(receipt.Logs, &types.ReceiptLog{Ty: x2eTy.TySetConsensusThresholdLog, Log: types.Encode(consensusThreshold)})
} else {
return nil, err
}
} else {
var mc x2eTy.ReceiptQueryConsensusThreshold
_ = types.Decode(consensusNeededBytes, &mc)
_, _, err = a.oracle.ProcessSetConsensusNeeded(mc.ConsensusThreshold)
if err != nil {
return nil, err
}
}
return receipt, nil return receipt, nil
} }
package executor
import (
"strconv"
"strings"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common/address"
dbm "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types"
x2eTy "github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
)
type Oracle struct {
db dbm.KV
consensusThreshold int64
}
func NewOracle(db dbm.KV, consensusThreshold int64) *Oracle {
if consensusThreshold <= 0 || consensusThreshold > 100 {
return nil
}
return &Oracle{
consensusThreshold: consensusThreshold,
db: db,
}
}
// 处理经过审核的关于Lock的claim
func (o *Oracle) ProcessSuccessfulClaimForLock(claim, execAddr, tokenSymbol string, accDB *account.DB) (*types.Receipt, error) {
var receipt *types.Receipt
oracleClaim, err := CreateOracleClaimFromOracleString(claim)
if err != nil {
elog.Error("CreateEthClaimFromOracleString", "CreateOracleClaimFromOracleString error", err)
return nil, err
}
receiverAddress := oracleClaim.Chain33Receiver
if oracleClaim.ClaimType == int64(x2eTy.LOCK_CLAIM_TYPE) {
//铸币到相关的tokenSymbolBank账户下
amount, _ := strconv.ParseInt(x2eTy.TrimZeroAndDot(oracleClaim.Amount), 10, 64)
receipt, err = accDB.Mint(receiverAddress, amount)
if err != nil {
return nil, err
}
return receipt, nil
}
return nil, x2eTy.ErrInvalidClaimType
}
// 处理经过审核的关于Burn的claim
func (o *Oracle) ProcessSuccessfulClaimForBurn(claim, execAddr, tokenSymbol string, accDB *account.DB) (*types.Receipt, error) {
receipt := new(types.Receipt)
oracleClaim, err := CreateOracleClaimFromOracleString(claim)
if err != nil {
elog.Error("CreateEthClaimFromOracleString", "CreateOracleClaimFromOracleString error", err)
return nil, err
}
senderAddr := oracleClaim.Chain33Receiver
if oracleClaim.ClaimType == int64(x2eTy.BURN_CLAIM_TYPE) {
amount, _ := strconv.ParseInt(x2eTy.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, x2eTy.ErrInvalidClaimType
}
// ProcessBurn processes the burn of bridged coins from the given sender
func (o *Oracle) ProcessBurn(address, execAddr, amount, tokenAddress string, d int64, accDB *account.DB) (*types.Receipt, error) {
var a int64
a, _ = strconv.ParseInt(x2eTy.TrimZeroAndDot(amount), 10, 64)
receipt, err := accDB.Burn(address, a)
if err != nil {
return nil, err
}
return receipt, nil
}
// ProcessLock processes the lockup of cosmos coins from the given sender
// accDB = mavl-coins-bty-addr
func (o *Oracle) ProcessLock(address, to, execAddr, amount string, accDB *account.DB) (*types.Receipt, error) {
// 转到 mavl-coins-bty-execAddr:addr
a, _ := strconv.ParseInt(x2eTy.TrimZeroAndDot(amount), 10, 64)
receipt, err := accDB.ExecTransfer(address, to, execAddr, a)
if err != nil {
return nil, err
}
return receipt, nil
}
// 对于相同的地址该如何处理?
// 现有方案是相同地址就报错
func (o *Oracle) ProcessAddValidator(address string, power int64) (*types.Receipt, error) {
receipt := new(types.Receipt)
validatorMaps, err := o.GetValidatorArray()
if err != nil && err != types.ErrNotFound {
return nil, err
}
if validatorMaps == nil {
validatorMaps = new(x2eTy.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, x2eTy.ErrAddressExists
}
}
vs := append(validatorMaps.Validators, &x2eTy.MsgValidator{
Address: address,
Power: power,
})
validatorMaps.Validators = vs
v := types.Encode(validatorMaps)
receipt.KV = append(receipt.KV, &types.KeyValue{Key: x2eTy.CalValidatorMapsPrefix(), Value: v})
totalPower += power
totalP := x2eTy.ReceiptQueryTotalPower{
TotalPower: totalPower,
}
totalPBytes := types.Encode(&totalP)
receipt.KV = append(receipt.KV, &types.KeyValue{Key: x2eTy.CalLastTotalPowerPrefix(), Value: totalPBytes})
return receipt, nil
}
func (o *Oracle) ProcessRemoveValidator(address string) (*types.Receipt, error) {
var exist bool
receipt := new(types.Receipt)
validatorMaps, err := o.GetValidatorArray()
if err != nil {
return nil, err
}
elog.Info("ProcessLogOutValidator", "pre validatorMaps", validatorMaps, "Delete Address", address)
var totalPower int64
validatorRes := new(x2eTy.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, x2eTy.ErrAddressNotExist
}
v := types.Encode(validatorRes)
receipt.KV = append(receipt.KV, &types.KeyValue{Key: x2eTy.CalValidatorMapsPrefix(), Value: v})
totalP := x2eTy.ReceiptQueryTotalPower{
TotalPower: totalPower,
}
totalPBytes := types.Encode(&totalP)
receipt.KV = append(receipt.KV, &types.KeyValue{Key: x2eTy.CalLastTotalPowerPrefix(), Value: totalPBytes})
return receipt, nil
}
//这里的power指的是修改后的power
func (o *Oracle) ProcessModifyValidator(address string, power int64) (*types.Receipt, error) {
var exist bool
receipt := new(types.Receipt)
validatorMaps, err := o.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, x2eTy.ErrAddressNotExist
}
v := types.Encode(validatorMaps)
receipt.KV = append(receipt.KV, &types.KeyValue{Key: x2eTy.CalValidatorMapsPrefix(), Value: v})
totalP := x2eTy.ReceiptQueryTotalPower{
TotalPower: totalPower,
}
totalPBytes := types.Encode(&totalP)
receipt.KV = append(receipt.KV, &types.KeyValue{Key: x2eTy.CalLastTotalPowerPrefix(), Value: totalPBytes})
return receipt, nil
}
func (o *Oracle) ProcessSetConsensusNeeded(ConsensusThreshold int64) (int64, int64, error) {
preCon := o.GetConsensusThreshold()
o.SetConsensusThreshold(ConsensusThreshold)
nowCon := o.GetConsensusThreshold()
elog.Info("ProcessSetConsensusNeeded", "pre ConsensusThreshold", preCon, "now ConsensusThreshold", nowCon)
return preCon, nowCon, nil
}
func (o *Oracle) GetProphecy(id string) (*x2eTy.ReceiptEthProphecy, error) {
if id == "" {
return nil, x2eTy.ErrInvalidIdentifier
}
bz, err := o.db.Get(x2eTy.CalProphecyPrefix(id))
if err != nil && err != types.ErrNotFound {
return nil, x2eTy.ErrProphecyGet
} else if err == types.ErrNotFound {
return nil, x2eTy.ErrProphecyNotFound
}
var dbProphecy x2eTy.ReceiptEthProphecy
err = types.Decode(bz, &dbProphecy)
if err != nil {
return nil, types.ErrUnmarshal
}
return &dbProphecy, nil
}
// setProphecy saves a prophecy with an initial claim
func (o *Oracle) setProphecy(prophecy *x2eTy.ReceiptEthProphecy) error {
err := o.checkProphecy(prophecy)
if err != nil {
return err
}
bz, err := o.db.Get(x2eTy.CalProphecyPrefix(prophecy.ID))
if err != nil && err != types.ErrNotFound {
return x2eTy.ErrProphecyGet
}
var dbProphecy x2eTy.ReceiptEthProphecy
if err != types.ErrNotFound {
err = types.Decode(bz, &dbProphecy)
if err != nil {
return types.ErrUnmarshal
}
}
dbProphecy = *prophecy
serializedProphecyBytes := types.Encode(&dbProphecy)
err = o.db.Set(x2eTy.CalProphecyPrefix(prophecy.ID), serializedProphecyBytes)
if err != nil {
return x2eTy.ErrSetKV
}
return nil
}
func (o *Oracle) checkProphecy(prophecy *x2eTy.ReceiptEthProphecy) error {
if prophecy.ID == "" {
return x2eTy.ErrInvalidIdentifier
}
if len(prophecy.ClaimValidators) == 0 {
return x2eTy.ErrNoClaims
}
return nil
}
// 处理接收到的ethchain33请求
func (o *Oracle) ProcessClaim(claim x2eTy.Eth2Chain33) (*x2eTy.ProphecyStatus, error) {
oracleClaim, err := CreateOracleClaimFromEthClaim(claim)
if err != nil {
elog.Error("CreateEthClaimFromOracleString", "CreateOracleClaimFromOracleString error", err)
return nil, err
}
activeValidator := o.checkActiveValidator(oracleClaim.ValidatorAddress)
if !activeValidator {
return nil, x2eTy.ErrInvalidValidator
}
if strings.TrimSpace(oracleClaim.Content) == "" {
return nil, x2eTy.ErrInvalidClaim
}
var claimContent x2eTy.OracleClaimContent
err = types.Decode([]byte(oracleClaim.Content), &claimContent)
if err != nil {
return nil, types.ErrUnmarshal
}
prophecy, err := o.GetProphecy(oracleClaim.ID)
if err != nil {
if err != x2eTy.ErrProphecyNotFound {
return nil, err
}
prophecy = NewProphecy(oracleClaim.ID)
} else {
var exist bool
for _, vc := range prophecy.ValidatorClaims {
if vc.Claim == oracleClaim.Content {
exist = true
}
}
if !exist {
prophecy.Status.Text = x2eTy.EthBridgeStatus_FailedStatusText
return nil, x2eTy.ErrClaimInconsist
}
if prophecy.Status.Text == x2eTy.EthBridgeStatus_FailedStatusText {
return nil, x2eTy.ErrProphecyFinalized
}
for _, vc := range prophecy.ValidatorClaims {
if vc.Validator == claim.ValidatorAddress && vc.Claim != "" {
return nil, x2eTy.ErrDuplicateMessage
}
}
}
AddClaim(prophecy, oracleClaim.ValidatorAddress, oracleClaim.Content)
prophecy, err = o.processCompletion(prophecy, claimContent.ClaimType)
if err != nil {
return nil, err
}
err = o.setProphecy(prophecy)
if err != nil {
return nil, err
}
return prophecy.Status, nil
}
func (o *Oracle) checkActiveValidator(validatorAddress string) bool {
validatorMap, err := o.GetValidatorArray()
if err != nil {
return false
}
for _, v := range validatorMap.Validators {
if v.Address == validatorAddress {
return true
}
}
return false
}
// 计算该prophecy是否达标
func (o *Oracle) processCompletion(prophecy *x2eTy.ReceiptEthProphecy, claimType int64) (*x2eTy.ReceiptEthProphecy, error) {
address2power := make(map[string]int64)
validatorArrays, err := o.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 := o.GetLastTotalPower()
if err != nil {
return nil, err
}
highestConsensusRatio := highestClaimPower * 100
remainingPossibleClaimPower := totalPower - totalClaimsPower
highestPossibleClaimPower := highestClaimPower + remainingPossibleClaimPower
highestPossibleConsensusRatio := highestPossibleClaimPower * 100
elog.Info("processCompletion", "highestConsensusRatio", highestConsensusRatio/totalPower, "ConsensusThreshold", o.consensusThreshold, "highestPossibleConsensusRatio", highestPossibleConsensusRatio/totalPower)
if highestConsensusRatio >= o.consensusThreshold*totalPower {
prophecy.Status.Text = x2eTy.EthBridgeStatus_SuccessStatusText
prophecy.Status.FinalClaim = highestClaim
} else if highestPossibleConsensusRatio < o.consensusThreshold*totalPower {
prophecy.Status.Text = x2eTy.EthBridgeStatus_FailedStatusText
}
return prophecy, nil
}
// Load the last total validator power.
func (o *Oracle) GetLastTotalPower() (int64, error) {
b, err := o.db.Get(x2eTy.CalLastTotalPowerPrefix())
if err != nil && err != types.ErrNotFound {
return 0, err
} else if err == types.ErrNotFound {
return 0, nil
}
var powers x2eTy.ReceiptQueryTotalPower
err = types.Decode(b, &powers)
if err != nil {
return 0, types.ErrUnmarshal
}
return powers.TotalPower, nil
}
// Set the last total validator power.
func (o *Oracle) SetLastTotalPower() error {
var totalPower int64
validatorArrays, err := o.GetValidatorArray()
if err != nil {
return err
}
for _, validator := range validatorArrays.Validators {
totalPower += validator.Power
}
totalP := x2eTy.ReceiptQueryTotalPower{
TotalPower: totalPower,
}
totalPBytes := types.Encode(&totalP)
err = o.db.Set(x2eTy.CalLastTotalPowerPrefix(), totalPBytes)
if err != nil {
return x2eTy.ErrSetKV
}
return nil
}
func (o *Oracle) GetValidatorArray() (*x2eTy.ValidatorList, error) {
validatorsBytes, err := o.db.Get(x2eTy.CalValidatorMapsPrefix())
if err != nil {
return nil, err
}
var validatorArrays x2eTy.ValidatorList
err = types.Decode(validatorsBytes, &validatorArrays)
if err != nil {
return nil, types.ErrUnmarshal
}
return &validatorArrays, nil
}
func (o *Oracle) SetConsensusThreshold(ConsensusThreshold int64) {
o.consensusThreshold = ConsensusThreshold
elog.Info("SetConsensusNeeded", "nowConsensusNeeded", o.consensusThreshold)
return
}
func (o *Oracle) GetConsensusThreshold() int64 {
return o.consensusThreshold
}
...@@ -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 = 10; int32 ty = 12;
} }
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 EthSymbol = 5; string IssuerDotSymbol = 5;
int64 Decimals = 6; int64 Decimals = 6;
} }
......
...@@ -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)
......
...@@ -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.
......
...@@ -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
}
...@@ -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"
} }
...@@ -6,11 +6,10 @@ package types ...@@ -6,11 +6,10 @@ package types
import ( import (
context "context" context "context"
fmt "fmt" fmt "fmt"
math "math"
types "github.com/33cn/chain33/types" types "github.com/33cn/chain33/types"
proto "github.com/golang/protobuf/proto" proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
math "math"
) )
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
...@@ -63,8 +62,10 @@ type X2EthereumAction struct { ...@@ -63,8 +62,10 @@ type X2EthereumAction struct {
// *X2EthereumAction_ModifyPower // *X2EthereumAction_ModifyPower
// *X2EthereumAction_SetConsensusThreshold // *X2EthereumAction_SetConsensusThreshold
// *X2EthereumAction_Transfer // *X2EthereumAction_Transfer
// *X2EthereumAction_TransferToExec
// *X2EthereumAction_Withdraw
Value isX2EthereumAction_Value `protobuf_oneof:"value"` Value isX2EthereumAction_Value `protobuf_oneof:"value"`
Ty int32 `protobuf:"varint,10,opt,name=ty,proto3" json:"ty,omitempty"` Ty int32 `protobuf:"varint,12,opt,name=ty,proto3" json:"ty,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"` XXX_sizecache int32 `json:"-"`
...@@ -135,6 +136,14 @@ type X2EthereumAction_Transfer struct { ...@@ -135,6 +136,14 @@ type X2EthereumAction_Transfer struct {
Transfer *types.AssetsTransfer `protobuf:"bytes,9,opt,name=transfer,proto3,oneof"` Transfer *types.AssetsTransfer `protobuf:"bytes,9,opt,name=transfer,proto3,oneof"`
} }
type X2EthereumAction_TransferToExec struct {
TransferToExec *types.AssetsTransferToExec `protobuf:"bytes,10,opt,name=transferToExec,proto3,oneof"`
}
type X2EthereumAction_Withdraw struct {
Withdraw *types.AssetsWithdraw `protobuf:"bytes,11,opt,name=withdraw,proto3,oneof"`
}
func (*X2EthereumAction_Eth2Chain33) isX2EthereumAction_Value() {} func (*X2EthereumAction_Eth2Chain33) isX2EthereumAction_Value() {}
func (*X2EthereumAction_WithdrawEth) isX2EthereumAction_Value() {} func (*X2EthereumAction_WithdrawEth) isX2EthereumAction_Value() {}
...@@ -153,6 +162,10 @@ func (*X2EthereumAction_SetConsensusThreshold) isX2EthereumAction_Value() {} ...@@ -153,6 +162,10 @@ func (*X2EthereumAction_SetConsensusThreshold) isX2EthereumAction_Value() {}
func (*X2EthereumAction_Transfer) isX2EthereumAction_Value() {} func (*X2EthereumAction_Transfer) isX2EthereumAction_Value() {}
func (*X2EthereumAction_TransferToExec) isX2EthereumAction_Value() {}
func (*X2EthereumAction_Withdraw) isX2EthereumAction_Value() {}
func (m *X2EthereumAction) GetValue() isX2EthereumAction_Value { func (m *X2EthereumAction) GetValue() isX2EthereumAction_Value {
if m != nil { if m != nil {
return m.Value return m.Value
...@@ -223,6 +236,20 @@ func (m *X2EthereumAction) GetTransfer() *types.AssetsTransfer { ...@@ -223,6 +236,20 @@ func (m *X2EthereumAction) GetTransfer() *types.AssetsTransfer {
return nil return nil
} }
func (m *X2EthereumAction) GetTransferToExec() *types.AssetsTransferToExec {
if x, ok := m.GetValue().(*X2EthereumAction_TransferToExec); ok {
return x.TransferToExec
}
return nil
}
func (m *X2EthereumAction) GetWithdraw() *types.AssetsWithdraw {
if x, ok := m.GetValue().(*X2EthereumAction_Withdraw); ok {
return x.Withdraw
}
return nil
}
func (m *X2EthereumAction) GetTy() int32 { func (m *X2EthereumAction) GetTy() int32 {
if m != nil { if m != nil {
return m.Ty return m.Ty
...@@ -242,6 +269,8 @@ func (*X2EthereumAction) XXX_OneofWrappers() []interface{} { ...@@ -242,6 +269,8 @@ func (*X2EthereumAction) XXX_OneofWrappers() []interface{} {
(*X2EthereumAction_ModifyPower)(nil), (*X2EthereumAction_ModifyPower)(nil),
(*X2EthereumAction_SetConsensusThreshold)(nil), (*X2EthereumAction_SetConsensusThreshold)(nil),
(*X2EthereumAction_Transfer)(nil), (*X2EthereumAction_Transfer)(nil),
(*X2EthereumAction_TransferToExec)(nil),
(*X2EthereumAction_Withdraw)(nil),
} }
} }
...@@ -336,8 +365,7 @@ type Eth2Chain33 struct { ...@@ -336,8 +365,7 @@ type Eth2Chain33 struct {
EthereumChainID int64 `protobuf:"varint,1,opt,name=EthereumChainID,proto3" json:"EthereumChainID,omitempty"` EthereumChainID int64 `protobuf:"varint,1,opt,name=EthereumChainID,proto3" json:"EthereumChainID,omitempty"`
BridgeContractAddress string `protobuf:"bytes,2,opt,name=BridgeContractAddress,proto3" json:"BridgeContractAddress,omitempty"` BridgeContractAddress string `protobuf:"bytes,2,opt,name=BridgeContractAddress,proto3" json:"BridgeContractAddress,omitempty"`
Nonce int64 `protobuf:"varint,3,opt,name=Nonce,proto3" json:"Nonce,omitempty"` Nonce int64 `protobuf:"varint,3,opt,name=Nonce,proto3" json:"Nonce,omitempty"`
LocalCoinSymbol string `protobuf:"bytes,4,opt,name=localCoinSymbol,proto3" json:"localCoinSymbol,omitempty"` IssuerDotSymbol string `protobuf:"bytes,4,opt,name=IssuerDotSymbol,proto3" json:"IssuerDotSymbol,omitempty"`
LocalCoinExec string `protobuf:"bytes,5,opt,name=localCoinExec,proto3" json:"localCoinExec,omitempty"`
TokenContractAddress string `protobuf:"bytes,6,opt,name=TokenContractAddress,proto3" json:"TokenContractAddress,omitempty"` TokenContractAddress string `protobuf:"bytes,6,opt,name=TokenContractAddress,proto3" json:"TokenContractAddress,omitempty"`
EthereumSender string `protobuf:"bytes,7,opt,name=EthereumSender,proto3" json:"EthereumSender,omitempty"` EthereumSender string `protobuf:"bytes,7,opt,name=EthereumSender,proto3" json:"EthereumSender,omitempty"`
Chain33Receiver string `protobuf:"bytes,8,opt,name=Chain33Receiver,proto3" json:"Chain33Receiver,omitempty"` Chain33Receiver string `protobuf:"bytes,8,opt,name=Chain33Receiver,proto3" json:"Chain33Receiver,omitempty"`
...@@ -396,16 +424,9 @@ func (m *Eth2Chain33) GetNonce() int64 { ...@@ -396,16 +424,9 @@ func (m *Eth2Chain33) GetNonce() int64 {
return 0 return 0
} }
func (m *Eth2Chain33) GetLocalCoinSymbol() string { func (m *Eth2Chain33) GetIssuerDotSymbol() string {
if m != nil { if m != nil {
return m.LocalCoinSymbol return m.IssuerDotSymbol
}
return ""
}
func (m *Eth2Chain33) GetLocalCoinExec() string {
if m != nil {
return m.LocalCoinExec
} }
return "" return ""
} }
...@@ -529,8 +550,7 @@ type Chain33ToEth struct { ...@@ -529,8 +550,7 @@ type Chain33ToEth struct {
Chain33Sender string `protobuf:"bytes,2,opt,name=Chain33Sender,proto3" json:"Chain33Sender,omitempty"` Chain33Sender string `protobuf:"bytes,2,opt,name=Chain33Sender,proto3" json:"Chain33Sender,omitempty"`
EthereumReceiver string `protobuf:"bytes,3,opt,name=EthereumReceiver,proto3" json:"EthereumReceiver,omitempty"` EthereumReceiver string `protobuf:"bytes,3,opt,name=EthereumReceiver,proto3" json:"EthereumReceiver,omitempty"`
Amount string `protobuf:"bytes,4,opt,name=Amount,proto3" json:"Amount,omitempty"` Amount string `protobuf:"bytes,4,opt,name=Amount,proto3" json:"Amount,omitempty"`
LocalCoinSymbol string `protobuf:"bytes,5,opt,name=localCoinSymbol,proto3" json:"localCoinSymbol,omitempty"` IssuerDotSymbol string `protobuf:"bytes,5,opt,name=IssuerDotSymbol,proto3" json:"IssuerDotSymbol,omitempty"`
LocalCoinExec string `protobuf:"bytes,6,opt,name=localCoinExec,proto3" json:"localCoinExec,omitempty"`
Decimals int64 `protobuf:"varint,7,opt,name=Decimals,proto3" json:"Decimals,omitempty"` Decimals int64 `protobuf:"varint,7,opt,name=Decimals,proto3" json:"Decimals,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
...@@ -590,16 +610,9 @@ func (m *Chain33ToEth) GetAmount() string { ...@@ -590,16 +610,9 @@ func (m *Chain33ToEth) GetAmount() string {
return "" return ""
} }
func (m *Chain33ToEth) GetLocalCoinSymbol() string { func (m *Chain33ToEth) GetIssuerDotSymbol() string {
if m != nil {
return m.LocalCoinSymbol
}
return ""
}
func (m *Chain33ToEth) GetLocalCoinExec() string {
if m != nil { if m != nil {
return m.LocalCoinExec return m.IssuerDotSymbol
} }
return "" return ""
} }
...@@ -616,9 +629,8 @@ type ReceiptEth2Chain33 struct { ...@@ -616,9 +629,8 @@ type ReceiptEth2Chain33 struct {
EthereumChainID int64 `protobuf:"varint,1,opt,name=EthereumChainID,proto3" json:"EthereumChainID,omitempty"` EthereumChainID int64 `protobuf:"varint,1,opt,name=EthereumChainID,proto3" json:"EthereumChainID,omitempty"`
BridgeContractAddress string `protobuf:"bytes,2,opt,name=BridgeContractAddress,proto3" json:"BridgeContractAddress,omitempty"` BridgeContractAddress string `protobuf:"bytes,2,opt,name=BridgeContractAddress,proto3" json:"BridgeContractAddress,omitempty"`
Nonce int64 `protobuf:"varint,3,opt,name=Nonce,proto3" json:"Nonce,omitempty"` Nonce int64 `protobuf:"varint,3,opt,name=Nonce,proto3" json:"Nonce,omitempty"`
LocalCoinSymbol string `protobuf:"bytes,4,opt,name=localCoinSymbol,proto3" json:"localCoinSymbol,omitempty"` IssuerDotSymbol string `protobuf:"bytes,4,opt,name=IssuerDotSymbol,proto3" json:"IssuerDotSymbol,omitempty"`
LocalCoinExec string `protobuf:"bytes,5,opt,name=localCoinExec,proto3" json:"localCoinExec,omitempty"` TokenAddress string `protobuf:"bytes,5,opt,name=TokenAddress,proto3" json:"TokenAddress,omitempty"`
TokenContractAddress string `protobuf:"bytes,6,opt,name=TokenContractAddress,proto3" json:"TokenContractAddress,omitempty"`
EthereumSender string `protobuf:"bytes,7,opt,name=EthereumSender,proto3" json:"EthereumSender,omitempty"` EthereumSender string `protobuf:"bytes,7,opt,name=EthereumSender,proto3" json:"EthereumSender,omitempty"`
Chain33Receiver string `protobuf:"bytes,8,opt,name=Chain33Receiver,proto3" json:"Chain33Receiver,omitempty"` Chain33Receiver string `protobuf:"bytes,8,opt,name=Chain33Receiver,proto3" json:"Chain33Receiver,omitempty"`
ValidatorAddress string `protobuf:"bytes,9,opt,name=ValidatorAddress,proto3" json:"ValidatorAddress,omitempty"` ValidatorAddress string `protobuf:"bytes,9,opt,name=ValidatorAddress,proto3" json:"ValidatorAddress,omitempty"`
...@@ -679,23 +691,16 @@ func (m *ReceiptEth2Chain33) GetNonce() int64 { ...@@ -679,23 +691,16 @@ func (m *ReceiptEth2Chain33) GetNonce() int64 {
return 0 return 0
} }
func (m *ReceiptEth2Chain33) GetLocalCoinSymbol() string { func (m *ReceiptEth2Chain33) GetIssuerDotSymbol() string {
if m != nil {
return m.LocalCoinSymbol
}
return ""
}
func (m *ReceiptEth2Chain33) GetLocalCoinExec() string {
if m != nil { if m != nil {
return m.LocalCoinExec return m.IssuerDotSymbol
} }
return "" return ""
} }
func (m *ReceiptEth2Chain33) GetTokenContractAddress() string { func (m *ReceiptEth2Chain33) GetTokenAddress() string {
if m != nil { if m != nil {
return m.TokenContractAddress return m.TokenAddress
} }
return "" return ""
} }
...@@ -768,7 +773,7 @@ type ReceiptChain33ToEth struct { ...@@ -768,7 +773,7 @@ type ReceiptChain33ToEth struct {
Chain33Sender string `protobuf:"bytes,2,opt,name=Chain33Sender,proto3" json:"Chain33Sender,omitempty"` Chain33Sender string `protobuf:"bytes,2,opt,name=Chain33Sender,proto3" json:"Chain33Sender,omitempty"`
EthereumReceiver string `protobuf:"bytes,3,opt,name=EthereumReceiver,proto3" json:"EthereumReceiver,omitempty"` EthereumReceiver string `protobuf:"bytes,3,opt,name=EthereumReceiver,proto3" json:"EthereumReceiver,omitempty"`
Amount string `protobuf:"bytes,4,opt,name=Amount,proto3" json:"Amount,omitempty"` Amount string `protobuf:"bytes,4,opt,name=Amount,proto3" json:"Amount,omitempty"`
EthSymbol string `protobuf:"bytes,5,opt,name=EthSymbol,proto3" json:"EthSymbol,omitempty"` IssuerDotSymbol string `protobuf:"bytes,5,opt,name=IssuerDotSymbol,proto3" json:"IssuerDotSymbol,omitempty"`
Decimals int64 `protobuf:"varint,6,opt,name=Decimals,proto3" json:"Decimals,omitempty"` Decimals int64 `protobuf:"varint,6,opt,name=Decimals,proto3" json:"Decimals,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
...@@ -828,9 +833,9 @@ func (m *ReceiptChain33ToEth) GetAmount() string { ...@@ -828,9 +833,9 @@ func (m *ReceiptChain33ToEth) GetAmount() string {
return "" return ""
} }
func (m *ReceiptChain33ToEth) GetEthSymbol() string { func (m *ReceiptChain33ToEth) GetIssuerDotSymbol() string {
if m != nil { if m != nil {
return m.EthSymbol return m.IssuerDotSymbol
} }
return "" return ""
} }
...@@ -1924,92 +1929,93 @@ func init() { ...@@ -1924,92 +1929,93 @@ func init() {
} }
var fileDescriptor_1dd1834a817ceb21 = []byte{ var fileDescriptor_1dd1834a817ceb21 = []byte{
// 1346 bytes of a gzipped FileDescriptorProto // 1368 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x58, 0xcb, 0x6e, 0xdb, 0x46, 0x1f, 0x8b, 0x08, 0x00,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1a, 0xba, 0x0d, 0x12, 0x4d, 0x36, 0x6d, 0x01, 0xbb, 0xff, 0x5c, 0xbe, 0xa6, 0xf5, 0x05, 0x88, 0xba, 0x70, 0xf3,
0xbd, 0xc7, 0xc4, 0x0f, 0xa8, 0xab, 0xa0, 0x8d, 0x83, 0x2e, 0x40, 0xf1, 0xff, 0xd3, 0x79, 0x5b, 0x94, 0x86, 0xae, 0x1f, 0x9e, 0x27, 0x80, 0xd8, 0x87, 0x9d, 0x15, 0x01, 0x0f, 0xa7, 0x8e, 0x43,
0xfc, 0xaf, 0x74, 0xf8, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1f, 0xcd, 0x0e, 0x4f, 0x94, 0x12, 0xe3, 0x58, 0x83, 0x0d, 0x74, 0x1b, 0x3a, 0x4f, 0x88, 0x1f, 0x50, 0x57, 0x43, 0x6b, 0x7b, 0x6d,
0x00, 0x00, 0x80, 0xfc, 0x57, 0xa8, 0xb3, 0x55, 0xf9, 0xeb, 0xd2, 0xfe, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff,
0xa6, 0x2d, 0xf8, 0xf1, 0x9a, 0x12, 0x00, 0x00,
} }
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment