connector

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package connector provides the functionality to invoke and query Perun canister methods and handles the responses.

Index

Constants

View Source
const (
	DefaultBufferSize                  = 3
	DefaultSubscriptionPollingInterval = time.Duration(4) * time.Second
)
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
	// Length of a channel ID in byte.
	IDLen = 32
	// Fee for transfering on IC
	ICTransferFee = 10000
	// MaxBalance is the maximum balance allowed
	MaxBalance = uint64(1) << 30
)
View Source
const ChanBuffSize = 1024
View Source
const DefaultTimeoutPollInterval = 1 * time.Second

DefaultTimeoutPollInterval default value for the PollInterval of a Timeout.

View Source
const MaxNumIters = 4

Variables

View Source
var (

	// 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")
	// Channel was assumed concluded, but is not
	ErrNotConcluded = errors.New("channel not concluded")
	// Depositing funds into the canister failed
	ErrFundTransfer = errors.New("funding transfer failed")
)

Functions

func BuildDeposit

func BuildDeposit(addr wallet.Address, cid ChannelID) icperun.Funding

func DecodePrincipal

func DecodePrincipal(principalString string) (*principal.Principal, error)

func EvaluateConcludedEvents

func EvaluateConcludedEvents(events []ConcludedEvent) (bool, error)

func GetBasePath

func GetBasePath() string

func HandleTransferError

func HandleTransferError(err *icpledger.TransferError) error

func MakeTime

func MakeTime(sec ChallengeDuration) time.Duration

MakeTime creates a new time from the argument.

func MakeTransferArgs

func MakeTransferArgs(memo Memo, amount uint64, fee uint64, recipient string) icpledger.TransferArgs

func NewICAgent

func NewICAgent(accountPath string, host string, port int) (*agent.Agent, error)

func NewIdentity

func NewIdentity(accountPath string) (*identity.Identity, error)

func NewLedgerAgent

func NewLedgerAgent(canID principal.Principal, accountPath, host string, port int) (*icpledger.Agent, error)

func NewPerunAgent

func NewPerunAgent(canID principal.Principal, accountPath, host string, port int) (*icperun.Agent, error)

Types

type AdjEvent

type AdjEvent interface {
	SetEventData(cid pchannel.ID, version uint64, finalized bool, alloc [2]uint64, timeout, timestamp uint64) error
	ID() pchannel.ID
	Timeout() pchannel.Timeout
	Version() Version
	Tstamp() uint64
}

predecessor to the go-perun AdjEvent interface

type AdjEventSub

type AdjEventSub struct {
	Ev []AdjEvent
	// contains filtered or unexported fields
}

AdjudicatorSub implements the AdjudicatorSubscription interface.

func NewAdjEventSub

func NewAdjEventSub(addr pwallet.Address, chanID pchannel.ID, starttime uint64, req pchannel.AdjudicatorReq, conn *Connector) (*AdjEventSub, error)

func NewAdjudicatorSub

func NewAdjudicatorSub(ctx context.Context, cid pchannel.ID, conn *Connector) *AdjEventSub

func (*AdjEventSub) Close

func (s *AdjEventSub) Close() error

func (*AdjEventSub) Err

func (s *AdjEventSub) Err() error

func (*AdjEventSub) Events

func (s *AdjEventSub) Events() <-chan AdjEvent

func (*AdjEventSub) GetEvents

func (e *AdjEventSub) GetEvents() <-chan AdjEvent

func (*AdjEventSub) Next

Next implements the AdjudicatorSub.Next function.

func (*AdjEventSub) PanicErr

func (s *AdjEventSub) PanicErr() <-chan error

func (*AdjEventSub) QueryEvents

func (e *AdjEventSub) QueryEvents() (string, error)

type AppID

type AppID = OffIdentity

AppID is the identifier of a channel application.

type Balance

type Balance = uint64

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

func MakeAlloc

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

func MakeBalance

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

type BlockNum

type BlockNum = uint64

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 {
	Finalized bool
	Alloc     [2]uint64
	Tout      uint64
	Timestamp uint64

	VersionV Version
	IDV      pchannel.ID
	// contains filtered or unexported fields
}

func ParseEventsConcluded

func ParseEventsConcluded(input string) ([]ConcludedEvent, error)

func (*ConcludedEvent) ID

func (c *ConcludedEvent) ID() pchannel.ID

func (*ConcludedEvent) SetEventData

func (e *ConcludedEvent) SetEventData(cid pchannel.ID, version Version, finalized bool, alloc [2]uint64, timeout, timestamp uint64) error

func (*ConcludedEvent) Timeout

func (c *ConcludedEvent) Timeout() pchannel.Timeout

func (*ConcludedEvent) Tstamp

func (c *ConcludedEvent) Tstamp() uint64

func (*ConcludedEvent) Version

func (c *ConcludedEvent) Version() Version

type Connector

type Connector struct {
	Log         log.Embedding
	ICAgent     *agent.Agent
	PerunID     *principal.Principal
	LedgerID    *principal.Principal
	L1Account   *principal.Principal
	LedgerAgent *icpledger.Agent
	PerunAgent  *icperun.Agent
}

Connects Perun users with the Internet Computer

func NewICConnector

func NewICConnector(perunID, ledgerID, pemAccountPath, host string, port int) *Connector

func (*Connector) BuildTransfer

func (c *Connector) BuildTransfer(transactor principal.Principal, _amount, _fee *big.Int, funding Funding, receiver principal.Principal) (icpledger.TransferArgs, error)

func (*Connector) DepositToPerunChannel

func (c *Connector) DepositToPerunChannel(addr wallet.Address, cid ChannelID) error

func (*Connector) NotifyTransferToPerun

func (c *Connector) NotifyTransferToPerun(blockNum BlockNum, recipientPerun principal.Principal) (uint64, error)

func (*Connector) TransferIC

func (c *Connector) TransferIC(txArgs icpledger.TransferArgs) (*icpledger.TransferResult, error)

type DisputedEvent

type DisputedEvent struct {
	Finalized bool
	Alloc     [2]uint64
	Tout      uint64
	Timestamp uint64

	VersionV Version
	IDV      pchannel.ID
	// contains filtered or unexported fields
}

func (*DisputedEvent) ID

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

func (*DisputedEvent) SetEventData

func (e *DisputedEvent) SetEventData(cid pchannel.ID, version Version, finalized bool, alloc [2]uint64, timeout, timestamp uint64) error

func (*DisputedEvent) Timeout

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

func (*DisputedEvent) Tstamp

func (d *DisputedEvent) Tstamp() Version

func (*DisputedEvent) Version

func (d *DisputedEvent) Version() Version

type EventPredicate

type EventPredicate func(PerunEvent) bool

EventPredicate can be used to filter events.

type ExecPath

type ExecPath = string

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 FundedEvent

type FundedEvent struct {
	Cid     FundingID
	Balance Balance
	Vs      Version
}

func (*FundedEvent) ID

func (c *FundedEvent) ID() pchannel.ID

func (*FundedEvent) Timeout

func (c *FundedEvent) Timeout() pchannel.Timeout

func (*FundedEvent) Version

func (c *FundedEvent) Version() Version

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 NewFunding

func NewFunding(id ChannelID, part OffIdentity) *Funding

NewFunding returns a new Funding.

func (*Funding) Memo

func (f *Funding) Memo() (Memo, error)

type FundingID

type FundingID = [FIDLen]byte

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

type Memo

type Memo = uint64

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)

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 wallet.Address) (OnIdentity, error)

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 {
	ID() pchannel.ID
	Timeout() pchannel.Timeout
	Version() Version
}

PerunEvent is a Perun event.

type Sig

type Sig = [SigLen]byte

Sig is an off-chain signature.

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)

func StateForChain

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

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(sec ChallengeDuration) *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

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.

Directories

Path Synopsis
Package icperun contains functions to communicate to the Perun canister
Package icperun contains functions to communicate to the Perun canister

Jump to

Keyboard shortcuts

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