TRON driver update #426
@@ -11,6 +11,7 @@ require (
|
||||
github.com/hashicorp/vault/api v1.22.0
|
||||
github.com/mitchellh/mapstructure v1.5.0
|
||||
github.com/prometheus/client_golang v1.23.2
|
||||
github.com/shengdoushi/base58 v1.0.0
|
||||
github.com/shopspring/decimal v1.4.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
github.com/tech/sendico/pkg v0.1.0
|
||||
@@ -72,7 +73,6 @@ require (
|
||||
github.com/prometheus/procfs v0.19.2 // indirect
|
||||
github.com/rjeczalik/notify v0.9.3 // indirect
|
||||
github.com/ryanuber/go-glob v1.0.0 // indirect
|
||||
github.com/shengdoushi/base58 v1.0.0 // indirect
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
|
||||
github.com/supranational/blst v0.3.16 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.16 // indirect
|
||||
|
||||
@@ -76,7 +76,7 @@ func (c *createManagedWalletCommand) Execute(ctx context.Context, req *chainv1.C
|
||||
c.deps.Logger.Warn("Missing token symbol")
|
||||
return gsresponse.InvalidArgument[chainv1.CreateManagedWalletResponse](c.deps.Logger, mservice.ChainGateway, merrors.InvalidArgument("asset.token_symbol is required"))
|
||||
}
|
||||
contractAddress := strings.ToLower(strings.TrimSpace(asset.GetContractAddress()))
|
||||
contractAddress := strings.TrimSpace(asset.GetContractAddress())
|
||||
if contractAddress == "" {
|
||||
if !strings.EqualFold(tokenSymbol, networkCfg.NativeToken) {
|
||||
contractAddress = shared.ResolveContractAddress(networkCfg.TokenConfigs, tokenSymbol)
|
||||
|
||||
@@ -2,7 +2,9 @@ package evm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -13,6 +15,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/shengdoushi/base58"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/tech/sendico/gateway/tron/internal/service/gateway/driver"
|
||||
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
|
||||
@@ -59,6 +62,34 @@ const erc20ABIJSON = `
|
||||
}
|
||||
]`
|
||||
|
||||
func TronBase58ToHex(addr string) (string, error) {
|
||||
const (
|
||||
tronAddrLen = 25
|
||||
tronPrefix = byte(0x41)
|
||||
payloadLen = 21
|
||||
checksumBytes = 4
|
||||
)
|
||||
|
||||
raw, err := base58.Decode(addr, base58.BitcoinAlphabet)
|
||||
if err != nil {
|
||||
return "", merrors.InvalidArgument(fmt.Sprintf("tron address: base58 decode failed: %s", err.Error()))
|
||||
}
|
||||
|
||||
if len(raw) != tronAddrLen {
|
||||
return "", merrors.DataConflict("tron address: invalid length")
|
||||
}
|
||||
|
||||
// 21 байт: prefix + 20 байт EVM адреса
|
||||
payload := raw[:payloadLen]
|
||||
|
||||
if payload[0] != tronPrefix {
|
||||
return "", merrors.DataConflict("tron address: invalid prefix")
|
||||
}
|
||||
|
||||
evm := payload[1:payloadLen]
|
||||
return "0x" + hex.EncodeToString(evm), nil
|
||||
}
|
||||
|
||||
// NormalizeAddress validates and normalizes EVM hex addresses.
|
||||
func NormalizeAddress(address string) (string, error) {
|
||||
trimmed := strings.TrimSpace(address)
|
||||
@@ -116,7 +147,7 @@ func Balance(ctx context.Context, deps driver.Deps, network shared.Network, wall
|
||||
zap.String("wallet_ref", wallet.WalletRef),
|
||||
zap.String("network", network.Name.String()),
|
||||
zap.String("token_symbol", strings.ToUpper(strings.TrimSpace(wallet.TokenSymbol))),
|
||||
zap.String("contract", strings.ToLower(strings.TrimSpace(wallet.ContractAddress))),
|
||||
zap.String("contract", strings.TrimSpace(wallet.ContractAddress)),
|
||||
zap.String("wallet_address", normalizedAddress),
|
||||
}
|
||||
if rpcURL == "" {
|
||||
|
||||
@@ -69,12 +69,12 @@ func (a *WalletAPI) getWalletBalance(r *http.Request, account *model.Account, to
|
||||
bal, err := a.queryBalanceFromGateways(ctx, cryptoGateways, walletRef)
|
||||
if err != nil {
|
||||
a.logger.Warn("Failed to fetch wallet balance from gateways", zap.Error(err), zap.String("wallet_ref", walletRef))
|
||||
return response.Auto(a.logger, mservice.ChainGateway, err)
|
||||
return response.Auto(a.logger, a.Name(), err)
|
||||
}
|
||||
|
||||
if bal == nil {
|
||||
a.logger.Warn("Wallet balance not found on any gateway", zap.String("wallet_ref", walletRef))
|
||||
return response.Auto(a.logger, mservice.ChainGateway, merrors.NoData("wallet not found"))
|
||||
return response.Auto(a.logger, a.Name(), merrors.NoData("wallet not found"))
|
||||
}
|
||||
|
||||
return sresponse.WalletBalanceFromConnector(a.logger, bal, token)
|
||||
|
||||
Reference in New Issue
Block a user