Documentation ¶
Overview ¶
Package channel contains the Polkadot channel backend implementation.
Index ¶
- Constants
- Variables
- func CalcID(params *pchannel.Params) (id pchannel.ID)
- func EventIsConcluded(cid ChannelID) func(PerunEvent) bool
- func EventIsDeposited(e PerunEvent) bool
- func EventIsDisputed(cid ChannelID) func(PerunEvent) bool
- func EventIsProgressed(cid ChannelID) func(PerunEvent) bool
- func EventIsWithdrawn(e PerunEvent) bool
- func MakeDuration(sec ChallengeDuration) time.Duration
- func MakePerunAlloc(bals []Balance) pchannel.Allocation
- func MakePerunBalance(bal Balance) *big.Int
- func MakePerunBalances(bals []Balance) pchannel.Balances
- func MakePerunChallengeDuration(sec ChallengeDuration) uint64
- func MakeTime(sec ChallengeDuration) time.Time
- func MakeTimeout(sec ChallengeDuration, storage substrate.StorageQueryer) pchannel.Timeout
- func NewPerunState(s *State, app pchannel.App) *pchannel.State
- func ScaleDecode(obj interface{}, data []byte) error
- func ScaleEncode(obj interface{}) ([]byte, error)
- type AppID
- type Balance
- type ChallengeDuration
- type ChannelID
- type ConcludedEvent
- type DepositedEvent
- type DisputePhase
- type DisputedEvent
- type EventRecords
- type Funding
- type FundingID
- type Nonce
- type OffIdentity
- type OnIdentity
- type Params
- type PerunEvent
- type ProgressedEvent
- type RegisteredState
- type Sig
- type State
- type Version
- type Withdrawal
- type WithdrawnEvent
Constants ¶
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 ¶
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") )
var Asset = &asset{}
Asset is the unique asset that is supported by the chain.
var Backend backend
Backend is the channel backend. Is a singleton since there is only one backend.
Functions ¶
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 ¶
MakePerunBalance creates a Perun balance.
func MakePerunBalances ¶
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 ¶
NewPerunState creates a new Perun state and fills the App-Data with a default value.
func ScaleDecode ¶
ScaleDecode decodes any struct according to the SCALE codec.
func ScaleEncode ¶
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 ¶
Balance is the balance of an on- or off-chain Address.
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 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.
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.
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 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.
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 ¶
NewWithdrawal creates a new Withdrawal.
Source Files ¶
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. |