swap

package
v0.0.0-...-fa704fd Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWrongChequebook is the error if a peer uses a different chequebook from before.
	ErrWrongChequebook = errors.New("wrong chequebook")
	// ErrWrongBeneficiary is the error if a peer uses a different beneficiary than expected.
	ErrWrongBeneficiary = errors.New("wrong beneficiary")
	// ErrUnknownBeneficary is the error if a peer has never announced a beneficiary.
	ErrUnknownBeneficary = errors.New("unknown beneficiary for peer")
)

Functions

This section is empty.

Types

type Addressbook

type Addressbook interface {
	// Beneficiary returns the beneficiary for the given peer.
	Beneficiary(peer penguin.Address) (beneficiary common.Address, known bool, err error)
	// Chequebook returns the chequebook for the given peer.
	Chequebook(peer penguin.Address) (chequebookAddress common.Address, known bool, err error)
	// BeneficiaryPeer returns the peer for a beneficiary.
	BeneficiaryPeer(beneficiary common.Address) (peer penguin.Address, known bool, err error)
	// ChequebookPeer returns the peer for a beneficiary.
	ChequebookPeer(chequebook common.Address) (peer penguin.Address, known bool, err error)
	// PutBeneficiary stores the beneficiary for the given peer.
	PutBeneficiary(peer penguin.Address, beneficiary common.Address) error
	// PutChequebook stores the chequebook for the given peer.
	PutChequebook(peer penguin.Address, chequebook common.Address) error
}

Addressbook maps peers to beneficaries, chequebooks and in reverse.

func NewAddressbook

func NewAddressbook(store storage.StateStorer) Addressbook

NewAddressbook creates a new addressbook using the store.

type Interface

type Interface interface {
	settlement.Interface
	// LastSentCheque returns the last sent cheque for the peer
	LastSentCheque(peer penguin.Address) (*chequebook.SignedCheque, error)
	// LastSentCheques returns the list of last sent cheques for all peers
	LastSentCheques() (map[string]*chequebook.SignedCheque, error)
	// LastReceivedCheque returns the last received cheque for the peer
	LastReceivedCheque(peer penguin.Address) (*chequebook.SignedCheque, error)
	// LastReceivedCheques returns the list of last received cheques for all peers
	LastReceivedCheques() (map[string]*chequebook.SignedCheque, error)
	// CashCheque sends a cashing transaction for the last cheque of the peer
	CashCheque(ctx context.Context, peer penguin.Address) (common.Hash, error)
	// CashoutStatus gets the status of the latest cashout transaction for the peers chequebook
	CashoutStatus(ctx context.Context, peer penguin.Address) (*chequebook.CashoutStatus, error)
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the implementation of the swap settlement layer.

func New

func New(proto swapprotocol.Interface, logger logging.Logger, store storage.StateStorer, chequebook chequebook.Service, chequeStore chequebook.ChequeStore, addressbook Addressbook, networkID uint64, cashout chequebook.CashoutService, p2pService p2p.Service, accounting settlement.Accounting) *Service

New creates a new swap Service.

func (*Service) CashCheque

func (s *Service) CashCheque(ctx context.Context, peer penguin.Address) (common.Hash, error)

CashCheque sends a cashing transaction for the last cheque of the peer

func (*Service) CashoutStatus

func (s *Service) CashoutStatus(ctx context.Context, peer penguin.Address) (*chequebook.CashoutStatus, error)

CashoutStatus gets the status of the latest cashout transaction for the peers chequebook

func (*Service) Handshake

func (s *Service) Handshake(peer penguin.Address, beneficiary common.Address) error

Handshake is called by the swap protocol when a handshake is received.

func (*Service) LastReceivedCheque

func (s *Service) LastReceivedCheque(peer penguin.Address) (*chequebook.SignedCheque, error)

LastReceivedCheque returns the last received cheque for the peer

func (*Service) LastReceivedCheques

func (s *Service) LastReceivedCheques() (map[string]*chequebook.SignedCheque, error)

LastReceivedCheques returns the list of last received cheques for all peers

func (*Service) LastSentCheque

func (s *Service) LastSentCheque(peer penguin.Address) (*chequebook.SignedCheque, error)

LastSentCheque returns the last sent cheque for the peer

func (*Service) LastSentCheques

func (s *Service) LastSentCheques() (map[string]*chequebook.SignedCheque, error)

LastSentCheques returns the list of last sent cheques for all peers

func (*Service) Metrics

func (s *Service) Metrics() []prometheus.Collector

func (*Service) Pay

func (s *Service) Pay(ctx context.Context, peer penguin.Address, amount *big.Int)

Pay initiates a payment to the given peer

func (*Service) ReceiveCheque

func (s *Service) ReceiveCheque(ctx context.Context, peer penguin.Address, cheque *chequebook.SignedCheque) (err error)

ReceiveCheque is called by the swap protocol if a cheque is received.

func (*Service) SetAccounting

func (s *Service) SetAccounting(accounting settlement.Accounting)

func (*Service) SettlementsReceived

func (s *Service) SettlementsReceived() (map[string]*big.Int, error)

SettlementsReceived returns received settlements for each individual known peer.

func (*Service) SettlementsSent

func (s *Service) SettlementsSent() (map[string]*big.Int, error)

SettlementsSent returns sent settlements for each individual known peer

func (*Service) TotalReceived

func (s *Service) TotalReceived(peer penguin.Address) (totalReceived *big.Int, err error)

TotalReceived returns the total amount received from a peer

func (*Service) TotalSent

func (s *Service) TotalSent(peer penguin.Address) (totalSent *big.Int, err error)

TotalSent returns the total amount sent to a peer

Directories

Path Synopsis
chequestore
pb

Jump to

Keyboard shortcuts

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