paymgr

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: Apache-2.0, MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opts

type Opts struct {
	// The datastore path of the payment manager.
	Path string

	// The cache and store sync frequency.
	CacheSyncFreq time.Duration

	// The reservation cleaning frequency.
	ResCleanFreq time.Duration

	// The reservation cleaning timeout (for locking).
	ResCleanTimeout time.Duration

	// The peer cleaning frequency.
	PeerCleanFreq time.Duration

	// The peer cleaning timeout (for locking).
	PeerCleanTimeout time.Duration
}

Opts is the options for payment manager.

type PaymentManager

type PaymentManager interface {

	// Reserve is used to reserve a certain amount.
	//
	// @input - context, currency id, recipient address, petty amount required, whether reservation requires served channel, optional received offer, first expiration time, subsequent allowed inactivity time, peer addr who requests the reservation.
	//
	// @output - reserved inbound price-per-byte, reserved inbound period, reserved channel address, reservation id, error.
	Reserve(ctx context.Context, currencyID byte, toAddr string, pettyAmtRequired *big.Int, servedRequired bool, receivedOffer *fcroffer.PayOffer, expiration time.Time, inactivity time.Duration, peerAddr string) (*big.Int, *big.Int, string, uint64, error)

	// Pay is used to make a payment.
	//
	// @input - context, currency id, recipient address, reserved channel address, reservation id, received gross payment to drive this payment, petty amount required.
	//
	// @output - voucher, potential linked offer, function to commit & record access time, function to revert & record network loss, error.
	Pay(ctx context.Context, currencyID byte, toAddr string, chAddr string, resID uint64, grossAmtReceived *big.Int, pettyAmtRequired *big.Int) (string, *fcroffer.PayOffer, func(time.Time), func(string), error)

	// Receive is used to receive a payment in a voucher.
	//
	// @input - context, currency id, voucher.
	//
	// @output - received gross amount, function to commit, function to revert, the lastest voucher recorded previously if network loss presents, error.
	Receive(ctx context.Context, currencyID byte, voucher string) (*big.Int, func(), func(), string, error)

	// ReserveForSelf is used to reserve a certain amount for self to spend for configured time.
	//
	// @input - context, currency id, recipient address, petty amount, first expiration time, subsequent allowed inactivity time.
	//
	// @output - reserved channel address, reservation id, error.
	ReserveForSelf(ctx context.Context, currencyID byte, toAddr string, pettyAmt *big.Int, expiration time.Time, inactivity time.Duration) (string, uint64, error)

	// ReserveForSelfWithOffer is used to reserve a certain amount for self to spend based on a received offer.
	//
	// @input - context, received offer.
	//
	// @output - reserved channel address, reservation id, error.
	ReserveForSelfWithOffer(ctx context.Context, receivedOffer fcroffer.PayOffer) (string, uint64, error)

	// ReserveForOthersIntermediate is used to reserve some amount for others as an intermediate node based on required inbound surcharge and a received offer, peer addr who requests the reservation.
	//
	// @input - context, received offer.
	//
	// @output - reserved inbound price-per-byte, reserved inbound period, reserved channel address, reservation id, error.
	ReserveForOthersIntermediate(ctx context.Context, receivedOffer fcroffer.PayOffer, peerAddr string) (*big.Int, *big.Int, string, uint64, error)

	// ReserveForOthersFinal is used to reserve some amount for others as a final node based on required inbound surcharge, peer addr who requests the reservation.
	//
	// @input - context, currency id, recipient address, petty amount, first expiration time, subsequent allowed inactivity time.
	//
	// @output - reserved inbound price-per-byte, reserved inbound period, reserved channel address, reservation id, error.
	ReserveForOthersFinal(ctx context.Context, currencyID byte, toAddr string, pettyAmt *big.Int, expiration time.Time, inactivity time.Duration, peerAddr string) (*big.Int, *big.Int, string, uint64, error)

	// PayForSelf is used to make a payment for self.
	//
	// @input - context, currency id, recipient address, reserved channel address, reservation id, petty amount required.
	//
	// @output - voucher, potential linked offer, function to commit & record access time, function to revert & record network loss, error.
	PayForSelf(ctx context.Context, currencyID byte, toAddr string, chAddr string, resID uint64, pettyAmtRequired *big.Int) (string, *fcroffer.PayOffer, func(time.Time), func(string), error)

	// PayForOthers is used to make a payment for others.
	//
	// @input - context, currency id, recipient address, reserved channel address, reservation id, gross amount received, petty amount required.
	//
	// @output - voucher, potential linked offer, function to commit & record access time, function to revert & record network loss, error.
	PayForOthers(ctx context.Context, currencyID byte, toAddr string, chAddr string, resID uint64, grossAmtReceived *big.Int, pettyAmtRequired *big.Int) (string, *fcroffer.PayOffer, func(time.Time), func(string), error)

	// AddInboundChannel is used to add an inbound payment channel.
	//
	// @input - context, currency id, from address, channel address.
	//
	// @output - error.
	AddInboundChannel(ctx context.Context, currencyID byte, fromAddr string, chAddr string) error

	// RetireInboundChannel is used to retire an inbound payment channel.
	//
	// @input - context, currency id, from address, channel address.
	//
	// @output - error.
	RetireInboundChannel(ctx context.Context, currencyID byte, fromAddr string, chAddr string) error

	// AddOutboundChannel is used to add an outbound payment channel.
	//
	// @input - context, currency id, recipient address, channel address.
	//
	// @output - error.
	AddOutboundChannel(ctx context.Context, currencyID byte, toAddr string, chAddr string) error

	// RetireOutboundChannel is used to retire an outbound payment channel.
	//
	// @input - context, currency id, recipient address, channel address.
	//
	// @output - error.
	RetireOutboundChannel(ctx context.Context, currencyID byte, toAddr string, chAddr string) error

	// UpdateOutboundChannelBalance is used to update the balance of an outbound payment channel.
	//
	// @input - context, currency id, recipient address, channel address.
	//
	// @output - error.
	UpdateOutboundChannelBalance(ctx context.Context, currencyID byte, toAddr string, chAddr string) error

	// BearNetworkLoss is used to bear and ignore the network loss of a given channel.
	//
	// @input - context, currency id, recipient address, channel address.
	//
	// @output - error.
	BearNetworkLoss(ctx context.Context, currencyID byte, toAddr string, chAddr string) error
}

