escrow

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 escrow implements an Escrow.

> An escrow is a financial arrangement where a third party holds and regulates > payment of the funds required for two parties involved in a given transaction. > It helps make transactions more secure by keeping the payment in a secure > escrow account which is only released when all of the terms of an agreement are > met as overseen by the escrow company.

Escrow holds some coins. The arbiter or sender can release them to the recipient. The recipient can return them to the sender. Upon timeout, they will be returned to the sender.

Index

Constants

View Source
const (
	// BucketName is where we store the escrows
	BucketName = "esc"
	// SequenceName is an auto-increment ID counter for escrows
	SequenceName = "id"
)

Variables

View Source
var (
	ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowCodec   = fmt.Errorf("proto: integer overflow")
)

Functions

func Condition

func Condition(key []byte) weave.Condition

Condition calculates the address of an escrow given the key

func NewEscrow

func NewEscrow(
	id []byte,
	sender weave.Address,
	recipient weave.Address,
	arbiter weave.Condition,
	amount coin.Coins,
	timeout weave.UnixTime,
	memo string,
) orm.Object

NewEscrow creates an escrow orm.Object

func RegisterQuery

func RegisterQuery(qr weave.QueryRouter)

RegisterQuery will register this bucket as "/escrows"

func RegisterRoutes

func RegisterRoutes(r weave.Registry, auth x.Authenticator, cashctrl cash.Controller)

RegisterRoutes will instantiate and register all handlers in this package

Types

type Bucket

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

Bucket is a type-safe wrapper around orm.Bucket

func NewBucket

func NewBucket() Bucket

NewBucket initializes a Bucket with default name

inherit Get and Save from orm.Bucket add Create

func (Bucket) Build added in v0.10.0

func (b Bucket) Build(db weave.KVStore, escrow *Escrow) orm.Object

Build assigns an ID to given escrow instance and returns it as an orm Object. It does not persist the escrow in the store.

func (Bucket) Save

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

Save enforces the proper type

type CreateEscrowHandler

type CreateEscrowHandler struct {
	// contains filtered or unexported fields
}

CreateEscrowHandler will set a name for objects in this bucket

func (CreateEscrowHandler) Check

Check just verifies it is properly formed and returns the cost of executing it.

func (CreateEscrowHandler) Deliver

Deliver moves the tokens from sender to the escrow account if all preconditions are met.

type CreateEscrowMsg

type CreateEscrowMsg struct {
	// Sender, Arbiter, Recipient are all weave.Permission
	Src       []byte `protobuf:"bytes,1,opt,name=src,proto3" json:"src,omitempty"`
	Arbiter   []byte `protobuf:"bytes,2,opt,name=arbiter,proto3" json:"arbiter,omitempty"`
	Recipient []byte `protobuf:"bytes,3,opt,name=recipient,proto3" json:"recipient,omitempty"`
	// amount may contain multiple token types
	Amount []*coin.Coin `protobuf:"bytes,4,rep,name=amount,proto3" json:"amount,omitempty"`
	// Timeout represents wall clock time.
	Timeout github_com_iov_one_weave.UnixTime `protobuf:"varint,5,opt,name=timeout,proto3,casttype=github.com/iov-one/weave.UnixTime" json:"timeout,omitempty"`
	// max length 128 character
	Memo string `protobuf:"bytes,6,opt,name=memo,proto3" json:"memo,omitempty"`
}

CreateEscrowMsg is a request to create an Escrow with some tokens. If sender is not defined, it defaults to the first signer The rest must be defined

func NewCreateMsg

func NewCreateMsg(
	sender weave.Address,
	recipient weave.Address,
	arbiter weave.Condition,
	amount coin.Coins,
	timeout weave.UnixTime,
	memo string,
) *CreateEscrowMsg

NewCreateMsg is a helper to quickly build a create escrow message

func (*CreateEscrowMsg) Descriptor

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

func (*CreateEscrowMsg) GetAmount

func (m *CreateEscrowMsg) GetAmount() []*coin.Coin

func (*CreateEscrowMsg) GetArbiter

func (m *CreateEscrowMsg) GetArbiter() []byte

func (*CreateEscrowMsg) GetMemo

func (m *CreateEscrowMsg) GetMemo() string

func (*CreateEscrowMsg) GetRecipient

func (m *CreateEscrowMsg) GetRecipient() []byte

