ogmigo

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2021 License: Apache-2.0 Imports: 13 Imported by: 1

README

ogmigo

ogmigo is a go client for ogmios.

This library is under heavy development, use at your own risk.

Example

package example

import (
	"context"
	"github.com/savaki/ogmigo"
)

func example(ctx context.Context) error {
	var callback ogmigo.ChainSyncFunc = func(ctx context.Context, data []byte) error {
		// do work
		return nil
	}

	client := ogmigo.New(ogmigo.WithEndpoint("ws://example.com:1337"))
	closer, err := client.ChainSync(ctx, callback)
	if err != nil {
		return err
	}
	if err := closer.Close(); err != nil {
		return err
	}

	return nil
}

Submodules

ogmigo imports ogmios as a submodule for testing purposes. To fetch the submodules,

git submodule update --init --recursive

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger = defaultLogger{}

DefaultLogger logs via the log package

View Source
var NopLogger = nopLogger{}

NopLogger logs nothing

Functions

This section is empty.

Types

type ChainSyncFunc

type ChainSyncFunc func(ctx context.Context, data []byte) error

ChainSyncFunc callback containing json encoded chainsync.Response

type ChainSyncOption

type ChainSyncOption func(opts *ChainSyncOptions)

ChainSyncOption provides functional options for ChainSync

func WithPoints

func WithPoints(points ...chainsync.Point) ChainSyncOption

WithPoints allows starting from an optional point

func WithStore

func WithStore(store Store) ChainSyncOption

WithStore specifies store to persist points to; defaults to no persistence

type ChainSyncOptions

type ChainSyncOptions struct {
	// contains filtered or unexported fields
}

ChainSyncOptions configuration parameters

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides a client for the chain sync protocol only

func New

func New(opts ...Option) *Client

New returns a new Client

func (*Client) ChainSync

func (c *Client) ChainSync(ctx context.Context, callback ChainSyncFunc, opts ...ChainSyncOption) (io.Closer, error)

ChainSync replays the blockchain by invoking the callback for each block By default, ChainSync stores no checkpoints and always restarts from origin. These can be overridden via WithPoints and WithStore

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

func KV

func KV(key, value string) KeyValue

type Logger

type Logger interface {
	Debug(message string, kvs ...KeyValue)
	Info(message string, kvs ...KeyValue)
	With(kvs ...KeyValue) Logger
}

type Option

type Option func(*Options)

Option to cardano client

func WithEndpoint

func WithEndpoint(endpoint string) Option

WithEndpoint allows ogmios endpoint to set; defaults to ws://127.0.0.1:1337

func WithInterval

func WithInterval(n int) Option

WithInterval specifies how frequently to save checkpoints when reading

func WithLogger

func WithLogger(logger Logger) Option

WithLogger allows custom logger to be specified

func WithPipeline

func WithPipeline(n int) Option

WithPipeline allows number of pipelined ogmios requests to be provided

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options available to ogmios client

type Store

type Store interface {
	// Save the point; save will be called multiple times and should only
	// keep track of the most recent points
	Save(ctx context.Context, point chainsync.Point) error
	// Load saved points
	Load(ctx context.Context) (chainsync.Points, error)
}

Store allows points to be saved and retrieved to allow graceful recovery after shutdown

Directories

Path Synopsis
logger
zaplogger Module
ouroboros
store
badgerstore Module

Jump to

Keyboard shortcuts

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