Merge pull request 'fixed transactions' (#430) from tron-430 into main
Reviewed-on: #430
This commit was merged in pull request #430.
This commit is contained in:
@@ -49,9 +49,7 @@ chains:
|
|||||||
max_topup_trx: 100
|
max_topup_trx: 100
|
||||||
tokens:
|
tokens:
|
||||||
- symbol: USDT
|
- symbol: USDT
|
||||||
contract: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
|
contract: "TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf"
|
||||||
- symbol: USDC
|
|
||||||
contract: "TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8"
|
|
||||||
|
|
||||||
service_wallet:
|
service_wallet:
|
||||||
chain: tron_nile
|
chain: tron_nile
|
||||||
|
|||||||
@@ -50,8 +50,6 @@ chains:
|
|||||||
tokens:
|
tokens:
|
||||||
- symbol: USDT
|
- symbol: USDT
|
||||||
contract: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
|
contract: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
|
||||||
- symbol: USDC
|
|
||||||
contract: "TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8"
|
|
||||||
|
|
||||||
service_wallet:
|
service_wallet:
|
||||||
chain: tron_mainnet
|
chain: tron_mainnet
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ package evm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -15,7 +13,6 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/shengdoushi/base58"
|
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
"github.com/tech/sendico/gateway/tron/internal/service/gateway/driver"
|
"github.com/tech/sendico/gateway/tron/internal/service/gateway/driver"
|
||||||
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
|
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
|
||||||
@@ -62,34 +59,6 @@ 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.
|
// NormalizeAddress validates and normalizes EVM hex addresses.
|
||||||
func NormalizeAddress(address string) (string, error) {
|
func NormalizeAddress(address string) (string, error) {
|
||||||
trimmed := strings.TrimSpace(address)
|
trimmed := strings.TrimSpace(address)
|
||||||
@@ -155,7 +124,7 @@ func Balance(ctx context.Context, deps driver.Deps, network shared.Network, wall
|
|||||||
return nil, merrors.Internal("network rpc url is not configured")
|
return nil, merrors.Internal("network rpc url is not configured")
|
||||||
}
|
}
|
||||||
|
|
||||||
contract, err := tronBase58ToHex(strings.TrimSpace(wallet.ContractAddress))
|
contract, err := shared.TronBase58ToHex(strings.TrimSpace(wallet.ContractAddress))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("Failed to convert contract address", zap.String("contract_address", wallet.ContractAddress))
|
logger.Warn("Failed to convert contract address", zap.String("contract_address", wallet.ContractAddress))
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -471,7 +440,7 @@ func SubmitTransfer(ctx context.Context, deps driver.Deps, network shared.Networ
|
|||||||
|
|
||||||
chainID := new(big.Int).SetUint64(network.ChainID)
|
chainID := new(big.Int).SetUint64(network.ChainID)
|
||||||
|
|
||||||
contract, err := tronBase58ToHex(strings.TrimSpace(transfer.ContractAddress))
|
contract, err := shared.TronBase58ToHex(strings.TrimSpace(transfer.ContractAddress))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("Failed to convert contract address", zap.String("contract_address", transfer.ContractAddress))
|
logger.Warn("Failed to convert contract address", zap.String("contract_address", transfer.ContractAddress))
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func SubmitTransferNative(
|
|||||||
if contract != "" {
|
if contract != "" {
|
||||||
normalizedContract, err := normalizeAddress(contract)
|
normalizedContract, err := normalizeAddress(contract)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("Invalid TRON contract address", zap.String("transfer_ref", transfer.TransferRef), zap.Error(err))
|
logger.Warn("Invalid TRON contract address", zap.String("contract_address", contract), zap.String("transfer_ref", transfer.TransferRef), zap.Error(err))
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
contract = normalizedContract
|
contract = normalizedContract
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package shared
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/shengdoushi/base58"
|
||||||
|
"github.com/tech/sendico/pkg/merrors"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -89,7 +89,7 @@ func (t *Transfer) Normalize() {
|
|||||||
t.SourceWalletRef = strings.TrimSpace(t.SourceWalletRef)
|
t.SourceWalletRef = strings.TrimSpace(t.SourceWalletRef)
|
||||||
t.Network = strings.TrimSpace(strings.ToLower(t.Network))
|
t.Network = strings.TrimSpace(strings.ToLower(t.Network))
|
||||||
t.TokenSymbol = strings.TrimSpace(strings.ToUpper(t.TokenSymbol))
|
t.TokenSymbol = strings.TrimSpace(strings.ToUpper(t.TokenSymbol))
|
||||||
t.ContractAddress = strings.TrimSpace(strings.ToLower(t.ContractAddress))
|
t.ContractAddress = strings.TrimSpace(t.ContractAddress)
|
||||||
t.Destination.ManagedWalletRef = strings.TrimSpace(t.Destination.ManagedWalletRef)
|
t.Destination.ManagedWalletRef = strings.TrimSpace(t.Destination.ManagedWalletRef)
|
||||||
t.Destination.ExternalAddress = normalizeWalletAddress(t.Destination.ExternalAddress)
|
t.Destination.ExternalAddress = normalizeWalletAddress(t.Destination.ExternalAddress)
|
||||||
t.Destination.ExternalAddressOriginal = strings.TrimSpace(t.Destination.ExternalAddressOriginal)
|
t.Destination.ExternalAddressOriginal = strings.TrimSpace(t.Destination.ExternalAddressOriginal)
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import 'package:pweb/pages/address_book/page/page.dart';
|
|||||||
import 'package:pweb/pages/dashboard/dashboard.dart';
|
import 'package:pweb/pages/dashboard/dashboard.dart';
|
||||||
import 'package:pweb/pages/invitations/page.dart';
|
import 'package:pweb/pages/invitations/page.dart';
|
||||||
import 'package:pweb/pages/payment_methods/page.dart';
|
import 'package:pweb/pages/payment_methods/page.dart';
|
||||||
import 'package:pweb/pages/payout_page/page.dart';
|
|
||||||
import 'package:pweb/pages/payout_page/wallet/edit/page.dart';
|
import 'package:pweb/pages/payout_page/wallet/edit/page.dart';
|
||||||
import 'package:pweb/pages/report/page.dart';
|
import 'package:pweb/pages/report/page.dart';
|
||||||
import 'package:pweb/pages/settings/profile/page.dart';
|
import 'package:pweb/pages/settings/profile/page.dart';
|
||||||
|
|||||||
Reference in New Issue
Block a user