payments

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0, MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const PAYER_INDEX = 0

Variables

This section is empty.

Functions

func GetPayee

func GetPayee(participants []types.Address) types.Address

GetPayee returns the payee on a payment channel

func GetPayer

func GetPayer(participants []types.Address) types.Address

GetPayer returns the payer on a payment channel

Types

type ReceiveVoucherSummary

type ReceiveVoucherSummary struct {
	Total *big.Int
	Delta *big.Int
}

type Voucher

type Voucher struct {
	ChannelId types.Destination
	Amount    *big.Int
	Signature state.Signature
}

A Voucher signed by Alice can be used by Bob to redeem payments in case of a misbehaving Alice.

During normal operation, Alice & Bob would terminate the channel with an outcome reflecting the largest amount signed by Alice. For instance,

  • if the channel started with balances {alice: 100, bob: 0}
  • and the biggest voucher signed by alice had amount = 20
  • then Alice and Bob would cooperatively conclude the channel with outcome {alice: 80, bob: 20}

func (*Voucher) Equal

func (v *Voucher) Equal(other *Voucher) bool

Equal returns true if the two vouchers have the same channel id, amount and signatures

func (*Voucher) Hash

func (v *Voucher) Hash() (types.Bytes32, error)

func (*Voucher) RecoverSigner

func (v *Voucher) RecoverSigner() (types.Address, error)

func (*Voucher) Sign

func (v *Voucher) Sign(pk []byte) error

type VoucherInfo

type VoucherInfo struct {
	ChannelPayer    common.Address
	ChannelPayee    common.Address
	StartingBalance *big.Int
	LargestVoucher  Voucher
}

VoucherInfo contains the largest voucher we've received on a channel. As well as details about the balance and who the payee/payer is.

func (*VoucherInfo) Paid

func (v *VoucherInfo) Paid() *big.Int

Paid is the amount of funds that already have been used as payments

func (*VoucherInfo) Remaining

func (v *VoucherInfo) Remaining() *big.Int

Remaining returns the amount of funds left to be used as payments

type VoucherManager

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

VoucherInfo stores the status of payments for a given payment channel. VoucherManager receives and generates vouchers. It is responsible for storing vouchers.

func NewVoucherManager

func NewVoucherManager(me types.Address, store VoucherStore) *VoucherManager

NewVoucherManager creates a new voucher manager

func (*VoucherManager) ChannelRegistered

func (vm *VoucherManager) ChannelRegistered(channelId types.Destination) bool

ChannelRegistered returns whether a channel has been registered with the voucher manager or not

func (*VoucherManager) Paid

func (vm *VoucherManager) Paid(chanId types.Destination) (*big.Int, error)

Paid returns the total amount paid so far on a channel

func (*VoucherManager) Pay

func (vm *VoucherManager) Pay(channelId types.Destination, amount *big.Int, pk []byte) (Voucher, error)

Pay will deduct amount from balance and add it to paid, returning a signed voucher for the total amount paid.

func (*VoucherManager) Receive

func (vm *VoucherManager) Receive(voucher Voucher) (total *big.Int, delta *big.Int, err error)

Receive validates the incoming voucher, and returns the total amount received so far as well as the amount received from the voucher

func (*VoucherManager) Register

func (vm *VoucherManager) Register(channelId types.Destination, payer common.Address, payee common.Address, startingBalance *big.Int) error

Register registers a channel for use, given the payer, payee and starting balance of the channel

func (*VoucherManager) Remaining

func (vm *VoucherManager) Remaining(chanId types.Destination) (*big.Int, error)

Remaining returns the remaining amount of funds in the channel

func (*VoucherManager) Remove

func (vm *VoucherManager) Remove(channelId types.Destination) error

Remove deletes the channel's status

type VoucherStore

type VoucherStore interface {
	SetVoucherInfo(channelId types.Destination, v VoucherInfo) error
	GetVoucherInfo(channelId types.Destination) (v *VoucherInfo, err error)
	RemoveVoucherInfo(channelId types.Destination) error
}

VoucherStore is an interface for storing voucher information that the voucher manager expects. To avoid import cycles, this interface is defined in the payments package, but implemented in the store package.

Jump to

Keyboard shortcuts

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