{"modulePath":"github.com/GoPlugin/pluginV2","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package chains\n\n## Variables\n\n```go\nvar (\n\t// ErrChainIDEmpty is returned when chain is required but was empty.\n\tErrChainIDEmpty = errors.New(\"chain id empty\")\n\t// ErrChainIDInvalid is returned when a chain id does not match any configured chains.\n\tErrChainIDInvalid = errors.New(\"chain id does not match any local chains\")\n)\n```\n\n## Types\n\n```go\ntype ChainConfig[I ID, C Config, N Node] interface {\n\t// contains filtered or unexported methods\n}\n```\n\n```go\ntype ChainService[C Config] interface {\n\tservices.ServiceCtx\n\tUpdateConfig(C)\n}\n```\nChainService is a live, runtime chain instance, with supporting services.\n\n```go\ntype ChainSet[I ID, C Config, N Node, S ChainService[C]] interface {\n\tservices.ServiceCtx\n\n\tName() string\n\tHealthReport() map[string]error\n\n\tDBChainSet[I, C]\n\n\tDBNodeSet[I, N]\n\n\t// Chain returns the ChainService for this ID (if a configuration is available), creating one if necessary.\n\tChain(context.Context, I) (S, error)\n}\n```\nChainSet manages a live set of ChainService instances.\n\n```go\nfunc NewChainSet[I ID, C Config, N Node, S ChainService[C]](\n\topts ChainSetOpts[I, C, N, S], formatID func(I) string,\n) (ChainSet[I, C, N, S], error)\n```\nNewChainSet returns a new ChainSet for the given ChainSetOpts. [https://app.shortcut.com/chainlinklabs/story/33622/remove-legacy-config](https://app.shortcut.com/chainlinklabs/story/33622/remove-legacy-config)\n\n```go\nfunc NewChainSetImmut[I ID, C Config, N Node, S ChainService[C]](chains map[string]S,\n\topts ChainSetOpts[I, C, N, S], formatID func(I) string,\n) (ChainSet[I, C, N, S], error)\n```\nNewChainSetImmut returns a new immutable ChainSet for the given ChainSetOpts.\n\n```go\ntype ChainSetOpts[I ID, C Config, N Node, S ChainService[C]] interface {\n\tValidate() error\n\t// https://app.shortcut.com/chainlinklabs/story/33622/remove-legacy-config\n\tNewChain(DBChain[I, C]) (S, error)\n\tORMAndLogger() (ORM[I, C, N], logger.Logger)\n}\n```\nChainSetOpts holds options for configuring a ChainSet via NewChainSet.\n\n```go\ntype ChainsORM[I ID, CFG Config, C DBChain[I, CFG]] interface {\n\tChain(I, ...pg.QOpt) (C, error)\n\tChains(offset, limit int, qopts ...pg.QOpt) ([]C, int, error)\n\tCreateChain(id I, config CFG, qopts ...pg.QOpt) (C, error)\n\tUpdateChain(id I, enabled bool, config CFG, qopts ...pg.QOpt) (C, error)\n\tDeleteChain(id I, qopts ...pg.QOpt) error\n\tGetChainsByIDs(ids []I) (chains []C, err error)\n\tEnabledChains(...pg.QOpt) ([]C, error)\n}\n```\n\n```go\ntype Config interface {\n\tsql.Scanner\n\tdriver.Valuer\n}\n```\nConfig types should have fields for chain configuration, and implement sql.Scanner and driver.Valuer for persistence in JSON format.\n\n```go\ntype DBChain[I ID, C Config] struct {\n\tID        I\n\tCfg       C\n\tCreatedAt time.Time\n\tUpdatedAt time.Time\n\tEnabled   bool\n}\n```\nDBChain is a generic DB chain for an ID and Config.\n\nA DBChain type alias can be used for convenience:\n\n\ttype DBChain = chains.DBChain[string, pkg.ChainCfg]\n\n```go\ntype DBChainSet[I ID, C Config] interface {\n\tAdd(ctx context.Context, id I, cfg C) (DBChain[I, C], error)\n\tShow(id I) (DBChain[I, C], error)\n\tConfigure(ctx context.Context, id I, enabled bool, cfg C) (DBChain[I, C], error)\n\tRemove(id I) error\n\tIndex(offset, limit int) ([]DBChain[I, C], int, error)\n}\n```\nDBChainSet is a generic interface for DBChain\\[I, C] configuration.\n\n```go\ntype DBNodeSet[I ID, N Node] interface {\n\tGetNodes(ctx context.Context, offset, limit int) (nodes []N, count int, err error)\n\tGetNodesForChain(ctx context.Context, chainID I, offset, limit int) (nodes []N, count int, err error)\n\tCreateNode(context.Context, N) (N, error)\n\tDeleteNode(context.Context, int32) error\n}\n```\nDBNodeSet is a generic interface for Node configuration.\n\n```go\ntype ID any\n```\nID types represent unique identifiers within a particular chain type. Using string is recommended.\n\n```go\ntype Node any\n```\nNode types should be a struct including these default fields:\n\n\tID        int32\n\tName      string\n\tCreatedAt time.Time\n\tUpdatedAt time.Time\n\n```go\ntype NodesORM[I ID, N Node] interface {\n\tCreateNode(N, ...pg.QOpt) (N, error)\n\tDeleteNode(int32, ...pg.QOpt) error\n\tGetNodesByChainIDs(chainIDs []I, qopts ...pg.QOpt) (nodes []N, err error)\n\tNodeNamed(string, ...pg.QOpt) (N, error)\n\tNodes(offset, limit int, qopts ...pg.QOpt) (nodes []N, count int, err error)\n\tNodesForChain(chainID I, offset, limit int, qopts ...pg.QOpt) (nodes []N, count int, err error)\n}\n```\n\n```go\ntype ORM[I ID, C Config, N Node] interface {\n\tChainsORM[I, C, DBChain[I, C]]\n\n\tNodesORM[I, N]\n\n\tStoreString(chainID I, key, val string) error\n\tClear(chainID I, key string) error\n\n\t// SetupNodes is a shim to help with configuring multiple nodes via ENV.\n\t// All existing nodes are dropped, and any missing chains are automatically created.\n\t// Then all nodes are inserted, and conflicts are ignored.\n\tSetupNodes(nodes []N, chainIDs []I) error\n\tEnsureChains([]I, ...pg.QOpt) error\n}\n```\nORM manages chains and nodes.\n\n```go\nfunc NewORM[I ID, C Config, N Node](q pg.Q, prefix string, nodeCols ...string) ORM[I, C, N]\n```\nNewORM returns an ORM backed by q, for the tables \\\u003cprefix\u003e\\_chains and \\\u003cprefix\u003e\\_nodes with column \\\u003cprefix\u003e\\_chain\\_id. Additional Node fields should be included in nodeCols. [https://app.shortcut.com/chainlinklabs/story/33622/remove-legacy-config](https://app.shortcut.com/chainlinklabs/story/33622/remove-legacy-config)\n\n```go\nfunc NewORMImmut[I ID, C Config, N Node](chainConfigs ChainConfig[I, C, N]) ORM[I, C, N]\n```\nNewORMImmut returns an ORM backed by q, for the tables \\\u003cprefix\u003e\\_chains and \\\u003cprefix\u003e\\_nodes with column \\\u003cprefix\u003e\\_chain\\_id. Additional Node fields should be included in nodeCols.\n\n","path":"github.com/GoPlugin/pluginV2/core/chains","name":"chains","synopsis":"","isRedistributable":true}
