Documentation ¶
Overview ¶
Package paychan implements payment side channel functionality.
Payment channel functionality allows to deposit an amount that can be later transferred in chunks over that payment channel. Owner of the payment channel can choose to send full allocated amount or just a part of it over time and recipient can claim received money. When funds from a payment channel are claimed, payment channel is closed and any remaining tokens are returned to the payment channel owner.
Except creation and final closing transaction, all payment channel operations are made off the chain and therefore are very fast and cheap to execute.
Payment channel can be closed only by the recipient when claiming received funds or by the payment channel owner after the deadline was reached.
Index ¶
- Variables
- func RegisterQuery(qr weave.QueryRouter)
- func RegisterRoutes(r weave.Registry, auth x.Authenticator, cash cash.Controller)
- type ClosePaymentChannelMsg
- func (*ClosePaymentChannelMsg) Descriptor() ([]byte, []int)
- func (m *ClosePaymentChannelMsg) GetChannelID() []byte
- func (m *ClosePaymentChannelMsg) GetMemo() string
- func (m *ClosePaymentChannelMsg) Marshal() (dAtA []byte, err error)
- func (m *ClosePaymentChannelMsg) MarshalTo(dAtA []byte) (int, error)
- func (ClosePaymentChannelMsg) Path() string
- func (*ClosePaymentChannelMsg) ProtoMessage()
- func (m *ClosePaymentChannelMsg) Reset()
- func (m *ClosePaymentChannelMsg) Size() (n int)
- func (m *ClosePaymentChannelMsg) String() string
- func (m *ClosePaymentChannelMsg) Unmarshal(dAtA []byte) error
- func (m *ClosePaymentChannelMsg) Validate() error
- func (m *ClosePaymentChannelMsg) XXX_DiscardUnknown()
- func (m *ClosePaymentChannelMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ClosePaymentChannelMsg) XXX_Merge(src proto.Message)
- func (m *ClosePaymentChannelMsg) XXX_Size() int
- func (m *ClosePaymentChannelMsg) XXX_Unmarshal(b []byte) error
- type CreatePaymentChannelMsg
- func (*CreatePaymentChannelMsg) Descriptor() ([]byte, []int)
- func (m *CreatePaymentChannelMsg) GetMemo() string
- func (m *CreatePaymentChannelMsg) GetRecipient() []byte
- func (m *CreatePaymentChannelMsg) GetSenderPubkey() *crypto.PublicKey
- func (m *CreatePaymentChannelMsg) GetSrc() []byte
- func (m *CreatePaymentChannelMsg) GetTimeout() int64
- func (m *CreatePaymentChannelMsg) GetTotal() *coin.Coin
- func (m *CreatePaymentChannelMsg) Marshal() (dAtA []byte, err error)
- func (m *CreatePaymentChannelMsg) MarshalTo(dAtA []byte) (int, error)
- func (CreatePaymentChannelMsg) Path() string
- func (*CreatePaymentChannelMsg) ProtoMessage()
- func (m *CreatePaymentChannelMsg) Reset()
- func (m *CreatePaymentChannelMsg) Size() (n int)
- func (m *CreatePaymentChannelMsg) String() string
- func (m *CreatePaymentChannelMsg) Unmarshal(dAtA []byte) error
- func (m *CreatePaymentChannelMsg) Validate() error
- func (m *CreatePaymentChannelMsg) XXX_DiscardUnknown()
- func (m *CreatePaymentChannelMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *CreatePaymentChannelMsg) XXX_Merge(src proto.Message)
- func (m *CreatePaymentChannelMsg) XXX_Size() int
- func (m *CreatePaymentChannelMsg) XXX_Unmarshal(b []byte) error
- type Payment
- func (*Payment) Descriptor() ([]byte, []int)
- func (m *Payment) GetAmount() *coin.Coin
- func (m *Payment) GetChainID() string
- func (m *Payment) GetChannelID() []byte
- func (m *Payment) GetMemo() string
- func (m *Payment) Marshal() (dAtA []byte, err error)
- func (m *Payment) MarshalTo(dAtA []byte) (int, error)
- func (*Payment) ProtoMessage()
- func (m *Payment) Reset()
- func (m *Payment) Size() (n int)
- func (m *Payment) String() string
- func (m *Payment) Unmarshal(dAtA []byte) error
- func (m *Payment) XXX_DiscardUnknown()
- func (m *Payment) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Payment) XXX_Merge(src proto.Message)
- func (m *Payment) XXX_Size() int
- func (m *Payment) XXX_Unmarshal(b []byte) error
- type PaymentChannel
- func (pc PaymentChannel) Copy() orm.CloneableData
- func (*PaymentChannel) Descriptor() ([]byte, []int)
- func (m *PaymentChannel) GetMemo() string
- func (m *PaymentChannel) GetRecipient() []byte
- func (m *PaymentChannel) GetSenderPubkey() *crypto.PublicKey
- func (m *PaymentChannel) GetSrc() []byte
- func (m *PaymentChannel) GetTimeout() int64
- func (m *PaymentChannel) GetTotal() *coin.Coin
- func (m *PaymentChannel) GetTransferred() *coin.Coin
- func (m *PaymentChannel) Marshal() (dAtA []byte, err error)
- func (m *PaymentChannel) MarshalTo(dAtA []byte) (int, error)
- func (*PaymentChannel) ProtoMessage()
- func (m *PaymentChannel) Reset()
- func (m *PaymentChannel) Size() (n int)
- func (m *PaymentChannel) String() string
- func (m *PaymentChannel) Unmarshal(dAtA []byte) error
- func (pc *PaymentChannel) Validate() error
- func (m *PaymentChannel) XXX_DiscardUnknown()
- func (m *PaymentChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *PaymentChannel) XXX_Merge(src proto.Message)
- func (m *PaymentChannel) XXX_Size() int
- func (m *PaymentChannel) XXX_Unmarshal(b []byte) error
- type PaymentChannelBucket
- type TransferPaymentChannelMsg
- func (*TransferPaymentChannelMsg) Descriptor() ([]byte, []int)
- func (m *TransferPaymentChannelMsg) GetPayment() *Payment
- func (m *TransferPaymentChannelMsg) GetSignature() *crypto.Signature
- func (m *TransferPaymentChannelMsg) Marshal() (dAtA []byte, err error)
- func (m *TransferPaymentChannelMsg) MarshalTo(dAtA []byte) (int, error)
- func (TransferPaymentChannelMsg) Path() string
- func (*TransferPaymentChannelMsg) ProtoMessage()
- func (m *TransferPaymentChannelMsg) Reset()
- func (m *TransferPaymentChannelMsg) Size() (n int)
- func (m *TransferPaymentChannelMsg) String() string
- func (m *TransferPaymentChannelMsg) Unmarshal(dAtA []byte) error
- func (m *TransferPaymentChannelMsg) Validate() error
- func (m *TransferPaymentChannelMsg) XXX_DiscardUnknown()
- func (m *TransferPaymentChannelMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *TransferPaymentChannelMsg) XXX_Merge(src proto.Message)
- func (m *TransferPaymentChannelMsg) XXX_Size() int
- func (m *TransferPaymentChannelMsg) XXX_Unmarshal(b []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowCodec = fmt.Errorf("proto: integer overflow") )
Functions ¶
func RegisterQuery ¶
func RegisterQuery(qr weave.QueryRouter)
RegisterQuery registers payment channel bucket under /paychans.
func RegisterRoutes ¶
func RegisterRoutes(r weave.Registry, auth x.Authenticator, cash cash.Controller)
RegisterRouters registers payment channel message handelers in given registry.
Types ¶
type ClosePaymentChannelMsg ¶
type ClosePaymentChannelMsg struct { ChannelID []byte `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` // Max length 128 character. Memo string `protobuf:"bytes,2,opt,name=memo,proto3" json:"memo,omitempty"` }
ClosePaymentChannelMsg close a payment channel and release remaining founds by sending them back to the sender account.
Recipient account can close channel at any moment.
Sender can close channel only if the timeout chain height was reached.
func (*ClosePaymentChannelMsg) Descriptor ¶
func (*ClosePaymentChannelMsg) Descriptor() ([]byte, []int)
func (*ClosePaymentChannelMsg) GetChannelID ¶ added in v0.10.0
func (m *ClosePaymentChannelMsg) GetChannelID() []byte
func (*ClosePaymentChannelMsg) GetMemo ¶
func (m *ClosePaymentChannelMsg) GetMemo() string
func (*ClosePaymentChannelMsg) Marshal ¶
func (m *ClosePaymentChannelMsg) Marshal() (dAtA []byte, err error)
func (*ClosePaymentChannelMsg) MarshalTo ¶
func (m *ClosePaymentChannelMsg) MarshalTo(dAtA []byte) (int, error)
func (ClosePaymentChannelMsg) Path ¶
func (ClosePaymentChannelMsg) Path() string
func (*ClosePaymentChannelMsg) ProtoMessage ¶
func (*ClosePaymentChannelMsg) ProtoMessage()
func (*ClosePaymentChannelMsg) Reset ¶
func (m *ClosePaymentChannelMsg) Reset()
func (*ClosePaymentChannelMsg) Size ¶
func (m *ClosePaymentChannelMsg) Size() (n int)
func (*ClosePaymentChannelMsg) String ¶
func (m *ClosePaymentChannelMsg) String() string
func (*ClosePaymentChannelMsg) Unmarshal ¶
func (m *ClosePaymentChannelMsg) Unmarshal(dAtA []byte) error
func (*ClosePaymentChannelMsg) Validate ¶
func (m *ClosePaymentChannelMsg) Validate() error
func (*ClosePaymentChannelMsg) XXX_DiscardUnknown ¶ added in v0.12.0
func (m *ClosePaymentChannelMsg) XXX_DiscardUnknown()
func (*ClosePaymentChannelMsg) XXX_Marshal ¶ added in v0.12.0
func (m *ClosePaymentChannelMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ClosePaymentChannelMsg) XXX_Merge ¶ added in v0.12.0
func (m *ClosePaymentChannelMsg) XXX_Merge(src proto.Message)
func (*ClosePaymentChannelMsg) XXX_Size ¶ added in v0.12.0
func (m *ClosePaymentChannelMsg) XXX_Size() int
func (*ClosePaymentChannelMsg) XXX_Unmarshal ¶ added in v0.12.0
func (m *ClosePaymentChannelMsg) XXX_Unmarshal(b []byte) error
type CreatePaymentChannelMsg ¶
type CreatePaymentChannelMsg struct { // Sender address (weave.Address). Src []byte `protobuf:"bytes,1,opt,name=src,proto3" json:"src,omitempty"` // Sender public key is for validating transfer message signature. SenderPubkey *crypto.PublicKey `protobuf:"bytes,2,opt,name=sender_pubkey,json=senderPubkey,proto3" json:"sender_pubkey,omitempty"` // Recipient address (weave.Address). Recipient []byte `protobuf:"bytes,3,opt,name=recipient,proto3" json:"recipient,omitempty"` // Maximum amount that can be transferred via this channel. Total *coin.Coin `protobuf:"bytes,4,opt,name=total,proto3" json:"total,omitempty"` // Absolute block height value. If reached, channel can be closed by // anyone. Timeout int64 `protobuf:"varint,5,opt,name=timeout,proto3" json:"timeout,omitempty"` // Max length 128 character. Memo string `protobuf:"bytes,6,opt,name=memo,proto3" json:"memo,omitempty"` }
CreatePaymentChannelMsg creates a new payment channel that can be used to transfer value between two parties.
Total amount will be taken from the senders account and allocated for user in the transactions done via created payment channel.
func (*CreatePaymentChannelMsg) Descriptor ¶
func (*CreatePaymentChannelMsg) Descriptor() ([]byte, []int)
func (*CreatePaymentChannelMsg) GetMemo ¶
func (m *CreatePaymentChannelMsg) GetMemo() string
func (*CreatePaymentChannelMsg) GetRecipient ¶
func (m *CreatePaymentChannelMsg) GetRecipient() []byte
func (*CreatePaymentChannelMsg) GetSenderPubkey ¶
func (m *CreatePaymentChannelMsg) GetSenderPubkey() *crypto.PublicKey
func (*CreatePaymentChannelMsg) GetSrc ¶
func (m *CreatePaymentChannelMsg) GetSrc() []byte
func (*CreatePaymentChannelMsg) GetTimeout ¶
func (m *CreatePaymentChannelMsg) GetTimeout() int64
func (*CreatePaymentChannelMsg) GetTotal ¶
func (m *CreatePaymentChannelMsg) GetTotal() *coin.Coin
func (*CreatePaymentChannelMsg) Marshal ¶
func (m *CreatePaymentChannelMsg) Marshal() (dAtA []byte, err error)
func (*CreatePaymentChannelMsg) MarshalTo ¶
func (m *CreatePaymentChannelMsg) MarshalTo(dAtA []byte) (int, error)
func (CreatePaymentChannelMsg) Path ¶
func (CreatePaymentChannelMsg) Path() string
func (*CreatePaymentChannelMsg) ProtoMessage ¶
func (*CreatePaymentChannelMsg) ProtoMessage()
func (*CreatePaymentChannelMsg) Reset ¶
func (m *CreatePaymentChannelMsg) Reset()
func (*CreatePaymentChannelMsg) Size ¶
func (m *CreatePaymentChannelMsg) Size() (n int)
func (*CreatePaymentChannelMsg) String ¶
func (m *CreatePaymentChannelMsg) String() string
func (*CreatePaymentChannelMsg) Unmarshal ¶
func (m *CreatePaymentChannelMsg) Unmarshal(dAtA []byte) error
func (*CreatePaymentChannelMsg) Validate ¶
func (m *CreatePaymentChannelMsg) Validate() error
func (*CreatePaymentChannelMsg) XXX_DiscardUnknown ¶ added in v0.12.0
func (m *CreatePaymentChannelMsg) XXX_DiscardUnknown()
func (*CreatePaymentChannelMsg) XXX_Marshal ¶ added in v0.12.0
func (m *CreatePaymentChannelMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*CreatePaymentChannelMsg) XXX_Merge ¶ added in v0.12.0
func (m *CreatePaymentChannelMsg) XXX_Merge(src proto.Message)
func (*CreatePaymentChannelMsg) XXX_Size ¶ added in v0.12.0
func (m *CreatePaymentChannelMsg) XXX_Size() int
func (*CreatePaymentChannelMsg) XXX_Unmarshal ¶ added in v0.12.0
func (m *CreatePaymentChannelMsg) XXX_Unmarshal(b []byte) error
type Payment ¶
type Payment struct { ChainID string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` ChannelID []byte `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` Amount *coin.Coin `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount,omitempty"` // Max length 128 character. Memo string `protobuf:"bytes,4,opt,name=memo,proto3" json:"memo,omitempty"` }
Payment is created by the sender. Sender should give the message to the recipient, so that it can be redeemed at any time.
Each Payment should be created with amount greater than the previous one.
func (*Payment) Descriptor ¶
func (*Payment) GetChainID ¶ added in v0.10.0
func (*Payment) GetChannelID ¶ added in v0.10.0
func (*Payment) ProtoMessage ¶
func (*Payment) ProtoMessage()
func (*Payment) XXX_DiscardUnknown ¶ added in v0.12.0
func (m *Payment) XXX_DiscardUnknown()
func (*Payment) XXX_Marshal ¶ added in v0.12.0
func (*Payment) XXX_Unmarshal ¶ added in v0.12.0
type PaymentChannel ¶
type PaymentChannel struct { // Sender is the source that the founds are allocated from (weave.Address). Src []byte `protobuf:"bytes,1,opt,name=src,proto3" json:"src,omitempty"` // Sender public key is a key that must be used to verify signature of // transfer message. Sender creates signed transfer messages and gives them // to the recipient. Signature prevents from altering transfer message. SenderPubkey *crypto.PublicKey `protobuf:"bytes,2,opt,name=sender_pubkey,json=senderPubkey,proto3" json:"sender_pubkey,omitempty"` // Recipient is the party that receives payments through this channel // (weave.Address). Recipient []byte `protobuf:"bytes,3,opt,name=recipient,proto3" json:"recipient,omitempty"` // Total represents a maximum value that can be transferred via this // payment channel. Total *coin.Coin `protobuf:"bytes,4,opt,name=total,proto3" json:"total,omitempty"` // Absolute block height value. If reached, channel can be closed by // sender. Timeout int64 `protobuf:"varint,5,opt,name=timeout,proto3" json:"timeout,omitempty"` // Max length 128 character. Memo string `protobuf:"bytes,6,opt,name=memo,proto3" json:"memo,omitempty"` // Transferred represents total amount that was transferred using allocated // (total) value. Transferred must never exceed total value. Transferred *coin.Coin `protobuf:"bytes,7,opt,name=transferred,proto3" json:"transferred,omitempty"` }
PaymentChannel holds the state of a payment channel during its lifetime.
func (PaymentChannel) Copy ¶
func (pc PaymentChannel) Copy() orm.CloneableData
Copy returns a shallow copy of this PaymentChannel.
func (*PaymentChannel) Descriptor ¶
func (*PaymentChannel) Descriptor() ([]byte, []int)
func (*PaymentChannel) GetMemo ¶
func (m *PaymentChannel) GetMemo() string
func (*PaymentChannel) GetRecipient ¶
func (m *PaymentChannel) GetRecipient() []byte
func (*PaymentChannel) GetSenderPubkey ¶
func (m *PaymentChannel) GetSenderPubkey() *crypto.PublicKey
func (*PaymentChannel) GetSrc ¶
func (m *PaymentChannel) GetSrc() []byte
func (*PaymentChannel) GetTimeout ¶
func (m *PaymentChannel) GetTimeout() int64
func (*PaymentChannel) GetTotal ¶
func (m *PaymentChannel) GetTotal() *coin.Coin
func (*PaymentChannel) GetTransferred ¶
func (m *PaymentChannel) GetTransferred() *coin.Coin
func (*PaymentChannel) Marshal ¶
func (m *PaymentChannel) Marshal() (dAtA []byte, err error)
func (*PaymentChannel) ProtoMessage ¶
func (*PaymentChannel) ProtoMessage()
func (*PaymentChannel) Reset ¶
func (m *PaymentChannel) Reset()
func (*PaymentChannel) Size ¶
func (m *PaymentChannel) Size() (n int)
func (*PaymentChannel) String ¶
func (m *PaymentChannel) String() string
func (*PaymentChannel) Unmarshal ¶
func (m *PaymentChannel) Unmarshal(dAtA []byte) error
func (*PaymentChannel) Validate ¶
func (pc *PaymentChannel) Validate() error
Validate ensures the payment channel is valid.
func (*PaymentChannel) XXX_DiscardUnknown ¶ added in v0.12.0
func (m *PaymentChannel) XXX_DiscardUnknown()
func (*PaymentChannel) XXX_Marshal ¶ added in v0.12.0
func (m *PaymentChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*PaymentChannel) XXX_Merge ¶ added in v0.12.0
func (m *PaymentChannel) XXX_Merge(src proto.Message)
func (*PaymentChannel) XXX_Size ¶ added in v0.12.0
func (m *PaymentChannel) XXX_Size() int
func (*PaymentChannel) XXX_Unmarshal ¶ added in v0.12.0
func (m *PaymentChannel) XXX_Unmarshal(b []byte) error
type PaymentChannelBucket ¶
PaymentChannelBucket is a wrapper over orm.Bucket that ensures that only PaymentChannel entities can be persisted.
func NewPaymentChannelBucket ¶
func NewPaymentChannelBucket() PaymentChannelBucket
NewPaymentChannelBucket returns a bucket for storing PaymentChannel state.
func (*PaymentChannelBucket) Create ¶
func (b *PaymentChannelBucket) Create(db weave.KVStore, pc *PaymentChannel) (orm.Object, error)
Create adds given payment store entity to the store and returns the ID of the newly inserted entity.
func (*PaymentChannelBucket) GetPaymentChannel ¶
func (b *PaymentChannelBucket) GetPaymentChannel(db weave.KVStore, paymentChannelID []byte) (*PaymentChannel, error)
GetPaymentChannel returns a payment channel instance with given ID or returns an error.
type TransferPaymentChannelMsg ¶
type TransferPaymentChannelMsg struct { Payment *Payment `protobuf:"bytes,1,opt,name=payment,proto3" json:"payment,omitempty"` Signature *crypto.Signature `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` }
TransferPaymentChannelMsg binds Payment with a signature created using senders private key. Signature is there to ensure that payment message was not altered.
func (*TransferPaymentChannelMsg) Descriptor ¶
func (*TransferPaymentChannelMsg) Descriptor() ([]byte, []int)
func (*TransferPaymentChannelMsg) GetPayment ¶
func (m *TransferPaymentChannelMsg) GetPayment() *Payment
func (*TransferPaymentChannelMsg) GetSignature ¶
func (m *TransferPaymentChannelMsg) GetSignature() *crypto.Signature
func (*TransferPaymentChannelMsg) Marshal ¶
func (m *TransferPaymentChannelMsg) Marshal() (dAtA []byte, err error)
func (*TransferPaymentChannelMsg) MarshalTo ¶
func (m *TransferPaymentChannelMsg) MarshalTo(dAtA []byte) (int, error)
func (TransferPaymentChannelMsg) Path ¶
func (TransferPaymentChannelMsg) Path() string
func (*TransferPaymentChannelMsg) ProtoMessage ¶
func (*TransferPaymentChannelMsg) ProtoMessage()
func (*TransferPaymentChannelMsg) Reset ¶
func (m *TransferPaymentChannelMsg) Reset()
func (*TransferPaymentChannelMsg) Size ¶
func (m *TransferPaymentChannelMsg) Size() (n int)
func (*TransferPaymentChannelMsg) String ¶
func (m *TransferPaymentChannelMsg) String() string
func (*TransferPaymentChannelMsg) Unmarshal ¶
func (m *TransferPaymentChannelMsg) Unmarshal(dAtA []byte) error
func (*TransferPaymentChannelMsg) Validate ¶
func (m *TransferPaymentChannelMsg) Validate() error
func (*TransferPaymentChannelMsg) XXX_DiscardUnknown ¶ added in v0.12.0
func (m *TransferPaymentChannelMsg) XXX_DiscardUnknown()
func (*TransferPaymentChannelMsg) XXX_Marshal ¶ added in v0.12.0
func (m *TransferPaymentChannelMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*TransferPaymentChannelMsg) XXX_Merge ¶ added in v0.12.0
func (m *TransferPaymentChannelMsg) XXX_Merge(src proto.Message)
func (*TransferPaymentChannelMsg) XXX_Size ¶ added in v0.12.0
func (m *TransferPaymentChannelMsg) XXX_Size() int
func (*TransferPaymentChannelMsg) XXX_Unmarshal ¶ added in v0.12.0
func (m *TransferPaymentChannelMsg) XXX_Unmarshal(b []byte) error