Skip to content

Commit

Permalink
api.NewHandler() to create no op spam filter when options.spamFilter …
Browse files Browse the repository at this point in the history
…== nil
  • Loading branch information
aleksej-paschenko committed Oct 20, 2023
1 parent 9da2f9d commit d622641
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/tonkeeper/opentonapi/pkg/blockchain/indexer"
"github.com/tonkeeper/opentonapi/pkg/spam"
"github.com/tonkeeper/tongo"
"go.uber.org/zap"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -49,11 +50,13 @@ func main() {
if err != nil {
log.Fatal("failed to create msg sender", zap.Error(err))
}
spamFilter := spam.NewSpamFilter()
h, err := api.NewHandler(log,
api.WithStorage(storage),
api.WithAddressBook(book),
api.WithExecutor(storage),
api.WithMessageSender(msgSender),
api.WithSpamFilter(spamFilter),
api.WithTonConnectSecret(cfg.TonConnect.Secret),
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func NewHandler(logger *zap.Logger, opts ...Option) (*Handler, error) {
options.chainState = chainstate.NewChainState(options.storage)
}
if options.spamFilter == nil {
options.spamFilter = spam.NewSpamFilter()
options.spamFilter = spam.NewNoOpSpamFilter()
}
if options.ratesSource == nil {
options.ratesSource = rates.Mock{Storage: options.storage}
Expand Down
22 changes: 22 additions & 0 deletions pkg/spam/no_op_spam_filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package spam

import (
rules "github.com/tonkeeper/scam_backoffice_rules"
"github.com/tonkeeper/tongo"
)

// NoOpSpamFilter is a spam filter that does nothing and pretends there is no spam in the TON blockchain.
type NoOpSpamFilter struct {
}

func NewNoOpSpamFilter() *NoOpSpamFilter {
return &NoOpSpamFilter{}
}

func (s *NoOpSpamFilter) GetRules() rules.Rules {
return nil
}

func (s *NoOpSpamFilter) IsJettonBlacklisted(address tongo.AccountID, symbol string) bool {
return false
}

0 comments on commit d622641

Please sign in to comment.