client

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: Apache-2.0 Imports: 24 Imported by: 14

Documentation

Overview

Package client contains the Perun State Channel network protocol implementation. It provides a Client that exposes the central API to communicate with a channel network. The Client provides Channel controllers to interact with individual channels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewChainNotReachableError added in v0.7.0

func NewChainNotReachableError(actualErr error) error

NewChainNotReachableError constructs a ChainNotReachableError and wraps it with the actual error message.

func NewTxTimedoutError added in v0.7.0

func NewTxTimedoutError(txType, txID, actualErrMsg string) error

NewTxTimedoutError constructs a TxTimedoutError and wraps it with the actual error message.

txID is the ID required for tracking the transaction on the blockchain and txType is the type of on-chain transaction. Valid types should be defined by each of the blockchain backend.

Types

type AdjudicatorEventHandler added in v0.6.0

type AdjudicatorEventHandler interface {
	HandleAdjudicatorEvent(channel.AdjudicatorEvent)
}

AdjudicatorEventHandler represents an interface for handling adjudicator events.

type BaseChannelProposal added in v0.4.1

type BaseChannelProposal struct {
	ChallengeDuration uint64              // Dispute challenge duration.
	NonceShare        NonceShare          // Proposer's channel nonce share.
	App               channel.App         // App definition, or nil.
	InitData          channel.Data        // Initial App data.
	InitBals          *channel.Allocation // Initial balances.
	FundingAgreement  channel.Balances    // Possibly different funding agreement from initial state's balances.
}

BaseChannelProposal contains all data necessary to propose a new channel to a given set of peers. It is also sent over the wire.

BaseChannelProposal implements the channel proposal messages from the Multi-Party Channel Proposal Protocol (MPCPP).

func (*BaseChannelProposal) Base added in v0.5.0

Base returns the channel proposal's common values.

func (*BaseChannelProposal) Decode added in v0.4.1

func (p *BaseChannelProposal) Decode(r io.Reader) (err error)

Decode decodes a BaseChannelProposal from an io.Reader.

func (BaseChannelProposal) Encode added in v0.4.1

func (p BaseChannelProposal) Encode(w io.Writer) error

Encode encodes the BaseChannelProposal into an io.Writer.

func (BaseChannelProposal) NumPeers added in v0.5.2

func (p BaseChannelProposal) NumPeers() int

NumPeers returns the number of peers in a channel.

func (BaseChannelProposal) ProposalID added in v0.4.1

func (p BaseChannelProposal) ProposalID() (propID ProposalID)

ProposalID returns the identifier of this channel proposal.

func (*BaseChannelProposal) Valid added in v0.4.1

func (p *BaseChannelProposal) Valid() error

Valid checks that the channel proposal is valid: * InitBals must not be nil * ValidateProposalParameters returns nil * InitBals are valid * No locked sub-allocations * non-zero ChallengeDuration.

type BaseChannelProposalAcc added in v0.5.2

type BaseChannelProposalAcc struct {
	ProposalID ProposalID // Proposal session ID we're answering.
	NonceShare NonceShare // Responder's channel nonce share.
}

BaseChannelProposalAcc contains all data for a response to a channel proposal message. The ProposalID must correspond to the channel proposal request one wishes to respond to. Participant should be a participant address just for this channel instantiation.

The type implements the channel proposal response messages from the Multi-Party Channel Proposal Protocol (MPCPP).

func (*BaseChannelProposalAcc) Decode added in v0.5.2

func (acc *BaseChannelProposalAcc) Decode(r io.Reader) error

Decode decodes a BaseChannelProposalAcc.

func (BaseChannelProposalAcc) Encode added in v0.5.2

func (acc BaseChannelProposalAcc) Encode(w io.Writer) error

Encode encodes a BaseChannelProposalAcc.

type ChainNotReachableError added in v0.7.0

type ChainNotReachableError struct {
}

ChainNotReachableError indicates problems in connecting to the blockchain network when trying to do on-chain transactions or reading from the blockchain.

