channel

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Overview

Package channel contains the Polkadot channel backend implementation.

Index

Constants

View Source
const (
	// OffIdentityLen is the length of an OffIdentity in byte.
	OffIdentityLen = 32
	// OnIdentityLen is the length of an OnIdentity in byte.
	OnIdentityLen = 32
	// NonceLen is the length of a Nonce in byte.
	NonceLen = 32
	// SigLen is the length of a Sig in byte.
	SigLen = 64
	// FIDLen is the length of a FundingId in byte.
	FIDLen = 32
)

Variables

View Source
var (
	// MaxBalance is the highest possible value of a Balance.
	// Substrate uses U128 for balance representation as opposed to go-perun
	// which uses big.Int so this restriction is necessary.
	MaxBalance Balance = types.NewU128(*new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 128), big.NewInt(1)))

	// ErrNonceOutOfRange a nonce was out of range of valid values.
	ErrNonceOutOfRange = errors.New("nonce values was out of range")
	// ErrAllocIncompatible an allocation was incompatible.
	ErrAllocIncompatible = errors.New("incompatible allocation")
	// ErrStateIncompatible a state was incompatible.
	ErrStateIncompatible = errors.New("incompatible state")
	// ErrIdentLenMismatch the length of an identity was wrong.
	ErrIdentLenMismatch = errors.New("length of an identity was wrong")
)
View Source
var Asset = &asset{}

Asset is the unique asset that is supported by the chain.

View Source
var Backend backend

Backend is the channel backend. Is a singleton since there is only one backend.

Functions

func CalcID

func CalcID(params *pchannel.Params) (id pchannel.ID)

CalcID calculates the channelID by encoding and hashing the params.

func EventIsConcluded

func EventIsConcluded(cid ChannelID) func(PerunEvent) bool

EventIsConcluded checks whether an event is a ConcludedEvent for a specific channel.

func EventIsDeposited

func EventIsDeposited(e PerunEvent) bool

EventIsDeposited returns whether an event is a DepositedEvent.

func EventIsDisputed

func EventIsDisputed(cid ChannelID) func(PerunEvent) bool

EventIsDisputed checks whether an event is a DisputedEvent for a specific channel.

func EventIsProgressed added in v0.2.0

func EventIsProgressed(cid ChannelID) func(PerunEvent) bool

EventIsProgressed checks whether an event is a ProgressedEvent for a specific channel.

func EventIsWithdrawn

func EventIsWithdrawn(e PerunEvent) bool

EventIsWithdrawn returns whether an event is a WithdrawnEvent.

func MakeDuration

func MakeDuration(sec ChallengeDuration) time.Duration

MakeDuration creates a new duration from the argument.

func MakePerunAlloc

func MakePerunAlloc(bals []Balance) pchannel.Allocation

MakePerunAlloc creates a new Perun allocation and fills the Locked balances with a default value. It uses the fixed backend asset.

func MakePerunBalance

func MakePerunBalance(bal Balance) *big.Int

MakePerunBalance creates a Perun balance.

func MakePerunBalances

func MakePerunBalances(bals []Balance) pchannel.Balances

MakePerunBalances creates Perun balances with the fixed backend asset.

func MakePerunChallengeDuration

func MakePerunChallengeDuration(sec ChallengeDuration) uint64

MakePerunChallengeDuration creates a new Perun ChallengeDuration.

func MakeTime

func MakeTime(sec ChallengeDuration) time.Time

MakeTime creates a new time from the argument.

func MakeTimeout

func MakeTimeout(sec ChallengeDuration, storage substrate.StorageQueryer) pchannel.Timeout

MakeTimeout creates a new timeout.

func NewPerunState

func NewPerunState(s *State, app pchannel.App) *pchannel.State

NewPerunState creates a new Perun state and fills the App-Data with a default value.

func ScaleDecode

func ScaleDecode(obj interface{}, data []byte) error

ScaleDecode decodes any struct according to the SCALE codec.

func ScaleEncode

func ScaleEncode(obj interface{}) ([]byte, error)

ScaleEncode encodes any struct according to the SCALE codec.

Types

type AppID added in v0.2.0

type AppID = OffIdentity

AppID is the identifier of a channel application.

type Balance

type Balance = types.U128

Balance is the balance of an on- or off-chain Address.

func MakeAlloc

func MakeAlloc(a *pchannel.Allocation) ([]Balance, error)

MakeAlloc converts an Allocation to Balances. Currently, it supports only a single asset.

func MakeBalance

func MakeBalance(bal *big.Int) (Balance, error)

MakeBalance creates a new Balance.

type ChallengeDuration

type ChallengeDuration = uint64

ChallengeDuration the duration of a challenge as defined by go-perun.

func MakeChallengeDuration

func MakeChallengeDuration(challengeDuration uint64) ChallengeDuration

MakeChallengeDuration creates a new ChallengeDuration from the argument.

type ChannelID

type ChannelID = pchannel.ID

ChannelID the ID of a channel as defined by go-perun.

type ConcludedEvent

type ConcludedEvent struct {
	Phase  types.Phase // required
	Cid    ChannelID
	Topics []types.Hash // required
}

ConcludedEvent is emitted when a channel is concluded.

type DepositedEvent

type DepositedEvent struct {
	Phase   types.Phase // required
	Fid     FundingID
	Balance Balance      // total deposit of the Fid
	Topics  []types.Hash // required
}

DepositedEvent is emitted when a deposit is received.

type DisputePhase added in v0.2.0

type DisputePhase = uint8
const (
	RegisterPhase DisputePhase = iota
	ProgressPhase
	ConcludePhase
)

type DisputedEvent

type DisputedEvent struct {
	Phase  types.Phase // required
	Cid    ChannelID
	State  State
	Topics []types.Hash // required
}

