Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-tron committed Jan 10, 2025
2 parents ab20e62 + 307a546 commit 03313c0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
15 changes: 11 additions & 4 deletions pkg/api/account_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package api

import (
"fmt"
imgGenerator "github.com/tonkeeper/opentonapi/pkg/image"
"github.com/tonkeeper/opentonapi/pkg/references"
"math/big"
"sort"

imgGenerator "github.com/tonkeeper/opentonapi/pkg/image"
"github.com/tonkeeper/opentonapi/pkg/references"

"github.com/tonkeeper/tongo/abi"
"github.com/tonkeeper/tongo/tlb"

Expand Down Expand Up @@ -94,7 +95,7 @@ func convertExtraCurrencies(extraBalances core.ExtraCurrencies) []oas.ExtraCurre
return res
}

func convertToAccount(account *core.Account, ab *addressbook.KnownAddress, state chainState) oas.Account {
func convertToAccount(account *core.Account, ab *addressbook.KnownAddress, state chainState, spamFilter SpamFilter) oas.Account {
acc := oas.Account{
Address: account.AccountAddress.ToRaw(),
Balance: account.TonBalance,
Expand All @@ -119,10 +120,16 @@ func convertToAccount(account *core.Account, ab *addressbook.KnownAddress, state
}
}
}
trust := spamFilter.AccountTrust(account.AccountAddress)
if trust == core.TrustBlacklist {
acc.IsScam = oas.NewOptBool(true)
}
if ab == nil {
return acc
}
acc.IsScam = oas.NewOptBool(ab.IsScam)
if !acc.IsScam.Value {
acc.IsScam = oas.NewOptBool(ab.IsScam)
}
if len(ab.Name) > 0 {
acc.Name = oas.NewOptString(ab.Name)
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/api/account_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ func (h *Handler) GetAccount(ctx context.Context, params oas.GetAccountParams) (
ab, found := h.addressBook.GetAddressInfoByAddress(account.ID)
var res oas.Account
if found {
res = convertToAccount(rawAccount, &ab, h.state)
res = convertToAccount(rawAccount, &ab, h.state, h.spamFilter)
} else {
res = convertToAccount(rawAccount, nil, h.state)
res = convertToAccount(rawAccount, nil, h.state, h.spamFilter)
}
if rawAccount.ExtraBalances != nil {
res.ExtraBalance = convertExtraCurrencies(rawAccount.ExtraBalances)
Expand Down Expand Up @@ -114,9 +114,9 @@ func (h *Handler) GetAccounts(ctx context.Context, request oas.OptGetAccountsReq
ab, found := h.addressBook.GetAddressInfoByAddress(account.AccountAddress)
var res oas.Account
if found {
res = convertToAccount(account, &ab, h.state)
res = convertToAccount(account, &ab, h.state, h.spamFilter)
} else {
res = convertToAccount(account, nil, h.state)
res = convertToAccount(account, nil, h.state, h.spamFilter)
}
if account.ExtraBalances != nil {
res.ExtraBalance = convertExtraCurrencies(account.ExtraBalances)
Expand Down Expand Up @@ -275,6 +275,10 @@ func (h *Handler) SearchAccounts(ctx context.Context, params oas.SearchAccountsP
continue
}
}
trust := h.spamFilter.AccountTrust(account.Wallet)
if trust == core.TrustBlacklist {
continue
}
parsedAccounts[account.Wallet] = account
}
accounts := maps.Values(parsedAccounts)
Expand Down
1 change: 1 addition & 0 deletions pkg/api/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ type scoreSource interface {
type SpamFilter interface {
CheckActions(actions []oas.Action, viewer *ton.AccountID, initiator ton.AccountID) bool
JettonTrust(address tongo.AccountID, symbol, name, image string) core.TrustType
AccountTrust(address tongo.AccountID) core.TrustType
NftTrust(address tongo.AccountID, collection *ton.AccountID, description, image string) core.TrustType
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/api/wallet_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/tonkeeper/opentonapi/pkg/core"
"net/http"

"github.com/tonkeeper/opentonapi/pkg/core"

"github.com/tonkeeper/opentonapi/pkg/oas"
"github.com/tonkeeper/opentonapi/pkg/wallet"
"github.com/tonkeeper/tongo"
Expand All @@ -34,9 +35,9 @@ func (h *Handler) GetWalletsByPublicKey(ctx context.Context, params oas.GetWalle
ab, found := h.addressBook.GetAddressInfoByAddress(account.AccountAddress)
var res oas.Account
if found {
res = convertToAccount(account, &ab, h.state)
res = convertToAccount(account, &ab, h.state, h.spamFilter)
} else {
res = convertToAccount(account, nil, h.state)
res = convertToAccount(account, nil, h.state, h.spamFilter)
}
if account.ExtraBalances != nil {
res.ExtraBalance = convertExtraCurrencies(account.ExtraBalances)
Expand Down
4 changes: 4 additions & 0 deletions pkg/spam/spam.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ func (f Filter) JettonTrust(address tongo.AccountID, symbol, name, image string)
func (f Filter) NftTrust(address tongo.AccountID, collection *ton.AccountID, description, image string) core.TrustType {
return core.TrustNone
}

func (f Filter) AccountTrust(address tongo.AccountID) core.TrustType {
return core.TrustNone
}

0 comments on commit 03313c0

Please sign in to comment.