func (ChainNotReachableError) Error added in v0.7.0

func (e ChainNotReachableError) Error() string

Error implements the error interface.

type Channel

type Channel struct {
	perunsync.OnCloser
	log.Embedding
	// contains filtered or unexported fields
}

Channel is the channel controller, progressing the channel state machine and executing the channel update and dispute protocols.

Currently, only the two-party protocol is fully implemented.

func (*Channel) Close

func (c *Channel) Close() error

Close closes the channel and all associated peer subscriptions.

func (*Channel) Ctx added in v0.3.0

func (c *Channel) Ctx() context.Context

Ctx returns a context that is active for the channel's lifetime.

func (*Channel) HasApp added in v0.6.0

func (c *Channel) HasApp() bool

HasApp returns whether the channel has an app.

func (*Channel) ID

func (c *Channel) ID() channel.ID

ID returns the channel ID.

func (*Channel) Idx

func (c *Channel) Idx() channel.Index

Idx returns our index in the channel.

func (*Channel) IsClosed added in v0.3.0

func (c *Channel) IsClosed() bool

IsClosed returns whether the channel is closed.

func (*Channel) IsLedgerChannel added in v0.6.0

func (c *Channel) IsLedgerChannel() bool

IsLedgerChannel returns whether the channel is a ledger channel.

func (*Channel) IsSubChannel added in v0.5.0

func (c *Channel) IsSubChannel() bool

IsSubChannel returns whether the channel is a sub-channel.

func (*Channel) IsVirtualChannel added in v0.7.0

func (c *Channel) IsVirtualChannel() bool

IsVirtualChannel returns whether the channel is a virtual channel. A virtual channel is a channel that has a parent channel with different participants.

func (*Channel) OnUpdate added in v0.4.1

func (c *Channel) OnUpdate(cb func(from, to *channel.State))

OnUpdate sets up a callback to state updates for the channel. The subscription cannot be canceled, but it can be replaced. The States that are passed to the callback are not clones but pointers to the State in the channel machine, so they must not be modified. If you need to modify the State, .Clone() them first.

func (*Channel) Params

func (c *Channel) Params() *channel.Params

Params returns the channel parameters.

func (*Channel) Parent added in v0.5.0

func (c *Channel) Parent() *Channel

Parent returns the parent channel. Can be nil.

func (*Channel) Peers added in v0.4.0

func (c *Channel) Peers() []wire.Address

Peers returns the Perun network addresses of all peers, in the order of the channel participants.

func (*Channel) Phase

func (c *Channel) Phase() channel.Phase

Phase returns the current phase of the channel state machine. Can not be called from an update handler.

func (*Channel) ProgressBy added in v0.6.0

func (c *Channel) ProgressBy(ctx context.Context, update func(*channel.State)) error

ProgressBy progresses the channel state in the adjudicator backend.

Returns TxTimedoutError when the program times out waiting for a transaction to be mined. Returns ChainNotReachableError if the connection to the blockchain network fails when sending a transaction to / reading from the blockchain.

func (*Channel) Register added in v0.6.0

func (c *Channel) Register(ctx context.Context) error

Register registers the channel and all its relatives on the adjudicator.

Returns TxTimedoutError when the program times out waiting for a transaction to be mined. Returns ChainNotReachableError if the connection to the blockchain network fails when sending a transaction to / reading from the blockchain.

func (*Channel) Settle

func (c *Channel) Settle(ctx context.Context, secondary bool) (err error)

Settle concludes the channel and withdraws the funds.

This only works if the channel is concludable. - A ledger channel is concludable, if it is final or if it has been disputed before and the dispute timeout has passed. - Sub-channels and virtual channels are only concludable if they are final and do not have any sub-channels. Otherwise, this means a dispute has occurred and the corresponding ledger channel must be disputed.

Returns TxTimedoutError when the program times out waiting for a transaction to be mined. Returns ChainNotReachableError if the connection to the blockchain network fails when sending a transaction to / reading from the blockchain.

func (*Channel) State