PaymentManager is an interface for a payment manager that handles all payment related functionalities.

type PaymentManagerImpl

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

PaymentManagerImpl is the implementation of the PaymentManager interface.

func NewPaymentManagerImpl

func NewPaymentManagerImpl(
	ctx context.Context,
	activeOutStore paychstore.PaychStore,
	activeInStore paychstore.PaychStore,
	inactiveOutStore paychstore.PaychStore,
	inactiveInStore paychstore.PaychStore,
	pservMgr pservmgr.PaychServingManager,
	reservMgr reservmgr.ReservationManager,
	rs routestore.RouteStore,
	subs substore.SubStore,
	transactor trans.Transactor,
	signer crypto.Signer,
	opts Opts,
) (*PaymentManagerImpl, error)

NewPaymentManagerImpl creates a new PaymentManagerImpl.

@input - context, currencies, active out channel store, active in channel store, inactive out channel store, inactive in channel store, transactor, signer, options.

@output - payment manager, error.

func (*PaymentManagerImpl) AddInboundChannel

func (mgr *PaymentManagerImpl) AddInboundChannel(ctx context.Context, currencyID byte, fromAddr string, chAddr string) error

AddInboundChannel is used to add an inbound payment channel.

@input - context, currency id, from address, channel address.

@output - error.

func (*PaymentManagerImpl) AddOutboundChannel

func (mgr *PaymentManagerImpl) AddOutboundChannel(ctx context.Context, currencyID byte, toAddr string, chAddr string) error

AddOutboundChannel is used to add an outbound payment channel.

@input - context, currency id, recipient address, channel address.

@output - error.

func (*PaymentManagerImpl) BearNetworkLoss

func (mgr *PaymentManagerImpl) BearNetworkLoss(ctx context.Context, currencyID byte, toAddr string, chAddr string) error

BearNetworkLoss is used to bear and ignore the network loss of a given channel.

@input - context, currency id, recipient address, channel address.

@output - error.

func (*PaymentManagerImpl) Pay

func (mgr *PaymentManagerImpl) Pay(ctx context.Context, currencyID byte, toAddr string, chAddr string, resID uint64, grossAmtReceived *big.Int, pettyAmtRequired *big.Int) (string, *fcroffer.PayOffer, func(time.Time), func(string), error)

Pay is used to make a payment.

@input - context, currency id, recipient address, reserved channel address, reservation id, received gross payment to drive this payment, petty amount required.

@output - voucher, potential linked offer, function to commit & record access time, function to revert & record network loss, error.

func (*PaymentManagerImpl) PayForOthers

func (mgr *PaymentManagerImpl) PayForOthers(ctx context.Context, currencyID byte, toAddr string, chAddr string, resID uint64, grossAmtReceived *big.Int, pettyAmtRequired *big.Int) (string, *fcroffer.PayOffer, func(time.Time), func(string), error)

PayForOthers is used to make a payment for others.

@input - context, currency id, recipient address, reserved channel address, reservation id, gross amount received, petty amount required.

@output - voucher, potential linked offer, function to commit & record access time, function to revert & record network loss, error.

func (*PaymentManagerImpl) PayForSelf

