channel

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package channel contains all relevant components to generate, utilize and conclude payment channels on the Stellar blockchain. These main components consist of the Funder and Adjudicator interfaces that govern the interaction between the channel users. Additionally, the AdjEventSub interface processes the emitted events from the Soroban smart contracts, using the interfaces from go-perun.

Index

Constants

View Source
const (
	DefaultBufferSize                  = 1024
	DefaultSubscriptionPollingInterval = time.Duration(5) * time.Second
)
View Source
const AssertPerunSymbol = "perun"
View Source
const DefaultPollingInterval = time.Duration(6) * time.Second
View Source
const DefaultTimeoutPollInterval = 1 * time.Second

DefaultTimeoutPollInterval default value for the PollInterval of a Timeout.

View Source
const MaxIterationsUntilAbort = 20
View Source
const PerunContractPath = "../testdata/perun_soroban_contract.wasm"

Variables

View Source
var (
	STELLAR_PERUN_CHANNEL_CONTRACT_TOPICS = map[xdr.ScSymbol]EventType{
		xdr.ScSymbol("open"):     EventTypeOpen,
		xdr.ScSymbol("fund"):     EventTypeFundChannel,
		xdr.ScSymbol("fund_c"):   EventTypeFundedChannel,
		xdr.ScSymbol("closed"):   EventTypeClosed,
		xdr.ScSymbol("withdraw"): EventTypeWithdrawing,
		xdr.ScSymbol("pay_c"):    EventTypeWithdrawn,
		xdr.ScSymbol("f_closed"): EventTypeForceClosed,
		xdr.ScSymbol("dispute"):  EventTypeDisputed,
	}

	ErrNotStellarPerunContract = errors.New("event was not from a Perun payment channel contract")
	ErrEventUnsupported        = errors.New("this type of event is unsupported")
	ErrEventIntegrity          = errors.New("contract ID does not match payment channel + passphrase")
)
View Source
var Backend = backend{}
View Source
var ErrChannelAlreadyClosed = errors.New("channel is already closed")

Functions

func AssembleCreateContractOp

func AssembleCreateContractOp(sourceAccount string, wasmFileName string, contractSalt string, passPhrase string) *txnbuild.InvokeHostFunction

func AssembleInstallContractCodeOp

func AssembleInstallContractCodeOp(sourceAccount string, wasmFileName string) *txnbuild.InvokeHostFunction

func BuildCloseTxArgs

func BuildCloseTxArgs(state pchannel.State, sigs []pwallet.Sig) (xdr.ScVec, error)

func BuildDisputeTxArgs

func BuildDisputeTxArgs(state pchannel.State, sigs []pwallet.Sig) (xdr.ScVec, error)

func EncodeState

func EncodeState(state *channel.State) ([]byte, error)

func GetChannelBoolFromEvents

func GetChannelBoolFromEvents(evData xdr.ScVal) (wire.Channel, bool, error)

func GetChannelFromEvents

func GetChannelFromEvents(evData xdr.ScVal) (wire.Channel, error)

func IdenticalControls

func IdenticalControls(controlCurr, controlNext wire.Control) bool

func MakeTime

func MakeTime(challDurSec uint64) time.Duration

MakeTime creates a new time from the argument.

Types

type AdjEvent

type AdjEvent interface {
	// Sets the necessary event data from the channel information
	EventDataFromChannel(cchanState wire.Channel, timestamp uint64) error
	ID() pchannel.ID
	Timeout() pchannel.Timeout
	Version() Version
	Tstamp() uint64
}

func DifferencesInControls

func DifferencesInControls(controlCurr, controlNext wire.Control) (AdjEvent, error)

type AdjEventSub

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

AdjudicatorSub implements the AdjudicatorSubscription interface.

func NewAdjudicatorSub

func NewAdjudicatorSub(ctx context.Context, cid pchannel.ID, stellarClient *env.StellarClient, perunID xdr.ScAddress, assetID xdr.ScAddress) (*AdjEventSub, error)

func (*AdjEventSub) Close

func (s *AdjEventSub) Close() error

func (*AdjEventSub) Err

func (s *AdjEventSub) Err() error

func (*AdjEventSub) GetChannelState

func (s *AdjEventSub) GetChannelState(chanArgs xdr.ScVec) (wire.Channel, error)

func (*AdjEventSub) Next

type Adjudicator

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

func NewAdjudicator