func (c *Channel) State() *channel.State

State returns a pointer to the current state. Clone it if you want to modify it. Can not be called from an update handler.

func (*Channel) Update

func (c *Channel) Update(ctx context.Context, next *channel.State) (err error)

Update proposes the `next` state to all channel participants. `next` should not be modified while this function runs.

Returns nil if all peers accept the update. Returns RequestTimedOutError if any peer did not respond before the context expires or is cancelled. Returns an error if any runtime error occurs or any peer rejects the update.

func (*Channel) UpdateBy added in v0.3.0

func (c *Channel) UpdateBy(ctx context.Context, update func(*channel.State) error) (err error)

UpdateBy updates the channel state using the update function and proposes the new state to all other channel participants. The update function must not update the version counter.

Returns nil if all peers accept the update. Returns RequestTimedOutError if any peer did not respond before the context expires or is cancelled. Returns an error if any runtime error occurs or any peer rejects the update.

func (*Channel) Watch added in v0.2.0

Watch watches the adjudicator for channel events and responds accordingly. The handler is notified about the corresponding events.

The routine takes care that if an old state is registered, the on-chain state is refuted with the most recent event available by registering the channel tree. In such a case, the handler may receive multiple registered events in short succession.

Returns TxTimedoutError when watcher refutes with the most recent state and the program times out waiting for a transaction to be mined. Returns ChainNotReachableError if the connection to the blockchain network fails when sending a transaction to / reading from the blockchain.

type ChannelMsg

type ChannelMsg interface {
	wire.Msg
	ID() channel.ID
}

ChannelMsg are all messages that can be routed to a particular channel controller.

type ChannelProposal

type ChannelProposal interface {
	wire.Msg
	perunio.Decoder

	// Base returns the channel proposal's common values.
	Base() *BaseChannelProposal

	// Matches checks whether an accept message is of the correct type. This
	// does not check any contents of the accept message, only its type.
	Matches(ChannelProposalAccept) bool

	// Valid checks whether a channel proposal is valid.
	Valid() error

	// ProposalID calculates the proposal's unique identifier.
	ProposalID() ProposalID
}

ChannelProposal is the interface that describes all channel proposal message types.

type ChannelProposalAccept added in v0.5.2

type ChannelProposalAccept interface {
	wire.Msg
	Base() *BaseChannelProposalAcc
}

ChannelProposalAccept is the generic interface for channel proposal accept messages.

type ChannelProposalRej

type ChannelProposalRej struct {
	ProposalID ProposalID // The channel proposal to reject.
	Reason     string     // The rejection reason.
}

ChannelProposalRej is used to reject a ChannelProposalReq. An optional reason for the rejection can be set.

The message is one of two possible responses in the Multi-Party Channel Proposal Protocol (MPCPP).

func (*ChannelProposalRej) Decode

func (rej *ChannelProposalRej) Decode(r io.Reader) error

Decode decodes a ChannelProposalRej from an io.Reader.

func (ChannelProposalRej) Encode

func (rej ChannelProposalRej) Encode(w io.Writer) error

Encode encodes a ChannelProposalRej into an io.Writer.

func (ChannelProposalRej) Type

func (ChannelProposalRej) Type() wire.Type

Type returns wire.ChannelProposalRej.

type ChannelUpdate

type ChannelUpdate struct {
	// State is the proposed new state.
	State *channel.State
	// ActorIdx is the actor causing the new state. It does not need to
	// coincide with the sender of the request.
	ActorIdx channel.Index
}

ChannelUpdate is a channel update proposal.

type ChannelUpdateProposal added in v0.7.0

type ChannelUpdateProposal interface {
	wire.Msg
	perunio.Decoder
	Base() *msgChannelUpdate
}

ChannelUpdateProposal represents an abstract update proposal message.

type Client

type Client struct {
	sync.Closer
	// contains filtered or unexported fields
}

Client is a state channel client. It is the central controller to interact with a state channel network. It can be used to propose channels to other channel network peers.

Currently, only the two-party protocol is fully implemented.

