swap

package
v0.0.0-...-9fdd194 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0, MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWrongVault is the error if a peer uses a different vault from before.
	ErrWrongVault = errors.New("wrong vault")
	// 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")
)

Functions

This section is empty.

Types

type Addressbook

type Addressbook interface {
	// Beneficiary returns the beneficiary for the given peer.
	Beneficiary(peer string) (beneficiary common.Address, known bool, err error)
	// Vault returns the vault for the given peer.
	Vault(peer string) (vaultAddress common.Address, known bool, err error)
	// BeneficiaryPeer returns the peer for a beneficiary.
	BeneficiaryPeer(beneficiary common.Address) (peer string, known bool, err error)
	// VaultPeer returns the peer for a vault.
	VaultPeer(vault common.Address) (peer string, known bool, err error)
	// PutBeneficiary stores the beneficiary for the given peer.
	PutBeneficiary(peer string, beneficiary common.Address) error
	// PutVault stores the vault for the given peer.
	PutVault(peer string, vault common.Address) error
	// MigratePeer returns whether a peer have already received a cheque that has been deducted
	MigratePeer(oldPeer, newPeer string) error
}

Addressbook maps peers to beneficaries, vaults 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

	// LastReceivedCheque returns the last received cheque for the peer
	LastReceivedCheque(peer string) (*vault.SignedCheque, error)
	// LastReceivedCheques returns the list of last received cheques for all peers
	LastReceivedCheques() (map[string]*vault.SignedCheque, error)
	// ReceivedChequeRecordsByPeer gets the records of the cheque for the peer's vault
	ReceivedChequeRecordsByPeer(peer string) ([]vault.ChequeRecord, error)
	// ReceivedChequeRecordsAll gets the records of the cheque for all vault
	ReceivedChequeRecordsAll() ([]vault.ChequeRecord, error)
	// ReceivedChequeRecordsCount
	ReceivedChequeRecordsCount() (int, error)

	// LastSendCheque returns the last received cheque for the peer
	LastSendCheque(peer string) (*vault.SignedCheque, error)
	// LastSendCheques returns the list of last send cheques for this peer
	LastSendCheques() (map[string]*vault.SignedCheque, error)
	// SendChequeRecordsByPeer gets the records of the cheque for the peer's vault
	SendChequeRecordsByPeer(peer string) ([]vault.ChequeRecord, error)
	// SendChequeRecordsAll gets the records of the cheque for all vault
	SendChequeRecordsAll() ([]vault.ChequeRecord, error)

	// CashCheque sends a cashing transaction for the last cheque of the peer
	CashCheque(ctx context.Context, peer string) (common.Hash, error)
	// CashoutStatus gets the status of the latest cashout transaction for the peers vault
	CashoutStatus(ctx context.Context, peer string) (*vault.CashoutStatus, error)
	// HasCashoutAction
	HasCashoutAction(ctx context.Context, peer string) (bool, 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, store storage.StateStorer, vault vault.Service, chequeStore vault.ChequeStore, addressbook Addressbook, chainID int64, cashout vault.CashoutService, accounting settlement.Accounting) *Service

New creates a new swap Service.

func (*Service) Beneficiary

func (s *Service) Beneficiary(peer string) (beneficiary common.Address, known bool, err error)

func (*Service) BeneficiaryPeer

func (s *Service) BeneficiaryPeer(beneficiary common.Address) (peer string, known bool, err error)

func (*Service) CashCheque

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

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

func (*Service) GetChainid

func (s *Service) GetChainid() int64

func (*Service) GetProtocols

func (s *Service) GetProtocols() swapprotocol.Interface

func (*Service) HasCashoutAction

func (s *Service) HasCashoutAction(ctx context.Context, peer string, token common.Address) (bool, error)

func (*Service) LastReceivedCheque

func (s *Service) LastReceivedCheque(peer string, token common.Address) (*vault.SignedCheque, error)

LastReceivedCheque returns the last received cheque for the peer

func (*Service) LastReceivedCheques

func (s *Service) LastReceivedCheques(token common.Address) (map[string]*vault.SignedCheque, error)

LastReceivedCheques returns map[peer]cheque

func (*Service) LastSendCheque

func (s *Service) LastSendCheque(peer string, token common.Address) (*vault.SignedCheque, error)

LastReceivedCheque returns the last received cheque for the peer

func (*Service) LastSendCheques

func (s *Service) LastSendCheques(token common.Address) (map[string]*vault.SignedCheque, error)

LastReceivedCheques returns the list of last received cheques for all peers

func (*Service) Pay

func (s *Service) Pay(ctx context.Context, peer string, amount *big.Int, contractId string, token common.Address)

Pay initiates a payment to the given peer

func (*Service) PutBeneficiary

func (s *Service) PutBeneficiary(peer string, beneficiary common.Address) (common.Address, error)

func (*Service) ReceiveCheque

func (s *Service) ReceiveCheque(ctx context.Context, peer string, cheque *vault.SignedCheque, realAmount *big.Int, token common.Address) (err error)

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

func (*Service) ReceivedChequeRecordsAll

func (s *Service) ReceivedChequeRecordsAll() ([]vault.ChequeRecord, error)

ReceivedChequeRecordsAll returns the last received cheque for the peer

func (*Service) ReceivedChequeRecordsByPeer

func (s *Service) ReceivedChequeRecordsByPeer(peer string) ([]vault.ChequeRecord, error)

LastReceivedCheque returns the last received cheque for the peer

func (*Service) ReceivedChequeRecordsCount

func (s *Service) ReceivedChequeRecordsCount() (int, error)

ReceivedChequeRecordsCount returns the last received cheque for the peer

func (*Service) SendChequeRecordsAll

func (s *Service) SendChequeRecordsAll() ([]vault.ChequeRecord, error)

SendChequeRecordsAll returns the last received cheque for all peer

func (*Service) SendChequeRecordsByPeer

func (s *Service) SendChequeRecordsByPeer(peer string) ([]vault.ChequeRecord, error)

SendChequeRecordsByPeer returns the last received cheque for the peer

func (*Service) SetAccounting

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

func (*Service) Settle

func (s *Service) Settle(toPeer string, paymentAmount *big.Int, contractId string, token common.Address) error

func (*Service) SettlementsReceived

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

SettlementsReceived returns received settlements for each individual known peer.

func (*Service) SettlementsSent

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

SettlementsSent returns sent settlements for each individual known peer

func (*Service) TotalReceived

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

TotalReceived returns the total amount received from a peer

func (*Service) TotalSent

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

TotalSent returns the total amount sent to a peer

func (*Service) VaultPeer

func (s *Service) VaultPeer(vault common.Address) (peer string, known bool, err error)

Directories

Path Synopsis
chequestore
pb

Jump to

Keyboard shortcuts

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