feat: refactor payment system with multi-currency support and TRX native transfer detection
- Add multi-currency exchange rate API integration (GetRateForCoin) - Implement native TRX transfer detection alongside TRC20 USDT transfers - Replace deprecated Tronscan API with Trongrid API for better reliability - Add TRON Grid API key configuration support - Refactor order service to support multiple tokens and currencies - Update wallet address locking/unlocking to track token type - Add base58 and gjson dependencies for crypto operations - Optimize SQLite connection with WAL mode and busy timeout - Remove deprecated USDT rate job (replaced by dynamic rate API) - Update order data model to include currency and receive address fields - Enhance TRC20 callback with improved error handling and logging
This commit is contained in:
+65
-10
@@ -2,22 +2,28 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/assimon/luuu/util/http_client"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
var (
|
||||
AppDebug bool
|
||||
MysqlDns string
|
||||
RuntimePath string
|
||||
LogSavePath string
|
||||
StaticPath string
|
||||
TgBotToken string
|
||||
TgProxy string
|
||||
TgManage int64
|
||||
UsdtRate float64
|
||||
AppDebug bool
|
||||
MysqlDns string
|
||||
RuntimePath string
|
||||
LogSavePath string
|
||||
StaticPath string
|
||||
TgBotToken string
|
||||
TgProxy string
|
||||
TgManage int64
|
||||
UsdtRate float64
|
||||
RateApiUrl string
|
||||
TRON_GRID_API_KEY string
|
||||
)
|
||||
|
||||
func Init() {
|
||||
@@ -52,6 +58,9 @@ func Init() {
|
||||
TgBotToken = viper.GetString("tg_bot_token")
|
||||
TgProxy = viper.GetString("tg_proxy")
|
||||
TgManage = viper.GetInt64("tg_manage")
|
||||
|
||||
GetRateApiUrl()
|
||||
TRON_GRID_API_KEY = viper.GetString("tron_grid_api_key")
|
||||
}
|
||||
|
||||
func GetAppVersion() string {
|
||||
@@ -74,6 +83,52 @@ func GetApiAuthToken() string {
|
||||
return viper.GetString("api_auth_token")
|
||||
}
|
||||
|
||||
func GetRateApiUrl() string {
|
||||
url := viper.GetString("api_rate_url")
|
||||
urlFromEnv := os.Getenv("API_RATE_URL")
|
||||
if url == "" && urlFromEnv != "" {
|
||||
url = urlFromEnv
|
||||
}
|
||||
if url == "" {
|
||||
log.Println("api_rate_url is empty")
|
||||
}
|
||||
RateApiUrl = url
|
||||
return url
|
||||
}
|
||||
|
||||
func GetRateForCoin(coin string, base string) float64 {
|
||||
client := http_client.GetHttpClient()
|
||||
baseUrl := RateApiUrl
|
||||
if baseUrl == "" {
|
||||
log.Printf("rate api url is empty")
|
||||
return 0.0
|
||||
}
|
||||
if baseUrl[len(baseUrl)-1] != '/' {
|
||||
baseUrl += "/"
|
||||
}
|
||||
url := baseUrl + fmt.Sprintf("%s.json", base)
|
||||
|
||||
fmt.Println("call rate api url:", url)
|
||||
|
||||
resp, err := client.R().Get(url)
|
||||
if err != nil {
|
||||
log.Printf("call rate api error: %s", err.Error())
|
||||
return 0.0
|
||||
}
|
||||
|
||||
targetRate := 0.0
|
||||
|
||||
gjson.GetBytes(resp.Body(), base).ForEach(func(key, value gjson.Result) bool {
|
||||
if key.String() == coin {
|
||||
targetRate = value.Float()
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
return targetRate
|
||||
|
||||
}
|
||||
|
||||
func GetUsdtRate() float64 {
|
||||
forcedUsdtRate := viper.GetFloat64("forced_usdt_rate")
|
||||
if forcedUsdtRate > 0 {
|
||||
|
||||
Reference in New Issue
Block a user