fixed db operations

This commit is contained in:
Stephan D
2026-02-05 16:27:43 +01:00
parent 42da0260b0
commit 761dda9377
38 changed files with 92 additions and 137 deletions

View File

@@ -14,8 +14,8 @@ import (
gatewayservice "github.com/tech/sendico/gateway/tron/internal/service/gateway"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/drivers"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/rpcclient"
gatewayshared "github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/tronclient"
gatewayshared "github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage"
gatewaymongo "github.com/tech/sendico/gateway/tron/storage/mongo"
"github.com/tech/sendico/pkg/api/routers"

View File

@@ -4,7 +4,7 @@ import (
"strings"
"github.com/shopspring/decimal"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/merrors"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"

View File

@@ -7,8 +7,8 @@ import (
"github.com/tech/sendico/gateway/tron/internal/keymanager"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/drivers"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/rpcclient"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/tronclient"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage"
clockpkg "github.com/tech/sendico/pkg/clock"
"github.com/tech/sendico/pkg/mlogger"

View File

@@ -6,7 +6,7 @@ import (
"strings"
"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/shared"
"github.com/tech/sendico/pkg/api/routers/gsresponse"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mservice"

View File

@@ -8,7 +8,7 @@ import (
"github.com/tech/sendico/gateway/tron/internal/service/gateway/commands/wallet"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/driver/evm"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/driver/tron"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/api/routers/gsresponse"
"github.com/tech/sendico/pkg/merrors"

View File

@@ -4,7 +4,7 @@ import (
"context"
"strings"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/api/routers/gsresponse"
"github.com/tech/sendico/pkg/mservice"

View File

@@ -1,7 +1,7 @@
package transfer
import (
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
"google.golang.org/protobuf/types/known/timestamppb"

View File

@@ -6,7 +6,7 @@ import (
"strings"
"github.com/shopspring/decimal"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/api/routers/gsresponse"
"github.com/tech/sendico/pkg/merrors"

View File

@@ -6,7 +6,7 @@ import (
"strings"
"time"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/api/routers/gsresponse"
"github.com/tech/sendico/pkg/merrors"

View File

@@ -5,7 +5,7 @@ import (
"errors"
"strings"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/api/routers/gsresponse"
"github.com/tech/sendico/pkg/merrors"

View File

@@ -4,7 +4,7 @@ import (
"context"
"strings"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/api/routers/gsresponse"
"github.com/tech/sendico/pkg/mservice"

View File

@@ -3,7 +3,7 @@ package wallet
import (
"strings"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
describablev1 "github.com/tech/sendico/pkg/proto/common/describable/v1"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"

View File

@@ -7,7 +7,7 @@ import (
"strings"
"github.com/tech/sendico/gateway/tron/internal/appversion"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
chainasset "github.com/tech/sendico/pkg/chain"
"github.com/tech/sendico/pkg/connector/params"
"github.com/tech/sendico/pkg/merrors"

View File

@@ -7,8 +7,8 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/tech/sendico/gateway/tron/internal/keymanager"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/rpcclient"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/tronclient"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/mlogger"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"

View File

@@ -15,7 +15,7 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/shopspring/decimal"
"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/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/merrors"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"

View File

@@ -5,7 +5,7 @@ import (
"strings"
"github.com/shopspring/decimal"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/merrors"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"

View File

@@ -5,7 +5,7 @@ import (
"github.com/shopspring/decimal"
"github.com/stretchr/testify/require"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
)

View File

@@ -8,6 +8,7 @@ import (
"math/big"
"strings"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/pkg/merrors"
)
@@ -41,7 +42,7 @@ func rpcAddress(address string) (string, error) {
if strings.HasPrefix(trimmed, tronHexPrefix) || isHexString(trimmed) {
return normalizeHexRPC(trimmed)
}
return base58ToHex(trimmed)
return shared.TronBase58ToHex(trimmed)
}
func hexToBase58(address string) (string, error) {
@@ -53,17 +54,6 @@ func hexToBase58(address string) (string, error) {
return base58Encode(payload), nil
}
func base58ToHex(address string) (string, error) {
decoded, err := base58Decode(address)
if err != nil {
return "", err
}
if err := validateChecksum(decoded); err != nil {
return "", err
}
return tronHexPrefix + hex.EncodeToString(decoded[1:21]), nil
}
func parseHexAddress(address string) ([]byte, error) {
trimmed := strings.TrimPrefix(strings.TrimSpace(address), tronHexPrefix)
if trimmed == "" {

View File

@@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/driver"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/driver/evm"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"

View File

@@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/require"
"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/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
"go.uber.org/zap"

View File

@@ -5,7 +5,7 @@ import (
"strings"
"github.com/shopspring/decimal"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/merrors"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"

View File

@@ -5,7 +5,7 @@ import (
"github.com/shopspring/decimal"
"github.com/stretchr/testify/require"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
)

View File

@@ -6,7 +6,7 @@ import (
"github.com/tech/sendico/gateway/tron/internal/service/gateway/driver"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/driver/tron"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"go.uber.org/zap"

View File

@@ -14,7 +14,7 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/shopspring/decimal"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/rpcclient"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"go.uber.org/zap"
"github.com/tech/sendico/gateway/tron/internal/keymanager"

View File

@@ -6,8 +6,8 @@ import (
"github.com/tech/sendico/gateway/tron/internal/keymanager"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/drivers"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/rpcclient"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/tronclient"
"github.com/tech/sendico/gateway/tron/shared"
clockpkg "github.com/tech/sendico/pkg/clock"
)

View File

@@ -11,7 +11,7 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"go.uber.org/zap"

View File

@@ -5,7 +5,7 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/pkg/merrors"
)

View File

@@ -10,8 +10,8 @@ import (
"github.com/tech/sendico/gateway/tron/internal/service/gateway/commands/wallet"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/drivers"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/rpcclient"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/tronclient"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage"
"github.com/tech/sendico/pkg/api/routers"
"github.com/tech/sendico/pkg/api/routers/gsresponse"

View File

@@ -21,7 +21,7 @@ import (
"github.com/tech/sendico/gateway/tron/internal/keymanager"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/drivers"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/gateway/tron/storage"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/merrors"

View File

@@ -1,32 +0,0 @@
package shared
import "github.com/shopspring/decimal"
// GasTopUpRule defines buffer, minimum, rounding, and cap behavior for native gas top-ups.
type GasTopUpRule struct {
BufferPercent decimal.Decimal
MinNativeBalance decimal.Decimal
RoundingUnit decimal.Decimal
MaxTopUp decimal.Decimal
}
// GasTopUpPolicy captures default and optional overrides for native vs contract transfers.
type GasTopUpPolicy struct {
Default GasTopUpRule
Native *GasTopUpRule
Contract *GasTopUpRule
}
// Rule selects the policy rule for the transfer type.
func (p *GasTopUpPolicy) Rule(contractTransfer bool) (GasTopUpRule, bool) {
if p == nil {
return GasTopUpRule{}, false
}
if contractTransfer && p.Contract != nil {
return *p.Contract, true
}
if !contractTransfer && p.Native != nil {
return *p.Native, true
}
return p.Default, true
}

View File

@@ -1,210 +0,0 @@
package shared
import (
"strings"
"github.com/tech/sendico/gateway/tron/storage/model"
chainasset "github.com/tech/sendico/pkg/chain"
pmodel "github.com/tech/sendico/pkg/model"
paymenttypes "github.com/tech/sendico/pkg/payments/types"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
"go.mongodb.org/mongo-driver/v2/bson"
)
// CloneMoney defensively copies a Money proto.
func CloneMoney(m *moneyv1.Money) *moneyv1.Money {
if m == nil {
return nil
}
return &moneyv1.Money{Amount: m.GetAmount(), Currency: m.GetCurrency()}
}
// CloneMetadata defensively copies metadata maps.
func CloneMetadata(input map[string]string) map[string]string {
if len(input) == 0 {
return nil
}
clone := make(map[string]string, len(input))
for k, v := range input {
clone[k] = v
}
return clone
}
// ResolveContractAddress finds a token contract for a symbol in a case-insensitive manner.
func ResolveContractAddress(tokens []TokenContract, symbol string) string {
upper := strings.ToUpper(symbol)
for _, token := range tokens {
if strings.EqualFold(token.Symbol, upper) && token.ContractAddress != "" {
return strings.ToLower(token.ContractAddress)
}
}
return ""
}
func GenerateWalletRef() string {
return bson.NewObjectID().Hex()
}
func GenerateTransferRef() string {
return bson.NewObjectID().Hex()
}
func ChainKeyFromEnum(chain chainv1.ChainNetwork) (string, chainv1.ChainNetwork) {
if name, ok := chainv1.ChainNetwork_name[int32(chain)]; ok {
key := strings.ToLower(strings.TrimPrefix(name, "CHAIN_NETWORK_"))
return key, chain
}
return "", chainv1.ChainNetwork_CHAIN_NETWORK_UNSPECIFIED
}
func ChainEnumFromName(name string) chainv1.ChainNetwork {
return chainasset.NetworkFromString(name)
}
func ManagedWalletStatusToProto(status model.ManagedWalletStatus) chainv1.ManagedWalletStatus {
switch status {
case model.ManagedWalletStatusActive:
return chainv1.ManagedWalletStatus_MANAGED_WALLET_ACTIVE
case model.ManagedWalletStatusSuspended:
return chainv1.ManagedWalletStatus_MANAGED_WALLET_SUSPENDED
case model.ManagedWalletStatusClosed:
return chainv1.ManagedWalletStatus_MANAGED_WALLET_CLOSED
default:
return chainv1.ManagedWalletStatus_MANAGED_WALLET_STATUS_UNSPECIFIED
}
}
func TransferStatusToModel(status chainv1.TransferStatus) model.TransferStatus {
switch status {
case chainv1.TransferStatus_TRANSFER_CREATED:
return model.TransferStatusCreated
case chainv1.TransferStatus_TRANSFER_PROCESSING:
return model.TransferStatusProcessing
case chainv1.TransferStatus_TRANSFER_WAITING:
return model.TransferStatusWaiting
case chainv1.TransferStatus_TRANSFER_SUCCESS:
return model.TransferStatusSuccess
case chainv1.TransferStatus_TRANSFER_FAILED:
return model.TransferStatusFailed
case chainv1.TransferStatus_TRANSFER_CANCELLED:
return model.TransferStatusCancelled
default:
return model.TransferStatus("")
}
}
func TransferStatusToProto(status model.TransferStatus) chainv1.TransferStatus {
switch status {
case model.TransferStatusCreated:
return chainv1.TransferStatus_TRANSFER_CREATED
case model.TransferStatusProcessing:
return chainv1.TransferStatus_TRANSFER_PROCESSING
case model.TransferStatusWaiting:
return chainv1.TransferStatus_TRANSFER_WAITING
case model.TransferStatusSuccess:
return chainv1.TransferStatus_TRANSFER_SUCCESS
case model.TransferStatusFailed:
return chainv1.TransferStatus_TRANSFER_FAILED
case model.TransferStatusCancelled:
return chainv1.TransferStatus_TRANSFER_CANCELLED
default:
return chainv1.TransferStatus_TRANSFER_STATUS_UNSPECIFIED
}
}
func ChainTransferStatusToOperation(status chainv1.TransferStatus) connectorv1.OperationStatus {
switch status {
case chainv1.TransferStatus_TRANSFER_CREATED:
return connectorv1.OperationStatus_OPERATION_CREATED
case chainv1.TransferStatus_TRANSFER_PROCESSING:
return connectorv1.OperationStatus_OPERATION_PROCESSING
case chainv1.TransferStatus_TRANSFER_WAITING:
return connectorv1.OperationStatus_OPERATION_WAITING
case chainv1.TransferStatus_TRANSFER_SUCCESS:
return connectorv1.OperationStatus_OPERATION_SUCCESS
case chainv1.TransferStatus_TRANSFER_FAILED:
return connectorv1.OperationStatus_OPERATION_FAILED
case chainv1.TransferStatus_TRANSFER_CANCELLED:
return connectorv1.OperationStatus_OPERATION_CANCELLED
default:
return connectorv1.OperationStatus_OPERATION_STATUS_UNSPECIFIED
}
}
// NativeCurrency returns the canonical native token symbol for a network.
func NativeCurrency(network Network) string {
currency := strings.ToUpper(strings.TrimSpace(network.NativeToken))
if currency == "" {
currency = strings.ToUpper(network.Name.String())
}
return currency
}
// Network describes a supported blockchain network and known token contracts.
type Network struct {
Name pmodel.ChainNetwork
RPCURL string
GRPCUrl string // Native TRON gRPC endpoint (for transactions)
GRPCToken string // Optional auth token for TRON gRPC (x-token header)
ChainID uint64
NativeToken string
TokenConfigs []TokenContract
GasTopUpPolicy *GasTopUpPolicy
}
// TokenContract captures the metadata needed to work with a specific on-chain token.
type TokenContract struct {
Symbol string
ContractAddress string
}
// ServiceWallet captures the managed service wallet configuration.
type ServiceWallet struct {
Network pmodel.ChainNetwork
Address string
PrivateKey string
}
func ProtoToMoney(money *moneyv1.Money) *paymenttypes.Money {
if money == nil {
return &paymenttypes.Money{}
}
return &paymenttypes.Money{
Amount: money.GetAmount(),
Currency: money.GetCurrency(),
}
}
func MonenyToProto(money *paymenttypes.Money) *moneyv1.Money {
if money == nil {
return &moneyv1.Money{}
}
return &moneyv1.Money{
Amount: money.Amount,
Currency: money.Currency,
}
}

View File

@@ -1,50 +0,0 @@
package shared
import (
"math/big"
"strings"
"github.com/tech/sendico/pkg/merrors"
)
var (
errHexEmpty = merrors.InvalidArgument("hex value is empty")
errHexInvalid = merrors.InvalidArgument("invalid hex number")
errHexOutOfRange = merrors.InvalidArgument("hex number out of range")
)
// DecodeHexBig parses a hex string that may include leading zero digits.
func DecodeHexBig(input string) (*big.Int, error) {
trimmed := strings.TrimSpace(input)
if trimmed == "" {
return nil, errHexEmpty
}
noPrefix := strings.TrimPrefix(trimmed, "0x")
if noPrefix == "" {
return nil, errHexEmpty
}
value := strings.TrimLeft(noPrefix, "0")
if value == "" {
return big.NewInt(0), nil
}
val := new(big.Int)
if _, ok := val.SetString(value, 16); !ok {
return nil, errHexInvalid
}
return val, nil
}
// DecodeHexUint8 parses a hex string into uint8, allowing leading zeros.
func DecodeHexUint8(input string) (uint8, error) {
val, err := DecodeHexBig(input)
if err != nil {
return 0, err
}
if val == nil {
return 0, errHexInvalid
}
if val.BitLen() > 8 {
return 0, errHexOutOfRange
}
return uint8(val.Uint64()), nil
}

View File

@@ -1,16 +0,0 @@
package shared
import "testing"
func TestDecodeHexUint8_LeadingZeros(t *testing.T) {
t.Parallel()
const resp = "0x0000000000000000000000000000000000000000000000000000000000000006"
val, err := DecodeHexUint8(resp)
if err != nil {
t.Fatalf("DecodeHexUint8 error: %v", err)
}
if val != 6 {
t.Fatalf("DecodeHexUint8 value = %d, want 6", val)
}
}

View File

@@ -1,37 +0,0 @@
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
}

View File

@@ -8,7 +8,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"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/shared"
"github.com/tech/sendico/gateway/tron/storage/model"
"github.com/tech/sendico/pkg/merrors"
"go.uber.org/zap"

View File

@@ -6,7 +6,7 @@ import (
"strings"
"time"
"github.com/tech/sendico/gateway/tron/internal/service/gateway/shared"
"github.com/tech/sendico/gateway/tron/shared"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"go.uber.org/zap"