func New

func New(
	address wire.Address,
	bus wire.Bus,
	funder channel.Funder,
	adjudicator channel.Adjudicator,
	wallet wallet.Wallet,
) (c *Client, err error)

New creates a new State Channel Client.

address is the channel network address of this client. It is the persistend identifier in the network and not necessarily related to any on-chain identity or channel participant address.

bus is the wire protocol bus over which messages to other network clients are sent and received from.

The funder and adjudicator are used to fund and dispute or settle a ledger channel, respectively.

The wallet is used to resolve addresses to accounts when creating or restoring channels.

If any argument is nil, New panics.

func (*Client) Channel added in v0.2.0

func (c *Client) Channel(id channel.ID) (*Channel, error)

Channel queries a channel by its ID.

func (*Client) Close

func (c *Client) Close() error

Close closes this state channel client. It also closes the peer registry.

func (*Client) EnablePersistence added in v0.3.0

func (c *Client) EnablePersistence(pr persistence.PersistRestorer)

EnablePersistence sets the PersistRestorer that the client is going to use for channel persistence. This methods is expected to be called once during the setup of the client and is hence not thread-safe.

The PersistRestorer is not closed when the Client is closed.

func (*Client) Handle added in v0.3.0

func (c *Client) Handle(ph ProposalHandler, uh UpdateHandler)

Handle is the incoming request handler routine. It handles channel proposals and channel update requests. It must be started exactly once by the user, during the setup of the Client. Incoming requests are handled by the passed respecive handlers.

func (*Client) Log

func (c *Client) Log() log.Logger

Log returns the logger used by the client. It is not thread-safe.

func (*Client) OnNewChannel added in v0.3.0

func (c *Client) OnNewChannel(handler func(*Channel))

OnNewChannel sets a callback to be called whenever a new channel is created or restored. Only one such handler can be set at a time, and repeated calls to this function will overwrite the currently existing handler. This function may be safely called at any time.

func (*Client) ProposeChannel

func (c *Client) ProposeChannel(ctx context.Context, prop ChannelProposal) (*Channel, error)

ProposeChannel attempts to open a channel with the parameters and peers from ChannelProposal prop: - the proposal is sent to the peers and if all peers accept, - the channel is funded. If successful, - the channel controller is returned.

After the channel controller got successfully set up, it is passed to the callback registered with Client.OnNewChannel. Accept returns after this callback has run.

It is important that the passed context does not cancel before twice the ChallengeDuration has passed (at least for real blockchain backends with wall time), or the channel cannot be settled if a peer times out funding.

After the channel got successfully created, the user is required to start the channel watcher with Channel.Watch() on the returned channel controller.

Returns PeerRejectedProposalError if the channel is rejected by the peer. Returns RequestTimedOutError if the peer did not respond before the context expires or is cancelled. Returns FundingTimeoutError if any of the participants do not fund the channel in time. Returns TxTimedoutError when the program times out waiting for a transaction to be mined. Returns ChainNotReachableError if the connection to the blockchain network fails when sending a transaction to / reading from the blockchain.

func (*Client) Restore added in v0.4.0

func (c *Client) Restore(ctx context.Context) error

Restore restores all channels from persistence. Channels are restored in parallel. Newly restored channels should be acquired through the OnNewChannel callback.

func (*Client) SetLog added in v0.4.0

func (c *Client) SetLog(l log.Logger)

SetLog sets the logger used by the client. It is not thread-safe.

type LedgerChannelProposal added in v0.4.1

type LedgerChannelProposal struct {
	BaseChannelProposal
	Participant wallet.Address // Proposer's address in the channel.
	Peers       []wire.Address // Participants' wire addresses.
}

LedgerChannelProposal is a channel proposal for ledger channels.

func NewLedgerChannelProposal added in v0.4.1

func NewLedgerChannelProposal(
	challengeDuration uint64,
	participant wallet.Address,
	initBals *channel.Allocation,
	peers []wire.Address,
	opts ...ProposalOpts,
) (prop *LedgerChannelProposal, err error)

