This commit is contained in:
“dev”
2025-11-22 17:07:25 +08:00
parent 011d602ffe
commit 61d3cc819e
4 changed files with 63 additions and 2 deletions
+8 -2
View File
@@ -2,6 +2,7 @@ package telegram
import (
"fmt"
"github.com/assimon/luuu/model/data"
"github.com/assimon/luuu/model/mdb"
"github.com/gookit/goutil/mathutil"
@@ -16,11 +17,16 @@ const (
func OnTextMessageHandle(c tb.Context) error {
if c.Message().ReplyTo.Text == ReplayAddWallet {
defer bots.Delete(c.Message().ReplyTo)
_, err := data.AddWalletAddress(c.Message().Text)
msgText := c.Message().Text
if !isValidTronAddress(msgText) {
_ = c.Send(fmt.Sprintf("钱包[%s]添加失败: 非Tron地址!", msgText))
return nil
}
_, err := data.AddWalletAddress(msgText)
if err != nil {
return c.Send(err.Error())
}
c.Send(fmt.Sprintf("钱包[%s]添加成功!", c.Message().Text))
_ = c.Send(fmt.Sprintf("钱包[%s]添加成功!", msgText))
return WalletList(c)
}
return nil
+34
View File
@@ -0,0 +1,34 @@
package telegram
import (
"crypto/sha256"
"github.com/btcsuite/btcutil/base58"
)
// isValidTronAddress 校验 Tron Base58Check 地址是否合法
func isValidTronAddress(addr string) bool {
// 基本过滤
if len(addr) < 26 || len(addr) > 35 || addr[0] != 'T' {
return false
}
decoded := base58.Decode(addr)
if len(decoded) != 25 {
return false
}
// TRON 主网地址必须以 0x41 开头
if decoded[0] != 0x41 {
return false
}
// Base58Check 校验
payload := decoded[:21] // 前 21 字节
checksum := decoded[21:] // 后 4 字节
hash := sha256.Sum256(payload)
hash2 := sha256.Sum256(hash[:])
return string(checksum) == string(hash2[:4])
}