Skip to content

Commit c6d643f

Browse files
fix to generate names for one account
1 parent 873cd2c commit c6d643f

File tree

4 files changed

+24
-35
lines changed

4 files changed

+24
-35
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/shopspring/decimal v1.3.1
2424
github.com/sourcegraph/conc v0.3.0
2525
github.com/stretchr/testify v1.9.0
26-
github.com/tonkeeper/scam_backoffice_rules v0.0.0-20241106130559-c44de2d4177b
26+
github.com/tonkeeper/scam_backoffice_rules v0.0.1
2727
github.com/tonkeeper/tongo v1.14.3
2828
go.opentelemetry.io/otel v1.24.0
2929
go.opentelemetry.io/otel/metric v1.24.0

go.sum

+2-6
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
268268
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
269269
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
270270
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
271-
github.com/tonkeeper/scam_backoffice_rules v0.0.0-20241106130559-c44de2d4177b h1:udp2XHUF2gba2mrHbPcEjmeedRoXvpldO+3mXDiKJ2A=
272-
github.com/tonkeeper/scam_backoffice_rules v0.0.0-20241106130559-c44de2d4177b/go.mod h1:SqZXYO9vbID8ku+xnnaKXeNGmehxigODGrk5V1KqbRA=
273-
github.com/tonkeeper/tongo v1.13.0 h1:LesxO+HFrLSkhDYMXLl+zlabZpVTnaMNHUqwkIhzl0c=
274-
github.com/tonkeeper/tongo v1.13.0/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs=
275-
github.com/tonkeeper/tongo v1.14.2 h1:Ji+G2RfHbXGuRs7FG2iSLUGOW3zWU8TnYtM/LuZbG7w=
276-
github.com/tonkeeper/tongo v1.14.2/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs=
271+
github.com/tonkeeper/scam_backoffice_rules v0.0.1 h1:q98OLTO2tjaTOCxBl3EmY+PMClkvamR0+c7ytIisH7o=
272+
github.com/tonkeeper/scam_backoffice_rules v0.0.1/go.mod h1:SqZXYO9vbID8ku+xnnaKXeNGmehxigODGrk5V1KqbRA=
277273
github.com/tonkeeper/tongo v1.14.3 h1:euA0eM+vh6AlRY/TovD1aOhZ3D/pE38P96Ao6y5V5B0=
278274
github.com/tonkeeper/tongo v1.14.3/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs=
279275
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=