DisputedEvent is emitted when a dispute was opened or updated.

type EventRecords

type EventRecords struct {
	types.EventRecords

	PerunModule_Deposited  []DepositedEvent  // nolint: stylecheck
	PerunModule_Disputed   []DisputedEvent   // nolint: stylecheck
	PerunModule_Progressed []ProgressedEvent // nolint: stylecheck
	PerunModule_Concluded  []ConcludedEvent  // nolint: stylecheck
	PerunModule_Withdrawn  []WithdrawnEvent  // nolint: stylecheck
}

EventRecords contains all events that can be emitted by a substrate chain that has the the Perun pallet deployed.

func (*EventRecords) Events

func (r *EventRecords) Events() []PerunEvent

Events extracts all Perun events into one slice and returns it.

type Funding

type Funding struct {
	// Channel is the channel to fund.
	Channel ChannelID
	// Part is the participant who wants to fund.
	Part OffIdentity
}

Funding is used to calculate a FundingId.

func MakeFundingReq

func MakeFundingReq(req *pchannel.FundingReq) (Funding, error)

MakeFundingReq creates a new Funding.

func NewFunding

func NewFunding(id ChannelID, part OffIdentity) *Funding

NewFunding returns a new Funding.

func (Funding) ID

func (p Funding) ID() (FundingID, error)

ID calculates the funding ID by encoding and hashing the Funding.

type FundingID

type FundingID = [FIDLen]byte

FundingID used to a the funding of a participant in a channel.

type Nonce

type Nonce = [NonceLen]byte

Nonce makes a channels ID unique by providing randomness to the params.

func MakeNonce

func MakeNonce(nonce *big.Int) (Nonce, error)

MakeNonce creates a new Nonce or an error if the argument was out of range.

type OffIdentity

type OffIdentity = [OffIdentityLen]byte

OffIdentity is an off-chain identity.

func MakeOffIdent

func MakeOffIdent(part pwallet.Address) (OffIdentity, error)

MakeOffIdent creates a new OffIdentity.

func MakeOffIdents

func MakeOffIdents(parts []pwallet.Address) ([]OffIdentity, error)

MakeOffIdents creates a new []OffIdentity.

type OnIdentity

type OnIdentity = [OnIdentityLen]byte

OnIdentity is an on-chain identity.

func MakeOnIdent

func MakeOnIdent(addr pwallet.Address) (OnIdentity, error)

MakeOnIdent creates a new OnIdentity.

type Params

type Params struct {
	// Nonce is the unique nonce of a channel.
	Nonce Nonce
	// Participants are the off-chain participants of a channel.
	Participants []OffIdentity
	// ChallengeDuration is the duration that disputes can be refuted in.
	ChallengeDuration ChallengeDuration
	// App is the identifier of the channel application.
	App AppID
}

Params holds the fixed parameters of a channel and uniquely identifies it.

func NewParams

func NewParams(p *pchannel.Params) (*Params, error)

NewParams creates backend-specific parameters from generic Perun parameters.

type PerunEvent

type PerunEvent interface{}

PerunEvent is a Perun event.

type ProgressedEvent added in v0.2.0

type ProgressedEvent struct {
	Phase   types.Phase // required
	Cid     ChannelID
	Version Version
	App     AppID
	Topics  []types.Hash // required
}

ProgressedEvent is emitted when a channel state was progressed.

type RegisteredState

type RegisteredState struct {
	// Phase is the phase of the dispute.
	Phase DisputePhase
	// State is the state of the channel.
	State State
	// Timeout is the duration that the dispute can be refuted in.
	Timeout ChallengeDuration
}

RegisteredState is a channel state that was registered on-chain.

type Sig

type Sig = [SigLen]byte

Sig is an off-chain signature.

func MakeSig

func MakeSig(sig pwallet.Sig) (Sig, error)

MakeSig creates a new Sig.

func MakeSigs

func MakeSigs(sigs []pwallet.Sig) ([]Sig, error)

MakeSigs creates Sigs.

type State

type State struct {
	// Channel is the unique ID of the channel that this state belongs to.
	Channel ChannelID
	// Version is the version of the state.
	Version Version
	// Balances are the balances of the participants.
	Balances []Balance
	// Final whether or not this state is the final one.
	Final bool
	// Data is the channel's application data.
	Data []byte
}

State is the state of a channel.

func NewState

func NewState(s *pchannel.State) (*State, error)

NewState creates a new State. It discards app data because app-channels are currently not supported.

type Version

type Version = uint64

Version of a state as defined by go-perun.

type Withdrawal

type Withdrawal struct {
	// Channel is the channel from which to withdraw.
	Channel ChannelID
	// Part is the participant who wants to withdraw.
	Part OffIdentity
	// Receiver is the receiver of the withdrawal.
	Receiver OnIdentity
}

Withdrawal is used by a participant to withdraw his on-chain funds.

func NewWithdrawal

func NewWithdrawal(cid pchannel.ID, part, receiver pwallet.Address) (*Withdrawal, error)

NewWithdrawal creates a new Withdrawal.

type WithdrawnEvent

type WithdrawnEvent struct {
	Phase  types.Phase // required
	Fid    FundingID
	Topics []types.Hash // required
}

WithdrawnEvent is emitted when all funds are withdrawn from a funding ID.

Directories

Path Synopsis
Package pallet implements functions to interact with a Perun pallet.
Package pallet implements functions to interact with a Perun pallet.
test
Package test provides helper and setup functions to test the pallet package.
Package test provides helper and setup functions to test the pallet package.
Package test provides helper and setup functions to test the channel package.
Package test provides helper and setup functions to test the channel package.

Jump to

Keyboard shortcuts

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