Skip to content

Commit 03313c0

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents ab20e62 + 307a546 commit 03313c0

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

pkg/api/account_converters.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package api
22

33
import (
44
"fmt"
5-
imgGenerator "github.com/tonkeeper/opentonapi/pkg/image"
6-
"github.com/tonkeeper/opentonapi/pkg/references"
75
"math/big"
86
"sort"
97

8+
imgGenerator "github.com/tonkeeper/opentonapi/pkg/image"
9+
"github.com/tonkeeper/opentonapi/pkg/references"
10+
1011
"github.com/tonkeeper/tongo/abi"
1112
"github.com/tonkeeper/tongo/tlb"
1213

@@ -94,7 +95,7 @@ func convertExtraCurrencies(extraBalances core.ExtraCurrencies) []oas.ExtraCurre
9495
return res
9596
}
9697

97-
func convertToAccount(account *core.Account, ab *addressbook.KnownAddress, state chainState) oas.Account {
98+
func convertToAccount(account *core.Account, ab *addressbook.KnownAddress, state chainState, spamFilter SpamFilter) oas.Account {
9899
acc := oas.Account{
99100
Address: account.AccountAddress.ToRaw(),
100101
Balance: account.TonBalance,
@@ -119,10 +120,16 @@ func convertToAccount(account *core.Account, ab *addressbook.KnownAddress, state
119120
}
120121
}
121122
}
123+
trust := spamFilter.AccountTrust(account.AccountAddress)
124+
if trust == core.TrustBlacklist {
125+
acc.IsScam = oas.NewOptBool(true)
126+
}
122127
if ab == nil {
123128
return acc
124129
}
125-
acc.IsScam = oas.NewOptBool(ab.IsScam)
130+
if !acc.IsScam.Value {
131+
acc.IsScam = oas.NewOptBool(ab.IsScam)
132+
}
126133
if len(ab.Name) > 0 {
127134
acc.Name = oas.NewOptString(ab.Name)
128135
}

pkg/api/account_handlers.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ func (h *Handler) GetAccount(ctx context.Context, params oas.GetAccountParams) (
6969
ab, found := h.addressBook.GetAddressInfoByAddress(account.ID)
7070
var res oas.Account
7171
if found {
72-
res = convertToAccount(rawAccount, &ab, h.state)
72+
res = convertToAccount(rawAccount, &ab, h.state, h.spamFilter)
7373
} else {
74-
res = convertToAccount(rawAccount, nil, h.state)
74+
res = convertToAccount(rawAccount, nil, h.state, h.spamFilter)
7575
}
7676
if rawAccount.ExtraBalances != nil {
7777
res.ExtraBalance = convertExtraCurrencies(rawAccount.ExtraBalances)
@@ -114,9 +114,9 @@ func (h *Handler) GetAccounts(ctx context.Context, request oas.OptGetAccountsReq
114114
ab, found := h.addressBook.GetAddressInfoByAddress(account.AccountAddress)
115115
var res oas.Account
116116
if found {
117-
res = convertToAccount(account, &ab, h.state)
117+
res = convertToAccount(account, &ab, h.state, h.spamFilter)
118118
} else {
119-
res = convertToAccount(account, nil, h.state)
119+
res = convertToAccount(account, nil, h.state, h.spamFilter)
120120
}
121121
if account.ExtraBalances != nil {
122122
res.ExtraBalance = convertExtraCurrencies(account.ExtraBalances)
@@ -275,6 +275,10 @@ func (h *Handler) SearchAccounts(ctx context.Context, params oas.SearchAccountsP
275275
continue
276276
}
277277
}
278+
trust := h.spamFilter.AccountTrust(account.Wallet)
279+
if trust == core.TrustBlacklist {
280+
continue
281+
}
278282
parsedAccounts[account.Wallet] = account
279283
}
280284
accounts := maps.Values(parsedAccounts)

pkg/api/interfaces.go

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ type scoreSource interface {
186186
type SpamFilter interface {
187187
CheckActions(actions []oas.Action, viewer *ton.AccountID, initiator ton.AccountID) bool
188188
JettonTrust(address tongo.AccountID, symbol, name, image string) core.TrustType
189+
AccountTrust(address tongo.AccountID) core.TrustType
189190
NftTrust(address tongo.AccountID, collection *ton.AccountID, description, image string) core.TrustType
190191
}
191192

pkg/api/wallet_handlers.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
"encoding/hex"
66
"errors"
77
"fmt"
8-
"github.com/tonkeeper/opentonapi/pkg/core"
98
"net/http"
109

10+
"github.com/tonkeeper/opentonapi/pkg/core"
11+
1112
"github.com/tonkeeper/opentonapi/pkg/oas"
1213
"github.com/tonkeeper/opentonapi/pkg/wallet"
1314
"github.com/tonkeeper/tongo"
@@ -34,9 +35,9 @@ func (h *Handler) GetWalletsByPublicKey(ctx context.Context, params oas.GetWalle
3435
ab, found := h.addressBook.GetAddressInfoByAddress(account.AccountAddress)
3536
var res oas.Account
3637
if found {
37-
res = convertToAccount(account, &ab, h.state)
38+
res = convertToAccount(account, &ab, h.state, h.spamFilter)
3839
} else {
39-
res = convertToAccount(account, nil, h.state)
40+
res = convertToAccount(account, nil, h.state, h.spamFilter)
4041
}
4142
if account.ExtraBalances != nil {
4243
res.ExtraBalance = convertExtraCurrencies(account.ExtraBalances)

pkg/spam/spam.go

+4
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ func (f Filter) JettonTrust(address tongo.AccountID, symbol, name, image string)
4949
func (f Filter) NftTrust(address tongo.AccountID, collection *ton.AccountID, description, image string) core.TrustType {
5050
return core.TrustNone
5151
}
52+
53+
func (f Filter) AccountTrust(address tongo.AccountID) core.TrustType {
54+
return core.TrustNone
55+
}

0 commit comments

Comments
 (0)