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,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"

View File

@@ -0,0 +1,52 @@
package shared
import (
"bytes"
"crypto/sha256"
"encoding/hex"
"fmt"
"strings"
"github.com/shengdoushi/base58"
"github.com/tech/sendico/pkg/merrors"
)
func TronBase58ToHex(addr string) (string, error) {
const (
tronAddrLen = 25
tronPrefix = byte(0x41)
)
raw, err := base58.Decode(strings.TrimSpace(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(
fmt.Sprintf("tron address: invalid length %d", len(raw)),
)
}
// 21 байт: prefix + 20 байт EVM
payload := raw[:21]
checksum := raw[21:]
if payload[0] != tronPrefix {
return "", merrors.DataConflict("tron address: invalid prefix")
}
// validate checksum (double sha256)
h1 := sha256.Sum256(payload)
h2 := sha256.Sum256(h1[:])
expectedChecksum := h2[:4]
if !bytes.Equal(expectedChecksum, checksum) {
return "", merrors.DataConflict("tron address: invalid checksum")
}
evm := payload[1:]
return "0x" + hex.EncodeToString(evm), nil
}