chains

package
v1.4.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain[I, C any] struct {
	ID        I
	Cfg       C
	CreatedAt time.Time
	UpdatedAt time.Time
	Enabled   bool
}

Chain is a generic DB chain for any configuration C and chain id I.

C normally implements sql.Scanner and driver.Valuer, but that is not enforced here.

A Chain type alias can be used for convenience:

type Chain = chains.Chain[string, pkg.ChainCfg]

type ORM added in v1.4.0

type ORM[I, C, N any] interface {
	Chain(I, ...pg.QOpt) (Chain[I, C], error)
	Chains(offset, limit int, qopts ...pg.QOpt) ([]Chain[I, C], int, error)
	CreateChain(id I, config C, qopts ...pg.QOpt) (Chain[I, C], error)
	UpdateChain(id I, enabled bool, config C, qopts ...pg.QOpt) (Chain[I, C], error)
	DeleteChain(id I, qopts ...pg.QOpt) error
	GetChainsByIDs(ids []I) (chains []Chain[I, C], err error)
	EnabledChains(...pg.QOpt) ([]Chain[I, C], error)

	CreateNode(N, ...pg.QOpt) (N, error)
	DeleteNode(int32, ...pg.QOpt) error
	GetNodesByChainIDs(chainIDs []I, qopts ...pg.QOpt) (nodes []N, err error)
	Node(int32, ...pg.QOpt) (N, error)
	NodeNamed(string, ...pg.QOpt) (N, error)
	Nodes(offset, limit int, qopts ...pg.QOpt) (nodes []N, count int, err error)
	NodesForChain(chainID I, offset, limit int, qopts ...pg.QOpt) (nodes []N, count int, err error)

	StoreString(chainID I, key, val string) error
	Clear(chainID I, key string) error

	// SetupNodes is a shim to help with configuring multiple nodes via ENV.
	// All existing nodes are dropped, and any missing chains are automatically created.
	// Then all nodes are inserted, and conflicts are ignored.
	SetupNodes(nodes []N, chainIDs []I) error
}

ORM manages chains and nodes.

I: Chain ID

C: Chain Config

N: Node including these default fields:

ID        int32
Name      string
CreatedAt time.Time
UpdatedAt time.Time

func NewORM added in v1.4.0

func NewORM[I, C, N any](q pg.Q, prefix string, nodeCols ...string) ORM[I, C, N]

NewORM returns an ORM backed by q, for the tables <prefix>_chains and <prefix>_nodes with column <prefix>_chain_id. Additional Node fields should be included in nodeCols.

Example
type Config struct {
	Foo null.String
}
type Node = struct {
	ID             int32
	Name           string
	ExampleChainID string
	URL            string
	Bar            null.Int
	CreatedAt      time.Time
	UpdatedAt      time.Time
}
var q pg.Q
_ = chains.NewORM[string, Config, Node](q, "example", "url", "bar")
Output:

Directories

Path Synopsis
evm
gas
log
TODO: Improve code reuse (mostly c/p of core/chains/terra/chain_set.go)
TODO: Improve code reuse (mostly c/p of core/chains/terra/chain_set.go)
monitor
TODO: Improve code reuse (mostly c/p of core/chains/terra/monitor/balance.go)
TODO: Improve code reuse (mostly c/p of core/chains/terra/monitor/balance.go)

Jump to

Keyboard shortcuts

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