Commit 41e28bc3 authored by vicotor's avatar vicotor

update code

parent 16675e84
......@@ -203,7 +203,7 @@ func (s *ChainSync) SyncLogs(beginHeight, endHeight int64) error {
topics := []string{
dao.TransferOutEvent.ID.Hex(),
dao.TransferInEvent.ID.Hex(),
//dao.TransferInConfirmationEvent.ID.Hex(),
dao.TransferInConfirmationEvent.ID.Hex(),
dao.TransferInRejectionEvent.ID.Hex(),
dao.TransferInExecutionEvent.ID.Hex(),
dao.TokenConfigChangedEvent.ID.Hex(),
......
......@@ -159,7 +159,6 @@ func (s *Dao) filterTransferIn(chain ChainInterface, txLog types.Log, ctx contex
ToToken: strings.ToLower(event.Token.String()),
ReceiveAmount: event.Amount.Text(10),
ToChainStatus: int(TransferChainWaitConfirm),
ToContract: strings.ToLower(txLog.Address.String()),
InTimestamp: int64(blocktime),
ToChain: chain.GetChain().ChainId,
......@@ -186,12 +185,26 @@ func (s *Dao) filterTransferIn(chain ChainInterface, txLog types.Log, ctx contex
}).Error("db update transfer in execution event")
return err
}
case TransferInConfirmationEvent.ID.Hex():
event, err := chain.ParseTransferInConfirmation(txLog)
if err != nil {
log.WithField("chain", chain.Name()).WithError(err).Error("parse TransferInConfirmation log")
return err
}
if err := s.AddValidatorOp(ctx, chain.GetChain().ChainId, event.InId.Int64(), strings.ToLower(event.Validator.String()), true); err != nil {
log.WithField("chain", chain.Name()).WithError(err).Error("add validator op failed")
return err
}
case TransferInRejectionEvent.ID.Hex():
event, err := chain.ParseTransferInRejection(txLog)
if err != nil {
log.WithField("chain", chain.Name()).WithError(err).Error("parse TransferInExecution log")
return err
}
if err := s.AddValidatorOp(ctx, chain.GetChain().ChainId, event.InId.Int64(), strings.ToLower(event.Validator.String()), false); err != nil {
log.WithField("chain", chain.Name()).WithError(err).Error("add validator op failed")
return err
}
if err := s.UpdateBridgeResult(ctx, chain.GetChain().ChainId, event.InId.Int64(), TransferChainRejected, txLog.TxHash); err != nil {
log.WithField("chain", chain.Name()).WithFields(log.Fields{
"error": err.Error(),
......
......@@ -166,6 +166,8 @@ func (d *Dao) GetHistoryInfo(user string) (history apiModel.History, err error)
UrlSource: fromChain.Explorer + "/tx/" + event.FromChainTxHash,
Status: constant.TransferStatus(event.ToChainStatus).String(),
ConfirmCount: len(event.ConfirmedValidators),
RejectCount: len(event.RejectedValidators),
}
if event.ToChainStatus <= int(constant.TransferChainWaitConfirm) {
pendingHistory = append(pendingHistory, record)
......
......@@ -115,6 +115,29 @@ func (d *Dao) FillOutTransferEventInfo(ctx context.Context, outEvent *dbModel.Br
return err
}
func (s *Dao) AddValidatorOp(ctx context.Context, toChainId int64, inId int64, validator string, isConfirmed bool) error {
collection := s.db.Collection("bridge_events")
var update bson.M
if isConfirmed {
update = bson.M{
"$addToSet": bson.M{
"confirmed_validators": validator,
},
}
} else {
update = bson.M{
"$addToSet": bson.M{
"rejected_validators": validator,
},
}
}
filter := bson.M{"to_chain": toChainId, "in_id": inId}
_, err := collection.UpdateOne(ctx, filter, update)
return err
}
func (d *Dao) UpdateBridgeResult(ctx context.Context, toChainId int64, inId int64, result constant.TransferStatus, txhash common.Hash) error {
collection := d.db.Collection(new(dbModel.BridgeEvent).TableName())
......
......@@ -30,6 +30,8 @@ type HistoryInfo struct {
TokenSymbol string `json:"token_symbol" bson:"token_symbol"`
UrlTarget string `json:"url_target" bson:"url_target"`
Status string `json:"status" bson:"status"`
ConfirmCount int `json:"confirm_count" bson:"confirm_count"`
RejectCount int `json:"reject_count" bson:"reject_count"`
}
type History struct {
......
......@@ -33,6 +33,8 @@ type BridgeEvent struct {
ToContract string `bson:"to_contract"`
ToChainTxHash string `bson:"to_chain_tx_hash"`
ToChainStatus int `bson:"to_chain_status"`
ConfirmedValidators []string `bson:"confirmed_validators"`
RejectedValidators []string `bson:"rejected_validators"`
}
func (b *BridgeEvent) TableName() string {
......
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