Skip to content

Commit

Permalink
update code after review
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhar-petukhov committed Aug 31, 2023
1 parent 53f9bb3 commit a031d42
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkg/api/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 4 additions & 17 deletions pkg/api/jetton_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"errors"
"math/big"
"net/http"
"sort"
"strconv"

"github.com/tonkeeper/tongo"
"github.com/tonkeeper/tongo/liteapi"
Expand Down Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions pkg/core/jetton.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a031d42

Please sign in to comment.