Documentation
¶
Overview ¶
Package virtualfund implements an off-chain protocol to virtually fund a channel.
Index ¶
- Constants
- func IsVirtualFundObjective(id protocols.ObjectiveId) bool
- type Connection
- type GetTwoPartyConsensusLedgerFunction
- type GuaranteeInfo
- type Objective
- func (o *Objective) Approve() protocols.Objective
- func (o *Objective) Crank(secretKey *[]byte) (protocols.Objective, protocols.SideEffects, protocols.WaitingFor, error)
- func (o *Objective) GetStatus() protocols.ObjectiveStatus
- func (o *Objective) Id() protocols.ObjectiveId
- func (o Objective) MarshalJSON() ([]byte, error)
- func (o *Objective) OwnsChannel() types.Destination
- func (o *Objective) ReceiveProposal(sp consensus_channel.SignedProposal) (protocols.ProposalReceiver, error)
- func (o *Objective) Reject() (protocols.Objective, protocols.SideEffects)
- func (o *Objective) Related() []protocols.Storable
- func (o *Objective) UnmarshalJSON(data []byte) error
- func (o *Objective) Update(raw protocols.ObjectivePayload) (protocols.Objective, error)
- type ObjectiveRequest
- type ObjectiveResponse
Constants ¶
const ( WaitingForCompletePrefund protocols.WaitingFor = "WaitingForCompletePrefund" // Round 1 WaitingForCompleteFunding protocols.WaitingFor = "WaitingForCompleteFunding" // Round 2 WaitingForCompletePostFund protocols.WaitingFor = "WaitingForCompletePostFund" // Round 3 WaitingForNothing protocols.WaitingFor = "WaitingForNothing" // Finished )
const ObjectivePrefix = "VirtualFund-"
const (
SignedStatePayload protocols.PayloadType = "SignedStatePayload"
)
Variables ¶
This section is empty.
Functions ¶
func IsVirtualFundObjective ¶
func IsVirtualFundObjective(id protocols.ObjectiveId) bool
IsVirtualFundObjective inspects a objective id and returns true if the objective id is for a virtual fund objective.
Types ¶
type Connection ¶
type Connection struct {
Channel *consensus_channel.ConsensusChannel
GuaranteeInfo GuaranteeInfo
}
func (*Connection) IsFundingTheTarget ¶
func (c *Connection) IsFundingTheTarget() bool
IsFundingTheTarget computes whether the ledger channel on the receiver funds the guarantee expected by this connection
func (Connection) MarshalJSON ¶
func (c Connection) MarshalJSON() ([]byte, error)
MarshalJSON returns a JSON representation of the Connection NOTE: Marshal -> Unmarshal is a lossy process. All channel data other than the ID is dropped
func (*Connection) UnmarshalJSON ¶
func (c *Connection) UnmarshalJSON(data []byte) error
UnmarshalJSON populates the calling Connection with the json-encoded data
NOTE: Marshal -> Unmarshal is a lossy process. All channel data from
(other than Id) is discarded
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 GuaranteeInfo ¶
type GuaranteeInfo struct {
Left types.Destination
Right types.Destination
LeftAmount types.Funds
RightAmount types.Funds
GuaranteeDestination types.Destination
}
GuaranteeInfo contains the information used to generate the expected guarantees.
type Objective ¶
type Objective struct {
Status protocols.ObjectiveStatus
V *channel.VirtualChannel
ToMyLeft *Connection
ToMyRight *Connection
MyRole uint // index in the virtual funding protocol. 0 for Alice, n+1 for Bob. Otherwise, one of the intermediaries.
// contains filtered or unexported fields
}
Objective is a cache of data computed by reading from the store. It stores (potentially) infinite data.
func ConstructObjectiveFromPayload ¶
func ConstructObjectiveFromPayload( p protocols.ObjectivePayload, preapprove bool, myAddress types.Address, getTwoPartyConsensusLedger GetTwoPartyConsensusLedgerFunction, ) (Objective, error)
ConstructObjectiveFromPayload takes in a message and constructs an objective from it. It accepts the message, myAddress, and a function to to retrieve ledgers from a store.
func NewObjective ¶
func NewObjective(request ObjectiveRequest, preApprove bool, myAddress types.Address, chainId *big.Int, getTwoPartyConsensusLedger GetTwoPartyConsensusLedgerFunction) (Objective, error)
NewObjective creates a new virtual funding objective from a given request.
func (*Objective) Crank ¶
func (o *Objective) Crank(secretKey *[]byte) (protocols.Objective, protocols.SideEffects, protocols.WaitingFor, error)
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) GetStatus ¶
func (o *Objective) GetStatus() protocols.ObjectiveStatus
GetStatus returns the status of the objective.
func (Objective) MarshalJSON ¶
MarshalJSON returns a JSON representation of the VirtualFundObjective NOTE: Marshal -> Unmarshal is a lossy process. All channel data from the virtual and ledger channels (other than Ids) is discarded
func (*Objective) OwnsChannel ¶
func (o *Objective) OwnsChannel() types.Destination
OwnsChannel returns the channel that the objective is funding.
func (*Objective) ReceiveProposal ¶
func (o *Objective) ReceiveProposal(sp consensus_channel.SignedProposal) (protocols.ProposalReceiver, error)
func (*Objective) Reject ¶
func (o *Objective) Reject() (protocols.Objective, protocols.SideEffects)
Reject returns a rejected copy of the objective.
func (*Objective) UnmarshalJSON ¶
UnmarshalJSON populates the calling VirtualFundObjective with the json-encoded data
NOTE: Marshal -> Unmarshal is a lossy process. All channel data from
the virtual and ledger channels (other than Ids) is discarded
type ObjectiveRequest ¶
type ObjectiveRequest struct {
Intermediaries []types.Address
CounterParty types.Address
ChallengeDuration uint32
Outcome outcome.Exit
Nonce uint64
AppDefinition types.Address
// contains filtered or unexported fields
}
ObjectiveRequest represents a request to create a new virtual funding objective.
func NewObjectiveRequest ¶
func NewObjectiveRequest(intermediaries []types.Address, 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) 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.