Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
goalongway committed Sep 26, 2024
1 parent 499ab80 commit ab7db5a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
8 changes: 4 additions & 4 deletions applications/internal/serves/listener/bitcoin/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func (l *BitcoinListener) handleMessage(deposit models.Deposit) error {
} else if err != nil && err.Error() == "AAGetBTCAccount not found" {
err = l.db.Model(models.Deposit{}).
Where("id=?", deposit.Id).
Update("status", enums.MessageStatusInvalid).Error
Update("status", enums.DepositStatusInvalid).Error
return nil
}

Expand All @@ -631,7 +631,7 @@ func (l *BitcoinListener) handleMessage(deposit models.Deposit) error {
} else {
err = l.db.Model(models.Deposit{}).
Where("id=?", deposit.Id).
Update("status", enums.MessageStatusInvalid).Error
Update("status", enums.DepositStatusInvalid).Error
return nil
}
msg := models.Message{
Expand Down Expand Up @@ -665,12 +665,12 @@ func (l *BitcoinListener) handleMessage(deposit models.Deposit) error {
if deposit.BtcFromEvmAddress != "" {
err = tx.Model(models.Deposit{}).
Where("id=?", deposit.Id).
Update("status", enums.MessageStatusValid).Error
Update("status", enums.DepositStatusValid).Error
} else {
err = tx.Model(models.Deposit{}).
Where("id=?", deposit.Id).
Update("btc_from_aa_address", depositAddress).
Update("status", enums.MessageStatusValid).Error
Update("status", enums.DepositStatusValid).Error
}
if err != nil {
l.logger.Errorf("update deposit failed: %s", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion applications/internal/serves/proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (p *Proposer) send(message models.Message) error {
} else {
chainParams = &chaincfg.TestNet3Params
}
verify, err := tx.VerifyBtcTx(p.client.BtcRpc, chainParams, p.particle, p.conf.ListenAddress, message.TxHash, message.FromId, message.ToBytes)
verify, err := tx.VerifyBtcTx(p.client.BtcRpc, chainParams, p.particle, message.FromMessageBridge, message.TxHash, message.FromId, message.ToBytes)
if err != nil {
p.logger.Errorf("verify btc tx err: %s", err)
return err
Expand Down
41 changes: 20 additions & 21 deletions applications/internal/utils/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func VerifyEthTx(rpc *ethclient.Client, txHash string, logIndex int64, fromMessa
}

func VerifyBtcTx(rpc *rpcclient.Client, chainParams *chaincfg.Params, particle config.Particle, listenAddress string, txHash string, fromId string, data string) (bool, error) {
_txHash, err := chainhash.NewHashFromStr(txHash)
_txHash, err := chainhash.NewHashFromStr(txHash[2:])
if err != nil {
return false, err
}
Expand All @@ -63,32 +63,34 @@ func VerifyBtcTx(rpc *rpcclient.Client, chainParams *chaincfg.Params, particle c
return false, err
}
txResult := tx.MsgTx()

_listenAddress, err := btcutil.DecodeAddress(listenAddress, chainParams)
if err != nil {
return false, err
}

var totalValue int64
var depositAddress string
for _, v := range txResult.TxOut {
pkAddress, err := parseAddress(chainParams, v.PkScript)
if err != nil && errors.Is(err, ErrParsePkScript) {
continue
} else if err != nil && errors.Is(err, ErrParsePkScriptNullData) {
nullData, err := parseNullData(v.PkScript)
if err != nil {
continue
}
evmAddress, err := parseEvmAddress(nullData)
if err != nil {
if err != nil {
if errors.Is(err, ErrParsePkScript) {
continue
}
if depositAddress != "" {
depositAddress = evmAddress
if errors.Is(err, ErrParsePkScriptNullData) {
nullData, err := parseNullData(v.PkScript)
if err != nil {
continue
}
evmAddress, err := parseEvmAddress(nullData)
if err != nil {
continue
}
fmt.Println("evmAddress:", evmAddress)
if depositAddress == "" {
depositAddress = evmAddress
}
} else {
return false, err
}
} else if err != nil {
return false, err
}
if pkAddress == _listenAddress.EncodeAddress() {
totalValue += v.Value
Expand All @@ -101,20 +103,17 @@ func VerifyBtcTx(rpc *rpcclient.Client, chainParams *chaincfg.Params, particle c
if len(fromAddress) == 0 {
return false, errors.New("fromAddress invalid")
}
if depositAddress != "" {
if depositAddress == "" {
_depositAddress, err := getAADepositAddress(particle, fromAddress[0].Address)
if err != nil {
return false, err
}
depositAddress = _depositAddress
}

_data := message.EncodeSendData(txResult.TxHash().String(), fromAddress[0].Address, depositAddress, decimal.New(totalValue, 0))

if common.HexToHash(fromId) == common.HexToHash(txHash) && data == hex.EncodeToString(_data) {
if common.HexToHash(fromId) == common.HexToHash(txHash) && data == "0x"+hex.EncodeToString(_data) {
return true, nil
}

return false, nil
}

Expand Down

0 comments on commit ab7db5a

Please sign in to comment.