From ffd7f2c8ab179950b62e83ee131204ffa4591c36 Mon Sep 17 00:00:00 2001 From: Zakhar Petukhov Date: Thu, 30 Nov 2023 15:22:05 +0700 Subject: [PATCH] create spam control for nft description --- api/openapi.json | 23 ++-- api/openapi.yml | 28 ++--- pkg/api/account_handlers.go | 2 +- pkg/api/dns_handlers.go | 2 +- pkg/api/event_converters.go | 6 +- pkg/api/jetton_converters.go | 2 +- pkg/api/jetton_handlers.go | 4 +- pkg/api/nft_converters.go | 97 ++++++++-------- pkg/api/nft_handlers.go | 15 +-- pkg/oas/oas_json_gen.go | 164 +++++++++++++++++---------- pkg/oas/oas_schemas_gen.go | 205 ++++++++++++++++++++++------------ pkg/oas/oas_validators_gen.go | 44 +++++--- tonapi/oas_json_gen.go | 164 +++++++++++++++++---------- tonapi/oas_schemas_gen.go | 205 ++++++++++++++++++++++------------ tonapi/oas_validators_gen.go | 44 +++++--- 15 files changed, 632 insertions(+), 373 deletions(-) diff --git a/api/openapi.json b/api/openapi.json index d7da7083..255ed5fc 100644 --- a/api/openapi.json +++ b/api/openapi.json @@ -3211,7 +3211,7 @@ "type": "string" }, "verification": { - "$ref": "#/components/schemas/JettonVerificationType" + "$ref": "#/components/schemas/VerificationType" } }, "required": [ @@ -3337,7 +3337,7 @@ "type": "string" }, "verification": { - "$ref": "#/components/schemas/JettonVerificationType" + "$ref": "#/components/schemas/VerificationType" } }, "required": [ @@ -3463,14 +3463,6 @@ ], "type": "object" }, - "JettonVerificationType": { - "enum": [ - "whitelist", - "blacklist", - "none" - ], - "type": "string" - }, "Jettons": { "properties": { "jettons": { @@ -3856,6 +3848,9 @@ "sale": { "$ref": "#/components/schemas/Sale" }, + "verification": { + "$ref": "#/components/schemas/VerificationType" + }, "verified": { "example": true, "type": "boolean" @@ -5016,6 +5011,14 @@ ], "type": "object" }, + "VerificationType": { + "enum": [ + "whitelist", + "blacklist", + "none" + ], + "type": "string" + }, "WalletDNS": { "properties": { "address": { diff --git a/api/openapi.yml b/api/openapi.yml index b8030bb9..6e45c0b6 100644 --- a/api/openapi.yml +++ b/api/openapi.yml @@ -33,18 +33,18 @@ paths: description: Get blockchain block shards operationId: getBlockchainMasterchainShards tags: - - Blockchain + - Blockchain parameters: - $ref: '#/components/parameters/masterchainSeqno' responses: - '200': - description: blockchain block shards - content: - application/json: - schema: - $ref: '#/components/schemas/BlockchainBlockShards' - 'default': - $ref: '#/components/responses/Error' + '200': + description: blockchain block shards + content: + application/json: + schema: + $ref: '#/components/schemas/BlockchainBlockShards' + 'default': + $ref: '#/components/responses/Error' /v2/blockchain/masterchain/{masterchain_seqno}/config: get: description: Get blockchain config from a specific block, if present. @@ -2552,7 +2552,7 @@ components: items: type: object required: - - address + - address properties: address: type: string @@ -4387,7 +4387,7 @@ components: type: array items: $ref: '#/components/schemas/DomainBid' - JettonVerificationType: + VerificationType: type: string enum: - whitelist @@ -4419,7 +4419,7 @@ components: type: string example: https://cache.tonapi.io/images/jetton.jpg verification: - $ref: '#/components/schemas/JettonVerificationType' + $ref: '#/components/schemas/VerificationType' JettonBalance: type: object required: @@ -4531,6 +4531,8 @@ components: verified: type: boolean example: true + verification: + $ref: '#/components/schemas/VerificationType' metadata: type: object additionalProperties: true @@ -5655,7 +5657,7 @@ components: metadata: $ref: '#/components/schemas/JettonMetadata' verification: - $ref: '#/components/schemas/JettonVerificationType' + $ref: '#/components/schemas/VerificationType' holders_count: type: integer format: int32 diff --git a/pkg/api/account_handlers.go b/pkg/api/account_handlers.go index e96b06cd..8eeb144b 100644 --- a/pkg/api/account_handlers.go +++ b/pkg/api/account_handlers.go @@ -260,7 +260,7 @@ func (h *Handler) GetAccountDnsExpiring(ctx context.Context, params oas.GetAccou if dns.DnsItem != nil { for _, n := range nfts { if n.Address == dns.DnsItem.Address { - dei.DNSItem = oas.NewOptNftItem(convertNFT(ctx, n, h.addressBook, h.metaCache)) + dei.DNSItem = oas.NewOptNftItem(h.convertNFT(ctx, n, h.addressBook, h.metaCache)) break } } diff --git a/pkg/api/dns_handlers.go b/pkg/api/dns_handlers.go index eff40608..b09063e5 100644 --- a/pkg/api/dns_handlers.go +++ b/pkg/api/dns_handlers.go @@ -141,7 +141,7 @@ func (h *Handler) GetDnsInfo(ctx context.Context, params oas.GetDnsInfoParams) ( convertedDomainInfo := oas.DomainInfo{ Name: params.DomainName, } - convertedDomainInfo.Item.SetTo(convertNFT(ctx, nft, h.addressBook, h.metaCache)) + convertedDomainInfo.Item.SetTo(h.convertNFT(ctx, nft, h.addressBook, h.metaCache)) if expTime != 0 { convertedDomainInfo.ExpiringAt.SetTo(expTime) } diff --git a/pkg/api/event_converters.go b/pkg/api/event_converters.go index 914bc68f..d08f7c46 100644 --- a/pkg/api/event_converters.go +++ b/pkg/api/event_converters.go @@ -86,7 +86,7 @@ func (h *Handler) convertRisk(ctx context.Context, risk wallet.Risk, walletAddre return oas.Risk{}, err } for _, item := range items { - nft := convertNFT(ctx, item, h.addressBook, h.metaCache) + nft := h.convertNFT(ctx, item, h.addressBook, h.metaCache) oasRisk.Nfts = append(oasRisk.Nfts, nft) } } @@ -479,7 +479,7 @@ func (h *Handler) convertAction(ctx context.Context, viewer *tongo.AccountID, a var name string if len(items) == 1 { // opentonapi doesn't implement GetNFTs() now - nft = convertNFT(ctx, items[0], h.addressBook, h.metaCache) + nft = h.convertNFT(ctx, items[0], h.addressBook, h.metaCache) if len(nft.Previews) > 0 { nftImage = nft.Previews[0].URL } @@ -615,7 +615,7 @@ func (h *Handler) convertAction(ctx context.Context, viewer *tongo.AccountID, a if a.AuctionBid.Nft == nil { return oas.Action{}, false, fmt.Errorf("nft is nil") } - nft.SetTo(convertNFT(ctx, *a.AuctionBid.Nft, h.addressBook, h.metaCache)) + nft.SetTo(h.convertNFT(ctx, *a.AuctionBid.Nft, h.addressBook, h.metaCache)) action.AuctionBid.SetTo(oas.AuctionBidAction{ Amount: oas.Price{ Value: fmt.Sprintf("%v", a.AuctionBid.Amount), diff --git a/pkg/api/jetton_converters.go b/pkg/api/jetton_converters.go index 0f236c3c..d1f93547 100644 --- a/pkg/api/jetton_converters.go +++ b/pkg/api/jetton_converters.go @@ -14,7 +14,7 @@ func jettonPreview(master tongo.AccountID, meta NormalizedMetadata) oas.JettonPr Address: master.ToRaw(), Name: meta.Name, Symbol: meta.Symbol, - Verification: oas.JettonVerificationType(meta.Verification), + Verification: oas.VerificationType(meta.Verification), Decimals: meta.Decimals, Image: meta.Image, } diff --git a/pkg/api/jetton_handlers.go b/pkg/api/jetton_handlers.go index 3598ccb6..3b4c662c 100644 --- a/pkg/api/jetton_handlers.go +++ b/pkg/api/jetton_handlers.go @@ -109,7 +109,7 @@ func (h *Handler) GetJettonInfo(ctx context.Context, params oas.GetJettonInfoPar Mintable: data.Mintable, TotalSupply: data.TotalSupply.String(), Metadata: metadata, - Verification: oas.JettonVerificationType(meta.Verification), + Verification: oas.VerificationType(meta.Verification), HoldersCount: holdersCount[account.ID], }, nil } @@ -191,7 +191,7 @@ func (h *Handler) GetJettons(ctx context.Context, params oas.GetJettonsParams) ( Mintable: master.Mintable, TotalSupply: master.TotalSupply.String(), Metadata: metadata, - Verification: oas.JettonVerificationType(meta.Verification), + Verification: oas.VerificationType(meta.Verification), HoldersCount: jettonsHolders[master.Address], } results = append(results, info) diff --git a/pkg/api/nft_converters.go b/pkg/api/nft_converters.go index c6764024..9443ab83 100644 --- a/pkg/api/nft_converters.go +++ b/pkg/api/nft_converters.go @@ -9,6 +9,7 @@ import ( "github.com/tonkeeper/opentonapi/internal/g" "github.com/tonkeeper/opentonapi/pkg/bath" imgGenerator "github.com/tonkeeper/opentonapi/pkg/image" + rules "github.com/tonkeeper/scam_backoffice_rules" "github.com/tonkeeper/tongo" "github.com/go-faster/jx" @@ -17,14 +18,15 @@ import ( "github.com/tonkeeper/opentonapi/pkg/references" ) -func convertNFT(ctx context.Context, item core.NftItem, book addressBook, metaCache metadataCache) oas.NftItem { +func (h *Handler) convertNFT(ctx context.Context, item core.NftItem, book addressBook, metaCache metadataCache) oas.NftItem { i := oas.NftItem{ - Address: item.Address.ToRaw(), - Index: item.Index.BigInt().Int64(), - Owner: convertOptAccountAddress(item.OwnerAddress, book), - Verified: item.Verified, - Metadata: anyToJSONRawMap(item.Metadata), - DNS: g.Opt(item.DNS), + Address: item.Address.ToRaw(), + Index: item.Index.BigInt().Int64(), + Owner: convertOptAccountAddress(item.OwnerAddress, book), + Verified: item.Verified, + Metadata: anyToJSONRawMap(item.Metadata), + Verification: oas.NewOptVerificationType(oas.VerificationTypeNone), + DNS: g.Opt(item.DNS), } if item.Sale != nil { tokenName := "TON" @@ -35,18 +37,15 @@ func convertNFT(ctx context.Context, item core.NftItem, book addressBook, metaCa tokenName = UnknownJettonName } } - i.SetSale(oas.OptSale{ - Value: oas.Sale{ - Address: item.Sale.Contract.ToRaw(), - Market: convertAccountAddress(item.Sale.Marketplace, book), - Owner: convertOptAccountAddress(item.Sale.Seller, book), - Price: oas.Price{ - Value: fmt.Sprintf("%v", item.Sale.Price.Amount), - TokenName: tokenName, - }, - }, - Set: true, - }) + i.SetSale(oas.NewOptSale(oas.Sale{ + Address: item.Sale.Contract.ToRaw(), + Market: convertAccountAddress(item.Sale.Marketplace, book), + Owner: convertOptAccountAddress(item.Sale.Seller, book), + Price: oas.Price{ + Value: fmt.Sprintf("%v", item.Sale.Price.Amount), + TokenName: tokenName, + }}, + )) } var image string if item.CollectionAddress != nil { @@ -55,17 +54,12 @@ func convertNFT(ctx context.Context, item core.NftItem, book addressBook, metaCa i.ApprovedBy = append(i.ApprovedBy, a) } } - cInfo, _ := metaCache.getCollectionMeta(ctx, *item.CollectionAddress) - - // TODO: REMOVE, FAST HACK - if strings.Contains(cInfo.Description, "ton-staker.com") { - cInfo.Description = "SCAM" - } - + collectionInfo, _ := metaCache.getCollectionMeta(ctx, *item.CollectionAddress) + collectionInfo.Description, _ = h.nftDescriptionSpamControl(collectionInfo.Description, i.ApprovedBy) i.Collection.SetTo(oas.NftItemCollection{ Address: item.CollectionAddress.ToRaw(), - Name: cInfo.Name, - Description: cInfo.Description, + Name: collectionInfo.Name, + Description: collectionInfo.Description, }) if *item.CollectionAddress == references.RootDotTon && item.DNS != nil && item.Verified { image = "https://cache.tonapi.io/dns/preview/" + *item.DNS + ".png" @@ -77,11 +71,10 @@ func convertNFT(ctx context.Context, item core.NftItem, book addressBook, metaCa if imageI, prs := item.Metadata["image"]; prs { image, _ = imageI.(string) } - // TODO: REMOVE, FAST HACK - if description, ok := item.Metadata["description"]; ok { - if value, ok := description.(string); ok && strings.Contains(value, "ton-staker.com") { - i.Metadata["description"] = []byte(`"SCAM"`) - } + if value, ok := item.Metadata["description"]; ok { + description, verificationType := h.nftDescriptionSpamControl(value.(string), i.ApprovedBy) + i.Verification = oas.NewOptVerificationType(oas.VerificationType(verificationType)) + i.Metadata["description"] = []byte(description) } } if image == "" { @@ -97,7 +90,7 @@ func convertNFT(ctx context.Context, item core.NftItem, book addressBook, metaCa return i } -func convertNftCollection(collection core.NftCollection, book addressBook) oas.NftCollection { +func (h *Handler) convertNftCollection(collection core.NftCollection, book addressBook) oas.NftCollection { c := oas.NftCollection{ Address: collection.Address.ToRaw(), NextItemIndex: int64(collection.NextItemIndex), @@ -107,32 +100,27 @@ func convertNftCollection(collection core.NftCollection, book addressBook) oas.N if len(collection.Metadata) == 0 { return c } + if known, ok := book.GetCollectionInfoByAddress(collection.Address); ok { + for _, a := range known.Approvers { + c.ApprovedBy = append(c.ApprovedBy, a) + } + } metadata := map[string]jx.Raw{} image := references.Placeholder for k, v := range collection.Metadata { - // TODO: REMOVE, FAST HACK if k == "description" { - if value, ok := v.(string); ok && strings.Contains(value, "ton-staker.com") { - v = "SCAM" - } + v, _ = h.nftDescriptionSpamControl(v.(string), c.ApprovedBy) } - - var err error if k == "image" { if i, ok := v.(string); ok && i != "" { image = i } } - metadata[k], err = json.Marshal(v) - if err != nil { + var err error + if metadata[k], err = json.Marshal(v); err != nil { continue } } - if known, ok := book.GetCollectionInfoByAddress(collection.Address); ok { - for _, a := range known.Approvers { - c.ApprovedBy = append(c.ApprovedBy, a) - } - } c.Metadata.SetTo(metadata) for _, size := range []int{5, 100, 500, 1500} { url := imgGenerator.DefaultGenerator.GenerateImageUrl(image, size, size) @@ -186,3 +174,18 @@ func (h *Handler) convertNftHistory(ctx context.Context, account tongo.AccountID return events, int64(lastLT), nil } + +func (h *Handler) nftDescriptionSpamControl(description string, approvedBy oas.NftApprovedBy) (string, VerificationType) { + const scam = "SCAM" + if strings.Contains(description, "ton-staker.com") { // TODO: REMOVE, FAST HACK + return scam, VerificationBlacklist + } + if len(approvedBy) > 0 { + return description, VerificationWhitelist + } else { + if spamAction := rules.CheckAction(h.spamFilter.GetRules(), description); spamAction == rules.Drop { + return scam, VerificationBlacklist + } + } + return description, VerificationNone +} diff --git a/pkg/api/nft_handlers.go b/pkg/api/nft_handlers.go index 8a1dfd90..3bf37630 100644 --- a/pkg/api/nft_handlers.go +++ b/pkg/api/nft_handlers.go @@ -4,9 +4,10 @@ import ( "context" "errors" "fmt" - "golang.org/x/exp/slices" "net/http" + "golang.org/x/exp/slices" + "github.com/tonkeeper/opentonapi/pkg/core" "github.com/tonkeeper/opentonapi/pkg/oas" "github.com/tonkeeper/tongo" @@ -34,7 +35,7 @@ func (h *Handler) GetNftItemsByAddresses(ctx context.Context, request oas.OptGet } var result oas.NftItems for _, i := range items { - result.NftItems = append(result.NftItems, convertNFT(ctx, i, h.addressBook, h.metaCache)) + result.NftItems = append(result.NftItems, h.convertNFT(ctx, i, h.addressBook, h.metaCache)) } return &result, nil } @@ -51,7 +52,7 @@ func (h *Handler) GetNftItemByAddress(ctx context.Context, params oas.GetNftItem if len(items) != 1 { return nil, toError(http.StatusNotFound, fmt.Errorf("item not found")) } - result := convertNFT(ctx, items[0], h.addressBook, h.metaCache) + result := h.convertNFT(ctx, items[0], h.addressBook, h.metaCache) return &result, nil } @@ -87,7 +88,7 @@ func (h *Handler) GetAccountNftItems(ctx context.Context, params oas.GetAccountN return nil, toError(http.StatusInternalServerError, err) } for _, i := range items { - result.NftItems = append(result.NftItems, convertNFT(ctx, i, h.addressBook, h.metaCache)) + result.NftItems = append(result.NftItems, h.convertNFT(ctx, i, h.addressBook, h.metaCache)) } return &result, nil } @@ -99,7 +100,7 @@ func (h *Handler) GetNftCollections(ctx context.Context, params oas.GetNftCollec } var collectionsRes oas.NftCollections for _, collection := range collections { - col := convertNftCollection(collection, h.addressBook) + col := h.convertNftCollection(collection, h.addressBook) collectionsRes.NftCollections = append(collectionsRes.NftCollections, col) } return &collectionsRes, nil @@ -117,7 +118,7 @@ func (h *Handler) GetNftCollection(ctx context.Context, params oas.GetNftCollect if err != nil { return nil, toError(http.StatusInternalServerError, err) } - col := convertNftCollection(collection, h.addressBook) + col := h.convertNftCollection(collection, h.addressBook) return &col, nil } @@ -142,7 +143,7 @@ func (h *Handler) GetItemsFromCollection(ctx context.Context, params oas.GetItem return a.Index.Cmp(b.Index) }) for _, i := range items { - result.NftItems = append(result.NftItems, convertNFT(ctx, i, h.addressBook, h.metaCache)) + result.NftItems = append(result.NftItems, h.convertNFT(ctx, i, h.addressBook, h.metaCache)) } return &result, nil } diff --git a/pkg/oas/oas_json_gen.go b/pkg/oas/oas_json_gen.go index 53e4dbb0..0cef85a3 100644 --- a/pkg/oas/oas_json_gen.go +++ b/pkg/oas/oas_json_gen.go @@ -21998,48 +21998,6 @@ func (s *JettonTransferAction) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes JettonVerificationType as json. -func (s JettonVerificationType) Encode(e *jx.Encoder) { - e.Str(string(s)) -} - -// Decode decodes JettonVerificationType from json. -func (s *JettonVerificationType) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode JettonVerificationType to nil") - } - v, err := d.StrBytes() - if err != nil { - return err - } - // Try to use constant string. - switch JettonVerificationType(v) { - case JettonVerificationTypeWhitelist: - *s = JettonVerificationTypeWhitelist - case JettonVerificationTypeBlacklist: - *s = JettonVerificationTypeBlacklist - case JettonVerificationTypeNone: - *s = JettonVerificationTypeNone - default: - *s = JettonVerificationType(v) - } - - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s JettonVerificationType) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *JettonVerificationType) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode implements json.Marshaler. func (s *Jettons) Encode(e *jx.Encoder) { e.ObjStart() @@ -23831,6 +23789,12 @@ func (s *NftItem) encodeFields(e *jx.Encoder) { e.FieldStart("verified") e.Bool(s.Verified) } + { + if s.Verification.Set { + e.FieldStart("verification") + s.Verification.Encode(e) + } + } { e.FieldStart("metadata") s.Metadata.Encode(e) @@ -23863,17 +23827,18 @@ func (s *NftItem) encodeFields(e *jx.Encoder) { } } -var jsonFieldsNameOfNftItem = [10]string{ - 0: "address", - 1: "index", - 2: "owner", - 3: "collection", - 4: "verified", - 5: "metadata", - 6: "sale", - 7: "previews", - 8: "dns", - 9: "approved_by", +var jsonFieldsNameOfNftItem = [11]string{ + 0: "address", + 1: "index", + 2: "owner", + 3: "collection", + 4: "verified", + 5: "verification", + 6: "metadata", + 7: "sale", + 8: "previews", + 9: "dns", + 10: "approved_by", } // Decode decodes NftItem from json. @@ -23941,8 +23906,18 @@ func (s *NftItem) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"verified\"") } + case "verification": + if err := func() error { + s.Verification.Reset() + if err := s.Verification.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"verification\"") + } case "metadata": - requiredBitSet[0] |= 1 << 5 + requiredBitSet[0] |= 1 << 6 if err := func() error { if err := s.Metadata.Decode(d); err != nil { return err @@ -23989,7 +23964,7 @@ func (s *NftItem) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"dns\"") } case "approved_by": - requiredBitSet[1] |= 1 << 1 + requiredBitSet[1] |= 1 << 2 if err := func() error { if err := s.ApprovedBy.Decode(d); err != nil { return err @@ -24008,8 +23983,8 @@ func (s *NftItem) Decode(d *jx.Decoder) error { // Validate required fields. var failures []validate.FieldError for i, mask := range [2]uint8{ - 0b00110011, - 0b00000010, + 0b01010011, + 0b00000100, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. @@ -27601,6 +27576,39 @@ func (s *OptValidatorsSet) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes VerificationType as json. +func (o OptVerificationType) Encode(e *jx.Encoder) { + if !o.Set { + return + } + e.Str(string(o.Value)) +} + +// Decode decodes VerificationType from json. +func (o *OptVerificationType) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptVerificationType to nil") + } + o.Set = true + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptVerificationType) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptVerificationType) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes WalletDNS as json. func (o OptWalletDNS) Encode(e *jx.Encoder) { if !o.Set { @@ -34226,6 +34234,48 @@ func (s *ValueFlowJettonsItem) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes VerificationType as json. +func (s VerificationType) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes VerificationType from json. +func (s *VerificationType) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode VerificationType to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch VerificationType(v) { + case VerificationTypeWhitelist: + *s = VerificationTypeWhitelist + case VerificationTypeBlacklist: + *s = VerificationTypeBlacklist + case VerificationTypeNone: + *s = VerificationTypeNone + default: + *s = VerificationType(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s VerificationType) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *VerificationType) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode implements json.Marshaler. func (s *WalletDNS) Encode(e *jx.Encoder) { e.ObjStart() diff --git a/pkg/oas/oas_schemas_gen.go b/pkg/oas/oas_schemas_gen.go index 04141486..50bd6895 100644 --- a/pkg/oas/oas_schemas_gen.go +++ b/pkg/oas/oas_schemas_gen.go @@ -6706,11 +6706,11 @@ func (s *JettonHoldersAddressesItem) SetBalance(val string) { // Ref: #/components/schemas/JettonInfo type JettonInfo struct { - Mintable bool `json:"mintable"` - TotalSupply string `json:"total_supply"` - Metadata JettonMetadata `json:"metadata"` - Verification JettonVerificationType `json:"verification"` - HoldersCount int32 `json:"holders_count"` + Mintable bool `json:"mintable"` + TotalSupply string `json:"total_supply"` + Metadata JettonMetadata `json:"metadata"` + Verification VerificationType `json:"verification"` + HoldersCount int32 `json:"holders_count"` } // GetMintable returns the value of Mintable. @@ -6729,7 +6729,7 @@ func (s *JettonInfo) GetMetadata() JettonMetadata { } // GetVerification returns the value of Verification. -func (s *JettonInfo) GetVerification() JettonVerificationType { +func (s *JettonInfo) GetVerification() VerificationType { return s.Verification } @@ -6754,7 +6754,7 @@ func (s *JettonInfo) SetMetadata(val JettonMetadata) { } // SetVerification sets the value of Verification. -func (s *JettonInfo) SetVerification(val JettonVerificationType) { +func (s *JettonInfo) SetVerification(val VerificationType) { s.Verification = val } @@ -6917,12 +6917,12 @@ func (s *JettonMintAction) SetJetton(val JettonPreview) { // Ref: #/components/schemas/JettonPreview type JettonPreview struct { - Address string `json:"address"` - Name string `json:"name"` - Symbol string `json:"symbol"` - Decimals int `json:"decimals"` - Image string `json:"image"` - Verification JettonVerificationType `json:"verification"` + Address string `json:"address"` + Name string `json:"name"` + Symbol string `json:"symbol"` + Decimals int `json:"decimals"` + Image string `json:"image"` + Verification VerificationType `json:"verification"` } // GetAddress returns the value of Address. @@ -6951,7 +6951,7 @@ func (s *JettonPreview) GetImage() string { } // GetVerification returns the value of Verification. -func (s *JettonPreview) GetVerification() JettonVerificationType { +func (s *JettonPreview) GetVerification() VerificationType { return s.Verification } @@ -6981,7 +6981,7 @@ func (s *JettonPreview) SetImage(val string) { } // SetVerification sets the value of Verification. -func (s *JettonPreview) SetVerification(val JettonVerificationType) { +func (s *JettonPreview) SetVerification(val VerificationType) { s.Verification = val } @@ -7277,55 +7277,6 @@ func (s *JettonTransferAction) SetJetton(val JettonPreview) { s.Jetton = val } -// Ref: #/components/schemas/JettonVerificationType -type JettonVerificationType string - -const ( - JettonVerificationTypeWhitelist JettonVerificationType = "whitelist" - JettonVerificationTypeBlacklist JettonVerificationType = "blacklist" - JettonVerificationTypeNone JettonVerificationType = "none" -) - -// AllValues returns all JettonVerificationType values. -func (JettonVerificationType) AllValues() []JettonVerificationType { - return []JettonVerificationType{ - JettonVerificationTypeWhitelist, - JettonVerificationTypeBlacklist, - JettonVerificationTypeNone, - } -} - -// MarshalText implements encoding.TextMarshaler. -func (s JettonVerificationType) MarshalText() ([]byte, error) { - switch s { - case JettonVerificationTypeWhitelist: - return []byte(s), nil - case JettonVerificationTypeBlacklist: - return []byte(s), nil - case JettonVerificationTypeNone: - return []byte(s), nil - default: - return nil, errors.Errorf("invalid value: %q", s) - } -} - -// UnmarshalText implements encoding.TextUnmarshaler. -func (s *JettonVerificationType) UnmarshalText(data []byte) error { - switch JettonVerificationType(data) { - case JettonVerificationTypeWhitelist: - *s = JettonVerificationTypeWhitelist - return nil - case JettonVerificationTypeBlacklist: - *s = JettonVerificationTypeBlacklist - return nil - case JettonVerificationTypeNone: - *s = JettonVerificationTypeNone - return nil - default: - return errors.Errorf("invalid value: %q", data) - } -} - // Ref: #/components/schemas/Jettons type Jettons struct { Jettons []JettonInfo `json:"jettons"` @@ -7977,16 +7928,17 @@ func (s *NftCollections) SetNftCollections(val []NftCollection) { // Ref: #/components/schemas/NftItem type NftItem struct { - Address string `json:"address"` - Index int64 `json:"index"` - Owner OptAccountAddress `json:"owner"` - Collection OptNftItemCollection `json:"collection"` - Verified bool `json:"verified"` - Metadata NftItemMetadata `json:"metadata"` - Sale OptSale `json:"sale"` - Previews []ImagePreview `json:"previews"` - DNS OptString `json:"dns"` - ApprovedBy NftApprovedBy `json:"approved_by"` + Address string `json:"address"` + Index int64 `json:"index"` + Owner OptAccountAddress `json:"owner"` + Collection OptNftItemCollection `json:"collection"` + Verified bool `json:"verified"` + Verification OptVerificationType `json:"verification"` + Metadata NftItemMetadata `json:"metadata"` + Sale OptSale `json:"sale"` + Previews []ImagePreview `json:"previews"` + DNS OptString `json:"dns"` + ApprovedBy NftApprovedBy `json:"approved_by"` } // GetAddress returns the value of Address. @@ -8014,6 +7966,11 @@ func (s *NftItem) GetVerified() bool { return s.Verified } +// GetVerification returns the value of Verification. +func (s *NftItem) GetVerification() OptVerificationType { + return s.Verification +} + // GetMetadata returns the value of Metadata. func (s *NftItem) GetMetadata() NftItemMetadata { return s.Metadata @@ -8064,6 +8021,11 @@ func (s *NftItem) SetVerified(val bool) { s.Verified = val } +// SetVerification sets the value of Verification. +func (s *NftItem) SetVerification(val OptVerificationType) { + s.Verification = val +} + // SetMetadata sets the value of Metadata. func (s *NftItem) SetMetadata(val NftItemMetadata) { s.Metadata = val @@ -12296,6 +12258,52 @@ func (o OptValidatorsSet) Or(d ValidatorsSet) ValidatorsSet { return d } +// NewOptVerificationType returns new OptVerificationType with value set to v. +func NewOptVerificationType(v VerificationType) OptVerificationType { + return OptVerificationType{ + Value: v, + Set: true, + } +} + +// OptVerificationType is optional VerificationType. +type OptVerificationType struct { + Value VerificationType + Set bool +} + +// IsSet returns true if OptVerificationType was set. +func (o OptVerificationType) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptVerificationType) Reset() { + var v VerificationType + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptVerificationType) SetTo(v VerificationType) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptVerificationType) Get() (v VerificationType, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptVerificationType) Or(d VerificationType) VerificationType { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptWalletDNS returns new OptWalletDNS with value set to v. func NewOptWalletDNS(v WalletDNS) OptWalletDNS { return OptWalletDNS{ @@ -14761,6 +14769,55 @@ func (s *ValueFlowJettonsItem) SetQuantity(val int64) { s.Quantity = val } +// Ref: #/components/schemas/VerificationType +type VerificationType string + +const ( + VerificationTypeWhitelist VerificationType = "whitelist" + VerificationTypeBlacklist VerificationType = "blacklist" + VerificationTypeNone VerificationType = "none" +) + +// AllValues returns all VerificationType values. +func (VerificationType) AllValues() []VerificationType { + return []VerificationType{ + VerificationTypeWhitelist, + VerificationTypeBlacklist, + VerificationTypeNone, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s VerificationType) MarshalText() ([]byte, error) { + switch s { + case VerificationTypeWhitelist: + return []byte(s), nil + case VerificationTypeBlacklist: + return []byte(s), nil + case VerificationTypeNone: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *VerificationType) UnmarshalText(data []byte) error { + switch VerificationType(data) { + case VerificationTypeWhitelist: + *s = VerificationTypeWhitelist + return nil + case VerificationTypeBlacklist: + *s = VerificationTypeBlacklist + return nil + case VerificationTypeNone: + *s = VerificationTypeNone + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + // Ref: #/components/schemas/WalletDNS type WalletDNS struct { Address string `json:"address"` diff --git a/pkg/oas/oas_validators_gen.go b/pkg/oas/oas_validators_gen.go index 59cbdead..6ebaee7c 100644 --- a/pkg/oas/oas_validators_gen.go +++ b/pkg/oas/oas_validators_gen.go @@ -2592,19 +2592,6 @@ func (s *JettonTransferAction) Validate() error { return nil } -func (s JettonVerificationType) Validate() error { - switch s { - case "whitelist": - return nil - case "blacklist": - return nil - case "none": - return nil - default: - return errors.Errorf("invalid value: %v", s) - } -} - func (s *Jettons) Validate() error { var failures []validate.FieldError if err := func() error { @@ -2849,6 +2836,24 @@ func (s *NftCollections) Validate() error { func (s *NftItem) Validate() error { var failures []validate.FieldError + if err := func() error { + if value, ok := s.Verification.Get(); ok { + if err := func() error { + if err := value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "verification", + Error: err, + }) + } if err := func() error { if err := s.ApprovedBy.Validate(); err != nil { return err @@ -3698,6 +3703,19 @@ func (s *ValueFlowJettonsItem) Validate() error { return nil } +func (s VerificationType) Validate() error { + switch s { + case "whitelist": + return nil + case "blacklist": + return nil + case "none": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + func (s *WalletDNS) Validate() error { var failures []validate.FieldError if err := func() error { diff --git a/tonapi/oas_json_gen.go b/tonapi/oas_json_gen.go index 686df70c..22d76e66 100644 --- a/tonapi/oas_json_gen.go +++ b/tonapi/oas_json_gen.go @@ -21998,48 +21998,6 @@ func (s *JettonTransferAction) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes JettonVerificationType as json. -func (s JettonVerificationType) Encode(e *jx.Encoder) { - e.Str(string(s)) -} - -// Decode decodes JettonVerificationType from json. -func (s *JettonVerificationType) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode JettonVerificationType to nil") - } - v, err := d.StrBytes() - if err != nil { - return err - } - // Try to use constant string. - switch JettonVerificationType(v) { - case JettonVerificationTypeWhitelist: - *s = JettonVerificationTypeWhitelist - case JettonVerificationTypeBlacklist: - *s = JettonVerificationTypeBlacklist - case JettonVerificationTypeNone: - *s = JettonVerificationTypeNone - default: - *s = JettonVerificationType(v) - } - - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s JettonVerificationType) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *JettonVerificationType) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode implements json.Marshaler. func (s *Jettons) Encode(e *jx.Encoder) { e.ObjStart() @@ -23831,6 +23789,12 @@ func (s *NftItem) encodeFields(e *jx.Encoder) { e.FieldStart("verified") e.Bool(s.Verified) } + { + if s.Verification.Set { + e.FieldStart("verification") + s.Verification.Encode(e) + } + } { e.FieldStart("metadata") s.Metadata.Encode(e) @@ -23863,17 +23827,18 @@ func (s *NftItem) encodeFields(e *jx.Encoder) { } } -var jsonFieldsNameOfNftItem = [10]string{ - 0: "address", - 1: "index", - 2: "owner", - 3: "collection", - 4: "verified", - 5: "metadata", - 6: "sale", - 7: "previews", - 8: "dns", - 9: "approved_by", +var jsonFieldsNameOfNftItem = [11]string{ + 0: "address", + 1: "index", + 2: "owner", + 3: "collection", + 4: "verified", + 5: "verification", + 6: "metadata", + 7: "sale", + 8: "previews", + 9: "dns", + 10: "approved_by", } // Decode decodes NftItem from json. @@ -23941,8 +23906,18 @@ func (s *NftItem) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"verified\"") } + case "verification": + if err := func() error { + s.Verification.Reset() + if err := s.Verification.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"verification\"") + } case "metadata": - requiredBitSet[0] |= 1 << 5 + requiredBitSet[0] |= 1 << 6 if err := func() error { if err := s.Metadata.Decode(d); err != nil { return err @@ -23989,7 +23964,7 @@ func (s *NftItem) Decode(d *jx.Decoder) error { return errors.Wrap(err, "decode field \"dns\"") } case "approved_by": - requiredBitSet[1] |= 1 << 1 + requiredBitSet[1] |= 1 << 2 if err := func() error { if err := s.ApprovedBy.Decode(d); err != nil { return err @@ -24008,8 +23983,8 @@ func (s *NftItem) Decode(d *jx.Decoder) error { // Validate required fields. var failures []validate.FieldError for i, mask := range [2]uint8{ - 0b00110011, - 0b00000010, + 0b01010011, + 0b00000100, } { if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { // Mask only required fields and check equality to mask using XOR. @@ -27601,6 +27576,39 @@ func (s *OptValidatorsSet) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes VerificationType as json. +func (o OptVerificationType) Encode(e *jx.Encoder) { + if !o.Set { + return + } + e.Str(string(o.Value)) +} + +// Decode decodes VerificationType from json. +func (o *OptVerificationType) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptVerificationType to nil") + } + o.Set = true + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptVerificationType) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptVerificationType) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes WalletDNS as json. func (o OptWalletDNS) Encode(e *jx.Encoder) { if !o.Set { @@ -34226,6 +34234,48 @@ func (s *ValueFlowJettonsItem) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes VerificationType as json. +func (s VerificationType) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes VerificationType from json. +func (s *VerificationType) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode VerificationType to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch VerificationType(v) { + case VerificationTypeWhitelist: + *s = VerificationTypeWhitelist + case VerificationTypeBlacklist: + *s = VerificationTypeBlacklist + case VerificationTypeNone: + *s = VerificationTypeNone + default: + *s = VerificationType(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s VerificationType) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *VerificationType) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode implements json.Marshaler. func (s *WalletDNS) Encode(e *jx.Encoder) { e.ObjStart() diff --git a/tonapi/oas_schemas_gen.go b/tonapi/oas_schemas_gen.go index 73d6adb1..4910f5c7 100644 --- a/tonapi/oas_schemas_gen.go +++ b/tonapi/oas_schemas_gen.go @@ -6706,11 +6706,11 @@ func (s *JettonHoldersAddressesItem) SetBalance(val string) { // Ref: #/components/schemas/JettonInfo type JettonInfo struct { - Mintable bool `json:"mintable"` - TotalSupply string `json:"total_supply"` - Metadata JettonMetadata `json:"metadata"` - Verification JettonVerificationType `json:"verification"` - HoldersCount int32 `json:"holders_count"` + Mintable bool `json:"mintable"` + TotalSupply string `json:"total_supply"` + Metadata JettonMetadata `json:"metadata"` + Verification VerificationType `json:"verification"` + HoldersCount int32 `json:"holders_count"` } // GetMintable returns the value of Mintable. @@ -6729,7 +6729,7 @@ func (s *JettonInfo) GetMetadata() JettonMetadata { } // GetVerification returns the value of Verification. -func (s *JettonInfo) GetVerification() JettonVerificationType { +func (s *JettonInfo) GetVerification() VerificationType { return s.Verification } @@ -6754,7 +6754,7 @@ func (s *JettonInfo) SetMetadata(val JettonMetadata) { } // SetVerification sets the value of Verification. -func (s *JettonInfo) SetVerification(val JettonVerificationType) { +func (s *JettonInfo) SetVerification(val VerificationType) { s.Verification = val } @@ -6917,12 +6917,12 @@ func (s *JettonMintAction) SetJetton(val JettonPreview) { // Ref: #/components/schemas/JettonPreview type JettonPreview struct { - Address string `json:"address"` - Name string `json:"name"` - Symbol string `json:"symbol"` - Decimals int `json:"decimals"` - Image string `json:"image"` - Verification JettonVerificationType `json:"verification"` + Address string `json:"address"` + Name string `json:"name"` + Symbol string `json:"symbol"` + Decimals int `json:"decimals"` + Image string `json:"image"` + Verification VerificationType `json:"verification"` } // GetAddress returns the value of Address. @@ -6951,7 +6951,7 @@ func (s *JettonPreview) GetImage() string { } // GetVerification returns the value of Verification. -func (s *JettonPreview) GetVerification() JettonVerificationType { +func (s *JettonPreview) GetVerification() VerificationType { return s.Verification } @@ -6981,7 +6981,7 @@ func (s *JettonPreview) SetImage(val string) { } // SetVerification sets the value of Verification. -func (s *JettonPreview) SetVerification(val JettonVerificationType) { +func (s *JettonPreview) SetVerification(val VerificationType) { s.Verification = val } @@ -7277,55 +7277,6 @@ func (s *JettonTransferAction) SetJetton(val JettonPreview) { s.Jetton = val } -// Ref: #/components/schemas/JettonVerificationType -type JettonVerificationType string - -const ( - JettonVerificationTypeWhitelist JettonVerificationType = "whitelist" - JettonVerificationTypeBlacklist JettonVerificationType = "blacklist" - JettonVerificationTypeNone JettonVerificationType = "none" -) - -// AllValues returns all JettonVerificationType values. -func (JettonVerificationType) AllValues() []JettonVerificationType { - return []JettonVerificationType{ - JettonVerificationTypeWhitelist, - JettonVerificationTypeBlacklist, - JettonVerificationTypeNone, - } -} - -// MarshalText implements encoding.TextMarshaler. -func (s JettonVerificationType) MarshalText() ([]byte, error) { - switch s { - case JettonVerificationTypeWhitelist: - return []byte(s), nil - case JettonVerificationTypeBlacklist: - return []byte(s), nil - case JettonVerificationTypeNone: - return []byte(s), nil - default: - return nil, errors.Errorf("invalid value: %q", s) - } -} - -// UnmarshalText implements encoding.TextUnmarshaler. -func (s *JettonVerificationType) UnmarshalText(data []byte) error { - switch JettonVerificationType(data) { - case JettonVerificationTypeWhitelist: - *s = JettonVerificationTypeWhitelist - return nil - case JettonVerificationTypeBlacklist: - *s = JettonVerificationTypeBlacklist - return nil - case JettonVerificationTypeNone: - *s = JettonVerificationTypeNone - return nil - default: - return errors.Errorf("invalid value: %q", data) - } -} - // Ref: #/components/schemas/Jettons type Jettons struct { Jettons []JettonInfo `json:"jettons"` @@ -7977,16 +7928,17 @@ func (s *NftCollections) SetNftCollections(val []NftCollection) { // Ref: #/components/schemas/NftItem type NftItem struct { - Address string `json:"address"` - Index int64 `json:"index"` - Owner OptAccountAddress `json:"owner"` - Collection OptNftItemCollection `json:"collection"` - Verified bool `json:"verified"` - Metadata NftItemMetadata `json:"metadata"` - Sale OptSale `json:"sale"` - Previews []ImagePreview `json:"previews"` - DNS OptString `json:"dns"` - ApprovedBy NftApprovedBy `json:"approved_by"` + Address string `json:"address"` + Index int64 `json:"index"` + Owner OptAccountAddress `json:"owner"` + Collection OptNftItemCollection `json:"collection"` + Verified bool `json:"verified"` + Verification OptVerificationType `json:"verification"` + Metadata NftItemMetadata `json:"metadata"` + Sale OptSale `json:"sale"` + Previews []ImagePreview `json:"previews"` + DNS OptString `json:"dns"` + ApprovedBy NftApprovedBy `json:"approved_by"` } // GetAddress returns the value of Address. @@ -8014,6 +7966,11 @@ func (s *NftItem) GetVerified() bool { return s.Verified } +// GetVerification returns the value of Verification. +func (s *NftItem) GetVerification() OptVerificationType { + return s.Verification +} + // GetMetadata returns the value of Metadata. func (s *NftItem) GetMetadata() NftItemMetadata { return s.Metadata @@ -8064,6 +8021,11 @@ func (s *NftItem) SetVerified(val bool) { s.Verified = val } +// SetVerification sets the value of Verification. +func (s *NftItem) SetVerification(val OptVerificationType) { + s.Verification = val +} + // SetMetadata sets the value of Metadata. func (s *NftItem) SetMetadata(val NftItemMetadata) { s.Metadata = val @@ -12296,6 +12258,52 @@ func (o OptValidatorsSet) Or(d ValidatorsSet) ValidatorsSet { return d } +// NewOptVerificationType returns new OptVerificationType with value set to v. +func NewOptVerificationType(v VerificationType) OptVerificationType { + return OptVerificationType{ + Value: v, + Set: true, + } +} + +// OptVerificationType is optional VerificationType. +type OptVerificationType struct { + Value VerificationType + Set bool +} + +// IsSet returns true if OptVerificationType was set. +func (o OptVerificationType) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptVerificationType) Reset() { + var v VerificationType + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptVerificationType) SetTo(v VerificationType) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptVerificationType) Get() (v VerificationType, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptVerificationType) Or(d VerificationType) VerificationType { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptWalletDNS returns new OptWalletDNS with value set to v. func NewOptWalletDNS(v WalletDNS) OptWalletDNS { return OptWalletDNS{ @@ -14761,6 +14769,55 @@ func (s *ValueFlowJettonsItem) SetQuantity(val int64) { s.Quantity = val } +// Ref: #/components/schemas/VerificationType +type VerificationType string + +const ( + VerificationTypeWhitelist VerificationType = "whitelist" + VerificationTypeBlacklist VerificationType = "blacklist" + VerificationTypeNone VerificationType = "none" +) + +// AllValues returns all VerificationType values. +func (VerificationType) AllValues() []VerificationType { + return []VerificationType{ + VerificationTypeWhitelist, + VerificationTypeBlacklist, + VerificationTypeNone, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s VerificationType) MarshalText() ([]byte, error) { + switch s { + case VerificationTypeWhitelist: + return []byte(s), nil + case VerificationTypeBlacklist: + return []byte(s), nil + case VerificationTypeNone: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *VerificationType) UnmarshalText(data []byte) error { + switch VerificationType(data) { + case VerificationTypeWhitelist: + *s = VerificationTypeWhitelist + return nil + case VerificationTypeBlacklist: + *s = VerificationTypeBlacklist + return nil + case VerificationTypeNone: + *s = VerificationTypeNone + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + // Ref: #/components/schemas/WalletDNS type WalletDNS struct { Address string `json:"address"` diff --git a/tonapi/oas_validators_gen.go b/tonapi/oas_validators_gen.go index 8e727f02..2066a14e 100644 --- a/tonapi/oas_validators_gen.go +++ b/tonapi/oas_validators_gen.go @@ -2592,19 +2592,6 @@ func (s *JettonTransferAction) Validate() error { return nil } -func (s JettonVerificationType) Validate() error { - switch s { - case "whitelist": - return nil - case "blacklist": - return nil - case "none": - return nil - default: - return errors.Errorf("invalid value: %v", s) - } -} - func (s *Jettons) Validate() error { var failures []validate.FieldError if err := func() error { @@ -2849,6 +2836,24 @@ func (s *NftCollections) Validate() error { func (s *NftItem) Validate() error { var failures []validate.FieldError + if err := func() error { + if value, ok := s.Verification.Get(); ok { + if err := func() error { + if err := value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "verification", + Error: err, + }) + } if err := func() error { if err := s.ApprovedBy.Validate(); err != nil { return err @@ -3698,6 +3703,19 @@ func (s *ValueFlowJettonsItem) Validate() error { return nil } +func (s VerificationType) Validate() error { + switch s { + case "whitelist": + return nil + case "blacklist": + return nil + case "none": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + func (s *WalletDNS) Validate() error { var failures []validate.FieldError if err := func() error {