1、在线支付
Some checks failed
Build / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
build / Build (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitee (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitlab (push) Has been cancelled
Issue Close Require / issue-close-require (push) Has been cancelled
Some checks failed
Build / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
build / Build (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitee (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitlab (push) Has been cancelled
Issue Close Require / issue-close-require (push) Has been cancelled
2、查询平台剩余字符数
This commit is contained in:
35
utils/chainhelper/chainhelper.go
Normal file
35
utils/chainhelper/chainhelper.go
Normal file
@ -0,0 +1,35 @@
|
||||
package chainhelper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// 比较钱包地址格式
|
||||
func JudgeChainAddress(chain, walletAddress string) error {
|
||||
switch chain {
|
||||
case "trx":
|
||||
return validateTronAddress(walletAddress)
|
||||
default:
|
||||
return errors.New("invalid chain")
|
||||
}
|
||||
}
|
||||
|
||||
func validateTronAddress(address string) error {
|
||||
// TRON 地址通常以 'T' 开头,并且是 34 个字符的 Base58Check 编码
|
||||
// 这是一个简化的检查,最佳实践是使用专门的 Tron 地址验证库来包含校验和验证
|
||||
if len(address) != 34 {
|
||||
return errors.New("Tron 钱包地址长度不正确")
|
||||
}
|
||||
if address[0] != 'T' {
|
||||
return errors.New("Tron 钱包地址长度不正确,必须以 'T'开头")
|
||||
}
|
||||
|
||||
// 检查字符集
|
||||
matched, _ := regexp.MatchString("^[T][1-9a-zA-Z]{33}$", address)
|
||||
if !matched {
|
||||
return errors.New("TRON 钱包地址格式不正确")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user