Documentation ¶
Index ¶
- Constants
- Variables
- type API
- type Cheque
- type ChequeParams
- type EmitChequeMsg
- type HandshakeMsg
- type HoneyOracle
- type Owner
- type Params
- type Peer
- type Swap
- func (s *Swap) APIs() []rpc.API
- func (s *Swap) Add(amount int64, peer *protocols.Peer) (err error)
- func (s *Swap) Balance(peer enode.ID) (balance int64, err error)
- func (s *Swap) Balances() (map[enode.ID]int64, error)
- func (s *Swap) Close() error
- func (s *Swap) Deploy(ctx context.Context, initialDepositAmount uint64) (contract.Contract, error)
- func (s *Swap) GetParams() *swap.Params
- func (s *Swap) Protocols() []p2p.Protocol
- func (s *Swap) Start(server *p2p.Server) error
- func (s *Swap) StartChequebook(chequebookAddrFlag common.Address, initialDepositAmount uint64) (contract contract.Contract, err error)
- func (s *Swap) Stop() error
Constants ¶
const ( // Thresholds which trigger payment or disconnection. The unit is in honey (internal accounting unit) DefaultPaymentThreshold = 1000000 DefaultDisconnectThreshold = 1500000 // DefaultInitialDepositAmount is the default amount to send to the contract when initially deploying // NOTE: deliberate value for now; needs experimentation DefaultInitialDepositAmount = 0 // Until we deploy swap officially, it's only allowed to be enabled under a specific network ID (use the --bzznetworkid flag to set it) AllowedNetworkID = 5 )
These are currently arbitrary values which have not been verified nor tested Need experimentation to arrive to values which make sense
const ( RetrieveRequestPrice = uint64(1) ChunkDeliveryPrice = uint64(1) )
Placeholder prices
Variables ¶
var ( // ErrEmptyAddressInSignature is used when the empty address is used for the chequebook in the handshake ErrEmptyAddressInSignature = errors.New("empty address in handshake") // ErrInvalidHandshakeMsg is used when the message received during handshake does not conform to the // structure of the HandshakeMsg ErrInvalidHandshakeMsg = errors.New("invalid handshake message") // Spec is the swap protocol specification Spec = &protocols.Spec{ Name: "swap", Version: 1, MaxMsgSize: 10 * 1024 * 1024, Messages: []interface{}{ HandshakeMsg{}, EmitChequeMsg{}, }, } )
var ErrDontOwe = errors.New("no negative balance")
ErrDontOwe indictates that no balance is actially owned
var ErrInvalidChequeSignature = errors.New("invalid cheque signature")
ErrInvalidChequeSignature indicates the signature on the cheque was invalid
Functions ¶
This section is empty.
Types ¶
type Cheque ¶ added in v0.5.0
type Cheque struct { ChequeParams Honey uint64 // amount of honey which resulted in the cumulative currency difference Signature []byte // signature Sign(Keccak256(contract, beneficiary, amount), prvKey) }
Cheque encapsulates the parameters and the signature
type ChequeParams ¶ added in v0.5.0
type ChequeParams struct { Contract common.Address // address of chequebook, needed to avoid cross-contract submission Beneficiary common.Address // address of the beneficiary, the contract which will redeem the cheque CumulativePayout uint64 // cumulative amount of the cheque in currency }
ChequeParams encapsulate all cheque parameters
func (*ChequeParams) Sign ¶ added in v0.5.0
func (cheque *ChequeParams) Sign(prv *ecdsa.PrivateKey) ([]byte, error)
Sign returns the cheque's signature with supplied private key
type EmitChequeMsg ¶ added in v0.5.0
type EmitChequeMsg struct {
Cheque *Cheque
}
EmitChequeMsg is sent from the debitor to the creditor with the actual check
type HandshakeMsg ¶ added in v0.5.0
HandshakeMsg is exchanged on peer handshake
type HoneyOracle ¶ added in v0.5.0
HoneyOracle is the interface through which Oracles will deliver prices
func NewHoneyPriceOracle ¶ added in v0.5.0
func NewHoneyPriceOracle() HoneyOracle
NewHoneyPriceOracle returns the actual oracle to be used for discovering the price It will return a default one
type Owner ¶ added in v0.5.0
type Owner struct {
// contains filtered or unexported fields
}
Owner encapsulates information related to accessing the contract
type Params ¶ added in v0.5.0
type Params struct { LogPath string // optional audit log path PaymentThreshold int64 // honey amount at which a payment is triggered DisconnectThreshold int64 // honey amount at which a peer disconnects }
Params encapsulates param
type Swap ¶
type Swap struct {
// contains filtered or unexported fields
}
Swap represents the Swarm Accounting Protocol a peer to peer micropayment system A node maintains an individual balance with every peer Only messages which have a price will be accounted for
func New ¶
func New(dbPath string, prvkey *ecdsa.PrivateKey, backendURL string, params *Params, chequebookAddressFlag common.Address, initialDepositAmountFlag uint64) (swap *Swap, err error)
New prepares and creates all fields to create a swap instance: - sets up a SWAP database; - verifies whether the disconnect threshold is higher than the payment threshold; - connects to the blockchain backend; - verifies that we have not connected SWAP before on a different blockchain backend; - starts the chequebook; creates the swap instance
func (*Swap) Add ¶
Add is the (sole) accounting function Swap implements the protocols.Balance interface
func (*Swap) GetParams ¶ added in v0.5.0
GetParams returns contract parameters (Bin, ABI, contractAddress) from the contract
func (*Swap) StartChequebook ¶ added in v0.5.0
func (s *Swap) StartChequebook(chequebookAddrFlag common.Address, initialDepositAmount uint64) (contract contract.Contract, err error)
StartChequebook starts the chequebook, taking into account the chequebookAddress passed in by the user and the chequebook addresses saved on the node's database