Documentation ¶
Index ¶
- Variables
- type Addressbook
- type Interface
- type Service
- func (s *Service) Beneficiary(peer string) (beneficiary common.Address, known bool, err error)
- func (s *Service) BeneficiaryPeer(beneficiary common.Address) (peer string, known bool, err error)
- func (s *Service) CashCheque(ctx context.Context, peer string, token common.Address) (common.Hash, error)
- func (s *Service) CashoutStatus(ctx context.Context, peer string, token common.Address) (*vault.CashoutStatus, error)
- func (s *Service) GetChainid() int64
- func (s *Service) GetProtocols() swapprotocol.Interface
- func (s *Service) HasCashoutAction(ctx context.Context, peer string, token common.Address) (bool, error)
- func (s *Service) LastReceivedCheque(peer string, token common.Address) (*vault.SignedCheque, error)
- func (s *Service) LastReceivedCheques(token common.Address) (map[string]*vault.SignedCheque, error)
- func (s *Service) LastSendCheque(peer string, token common.Address) (*vault.SignedCheque, error)
- func (s *Service) LastSendCheques(token common.Address) (map[string]*vault.SignedCheque, error)
- func (s *Service) Pay(ctx context.Context, peer string, amount *big.Int, contractId string, ...)
- func (s *Service) PutBeneficiary(peer string, beneficiary common.Address) (common.Address, error)
- func (s *Service) ReceiveCheque(ctx context.Context, peer string, cheque *vault.SignedCheque, ...) (err error)
- func (s *Service) ReceivedChequeRecordsAll() ([]vault.ChequeRecord, error)
- func (s *Service) ReceivedChequeRecordsByPeer(peer string) ([]vault.ChequeRecord, error)
- func (s *Service) ReceivedChequeRecordsCount() (int, error)
- func (s *Service) SendChequeRecordsAll() ([]vault.ChequeRecord, error)
- func (s *Service) SendChequeRecordsByPeer(peer string) ([]vault.ChequeRecord, error)
- func (s *Service) SetAccounting(accounting settlement.Accounting)
- func (s *Service) Settle(toPeer string, paymentAmount *big.Int, contractId string, token common.Address) error
- func (s *Service) SettlementsReceived(token common.Address) (map[string]*big.Int, error)
- func (s *Service) SettlementsSent(token common.Address) (map[string]*big.Int, error)
- func (s *Service) TotalReceived(peer string, token common.Address) (totalReceived *big.Int, err error)
- func (s *Service) TotalSent(peer string, token common.Address) (totalSent *big.Int, err error)
- func (s *Service) VaultPeer(vault common.Address) (peer string, known bool, err error)
Constants ¶
This section is empty.
Variables ¶
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 (*Service) BeneficiaryPeer ¶
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 (*Service) GetProtocols ¶
func (s *Service) GetProtocols() swapprotocol.Interface
func (*Service) HasCashoutAction ¶
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 ¶
LastReceivedCheques returns map[peer]cheque
func (*Service) LastSendCheque ¶
LastReceivedCheque returns the last received cheque for the peer
func (*Service) LastSendCheques ¶
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 (*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 ¶
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) 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 ¶
func (s *Service) TotalReceived(peer string, token common.Address) (totalReceived *big.Int, err error)
TotalReceived returns the total amount received from a peer