Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/api/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type storage interface {
GetDomainInfo(ctx context.Context, domain string) (core.NftItem, int64, error)

GetWalletPubKey(ctx context.Context, address tongo.AccountID) (ed25519.PublicKey, error)
GetWalletAddressesByPubkey(ctx context.Context, pubKey ed25519.PublicKey) (map[ton.AccountID]abi.ContractInterface, error)
GetSubscriptionsV2(ctx context.Context, address tongo.AccountID) ([]core.SubscriptionV2, error)
GetSubscriptionsV1(ctx context.Context, address tongo.AccountID) ([]core.SubscriptionV1, error)
GetJettonMasters(ctx context.Context, limit, offset int) ([]core.JettonMaster, error)
Expand Down
34 changes: 5 additions & 29 deletions pkg/api/wallet_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package api

import (
"context"
"crypto/ed25519"
"encoding/hex"
"errors"
"fmt"
Expand All @@ -26,9 +25,12 @@ func (h *Handler) GetWalletsByPublicKey(ctx context.Context, params oas.GetWalle
if err != nil {
return nil, toError(http.StatusBadRequest, err)
}
versions := getWalletAddressesByPubkey(publicKey)
versions, err := h.storage.GetWalletAddressesByPubkey(ctx, publicKey)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
var addresses []ton.AccountID
for addr, _ := range versions {
for addr := range versions {
addresses = append(addresses, addr)
}
rawAccounts, err := h.storage.GetRawAccounts(ctx, addresses)
Expand Down Expand Up @@ -172,29 +174,3 @@ func (h *Handler) processWallet(ctx context.Context, account *core.Account) (*oa
}
return &converted, nil, http.StatusOK
}

var SupportedWallets = map[tongoWallet.Version]abi.ContractInterface{
tongoWallet.V1R1: abi.WalletV1R1,
tongoWallet.V1R2: abi.WalletV1R2,
tongoWallet.V1R3: abi.WalletV1R3,
tongoWallet.V2R1: abi.WalletV2R1,
tongoWallet.V2R2: abi.WalletV2R2,
tongoWallet.V3R1: abi.WalletV3R1,
tongoWallet.V3R2: abi.WalletV3R2,
tongoWallet.V4R1: abi.WalletV4R1,
tongoWallet.V4R2: abi.WalletV4R2,
tongoWallet.V5Beta: abi.WalletV5Beta,
tongoWallet.V5R1: abi.WalletV5R1,
}

func getWalletAddressesByPubkey(pubKey ed25519.PublicKey) map[ton.AccountID]abi.ContractInterface {
wallets := make(map[ton.AccountID]abi.ContractInterface, len(SupportedWallets))
for version, ifc := range SupportedWallets {
walletAddress, err := tongoWallet.GenerateWalletAddress(pubKey, version, nil, 0, nil)
if err != nil {
continue
}
wallets[walletAddress] = ifc
}
return wallets
}
32 changes: 32 additions & 0 deletions pkg/litestorage/litestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/tonkeeper/tongo/tep64"
"github.com/tonkeeper/tongo/tlb"
"github.com/tonkeeper/tongo/ton"
"github.com/tonkeeper/tongo/wallet"
"go.uber.org/zap"
"golang.org/x/exp/maps"

Expand Down Expand Up @@ -526,6 +527,37 @@ func (s *LiteStorage) GetWalletPubKey(ctx context.Context, address tongo.Account
return nil, fmt.Errorf("can't get public key")
}

var SupportedWallets = map[wallet.Version]abi.ContractInterface{
wallet.V1R1: abi.WalletV1R1,
wallet.V1R2: abi.WalletV1R2,
wallet.V1R3: abi.WalletV1R3,
wallet.V2R1: abi.WalletV2R1,
wallet.V2R2: abi.WalletV2R2,
wallet.V3R1: abi.WalletV3R1,
wallet.V3R2: abi.WalletV3R2,
wallet.V4R1: abi.WalletV4R1,
wallet.V4R2: abi.WalletV4R2,
wallet.V5Beta: abi.WalletV5Beta,
wallet.V5R1: abi.WalletV5R1,
}

func (s *LiteStorage) GetWalletAddressesByPubkey(ctx context.Context, pubKey ed25519.PublicKey) (map[ton.AccountID]abi.ContractInterface, error) {
timer := prometheus.NewTimer(prometheus.ObserverFunc(func(v float64) {
storageTimeHistogramVec.WithLabelValues("get_wallet_addresses_by_pubkey").Observe(v)
}))
defer timer.ObserveDuration()

wallets := make(map[ton.AccountID]abi.ContractInterface, len(SupportedWallets))
for version, ifc := range SupportedWallets {
walletAddress, err := wallet.GenerateWalletAddress(pubKey, version, nil, 0, nil)
if err != nil {
continue
}
wallets[walletAddress] = ifc
}
return wallets, nil
}

func (s *LiteStorage) ReindexAccount(ctx context.Context, accountID tongo.AccountID) error {
timer := prometheus.NewTimer(prometheus.ObserverFunc(func(v float64) {
storageTimeHistogramVec.WithLabelValues("reindex_account").Observe(v)
Expand Down
Loading