Skip to content

Commit

Permalink
feat(bux-246): optimize structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazarii-4chain committed Apr 4, 2024
1 parent a338b4b commit 60f49e1
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 72 deletions.
8 changes: 4 additions & 4 deletions actions/admin/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

// CreatePaymail is the model for creating a paymail
type CreatePaymail struct {
// Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource
Metadata engine.Metadata `json:"metadata" swaggertype:"object,string" example:"key:value,key2:value2"`
// The xpub with which the paymail is associated
Key string `json:"key" example:"xpub661MyMwAqRbcGpZVrSHU..."`
// The paymail address
Expand All @@ -14,8 +16,6 @@ type CreatePaymail struct {
PublicName string `json:"public_name" example:"Test"`
// The avatar of the paymail (url address)
Avatar string `json:"avatar" example:"https://example.com/avatar.png"`
// Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource
Metadata engine.Metadata `json:"metadata" swaggertype:"object,string" example:"key:value,key2:value2"`
}

// PaymailAddress is the model containing only paymail address used for getting and deleting paymail address
Expand All @@ -32,8 +32,8 @@ type RecordTransaction struct {

// CreateXpub is the model for creating an xpub
type CreateXpub struct {
// The xpub key
Key string `json:"key" example:"xpub661MyMwAqRbcGpZVrSHU..."`
// Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource
Metadata engine.Metadata `json:"metadata" swaggertype:"object,string" example:"key:value,key2:value2"`
// The xpub key
Key string `json:"key" example:"xpub661MyMwAqRbcGpZVrSHU..."`
}
4 changes: 2 additions & 2 deletions actions/destinations/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ type CreateDestination struct {

// UpdateDestination is the model for updating a destination
type UpdateDestination struct {
// Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource
Metadata engine.Metadata `json:"metadata" swaggertype:"object,string" example:"key:value,key2:value2"`
// ID of the destination which is the hash of the LockingScript
ID string `json:"id" example:"82a5d848f997819a478b05fb713208d7f3aa66da5ba00953b9845fb1701f9b98"`
// Address of the destination
Address string `json:"address" example:"1CDUf7CKu8ocTTkhcYUbq75t14Ft168K65"`
// LockingScript of the destination
LockingScript string `json:"locking_script" example:"76a9147b05764a97f3b4b981471492aa703b188e45979b88ac"`
// Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource
Metadata engine.Metadata `json:"metadata" swaggertype:"object,string" example:"key:value,key2:value2"`
}
8 changes: 4 additions & 4 deletions actions/transactions/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import (

// UpdateTransaction is the model for updating a transaction
type UpdateTransaction struct {
// Id of the transaction which is a hash of the transaction
ID string `json:"id" example:"01d0d0067652f684c6acb3683763f353fce55f6496521c7d99e71e1d27e53f5c"`
// Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource
Metadata engine.Metadata `json:"metadata" swaggertype:"object,string" example:"key:value,key2:value2"`
// ID of the transaction which is a hash of the transaction
ID string `json:"id" example:"01d0d0067652f684c6acb3683763f353fce55f6496521c7d99e71e1d27e53f5c"`
}

// RecordTransaction is the model for recording a transaction
type RecordTransaction struct {
// Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource
Metadata engine.Metadata `json:"metadata" swaggertype:"object,string" example:"key:value,key2:value2"`
// Hex of the transaction
Hex string `json:"hex" example:"0100000002..."`
// ReferenceID which is a ID of the draft transaction
ReferenceID string `json:"reference_id" example:"b356f7fa00cd3f20cce6c21d704cd13e871d28d714a5ebd0532f5a0e0cde63f7"`
// Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource
Metadata engine.Metadata `json:"metadata" swaggertype:"object,string" example:"key:value,key2:value2"`
}

// NewTransaction is the model for creating a new transaction
Expand Down
78 changes: 39 additions & 39 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ type AppConfig struct {
Cache *CacheConfig `json:"cache" mapstructure:"cache"`
// Db is the configuration for database related settings.
Db *DbConfig `json:"db" mapstructure:"db"`
// Debug is a flag for enabling additional information from SPV Wallet.
Debug bool `json:"debug" mapstructure:"debug"`
// DebugProfiling is a flag for enabling additinal debug profiling.
DebugProfiling bool `json:"debug_profiling" mapstructure:"debug_profiling"`
// DisableITC is a flag for disabling Incoming Transaction Checking.
DisableITC bool `json:"disable_itc" mapstructure:"disable_itc"`
// ImportBlockHeaders is a URL from where the headers can be downloaded.
ImportBlockHeaders string `json:"import_block_headers" mapstructure:"import_block_headers"`
// Server is a general configuration for spv-wallet.
Server *ServerConfig `json:"server_config" mapstructure:"server_config"`
// TaskManager is a configuration for Task Manager in SPV Wallet.
TaskManager *TaskManagerConfig `json:"task_manager" mapstructure:"task_manager"`
// Metrics is a configuration for metrics in SPV Wallet.
Metrics *MetricsConfig `json:"metrics" mapstructure:"metrics"`
// ExperimentalFeatures is a configuration that allows to enable features that are considered experimental/non-production.
ExperimentalFeatures *ExperimentalConfig `json:"experimental_features" mapstructure:"experimental_features"`
// Logging is the configuration for zerolog used in SPV Wallet.
Logging *LoggingConfig `json:"logging" mapstructure:"logging"`
// NewRelic is New Relic related settings.
Expand All @@ -49,38 +49,38 @@ type AppConfig struct {
Notifications *NotificationsConfig `json:"notifications" mapstructure:"notifications"`
// Paymail is a config for Paymail and BEEF.
Paymail *PaymailConfig `json:"paymail" mapstructure:"paymail"`
// Debug is a flag for enabling additional information from SPV Wallet.
Debug bool `json:"debug" mapstructure:"debug"`
// DebugProfiling is a flag for enabling additinal debug profiling.
DebugProfiling bool `json:"debug_profiling" mapstructure:"debug_profiling"`
// DisableITC is a flag for disabling Incoming Transaction Checking.
DisableITC bool `json:"disable_itc" mapstructure:"disable_itc"`
// RequestLogging is flag for enabling logging in go-api-router.
RequestLogging bool `json:"request_logging" mapstructure:"request_logging"`
// Server is a general configuration for spv-wallet.
Server *ServerConfig `json:"server_config" mapstructure:"server_config"`
// TaskManager is a configuration for Task Manager in SPV Wallet.
TaskManager *TaskManagerConfig `json:"task_manager" mapstructure:"task_manager"`
// Metrics is a configuration for metrics in SPV Wallet.
Metrics *MetricsConfig `json:"metrics" mapstructure:"metrics"`
// ExperimentalFeatures is a configuration that allows to enable features that are considered experimental/non-production.
ExperimentalFeatures *ExperimentalConfig `json:"experimental_features" mapstructure:"experimental_features"`
// ImportBlockHeaders is a URL from where the headers can be downloaded.
ImportBlockHeaders string `json:"import_block_headers" mapstructure:"import_block_headers"`
}

// AuthenticationConfig is the configuration for Authentication
type AuthenticationConfig struct {

Check failure on line 65 in config/config.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 32 pointer bytes could be 24 (govet)
// AdminKey is used for administrative requests
AdminKey string `json:"admin_key" mapstructure:"admin_key"`
// RequireSigning is the flag that decides if the signing is required
RequireSigning bool `json:"require_signing" mapstructure:"require_signing"`
// Scheme it the authentication scheme to use (default is: xpub)
Scheme string `json:"scheme" mapstructure:"scheme"`
// SigningDisabled turns off signing. NOTE: Only for development
SigningDisabled bool `json:"signing_disabled" mapstructure:"signing_disabled"`
// AdminKey is used for administrative requests
AdminKey string `json:"admin_key" mapstructure:"admin_key"`
// Scheme it the authentication scheme to use (default is: xpub)
Scheme string `json:"scheme" mapstructure:"scheme"`
}

// CacheConfig is a configuration for cachestore
type CacheConfig struct {
// Engine is the cache engine to use (redis, freecache).
Engine cachestore.Engine `json:"engine" mapstructure:"engine"`
// Cluster is the cluster-specific configuration for SPV Wallet.
Cluster *ClusterConfig `json:"cluster" mapstructure:"cluster"`
// Redis is a general config for redis if the engine is set to it.
Redis *RedisConfig `json:"redis" mapstructure:"redis"`
// Engine is the cache engine to use (redis, freecache).
Engine cachestore.Engine `json:"engine" mapstructure:"engine"`
}

// CallbackConfig is the configuration for callbacks
Expand All @@ -93,30 +93,30 @@ type CallbackConfig struct {

// ClusterConfig is a configuration for the SPV Wallet cluster
type ClusterConfig struct {
// Redis is cluster-specific redis config, will use cache config if this is unset.
Redis *RedisConfig `json:"redis" mapstrcuture:"redis"`
// Coordinator is a cluster coordinator (redis or memory).
Coordinator cluster.Coordinator `json:"coordinator" mapstructure:"coordinator"`
// Prefix is the string to use for all cluster keys.
Prefix string `json:"prefix" mapstructure:"prefix"`
// Redis is cluster-specific redis config, will use cache config if this is unset.
Redis *RedisConfig `json:"redis" mapstrcuture:"redis"`
}

// RedisConfig is a configuration for Redis cachestore or taskmanager
type RedisConfig struct {

Check failure on line 105 in config/config.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 48 pointer bytes could be 8 (govet)
// DependencyMode works only in Redis with script enabled.
DependencyMode bool `json:"dependency_mode" mapstructure:"dependency_mode"`
// UseTLS is a flag which decides whether to use TLS
UseTLS bool `json:"use_tls" mapstructure:"use_tls"`
// MaxActiveConnections is maximum number of active redis connections.
MaxActiveConnections int `json:"max_active_connections" mapstructure:"max_active_connections"`
// MaxConnectionLifetime is the maximum duration of the connection.
MaxConnectionLifetime time.Duration `json:"max_connection_lifetime" mapstructure:"max_connection_lifetime"`
// MaxIdleConnections is the maximum number of idle connections.
MaxIdleConnections int `json:"max_idle_connections" mapstructure:"max_idle_connections"`
// MaxConnectionLifetime is the maximum duration of the connection.
MaxConnectionLifetime time.Duration `json:"max_connection_lifetime" mapstructure:"max_connection_lifetime"`
// MaxIdleTimeout is the maximum duration of idle redis connection before timeout.
MaxIdleTimeout time.Duration `json:"max_idle_timeout" mapstructure:"max_idle_timeout"`
// URL is Redis url connection string.
URL string `json:"url" mapstructure:"url"`
// UseTLS is a flag which decides whether to use TLS
UseTLS bool `json:"use_tls" mapstructure:"use_tls"`
}

// DbConfig consists of datastore config and specific dbs configs
Expand All @@ -135,30 +135,30 @@ type DbConfig struct {
type DatastoreConfig struct {

Check failure on line 135 in config/config.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 32 pointer bytes could be 24 (govet)
// Debug is a flag that decides whether additional output (such as sql statements) should be produced from datastore.
Debug bool `json:"debug" mapstructure:"debug"`
// Engine is the database to be used, mysql, sqlite, postgresql.
Engine datastore.Engine `json:"engine" mapstructure:"engine"`
// TablePrefix is the prefix for all table names in the database.
TablePrefix string `json:"table_prefix" mapstructure:"table_prefix"`
// Engine is the database to be used, mysql, sqlite, postgresql.
Engine datastore.Engine `json:"engine" mapstructure:"engine"`
}

// NewRelicConfig is the configuration for New Relic
type NewRelicConfig struct {

Check failure on line 145 in config/config.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 32 pointer bytes could be 24 (govet)
// DomainName is used for hostname display.
DomainName string `json:"domain_name" mapstructure:"domain_name"`
// Enabled is the flag that enables New Relic service.
Enabled bool `json:"enabled" mapstructure:"enabled"`
// DomainName is used for hostname display.
DomainName string `json:"domain_name" mapstructure:"domain_name"`
// LicenseKey is the New Relic license key.
LicenseKey string `json:"license_key" mapstructure:"license_key"`
}

// NodesConfig consists of blockchain nodes (such as Minercraft and Arc) configuration
type NodesConfig struct {

Check failure on line 155 in config/config.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 72 pointer bytes could be 56 (govet)
DeploymentID string `json:"deployment_id" mapstructure:"deployment_id"`
Callback *CallbackConfig `json:"callback" mapstructure:"callback"`
Protocol NodesProtocol `json:"protocol" mapstructure:"protocol"`
Apis []*MinerAPI `json:"apis" mapstructure:"apis"`
UseFeeQuotes bool `json:"use_fee_quotes" mapstructure:"use_fee_quotes"`
FeeUnit *FeeUnitConfig `json:"fee_unit" mapstructure:"fee_unit"`
UseFeeQuotes bool `json:"use_fee_quotes" mapstructure:"use_fee_quotes"`
DeploymentID string `json:"deployment_id" mapstructure:"deployment_id"`
Protocol NodesProtocol `json:"protocol" mapstructure:"protocol"`
}

// FeeUnitConfig reflects the utils.FeeUnit struct with proper annotations for json and mapstructure
Expand All @@ -179,10 +179,10 @@ type MinerAPI struct {

// NotificationsConfig is the configuration for notifications
type NotificationsConfig struct {
// Enabled is the flag that enables notifications service.
Enabled bool `json:"enabled" mapstructure:"enabled"`
// WebhookEndpoint is the endpoint for webhook registration.
WebhookEndpoint string `json:"webhook_endpoint" mapstructure:"webhook_endpoint"`
// Enabled is the flag that enables notifications service.
Enabled bool `json:"enabled" mapstructure:"enabled"`
}

// LoggingConfig is a configuration for logging
Expand Down Expand Up @@ -213,12 +213,12 @@ type PaymailConfig struct {

// BeefConfig consists of components required to use beef, e.g. Block Headers Service for merkle roots validation
type BeefConfig struct {
// UseBeef is a flag for enabling BEEF transactions format.
UseBeef bool `json:"use_beef" mapstructure:"use_beef"`
// BlockHeaderServiceHeaderValidationURL is the URL for merkle roots validation in Block Headers Service.
BlockHeaderServiceHeaderValidationURL string `json:"block_header_service_url" mapstructure:"block_header_service_url"`
// BlockHeaderServiceAuthToken is the authentication token for validating merkle roots in Block Headers Service.
BlockHeaderServiceAuthToken string `json:"block_header_service_auth_token" mapstructure:"block_header_service_auth_token"`
// UseBeef is a flag for enabling BEEF transactions format.
UseBeef bool `json:"use_beef" mapstructure:"use_beef"`
}

func (b *BeefConfig) enabled() bool {
Expand Down
2 changes: 1 addition & 1 deletion dictionary/dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
// ErrorMessage is used for standardizing the messages/codes for errors
type ErrorMessage struct {

Check failure on line 10 in dictionary/dictionary.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 40 pointer bytes could be 24 (govet)
Code ErrorCode `json:"code"`
StatusCode int `json:"status_code"`
InternalMessage string `json:"internal_message"`
PublicMessage string `json:"public_message"`
StatusCode int `json:"status_code"`
}

// errorMessages is the public
Expand Down
44 changes: 22 additions & 22 deletions dictionary/dictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,59 @@ func TestErrorCode_IsValid(t *testing.T) {
t.Parallel()

var tests = []struct {

Check failure on line 14 in dictionary/dictionary_test.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 16 pointer bytes could be 8 (govet)
testCase string
code ErrorCode
expectValid bool
code ErrorCode
testCase string
}{
{
"ErrorBadErrorCode",
ErrorBadErrorCode,
true,
ErrorBadErrorCode,
"ErrorBadErrorCode",
},
{
"ErrorMissingEnv",
ErrorMissingEnv,
true,
ErrorMissingEnv,
"ErrorMissingEnv",
},
{
"ErrorInvalidEnv",
ErrorInvalidEnv,
true,
ErrorInvalidEnv,
"ErrorInvalidEnv",
},
{
"ErrorReadingConfig",
ErrorReadingConfig,
true,
ErrorReadingConfig,
"ErrorReadingConfig",
},
{
"ErrorViper",
ErrorViper,
true,
ErrorViper,
"ErrorViper",
},
{
"ErrorConfigValidation",
ErrorConfigValidation,
true,
ErrorConfigValidation,
"ErrorConfigValidation",
},
{
"ErrorDecryptEnv",
ErrorDecryptEnv,
true,
ErrorDecryptEnv,
"ErrorDecryptEnv",
},
{
"ErrorLoadingConfig",
ErrorLoadingConfig,
true,
ErrorLoadingConfig,
"ErrorLoadingConfig",
},
{
"ErrorLoadingCache",
ErrorLoadingCache,
true,
ErrorLoadingCache,
"ErrorLoadingCache",
},
{
"unknown code",
9999,
false,
9999,
"unknown code",
},
}

Expand Down

0 comments on commit 60f49e1

Please sign in to comment.