cash

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: Apache-2.0 Imports: 9 Imported by: 18

Documentation

Overview

Package cash is a generated protocol buffer package.

It is generated from these files:
	x/cash/codec.proto

It has these top-level messages:
	Set
	SendMsg
	FeeInfo

Package cash defines a simple implementation of sending coins between multi-signature wallets.

There is no logic in the coins (tokens), except that the balance of any coin may not go below zero. Thus, this implementation is referred to as cash. Simple and safe.

In the future, there should be more implementations that support sending and issuing tokens with much more logic inside.

Index

Constants

View Source
const (
	CodeInsufficientFees  uint32 = 32
	CodeInsufficientFunds        = 33
	CodeInvalidAmount            = 34
	CodeInvalidMemo              = 35
	CodeEmptyAccount             = 36
)

ABCI Response Codes x/coins reserves 30 ~ 39.

View Source
const BucketName = "cash"

BucketName is where we store the balances

Variables

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

Functions

func Add

func Add(cng Coinage, c x.Coin) error

Add modifies the coinage to add Coin c

func AsCoins

func AsCoins(obj orm.Object) x.Coins

AsCoins will extract XCoins from any object

func Concat

func Concat(cng Coinage, coins x.Coins) error

Concat combines the coins to make sure they are sorted and rounded off, with no duplicates or 0 values.

func ErrEmptyAccount

func ErrEmptyAccount(addr weave.Address) error

func ErrInsufficientFees

func ErrInsufficientFees(coin x.Coin) error

func ErrInsufficientFunds

func ErrInsufficientFunds() error

func ErrInvalidAmount

func ErrInvalidAmount(reason string) error

func ErrInvalidMemo

func ErrInvalidMemo(reason string) error

func IsEmptyAccountErr

func IsEmptyAccountErr(err error) bool

func IsInsufficientFeesErr

func IsInsufficientFeesErr(err error) bool

func IsInsufficientFundsErr

func IsInsufficientFundsErr(err error) bool

func IsInvalidAmountErr

func IsInvalidAmountErr(err error) bool

func IsInvalidMemoErr

func IsInvalidMemoErr(err error) bool

func NewWallet

func NewWallet(key weave.Address) orm.Object

NewWallet creates an empty wallet with this address serves as an object for the bucket

func RegisterQuery

func RegisterQuery(qr weave.QueryRouter)

RegisterQuery will register this bucket as "/wallets"

func RegisterRoutes

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

RegisterRoutes will instantiate and register all handlers in this package

func Subtract

func Subtract(cng Coinage, c x.Coin) error

Subtract modifies the coinage to remove Coin c

func ValidateWalletBucket

func ValidateWalletBucket(bucket WalletBucket)

ValidateWalletBucket makes sure that it supports AsCoinage objects, unfortunately this check is done runtime....

panics on error (meant as a sanity check in init)

func WalletWith

func WalletWith(key weave.Address, coins ...*x.Coin) (orm.Object, error)

WalletWith creates an wallet with a balance

func XCoins

func XCoins(c Coinage) x.Coins

XCoins returns the stored coins cast properly

Types

type BaseController

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

BaseController is a simple implementation of controller wallet must return something that supports AsSet

func NewController

func NewController(bucket WalletBucket) BaseController

NewController returns a basic controller implementation

func (BaseController) IssueCoins

func (c BaseController) IssueCoins(store weave.KVStore,
	dest weave.Address, amount x.Coin) error

IssueCoins attempts to add the given amount of coins to the destination address. Fails if it overflows the wallet.

Note the amount may also be negative: "the lord giveth and the lord taketh away"

func (BaseController) MoveCoins

func (c BaseController) MoveCoins(store weave.KVStore,
	src weave.Address, dest weave.Address, amount x.Coin) error

MoveCoins moves the given amount from src to dest. If src doesn't exist, or doesn't have sufficient coins, it fails.

type Bucket

type Bucket struct {
	orm.Bucket
}

Bucket is a type-safe wrapper around orm.Bucket

func NewBucket

func NewBucket() Bucket

NewBucket initializes a cash.Bucket with default name

