paychan

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: Apache-2.0 Imports: 13 Imported by: 1

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 destination 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 destination when claiming received funds or by the payment channel owner after the deadline was reached.

Index

Constants

This section is empty.

Variables

View Source
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 source account.

Destination account can close channel at any moment.

Source can close channel only if the timeout was reached.

func (*CloseMsg) Descriptor added in v0.17.0

func (*CloseMsg) Descriptor() ([]byte, []int)

func (*CloseMsg) GetChannelID added in v0.17.0

func (m *CloseMsg) GetChannelID() []byte

func (*CloseMsg) GetMemo added in v0.17.0

func (m *CloseMsg) GetMemo() string

func (*CloseMsg) GetMetadata added in v0.17.0

func (m *CloseMsg) GetMetadata() *weave.Metadata

func (*CloseMsg) Marshal added in v0.17.0

func (m *CloseMsg) Marshal() (dAtA []byte, err error)

func (*CloseMsg) MarshalTo added in v0.17.0

func (m *CloseMsg) MarshalTo(dAtA []byte) (int, error)

func (CloseMsg) Path added in v0.17.0

func (CloseMsg) Path() string

func (*CloseMsg) ProtoMessage added in v0.17.0

func (*CloseMsg) ProtoMessage()

func (*CloseMsg) Reset added in v0.17.0

func (m *CloseMsg) Reset()

func (*CloseMsg) Size added in v0.17.0

func (m *CloseMsg) Size() (n int)

func (*CloseMsg) String added in v0.17.0

func (m *CloseMsg) String() string

func (*CloseMsg) Unmarshal added in v0.17.0

func (m *CloseMsg) Unmarshal(dAtA []byte) error

func (*CloseMsg) Validate added in v0.17.0

func (m *CloseMsg) Validate() error

func (*CloseMsg) XXX_DiscardUnknown added in v0.17.0

func (m *CloseMsg) XXX_DiscardUnknown()

func (*CloseMsg) XXX_Marshal added in v0.17.0

func (m *CloseMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CloseMsg) XXX_Merge added in v0.17.0

func (m *CloseMsg) XXX_Merge(src proto.Message)

func (*CloseMsg) XXX_Size added in v0.17.0

func (m *CloseMsg) XXX_Size() int

func (*CloseMsg) XXX_Unmarshal added in v0.17.0

func (m *CloseMsg) XXX_Unmarshal(b []byte) error

type CreateMsg added in v0.17.0

