From c6d643fe51ac203e90ebfee9436f22f9b117d6ba Mon Sep 17 00:00:00 2001 From: Zakhar Petukhov Date: Tue, 14 Jan 2025 13:35:26 +0800 Subject: [PATCH] fix to generate names for one account --- go.mod | 2 +- go.sum | 8 ++----- pkg/addressbook/addressbook.go | 18 ++++++---------- pkg/addressbook/attached_accounts.go | 31 ++++++++++++++-------------- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/go.mod b/go.mod index 0907d0e7..d062e569 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/shopspring/decimal v1.3.1 github.com/sourcegraph/conc v0.3.0 github.com/stretchr/testify v1.9.0 - github.com/tonkeeper/scam_backoffice_rules v0.0.0-20241106130559-c44de2d4177b + github.com/tonkeeper/scam_backoffice_rules v0.0.1 github.com/tonkeeper/tongo v1.14.3 go.opentelemetry.io/otel v1.24.0 go.opentelemetry.io/otel/metric v1.24.0 diff --git a/go.sum b/go.sum index 1d56ef9f..30b1c5d4 100644 --- a/go.sum +++ b/go.sum @@ -268,12 +268,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/tonkeeper/scam_backoffice_rules v0.0.0-20241106130559-c44de2d4177b h1:udp2XHUF2gba2mrHbPcEjmeedRoXvpldO+3mXDiKJ2A= -github.com/tonkeeper/scam_backoffice_rules v0.0.0-20241106130559-c44de2d4177b/go.mod h1:SqZXYO9vbID8ku+xnnaKXeNGmehxigODGrk5V1KqbRA= -github.com/tonkeeper/tongo v1.13.0 h1:LesxO+HFrLSkhDYMXLl+zlabZpVTnaMNHUqwkIhzl0c= -github.com/tonkeeper/tongo v1.13.0/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs= -github.com/tonkeeper/tongo v1.14.2 h1:Ji+G2RfHbXGuRs7FG2iSLUGOW3zWU8TnYtM/LuZbG7w= -github.com/tonkeeper/tongo v1.14.2/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs= +github.com/tonkeeper/scam_backoffice_rules v0.0.1 h1:q98OLTO2tjaTOCxBl3EmY+PMClkvamR0+c7ytIisH7o= +github.com/tonkeeper/scam_backoffice_rules v0.0.1/go.mod h1:SqZXYO9vbID8ku+xnnaKXeNGmehxigODGrk5V1KqbRA= github.com/tonkeeper/tongo v1.14.3 h1:euA0eM+vh6AlRY/TovD1aOhZ3D/pE38P96Ao6y5V5B0= github.com/tonkeeper/tongo v1.14.3/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= diff --git a/pkg/addressbook/addressbook.go b/pkg/addressbook/addressbook.go index b64d0bc1..ec85fc5b 100644 --- a/pkg/addressbook/addressbook.go +++ b/pkg/addressbook/addressbook.go @@ -297,14 +297,11 @@ func (m *manualAddresser) refreshAddresses(addressPath string) error { item.Address = account.ID.ToRaw() knownAccounts[account.ID] = item // Generate name variants for the account - names := GenerateNameVariants(item.Name) - for idx, name := range names { + slugs := GenerateSlugVariants(item.Name) + for _, slug := range slugs { weight := KnownAccountWeight - if idx == 0 { // Boost weight for the first name - weight *= BoostForOriginalName - } // Convert known account to attached account - attachedAccount, err := ConvertAttachedAccount(name, item.Image, account.ID, weight, core.TrustWhitelist, ManualAccountType) + attachedAccount, err := ConvertAttachedAccount(item.Name, slug, item.Image, account.ID, weight, core.TrustWhitelist, ManualAccountType) if err != nil { continue } @@ -388,14 +385,11 @@ func (b *Book) refreshJettons(addresser *manualAddresser, jettonPath string) err item.Address = account.ID.ToRaw() knownJettons[account.ID] = item // Generate name variants for the jetton - names := GenerateNameVariants(item.Name) - for idx, name := range names { + slugs := GenerateSlugVariants(item.Name) + for _, slug := range slugs { weight := KnownAccountWeight - if idx == 0 { // Boost weight for the first name - weight *= BoostForOriginalName - } // Convert known account to attached account - attachedAccount, err := ConvertAttachedAccount(name, item.Image, account.ID, weight, core.TrustWhitelist, JettonNameAccountType) + attachedAccount, err := ConvertAttachedAccount(item.Name, slug, item.Image, account.ID, weight, core.TrustWhitelist, JettonNameAccountType) if err != nil { continue } diff --git a/pkg/addressbook/attached_accounts.go b/pkg/addressbook/attached_accounts.go index c4d4b944..3d1b9b79 100644 --- a/pkg/addressbook/attached_accounts.go +++ b/pkg/addressbook/attached_accounts.go @@ -13,10 +13,9 @@ import ( // AttachedAccountType represents the type of the attached account const ( - KnownAccountWeight = 1000 - BoostForFullMatch = 100 - BoostForOriginalName = 50 - BoostForVerified = 5 + KnownAccountWeight = 1000 + BoostForFullMatch = 100 + BoostForVerified = 10 ) // AttachedAccount represents domains, nft collections for quick search by name are presented @@ -34,31 +33,31 @@ type AttachedAccount struct { } // ConvertAttachedAccount converts a known account to an attached account -func ConvertAttachedAccount(slug, image string, account ton.AccountID, weight int, trust core.TrustType, accountType AttachedAccountType) (AttachedAccount, error) { - var name string +func ConvertAttachedAccount(name, slug, image string, account ton.AccountID, weight int, trust core.TrustType, accountType AttachedAccountType) (AttachedAccount, error) { + var convertedName string // Handle different account types and assign appropriate values switch accountType { case TonDomainAccountType, TgDomainAccountType: weight = 1000 - name = fmt.Sprintf("%v · account", slug) + convertedName = fmt.Sprintf("%v · account", name) // Generate image URL for "t.me" subdomains - if strings.HasSuffix(slug, "t.me") && strings.Count(slug, ".") == 2 { - image = fmt.Sprintf("https://t.me/i/userpic/320/%v.jpg", strings.TrimSuffix(slug, ".t.me")) + if strings.HasSuffix(name, "t.me") && strings.Count(name, ".") == 2 { + image = fmt.Sprintf("https://t.me/i/userpic/320/%v.jpg", strings.TrimSuffix(name, ".t.me")) } else { image = references.PlugAutoCompleteDomain } case JettonSymbolAccountType, JettonNameAccountType: - name = fmt.Sprintf("%v · jetton", slug) + convertedName = fmt.Sprintf("%v · jetton", name) if image == "" { image = references.PlugAutoCompleteJetton } case NftCollectionAccountType: - name = fmt.Sprintf("%v · collection", slug) + convertedName = fmt.Sprintf("%v · collection", name) if image == "" { image = references.PlugAutoCompleteCollection } case ManualAccountType: - name = fmt.Sprintf("%v · account", slug) + convertedName = fmt.Sprintf("%v · account", name) if image == "" { image = references.PlugAutoCompleteAccount } @@ -69,7 +68,7 @@ func ConvertAttachedAccount(slug, image string, account ton.AccountID, weight in image = imgGenerator.DefaultGenerator.GenerateImageUrl(image, 200, 200) } return AttachedAccount{ - Name: name, + Name: convertedName, Slug: slug, Preview: image, Wallet: account, @@ -77,12 +76,12 @@ func ConvertAttachedAccount(slug, image string, account ton.AccountID, weight in Weight: int64(weight), Popular: int64(weight), Trust: trust, - Normalized: rules.NormalizeJettonSymbol(slug), + Normalized: rules.NormalizeString(slug), }, nil } -// GenerateNameVariants generates name variants by rotating the words -func GenerateNameVariants(name string) []string { +// GenerateSlugVariants generates name variants by rotating the words +func GenerateSlugVariants(name string) []string { words := strings.Fields(name) // Split the name into words var variants []string // Generate up to 3 variants by rotating the words