X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=common%2Faddress.go;h=3fe4999fba89bf42c1587fcb4867d1262612cac6;hp=a5162e40d5ade465efcccf672abedf9bb5ef67c1;hb=73164af54a2587ba479b8b133274e3ecd0559a68;hpb=f8b08ae822eec5e86e60863e5b00b6353490a6bd diff --git a/common/address.go b/common/address.go index a5162e40..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,6 +144,13 @@ func DecodeAddress(addr string, param *consensus.Params) (Address, error) { 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 // returns the witness version and witness program byte representation. func decodeSegWitAddress(address string) (byte, []byte, error) {