func (mgr *PaymentManagerImpl) PayForSelf(ctx context.Context, currencyID byte, toAddr string, chAddr string, resID uint64, pettyAmtRequired *big.Int) (string, *fcroffer.PayOffer, func(time.Time), func(string), error)

PayForSelf is used to make a payment for self.

@input - context, currency id, recipient address, reserved channel address, reservation id, petty amount required.

@output - voucher, potential linked offer, function to commit & record access time, function to revert & record network loss, error.

func (*PaymentManagerImpl) Receive

func (mgr *PaymentManagerImpl) Receive(ctx context.Context, currencyID byte, voucher string) (*big.Int, func(), func(), string, error)

Receive is used to receive a payment in a voucher.

@input - context, currency id, voucher.

@output - received gross amount, function to commit, function to revert, the lastest voucher recorded previously if network loss presents, error.

func (*PaymentManagerImpl) Reserve

func (mgr *PaymentManagerImpl) Reserve(ctx context.Context, currencyID byte, toAddr string, pettyAmtRequired *big.Int, servedRequired bool, receivedOffer *fcroffer.PayOffer, expiration time.Time, inactivity time.Duration, peerAddr string) (*big.Int, *big.Int, string, uint64, error)

Reserve is used to reserve a certain amount.

@input - context, currency id, recipient address, petty amount required, whether reservation requires served channel, optional received offer, first expiration time, subsequent allowed inactivity time, peer addr who requests the reservation.

@output - reserved inbound price-per-byte, reserved inbound period, reserved channel address, reservation id, error.

func (*PaymentManagerImpl) ReserveForOthersFinal

func (mgr *PaymentManagerImpl) ReserveForOthersFinal(ctx context.Context, currencyID byte, toAddr string, pettyAmt *big.Int, expiration time.Time, inactivity time.Duration, peerAddr string) (*big.Int, *big.Int, string, uint64, error)

ReserveForOthersFinal is used to reserve some amount for others as a final node based on required inbound surcharge, peer addr who requests the reservation.

@input - context, currency id, recipient address, petty amount, first expiration time, subsequent allowed inactivity time.

@output - reserved inbound price-per-byte, reserved inbound period, reserved channel address, reservation id, error.

func (*PaymentManagerImpl) ReserveForOthersIntermediate

func (mgr *PaymentManagerImpl) ReserveForOthersIntermediate(ctx context.Context, receivedOffer fcroffer.PayOffer, peerAddr string) (*big.Int, *big.Int, string, uint64, error)

ReserveForOthersIntermediate is used to reserve some amount for others as an intermediate node based on required inbound surcharge and a received offer, peer addr who requests the reservation.

@input - context, received offer.

@output - reserved inbound price-per-byte, reserved inbound period, reserved channel address, reservation id, error.

func (*PaymentManagerImpl) ReserveForSelf

func (mgr *PaymentManagerImpl) ReserveForSelf(ctx context.Context, currencyID byte, toAddr string, pettyAmt *big.Int, expiration time.Time, inactivity time.Duration) (string, uint64, error)

ReserveForSelf is used to reserve a certain amount for self to spend for configured time.

@input - context, currency id, recipient address, petty amount, first expiration time, subsequent allowed inactivity time.

@output - reserved channel address, reservation id, error.

func (*PaymentManagerImpl) ReserveForSelfWithOffer

func (mgr *PaymentManagerImpl) ReserveForSelfWithOffer(ctx context.Context, receivedOffer fcroffer.PayOffer) (string, uint64, error)

ReserveForSelfWithOffer is used to reserve a certain amount for self to spend based on a received offer.

@input - context, received offer.

@output - reserved channel address, reservation id, error.

func (*PaymentManagerImpl) RetireInboundChannel

func (mgr *PaymentManagerImpl) RetireInboundChannel(ctx context.Context, currencyID byte, fromAddr string, chAddr string) error

RetireInboundChannel is used to retire an inbound payment channel.

@input - context, currency id, from address, channel address.

@output - error.

func (*PaymentManagerImpl) RetireOutboundChannel

func (mgr *PaymentManagerImpl) RetireOutboundChannel(ctx context.Context, currencyID byte, toAddr string, chAddr string) error

RetireOutboundChannel is used to retire an outbound payment channel.

@input - context, currency id, recipient address, channel address.

@output - error.

func (*PaymentManagerImpl) Shutdown

func (mgr *PaymentManagerImpl) Shutdown()

Shutdown safely shuts down the component.

func (*PaymentManagerImpl) UpdateOutboundChannelBalance

func (mgr *PaymentManagerImpl) UpdateOutboundChannelBalance(ctx context.Context, currencyID byte, toAddr string, chAddr string) error

UpdateOutboundChannelBalance is used to update the balance of an outbound payment channel.

@input - context, currency id, recipient address, channel address.

@output - error.

Jump to

Keyboard shortcuts

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