node

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0, MIT Imports: 21 Imported by: 0

README

go-nitro Node

Our integration tests give the best idea of how to use the API. Another useful resource is the godoc description of the go-nitro.Node API.

Broadly, consumers will construct a go-nitro Node, possibly using injected dependencies. Then, they can create channels and send payments:

 import nc "github.com/statechannels/go-nitro/node"

 nitroNode := nc.New(
                    messageservice,
                    chain,
                    storeA,
                    logDestination,
                    nil,
                    nil
                )
response := nitroNode.CreateLedgerChannel(hub.Address, 0, someOutcome)
nitroNode.WaitForCompletedObjective(response.objectiveId)

response = nitroNode.CreateVirtualPaymentChannel([hub.Address],bob.Address, defaultChallengeDuration, someOtherOutcome)
nitroNode.WaitForCompletedObjective(response.objectiveId)

for i := 0; i < len(10); i++ {
    nitroNode.Pay(response.ChannelId, big.NewInt(int64(5)))
}

response = nitroNode.CloseVirtualChannel(response.ChannelId)
nitroNode.WaitForCompletedObjective(response.objectiveId)

Documentation

Overview

Package node contains imperative library code for running a go-nitro node inside another application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	Address *types.Address
	// contains filtered or unexported fields
}

Node provides the interface for the consuming application

func New

func New(messageService messageservice.MessageService, chainservice chainservice.ChainService, store store.Store, policymaker engine.PolicyMaker) Node

New is the constructor for a Node. It accepts a messaging service, a chain service, and a store as injected dependencies.

func (*Node) Close

func (n *Node) Close() error

Close stops the node from responding to any input.

func (*Node) CloseLedgerChannel

func (n *Node) CloseLedgerChannel(channelId types.Destination) (protocols.ObjectiveId, error)

CloseLedgerChannel attempts to close and defund the given directly funded channel.

func (*Node) ClosePaymentChannel

func (n *Node) ClosePaymentChannel(channelId types.Destination) (protocols.ObjectiveId, error)

ClosePaymentChannel attempts to close and defund the given virtually funded channel.

func (*Node) CompletedObjectives

func (n *Node) CompletedObjectives() <-chan protocols.ObjectiveId

CompletedObjectives returns a chan that receives a objective id whenever that objective is completed. Not suitable fo multiple subscribers.

func (*Node) CreateLedgerChannel

func (n *Node) CreateLedgerChannel(Counterparty types.Address, ChallengeDuration uint32, outcome outcome.Exit) (directfund.ObjectiveResponse, error)

CreateLedgerChannel creates a directly funded ledger channel with the given counterparty. The channel will run under full consensus rules (it is not possible to provide a custom AppDefinition or AppData).

func (*Node) CreatePaymentChannel

func (n *Node) CreatePaymentChannel(Intermediaries []types.Address, CounterParty types.Address, ChallengeDuration uint32, Outcome outcome.Exit) (virtualfund.ObjectiveResponse, error)

CreatePaymentChannel creates a virtual channel with the counterParty using ledger channels with the supplied intermediaries.

func (*Node) CreateVoucher

func (n *Node) CreateVoucher(channelId types.Destination, amount *big.Int) (payments.Voucher, error)

CreateVoucher creates and returns a voucher for the given channelId which increments the redeemable balance by amount. It is the responsibility of the caller to send the voucher to the payee.

func (*Node) FailedObjectives

func (n *Node) FailedObjectives() <-chan protocols.ObjectiveId

FailedObjectives returns a chan that receives an objective id whenever that objective has failed

func (*Node) GetAllLedgerChannels

func (n *Node) GetAllLedgerChannels() ([]query.LedgerChannelInfo, error)

GetAllLedgerChannels returns all ledger channels.

func (*Node) GetLastBlockNum added in v0.1.1

func (n *Node) GetLastBlockNum() (uint64, error)

GetLastBlockNum returns last confirmed blockNum read from store

func (*Node) GetLedgerChannel

func (n *Node) GetLedgerChannel(id types.Destination) (query.LedgerChannelInfo, error)

GetLedgerChannel returns the ledger channel with the given id. If no ledger channel exists with the given id an error is returned.

func (*Node) GetPaymentChannel

func (n *Node) GetPaymentChannel(id types.Destination) (query.PaymentChannelInfo, error)

GetPaymentChannel returns the payment channel with the given id. If no ledger channel exists with the given id an error is returned.

func (*Node) GetPaymentChannelsByLedger

func (n *Node) GetPaymentChannelsByLedger(ledgerId types.Destination) ([]query.PaymentChannelInfo, error)

GetPaymentChannelsByLedger returns all active payment channels that are funded by the given ledger channel.

func (*Node) LedgerUpdatedChan

func (n *Node) LedgerUpdatedChan(ledgerId types.Destination) <-chan query.LedgerChannelInfo

LedgerUpdatedChan returns a chan that receives a ledger channel info whenever the ledger with given id is updated

func (*Node) LedgerUpdates

func (n *Node) LedgerUpdates() <-chan query.LedgerChannelInfo

LedgerUpdates returns a chan that receives ledger channel info whenever that ledger channel is updated. Not suitable for multiple subscribers.

func (*Node) ObjectiveCompleteChan

func (n *Node) ObjectiveCompleteChan(id protocols.ObjectiveId) <-chan struct{}

ObjectiveCompleteChan returns a chan that is closed when the objective with given id is completed

func (*Node) Pay

func (n *Node) Pay(channelId types.Destination, amount *big.Int)

Pay will send a signed voucher to the payee that they can redeem for the given amount.

func (*Node) PaymentChannelUpdatedChan

func (n *Node) PaymentChannelUpdatedChan(ledgerId types.Destination) <-chan query.PaymentChannelInfo

PaymentChannelUpdatedChan returns a chan that receives a payment channel info whenever the payment channel with given id is updated

func (*Node) PaymentUpdates

func (n *Node) PaymentUpdates() <-chan query.PaymentChannelInfo

PaymentUpdates returns a chan that receives payment channel info whenever that payment channel is updated. Not suitable fo multiple subscribers.

func (*Node) ReceiveVoucher

func (c *Node) ReceiveVoucher(v payments.Voucher) (payments.ReceiveVoucherSummary, error)

ReceiveVoucher receives a voucher and returns the amount that was paid. It can be used to add a voucher that was sent outside of the go-nitro system.

func (*Node) ReceivedVouchers

func (n *Node) ReceivedVouchers() <-chan payments.Voucher

ReceivedVouchers returns a chan that receives a voucher every time we receive a payment voucher

func (*Node) Version

func (n *Node) Version() string

Version returns the go-nitro version

Directories

Path Synopsis
Package engine contains the types and imperative code for the business logic of a go-nitro Node.
Package engine contains the types and imperative code for the business logic of a go-nitro Node.
chainservice
Package chainservice is a chain service responsible for submitting blockchain transactions and relaying blockchain events.
Package chainservice is a chain service responsible for submitting blockchain transactions and relaying blockchain events.
chainservice/adjudicator
package NitroAdjudicator contains bindings generated from the Nitro Adjudicator solidity contract, as well as utilities for converting client types to on-chain types.
package NitroAdjudicator contains bindings generated from the Nitro Adjudicator solidity contract, as well as utilities for converting client types to on-chain types.
messageservice
Package messageservice is a messaging service responsible for routing messages to peers and relaying messages received from peers.
Package messageservice is a messaging service responsible for routing messages to peers and relaying messages received from peers.
store
Package store contains the interface for a go-nitro store.
Package store contains the interface for a go-nitro store.

Jump to

Keyboard shortcuts

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