From 74c0717f4685ce3c5b7f98b48c4ee380df927806 Mon Sep 17 00:00:00 2001 From: chris-4chain <152964795+chris-4chain@users.noreply.github.com> Date: Tue, 10 Dec 2024 12:44:27 +0100 Subject: [PATCH] fix(SPV-1069) fix lint errors for "models" package (#800) --- models/bsv/satoshis.go | 1 + models/contact.go | 3 +++ models/filter/access_key_filter.go | 2 +- models/filter/contact_filter.go | 2 +- models/filter/destination_filter.go | 2 +- models/filter/generics.go | 2 +- models/filter/paymail_filter.go | 6 ++++-- models/filter/search_params.go | 6 +++++- models/filter/transaction_admin_filter.go | 2 +- models/filter/transaction_filter.go | 2 +- models/filter/utxo_filter.go | 2 +- models/filter/xpub_filter.go | 2 +- models/optional/optional.go | 2 ++ models/request/opreturn/data_type.go | 6 ++++-- models/request/opreturn/output.go | 2 ++ models/request/paymail/paymail_output.go | 2 ++ models/request/transaction_specification.go | 6 +++--- models/request/transaction_specification_json.go | 6 +++--- models/response/contact.go | 5 +++++ models/swagger/access_key_params.go | 1 + 20 files changed, 43 insertions(+), 19 deletions(-) diff --git a/models/bsv/satoshis.go b/models/bsv/satoshis.go index 4ac6d202f..62d2e4f34 100644 --- a/models/bsv/satoshis.go +++ b/models/bsv/satoshis.go @@ -1,3 +1,4 @@ package bsv +// Satoshis specifies a type that should be used to store value in satoshis type Satoshis uint64 diff --git a/models/contact.go b/models/contact.go index 1821ea28d..b0933db7d 100644 --- a/models/contact.go +++ b/models/contact.go @@ -5,11 +5,13 @@ import ( "github.com/bitcoin-sv/spv-wallet/models/response" ) +// CreateContactResponse is a model for response on contact creation. type CreateContactResponse struct { Contact *Contact `json:"contact"` AdditionalInfo map[string]string `json:"additionalInfo"` } +// Contact is a model for contact. type Contact struct { common.Model @@ -25,6 +27,7 @@ type Contact struct { Status response.ContactStatus `json:"status" example:"unconfirmed"` } +// AddAdditionalInfo adds additional information (as key-value map) to the response. func (m *CreateContactResponse) AddAdditionalInfo(k, v string) { if m.AdditionalInfo == nil { m.AdditionalInfo = make(map[string]string) diff --git a/models/filter/access_key_filter.go b/models/filter/access_key_filter.go index 3e0609002..32c319be1 100644 --- a/models/filter/access_key_filter.go +++ b/models/filter/access_key_filter.go @@ -3,7 +3,7 @@ package filter // AccessKeyFilter is a struct for handling request parameters for destination search requests type AccessKeyFilter struct { // ModelFilter is a struct for handling typical request parameters for search requests - //lint:ignore SA5008 We want to reuse json tags also to mapstructure. + //nolint:staticcheck // SA5008 We want to reuse json tags also to mapstructure. ModelFilter `json:",inline,squash"` // RevokedRange specifies the time range when a record was revoked. diff --git a/models/filter/contact_filter.go b/models/filter/contact_filter.go index 72020cbac..083698471 100644 --- a/models/filter/contact_filter.go +++ b/models/filter/contact_filter.go @@ -3,7 +3,7 @@ package filter // ContactFilter is a struct for handling request parameters for contact search requests type ContactFilter struct { // ModelFilter is a struct for handling typical request parameters for search requests - //lint:ignore SA5008 We want to reuse json tags also to mapstructure. + //nolint:staticcheck // SA5008 We want to reuse json tags also to mapstructure. ModelFilter `json:",inline,squash"` ID *string `json:"id" example:"ffdbe74e-0700-4710-aac5-611a1f877c7f"` FullName *string `json:"fullName" example:"Alice"` diff --git a/models/filter/destination_filter.go b/models/filter/destination_filter.go index 0790430d1..02a000fbd 100644 --- a/models/filter/destination_filter.go +++ b/models/filter/destination_filter.go @@ -3,7 +3,7 @@ package filter // DestinationFilter is a struct for handling request parameters for destination search requests type DestinationFilter struct { // ModelFilter is a struct for handling typical request parameters for search requests - //lint:ignore SA5008 We want to reuse json tags also to mapstructure. + //nolint:staticcheck // SA5008 We want to reuse json tags also to mapstructure. ModelFilter `json:",inline,squash"` LockingScript *string `json:"lockingScript,omitempty" example:"76a9147b05764a97f3b4b981471492aa703b188e45979b88ac"` Address *string `json:"address,omitempty" example:"1CDUf7CKu8ocTTkhcYUbq75t14Ft168K65"` diff --git a/models/filter/generics.go b/models/filter/generics.go index a4243fb64..bae81db9e 100644 --- a/models/filter/generics.go +++ b/models/filter/generics.go @@ -16,7 +16,7 @@ type SearchModel[TFilter any] struct { QueryParams *QueryParams `json:"params,omitempty" swaggertype:"object,string" example:"page:1,page_size:10,order_by_field:created_at,order_by_direction:desc"` } -// DefaultsIfNil fills empty but neccessary fields with default values +// DefaultsIfNil fills empty but necessary fields with default values func (sm *SearchModel[TFilter]) DefaultsIfNil() { if sm.QueryParams == nil { sm.QueryParams = DefaultQueryParams() diff --git a/models/filter/paymail_filter.go b/models/filter/paymail_filter.go index bdcf7fac2..fcf1a668c 100644 --- a/models/filter/paymail_filter.go +++ b/models/filter/paymail_filter.go @@ -3,7 +3,7 @@ package filter // PaymailFilter is a struct for handling request parameters for paymail_addresses search requests type PaymailFilter struct { // ModelFilter is a struct for handling typical request parameters for search requests - //lint:ignore SA5008 We want to reuse json tags also to mapstructure. + //nolint:staticcheck // SA5008 We want to reuse json tags also to mapstructure. ModelFilter `json:",inline,squash"` ID *string `json:"id,omitempty" example:"ffb86c103d17d87c15aaf080aab6be5415c9fa885309a79b04c9910e39f2b542"` @@ -28,13 +28,15 @@ func (d *PaymailFilter) ToDbConditions() map[string]interface{} { return conditions } +// AdminPaymailFilter wraps the PaymailFilter providing additional fields for admin paymail search requests type AdminPaymailFilter struct { - //lint:ignore SA5008 We want to reuse json tags also to mapstructure. + //nolint:staticcheck // SA5008 We want to reuse json tags also to mapstructure. PaymailFilter `json:",inline,squash"` XpubID *string `json:"xpubId,omitempty" example:"79f90a6bab0a44402fc64828af820e9465645658aea2d138c5205b88e6dabd00"` } +// ToDbConditions converts filter fields to the datastore conditions using gorm naming strategy func (d *AdminPaymailFilter) ToDbConditions() map[string]interface{} { if d == nil { return nil diff --git a/models/filter/search_params.go b/models/filter/search_params.go index a69ab2186..5fe307da4 100644 --- a/models/filter/search_params.go +++ b/models/filter/search_params.go @@ -1,5 +1,6 @@ package filter +// Page is a struct for handling paging parameters for search requests type Page struct { Number int `json:"page,omitempty"` Size int `json:"size,omitempty"` @@ -7,8 +8,11 @@ type Page struct { SortBy string `json:"sortBy,omitempty"` } +// SearchParams is a generic struct for handling request parameters for search requests type SearchParams[T any] struct { - Page Page `json:"paging,squash"` + //nolint:staticcheck // SA5008 We want to reuse json tags also to mapstructure. + Page Page `json:"paging,squash"` + //nolint:staticcheck // SA5008 We want to reuse json tags also to mapstructure. Conditions T `json:"conditions,squash"` Metadata map[string]interface{} `json:"metadata,omitempty"` } diff --git a/models/filter/transaction_admin_filter.go b/models/filter/transaction_admin_filter.go index ca9c3b9da..51df7a862 100644 --- a/models/filter/transaction_admin_filter.go +++ b/models/filter/transaction_admin_filter.go @@ -2,7 +2,7 @@ package filter // AdminTransactionFilter extends TransactionFilter for admin-specific use, including xpubid filtering type AdminTransactionFilter struct { - //lint:ignore SA5008 We want to reuse json tags also to mapstructure. + //nolint:staticcheck // SA5008 We want to reuse json tags also to mapstructure. TransactionFilter `json:",inline,squash"` XPubID *string `json:"xpubid,omitempty" example:"623bc25ce1c0fc510dea72b5ee27b2e70384c099f1f3dce9e73dd987198c3486"` } diff --git a/models/filter/transaction_filter.go b/models/filter/transaction_filter.go index a07b25629..bfc9a15c2 100644 --- a/models/filter/transaction_filter.go +++ b/models/filter/transaction_filter.go @@ -3,7 +3,7 @@ package filter // TransactionFilter is a struct for handling request parameters for transactions search requests type TransactionFilter struct { // ModelFilter is a struct for handling typical request parameters for search requests - //lint:ignore SA5008 We want to reuse json tags also to mapstructure. + //nolint:staticcheck // SA5008 We want to reuse json tags also to mapstructure. ModelFilter `json:",inline,squash"` Id *string `json:"id,omitempty" example:"d425432e0d10a46af1ec6d00f380e9581ebf7907f3486572b3cd561a4c326e14"` Hex *string `json:"hex,omitempty"` diff --git a/models/filter/utxo_filter.go b/models/filter/utxo_filter.go index 24619c276..d16441900 100644 --- a/models/filter/utxo_filter.go +++ b/models/filter/utxo_filter.go @@ -4,7 +4,7 @@ package filter type UtxoFilter struct { // ModelFilter is a struct for handling typical request parameters for search requests - //lint:ignore SA5008 We want to reuse json tags also to mapstructure. + //nolint:staticcheck // SA5008 We want to reuse json tags also to mapstructure. ModelFilter `json:",inline,squash"` TransactionID *string `json:"transactionId,omitempty" example:"5e17858ea0ca4155827754ba82bdcfcce108d5bb5b47fbb3aa54bd14540683c6"` diff --git a/models/filter/xpub_filter.go b/models/filter/xpub_filter.go index 7ff07bbfc..8462ab6d2 100644 --- a/models/filter/xpub_filter.go +++ b/models/filter/xpub_filter.go @@ -3,7 +3,7 @@ package filter // XpubFilter is a struct for handling request parameters for utxo search requests type XpubFilter struct { // ModelFilter is a struct for handling typical request parameters for search requests - //lint:ignore SA5008 We want to reuse json tags also to mapstructure. + //nolint:staticcheck // SA5008 We want to reuse json tags also to mapstructure. ModelFilter `json:",inline,squash"` ID *string `json:"id,omitempty" example:"00b953624f78004a4c727cd28557475d5233c15f17aef545106639f4d71b712d"` diff --git a/models/optional/optional.go b/models/optional/optional.go index 0297bdd5f..7bf76c2ff 100644 --- a/models/optional/optional.go +++ b/models/optional/optional.go @@ -1,7 +1,9 @@ package optional +// Param is a pointer to a value of type T. type Param[T any] *T +// Of returns a pointer to a value of type T. func Of[T any](v T) Param[T] { return &v } diff --git a/models/request/opreturn/data_type.go b/models/request/opreturn/data_type.go index 38dd802fd..eedf8cfe2 100644 --- a/models/request/opreturn/data_type.go +++ b/models/request/opreturn/data_type.go @@ -5,8 +5,10 @@ import ( "errors" ) +// DataType represents the type of data in the OP_RETURN output. type DataType int +// Enum values for DataType const ( DataTypeDefault DataType = iota DataTypeStrings @@ -17,7 +19,7 @@ const ( func (d *DataType) UnmarshalJSON(data []byte) error { var dataType string if err := json.Unmarshal(data, &dataType); err != nil { - return err + return err //nolint:wrapcheck // UnmarshalJSON is run internally by json.Unmarshal on "DataType" object, so we don't want to wrap the error } switch dataType { @@ -44,5 +46,5 @@ func (d DataType) MarshalJSON() ([]byte, error) { default: return nil, errors.New("invalid data type") } - return json.Marshal(dataType) + return json.Marshal(dataType) //nolint:wrapcheck // MarshalJSON is run internally by json.Marshal on "DataType" object, so we don't want to wrap the error } diff --git a/models/request/opreturn/output.go b/models/request/opreturn/output.go index 0402c48e8..2ba407978 100644 --- a/models/request/opreturn/output.go +++ b/models/request/opreturn/output.go @@ -1,10 +1,12 @@ package opreturn +// Output is a struct that represents the output containing OP_RETURN script type Output struct { DataType DataType `json:"dataType,omitempty"` Data []string `json:"data"` } +// GetType returns the string typename of the output func (o Output) GetType() string { return "op_return" } diff --git a/models/request/paymail/paymail_output.go b/models/request/paymail/paymail_output.go index fd083c8e6..1d1078723 100644 --- a/models/request/paymail/paymail_output.go +++ b/models/request/paymail/paymail_output.go @@ -5,12 +5,14 @@ import ( "github.com/bitcoin-sv/spv-wallet/models/optional" ) +// Output represents a paymail output. type Output struct { To string `json:"to"` Satoshis bsv.Satoshis `json:"satoshis"` From optional.Param[string] `json:"from,omitempty"` } +// GetType returns a string typename of the output. func (o Output) GetType() string { return "paymail" } diff --git a/models/request/transaction_specification.go b/models/request/transaction_specification.go index 17fa090d4..d4f064f46 100644 --- a/models/request/transaction_specification.go +++ b/models/request/transaction_specification.go @@ -45,7 +45,7 @@ func (dt *TransactionSpecification) unmarshalPartials(data []byte) (rawOutputs [ } if err := json.Unmarshal(data, &temp); err != nil { - return nil, err + return nil, err //nolint:wrapcheck // unmarshalPartials is run internally by json.Unmarshal, so we don't want to wrap the error } return temp.Outputs, nil @@ -58,7 +58,7 @@ func unmarshalOutputs(outputs []json.RawMessage) ([]Output, error) { Type string `json:"type"` } if err := json.Unmarshal(rawOutput, &typeField); err != nil { - return nil, err + return nil, err //nolint:wrapcheck // unmarshalOutputs is run internally by json.Unmarshal, so we don't want to wrap the error } output, err := unmarshalOutput(rawOutput, typeField.Type) @@ -88,5 +88,5 @@ func (dt *TransactionSpecification) MarshalJSON() ([]byte, error) { temp.Outputs = append(temp.Outputs, out) } - return json.Marshal(temp) + return json.Marshal(temp) //nolint:wrapcheck // MarshalJSON is run internally by json.Marshal, so we don't want to wrap the error } diff --git a/models/request/transaction_specification_json.go b/models/request/transaction_specification_json.go index 9c0718593..95c671fab 100644 --- a/models/request/transaction_specification_json.go +++ b/models/request/transaction_specification_json.go @@ -15,13 +15,13 @@ func unmarshalOutput(rawOutput json.RawMessage, outputType string) (Output, erro case "op_return": var out opreturn.Output if err := json.Unmarshal(rawOutput, &out); err != nil { - return nil, err + return nil, err //nolint:wrapcheck // unmarshalOutput is run internally by json.Unmarshal, so we don't want to wrap the error } return out, nil case "paymail": var out paymailreq.Output if err := json.Unmarshal(rawOutput, &out); err != nil { - return nil, err + return nil, err //nolint:wrapcheck // unmarshalOutput is run internally by json.Unmarshal, so we don't want to wrap the error } return out, nil default: @@ -29,7 +29,7 @@ func unmarshalOutput(rawOutput json.RawMessage, outputType string) (Output, erro } } -// expandOutputForMarshaling used by TransactionSpecification marshalling to expand Output object before marshalling. +// expandOutputForMarshaling used by TransactionSpecification marshaling to expand Output object before marshaling. // IMPORTANT: Every time a new output type is added, it must be handled here also. func expandOutputForMarshaling(output Output) (any, error) { switch o := output.(type) { diff --git a/models/response/contact.go b/models/response/contact.go index b50e0fb5f..c09eb31ff 100644 --- a/models/response/contact.go +++ b/models/response/contact.go @@ -1,10 +1,12 @@ package response +// CreateContactResponse is a model for response on contact creation. type CreateContactResponse struct { Contact *Contact `json:"contact"` AdditionalInfo map[string]string `json:"additionalInfo"` } +// Contact is a model for contact. type Contact struct { Model @@ -20,8 +22,10 @@ type Contact struct { Status ContactStatus `json:"status" example:"unconfirmed"` } +// ContactStatus is a type for contact status. type ContactStatus string +// Enum values for ContactStatus. const ( ContactNotConfirmed ContactStatus = "unconfirmed" ContactAwaitAccept ContactStatus = "awaiting" @@ -29,6 +33,7 @@ const ( ContactRejected ContactStatus = "rejected" ) +// AddAdditionalInfo adds additional information (as key-value map) to the response. func (m *CreateContactResponse) AddAdditionalInfo(k, v string) { if m.AdditionalInfo == nil { m.AdditionalInfo = make(map[string]string) diff --git a/models/swagger/access_key_params.go b/models/swagger/access_key_params.go index b800a134b..2cb6ccb14 100644 --- a/models/swagger/access_key_params.go +++ b/models/swagger/access_key_params.go @@ -6,6 +6,7 @@ import ( "github.com/bitcoin-sv/spv-wallet/models/filter" ) +// CommonFilteringQueryParams is a model for common filtering query parameters. type CommonFilteringQueryParams struct { filter.Page `json:",inline"`