channel

package
v0.0.0-...-7bd1b19 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CreatedTag   = "Created"
	DepositedTag = "Deposited"
	DisputedTag  = "Disputed"
	ConcludedTag = "Concluded"
)
View Source
const (
	ContractEndpoint    = "/api/contract"
	ActivateEndpoint    = ContractEndpoint + "/activate"
	InstanceEndpoint    = ContractEndpoint + "/instance"
	WebSocketEndpoint   = "/ws"
	StartEndpointFormat = InstanceEndpoint + "/%s/endpoint/start"
	FundEndpointFormat  = InstanceEndpoint + "/%s/endpoint/fund"
	CloseEndpointFormat = InstanceEndpoint + "/%s/endpoint/close"
)

Variables

View Source
var (
	MismatchingChannelTokenError = errors.New("mismatching channel tokens")
	MismatchingChannelIDError    = errors.New("mismatching channel ids")
)
View Source
var Backend backend

Functions

func SetWalletBackend

func SetWalletBackend(remoteBackend types.ExtendedWalletBackend)

SetWalletBackend needs to be called initially.

Types

type Adjudicator

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

func NewAdjudicator

func NewAdjudicator(pab *PAB) *Adjudicator

func (Adjudicator) Progress

func (a Adjudicator) Progress(ctx context.Context, req channel.ProgressReq) error

func (Adjudicator) Register

func (a Adjudicator) Register(ctx context.Context, req channel.AdjudicatorReq, states []channel.SignedState) error

func (Adjudicator) Subscribe

func (Adjudicator) Withdraw

func (a Adjudicator) Withdraw(ctx context.Context, req channel.AdjudicatorReq, stateMap channel.StateMap) error

type AdjudicatorSub

type AdjudicatorSub struct {
	ChannelID types.ID

	// IsPerunSub specifies whether a subscription yields Perun events or Internal events.
	IsPerunSub bool
	// contains filtered or unexported fields
}

AdjudicatorSub is a subscription to the Adjudicator events. Instances should only be created using PAB.NewSubscription.

func (AdjudicatorSub) Close

func (a AdjudicatorSub) Close() error

Close closes the subscription.

func (AdjudicatorSub) Err

func (a AdjudicatorSub) Err() error

Err returns the error after a call to Next returned nil, or nil if there is no error. Once Err returns a non-nil error, all subsequent calls to Err will return the same error. It is important to only interact with one Subscription from a single go-routine!

func (AdjudicatorSub) Next

Next returns the next AdjudicatorEvent. It blocks until the next event is available. If the subscription is closed, or there is an error, it returns nil. Once Next returns nil, a subsequent call to Err will return the error that caused the subscription to close and all subsequent calls to Next will also return nil. It is important to only interact with one Subscription from a single go-routine! Note: This may return either a types.InternalEvent or an AdjudicatorEvent depending on the type of the subscription.

type Concluded

type Concluded struct {
	ChannelID types.ID
	OldDatum  types.ChannelDatum
}

func (Concluded) FromEvent

func (c Concluded) FromEvent(id types.ID, ev wire.Event) (Concluded, error)

func (Concluded) ID

func (c Concluded) ID() channel.ID

func (Concluded) Timeout

func (c Concluded) Timeout() channel.Timeout

func (Concluded) ToPerunEvent

func (c Concluded) ToPerunEvent() channel.AdjudicatorEvent

func (Concluded) Version

func (c Concluded) Version() uint64

type Created

type Created struct {
	ChannelID types.ID
	NewDatum  types.ChannelDatum
}

func (Created) FromEvent

func (c Created) FromEvent(id types.ID, ev wire.Event) (Created, error)

func (Created) ID

func (c Created) ID() channel.ID

func (Created) Timeout

func (c Created) Timeout() channel.Timeout

func (Created) ToPerunEvent

func (c Created) ToPerunEvent() channel.AdjudicatorEvent

func (Created) Version

func (c Created) Version() uint64

type Deposited

type Deposited struct {
	ChannelID types.ID
	OldDatum  types.ChannelDatum
	NewDatum  types.ChannelDatum
}

func (Deposited) FromEvent

func (d Deposited) FromEvent(id types.ID, ev wire.Event) (Deposited, error)

func (Deposited) ID

func (d Deposited) ID() channel.ID

func (Deposited) Timeout

func (d Deposited) Timeout() channel.Timeout

func (Deposited) ToPerunEvent

func (d Deposited) ToPerunEvent() channel.AdjudicatorEvent

