paychan

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

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

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 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) 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) 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) 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 {
	// 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) 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 PaymentChannelBucket

type PaymentChannelBucket struct {
	orm.Bucket
	// contains filtered or unexported fields
}

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

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.

func (*PaymentChannelBucket) Save

func (b *PaymentChannelBucket) Save(db weave.KVStore, obj orm.Object) error

Save updates the state of given PaymentChannel entity in the store.

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

Jump to

Keyboard shortcuts

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