NewLedgerChannelProposal creates a ledger channel proposal and applies the supplied options. challengeDuration is the on-chain challenge duration in seconds. participant is our wallet address. initBals are the initial balances. peers are the wire addresses of the channel participants. For more information, see ProposalOpts.

func (LedgerChannelProposal) Accept added in v0.5.2

func (p LedgerChannelProposal) Accept(
	participant wallet.Address,
	nonceShare ProposalOpts,
) *LedgerChannelProposalAcc

Accept constructs an accept message that belongs to a proposal message. It should be used instead of manually constructing an accept message.

func (*LedgerChannelProposal) Decode added in v0.5.2

func (p *LedgerChannelProposal) Decode(r io.Reader) error

Decode decodes a ledger channel proposal.

func (LedgerChannelProposal) Encode added in v0.5.2

func (p LedgerChannelProposal) Encode(w io.Writer) error

Encode encodes a ledger channel proposal.

func (LedgerChannelProposal) Matches added in v0.5.2

Matches requires that the accept message is a LedgerChannelAcc message.

func (LedgerChannelProposal) ProposalID added in v0.5.2

func (p LedgerChannelProposal) ProposalID() (propID ProposalID)

ProposalID returns the identifier of this channel proposal request.

func (LedgerChannelProposal) Type added in v0.4.1

Type returns wire.LedgerChannelProposal.

func (LedgerChannelProposal) Valid added in v0.5.2

func (p LedgerChannelProposal) Valid() error

Valid checks whether the participant address is nil.

type LedgerChannelProposalAcc added in v0.5.2

type LedgerChannelProposalAcc struct {
	BaseChannelProposalAcc
	Participant wallet.Address // Responder's participant address.
}

LedgerChannelProposalAcc is the accept message type corresponding to ledger channel proposals. ParticipantAdd is recommended to be unique for each channel instantiation.

func (*LedgerChannelProposalAcc) Base added in v0.5.2

Base returns the common proposal accept values.

func (*LedgerChannelProposalAcc) Decode added in v0.5.2

func (acc *LedgerChannelProposalAcc) Decode(r io.Reader) error

Decode decodes a LedgerChannelProposalAcc from an io.Reader.

func (LedgerChannelProposalAcc) Encode added in v0.5.2

func (acc LedgerChannelProposalAcc) Encode(w io.Writer) error

Encode encodes the LedgerChannelProposalAcc into an io.Writer.

func (LedgerChannelProposalAcc) Type added in v0.5.2

Type returns wire.ChannelProposalAcc.

type NonceShare added in v0.4.1

type NonceShare = [32]byte

NonceShare is used to cooperatively calculate a channel's nonce.

type OptAppAndDataDec added in v0.4.1

type OptAppAndDataDec struct {
	App  *channel.App
	Data *channel.Data
}

OptAppAndDataDec makes an optional pair of App definition and Data decodable.

func (OptAppAndDataDec) Decode added in v0.4.1

func (o OptAppAndDataDec) Decode(r io.Reader) (err error)

Decode decodes an optional pair of App definition and Data.

type OptAppAndDataEnc added in v0.4.1

type OptAppAndDataEnc struct {
	channel.App
	channel.Data
}

OptAppAndDataEnc makes an optional pair of App definition and Data encodable.

func (OptAppAndDataEnc) Encode added in v0.4.1

func (o OptAppAndDataEnc) Encode(w io.Writer) error

Encode encodes an optional pair of App definition and Data.

type PeerRejectedError added in v0.7.0

type PeerRejectedError struct {
	ItemType string // ItemType indicates the type of item rejected (channel proposal or channel update).
	Reason   string // Reason sent by the peer for the rejection.
}

PeerRejectedError indicates the channel proposal or channel update was rejected by the peer.

func (PeerRejectedError) Error added in v0.7.0

func (e PeerRejectedError) Error() string

Error implements the error interface.

type ProposalHandler

