diff --git a/pkg/api/interfaces.go b/pkg/api/interfaces.go index 67dc6da2..e0912902 100644 --- a/pkg/api/interfaces.go +++ b/pkg/api/interfaces.go @@ -65,7 +65,7 @@ type storage interface { GetJettonWalletsByOwnerAddress(ctx context.Context, address tongo.AccountID) ([]core.JettonWallet, error) GetJettonsHoldersCount(ctx context.Context, accountIDs []tongo.AccountID) (map[tongo.AccountID]int32, error) - GetJettonHolders(ctx context.Context, jettonMaster tongo.AccountID) (map[tongo.AccountID]string, error) + GetJettonHolders(ctx context.Context, jettonMaster tongo.AccountID) ([]core.JettonHolder, error) GetJettonMasterMetadata(ctx context.Context, master tongo.AccountID) (tongo.JettonMetadata, error) GetJettonMasterData(ctx context.Context, master tongo.AccountID) (abi.GetJettonDataResult, error) GetAccountJettonsHistory(ctx context.Context, address tongo.AccountID, limit int, beforeLT *int64, startTime *int64, endTime *int64) ([]tongo.Bits256, error) diff --git a/pkg/api/jetton_handlers.go b/pkg/api/jetton_handlers.go index fec302bd..e926f817 100644 --- a/pkg/api/jetton_handlers.go +++ b/pkg/api/jetton_handlers.go @@ -5,8 +5,6 @@ import ( "errors" "math/big" "net/http" - "sort" - "strconv" "github.com/tonkeeper/tongo" "github.com/tonkeeper/tongo/liteapi" @@ -175,27 +173,16 @@ func (h Handler) GetJettonHolders(ctx context.Context, params oas.GetJettonHolde if err != nil { return nil, toError(http.StatusBadRequest, err) } - accounts, err := h.storage.GetJettonHolders(ctx, accountID) + holders, err := h.storage.GetJettonHolders(ctx, accountID) if err != nil { return nil, toError(http.StatusInternalServerError, err) } var results oas.JettonHolders - for account, balance := range accounts { + for _, holder := range holders { results.Addresses = append(results.Addresses, oas.JettonHoldersAddressesItem{ - Address: account.ToRaw(), - Balance: balance, + Address: holder.Address.ToRaw(), + Balance: holder.Balance.String(), }) } - sort.Slice(results.Addresses, func(i, j int) bool { - firstBalance, err := strconv.ParseInt(results.Addresses[i].Balance, 10, 64) - if err != nil { - return false - } - secondBalance, err := strconv.ParseInt(results.Addresses[j].Balance, 10, 64) - if err != nil { - return false - } - return firstBalance > secondBalance - }) return &results, nil } diff --git a/pkg/core/jetton.go b/pkg/core/jetton.go index 3cd7ffee..2e4b9af8 100644 --- a/pkg/core/jetton.go +++ b/pkg/core/jetton.go @@ -17,6 +17,12 @@ type JettonWallet struct { Code []byte } +type JettonHolder struct { + JettonAddress tongo.AccountID + Address tongo.AccountID + Balance decimal.Decimal +} + type JettonMaster struct { // Address of a jetton master. Address tongo.AccountID