pkg/addressbook/addressbook.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,11 @@ func (m *manualAddresser) refreshAddresses(addressPath string) error {
297297
item.Address = account.ID.ToRaw()
298298
knownAccounts[account.ID] = item
299299
// Generate name variants for the account
300-
names := GenerateNameVariants(item.Name)
301-
for idx, name := range names {
300+
slugs := GenerateSlugVariants(item.Name)
301+
for _, slug := range slugs {
302302
weight := KnownAccountWeight
303-
if idx == 0 { // Boost weight for the first name
304-
weight *= BoostForOriginalName
305-
}
306303
// Convert known account to attached account
307-
attachedAccount, err := ConvertAttachedAccount(name, item.Image, account.ID, weight, core.TrustWhitelist, ManualAccountType)
304+
attachedAccount, err := ConvertAttachedAccount(item.Name, slug, item.Image, account.ID, weight, core.TrustWhitelist, ManualAccountType)
308305
if err != nil {
309306
continue
310307
}
@@ -388,14 +385,11 @@ func (b *Book) refreshJettons(addresser *manualAddresser, jettonPath string) err
388385
item.Address = account.ID.ToRaw()
389386
knownJettons[account.ID] = item
390387
// Generate name variants for the jetton
391-
names := GenerateNameVariants(item.Name)
392-
for idx, name := range names {
388+
slugs := GenerateSlugVariants(item.Name)
389+
for _, slug := range slugs {
393390
weight := KnownAccountWeight
394-
if idx == 0 { // Boost weight for the first name
395-
weight *= BoostForOriginalName
396-
}
397391
// Convert known account to attached account
398-
attachedAccount, err := ConvertAttachedAccount(name, item.Image, account.ID, weight, core.TrustWhitelist, JettonNameAccountType)
392+
attachedAccount, err := ConvertAttachedAccount(item.Name, slug, item.Image, account.ID, weight, core.TrustWhitelist, JettonNameAccountType)
399393
if err != nil {
400394
continue
401395
}

pkg/addressbook/attached_accounts.go

+15-16
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import (
1313

1414
// AttachedAccountType represents the type of the attached account
1515
const (
16-
KnownAccountWeight = 1000
17-
BoostForFullMatch = 100
18-
BoostForOriginalName = 50
19-
BoostForVerified = 5
16+
KnownAccountWeight = 1000
17+
BoostForFullMatch = 100
18+
BoostForVerified = 10
2019
)
2120

2221
// AttachedAccount represents domains, nft collections for quick search by name are presented
@@ -34,31 +33,31 @@ type AttachedAccount struct {
3433
}
3534

3635
// ConvertAttachedAccount converts a known account to an attached account
37-
func ConvertAttachedAccount(slug, image string, account ton.AccountID, weight int, trust core.TrustType, accountType AttachedAccountType) (AttachedAccount, error) {
38-
var name string
36+
func ConvertAttachedAccount(name, slug, image string, account ton.AccountID, weight int, trust core.TrustType, accountType AttachedAccountType) (AttachedAccount, error) {
37+
var convertedName string
3938
// Handle different account types and assign appropriate values
4039
switch accountType {
4140
case TonDomainAccountType, TgDomainAccountType:
4241
weight = 1000
43-
name = fmt.Sprintf("%v · account", slug)
42+
convertedName = fmt.Sprintf("%v · account", name)
4443
// Generate image URL for "t.me" subdomains
45-
if strings.HasSuffix(slug, "t.me") && strings.Count(slug, ".") == 2 {
46-
image = fmt.Sprintf("https://t.me/i/userpic/320/%v.jpg", strings.TrimSuffix(slug, ".t.me"))
44+
if strings.HasSuffix(name, "t.me") && strings.Count(name, ".") == 2 {
45+
image = fmt.Sprintf("https://t.me/i/userpic/320/%v.jpg", strings.TrimSuffix(name, ".t.me"))
4746
} else {
4847
image = references.PlugAutoCompleteDomain
4948
}
5049
case JettonSymbolAccountType, JettonNameAccountType:
51-
name = fmt.Sprintf("%v · jetton", slug)
50+
convertedName = fmt.Sprintf("%v · jetton", name)
5251
if image == "" {
5352
image = references.PlugAutoCompleteJetton
5453
}
5554
case NftCollectionAccountType:
56-
name = fmt.Sprintf("%v · collection", slug)
55+
convertedName = fmt.Sprintf("%v · collection", name)
5756
if image == "" {
5857
image = references.PlugAutoCompleteCollection
5958
}
6059
case ManualAccountType:
61-
name = fmt.Sprintf("%v · account", slug)
60+
convertedName = fmt.Sprintf("%v · account", name)
6261
if image == "" {
6362
image = references.PlugAutoCompleteAccount
6463
}
@@ -69,20 +68,20 @@ func ConvertAttachedAccount(slug, image string, account ton.AccountID, weight in
6968
image = imgGenerator.DefaultGenerator.GenerateImageUrl(image, 200, 200)
7069
}
7170
return AttachedAccount{
72-
Name: name,
71+
Name: convertedName,
7372
Slug: slug,
7473
Preview: image,
7574
Wallet: account,
7675
Type: accountType,
7776
Weight: int64(weight),
7877
Popular: int64(weight),
7978
Trust: trust,
80-
Normalized: rules.NormalizeJettonSymbol(slug),
79+
Normalized: rules.NormalizeString(slug),
8180
}, nil
8281
}
8382

84-
// GenerateNameVariants generates name variants by rotating the words
85-
func GenerateNameVariants(name string) []string {
83+
// GenerateSlugVariants generates name variants by rotating the words
84+
func GenerateSlugVariants(name string) []string {
8685
words := strings.Fields(name) // Split the name into words
8786
var variants []string
8887
// Generate up to 3 variants by rotating the words

0 commit comments

Comments
 (0)