Documentation ¶
Overview ¶
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
- Variables
- func Add(cng Coinage, c coin.Coin) error
- func AsCoins(obj orm.Object) coin.Coins
- func Concat(cng Coinage, coins coin.Coins) error
- func MoveCoins(db weave.KVStore, bank CoinMover, src, dest weave.Address, ...) error
- func NewConfigHandler(auth x.Authenticator) weave.Handler
- func NewWallet(key weave.Address) orm.Object
- func RegisterQuery(qr weave.QueryRouter)
- func RegisterRoutes(r weave.Registry, auth x.Authenticator, control Controller)
- func Subtract(cng Coinage, c coin.Coin) error
- func ValidateWalletBucket(bucket WalletBucket)
- func WalletWith(key weave.Address, coins ...*coin.Coin) (orm.Object, error)
- func XCoins(c Coinage) coin.Coins
- type Balancer
- type BaseController
- func (c BaseController) Balance(store weave.KVStore, src weave.Address) (coin.Coins, error)
- func (c BaseController) CoinMint(store weave.KVStore, dest weave.Address, amount coin.Coin) error
- func (c BaseController) MoveCoins(store weave.KVStore, src weave.Address, dest weave.Address, amount coin.Coin) error
- type Bucket
- type CoinMinter
- type CoinMover
- type Coinage
- type Configuration
- func (*Configuration) Descriptor() ([]byte, []int)
- func (m *Configuration) GetCollectorAddress() github_com_iov_one_weave.Address
- func (m *Configuration) GetMetadata() *weave.Metadata
- func (m *Configuration) GetMinimalFee() coin.Coin
- func (m *Configuration) GetOwner() github_com_iov_one_weave.Address
- func (m *Configuration) Marshal() (dAtA []byte, err error)
- func (m *Configuration) MarshalTo(dAtA []byte) (int, error)
- func (*Configuration) ProtoMessage()
- func (m *Configuration) Reset()
- func (m *Configuration) Size() (n int)
- func (m *Configuration) String() string
- func (m *Configuration) Unmarshal(dAtA []byte) error
- func (c *Configuration) Validate() error
- func (m *Configuration) XXX_DiscardUnknown()
- func (m *Configuration) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Configuration) XXX_Merge(src proto.Message)
- func (m *Configuration) XXX_Size() int
- func (m *Configuration) XXX_Unmarshal(b []byte) error
- type Controller
- type DynamicFeeDecorator
- type FeeDecorator
- type FeeInfo
- func (f *FeeInfo) DefaultPayer(addr []byte) *FeeInfo
- func (*FeeInfo) Descriptor() ([]byte, []int)
- func (m *FeeInfo) GetFees() *coin.Coin
- func (m *FeeInfo) GetPayer() github_com_iov_one_weave.Address
- func (m *FeeInfo) Marshal() (dAtA []byte, err error)
- func (m *FeeInfo) MarshalTo(dAtA []byte) (int, error)
- func (*FeeInfo) ProtoMessage()
- func (m *FeeInfo) Reset()
- func (m *FeeInfo) Size() (n int)
- func (m *FeeInfo) String() string
- func (m *FeeInfo) Unmarshal(dAtA []byte) error
- func (f *FeeInfo) Validate() error
- func (m *FeeInfo) XXX_DiscardUnknown()
- func (m *FeeInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *FeeInfo) XXX_Merge(src proto.Message)
- func (m *FeeInfo) XXX_Size() int
- func (m *FeeInfo) XXX_Unmarshal(b []byte) error
- type FeeTx
- type GenesisAccount
- type Initializer
- type SendHandler
- type SendMsg
- func (s *SendMsg) DefaultSource(addr []byte) *SendMsg
- func (*SendMsg) Descriptor() ([]byte, []int)
- func (m *SendMsg) GetAmount() *coin.Coin
- func (m *SendMsg) GetDestination() github_com_iov_one_weave.Address
- func (m *SendMsg) GetMemo() string
- func (m *SendMsg) GetMetadata() *weave.Metadata
- func (m *SendMsg) GetRef() []byte
- func (m *SendMsg) GetSource() github_com_iov_one_weave.Address
- func (m *SendMsg) Marshal() (dAtA []byte, err error)
- func (m *SendMsg) MarshalTo(dAtA []byte) (int, error)
- func (SendMsg) Path() string
- func (*SendMsg) ProtoMessage()
- func (m *SendMsg) Reset()
- func (m *SendMsg) Size() (n int)
- func (m *SendMsg) String() string
- func (m *SendMsg) Unmarshal(dAtA []byte) error
- func (s *SendMsg) Validate() error
- func (m *SendMsg) XXX_DiscardUnknown()
- func (m *SendMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *SendMsg) XXX_Merge(src proto.Message)
- func (m *SendMsg) XXX_Size() int
- func (m *SendMsg) XXX_Unmarshal(b []byte) error
- type Set
- func (*Set) Descriptor() ([]byte, []int)
- func (m *Set) GetCoins() []*coin.Coin
- func (m *Set) GetMetadata() *weave.Metadata
- func (m *Set) Marshal() (dAtA []byte, err error)
- func (m *Set) MarshalTo(dAtA []byte) (int, error)
- func (*Set) ProtoMessage()
- func (m *Set) Reset()
- func (s *Set) SetCoins(coins []*coin.Coin)
- func (m *Set) Size() (n int)
- func (m *Set) String() string
- func (m *Set) Unmarshal(dAtA []byte) error
- func (s *Set) Validate() error
- func (m *Set) XXX_DiscardUnknown()
- func (m *Set) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Set) XXX_Merge(src proto.Message)
- func (m *Set) XXX_Size() int
- func (m *Set) XXX_Unmarshal(b []byte) error
- type UpdateConfigurationMsg
- func (*UpdateConfigurationMsg) Descriptor() ([]byte, []int)
- func (m *UpdateConfigurationMsg) GetMetadata() *weave.Metadata
- func (m *UpdateConfigurationMsg) GetPatch() *Configuration
- func (m *UpdateConfigurationMsg) Marshal() (dAtA []byte, err error)
- func (m *UpdateConfigurationMsg) MarshalTo(dAtA []byte) (int, error)
- func (*UpdateConfigurationMsg) Path() string
- func (*UpdateConfigurationMsg) ProtoMessage()
- func (m *UpdateConfigurationMsg) Reset()
- func (m *UpdateConfigurationMsg) Size() (n int)
- func (m *UpdateConfigurationMsg) String() string
- func (m *UpdateConfigurationMsg) Unmarshal(dAtA []byte) error
- func (m *UpdateConfigurationMsg) Validate() error
- func (m *UpdateConfigurationMsg) XXX_DiscardUnknown()
- func (m *UpdateConfigurationMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *UpdateConfigurationMsg) XXX_Merge(src proto.Message)
- func (m *UpdateConfigurationMsg) XXX_Size() int
- func (m *UpdateConfigurationMsg) XXX_Unmarshal(b []byte) error
- type WalletBucket
Constants ¶
const BucketName = "cash"
BucketName is where we store the balances
Variables ¶
var ( ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowCodec = fmt.Errorf("proto: integer overflow") )
Functions ¶
func Concat ¶
Concat combines the coins to make sure they are sorted and rounded off, with no duplicates or 0 values.
func NewConfigHandler ¶ added in v0.15.0
func NewConfigHandler(auth x.Authenticator) weave.Handler
func NewWallet ¶
NewWallet creates an empty wallet with this address serves as an object for the bucket. NewWallet wraps Set into 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 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 ¶
WalletWith creates an wallet with a balance
Types ¶
type Balancer ¶ added in v0.12.0
type Balancer interface { // Balance returns the amount of funds stored under given account address. Balance(weave.KVStore, weave.Address) (coin.Coins, error) }
Balancer is an interface to query the amount of coins.
type BaseController ¶
type BaseController struct {
// contains filtered or unexported fields
}
BaseController implements Controller interface, using WalletBucket as the storage engine. Wallet must return something that supports AsSet.
func NewController ¶
func NewController(bucket WalletBucket) BaseController
NewController returns a base controller implementation.
func (BaseController) Balance ¶ added in v0.12.0
Balance returns the amount of funds stored under given account address.
type CoinMinter ¶ added in v0.12.0
type CoinMinter interface { // CoinMint increase the number of funds on given account by a // specified amount. CoinMint(weave.KVStore, weave.Address, coin.Coin) error }
CoinMinter is an interface to create new coins.
type CoinMover ¶ added in v0.12.0
type CoinMover interface { // Moving coins must happen from the source to the destination address. // Zero or negative values must result in an error. MoveCoins(store weave.KVStore, src weave.Address, dest weave.Address, amount coin.Coin) error }
CoinsMover is an interface for moving coins between accounts.
type Coinage ¶
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)
type Configuration ¶ added in v0.15.0
type Configuration struct { Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` // Owner is present to implement gconf.OwnedConfig interface // This defines the Address that is allowed to update the Configuration object and is // needed to make use of gconf.NewUpdateConfigurationHandler Owner github_com_iov_one_weave.Address `protobuf:"bytes,2,opt,name=owner,proto3,casttype=github.com/iov-one/weave.Address" json:"owner,omitempty"` CollectorAddress github_com_iov_one_weave.Address `` /* 151-byte string literal not displayed */ MinimalFee coin.Coin `protobuf:"bytes,4,opt,name=minimal_fee,json=minimalFee,proto3" json:"minimal_fee"` }
func (*Configuration) Descriptor ¶ added in v0.15.0
func (*Configuration) Descriptor() ([]byte, []int)
func (*Configuration) GetCollectorAddress ¶ added in v0.15.0
func (m *Configuration) GetCollectorAddress() github_com_iov_one_weave.Address
func (*Configuration) GetMetadata ¶ added in v0.17.0
func (m *Configuration) GetMetadata() *weave.Metadata
func (*Configuration) GetMinimalFee ¶ added in v0.15.0
func (m *Configuration) GetMinimalFee() coin.Coin
func (*Configuration) GetOwner ¶ added in v0.15.0
func (m *Configuration) GetOwner() github_com_iov_one_weave.Address
func (*Configuration) Marshal ¶ added in v0.15.0
func (m *Configuration) Marshal() (dAtA []byte, err error)
func (*Configuration) MarshalTo ¶ added in v0.15.0
func (m *Configuration) MarshalTo(dAtA []byte) (int, error)
func (*Configuration) ProtoMessage ¶ added in v0.15.0
func (*Configuration) ProtoMessage()
func (*Configuration) Reset ¶ added in v0.15.0
func (m *Configuration) Reset()
func (*Configuration) Size ¶ added in v0.15.0
func (m *Configuration) Size() (n int)
func (*Configuration) String ¶ added in v0.15.0
func (m *Configuration) String() string
func (*Configuration) Unmarshal ¶ added in v0.15.0
func (m *Configuration) Unmarshal(dAtA []byte) error
func (*Configuration) Validate ¶ added in v0.15.0
func (c *Configuration) Validate() error
func (*Configuration) XXX_DiscardUnknown ¶ added in v0.15.0
func (m *Configuration) XXX_DiscardUnknown()
func (*Configuration) XXX_Marshal ¶ added in v0.15.0
func (m *Configuration) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*Configuration) XXX_Merge ¶ added in v0.15.0
func (m *Configuration) XXX_Merge(src proto.Message)
func (*Configuration) XXX_Size ¶ added in v0.15.0
func (m *Configuration) XXX_Size() int
func (*Configuration) XXX_Unmarshal ¶ added in v0.15.0
func (m *Configuration) XXX_Unmarshal(b []byte) error
type Controller ¶
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 DynamicFeeDecorator ¶ added in v0.12.0
type DynamicFeeDecorator struct {
// contains filtered or unexported fields
}
func NewDynamicFeeDecorator ¶ added in v0.12.0
func NewDynamicFeeDecorator(auth x.Authenticator, ctrl Controller) DynamicFeeDecorator
NewDynamicFeeDecorator returns a DynamicFeeDecorator with the given minimum fee, and all collected fees going to a default address.
type FeeDecorator ¶
type FeeDecorator struct {
// contains filtered or unexported fields
}
func NewFeeDecorator ¶
func NewFeeDecorator(auth x.Authenticator, ctrl CoinMover) FeeDecorator
NewFeeDecorator returns a FeeDecorator with the given minimum fee, and all collected fees going to a default address.
type FeeInfo ¶
type FeeInfo struct { // Payer represents an address that will pay the fee. A fee fund will be // withdrawn from that account in order to process a transaction. // Warning: This field is optional and when not set it will default to any // signer. It is recommended to always explicitely set the value of this // field, as the signer order is not guaranteed. Payer github_com_iov_one_weave.Address `protobuf:"bytes,2,opt,name=payer,proto3,casttype=github.com/iov-one/weave.Address" json:"payer,omitempty"` Fees *coin.Coin `protobuf:"bytes,3,opt,name=fees,proto3" json:"fees,omitempty"` }
FeeInfo records who pays what fees to have this message processed
func (*FeeInfo) DefaultPayer ¶
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) GetPayer ¶
func (m *FeeInfo) GetPayer() github_com_iov_one_weave.Address
func (*FeeInfo) ProtoMessage ¶
func (*FeeInfo) ProtoMessage()
func (*FeeInfo) Validate ¶
Validate makes sure that this is sensible. Note that fee must be present, even if 0
func (*FeeInfo) XXX_DiscardUnknown ¶ added in v0.12.0
func (m *FeeInfo) XXX_DiscardUnknown()
func (*FeeInfo) XXX_Marshal ¶ added in v0.12.0
func (*FeeInfo) XXX_Unmarshal ¶ added in v0.12.0
type FeeTx ¶
type FeeTx interface {
GetFees() *FeeInfo
}
FeeTx exposes information about the fees that should be paid.
type GenesisAccount ¶
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, params weave.GenesisParams, 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
type SendMsg ¶
type SendMsg struct { Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` Source github_com_iov_one_weave.Address `protobuf:"bytes,2,opt,name=source,proto3,casttype=github.com/iov-one/weave.Address" json:"source,omitempty"` Destination github_com_iov_one_weave.Address `protobuf:"bytes,3,opt,name=destination,proto3,casttype=github.com/iov-one/weave.Address" json:"destination,omitempty"` Amount *coin.Coin `protobuf:"bytes,4,opt,name=amount,proto3" json:"amount,omitempty"` // max length 128 character Memo string `protobuf:"bytes,5,opt,name=memo,proto3" json:"memo,omitempty"` // max length 64 bytes Ref []byte `protobuf:"bytes,6,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 ¶
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) GetDestination ¶ added in v0.18.0
func (m *SendMsg) GetDestination() github_com_iov_one_weave.Address
func (*SendMsg) GetMetadata ¶ added in v0.15.0
func (*SendMsg) GetSource ¶ added in v0.18.0
func (m *SendMsg) GetSource() github_com_iov_one_weave.Address
func (*SendMsg) ProtoMessage ¶
func (*SendMsg) ProtoMessage()
func (*SendMsg) XXX_DiscardUnknown ¶ added in v0.12.0
func (m *SendMsg) XXX_DiscardUnknown()
func (*SendMsg) XXX_Marshal ¶ added in v0.12.0
func (*SendMsg) XXX_Unmarshal ¶ added in v0.12.0
type Set ¶
type Set struct { Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` Coins []*coin.Coin `protobuf:"bytes,2,rep,name=coins,proto3" json:"coins,omitempty"` }
Set may contain Coin of many different currencies. It handles adding and subtracting sets of currencies.
func (*Set) Descriptor ¶
func (*Set) GetMetadata ¶ added in v0.15.0
func (*Set) ProtoMessage ¶
func (*Set) ProtoMessage()
func (*Set) XXX_DiscardUnknown ¶ added in v0.12.0
func (m *Set) XXX_DiscardUnknown()
func (*Set) XXX_Marshal ¶ added in v0.12.0
func (*Set) XXX_Unmarshal ¶ added in v0.12.0
type UpdateConfigurationMsg ¶ added in v0.17.0
type UpdateConfigurationMsg struct { Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"` Patch *Configuration `protobuf:"bytes,2,opt,name=patch,proto3" json:"patch,omitempty"` }
func (*UpdateConfigurationMsg) Descriptor ¶ added in v0.17.0
func (*UpdateConfigurationMsg) Descriptor() ([]byte, []int)
func (*UpdateConfigurationMsg) GetMetadata ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) GetMetadata() *weave.Metadata
func (*UpdateConfigurationMsg) GetPatch ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) GetPatch() *Configuration
func (*UpdateConfigurationMsg) Marshal ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) Marshal() (dAtA []byte, err error)
func (*UpdateConfigurationMsg) MarshalTo ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) MarshalTo(dAtA []byte) (int, error)
func (*UpdateConfigurationMsg) Path ¶ added in v0.17.0
func (*UpdateConfigurationMsg) Path() string
func (*UpdateConfigurationMsg) ProtoMessage ¶ added in v0.17.0
func (*UpdateConfigurationMsg) ProtoMessage()
func (*UpdateConfigurationMsg) Reset ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) Reset()
func (*UpdateConfigurationMsg) Size ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) Size() (n int)
func (*UpdateConfigurationMsg) String ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) String() string
func (*UpdateConfigurationMsg) Unmarshal ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) Unmarshal(dAtA []byte) error
func (*UpdateConfigurationMsg) Validate ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) Validate() error
Validate will skip any zero fields and validate the set ones.
func (*UpdateConfigurationMsg) XXX_DiscardUnknown ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) XXX_DiscardUnknown()
func (*UpdateConfigurationMsg) XXX_Marshal ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*UpdateConfigurationMsg) XXX_Merge ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) XXX_Merge(src proto.Message)
func (*UpdateConfigurationMsg) XXX_Size ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) XXX_Size() int
func (*UpdateConfigurationMsg) XXX_Unmarshal ¶ added in v0.17.0
func (m *UpdateConfigurationMsg) XXX_Unmarshal(b []byte) error
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 :()