Documentation ¶
Index ¶
- Constants
- Variables
- func SetWalletBackend(remoteBackend types.ExtendedWalletBackend)
- type Adjudicator
- func (a Adjudicator) Progress(ctx context.Context, req channel.ProgressReq) error
- func (a Adjudicator) Register(ctx context.Context, req channel.AdjudicatorReq, states []channel.SignedState) error
- func (a Adjudicator) Subscribe(ctx context.Context, id channel.ID) (channel.AdjudicatorSubscription, error)
- func (a Adjudicator) Withdraw(ctx context.Context, req channel.AdjudicatorReq, stateMap channel.StateMap) error
- type AdjudicatorSub
- type Concluded
- type Created
- type Deposited
- type Disputed
- type Funder
- type InternalEvent
- type PAB
- func (p *PAB) Abort()
- func (r *PAB) CallEndpoint(endpoint string, body interface{}, result interface{}) error
- func (p *PAB) Close(id channel.ID, params types.ChannelParameters, state types.ChannelState, ...) error
- func (p *PAB) Dispute()
- func (p *PAB) ForceClose()
- func (p *PAB) Fund(cid channel.ID, index channel.Index) error
- func (p *PAB) GetChannelToken(id channel.ID) (types.ChannelToken, error)
- func (p *PAB) GetContractInstanceID() string
- func (p *PAB) NewInternalSubscription(id channel.ID) (*AdjudicatorSub, error)
- func (p *PAB) NewPerunEventSubscription(id channel.ID) (*AdjudicatorSub, error)
- func (p *PAB) SetChannelToken(id channel.ID, token types.ChannelToken) error
- func (p *PAB) Start(cid channel.ID, params types.ChannelParameters, state types.ChannelState) error
Constants ¶
const ( CreatedTag = "Created" DepositedTag = "Deposited" DisputedTag = "Disputed" ConcludedTag = "Concluded" )
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 ¶
var ( MismatchingChannelTokenError = errors.New("mismatching channel tokens") MismatchingChannelIDError = errors.New("mismatching channel ids") )
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 (a Adjudicator) Subscribe(ctx context.Context, id channel.ID) (channel.AdjudicatorSubscription, error)
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) 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 ¶
func (a AdjudicatorSub) Next() gpchannel.AdjudicatorEvent
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) ToPerunEvent ¶
func (c Concluded) ToPerunEvent() channel.AdjudicatorEvent
type Created ¶
type Created struct { ChannelID types.ID NewDatum types.ChannelDatum }
func (Created) ToPerunEvent ¶
func (c Created) ToPerunEvent() channel.AdjudicatorEvent
type Deposited ¶
type Deposited struct { ChannelID types.ID OldDatum types.ChannelDatum NewDatum types.ChannelDatum }
func (Deposited) ToPerunEvent ¶
func (d Deposited) ToPerunEvent() channel.AdjudicatorEvent
type Disputed ¶
type Disputed struct { ChannelID types.ID OldDatum types.ChannelDatum NewDatum types.ChannelDatum Signatures []wallet.Sig }
func (Disputed) ToPerunEvent ¶
func (d Disputed) ToPerunEvent() channel.AdjudicatorEvent
type Funder ¶
type Funder struct {
// contains filtered or unexported fields
}
func (Funder) ExpectAndHandleDepositedEvent ¶
func (Funder) ExpectAndHandleStartEvent ¶
func (f Funder) ExpectAndHandleStartEvent(id types.ID, sub *AdjudicatorSub, state types.ChannelState) 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 ¶
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) GetChannelToken ¶
func (*PAB) GetContractInstanceID ¶
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 (*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.