func (*CreateEscrowMsg) GetSrc added in v0.9.0

func (m *CreateEscrowMsg) GetSrc() []byte

func (*CreateEscrowMsg) GetTimeout

func (*CreateEscrowMsg) Marshal

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

func (*CreateEscrowMsg) MarshalTo

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

func (CreateEscrowMsg) Path

func (CreateEscrowMsg) Path() string

Path fulfills weave.Msg interface to allow routing

func (*CreateEscrowMsg) ProtoMessage

func (*CreateEscrowMsg) ProtoMessage()

func (*CreateEscrowMsg) Reset

func (m *CreateEscrowMsg) Reset()

func (*CreateEscrowMsg) Size

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

func (*CreateEscrowMsg) String

func (m *CreateEscrowMsg) String() string

func (*CreateEscrowMsg) Unmarshal

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

func (*CreateEscrowMsg) Validate

func (m *CreateEscrowMsg) Validate() error

Validate makes sure that this is sensible

func (*CreateEscrowMsg) XXX_DiscardUnknown added in v0.12.0

func (m *CreateEscrowMsg) XXX_DiscardUnknown()

func (*CreateEscrowMsg) XXX_Marshal added in v0.12.0

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

func (*CreateEscrowMsg) XXX_Merge added in v0.12.0

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

func (*CreateEscrowMsg) XXX_Size added in v0.12.0

func (m *CreateEscrowMsg) XXX_Size() int

func (*CreateEscrowMsg) XXX_Unmarshal added in v0.12.0

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

type Escrow

type Escrow struct {
	// Sender, Arbiter, Recipient are all weave.Permission
	Sender    []byte `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"`
	Arbiter   []byte `protobuf:"bytes,2,opt,name=arbiter,proto3" json:"arbiter,omitempty"`
	Recipient []byte `protobuf:"bytes,3,opt,name=recipient,proto3" json:"recipient,omitempty"`
	// If unreleased before timeout, escrow will return to sender.
	// 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 escrow 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,5,opt,name=timeout,proto3,casttype=github.com/iov-one/weave.UnixTime" json:"timeout,omitempty"`
	// max length 128 character
	Memo string `protobuf:"bytes,6,opt,name=memo,proto3" json:"memo,omitempty"`
}

Escrow holds some coins. The arbiter or sender can release them to the recipient. The recipient can return them to the sender. Upon timeout, they will be returned to the sender.

Note that if the arbiter is a Hashlock permission, we have an HTLC ;)

func AsEscrow

func AsEscrow(obj orm.Object) *Escrow

AsEscrow extracts an *Escrow value or nil from the object Must be called on a Bucket result that is an *Escrow, will panic on bad type.

func (*Escrow) Copy

func (e *Escrow) Copy() orm.CloneableData

Copy makes a new set with the same coins

func (*Escrow) Descriptor

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

func (*Escrow) GetArbiter

func (m *Escrow) GetArbiter() []byte

func (*Escrow) GetMemo

func (m *Escrow) GetMemo() string

func (*Escrow) GetRecipient

func (m *Escrow) GetRecipient() []byte

func (*Escrow) GetSender

func (m *Escrow) GetSender() []byte

func (*Escrow) GetTimeout

func (m *Escrow) GetTimeout() github_com_iov_one_weave.UnixTime

func (*Escrow) Marshal

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

func (*Escrow) MarshalTo

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

func (*Escrow) ProtoMessage

func (*Escrow) ProtoMessage()

func (*Escrow) Reset

func (m *Escrow) Reset()

func (*Escrow) Size

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

func (*Escrow) String

func (m *Escrow) String() string

func (*Escrow) Unmarshal

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

func (*Escrow) Validate

func (e *Escrow) Validate() error

Validate ensures the escrow is valid

func (*Escrow) XXX_DiscardUnknown added in v0.12.0

func (m *Escrow) XXX_DiscardUnknown()

func (*Escrow) XXX_Marshal added in v0.12.0

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

func (*Escrow) XXX_Merge added in v0.12.0

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

func (*Escrow) XXX_Size added in v0.12.0

func (m *Escrow) XXX_Size() int

func (*Escrow) XXX_Unmarshal added in v0.12.0

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

type Initializer added in v0.12.0

type Initializer struct {
	Minter cash.CoinMinter
}

Initializer fulfils the Initializer interface to load data from the genesis file

func (*Initializer) FromGenesis added in v0.12.0

