Skip to content

Commit

Permalink
add evm listener
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcc committed Nov 23, 2023
1 parent 0dbf717 commit 6cc0d5f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions bitcoin/evm_listener_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (eis *EVMListenerService) OnStart() error {
btcSignal := make(chan struct{})
go func() {
for {
eis.Logger.Error("EVMListenerService btc rpc start...")
eis.Logger.Info("EVMListenerService btc rpc start...")
connCfg := &btcrpcclient.ConnConfig{
Host: fmt.Sprintf("%s:%s", eis.config.RPCHost, eis.config.RPCPort),
User: eis.config.RPCUser,
Expand All @@ -107,7 +107,7 @@ func (eis *EVMListenerService) OnStart() error {
continue
}
eis.btcCli = client
eis.Logger.Error("EVMListenerService btc rpc success...")
eis.Logger.Info("EVMListenerService btc rpc success...")
//defer client.Shutdown()

Check failure on line 111 in bitcoin/evm_listener_service.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
<-btcSignal
}
Expand Down Expand Up @@ -231,7 +231,7 @@ func (eis *EVMListenerService) transferToBtc(destAddrStr string, amount int64) e
switch networkName {
case "signet":
defaultNet = chaincfg.SigNetParams
case "testnet3":
case "testnet":
defaultNet = chaincfg.TestNet3Params
case "main":
defaultNet = chaincfg.MainNetParams
Expand All @@ -248,7 +248,7 @@ func (eis *EVMListenerService) transferToBtc(destAddrStr string, amount int64) e

unspentTxs, err := eis.btcCli.ListUnspentMinMaxAddresses(1, 9999999, []btcutil.Address{sourceAddr})
if err != nil {
eis.Logger.Error("ListUnspentMinMaxAddresses transferToBtc DecodeAddress failed: ", "err", err)
eis.Logger.Error("EVMListenerService ListUnspentMinMaxAddresses transferToBtc DecodeAddress failed: ", "err", err)
return err
}

Expand All @@ -266,12 +266,12 @@ func (eis *EVMListenerService) transferToBtc(destAddrStr string, amount int64) e
if changeAmount > 0 {
changeAddr, err := btcutil.DecodeAddress(sourceAddrStr, &defaultNet)
if err != nil {
eis.Logger.Error("ListUnspentMinMaxAddresses transferToBtc DecodeAddress sourceAddress failed: ", "err", err)
eis.Logger.Error("EVMListenerService transferToBtc DecodeAddress sourceAddress failed: ", "err", err)
return err
}
destAddr, err := btcutil.DecodeAddress(destAddrStr, &defaultNet)
if err != nil {
eis.Logger.Error("ListUnspentMinMaxAddresses transferToBtc DecodeAddress destAddress failed: ", "err", err)
eis.Logger.Error("EVMListenerService transferToBtc DecodeAddress destAddress failed: ", "err", err)
return err
}
outputs := map[btcutil.Address]btcutil.Amount{
Expand All @@ -281,28 +281,28 @@ func (eis *EVMListenerService) transferToBtc(destAddrStr string, amount int64) e
//eis.Logger.Info("ListUnspentMinMaxAddresses ", "changeAmount", changeAmount, "amount", amount, "totalInputAmount", totalInputAmount, "fee", eis.config.Fee)

Check failure on line 281 in bitcoin/evm_listener_service.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
rawTx, err := eis.btcCli.CreateRawTransaction(inputs, outputs, nil)
if err != nil {
eis.Logger.Error("ListUnspentMinMaxAddresses transferToBtc CreateRawTransaction failed: ", "err", err)
eis.Logger.Error("EVMListenerService transferToBtc CreateRawTransaction failed: ", "err", err)
return err
}

// sign
signedTx, complete, err := eis.btcCli.SignRawTransactionWithWallet(rawTx)
if err != nil {
eis.Logger.Error("ListUnspentMinMaxAddresses transferToBtc SignRawTransactionWithWallet failed: ", "err", err)
eis.Logger.Error("EVMListenerService transferToBtc SignRawTransactionWithWallet failed: ", "err", err)
return err
}
if !complete {
eis.Logger.Error("ListUnspentMinMaxAddresses transferToBtc SignRawTransactionWithWallet failed: ", "err", errors.New("SignRawTransaction not complete"))
eis.Logger.Error("EVMListenerService transferToBtc SignRawTransactionWithWallet failed: ", "err", errors.New("SignRawTransaction not complete"))
return errors.New("SignRawTransaction not complete")
}
// send
txHash, err := eis.btcCli.SendRawTransaction(signedTx, true)
if err != nil {
eis.Logger.Error("ListUnspentMinMaxAddresses transferToBtc SendRawTransaction failed: ", "err", err)
eis.Logger.Error("EVMListenerService transferToBtc SendRawTransaction failed: ", "err", err)
return err
}

eis.Logger.Info("ListUnspentMinMaxAddresses transferToBtc SendRawTransaction success: ", "fromAddress", sourceAddrStr, "toAddress", destAddrStr, "hash", txHash.String())
eis.Logger.Info("EVMListenerService transferToBtc SendRawTransaction success: ", "fromAddress", sourceAddrStr, "toAddress", destAddrStr, "hash", txHash.String())

return nil
}
Expand Down

0 comments on commit 6cc0d5f

Please sign in to comment.