Skip to content

Commit

Permalink
fix to generate names for one account
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhar-petukhov committed Jan 14, 2025
1 parent 873cd2c commit c6d643f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 35 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
18 changes: 6 additions & 12 deletions pkg/addressbook/addressbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
31 changes: 15 additions & 16 deletions pkg/addressbook/attached_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -69,20 +68,20 @@ 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,
Type: accountType,
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
Expand Down

0 comments on commit c6d643f

Please sign in to comment.