fixed transactions
This commit is contained in:
@@ -2,9 +2,7 @@ package evm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -15,7 +13,6 @@ 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"
|
||||
@@ -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.
|
||||
func NormalizeAddress(address string) (string, error) {
|
||||
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")
|
||||
}
|
||||
|
||||
contract, err := tronBase58ToHex(strings.TrimSpace(wallet.ContractAddress))
|
||||
contract, err := shared.TronBase58ToHex(strings.TrimSpace(wallet.ContractAddress))
|
||||
if err != nil {
|
||||
logger.Warn("Failed to convert contract address", zap.String("contract_address", wallet.ContractAddress))
|
||||
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)
|
||||
|
||||
contract, err := tronBase58ToHex(strings.TrimSpace(transfer.ContractAddress))
|
||||
contract, err := shared.TronBase58ToHex(strings.TrimSpace(transfer.ContractAddress))
|
||||
if err != nil {
|
||||
logger.Warn("Failed to convert contract address", zap.String("contract_address", transfer.ContractAddress))
|
||||
return "", err
|
||||
|
||||
@@ -73,7 +73,7 @@ func SubmitTransferNative(
|
||||
if contract != "" {
|
||||
normalizedContract, err := normalizeAddress(contract)
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user