func NewAdjudicator(acc *wallet.Account, stellarClient *env.StellarClient, perunID xdr.ScAddress, assetID xdr.ScAddress) *Adjudicator

func (*Adjudicator) BuildWithdrawTxArgs

func (a *Adjudicator) BuildWithdrawTxArgs(req pchannel.AdjudicatorReq) (xdr.ScVec, error)

func (*Adjudicator) Close

func (a *Adjudicator) Close(ctx context.Context, id pchannel.ID, state *pchannel.State, sigs []pwallet.Sig) error

func (*Adjudicator) Dispute

func (a *Adjudicator) Dispute(ctx context.Context, state *pchannel.State, sigs []pwallet.Sig) error

func (*Adjudicator) ForceClose

func (a *Adjudicator) ForceClose(ctx context.Context, id pchannel.ID, state *pchannel.State, sigs []pwallet.Sig, params *pchannel.Params) error

func (*Adjudicator) GetAssetID

func (a *Adjudicator) GetAssetID() xdr.ScAddress

func (*Adjudicator) GetChannelState

func (a *Adjudicator) GetChannelState(ctx context.Context, state *pchannel.State) (wire.Channel, error)

func (*Adjudicator) GetPerunID

func (a *Adjudicator) GetPerunID() xdr.ScAddress

func (Adjudicator) Progress

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

func (*Adjudicator) Register

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

Register registers and disputes a channel.

func (*Adjudicator) Subscribe

func (*Adjudicator) Withdraw

type CloseEvent

type CloseEvent struct {
	Channel   wire.Channel
	IDV       pchannel.ID
	VersionV  Version
	Timestamp uint64
}

func (*CloseEvent) EventDataFromChannel

func (e *CloseEvent) EventDataFromChannel(chanState wire.Channel, timestamp uint64) error

func (*CloseEvent) GetChannel

func (e *CloseEvent) GetChannel() wire.Channel

func (*CloseEvent) ID

func (e *CloseEvent) ID() pchannel.ID

func (*CloseEvent) Timeout

func (e *CloseEvent) Timeout() pchannel.Timeout

func (*CloseEvent) Tstamp

func (e *CloseEvent) Tstamp() uint64

func (*CloseEvent) Version

func (e *CloseEvent) Version() Version

type DisputedEvent

type DisputedEvent struct {
	Channel   wire.Channel
	IDV       pchannel.ID
	VersionV  Version
	Timestamp uint64
}

func (*DisputedEvent) EventDataFromChannel

func (e *DisputedEvent) EventDataFromChannel(chanState wire.Channel, timestamp uint64) error

func (*DisputedEvent) ID

func (e *DisputedEvent) ID() pchannel.ID

func (*DisputedEvent) Timeout

func (e *DisputedEvent) Timeout() pchannel.Timeout

func (*DisputedEvent) Tstamp

func (e *DisputedEvent) Tstamp() uint64

func (*DisputedEvent) Version

func (e *DisputedEvent) Version() Version

type Event

type Event = xdr.ContractEvent

type EventType

type EventType int
const (
	EventTypeOpen          EventType = iota
	EventTypeFundChannel             // participant/s funding channel
	EventTypeFundedChannel           // participants have funded channel
	EventTypeClosed                  // channel closed -> withdrawing enabled
	EventTypeWithdrawing             // participant/s withdrawing
	EventTypeWithdrawn               // participants have withdrawn
	EventTypeForceClosed             // participant has force closed the channel
	EventTypeDisputed                // participant has disputed the channel
)

type ExpiredTimeout

type ExpiredTimeout struct{}

ExpiredTimeout is always expired. Implements the Perun Timeout interface.

func NewExpiredTimeout

func NewExpiredTimeout() *ExpiredTimeout

NewExpiredTimeout returns a new ExpiredTimeout.

func (*ExpiredTimeout) IsElapsed

func (*ExpiredTimeout) IsElapsed(context.Context) bool

func (*ExpiredTimeout) Wait

Wait returns nil.

type FundEvent

type FundEvent struct {
	Channel   wire.Channel
	IDV       pchannel.ID
	VersionV  Version
	Timestamp uint64
}

func (*FundEvent) EventDataFromChannel

func (e *FundEvent) EventDataFromChannel(chanState wire.Channel, timestamp uint64) error

func (*FundEvent) ID

func (e *FundEvent) ID() pchannel.ID

func (*FundEvent) Timeout

func (e *FundEvent) Timeout() pchannel.Timeout

func (*FundEvent) Tstamp

func (e *FundEvent) Tstamp() uint64

