From f46fea85806aae0f7ef9eb1b9b6d1f4b91e2fb27 Mon Sep 17 00:00:00 2001 From: Ethan Reesor Date: Thu, 11 Jul 2024 20:56:59 +0000 Subject: [PATCH] Convert cmd/accumulated/run to schema [#3615] Closes #3615. Convert `cmd/accumulated/run` to use the new schema package. Changelog: refactor --- cmd/accumulated-http/main.go | 3 +- cmd/accumulated/cmd_init_devnet.go | 4 +- cmd/accumulated/run/config.yml | 589 --- cmd/accumulated/run/consensus.go | 12 - cmd/accumulated/run/core_validator.go | 2 +- cmd/accumulated/run/enums.yml | 68 - cmd/accumulated/run/enums_gen.go | 505 --- cmd/accumulated/run/http.go | 5 +- cmd/accumulated/run/instrumentation.go | 11 +- cmd/accumulated/run/key.go | 7 - cmd/accumulated/run/reference.go | 2 - cmd/accumulated/run/schema.yml | 613 +++ cmd/accumulated/run/schema_gen.go | 1592 ++++++++ cmd/accumulated/run/storage.go | 8 - cmd/accumulated/run/telemetry.go | 19 +- cmd/accumulated/run/types.go | 59 +- cmd/accumulated/run/types_gen.go | 4398 +++++---------------- cmd/accumulated/run/unions_gen.go | 514 --- go.mod | 2 +- go.sum | 4 +- pkg/database/bpt/schema_gen.go | 10 +- pkg/database/keyvalue/block/schema_gen.go | 6 +- pkg/database/keyvalue/block/types_gen.go | 2 +- pkg/types/encoding/time.go | 122 + 24 files changed, 3373 insertions(+), 5184 deletions(-) delete mode 100644 cmd/accumulated/run/config.yml delete mode 100644 cmd/accumulated/run/enums.yml delete mode 100644 cmd/accumulated/run/enums_gen.go create mode 100644 cmd/accumulated/run/schema.yml create mode 100644 cmd/accumulated/run/schema_gen.go delete mode 100644 cmd/accumulated/run/unions_gen.go create mode 100644 pkg/types/encoding/time.go diff --git a/cmd/accumulated-http/main.go b/cmd/accumulated-http/main.go index 63d2ff9a9..2d5d9f6cb 100644 --- a/cmd/accumulated-http/main.go +++ b/cmd/accumulated-http/main.go @@ -25,6 +25,7 @@ import ( . "gitlab.com/accumulatenetwork/accumulate/internal/util/cmd" cmdutil "gitlab.com/accumulatenetwork/accumulate/internal/util/cmd" "gitlab.com/accumulatenetwork/accumulate/pkg/accumulate" + "gitlab.com/accumulatenetwork/accumulate/pkg/types/encoding" ) func main() { @@ -116,7 +117,7 @@ func run(cmd *cobra.Command, args []string) { HttpListener: HttpListener{ Listen: flag.HttpListen, ConnectionLimit: &flag.ConnLimit, - ReadHeaderTimeout: &flag.Timeout, + ReadHeaderTimeout: (*encoding.Duration)(&flag.Timeout), TlsCertPath: flag.TlsCert, TlsKeyPath: flag.TlsKey, }, diff --git a/cmd/accumulated/cmd_init_devnet.go b/cmd/accumulated/cmd_init_devnet.go index eba35b970..c0b18ecab 100644 --- a/cmd/accumulated/cmd_init_devnet.go +++ b/cmd/accumulated/cmd_init_devnet.go @@ -93,8 +93,8 @@ func applyDevNetFlags(cmd *cobra.Command, cfg *run.Config, dev *run.DevnetConfig } if cmd.Flag("database").Changed { - typ, ok := run.StorageTypeByName(flagRunDevnet.Database) - if !ok { + var typ run.StorageType + if !typ.SetByName(flagRunDevnet.Database) { fatalf("--database: %q is not a valid storage type", flagRunDevnet.Database) } dev.StorageType = &typ diff --git a/cmd/accumulated/run/config.yml b/cmd/accumulated/run/config.yml deleted file mode 100644 index 5b584c261..000000000 --- a/cmd/accumulated/run/config.yml +++ /dev/null @@ -1,589 +0,0 @@ -Config: - non-binary: true - fields: - - name: file - type: string - marshal-as: none - - name: fs - type: fs.FS - marshal-as: none - - name: DotEnv - type: bool - pointer: true - - name: Network - type: string - - name: Logging - type: Logging - marshal-as: reference - pointer: true - - name: Instrumentation - type: Instrumentation - marshal-as: reference - pointer: true - - name: Telemetry - type: Telemetry - marshal-as: reference - pointer: true - - name: P2P - type: P2P - marshal-as: reference - pointer: true - - name: Configurations - type: Configuration - marshal-as: union - repeatable: true - - name: Services - type: Service - marshal-as: union - repeatable: true - -Logging: - non-binary: true - fields: - - name: Format - type: string - - name: Color - type: bool - pointer: true - - name: Rules - type: LoggingRule - marshal-as: reference - pointer: true - repeatable: true - - name: Loki - type: LokiLogging - marshal-as: reference - pointer: true - -LoggingRule: - non-binary: true - fields: - - name: Level - type: slog.Level - marshal-as: value - zero-value: '0' - keep-empty: true - - name: Modules - type: string - repeatable: true - -LokiLogging: - non-binary: true - fields: - - name: Enable - type: bool - - name: Url - type: string - - name: Username - type: string - - name: Password - type: string - -Instrumentation: - non-binary: true - fields: - - type: HttpListener - marshal-as: reference - - name: Monitoring - type: Monitor - marshal-as: reference - pointer: true - - name: PprofListen - type: p2p.Multiaddr - marshal-as: union - -Telemetry: - non-binary: true - fields: - - name: Enabled - type: bool - pointer: true - - name: Stdout - type: bool - pointer: true - - name: Otlp - type: OtlpConfig - pointer: true - marshal-as: reference - - name: Export - type: HttpListener - pointer: true - marshal-as: reference - - name: Rules - type: TelemetryRule - pointer: true - repeatable: true - marshal-as: reference - -TelemetryRule: - non-binary: true - fields: - - name: Match - type: string - repeatable: true - - name: Drop - type: bool - - name: Rate - type: duration - -OtlpConfig: - non-binary: true - fields: - - name: Enabled - type: bool - pointer: true - - name: Endpoint - type: string - - name: Username - type: string - - name: Password - type: string - -Monitor: - non-binary: true - fields: - - name: Directory - description: is the directory traces and profiles are written to - type: string - - name: ProfileMemory - description: enables profiling when memory usage increases dramatically - type: bool - pointer: true - - name: MemoryPollingRate - description: is rate at which to poll memory usage - type: duration - pointer: true - - name: AllocRateTrigger - description: is the rate of allocation in bytes/second that triggers a profile - type: float - pointer: true - -HttpListener: - non-binary: true - fields: - - name: Listen - description: are the addresses and schemes to listen on - type: p2p.Multiaddr - marshal-as: union - repeatable: true - - name: ConnectionLimit - description: limits the number of concurrent connections - type: int - optional: true - pointer: true - - name: ReadHeaderTimeout - description: protects against slow-loris attacks - type: duration - optional: true - pointer: true - - name: TlsCertPath - description: is the path of the TLS certificate - type: string - optional: true - - name: TlsKeyPath - description: is the path of the TLS key - type: string - optional: true - -P2P: - non-binary: true - fields: - - name: Listen - type: p2p.Multiaddr - marshal-as: union - repeatable: true - - name: BootstrapPeers - type: p2p.Multiaddr - marshal-as: union - repeatable: true - - name: Key - type: PrivateKey - marshal-as: union - - name: PeerDB - type: string - pointer: true - - name: EnablePeerTracking - type: bool - - name: DiscoveryMode - type: DhtMode - marshal-as: value - pointer: true - - name: External - type: p2p.Multiaddr - marshal-as: union - -RawPrivateKey: - union: { type: privateKey } - non-binary: true - fields: - - name: Address - type: string - -TransientPrivateKey: - union: { type: privateKey } - non-binary: true - fields: - - name: key - type: address.Address - marshal-as: none - -PrivateKeySeed: - union: { type: privateKey, value: seed } - non-binary: true - fields: - - name: key - type: address.Address - marshal-as: none - - name: Seed - type: record.Key - marshal-as: reference - pointer: true - -CometPrivValFile: - union: { type: privateKey } - non-binary: true - fields: - - name: key - type: address.Address - marshal-as: none - - name: Path - type: string - -CometNodeKeyFile: - union: { type: privateKey } - non-binary: true - fields: - - name: key - type: address.Address - marshal-as: none - - name: Path - type: string - -StorageService: - union: { type: service } - non-binary: true - fields: - - name: Name - type: string - optional: true - - name: Storage - type: Storage - marshal-as: union - -MemoryStorage: - union: { type: storage } - non-binary: true - fields: ~ - -BadgerStorage: - union: { type: storage } - non-binary: true - fields: - - name: Path - type: string - - name: Version - type: int - -BoltStorage: - union: { type: storage } - non-binary: true - fields: - - name: Path - type: string - -LevelDBStorage: - union: { type: storage } - non-binary: true - fields: - - name: Path - type: string - -ExpBlockDBStorage: - union: { type: storage } - non-binary: true - fields: - - name: Path - type: string - -HttpService: - union: { type: service } - non-binary: true - fields: - - type: HttpListener - marshal-as: reference - - name: CorsOrigins - description: is a list of allowed CORS origins - type: string - repeatable: true - optional: true - - name: LetsEncrypt - description: automatically retrieves a certificate from Let's Encrypt for the specified domains - type: string - repeatable: true - optional: true - - name: DebugJsonRpc - type: bool - optional: true - pointer: true - - name: Router - type: { name: ServiceOrRef, parameters: [{ type: RouterService, pointer: true }] } - marshal-as: reference - pointer: true - - name: PeerMap - description: hard-codes the peer map - type: HttpPeerMapEntry - marshal-as: reference - pointer: true - repeatable: true - -HttpPeerMapEntry: - fields: - - name: ID - type: p2p.PeerID - marshal-as: union - zero-value: '""' - - name: Partitions - type: string - repeatable: true - - name: Addresses - type: p2p.Multiaddr - marshal-as: union - repeatable: true - -RouterService: - union: { type: service } - fields: - - name: Name - type: string - optional: true - - name: Events - description: may specify an event bus to use for routing table updates - type: string - optional: true - - name: PeerMap - description: uses a hard-coded peer map for initializing routing - type: HttpPeerMapEntry - marshal-as: reference - pointer: true - repeatable: true - -FaucetService: - union: { type: service } - non-binary: true - fields: - - name: Account - type: url - pointer: true - - name: SigningKey - type: PrivateKey - marshal-as: union - - name: Router - type: { name: ServiceOrRef, parameters: [{ type: RouterService, pointer: true }] } - marshal-as: reference - pointer: true - -GatewayConfiguration: - union: { type: configuration } - non-binary: true - fields: - - name: Listen - type: p2p.Multiaddr - marshal-as: union - -Querier: - union: { type: service } - non-binary: true - fields: - - name: Partition - type: string - - name: Storage - type: StorageOrRef - marshal-as: reference - pointer: true - optional: true - -NetworkService: - union: { type: service } - non-binary: true - fields: - - name: Partition - type: string - -MetricsService: - union: { type: service } - non-binary: true - fields: - - name: Partition - type: string - -EventsService: - union: { type: service } - non-binary: true - fields: - - name: Partition - type: string - -SnapshotService: - union: { type: service } - non-binary: true - fields: - - name: Partition - type: string - - name: Storage - type: StorageOrRef - marshal-as: reference - pointer: true - optional: true - - - name: Directory - description: is the directory to store snapshots in - type: string - - name: Schedule - description: is the schedule for capturing snapshots - type: network.CronSchedule - marshal-as: reference - pointer: true - optional: true - - name: RetainCount - description: is the number of snapshots to retain - type: uint - optional: true - pointer: true - - name: EnableIndexing - description: enables indexing of snapshots - type: bool - optional: true - pointer: true - -CoreValidatorConfiguration: - union: { type: configuration } - non-binary: true - fields: - - name: Mode - type: CoreValidatorMode - marshal-as: enum - - name: Listen - type: p2p.Multiaddr - marshal-as: union - - name: BVN - type: string - - name: ValidatorKey - type: PrivateKey - marshal-as: union - - name: DnGenesis - type: string - - name: BvnGenesis - type: string - - name: DnBootstrapPeers - type: p2p.Multiaddr - marshal-as: union - repeatable: true - - name: BvnBootstrapPeers - type: p2p.Multiaddr - marshal-as: union - repeatable: true - - name: EnableHealing - type: bool - pointer: true - optional: true - - name: EnableDirectDispatch - type: bool - optional: true - pointer: true - - name: EnableSnapshots - type: bool - optional: true - pointer: true - - name: MaxEnvelopesPerBlock - type: uint - optional: true - pointer: true - - name: StorageType - type: StorageType - marshal-as: enum - pointer: true - optional: true - -ConsensusService: - union: { type: service } - non-binary: true - fields: - - name: NodeDir - type: string - - name: ValidatorKey - type: PrivateKey - marshal-as: union - - name: Genesis - type: string - - name: Listen - type: p2p.Multiaddr - marshal-as: union - - name: BootstrapPeers - type: p2p.Multiaddr - marshal-as: union - repeatable: true - - name: MetricsNamespace - type: string - optional: true - - name: App - type: ConsensusApp - marshal-as: union - -CoreConsensusApp: - union: { type: consensusApp } - non-binary: true - fields: - - name: Partition - type: protocol.PartitionInfo - marshal-as: reference - pointer: true - - name: EnableHealing - type: bool - optional: true - pointer: true - - name: EnableDirectDispatch - type: bool - optional: true - pointer: true - - name: MaxEnvelopesPerBlock - type: uint - optional: true - pointer: true - -DevnetConfiguration: - union: { type: configuration } - non-binary: true - fields: - - name: Listen - type: p2p.Multiaddr - marshal-as: union - - name: Bvns - type: uint - - name: Validators - type: uint - - name: Followers - type: uint - optional: true - - name: Globals - type: network.GlobalValues - marshal-as: reference - pointer: true - - name: StorageType - type: StorageType - marshal-as: enum - pointer: true - optional: true - -SubnodeService: - union: { type: service } - non-binary: true - fields: - - name: Name - type: string - - name: NodeKey - type: PrivateKey - marshal-as: union - - name: Services - type: Service - marshal-as: union - repeatable: true diff --git a/cmd/accumulated/run/consensus.go b/cmd/accumulated/run/consensus.go index e83535e39..d8894c7ba 100644 --- a/cmd/accumulated/run/consensus.go +++ b/cmd/accumulated/run/consensus.go @@ -71,18 +71,6 @@ var ( coreConsensusProvidesClient = ioc.Provides[client.Client](func(c *CoreConsensusApp) string { return c.Partition.ID }) ) -type ConsensusApp interface { - Type() ConsensusAppType - CopyAsInterface() any - - partition() *protocol.PartitionInfo - Requires() []ioc.Requirement - Provides() []ioc.Provided - prestart(*Instance) error - start(*Instance, *tendermint) (types.Application, error) - register(*Instance, *tendermint, *tmnode.Node) error -} - type tendermint struct { config *tmcfg.Config privVal *tmpv.FilePV diff --git a/cmd/accumulated/run/core_validator.go b/cmd/accumulated/run/core_validator.go index 9d547f3c4..1bc748905 100644 --- a/cmd/accumulated/run/core_validator.go +++ b/cmd/accumulated/run/core_validator.go @@ -147,7 +147,7 @@ func (p partOpts) apply(cfg *Config) error { // Storage if !haveService2(cfg, p.ID, func(s *StorageService) string { return s.Name }, nil) { - storage, err := NewStorage(*p.StorageType) + storage, err := sStorage.New(*p.StorageType) if err != nil { return errors.UnknownError.Wrap(err) } diff --git a/cmd/accumulated/run/enums.yml b/cmd/accumulated/run/enums.yml deleted file mode 100644 index 23f59aaa2..000000000 --- a/cmd/accumulated/run/enums.yml +++ /dev/null @@ -1,68 +0,0 @@ -PrivateKeyType: - Raw: - value: 1 - Transient: - value: 2 - Seed: - value: 3 - CometPrivValFile: - value: 4 - CometNodeKeyFile: - value: 5 - -ServiceType: - Storage: - value: 1 - Consensus: - value: 2 - Querier: - value: 3 - Network: - value: 4 - Metrics: - value: 5 - Events: - value: 6 - Http: - value: 7 - Router: - value: 8 - Snapshot: - value: 9 - Faucet: - value: 10 - Subnode: - value: 11 - -StorageType: - Memory: - value: 1 - Badger: - value: 2 - Bolt: - value: 3 - LevelDB: - value: 4 - - ExpBlockDB: - value: 1001 - -ConfigurationType: - CoreValidator: - value: 1 - Gateway: - value: 2 - Devnet: - value: 3 - -ConsensusAppType: - Core: - value: 1 - -CoreValidatorMode: - Dual: - value: 0 - DN: - value: 1 - BVN: - value: 2 diff --git a/cmd/accumulated/run/enums_gen.go b/cmd/accumulated/run/enums_gen.go deleted file mode 100644 index 2fac209b9..000000000 --- a/cmd/accumulated/run/enums_gen.go +++ /dev/null @@ -1,505 +0,0 @@ -// Copyright 2024 The Accumulate Authors -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT. - -package run - -// GENERATED BY go run ./tools/cmd/gen-enum. DO NOT EDIT. - -import ( - "encoding/json" - "fmt" - "strings" -) - -// ConfigurationTypeCoreValidator . -const ConfigurationTypeCoreValidator ConfigurationType = 1 - -// ConfigurationTypeGateway . -const ConfigurationTypeGateway ConfigurationType = 2 - -// ConfigurationTypeDevnet . -const ConfigurationTypeDevnet ConfigurationType = 3 - -// ConsensusAppTypeCore . -const ConsensusAppTypeCore ConsensusAppType = 1 - -// CoreValidatorModeDual . -const CoreValidatorModeDual CoreValidatorMode = 0 - -// CoreValidatorModeDN . -const CoreValidatorModeDN CoreValidatorMode = 1 - -// CoreValidatorModeBVN . -const CoreValidatorModeBVN CoreValidatorMode = 2 - -// PrivateKeyTypeRaw . -const PrivateKeyTypeRaw PrivateKeyType = 1 - -// PrivateKeyTypeTransient . -const PrivateKeyTypeTransient PrivateKeyType = 2 - -// PrivateKeyTypeSeed . -const PrivateKeyTypeSeed PrivateKeyType = 3 - -// PrivateKeyTypeCometPrivValFile . -const PrivateKeyTypeCometPrivValFile PrivateKeyType = 4 - -// PrivateKeyTypeCometNodeKeyFile . -const PrivateKeyTypeCometNodeKeyFile PrivateKeyType = 5 - -// ServiceTypeStorage . -const ServiceTypeStorage ServiceType = 1 - -// ServiceTypeConsensus . -const ServiceTypeConsensus ServiceType = 2 - -// ServiceTypeQuerier . -const ServiceTypeQuerier ServiceType = 3 - -// ServiceTypeNetwork . -const ServiceTypeNetwork ServiceType = 4 - -// ServiceTypeMetrics . -const ServiceTypeMetrics ServiceType = 5 - -// ServiceTypeEvents . -const ServiceTypeEvents ServiceType = 6 - -// ServiceTypeHttp . -const ServiceTypeHttp ServiceType = 7 - -// ServiceTypeRouter . -const ServiceTypeRouter ServiceType = 8 - -// ServiceTypeSnapshot . -const ServiceTypeSnapshot ServiceType = 9 - -// ServiceTypeFaucet . -const ServiceTypeFaucet ServiceType = 10 - -// ServiceTypeSubnode . -const ServiceTypeSubnode ServiceType = 11 - -// StorageTypeMemory . -const StorageTypeMemory StorageType = 1 - -// StorageTypeBadger . -const StorageTypeBadger StorageType = 2 - -// StorageTypeBolt . -const StorageTypeBolt StorageType = 3 - -// StorageTypeLevelDB . -const StorageTypeLevelDB StorageType = 4 - -// StorageTypeExpBlockDB . -const StorageTypeExpBlockDB StorageType = 1001 - -// GetEnumValue returns the value of the Configuration Type -func (v ConfigurationType) GetEnumValue() uint64 { return uint64(v) } - -// SetEnumValue sets the value. SetEnumValue returns false if the value is invalid. -func (v *ConfigurationType) SetEnumValue(id uint64) bool { - u := ConfigurationType(id) - switch u { - case ConfigurationTypeCoreValidator, ConfigurationTypeGateway, ConfigurationTypeDevnet: - *v = u - return true - } - return false -} - -// String returns the name of the Configuration Type. -func (v ConfigurationType) String() string { - switch v { - case ConfigurationTypeCoreValidator: - return "coreValidator" - case ConfigurationTypeGateway: - return "gateway" - case ConfigurationTypeDevnet: - return "devnet" - } - return fmt.Sprintf("ConfigurationType:%d", v) -} - -// ConfigurationTypeByName returns the named Configuration Type. -func ConfigurationTypeByName(name string) (ConfigurationType, bool) { - switch strings.ToLower(name) { - case "corevalidator": - return ConfigurationTypeCoreValidator, true - case "gateway": - return ConfigurationTypeGateway, true - case "devnet": - return ConfigurationTypeDevnet, true - } - return 0, false -} - -// MarshalJSON marshals the Configuration Type to JSON as a string. -func (v ConfigurationType) MarshalJSON() ([]byte, error) { - return json.Marshal(v.String()) -} - -// UnmarshalJSON unmarshals the Configuration Type from JSON as a string. -func (v *ConfigurationType) UnmarshalJSON(data []byte) error { - var s string - err := json.Unmarshal(data, &s) - if err != nil { - return err - } - - var ok bool - *v, ok = ConfigurationTypeByName(s) - if !ok || strings.ContainsRune(v.String(), ':') { - return fmt.Errorf("invalid Configuration Type %q", s) - } - return nil -} - -// GetEnumValue returns the value of the Consensus App Type -func (v ConsensusAppType) GetEnumValue() uint64 { return uint64(v) } - -// SetEnumValue sets the value. SetEnumValue returns false if the value is invalid. -func (v *ConsensusAppType) SetEnumValue(id uint64) bool { - u := ConsensusAppType(id) - switch u { - case ConsensusAppTypeCore: - *v = u - return true - } - return false -} - -// String returns the name of the Consensus App Type. -func (v ConsensusAppType) String() string { - switch v { - case ConsensusAppTypeCore: - return "core" - } - return fmt.Sprintf("ConsensusAppType:%d", v) -} - -// ConsensusAppTypeByName returns the named Consensus App Type. -func ConsensusAppTypeByName(name string) (ConsensusAppType, bool) { - switch strings.ToLower(name) { - case "core": - return ConsensusAppTypeCore, true - } - return 0, false -} - -// MarshalJSON marshals the Consensus App Type to JSON as a string. -func (v ConsensusAppType) MarshalJSON() ([]byte, error) { - return json.Marshal(v.String()) -} - -// UnmarshalJSON unmarshals the Consensus App Type from JSON as a string. -func (v *ConsensusAppType) UnmarshalJSON(data []byte) error { - var s string - err := json.Unmarshal(data, &s) - if err != nil { - return err - } - - var ok bool - *v, ok = ConsensusAppTypeByName(s) - if !ok || strings.ContainsRune(v.String(), ':') { - return fmt.Errorf("invalid Consensus App Type %q", s) - } - return nil -} - -// GetEnumValue returns the value of the Core Validator Mode -func (v CoreValidatorMode) GetEnumValue() uint64 { return uint64(v) } - -// SetEnumValue sets the value. SetEnumValue returns false if the value is invalid. -func (v *CoreValidatorMode) SetEnumValue(id uint64) bool { - u := CoreValidatorMode(id) - switch u { - case CoreValidatorModeDual, CoreValidatorModeDN, CoreValidatorModeBVN: - *v = u - return true - } - return false -} - -// String returns the name of the Core Validator Mode. -func (v CoreValidatorMode) String() string { - switch v { - case CoreValidatorModeDual: - return "dual" - case CoreValidatorModeDN: - return "dn" - case CoreValidatorModeBVN: - return "bvn" - } - return fmt.Sprintf("CoreValidatorMode:%d", v) -} - -// CoreValidatorModeByName returns the named Core Validator Mode. -func CoreValidatorModeByName(name string) (CoreValidatorMode, bool) { - switch strings.ToLower(name) { - case "dual": - return CoreValidatorModeDual, true - case "dn": - return CoreValidatorModeDN, true - case "bvn": - return CoreValidatorModeBVN, true - } - return 0, false -} - -// MarshalJSON marshals the Core Validator Mode to JSON as a string. -func (v CoreValidatorMode) MarshalJSON() ([]byte, error) { - return json.Marshal(v.String()) -} - -// UnmarshalJSON unmarshals the Core Validator Mode from JSON as a string. -func (v *CoreValidatorMode) UnmarshalJSON(data []byte) error { - var s string - err := json.Unmarshal(data, &s) - if err != nil { - return err - } - - var ok bool - *v, ok = CoreValidatorModeByName(s) - if !ok || strings.ContainsRune(v.String(), ':') { - return fmt.Errorf("invalid Core Validator Mode %q", s) - } - return nil -} - -// GetEnumValue returns the value of the Private Key Type -func (v PrivateKeyType) GetEnumValue() uint64 { return uint64(v) } - -// SetEnumValue sets the value. SetEnumValue returns false if the value is invalid. -func (v *PrivateKeyType) SetEnumValue(id uint64) bool { - u := PrivateKeyType(id) - switch u { - case PrivateKeyTypeRaw, PrivateKeyTypeTransient, PrivateKeyTypeSeed, PrivateKeyTypeCometPrivValFile, PrivateKeyTypeCometNodeKeyFile: - *v = u - return true - } - return false -} - -// String returns the name of the Private Key Type. -func (v PrivateKeyType) String() string { - switch v { - case PrivateKeyTypeRaw: - return "raw" - case PrivateKeyTypeTransient: - return "transient" - case PrivateKeyTypeSeed: - return "seed" - case PrivateKeyTypeCometPrivValFile: - return "cometPrivValFile" - case PrivateKeyTypeCometNodeKeyFile: - return "cometNodeKeyFile" - } - return fmt.Sprintf("PrivateKeyType:%d", v) -} - -// PrivateKeyTypeByName returns the named Private Key Type. -func PrivateKeyTypeByName(name string) (PrivateKeyType, bool) { - switch strings.ToLower(name) { - case "raw": - return PrivateKeyTypeRaw, true - case "transient": - return PrivateKeyTypeTransient, true - case "seed": - return PrivateKeyTypeSeed, true - case "cometprivvalfile": - return PrivateKeyTypeCometPrivValFile, true - case "cometnodekeyfile": - return PrivateKeyTypeCometNodeKeyFile, true - } - return 0, false -} - -// MarshalJSON marshals the Private Key Type to JSON as a string. -func (v PrivateKeyType) MarshalJSON() ([]byte, error) { - return json.Marshal(v.String()) -} - -// UnmarshalJSON unmarshals the Private Key Type from JSON as a string. -func (v *PrivateKeyType) UnmarshalJSON(data []byte) error { - var s string - err := json.Unmarshal(data, &s) - if err != nil { - return err - } - - var ok bool - *v, ok = PrivateKeyTypeByName(s) - if !ok || strings.ContainsRune(v.String(), ':') { - return fmt.Errorf("invalid Private Key Type %q", s) - } - return nil -} - -// GetEnumValue returns the value of the Service Type -func (v ServiceType) GetEnumValue() uint64 { return uint64(v) } - -// SetEnumValue sets the value. SetEnumValue returns false if the value is invalid. -func (v *ServiceType) SetEnumValue(id uint64) bool { - u := ServiceType(id) - switch u { - case ServiceTypeStorage, ServiceTypeConsensus, ServiceTypeQuerier, ServiceTypeNetwork, ServiceTypeMetrics, ServiceTypeEvents, ServiceTypeHttp, ServiceTypeRouter, ServiceTypeSnapshot, ServiceTypeFaucet, ServiceTypeSubnode: - *v = u - return true - } - return false -} - -// String returns the name of the Service Type. -func (v ServiceType) String() string { - switch v { - case ServiceTypeStorage: - return "storage" - case ServiceTypeConsensus: - return "consensus" - case ServiceTypeQuerier: - return "querier" - case ServiceTypeNetwork: - return "network" - case ServiceTypeMetrics: - return "metrics" - case ServiceTypeEvents: - return "events" - case ServiceTypeHttp: - return "http" - case ServiceTypeRouter: - return "router" - case ServiceTypeSnapshot: - return "snapshot" - case ServiceTypeFaucet: - return "faucet" - case ServiceTypeSubnode: - return "subnode" - } - return fmt.Sprintf("ServiceType:%d", v) -} - -// ServiceTypeByName returns the named Service Type. -func ServiceTypeByName(name string) (ServiceType, bool) { - switch strings.ToLower(name) { - case "storage": - return ServiceTypeStorage, true - case "consensus": - return ServiceTypeConsensus, true - case "querier": - return ServiceTypeQuerier, true - case "network": - return ServiceTypeNetwork, true - case "metrics": - return ServiceTypeMetrics, true - case "events": - return ServiceTypeEvents, true - case "http": - return ServiceTypeHttp, true - case "router": - return ServiceTypeRouter, true - case "snapshot": - return ServiceTypeSnapshot, true - case "faucet": - return ServiceTypeFaucet, true - case "subnode": - return ServiceTypeSubnode, true - } - return 0, false -} - -// MarshalJSON marshals the Service Type to JSON as a string. -func (v ServiceType) MarshalJSON() ([]byte, error) { - return json.Marshal(v.String()) -} - -// UnmarshalJSON unmarshals the Service Type from JSON as a string. -func (v *ServiceType) UnmarshalJSON(data []byte) error { - var s string - err := json.Unmarshal(data, &s) - if err != nil { - return err - } - - var ok bool - *v, ok = ServiceTypeByName(s) - if !ok || strings.ContainsRune(v.String(), ':') { - return fmt.Errorf("invalid Service Type %q", s) - } - return nil -} - -// GetEnumValue returns the value of the Storage Type -func (v StorageType) GetEnumValue() uint64 { return uint64(v) } - -// SetEnumValue sets the value. SetEnumValue returns false if the value is invalid. -func (v *StorageType) SetEnumValue(id uint64) bool { - u := StorageType(id) - switch u { - case StorageTypeMemory, StorageTypeBadger, StorageTypeBolt, StorageTypeLevelDB, StorageTypeExpBlockDB: - *v = u - return true - } - return false -} - -// String returns the name of the Storage Type. -func (v StorageType) String() string { - switch v { - case StorageTypeMemory: - return "memory" - case StorageTypeBadger: - return "badger" - case StorageTypeBolt: - return "bolt" - case StorageTypeLevelDB: - return "levelDB" - case StorageTypeExpBlockDB: - return "expBlockDB" - } - return fmt.Sprintf("StorageType:%d", v) -} - -// StorageTypeByName returns the named Storage Type. -func StorageTypeByName(name string) (StorageType, bool) { - switch strings.ToLower(name) { - case "memory": - return StorageTypeMemory, true - case "badger": - return StorageTypeBadger, true - case "bolt": - return StorageTypeBolt, true - case "leveldb": - return StorageTypeLevelDB, true - case "expblockdb": - return StorageTypeExpBlockDB, true - } - return 0, false -} - -// MarshalJSON marshals the Storage Type to JSON as a string. -func (v StorageType) MarshalJSON() ([]byte, error) { - return json.Marshal(v.String()) -} - -// UnmarshalJSON unmarshals the Storage Type from JSON as a string. -func (v *StorageType) UnmarshalJSON(data []byte) error { - var s string - err := json.Unmarshal(data, &s) - if err != nil { - return err - } - - var ok bool - *v, ok = StorageTypeByName(s) - if !ok || strings.ContainsRune(v.String(), ':') { - return fmt.Errorf("invalid Storage Type %q", s) - } - return nil -} diff --git a/cmd/accumulated/run/http.go b/cmd/accumulated/run/http.go index b0f9463bc..50787f0b0 100644 --- a/cmd/accumulated/run/http.go +++ b/cmd/accumulated/run/http.go @@ -26,6 +26,7 @@ import ( "gitlab.com/accumulatenetwork/accumulate/pkg/api/v3/message" "gitlab.com/accumulatenetwork/accumulate/pkg/database/keyvalue/memory" "gitlab.com/accumulatenetwork/accumulate/pkg/errors" + "gitlab.com/accumulatenetwork/accumulate/pkg/types/encoding" "gitlab.com/accumulatenetwork/accumulate/pkg/url" "golang.org/x/crypto/acme/autocert" ) @@ -143,14 +144,14 @@ func (h *HttpService) start(inst *Instance) error { } func (h *HttpListener) applyHttpDefaults() { - setDefaultPtr(&h.ReadHeaderTimeout, DefaultHTTPReadHeaderTimeout) + setDefaultPtr(&h.ReadHeaderTimeout, encoding.Duration(DefaultHTTPReadHeaderTimeout)) setDefaultPtr(&h.ConnectionLimit, DefaultHTTPConnectionLimit) } func (h *HttpListener) startHTTP(inst *Instance, handler http.Handler) (*http.Server, error) { server := &http.Server{ Handler: handler, - ReadHeaderTimeout: *h.ReadHeaderTimeout, + ReadHeaderTimeout: h.ReadHeaderTimeout.Get(), } inst.cleanup(server.Shutdown) diff --git a/cmd/accumulated/run/instrumentation.go b/cmd/accumulated/run/instrumentation.go index 0988eb106..d18eb2d02 100644 --- a/cmd/accumulated/run/instrumentation.go +++ b/cmd/accumulated/run/instrumentation.go @@ -19,6 +19,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "gitlab.com/accumulatenetwork/accumulate/pkg/errors" + "gitlab.com/accumulatenetwork/accumulate/pkg/types/encoding" ) func (i *Instrumentation) start(inst *Instance) error { @@ -90,10 +91,10 @@ func (m *Monitor) start(inst *Instance) error { m = new(Monitor) } - setDefaultPtr(&m.ProfileMemory, false) // Enabled = false - setDefaultPtr(&m.MemoryPollingRate, time.Minute) // Polling rate = every minute - setDefaultPtr(&m.AllocRateTrigger, 50<<20) // Trigger rate = 50 MiB/s - setDefaultVal(&m.Directory, "traces") // Directory = ./traces + setDefaultPtr(&m.ProfileMemory, false) // Enabled = false + setDefaultPtr(&m.MemoryPollingRate, encoding.Duration(time.Minute)) // Polling rate = every minute + setDefaultPtr(&m.AllocRateTrigger, 50<<20) // Trigger rate = 50 MiB/s + setDefaultVal(&m.Directory, "traces") // Directory = ./traces if *m.ProfileMemory { err := os.MkdirAll(inst.path(m.Directory), 0700) @@ -108,7 +109,7 @@ func (m *Monitor) start(inst *Instance) error { } func (m *Monitor) pollMemory(inst *Instance) { - tick := time.NewTicker(*m.MemoryPollingRate) + tick := time.NewTicker(m.MemoryPollingRate.Get()) inst.cleanup(func(context.Context) error { tick.Stop(); return nil }) var s1, s2 runtime.MemStats diff --git a/cmd/accumulated/run/key.go b/cmd/accumulated/run/key.go index 5578c809e..d99c14227 100644 --- a/cmd/accumulated/run/key.go +++ b/cmd/accumulated/run/key.go @@ -21,13 +21,6 @@ import ( "gitlab.com/accumulatenetwork/accumulate/protocol" ) -type PrivateKey interface { - Type() PrivateKeyType - CopyAsInterface() any - - get(inst *Instance) (address.Address, error) -} - func (k *RawPrivateKey) get(inst *Instance) (address.Address, error) { return address.Parse(k.Address) } diff --git a/cmd/accumulated/run/reference.go b/cmd/accumulated/run/reference.go index 68403600e..c7732eca7 100644 --- a/cmd/accumulated/run/reference.go +++ b/cmd/accumulated/run/reference.go @@ -10,7 +10,6 @@ import ( "encoding/json" "gitlab.com/accumulatenetwork/accumulate/exp/ioc" - "gitlab.com/accumulatenetwork/accumulate/pkg/types/encoding" ) type baseRef[T comparable] struct { @@ -83,7 +82,6 @@ type ServiceOrRef[T serviceType[T]] baseRef[T] type serviceType[T any] interface { Service - encoding.BinaryValue Copy() T Equal(T) bool comparable diff --git a/cmd/accumulated/run/schema.yml b/cmd/accumulated/run/schema.yml new file mode 100644 index 000000000..9596bb14c --- /dev/null +++ b/cmd/accumulated/run/schema.yml @@ -0,0 +1,613 @@ +$generate: + methods: + json: true + + import: + url: gitlab.com/accumulatenetwork/accumulate/pkg/url + record: gitlab.com/accumulatenetwork/accumulate/pkg/types/record + encoding: gitlab.com/accumulatenetwork/accumulate/pkg/types/encoding + + varPrefix: + schema: s + +Config: + class: composite + transients: + - name: file + type: string + marshal-as: none + - name: fs + type: fs.FS + marshal-as: none + fields: + - name: DotEnv + type: '*bool' + - name: Network + type: string + - name: Configurations + type: '[]Configuration' + - name: Services + type: '[]Service' + + - name: P2P + type: + name: P2P + class: composite + pointer: true + fields: + - name: Listen + type: '[]p2p.Multiaddr' + - name: BootstrapPeers + type: '[]p2p.Multiaddr' + - name: Key + type: PrivateKey + - name: PeerDB + type: '*string' + - name: EnablePeerTracking + type: bool + - name: DiscoveryMode + type: '*DhtMode' + - name: External + type: p2p.Multiaddr + + - name: Logging + type: + name: Logging + class: composite + pointer: true + fields: + - name: Format + type: string + - name: Color + type: '*bool' + + - name: Rules + type: + name: LoggingRule + class: composite + pointer: true + repeatable: true + fields: + - name: Level + type: slog.Level + keep-empty: true + - name: Modules + type: '[]string' + + - name: Loki + type: + name: LokiLogging + class: composite + pointer: true + fields: + - name: Enable + type: bool + - name: Url + type: string + - name: Username + type: string + - name: Password + type: string + + - name: Instrumentation + type: + name: Instrumentation + class: composite + pointer: true + fields: + - type: HttpListener + - name: PprofListen + type: p2p.Multiaddr + + - name: Monitoring + type: + name: Monitor + class: composite + pointer: true + fields: + - name: Directory + description: is the directory traces and profiles are written to + type: string + - name: ProfileMemory + description: enables profiling when memory usage increases dramatically + type: '*bool' + - name: MemoryPollingRate + description: is rate at which to poll memory usage + type: '*encoding.Duration' + - name: AllocRateTrigger + description: is the rate of allocation in bytes/second that triggers a profile + type: '*float' + + - name: Telemetry + type: + name: Telemetry + class: composite + pointer: true + fields: + - name: Enabled + type: '*bool' + - name: Stdout + type: '*bool' + - name: Export + type: '*HttpListener' + + - name: Otlp + type: + name: OtlpConfig + class: composite + pointer: true + fields: + - name: Enabled + type: '*bool' + - name: Endpoint + type: string + - name: Username + type: string + - name: Password + type: string + + - name: Rules + type: + name: TelemetryRule + class: composite + pointer: true + repeatable: true + fields: + - name: Match + type: '[]string' + - name: Drop + type: bool + - name: Rate + type: encoding.Duration + +Configuration: + class: union + discriminator: + field: Type + type: + name: ConfigurationType + class: enum + underlying: int + values: + CoreValidator: + value: 1 + Gateway: + value: 2 + Devnet: + value: 3 + + members: + - name: CoreValidatorConfiguration + class: composite + pointer: true + fields: + - name: Mode + type: + name: CoreValidatorMode + class: enum + underlying: int + values: + Dual: + value: 0 + DN: + value: 1 + BVN: + value: 2 + - name: Listen + type: p2p.Multiaddr + - name: BVN + type: string + - name: ValidatorKey + type: PrivateKey + - name: DnGenesis + type: string + - name: BvnGenesis + type: string + - name: DnBootstrapPeers + type: '[]p2p.Multiaddr' + - name: BvnBootstrapPeers + type: '[]p2p.Multiaddr' + - name: EnableHealing + type: '*bool' + optional: true + - name: EnableDirectDispatch + type: '*bool' + optional: true + - name: EnableSnapshots + type: '*bool' + optional: true + - name: MaxEnvelopesPerBlock + type: '*uint' + optional: true + - name: StorageType + type: '*StorageType' + optional: true + + - name: GatewayConfiguration + class: composite + pointer: true + fields: + - name: Listen + type: p2p.Multiaddr + + - name: DevnetConfiguration + class: composite + pointer: true + fields: + - name: Listen + type: p2p.Multiaddr + - name: Bvns + type: uint + - name: Validators + type: uint + - name: Followers + type: uint + optional: true + - name: Globals + type: '*network.GlobalValues' + - name: StorageType + type: '*StorageType' + optional: true + +Service: + class: union + discriminator: + field: Type + type: + name: ServiceType + class: enum + underlying: int + values: + Storage: + value: 1 + Consensus: + value: 2 + Querier: + value: 3 + Network: + value: 4 + Metrics: + value: 5 + Events: + value: 6 + Http: + value: 7 + Router: + value: 8 + Snapshot: + value: 9 + Faucet: + value: 10 + Subnode: + value: 11 + + members: + - name: StorageService + class: composite + pointer: true + fields: + - name: Name + type: string + optional: true + - name: Storage + type: Storage + + - name: ConsensusService + class: composite + pointer: true + fields: + - name: NodeDir + type: string + - name: ValidatorKey + type: PrivateKey + - name: Genesis + type: string + - name: Listen + type: p2p.Multiaddr + - name: BootstrapPeers + type: '[]p2p.Multiaddr' + - name: MetricsNamespace + type: string + optional: true + - name: App + type: + name: ConsensusApp + class: union + discriminator: + field: Type + type: + name: ConsensusAppType + class: enum + underlying: int + values: + Core: + value: 1 + members: + - name: CoreConsensusApp + class: composite + pointer: true + fields: + - name: Partition + type: '*protocol.PartitionInfo' + - name: EnableHealing + type: '*bool' + optional: true + - name: EnableDirectDispatch + type: '*bool' + optional: true + - name: MaxEnvelopesPerBlock + type: '*uint' + optional: true + + + - name: Querier + class: composite + pointer: true + fields: + - name: Partition + type: string + - name: Storage + type: '*StorageOrRef' + optional: true + + - name: NetworkService + class: composite + pointer: true + fields: + - name: Partition + type: string + + - name: MetricsService + class: composite + pointer: true + fields: + - name: Partition + type: string + + - name: EventsService + class: composite + pointer: true + fields: + - name: Partition + type: string + + - name: HttpService + class: composite + pointer: true + fields: + - type: + name: HttpListener + class: composite + fields: + - name: Listen + description: are the addresses and schemes to listen on + type: '[]p2p.Multiaddr' + - name: ConnectionLimit + description: limits the number of concurrent connections + type: '*int' + optional: true + - name: ReadHeaderTimeout + description: protects against slow-loris attacks + type: '*encoding.Duration' + optional: true + - name: TlsCertPath + description: is the path of the TLS certificate + type: string + optional: true + - name: TlsKeyPath + description: is the path of the TLS key + type: string + optional: true + - name: CorsOrigins + description: is a list of allowed CORS origins + type: '[]string' + optional: true + - name: LetsEncrypt + description: automatically retrieves a certificate from Let's Encrypt for the specified domains + type: '[]string' + optional: true + - name: DebugJsonRpc + type: '*bool' + optional: true + - name: Router + type: '*RouterServiceRef' + - name: PeerMap + description: hard-codes the peer map + # type: '[]*HttpPeerMapEntry' + type: + name: HttpPeerMapEntry + class: composite + pointer: true + repeatable: true + fields: + - name: ID + type: p2p.PeerID + - name: Partitions + type: '[]string' + - name: Addresses + type: '[]p2p.Multiaddr' + + - name: RouterService + class: composite + pointer: true + fields: + - name: Name + type: string + optional: true + - name: Events + description: may specify an event bus to use for routing table updates + type: string + optional: true + - name: PeerMap + description: uses a hard-coded peer map for initializing routing + type: '[]*HttpPeerMapEntry' + + - name: SnapshotService + class: composite + pointer: true + fields: + - name: Partition + type: string + - name: Storage + type: '*StorageOrRef' + optional: true + - name: Directory + description: is the directory to store snapshots in + type: string + - name: Schedule + description: is the schedule for capturing snapshots + type: '*network.CronSchedule' + optional: true + - name: RetainCount + description: is the number of snapshots to retain + type: '*uint' + optional: true + - name: EnableIndexing + description: enables indexing of snapshots + type: '*bool' + optional: true + + - name: FaucetService + class: composite + pointer: true + fields: + - name: Account + type: '*url.URL' + - name: SigningKey + type: PrivateKey + - name: Router + type: '*RouterServiceRef' + + - name: SubnodeService + class: composite + pointer: true + fields: + - name: Name + type: string + - name: NodeKey + type: PrivateKey + - name: Services + type: '[]Service' + +Storage: + class: union + discriminator: + field: Type + type: + name: StorageType + class: enum + underlying: int + values: + Memory: + value: 1 + Badger: + value: 2 + Bolt: + value: 3 + LevelDB: + value: 4 + + ExpBlockDB: + value: 1001 + + members: + - name: MemoryStorage + class: composite + pointer: true + fields: [] + + - name: BadgerStorage + class: composite + pointer: true + fields: + - name: Path + type: string + - name: Version + type: int + + - name: BoltStorage + class: composite + pointer: true + fields: + - name: Path + type: string + + - name: LevelDBStorage + class: composite + pointer: true + fields: + - name: Path + type: string + + - name: ExpBlockDBStorage + class: composite + pointer: true + fields: + - name: Path + type: string + +PrivateKey: + class: union + discriminator: + field: Type + type: + name: PrivateKeyType + class: enum + underlying: int + values: + Raw: + value: 1 + Transient: + value: 2 + Seed: + value: 3 + CometPrivValFile: + value: 4 + CometNodeKeyFile: + value: 5 + + members: + - name: RawPrivateKey + class: composite + pointer: true + fields: + - name: Address + type: string + + - name: TransientPrivateKey + class: composite + pointer: true + transients: + - name: key + type: address.Address + + - name: PrivateKeySeed + discriminator: seed + class: composite + pointer: true + fields: + - name: Seed + type: '*record.Key' + transients: + - name: key + type: address.Address + + - name: CometPrivValFile + class: composite + pointer: true + fields: + - name: Path + type: string + transients: + - name: key + type: address.Address + + - name: CometNodeKeyFile + class: composite + pointer: true + fields: + - name: Path + type: string + transients: + - name: key + type: address.Address diff --git a/cmd/accumulated/run/schema_gen.go b/cmd/accumulated/run/schema_gen.go new file mode 100644 index 000000000..4065f94a1 --- /dev/null +++ b/cmd/accumulated/run/schema_gen.go @@ -0,0 +1,1592 @@ +// Code generated by gitlab.com/accumulatenetwork/core/schema. DO NOT EDIT. + +package run + +import ( + "fmt" + "io/fs" + "log/slog" + + "gitlab.com/accumulatenetwork/accumulate/pkg/types/address" + encoding "gitlab.com/accumulatenetwork/accumulate/pkg/types/encoding" + "gitlab.com/accumulatenetwork/accumulate/pkg/types/network" + "gitlab.com/accumulatenetwork/accumulate/pkg/types/p2p" + record "gitlab.com/accumulatenetwork/accumulate/pkg/types/record" + url "gitlab.com/accumulatenetwork/accumulate/pkg/url" + "gitlab.com/accumulatenetwork/accumulate/protocol" + "gitlab.com/accumulatenetwork/core/schema" +) + +var ( + sBadgerStorage schema.Methods[*BadgerStorage, *BadgerStorage, *schema.CompositeType] + sBoltStorage schema.Methods[*BoltStorage, *BoltStorage, *schema.CompositeType] + sCometNodeKeyFile schema.Methods[*CometNodeKeyFile, *CometNodeKeyFile, *schema.CompositeType] + sCometPrivValFile schema.Methods[*CometPrivValFile, *CometPrivValFile, *schema.CompositeType] + sConfig schema.Methods[*Config, *Config, *schema.CompositeType] + sConfiguration schema.UnionMethods[Configuration, ConfigurationType] + sConfigurationType schema.EnumMethods[ConfigurationType] + sConsensusApp schema.UnionMethods[ConsensusApp, ConsensusAppType] + sConsensusAppType schema.EnumMethods[ConsensusAppType] + sConsensusService schema.Methods[*ConsensusService, *ConsensusService, *schema.CompositeType] + sCoreConsensusApp schema.Methods[*CoreConsensusApp, *CoreConsensusApp, *schema.CompositeType] + sCoreValidatorConfiguration schema.Methods[*CoreValidatorConfiguration, *CoreValidatorConfiguration, *schema.CompositeType] + sCoreValidatorMode schema.EnumMethods[CoreValidatorMode] + sDevnetConfiguration schema.Methods[*DevnetConfiguration, *DevnetConfiguration, *schema.CompositeType] + sEventsService schema.Methods[*EventsService, *EventsService, *schema.CompositeType] + sExpBlockDBStorage schema.Methods[*ExpBlockDBStorage, *ExpBlockDBStorage, *schema.CompositeType] + sFaucetService schema.Methods[*FaucetService, *FaucetService, *schema.CompositeType] + sGatewayConfiguration schema.Methods[*GatewayConfiguration, *GatewayConfiguration, *schema.CompositeType] + sHttpListener schema.Methods[*HttpListener, *HttpListener, *schema.CompositeType] + sHttpPeerMapEntry schema.Methods[*HttpPeerMapEntry, *HttpPeerMapEntry, *schema.CompositeType] + sHttpService schema.Methods[*HttpService, *HttpService, *schema.CompositeType] + sInstrumentation schema.Methods[*Instrumentation, *Instrumentation, *schema.CompositeType] + sLevelDBStorage schema.Methods[*LevelDBStorage, *LevelDBStorage, *schema.CompositeType] + sLogging schema.Methods[*Logging, *Logging, *schema.CompositeType] + sLoggingRule schema.Methods[*LoggingRule, *LoggingRule, *schema.CompositeType] + sLokiLogging schema.Methods[*LokiLogging, *LokiLogging, *schema.CompositeType] + sMemoryStorage schema.Methods[*MemoryStorage, *MemoryStorage, *schema.CompositeType] + sMetricsService schema.Methods[*MetricsService, *MetricsService, *schema.CompositeType] + sMonitor schema.Methods[*Monitor, *Monitor, *schema.CompositeType] + sNetworkService schema.Methods[*NetworkService, *NetworkService, *schema.CompositeType] + sOtlpConfig schema.Methods[*OtlpConfig, *OtlpConfig, *schema.CompositeType] + sP2P schema.Methods[*P2P, *P2P, *schema.CompositeType] + sPrivateKey schema.UnionMethods[PrivateKey, PrivateKeyType] + sPrivateKeySeed schema.Methods[*PrivateKeySeed, *PrivateKeySeed, *schema.CompositeType] + sPrivateKeyType schema.EnumMethods[PrivateKeyType] + sQuerier schema.Methods[*Querier, *Querier, *schema.CompositeType] + sRawPrivateKey schema.Methods[*RawPrivateKey, *RawPrivateKey, *schema.CompositeType] + sRouterService schema.Methods[*RouterService, *RouterService, *schema.CompositeType] + sService schema.UnionMethods[Service, ServiceType] + sServiceType schema.EnumMethods[ServiceType] + sSnapshotService schema.Methods[*SnapshotService, *SnapshotService, *schema.CompositeType] + sStorage schema.UnionMethods[Storage, StorageType] + sStorageService schema.Methods[*StorageService, *StorageService, *schema.CompositeType] + sStorageType schema.EnumMethods[StorageType] + sSubnodeService schema.Methods[*SubnodeService, *SubnodeService, *schema.CompositeType] + sTelemetry schema.Methods[*Telemetry, *Telemetry, *schema.CompositeType] + sTelemetryRule schema.Methods[*TelemetryRule, *TelemetryRule, *schema.CompositeType] + sTransientPrivateKey schema.Methods[*TransientPrivateKey, *TransientPrivateKey, *schema.CompositeType] +) + +func init() { + var deferredTypes schema.ResolverSet + + sBadgerStorage = schema.WithMethods[*BadgerStorage, *BadgerStorage](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "BadgerStorage", + }, + Fields: []*schema.Field{ + { + Name: "Path", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "Version", + Type: &schema.SimpleType{Type: schema.SimpleTypeInt}, + }, + }, + }).SetGoType() + + sBoltStorage = schema.WithMethods[*BoltStorage, *BoltStorage](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "BoltStorage", + }, + Fields: []*schema.Field{ + { + Name: "Path", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + }).SetGoType() + + sCometNodeKeyFile = schema.WithMethods[*CometNodeKeyFile, *CometNodeKeyFile](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "CometNodeKeyFile", + }, + Fields: []*schema.Field{ + { + Name: "Path", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + Transients: []*schema.Field{ + { + Name: "key", + Type: schema.TypeReferenceFor[address.Address](), + }, + }, + }).SetGoType() + + sCometPrivValFile = schema.WithMethods[*CometPrivValFile, *CometPrivValFile](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "CometPrivValFile", + }, + Fields: []*schema.Field{ + { + Name: "Path", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + Transients: []*schema.Field{ + { + Name: "key", + Type: schema.TypeReferenceFor[address.Address](), + }, + }, + }).SetGoType() + + sConfig = schema.WithMethods[*Config, *Config](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "Config", + }, + Fields: []*schema.Field{ + { + Name: "DotEnv", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + { + Name: "Network", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "Configurations", + Type: (&schema.ArrayType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "Configuration"), + }, + { + Name: "Services", + Type: (&schema.ArrayType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "Service"), + }, + { + Name: "P2P", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "P2P"), + }, + { + Name: "Logging", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "Logging"), + }, + { + Name: "Instrumentation", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "Instrumentation"), + }, + { + Name: "Telemetry", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "Telemetry"), + }, + }, + Transients: []*schema.Field{ + { + Name: "file", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "fs", + Type: schema.TypeReferenceFor[fs.FS](), + }, + }, + }).SetGoType() + + sConfiguration = schema.WithUnionMethods[Configuration, ConfigurationType]( + &schema.UnionType{ + TypeBase: schema.TypeBase{ + Name: "Configuration", + }, + Discriminator: (&schema.UnionDiscriminator{ + Field: "Type", + }). + ResolveTypeTo(&deferredTypes, "ConfigurationType"). + ResolveEnumTo(&deferredTypes, "ConfigurationType"), + Members: []*schema.UnionMember{ + { + Discriminator: "coreValidator", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "CoreValidatorConfiguration"), + }, + { + Discriminator: "gateway", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "GatewayConfiguration"), + }, + { + Discriminator: "devnet", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "DevnetConfiguration"), + }, + }, + }).SetGoType() + + sConfigurationType = schema.WithEnumMethods[ConfigurationType]( + &schema.EnumType{ + TypeBase: schema.TypeBase{ + Name: "ConfigurationType", + }, + Underlying: &schema.SimpleType{Type: schema.SimpleTypeInt}, + Values: map[string]*schema.EnumValue{ + "CoreValidator": { + Name: "CoreValidator", + Value: 1, + }, + "Devnet": { + Name: "Devnet", + Value: 3, + }, + "Gateway": { + Name: "Gateway", + Value: 2, + }, + }, + }).SetGoType() + + sConsensusApp = schema.WithUnionMethods[ConsensusApp, ConsensusAppType]( + &schema.UnionType{ + TypeBase: schema.TypeBase{ + Name: "ConsensusApp", + }, + Discriminator: (&schema.UnionDiscriminator{ + Field: "Type", + }). + ResolveTypeTo(&deferredTypes, "ConsensusAppType"). + ResolveEnumTo(&deferredTypes, "ConsensusAppType"), + Members: []*schema.UnionMember{ + { + Discriminator: "core", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "CoreConsensusApp"), + }, + }, + }).SetGoType() + + sConsensusAppType = schema.WithEnumMethods[ConsensusAppType]( + &schema.EnumType{ + TypeBase: schema.TypeBase{ + Name: "ConsensusAppType", + }, + Underlying: &schema.SimpleType{Type: schema.SimpleTypeInt}, + Values: map[string]*schema.EnumValue{ + "Core": { + Name: "Core", + Value: 1, + }, + }, + }).SetGoType() + + sConsensusService = schema.WithMethods[*ConsensusService, *ConsensusService](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "ConsensusService", + }, + Fields: []*schema.Field{ + { + Name: "NodeDir", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + (&schema.Field{ + Name: "ValidatorKey", + }).ResolveTo(&deferredTypes, "PrivateKey"), + { + Name: "Genesis", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "Listen", + Type: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + { + Name: "BootstrapPeers", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + }, + { + Name: "MetricsNamespace", + Optional: true, + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + (&schema.Field{ + Name: "App", + }).ResolveTo(&deferredTypes, "ConsensusApp"), + }, + }).SetGoType() + + sCoreConsensusApp = schema.WithMethods[*CoreConsensusApp, *CoreConsensusApp](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "CoreConsensusApp", + }, + Fields: []*schema.Field{ + { + Name: "Partition", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[protocol.PartitionInfo](), + }, + }, + { + Name: "EnableHealing", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + { + Name: "EnableDirectDispatch", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + { + Name: "MaxEnvelopesPerBlock", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeUint}, + }, + }, + }, + }).SetGoType() + + sCoreValidatorConfiguration = schema.WithMethods[*CoreValidatorConfiguration, *CoreValidatorConfiguration](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "CoreValidatorConfiguration", + }, + Fields: []*schema.Field{ + (&schema.Field{ + Name: "Mode", + }).ResolveTo(&deferredTypes, "CoreValidatorMode"), + { + Name: "Listen", + Type: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + { + Name: "BVN", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + (&schema.Field{ + Name: "ValidatorKey", + }).ResolveTo(&deferredTypes, "PrivateKey"), + { + Name: "DnGenesis", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "BvnGenesis", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "DnBootstrapPeers", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + }, + { + Name: "BvnBootstrapPeers", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + }, + { + Name: "EnableHealing", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + { + Name: "EnableDirectDispatch", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + { + Name: "EnableSnapshots", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + { + Name: "MaxEnvelopesPerBlock", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeUint}, + }, + }, + { + Name: "StorageType", + Optional: true, + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "StorageType"), + }, + }, + }).SetGoType() + + sCoreValidatorMode = schema.WithEnumMethods[CoreValidatorMode]( + &schema.EnumType{ + TypeBase: schema.TypeBase{ + Name: "CoreValidatorMode", + }, + Underlying: &schema.SimpleType{Type: schema.SimpleTypeInt}, + Values: map[string]*schema.EnumValue{ + "BVN": { + Name: "BVN", + Value: 2, + }, + "DN": { + Name: "DN", + Value: 1, + }, + "Dual": { + Name: "Dual", + Value: 0, + }, + }, + }).SetGoType() + + sDevnetConfiguration = schema.WithMethods[*DevnetConfiguration, *DevnetConfiguration](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "DevnetConfiguration", + }, + Fields: []*schema.Field{ + { + Name: "Listen", + Type: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + { + Name: "Bvns", + Type: &schema.SimpleType{Type: schema.SimpleTypeUint}, + }, + { + Name: "Validators", + Type: &schema.SimpleType{Type: schema.SimpleTypeUint}, + }, + { + Name: "Followers", + Optional: true, + Type: &schema.SimpleType{Type: schema.SimpleTypeUint}, + }, + { + Name: "Globals", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[network.GlobalValues](), + }, + }, + { + Name: "StorageType", + Optional: true, + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "StorageType"), + }, + }, + }).SetGoType() + + sEventsService = schema.WithMethods[*EventsService, *EventsService](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "EventsService", + }, + Fields: []*schema.Field{ + { + Name: "Partition", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + }).SetGoType() + + sExpBlockDBStorage = schema.WithMethods[*ExpBlockDBStorage, *ExpBlockDBStorage](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "ExpBlockDBStorage", + }, + Fields: []*schema.Field{ + { + Name: "Path", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + }).SetGoType() + + sFaucetService = schema.WithMethods[*FaucetService, *FaucetService](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "FaucetService", + }, + Fields: []*schema.Field{ + { + Name: "Account", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[url.URL](), + }, + }, + (&schema.Field{ + Name: "SigningKey", + }).ResolveTo(&deferredTypes, "PrivateKey"), + { + Name: "Router", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[RouterServiceRef](), + }, + }, + }, + }).SetGoType() + + sGatewayConfiguration = schema.WithMethods[*GatewayConfiguration, *GatewayConfiguration](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "GatewayConfiguration", + }, + Fields: []*schema.Field{ + { + Name: "Listen", + Type: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + }, + }).SetGoType() + + sHttpListener = schema.WithMethods[*HttpListener, *HttpListener](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "HttpListener", + }, + Fields: []*schema.Field{ + { + Name: "Listen", + Description: "are the addresses and schemes to listen on", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + }, + { + Name: "ConnectionLimit", + Description: "limits the number of concurrent connections", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeInt}, + }, + }, + { + Name: "ReadHeaderTimeout", + Description: "protects against slow-loris attacks", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[encoding.Duration](), + }, + }, + { + Name: "TlsCertPath", + Description: "is the path of the TLS certificate", + Optional: true, + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "TlsKeyPath", + Description: "is the path of the TLS key", + Optional: true, + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + }).SetGoType() + + sHttpPeerMapEntry = schema.WithMethods[*HttpPeerMapEntry, *HttpPeerMapEntry](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "HttpPeerMapEntry", + }, + Fields: []*schema.Field{ + { + Name: "ID", + Type: schema.TypeReferenceFor[p2p.PeerID](), + }, + { + Name: "Partitions", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + { + Name: "Addresses", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + }, + }, + }).SetGoType() + + sHttpService = schema.WithMethods[*HttpService, *HttpService](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "HttpService", + }, + Fields: []*schema.Field{ + (&schema.Field{}).ResolveTo(&deferredTypes, "HttpListener"), + { + Name: "CorsOrigins", + Description: "is a list of allowed CORS origins", + Optional: true, + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + { + Name: "LetsEncrypt", + Description: "automatically retrieves a certificate from Let's Encrypt for the specified domains", + Optional: true, + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + { + Name: "DebugJsonRpc", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + { + Name: "Router", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[RouterServiceRef](), + }, + }, + { + Name: "PeerMap", + Description: "hard-codes the peer map", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "HttpPeerMapEntry"), + }, + }, + }, + }).SetGoType() + + sInstrumentation = schema.WithMethods[*Instrumentation, *Instrumentation](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "Instrumentation", + }, + Fields: []*schema.Field{ + (&schema.Field{}).ResolveTo(&deferredTypes, "HttpListener"), + { + Name: "PprofListen", + Type: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + { + Name: "Monitoring", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "Monitor"), + }, + }, + }).SetGoType() + + sLevelDBStorage = schema.WithMethods[*LevelDBStorage, *LevelDBStorage](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "LevelDBStorage", + }, + Fields: []*schema.Field{ + { + Name: "Path", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + }).SetGoType() + + sLogging = schema.WithMethods[*Logging, *Logging](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "Logging", + }, + Fields: []*schema.Field{ + { + Name: "Format", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "Color", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + { + Name: "Rules", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "LoggingRule"), + }, + }, + { + Name: "Loki", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "LokiLogging"), + }, + }, + }).SetGoType() + + sLoggingRule = schema.WithMethods[*LoggingRule, *LoggingRule](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "LoggingRule", + }, + Fields: []*schema.Field{ + { + Name: "Level", + Type: schema.TypeReferenceFor[slog.Level](), + }, + { + Name: "Modules", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + }, + }).SetGoType() + + sLokiLogging = schema.WithMethods[*LokiLogging, *LokiLogging](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "LokiLogging", + }, + Fields: []*schema.Field{ + { + Name: "Enable", + Type: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + { + Name: "Url", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "Username", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "Password", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + }).SetGoType() + + sMemoryStorage = schema.WithMethods[*MemoryStorage, *MemoryStorage](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "MemoryStorage", + }, + }).SetGoType() + + sMetricsService = schema.WithMethods[*MetricsService, *MetricsService](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "MetricsService", + }, + Fields: []*schema.Field{ + { + Name: "Partition", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + }).SetGoType() + + sMonitor = schema.WithMethods[*Monitor, *Monitor](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "Monitor", + }, + Fields: []*schema.Field{ + { + Name: "Directory", + Description: "is the directory traces and profiles are written to", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "ProfileMemory", + Description: "enables profiling when memory usage increases dramatically", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + { + Name: "MemoryPollingRate", + Description: "is rate at which to poll memory usage", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[encoding.Duration](), + }, + }, + { + Name: "AllocRateTrigger", + Description: "is the rate of allocation in bytes/second that triggers a profile", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeFloat}, + }, + }, + }, + }).SetGoType() + + sNetworkService = schema.WithMethods[*NetworkService, *NetworkService](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "NetworkService", + }, + Fields: []*schema.Field{ + { + Name: "Partition", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + }).SetGoType() + + sOtlpConfig = schema.WithMethods[*OtlpConfig, *OtlpConfig](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "OtlpConfig", + }, + Fields: []*schema.Field{ + { + Name: "Enabled", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + { + Name: "Endpoint", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "Username", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "Password", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + }).SetGoType() + + sP2P = schema.WithMethods[*P2P, *P2P](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "P2P", + }, + Fields: []*schema.Field{ + { + Name: "Listen", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + }, + { + Name: "BootstrapPeers", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + }, + (&schema.Field{ + Name: "Key", + }).ResolveTo(&deferredTypes, "PrivateKey"), + { + Name: "PeerDB", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + { + Name: "EnablePeerTracking", + Type: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + { + Name: "DiscoveryMode", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[DhtMode](), + }, + }, + { + Name: "External", + Type: schema.TypeReferenceFor[p2p.Multiaddr](), + }, + }, + }).SetGoType() + + sPrivateKey = schema.WithUnionMethods[PrivateKey, PrivateKeyType]( + &schema.UnionType{ + TypeBase: schema.TypeBase{ + Name: "PrivateKey", + }, + Discriminator: (&schema.UnionDiscriminator{ + Field: "Type", + }). + ResolveTypeTo(&deferredTypes, "PrivateKeyType"). + ResolveEnumTo(&deferredTypes, "PrivateKeyType"), + Members: []*schema.UnionMember{ + { + Discriminator: "raw", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "RawPrivateKey"), + }, + { + Discriminator: "transient", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "TransientPrivateKey"), + }, + { + Discriminator: "seed", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "PrivateKeySeed"), + }, + { + Discriminator: "cometPrivValFile", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "CometPrivValFile"), + }, + { + Discriminator: "cometNodeKeyFile", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "CometNodeKeyFile"), + }, + }, + }).SetGoType() + + sPrivateKeySeed = schema.WithMethods[*PrivateKeySeed, *PrivateKeySeed](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "PrivateKeySeed", + }, + Fields: []*schema.Field{ + { + Name: "Seed", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[record.Key](), + }, + }, + }, + Transients: []*schema.Field{ + { + Name: "key", + Type: schema.TypeReferenceFor[address.Address](), + }, + }, + }).SetGoType() + + sPrivateKeyType = schema.WithEnumMethods[PrivateKeyType]( + &schema.EnumType{ + TypeBase: schema.TypeBase{ + Name: "PrivateKeyType", + }, + Underlying: &schema.SimpleType{Type: schema.SimpleTypeInt}, + Values: map[string]*schema.EnumValue{ + "CometNodeKeyFile": { + Name: "CometNodeKeyFile", + Value: 5, + }, + "CometPrivValFile": { + Name: "CometPrivValFile", + Value: 4, + }, + "Raw": { + Name: "Raw", + Value: 1, + }, + "Seed": { + Name: "Seed", + Value: 3, + }, + "Transient": { + Name: "Transient", + Value: 2, + }, + }, + }).SetGoType() + + sQuerier = schema.WithMethods[*Querier, *Querier](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "Querier", + }, + Fields: []*schema.Field{ + { + Name: "Partition", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "Storage", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[StorageOrRef](), + }, + }, + }, + }).SetGoType() + + sRawPrivateKey = schema.WithMethods[*RawPrivateKey, *RawPrivateKey](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "RawPrivateKey", + }, + Fields: []*schema.Field{ + { + Name: "Address", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + }).SetGoType() + + sRouterService = schema.WithMethods[*RouterService, *RouterService](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "RouterService", + }, + Fields: []*schema.Field{ + { + Name: "Name", + Optional: true, + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "Events", + Description: "may specify an event bus to use for routing table updates", + Optional: true, + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "PeerMap", + Description: "uses a hard-coded peer map for initializing routing", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "HttpPeerMapEntry"), + }, + }, + }, + }).SetGoType() + + sService = schema.WithUnionMethods[Service, ServiceType]( + &schema.UnionType{ + TypeBase: schema.TypeBase{ + Name: "Service", + }, + Discriminator: (&schema.UnionDiscriminator{ + Field: "Type", + }). + ResolveTypeTo(&deferredTypes, "ServiceType"). + ResolveEnumTo(&deferredTypes, "ServiceType"), + Members: []*schema.UnionMember{ + { + Discriminator: "storage", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "StorageService"), + }, + { + Discriminator: "consensus", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "ConsensusService"), + }, + { + Discriminator: "querier", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "Querier"), + }, + { + Discriminator: "network", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "NetworkService"), + }, + { + Discriminator: "metrics", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "MetricsService"), + }, + { + Discriminator: "events", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "EventsService"), + }, + { + Discriminator: "http", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "HttpService"), + }, + { + Discriminator: "router", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "RouterService"), + }, + { + Discriminator: "snapshot", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "SnapshotService"), + }, + { + Discriminator: "faucet", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "FaucetService"), + }, + { + Discriminator: "subnode", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "SubnodeService"), + }, + }, + }).SetGoType() + + sServiceType = schema.WithEnumMethods[ServiceType]( + &schema.EnumType{ + TypeBase: schema.TypeBase{ + Name: "ServiceType", + }, + Underlying: &schema.SimpleType{Type: schema.SimpleTypeInt}, + Values: map[string]*schema.EnumValue{ + "Consensus": { + Name: "Consensus", + Value: 2, + }, + "Events": { + Name: "Events", + Value: 6, + }, + "Faucet": { + Name: "Faucet", + Value: 10, + }, + "Http": { + Name: "Http", + Value: 7, + }, + "Metrics": { + Name: "Metrics", + Value: 5, + }, + "Network": { + Name: "Network", + Value: 4, + }, + "Querier": { + Name: "Querier", + Value: 3, + }, + "Router": { + Name: "Router", + Value: 8, + }, + "Snapshot": { + Name: "Snapshot", + Value: 9, + }, + "Storage": { + Name: "Storage", + Value: 1, + }, + "Subnode": { + Name: "Subnode", + Value: 11, + }, + }, + }).SetGoType() + + sSnapshotService = schema.WithMethods[*SnapshotService, *SnapshotService](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "SnapshotService", + }, + Fields: []*schema.Field{ + { + Name: "Partition", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "Storage", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[StorageOrRef](), + }, + }, + { + Name: "Directory", + Description: "is the directory to store snapshots in", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + { + Name: "Schedule", + Description: "is the schedule for capturing snapshots", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: schema.TypeReferenceFor[network.CronSchedule](), + }, + }, + { + Name: "RetainCount", + Description: "is the number of snapshots to retain", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeUint}, + }, + }, + { + Name: "EnableIndexing", + Description: "enables indexing of snapshots", + Optional: true, + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + }, + }).SetGoType() + + sStorage = schema.WithUnionMethods[Storage, StorageType]( + &schema.UnionType{ + TypeBase: schema.TypeBase{ + Name: "Storage", + }, + Discriminator: (&schema.UnionDiscriminator{ + Field: "Type", + }). + ResolveTypeTo(&deferredTypes, "StorageType"). + ResolveEnumTo(&deferredTypes, "StorageType"), + Members: []*schema.UnionMember{ + { + Discriminator: "memory", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "MemoryStorage"), + }, + { + Discriminator: "badger", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "BadgerStorage"), + }, + { + Discriminator: "bolt", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "BoltStorage"), + }, + { + Discriminator: "levelDB", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "LevelDBStorage"), + }, + { + Discriminator: "expBlockDB", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "ExpBlockDBStorage"), + }, + }, + }).SetGoType() + + sStorageService = schema.WithMethods[*StorageService, *StorageService](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "StorageService", + }, + Fields: []*schema.Field{ + { + Name: "Name", + Optional: true, + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + (&schema.Field{ + Name: "Storage", + }).ResolveTo(&deferredTypes, "Storage"), + }, + }).SetGoType() + + sStorageType = schema.WithEnumMethods[StorageType]( + &schema.EnumType{ + TypeBase: schema.TypeBase{ + Name: "StorageType", + }, + Underlying: &schema.SimpleType{Type: schema.SimpleTypeInt}, + Values: map[string]*schema.EnumValue{ + "Badger": { + Name: "Badger", + Value: 2, + }, + "Bolt": { + Name: "Bolt", + Value: 3, + }, + "ExpBlockDB": { + Name: "ExpBlockDB", + Value: 1001, + }, + "LevelDB": { + Name: "LevelDB", + Value: 4, + }, + "Memory": { + Name: "Memory", + Value: 1, + }, + }, + }).SetGoType() + + sSubnodeService = schema.WithMethods[*SubnodeService, *SubnodeService](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "SubnodeService", + }, + Fields: []*schema.Field{ + { + Name: "Name", + Type: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + (&schema.Field{ + Name: "NodeKey", + }).ResolveTo(&deferredTypes, "PrivateKey"), + { + Name: "Services", + Type: (&schema.ArrayType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "Service"), + }, + }, + }).SetGoType() + + sTelemetry = schema.WithMethods[*Telemetry, *Telemetry](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "Telemetry", + }, + Fields: []*schema.Field{ + { + Name: "Enabled", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + { + Name: "Stdout", + Type: &schema.PointerType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + }, + { + Name: "Export", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "HttpListener"), + }, + { + Name: "Otlp", + Type: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "OtlpConfig"), + }, + { + Name: "Rules", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: (&schema.PointerType{ + TypeBase: schema.TypeBase{}, + }). + ResolveElemTo(&deferredTypes, "TelemetryRule"), + }, + }, + }, + }).SetGoType() + + sTelemetryRule = schema.WithMethods[*TelemetryRule, *TelemetryRule](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "TelemetryRule", + }, + Fields: []*schema.Field{ + { + Name: "Match", + Type: &schema.ArrayType{ + TypeBase: schema.TypeBase{}, + Elem: &schema.SimpleType{Type: schema.SimpleTypeString}, + }, + }, + { + Name: "Drop", + Type: &schema.SimpleType{Type: schema.SimpleTypeBool}, + }, + { + Name: "Rate", + Type: schema.TypeReferenceFor[encoding.Duration](), + }, + }, + }).SetGoType() + + sTransientPrivateKey = schema.WithMethods[*TransientPrivateKey, *TransientPrivateKey](&schema.CompositeType{ + TypeBase: schema.TypeBase{ + Name: "TransientPrivateKey", + }, + Transients: []*schema.Field{ + { + Name: "key", + Type: schema.TypeReferenceFor[address.Address](), + }, + }, + }).SetGoType() + + s, err := schema.New( + sBadgerStorage.Type, + sBoltStorage.Type, + sCometNodeKeyFile.Type, + sCometPrivValFile.Type, + sConfig.Type, + sConfiguration.Type, + sConfigurationType.Type, + sConsensusApp.Type, + sConsensusAppType.Type, + sConsensusService.Type, + sCoreConsensusApp.Type, + sCoreValidatorConfiguration.Type, + sCoreValidatorMode.Type, + sDevnetConfiguration.Type, + sEventsService.Type, + sExpBlockDBStorage.Type, + sFaucetService.Type, + sGatewayConfiguration.Type, + sHttpListener.Type, + sHttpPeerMapEntry.Type, + sHttpService.Type, + sInstrumentation.Type, + sLevelDBStorage.Type, + sLogging.Type, + sLoggingRule.Type, + sLokiLogging.Type, + sMemoryStorage.Type, + sMetricsService.Type, + sMonitor.Type, + sNetworkService.Type, + sOtlpConfig.Type, + sP2P.Type, + sPrivateKey.Type, + sPrivateKeySeed.Type, + sPrivateKeyType.Type, + sQuerier.Type, + sRawPrivateKey.Type, + sRouterService.Type, + sService.Type, + sServiceType.Type, + sSnapshotService.Type, + sStorage.Type, + sStorageService.Type, + sStorageType.Type, + sSubnodeService.Type, + sTelemetry.Type, + sTelemetryRule.Type, + sTransientPrivateKey.Type, + ) + if err != nil { + panic(fmt.Errorf("invalid embedded schema: %w", err)) + } + + s.Generate = schema.MapValue{ + "import": schema.MapValue{ + "encoding": schema.StringValue("gitlab.com/accumulatenetwork/accumulate/pkg/types/encoding"), + "record": schema.StringValue("gitlab.com/accumulatenetwork/accumulate/pkg/types/record"), + "url": schema.StringValue("gitlab.com/accumulatenetwork/accumulate/pkg/url"), + }, + "methods": schema.MapValue{ + "json": schema.BooleanValue(true), + }, + "varPrefix": schema.MapValue{ + "schema": schema.StringValue("s"), + }, + } + + deferredTypes.Resolve(s) + err = s.Validate() + if err != nil { + panic(fmt.Errorf("invalid embedded schema: %w", err)) + } +} diff --git a/cmd/accumulated/run/storage.go b/cmd/accumulated/run/storage.go index cb7b74466..00cce75a0 100644 --- a/cmd/accumulated/run/storage.go +++ b/cmd/accumulated/run/storage.go @@ -39,14 +39,6 @@ func (s *StorageService) start(inst *Instance) error { return storageProvides.Register(inst.services, s, store) } -type Storage interface { - Type() StorageType - CopyAsInterface() any - - setPath(path string) - open(*Instance) (keyvalue.Beginner, error) -} - func (s *BadgerStorage) setPath(path string) { s.Path = path } func (s *BoltStorage) setPath(path string) { s.Path = path } func (s *ExpBlockDBStorage) setPath(path string) { s.Path = path } diff --git a/cmd/accumulated/run/telemetry.go b/cmd/accumulated/run/telemetry.go index 10186d886..366cd7957 100644 --- a/cmd/accumulated/run/telemetry.go +++ b/cmd/accumulated/run/telemetry.go @@ -38,7 +38,10 @@ import ( ) func (t *Telemetry) start(inst *Instance) error { - if !setDefaultPtr(&t.Enabled, true) { + setDefaultPtr(&t.Enabled, true) + setDefaultPtr(&t.Stdout, false) + + if !*t.Enabled { return nil } @@ -83,6 +86,9 @@ func (t *Telemetry) setupPropagator(*resource.Resource, *Instance) error { } func (t *Telemetry) setupTraceProvider(res *resource.Resource, inst *Instance) error { + if !*t.Stdout { + return nil + } exporter, err := stdouttrace.New( stdouttrace.WithPrettyPrint()) if err != nil { @@ -130,7 +136,7 @@ func (t *Telemetry) setupMeterProvider(res *resource.Resource, inst *Instance) e } var exporters []metric.Exporter - if setDefaultPtr(&t.Stdout, false) { + if *t.Stdout { exporter, err := stdoutmetric.New() if err != nil { return err @@ -164,7 +170,7 @@ func (t *Telemetry) setupMeterProvider(res *resource.Resource, inst *Instance) e defaultRule = new(TelemetryRule) } if !defaultRule.Drop && defaultRule.Rate == 0 { - defaultRule.Rate = time.Minute + defaultRule.Rate.Set(time.Minute) } var drop []func(string) bool @@ -190,7 +196,7 @@ func (t *Telemetry) setupMeterProvider(res *resource.Resource, inst *Instance) e return err } rateFilters = append(rateFilters, f) - rates = append(rates, r.Rate) + rates = append(rates, r.Rate.Get()) } for _, exporter := range exporters { @@ -217,7 +223,7 @@ func (t *Telemetry) setupMeterProvider(res *resource.Resource, inst *Instance) e metric.WithReader( metric.NewPeriodicReader(&filterExporter{Exporter: exporter, match: match}, metric.WithProducer(otelProm), - metric.WithInterval(defaultRule.Rate)))) + metric.WithInterval(defaultRule.Rate.Get())))) } for i, rate := range rates { @@ -252,6 +258,9 @@ func (t *Telemetry) setupMeterProvider(res *resource.Resource, inst *Instance) e } func (t *Telemetry) setupLoggerProvider(res *resource.Resource, inst *Instance) error { + if !*t.Stdout { + return nil + } exporter, err := stdoutlog.New() if err != nil { return err diff --git a/cmd/accumulated/run/types.go b/cmd/accumulated/run/types.go index 5946b6014..f3b86d802 100644 --- a/cmd/accumulated/run/types.go +++ b/cmd/accumulated/run/types.go @@ -7,30 +7,20 @@ package run import ( + types "github.com/cometbft/cometbft/abci/types" + tmnode "github.com/cometbft/cometbft/node" "gitlab.com/accumulatenetwork/accumulate/exp/ioc" + "gitlab.com/accumulatenetwork/accumulate/pkg/database/keyvalue" + "gitlab.com/accumulatenetwork/accumulate/pkg/types/address" + "gitlab.com/accumulatenetwork/accumulate/protocol" ) -//go:generate go run gitlab.com/accumulatenetwork/accumulate/tools/cmd/gen-enum --package run enums.yml -//go:generate go run gitlab.com/accumulatenetwork/accumulate/tools/cmd/gen-types --package run config.yml -//go:generate go run gitlab.com/accumulatenetwork/accumulate/tools/cmd/gen-types --package run --language go-union --out unions_gen.go config.yml - -type ( - ConfigurationType int - ServiceType int - StorageType int - PrivateKeyType int - ConsensusAppType int - CoreValidatorMode int -) - -type Service interface { - ioc.Factory +//go:generate go run gitlab.com/accumulatenetwork/core/schema/cmd/generate schema schema.yml -w schema_gen.go +//go:generate go run gitlab.com/accumulatenetwork/core/schema/cmd/generate types schema.yml -w types_gen.go +//go:generate go run github.com/rinchsan/gosimports/cmd/gosimports -w . - Type() ServiceType - CopyAsInterface() any - - start(inst *Instance) error -} +// TODO: Remove (once schema supports it) +type RouterServiceRef = ServiceOrRef[*RouterService] type resetable interface { reset(inst *Instance) error @@ -42,7 +32,32 @@ type prestarter interface { type Configuration interface { Type() ConfigurationType - CopyAsInterface() any - apply(inst *Instance, cfg *Config) error } + +type Service interface { + ioc.Factory + Type() ServiceType + start(inst *Instance) error +} + +type Storage interface { + Type() StorageType + setPath(path string) + open(*Instance) (keyvalue.Beginner, error) +} + +type PrivateKey interface { + Type() PrivateKeyType + get(inst *Instance) (address.Address, error) +} + +type ConsensusApp interface { + Type() ConsensusAppType + partition() *protocol.PartitionInfo + Requires() []ioc.Requirement + Provides() []ioc.Provided + prestart(*Instance) error + start(*Instance, *tendermint) (types.Application, error) + register(*Instance, *tendermint, *tmnode.Node) error +} diff --git a/cmd/accumulated/run/types_gen.go b/cmd/accumulated/run/types_gen.go index 19269cd46..4256ff449 100644 --- a/cmd/accumulated/run/types_gen.go +++ b/cmd/accumulated/run/types_gen.go @@ -1,3836 +1,1376 @@ -// Copyright 2022 The Accumulate Authors -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT. +// Code generated by gitlab.com/accumulatenetwork/core/schema. DO NOT EDIT. package run -// GENERATED BY go run ./tools/cmd/gen-types. DO NOT EDIT. - -//lint:file-ignore S1001,S1002,S1008,SA4013 generated code - import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io" "io/fs" "log/slog" - "strings" - "time" "gitlab.com/accumulatenetwork/accumulate/pkg/types/address" - "gitlab.com/accumulatenetwork/accumulate/pkg/types/encoding" + encoding "gitlab.com/accumulatenetwork/accumulate/pkg/types/encoding" "gitlab.com/accumulatenetwork/accumulate/pkg/types/network" "gitlab.com/accumulatenetwork/accumulate/pkg/types/p2p" - "gitlab.com/accumulatenetwork/accumulate/pkg/types/record" - "gitlab.com/accumulatenetwork/accumulate/pkg/url" + record "gitlab.com/accumulatenetwork/accumulate/pkg/types/record" + url "gitlab.com/accumulatenetwork/accumulate/pkg/url" "gitlab.com/accumulatenetwork/accumulate/protocol" ) type BadgerStorage struct { - Path string `json:"path,omitempty" form:"path" query:"path" validate:"required"` - Version int64 `json:"version,omitempty" form:"version" query:"version" validate:"required"` + Path string + Version int64 } -type BoltStorage struct { - Path string `json:"path,omitempty" form:"path" query:"path" validate:"required"` -} +func (BadgerStorage) Type() StorageType { return StorageTypeBadger } -type CometNodeKeyFile struct { - key address.Address - Path string `json:"path,omitempty" form:"path" query:"path" validate:"required"` +// Copy returns a copy of the BadgerStorage. +func (v *BadgerStorage) Copy() *BadgerStorage { + return sBadgerStorage.Copy(v) } -type CometPrivValFile struct { - key address.Address - Path string `json:"path,omitempty" form:"path" query:"path" validate:"required"` +// EqualBadgerStorage returns true if V is equal to U. +func (v *BadgerStorage) Equal(u *BadgerStorage) bool { + return sBadgerStorage.Equal(v, u) } -type Config struct { - file string - fs fs.FS - DotEnv *bool `json:"dotEnv,omitempty" form:"dotEnv" query:"dotEnv" validate:"required"` - Network string `json:"network,omitempty" form:"network" query:"network" validate:"required"` - Logging *Logging `json:"logging,omitempty" form:"logging" query:"logging" validate:"required"` - Instrumentation *Instrumentation `json:"instrumentation,omitempty" form:"instrumentation" query:"instrumentation" validate:"required"` - Telemetry *Telemetry `json:"telemetry,omitempty" form:"telemetry" query:"telemetry" validate:"required"` - P2P *P2P `json:"p2P,omitempty" form:"p2P" query:"p2P" validate:"required"` - Configurations []Configuration `json:"configurations,omitempty" form:"configurations" query:"configurations" validate:"required"` - Services []Service `json:"services,omitempty" form:"services" query:"services" validate:"required"` +// MarshalBinary marshals the BadgerStorage to JSON. +func (v *BadgerStorage) MarshalJSON() ([]byte, error) { + return sBadgerStorage.MarshalJSON(v) } -type ConsensusService struct { - NodeDir string `json:"nodeDir,omitempty" form:"nodeDir" query:"nodeDir" validate:"required"` - ValidatorKey PrivateKey `json:"validatorKey,omitempty" form:"validatorKey" query:"validatorKey" validate:"required"` - Genesis string `json:"genesis,omitempty" form:"genesis" query:"genesis" validate:"required"` - Listen p2p.Multiaddr `json:"listen,omitempty" form:"listen" query:"listen" validate:"required"` - BootstrapPeers []p2p.Multiaddr `json:"bootstrapPeers,omitempty" form:"bootstrapPeers" query:"bootstrapPeers" validate:"required"` - MetricsNamespace string `json:"metricsNamespace,omitempty" form:"metricsNamespace" query:"metricsNamespace"` - App ConsensusApp `json:"app,omitempty" form:"app" query:"app" validate:"required"` +// UnmarshalJSON unmarshals the BadgerStorage from JSON. +func (v *BadgerStorage) UnmarshalJSON(b []byte) error { + return sBadgerStorage.UnmarshalJSON(b, v) } -type CoreConsensusApp struct { - Partition *protocol.PartitionInfo `json:"partition,omitempty" form:"partition" query:"partition" validate:"required"` - EnableHealing *bool `json:"enableHealing,omitempty" form:"enableHealing" query:"enableHealing"` - EnableDirectDispatch *bool `json:"enableDirectDispatch,omitempty" form:"enableDirectDispatch" query:"enableDirectDispatch"` - MaxEnvelopesPerBlock *uint64 `json:"maxEnvelopesPerBlock,omitempty" form:"maxEnvelopesPerBlock" query:"maxEnvelopesPerBlock"` +type BoltStorage struct { + Path string } -type CoreValidatorConfiguration struct { - Mode CoreValidatorMode `json:"mode,omitempty" form:"mode" query:"mode" validate:"required"` - Listen p2p.Multiaddr `json:"listen,omitempty" form:"listen" query:"listen" validate:"required"` - BVN string `json:"bvn,omitempty" form:"bvn" query:"bvn" validate:"required"` - ValidatorKey PrivateKey `json:"validatorKey,omitempty" form:"validatorKey" query:"validatorKey" validate:"required"` - DnGenesis string `json:"dnGenesis,omitempty" form:"dnGenesis" query:"dnGenesis" validate:"required"` - BvnGenesis string `json:"bvnGenesis,omitempty" form:"bvnGenesis" query:"bvnGenesis" validate:"required"` - DnBootstrapPeers []p2p.Multiaddr `json:"dnBootstrapPeers,omitempty" form:"dnBootstrapPeers" query:"dnBootstrapPeers" validate:"required"` - BvnBootstrapPeers []p2p.Multiaddr `json:"bvnBootstrapPeers,omitempty" form:"bvnBootstrapPeers" query:"bvnBootstrapPeers" validate:"required"` - EnableHealing *bool `json:"enableHealing,omitempty" form:"enableHealing" query:"enableHealing"` - EnableDirectDispatch *bool `json:"enableDirectDispatch,omitempty" form:"enableDirectDispatch" query:"enableDirectDispatch"` - EnableSnapshots *bool `json:"enableSnapshots,omitempty" form:"enableSnapshots" query:"enableSnapshots"` - MaxEnvelopesPerBlock *uint64 `json:"maxEnvelopesPerBlock,omitempty" form:"maxEnvelopesPerBlock" query:"maxEnvelopesPerBlock"` - StorageType *StorageType `json:"storageType,omitempty" form:"storageType" query:"storageType"` -} +func (BoltStorage) Type() StorageType { return StorageTypeBolt } -type DevnetConfiguration struct { - Listen p2p.Multiaddr `json:"listen,omitempty" form:"listen" query:"listen" validate:"required"` - Bvns uint64 `json:"bvns,omitempty" form:"bvns" query:"bvns" validate:"required"` - Validators uint64 `json:"validators,omitempty" form:"validators" query:"validators" validate:"required"` - Followers uint64 `json:"followers,omitempty" form:"followers" query:"followers"` - Globals *network.GlobalValues `json:"globals,omitempty" form:"globals" query:"globals" validate:"required"` - StorageType *StorageType `json:"storageType,omitempty" form:"storageType" query:"storageType"` +// Copy returns a copy of the BoltStorage. +func (v *BoltStorage) Copy() *BoltStorage { + return sBoltStorage.Copy(v) } -type EventsService struct { - Partition string `json:"partition,omitempty" form:"partition" query:"partition" validate:"required"` +// EqualBoltStorage returns true if V is equal to U. +func (v *BoltStorage) Equal(u *BoltStorage) bool { + return sBoltStorage.Equal(v, u) } -type ExpBlockDBStorage struct { - Path string `json:"path,omitempty" form:"path" query:"path" validate:"required"` +// MarshalBinary marshals the BoltStorage to JSON. +func (v *BoltStorage) MarshalJSON() ([]byte, error) { + return sBoltStorage.MarshalJSON(v) } -type FaucetService struct { - Account *url.URL `json:"account,omitempty" form:"account" query:"account" validate:"required"` - SigningKey PrivateKey `json:"signingKey,omitempty" form:"signingKey" query:"signingKey" validate:"required"` - Router *ServiceOrRef[*RouterService] `json:"router,omitempty" form:"router" query:"router" validate:"required"` +// UnmarshalJSON unmarshals the BoltStorage from JSON. +func (v *BoltStorage) UnmarshalJSON(b []byte) error { + return sBoltStorage.UnmarshalJSON(b, v) } -type GatewayConfiguration struct { - Listen p2p.Multiaddr `json:"listen,omitempty" form:"listen" query:"listen" validate:"required"` +type CometNodeKeyFile struct { + Path string + key address.Address } -type HttpListener struct { +func (CometNodeKeyFile) Type() PrivateKeyType { return PrivateKeyTypeCometNodeKeyFile } - // Listen are the addresses and schemes to listen on. - Listen []p2p.Multiaddr `json:"listen,omitempty" form:"listen" query:"listen" validate:"required"` - // ConnectionLimit limits the number of concurrent connections. - ConnectionLimit *int64 `json:"connectionLimit,omitempty" form:"connectionLimit" query:"connectionLimit"` - // ReadHeaderTimeout protects against slow-loris attacks. - ReadHeaderTimeout *time.Duration `json:"readHeaderTimeout,omitempty" form:"readHeaderTimeout" query:"readHeaderTimeout"` - // TlsCertPath is the path of the TLS certificate. - TlsCertPath string `json:"tlsCertPath,omitempty" form:"tlsCertPath" query:"tlsCertPath"` - // TlsKeyPath is the path of the TLS key. - TlsKeyPath string `json:"tlsKeyPath,omitempty" form:"tlsKeyPath" query:"tlsKeyPath"` +// Copy returns a copy of the CometNodeKeyFile. +func (v *CometNodeKeyFile) Copy() *CometNodeKeyFile { + return sCometNodeKeyFile.Copy(v) } -type HttpPeerMapEntry struct { - fieldsSet []bool - ID p2p.PeerID `json:"id,omitempty" form:"id" query:"id" validate:"required"` - Partitions []string `json:"partitions,omitempty" form:"partitions" query:"partitions" validate:"required"` - Addresses []p2p.Multiaddr `json:"addresses,omitempty" form:"addresses" query:"addresses" validate:"required"` - extraData []byte +// EqualCometNodeKeyFile returns true if V is equal to U. +func (v *CometNodeKeyFile) Equal(u *CometNodeKeyFile) bool { + return sCometNodeKeyFile.Equal(v, u) } -type HttpService struct { - HttpListener - // CorsOrigins is a list of allowed CORS origins. - CorsOrigins []string `json:"corsOrigins,omitempty" form:"corsOrigins" query:"corsOrigins"` - // LetsEncrypt automatically retrieves a certificate from Let's Encrypt for the specified domains. - LetsEncrypt []string `json:"letsEncrypt,omitempty" form:"letsEncrypt" query:"letsEncrypt"` - DebugJsonRpc *bool `json:"debugJsonRpc,omitempty" form:"debugJsonRpc" query:"debugJsonRpc"` - Router *ServiceOrRef[*RouterService] `json:"router,omitempty" form:"router" query:"router" validate:"required"` - // PeerMap hard-codes the peer map. - PeerMap []*HttpPeerMapEntry `json:"peerMap,omitempty" form:"peerMap" query:"peerMap" validate:"required"` +// MarshalBinary marshals the CometNodeKeyFile to JSON. +func (v *CometNodeKeyFile) MarshalJSON() ([]byte, error) { + return sCometNodeKeyFile.MarshalJSON(v) } -type Instrumentation struct { - HttpListener - Monitoring *Monitor `json:"monitoring,omitempty" form:"monitoring" query:"monitoring" validate:"required"` - PprofListen p2p.Multiaddr `json:"pprofListen,omitempty" form:"pprofListen" query:"pprofListen" validate:"required"` +// UnmarshalJSON unmarshals the CometNodeKeyFile from JSON. +func (v *CometNodeKeyFile) UnmarshalJSON(b []byte) error { + return sCometNodeKeyFile.UnmarshalJSON(b, v) } -type LevelDBStorage struct { - Path string `json:"path,omitempty" form:"path" query:"path" validate:"required"` +type CometPrivValFile struct { + Path string + key address.Address } -type Logging struct { - Format string `json:"format,omitempty" form:"format" query:"format" validate:"required"` - Color *bool `json:"color,omitempty" form:"color" query:"color" validate:"required"` - Rules []*LoggingRule `json:"rules,omitempty" form:"rules" query:"rules" validate:"required"` - Loki *LokiLogging `json:"loki,omitempty" form:"loki" query:"loki" validate:"required"` -} +func (CometPrivValFile) Type() PrivateKeyType { return PrivateKeyTypeCometPrivValFile } -type LoggingRule struct { - Level slog.Level `json:"level" form:"level" query:"level" validate:"required"` - Modules []string `json:"modules,omitempty" form:"modules" query:"modules" validate:"required"` +// Copy returns a copy of the CometPrivValFile. +func (v *CometPrivValFile) Copy() *CometPrivValFile { + return sCometPrivValFile.Copy(v) } -type LokiLogging struct { - Enable bool `json:"enable,omitempty" form:"enable" query:"enable" validate:"required"` - Url string `json:"url,omitempty" form:"url" query:"url" validate:"required"` - Username string `json:"username,omitempty" form:"username" query:"username" validate:"required"` - Password string `json:"password,omitempty" form:"password" query:"password" validate:"required"` +// EqualCometPrivValFile returns true if V is equal to U. +func (v *CometPrivValFile) Equal(u *CometPrivValFile) bool { + return sCometPrivValFile.Equal(v, u) } -type MemoryStorage struct { +// MarshalBinary marshals the CometPrivValFile to JSON. +func (v *CometPrivValFile) MarshalJSON() ([]byte, error) { + return sCometPrivValFile.MarshalJSON(v) } -type MetricsService struct { - Partition string `json:"partition,omitempty" form:"partition" query:"partition" validate:"required"` +// UnmarshalJSON unmarshals the CometPrivValFile from JSON. +func (v *CometPrivValFile) UnmarshalJSON(b []byte) error { + return sCometPrivValFile.UnmarshalJSON(b, v) } -type Monitor struct { - - // Directory is the directory traces and profiles are written to. - Directory string `json:"directory,omitempty" form:"directory" query:"directory" validate:"required"` - // ProfileMemory enables profiling when memory usage increases dramatically. - ProfileMemory *bool `json:"profileMemory,omitempty" form:"profileMemory" query:"profileMemory" validate:"required"` - // MemoryPollingRate is rate at which to poll memory usage. - MemoryPollingRate *time.Duration `json:"memoryPollingRate,omitempty" form:"memoryPollingRate" query:"memoryPollingRate" validate:"required"` - // AllocRateTrigger is the rate of allocation in bytes/second that triggers a profile. - AllocRateTrigger *float64 `json:"allocRateTrigger,omitempty" form:"allocRateTrigger" query:"allocRateTrigger" validate:"required"` +type Config struct { + DotEnv *bool + Network string + Configurations []Configuration + Services []Service + P2P *P2P + Logging *Logging + Instrumentation *Instrumentation + Telemetry *Telemetry + file string + fs fs.FS } -type NetworkService struct { - Partition string `json:"partition,omitempty" form:"partition" query:"partition" validate:"required"` +// Copy returns a copy of the Config. +func (v *Config) Copy() *Config { + return sConfig.Copy(v) } -type OtlpConfig struct { - Enabled *bool `json:"enabled,omitempty" form:"enabled" query:"enabled" validate:"required"` - Endpoint string `json:"endpoint,omitempty" form:"endpoint" query:"endpoint" validate:"required"` - Username string `json:"username,omitempty" form:"username" query:"username" validate:"required"` - Password string `json:"password,omitempty" form:"password" query:"password" validate:"required"` +// EqualConfig returns true if V is equal to U. +func (v *Config) Equal(u *Config) bool { + return sConfig.Equal(v, u) } -type P2P struct { - Listen []p2p.Multiaddr `json:"listen,omitempty" form:"listen" query:"listen" validate:"required"` - BootstrapPeers []p2p.Multiaddr `json:"bootstrapPeers,omitempty" form:"bootstrapPeers" query:"bootstrapPeers" validate:"required"` - Key PrivateKey `json:"key,omitempty" form:"key" query:"key" validate:"required"` - PeerDB *string `json:"peerDB,omitempty" form:"peerDB" query:"peerDB" validate:"required"` - EnablePeerTracking bool `json:"enablePeerTracking,omitempty" form:"enablePeerTracking" query:"enablePeerTracking" validate:"required"` - DiscoveryMode *DhtMode `json:"discoveryMode,omitempty" form:"discoveryMode" query:"discoveryMode" validate:"required"` - External p2p.Multiaddr `json:"external,omitempty" form:"external" query:"external" validate:"required"` +// MarshalBinary marshals the Config to JSON. +func (v *Config) MarshalJSON() ([]byte, error) { + return sConfig.MarshalJSON(v) } -type PrivateKeySeed struct { - key address.Address - Seed *record.Key `json:"seed,omitempty" form:"seed" query:"seed" validate:"required"` +// UnmarshalJSON unmarshals the Config from JSON. +func (v *Config) UnmarshalJSON(b []byte) error { + return sConfig.UnmarshalJSON(b, v) } -type Querier struct { - Partition string `json:"partition,omitempty" form:"partition" query:"partition" validate:"required"` - Storage *StorageOrRef `json:"storage,omitempty" form:"storage" query:"storage"` -} +// TODO type Configuration interface {} -type RawPrivateKey struct { - Address string `json:"address,omitempty" form:"address" query:"address" validate:"required"` +// CopyConfiguration returns a copy of the Configuration. +func CopyConfiguration(v Configuration) Configuration { + return sConfiguration.Copy(v) } -type RouterService struct { - fieldsSet []bool - Name string `json:"name,omitempty" form:"name" query:"name"` - // Events may specify an event bus to use for routing table updates. - Events string `json:"events,omitempty" form:"events" query:"events"` - // PeerMap uses a hard-coded peer map for initializing routing. - PeerMap []*HttpPeerMapEntry `json:"peerMap,omitempty" form:"peerMap" query:"peerMap" validate:"required"` - extraData []byte +// EqualConfiguration returns true if A and B are equal. +func EqualConfiguration(a, b Configuration) bool { + return sConfiguration.Equal(a, b) } -type SnapshotService struct { - Partition string `json:"partition,omitempty" form:"partition" query:"partition" validate:"required"` - Storage *StorageOrRef `json:"storage,omitempty" form:"storage" query:"storage"` - // Directory is the directory to store snapshots in. - Directory string `json:"directory,omitempty" form:"directory" query:"directory" validate:"required"` - // Schedule is the schedule for capturing snapshots. - Schedule *network.CronSchedule `json:"schedule,omitempty" form:"schedule" query:"schedule"` - // RetainCount is the number of snapshots to retain. - RetainCount *uint64 `json:"retainCount,omitempty" form:"retainCount" query:"retainCount"` - // EnableIndexing enables indexing of snapshots. - EnableIndexing *bool `json:"enableIndexing,omitempty" form:"enableIndexing" query:"enableIndexing"` +// UnmarshalConfigurationJSON unmarshals a Configuration from JSON. +func UnmarshalConfigurationJSON(b []byte) (Configuration, error) { + var v Configuration + err := sConfiguration.UnmarshalJSON(b, &v) + return v, err } -type StorageService struct { - Name string `json:"name,omitempty" form:"name" query:"name"` - Storage Storage `json:"storage,omitempty" form:"storage" query:"storage" validate:"required"` -} +type ConfigurationType int64 -type SubnodeService struct { - Name string `json:"name,omitempty" form:"name" query:"name" validate:"required"` - NodeKey PrivateKey `json:"nodeKey,omitempty" form:"nodeKey" query:"nodeKey" validate:"required"` - Services []Service `json:"services,omitempty" form:"services" query:"services" validate:"required"` -} +const ( + ConfigurationTypeCoreValidator ConfigurationType = 1 + ConfigurationTypeDevnet ConfigurationType = 3 + ConfigurationTypeGateway ConfigurationType = 2 +) -type Telemetry struct { - Enabled *bool `json:"enabled,omitempty" form:"enabled" query:"enabled" validate:"required"` - Stdout *bool `json:"stdout,omitempty" form:"stdout" query:"stdout" validate:"required"` - Otlp *OtlpConfig `json:"otlp,omitempty" form:"otlp" query:"otlp" validate:"required"` - Export *HttpListener `json:"export,omitempty" form:"export" query:"export" validate:"required"` - Rules []*TelemetryRule `json:"rules,omitempty" form:"rules" query:"rules" validate:"required"` +// SetByName looks up a ConfigurationType by name. +func (v *ConfigurationType) SetByName(s string) (ok bool) { + *v, ok = sConfigurationType.ByName(s) + return } -type TelemetryRule struct { - Match []string `json:"match,omitempty" form:"match" query:"match" validate:"required"` - Drop bool `json:"drop,omitempty" form:"drop" query:"drop" validate:"required"` - Rate time.Duration `json:"rate,omitempty" form:"rate" query:"rate" validate:"required"` +// SetByValue looks up a ConfigurationType by value. +func (v *ConfigurationType) SetByValue(i int64) (ok bool) { + *v, ok = sConfigurationType.ByValue(i) + return } -type TransientPrivateKey struct { - key address.Address +// String returns the label or name of the ConfigurationType. +func (v ConfigurationType) String() string { + return sConfigurationType.String(v) } -func (*BadgerStorage) Type() StorageType { return StorageTypeBadger } +// MarshalBinary marshals the ConfigurationType to JSON. +func (v ConfigurationType) MarshalJSON() ([]byte, error) { + return sConfigurationType.MarshalJSON(v) +} -func (*BoltStorage) Type() StorageType { return StorageTypeBolt } +// UnmarshalJSON unmarshals the ConfigurationType from JSON. +func (v *ConfigurationType) UnmarshalJSON(b []byte) error { + return sConfigurationType.UnmarshalJSON(b, v) +} -func (*CometNodeKeyFile) Type() PrivateKeyType { return PrivateKeyTypeCometNodeKeyFile } +// TODO type ConsensusApp interface {} -func (*CometPrivValFile) Type() PrivateKeyType { return PrivateKeyTypeCometPrivValFile } +// CopyConsensusApp returns a copy of the ConsensusApp. +func CopyConsensusApp(v ConsensusApp) ConsensusApp { + return sConsensusApp.Copy(v) +} -func (*ConsensusService) Type() ServiceType { return ServiceTypeConsensus } +// EqualConsensusApp returns true if A and B are equal. +func EqualConsensusApp(a, b ConsensusApp) bool { + return sConsensusApp.Equal(a, b) +} -func (*CoreConsensusApp) Type() ConsensusAppType { return ConsensusAppTypeCore } +// UnmarshalConsensusAppJSON unmarshals a ConsensusApp from JSON. +func UnmarshalConsensusAppJSON(b []byte) (ConsensusApp, error) { + var v ConsensusApp + err := sConsensusApp.UnmarshalJSON(b, &v) + return v, err +} -func (*CoreValidatorConfiguration) Type() ConfigurationType { return ConfigurationTypeCoreValidator } +type ConsensusAppType int64 -func (*DevnetConfiguration) Type() ConfigurationType { return ConfigurationTypeDevnet } +const ( + ConsensusAppTypeCore ConsensusAppType = 1 +) -func (*EventsService) Type() ServiceType { return ServiceTypeEvents } +// SetByName looks up a ConsensusAppType by name. +func (v *ConsensusAppType) SetByName(s string) (ok bool) { + *v, ok = sConsensusAppType.ByName(s) + return +} -func (*ExpBlockDBStorage) Type() StorageType { return StorageTypeExpBlockDB } +// SetByValue looks up a ConsensusAppType by value. +func (v *ConsensusAppType) SetByValue(i int64) (ok bool) { + *v, ok = sConsensusAppType.ByValue(i) + return +} -func (*FaucetService) Type() ServiceType { return ServiceTypeFaucet } +// String returns the label or name of the ConsensusAppType. +func (v ConsensusAppType) String() string { + return sConsensusAppType.String(v) +} -func (*GatewayConfiguration) Type() ConfigurationType { return ConfigurationTypeGateway } +// MarshalBinary marshals the ConsensusAppType to JSON. +func (v ConsensusAppType) MarshalJSON() ([]byte, error) { + return sConsensusAppType.MarshalJSON(v) +} -func (*HttpService) Type() ServiceType { return ServiceTypeHttp } +// UnmarshalJSON unmarshals the ConsensusAppType from JSON. +func (v *ConsensusAppType) UnmarshalJSON(b []byte) error { + return sConsensusAppType.UnmarshalJSON(b, v) +} -func (*LevelDBStorage) Type() StorageType { return StorageTypeLevelDB } +type ConsensusService struct { + NodeDir string + ValidatorKey PrivateKey + Genesis string + Listen p2p.Multiaddr + BootstrapPeers []p2p.Multiaddr + MetricsNamespace string + App ConsensusApp +} -func (*MemoryStorage) Type() StorageType { return StorageTypeMemory } +func (ConsensusService) Type() ServiceType { return ServiceTypeConsensus } -func (*MetricsService) Type() ServiceType { return ServiceTypeMetrics } +// Copy returns a copy of the ConsensusService. +func (v *ConsensusService) Copy() *ConsensusService { + return sConsensusService.Copy(v) +} -func (*NetworkService) Type() ServiceType { return ServiceTypeNetwork } +// EqualConsensusService returns true if V is equal to U. +func (v *ConsensusService) Equal(u *ConsensusService) bool { + return sConsensusService.Equal(v, u) +} -func (*PrivateKeySeed) Type() PrivateKeyType { return PrivateKeyTypeSeed } +// MarshalBinary marshals the ConsensusService to JSON. +func (v *ConsensusService) MarshalJSON() ([]byte, error) { + return sConsensusService.MarshalJSON(v) +} -func (*Querier) Type() ServiceType { return ServiceTypeQuerier } +// UnmarshalJSON unmarshals the ConsensusService from JSON. +func (v *ConsensusService) UnmarshalJSON(b []byte) error { + return sConsensusService.UnmarshalJSON(b, v) +} -func (*RawPrivateKey) Type() PrivateKeyType { return PrivateKeyTypeRaw } +type CoreConsensusApp struct { + Partition *protocol.PartitionInfo + EnableHealing *bool + EnableDirectDispatch *bool + MaxEnvelopesPerBlock *uint64 +} -func (*RouterService) Type() ServiceType { return ServiceTypeRouter } +func (CoreConsensusApp) Type() ConsensusAppType { return ConsensusAppTypeCore } -func (*SnapshotService) Type() ServiceType { return ServiceTypeSnapshot } +// Copy returns a copy of the CoreConsensusApp. +func (v *CoreConsensusApp) Copy() *CoreConsensusApp { + return sCoreConsensusApp.Copy(v) +} -func (*StorageService) Type() ServiceType { return ServiceTypeStorage } +// EqualCoreConsensusApp returns true if V is equal to U. +func (v *CoreConsensusApp) Equal(u *CoreConsensusApp) bool { + return sCoreConsensusApp.Equal(v, u) +} -func (*SubnodeService) Type() ServiceType { return ServiceTypeSubnode } +// MarshalBinary marshals the CoreConsensusApp to JSON. +func (v *CoreConsensusApp) MarshalJSON() ([]byte, error) { + return sCoreConsensusApp.MarshalJSON(v) +} -func (*TransientPrivateKey) Type() PrivateKeyType { return PrivateKeyTypeTransient } +// UnmarshalJSON unmarshals the CoreConsensusApp from JSON. +func (v *CoreConsensusApp) UnmarshalJSON(b []byte) error { + return sCoreConsensusApp.UnmarshalJSON(b, v) +} -func (v *BadgerStorage) Copy() *BadgerStorage { - u := new(BadgerStorage) +type CoreValidatorConfiguration struct { + Mode CoreValidatorMode + Listen p2p.Multiaddr + BVN string + ValidatorKey PrivateKey + DnGenesis string + BvnGenesis string + DnBootstrapPeers []p2p.Multiaddr + BvnBootstrapPeers []p2p.Multiaddr + EnableHealing *bool + EnableDirectDispatch *bool + EnableSnapshots *bool + MaxEnvelopesPerBlock *uint64 + StorageType *StorageType +} + +func (CoreValidatorConfiguration) Type() ConfigurationType { return ConfigurationTypeCoreValidator } + +// Copy returns a copy of the CoreValidatorConfiguration. +func (v *CoreValidatorConfiguration) Copy() *CoreValidatorConfiguration { + return sCoreValidatorConfiguration.Copy(v) +} - u.Path = v.Path - u.Version = v.Version +// EqualCoreValidatorConfiguration returns true if V is equal to U. +func (v *CoreValidatorConfiguration) Equal(u *CoreValidatorConfiguration) bool { + return sCoreValidatorConfiguration.Equal(v, u) +} - return u +// MarshalBinary marshals the CoreValidatorConfiguration to JSON. +func (v *CoreValidatorConfiguration) MarshalJSON() ([]byte, error) { + return sCoreValidatorConfiguration.MarshalJSON(v) } -func (v *BadgerStorage) CopyAsInterface() interface{} { return v.Copy() } +// UnmarshalJSON unmarshals the CoreValidatorConfiguration from JSON. +func (v *CoreValidatorConfiguration) UnmarshalJSON(b []byte) error { + return sCoreValidatorConfiguration.UnmarshalJSON(b, v) +} -func (v *BoltStorage) Copy() *BoltStorage { - u := new(BoltStorage) +type CoreValidatorMode int64 - u.Path = v.Path +const ( + CoreValidatorModeBVN CoreValidatorMode = 2 + CoreValidatorModeDN CoreValidatorMode = 1 + CoreValidatorModeDual CoreValidatorMode = 0 +) - return u +// SetByName looks up a CoreValidatorMode by name. +func (v *CoreValidatorMode) SetByName(s string) (ok bool) { + *v, ok = sCoreValidatorMode.ByName(s) + return } -func (v *BoltStorage) CopyAsInterface() interface{} { return v.Copy() } - -func (v *CometNodeKeyFile) Copy() *CometNodeKeyFile { - u := new(CometNodeKeyFile) +// SetByValue looks up a CoreValidatorMode by value. +func (v *CoreValidatorMode) SetByValue(i int64) (ok bool) { + *v, ok = sCoreValidatorMode.ByValue(i) + return +} - u.Path = v.Path +// String returns the label or name of the CoreValidatorMode. +func (v CoreValidatorMode) String() string { + return sCoreValidatorMode.String(v) +} - return u +// MarshalBinary marshals the CoreValidatorMode to JSON. +func (v CoreValidatorMode) MarshalJSON() ([]byte, error) { + return sCoreValidatorMode.MarshalJSON(v) } -func (v *CometNodeKeyFile) CopyAsInterface() interface{} { return v.Copy() } +// UnmarshalJSON unmarshals the CoreValidatorMode from JSON. +func (v *CoreValidatorMode) UnmarshalJSON(b []byte) error { + return sCoreValidatorMode.UnmarshalJSON(b, v) +} -func (v *CometPrivValFile) Copy() *CometPrivValFile { - u := new(CometPrivValFile) +type DevnetConfiguration struct { + Listen p2p.Multiaddr + Bvns uint64 + Validators uint64 + Followers uint64 + Globals *network.GlobalValues + StorageType *StorageType +} - u.Path = v.Path +func (DevnetConfiguration) Type() ConfigurationType { return ConfigurationTypeDevnet } - return u +// Copy returns a copy of the DevnetConfiguration. +func (v *DevnetConfiguration) Copy() *DevnetConfiguration { + return sDevnetConfiguration.Copy(v) } -func (v *CometPrivValFile) CopyAsInterface() interface{} { return v.Copy() } +// EqualDevnetConfiguration returns true if V is equal to U. +func (v *DevnetConfiguration) Equal(u *DevnetConfiguration) bool { + return sDevnetConfiguration.Equal(v, u) +} -func (v *Config) Copy() *Config { - u := new(Config) - - if v.DotEnv != nil { - u.DotEnv = new(bool) - *u.DotEnv = *v.DotEnv - } - u.Network = v.Network - if v.Logging != nil { - u.Logging = (v.Logging).Copy() - } - if v.Instrumentation != nil { - u.Instrumentation = (v.Instrumentation).Copy() - } - if v.Telemetry != nil { - u.Telemetry = (v.Telemetry).Copy() - } - if v.P2P != nil { - u.P2P = (v.P2P).Copy() - } - u.Configurations = make([]Configuration, len(v.Configurations)) - for i, v := range v.Configurations { - v := v - if v != nil { - u.Configurations[i] = CopyConfiguration(v) - } - } - u.Services = make([]Service, len(v.Services)) - for i, v := range v.Services { - v := v - if v != nil { - u.Services[i] = CopyService(v) - } - } - - return u -} - -func (v *Config) CopyAsInterface() interface{} { return v.Copy() } +// MarshalBinary marshals the DevnetConfiguration to JSON. +func (v *DevnetConfiguration) MarshalJSON() ([]byte, error) { + return sDevnetConfiguration.MarshalJSON(v) +} -func (v *ConsensusService) Copy() *ConsensusService { - u := new(ConsensusService) - - u.NodeDir = v.NodeDir - if v.ValidatorKey != nil { - u.ValidatorKey = CopyPrivateKey(v.ValidatorKey) - } - u.Genesis = v.Genesis - if v.Listen != nil { - u.Listen = p2p.CopyMultiaddr(v.Listen) - } - u.BootstrapPeers = make([]p2p.Multiaddr, len(v.BootstrapPeers)) - for i, v := range v.BootstrapPeers { - v := v - if v != nil { - u.BootstrapPeers[i] = p2p.CopyMultiaddr(v) - } - } - u.MetricsNamespace = v.MetricsNamespace - if v.App != nil { - u.App = CopyConsensusApp(v.App) - } - - return u -} - -func (v *ConsensusService) CopyAsInterface() interface{} { return v.Copy() } +// UnmarshalJSON unmarshals the DevnetConfiguration from JSON. +func (v *DevnetConfiguration) UnmarshalJSON(b []byte) error { + return sDevnetConfiguration.UnmarshalJSON(b, v) +} -func (v *CoreConsensusApp) Copy() *CoreConsensusApp { - u := new(CoreConsensusApp) +type EventsService struct { + Partition string +} - if v.Partition != nil { - u.Partition = (v.Partition).Copy() - } - if v.EnableHealing != nil { - u.EnableHealing = new(bool) - *u.EnableHealing = *v.EnableHealing - } - if v.EnableDirectDispatch != nil { - u.EnableDirectDispatch = new(bool) - *u.EnableDirectDispatch = *v.EnableDirectDispatch - } - if v.MaxEnvelopesPerBlock != nil { - u.MaxEnvelopesPerBlock = new(uint64) - *u.MaxEnvelopesPerBlock = *v.MaxEnvelopesPerBlock - } +func (EventsService) Type() ServiceType { return ServiceTypeEvents } - return u +// Copy returns a copy of the EventsService. +func (v *EventsService) Copy() *EventsService { + return sEventsService.Copy(v) } -func (v *CoreConsensusApp) CopyAsInterface() interface{} { return v.Copy() } - -func (v *CoreValidatorConfiguration) Copy() *CoreValidatorConfiguration { - u := new(CoreValidatorConfiguration) - - u.Mode = v.Mode - if v.Listen != nil { - u.Listen = p2p.CopyMultiaddr(v.Listen) - } - u.BVN = v.BVN - if v.ValidatorKey != nil { - u.ValidatorKey = CopyPrivateKey(v.ValidatorKey) - } - u.DnGenesis = v.DnGenesis - u.BvnGenesis = v.BvnGenesis - u.DnBootstrapPeers = make([]p2p.Multiaddr, len(v.DnBootstrapPeers)) - for i, v := range v.DnBootstrapPeers { - v := v - if v != nil { - u.DnBootstrapPeers[i] = p2p.CopyMultiaddr(v) - } - } - u.BvnBootstrapPeers = make([]p2p.Multiaddr, len(v.BvnBootstrapPeers)) - for i, v := range v.BvnBootstrapPeers { - v := v - if v != nil { - u.BvnBootstrapPeers[i] = p2p.CopyMultiaddr(v) - } - } - if v.EnableHealing != nil { - u.EnableHealing = new(bool) - *u.EnableHealing = *v.EnableHealing - } - if v.EnableDirectDispatch != nil { - u.EnableDirectDispatch = new(bool) - *u.EnableDirectDispatch = *v.EnableDirectDispatch - } - if v.EnableSnapshots != nil { - u.EnableSnapshots = new(bool) - *u.EnableSnapshots = *v.EnableSnapshots - } - if v.MaxEnvelopesPerBlock != nil { - u.MaxEnvelopesPerBlock = new(uint64) - *u.MaxEnvelopesPerBlock = *v.MaxEnvelopesPerBlock - } - if v.StorageType != nil { - u.StorageType = new(StorageType) - *u.StorageType = *v.StorageType - } - - return u -} - -func (v *CoreValidatorConfiguration) CopyAsInterface() interface{} { return v.Copy() } +// EqualEventsService returns true if V is equal to U. +func (v *EventsService) Equal(u *EventsService) bool { + return sEventsService.Equal(v, u) +} -func (v *DevnetConfiguration) Copy() *DevnetConfiguration { - u := new(DevnetConfiguration) +// MarshalBinary marshals the EventsService to JSON. +func (v *EventsService) MarshalJSON() ([]byte, error) { + return sEventsService.MarshalJSON(v) +} - if v.Listen != nil { - u.Listen = p2p.CopyMultiaddr(v.Listen) - } - u.Bvns = v.Bvns - u.Validators = v.Validators - u.Followers = v.Followers - if v.Globals != nil { - u.Globals = (v.Globals).Copy() - } - if v.StorageType != nil { - u.StorageType = new(StorageType) - *u.StorageType = *v.StorageType - } +// UnmarshalJSON unmarshals the EventsService from JSON. +func (v *EventsService) UnmarshalJSON(b []byte) error { + return sEventsService.UnmarshalJSON(b, v) +} - return u +type ExpBlockDBStorage struct { + Path string } -func (v *DevnetConfiguration) CopyAsInterface() interface{} { return v.Copy() } +func (ExpBlockDBStorage) Type() StorageType { return StorageTypeExpBlockDB } -func (v *EventsService) Copy() *EventsService { - u := new(EventsService) +// Copy returns a copy of the ExpBlockDBStorage. +func (v *ExpBlockDBStorage) Copy() *ExpBlockDBStorage { + return sExpBlockDBStorage.Copy(v) +} - u.Partition = v.Partition +// EqualExpBlockDBStorage returns true if V is equal to U. +func (v *ExpBlockDBStorage) Equal(u *ExpBlockDBStorage) bool { + return sExpBlockDBStorage.Equal(v, u) +} - return u +// MarshalBinary marshals the ExpBlockDBStorage to JSON. +func (v *ExpBlockDBStorage) MarshalJSON() ([]byte, error) { + return sExpBlockDBStorage.MarshalJSON(v) } -func (v *EventsService) CopyAsInterface() interface{} { return v.Copy() } +// UnmarshalJSON unmarshals the ExpBlockDBStorage from JSON. +func (v *ExpBlockDBStorage) UnmarshalJSON(b []byte) error { + return sExpBlockDBStorage.UnmarshalJSON(b, v) +} -func (v *ExpBlockDBStorage) Copy() *ExpBlockDBStorage { - u := new(ExpBlockDBStorage) +type FaucetService struct { + Account *url.URL + SigningKey PrivateKey + Router *RouterServiceRef +} - u.Path = v.Path +func (FaucetService) Type() ServiceType { return ServiceTypeFaucet } - return u +// Copy returns a copy of the FaucetService. +func (v *FaucetService) Copy() *FaucetService { + return sFaucetService.Copy(v) } -func (v *ExpBlockDBStorage) CopyAsInterface() interface{} { return v.Copy() } +// EqualFaucetService returns true if V is equal to U. +func (v *FaucetService) Equal(u *FaucetService) bool { + return sFaucetService.Equal(v, u) +} -func (v *FaucetService) Copy() *FaucetService { - u := new(FaucetService) +// MarshalBinary marshals the FaucetService to JSON. +func (v *FaucetService) MarshalJSON() ([]byte, error) { + return sFaucetService.MarshalJSON(v) +} - if v.Account != nil { - u.Account = v.Account - } - if v.SigningKey != nil { - u.SigningKey = CopyPrivateKey(v.SigningKey) - } - if v.Router != nil { - u.Router = (v.Router).Copy() - } +// UnmarshalJSON unmarshals the FaucetService from JSON. +func (v *FaucetService) UnmarshalJSON(b []byte) error { + return sFaucetService.UnmarshalJSON(b, v) +} - return u +type GatewayConfiguration struct { + Listen p2p.Multiaddr } -func (v *FaucetService) CopyAsInterface() interface{} { return v.Copy() } +func (GatewayConfiguration) Type() ConfigurationType { return ConfigurationTypeGateway } +// Copy returns a copy of the GatewayConfiguration. func (v *GatewayConfiguration) Copy() *GatewayConfiguration { - u := new(GatewayConfiguration) - - if v.Listen != nil { - u.Listen = p2p.CopyMultiaddr(v.Listen) - } + return sGatewayConfiguration.Copy(v) +} - return u +// EqualGatewayConfiguration returns true if V is equal to U. +func (v *GatewayConfiguration) Equal(u *GatewayConfiguration) bool { + return sGatewayConfiguration.Equal(v, u) } -func (v *GatewayConfiguration) CopyAsInterface() interface{} { return v.Copy() } +// MarshalBinary marshals the GatewayConfiguration to JSON. +func (v *GatewayConfiguration) MarshalJSON() ([]byte, error) { + return sGatewayConfiguration.MarshalJSON(v) +} -func (v *HttpListener) Copy() *HttpListener { - u := new(HttpListener) - - u.Listen = make([]p2p.Multiaddr, len(v.Listen)) - for i, v := range v.Listen { - v := v - if v != nil { - u.Listen[i] = p2p.CopyMultiaddr(v) - } - } - if v.ConnectionLimit != nil { - u.ConnectionLimit = new(int64) - *u.ConnectionLimit = *v.ConnectionLimit - } - if v.ReadHeaderTimeout != nil { - u.ReadHeaderTimeout = new(time.Duration) - *u.ReadHeaderTimeout = *v.ReadHeaderTimeout - } - u.TlsCertPath = v.TlsCertPath - u.TlsKeyPath = v.TlsKeyPath - - return u -} - -func (v *HttpListener) CopyAsInterface() interface{} { return v.Copy() } +// UnmarshalJSON unmarshals the GatewayConfiguration from JSON. +func (v *GatewayConfiguration) UnmarshalJSON(b []byte) error { + return sGatewayConfiguration.UnmarshalJSON(b, v) +} -func (v *HttpPeerMapEntry) Copy() *HttpPeerMapEntry { - u := new(HttpPeerMapEntry) - - if v.ID != "" { - u.ID = p2p.CopyPeerID(v.ID) - } - u.Partitions = make([]string, len(v.Partitions)) - for i, v := range v.Partitions { - v := v - u.Partitions[i] = v - } - u.Addresses = make([]p2p.Multiaddr, len(v.Addresses)) - for i, v := range v.Addresses { - v := v - if v != nil { - u.Addresses[i] = p2p.CopyMultiaddr(v) - } - } - if len(v.extraData) > 0 { - u.extraData = make([]byte, len(v.extraData)) - copy(u.extraData, v.extraData) - } - - return u -} - -func (v *HttpPeerMapEntry) CopyAsInterface() interface{} { return v.Copy() } +type HttpListener struct { + // Listen are the addresses and schemes to listen on. + Listen []p2p.Multiaddr + // ConnectionLimit limits the number of concurrent connections. + ConnectionLimit *int64 + // ReadHeaderTimeout protects against slow-loris attacks. + ReadHeaderTimeout *encoding.Duration + // TlsCertPath is the path of the TLS certificate. + TlsCertPath string + // TlsKeyPath is the path of the TLS key. + TlsKeyPath string +} -func (v *HttpService) Copy() *HttpService { - u := new(HttpService) - - u.HttpListener = *v.HttpListener.Copy() - u.CorsOrigins = make([]string, len(v.CorsOrigins)) - for i, v := range v.CorsOrigins { - v := v - u.CorsOrigins[i] = v - } - u.LetsEncrypt = make([]string, len(v.LetsEncrypt)) - for i, v := range v.LetsEncrypt { - v := v - u.LetsEncrypt[i] = v - } - if v.DebugJsonRpc != nil { - u.DebugJsonRpc = new(bool) - *u.DebugJsonRpc = *v.DebugJsonRpc - } - if v.Router != nil { - u.Router = (v.Router).Copy() - } - u.PeerMap = make([]*HttpPeerMapEntry, len(v.PeerMap)) - for i, v := range v.PeerMap { - v := v - if v != nil { - u.PeerMap[i] = (v).Copy() - } - } - - return u -} - -func (v *HttpService) CopyAsInterface() interface{} { return v.Copy() } +// Copy returns a copy of the HttpListener. +func (v *HttpListener) Copy() *HttpListener { + return sHttpListener.Copy(v) +} -func (v *Instrumentation) Copy() *Instrumentation { - u := new(Instrumentation) +// EqualHttpListener returns true if V is equal to U. +func (v *HttpListener) Equal(u *HttpListener) bool { + return sHttpListener.Equal(v, u) +} - u.HttpListener = *v.HttpListener.Copy() - if v.Monitoring != nil { - u.Monitoring = (v.Monitoring).Copy() - } - if v.PprofListen != nil { - u.PprofListen = p2p.CopyMultiaddr(v.PprofListen) - } +// MarshalBinary marshals the HttpListener to JSON. +func (v *HttpListener) MarshalJSON() ([]byte, error) { + return sHttpListener.MarshalJSON(v) +} - return u +// UnmarshalJSON unmarshals the HttpListener from JSON. +func (v *HttpListener) UnmarshalJSON(b []byte) error { + return sHttpListener.UnmarshalJSON(b, v) } -func (v *Instrumentation) CopyAsInterface() interface{} { return v.Copy() } +type HttpPeerMapEntry struct { + ID p2p.PeerID + Partitions []string + Addresses []p2p.Multiaddr +} -func (v *LevelDBStorage) Copy() *LevelDBStorage { - u := new(LevelDBStorage) +// Copy returns a copy of the HttpPeerMapEntry. +func (v *HttpPeerMapEntry) Copy() *HttpPeerMapEntry { + return sHttpPeerMapEntry.Copy(v) +} - u.Path = v.Path +// EqualHttpPeerMapEntry returns true if V is equal to U. +func (v *HttpPeerMapEntry) Equal(u *HttpPeerMapEntry) bool { + return sHttpPeerMapEntry.Equal(v, u) +} - return u +// MarshalBinary marshals the HttpPeerMapEntry to JSON. +func (v *HttpPeerMapEntry) MarshalJSON() ([]byte, error) { + return sHttpPeerMapEntry.MarshalJSON(v) } -func (v *LevelDBStorage) CopyAsInterface() interface{} { return v.Copy() } +// UnmarshalJSON unmarshals the HttpPeerMapEntry from JSON. +func (v *HttpPeerMapEntry) UnmarshalJSON(b []byte) error { + return sHttpPeerMapEntry.UnmarshalJSON(b, v) +} -func (v *Logging) Copy() *Logging { - u := new(Logging) +type HttpService struct { + HttpListener + // CorsOrigins is a list of allowed CORS origins. + CorsOrigins []string + // LetsEncrypt automatically retrieves a certificate from Let's Encrypt for the specified domains. + LetsEncrypt []string + DebugJsonRpc *bool + Router *RouterServiceRef + // PeerMap hard-codes the peer map. + PeerMap []*HttpPeerMapEntry +} - u.Format = v.Format - if v.Color != nil { - u.Color = new(bool) - *u.Color = *v.Color - } - u.Rules = make([]*LoggingRule, len(v.Rules)) - for i, v := range v.Rules { - v := v - if v != nil { - u.Rules[i] = (v).Copy() - } - } - if v.Loki != nil { - u.Loki = (v.Loki).Copy() - } +func (HttpService) Type() ServiceType { return ServiceTypeHttp } - return u +// Copy returns a copy of the HttpService. +func (v *HttpService) Copy() *HttpService { + return sHttpService.Copy(v) } -func (v *Logging) CopyAsInterface() interface{} { return v.Copy() } +// EqualHttpService returns true if V is equal to U. +func (v *HttpService) Equal(u *HttpService) bool { + return sHttpService.Equal(v, u) +} -func (v *LoggingRule) Copy() *LoggingRule { - u := new(LoggingRule) +// MarshalBinary marshals the HttpService to JSON. +func (v *HttpService) MarshalJSON() ([]byte, error) { + return sHttpService.MarshalJSON(v) +} - u.Level = v.Level - u.Modules = make([]string, len(v.Modules)) - for i, v := range v.Modules { - v := v - u.Modules[i] = v - } +// UnmarshalJSON unmarshals the HttpService from JSON. +func (v *HttpService) UnmarshalJSON(b []byte) error { + return sHttpService.UnmarshalJSON(b, v) +} - return u +type Instrumentation struct { + HttpListener + PprofListen p2p.Multiaddr + Monitoring *Monitor } -func (v *LoggingRule) CopyAsInterface() interface{} { return v.Copy() } +// Copy returns a copy of the Instrumentation. +func (v *Instrumentation) Copy() *Instrumentation { + return sInstrumentation.Copy(v) +} -func (v *LokiLogging) Copy() *LokiLogging { - u := new(LokiLogging) +// EqualInstrumentation returns true if V is equal to U. +func (v *Instrumentation) Equal(u *Instrumentation) bool { + return sInstrumentation.Equal(v, u) +} - u.Enable = v.Enable - u.Url = v.Url - u.Username = v.Username - u.Password = v.Password +// MarshalBinary marshals the Instrumentation to JSON. +func (v *Instrumentation) MarshalJSON() ([]byte, error) { + return sInstrumentation.MarshalJSON(v) +} - return u +// UnmarshalJSON unmarshals the Instrumentation from JSON. +func (v *Instrumentation) UnmarshalJSON(b []byte) error { + return sInstrumentation.UnmarshalJSON(b, v) } -func (v *LokiLogging) CopyAsInterface() interface{} { return v.Copy() } +type LevelDBStorage struct { + Path string +} -func (v *MemoryStorage) Copy() *MemoryStorage { - u := new(MemoryStorage) +func (LevelDBStorage) Type() StorageType { return StorageTypeLevelDB } - return u +// Copy returns a copy of the LevelDBStorage. +func (v *LevelDBStorage) Copy() *LevelDBStorage { + return sLevelDBStorage.Copy(v) } -func (v *MemoryStorage) CopyAsInterface() interface{} { return v.Copy() } +// EqualLevelDBStorage returns true if V is equal to U. +func (v *LevelDBStorage) Equal(u *LevelDBStorage) bool { + return sLevelDBStorage.Equal(v, u) +} -func (v *MetricsService) Copy() *MetricsService { - u := new(MetricsService) +// MarshalBinary marshals the LevelDBStorage to JSON. +func (v *LevelDBStorage) MarshalJSON() ([]byte, error) { + return sLevelDBStorage.MarshalJSON(v) +} - u.Partition = v.Partition +// UnmarshalJSON unmarshals the LevelDBStorage from JSON. +func (v *LevelDBStorage) UnmarshalJSON(b []byte) error { + return sLevelDBStorage.UnmarshalJSON(b, v) +} - return u +type Logging struct { + Format string + Color *bool + Rules []*LoggingRule + Loki *LokiLogging } -func (v *MetricsService) CopyAsInterface() interface{} { return v.Copy() } +// Copy returns a copy of the Logging. +func (v *Logging) Copy() *Logging { + return sLogging.Copy(v) +} -func (v *Monitor) Copy() *Monitor { - u := new(Monitor) +// EqualLogging returns true if V is equal to U. +func (v *Logging) Equal(u *Logging) bool { + return sLogging.Equal(v, u) +} - u.Directory = v.Directory - if v.ProfileMemory != nil { - u.ProfileMemory = new(bool) - *u.ProfileMemory = *v.ProfileMemory - } - if v.MemoryPollingRate != nil { - u.MemoryPollingRate = new(time.Duration) - *u.MemoryPollingRate = *v.MemoryPollingRate - } - if v.AllocRateTrigger != nil { - u.AllocRateTrigger = new(float64) - *u.AllocRateTrigger = *v.AllocRateTrigger - } +// MarshalBinary marshals the Logging to JSON. +func (v *Logging) MarshalJSON() ([]byte, error) { + return sLogging.MarshalJSON(v) +} - return u +// UnmarshalJSON unmarshals the Logging from JSON. +func (v *Logging) UnmarshalJSON(b []byte) error { + return sLogging.UnmarshalJSON(b, v) } -func (v *Monitor) CopyAsInterface() interface{} { return v.Copy() } +type LoggingRule struct { + Level slog.Level + Modules []string +} -func (v *NetworkService) Copy() *NetworkService { - u := new(NetworkService) +// Copy returns a copy of the LoggingRule. +func (v *LoggingRule) Copy() *LoggingRule { + return sLoggingRule.Copy(v) +} - u.Partition = v.Partition +// EqualLoggingRule returns true if V is equal to U. +func (v *LoggingRule) Equal(u *LoggingRule) bool { + return sLoggingRule.Equal(v, u) +} - return u +// MarshalBinary marshals the LoggingRule to JSON. +func (v *LoggingRule) MarshalJSON() ([]byte, error) { + return sLoggingRule.MarshalJSON(v) } -func (v *NetworkService) CopyAsInterface() interface{} { return v.Copy() } +// UnmarshalJSON unmarshals the LoggingRule from JSON. +func (v *LoggingRule) UnmarshalJSON(b []byte) error { + return sLoggingRule.UnmarshalJSON(b, v) +} -func (v *OtlpConfig) Copy() *OtlpConfig { - u := new(OtlpConfig) +type LokiLogging struct { + Enable bool + Url string + Username string + Password string +} - if v.Enabled != nil { - u.Enabled = new(bool) - *u.Enabled = *v.Enabled - } - u.Endpoint = v.Endpoint - u.Username = v.Username - u.Password = v.Password +// Copy returns a copy of the LokiLogging. +func (v *LokiLogging) Copy() *LokiLogging { + return sLokiLogging.Copy(v) +} - return u +// EqualLokiLogging returns true if V is equal to U. +func (v *LokiLogging) Equal(u *LokiLogging) bool { + return sLokiLogging.Equal(v, u) } -func (v *OtlpConfig) CopyAsInterface() interface{} { return v.Copy() } +// MarshalBinary marshals the LokiLogging to JSON. +func (v *LokiLogging) MarshalJSON() ([]byte, error) { + return sLokiLogging.MarshalJSON(v) +} -func (v *P2P) Copy() *P2P { - u := new(P2P) - - u.Listen = make([]p2p.Multiaddr, len(v.Listen)) - for i, v := range v.Listen { - v := v - if v != nil { - u.Listen[i] = p2p.CopyMultiaddr(v) - } - } - u.BootstrapPeers = make([]p2p.Multiaddr, len(v.BootstrapPeers)) - for i, v := range v.BootstrapPeers { - v := v - if v != nil { - u.BootstrapPeers[i] = p2p.CopyMultiaddr(v) - } - } - if v.Key != nil { - u.Key = CopyPrivateKey(v.Key) - } - if v.PeerDB != nil { - u.PeerDB = new(string) - *u.PeerDB = *v.PeerDB - } - u.EnablePeerTracking = v.EnablePeerTracking - if v.DiscoveryMode != nil { - u.DiscoveryMode = new(DhtMode) - *u.DiscoveryMode = *v.DiscoveryMode - } - if v.External != nil { - u.External = p2p.CopyMultiaddr(v.External) - } - - return u -} - -func (v *P2P) CopyAsInterface() interface{} { return v.Copy() } +// UnmarshalJSON unmarshals the LokiLogging from JSON. +func (v *LokiLogging) UnmarshalJSON(b []byte) error { + return sLokiLogging.UnmarshalJSON(b, v) +} -func (v *PrivateKeySeed) Copy() *PrivateKeySeed { - u := new(PrivateKeySeed) +type MemoryStorage struct { +} - if v.Seed != nil { - u.Seed = (v.Seed).Copy() - } +func (MemoryStorage) Type() StorageType { return StorageTypeMemory } - return u +// Copy returns a copy of the MemoryStorage. +func (v *MemoryStorage) Copy() *MemoryStorage { + return sMemoryStorage.Copy(v) } -func (v *PrivateKeySeed) CopyAsInterface() interface{} { return v.Copy() } +// EqualMemoryStorage returns true if V is equal to U. +func (v *MemoryStorage) Equal(u *MemoryStorage) bool { + return sMemoryStorage.Equal(v, u) +} -func (v *Querier) Copy() *Querier { - u := new(Querier) +// MarshalBinary marshals the MemoryStorage to JSON. +func (v *MemoryStorage) MarshalJSON() ([]byte, error) { + return sMemoryStorage.MarshalJSON(v) +} - u.Partition = v.Partition - if v.Storage != nil { - u.Storage = (v.Storage).Copy() - } +// UnmarshalJSON unmarshals the MemoryStorage from JSON. +func (v *MemoryStorage) UnmarshalJSON(b []byte) error { + return sMemoryStorage.UnmarshalJSON(b, v) +} - return u +type MetricsService struct { + Partition string } -func (v *Querier) CopyAsInterface() interface{} { return v.Copy() } +func (MetricsService) Type() ServiceType { return ServiceTypeMetrics } -func (v *RawPrivateKey) Copy() *RawPrivateKey { - u := new(RawPrivateKey) +// Copy returns a copy of the MetricsService. +func (v *MetricsService) Copy() *MetricsService { + return sMetricsService.Copy(v) +} - u.Address = v.Address +// EqualMetricsService returns true if V is equal to U. +func (v *MetricsService) Equal(u *MetricsService) bool { + return sMetricsService.Equal(v, u) +} - return u +// MarshalBinary marshals the MetricsService to JSON. +func (v *MetricsService) MarshalJSON() ([]byte, error) { + return sMetricsService.MarshalJSON(v) } -func (v *RawPrivateKey) CopyAsInterface() interface{} { return v.Copy() } +// UnmarshalJSON unmarshals the MetricsService from JSON. +func (v *MetricsService) UnmarshalJSON(b []byte) error { + return sMetricsService.UnmarshalJSON(b, v) +} -func (v *RouterService) Copy() *RouterService { - u := new(RouterService) +type Monitor struct { + // Directory is the directory traces and profiles are written to. + Directory string + // ProfileMemory enables profiling when memory usage increases dramatically. + ProfileMemory *bool + // MemoryPollingRate is rate at which to poll memory usage. + MemoryPollingRate *encoding.Duration + // AllocRateTrigger is the rate of allocation in bytes/second that triggers a profile. + AllocRateTrigger *float64 +} - u.Name = v.Name - u.Events = v.Events - u.PeerMap = make([]*HttpPeerMapEntry, len(v.PeerMap)) - for i, v := range v.PeerMap { - v := v - if v != nil { - u.PeerMap[i] = (v).Copy() - } - } - if len(v.extraData) > 0 { - u.extraData = make([]byte, len(v.extraData)) - copy(u.extraData, v.extraData) - } +// Copy returns a copy of the Monitor. +func (v *Monitor) Copy() *Monitor { + return sMonitor.Copy(v) +} - return u +// EqualMonitor returns true if V is equal to U. +func (v *Monitor) Equal(u *Monitor) bool { + return sMonitor.Equal(v, u) } -func (v *RouterService) CopyAsInterface() interface{} { return v.Copy() } +// MarshalBinary marshals the Monitor to JSON. +func (v *Monitor) MarshalJSON() ([]byte, error) { + return sMonitor.MarshalJSON(v) +} -func (v *SnapshotService) Copy() *SnapshotService { - u := new(SnapshotService) - - u.Partition = v.Partition - if v.Storage != nil { - u.Storage = (v.Storage).Copy() - } - u.Directory = v.Directory - if v.Schedule != nil { - u.Schedule = (v.Schedule).Copy() - } - if v.RetainCount != nil { - u.RetainCount = new(uint64) - *u.RetainCount = *v.RetainCount - } - if v.EnableIndexing != nil { - u.EnableIndexing = new(bool) - *u.EnableIndexing = *v.EnableIndexing - } - - return u -} - -func (v *SnapshotService) CopyAsInterface() interface{} { return v.Copy() } +// UnmarshalJSON unmarshals the Monitor from JSON. +func (v *Monitor) UnmarshalJSON(b []byte) error { + return sMonitor.UnmarshalJSON(b, v) +} -func (v *StorageService) Copy() *StorageService { - u := new(StorageService) +type NetworkService struct { + Partition string +} - u.Name = v.Name - if v.Storage != nil { - u.Storage = CopyStorage(v.Storage) - } +func (NetworkService) Type() ServiceType { return ServiceTypeNetwork } - return u +// Copy returns a copy of the NetworkService. +func (v *NetworkService) Copy() *NetworkService { + return sNetworkService.Copy(v) } -func (v *StorageService) CopyAsInterface() interface{} { return v.Copy() } +// EqualNetworkService returns true if V is equal to U. +func (v *NetworkService) Equal(u *NetworkService) bool { + return sNetworkService.Equal(v, u) +} -func (v *SubnodeService) Copy() *SubnodeService { - u := new(SubnodeService) +// MarshalBinary marshals the NetworkService to JSON. +func (v *NetworkService) MarshalJSON() ([]byte, error) { + return sNetworkService.MarshalJSON(v) +} - u.Name = v.Name - if v.NodeKey != nil { - u.NodeKey = CopyPrivateKey(v.NodeKey) - } - u.Services = make([]Service, len(v.Services)) - for i, v := range v.Services { - v := v - if v != nil { - u.Services[i] = CopyService(v) - } - } +// UnmarshalJSON unmarshals the NetworkService from JSON. +func (v *NetworkService) UnmarshalJSON(b []byte) error { + return sNetworkService.UnmarshalJSON(b, v) +} - return u +type OtlpConfig struct { + Enabled *bool + Endpoint string + Username string + Password string } -func (v *SubnodeService) CopyAsInterface() interface{} { return v.Copy() } +// Copy returns a copy of the OtlpConfig. +func (v *OtlpConfig) Copy() *OtlpConfig { + return sOtlpConfig.Copy(v) +} -func (v *Telemetry) Copy() *Telemetry { - u := new(Telemetry) - - if v.Enabled != nil { - u.Enabled = new(bool) - *u.Enabled = *v.Enabled - } - if v.Stdout != nil { - u.Stdout = new(bool) - *u.Stdout = *v.Stdout - } - if v.Otlp != nil { - u.Otlp = (v.Otlp).Copy() - } - if v.Export != nil { - u.Export = (v.Export).Copy() - } - u.Rules = make([]*TelemetryRule, len(v.Rules)) - for i, v := range v.Rules { - v := v - if v != nil { - u.Rules[i] = (v).Copy() - } - } - - return u -} - -func (v *Telemetry) CopyAsInterface() interface{} { return v.Copy() } +// EqualOtlpConfig returns true if V is equal to U. +func (v *OtlpConfig) Equal(u *OtlpConfig) bool { + return sOtlpConfig.Equal(v, u) +} -func (v *TelemetryRule) Copy() *TelemetryRule { - u := new(TelemetryRule) +// MarshalBinary marshals the OtlpConfig to JSON. +func (v *OtlpConfig) MarshalJSON() ([]byte, error) { + return sOtlpConfig.MarshalJSON(v) +} - u.Match = make([]string, len(v.Match)) - for i, v := range v.Match { - v := v - u.Match[i] = v - } - u.Drop = v.Drop - u.Rate = v.Rate +// UnmarshalJSON unmarshals the OtlpConfig from JSON. +func (v *OtlpConfig) UnmarshalJSON(b []byte) error { + return sOtlpConfig.UnmarshalJSON(b, v) +} - return u +type P2P struct { + Listen []p2p.Multiaddr + BootstrapPeers []p2p.Multiaddr + Key PrivateKey + PeerDB *string + EnablePeerTracking bool + DiscoveryMode *DhtMode + External p2p.Multiaddr } -func (v *TelemetryRule) CopyAsInterface() interface{} { return v.Copy() } +// Copy returns a copy of the P2P. +func (v *P2P) Copy() *P2P { + return sP2P.Copy(v) +} -func (v *TransientPrivateKey) Copy() *TransientPrivateKey { - u := new(TransientPrivateKey) +// EqualP2P returns true if V is equal to U. +func (v *P2P) Equal(u *P2P) bool { + return sP2P.Equal(v, u) +} - return u +// MarshalBinary marshals the P2P to JSON. +func (v *P2P) MarshalJSON() ([]byte, error) { + return sP2P.MarshalJSON(v) } -func (v *TransientPrivateKey) CopyAsInterface() interface{} { return v.Copy() } +// UnmarshalJSON unmarshals the P2P from JSON. +func (v *P2P) UnmarshalJSON(b []byte) error { + return sP2P.UnmarshalJSON(b, v) +} -func (v *BadgerStorage) Equal(u *BadgerStorage) bool { - if !(v.Path == u.Path) { - return false - } - if !(v.Version == u.Version) { - return false - } +// TODO type PrivateKey interface {} - return true +// CopyPrivateKey returns a copy of the PrivateKey. +func CopyPrivateKey(v PrivateKey) PrivateKey { + return sPrivateKey.Copy(v) } -func (v *BoltStorage) Equal(u *BoltStorage) bool { - if !(v.Path == u.Path) { - return false - } - - return true +// EqualPrivateKey returns true if A and B are equal. +func EqualPrivateKey(a, b PrivateKey) bool { + return sPrivateKey.Equal(a, b) } -func (v *CometNodeKeyFile) Equal(u *CometNodeKeyFile) bool { - if !(v.Path == u.Path) { - return false - } +// UnmarshalPrivateKeyJSON unmarshals a PrivateKey from JSON. +func UnmarshalPrivateKeyJSON(b []byte) (PrivateKey, error) { + var v PrivateKey + err := sPrivateKey.UnmarshalJSON(b, &v) + return v, err +} - return true +type PrivateKeySeed struct { + Seed *record.Key + key address.Address } -func (v *CometPrivValFile) Equal(u *CometPrivValFile) bool { - if !(v.Path == u.Path) { - return false - } +func (PrivateKeySeed) Type() PrivateKeyType { return PrivateKeyTypeSeed } - return true +// Copy returns a copy of the PrivateKeySeed. +func (v *PrivateKeySeed) Copy() *PrivateKeySeed { + return sPrivateKeySeed.Copy(v) } -func (v *Config) Equal(u *Config) bool { - switch { - case v.DotEnv == u.DotEnv: - // equal - case v.DotEnv == nil || u.DotEnv == nil: - return false - case !(*v.DotEnv == *u.DotEnv): - return false - } - if !(v.Network == u.Network) { - return false - } - switch { - case v.Logging == u.Logging: - // equal - case v.Logging == nil || u.Logging == nil: - return false - case !((v.Logging).Equal(u.Logging)): - return false - } - switch { - case v.Instrumentation == u.Instrumentation: - // equal - case v.Instrumentation == nil || u.Instrumentation == nil: - return false - case !((v.Instrumentation).Equal(u.Instrumentation)): - return false - } - switch { - case v.Telemetry == u.Telemetry: - // equal - case v.Telemetry == nil || u.Telemetry == nil: - return false - case !((v.Telemetry).Equal(u.Telemetry)): - return false - } - switch { - case v.P2P == u.P2P: - // equal - case v.P2P == nil || u.P2P == nil: - return false - case !((v.P2P).Equal(u.P2P)): - return false - } - if len(v.Configurations) != len(u.Configurations) { - return false - } - for i := range v.Configurations { - if !(EqualConfiguration(v.Configurations[i], u.Configurations[i])) { - return false - } - } - if len(v.Services) != len(u.Services) { - return false - } - for i := range v.Services { - if !(EqualService(v.Services[i], u.Services[i])) { - return false - } - } - - return true +// EqualPrivateKeySeed returns true if V is equal to U. +func (v *PrivateKeySeed) Equal(u *PrivateKeySeed) bool { + return sPrivateKeySeed.Equal(v, u) } -func (v *ConsensusService) Equal(u *ConsensusService) bool { - if !(v.NodeDir == u.NodeDir) { - return false - } - if !(EqualPrivateKey(v.ValidatorKey, u.ValidatorKey)) { - return false - } - if !(v.Genesis == u.Genesis) { - return false - } - if !(p2p.EqualMultiaddr(v.Listen, u.Listen)) { - return false - } - if len(v.BootstrapPeers) != len(u.BootstrapPeers) { - return false - } - for i := range v.BootstrapPeers { - if !(p2p.EqualMultiaddr(v.BootstrapPeers[i], u.BootstrapPeers[i])) { - return false - } - } - if !(v.MetricsNamespace == u.MetricsNamespace) { - return false - } - if !(EqualConsensusApp(v.App, u.App)) { - return false - } - - return true +// MarshalBinary marshals the PrivateKeySeed to JSON. +func (v *PrivateKeySeed) MarshalJSON() ([]byte, error) { + return sPrivateKeySeed.MarshalJSON(v) } -func (v *CoreConsensusApp) Equal(u *CoreConsensusApp) bool { - switch { - case v.Partition == u.Partition: - // equal - case v.Partition == nil || u.Partition == nil: - return false - case !((v.Partition).Equal(u.Partition)): - return false - } - switch { - case v.EnableHealing == u.EnableHealing: - // equal - case v.EnableHealing == nil || u.EnableHealing == nil: - return false - case !(*v.EnableHealing == *u.EnableHealing): - return false - } - switch { - case v.EnableDirectDispatch == u.EnableDirectDispatch: - // equal - case v.EnableDirectDispatch == nil || u.EnableDirectDispatch == nil: - return false - case !(*v.EnableDirectDispatch == *u.EnableDirectDispatch): - return false - } - switch { - case v.MaxEnvelopesPerBlock == u.MaxEnvelopesPerBlock: - // equal - case v.MaxEnvelopesPerBlock == nil || u.MaxEnvelopesPerBlock == nil: - return false - case !(*v.MaxEnvelopesPerBlock == *u.MaxEnvelopesPerBlock): - return false - } - - return true +// UnmarshalJSON unmarshals the PrivateKeySeed from JSON. +func (v *PrivateKeySeed) UnmarshalJSON(b []byte) error { + return sPrivateKeySeed.UnmarshalJSON(b, v) } -func (v *CoreValidatorConfiguration) Equal(u *CoreValidatorConfiguration) bool { - if !(v.Mode == u.Mode) { - return false - } - if !(p2p.EqualMultiaddr(v.Listen, u.Listen)) { - return false - } - if !(v.BVN == u.BVN) { - return false - } - if !(EqualPrivateKey(v.ValidatorKey, u.ValidatorKey)) { - return false - } - if !(v.DnGenesis == u.DnGenesis) { - return false - } - if !(v.BvnGenesis == u.BvnGenesis) { - return false - } - if len(v.DnBootstrapPeers) != len(u.DnBootstrapPeers) { - return false - } - for i := range v.DnBootstrapPeers { - if !(p2p.EqualMultiaddr(v.DnBootstrapPeers[i], u.DnBootstrapPeers[i])) { - return false - } - } - if len(v.BvnBootstrapPeers) != len(u.BvnBootstrapPeers) { - return false - } - for i := range v.BvnBootstrapPeers { - if !(p2p.EqualMultiaddr(v.BvnBootstrapPeers[i], u.BvnBootstrapPeers[i])) { - return false - } - } - switch { - case v.EnableHealing == u.EnableHealing: - // equal - case v.EnableHealing == nil || u.EnableHealing == nil: - return false - case !(*v.EnableHealing == *u.EnableHealing): - return false - } - switch { - case v.EnableDirectDispatch == u.EnableDirectDispatch: - // equal - case v.EnableDirectDispatch == nil || u.EnableDirectDispatch == nil: - return false - case !(*v.EnableDirectDispatch == *u.EnableDirectDispatch): - return false - } - switch { - case v.EnableSnapshots == u.EnableSnapshots: - // equal - case v.EnableSnapshots == nil || u.EnableSnapshots == nil: - return false - case !(*v.EnableSnapshots == *u.EnableSnapshots): - return false - } - switch { - case v.MaxEnvelopesPerBlock == u.MaxEnvelopesPerBlock: - // equal - case v.MaxEnvelopesPerBlock == nil || u.MaxEnvelopesPerBlock == nil: - return false - case !(*v.MaxEnvelopesPerBlock == *u.MaxEnvelopesPerBlock): - return false - } - switch { - case v.StorageType == u.StorageType: - // equal - case v.StorageType == nil || u.StorageType == nil: - return false - case !(*v.StorageType == *u.StorageType): - return false - } - - return true -} +type PrivateKeyType int64 -func (v *DevnetConfiguration) Equal(u *DevnetConfiguration) bool { - if !(p2p.EqualMultiaddr(v.Listen, u.Listen)) { - return false - } - if !(v.Bvns == u.Bvns) { - return false - } - if !(v.Validators == u.Validators) { - return false - } - if !(v.Followers == u.Followers) { - return false - } - switch { - case v.Globals == u.Globals: - // equal - case v.Globals == nil || u.Globals == nil: - return false - case !((v.Globals).Equal(u.Globals)): - return false - } - switch { - case v.StorageType == u.StorageType: - // equal - case v.StorageType == nil || u.StorageType == nil: - return false - case !(*v.StorageType == *u.StorageType): - return false - } - - return true +const ( + PrivateKeyTypeCometNodeKeyFile PrivateKeyType = 5 + PrivateKeyTypeCometPrivValFile PrivateKeyType = 4 + PrivateKeyTypeRaw PrivateKeyType = 1 + PrivateKeyTypeSeed PrivateKeyType = 3 + PrivateKeyTypeTransient PrivateKeyType = 2 +) + +// SetByName looks up a PrivateKeyType by name. +func (v *PrivateKeyType) SetByName(s string) (ok bool) { + *v, ok = sPrivateKeyType.ByName(s) + return } -func (v *EventsService) Equal(u *EventsService) bool { - if !(v.Partition == u.Partition) { - return false - } +// SetByValue looks up a PrivateKeyType by value. +func (v *PrivateKeyType) SetByValue(i int64) (ok bool) { + *v, ok = sPrivateKeyType.ByValue(i) + return +} - return true +// String returns the label or name of the PrivateKeyType. +func (v PrivateKeyType) String() string { + return sPrivateKeyType.String(v) } -func (v *ExpBlockDBStorage) Equal(u *ExpBlockDBStorage) bool { - if !(v.Path == u.Path) { - return false - } +// MarshalBinary marshals the PrivateKeyType to JSON. +func (v PrivateKeyType) MarshalJSON() ([]byte, error) { + return sPrivateKeyType.MarshalJSON(v) +} - return true +// UnmarshalJSON unmarshals the PrivateKeyType from JSON. +func (v *PrivateKeyType) UnmarshalJSON(b []byte) error { + return sPrivateKeyType.UnmarshalJSON(b, v) } -func (v *FaucetService) Equal(u *FaucetService) bool { - switch { - case v.Account == u.Account: - // equal - case v.Account == nil || u.Account == nil: - return false - case !((v.Account).Equal(u.Account)): - return false - } - if !(EqualPrivateKey(v.SigningKey, u.SigningKey)) { - return false - } - switch { - case v.Router == u.Router: - // equal - case v.Router == nil || u.Router == nil: - return false - case !((v.Router).Equal(u.Router)): - return false - } - - return true +type Querier struct { + Partition string + Storage *StorageOrRef } -func (v *GatewayConfiguration) Equal(u *GatewayConfiguration) bool { - if !(p2p.EqualMultiaddr(v.Listen, u.Listen)) { - return false - } +func (Querier) Type() ServiceType { return ServiceTypeQuerier } - return true +// Copy returns a copy of the Querier. +func (v *Querier) Copy() *Querier { + return sQuerier.Copy(v) } -func (v *HttpListener) Equal(u *HttpListener) bool { - if len(v.Listen) != len(u.Listen) { - return false - } - for i := range v.Listen { - if !(p2p.EqualMultiaddr(v.Listen[i], u.Listen[i])) { - return false - } - } - switch { - case v.ConnectionLimit == u.ConnectionLimit: - // equal - case v.ConnectionLimit == nil || u.ConnectionLimit == nil: - return false - case !(*v.ConnectionLimit == *u.ConnectionLimit): - return false - } - switch { - case v.ReadHeaderTimeout == u.ReadHeaderTimeout: - // equal - case v.ReadHeaderTimeout == nil || u.ReadHeaderTimeout == nil: - return false - case !(*v.ReadHeaderTimeout == *u.ReadHeaderTimeout): - return false - } - if !(v.TlsCertPath == u.TlsCertPath) { - return false - } - if !(v.TlsKeyPath == u.TlsKeyPath) { - return false - } - - return true +// EqualQuerier returns true if V is equal to U. +func (v *Querier) Equal(u *Querier) bool { + return sQuerier.Equal(v, u) } -func (v *HttpPeerMapEntry) Equal(u *HttpPeerMapEntry) bool { - if !(p2p.EqualPeerID(v.ID, u.ID)) { - return false - } - if len(v.Partitions) != len(u.Partitions) { - return false - } - for i := range v.Partitions { - if !(v.Partitions[i] == u.Partitions[i]) { - return false - } - } - if len(v.Addresses) != len(u.Addresses) { - return false - } - for i := range v.Addresses { - if !(p2p.EqualMultiaddr(v.Addresses[i], u.Addresses[i])) { - return false - } - } - - return true +// MarshalBinary marshals the Querier to JSON. +func (v *Querier) MarshalJSON() ([]byte, error) { + return sQuerier.MarshalJSON(v) } -func (v *HttpService) Equal(u *HttpService) bool { - if !v.HttpListener.Equal(&u.HttpListener) { - return false - } - if len(v.CorsOrigins) != len(u.CorsOrigins) { - return false - } - for i := range v.CorsOrigins { - if !(v.CorsOrigins[i] == u.CorsOrigins[i]) { - return false - } - } - if len(v.LetsEncrypt) != len(u.LetsEncrypt) { - return false - } - for i := range v.LetsEncrypt { - if !(v.LetsEncrypt[i] == u.LetsEncrypt[i]) { - return false - } - } - switch { - case v.DebugJsonRpc == u.DebugJsonRpc: - // equal - case v.DebugJsonRpc == nil || u.DebugJsonRpc == nil: - return false - case !(*v.DebugJsonRpc == *u.DebugJsonRpc): - return false - } - switch { - case v.Router == u.Router: - // equal - case v.Router == nil || u.Router == nil: - return false - case !((v.Router).Equal(u.Router)): - return false - } - if len(v.PeerMap) != len(u.PeerMap) { - return false - } - for i := range v.PeerMap { - if !((v.PeerMap[i]).Equal(u.PeerMap[i])) { - return false - } - } - - return true +// UnmarshalJSON unmarshals the Querier from JSON. +func (v *Querier) UnmarshalJSON(b []byte) error { + return sQuerier.UnmarshalJSON(b, v) } -func (v *Instrumentation) Equal(u *Instrumentation) bool { - if !v.HttpListener.Equal(&u.HttpListener) { - return false - } - switch { - case v.Monitoring == u.Monitoring: - // equal - case v.Monitoring == nil || u.Monitoring == nil: - return false - case !((v.Monitoring).Equal(u.Monitoring)): - return false - } - if !(p2p.EqualMultiaddr(v.PprofListen, u.PprofListen)) { - return false - } - - return true +type RawPrivateKey struct { + Address string } -func (v *LevelDBStorage) Equal(u *LevelDBStorage) bool { - if !(v.Path == u.Path) { - return false - } +func (RawPrivateKey) Type() PrivateKeyType { return PrivateKeyTypeRaw } - return true +// Copy returns a copy of the RawPrivateKey. +func (v *RawPrivateKey) Copy() *RawPrivateKey { + return sRawPrivateKey.Copy(v) } -func (v *Logging) Equal(u *Logging) bool { - if !(v.Format == u.Format) { - return false - } - switch { - case v.Color == u.Color: - // equal - case v.Color == nil || u.Color == nil: - return false - case !(*v.Color == *u.Color): - return false - } - if len(v.Rules) != len(u.Rules) { - return false - } - for i := range v.Rules { - if !((v.Rules[i]).Equal(u.Rules[i])) { - return false - } - } - switch { - case v.Loki == u.Loki: - // equal - case v.Loki == nil || u.Loki == nil: - return false - case !((v.Loki).Equal(u.Loki)): - return false - } - - return true +// EqualRawPrivateKey returns true if V is equal to U. +func (v *RawPrivateKey) Equal(u *RawPrivateKey) bool { + return sRawPrivateKey.Equal(v, u) } -func (v *LoggingRule) Equal(u *LoggingRule) bool { - if !(v.Level == u.Level) { - return false - } - if len(v.Modules) != len(u.Modules) { - return false - } - for i := range v.Modules { - if !(v.Modules[i] == u.Modules[i]) { - return false - } - } +// MarshalBinary marshals the RawPrivateKey to JSON. +func (v *RawPrivateKey) MarshalJSON() ([]byte, error) { + return sRawPrivateKey.MarshalJSON(v) +} - return true +// UnmarshalJSON unmarshals the RawPrivateKey from JSON. +func (v *RawPrivateKey) UnmarshalJSON(b []byte) error { + return sRawPrivateKey.UnmarshalJSON(b, v) } -func (v *LokiLogging) Equal(u *LokiLogging) bool { - if !(v.Enable == u.Enable) { - return false - } - if !(v.Url == u.Url) { - return false - } - if !(v.Username == u.Username) { - return false - } - if !(v.Password == u.Password) { - return false - } - - return true +type RouterService struct { + Name string + // Events may specify an event bus to use for routing table updates. + Events string + // PeerMap uses a hard-coded peer map for initializing routing. + PeerMap []*HttpPeerMapEntry } -func (v *MemoryStorage) Equal(u *MemoryStorage) bool { +func (RouterService) Type() ServiceType { return ServiceTypeRouter } - return true +// Copy returns a copy of the RouterService. +func (v *RouterService) Copy() *RouterService { + return sRouterService.Copy(v) } -func (v *MetricsService) Equal(u *MetricsService) bool { - if !(v.Partition == u.Partition) { - return false - } +// EqualRouterService returns true if V is equal to U. +func (v *RouterService) Equal(u *RouterService) bool { + return sRouterService.Equal(v, u) +} - return true +// MarshalBinary marshals the RouterService to JSON. +func (v *RouterService) MarshalJSON() ([]byte, error) { + return sRouterService.MarshalJSON(v) } -func (v *Monitor) Equal(u *Monitor) bool { - if !(v.Directory == u.Directory) { - return false - } - switch { - case v.ProfileMemory == u.ProfileMemory: - // equal - case v.ProfileMemory == nil || u.ProfileMemory == nil: - return false - case !(*v.ProfileMemory == *u.ProfileMemory): - return false - } - switch { - case v.MemoryPollingRate == u.MemoryPollingRate: - // equal - case v.MemoryPollingRate == nil || u.MemoryPollingRate == nil: - return false - case !(*v.MemoryPollingRate == *u.MemoryPollingRate): - return false - } - switch { - case v.AllocRateTrigger == u.AllocRateTrigger: - // equal - case v.AllocRateTrigger == nil || u.AllocRateTrigger == nil: - return false - case !(*v.AllocRateTrigger == *u.AllocRateTrigger): - return false - } - - return true +// UnmarshalJSON unmarshals the RouterService from JSON. +func (v *RouterService) UnmarshalJSON(b []byte) error { + return sRouterService.UnmarshalJSON(b, v) } -func (v *NetworkService) Equal(u *NetworkService) bool { - if !(v.Partition == u.Partition) { - return false - } +// TODO type Service interface {} - return true +// CopyService returns a copy of the Service. +func CopyService(v Service) Service { + return sService.Copy(v) } -func (v *OtlpConfig) Equal(u *OtlpConfig) bool { - switch { - case v.Enabled == u.Enabled: - // equal - case v.Enabled == nil || u.Enabled == nil: - return false - case !(*v.Enabled == *u.Enabled): - return false - } - if !(v.Endpoint == u.Endpoint) { - return false - } - if !(v.Username == u.Username) { - return false - } - if !(v.Password == u.Password) { - return false - } - - return true +// EqualService returns true if A and B are equal. +func EqualService(a, b Service) bool { + return sService.Equal(a, b) } -func (v *P2P) Equal(u *P2P) bool { - if len(v.Listen) != len(u.Listen) { - return false - } - for i := range v.Listen { - if !(p2p.EqualMultiaddr(v.Listen[i], u.Listen[i])) { - return false - } - } - if len(v.BootstrapPeers) != len(u.BootstrapPeers) { - return false - } - for i := range v.BootstrapPeers { - if !(p2p.EqualMultiaddr(v.BootstrapPeers[i], u.BootstrapPeers[i])) { - return false - } - } - if !(EqualPrivateKey(v.Key, u.Key)) { - return false - } - switch { - case v.PeerDB == u.PeerDB: - // equal - case v.PeerDB == nil || u.PeerDB == nil: - return false - case !(*v.PeerDB == *u.PeerDB): - return false - } - if !(v.EnablePeerTracking == u.EnablePeerTracking) { - return false - } - switch { - case v.DiscoveryMode == u.DiscoveryMode: - // equal - case v.DiscoveryMode == nil || u.DiscoveryMode == nil: - return false - case !(*v.DiscoveryMode == *u.DiscoveryMode): - return false - } - if !(p2p.EqualMultiaddr(v.External, u.External)) { - return false - } - - return true +// UnmarshalServiceJSON unmarshals a Service from JSON. +func UnmarshalServiceJSON(b []byte) (Service, error) { + var v Service + err := sService.UnmarshalJSON(b, &v) + return v, err } -func (v *PrivateKeySeed) Equal(u *PrivateKeySeed) bool { - switch { - case v.Seed == u.Seed: - // equal - case v.Seed == nil || u.Seed == nil: - return false - case !((v.Seed).Equal(u.Seed)): - return false - } +type ServiceType int64 - return true -} +const ( + ServiceTypeConsensus ServiceType = 2 + ServiceTypeEvents ServiceType = 6 + ServiceTypeFaucet ServiceType = 10 + ServiceTypeHttp ServiceType = 7 + ServiceTypeMetrics ServiceType = 5 + ServiceTypeNetwork ServiceType = 4 + ServiceTypeQuerier ServiceType = 3 + ServiceTypeRouter ServiceType = 8 + ServiceTypeSnapshot ServiceType = 9 + ServiceTypeStorage ServiceType = 1 + ServiceTypeSubnode ServiceType = 11 +) -func (v *Querier) Equal(u *Querier) bool { - if !(v.Partition == u.Partition) { - return false - } - switch { - case v.Storage == u.Storage: - // equal - case v.Storage == nil || u.Storage == nil: - return false - case !((v.Storage).Equal(u.Storage)): - return false - } +// SetByName looks up a ServiceType by name. +func (v *ServiceType) SetByName(s string) (ok bool) { + *v, ok = sServiceType.ByName(s) + return +} - return true +// SetByValue looks up a ServiceType by value. +func (v *ServiceType) SetByValue(i int64) (ok bool) { + *v, ok = sServiceType.ByValue(i) + return } -func (v *RawPrivateKey) Equal(u *RawPrivateKey) bool { - if !(v.Address == u.Address) { - return false - } +// String returns the label or name of the ServiceType. +func (v ServiceType) String() string { + return sServiceType.String(v) +} - return true +// MarshalBinary marshals the ServiceType to JSON. +func (v ServiceType) MarshalJSON() ([]byte, error) { + return sServiceType.MarshalJSON(v) } -func (v *RouterService) Equal(u *RouterService) bool { - if !(v.Name == u.Name) { - return false - } - if !(v.Events == u.Events) { - return false - } - if len(v.PeerMap) != len(u.PeerMap) { - return false - } - for i := range v.PeerMap { - if !((v.PeerMap[i]).Equal(u.PeerMap[i])) { - return false - } - } - - return true +// UnmarshalJSON unmarshals the ServiceType from JSON. +func (v *ServiceType) UnmarshalJSON(b []byte) error { + return sServiceType.UnmarshalJSON(b, v) } -func (v *SnapshotService) Equal(u *SnapshotService) bool { - if !(v.Partition == u.Partition) { - return false - } - switch { - case v.Storage == u.Storage: - // equal - case v.Storage == nil || u.Storage == nil: - return false - case !((v.Storage).Equal(u.Storage)): - return false - } - if !(v.Directory == u.Directory) { - return false - } - switch { - case v.Schedule == u.Schedule: - // equal - case v.Schedule == nil || u.Schedule == nil: - return false - case !((v.Schedule).Equal(u.Schedule)): - return false - } - switch { - case v.RetainCount == u.RetainCount: - // equal - case v.RetainCount == nil || u.RetainCount == nil: - return false - case !(*v.RetainCount == *u.RetainCount): - return false - } - switch { - case v.EnableIndexing == u.EnableIndexing: - // equal - case v.EnableIndexing == nil || u.EnableIndexing == nil: - return false - case !(*v.EnableIndexing == *u.EnableIndexing): - return false - } - - return true +type SnapshotService struct { + Partition string + Storage *StorageOrRef + // Directory is the directory to store snapshots in. + Directory string + // Schedule is the schedule for capturing snapshots. + Schedule *network.CronSchedule + // RetainCount is the number of snapshots to retain. + RetainCount *uint64 + // EnableIndexing enables indexing of snapshots. + EnableIndexing *bool } -func (v *StorageService) Equal(u *StorageService) bool { - if !(v.Name == u.Name) { - return false - } - if !(EqualStorage(v.Storage, u.Storage)) { - return false - } +func (SnapshotService) Type() ServiceType { return ServiceTypeSnapshot } - return true +// Copy returns a copy of the SnapshotService. +func (v *SnapshotService) Copy() *SnapshotService { + return sSnapshotService.Copy(v) } -func (v *SubnodeService) Equal(u *SubnodeService) bool { - if !(v.Name == u.Name) { - return false - } - if !(EqualPrivateKey(v.NodeKey, u.NodeKey)) { - return false - } - if len(v.Services) != len(u.Services) { - return false - } - for i := range v.Services { - if !(EqualService(v.Services[i], u.Services[i])) { - return false - } - } - - return true +// EqualSnapshotService returns true if V is equal to U. +func (v *SnapshotService) Equal(u *SnapshotService) bool { + return sSnapshotService.Equal(v, u) } -func (v *Telemetry) Equal(u *Telemetry) bool { - switch { - case v.Enabled == u.Enabled: - // equal - case v.Enabled == nil || u.Enabled == nil: - return false - case !(*v.Enabled == *u.Enabled): - return false - } - switch { - case v.Stdout == u.Stdout: - // equal - case v.Stdout == nil || u.Stdout == nil: - return false - case !(*v.Stdout == *u.Stdout): - return false - } - switch { - case v.Otlp == u.Otlp: - // equal - case v.Otlp == nil || u.Otlp == nil: - return false - case !((v.Otlp).Equal(u.Otlp)): - return false - } - switch { - case v.Export == u.Export: - // equal - case v.Export == nil || u.Export == nil: - return false - case !((v.Export).Equal(u.Export)): - return false - } - if len(v.Rules) != len(u.Rules) { - return false - } - for i := range v.Rules { - if !((v.Rules[i]).Equal(u.Rules[i])) { - return false - } - } - - return true +// MarshalBinary marshals the SnapshotService to JSON. +func (v *SnapshotService) MarshalJSON() ([]byte, error) { + return sSnapshotService.MarshalJSON(v) } -func (v *TelemetryRule) Equal(u *TelemetryRule) bool { - if len(v.Match) != len(u.Match) { - return false - } - for i := range v.Match { - if !(v.Match[i] == u.Match[i]) { - return false - } - } - if !(v.Drop == u.Drop) { - return false - } - if !(v.Rate == u.Rate) { - return false - } - - return true +// UnmarshalJSON unmarshals the SnapshotService from JSON. +func (v *SnapshotService) UnmarshalJSON(b []byte) error { + return sSnapshotService.UnmarshalJSON(b, v) } -func (v *TransientPrivateKey) Equal(u *TransientPrivateKey) bool { +// TODO type Storage interface {} - return true -} - -var fieldNames_HttpPeerMapEntry = []string{ - 1: "ID", - 2: "Partitions", - 3: "Addresses", -} - -func (v *HttpPeerMapEntry) MarshalBinary() ([]byte, error) { - if v == nil { - return []byte{encoding.EmptyObject}, nil - } - - buffer := new(bytes.Buffer) - writer := encoding.NewWriter(buffer) - - if !(v.ID == ("")) { - writer.WriteValue(1, v.ID.MarshalBinary) - } - if !(len(v.Partitions) == 0) { - for _, v := range v.Partitions { - writer.WriteString(2, v) - } - } - if !(len(v.Addresses) == 0) { - for _, v := range v.Addresses { - writer.WriteValue(3, v.MarshalBinary) - } - } - - _, _, err := writer.Reset(fieldNames_HttpPeerMapEntry) - if err != nil { - return nil, encoding.Error{E: err} - } - buffer.Write(v.extraData) - return buffer.Bytes(), nil -} - -func (v *HttpPeerMapEntry) IsValid() error { - var errs []string - - if len(v.fieldsSet) > 0 && !v.fieldsSet[0] { - errs = append(errs, "field ID is missing") - } else if v.ID == ("") { - errs = append(errs, "field ID is not set") - } - if len(v.fieldsSet) > 1 && !v.fieldsSet[1] { - errs = append(errs, "field Partitions is missing") - } else if len(v.Partitions) == 0 { - errs = append(errs, "field Partitions is not set") - } - if len(v.fieldsSet) > 2 && !v.fieldsSet[2] { - errs = append(errs, "field Addresses is missing") - } else if len(v.Addresses) == 0 { - errs = append(errs, "field Addresses is not set") - } - - switch len(errs) { - case 0: - return nil - case 1: - return errors.New(errs[0]) - default: - return errors.New(strings.Join(errs, "; ")) - } -} - -var fieldNames_RouterService = []string{ - 1: "Type", - 2: "Name", - 3: "Events", - 4: "PeerMap", -} - -func (v *RouterService) MarshalBinary() ([]byte, error) { - if v == nil { - return []byte{encoding.EmptyObject}, nil - } - - buffer := new(bytes.Buffer) - writer := encoding.NewWriter(buffer) - - writer.WriteEnum(1, v.Type()) - if !(len(v.Name) == 0) { - writer.WriteString(2, v.Name) - } - if !(len(v.Events) == 0) { - writer.WriteString(3, v.Events) - } - if !(len(v.PeerMap) == 0) { - for _, v := range v.PeerMap { - writer.WriteValue(4, v.MarshalBinary) - } - } - - _, _, err := writer.Reset(fieldNames_RouterService) - if err != nil { - return nil, encoding.Error{E: err} - } - buffer.Write(v.extraData) - return buffer.Bytes(), nil -} - -func (v *RouterService) IsValid() error { - var errs []string - - if len(v.fieldsSet) > 0 && !v.fieldsSet[0] { - errs = append(errs, "field Type is missing") - } - if len(v.fieldsSet) > 3 && !v.fieldsSet[3] { - errs = append(errs, "field PeerMap is missing") - } else if len(v.PeerMap) == 0 { - errs = append(errs, "field PeerMap is not set") - } - - switch len(errs) { - case 0: - return nil - case 1: - return errors.New(errs[0]) - default: - return errors.New(strings.Join(errs, "; ")) - } -} - -func (v *HttpPeerMapEntry) UnmarshalBinary(data []byte) error { - return v.UnmarshalBinaryFrom(bytes.NewReader(data)) -} - -func (v *HttpPeerMapEntry) UnmarshalBinaryFrom(rd io.Reader) error { - reader := encoding.NewReader(rd) - - reader.ReadValue(1, func(r io.Reader) error { - x, err := p2p.UnmarshalPeerIDFrom(r) - if err == nil { - v.ID = x - } - return err - }) - for { - if x, ok := reader.ReadString(2); ok { - v.Partitions = append(v.Partitions, x) - } else { - break - } - } - for { - ok := reader.ReadValue(3, func(r io.Reader) error { - x, err := p2p.UnmarshalMultiaddrFrom(r) - if err == nil { - v.Addresses = append(v.Addresses, x) - } - return err - }) - if !ok { - break - } - } - - seen, err := reader.Reset(fieldNames_HttpPeerMapEntry) - if err != nil { - return encoding.Error{E: err} - } - v.fieldsSet = seen - v.extraData, err = reader.ReadAll() - if err != nil { - return encoding.Error{E: err} - } - return nil -} - -func (v *RouterService) UnmarshalBinary(data []byte) error { - return v.UnmarshalBinaryFrom(bytes.NewReader(data)) -} - -func (v *RouterService) UnmarshalBinaryFrom(rd io.Reader) error { - reader := encoding.NewReader(rd) - - var vType ServiceType - if x := new(ServiceType); reader.ReadEnum(1, x) { - vType = *x - } - if !(v.Type() == vType) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), vType) - } - - return v.UnmarshalFieldsFrom(reader) -} - -func (v *RouterService) UnmarshalFieldsFrom(reader *encoding.Reader) error { - if x, ok := reader.ReadString(2); ok { - v.Name = x - } - if x, ok := reader.ReadString(3); ok { - v.Events = x - } - for { - if x := new(HttpPeerMapEntry); reader.ReadValue(4, x.UnmarshalBinaryFrom) { - v.PeerMap = append(v.PeerMap, x) - } else { - break - } - } - - seen, err := reader.Reset(fieldNames_RouterService) - if err != nil { - return encoding.Error{E: err} - } - v.fieldsSet = seen - v.extraData, err = reader.ReadAll() - if err != nil { - return encoding.Error{E: err} - } - return nil +// CopyStorage returns a copy of the Storage. +func CopyStorage(v Storage) Storage { + return sStorage.Copy(v) } -func (v *BadgerStorage) MarshalJSON() ([]byte, error) { - u := struct { - Type StorageType `json:"type"` - Path string `json:"path,omitempty"` - Version int64 `json:"version,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Path) == 0) { - u.Path = v.Path - } - if !(v.Version == 0) { - u.Version = v.Version - } - return json.Marshal(&u) +// EqualStorage returns true if A and B are equal. +func EqualStorage(a, b Storage) bool { + return sStorage.Equal(a, b) } -func (v *BoltStorage) MarshalJSON() ([]byte, error) { - u := struct { - Type StorageType `json:"type"` - Path string `json:"path,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Path) == 0) { - u.Path = v.Path - } - return json.Marshal(&u) +// UnmarshalStorageJSON unmarshals a Storage from JSON. +func UnmarshalStorageJSON(b []byte) (Storage, error) { + var v Storage + err := sStorage.UnmarshalJSON(b, &v) + return v, err } -func (v *CometNodeKeyFile) MarshalJSON() ([]byte, error) { - u := struct { - Type PrivateKeyType `json:"type"` - Path string `json:"path,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Path) == 0) { - u.Path = v.Path - } - return json.Marshal(&u) +type StorageService struct { + Name string + Storage Storage } -func (v *CometPrivValFile) MarshalJSON() ([]byte, error) { - u := struct { - Type PrivateKeyType `json:"type"` - Path string `json:"path,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Path) == 0) { - u.Path = v.Path - } - return json.Marshal(&u) -} +func (StorageService) Type() ServiceType { return ServiceTypeStorage } -func (v *Config) MarshalJSON() ([]byte, error) { - u := struct { - DotEnv *bool `json:"dotEnv,omitempty"` - Network string `json:"network,omitempty"` - Logging *Logging `json:"logging,omitempty"` - Instrumentation *Instrumentation `json:"instrumentation,omitempty"` - Telemetry *Telemetry `json:"telemetry,omitempty"` - P2P *P2P `json:"p2P,omitempty"` - Configurations *encoding.JsonUnmarshalListWith[Configuration] `json:"configurations,omitempty"` - Services *encoding.JsonUnmarshalListWith[Service] `json:"services,omitempty"` - }{} - if !(v.DotEnv == nil) { - u.DotEnv = v.DotEnv - } - if !(len(v.Network) == 0) { - u.Network = v.Network - } - if !(v.Logging == nil) { - u.Logging = v.Logging - } - if !(v.Instrumentation == nil) { - u.Instrumentation = v.Instrumentation - } - if !(v.Telemetry == nil) { - u.Telemetry = v.Telemetry - } - if !(v.P2P == nil) { - u.P2P = v.P2P - } - if !(len(v.Configurations) == 0) { - u.Configurations = &encoding.JsonUnmarshalListWith[Configuration]{Value: v.Configurations, Func: UnmarshalConfigurationJSON} - } - if !(len(v.Services) == 0) { - u.Services = &encoding.JsonUnmarshalListWith[Service]{Value: v.Services, Func: UnmarshalServiceJSON} - } - return json.Marshal(&u) +// Copy returns a copy of the StorageService. +func (v *StorageService) Copy() *StorageService { + return sStorageService.Copy(v) } -func (v *ConsensusService) MarshalJSON() ([]byte, error) { - u := struct { - Type ServiceType `json:"type"` - NodeDir string `json:"nodeDir,omitempty"` - ValidatorKey *encoding.JsonUnmarshalWith[PrivateKey] `json:"validatorKey,omitempty"` - Genesis string `json:"genesis,omitempty"` - Listen *encoding.JsonUnmarshalWith[p2p.Multiaddr] `json:"listen,omitempty"` - BootstrapPeers *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"bootstrapPeers,omitempty"` - MetricsNamespace string `json:"metricsNamespace,omitempty"` - App *encoding.JsonUnmarshalWith[ConsensusApp] `json:"app,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.NodeDir) == 0) { - u.NodeDir = v.NodeDir - } - if !(EqualPrivateKey(v.ValidatorKey, nil)) { - u.ValidatorKey = &encoding.JsonUnmarshalWith[PrivateKey]{Value: v.ValidatorKey, Func: UnmarshalPrivateKeyJSON} - } - if !(len(v.Genesis) == 0) { - u.Genesis = v.Genesis - } - if !(p2p.EqualMultiaddr(v.Listen, nil)) { - u.Listen = &encoding.JsonUnmarshalWith[p2p.Multiaddr]{Value: v.Listen, Func: p2p.UnmarshalMultiaddrJSON} - } - if !(len(v.BootstrapPeers) == 0) { - u.BootstrapPeers = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.BootstrapPeers, Func: p2p.UnmarshalMultiaddrJSON} - } - if !(len(v.MetricsNamespace) == 0) { - u.MetricsNamespace = v.MetricsNamespace - } - if !(EqualConsensusApp(v.App, nil)) { - u.App = &encoding.JsonUnmarshalWith[ConsensusApp]{Value: v.App, Func: UnmarshalConsensusAppJSON} - } - return json.Marshal(&u) +// EqualStorageService returns true if V is equal to U. +func (v *StorageService) Equal(u *StorageService) bool { + return sStorageService.Equal(v, u) } -func (v *CoreConsensusApp) MarshalJSON() ([]byte, error) { - u := struct { - Type ConsensusAppType `json:"type"` - Partition *protocol.PartitionInfo `json:"partition,omitempty"` - EnableHealing *bool `json:"enableHealing,omitempty"` - EnableDirectDispatch *bool `json:"enableDirectDispatch,omitempty"` - MaxEnvelopesPerBlock *uint64 `json:"maxEnvelopesPerBlock,omitempty"` - }{} - u.Type = v.Type() - if !(v.Partition == nil) { - u.Partition = v.Partition - } - if !(v.EnableHealing == nil) { - u.EnableHealing = v.EnableHealing - } - if !(v.EnableDirectDispatch == nil) { - u.EnableDirectDispatch = v.EnableDirectDispatch - } - if !(v.MaxEnvelopesPerBlock == nil) { - u.MaxEnvelopesPerBlock = v.MaxEnvelopesPerBlock - } - return json.Marshal(&u) +// MarshalBinary marshals the StorageService to JSON. +func (v *StorageService) MarshalJSON() ([]byte, error) { + return sStorageService.MarshalJSON(v) } -func (v *CoreValidatorConfiguration) MarshalJSON() ([]byte, error) { - u := struct { - Type ConfigurationType `json:"type"` - Mode CoreValidatorMode `json:"mode,omitempty"` - Listen *encoding.JsonUnmarshalWith[p2p.Multiaddr] `json:"listen,omitempty"` - BVN string `json:"bvn,omitempty"` - ValidatorKey *encoding.JsonUnmarshalWith[PrivateKey] `json:"validatorKey,omitempty"` - DnGenesis string `json:"dnGenesis,omitempty"` - BvnGenesis string `json:"bvnGenesis,omitempty"` - DnBootstrapPeers *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"dnBootstrapPeers,omitempty"` - BvnBootstrapPeers *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"bvnBootstrapPeers,omitempty"` - EnableHealing *bool `json:"enableHealing,omitempty"` - EnableDirectDispatch *bool `json:"enableDirectDispatch,omitempty"` - EnableSnapshots *bool `json:"enableSnapshots,omitempty"` - MaxEnvelopesPerBlock *uint64 `json:"maxEnvelopesPerBlock,omitempty"` - StorageType *StorageType `json:"storageType,omitempty"` - }{} - u.Type = v.Type() - if !(v.Mode == 0) { - u.Mode = v.Mode - } - if !(p2p.EqualMultiaddr(v.Listen, nil)) { - u.Listen = &encoding.JsonUnmarshalWith[p2p.Multiaddr]{Value: v.Listen, Func: p2p.UnmarshalMultiaddrJSON} - } - if !(len(v.BVN) == 0) { - u.BVN = v.BVN - } - if !(EqualPrivateKey(v.ValidatorKey, nil)) { - u.ValidatorKey = &encoding.JsonUnmarshalWith[PrivateKey]{Value: v.ValidatorKey, Func: UnmarshalPrivateKeyJSON} - } - if !(len(v.DnGenesis) == 0) { - u.DnGenesis = v.DnGenesis - } - if !(len(v.BvnGenesis) == 0) { - u.BvnGenesis = v.BvnGenesis - } - if !(len(v.DnBootstrapPeers) == 0) { - u.DnBootstrapPeers = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.DnBootstrapPeers, Func: p2p.UnmarshalMultiaddrJSON} - } - if !(len(v.BvnBootstrapPeers) == 0) { - u.BvnBootstrapPeers = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.BvnBootstrapPeers, Func: p2p.UnmarshalMultiaddrJSON} - } - if !(v.EnableHealing == nil) { - u.EnableHealing = v.EnableHealing - } - if !(v.EnableDirectDispatch == nil) { - u.EnableDirectDispatch = v.EnableDirectDispatch - } - if !(v.EnableSnapshots == nil) { - u.EnableSnapshots = v.EnableSnapshots - } - if !(v.MaxEnvelopesPerBlock == nil) { - u.MaxEnvelopesPerBlock = v.MaxEnvelopesPerBlock - } - if !(v.StorageType == nil) { - u.StorageType = v.StorageType - } - return json.Marshal(&u) +// UnmarshalJSON unmarshals the StorageService from JSON. +func (v *StorageService) UnmarshalJSON(b []byte) error { + return sStorageService.UnmarshalJSON(b, v) } -func (v *DevnetConfiguration) MarshalJSON() ([]byte, error) { - u := struct { - Type ConfigurationType `json:"type"` - Listen *encoding.JsonUnmarshalWith[p2p.Multiaddr] `json:"listen,omitempty"` - Bvns uint64 `json:"bvns,omitempty"` - Validators uint64 `json:"validators,omitempty"` - Followers uint64 `json:"followers,omitempty"` - Globals *network.GlobalValues `json:"globals,omitempty"` - StorageType *StorageType `json:"storageType,omitempty"` - }{} - u.Type = v.Type() - if !(p2p.EqualMultiaddr(v.Listen, nil)) { - u.Listen = &encoding.JsonUnmarshalWith[p2p.Multiaddr]{Value: v.Listen, Func: p2p.UnmarshalMultiaddrJSON} - } - if !(v.Bvns == 0) { - u.Bvns = v.Bvns - } - if !(v.Validators == 0) { - u.Validators = v.Validators - } - if !(v.Followers == 0) { - u.Followers = v.Followers - } - if !(v.Globals == nil) { - u.Globals = v.Globals - } - if !(v.StorageType == nil) { - u.StorageType = v.StorageType - } - return json.Marshal(&u) -} +type StorageType int64 -func (v *EventsService) MarshalJSON() ([]byte, error) { - u := struct { - Type ServiceType `json:"type"` - Partition string `json:"partition,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Partition) == 0) { - u.Partition = v.Partition - } - return json.Marshal(&u) -} +const ( + StorageTypeBadger StorageType = 2 + StorageTypeBolt StorageType = 3 + StorageTypeExpBlockDB StorageType = 1001 + StorageTypeLevelDB StorageType = 4 + StorageTypeMemory StorageType = 1 +) -func (v *ExpBlockDBStorage) MarshalJSON() ([]byte, error) { - u := struct { - Type StorageType `json:"type"` - Path string `json:"path,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Path) == 0) { - u.Path = v.Path - } - return json.Marshal(&u) +// SetByName looks up a StorageType by name. +func (v *StorageType) SetByName(s string) (ok bool) { + *v, ok = sStorageType.ByName(s) + return } -func (v *FaucetService) MarshalJSON() ([]byte, error) { - u := struct { - Type ServiceType `json:"type"` - Account *url.URL `json:"account,omitempty"` - SigningKey *encoding.JsonUnmarshalWith[PrivateKey] `json:"signingKey,omitempty"` - Router *ServiceOrRef[*RouterService] `json:"router,omitempty"` - }{} - u.Type = v.Type() - if !(v.Account == nil) { - u.Account = v.Account - } - if !(EqualPrivateKey(v.SigningKey, nil)) { - u.SigningKey = &encoding.JsonUnmarshalWith[PrivateKey]{Value: v.SigningKey, Func: UnmarshalPrivateKeyJSON} - } - if !(v.Router == nil) { - u.Router = v.Router - } - return json.Marshal(&u) +// SetByValue looks up a StorageType by value. +func (v *StorageType) SetByValue(i int64) (ok bool) { + *v, ok = sStorageType.ByValue(i) + return } -func (v *GatewayConfiguration) MarshalJSON() ([]byte, error) { - u := struct { - Type ConfigurationType `json:"type"` - Listen *encoding.JsonUnmarshalWith[p2p.Multiaddr] `json:"listen,omitempty"` - }{} - u.Type = v.Type() - if !(p2p.EqualMultiaddr(v.Listen, nil)) { - u.Listen = &encoding.JsonUnmarshalWith[p2p.Multiaddr]{Value: v.Listen, Func: p2p.UnmarshalMultiaddrJSON} - } - return json.Marshal(&u) +// String returns the label or name of the StorageType. +func (v StorageType) String() string { + return sStorageType.String(v) } -func (v *HttpListener) MarshalJSON() ([]byte, error) { - u := struct { - Listen *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"listen,omitempty"` - ConnectionLimit *int64 `json:"connectionLimit,omitempty"` - ReadHeaderTimeout interface{} `json:"readHeaderTimeout,omitempty"` - TlsCertPath string `json:"tlsCertPath,omitempty"` - TlsKeyPath string `json:"tlsKeyPath,omitempty"` - }{} - if !(len(v.Listen) == 0) { - u.Listen = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.Listen, Func: p2p.UnmarshalMultiaddrJSON} - } - if !(v.ConnectionLimit == nil) { - u.ConnectionLimit = v.ConnectionLimit - } - if !(v.ReadHeaderTimeout == nil) { - if v.ReadHeaderTimeout != nil { - u.ReadHeaderTimeout = encoding.DurationToJSON(*v.ReadHeaderTimeout) - } - } - if !(len(v.TlsCertPath) == 0) { - u.TlsCertPath = v.TlsCertPath - } - if !(len(v.TlsKeyPath) == 0) { - u.TlsKeyPath = v.TlsKeyPath - } - return json.Marshal(&u) +// MarshalBinary marshals the StorageType to JSON. +func (v StorageType) MarshalJSON() ([]byte, error) { + return sStorageType.MarshalJSON(v) } -func (v *HttpPeerMapEntry) MarshalJSON() ([]byte, error) { - u := struct { - ID *encoding.JsonUnmarshalWith[p2p.PeerID] `json:"id,omitempty"` - Partitions encoding.JsonList[string] `json:"partitions,omitempty"` - Addresses *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"addresses,omitempty"` - ExtraData *string `json:"$epilogue,omitempty"` - }{} - if !(v.ID == ("")) { - u.ID = &encoding.JsonUnmarshalWith[p2p.PeerID]{Value: v.ID, Func: p2p.UnmarshalPeerIDJSON} - } - if !(len(v.Partitions) == 0) { - u.Partitions = v.Partitions - } - if !(len(v.Addresses) == 0) { - u.Addresses = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.Addresses, Func: p2p.UnmarshalMultiaddrJSON} - } - u.ExtraData = encoding.BytesToJSON(v.extraData) - return json.Marshal(&u) +// UnmarshalJSON unmarshals the StorageType from JSON. +func (v *StorageType) UnmarshalJSON(b []byte) error { + return sStorageType.UnmarshalJSON(b, v) } -func (v *HttpService) MarshalJSON() ([]byte, error) { - u := struct { - Type ServiceType `json:"type"` - Listen *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"listen,omitempty"` - ConnectionLimit *int64 `json:"connectionLimit,omitempty"` - ReadHeaderTimeout interface{} `json:"readHeaderTimeout,omitempty"` - TlsCertPath string `json:"tlsCertPath,omitempty"` - TlsKeyPath string `json:"tlsKeyPath,omitempty"` - CorsOrigins encoding.JsonList[string] `json:"corsOrigins,omitempty"` - LetsEncrypt encoding.JsonList[string] `json:"letsEncrypt,omitempty"` - DebugJsonRpc *bool `json:"debugJsonRpc,omitempty"` - Router *ServiceOrRef[*RouterService] `json:"router,omitempty"` - PeerMap encoding.JsonList[*HttpPeerMapEntry] `json:"peerMap,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.HttpListener.Listen) == 0) { - u.Listen = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.HttpListener.Listen, Func: p2p.UnmarshalMultiaddrJSON} - } - if !(v.HttpListener.ConnectionLimit == nil) { - u.ConnectionLimit = v.HttpListener.ConnectionLimit - } - if !(v.HttpListener.ReadHeaderTimeout == nil) { - if v.HttpListener.ReadHeaderTimeout != nil { - u.ReadHeaderTimeout = encoding.DurationToJSON(*v.HttpListener.ReadHeaderTimeout) - } - } - if !(len(v.HttpListener.TlsCertPath) == 0) { - u.TlsCertPath = v.HttpListener.TlsCertPath - } - if !(len(v.HttpListener.TlsKeyPath) == 0) { - u.TlsKeyPath = v.HttpListener.TlsKeyPath - } - if !(len(v.CorsOrigins) == 0) { - u.CorsOrigins = v.CorsOrigins - } - if !(len(v.LetsEncrypt) == 0) { - u.LetsEncrypt = v.LetsEncrypt - } - if !(v.DebugJsonRpc == nil) { - u.DebugJsonRpc = v.DebugJsonRpc - } - if !(v.Router == nil) { - u.Router = v.Router - } - if !(len(v.PeerMap) == 0) { - u.PeerMap = v.PeerMap - } - return json.Marshal(&u) +type SubnodeService struct { + Name string + NodeKey PrivateKey + Services []Service } -func (v *Instrumentation) MarshalJSON() ([]byte, error) { - u := struct { - Listen *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"listen,omitempty"` - ConnectionLimit *int64 `json:"connectionLimit,omitempty"` - ReadHeaderTimeout interface{} `json:"readHeaderTimeout,omitempty"` - TlsCertPath string `json:"tlsCertPath,omitempty"` - TlsKeyPath string `json:"tlsKeyPath,omitempty"` - Monitoring *Monitor `json:"monitoring,omitempty"` - PprofListen *encoding.JsonUnmarshalWith[p2p.Multiaddr] `json:"pprofListen,omitempty"` - }{} - if !(len(v.HttpListener.Listen) == 0) { - u.Listen = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.HttpListener.Listen, Func: p2p.UnmarshalMultiaddrJSON} - } - if !(v.HttpListener.ConnectionLimit == nil) { - u.ConnectionLimit = v.HttpListener.ConnectionLimit - } - if !(v.HttpListener.ReadHeaderTimeout == nil) { - if v.HttpListener.ReadHeaderTimeout != nil { - u.ReadHeaderTimeout = encoding.DurationToJSON(*v.HttpListener.ReadHeaderTimeout) - } - } - if !(len(v.HttpListener.TlsCertPath) == 0) { - u.TlsCertPath = v.HttpListener.TlsCertPath - } - if !(len(v.HttpListener.TlsKeyPath) == 0) { - u.TlsKeyPath = v.HttpListener.TlsKeyPath - } - if !(v.Monitoring == nil) { - u.Monitoring = v.Monitoring - } - if !(p2p.EqualMultiaddr(v.PprofListen, nil)) { - u.PprofListen = &encoding.JsonUnmarshalWith[p2p.Multiaddr]{Value: v.PprofListen, Func: p2p.UnmarshalMultiaddrJSON} - } - return json.Marshal(&u) -} +func (SubnodeService) Type() ServiceType { return ServiceTypeSubnode } -func (v *LevelDBStorage) MarshalJSON() ([]byte, error) { - u := struct { - Type StorageType `json:"type"` - Path string `json:"path,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Path) == 0) { - u.Path = v.Path - } - return json.Marshal(&u) +// Copy returns a copy of the SubnodeService. +func (v *SubnodeService) Copy() *SubnodeService { + return sSubnodeService.Copy(v) } -func (v *Logging) MarshalJSON() ([]byte, error) { - u := struct { - Format string `json:"format,omitempty"` - Color *bool `json:"color,omitempty"` - Rules encoding.JsonList[*LoggingRule] `json:"rules,omitempty"` - Loki *LokiLogging `json:"loki,omitempty"` - }{} - if !(len(v.Format) == 0) { - u.Format = v.Format - } - if !(v.Color == nil) { - u.Color = v.Color - } - if !(len(v.Rules) == 0) { - u.Rules = v.Rules - } - if !(v.Loki == nil) { - u.Loki = v.Loki - } - return json.Marshal(&u) +// EqualSubnodeService returns true if V is equal to U. +func (v *SubnodeService) Equal(u *SubnodeService) bool { + return sSubnodeService.Equal(v, u) } -func (v *LoggingRule) MarshalJSON() ([]byte, error) { - u := struct { - Level slog.Level `json:"level"` - Modules encoding.JsonList[string] `json:"modules,omitempty"` - }{} - u.Level = v.Level - if !(len(v.Modules) == 0) { - u.Modules = v.Modules - } - return json.Marshal(&u) +// MarshalBinary marshals the SubnodeService to JSON. +func (v *SubnodeService) MarshalJSON() ([]byte, error) { + return sSubnodeService.MarshalJSON(v) } -func (v *MemoryStorage) MarshalJSON() ([]byte, error) { - u := struct { - Type StorageType `json:"type"` - }{} - u.Type = v.Type() - return json.Marshal(&u) +// UnmarshalJSON unmarshals the SubnodeService from JSON. +func (v *SubnodeService) UnmarshalJSON(b []byte) error { + return sSubnodeService.UnmarshalJSON(b, v) } -func (v *MetricsService) MarshalJSON() ([]byte, error) { - u := struct { - Type ServiceType `json:"type"` - Partition string `json:"partition,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Partition) == 0) { - u.Partition = v.Partition - } - return json.Marshal(&u) +type Telemetry struct { + Enabled *bool + Stdout *bool + Export *HttpListener + Otlp *OtlpConfig + Rules []*TelemetryRule } -func (v *Monitor) MarshalJSON() ([]byte, error) { - u := struct { - Directory string `json:"directory,omitempty"` - ProfileMemory *bool `json:"profileMemory,omitempty"` - MemoryPollingRate interface{} `json:"memoryPollingRate,omitempty"` - AllocRateTrigger *float64 `json:"allocRateTrigger,omitempty"` - }{} - if !(len(v.Directory) == 0) { - u.Directory = v.Directory - } - if !(v.ProfileMemory == nil) { - u.ProfileMemory = v.ProfileMemory - } - if !(v.MemoryPollingRate == nil) { - if v.MemoryPollingRate != nil { - u.MemoryPollingRate = encoding.DurationToJSON(*v.MemoryPollingRate) - } - } - if !(v.AllocRateTrigger == nil) { - u.AllocRateTrigger = v.AllocRateTrigger - } - return json.Marshal(&u) +// Copy returns a copy of the Telemetry. +func (v *Telemetry) Copy() *Telemetry { + return sTelemetry.Copy(v) } -func (v *NetworkService) MarshalJSON() ([]byte, error) { - u := struct { - Type ServiceType `json:"type"` - Partition string `json:"partition,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Partition) == 0) { - u.Partition = v.Partition - } - return json.Marshal(&u) +// EqualTelemetry returns true if V is equal to U. +func (v *Telemetry) Equal(u *Telemetry) bool { + return sTelemetry.Equal(v, u) } -func (v *P2P) MarshalJSON() ([]byte, error) { - u := struct { - Listen *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"listen,omitempty"` - BootstrapPeers *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"bootstrapPeers,omitempty"` - Key *encoding.JsonUnmarshalWith[PrivateKey] `json:"key,omitempty"` - PeerDB *string `json:"peerDB,omitempty"` - EnablePeerTracking bool `json:"enablePeerTracking,omitempty"` - DiscoveryMode *DhtMode `json:"discoveryMode,omitempty"` - External *encoding.JsonUnmarshalWith[p2p.Multiaddr] `json:"external,omitempty"` - }{} - if !(len(v.Listen) == 0) { - u.Listen = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.Listen, Func: p2p.UnmarshalMultiaddrJSON} - } - if !(len(v.BootstrapPeers) == 0) { - u.BootstrapPeers = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.BootstrapPeers, Func: p2p.UnmarshalMultiaddrJSON} - } - if !(EqualPrivateKey(v.Key, nil)) { - u.Key = &encoding.JsonUnmarshalWith[PrivateKey]{Value: v.Key, Func: UnmarshalPrivateKeyJSON} - } - if !(v.PeerDB == nil) { - u.PeerDB = v.PeerDB - } - if !(!v.EnablePeerTracking) { - u.EnablePeerTracking = v.EnablePeerTracking - } - if !(v.DiscoveryMode == nil) { - u.DiscoveryMode = v.DiscoveryMode - } - if !(p2p.EqualMultiaddr(v.External, nil)) { - u.External = &encoding.JsonUnmarshalWith[p2p.Multiaddr]{Value: v.External, Func: p2p.UnmarshalMultiaddrJSON} - } - return json.Marshal(&u) +// MarshalBinary marshals the Telemetry to JSON. +func (v *Telemetry) MarshalJSON() ([]byte, error) { + return sTelemetry.MarshalJSON(v) } -func (v *PrivateKeySeed) MarshalJSON() ([]byte, error) { - u := struct { - Type PrivateKeyType `json:"type"` - Seed *record.Key `json:"seed,omitempty"` - }{} - u.Type = v.Type() - if !(v.Seed == nil) { - u.Seed = v.Seed - } - return json.Marshal(&u) +// UnmarshalJSON unmarshals the Telemetry from JSON. +func (v *Telemetry) UnmarshalJSON(b []byte) error { + return sTelemetry.UnmarshalJSON(b, v) } -func (v *Querier) MarshalJSON() ([]byte, error) { - u := struct { - Type ServiceType `json:"type"` - Partition string `json:"partition,omitempty"` - Storage *StorageOrRef `json:"storage,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Partition) == 0) { - u.Partition = v.Partition - } - if !(v.Storage == nil) { - u.Storage = v.Storage - } - return json.Marshal(&u) +type TelemetryRule struct { + Match []string + Drop bool + Rate encoding.Duration } -func (v *RawPrivateKey) MarshalJSON() ([]byte, error) { - u := struct { - Type PrivateKeyType `json:"type"` - Address string `json:"address,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Address) == 0) { - u.Address = v.Address - } - return json.Marshal(&u) +// Copy returns a copy of the TelemetryRule. +func (v *TelemetryRule) Copy() *TelemetryRule { + return sTelemetryRule.Copy(v) } -func (v *RouterService) MarshalJSON() ([]byte, error) { - u := struct { - Type ServiceType `json:"type"` - Name string `json:"name,omitempty"` - Events string `json:"events,omitempty"` - PeerMap encoding.JsonList[*HttpPeerMapEntry] `json:"peerMap,omitempty"` - ExtraData *string `json:"$epilogue,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Name) == 0) { - u.Name = v.Name - } - if !(len(v.Events) == 0) { - u.Events = v.Events - } - if !(len(v.PeerMap) == 0) { - u.PeerMap = v.PeerMap - } - u.ExtraData = encoding.BytesToJSON(v.extraData) - return json.Marshal(&u) +// EqualTelemetryRule returns true if V is equal to U. +func (v *TelemetryRule) Equal(u *TelemetryRule) bool { + return sTelemetryRule.Equal(v, u) } -func (v *SnapshotService) MarshalJSON() ([]byte, error) { - u := struct { - Type ServiceType `json:"type"` - Partition string `json:"partition,omitempty"` - Storage *StorageOrRef `json:"storage,omitempty"` - Directory string `json:"directory,omitempty"` - Schedule *network.CronSchedule `json:"schedule,omitempty"` - RetainCount *uint64 `json:"retainCount,omitempty"` - EnableIndexing *bool `json:"enableIndexing,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Partition) == 0) { - u.Partition = v.Partition - } - if !(v.Storage == nil) { - u.Storage = v.Storage - } - if !(len(v.Directory) == 0) { - u.Directory = v.Directory - } - if !(v.Schedule == nil) { - u.Schedule = v.Schedule - } - if !(v.RetainCount == nil) { - u.RetainCount = v.RetainCount - } - if !(v.EnableIndexing == nil) { - u.EnableIndexing = v.EnableIndexing - } - return json.Marshal(&u) +// MarshalBinary marshals the TelemetryRule to JSON. +func (v *TelemetryRule) MarshalJSON() ([]byte, error) { + return sTelemetryRule.MarshalJSON(v) } -func (v *StorageService) MarshalJSON() ([]byte, error) { - u := struct { - Type ServiceType `json:"type"` - Name string `json:"name,omitempty"` - Storage *encoding.JsonUnmarshalWith[Storage] `json:"storage,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Name) == 0) { - u.Name = v.Name - } - if !(EqualStorage(v.Storage, nil)) { - u.Storage = &encoding.JsonUnmarshalWith[Storage]{Value: v.Storage, Func: UnmarshalStorageJSON} - } - return json.Marshal(&u) +// UnmarshalJSON unmarshals the TelemetryRule from JSON. +func (v *TelemetryRule) UnmarshalJSON(b []byte) error { + return sTelemetryRule.UnmarshalJSON(b, v) } -func (v *SubnodeService) MarshalJSON() ([]byte, error) { - u := struct { - Type ServiceType `json:"type"` - Name string `json:"name,omitempty"` - NodeKey *encoding.JsonUnmarshalWith[PrivateKey] `json:"nodeKey,omitempty"` - Services *encoding.JsonUnmarshalListWith[Service] `json:"services,omitempty"` - }{} - u.Type = v.Type() - if !(len(v.Name) == 0) { - u.Name = v.Name - } - if !(EqualPrivateKey(v.NodeKey, nil)) { - u.NodeKey = &encoding.JsonUnmarshalWith[PrivateKey]{Value: v.NodeKey, Func: UnmarshalPrivateKeyJSON} - } - if !(len(v.Services) == 0) { - u.Services = &encoding.JsonUnmarshalListWith[Service]{Value: v.Services, Func: UnmarshalServiceJSON} - } - return json.Marshal(&u) +type TransientPrivateKey struct { + key address.Address } -func (v *Telemetry) MarshalJSON() ([]byte, error) { - u := struct { - Enabled *bool `json:"enabled,omitempty"` - Stdout *bool `json:"stdout,omitempty"` - Otlp *OtlpConfig `json:"otlp,omitempty"` - Export *HttpListener `json:"export,omitempty"` - Rules encoding.JsonList[*TelemetryRule] `json:"rules,omitempty"` - }{} - if !(v.Enabled == nil) { - u.Enabled = v.Enabled - } - if !(v.Stdout == nil) { - u.Stdout = v.Stdout - } - if !(v.Otlp == nil) { - u.Otlp = v.Otlp - } - if !(v.Export == nil) { - u.Export = v.Export - } - if !(len(v.Rules) == 0) { - u.Rules = v.Rules - } - return json.Marshal(&u) +func (TransientPrivateKey) Type() PrivateKeyType { return PrivateKeyTypeTransient } + +// Copy returns a copy of the TransientPrivateKey. +func (v *TransientPrivateKey) Copy() *TransientPrivateKey { + return sTransientPrivateKey.Copy(v) } -func (v *TelemetryRule) MarshalJSON() ([]byte, error) { - u := struct { - Match encoding.JsonList[string] `json:"match,omitempty"` - Drop bool `json:"drop,omitempty"` - Rate interface{} `json:"rate,omitempty"` - }{} - if !(len(v.Match) == 0) { - u.Match = v.Match - } - if !(!v.Drop) { - u.Drop = v.Drop - } - if !(v.Rate == 0) { - u.Rate = encoding.DurationToJSON(v.Rate) - } - return json.Marshal(&u) +// EqualTransientPrivateKey returns true if V is equal to U. +func (v *TransientPrivateKey) Equal(u *TransientPrivateKey) bool { + return sTransientPrivateKey.Equal(v, u) } +// MarshalBinary marshals the TransientPrivateKey to JSON. func (v *TransientPrivateKey) MarshalJSON() ([]byte, error) { - u := struct { - Type PrivateKeyType `json:"type"` - }{} - u.Type = v.Type() - return json.Marshal(&u) -} - -func (v *BadgerStorage) UnmarshalJSON(data []byte) error { - u := struct { - Type StorageType `json:"type"` - Path string `json:"path,omitempty"` - Version int64 `json:"version,omitempty"` - }{} - u.Type = v.Type() - u.Path = v.Path - u.Version = v.Version - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Path = u.Path - v.Version = u.Version - return nil -} - -func (v *BoltStorage) UnmarshalJSON(data []byte) error { - u := struct { - Type StorageType `json:"type"` - Path string `json:"path,omitempty"` - }{} - u.Type = v.Type() - u.Path = v.Path - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Path = u.Path - return nil -} - -func (v *CometNodeKeyFile) UnmarshalJSON(data []byte) error { - u := struct { - Type PrivateKeyType `json:"type"` - Path string `json:"path,omitempty"` - }{} - u.Type = v.Type() - - u.Path = v.Path - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Path = u.Path - return nil -} - -func (v *CometPrivValFile) UnmarshalJSON(data []byte) error { - u := struct { - Type PrivateKeyType `json:"type"` - Path string `json:"path,omitempty"` - }{} - u.Type = v.Type() - - u.Path = v.Path - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Path = u.Path - return nil -} - -func (v *Config) UnmarshalJSON(data []byte) error { - u := struct { - DotEnv *bool `json:"dotEnv,omitempty"` - Network string `json:"network,omitempty"` - Logging *Logging `json:"logging,omitempty"` - Instrumentation *Instrumentation `json:"instrumentation,omitempty"` - Telemetry *Telemetry `json:"telemetry,omitempty"` - P2P *P2P `json:"p2P,omitempty"` - Configurations *encoding.JsonUnmarshalListWith[Configuration] `json:"configurations,omitempty"` - Services *encoding.JsonUnmarshalListWith[Service] `json:"services,omitempty"` - }{} - - u.DotEnv = v.DotEnv - u.Network = v.Network - u.Logging = v.Logging - u.Instrumentation = v.Instrumentation - u.Telemetry = v.Telemetry - u.P2P = v.P2P - u.Configurations = &encoding.JsonUnmarshalListWith[Configuration]{Value: v.Configurations, Func: UnmarshalConfigurationJSON} - u.Services = &encoding.JsonUnmarshalListWith[Service]{Value: v.Services, Func: UnmarshalServiceJSON} - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - v.DotEnv = u.DotEnv - v.Network = u.Network - v.Logging = u.Logging - v.Instrumentation = u.Instrumentation - v.Telemetry = u.Telemetry - v.P2P = u.P2P - if u.Configurations != nil && u.Configurations.Value != nil { - v.Configurations = make([]Configuration, len(u.Configurations.Value)) - for i, x := range u.Configurations.Value { - v.Configurations[i] = x - } - } - if u.Services != nil && u.Services.Value != nil { - v.Services = make([]Service, len(u.Services.Value)) - for i, x := range u.Services.Value { - v.Services[i] = x - } - } - return nil -} - -func (v *ConsensusService) UnmarshalJSON(data []byte) error { - u := struct { - Type ServiceType `json:"type"` - NodeDir string `json:"nodeDir,omitempty"` - ValidatorKey *encoding.JsonUnmarshalWith[PrivateKey] `json:"validatorKey,omitempty"` - Genesis string `json:"genesis,omitempty"` - Listen *encoding.JsonUnmarshalWith[p2p.Multiaddr] `json:"listen,omitempty"` - BootstrapPeers *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"bootstrapPeers,omitempty"` - MetricsNamespace string `json:"metricsNamespace,omitempty"` - App *encoding.JsonUnmarshalWith[ConsensusApp] `json:"app,omitempty"` - }{} - u.Type = v.Type() - u.NodeDir = v.NodeDir - u.ValidatorKey = &encoding.JsonUnmarshalWith[PrivateKey]{Value: v.ValidatorKey, Func: UnmarshalPrivateKeyJSON} - u.Genesis = v.Genesis - u.Listen = &encoding.JsonUnmarshalWith[p2p.Multiaddr]{Value: v.Listen, Func: p2p.UnmarshalMultiaddrJSON} - u.BootstrapPeers = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.BootstrapPeers, Func: p2p.UnmarshalMultiaddrJSON} - u.MetricsNamespace = v.MetricsNamespace - u.App = &encoding.JsonUnmarshalWith[ConsensusApp]{Value: v.App, Func: UnmarshalConsensusAppJSON} - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.NodeDir = u.NodeDir - if u.ValidatorKey != nil { - v.ValidatorKey = u.ValidatorKey.Value - } - - v.Genesis = u.Genesis - if u.Listen != nil { - v.Listen = u.Listen.Value - } - - if u.BootstrapPeers != nil && u.BootstrapPeers.Value != nil { - v.BootstrapPeers = make([]p2p.Multiaddr, len(u.BootstrapPeers.Value)) - for i, x := range u.BootstrapPeers.Value { - v.BootstrapPeers[i] = x - } - } - v.MetricsNamespace = u.MetricsNamespace - if u.App != nil { - v.App = u.App.Value - } - - return nil -} - -func (v *CoreConsensusApp) UnmarshalJSON(data []byte) error { - u := struct { - Type ConsensusAppType `json:"type"` - Partition *protocol.PartitionInfo `json:"partition,omitempty"` - EnableHealing *bool `json:"enableHealing,omitempty"` - EnableDirectDispatch *bool `json:"enableDirectDispatch,omitempty"` - MaxEnvelopesPerBlock *uint64 `json:"maxEnvelopesPerBlock,omitempty"` - }{} - u.Type = v.Type() - u.Partition = v.Partition - u.EnableHealing = v.EnableHealing - u.EnableDirectDispatch = v.EnableDirectDispatch - u.MaxEnvelopesPerBlock = v.MaxEnvelopesPerBlock - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Partition = u.Partition - v.EnableHealing = u.EnableHealing - v.EnableDirectDispatch = u.EnableDirectDispatch - v.MaxEnvelopesPerBlock = u.MaxEnvelopesPerBlock - return nil -} - -func (v *CoreValidatorConfiguration) UnmarshalJSON(data []byte) error { - u := struct { - Type ConfigurationType `json:"type"` - Mode CoreValidatorMode `json:"mode,omitempty"` - Listen *encoding.JsonUnmarshalWith[p2p.Multiaddr] `json:"listen,omitempty"` - BVN string `json:"bvn,omitempty"` - ValidatorKey *encoding.JsonUnmarshalWith[PrivateKey] `json:"validatorKey,omitempty"` - DnGenesis string `json:"dnGenesis,omitempty"` - BvnGenesis string `json:"bvnGenesis,omitempty"` - DnBootstrapPeers *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"dnBootstrapPeers,omitempty"` - BvnBootstrapPeers *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"bvnBootstrapPeers,omitempty"` - EnableHealing *bool `json:"enableHealing,omitempty"` - EnableDirectDispatch *bool `json:"enableDirectDispatch,omitempty"` - EnableSnapshots *bool `json:"enableSnapshots,omitempty"` - MaxEnvelopesPerBlock *uint64 `json:"maxEnvelopesPerBlock,omitempty"` - StorageType *StorageType `json:"storageType,omitempty"` - }{} - u.Type = v.Type() - u.Mode = v.Mode - u.Listen = &encoding.JsonUnmarshalWith[p2p.Multiaddr]{Value: v.Listen, Func: p2p.UnmarshalMultiaddrJSON} - u.BVN = v.BVN - u.ValidatorKey = &encoding.JsonUnmarshalWith[PrivateKey]{Value: v.ValidatorKey, Func: UnmarshalPrivateKeyJSON} - u.DnGenesis = v.DnGenesis - u.BvnGenesis = v.BvnGenesis - u.DnBootstrapPeers = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.DnBootstrapPeers, Func: p2p.UnmarshalMultiaddrJSON} - u.BvnBootstrapPeers = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.BvnBootstrapPeers, Func: p2p.UnmarshalMultiaddrJSON} - u.EnableHealing = v.EnableHealing - u.EnableDirectDispatch = v.EnableDirectDispatch - u.EnableSnapshots = v.EnableSnapshots - u.MaxEnvelopesPerBlock = v.MaxEnvelopesPerBlock - u.StorageType = v.StorageType - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Mode = u.Mode - if u.Listen != nil { - v.Listen = u.Listen.Value - } - - v.BVN = u.BVN - if u.ValidatorKey != nil { - v.ValidatorKey = u.ValidatorKey.Value - } - - v.DnGenesis = u.DnGenesis - v.BvnGenesis = u.BvnGenesis - if u.DnBootstrapPeers != nil && u.DnBootstrapPeers.Value != nil { - v.DnBootstrapPeers = make([]p2p.Multiaddr, len(u.DnBootstrapPeers.Value)) - for i, x := range u.DnBootstrapPeers.Value { - v.DnBootstrapPeers[i] = x - } - } - if u.BvnBootstrapPeers != nil && u.BvnBootstrapPeers.Value != nil { - v.BvnBootstrapPeers = make([]p2p.Multiaddr, len(u.BvnBootstrapPeers.Value)) - for i, x := range u.BvnBootstrapPeers.Value { - v.BvnBootstrapPeers[i] = x - } - } - v.EnableHealing = u.EnableHealing - v.EnableDirectDispatch = u.EnableDirectDispatch - v.EnableSnapshots = u.EnableSnapshots - v.MaxEnvelopesPerBlock = u.MaxEnvelopesPerBlock - v.StorageType = u.StorageType - return nil -} - -func (v *DevnetConfiguration) UnmarshalJSON(data []byte) error { - u := struct { - Type ConfigurationType `json:"type"` - Listen *encoding.JsonUnmarshalWith[p2p.Multiaddr] `json:"listen,omitempty"` - Bvns uint64 `json:"bvns,omitempty"` - Validators uint64 `json:"validators,omitempty"` - Followers uint64 `json:"followers,omitempty"` - Globals *network.GlobalValues `json:"globals,omitempty"` - StorageType *StorageType `json:"storageType,omitempty"` - }{} - u.Type = v.Type() - u.Listen = &encoding.JsonUnmarshalWith[p2p.Multiaddr]{Value: v.Listen, Func: p2p.UnmarshalMultiaddrJSON} - u.Bvns = v.Bvns - u.Validators = v.Validators - u.Followers = v.Followers - u.Globals = v.Globals - u.StorageType = v.StorageType - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - if u.Listen != nil { - v.Listen = u.Listen.Value - } - - v.Bvns = u.Bvns - v.Validators = u.Validators - v.Followers = u.Followers - v.Globals = u.Globals - v.StorageType = u.StorageType - return nil -} - -func (v *EventsService) UnmarshalJSON(data []byte) error { - u := struct { - Type ServiceType `json:"type"` - Partition string `json:"partition,omitempty"` - }{} - u.Type = v.Type() - u.Partition = v.Partition - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Partition = u.Partition - return nil -} - -func (v *ExpBlockDBStorage) UnmarshalJSON(data []byte) error { - u := struct { - Type StorageType `json:"type"` - Path string `json:"path,omitempty"` - }{} - u.Type = v.Type() - u.Path = v.Path - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Path = u.Path - return nil -} - -func (v *FaucetService) UnmarshalJSON(data []byte) error { - u := struct { - Type ServiceType `json:"type"` - Account *url.URL `json:"account,omitempty"` - SigningKey *encoding.JsonUnmarshalWith[PrivateKey] `json:"signingKey,omitempty"` - Router *ServiceOrRef[*RouterService] `json:"router,omitempty"` - }{} - u.Type = v.Type() - u.Account = v.Account - u.SigningKey = &encoding.JsonUnmarshalWith[PrivateKey]{Value: v.SigningKey, Func: UnmarshalPrivateKeyJSON} - u.Router = v.Router - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Account = u.Account - if u.SigningKey != nil { - v.SigningKey = u.SigningKey.Value - } - - v.Router = u.Router - return nil -} - -func (v *GatewayConfiguration) UnmarshalJSON(data []byte) error { - u := struct { - Type ConfigurationType `json:"type"` - Listen *encoding.JsonUnmarshalWith[p2p.Multiaddr] `json:"listen,omitempty"` - }{} - u.Type = v.Type() - u.Listen = &encoding.JsonUnmarshalWith[p2p.Multiaddr]{Value: v.Listen, Func: p2p.UnmarshalMultiaddrJSON} - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - if u.Listen != nil { - v.Listen = u.Listen.Value - } - - return nil -} - -func (v *HttpListener) UnmarshalJSON(data []byte) error { - u := struct { - Listen *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"listen,omitempty"` - ConnectionLimit *int64 `json:"connectionLimit,omitempty"` - ReadHeaderTimeout interface{} `json:"readHeaderTimeout,omitempty"` - TlsCertPath string `json:"tlsCertPath,omitempty"` - TlsKeyPath string `json:"tlsKeyPath,omitempty"` - }{} - u.Listen = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.Listen, Func: p2p.UnmarshalMultiaddrJSON} - u.ConnectionLimit = v.ConnectionLimit - if v.ReadHeaderTimeout != nil { - u.ReadHeaderTimeout = encoding.DurationToJSON(*v.ReadHeaderTimeout) - } - u.TlsCertPath = v.TlsCertPath - u.TlsKeyPath = v.TlsKeyPath - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if u.Listen != nil && u.Listen.Value != nil { - v.Listen = make([]p2p.Multiaddr, len(u.Listen.Value)) - for i, x := range u.Listen.Value { - v.Listen[i] = x - } - } - v.ConnectionLimit = u.ConnectionLimit - if u.ReadHeaderTimeout != nil { - if x, err := encoding.DurationFromJSON(u.ReadHeaderTimeout); err != nil { - return fmt.Errorf("error decoding ReadHeaderTimeout: %w", err) - } else { - v.ReadHeaderTimeout = &x - } - } - v.TlsCertPath = u.TlsCertPath - v.TlsKeyPath = u.TlsKeyPath - return nil -} - -func (v *HttpPeerMapEntry) UnmarshalJSON(data []byte) error { - u := struct { - ID *encoding.JsonUnmarshalWith[p2p.PeerID] `json:"id,omitempty"` - Partitions encoding.JsonList[string] `json:"partitions,omitempty"` - Addresses *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"addresses,omitempty"` - ExtraData *string `json:"$epilogue,omitempty"` - }{} - u.ID = &encoding.JsonUnmarshalWith[p2p.PeerID]{Value: v.ID, Func: p2p.UnmarshalPeerIDJSON} - u.Partitions = v.Partitions - u.Addresses = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.Addresses, Func: p2p.UnmarshalMultiaddrJSON} - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if u.ID != nil { - v.ID = u.ID.Value - } - - v.Partitions = u.Partitions - if u.Addresses != nil && u.Addresses.Value != nil { - v.Addresses = make([]p2p.Multiaddr, len(u.Addresses.Value)) - for i, x := range u.Addresses.Value { - v.Addresses[i] = x - } - } - v.extraData, err = encoding.BytesFromJSON(u.ExtraData) - if err != nil { - return err - } - return nil -} - -func (v *HttpService) UnmarshalJSON(data []byte) error { - u := struct { - Type ServiceType `json:"type"` - Listen *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"listen,omitempty"` - ConnectionLimit *int64 `json:"connectionLimit,omitempty"` - ReadHeaderTimeout interface{} `json:"readHeaderTimeout,omitempty"` - TlsCertPath string `json:"tlsCertPath,omitempty"` - TlsKeyPath string `json:"tlsKeyPath,omitempty"` - CorsOrigins encoding.JsonList[string] `json:"corsOrigins,omitempty"` - LetsEncrypt encoding.JsonList[string] `json:"letsEncrypt,omitempty"` - DebugJsonRpc *bool `json:"debugJsonRpc,omitempty"` - Router *ServiceOrRef[*RouterService] `json:"router,omitempty"` - PeerMap encoding.JsonList[*HttpPeerMapEntry] `json:"peerMap,omitempty"` - }{} - u.Type = v.Type() - u.Listen = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.HttpListener.Listen, Func: p2p.UnmarshalMultiaddrJSON} - u.ConnectionLimit = v.HttpListener.ConnectionLimit - if v.HttpListener.ReadHeaderTimeout != nil { - u.ReadHeaderTimeout = encoding.DurationToJSON(*v.HttpListener.ReadHeaderTimeout) - } - u.TlsCertPath = v.HttpListener.TlsCertPath - u.TlsKeyPath = v.HttpListener.TlsKeyPath - u.CorsOrigins = v.CorsOrigins - u.LetsEncrypt = v.LetsEncrypt - u.DebugJsonRpc = v.DebugJsonRpc - u.Router = v.Router - u.PeerMap = v.PeerMap - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - if u.Listen != nil && u.Listen.Value != nil { - v.HttpListener.Listen = make([]p2p.Multiaddr, len(u.Listen.Value)) - for i, x := range u.Listen.Value { - v.HttpListener.Listen[i] = x - } - } - v.HttpListener.ConnectionLimit = u.ConnectionLimit - if u.ReadHeaderTimeout != nil { - if x, err := encoding.DurationFromJSON(u.ReadHeaderTimeout); err != nil { - return fmt.Errorf("error decoding ReadHeaderTimeout: %w", err) - } else { - v.HttpListener.ReadHeaderTimeout = &x - } - } - v.HttpListener.TlsCertPath = u.TlsCertPath - v.HttpListener.TlsKeyPath = u.TlsKeyPath - v.CorsOrigins = u.CorsOrigins - v.LetsEncrypt = u.LetsEncrypt - v.DebugJsonRpc = u.DebugJsonRpc - v.Router = u.Router - v.PeerMap = u.PeerMap - return nil -} - -func (v *Instrumentation) UnmarshalJSON(data []byte) error { - u := struct { - Listen *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"listen,omitempty"` - ConnectionLimit *int64 `json:"connectionLimit,omitempty"` - ReadHeaderTimeout interface{} `json:"readHeaderTimeout,omitempty"` - TlsCertPath string `json:"tlsCertPath,omitempty"` - TlsKeyPath string `json:"tlsKeyPath,omitempty"` - Monitoring *Monitor `json:"monitoring,omitempty"` - PprofListen *encoding.JsonUnmarshalWith[p2p.Multiaddr] `json:"pprofListen,omitempty"` - }{} - u.Listen = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.HttpListener.Listen, Func: p2p.UnmarshalMultiaddrJSON} - u.ConnectionLimit = v.HttpListener.ConnectionLimit - if v.HttpListener.ReadHeaderTimeout != nil { - u.ReadHeaderTimeout = encoding.DurationToJSON(*v.HttpListener.ReadHeaderTimeout) - } - u.TlsCertPath = v.HttpListener.TlsCertPath - u.TlsKeyPath = v.HttpListener.TlsKeyPath - u.Monitoring = v.Monitoring - u.PprofListen = &encoding.JsonUnmarshalWith[p2p.Multiaddr]{Value: v.PprofListen, Func: p2p.UnmarshalMultiaddrJSON} - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if u.Listen != nil && u.Listen.Value != nil { - v.HttpListener.Listen = make([]p2p.Multiaddr, len(u.Listen.Value)) - for i, x := range u.Listen.Value { - v.HttpListener.Listen[i] = x - } - } - v.HttpListener.ConnectionLimit = u.ConnectionLimit - if u.ReadHeaderTimeout != nil { - if x, err := encoding.DurationFromJSON(u.ReadHeaderTimeout); err != nil { - return fmt.Errorf("error decoding ReadHeaderTimeout: %w", err) - } else { - v.HttpListener.ReadHeaderTimeout = &x - } - } - v.HttpListener.TlsCertPath = u.TlsCertPath - v.HttpListener.TlsKeyPath = u.TlsKeyPath - v.Monitoring = u.Monitoring - if u.PprofListen != nil { - v.PprofListen = u.PprofListen.Value - } - - return nil -} - -func (v *LevelDBStorage) UnmarshalJSON(data []byte) error { - u := struct { - Type StorageType `json:"type"` - Path string `json:"path,omitempty"` - }{} - u.Type = v.Type() - u.Path = v.Path - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Path = u.Path - return nil -} - -func (v *Logging) UnmarshalJSON(data []byte) error { - u := struct { - Format string `json:"format,omitempty"` - Color *bool `json:"color,omitempty"` - Rules encoding.JsonList[*LoggingRule] `json:"rules,omitempty"` - Loki *LokiLogging `json:"loki,omitempty"` - }{} - u.Format = v.Format - u.Color = v.Color - u.Rules = v.Rules - u.Loki = v.Loki - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - v.Format = u.Format - v.Color = u.Color - v.Rules = u.Rules - v.Loki = u.Loki - return nil -} - -func (v *LoggingRule) UnmarshalJSON(data []byte) error { - u := struct { - Level slog.Level `json:"level"` - Modules encoding.JsonList[string] `json:"modules,omitempty"` - }{} - u.Level = v.Level - u.Modules = v.Modules - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - v.Level = u.Level - v.Modules = u.Modules - return nil -} - -func (v *MemoryStorage) UnmarshalJSON(data []byte) error { - u := struct { - Type StorageType `json:"type"` - }{} - u.Type = v.Type() - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - return nil -} - -func (v *MetricsService) UnmarshalJSON(data []byte) error { - u := struct { - Type ServiceType `json:"type"` - Partition string `json:"partition,omitempty"` - }{} - u.Type = v.Type() - u.Partition = v.Partition - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Partition = u.Partition - return nil -} - -func (v *Monitor) UnmarshalJSON(data []byte) error { - u := struct { - Directory string `json:"directory,omitempty"` - ProfileMemory *bool `json:"profileMemory,omitempty"` - MemoryPollingRate interface{} `json:"memoryPollingRate,omitempty"` - AllocRateTrigger *float64 `json:"allocRateTrigger,omitempty"` - }{} - u.Directory = v.Directory - u.ProfileMemory = v.ProfileMemory - if v.MemoryPollingRate != nil { - u.MemoryPollingRate = encoding.DurationToJSON(*v.MemoryPollingRate) - } - u.AllocRateTrigger = v.AllocRateTrigger - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - v.Directory = u.Directory - v.ProfileMemory = u.ProfileMemory - if u.MemoryPollingRate != nil { - if x, err := encoding.DurationFromJSON(u.MemoryPollingRate); err != nil { - return fmt.Errorf("error decoding MemoryPollingRate: %w", err) - } else { - v.MemoryPollingRate = &x - } - } - v.AllocRateTrigger = u.AllocRateTrigger - return nil -} - -func (v *NetworkService) UnmarshalJSON(data []byte) error { - u := struct { - Type ServiceType `json:"type"` - Partition string `json:"partition,omitempty"` - }{} - u.Type = v.Type() - u.Partition = v.Partition - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Partition = u.Partition - return nil -} - -func (v *P2P) UnmarshalJSON(data []byte) error { - u := struct { - Listen *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"listen,omitempty"` - BootstrapPeers *encoding.JsonUnmarshalListWith[p2p.Multiaddr] `json:"bootstrapPeers,omitempty"` - Key *encoding.JsonUnmarshalWith[PrivateKey] `json:"key,omitempty"` - PeerDB *string `json:"peerDB,omitempty"` - EnablePeerTracking bool `json:"enablePeerTracking,omitempty"` - DiscoveryMode *DhtMode `json:"discoveryMode,omitempty"` - External *encoding.JsonUnmarshalWith[p2p.Multiaddr] `json:"external,omitempty"` - }{} - u.Listen = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.Listen, Func: p2p.UnmarshalMultiaddrJSON} - u.BootstrapPeers = &encoding.JsonUnmarshalListWith[p2p.Multiaddr]{Value: v.BootstrapPeers, Func: p2p.UnmarshalMultiaddrJSON} - u.Key = &encoding.JsonUnmarshalWith[PrivateKey]{Value: v.Key, Func: UnmarshalPrivateKeyJSON} - u.PeerDB = v.PeerDB - u.EnablePeerTracking = v.EnablePeerTracking - u.DiscoveryMode = v.DiscoveryMode - u.External = &encoding.JsonUnmarshalWith[p2p.Multiaddr]{Value: v.External, Func: p2p.UnmarshalMultiaddrJSON} - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if u.Listen != nil && u.Listen.Value != nil { - v.Listen = make([]p2p.Multiaddr, len(u.Listen.Value)) - for i, x := range u.Listen.Value { - v.Listen[i] = x - } - } - if u.BootstrapPeers != nil && u.BootstrapPeers.Value != nil { - v.BootstrapPeers = make([]p2p.Multiaddr, len(u.BootstrapPeers.Value)) - for i, x := range u.BootstrapPeers.Value { - v.BootstrapPeers[i] = x - } - } - if u.Key != nil { - v.Key = u.Key.Value - } - - v.PeerDB = u.PeerDB - v.EnablePeerTracking = u.EnablePeerTracking - v.DiscoveryMode = u.DiscoveryMode - if u.External != nil { - v.External = u.External.Value - } - - return nil -} - -func (v *PrivateKeySeed) UnmarshalJSON(data []byte) error { - u := struct { - Type PrivateKeyType `json:"type"` - Seed *record.Key `json:"seed,omitempty"` - }{} - u.Type = v.Type() - - u.Seed = v.Seed - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Seed = u.Seed - return nil -} - -func (v *Querier) UnmarshalJSON(data []byte) error { - u := struct { - Type ServiceType `json:"type"` - Partition string `json:"partition,omitempty"` - Storage *StorageOrRef `json:"storage,omitempty"` - }{} - u.Type = v.Type() - u.Partition = v.Partition - u.Storage = v.Storage - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Partition = u.Partition - v.Storage = u.Storage - return nil -} - -func (v *RawPrivateKey) UnmarshalJSON(data []byte) error { - u := struct { - Type PrivateKeyType `json:"type"` - Address string `json:"address,omitempty"` - }{} - u.Type = v.Type() - u.Address = v.Address - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Address = u.Address - return nil -} - -func (v *RouterService) UnmarshalJSON(data []byte) error { - u := struct { - Type ServiceType `json:"type"` - Name string `json:"name,omitempty"` - Events string `json:"events,omitempty"` - PeerMap encoding.JsonList[*HttpPeerMapEntry] `json:"peerMap,omitempty"` - ExtraData *string `json:"$epilogue,omitempty"` - }{} - u.Type = v.Type() - u.Name = v.Name - u.Events = v.Events - u.PeerMap = v.PeerMap - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Name = u.Name - v.Events = u.Events - v.PeerMap = u.PeerMap - v.extraData, err = encoding.BytesFromJSON(u.ExtraData) - if err != nil { - return err - } - return nil -} - -func (v *SnapshotService) UnmarshalJSON(data []byte) error { - u := struct { - Type ServiceType `json:"type"` - Partition string `json:"partition,omitempty"` - Storage *StorageOrRef `json:"storage,omitempty"` - Directory string `json:"directory,omitempty"` - Schedule *network.CronSchedule `json:"schedule,omitempty"` - RetainCount *uint64 `json:"retainCount,omitempty"` - EnableIndexing *bool `json:"enableIndexing,omitempty"` - }{} - u.Type = v.Type() - u.Partition = v.Partition - u.Storage = v.Storage - u.Directory = v.Directory - u.Schedule = v.Schedule - u.RetainCount = v.RetainCount - u.EnableIndexing = v.EnableIndexing - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Partition = u.Partition - v.Storage = u.Storage - v.Directory = u.Directory - v.Schedule = u.Schedule - v.RetainCount = u.RetainCount - v.EnableIndexing = u.EnableIndexing - return nil -} - -func (v *StorageService) UnmarshalJSON(data []byte) error { - u := struct { - Type ServiceType `json:"type"` - Name string `json:"name,omitempty"` - Storage *encoding.JsonUnmarshalWith[Storage] `json:"storage,omitempty"` - }{} - u.Type = v.Type() - u.Name = v.Name - u.Storage = &encoding.JsonUnmarshalWith[Storage]{Value: v.Storage, Func: UnmarshalStorageJSON} - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Name = u.Name - if u.Storage != nil { - v.Storage = u.Storage.Value - } - - return nil -} - -func (v *SubnodeService) UnmarshalJSON(data []byte) error { - u := struct { - Type ServiceType `json:"type"` - Name string `json:"name,omitempty"` - NodeKey *encoding.JsonUnmarshalWith[PrivateKey] `json:"nodeKey,omitempty"` - Services *encoding.JsonUnmarshalListWith[Service] `json:"services,omitempty"` - }{} - u.Type = v.Type() - u.Name = v.Name - u.NodeKey = &encoding.JsonUnmarshalWith[PrivateKey]{Value: v.NodeKey, Func: UnmarshalPrivateKeyJSON} - u.Services = &encoding.JsonUnmarshalListWith[Service]{Value: v.Services, Func: UnmarshalServiceJSON} - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - v.Name = u.Name - if u.NodeKey != nil { - v.NodeKey = u.NodeKey.Value - } - - if u.Services != nil && u.Services.Value != nil { - v.Services = make([]Service, len(u.Services.Value)) - for i, x := range u.Services.Value { - v.Services[i] = x - } - } - return nil -} - -func (v *Telemetry) UnmarshalJSON(data []byte) error { - u := struct { - Enabled *bool `json:"enabled,omitempty"` - Stdout *bool `json:"stdout,omitempty"` - Otlp *OtlpConfig `json:"otlp,omitempty"` - Export *HttpListener `json:"export,omitempty"` - Rules encoding.JsonList[*TelemetryRule] `json:"rules,omitempty"` - }{} - u.Enabled = v.Enabled - u.Stdout = v.Stdout - u.Otlp = v.Otlp - u.Export = v.Export - u.Rules = v.Rules - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - v.Enabled = u.Enabled - v.Stdout = u.Stdout - v.Otlp = u.Otlp - v.Export = u.Export - v.Rules = u.Rules - return nil -} - -func (v *TelemetryRule) UnmarshalJSON(data []byte) error { - u := struct { - Match encoding.JsonList[string] `json:"match,omitempty"` - Drop bool `json:"drop,omitempty"` - Rate interface{} `json:"rate,omitempty"` - }{} - u.Match = v.Match - u.Drop = v.Drop - u.Rate = encoding.DurationToJSON(v.Rate) - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - v.Match = u.Match - v.Drop = u.Drop - if x, err := encoding.DurationFromJSON(u.Rate); err != nil { - return fmt.Errorf("error decoding Rate: %w", err) - } else { - v.Rate = x - } - return nil -} - -func (v *TransientPrivateKey) UnmarshalJSON(data []byte) error { - u := struct { - Type PrivateKeyType `json:"type"` - }{} - u.Type = v.Type() - - err := json.Unmarshal(data, &u) - if err != nil { - return err - } - if !(v.Type() == u.Type) { - return fmt.Errorf("field Type: not equal: want %v, got %v", v.Type(), u.Type) - } - return nil + return sTransientPrivateKey.MarshalJSON(v) +} + +// UnmarshalJSON unmarshals the TransientPrivateKey from JSON. +func (v *TransientPrivateKey) UnmarshalJSON(b []byte) error { + return sTransientPrivateKey.UnmarshalJSON(b, v) } diff --git a/cmd/accumulated/run/unions_gen.go b/cmd/accumulated/run/unions_gen.go deleted file mode 100644 index ca15f2ec5..000000000 --- a/cmd/accumulated/run/unions_gen.go +++ /dev/null @@ -1,514 +0,0 @@ -// Copyright 2022 The Accumulate Authors -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT. - -package run - -// GENERATED BY go run ./tools/cmd/gen-types. DO NOT EDIT. - -import ( - "encoding/json" - "fmt" -) - -// NewStorage creates a new Storage for the specified StorageType. -func NewStorage(typ StorageType) (Storage, error) { - switch typ { - case StorageTypeBadger: - return new(BadgerStorage), nil - case StorageTypeBolt: - return new(BoltStorage), nil - case StorageTypeExpBlockDB: - return new(ExpBlockDBStorage), nil - case StorageTypeLevelDB: - return new(LevelDBStorage), nil - case StorageTypeMemory: - return new(MemoryStorage), nil - } - return nil, fmt.Errorf("unknown storage %v", typ) -} - -// EqualStorage is used to compare the values of the union -func EqualStorage(a, b Storage) bool { - if a == b { - return true - } - switch a := a.(type) { - case *BadgerStorage: - if a == nil { - return b == nil - } - b, ok := b.(*BadgerStorage) - return ok && a.Equal(b) - case *BoltStorage: - if a == nil { - return b == nil - } - b, ok := b.(*BoltStorage) - return ok && a.Equal(b) - case *ExpBlockDBStorage: - if a == nil { - return b == nil - } - b, ok := b.(*ExpBlockDBStorage) - return ok && a.Equal(b) - case *LevelDBStorage: - if a == nil { - return b == nil - } - b, ok := b.(*LevelDBStorage) - return ok && a.Equal(b) - case *MemoryStorage: - if a == nil { - return b == nil - } - b, ok := b.(*MemoryStorage) - return ok && a.Equal(b) - } - return false -} - -// CopyStorage copies a Storage. -func CopyStorage(v Storage) Storage { - switch v := v.(type) { - case *BadgerStorage: - return v.Copy() - case *BoltStorage: - return v.Copy() - case *ExpBlockDBStorage: - return v.Copy() - case *LevelDBStorage: - return v.Copy() - case *MemoryStorage: - return v.Copy() - default: - return v.CopyAsInterface().(Storage) - } -} - -// UnmarshalStorageJson unmarshals a Storage. -func UnmarshalStorageJSON(data []byte) (Storage, error) { - var typ *struct{ Type StorageType } - err := json.Unmarshal(data, &typ) - if err != nil { - return nil, err - } - - if typ == nil { - return nil, nil - } - - acnt, err := NewStorage(typ.Type) - if err != nil { - return nil, err - } - - err = json.Unmarshal(data, acnt) - if err != nil { - return nil, err - } - - return acnt, nil -} - -// NewPrivateKey creates a new PrivateKey for the specified PrivateKeyType. -func NewPrivateKey(typ PrivateKeyType) (PrivateKey, error) { - switch typ { - case PrivateKeyTypeCometNodeKeyFile: - return new(CometNodeKeyFile), nil - case PrivateKeyTypeCometPrivValFile: - return new(CometPrivValFile), nil - case PrivateKeyTypeSeed: - return new(PrivateKeySeed), nil - case PrivateKeyTypeRaw: - return new(RawPrivateKey), nil - case PrivateKeyTypeTransient: - return new(TransientPrivateKey), nil - } - return nil, fmt.Errorf("unknown private key %v", typ) -} - -// EqualPrivateKey is used to compare the values of the union -func EqualPrivateKey(a, b PrivateKey) bool { - if a == b { - return true - } - switch a := a.(type) { - case *CometNodeKeyFile: - if a == nil { - return b == nil - } - b, ok := b.(*CometNodeKeyFile) - return ok && a.Equal(b) - case *CometPrivValFile: - if a == nil { - return b == nil - } - b, ok := b.(*CometPrivValFile) - return ok && a.Equal(b) - case *PrivateKeySeed: - if a == nil { - return b == nil - } - b, ok := b.(*PrivateKeySeed) - return ok && a.Equal(b) - case *RawPrivateKey: - if a == nil { - return b == nil - } - b, ok := b.(*RawPrivateKey) - return ok && a.Equal(b) - case *TransientPrivateKey: - if a == nil { - return b == nil - } - b, ok := b.(*TransientPrivateKey) - return ok && a.Equal(b) - } - return false -} - -// CopyPrivateKey copies a PrivateKey. -func CopyPrivateKey(v PrivateKey) PrivateKey { - switch v := v.(type) { - case *CometNodeKeyFile: - return v.Copy() - case *CometPrivValFile: - return v.Copy() - case *PrivateKeySeed: - return v.Copy() - case *RawPrivateKey: - return v.Copy() - case *TransientPrivateKey: - return v.Copy() - default: - return v.CopyAsInterface().(PrivateKey) - } -} - -// UnmarshalPrivateKeyJson unmarshals a PrivateKey. -func UnmarshalPrivateKeyJSON(data []byte) (PrivateKey, error) { - var typ *struct{ Type PrivateKeyType } - err := json.Unmarshal(data, &typ) - if err != nil { - return nil, err - } - - if typ == nil { - return nil, nil - } - - acnt, err := NewPrivateKey(typ.Type) - if err != nil { - return nil, err - } - - err = json.Unmarshal(data, acnt) - if err != nil { - return nil, err - } - - return acnt, nil -} - -// NewService creates a new Service for the specified ServiceType. -func NewService(typ ServiceType) (Service, error) { - switch typ { - case ServiceTypeConsensus: - return new(ConsensusService), nil - case ServiceTypeEvents: - return new(EventsService), nil - case ServiceTypeFaucet: - return new(FaucetService), nil - case ServiceTypeHttp: - return new(HttpService), nil - case ServiceTypeMetrics: - return new(MetricsService), nil - case ServiceTypeNetwork: - return new(NetworkService), nil - case ServiceTypeQuerier: - return new(Querier), nil - case ServiceTypeRouter: - return new(RouterService), nil - case ServiceTypeSnapshot: - return new(SnapshotService), nil - case ServiceTypeStorage: - return new(StorageService), nil - case ServiceTypeSubnode: - return new(SubnodeService), nil - } - return nil, fmt.Errorf("unknown service %v", typ) -} - -// EqualService is used to compare the values of the union -func EqualService(a, b Service) bool { - if a == b { - return true - } - switch a := a.(type) { - case *ConsensusService: - if a == nil { - return b == nil - } - b, ok := b.(*ConsensusService) - return ok && a.Equal(b) - case *EventsService: - if a == nil { - return b == nil - } - b, ok := b.(*EventsService) - return ok && a.Equal(b) - case *FaucetService: - if a == nil { - return b == nil - } - b, ok := b.(*FaucetService) - return ok && a.Equal(b) - case *HttpService: - if a == nil { - return b == nil - } - b, ok := b.(*HttpService) - return ok && a.Equal(b) - case *MetricsService: - if a == nil { - return b == nil - } - b, ok := b.(*MetricsService) - return ok && a.Equal(b) - case *NetworkService: - if a == nil { - return b == nil - } - b, ok := b.(*NetworkService) - return ok && a.Equal(b) - case *Querier: - if a == nil { - return b == nil - } - b, ok := b.(*Querier) - return ok && a.Equal(b) - case *RouterService: - if a == nil { - return b == nil - } - b, ok := b.(*RouterService) - return ok && a.Equal(b) - case *SnapshotService: - if a == nil { - return b == nil - } - b, ok := b.(*SnapshotService) - return ok && a.Equal(b) - case *StorageService: - if a == nil { - return b == nil - } - b, ok := b.(*StorageService) - return ok && a.Equal(b) - case *SubnodeService: - if a == nil { - return b == nil - } - b, ok := b.(*SubnodeService) - return ok && a.Equal(b) - } - return false -} - -// CopyService copies a Service. -func CopyService(v Service) Service { - switch v := v.(type) { - case *ConsensusService: - return v.Copy() - case *EventsService: - return v.Copy() - case *FaucetService: - return v.Copy() - case *HttpService: - return v.Copy() - case *MetricsService: - return v.Copy() - case *NetworkService: - return v.Copy() - case *Querier: - return v.Copy() - case *RouterService: - return v.Copy() - case *SnapshotService: - return v.Copy() - case *StorageService: - return v.Copy() - case *SubnodeService: - return v.Copy() - default: - return v.CopyAsInterface().(Service) - } -} - -// UnmarshalServiceJson unmarshals a Service. -func UnmarshalServiceJSON(data []byte) (Service, error) { - var typ *struct{ Type ServiceType } - err := json.Unmarshal(data, &typ) - if err != nil { - return nil, err - } - - if typ == nil { - return nil, nil - } - - acnt, err := NewService(typ.Type) - if err != nil { - return nil, err - } - - err = json.Unmarshal(data, acnt) - if err != nil { - return nil, err - } - - return acnt, nil -} - -// NewConsensusApp creates a new ConsensusApp for the specified ConsensusAppType. -func NewConsensusApp(typ ConsensusAppType) (ConsensusApp, error) { - switch typ { - case ConsensusAppTypeCore: - return new(CoreConsensusApp), nil - } - return nil, fmt.Errorf("unknown consensus app %v", typ) -} - -// EqualConsensusApp is used to compare the values of the union -func EqualConsensusApp(a, b ConsensusApp) bool { - if a == b { - return true - } - switch a := a.(type) { - case *CoreConsensusApp: - if a == nil { - return b == nil - } - b, ok := b.(*CoreConsensusApp) - return ok && a.Equal(b) - } - return false -} - -// CopyConsensusApp copies a ConsensusApp. -func CopyConsensusApp(v ConsensusApp) ConsensusApp { - switch v := v.(type) { - case *CoreConsensusApp: - return v.Copy() - default: - return v.CopyAsInterface().(ConsensusApp) - } -} - -// UnmarshalConsensusAppJson unmarshals a ConsensusApp. -func UnmarshalConsensusAppJSON(data []byte) (ConsensusApp, error) { - var typ *struct{ Type ConsensusAppType } - err := json.Unmarshal(data, &typ) - if err != nil { - return nil, err - } - - if typ == nil { - return nil, nil - } - - acnt, err := NewConsensusApp(typ.Type) - if err != nil { - return nil, err - } - - err = json.Unmarshal(data, acnt) - if err != nil { - return nil, err - } - - return acnt, nil -} - -// NewConfiguration creates a new Configuration for the specified ConfigurationType. -func NewConfiguration(typ ConfigurationType) (Configuration, error) { - switch typ { - case ConfigurationTypeCoreValidator: - return new(CoreValidatorConfiguration), nil - case ConfigurationTypeDevnet: - return new(DevnetConfiguration), nil - case ConfigurationTypeGateway: - return new(GatewayConfiguration), nil - } - return nil, fmt.Errorf("unknown configuration %v", typ) -} - -// EqualConfiguration is used to compare the values of the union -func EqualConfiguration(a, b Configuration) bool { - if a == b { - return true - } - switch a := a.(type) { - case *CoreValidatorConfiguration: - if a == nil { - return b == nil - } - b, ok := b.(*CoreValidatorConfiguration) - return ok && a.Equal(b) - case *DevnetConfiguration: - if a == nil { - return b == nil - } - b, ok := b.(*DevnetConfiguration) - return ok && a.Equal(b) - case *GatewayConfiguration: - if a == nil { - return b == nil - } - b, ok := b.(*GatewayConfiguration) - return ok && a.Equal(b) - } - return false -} - -// CopyConfiguration copies a Configuration. -func CopyConfiguration(v Configuration) Configuration { - switch v := v.(type) { - case *CoreValidatorConfiguration: - return v.Copy() - case *DevnetConfiguration: - return v.Copy() - case *GatewayConfiguration: - return v.Copy() - default: - return v.CopyAsInterface().(Configuration) - } -} - -// UnmarshalConfigurationJson unmarshals a Configuration. -func UnmarshalConfigurationJSON(data []byte) (Configuration, error) { - var typ *struct{ Type ConfigurationType } - err := json.Unmarshal(data, &typ) - if err != nil { - return nil, err - } - - if typ == nil { - return nil, nil - } - - acnt, err := NewConfiguration(typ.Type) - if err != nil { - return nil, err - } - - err = json.Unmarshal(data, acnt) - if err != nil { - return nil, err - } - - return acnt, nil -} diff --git a/go.mod b/go.mod index 932bcb676..18cd9d59e 100644 --- a/go.mod +++ b/go.mod @@ -72,7 +72,7 @@ require ( github.com/sergi/go-diff v1.2.0 github.com/ulikunitz/xz v0.5.11 github.com/vektra/mockery/v2 v2.42.3 - gitlab.com/accumulatenetwork/core/schema v0.1.1-0.20240620224759-19369030b361 + gitlab.com/accumulatenetwork/core/schema v0.2.1-0.20240711192735-5b3657ff1135 gitlab.com/firelizzard/go-script v0.0.0-20240404234115-d5f0a716003d go.opentelemetry.io/otel v1.27.0 go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0 diff --git a/go.sum b/go.sum index 77726a08f..eab1726e9 100644 --- a/go.sum +++ b/go.sum @@ -1170,8 +1170,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -gitlab.com/accumulatenetwork/core/schema v0.1.1-0.20240620224759-19369030b361 h1:J9FcjE7osYPinvoEzWrkpagukyqDwzLqH9fplznBA+M= -gitlab.com/accumulatenetwork/core/schema v0.1.1-0.20240620224759-19369030b361/go.mod h1:FTl7W44SWhDenzAtvKkLu30Cin8DAr249mH4eg7BNLY= +gitlab.com/accumulatenetwork/core/schema v0.2.1-0.20240711192735-5b3657ff1135 h1:DawYWpRLfW7HeTaN1k4idFrv1B+esoNAHjWbtGRqi80= +gitlab.com/accumulatenetwork/core/schema v0.2.1-0.20240711192735-5b3657ff1135/go.mod h1:FTl7W44SWhDenzAtvKkLu30Cin8DAr249mH4eg7BNLY= gitlab.com/bosi/decorder v0.4.1 h1:VdsdfxhstabyhZovHafFw+9eJ6eU0d2CkFNJcZz/NU4= gitlab.com/bosi/decorder v0.4.1/go.mod h1:jecSqWUew6Yle1pCr2eLWTensJMmsxHsBwt+PVbkAqA= gitlab.com/ethan.reesor/vscode-notebooks/go-playbooks v0.0.0-20220417214602-1121b9fae118 h1:UnyYFTz6dWVMBzLUyqHPIQwMrdpiuE+CE7p/5kUfvmk= diff --git a/pkg/database/bpt/schema_gen.go b/pkg/database/bpt/schema_gen.go index 69405477a..ba6f95b7e 100644 --- a/pkg/database/bpt/schema_gen.go +++ b/pkg/database/bpt/schema_gen.go @@ -14,7 +14,7 @@ var ( sbranch schema.Methods[*branch, *branch, *schema.CompositeType] semptyNode schema.Methods[*emptyNode, *emptyNode, *schema.CompositeType] sleaf schema.Methods[*leaf, *leaf, *schema.CompositeType] - snode schema.Methods[node, *node, *schema.UnionType] + snode schema.UnionMethods[node, nodeType] snodeType schema.EnumMethods[nodeType] sstateData schema.Methods[*stateData, *stateData, *schema.CompositeType] ) @@ -67,7 +67,7 @@ func init() { Name: "bpt", Type: &schema.PointerType{ TypeBase: schema.TypeBase{}, - Elem: schema.ExternalTypeReference[BPT](), + Elem: schema.TypeReferenceFor[BPT](), }, }, { @@ -79,7 +79,7 @@ func init() { }, { Name: "status", - Type: schema.ExternalTypeReference[branchStatus](), + Type: schema.TypeReferenceFor[branchStatus](), }, (&schema.Field{ Name: "Left", @@ -119,7 +119,7 @@ func init() { Name: "Key", Type: &schema.PointerType{ TypeBase: schema.TypeBase{}, - Elem: schema.ExternalTypeReference[record.Key](), + Elem: schema.TypeReferenceFor[record.Key](), }, }, { @@ -138,7 +138,7 @@ func init() { }, }).SetGoType() - snode = schema.WithMethods[node, *node]( + snode = schema.WithUnionMethods[node, nodeType]( &schema.UnionType{ TypeBase: schema.TypeBase{ Name: "node", diff --git a/pkg/database/keyvalue/block/schema_gen.go b/pkg/database/keyvalue/block/schema_gen.go index 7a6de6acd..24550a699 100644 --- a/pkg/database/keyvalue/block/schema_gen.go +++ b/pkg/database/keyvalue/block/schema_gen.go @@ -12,7 +12,7 @@ import ( var ( sblockID schema.Methods[*blockID, *blockID, *schema.CompositeType] sendBlockEntry schema.Methods[*endBlockEntry, *endBlockEntry, *schema.CompositeType] - sentry schema.Methods[entry, *entry, *schema.UnionType] + sentry schema.UnionMethods[entry, entryType] sentryType schema.EnumMethods[entryType] sfileHeader schema.Methods[*fileHeader, *fileHeader, *schema.CompositeType] srecordEntry schema.Methods[*recordEntry, *recordEntry, *schema.CompositeType] @@ -45,7 +45,7 @@ func init() { }, }).SetGoType() - sentry = schema.WithMethods[entry, *entry]( + sentry = schema.WithUnionMethods[entry, entryType]( &schema.UnionType{ TypeBase: schema.TypeBase{ Name: "entry", @@ -105,7 +105,7 @@ func init() { Name: "Key", Type: &schema.PointerType{ TypeBase: schema.TypeBase{}, - Elem: schema.ExternalTypeReference[record.Key](), + Elem: schema.TypeReferenceFor[record.Key](), }, }, { diff --git a/pkg/database/keyvalue/block/types_gen.go b/pkg/database/keyvalue/block/types_gen.go index da563d4c1..2998b1b82 100644 --- a/pkg/database/keyvalue/block/types_gen.go +++ b/pkg/database/keyvalue/block/types_gen.go @@ -14,7 +14,7 @@ type blockID struct { } var wblockID = widget.ForComposite(widget.Fields[blockID]{ - {Name: "iD", ID: 1, Widget: widget.ForUint(func(v *blockID) *uint64 { return &v.ID })}, + {Name: "id", ID: 1, Widget: widget.ForUint(func(v *blockID) *uint64 { return &v.ID })}, {Name: "part", ID: 2, Widget: widget.ForUint(func(v *blockID) *uint64 { return &v.Part })}, }, widget.Identity[*blockID]) diff --git a/pkg/types/encoding/time.go b/pkg/types/encoding/time.go new file mode 100644 index 000000000..873271bcd --- /dev/null +++ b/pkg/types/encoding/time.go @@ -0,0 +1,122 @@ +// Copyright 2024 The Accumulate Authors +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + +package encoding + +import ( + "errors" + "strings" + "time" + + "gitlab.com/accumulatenetwork/core/schema/pkg/binary" + "gitlab.com/accumulatenetwork/core/schema/pkg/json" +) + +type Time time.Time + +func (u Time) Get() time.Time { return time.Time(u) } +func (u *Time) Set(v time.Time) { *u = Time(v) } + +func (u *Time) String() string { return u.Get().String() } +func (u *Time) Copy() *Time { return u } +func (u *Time) Equal(v *Time) bool { return strings.EqualFold(u.String(), v.String()) } + +func (u *Time) MarshalJSON() ([]byte, error) { + return json.Marshal(u) +} + +func (u *Time) UnmarshalJSON(b []byte) error { + return json.Unmarshal(b, u) +} + +func (u *Time) MarshalJSONV2(e *json.Encoder) error { + return e.Encode(u.Get()) +} + +func (u *Time) UnmarshalJSONV2(d *json.Decoder) error { + return d.Decode((*time.Time)(u)) +} + +func (u *Time) MarshalBinary() ([]byte, error) { + return binary.Marshal(u) +} + +func (u *Time) UnmarshalBinary(b []byte) error { + return binary.Unmarshal(b, u) +} + +func (u *Time) MarshalBinaryV2(e *binary.Encoder) error { + return e.EncodeInt(u.Get().UTC().Unix()) +} + +func (u *Time) UnmarshalBinaryV2(d *binary.Decoder) error { + v, err := d.DecodeInt() + if err != nil { + return err + } + u.Set(time.Unix(v, 0).UTC()) + return nil +} + +type Duration time.Duration + +func (u Duration) Get() time.Duration { return time.Duration(u) } +func (u *Duration) Set(v time.Duration) { *u = Duration(v) } + +func (u Duration) String() string { return (time.Duration)(u).String() } +func (u Duration) Copy() *Duration { return &u } +func (u Duration) Equal(v *Duration) bool { return strings.EqualFold(u.String(), v.String()) } + +func (u Duration) MarshalJSON() ([]byte, error) { + return json.Marshal(u) +} + +func (u *Duration) UnmarshalJSON(b []byte) error { + return json.Unmarshal(b, u) +} + +func (u Duration) MarshalJSONV2(e *json.Encoder) error { + return e.Encode(DurationToJSON(u.Get())) +} + +func (u *Duration) UnmarshalJSONV2(d *json.Decoder) error { + var v any + err := d.Decode(&v) + if err != nil { + return err + } + w, err := DurationFromJSON(v) + if err != nil { + return err + } + u.Set(w) + return nil +} + +func (u Duration) MarshalBinary() ([]byte, error) { + return binary.Marshal(u) +} + +func (u *Duration) UnmarshalBinary(b []byte) error { + return binary.Unmarshal(b, u) +} + +func (u Duration) MarshalBinaryV2(e *binary.Encoder) error { + sec, ns := SplitDuration(u.Get()) + return errors.Join( + e.EncodeUint(sec), + e.NoField(), + e.EncodeUint(ns), + ) +} + +func (u *Duration) UnmarshalBinaryV2(d *binary.Decoder) error { + sec, e1 := d.DecodeUint() + e2 := d.NoField() + ns, e3 := d.DecodeUint() + u.Set(time.Duration(sec)*time.Second + time.Duration(ns)*time.Nanosecond) + return errors.Join(e1, e2, e3) +}