From bc93de811c5599fb413afc691bd140d22d244387 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 4 Jan 2024 15:08:27 -0500 Subject: [PATCH 01/12] add checks for params --- common/chain.go | 3 +++ .../orchestrator/smoketest/runner/setup_zeta.go | 3 +++ x/crosschain/keeper/btc_decode_test.go | 16 ++++++++++++++++ x/crosschain/keeper/evm_hooks.go | 3 +++ zetaclient/bitcoin_client.go | 3 +++ zetaclient/btc_signer.go | 4 ++++ 6 files changed, 32 insertions(+) create mode 100644 x/crosschain/keeper/btc_decode_test.go diff --git a/common/chain.go b/common/chain.go index fe19b302bf..1f409add12 100644 --- a/common/chain.go +++ b/common/chain.go @@ -52,6 +52,9 @@ func (chain Chain) EncodeAddress(b []byte) (string, error) { if err != nil { return "", err } + if chainParams == nil { + return "", fmt.Errorf("chain params not found") + } addr, err := btcutil.DecodeAddress(addrStr, chainParams) if err != nil { return "", err diff --git a/contrib/localnet/orchestrator/smoketest/runner/setup_zeta.go b/contrib/localnet/orchestrator/smoketest/runner/setup_zeta.go index 1a04830556..76761c3a3b 100644 --- a/contrib/localnet/orchestrator/smoketest/runner/setup_zeta.go +++ b/contrib/localnet/orchestrator/smoketest/runner/setup_zeta.go @@ -38,6 +38,9 @@ func (sm *SmokeTestRunner) SetTSSAddresses() { } tssAddress := ethcommon.HexToAddress(res.Eth) + if common.BitcoinRegnetParams == nil { + return + } btcTSSAddress, err := btcutil.DecodeAddress(res.Btc, common.BitcoinRegnetParams) if err != nil { panic(err) diff --git a/x/crosschain/keeper/btc_decode_test.go b/x/crosschain/keeper/btc_decode_test.go new file mode 100644 index 0000000000..5aff452622 --- /dev/null +++ b/x/crosschain/keeper/btc_decode_test.go @@ -0,0 +1,16 @@ +package keeper_test + +import ( + "testing" + + "github.com/btcsuite/btcutil" + "github.com/stretchr/testify/assert" + "github.com/zeta-chain/zetacore/common" +) + +func TestIsDecode(t *testing.T) { + params, err := common.GetBTCChainParams(18332) + assert.NoError(t, err) + _, err = btcutil.DecodeAddress("14CEjTd5ci3228J45GdnGeUKLSSeCWUQxK", params) + assert.NoError(t, err) +} diff --git a/x/crosschain/keeper/evm_hooks.go b/x/crosschain/keeper/evm_hooks.go index 92fa5ffad5..1c28114625 100644 --- a/x/crosschain/keeper/evm_hooks.go +++ b/x/crosschain/keeper/evm_hooks.go @@ -292,6 +292,9 @@ func (k Keeper) ParseZRC20WithdrawalEvent(ctx sdk.Context, log ethtypes.Log) (*z if err != nil { return nil, err } + if btcChainParams == nil { + return nil, fmt.Errorf("ParseZRC20WithdrawalEvent: chain params not found") + } addr, err := btcutil.DecodeAddress(string(event.To), btcChainParams) if err != nil { return nil, fmt.Errorf("ParseZRC20WithdrawalEvent: invalid address %s: %s", event.To, err) diff --git a/zetaclient/bitcoin_client.go b/zetaclient/bitcoin_client.go index e69f8d1a74..843af46b45 100644 --- a/zetaclient/bitcoin_client.go +++ b/zetaclient/bitcoin_client.go @@ -762,6 +762,9 @@ func (ob *BitcoinChainClient) FetchUTXOS() error { if err != nil { return fmt.Errorf("btc: error getting bitcoin net params : %v", err) } + if bitcoinNetParams == nil { + return fmt.Errorf("btc: error getting bitcoin net params : %v", err) + } address, err := btcutil.DecodeAddress(tssAddr, bitcoinNetParams) if err != nil { return fmt.Errorf("btc: error decoding wallet address (%s) : %s", tssAddr, err.Error()) diff --git a/zetaclient/btc_signer.go b/zetaclient/btc_signer.go index 435e9cbcc9..9f38bd8c7b 100644 --- a/zetaclient/btc_signer.go +++ b/zetaclient/btc_signer.go @@ -301,6 +301,10 @@ func (signer *BTCSigner) TryProcessOutTx( logger.Error().Err(err).Msgf("cannot get bitcoin net params%v", err) return } + if bitcoinNetParams == nil { + logger.Error().Msgf("cannot get bitcoin net params") + return + } addr, err := btcutil.DecodeAddress(params.Receiver, bitcoinNetParams) if err != nil { From 14d0d41680aec40d8304846b83d73140ce98c7ae Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 5 Jan 2024 10:03:14 -0500 Subject: [PATCH 02/12] add wrapper function for btc decode address --- common/address.go | 45 +++++++++++++++++++ common/address_test.go | 32 +++++++++++++ common/chain.go | 18 ++++++-- .../smoketest/runner/setup_zeta.go | 7 +-- x/crosschain/keeper/btc_decode_test.go | 16 ------- x/crosschain/keeper/evm_hooks.go | 9 +--- zetaclient/bitcoin_client.go | 9 +--- zetaclient/btc_signer.go | 7 +-- 8 files changed, 96 insertions(+), 47 deletions(-) delete mode 100644 x/crosschain/keeper/btc_decode_test.go diff --git a/common/address.go b/common/address.go index 032a0b88b0..5c9e8a3bfe 100644 --- a/common/address.go +++ b/common/address.go @@ -1,8 +1,11 @@ package common import ( + "errors" + "fmt" "strings" + "github.com/btcsuite/btcutil" eth "github.com/ethereum/go-ethereum/common" "github.com/zeta-chain/zetacore/common/cosmos" ) @@ -41,3 +44,45 @@ func (addr Address) IsEmpty() bool { func (addr Address) String() string { return string(addr) } + +func ConvertRecoverToError(r interface{}) error { + switch x := r.(type) { + case string: + return errors.New(x) + case error: + return x + default: + return errors.New(fmt.Sprint(x)) + } +} + +func DecodeBtcAddress(inputAddress string, chainId int64) (address btcutil.Address, err error) { + defer func() { + if r := recover(); r != nil { + err = ConvertRecoverToError(r) + err = fmt.Errorf("input address:%s,chainId:%d,err:%s", inputAddress, chainId, err.Error()) + return + } + }() + chainParams, err := GetBTCChainParams(chainId) + if err != nil { + return nil, err + } + if chainParams == nil { + return nil, fmt.Errorf("chain params not found") + } + oneIndex := strings.LastIndexByte(inputAddress, '1') + if oneIndex > 1 { + prefix := inputAddress[:oneIndex] + ok := IsValidPrefix(prefix, chainId) + if !ok { + return nil, fmt.Errorf("invalid prefix:%s,chain-id:%d", prefix, chainId) + } + addressString := inputAddress[oneIndex+1:] + if len(addressString) != 39 { + return nil, fmt.Errorf("invalid address length:%d,inputaddress:%s", len(addressString), inputAddress) + } + } + address, err = btcutil.DecodeAddress(inputAddress, chainParams) + return +} diff --git a/common/address_test.go b/common/address_test.go index 4487c48e28..60632d1379 100644 --- a/common/address_test.go +++ b/common/address_test.go @@ -1,6 +1,7 @@ package common import ( + "fmt" "testing" "github.com/stretchr/testify/require" @@ -20,3 +21,34 @@ func TestAddress(t *testing.T) { addr = NewAddress("0x90f2b1ae50e6018230e90a33f98c7844a0ab635a") require.EqualValuesf(t, "0x90f2b1ae50e6018230e90a33f98c7844a0ab635a", addr.String(), "address string should be equal") } + +func TestDecodeBtcAddress(t *testing.T) { + // �U�ڷ���i߭����꿚�l + // 14CEjTd5ci3228J45GdnGeUKLSSeCWUQxK + t.Run("invalid string", func(t *testing.T) { + _, err := DecodeBtcAddress("�U�ڷ���i߭����꿚�l", 18332) + require.ErrorContains(t, err, "runtime error: index out of range") + }) + t.Run("invalid chain", func(t *testing.T) { + _, err := DecodeBtcAddress("14CEjTd5ci3228J45GdnGeUKLSSeCWUQxK", 0) + require.ErrorContains(t, err, "is not a Bitcoin chain") + }) + t.Run("invalid prefix", func(t *testing.T) { + _, err := DecodeBtcAddress("bcrt1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2", 18332) + require.ErrorContains(t, err, "invalid prefix") + }) + t.Run("invalid checksum", func(t *testing.T) { + _, err := DecodeBtcAddress("tb1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2", 18332) + require.ErrorContains(t, err, "invalid checksum") + fmt.Println(err) + }) + t.Run("valid address", func(t *testing.T) { + _, err := DecodeBtcAddress("bcrt1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt22", 18444) + require.ErrorContains(t, err, "invalid address length") + }) + t.Run("valid address", func(t *testing.T) { + _, err := DecodeBtcAddress("bcrt1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2", 18444) + require.NoError(t, err) + }) + +} diff --git a/common/chain.go b/common/chain.go index 1f409add12..d07805a9f6 100644 --- a/common/chain.go +++ b/common/chain.go @@ -52,10 +52,7 @@ func (chain Chain) EncodeAddress(b []byte) (string, error) { if err != nil { return "", err } - if chainParams == nil { - return "", fmt.Errorf("chain params not found") - } - addr, err := btcutil.DecodeAddress(addrStr, chainParams) + addr, err := DecodeBtcAddress(addrStr, chain.ChainId) if err != nil { return "", err } @@ -213,6 +210,19 @@ func GetBTCChainParams(chainID int64) (*chaincfg.Params, error) { } } +func IsValidPrefix(prefix string, chainID int64) bool { + switch chainID { + case 18444: + return prefix == "bcrt" + case 18332: + return prefix == "tb" + case 8332: + return prefix == "bc" + default: + return false + } +} + // InChainList checks whether the chain is in the chain list func (chain Chain) InChainList(chainList []*Chain) bool { return ChainIDInChainList(chain.ChainId, chainList) diff --git a/contrib/localnet/orchestrator/smoketest/runner/setup_zeta.go b/contrib/localnet/orchestrator/smoketest/runner/setup_zeta.go index 76761c3a3b..80a7606ba2 100644 --- a/contrib/localnet/orchestrator/smoketest/runner/setup_zeta.go +++ b/contrib/localnet/orchestrator/smoketest/runner/setup_zeta.go @@ -6,7 +6,6 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/btcsuite/btcutil" ethcommon "github.com/ethereum/go-ethereum/common" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" @@ -38,10 +37,8 @@ func (sm *SmokeTestRunner) SetTSSAddresses() { } tssAddress := ethcommon.HexToAddress(res.Eth) - if common.BitcoinRegnetParams == nil { - return - } - btcTSSAddress, err := btcutil.DecodeAddress(res.Btc, common.BitcoinRegnetParams) + + btcTSSAddress, err := common.DecodeBtcAddress(res.Btc, common.BtcRegtestChain().ChainId) if err != nil { panic(err) } diff --git a/x/crosschain/keeper/btc_decode_test.go b/x/crosschain/keeper/btc_decode_test.go deleted file mode 100644 index 5aff452622..0000000000 --- a/x/crosschain/keeper/btc_decode_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package keeper_test - -import ( - "testing" - - "github.com/btcsuite/btcutil" - "github.com/stretchr/testify/assert" - "github.com/zeta-chain/zetacore/common" -) - -func TestIsDecode(t *testing.T) { - params, err := common.GetBTCChainParams(18332) - assert.NoError(t, err) - _, err = btcutil.DecodeAddress("14CEjTd5ci3228J45GdnGeUKLSSeCWUQxK", params) - assert.NoError(t, err) -} diff --git a/x/crosschain/keeper/evm_hooks.go b/x/crosschain/keeper/evm_hooks.go index 1c28114625..2e0e79a511 100644 --- a/x/crosschain/keeper/evm_hooks.go +++ b/x/crosschain/keeper/evm_hooks.go @@ -288,14 +288,7 @@ func (k Keeper) ParseZRC20WithdrawalEvent(ctx sdk.Context, log ethtypes.Log) (*z if event.Value.Cmp(big.NewInt(0)) <= 0 { return nil, fmt.Errorf("ParseZRC20WithdrawalEvent: invalid amount %s", event.Value.String()) } - btcChainParams, err := common.GetBTCChainParams(chainID) - if err != nil { - return nil, err - } - if btcChainParams == nil { - return nil, fmt.Errorf("ParseZRC20WithdrawalEvent: chain params not found") - } - addr, err := btcutil.DecodeAddress(string(event.To), btcChainParams) + addr, err := common.DecodeBtcAddress(string(event.To), chainID) if err != nil { return nil, fmt.Errorf("ParseZRC20WithdrawalEvent: invalid address %s: %s", event.To, err) } diff --git a/zetaclient/bitcoin_client.go b/zetaclient/bitcoin_client.go index 843af46b45..9c7a4015c1 100644 --- a/zetaclient/bitcoin_client.go +++ b/zetaclient/bitcoin_client.go @@ -758,14 +758,7 @@ func (ob *BitcoinChainClient) FetchUTXOS() error { // List unspent. tssAddr := ob.Tss.BTCAddress() - bitcoinNetParams, err := common.BitcoinNetParamsFromChainID(ob.chain.ChainId) - if err != nil { - return fmt.Errorf("btc: error getting bitcoin net params : %v", err) - } - if bitcoinNetParams == nil { - return fmt.Errorf("btc: error getting bitcoin net params : %v", err) - } - address, err := btcutil.DecodeAddress(tssAddr, bitcoinNetParams) + address, err := common.DecodeBtcAddress(tssAddr, ob.chain.ChainId) if err != nil { return fmt.Errorf("btc: error decoding wallet address (%s) : %s", tssAddr, err.Error()) } diff --git a/zetaclient/btc_signer.go b/zetaclient/btc_signer.go index 9f38bd8c7b..8d15dafda0 100644 --- a/zetaclient/btc_signer.go +++ b/zetaclient/btc_signer.go @@ -301,12 +301,7 @@ func (signer *BTCSigner) TryProcessOutTx( logger.Error().Err(err).Msgf("cannot get bitcoin net params%v", err) return } - if bitcoinNetParams == nil { - logger.Error().Msgf("cannot get bitcoin net params") - return - } - - addr, err := btcutil.DecodeAddress(params.Receiver, bitcoinNetParams) + addr, err := common.DecodeBtcAddress(params.Receiver, params.ReceiverChainId) if err != nil { logger.Error().Err(err).Msgf("cannot decode address %s ", params.Receiver) return From 61b0d7ba8f6fc925937675e582d035117274c950 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 5 Jan 2024 13:43:03 -0500 Subject: [PATCH 03/12] remove checks fro prefixes --- common/address.go | 12 ------------ common/address_test.go | 10 ---------- common/chain.go | 13 ------------- 3 files changed, 35 deletions(-) diff --git a/common/address.go b/common/address.go index 5c9e8a3bfe..15e614e14a 100644 --- a/common/address.go +++ b/common/address.go @@ -71,18 +71,6 @@ func DecodeBtcAddress(inputAddress string, chainId int64) (address btcutil.Addre if chainParams == nil { return nil, fmt.Errorf("chain params not found") } - oneIndex := strings.LastIndexByte(inputAddress, '1') - if oneIndex > 1 { - prefix := inputAddress[:oneIndex] - ok := IsValidPrefix(prefix, chainId) - if !ok { - return nil, fmt.Errorf("invalid prefix:%s,chain-id:%d", prefix, chainId) - } - addressString := inputAddress[oneIndex+1:] - if len(addressString) != 39 { - return nil, fmt.Errorf("invalid address length:%d,inputaddress:%s", len(addressString), inputAddress) - } - } address, err = btcutil.DecodeAddress(inputAddress, chainParams) return } diff --git a/common/address_test.go b/common/address_test.go index 60632d1379..c3d86315ed 100644 --- a/common/address_test.go +++ b/common/address_test.go @@ -1,7 +1,6 @@ package common import ( - "fmt" "testing" "github.com/stretchr/testify/require" @@ -33,18 +32,9 @@ func TestDecodeBtcAddress(t *testing.T) { _, err := DecodeBtcAddress("14CEjTd5ci3228J45GdnGeUKLSSeCWUQxK", 0) require.ErrorContains(t, err, "is not a Bitcoin chain") }) - t.Run("invalid prefix", func(t *testing.T) { - _, err := DecodeBtcAddress("bcrt1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2", 18332) - require.ErrorContains(t, err, "invalid prefix") - }) t.Run("invalid checksum", func(t *testing.T) { _, err := DecodeBtcAddress("tb1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2", 18332) require.ErrorContains(t, err, "invalid checksum") - fmt.Println(err) - }) - t.Run("valid address", func(t *testing.T) { - _, err := DecodeBtcAddress("bcrt1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt22", 18444) - require.ErrorContains(t, err, "invalid address length") }) t.Run("valid address", func(t *testing.T) { _, err := DecodeBtcAddress("bcrt1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2", 18444) diff --git a/common/chain.go b/common/chain.go index d07805a9f6..c966cbd412 100644 --- a/common/chain.go +++ b/common/chain.go @@ -210,19 +210,6 @@ func GetBTCChainParams(chainID int64) (*chaincfg.Params, error) { } } -func IsValidPrefix(prefix string, chainID int64) bool { - switch chainID { - case 18444: - return prefix == "bcrt" - case 18332: - return prefix == "tb" - case 8332: - return prefix == "bc" - default: - return false - } -} - // InChainList checks whether the chain is in the chain list func (chain Chain) InChainList(chainList []*Chain) bool { return ChainIDInChainList(chain.ChainId, chainList) From cd7b16339aba1fd1623ec62346150517f9a201d2 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 5 Jan 2024 13:45:39 -0500 Subject: [PATCH 04/12] add check to see if address belongs to a network --- common/address.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/address.go b/common/address.go index 15e614e14a..37e2a3699b 100644 --- a/common/address.go +++ b/common/address.go @@ -72,5 +72,9 @@ func DecodeBtcAddress(inputAddress string, chainId int64) (address btcutil.Addre return nil, fmt.Errorf("chain params not found") } address, err = btcutil.DecodeAddress(inputAddress, chainParams) + ok := address.IsForNet(chainParams) + if !ok { + return nil, fmt.Errorf("address is not for network %s", chainParams.Name) + } return } From f1a223e3105f8b51492af1ecb2f8d6d7935cac78 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 5 Jan 2024 13:48:47 -0500 Subject: [PATCH 05/12] fix unit tests --- common/address_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/address_test.go b/common/address_test.go index c3d86315ed..88475b5cbe 100644 --- a/common/address_test.go +++ b/common/address_test.go @@ -32,9 +32,9 @@ func TestDecodeBtcAddress(t *testing.T) { _, err := DecodeBtcAddress("14CEjTd5ci3228J45GdnGeUKLSSeCWUQxK", 0) require.ErrorContains(t, err, "is not a Bitcoin chain") }) - t.Run("invalid checksum", func(t *testing.T) { + t.Run("nil pointer dereference", func(t *testing.T) { _, err := DecodeBtcAddress("tb1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2", 18332) - require.ErrorContains(t, err, "invalid checksum") + require.ErrorContains(t, err, "runtime error: invalid memory address or nil pointer dereference") }) t.Run("valid address", func(t *testing.T) { _, err := DecodeBtcAddress("bcrt1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2", 18444) From f6023a62a4ba890cf828ae3e1d4cab72009cc08f Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 5 Jan 2024 13:52:09 -0500 Subject: [PATCH 06/12] add changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 3266548717..631af42ddc 100644 --- a/changelog.md +++ b/changelog.md @@ -27,6 +27,7 @@ * fix Athens-3 log print issue - avoid posting uncessary outtx confirmation * fix docker build issues with version: golang:1.20-alpine3.18 * [1522](https://github.com/zeta-chain/node/pull/1522/files) - block `distribution` module account from receiving zeta +* [1528](https://github.com/zeta-chain/node/pull/1528) - fix panic caused on decoding malformed BTC addresses ### Refactoring From de137a738c2c35d2d2ca7ff87356429acd9cfd65 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 5 Jan 2024 13:53:34 -0500 Subject: [PATCH 07/12] remove unnecessary print statements --- common/address_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/address_test.go b/common/address_test.go index 88475b5cbe..af386c3bdc 100644 --- a/common/address_test.go +++ b/common/address_test.go @@ -22,8 +22,6 @@ func TestAddress(t *testing.T) { } func TestDecodeBtcAddress(t *testing.T) { - // �U�ڷ���i߭����꿚�l - // 14CEjTd5ci3228J45GdnGeUKLSSeCWUQxK t.Run("invalid string", func(t *testing.T) { _, err := DecodeBtcAddress("�U�ڷ���i߭����꿚�l", 18332) require.ErrorContains(t, err, "runtime error: index out of range") From b606436d744e5802e21c895584e2fe192164c938 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Sun, 7 Jan 2024 09:37:43 -0500 Subject: [PATCH 08/12] Update common/address.go Co-authored-by: Lucas Bertrand --- common/address.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/address.go b/common/address.go index 37e2a3699b..2edf697727 100644 --- a/common/address.go +++ b/common/address.go @@ -60,7 +60,7 @@ func DecodeBtcAddress(inputAddress string, chainId int64) (address btcutil.Addre defer func() { if r := recover(); r != nil { err = ConvertRecoverToError(r) - err = fmt.Errorf("input address:%s,chainId:%d,err:%s", inputAddress, chainId, err.Error()) + err = fmt.Errorf("input address:%s, chainId:%d, err:%s", inputAddress, chainId, err.Error()) return } }() From 8911051e2c38b30abd8e88485056e5f006b399c3 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Sun, 7 Jan 2024 09:37:52 -0500 Subject: [PATCH 09/12] Update common/address.go Co-authored-by: Lucas Bertrand --- common/address.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/address.go b/common/address.go index 2edf697727..c46b3e43a1 100644 --- a/common/address.go +++ b/common/address.go @@ -52,7 +52,7 @@ func ConvertRecoverToError(r interface{}) error { case error: return x default: - return errors.New(fmt.Sprint(x)) + return errors.New(fmt.Sprint("%v", x)) } } From 4a289e0e281903c55364324cae1fa1e1b18d15b7 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Sun, 7 Jan 2024 09:38:02 -0500 Subject: [PATCH 10/12] Update common/address.go Co-authored-by: Lucas Bertrand --- common/address.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/address.go b/common/address.go index c46b3e43a1..79776cbf8e 100644 --- a/common/address.go +++ b/common/address.go @@ -56,7 +56,7 @@ func ConvertRecoverToError(r interface{}) error { } } -func DecodeBtcAddress(inputAddress string, chainId int64) (address btcutil.Address, err error) { +func DecodeBtcAddress(inputAddress string, chainID int64) (address btcutil.Address, err error) { defer func() { if r := recover(); r != nil { err = ConvertRecoverToError(r) From 81a3c050bd3e44689e9ca47d5caaf4f4a0201829 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 8 Jan 2024 09:50:15 -0500 Subject: [PATCH 11/12] fix lint --- common/address.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/address.go b/common/address.go index 37e2a3699b..9168a29634 100644 --- a/common/address.go +++ b/common/address.go @@ -56,15 +56,15 @@ func ConvertRecoverToError(r interface{}) error { } } -func DecodeBtcAddress(inputAddress string, chainId int64) (address btcutil.Address, err error) { +func DecodeBtcAddress(inputAddress string, chainID int64) (address btcutil.Address, err error) { defer func() { if r := recover(); r != nil { err = ConvertRecoverToError(r) - err = fmt.Errorf("input address:%s,chainId:%d,err:%s", inputAddress, chainId, err.Error()) + err = fmt.Errorf("input address:%s,chainId:%d,err:%s", inputAddress, chainID, err.Error()) return } }() - chainParams, err := GetBTCChainParams(chainId) + chainParams, err := GetBTCChainParams(chainID) if err != nil { return nil, err } From c57771c36274f73d3128167667161efcfebb69fc Mon Sep 17 00:00:00 2001 From: Tanmay Date: Tue, 9 Jan 2024 10:38:08 -0500 Subject: [PATCH 12/12] Update common/address.go Co-authored-by: Lucas Bertrand --- common/address.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/address.go b/common/address.go index c7057cf573..77b4234fed 100644 --- a/common/address.go +++ b/common/address.go @@ -52,7 +52,7 @@ func ConvertRecoverToError(r interface{}) error { case error: return x default: - return errors.New(fmt.Sprint("%v", x)) + return fmt.Errorf("%v", x) } }