Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2dfae5944 | ||
|
|
454d65cd5c |
+75
-46
@@ -4,6 +4,14 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil/base58"
|
||||
"github.com/go-telegram/bot"
|
||||
"github.com/go-telegram/bot/models"
|
||||
"github.com/shopspring/decimal"
|
||||
@@ -14,13 +22,12 @@ import (
|
||||
"github.com/v03413/bepusdt/app/log"
|
||||
"github.com/v03413/bepusdt/app/model"
|
||||
"github.com/v03413/go-cache"
|
||||
api2 "github.com/v03413/tronprotocol/api"
|
||||
"github.com/v03413/tronprotocol/core"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/backoff"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"gorm.io/gorm"
|
||||
"io"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const cbWallet = "wallet"
|
||||
@@ -292,7 +299,7 @@ func cbOrderDetailAction(ctx context.Context, b *bot.Bot, u *models.Update) {
|
||||
})
|
||||
}
|
||||
|
||||
if order.Status == model.OrderStatusExpired && order.NotifyState == model.OrderNotifyStateFail {
|
||||
if (order.Status == model.OrderStatusExpired || order.Status == model.OrderStatusWaiting) && order.NotifyState == model.OrderNotifyStateFail {
|
||||
markup.InlineKeyboard = append(markup.InlineKeyboard, []models.InlineKeyboardButton{
|
||||
{Text: "⚠️直接标记已支付(即使未收到款)", CallbackData: cbMarkOrderSucc + "|" + order.TradeId},
|
||||
})
|
||||
@@ -389,56 +396,78 @@ func dbMarkOrderSuccAction(ctx context.Context, b *bot.Bot, u *models.Update) {
|
||||
}
|
||||
|
||||
func getTronWalletInfo(address string) string {
|
||||
var client = http.Client{Timeout: time.Second * 5}
|
||||
resp, err := client.Get("https://apilist.tronscanapi.com/api/accountv2?address=" + address)
|
||||
var grpcParams = grpc.ConnectParams{
|
||||
Backoff: backoff.Config{BaseDelay: 1 * time.Second, MaxDelay: 30 * time.Second, Multiplier: 1.5},
|
||||
MinConnectTimeout: 1 * time.Minute,
|
||||
}
|
||||
conn, err := grpc.NewClient(conf.GetTronGrpcNode(), grpc.WithConnectParams(grpcParams), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
log.Error("GetWalletInfoByAddress client.Get(url)", err)
|
||||
log.Warn("getTronWalletInfo Error NewClient:", err)
|
||||
|
||||
return ""
|
||||
return "地址信息获取失败!"
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
log.Error("GetWalletInfoByAddress resp.StatusCode != 200", resp.StatusCode, err)
|
||||
defer conn.Close()
|
||||
|
||||
return ""
|
||||
var client = api2.NewWalletClient(conn)
|
||||
var ctx, cancel = context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
info, err2 := client.GetAccount(ctx, &core.Account{Address: base58.Decode(address)[:21]})
|
||||
if err2 != nil {
|
||||
log.Warn("getTronWalletInfo Error GetAccount:", err2)
|
||||
|
||||
return "地址信息获取失败!"
|
||||
}
|
||||
|
||||
all, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Error("GetWalletInfoByAddress io.ReadAll(resp.Body)", err)
|
||||
|
||||
return ""
|
||||
}
|
||||
result := gjson.ParseBytes(all)
|
||||
|
||||
var dateCreated = time.UnixMilli(result.Get("date_created").Int())
|
||||
var latestOperationTime = time.UnixMilli(result.Get("latest_operation_time").Int())
|
||||
var netRemaining = result.Get("bandwidth.netRemaining").Int() + result.Get("bandwidth.freeNetRemaining").Int()
|
||||
var netLimit = result.Get("bandwidth.netLimit").Int() + result.Get("bandwidth.freeNetLimit").Int()
|
||||
var text = `
|
||||
>💰 TRX余额:0.00 TRX
|
||||
>💲 USDT余额:0.00 USDT
|
||||
>📬 交易数量:` + result.Get("totalTransactionCount").String() + `
|
||||
>📈 转账数量:↑ ` + result.Get("transactions_out").String() + ` ↓ ` + result.Get("transactions_in").String() + `
|
||||
>📡 宽带资源:` + fmt.Sprintf("%v", netRemaining) + ` / ` + fmt.Sprintf("%v", netLimit) + `
|
||||
>🔋 能量资源:` + result.Get("bandwidth.energyRemaining").String() + ` / ` + result.Get("bandwidth.energyLimit").String() + `
|
||||
>⏰ 创建时间:` + help.Ec(dateCreated.Format(time.DateTime)) + `
|
||||
>⏰ 最后活动:` + help.Ec(latestOperationTime.Format(time.DateTime)) + `
|
||||
>☘️ 查询地址:` + address
|
||||
|
||||
for _, v := range result.Get("withPriceTokens").Array() {
|
||||
if v.Get("tokenName").String() == "trx" {
|
||||
text = strings.Replace(text, "0.00 TRX", help.Ec(fmt.Sprintf("%.2f TRX", v.Get("balance").Float()/1000000)), 1)
|
||||
}
|
||||
if v.Get("tokenName").String() == "Tether USD" {
|
||||
text = strings.Replace(text, "0.00 USDT", help.Ec(fmt.Sprintf("%.2f USDT", v.Get("balance").Float()/1000000)), 1)
|
||||
}
|
||||
}
|
||||
var dateCreated = time.UnixMilli(info.CreateTime)
|
||||
var latestOperationTime = time.UnixMilli(info.LatestOprationTime)
|
||||
var text = "```" + `
|
||||
💰TRX余额:` + decimal.NewFromBigInt(new(big.Int).SetInt64(info.Balance), -6).RoundFloor(2).String() + ` TRX
|
||||
💲USDT余额:` + getTronUsdtBalance(address) + ` USDT
|
||||
⏰创建时间:` + help.Ec(dateCreated.Format(time.DateTime)) + `
|
||||
⏰最后活动:` + help.Ec(latestOperationTime.Format(time.DateTime)) + `
|
||||
☘️查询地址:` + address + "\n```"
|
||||
|
||||
return text
|
||||
}
|
||||
|
||||
func getTronUsdtBalance(address string) string {
|
||||
var grpcParams = grpc.ConnectParams{
|
||||
Backoff: backoff.Config{BaseDelay: 1 * time.Second, MaxDelay: 30 * time.Second, Multiplier: 1.5},
|
||||
MinConnectTimeout: 1 * time.Minute,
|
||||
}
|
||||
conn, err := grpc.NewClient(conf.GetTronGrpcNode(), grpc.WithConnectParams(grpcParams), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
log.Warn("getTronUsdtBalance Error NewClient:", err)
|
||||
|
||||
return "0.00"
|
||||
}
|
||||
|
||||
defer conn.Close()
|
||||
|
||||
var client = api2.NewWalletClient(conn)
|
||||
var ctx, cancel = context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
var addr = base58.Decode(address)
|
||||
info, err2 := client.TriggerConstantContract(ctx, &core.TriggerSmartContract{
|
||||
OwnerAddress: addr,
|
||||
ContractAddress: []byte{0x41, 0xa6, 0x14, 0xf8, 0x03, 0xb6, 0xfd, 0x78, 0x09, 0x86, 0xa4, 0x2c, 0x78, 0xec, 0x9c, 0x7f, 0x77, 0xe6, 0xde, 0xd1, 0x3c},
|
||||
Data: append([]byte{0x70, 0xa0, 0x82, 0x31}, append(make([]byte, 12), addr[1:]...)...),
|
||||
})
|
||||
if err2 != nil {
|
||||
log.Warn("getTronUsdtBalance Error TriggerConstantContract:", err2)
|
||||
|
||||
return "0.00"
|
||||
}
|
||||
|
||||
var data = new(big.Int)
|
||||
data.SetBytes(info.ConstantResult[0])
|
||||
|
||||
return decimal.NewFromBigInt(data, -6).String()
|
||||
}
|
||||
|
||||
func getAptosWalletInfo(wa model.WalletAddress) string {
|
||||
|
||||
return fmt.Sprintf(">💲余额:%s\\(%s\\)\n>☘️地址:`%s`", help.Ec(aptTokenBalanceOf(wa)), help.Ec(wa.TradeType), wa.Address)
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package app
|
||||
|
||||
// Version 版本号说明 1.0.0 代表主版本号.功能版本号.修订号
|
||||
const Version = "1.22.6"
|
||||
const Version = "1.22.7"
|
||||
|
||||
Reference in New Issue
Block a user