somc

package
v0.0.0-...-cb3ca1d Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ReconnPeriod int // In milliseconds.
	URL          string
}

Config is a configuration for SOMC connection.

func NewConfig

func NewConfig() *Config

NewConfig creates a default configuration for SOMC connection.

type Conn

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

Conn is a websocket connection to SOMC.

func NewConn

func NewConn(conf *Config, logger *util.Logger) (*Conn, error)

NewConn creates and starts a new SOMC connection.

func (*Conn) Close

func (c *Conn) Close() error

Close closes a given SOMC connection.

func (*Conn) FindOfferings

func (c *Conn) FindOfferings(hashes []string) ([]OfferingData, error)

FindOfferings requests SOMC to find offerings by their hashes.

func (*Conn) PublishEndpoint

func (c *Conn) PublishEndpoint(channel string, endpoint []byte) error

PublishEndpoint publishes an endpoint for a state channel in SOMC.

func (*Conn) PublishOffering

func (c *Conn) PublishOffering(o []byte) error

PublishOffering publishes a given offering JSON in SOMC.

func (*Conn) WaitForEndpoint

func (c *Conn) WaitForEndpoint(channel string) ([]byte, error)

WaitForEndpoint waits for a state channel endpoint data and returns it when it's ready. Can take a while.

type FakeSOMC

type FakeSOMC struct {
	sync.Mutex // To make sure conn cannot be implicitly rewritten.
	// contains filtered or unexported fields
}

FakeSOMC is a fake somc server.

func NewFakeSOMC

func NewFakeSOMC(t *testing.T, somcURL string, startupDelay uint) *FakeSOMC

NewFakeSOMC returns new fake somc server.

func (*FakeSOMC) Close

func (s *FakeSOMC) Close()

Close closes connection and stops server.

func (*FakeSOMC) Read

func (s *FakeSOMC) Read(t *testing.T, method string) *JSONRPCMessage

Read reads from connection.

func (*FakeSOMC) ReadPublishEndpoint

func (s *FakeSOMC) ReadPublishEndpoint(t *testing.T) TestEndpointParams

ReadPublishEndpoint recieves and returns published endpoint.

func (*FakeSOMC) ReadPublishOfferings

func (s *FakeSOMC) ReadPublishOfferings(t *testing.T) TestOfferingParams

ReadPublishOfferings recieves and returns published endpoint.

func (*FakeSOMC) Write

func (s *FakeSOMC) Write(t *testing.T, msg *JSONRPCMessage)

Write writes reply to connection.

type JSONRPCMessage

type JSONRPCMessage struct {
	Version   string          `json:"jsonrpc"`
	ID        uint32          `json:"id"`
	Method    string          `json:"method,omitempty"`
	Params    json.RawMessage `json:"params,omitempty"`
	Result    json.RawMessage `json:"result,omitempty"`
	ErrorData json.RawMessage `json:"error,omitempty"`
}

JSONRPCMessage is a format of the rpc message.

func (*JSONRPCMessage) Error

func (m *JSONRPCMessage) Error() error

Error returns error if any.

func (*JSONRPCMessage) IDString

func (m *JSONRPCMessage) IDString() string

IDString helper func returns message id as string.

type OfferingData

type OfferingData struct {
	Hash     string
	Offering []byte
}

OfferingData is a simple container for offering JSON.

type TestConfig

type TestConfig struct {
	ServerStartupDelay uint // In milliseconds.
}

TestConfig the config related to somc tests.

func NewTestConfig

func NewTestConfig() *TestConfig

NewTestConfig returns default test config.

type TestEndpointParams

type TestEndpointParams endpointParams

TestEndpointParams exported for tests.

type TestOfferingParams

type TestOfferingParams publishOfferingParams

TestOfferingParams used for tests.

Jump to

Keyboard shortcuts

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