func (i *Initializer) FromGenesis(opts weave.Options, db weave.KVStore) error

FromGenesis will parse initial escrow info from genesis and save it in the database.

type ReleaseEscrowHandler

type ReleaseEscrowHandler struct {
	// contains filtered or unexported fields
}

ReleaseEscrowHandler will set a name for objects in this bucket.

func (ReleaseEscrowHandler) Check

Check just verifies it is properly formed and returns the cost of executing it

func (ReleaseEscrowHandler) Deliver

Deliver moves the tokens from escrow account to the receiver if all preconditions are met. When the escrow account is empty it is deleted.

type ReleaseEscrowMsg

type ReleaseEscrowMsg struct {
	EscrowId []byte       `protobuf:"bytes,1,opt,name=escrow_id,json=escrowId,proto3" json:"escrow_id,omitempty"`
	Amount   []*coin.Coin `protobuf:"bytes,2,rep,name=amount,proto3" json:"amount,omitempty"`
}

ReleaseEscrowMsg releases the content to the recipient. Must be authorized by sender or arbiter. If amount not provided, defaults to entire escrow, May be a subset of the current balance.

func (*ReleaseEscrowMsg) Descriptor

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

func (*ReleaseEscrowMsg) GetAmount

func (m *ReleaseEscrowMsg) GetAmount() []*coin.Coin

func (*ReleaseEscrowMsg) GetEscrowId

func (m *ReleaseEscrowMsg) GetEscrowId() []byte

func (*ReleaseEscrowMsg) Marshal

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

func (*ReleaseEscrowMsg) MarshalTo

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

func (ReleaseEscrowMsg) Path

func (ReleaseEscrowMsg) Path() string

Path fulfills weave.Msg interface to allow routing

func (*ReleaseEscrowMsg) ProtoMessage

func (*ReleaseEscrowMsg) ProtoMessage()

func (*ReleaseEscrowMsg) Reset

func (m *ReleaseEscrowMsg) Reset()

func (*ReleaseEscrowMsg) Size

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

func (*ReleaseEscrowMsg) String

func (m *ReleaseEscrowMsg) String() string

func (*ReleaseEscrowMsg) Unmarshal

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

func (*ReleaseEscrowMsg) Validate

func (m *ReleaseEscrowMsg) Validate() error

Validate makes sure that this is sensible

func (*ReleaseEscrowMsg) XXX_DiscardUnknown added in v0.12.0

func (m *ReleaseEscrowMsg) XXX_DiscardUnknown()

func (*ReleaseEscrowMsg) XXX_Marshal added in v0.12.0

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

func (*ReleaseEscrowMsg) XXX_Merge added in v0.12.0

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

func (*ReleaseEscrowMsg) XXX_Size added in v0.12.0

func (m *ReleaseEscrowMsg) XXX_Size() int

func (*ReleaseEscrowMsg) XXX_Unmarshal added in v0.12.0

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

type ReturnEscrowHandler

type ReturnEscrowHandler struct {
	// contains filtered or unexported fields
}

ReturnEscrowHandler will set a name for objects in this bucket

func (ReturnEscrowHandler) Check

Check just verifies it is properly formed and returns the cost of executing it.

func (ReturnEscrowHandler) Deliver

Deliver moves all the tokens from the escrow to the defined sender if all preconditions are met. The escrow is deleted afterwards.

type ReturnEscrowMsg

type ReturnEscrowMsg struct {
	EscrowId []byte `protobuf:"bytes,1,opt,name=escrow_id,json=escrowId,proto3" json:"escrow_id,omitempty"`
}

ReturnEscrowMsg returns the content to the sender. Must be authorized by the sender or an expired timeout

func (*ReturnEscrowMsg) Descriptor

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

func (*ReturnEscrowMsg) GetEscrowId

func (m *ReturnEscrowMsg) GetEscrowId() []byte

func (*ReturnEscrowMsg) Marshal

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

func (*ReturnEscrowMsg) MarshalTo

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

func (ReturnEscrowMsg) Path

func (ReturnEscrowMsg) Path() string

Path fulfills weave.Msg interface to allow routing

func (*ReturnEscrowMsg) ProtoMessage

func (*ReturnEscrowMsg) ProtoMessage()

func (*ReturnEscrowMsg) Reset

func (m *ReturnEscrowMsg) Reset()