type CreateMsg struct {
	Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	// Source address (weave.Address).
	Source github_com_iov_one_weave.Address `protobuf:"bytes,2,opt,name=source,proto3,casttype=github.com/iov-one/weave.Address" json:"source,omitempty"`
	// Source public key is for validating transfer message signature.
	SourcePubkey *crypto.PublicKey `protobuf:"bytes,3,opt,name=source_pubkey,json=sourcePubkey,proto3" json:"source_pubkey,omitempty"`
	// Destination address  (weave.Address).
	Destination github_com_iov_one_weave.Address `protobuf:"bytes,4,opt,name=destination,proto3,casttype=github.com/iov-one/weave.Address" json:"destination,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 sources account and allocated for user in the transactions done via created payment channel.

func (*CreateMsg) Descriptor added in v0.17.0

func (*CreateMsg) Descriptor() ([]byte, []int)

func (*CreateMsg) GetDestination added in v0.18.0

func (m *CreateMsg) GetDestination() github_com_iov_one_weave.Address

func (*CreateMsg) GetMemo added in v0.17.0

func (m *CreateMsg) GetMemo() string

func (*CreateMsg) GetMetadata added in v0.17.0

func (m *CreateMsg) GetMetadata() *weave.Metadata

func (*CreateMsg) GetSource added in v0.18.0

func (*CreateMsg) GetSourcePubkey added in v0.18.0

func (m *CreateMsg) GetSourcePubkey() *crypto.PublicKey

func (*CreateMsg) GetTimeout added in v0.17.0

func (*CreateMsg) GetTotal added in v0.17.0

func (m *CreateMsg) GetTotal() *coin.Coin

func (*CreateMsg) Marshal added in v0.17.0

func (m *CreateMsg) Marshal() (dAtA []byte, err error)

func (*CreateMsg) MarshalTo added in v0.17.0

func (m *CreateMsg) MarshalTo(dAtA []byte) (int, error)

func (CreateMsg) Path added in v0.17.0

func (CreateMsg) Path() string

func (*CreateMsg) ProtoMessage added in v0.17.0

func (*CreateMsg) ProtoMessage()

func (*CreateMsg) Reset added in v0.17.0

func (m *CreateMsg) Reset()

func (*CreateMsg) Size added in v0.17.0

func (m *CreateMsg) Size() (n int)

func (*CreateMsg) String added in v0.17.0

func (m *CreateMsg) String() string

func (*CreateMsg) Unmarshal added in v0.17.0

func (m *CreateMsg) Unmarshal(dAtA []byte) error

func (*CreateMsg) Validate added in v0.17.0

func (m *CreateMsg) Validate() error

func (*CreateMsg) XXX_DiscardUnknown added in v0.17.0

func (m *CreateMsg) XXX_DiscardUnknown()

func (*CreateMsg) XXX_Marshal added in v0.17.0

func (m *CreateMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CreateMsg) XXX_Merge added in v0.17.0

func (m *CreateMsg) XXX_Merge(src proto.Message)

func (*CreateMsg) XXX_Size added in v0.17.0

func (m *CreateMsg) XXX_Size() int

func (*CreateMsg) XXX_Unmarshal added in v0.17.0

func (m *CreateMsg) 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 source. Source should give the message to the destination, 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) Descriptor() ([]byte, []int)

func (*Payment) GetAmount

func (m *Payment) GetAmount() *coin.Coin

func (*Payment) GetChainID added in v0.10.0

func (m *Payment) GetChainID() string

func (*Payment) GetChannelID added in v0.10.0

func (m *Payment) GetChannelID() []byte

func (*Payment) GetMemo

func (m *Payment) GetMemo() string

func (*Payment) Marshal

func (m *Payment) Marshal() (dAtA []byte, err error)

func (*Payment) MarshalTo

func (m *Payment) MarshalTo(dAtA []byte) (int, error)

func (*Payment) ProtoMessage

func (*Payment) ProtoMessage()

func (*Payment) Reset

func (m *Payment) Reset()

func (*Payment) Size

func (m *Payment) Size() (n int)

func (*Payment) String

func (m *Payment) String() string

func (*Payment) Unmarshal

func (m *Payment) Unmarshal(dAtA []byte) error

func (*Payment) XXX_DiscardUnknown added in v0.12.0

func (m *Payment) XXX_DiscardUnknown()

func (*Payment) XXX_Marshal added in v0.12.0

func (m *Payment) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Payment) XXX_Merge added in v0.12.0

func (m *Payment) XXX_Merge(src proto.Message)

func (*Payment) XXX_Size added in v0.12.0

func (m *Payment) XXX_Size() int

func (*Payment) XXX_Unmarshal added in v0.12.0

func (m *Payment) XXX_Unmarshal(b []byte) error

type PaymentChannel

type PaymentChannel struct {
	Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	// Source is the source that the founds are allocated from.
	Source github_com_iov_one_weave.Address `protobuf:"bytes,2,opt,name=source,proto3,casttype=github.com/iov-one/weave.Address" json:"source,omitempty"`
	// Source public key is a key that must be used to verify signature of
	// transfer message. Source creates signed transfer messages and gives them
	// to the destination. Signature prevents from altering transfer message.
	SourcePubkey *crypto.PublicKey `protobuf:"bytes,3,opt,name=source_pubkey,json=sourcePubkey,proto3" json:"source_pubkey,omitempty"`
	// Destination is the party that receives payments through this channel
	Destination github_com_iov_one_weave.Address `protobuf:"bytes,4,opt,name=destination,proto3,casttype=github.com/iov-one/weave.Address" json:"destination,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"`
	// Address of this entity. Set during creation and does not change.
	Address github_com_iov_one_weave.Address `protobuf:"bytes,9,opt,name=address,proto3,casttype=github.com/iov-one/weave.Address" json:"address,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) GetAddress added in v0.19.0

func (*PaymentChannel) GetDestination added in v0.18.0

func (m *PaymentChannel) GetDestination() github_com_iov_one_weave.Address

func (*PaymentChannel) GetMemo

func (m *PaymentChannel) GetMemo() string

func (*PaymentChannel) GetMetadata added in v0.15.0

func (m *PaymentChannel) GetMetadata() *weave.Metadata

func (*PaymentChannel) GetSource added in v0.18.0

func (*PaymentChannel) GetSourcePubkey added in v0.18.0

func (m *PaymentChannel) GetSourcePubkey() *crypto.PublicKey

func (*PaymentChannel) GetTimeout

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) MarshalTo

func (m *PaymentChannel) MarshalTo(dAtA []byte) (int, 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 sources 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

Jump to

Keyboard shortcuts

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