substratecommon

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: BSD-3-Clause Imports: 11 Imported by: 1

README

substratecommon

Internal helper libraries for the shiroclient-sdk-go library.

CircleCI

IMPORTANT: DEPRECATED: this repo will eventually be removed, please only use shiroclient-sdk-go directly.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(user func(Substrate) error, opts ...ConnectOption) error

Connect connects to a plugin synchronously; all operations on the Substrate interface must be performed from within the passed closure.

func ConnectWithAttachStdamp

func ConnectWithAttachStdamp(attachStdamp io.Writer) func(co *connectOption) error

ConnectWithAttachStdamp specifies an io.Writer to receive stdio output from the plugin

func ConnectWithCommand

func ConnectWithCommand(command string) func(co *connectOption) error

ConnectWithCommand specifies the path to the plugin (the default is "")

func ConnectWithLogLevel

func ConnectWithLogLevel(level hclog.Level) func(co *connectOption) error

ConnectWithLogLevel specifies the log level to use (the default is Debug)

func EncodePhylumBytes

func EncodePhylumBytes(phylum string) string

EncodePhylumBytes encodes a phylum in the manner expected by mock substrate.

Types

type ArgsCall

type ArgsCall struct {
	Tag     string
	Command string
	Options *ConcreteRequestOptions
}

ArgsCall encodes the arguments to Call

type ArgsCloseMock

type ArgsCloseMock struct {
	Tag string
}

ArgsCloseMock encodes the arguments to CloseMock

type ArgsHealthCheck

type ArgsHealthCheck struct {
	Nat int
}

ArgsHealthCheck encodes the arguments to HealthCheck

type ArgsInit

type ArgsInit struct {
	Tag     string
	Phylum  string
	Options *ConcreteRequestOptions
}

ArgsInit encodes the arguments to Init

type ArgsNewMockFrom

type ArgsNewMockFrom struct {
	Name     string
	Version  string
	Snapshot []byte
}

ArgsNewMockFrom encodes the arguments to NewMockFrom

type ArgsQueryBlock

type ArgsQueryBlock struct {
	Tag     string
	Height  uint64
	Options *ConcreteRequestOptions
}

ArgsQueryBlock encodes the arguments to QueryBlock

type ArgsQueryInfo

type ArgsQueryInfo struct {
	Tag     string
	Options *ConcreteRequestOptions
}

ArgsQueryInfo encodes the arguments to QueryInfo

type ArgsSetCreatorWithAttributesMock

type ArgsSetCreatorWithAttributesMock struct {
	Tag     string
	Creator string
	Attrs   map[string]string
}

ArgsSetCreatorWithAttributesMock encodes the arguments to SetCreatorWithAttributesMock

type ArgsSnapshotMock

type ArgsSnapshotMock struct {
	Tag string
}

ArgsSnapshotMock encodes the arguments to SnapshotMock

type Block

type Block struct {
	Hash         string
	Transactions []*Transaction
}

Block represents summary information about a block.

type ConcreteRequestOptions

type ConcreteRequestOptions struct {
	Headers             map[string]string
	Endpoint            string
	ID                  string
	AuthToken           string
	Params              []byte
	Transient           map[string][]byte
	Timestamp           string
	MSPFilter           []string
	MinEndorsers        int
	Creator             string
	DependentTxID       string
	DisableWritePolling bool
	CCFetchURLDowngrade bool
	CCFetchURLProxy     string
	PhylumVersion       string
	DependentBlock      string
}

ConcreteRequestOptions is a variant of RequestOptions that is "flattened" to pure data.

type ConnectOption

type ConnectOption func(co *connectOption) error

ConnectOption represents the type of a builder action for connectOption

type Error

type Error struct {
	Diagnostic string
}

Error represents a possible error.

func (Error) Error

func (e Error) Error() string

type Plugin

type Plugin struct {
	// Impl Injection
	Impl Substrate
}

Plugin is the implementation of plugin.Plugin so we can serve/consume this.

Ignore MuxBroker. That is used to create more multiplexed streams on our plugin connection and is a more advanced use case.

func (Plugin) Client

func (Plugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error)

Client returns an implementation of our interface that communicates over an RPC client. We return PluginRPC for this.

func (*Plugin) Server

func (p *Plugin) Server(*plugin.MuxBroker) (interface{}, error)

Server returns an RPC server for this plugin type. We construct a PluginRPCServer for this.

type PluginRPC

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

PluginRPC is an implementation that talks over RPC

func (*PluginRPC) Call

func (g *PluginRPC) Call(tag string, command string, options *ConcreteRequestOptions) (*Response, error)

Call forwards the call

func (*PluginRPC) CloseMock

func (g *PluginRPC) CloseMock(tag string) error

CloseMock forwards the call

func (*PluginRPC) HealthCheck

func (g *PluginRPC) HealthCheck(nat int) (int, error)

HealthCheck forwards the call

func (*PluginRPC) Init

func (g *PluginRPC) Init(tag string, phylum string, options *ConcreteRequestOptions) error

Init forwards the call

func (*PluginRPC) NewMockFrom

func (g *PluginRPC) NewMockFrom(name string, version string, snapshot []byte) (string, error)

NewMockFrom forwards the call

func (*PluginRPC) QueryBlock

func (g *PluginRPC) QueryBlock(tag string, height uint64, options *ConcreteRequestOptions) (*Block, error)

QueryBlock forwards the call

func (*PluginRPC) QueryInfo

