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 NewPaymentChannelBucket() orm.ModelBucket
- func RegisterQuery(qr weave.QueryRouter)
- func RegisterRoutes(r weave.Registry, auth x.Authenticator, cash cash.Controller)
- type CloseMsg
- func (*CloseMsg) Descriptor() ([]byte, []int)
- func (m *CloseMsg) GetChannelID() []byte
- func (m *CloseMsg) GetMemo() string
- func (m *CloseMsg) GetMetadata() *weave.Metadata
- func (m *CloseMsg) Marshal() (dAtA []byte, err error)
- func (m *CloseMsg) MarshalTo(dAtA []byte) (int, error)
- func (CloseMsg) Path() string
- func (*CloseMsg) ProtoMessage()
- func (m *CloseMsg) Reset()
- func (m *CloseMsg) Size() (n int)
- func (m *CloseMsg) String() string
- func (m *CloseMsg) Unmarshal(dAtA []byte) error
- func (m *CloseMsg) Validate() error
- func (m *CloseMsg) XXX_DiscardUnknown()
- func (m *CloseMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *CloseMsg) XXX_Merge(src proto.Message)
- func (m *CloseMsg) XXX_Size() int
- func (m *CloseMsg) XXX_Unmarshal(b []byte) error
- type CreateMsg
- func (*CreateMsg) Descriptor() ([]byte, []int)
- func (m *CreateMsg) GetMemo() string
- func (m *CreateMsg) GetMetadata() *weave.Metadata
- func (m *CreateMsg) GetRecipient() github_com_iov_one_weave.Address
- func (m *CreateMsg) GetSenderPubkey() *crypto.PublicKey
- func (m *CreateMsg) GetSrc() github_com_iov_one_weave.Address
- func (m *CreateMsg) GetTimeout() github_com_iov_one_weave.UnixTime
- func (m *CreateMsg) GetTotal() *coin.Coin
- func (m *CreateMsg) Marshal() (dAtA []byte, err error)
- func (m *CreateMsg) MarshalTo(dAtA []byte) (int, error)
- func (CreateMsg) Path() string
- func (*CreateMsg) ProtoMessage()
- func (m *CreateMsg) Reset()
- func (m *CreateMsg) Size() (n int)
- func (m *CreateMsg) String() string
- func (m *CreateMsg) Unmarshal(dAtA []byte) error
- func (m *CreateMsg) Validate() error
- func (m *CreateMsg) XXX_DiscardUnknown()
- func (m *CreateMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *CreateMsg) XXX_Merge(src proto.Message)
- func (m *CreateMsg) XXX_Size() int
- func (m *CreateMsg) 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) GetMetadata() *weave.Metadata
- func (m *PaymentChannel) GetRecipient() github_com_iov_one_weave.Address
- func (m *PaymentChannel) GetSenderPubkey() *crypto.PublicKey
- func (m *PaymentChannel) GetSrc() github_com_iov_one_weave.Address
- func (m *PaymentChannel) GetTimeout() github_com_iov_one_weave.UnixTime
- 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 TransferMsg
- func (*TransferMsg) Descriptor() ([]byte, []int)
- func (m *TransferMsg) GetMetadata() *weave.Metadata
- func (m *TransferMsg) GetPayment() *Payment
- func (m *TransferMsg) GetSignature() *crypto.Signature
- func (m *TransferMsg) Marshal() (dAtA []byte, err error)
- func (m *TransferMsg) MarshalTo(dAtA []byte) (int, error)
- func (TransferMsg) Path() string
- func (*TransferMsg) ProtoMessage()
- func (m *TransferMsg) Reset()
- func (m *TransferMsg) Size() (n int)
- func (m *TransferMsg) String() string
- func (m *TransferMsg) Unmarshal(dAtA []byte) error
- func (m *TransferMsg) Validate() error
- func (m *TransferMsg) XXX_DiscardUnknown()
- func (m *TransferMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *TransferMsg) XXX_Merge(src proto.Message)
- func (m *TransferMsg) XXX_Size() int
- func (m *TransferMsg) 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 NewPaymentChannelBucket ¶
func NewPaymentChannelBucket() orm.ModelBucket
NewPaymentChannelBucket returns a bucket for storing PaymentChannel state.
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 CloseMsg ¶ added in v0.17.0
type CloseMsg struct { Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` ChannelID []byte `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` // Max length 128 character. Memo string `protobuf:"bytes,3,opt,name=memo,proto3" json:"memo,omitempty"` }
CloseMsg 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 was reached.
func (*CloseMsg) Descriptor ¶ added in v0.17.0
func (*CloseMsg) GetChannelID ¶ added in v0.17.0
func (*CloseMsg) GetMetadata ¶ added in v0.17.0
func (*CloseMsg) ProtoMessage ¶ added in v0.17.0
func (*CloseMsg) ProtoMessage()
func (*CloseMsg) XXX_DiscardUnknown ¶ added in v0.17.0
func (m *CloseMsg) XXX_DiscardUnknown()
func (*CloseMsg) XXX_Marshal ¶ added in v0.17.0
func (*CloseMsg) XXX_Unmarshal ¶ added in v0.17.0
type CreateMsg ¶ added in v0.17.0
type CreateMsg struct { Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` // Sender address (weave.Address). Src github_com_iov_one_weave.Address `protobuf:"bytes,2,opt,name=src,proto3,casttype=github.com/iov-one/weave.Address" json:"src,omitempty"` // Sender public key is for validating transfer message signature. SenderPubkey *crypto.PublicKey `protobuf:"bytes,3,opt,name=sender_pubkey,json=senderPubkey,proto3" json:"sender_pubkey,omitempty"` // Recipient address (weave.Address). Recipient github_com_iov_one_weave.Address `protobuf:"bytes,4,opt,name=recipient,proto3,casttype=github.com/iov-one/weave.Address" json:"recipient,omitempty"` // Maximum amount that can be transferred via this channel. Total *coin.Coin `protobuf:"bytes,5,opt,name=total,proto3" json:"total,omitempty"` // If reached, channel can be closed by anyone. Timeout github_com_iov_one_weave.UnixTime `protobuf:"varint,6,opt,name=timeout,proto3,casttype=github.com/iov-one/weave.UnixTime" json:"timeout,omitempty"` // Max length 128 character. Memo string `protobuf:"bytes,7,opt,name=memo,proto3" json:"memo,omitempty"` }
CreateMsg 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 (*CreateMsg) Descriptor ¶ added in v0.17.0
func (*CreateMsg) GetMetadata ¶ added in v0.17.0
func (*CreateMsg) GetRecipient ¶ added in v0.17.0
func (m *CreateMsg) GetRecipient() github_com_iov_one_weave.Address
func (*CreateMsg) GetSenderPubkey ¶ added in v0.17.0
func (*CreateMsg) GetSrc ¶ added in v0.17.0
func (m *CreateMsg) GetSrc() github_com_iov_one_weave.Address
func (*CreateMsg) GetTimeout ¶ added in v0.17.0
func (m *CreateMsg) GetTimeout() github_com_iov_one_weave.UnixTime
func (*CreateMsg) ProtoMessage ¶ added in v0.17.0
func (*CreateMsg) ProtoMessage()
func (*CreateMsg) XXX_DiscardUnknown ¶ added in v0.17.0
func (m *CreateMsg) XXX_DiscardUnknown()
func (*CreateMsg) XXX_Marshal ¶ added in v0.17.0
func (*CreateMsg) XXX_Unmarshal ¶ added in v0.17.0
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 { Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` // Sender is the source that the founds are allocated from. Src github_com_iov_one_weave.Address `protobuf:"bytes,2,opt,name=src,proto3,casttype=github.com/iov-one/weave.Address" 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,3,opt,name=sender_pubkey,json=senderPubkey,proto3" json:"sender_pubkey,omitempty"` // Recipient is the party that receives payments through this channel Recipient github_com_iov_one_weave.Address `protobuf:"bytes,4,opt,name=recipient,proto3,casttype=github.com/iov-one/weave.Address" json:"recipient,omitempty"` // Total represents a maximum value that can be transferred via this // payment channel. Total *coin.Coin `protobuf:"bytes,5,opt,name=total,proto3" json:"total,omitempty"` // Timeout represents wall clock time as read from the block header. Timeout // is represented using POSIX time format. // Expiration time is inclusive meaning that the paychan expires as soon as // the current time is equal or greater than timeout value. // nonexpired: [created, timeout) // expired: [timeout, infinity) Timeout github_com_iov_one_weave.UnixTime `protobuf:"varint,6,opt,name=timeout,proto3,casttype=github.com/iov-one/weave.UnixTime" json:"timeout,omitempty"` // Max length 128 character. Memo string `protobuf:"bytes,7,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,8,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 deep copy of this PaymentChannel.
func (*PaymentChannel) Descriptor ¶
func (*PaymentChannel) Descriptor() ([]byte, []int)
func (*PaymentChannel) GetMemo ¶
func (m *PaymentChannel) GetMemo() string
func (*PaymentChannel) GetMetadata ¶ added in v0.15.0
func (m *PaymentChannel) GetMetadata() *weave.Metadata
func (*PaymentChannel) GetRecipient ¶
func (m *PaymentChannel) GetRecipient() github_com_iov_one_weave.Address
func (*PaymentChannel) GetSenderPubkey ¶
func (m *PaymentChannel) GetSenderPubkey() *crypto.PublicKey
func (*PaymentChannel) GetSrc ¶
func (m *PaymentChannel) GetSrc() github_com_iov_one_weave.Address
func (*PaymentChannel) GetTimeout ¶
func (m *PaymentChannel) GetTimeout() github_com_iov_one_weave.UnixTime
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 TransferMsg ¶ added in v0.17.0
type TransferMsg struct { Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` Payment *Payment `protobuf:"bytes,2,opt,name=payment,proto3" json:"payment,omitempty"` Signature *crypto.Signature `protobuf:"bytes,3,opt,name=signature,proto3" json:"signature,omitempty"` }
TransferMsg binds Payment with a signature created using senders private key. Signature is there to ensure that payment message was not altered.
func (*TransferMsg) Descriptor ¶ added in v0.17.0
func (*TransferMsg) Descriptor() ([]byte, []int)
func (*TransferMsg) GetMetadata ¶ added in v0.17.0
func (m *TransferMsg) GetMetadata() *weave.Metadata
func (*TransferMsg) GetPayment ¶ added in v0.17.0
func (m *TransferMsg) GetPayment() *Payment
func (*TransferMsg) GetSignature ¶ added in v0.17.0
func (m *TransferMsg) GetSignature() *crypto.Signature
func (*TransferMsg) Marshal ¶ added in v0.17.0
func (m *TransferMsg) Marshal() (dAtA []byte, err error)
func (*TransferMsg) MarshalTo ¶ added in v0.17.0
func (m *TransferMsg) MarshalTo(dAtA []byte) (int, error)
func (TransferMsg) Path ¶ added in v0.17.0
func (TransferMsg) Path() string
func (*TransferMsg) ProtoMessage ¶ added in v0.17.0
func (*TransferMsg) ProtoMessage()
func (*TransferMsg) Reset ¶ added in v0.17.0
func (m *TransferMsg) Reset()
func (*TransferMsg) Size ¶ added in v0.17.0
func (m *TransferMsg) Size() (n int)
func (*TransferMsg) String ¶ added in v0.17.0
func (m *TransferMsg) String() string
func (*TransferMsg) Unmarshal ¶ added in v0.17.0
func (m *TransferMsg) Unmarshal(dAtA []byte) error
func (*TransferMsg) Validate ¶ added in v0.17.0
func (m *TransferMsg) Validate() error
func (*TransferMsg) XXX_DiscardUnknown ¶ added in v0.17.0
func (m *TransferMsg) XXX_DiscardUnknown()
func (*TransferMsg) XXX_Marshal ¶ added in v0.17.0
func (m *TransferMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*TransferMsg) XXX_Merge ¶ added in v0.17.0
func (m *TransferMsg) XXX_Merge(src proto.Message)
func (*TransferMsg) XXX_Size ¶ added in v0.17.0
func (m *TransferMsg) XXX_Size() int
func (*TransferMsg) XXX_Unmarshal ¶ added in v0.17.0
func (m *TransferMsg) XXX_Unmarshal(b []byte) error