Commit 36eed812 authored by vicotor's avatar vicotor

update code

parent e0bb6f74
......@@ -30,28 +30,28 @@ type ChainSync struct {
syncmode bool
}
func (s *ChainSync) ParseTransferOut(log types.Log) (*bridge.BridgeContractTransferOut, error) {
return s.bridgeCa.ParseTransferOut(log)
func (s *ChainSync) ParseTransferOut(log *types.Log) (*bridge.BridgeContractTransferOut, error) {
return s.bridgeCa.ParseTransferOut(*log)
}
func (s *ChainSync) ParseTransferIn(log types.Log) (*bridge.BridgeContractTransferIn, error) {
return s.bridgeCa.ParseTransferIn(log)
func (s *ChainSync) ParseTransferIn(log *types.Log) (*bridge.BridgeContractTransferIn, error) {
return s.bridgeCa.ParseTransferIn(*log)
}
func (s *ChainSync) ParseTransferInExecution(log types.Log) (*bridge.BridgeContractTransferInExecution, error) {
return s.bridgeCa.ParseTransferInExecution(log)
func (s *ChainSync) ParseTransferInExecution(log *types.Log) (*bridge.BridgeContractTransferInExecution, error) {
return s.bridgeCa.ParseTransferInExecution(*log)
}
func (s *ChainSync) ParseTransferInRejection(log types.Log) (*bridge.BridgeContractTransferInRejection, error) {
return s.bridgeCa.ParseTransferInRejection(log)
func (s *ChainSync) ParseTransferInRejection(log *types.Log) (*bridge.BridgeContractTransferInRejection, error) {
return s.bridgeCa.ParseTransferInRejection(*log)
}
func (s *ChainSync) ParseTransferInConfirmation(log types.Log) (*bridge.BridgeContractTransferInConfirmation, error) {
return s.bridgeCa.ParseTransferInConfirmation(log)
func (s *ChainSync) ParseTransferInConfirmation(log *types.Log) (*bridge.BridgeContractTransferInConfirmation, error) {
return s.bridgeCa.ParseTransferInConfirmation(*log)
}
func (s *ChainSync) ParseTokenConfigChanged(log types.Log) (*bridge.BridgeContractTokenConfigChanged, error) {
return s.bridgeCa.ParseTokenConfigChanged(log)
func (s *ChainSync) ParseTokenConfigChanged(log *types.Log) (*bridge.BridgeContractTokenConfigChanged, error) {
return s.bridgeCa.ParseTokenConfigChanged(*log)
}
func (s *ChainSync) GetReceiveToken(token common.Address, toChainId int64) (string, error) {
......
......@@ -17,12 +17,12 @@ type ChainInterface interface {
Name() string
GetChain() *config.ChainConfig
IsSyncing() bool
ParseTransferOut(log types.Log) (*bridge.BridgeContractTransferOut, error)
ParseTransferIn(log types.Log) (*bridge.BridgeContractTransferIn, error)
ParseTransferInExecution(log types.Log) (*bridge.BridgeContractTransferInExecution, error)
ParseTransferInRejection(log types.Log) (*bridge.BridgeContractTransferInRejection, error)
ParseTransferInConfirmation(log types.Log) (*bridge.BridgeContractTransferInConfirmation, error)
ParseTokenConfigChanged(log types.Log) (*bridge.BridgeContractTokenConfigChanged, error)
ParseTransferOut(log *types.Log) (*bridge.BridgeContractTransferOut, error)
ParseTransferIn(log *types.Log) (*bridge.BridgeContractTransferIn, error)
ParseTransferInExecution(log *types.Log) (*bridge.BridgeContractTransferInExecution, error)
ParseTransferInRejection(log *types.Log) (*bridge.BridgeContractTransferInRejection, error)
ParseTransferInConfirmation(log *types.Log) (*bridge.BridgeContractTransferInConfirmation, error)
ParseTokenConfigChanged(log *types.Log) (*bridge.BridgeContractTokenConfigChanged, error)
GetReceiveToken(token common.Address, toChainId int64) (string, error)
}
......@@ -42,6 +42,26 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
cname := chain.Name()
// refetch all logs
var txs []common.Hash
var txexist = make(map[common.Hash]bool)
for _, lg := range logs {
if _, ok := txexist[lg.TxHash]; !ok {
txs = append(txs, lg.TxHash)
txexist[lg.TxHash] = true
}
}
var allLogs []*types.Log
client := s.chainGroup[chain.GetChain().ChainId].cli
for _, tx := range txs {
receipt, err := client.TransactionReceipt(context.Background(), tx)
if err != nil {
log.WithField("chain", cname).WithError(err).Error("get tx receipt failed")
return err
}
allLogs = append(allLogs, receipt.Logs...)
}
// begin orm transaction
//supportSession := s.SupportsTransactions()
var ctx context.Context = context.Background()
......@@ -60,7 +80,7 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
//}
var ormTxErr error
for _, txLog := range logs {
for _, txLog := range allLogs {
if err := s.filterTransferOut(chain, txLog, ctx); err != nil {
ormTxErr = err
break
......@@ -100,7 +120,7 @@ func (s *Dao) HandleEvents(chain ChainInterface, logs []types.Log) error {
}
// filterTransferOut 用户从当前链跨出事件.
func (s *Dao) filterTransferOut(chain ChainInterface, txLog types.Log, ctx context.Context) error {
func (s *Dao) filterTransferOut(chain ChainInterface, txLog *types.Log, ctx context.Context) error {
if len(txLog.Topics) == 0 {
return nil
}
......@@ -137,7 +157,7 @@ func (s *Dao) filterTransferOut(chain ChainInterface, txLog types.Log, ctx conte
}
// filterTransferIn 用户从目标链跨入事件及执行结束事件.
func (s *Dao) filterTransferIn(chain ChainInterface, txLog types.Log, ctx context.Context) error {
func (s *Dao) filterTransferIn(chain ChainInterface, txLog *types.Log, ctx context.Context) error {
if len(txLog.Topics) == 0 {
return nil
}
......@@ -270,7 +290,7 @@ func (s *Dao) filterTransferIn(chain ChainInterface, txLog types.Log, ctx contex
return nil
}
func (s *Dao) filterTokenConfigChanged(chain ChainInterface, txLog types.Log, ctx context.Context) error {
func (s *Dao) filterTokenConfigChanged(chain ChainInterface, txLog *types.Log, ctx context.Context) error {
if len(txLog.Topics) == 0 {
return nil
}
......
......@@ -14,6 +14,42 @@ func (h *Height) TableName() string {
return "heights"
}
type TransferOutEvent struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
FromChain int64 `bson:"from_chain"`
OutTimestamp int64 `bson:"out_timestamp"`
FromToken string `bson:"from_token"`
FromAddress string `bson:"from_address"`
FromChainTxHash string `bson:"from_chain_tx_hash"`
SendAmount string `bson:"send_amount"`
FeeAmount string `bson:"fee_amount"`
Receiver string `bson:"receiver"`
ToChain int64 `bson:"to_chain"`
ToToken string `bson:"to_token"`
ReceiveAmount string `bson:"receive_amount"`
OutId int64 `bson:"out_id"`
}
func (t *TransferOutEvent) TableName() string {
return "transfer_out_events"
}
type TransferInEvent struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
ChainId int64 `bson:"chain_id"`
InTimestamp int64 `bson:"in_timestamp"`
InId int64 `bson:"in_id"`
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 (t *TransferInEvent) TableName() string {
return "transfer_in_events"
}
type BridgeEvent struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
FromChain int64 `bson:"from_chain"`
......
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