func (g *PluginRPC) QueryInfo(tag string, options *ConcreteRequestOptions) (uint64, error)

QueryInfo forwards the call

func (*PluginRPC) SetCreatorWithAttributesMock

func (g *PluginRPC) SetCreatorWithAttributesMock(tag string, creator string, attrs map[string]string) error

SetCreatorWithAttributesMock forwards the call

func (*PluginRPC) SnapshotMock

func (g *PluginRPC) SnapshotMock(tag string) ([]byte, error)

SnapshotMock forwards the call

type PluginRPCServer

type PluginRPCServer struct {
	// This is the real implementation
	Impl Substrate
}

PluginRPCServer is the RPC server that PluginRPC talks to, conforming to the requirements of net/rpc

func (*PluginRPCServer) Call

func (s *PluginRPCServer) Call(args *ArgsCall, resp *RespCall) error

Call forwards the call

func (*PluginRPCServer) CloseMock

func (s *PluginRPCServer) CloseMock(args *ArgsCloseMock, resp *RespCloseMock) error

CloseMock forwards the call

func (*PluginRPCServer) HealthCheck

func (s *PluginRPCServer) HealthCheck(args *ArgsHealthCheck, resp *RespHealthCheck) error

HealthCheck forwards the call

func (*PluginRPCServer) Init

func (s *PluginRPCServer) Init(args *ArgsInit, resp *RespInit) error

Init forwards the call

func (*PluginRPCServer) NewMockFrom

func (s *PluginRPCServer) NewMockFrom(args *ArgsNewMockFrom, resp *RespNewMockFrom) error

NewMockFrom forwards the call

func (*PluginRPCServer) QueryBlock

func (s *PluginRPCServer) QueryBlock(args *ArgsQueryBlock, resp *RespQueryBlock) error

QueryBlock forwards the call

func (*PluginRPCServer) QueryInfo

func (s *PluginRPCServer) QueryInfo(args *ArgsQueryInfo, resp *RespQueryInfo) error

QueryInfo forwards the call

func (*PluginRPCServer) SetCreatorWithAttributesMock

func (s *PluginRPCServer) SetCreatorWithAttributesMock(args *ArgsSetCreatorWithAttributesMock, resp *RespSetCreatorWithAttributesMock) error

SetCreatorWithAttributesMock forwards the call

func (*PluginRPCServer) SnapshotMock

func (s *PluginRPCServer) SnapshotMock(args *ArgsSnapshotMock, resp *RespSnapshotMock) error

SnapshotMock forwards the call

type RespCall

type RespCall struct {
	Response *Response
	Err      *Error
}

RespCall encodes the response from Call

type RespCloseMock

type RespCloseMock struct {
	Err *Error
}

RespCloseMock encodes the response from CloseMock

type RespHealthCheck

type RespHealthCheck struct {
	Suc int
}

RespHealthCheck encodes the response from HealthCheck

type RespInit

type RespInit struct {
	Err *Error
}

RespInit encodes the response from Init

type RespNewMockFrom

type RespNewMockFrom struct {
	Tag string
	Err *Error
}

RespNewMockFrom encodes the response from NewMockFrom

type RespQueryBlock

type RespQueryBlock struct {
	Block *Block
	Err   *Error
}

RespQueryBlock encodes the response from QueryBlock

type RespQueryInfo

type RespQueryInfo struct {
	Height uint64
	Err    *Error
}

RespQueryInfo encodes the response from QueryInfo

type RespSetCreatorWithAttributesMock

type RespSetCreatorWithAttributesMock struct {
	Err *Error
}

RespSetCreatorWithAttributesMock encodes the response from SetCreatorWithAttributesMock

type RespSnapshotMock

type RespSnapshotMock struct {
	Snapshot []byte
	Err      *Error
}

RespSnapshotMock encodes the response from SnapshotMock

type Response

type Response struct {
	ResultJSON    []byte
	HasError      bool
	ErrorCode     int
	ErrorMessage  string
	ErrorJSON     []byte
	TransactionID string
}

Response represents a shiroclient response.

func (*Response) UnmarshalTo

func (s *Response) UnmarshalTo(dst interface{}) error

UnmarshalTo unmarshals the response's result to dst.

type Substrate

type Substrate interface {
	HealthCheck(int) (int, error)

	NewMockFrom(string, string, []byte) (string, error)
	SetCreatorWithAttributesMock(string, string, map[string]string) error
	SnapshotMock(string) ([]byte, error)
	CloseMock(string) error

	Init(string, string, *ConcreteRequestOptions) error
	Call(string, string, *ConcreteRequestOptions) (*Response, error)
	QueryInfo(string, *ConcreteRequestOptions) (uint64, error)
	QueryBlock(string, uint64, *ConcreteRequestOptions) (*Block, error)
}

Substrate is the interface that we're exposing as a plugin.

type SubstrateConnection

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

func NewSubstrateConnection

func NewSubstrateConnection(opts ...ConnectOption) (*SubstrateConnection, error)

NewSubstrateConnection connects to a plugin in the background.

func (*SubstrateConnection) Close

func (s *SubstrateConnection) Close() error

Close closes a connection.

func (*SubstrateConnection) GetSubstrate

func (s *SubstrateConnection) GetSubstrate() Substrate

GetSubstrate returns the Substrate interface associated with a connection.

type Transaction

type Transaction struct {
	ID          string
	Reason      string
	Event       []byte
	ChaincodeID string
}

Transaction represents summary information about a transaction.

Jump to

Keyboard shortcuts

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