swap

package
v3.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: GPL-3.0, LGPL-3.0, LGPL-3.0-or-later Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InPayment

type InPayment interface {
	Receive(promise Promise) (*big.Int, error)
	AutoCash(cashInterval time.Duration, maxUncashed *big.Int)
	Stop()
}

InPayment interface for the (delayed) incoming payment system with autocash

type OutPayment

type OutPayment interface {
	Issue(amount *big.Int) (promise Promise, err error)
	AutoDeposit(interval time.Duration, threshold, buffer *big.Int)
	Stop()
}

OutPayment interface for the (delayed) outgoing payment system with auto-deposit

type Params

type Params struct {
	*Profile
	*Strategy
}

Params extends the public profile with private parameters relating to automatic deposit and automatic cashing

type Payment

type Payment struct {
	Out         OutPayment // outgoing payment handler
	In          InPayment  // incoming  payment handler
	Buys, Sells bool
}

Payment handlers

type Profile

type Profile struct {
	BuyAt  *big.Int // accepted max price for chunk
	SellAt *big.Int // offered sale price for chunk
	PayAt  uint     // threshold that triggers payment request
	DropAt uint     // threshold that triggers disconnect
}

Profile - public swap profile public parameters for SWAP, serializable config struct passed in handshake

type Promise

type Promise interface{}

Promise - 3rd party Provable Promise of Payment issued by outPayment serializable to send with Protocol

type Protocol

type Protocol interface {
	Pay(int, Promise) // units, payment proof
	Drop()
	String() string
}

Protocol interface for the peer protocol for testing or external alternative payment

type Strategy

type Strategy struct {
	AutoCashInterval     time.Duration // default interval for autocash
	AutoCashThreshold    *big.Int      // threshold that triggers autocash (wei)
	AutoDepositInterval  time.Duration // default interval for autocash
	AutoDepositThreshold *big.Int      // threshold that triggers autodeposit (wei)
	AutoDepositBuffer    *big.Int      // buffer that is surplus for fork protection etc (wei)
}

Strategy encapsulates parameters relating to automatic deposit and automatic cashing

type Swap

type Swap struct {
	Payment
	// contains filtered or unexported fields
}

Swap is the swarm accounting protocol instance * pairwise accounting and payments

func New

func New(local *Params, pm Payment, proto Protocol) (swap *Swap, err error)

New - swap constructor

func (*Swap) Add

func (swap *Swap) Add(n int) error

Add (n) n > 0 called when promised/provided n units of service n < 0 called when used/requested n units of service

func (*Swap) Balance

func (swap *Swap) Balance() int

Balance accessor

func (*Swap) Receive

func (swap *Swap) Receive(units int, promise Promise) error

Receive (units, promise) is called by the protocol when a payment msg is received returns error if promise is invalid.

func (*Swap) SetParams

func (swap *Swap) SetParams(local *Params)

SetParams - to set strategy dynamically

func (*Swap) SetRemote

func (swap *Swap) SetRemote(remote *Profile)

SetRemote - entry point for setting remote swap profile (e.g from handshake or other message)

func (*Swap) Stop

func (swap *Swap) Stop()

Stop causes autocash loop to terminate. Called after protocol handle loop terminates.

Jump to

Keyboard shortcuts

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