Documentation ¶
Index ¶
- Variables
- type Addressbook
- type Interface
- type NoOpSwap
- func (*NoOpSwap) CashCheque(ctx context.Context, peer swarm.Address) (common.Hash, error)
- func (*NoOpSwap) CashoutStatus(ctx context.Context, peer swarm.Address) (*chequebook.CashoutStatus, error)
- func (*NoOpSwap) LastReceivedCheque(peer swarm.Address) (*chequebook.SignedCheque, error)
- func (*NoOpSwap) LastReceivedCheques() (map[string]*chequebook.SignedCheque, error)
- func (*NoOpSwap) LastSentCheque(peer swarm.Address) (*chequebook.SignedCheque, error)
- func (*NoOpSwap) LastSentCheques() (map[string]*chequebook.SignedCheque, error)
- func (*NoOpSwap) SettlementsReceived() (map[string]*big.Int, error)
- func (*NoOpSwap) SettlementsSent() (map[string]*big.Int, error)
- func (*NoOpSwap) TotalReceived(peer swarm.Address) (totalSent *big.Int, err error)
- func (*NoOpSwap) TotalSent(peer swarm.Address) (totalSent *big.Int, err error)
- type Service
- func (s *Service) AddDeductionByPeer(peer swarm.Address) error
- func (s *Service) CashCheque(ctx context.Context, peer swarm.Address) (common.Hash, error)
- func (s *Service) CashoutStatus(ctx context.Context, peer swarm.Address) (*chequebook.CashoutStatus, error)
- func (s *Service) GetDeductionByPeer(peer swarm.Address) (bool, error)
- func (s *Service) GetDeductionForPeer(peer swarm.Address) (bool, error)
- func (s *Service) Handshake(peer swarm.Address, beneficiary common.Address) error
- func (s *Service) LastReceivedCheque(peer swarm.Address) (*chequebook.SignedCheque, error)
- func (s *Service) LastReceivedCheques() (map[string]*chequebook.SignedCheque, error)
- func (s *Service) LastSentCheque(peer swarm.Address) (*chequebook.SignedCheque, error)
- func (s *Service) LastSentCheques() (map[string]*chequebook.SignedCheque, error)
- func (s *Service) Metrics() []prometheus.Collector
- func (s *Service) Pay(ctx context.Context, peer swarm.Address, amount *big.Int)
- func (s *Service) ReceiveCheque(ctx context.Context, peer swarm.Address, cheque *chequebook.SignedCheque, ...) (err error)
- func (s *Service) SetAccounting(accounting settlement.Accounting)
- func (s *Service) SettlementsReceived() (map[string]*big.Int, error)
- func (s *Service) SettlementsSent() (map[string]*big.Int, error)
- func (s *Service) TotalReceived(peer swarm.Address) (totalReceived *big.Int, err error)
- func (s *Service) TotalSent(peer swarm.Address) (totalSent *big.Int, err error)
Constants ¶
This section is empty.
Variables ¶
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 ¶ added in v0.6.0
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 ¶ added in v1.5.0
type NoOpSwap struct { }
func (*NoOpSwap) CashCheque ¶ added in v1.5.0
CashCheque sends a cashing transaction for the last cheque of the peer
func (*NoOpSwap) CashoutStatus ¶ added in v1.5.0
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 ¶ added in v1.5.0
func (*NoOpSwap) LastReceivedCheque(peer swarm.Address) (*chequebook.SignedCheque, error)
LastReceivedCheque returns the last received cheque for the peer
func (*NoOpSwap) LastReceivedCheques ¶ added in v1.5.0
func (*NoOpSwap) LastReceivedCheques() (map[string]*chequebook.SignedCheque, error)
LastReceivedCheques returns the list of last received cheques for all peers
func (*NoOpSwap) LastSentCheque ¶ added in v1.5.0
func (*NoOpSwap) LastSentCheque(peer swarm.Address) (*chequebook.SignedCheque, error)
func (*NoOpSwap) LastSentCheques ¶ added in v1.5.0
func (*NoOpSwap) LastSentCheques() (map[string]*chequebook.SignedCheque, error)
LastSentCheques returns the list of last sent cheques for all peers
func (*NoOpSwap) SettlementsReceived ¶ added in v1.5.0
SettlementsReceived returns received settlements for each individual known peer
func (*NoOpSwap) SettlementsSent ¶ added in v1.5.0
SettlementsSent returns sent settlements for each individual known peer
func (*NoOpSwap) TotalReceived ¶ added in v1.5.0
TotalReceived returns the total amount received from a peer
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 ¶ added in v1.0.0
func (*Service) CashCheque ¶
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 ¶ added in v1.0.0
func (*Service) GetDeductionForPeer ¶ added in v1.0.0
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) 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 ¶ added in v0.6.0
func (s *Service) SetAccounting(accounting settlement.Accounting)
func (*Service) SettlementsReceived ¶
SettlementsReceived returns received settlements for each individual known peer.
func (*Service) SettlementsSent ¶
SettlementsSent returns sent settlements for each individual known peer
func (*Service) TotalReceived ¶
TotalReceived returns the total amount received from a peer