func (*FundEvent) Version

func (e *FundEvent) Version() Version

type Funder

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

func NewFunder

func NewFunder(acc *wallet.Account, stellarClient *env.StellarClient, perunID xdr.ScAddress, assetID xdr.ScAddress) *Funder

func (*Funder) AbortChannel

func (f *Funder) AbortChannel(ctx context.Context, params *pchannel.Params, state *pchannel.State) error

func (*Funder) Fund

func (f *Funder) Fund(ctx context.Context, req pchannel.FundingReq) error

func (*Funder) FundChannel

func (f *Funder) FundChannel(ctx context.Context, params *pchannel.Params, state *pchannel.State, funderIdx bool) error

func (*Funder) GetAssetID

func (f *Funder) GetAssetID() xdr.ScAddress

func (*Funder) GetChannelState

func (f *Funder) GetChannelState(ctx context.Context, params *pchannel.Params, state *pchannel.State) (wire.Channel, error)

func (*Funder) GetPerunID

func (f *Funder) GetPerunID() xdr.ScAddress

func (*Funder) OpenChannel

func (f *Funder) OpenChannel(ctx context.Context, params *pchannel.Params, state *pchannel.State) error

type OpenEvent

type OpenEvent struct {
	Channel   wire.Channel
	IDV       pchannel.ID
	VersionV  Version
	Timestamp uint64
}

func (*OpenEvent) GetChannel

func (e *OpenEvent) GetChannel() wire.Channel

func (*OpenEvent) ID

func (e *OpenEvent) ID() pchannel.ID

func (*OpenEvent) Timeout

func (e *OpenEvent) Timeout() pchannel.Timeout

func (*OpenEvent) Tstamp

func (e *OpenEvent) Tstamp() uint64

func (*OpenEvent) Version

func (e *OpenEvent) Version() Version

type PerunEvent

type PerunEvent interface {
	ID() pchannel.ID
	Timeout() pchannel.Timeout
	Version() Version
}

func DecodeEventsPerun

func DecodeEventsPerun(txMeta xdr.TransactionMeta) ([]PerunEvent, error)

type StellarEvent

type StellarEvent struct {
	Type         EventType
	ChannelState wire.Channel
}

func (*StellarEvent) GetType

func (e *StellarEvent) GetType() EventType

type TimePoint

type TimePoint uint64

TimePoint as defined by pallet Timestamp.

type Timeout

type Timeout struct {
	log.Embedding
	// contains filtered or unexported fields
}

Timeout can be used to wait until a specific timepoint is reached by the blockchain. Implements the Perun Timeout interface.

func MakeTimeout

func MakeTimeout(challDurSec uint64) *Timeout

MakeTimeout creates a new timeout.

func NewTimeout

func NewTimeout(when time.Time, pollInterval time.Duration) *Timeout

NewTimeout returns a new Timeout which expires at the given time.

func (*Timeout) IsElapsed

func (t *Timeout) IsElapsed(ctx context.Context) bool

IsElapsed returns whether the timeout is elapsed.

func (*Timeout) Wait

func (t *Timeout) Wait(ctx context.Context) error

Wait waits for the timeout or until the context is cancelled.

type Version

type Version = uint64

type WithdrawnEvent

type WithdrawnEvent struct {
	Channel   wire.Channel
	IDV       pchannel.ID
	VersionV  Version
	Timestamp uint64
}

func (*WithdrawnEvent) EventDataFromChannel

func (e *WithdrawnEvent) EventDataFromChannel(chanState wire.Channel, timestamp uint64) error

func (*WithdrawnEvent) GetChannel

func (e *WithdrawnEvent) GetChannel() wire.Channel

func (*WithdrawnEvent) ID

func (e *WithdrawnEvent) ID() pchannel.ID

func (*WithdrawnEvent) Timeout

func (e *WithdrawnEvent) Timeout() pchannel.Timeout

func (WithdrawnEvent) Tstamp

func (e WithdrawnEvent) Tstamp() uint64

func (*WithdrawnEvent) Version

func (e *WithdrawnEvent) Version() Version

Directories

Path Synopsis
Package env provides the functionality to connect to the Stellar blockchain and broadcast transactions to the network and decode its response.
Package env provides the functionality to connect to the Stellar blockchain and broadcast transactions to the network and decode its response.
Package types defines the stellar asset that is used in payment channels.
Package types defines the stellar asset that is used in payment channels.

Jump to

Keyboard shortcuts

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