Documentation
¶
Overview ¶
Package coins is a generated protocol buffer package.
It is generated from these files:
x/coins/codec.proto
It has these top-level messages:
Coin Set SendMsg FeeInfo
Index ¶
- Constants
- Variables
- func ErrEmptyAccount(addr []byte) error
- func ErrInsufficientFees(coin Coin) error
- func ErrInsufficientFunds() error
- func ErrInvalidAmount(reason string) error
- func ErrInvalidCurrency(cur string, other ...string) error
- func ErrInvalidMemo(reason string) error
- func ErrInvalidWallet(msg string) error
- func ErrMismatchedSign(coin Coin) error
- func ErrOutOfRange(coin Coin) error
- func IsEmpty(c *Coin) bool
- func IsEmptyAccountErr(err error) bool
- func IsInsufficientFeesErr(err error) bool
- func IsInsufficientFundsErr(err error) bool
- func IsInvalidAmountErr(err error) bool
- func IsInvalidCoinErr(err error) bool
- func IsInvalidCurrencyErr(err error) bool
- func IsInvalidMemoErr(err error) bool
- func IssueCoins(store weave.KVStore, dest weave.Address, amount Coin) error
- func MoveCoins(store weave.KVStore, src weave.Address, dest weave.Address, amount Coin) error
- func RegisterRoutes(r weave.Registry, auth weave.AuthFunc)
- type Coin
- func (c Coin) Add(o Coin) (Coin, error)
- func (c *Coin) Clone() *Coin
- func (c Coin) Compare(o Coin) int
- func (*Coin) Descriptor() ([]byte, []int)
- func (c Coin) Equals(o Coin) bool
- func (m *Coin) GetCurrencyCode() string
- func (m *Coin) GetFractional() int32
- func (m *Coin) GetInteger() int32
- func (m *Coin) GetIssuer() string
- func (c Coin) ID() string
- func (c Coin) IsGTE(o Coin) bool
- func (c Coin) IsNonNegative() bool
- func (c Coin) IsPositive() bool
- func (c Coin) IsZero() bool
- func (m *Coin) Marshal() (dAtA []byte, err error)
- func (m *Coin) MarshalTo(dAtA []byte) (int, error)
- func (c Coin) Negative() Coin
- func (*Coin) ProtoMessage()
- func (m *Coin) Reset()
- func (c Coin) SameType(o Coin) bool
- func (m *Coin) Size() (n int)
- func (m *Coin) String() string
- func (m *Coin) Unmarshal(dAtA []byte) error
- func (c Coin) Validate() error
- func (c Coin) WithIssuer(issuer string) Coin
- type FeeDecorator
- func (d FeeDecorator) Check(ctx weave.Context, store weave.KVStore, tx weave.Tx, next weave.Checker) (weave.CheckResult, error)
- func (d FeeDecorator) Deliver(ctx weave.Context, store weave.KVStore, tx weave.Tx, next weave.Deliverer) (weave.DeliverResult, error)
- func (d FeeDecorator) WithCollector(addr weave.Address) FeeDecorator
- type FeeInfo
- func (f *FeeInfo) DefaultPayer(addr []byte) *FeeInfo
- func (*FeeInfo) Descriptor() ([]byte, []int)
- func (m *FeeInfo) GetFees() *Coin
- func (m *FeeInfo) GetPayer() []byte
- 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
- type FeeTx
- type GenesisAccount
- type Initializer
- type Key
- type SendHandler
- type SendMsg
- func (s *SendMsg) DefaultSource(addr []byte) *SendMsg
- func (*SendMsg) Descriptor() ([]byte, []int)
- func (m *SendMsg) GetAmount() *Coin
- func (m *SendMsg) GetDest() []byte
- func (m *SendMsg) GetMemo() string
- func (m *SendMsg) GetRef() []byte
- func (m *SendMsg) GetSrc() []byte
- 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
- type Set
- func (s *Set) Add(c Coin) error
- func (s Set) Clone() Set
- func (s Set) Combine(o Set) (Set, error)
- func (s Set) Contains(c Coin) bool
- func (s Set) Count() int
- func (*Set) Descriptor() ([]byte, []int)
- func (s Set) Equals(o Set) bool
- func (m *Set) GetCoins() []*Coin
- func (s Set) IsEmpty() bool
- func (s Set) IsNonNegative() bool
- func (s Set) IsPositive() bool
- func (m *Set) Marshal() (dAtA []byte, err error)
- func (m *Set) MarshalTo(dAtA []byte) (int, error)
- func (*Set) ProtoMessage()
- func (m *Set) Reset()
- func (m *Set) Size() (n int)
- func (m *Set) String() string
- func (s *Set) Subtract(c Coin) error
- func (m *Set) Unmarshal(dAtA []byte) error
- func (s Set) Validate() error
- type Wallet
Constants ¶
const ( CodeInvalidCurrency uint32 = 30 CodeInvalidCoin = 31 CodeInsufficientFees = 32 CodeInsufficientFunds = 33 CodeInvalidAmount = 34 CodeInvalidMemo = 35 CodeEmptyAccount = 36 )
ABCI Response Codes x/coins reserves 30 ~ 39.
Variables ¶
var ( ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowCodec = fmt.Errorf("proto: integer overflow") )
Functions ¶
func ErrEmptyAccount ¶
func ErrInsufficientFees ¶
func ErrInsufficientFunds ¶
func ErrInsufficientFunds() error
func ErrInvalidAmount ¶
func ErrInvalidCurrency ¶
ErrInvalidCurrency takes one or two currencies that are not proper
func ErrInvalidMemo ¶
func ErrInvalidWallet ¶
func ErrMismatchedSign ¶
func ErrOutOfRange ¶
func IsEmptyAccountErr ¶
func IsInsufficientFeesErr ¶
func IsInsufficientFundsErr ¶
func IsInvalidAmountErr ¶
func IsInvalidCoinErr ¶
func IsInvalidCurrencyErr ¶
func IsInvalidMemoErr ¶
func IssueCoins ¶
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"
Types ¶
type Coin ¶
type Coin struct {
// Whole coins, -10^9 < integer < 10^9
Integer int32 `protobuf:"varint,1,opt,name=integer,proto3" json:"integer,omitempty"`
// Billionth of coins. 0 <= abs(fractional) < 10^9
// If fractional != 0, must have same sign as integer
Fractional int32 `protobuf:"varint,2,opt,name=fractional,proto3" json:"fractional,omitempty"`
// CurrencyCode is 3-4 upper-case letters and
// all Coins of the same currency can be combined
CurrencyCode string `protobuf:"bytes,3,opt,name=currency_code,json=currencyCode,proto3" json:"currency_code,omitempty"`
// Issuer is optional string, maybe chain_id? maybe custodian name?
// can be empty. tokens are only fungible if CurrencyCode and
// Issuer both match.
Issuer string `protobuf:"bytes,4,opt,name=issuer,proto3" json:"issuer,omitempty"`
}
Coin can hold any amount between -1 billion and +1 billion at steps of 10^-9. It is a fixed-point decimal representation and uses integers to avoid rounding associated with floats.
Every code has a denomination, which is just a ¶
If you want anything more complex, you should write your own type, possibly borrowing from this code.
func (Coin) Add ¶
Add combines two coins. Returns error if they are of different currencies, or if the combination would cause an overflow
To subtract:
c.Add(o.Negative())
func (Coin) Compare ¶
Compare will check values of two coins, without inspecting the currency code. It is up to the caller to determine if they want to check this. It also assumes they were already normalized.
Returns 1 if c is larger, -1 if o is larger, 0 if equal
func (*Coin) Descriptor ¶
func (*Coin) GetCurrencyCode ¶
func (*Coin) GetFractional ¶
func (*Coin) GetInteger ¶
func (Coin) ID ¶
ID returns a unique identifier. If issuer is empty, then just the CurrencyCode. If issuer is present, then <Issuer>/<CurrencyCode>
func (Coin) IsGTE ¶
IsGTE returns true if c is same type and at least as large as o. It assumes they were already normalized.
func (Coin) IsNonNegative ¶
IsNonNegative returns true if the value is 0 or higher
func (Coin) IsPositive ¶
IsPositive returns true if the value is greater than 0
func (Coin) Negative ¶
Negative returns the opposite coins value
c.Add(c.Negative()).IsZero() == true
func (*Coin) ProtoMessage ¶
func (*Coin) ProtoMessage()
func (Coin) Validate ¶
Validate ensures that the coin is in the valid range and valid currency code. It accepts negative values, so you may want to make other checks in your business logic
func (Coin) WithIssuer ¶
WithIssuer sets the Issuer on a coin. Returns new coin, so this can be chained on constructor
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 weave.AuthFunc, min 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 *Coin `protobuf:"bytes,2,opt,name=fees" 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) ProtoMessage ¶
func (*FeeInfo) ProtoMessage()
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 ¶
FromGenesis will parse initial account info from genesis and save it to the database
type Key ¶
type Key []byte
Key is the primary key we use to distinguish users This should be []byte, in order to index with our KVStore. Any structure to these bytes should be defined by the constructor.
Question: allow objects with a Marshal method???
type SendHandler ¶
type SendHandler struct {
// contains filtered or unexported fields
}
SendHandler will handle sending coins
func NewSendHandler ¶
func NewSendHandler(auth weave.AuthFunc) SendHandler
NewSendHandler creates a handler for SendMsg
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 *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 ¶
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) ProtoMessage ¶
func (*SendMsg) ProtoMessage()
type Set ¶
type Set struct {
Coins []*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 NewSet ¶
NewSet creates a Set containing all given coins. It will sort them and combine duplicates to produce a normalized form regardless of input.
func (Set) Contains ¶
Contains returns true if there is at least that much coin in the Set. If it returns true, then:
s.Remove(c).IsNonNegative() == true
func (*Set) Descriptor ¶
func (Set) IsNonNegative ¶
IsNonNegative returns true if all coins are positive, but also accepts an empty set
func (Set) IsPositive ¶
IsPositive returns true there is at least one coin and all coins are positive
func (*Set) ProtoMessage ¶
func (*Set) ProtoMessage()
type Wallet ¶
type Wallet struct {
Set
// contains filtered or unexported fields
}
Wallet is the actual object that we want to pass around in our code. It contains a set of coins, as well as logic to handle loading and saving the data to/from the persistent store, and helpers to manipulate state.
func GetOrCreateWallet ¶
GetOrCreateWallet loads this Wallet if present, or initializes a new Wallet with this key if not present.