func (Bucket) GetOrCreate

func (b Bucket) GetOrCreate(db weave.KVStore, key weave.Address) (orm.Object, error)

GetOrCreate will return the object if found, or create one if not.

type Coinage

type Coinage interface {
	GetCoins() []*x.Coin
	SetCoins([]*x.Coin)
}

Coinage is any model that allows getting and setting coins, Below functions work on these models (oh, how I long for default implementations for interface, like rust traits)

func AsCoinage

func AsCoinage(obj orm.Object) Coinage

AsCoinage will safely type-cast any value from Bucket to Coinage

type Controller

type Controller interface {
	MoveCoins(store weave.KVStore, src weave.Address,
		dest weave.Address, amount x.Coin) error
	IssueCoins(store weave.KVStore, dest weave.Address,
		amount x.Coin) error
}

Controller is the functionality needed by cash.Handler and cash.Decorator. BaseController should work plenty fine, but you can add other logic if so desired

type FeeDecorator

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

FeeDecorator ensures that the fee can be deducted from the account. All deducted fees are send to the collector, which can be set to an address controlled by another extension ("smart contract").

If minFee is zero, no fees required, but will speed processing. If a currency is set on minFee, then all fees must be paid in that currency

It uses auth to verify the sender

func NewFeeDecorator

func NewFeeDecorator(auth x.Authenticator, control Controller,
	min x.Coin) FeeDecorator

NewFeeDecorator returns a FeeDecorator with the given minimum fee, and all collected fees going to a default address.

func (FeeDecorator) Check

func (d FeeDecorator) Check(ctx weave.Context, store weave.KVStore, tx weave.Tx,
	next weave.Checker) (weave.CheckResult, error)

Check verifies and deducts fees before calling down the stack

func (FeeDecorator) Deliver

func (d FeeDecorator) Deliver(ctx weave.Context, store weave.KVStore, tx weave.Tx,
	next weave.Deliverer) (weave.DeliverResult, error)

Deliver verifies and deducts fees before calling down the stack

func (FeeDecorator) WithCollector

func (d FeeDecorator) WithCollector(addr weave.Address) FeeDecorator

WithCollector allows you to set the collector in app setup

type FeeInfo

type FeeInfo struct {
	Payer []byte  `protobuf:"bytes,1,opt,name=payer,proto3" json:"payer,omitempty"`
	Fees  *x.Coin `protobuf:"bytes,2,opt,name=fees" json:"fees,omitempty"`
}

FeeInfo records who pays what fees to have this message processed

func (*FeeInfo) DefaultPayer

func (f *FeeInfo) DefaultPayer(addr []byte) *FeeInfo

DefaultPayer makes sure there is a payer. If it was already set, returns f. If none was set, returns a new FeeInfo, with the New address set

func (*FeeInfo) Descriptor

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

func (*FeeInfo) GetFees

func (m *FeeInfo) GetFees() *x.Coin

func (*FeeInfo) GetPayer

func (m *FeeInfo) GetPayer() []byte

func (*FeeInfo) Marshal

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

func (*FeeInfo) MarshalTo

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

func (*FeeInfo) ProtoMessage

func (*FeeInfo) ProtoMessage()

func (*FeeInfo) Reset

func (m *FeeInfo) Reset()

func (*FeeInfo) Size

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

func (*FeeInfo) String

func (m *FeeInfo) String() string

func (*FeeInfo) Unmarshal

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

func (*FeeInfo) Validate

func (f *FeeInfo) Validate() error

Validate makes sure that this is sensible. Note that fee must be present, even if 0

type FeeTx

type FeeTx interface {
	GetFees() *FeeInfo
}

FeeTx exposes information about the fees that should be paid

type GenesisAccount

type GenesisAccount struct {
	Address weave.Address `json:"address"`
	Set
}

GenesisAccount is used to parse the json from genesis file use weave.Address, so address in hex, not base64

type Initializer

type Initializer struct{}

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

func (Initializer) FromGenesis

func (Initializer) FromGenesis(opts weave.Options, kv weave.KVStore) error

FromGenesis will parse initial account info from genesis and save it to the database