func (Deposited) Version

func (d Deposited) Version() uint64

type Disputed

type Disputed struct {
	ChannelID  types.ID
	OldDatum   types.ChannelDatum
	NewDatum   types.ChannelDatum
	Signatures []wallet.Sig
}

func (Disputed) FromEvent

func (d Disputed) FromEvent(id types.ID, ev wire.Event) (Disputed, error)

func (Disputed) ID

func (d Disputed) ID() channel.ID

func (Disputed) Timeout

func (d Disputed) Timeout() channel.Timeout

func (Disputed) ToPerunEvent

func (d Disputed) ToPerunEvent() channel.AdjudicatorEvent

func (Disputed) Version

func (d Disputed) Version() uint64

type Funder

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

func NewFunder

func NewFunder(pab *PAB) *Funder

func (Funder) ExpectAndHandleDepositedEvent

func (f Funder) ExpectAndHandleDepositedEvent(id types.ID, sub *AdjudicatorSub, idx channel.Index) error

func (Funder) ExpectAndHandleStartEvent

func (f Funder) ExpectAndHandleStartEvent(id types.ID, sub *AdjudicatorSub, state types.ChannelState) error

func (Funder) Fund

func (f Funder) Fund(_ context.Context, req channel.FundingReq) error

type InternalEvent

type InternalEvent interface {
	channel.AdjudicatorEvent
	ToPerunEvent() channel.AdjudicatorEvent
}

type PAB

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

PAB is a client for the PAB server. It is used to create and interact with Perun Channel contracts through the PAB server. It is also used to create event subscriptions for channels. One PAB instance can be used by one account to create multiple channels and create an arbitrary number of subscriptions per channel.

func NewPAB

func NewPAB(host string, acc wallet.RemoteAccount) (*PAB, error)

NewPAB creates a new PAB instance. It expects a host string in the format "host:port" (e.g. "localhost:9080").

func (*PAB) Abort

func (p *PAB) Abort()

Abort issues a request to the PAB to abort the channel. This only works on channels that are not completely funded yet.

func (*PAB) CallEndpoint

func (r *PAB) CallEndpoint(endpoint string, body interface{}, result interface{}) error

CallEndpoint calls the given endpoint on the remote wallet and decodes the json response into the given result. `result` must be a pointer.

func (*PAB) Close

func (p *PAB) Close(id channel.ID, params types.ChannelParameters, state types.ChannelState, sigs []gpwallet.Sig) error

Close issues a request to the PAB to close the channel with the given parameters and final state.

func (*PAB) Dispute

func (p *PAB) Dispute()

Dispute issues a request to the PAB to dispute the channel.

func (*PAB) ForceClose

func (p *PAB) ForceClose()

ForceClose issues a request to the PAB to force close the channel with the given parameters and state. This settles the current on-chain state of the channel. One can only force close a channel, if it was disputed beforehand and the relative time-lock has expired.

func (*PAB) Fund

func (p *PAB) Fund(cid channel.ID, index channel.Index) error

Fund issues a request to the PAB to fund the channel with the given parameters.

func (*PAB) GetChannelToken

func (p *PAB) GetChannelToken(id channel.ID) (types.ChannelToken, error)

func (*PAB) GetContractInstanceID

func (p *PAB) GetContractInstanceID() string

func (*PAB) NewInternalSubscription

func (p *PAB) NewInternalSubscription(id channel.ID) (*AdjudicatorSub, error)

NewInternalSubscription creates a new adjudicator subscription for the given channel. The subscription will return internal events. These are more specific to the Cardano implementation of the Perun contract and contain more information. The internal events can not be used for anything go-perun related. For this use NewPerunEventSubscription instead. Care: Only ever interact with the subscription's Next and Err methods from within the same goroutine.

func (*PAB) NewPerunEventSubscription

func (p *PAB) NewPerunEventSubscription(id channel.ID) (*AdjudicatorSub, error)

NewPerunEventSubscription creates a new adjudicator subscription for the given channel. The subscription will return perun events (generalized events compatible with the go-perun core). Care: Only ever interact with the subscription's Next and Err methods from within the same goroutine.

func (*PAB) SetChannelToken

func (p *PAB) SetChannelToken(id channel.ID, token types.ChannelToken) error

func (*PAB) Start

func (p *PAB) Start(cid channel.ID, params types.ChannelParameters, state types.ChannelState) error

Start issues a request to the PAB to start the channel with the given parameters and initial state.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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