Go 判断 BTC 交易地址合法校验

BTC 交易地址规则

一下代码是 Golang 判断是否是一个合法的 BTC 交易地址。


import "strings"

// 返回 true 为合法 BTC 交易地址
func IsValidBtcAddress(address string) bool {
    len := len(address)
    if len < 25 {
        return false
    }


    if strings.HasPrefix(address, "1") {
        if len >= 26 && len <= 34 {
            return true
        }
    }


    if strings.HasPrefix(address, "3") && len == 34 {
        return true
    }


    if strings.HasPrefix(address, "bc1") && len > 34 {
        return true
    }


    return false
}


原文地址:https://www.cnblogs.com/wf-l5201314/p/12146323.html