swap

package
v2.3.0-rc7 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: BSD-3-Clause Imports: 14 Imported by: 2

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")
	// ErrUnknownBeneficary is the error if a peer has never announced a beneficiary.
	ErrUnknownBeneficary = errors.New("unknown beneficiary for peer")
	// ErrChequeValueTooLow is the error a peer issued a cheque not covering 1 accounting credit
	ErrChequeValueTooLow = errors.New("cheque value too low")
	ErrNoChequebook      = errors.New("no chequebook")
)

Functions

This section is empty.

Types

type Addressbook

type Addressbook interface {
	// Beneficiary returns the beneficiary for the given peer.
	Beneficiary(peer swarm.Address) (beneficiary common.Address, known bool, err error)
	// Chequebook returns the chequebook for the given peer.
	Chequebook(peer swarm.Address) (chequebookAddress common.Address, known bool, err error)
	// BeneficiaryPeer returns the peer for a beneficiary.
	BeneficiaryPeer(beneficiary common.Address) (peer swarm.Address, known bool, err error)
	// ChequebookPeer returns the peer for a beneficiary.
	ChequebookPeer(chequebook common.Address) (peer swarm.Address, known bool, err error)
	// PutBeneficiary stores the beneficiary for the given peer.
	PutBeneficiary(peer swarm.Address, beneficiary common.Address) error
	// PutChequebook stores the chequebook for the given peer.
	PutChequebook(peer swarm.Address, chequebook common.Address) error
	// AddDeductionFor peer stores the flag indicating the peer have already issued a cheque that has been deducted
	AddDeductionFor(peer swarm.Address) error
	// AddDeductionFor peer stores the flag indicating the peer have already received a cheque that has been deducted
	AddDeductionBy(peer swarm.Address) error
	// GetDeductionFor returns whether a peer have already issued a cheque that has been deducted
	GetDeductionFor(peer swarm.Address) (bool, error)
	// GetDeductionBy returns whether a peer have already received a cheque that has been deducted
	GetDeductionBy(peer swarm.Address) (bool, error)
	// MigratePeer returns whether a peer have already received a cheque that has been deducted
	MigratePeer(oldPeer, newPeer swarm.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 swarm.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 swarm.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 swarm.Address) (common.Hash, error)
	// CashoutStatus gets the status of the latest cashout transaction for the peers chequebook
	CashoutStatus(ctx context.Context, peer swarm.Address) (*chequebook.CashoutStatus, error)
}

type NoOpSwap

type NoOpSwap struct {
}

func (*NoOpSwap) CashCheque

func (*NoOpSwap) CashCheque(ctx context.Context, peer swarm.Address) (common.Hash, error)

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

func (*NoOpSwap) CashoutStatus

func (*NoOpSwap) CashoutStatus(ctx context.Context, peer swarm.Address) (*chequebook.CashoutStatus, error)

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

func (*NoOpSwap) LastReceivedCheque

func (*NoOpSwap) LastReceivedCheque(peer swarm.Address) (*chequebook.SignedCheque, error)

LastReceivedCheque returns the last received cheque for the peer

func (*NoOpSwap) LastReceivedCheques

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

LastReceivedCheques returns the list of last received cheques for all peers

func (*NoOpSwap) LastSentCheque

func (*NoOpSwap) LastSentCheque(peer swarm.Address) (*chequebook.SignedCheque, error)

func (*NoOpSwap) LastSentCheques

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

LastSentCheques returns the list of last sent cheques for all peers

func (*NoOpSwap) SettlementsReceived

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

SettlementsReceived returns received settlements for each individual known peer

func (*NoOpSwap) SettlementsSent

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

SettlementsSent returns sent settlements for each individual known peer

func (*NoOpSwap) TotalReceived

func (*NoOpSwap) TotalReceived(peer swarm.Address) (totalSent *big.Int, err error)

TotalReceived returns the total amount received from a peer

func (*NoOpSwap) TotalSent

func (*NoOpSwap) TotalSent(peer swarm.Address) (totalSent *big.Int, err 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 log.Logger, store storage.StateStorer, chequebook chequebook.Service, chequeStore chequebook.ChequeStore, addressbook Addressbook, networkID uint64, cashout chequebook.CashoutService, accounting settlement.Accounting, cashoutAddress common.Address) *Service

New creates a new swap Service.

func (*Service) AddDeductionByPeer

func (s *Service) AddDeductionByPeer(peer swarm.Address) error

func (*Service) CashCheque

func (s *Service) CashCheque(ctx context.Context, peer swarm.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 swarm.Address) (*chequebook.CashoutStatus, error)

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

func (*Service) GetDeductionByPeer

func (s *Service) GetDeductionByPeer(peer swarm.Address) (bool, error)

func (*Service) GetDeductionForPeer

func (s *Service) GetDeductionForPeer(peer swarm.Address) (bool, error)

func (*Service) Handshake

func (s *Service) Handshake(peer swarm.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 swarm.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 swarm.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 swarm.Address, amount *big.Int)

Pay initiates a payment to the given peer

func (*Service) ReceiveCheque

func (s *Service) ReceiveCheque(ctx context.Context, peer swarm.Address, cheque *chequebook.SignedCheque, exchangeRate, deduction *big.Int) (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 swarm.Address) (totalReceived *big.Int, err error)

TotalReceived returns the total amount received from a peer

func (*Service) TotalSent

func (s *Service) TotalSent(peer swarm.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