type ProposalHandler interface {
	// HandleProposal is the user callback called by the Client on an incoming channel
	// proposal.
	// The response on the proposal responder must be called within the same go routine.
	HandleProposal(ChannelProposal, *ProposalResponder)
}

A ProposalHandler decides how to handle incoming channel proposals from other channel network peers.

type ProposalHandlerFunc added in v0.3.0

type ProposalHandlerFunc func(ChannelProposal, *ProposalResponder)

ProposalHandlerFunc is an adapter type to allow the use of functions as proposal handlers. ProposalHandlerFunc(f) is a ProposalHandler that calls f when HandleProposal is called.

func (ProposalHandlerFunc) HandleProposal added in v0.4.0

func (f ProposalHandlerFunc) HandleProposal(p ChannelProposal, r *ProposalResponder)

HandleProposal calls the proposal handler function.

type ProposalID added in v0.4.1

type ProposalID = [32]byte

ProposalID uniquely identifies the channel proposal as specified by the Channel Proposal Protocol (CPP).

type ProposalOpts added in v0.4.1

type ProposalOpts map[string]interface{}

ProposalOpts contains optional configuration instructions for channel proposals and channel proposal acceptance messages. Per default, NoApp and NoData is set, and a random nonce share is generated.

func WithApp added in v0.4.1

func WithApp(app channel.App, initData channel.Data) ProposalOpts

WithApp configures an app and initial data.

func WithFundingAgreement added in v0.5.2

func WithFundingAgreement(alloc channel.Balances) ProposalOpts

WithFundingAgreement configures a fixed funding agreement.

func WithNonce added in v0.4.1

func WithNonce(share NonceShare) ProposalOpts

WithNonce configures a fixed nonce share.

func WithNonceFrom added in v0.4.1

func WithNonceFrom(r io.Reader) ProposalOpts

WithNonceFrom reads a nonce share from a reader (should be random stream).

func WithRandomNonce added in v0.4.1

func WithRandomNonce() ProposalOpts

WithRandomNonce creates a nonce from crypto/rand.Reader.

func WithoutApp added in v0.4.1

func WithoutApp() ProposalOpts

WithoutApp configures a NoApp and NoData.

func (ProposalOpts) App added in v0.4.1

func (o ProposalOpts) App() channel.App

App returns the option's configured app.

func (ProposalOpts) AppData added in v0.4.1

func (o ProposalOpts) AppData() channel.Data

AppData returns the option's configured app data.

func (ProposalOpts) SetsApp added in v0.4.1

func (o ProposalOpts) SetsApp() bool

SetsApp returns whether an app and data have been explicitly set.

type ProposalResponder

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

ProposalResponder lets the user respond to a channel proposal. If the user wants to accept the proposal, they should call Accept(), otherwise Reject(). Only a single function must be called and every further call causes a panic.

func (*ProposalResponder) Accept

Accept lets the user signal that they want to accept the channel proposal. The ChannelProposalAcc message has to be created using ChannelProposal.Proposal().NewChannelProposalAcc on the proposal that was passed to the handler.

Accept returns the newly created channel controller if the channel was successfully created and funded. Panics if the proposal was already accepted or rejected.

After the channel controller got successfully set up, it is passed to the callback registered with Client.OnNewChannel. Accept returns after this callback has run.

It is important that the passed context does not cancel before twice the ChallengeDuration has passed (at least for real blockchain backends with wall time), or the channel cannot be settled if a peer times out funding.

After the channel got successfully created, the user is required to start the channel watcher with Channel.Watch() on the returned channel controller.

Returns TxTimedoutError when the program times out waiting for a transaction to be mined. Returns ChainNotReachableError if the connection to the blockchain network fails when sending a transaction to / reading from the blockchain.

func (*ProposalResponder) Reject

func (r *ProposalResponder) Reject(ctx context.Context, reason string) error

Reject lets the user signal that they reject the channel proposal. Returns whether the rejection message was successfully sent. Panics if the proposal was already accepted or rejected.

type RequestTimedOutError added in v0.7.0

