Commit 3d238249 authored by QM's avatar QM Committed by 33cn

add setWithdrawStatics

parent cfcea967
...@@ -25,7 +25,7 @@ func ShowStaticsFlags(cmd *cobra.Command) { ...@@ -25,7 +25,7 @@ func ShowStaticsFlags(cmd *cobra.Command) {
cmd.Flags().StringP("symbol", "s", "", "token symbol(optional)") cmd.Flags().StringP("symbol", "s", "", "token symbol(optional)")
cmd.Flags().Int32P("from", "f", 0, "source chain, 0=ethereum, and 1=chain33") cmd.Flags().Int32P("from", "f", 0, "source chain, 0=ethereum, and 1=chain33")
_ = cmd.MarkFlagRequired("from") _ = cmd.MarkFlagRequired("from")
cmd.Flags().Int32P("operation", "o", 0, "operation type, 1=burn, 2=lock, 3=withdraw") cmd.Flags().StringP("operation", "o", "b", "operation type, b=burn, l=lock, w=withdraw")
_ = cmd.MarkFlagRequired("operation") _ = cmd.MarkFlagRequired("operation")
cmd.Flags().Int32P("status", "u", 0, "show with specified status, default to show all, 1=pending, 2=successful, 3=failed") cmd.Flags().Int32P("status", "u", 0, "show with specified status, default to show all, 1=pending, 2=successful, 3=failed")
cmd.Flags().Int32P("count", "n", 0, "count to show, default to show all") cmd.Flags().Int32P("count", "n", 0, "count to show, default to show all")
...@@ -37,7 +37,7 @@ func ShowStatics(cmd *cobra.Command, args []string) { ...@@ -37,7 +37,7 @@ func ShowStatics(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr") rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
symbol, _ := cmd.Flags().GetString("symbol") symbol, _ := cmd.Flags().GetString("symbol")
from, _ := cmd.Flags().GetInt32("from") from, _ := cmd.Flags().GetInt32("from")
operation, _ := cmd.Flags().GetInt32("operation") operation, _ := cmd.Flags().GetString("operation")
status, _ := cmd.Flags().GetInt32("status") status, _ := cmd.Flags().GetInt32("status")
count, _ := cmd.Flags().GetInt32("count") count, _ := cmd.Flags().GetInt32("count")
index, _ := cmd.Flags().GetInt32("index") index, _ := cmd.Flags().GetInt32("index")
...@@ -47,8 +47,8 @@ func ShowStatics(cmd *cobra.Command, args []string) { ...@@ -47,8 +47,8 @@ func ShowStatics(cmd *cobra.Command, args []string) {
return return
} }
if operation != 2 && 1 != operation && operation != 3 { if operation != "b" && "l" != operation && operation != "w" {
fmt.Println("Pls set correct operation type, 1=burn, 2=lock, 3=withdraw") fmt.Println("Pls set correct operation type, b=burn, l=lock, w=withdraw")
return return
} }
...@@ -57,10 +57,19 @@ func ShowStatics(cmd *cobra.Command, args []string) { ...@@ -57,10 +57,19 @@ func ShowStatics(cmd *cobra.Command, args []string) {
return return
} }
var operationInt int32
if operation == "b" {
operationInt = 1
} else if operation == "l" {
operationInt = 2
} else if operation == "w" {
operationInt = 3
}
para := &ebTypes.TokenStaticsRequest{ para := &ebTypes.TokenStaticsRequest{
Symbol: symbol, Symbol: symbol,
From: from, From: from,
Operation: operation, Operation: operationInt,
Status: status, Status: status,
TxIndex: int64(index), TxIndex: int64(index),
Count: count, Count: count,
......
...@@ -151,7 +151,7 @@ message Chain33ToEthereumStatics { ...@@ -151,7 +151,7 @@ message Chain33ToEthereumStatics {
string ethTxstatus = 1; string ethTxstatus = 1;
string chain33Txhash = 2; string chain33Txhash = 2;
string EthereumTxhash = 3; string EthereumTxhash = 3;
int32 burnLock = 4; int32 burnLockWithdraw = 4;
//该笔lock或者burn交易的chain33发起人 //该笔lock或者burn交易的chain33发起人
string chain33Sender = 5; string chain33Sender = 5;
string ethereumReceiver = 6; string ethereumReceiver = 6;
......
...@@ -579,6 +579,11 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33 ...@@ -579,6 +579,11 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
if nil != err { if nil != err {
relayerLog.Error("handleLogWithdraw", "Failed to setWithdraw due to:", err.Error()) relayerLog.Error("handleLogWithdraw", "Failed to setWithdraw due to:", err.Error())
} }
err = ethRelayer.setWithdrawStatics(withdrawTx, chain33Msg)
if nil != err {
relayerLog.Error("handleLogWithdraw", "Failed to setWithdrawStatics due to:", err.Error())
}
}() }()
relayerLog.Info("handleLogWithdraw", "Received chain33Msg", chain33Msg, "tx hash string", common.Bytes2Hex(chain33Msg.TxHash)) relayerLog.Info("handleLogWithdraw", "Received chain33Msg", chain33Msg, "tx hash string", common.Bytes2Hex(chain33Msg.TxHash))
...@@ -653,7 +658,8 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33 ...@@ -653,7 +658,8 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
} }
//校验余额是否充足 //校验余额是否充足
if ok, err := ethRelayer.checkBalanceEnough(toAddr, amount2transfer, balanceOfData); !ok { err = ethRelayer.checkBalanceEnough(toAddr, amount2transfer, balanceOfData)
if err != nil {
relayerLog.Error("handleLogWithdraw", "Failed to checkBalanceEnough:", err.Error()) relayerLog.Error("handleLogWithdraw", "Failed to checkBalanceEnough:", err.Error())
err = errors.New("ErrBalanceNotEnough") err = errors.New("ErrBalanceNotEnough")
return return
...@@ -687,40 +693,10 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33 ...@@ -687,40 +693,10 @@ func (ethRelayer *Relayer4Ethereum) handleLogWithdraw(chain33Msg *events.Chain33
withdrawTx.StatusDescription = ethtxs.WDPending.String() withdrawTx.StatusDescription = ethtxs.WDPending.String()
withdrawTx.TxHashOnEthereum = signedTx.Hash().String() withdrawTx.TxHashOnEthereum = signedTx.Hash().String()
txIndex := atomic.AddInt64(&ethRelayer.totalTxRelayFromChain33, 1)
operationType := chain33Msg.ClaimType.String()
statics := &ebTypes.Chain33ToEthereumStatics{
EthTxstatus: ebTypes.Tx_Status_Pending,
Chain33Txhash: common.Bytes2Hex(chain33Msg.TxHash),
EthereumTxhash: withdrawTx.TxHashOnEthereum,
BurnLock: int32(chain33Msg.ClaimType),
Chain33Sender: chain33Msg.Chain33Sender.String(),
EthereumReceiver: chain33Msg.EthereumReceiver.String(),
Symbol: chain33Msg.Symbol,
Amount: chain33Msg.Amount.String(),
Nonce: chain33Msg.Nonce,
TxIndex: txIndex,
OperationType: operationType,
}
data := chain33Types.Encode(statics)
if err = ethRelayer.setLastestStatics(int32(chain33Msg.ClaimType), txIndex, data); nil != err {
relayerLog.Error("handleLogLockBurn", "Failed to RelayLockToChain33 due to:", err.Error())
return
}
relayerLog.Info("RelayOracleClaimToEthereum::successful",
"txIndex", txIndex,
"Chain33Txhash", statics.Chain33Txhash,
"EthereumTxhash", statics.EthereumTxhash,
"type", operationType,
"Symbol", chain33Msg.Symbol,
"Amount", chain33Msg.Amount,
"EthereumReceiver", statics.EthereumReceiver,
"Chain33Sender", statics.Chain33Sender)
return return
} }
func (ethRelayer *Relayer4Ethereum) checkBalanceEnough(addr common.Address, amount *big.Int, inputdata []byte) (bool, error) { func (ethRelayer *Relayer4Ethereum) checkBalanceEnough(addr common.Address, amount *big.Int, inputdata []byte) error {
//检测地址余额 //检测地址余额
var balance *big.Int var balance *big.Int
var err error var err error
...@@ -730,7 +706,7 @@ func (ethRelayer *Relayer4Ethereum) checkBalanceEnough(addr common.Address, amou ...@@ -730,7 +706,7 @@ func (ethRelayer *Relayer4Ethereum) checkBalanceEnough(addr common.Address, amou
//retry //retry
balance, err = ethRelayer.clientSpec.BalanceAt(context.Background(), addr, nil) balance, err = ethRelayer.clientSpec.BalanceAt(context.Background(), addr, nil)
if err != nil { if err != nil {
return false, err return err
} }
} }
} else { } else {
...@@ -742,24 +718,22 @@ func (ethRelayer *Relayer4Ethereum) checkBalanceEnough(addr common.Address, amou ...@@ -742,24 +718,22 @@ func (ethRelayer *Relayer4Ethereum) checkBalanceEnough(addr common.Address, amou
//retry //retry
result, err = ethRelayer.clientSpec.CallContract(context.Background(), msg, nil) result, err = ethRelayer.clientSpec.CallContract(context.Background(), msg, nil)
if err != nil { if err != nil {
return false, err return err
} }
} }
var ok bool var ok bool
balance, ok = big.NewInt(1).SetString(common.Bytes2Hex(result), 16) balance, ok = big.NewInt(1).SetString(common.Bytes2Hex(result), 16)
if !ok { if !ok {
return false, errors.New(fmt.Sprintf("token balance err:%v", common.Bytes2Hex(result))) return errors.New(fmt.Sprintf("token balance err:%v", common.Bytes2Hex(result)))
} }
} }
//与要发动的金额大小进行比较 //与要发动的金额大小进行比较
if balance.Cmp(amount) > 0 { if balance.Cmp(amount) > 0 {
return true, nil return nil
} }
relayerLog.Error("Insufficient balance", "balance", balance, "amount", amount) relayerLog.Error("Insufficient balance", "balance", balance, "amount", amount)
return false, errors.New("Insufficient balance") return errors.New("Insufficient balance")
} }
func (ethRelayer *Relayer4Ethereum) signTx(tx *types.Transaction, key *ecdsa.PrivateKey) (*types.Transaction, error) { func (ethRelayer *Relayer4Ethereum) signTx(tx *types.Transaction, key *ecdsa.PrivateKey) (*types.Transaction, error) {
...@@ -880,7 +854,7 @@ func (ethRelayer *Relayer4Ethereum) handleLogLockBurn(chain33Msg *events.Chain33 ...@@ -880,7 +854,7 @@ func (ethRelayer *Relayer4Ethereum) handleLogLockBurn(chain33Msg *events.Chain33
EthTxstatus: ebTypes.Tx_Status_Pending, EthTxstatus: ebTypes.Tx_Status_Pending,
Chain33Txhash: common.Bytes2Hex(chain33Msg.TxHash), Chain33Txhash: common.Bytes2Hex(chain33Msg.TxHash),
EthereumTxhash: txhash, EthereumTxhash: txhash,
BurnLock: int32(chain33Msg.ClaimType), BurnLockWithdraw: int32(chain33Msg.ClaimType),
Chain33Sender: chain33Msg.Chain33Sender.String(), Chain33Sender: chain33Msg.Chain33Sender.String(),
EthereumReceiver: chain33Msg.EthereumReceiver.String(), EthereumReceiver: chain33Msg.EthereumReceiver.String(),
Symbol: chain33Msg.Symbol, Symbol: chain33Msg.Symbol,
......
...@@ -4,7 +4,9 @@ import ( ...@@ -4,7 +4,9 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/33cn/plugin/plugin/dapp/cross2eth/ebrelayer/relayer/ethereum/ethtxs"
"math/big" "math/big"
"sync/atomic"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -460,6 +462,32 @@ func (ethRelayer *Relayer4Ethereum) setWithdraw(withdrawTx *ebTypes.WithdrawTx) ...@@ -460,6 +462,32 @@ func (ethRelayer *Relayer4Ethereum) setWithdraw(withdrawTx *ebTypes.WithdrawTx)
return ethRelayer.db.Set(listKey, listData) return ethRelayer.db.Set(listKey, listData)
} }
func (ethRelayer *Relayer4Ethereum) setWithdrawStatics(withdrawTx *ebTypes.WithdrawTx, chain33Msg *events.Chain33Msg) error {
txIndex := atomic.AddInt64(&ethRelayer.totalTxRelayFromChain33, 1)
operationType := chain33Msg.ClaimType.String()
statics := &ebTypes.Chain33ToEthereumStatics{
EthTxstatus: ebTypes.Tx_Status_Pending,
Chain33Txhash: common.Bytes2Hex(chain33Msg.TxHash),
EthereumTxhash: withdrawTx.TxHashOnEthereum,
BurnLockWithdraw: int32(chain33Msg.ClaimType),
Chain33Sender: chain33Msg.Chain33Sender.String(),
EthereumReceiver: chain33Msg.EthereumReceiver.String(),
Symbol: chain33Msg.Symbol,
Amount: chain33Msg.Amount.String(),
Nonce: chain33Msg.Nonce,
TxIndex: txIndex,
OperationType: operationType,
}
if withdrawTx.Status == int32(ethtxs.WDError) {
statics.EthTxstatus = ebTypes.Tx_Status_Failed
}
relayerLog.Info("setWithdrawStatics::successful", "txIndex", txIndex, "Chain33Txhash", statics.Chain33Txhash, "EthereumTxhash", statics.EthereumTxhash, "type", operationType,
"Symbol", chain33Msg.Symbol, "Amount", chain33Msg.Amount, "EthereumReceiver", statics.EthereumReceiver, "Chain33Sender", statics.Chain33Sender)
data := chain33Types.Encode(statics)
return ethRelayer.setLastestStatics(int32(chain33Msg.ClaimType), txIndex, data)
}
func (ethRelayer *Relayer4Ethereum) getWithdrawsWithinSameDay(withdrawTx *ebTypes.WithdrawTx) (*big.Int, error) { func (ethRelayer *Relayer4Ethereum) getWithdrawsWithinSameDay(withdrawTx *ebTypes.WithdrawTx) (*big.Int, error) {
chain33Sender := withdrawTx.Chain33Sender chain33Sender := withdrawTx.Chain33Sender
symbol := withdrawTx.Symbol symbol := withdrawTx.Symbol
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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