Skip to content

Commit

Permalink
remove checks fro prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Jan 5, 2024
1 parent 14d0d41 commit 61b0d7b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 35 deletions.
12 changes: 0 additions & 12 deletions common/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 0 additions & 10 deletions common/address_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package common

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 0 additions & 13 deletions common/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 61b0d7b

Please sign in to comment.