type RequestTimedOutError string

RequestTimedOutError indicates that a peer has not responded within the expected time period.

func (RequestTimedOutError) Error added in v0.7.0

func (e RequestTimedOutError) Error() string

Error implements error interface for RequestTimedOutError.

type SubChannelProposal added in v0.5.0

type SubChannelProposal struct {
	BaseChannelProposal
	Parent channel.ID
}

SubChannelProposal is a channel proposal for subchannels.

func NewSubChannelProposal added in v0.5.0

func NewSubChannelProposal(
	parent channel.ID,
	challengeDuration uint64,
	initBals *channel.Allocation,
	opts ...ProposalOpts,
) (prop *SubChannelProposal, err error)

NewSubChannelProposal creates a subchannel proposal and applies the supplied options. For more information, see ProposalOpts.

func (SubChannelProposal) Accept added in v0.5.2

func (p SubChannelProposal) Accept(
	nonceShare ProposalOpts,
) *SubChannelProposalAcc

Accept constructs an accept message that belongs to a proposal message. It should be used instead of manually constructing an accept message.

func (*SubChannelProposal) Decode added in v0.5.0

func (p *SubChannelProposal) Decode(r io.Reader) error

Decode decodes a SubChannelProposal from an io.Reader.

func (SubChannelProposal) Encode added in v0.5.0

func (p SubChannelProposal) Encode(w io.Writer) error

Encode encodes the SubChannelProposal into an io.Writer.

func (SubChannelProposal) Matches added in v0.5.2

Matches requires that the accept message is a sub channel proposal accept message.

func (SubChannelProposal) ProposalID added in v0.5.2

func (p SubChannelProposal) ProposalID() (propID ProposalID)

ProposalID returns the identifier of this channel proposal request.

func (SubChannelProposal) Type added in v0.5.0

func (SubChannelProposal) Type() wire.Type

Type returns wire.SubChannelProposal.

type SubChannelProposalAcc added in v0.5.2

type SubChannelProposalAcc struct {
	BaseChannelProposalAcc
}

SubChannelProposalAcc is the accept message type corresponding to sub channel proposals.

func (*SubChannelProposalAcc) Base added in v0.5.2

Base returns the common proposal accept values.

func (*SubChannelProposalAcc) Decode added in v0.5.2

func (acc *SubChannelProposalAcc) Decode(r io.Reader) error

Decode decodes a SubChannelProposalAcc from an io.Reader.

func (SubChannelProposalAcc) Encode added in v0.5.2

func (acc SubChannelProposalAcc) Encode(w io.Writer) error

Encode encodes the SubChannelProposalAcc into an io.Writer.

func (SubChannelProposalAcc) Type added in v0.5.2

Type returns wire.SubChannelProposalAcc.

type TestChannel added in v0.2.0

type TestChannel struct {
	*Channel
}

TestChannel grants access to the `AdjudicatorRequest` which is otherwise hidden by `Channel`. Behaves like a `Channel` in all other cases.

Only used for testing.

func NewTestChannel added in v0.2.0

func NewTestChannel(c *Channel) *TestChannel

NewTestChannel creates a new `TestChannel` from a `Channel`.

func (*TestChannel) AdjudicatorReq added in v0.2.0

func (c *TestChannel) AdjudicatorReq() channel.AdjudicatorReq

AdjudicatorReq returns the `AdjudicatorReq` of the underlying machine.

type TxTimedoutError added in v0.7.0

type TxTimedoutError struct {
	TxType string // Type of the transaction.
	TxID   string // Transaction ID to track it on the blockchain.
}

TxTimedoutError indicates that we have timed out waiting for a transaction to be mined.

It can happen that this transaction can be eventually mined. So the user should of the framework should be watching for the transaction to be mined and decide on what to do.

func (TxTimedoutError) Error added in v0.7.0

func (e TxTimedoutError) Error() string

Error implements the error interface.

type UpdateHandler