func (*ReturnEscrowMsg) Size

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

func (*ReturnEscrowMsg) String

func (m *ReturnEscrowMsg) String() string

func (*ReturnEscrowMsg) Unmarshal

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

func (*ReturnEscrowMsg) Validate

func (m *ReturnEscrowMsg) Validate() error

Validate always returns true for no data

func (*ReturnEscrowMsg) XXX_DiscardUnknown added in v0.12.0

func (m *ReturnEscrowMsg) XXX_DiscardUnknown()

func (*ReturnEscrowMsg) XXX_Marshal added in v0.12.0

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

func (*ReturnEscrowMsg) XXX_Merge added in v0.12.0

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

func (*ReturnEscrowMsg) XXX_Size added in v0.12.0

func (m *ReturnEscrowMsg) XXX_Size() int

func (*ReturnEscrowMsg) XXX_Unmarshal added in v0.12.0

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

type UpdateEscrowHandler

type UpdateEscrowHandler struct {
	// contains filtered or unexported fields
}

UpdateEscrowHandler will set a name for objects in this bucket.

func (UpdateEscrowHandler) Check

Check just verifies it is properly formed and returns the cost of executing it.

func (UpdateEscrowHandler) Deliver

Deliver updates the any of the sender, recipient or arbiter if all preconditions are met. No coins are moved.

type UpdateEscrowPartiesMsg

type UpdateEscrowPartiesMsg struct {
	EscrowId  []byte `protobuf:"bytes,1,opt,name=escrow_id,json=escrowId,proto3" json:"escrow_id,omitempty"`
	Sender    []byte `protobuf:"bytes,2,opt,name=sender,proto3" json:"sender,omitempty"`
	Arbiter   []byte `protobuf:"bytes,3,opt,name=arbiter,proto3" json:"arbiter,omitempty"`
	Recipient []byte `protobuf:"bytes,4,opt,name=recipient,proto3" json:"recipient,omitempty"`
}

UpdateEscrowPartiesMsg changes any of the parties of the escrow: sender, arbiter, recipient. This must be authorized by the current holder of that position (eg. only sender can update sender).

Represents delegating responsibility

func (*UpdateEscrowPartiesMsg) Descriptor

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

func (*UpdateEscrowPartiesMsg) GetArbiter

func (m *UpdateEscrowPartiesMsg) GetArbiter() []byte

func (*UpdateEscrowPartiesMsg) GetEscrowId

func (m *UpdateEscrowPartiesMsg) GetEscrowId() []byte

func (*UpdateEscrowPartiesMsg) GetRecipient

func (m *UpdateEscrowPartiesMsg) GetRecipient() []byte

func (*UpdateEscrowPartiesMsg) GetSender

func (m *UpdateEscrowPartiesMsg) GetSender() []byte

func (*UpdateEscrowPartiesMsg) Marshal

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

func (*UpdateEscrowPartiesMsg) MarshalTo

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

func (UpdateEscrowPartiesMsg) Path

Path fulfills weave.Msg interface to allow routing

func (*UpdateEscrowPartiesMsg) ProtoMessage

func (*UpdateEscrowPartiesMsg) ProtoMessage()

func (*UpdateEscrowPartiesMsg) Reset

func (m *UpdateEscrowPartiesMsg) Reset()

func (*UpdateEscrowPartiesMsg) Size

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

func (*UpdateEscrowPartiesMsg) String

func (m *UpdateEscrowPartiesMsg) String() string

func (*UpdateEscrowPartiesMsg) Unmarshal

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

func (*UpdateEscrowPartiesMsg) Validate

func (m *UpdateEscrowPartiesMsg) Validate() error

Validate makes sure any included items are valid permissions and there is at least one change

func (*UpdateEscrowPartiesMsg) XXX_DiscardUnknown added in v0.12.0

func (m *UpdateEscrowPartiesMsg) XXX_DiscardUnknown()

func (*UpdateEscrowPartiesMsg) XXX_Marshal added in v0.12.0

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

func (*UpdateEscrowPartiesMsg) XXX_Merge added in v0.12.0

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

func (*UpdateEscrowPartiesMsg) XXX_Size added in v0.12.0

func (m *UpdateEscrowPartiesMsg) XXX_Size() int

func (*UpdateEscrowPartiesMsg) XXX_Unmarshal added in v0.12.0

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

Jump to

Keyboard shortcuts

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