oneIndex := strings.LastIndexByte(addr, '1')
if oneIndex > 1 {
prefix := addr[:oneIndex+1]
- if consensus.IsBech32SegwitPrefix(prefix, param) {
+ if IsBech32SegwitPrefix(prefix, param) {
witnessVer, witnessProg, err := decodeSegWitAddress(addr)
if err != nil {
return nil, err
return nil, ErrUnknownAddressType
}
-func DecodeBytomAddress(addr string, param *consensus.Params) (Address, error) {
- // Bech32 encoded segwit addresses start with a human-readable part
- // (hrp) followed by '1'. For Bytom mainnet the hrp is "bm", and for
- // testnet it is "tm". If the address string has a prefix that matches
- // one of the prefixes for the known networks, we try to decode it as
- // a segwit address.
- oneIndex := strings.LastIndexByte(addr, '1')
- if oneIndex > 1 {
- prefix := addr[:oneIndex+1]
- if consensus.IsBytomBech32SegwitPrefix(prefix, param) {
- witnessVer, witnessProg, err := decodeSegWitAddress(addr)
- if err != nil {
- return nil, err
- }
-
- // We currently only support P2WPKH and P2WSH, which is
- // witness version 0.
- if witnessVer != 0 {
- return nil, ErrUnsupportedWitnessVer
- }
-
- // The HRP is everything before the found '1'.
- hrp := prefix[:len(prefix)-1]
-
- switch len(witnessProg) {
- case 20:
- return newAddressWitnessPubKeyHash(hrp, witnessProg)
- case 32:
- return newAddressWitnessScriptHash(hrp, witnessProg)
- default:
- return nil, ErrUnsupportedWitnessProgLen
- }
- }
- }
- return nil, ErrUnknownAddressType
+// IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit
+// addresses on any default or registered network. This is used when decoding
+// an address string into a specific address type.
+func IsBech32SegwitPrefix(prefix string, params *consensus.Params) bool {
+ return strings.ToLower(prefix) == params.Bech32HRPSegwit+"1"
}
// decodeSegWitAddress parses a bech32 encoded segwit address string and
return newAddressWitnessScriptHash(param.Bech32HRPSegwit, witnessProg)
}
-// NewAddressWitnessScriptHash returns a new AddressWitnessPubKeyHash.
-func NewPeginAddressWitnessScriptHash(witnessProg []byte, param *consensus.Params) (*AddressWitnessScriptHash, error) {
- return newAddressWitnessScriptHash(param.BytomBech32HRPSegwit, witnessProg)
-}
-
// newAddressWitnessScriptHash is an internal helper function to create an
// AddressWitnessScriptHash with a known human-readable part, rather than
// looking it up through its parameters.