type SendHandler

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

SendHandler will handle sending coins

func NewSendHandler

func NewSendHandler(auth x.Authenticator, control Controller) SendHandler

NewSendHandler creates a handler for SendMsg

func (SendHandler) Check

func (h SendHandler) Check(ctx weave.Context, store weave.KVStore,
	tx weave.Tx) (weave.CheckResult, error)

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

func (SendHandler) Deliver

func (h SendHandler) Deliver(ctx weave.Context, store weave.KVStore,
	tx weave.Tx) (weave.DeliverResult, error)

Deliver moves the tokens from sender to receiver if all preconditions are met

type SendMsg

type SendMsg struct {
	Src    []byte  `protobuf:"bytes,1,opt,name=src,proto3" json:"src,omitempty"`
	Dest   []byte  `protobuf:"bytes,2,opt,name=dest,proto3" json:"dest,omitempty"`
	Amount *x.Coin `protobuf:"bytes,3,opt,name=amount" json:"amount,omitempty"`
	// max length 128 character
	Memo string `protobuf:"bytes,4,opt,name=memo,proto3" json:"memo,omitempty"`
	// max length 64 bytes
	Ref []byte `protobuf:"bytes,5,opt,name=ref,proto3" json:"ref,omitempty"`
}

SendMsg is a request to move these coins from the given source to the given destination address. memo is an optional human-readable message ref is optional binary data, that can refer to another eg. tx hash

func (*SendMsg) DefaultSource

func (s *SendMsg) DefaultSource(addr []byte) *SendMsg

DefaultSource makes sure there is a payer. If it was already set, returns s. If none was set, returns a new SendMsg with the source set

func (*SendMsg) Descriptor

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

func (*SendMsg) GetAmount

func (m *SendMsg) GetAmount() *x.Coin

func (*SendMsg) GetDest

func (m *SendMsg) GetDest() []byte

func (*SendMsg) GetMemo

func (m *SendMsg) GetMemo() string

func (*SendMsg) GetRef

func (m *SendMsg) GetRef() []byte

func (*SendMsg) GetSrc

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

func (*SendMsg) Marshal

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

func (*SendMsg) MarshalTo

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

func (SendMsg) Path

func (SendMsg) Path() string

Path returns the routing path for this message

func (*SendMsg) ProtoMessage

func (*SendMsg) ProtoMessage()

func (*SendMsg) Reset

func (m *SendMsg) Reset()

func (*SendMsg) Size

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

func (*SendMsg) String

func (m *SendMsg) String() string

func (*SendMsg) Unmarshal

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

func (*SendMsg) Validate

func (s *SendMsg) Validate() error

Validate makes sure that this is sensible

type Set

type Set struct {
	Coins []*x.Coin `protobuf:"bytes,1,rep,name=coins" json:"coins,omitempty"`
}

Set may contain Coin of many different currencies. It handles adding and subtracting sets of currencies.

func (*Set) Copy

func (s *Set) Copy() orm.CloneableData

Copy makes a new set with the same coins

func (*Set) Descriptor

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

func (*Set) GetCoins

func (m *Set) GetCoins() []*x.Coin

func (*Set) Marshal

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

func (*Set) MarshalTo

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

func (*Set) ProtoMessage

func (*Set) ProtoMessage()

func (*Set) Reset

func (m *Set) Reset()

func (*Set) SetCoins

func (s *Set) SetCoins(coins []*x.Coin)

SetCoins allows us to modify the Set

func (*Set) Size

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

func (*Set) String

func (m *Set) String() string

func (*Set) Unmarshal

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

func (*Set) Validate

func (s *Set) Validate() error

Validate requires that all coins are in alphabetical

type WalletBucket

type WalletBucket interface {
	GetOrCreate(db weave.KVStore, key weave.Address) (orm.Object, error)
	Get(db weave.ReadOnlyKVStore, key []byte) (orm.Object, error)
	Save(db weave.KVStore, obj orm.Object) error
}

WalletBucket is what we expect to be able to do with wallets The object it returns must support AsSet (only checked runtime :()

Jump to

Keyboard shortcuts

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