type UpdateHandler interface {
	// HandleUpdate is the user callback called by the channel controller on an
	// incoming update request. The first argument contains the current state
	// of the channel before the update is applied. Clone it if you want to
	// modify it.
	HandleUpdate(*channel.State, ChannelUpdate, *UpdateResponder)
}

An UpdateHandler decides how to handle incoming channel update requests from other channel participants.

type UpdateHandlerFunc added in v0.3.0

type UpdateHandlerFunc func(*channel.State, ChannelUpdate, *UpdateResponder)

UpdateHandlerFunc is an adapter type to allow the use of functions as update handlers. UpdateHandlerFunc(f) is an UpdateHandler that calls f when HandleUpdate is called.

func (UpdateHandlerFunc) HandleUpdate added in v0.4.0

func (f UpdateHandlerFunc) HandleUpdate(s *channel.State, u ChannelUpdate, r *UpdateResponder)

HandleUpdate calls the update handler function.

type UpdateResponder

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

The UpdateResponder allows the user to react to the incoming channel update request. If the user wants to accept the update, Accept() should be called, otherwise Reject(), possibly giving a reason for the rejection. Only a single function must be called and every further call causes a panic.

func (*UpdateResponder) Accept

func (r *UpdateResponder) Accept(ctx context.Context) error

Accept lets the user signal that they want to accept the channel update.

func (*UpdateResponder) Reject

func (r *UpdateResponder) Reject(ctx context.Context, reason string) error

Reject lets the user signal that they reject the channel update.

type VirtualChannelProposal added in v0.7.0

type VirtualChannelProposal struct {
	BaseChannelProposal
	Proposer  wallet.Address    // Proposer's address in the channel.
	Peers     []wire.Address    // Participants' wire addresses.
	Parents   []channel.ID      // Parent channels for each participant.
	IndexMaps [][]channel.Index // Index mapping for each participant in relation to the root channel.
}

VirtualChannelProposal is a channel proposal for virtual channels.

func NewVirtualChannelProposal added in v0.7.0

func NewVirtualChannelProposal(
	challengeDuration uint64,
	participant wallet.Address,
	initBals *channel.Allocation,
	peers []wire.Address,
	parents []channel.ID,
	indexMaps [][]channel.Index,
	opts ...ProposalOpts,
) (prop *VirtualChannelProposal, err error)

NewVirtualChannelProposal creates a virtual channel proposal.

func (VirtualChannelProposal) Accept added in v0.7.0

Accept constructs an accept message that belongs to a proposal message.

func (*VirtualChannelProposal) Decode added in v0.7.0

func (p *VirtualChannelProposal) Decode(r io.Reader) error

Decode decodes a proposal from an io.Reader.

func (VirtualChannelProposal) Encode added in v0.7.0

func (p VirtualChannelProposal) Encode(w io.Writer) error

Encode encodes the proposal into an io.Writer.

func (VirtualChannelProposal) Matches added in v0.7.0

Matches requires that the accept message has the correct type.

func (VirtualChannelProposal) Type added in v0.7.0

Type returns the message type.

type VirtualChannelProposalAcc added in v0.7.0

type VirtualChannelProposalAcc struct {
	BaseChannelProposalAcc
	Responder wallet.Address // Responder's participant address.
}

VirtualChannelProposalAcc is the accept message type corresponding to virtual channel proposals.

func (*VirtualChannelProposalAcc) Base added in v0.7.0

Base returns the common proposal accept values.

func (*VirtualChannelProposalAcc) Decode added in v0.7.0

func (acc *VirtualChannelProposalAcc) Decode(r io.Reader) error

Decode decodes a message from an io.Reader.

func (VirtualChannelProposalAcc) Encode added in v0.7.0

func (acc VirtualChannelProposalAcc) Encode(w io.Writer) error

Encode encodes the message into an io.Writer.

func (VirtualChannelProposalAcc) Type added in v0.7.0

Type returns the message type.

Directories

Path Synopsis
Package test contains testing setup types and functions for package client.
Package test contains testing setup types and functions for package client.

Jump to

Keyboard shortcuts

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