swap

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: GPL-3.0 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()
}

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()
}

interface for the (delayed) ougoing payment system with autodeposit

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
}

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
}

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 serialisable to send with Protocol

type Protocol

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

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) (self *Swap, err error)

swap constructor

func (*Swap) Add

func (self *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 (self *Swap) Balance() int

func (*Swap) Receive

func (self *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 (self *Swap) SetParams(local *Params)

to set strategy dynamically

func (*Swap) SetRemote

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

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

func (*Swap) Stop

func (self *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