From 61b0d7ba8f6fc925937675e582d035117274c950 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 5 Jan 2024 13:43:03 -0500 Subject: [PATCH] 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)