diff --git a/api/openapi.json b/api/openapi.json index 10ac4108..ea318b38 100644 --- a/api/openapi.json +++ b/api/openapi.json @@ -3011,11 +3011,20 @@ "preview": { "example": "https://cache.tonapi.io/images/media.jpg", "type": "string" + }, + "type": { + "enum": [ + "jetton", + "nft", + "wallet" + ], + "type": "string" } }, "required": [ "address", "name", + "type", "preview" ], "type": "object" diff --git a/api/openapi.yml b/api/openapi.yml index 58691f3c..56e77fe9 100644 --- a/api/openapi.yml +++ b/api/openapi.yml @@ -6421,6 +6421,7 @@ components: required: - address - name + - type - preview properties: address: @@ -6432,6 +6433,12 @@ components: preview: type: string example: "https://cache.tonapi.io/images/media.jpg" + type: + type: string + enum: + - jetton + - nft + - wallet DnsExpiring: type: object required: diff --git a/go.sum b/go.sum index 43817321..d014739a 100644 --- a/go.sum +++ b/go.sum @@ -270,26 +270,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-20240412152144-9fb01586a942 h1:5yExly0WuV9P0e2nHWeDV86qQ+7zKeNTWqIpoIJ+g9M= -github.com/tonkeeper/scam_backoffice_rules v0.0.0-20240412152144-9fb01586a942/go.mod h1:SqZXYO9vbID8ku+xnnaKXeNGmehxigODGrk5V1KqbRA= github.com/tonkeeper/scam_backoffice_rules v0.0.0-20240522102801-ac5f863d8f14 h1:09T5ALZw2OOuxJmUGnK1saTBv/+wPGyBL7b4rRDGsk0= github.com/tonkeeper/scam_backoffice_rules v0.0.0-20240522102801-ac5f863d8f14/go.mod h1:SqZXYO9vbID8ku+xnnaKXeNGmehxigODGrk5V1KqbRA= -github.com/tonkeeper/tongo v1.7.2 h1:v5Tmmqn4oNUlLTB+ASAZNuBXtBqqFhS6Nd5D4ie99J0= -github.com/tonkeeper/tongo v1.7.2/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs= -github.com/tonkeeper/tongo v1.8.0 h1:vYFm1xzEnuVsNRHTAghVB9bujc49i+9ovjGTHWxaQ0w= -github.com/tonkeeper/tongo v1.8.0/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs= -github.com/tonkeeper/tongo v1.8.1 h1:1cix2RL2+Oifbr2jaVCTehJBmS9DACxMnstx7050F+U= -github.com/tonkeeper/tongo v1.8.1/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs= -github.com/tonkeeper/tongo v1.8.2 h1:zu3jteP87OtYhP7gDKv9643qaDwm6NF3lDCQgEy72jc= -github.com/tonkeeper/tongo v1.8.2/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs= -github.com/tonkeeper/tongo v1.8.3 h1:9NOUa6gkdzRINcDLTzHE9j89YRKS3d3Lu+og5RFPa4E= -github.com/tonkeeper/tongo v1.8.3/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs= -github.com/tonkeeper/tongo v1.8.5 h1:oG2i4tiNK+DeeiFd5E27SRn2tjF0gFqpzm1yUN1Ituo= -github.com/tonkeeper/tongo v1.8.5/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs= -github.com/tonkeeper/tongo v1.8.7 h1:tg24GzBAltO4RGZFNZOt+7CpsZEI42m3dHruG1GzMI4= -github.com/tonkeeper/tongo v1.8.7/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs= -github.com/tonkeeper/tongo v1.8.8 h1:n7boS77Gg/SG0g5pvxcS66deNsHyMqlRJ+gLZzq3fos= -github.com/tonkeeper/tongo v1.8.8/go.mod h1:MjgIgAytFarjCoVjMLjYEtpZNN1f2G/pnZhKjr28cWs= github.com/tonkeeper/tongo v1.8.9 h1:JC4tjO2s4/741oxHIzWl2IaETLYZ2YIshByDJDuf/Do= github.com/tonkeeper/tongo v1.8.9/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 9a6c0f35..56e8825f 100644 --- a/pkg/addressbook/addressbook.go +++ b/pkg/addressbook/addressbook.go @@ -31,13 +31,22 @@ type KnownAddress struct { Image string `json:"image,omitempty"` } +type AccountType string + +const ( + Jetton AccountType = "jetton" + Nft AccountType = "nft" + Wallet AccountType = "wallet" +) + // AttachedAccount represents domains, nft collections for quick search by name are presented type AttachedAccount struct { - Name string `json:"name"` - Preview string `json:"preview"` - Wallet string `json:"wallet"` - Symbol string `json:"-"` - Normalized string `json:"-"` + Name string `json:"name"` + Preview string `json:"preview"` + Wallet string `json:"wallet"` + AccountType AccountType `json:"-"` + Symbol string `json:"-"` + Normalized string `json:"-"` } type JettonVerificationType string diff --git a/pkg/api/account_handlers.go b/pkg/api/account_handlers.go index 568ef85a..8c1d5147 100644 --- a/pkg/api/account_handlers.go +++ b/pkg/api/account_handlers.go @@ -260,12 +260,16 @@ func (h *Handler) SearchAccounts(ctx context.Context, params oas.SearchAccountsP response.Addresses = append(response.Addresses, oas.FoundAccountsAddressesItem{ Address: account.Wallet, Name: account.Name, + Type: oas.FoundAccountsAddressesItemType(account.AccountType), Preview: account.Preview, }) } sort.Slice(response.Addresses, func(i, j int) bool { - return response.Addresses[i].Address == references.USDT.ToRaw() + if response.Addresses[i].Address == references.USDT.ToRaw() { + return true + } + return response.Addresses[i].Type == oas.FoundAccountsAddressesItemTypeWallet }) return &response, nil diff --git a/pkg/oas/oas_json_gen.go b/pkg/oas/oas_json_gen.go index ad3ef69f..628b9c0e 100644 --- a/pkg/oas/oas_json_gen.go +++ b/pkg/oas/oas_json_gen.go @@ -15180,12 +15180,17 @@ func (s *FoundAccountsAddressesItem) encodeFields(e *jx.Encoder) { e.FieldStart("preview") e.Str(s.Preview) } + { + e.FieldStart("type") + s.Type.Encode(e) + } } -var jsonFieldsNameOfFoundAccountsAddressesItem = [3]string{ +var jsonFieldsNameOfFoundAccountsAddressesItem = [4]string{ 0: "address", 1: "name", 2: "preview", + 3: "type", } // Decode decodes FoundAccountsAddressesItem from json. @@ -15233,6 +15238,16 @@ func (s *FoundAccountsAddressesItem) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"preview\"") } + case "type": + requiredBitSet[0] |= 1 << 3 + if err := func() error { + if err := s.Type.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"type\"") + } default: return d.Skip() } @@ -15243,7 +15258,7 @@ func (s *FoundAccountsAddressesItem) Decode(d *jx.Decoder) error { // Validate required fields. var failures []validate.FieldError for i, mask := range [1]uint8{ - 0b00000111, + 0b00001111, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. @@ -15289,6 +15304,48 @@ func (s *FoundAccountsAddressesItem) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes FoundAccountsAddressesItemType as json. +func (s FoundAccountsAddressesItemType) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes FoundAccountsAddressesItemType from json. +func (s *FoundAccountsAddressesItemType) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode FoundAccountsAddressesItemType to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch FoundAccountsAddressesItemType(v) { + case FoundAccountsAddressesItemTypeJetton: + *s = FoundAccountsAddressesItemTypeJetton + case FoundAccountsAddressesItemTypeNft: + *s = FoundAccountsAddressesItemTypeNft + case FoundAccountsAddressesItemTypeWallet: + *s = FoundAccountsAddressesItemTypeWallet + default: + *s = FoundAccountsAddressesItemType(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s FoundAccountsAddressesItemType) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *FoundAccountsAddressesItemType) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode implements json.Marshaler. func (s *GasLimitPrices) Encode(e *jx.Encoder) { e.ObjStart() diff --git a/pkg/oas/oas_schemas_gen.go b/pkg/oas/oas_schemas_gen.go index dd2a029a..f688e502 100644 --- a/pkg/oas/oas_schemas_gen.go +++ b/pkg/oas/oas_schemas_gen.go @@ -5265,9 +5265,10 @@ func (s *FoundAccounts) SetAddresses(val []FoundAccountsAddressesItem) { } type FoundAccountsAddressesItem struct { - Address string `json:"address"` - Name string `json:"name"` - Preview string `json:"preview"` + Address string `json:"address"` + Name string `json:"name"` + Preview string `json:"preview"` + Type FoundAccountsAddressesItemType `json:"type"` } // GetAddress returns the value of Address. @@ -5285,6 +5286,11 @@ func (s *FoundAccountsAddressesItem) GetPreview() string { return s.Preview } +// GetType returns the value of Type. +func (s *FoundAccountsAddressesItem) GetType() FoundAccountsAddressesItemType { + return s.Type +} + // SetAddress sets the value of Address. func (s *FoundAccountsAddressesItem) SetAddress(val string) { s.Address = val @@ -5300,6 +5306,59 @@ func (s *FoundAccountsAddressesItem) SetPreview(val string) { s.Preview = val } +// SetType sets the value of Type. +func (s *FoundAccountsAddressesItem) SetType(val FoundAccountsAddressesItemType) { + s.Type = val +} + +type FoundAccountsAddressesItemType string + +const ( + FoundAccountsAddressesItemTypeJetton FoundAccountsAddressesItemType = "jetton" + FoundAccountsAddressesItemTypeNft FoundAccountsAddressesItemType = "nft" + FoundAccountsAddressesItemTypeWallet FoundAccountsAddressesItemType = "wallet" +) + +// AllValues returns all FoundAccountsAddressesItemType values. +func (FoundAccountsAddressesItemType) AllValues() []FoundAccountsAddressesItemType { + return []FoundAccountsAddressesItemType{ + FoundAccountsAddressesItemTypeJetton, + FoundAccountsAddressesItemTypeNft, + FoundAccountsAddressesItemTypeWallet, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s FoundAccountsAddressesItemType) MarshalText() ([]byte, error) { + switch s { + case FoundAccountsAddressesItemTypeJetton: + return []byte(s), nil + case FoundAccountsAddressesItemTypeNft: + return []byte(s), nil + case FoundAccountsAddressesItemTypeWallet: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *FoundAccountsAddressesItemType) UnmarshalText(data []byte) error { + switch FoundAccountsAddressesItemType(data) { + case FoundAccountsAddressesItemTypeJetton: + *s = FoundAccountsAddressesItemTypeJetton + return nil + case FoundAccountsAddressesItemTypeNft: + *s = FoundAccountsAddressesItemTypeNft + return nil + case FoundAccountsAddressesItemTypeWallet: + *s = FoundAccountsAddressesItemTypeWallet + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + // Ref: #/components/schemas/GasLimitPrices type GasLimitPrices struct { SpecialGasLimit OptInt64 `json:"special_gas_limit"` diff --git a/pkg/oas/oas_validators_gen.go b/pkg/oas/oas_validators_gen.go index 51fcbc06..2fba589d 100644 --- a/pkg/oas/oas_validators_gen.go +++ b/pkg/oas/oas_validators_gen.go @@ -2266,6 +2266,23 @@ func (s *FoundAccounts) Validate() error { if s.Addresses == nil { return errors.New("nil is invalid value") } + var failures []validate.FieldError + for i, elem := range s.Addresses { + if err := func() error { + if err := elem.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: fmt.Sprintf("[%d]", i), + Error: err, + }) + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } return nil }(); err != nil { failures = append(failures, validate.FieldError{ @@ -2279,6 +2296,42 @@ func (s *FoundAccounts) Validate() error { return nil } +func (s *FoundAccountsAddressesItem) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := s.Type.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "type", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s FoundAccountsAddressesItemType) Validate() error { + switch s { + case "jetton": + return nil + case "nft": + return nil + case "wallet": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + func (s *GetAccountsReq) Validate() error { if s == nil { return validate.ErrNilPointer