genesisfile

package
v1.5.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2021 License: Apache-2.0 Imports: 18 Imported by: 4

README

genesisfile

genesisfile describes a configuration file format used to represent the system variables at genesis. This file is used for two purposes: it both represents the desired initial sysvar state, and is used to mock the state of the sysvars at genesis.

The data model in the genesisfile is more complicated than that of the actual system variables. Internally to ndau, they are a map of names to byte slices, which are then msgp-decoded into the appropriate types. That's not convenient for humans, though.

Instead, a Value type is defined which contains an almost-arbitrary TOML value, the corresponding go type, and some metadata. This is then converted into the appropriate binary data as necessary.

Valid Value types:

  • primitives, in which case Data must be the correct primitive
  • []byte, in which case Data must be a string with the base64-encoded representation
  • structs which implement Valuable
  • lists of structs which implement Valuable

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath(ndauhome string) string

DefaultPath returns the default path at which a chaos genesis file is expected

func RegisterValuable

func RegisterValuable(v Valuable)

RegisterValuable registers a Valuable instance

Valuables can only be unmarshalled if they have been registered. It is a good idea to put a bunch of RegisterValuable calls in in an init function in your code in order to be able to unmarshal your types.

Pre-registered types: - address.Address - signature.PublicKey - eai.RTRow

Types

type GFile

type GFile map[string]Value

GFile represents a genesisfile: a human-friendly representation of the system variables.

func Load

func Load(path string) (GFile, error)

Load returns a system variable set loaded from its file

func (GFile) Dump

func (gf GFile) Dump(path string) error

Dump stores the GFile in a file

func (GFile) IntoSysvars

func (gf GFile) IntoSysvars() (map[string][]byte, error)

IntoSysvars converts a GFile into ndau sysvars

func (GFile) Set

func (gf GFile) Set(name string, val interface{}) error

Set puts val into the specified location

type Valuable

Valuable is an interface defining what kind of struct can be represented in the genesisfile.

TextUnmarshaler is required to read the genesisfile. TextMarshaler is required to write the genesisfile. msgp.Marshaler is required to write to the chaos chain. msgp.Unmarshaler is required to read the value from the chaos chain.

type Value

type Value struct {
	GoType string      `toml:"go_type"`
	Data   interface{} `toml:"data"`
}

A Value is the innermost type on the chaos chain

GoType must be a string representation of the type of the data. Valid values:

- primitives, in which case `Data` must be of the correct type - `[]byte`, in which case `Data` must be a string the base64-encoded representation - structs which implement `Valuable` - lists of structs which implement `Valuable`

func PackValue

func PackValue(v interface{}) (out Value, err error)

PackValue constructs an appropriate Value from this value.

Value is primarily a text type, dealing with encoded data. PackValue produeces this encoded data as appropriate.

Only certain data types are supported:

  • bool, int, int64, uint, uint64, string, time.Time: these types are represented directly in the toml file as native data types
  • []byte: represented in the toml file as a base64-encoding
  • ndaumath/pkg/types.Ndau, Duration, and Timestamp: these types are represented with appropriate toml primitives
  • <type implementing Valuable>: packed with its MarshalText
  • []<type implementing Valuable>: packed with its MarshalText

func (Value) IntoBytes

func (v Value) IntoBytes() ([]byte, error)

IntoBytes converts this value into a []byte representation.

Only certain data types are supported:

- bool, int, int64, uint, uint64, []byte, string: converted using appropriate wkt encodings - time.Time: written directly in msgPack format - <type implementing msgp.Marshaler>: packed with its MarshalMsg

func (Value) Unpack

func (v Value) Unpack() (interface{}, error)

Unpack gets the appropriate concrete type from this Value.

Value is primarily a text type, dealing with encoded data. It is normal to wish to deal with raw data. Unpack produeces this.

Only certain data types are supported:

  • bool, int, int64, uint, uint64, string, time.Time: these types are represented directly in the toml file as native data types
  • []byte: represented in the toml file as a base64-encoding; these are unpacked
  • ndaumath/pkg/types.Ndau, Duration, and Timestamp: these types are represented with appropriate toml primitives
  • <type implementing Valuable>: unpacked with its UnmarshalText
  • []<type implementing Valuable>: unpacked with its UnmarshalText

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL