directfund

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package directfund implements an off-chain protocol to directly fund a channel.

Index

Constants

View Source
const (
	WaitingForCompletePrefund  protocols.WaitingFor = "WaitingForCompletePrefund"
	WaitingForMyTurnToFund     protocols.WaitingFor = "WaitingForMyTurnToFund"
	WaitingForCompleteFunding  protocols.WaitingFor = "WaitingForCompleteFunding"
	WaitingForCompletePostFund protocols.WaitingFor = "WaitingForCompletePostFund"
	WaitingForNothing          protocols.WaitingFor = "WaitingForNothing" // Finished
)
View Source
const ObjectivePrefix = "DirectFunding-"
View Source
const (
	SignedStatePayload protocols.PayloadType = "SignedStatePayload"
)

Variables

View Source
var ErrLedgerChannelExists error = errors.New("directfund: ledger channel already exists")

Functions

func ChannelsExistWithCounterparty

func ChannelsExistWithCounterparty(counterparty types.Address, getChannels GetChannelsByParticipantFunction, getTwoPartyConsensusLedger GetTwoPartyConsensusLedgerFunction) (bool, error)

ChannelsExistWithCounterparty returns true if a channel or consensus_channel exists with the counterparty

func FundOnChainEffect

func FundOnChainEffect(cId types.Destination, asset string, amount types.Funds) string

func IsDirectFundObjective

func IsDirectFundObjective(id protocols.ObjectiveId) bool

IsDirectFundObjective inspects a objective id and returns true if the objective id is for a direct fund objective.

Types

type GetChannelsByParticipantFunction

type GetChannelsByParticipantFunction func(participant types.Address) ([]*channel.Channel, error)

GetChannelByIdFunction specifies a function that can be used to retrieve channels from a store.

type GetTwoPartyConsensusLedgerFunction

type GetTwoPartyConsensusLedgerFunction func(counterparty types.Address) (ledger *consensus_channel.ConsensusChannel, ok bool)

GetTwoPartyConsensusLedgerFuncion describes functions which return a ConsensusChannel ledger channel between the calling client and the given counterparty, if such a channel exists.

type Objective

type Objective struct {
	Status protocols.ObjectiveStatus
	C      *channel.Channel
	// contains filtered or unexported fields
}

Objective is a cache of data computed by reading from the store. It stores (potentially) infinite data

func ConstructFromPayload

func ConstructFromPayload(
	preApprove bool,
	op protocols.ObjectivePayload,
	myAddress types.Address,
) (Objective, error)

ConstructFromPayload initiates a Objective with data calculated from the supplied initialState and client address

func NewObjective

func NewObjective(request ObjectiveRequest, preApprove bool, myAddress types.Address, chainId *big.Int, getChannels GetChannelsByParticipantFunction, getTwoPartyConsensusLedger GetTwoPartyConsensusLedgerFunction) (Objective, error)

NewObjective creates a new direct funding objective from a given request.

func (*Objective) Approve

func (o *Objective) Approve() protocols.Objective

func (*Objective) Crank

Crank inspects the extended state and declares a list of Effects to be executed It's like a state machine transition function where the finite / enumerable state is returned (computed from the extended state) rather than being independent of the extended state; and where there is only one type of event ("the crank") with no data on it at all

func (*Objective) CreateConsensusChannel

func (dfo *Objective) CreateConsensusChannel() (*consensus_channel.ConsensusChannel, error)

CreateConsensusChannel creates a ConsensusChannel from the Objective by extracting signatures and a single asset outcome from the post fund state.

func (*Objective) GetStatus

func (dfo *Objective) GetStatus() protocols.ObjectiveStatus

GetStatus returns the status of the objective.

func (*Objective) Id

func (Objective) MarshalJSON

func (o Objective) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of the DirectFundObjective NOTE: Marshal -> Unmarshal is a lossy process. All channel data (other than Id) from the field C is discarded

func (*Objective) OwnsChannel

func (dfo *Objective) OwnsChannel() types.Destination

OwnsChannel returns the channel that the objective is funding.

func (*Objective) Reject

func (*Objective) Related

func (o *Objective) Related() []protocols.Storable

func (*Objective) UnmarshalJSON

func (o *Objective) UnmarshalJSON(data []byte) error

UnmarshalJSON populates the calling DirectFundObjective with the json-encoded data NOTE: Marshal -> Unmarshal is a lossy process. All channel data (other than Id) from the field C is discarded

func (*Objective) Update

Update receives an ObjectivePayload, applies all applicable data to the DirectFundingObjectiveState, and returns the updated state

type ObjectiveRequest

type ObjectiveRequest struct {
	CounterParty      types.Address
	ChallengeDuration uint32
	Outcome           outcome.Exit
	AppDefinition     types.Address
	AppData           types.Bytes
	Nonce             uint64
	// contains filtered or unexported fields
}

ObjectiveRequest represents a request to create a new direct funding objective.

func NewObjectiveRequest

func NewObjectiveRequest(
	counterparty types.Address,
	challengeDuration uint32,
	outcome outcome.Exit,
	nonce uint64,
	appDefinition types.Address,
) ObjectiveRequest

NewObjectiveRequest creates a new ObjectiveRequest.

func (ObjectiveRequest) Id

func (r ObjectiveRequest) Id(myAddress types.Address, chainId *big.Int) protocols.ObjectiveId

Id returns the objective id for the request.

func (ObjectiveRequest) Response

func (r ObjectiveRequest) Response(myAddress types.Address, chainId *big.Int) ObjectiveResponse

Response computes and returns the appropriate response from the request.

func (ObjectiveRequest) SignalObjectiveStarted

func (r ObjectiveRequest) SignalObjectiveStarted()

SignalObjectiveStarted is used by the engine to signal the objective has been started.

func (ObjectiveRequest) WaitForObjectiveToStart

func (r ObjectiveRequest) WaitForObjectiveToStart()

WaitForObjectiveToStart blocks until the objective starts

type ObjectiveResponse

type ObjectiveResponse struct {
	Id        protocols.ObjectiveId
	ChannelId types.Destination
}

ObjectiveResponse is the type returned across the API in response to the ObjectiveRequest.

Jump to

Keyboard shortcuts

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