X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=common%2Faddress.go;h=3fe4999fba89bf42c1587fcb4867d1262612cac6;hp=7cc91673ab093174fd4d9422d2bdac8741ee6345;hb=refs%2Fheads%2Ffix_log;hpb=08281341c2cb02ba11d4218576256688854790fc diff --git a/common/address.go b/common/address.go index 7cc91673..3fe4999f 100644 --- a/common/address.go +++ b/common/address.go @@ -116,7 +116,7 @@ func DecodeAddress(addr string, param *consensus.Params) (Address, error) { 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 @@ -144,41 +144,11 @@ func DecodeAddress(addr string, param *consensus.Params) (Address, error) { 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 @@ -329,11 +299,6 @@ func NewAddressWitnessScriptHash(witnessProg []byte, param *consensus.Params) (* 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.