Documentation ¶
Overview ¶
Package x is a generated protocol buffer package. It is generated from these files: x/codec.proto It has these top-level messages: Coin
Package x contains some standard extensions ¶
Extensions implement common functionality (Handler, Decorator, etc.) and can be combined together to construct an application
All sub-packages are various extensions, useful to build applications, but not necessary to use the framework. All of them provide functionality commonly needed by blockchains. You are welcome to import them if desired, but if they don't match your particular needs, you may also write your own extensions and use them instead.
Index ¶
- Constants
- Variables
- func ErrInvalidCurrency(cur string, other ...string) error
- func ErrInvalidWallet(msg string) error
- func ErrMismatchedSign(coin Coin) error
- func ErrOutOfRange(coin Coin) error
- func GetAddresses(ctx weave.Context, auth Authenticator) []weave.Address
- func HasAllAddresses(ctx weave.Context, auth Authenticator, required []weave.Address) bool
- func HasAllConditions(ctx weave.Context, auth Authenticator, required []weave.Condition) bool
- func HasNAddresses(ctx weave.Context, auth Authenticator, required []weave.Address, n int) bool
- func HasNConditions(ctx weave.Context, auth Authenticator, requested []weave.Condition, n int) bool
- func IsEmpty(c *Coin) bool
- func IsInvalidCoinErr(err error) bool
- func IsInvalidCurrencyErr(err error) bool
- func MainSigner(ctx weave.Context, auth Authenticator) weave.Condition
- func MarshalValid(obj MarshalValidater) ([]byte, error)
- func MustMarshal(obj weave.Marshaller) []byte
- func MustMarshalValid(obj MarshalValidater) []byte
- func MustUnmarshal(obj weave.Persistent, bz []byte)
- func MustValidate(obj Validater)
- type Authenticator
- 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) GetFractional() int64
- func (m *Coin) GetIssuer() string
- func (m *Coin) GetTicker() string
- func (m *Coin) GetWhole() int64
- 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 Coins
- func (cs Coins) Add(c Coin) (Coins, error)
- func (cs Coins) Clone() Coins
- func (cs Coins) Combine(o Coins) (Coins, error)
- func (cs Coins) Contains(c Coin) bool
- func (cs Coins) Count() int
- func (cs Coins) Equals(o Coins) bool
- func (cs Coins) IsEmpty() bool
- func (cs Coins) IsNonNegative() bool
- func (cs Coins) IsPositive() bool
- func (cs Coins) Subtract(c Coin) (Coins, error)
- func (cs Coins) Validate() error
- type CountingDecorator
- type CountingHandler
- type CtxAuther
- type EnumHelpers
- type MarshalValidater
- type MultiAuth
- type TestHelpers
- func (TestHelpers) Authenticate(perms ...weave.Condition) Authenticator
- func (TestHelpers) CountingDecorator() CountingDecorator
- func (TestHelpers) CountingHandler() CountingHandler
- func (TestHelpers) CtxAuth(key interface{}) CtxAuther
- func (TestHelpers) ErrorDecorator(err error) weave.Decorator
- func (TestHelpers) ErrorHandler(err error) weave.Handler
- func (TestHelpers) MakeKey() (crypto.Signer, weave.Condition)
- func (TestHelpers) MockMsg(bz []byte) weave.Msg
- func (TestHelpers) MockTx(msg weave.Msg) weave.Tx
- func (TestHelpers) PanicAtHeightDecorator(h int64) weave.Decorator
- func (TestHelpers) PanicHandler(err error) weave.Handler
- func (TestHelpers) TagHandler(key, value []byte, err error) weave.Handler
- func (TestHelpers) Wrap(d weave.Decorator, h weave.Handler) weave.Handler
- func (TestHelpers) WriteDecorator(key, value []byte, after bool) weave.Decorator
- func (TestHelpers) WriteHandler(key, value []byte, err error) weave.Handler
- type Validater
Constants ¶
const ( // MaxInt is the largest whole value we accept MaxInt int64 = 999999999999999 // 10^15-1 // MinInt is the lowest whole value we accept MinInt = -MaxInt // FracUnit is the smallest numbers we divide by FracUnit int64 = 1000000000 // fractional units = 10^9 // MaxFrac is the highest possible fractional value MaxFrac = FracUnit - 1 // MinFrac is the lowest possible fractional value MinFrac = -MaxFrac )
const ( CodeInvalidCurrency uint32 = 30 CodeInvalidCoin = 31 )
ABCI Response Codes
Variables ¶
var ( ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowCodec = fmt.Errorf("proto: integer overflow") )
var IsCC = regexp.MustCompile(`^[A-Z]{3,4}$`).MatchString
IsCC is the RegExp to ensure valid currency codes
Functions ¶
func ErrInvalidCurrency ¶
ErrInvalidCurrency takes one or two currencies that are not proper
func ErrInvalidWallet ¶
func ErrMismatchedSign ¶
func ErrOutOfRange ¶
func GetAddresses ¶ added in v0.3.0
func GetAddresses(ctx weave.Context, auth Authenticator) []weave.Address
GetAddresses wraps the GetConditions method of any Authenticator
func HasAllAddresses ¶ added in v0.3.0
HasAllAddresses returns true if all elements in required are also in context.
func HasAllConditions ¶ added in v0.4.0
HasAllConditions returns true if all elements in required are also in context.
func HasNAddresses ¶ added in v0.8.0
HasNAddresses returns true if at least n elements in requested are also in context.
func HasNConditions ¶ added in v0.4.0
HasNConditions returns true if at least n elements in requested are also in context. Useful for threshold conditions (1 of 3, 3 of 5, etc...)
func IsInvalidCoinErr ¶
func IsInvalidCurrencyErr ¶
func MainSigner ¶
func MainSigner(ctx weave.Context, auth Authenticator) weave.Condition
MainSigner returns the first permission if any, otherwise nil
func MarshalValid ¶
func MarshalValid(obj MarshalValidater) ([]byte, error)
MarshalValid validates the object, then marshals
func MustMarshalValid ¶
func MustMarshalValid(obj MarshalValidater) []byte
MustMarshalValid marshals the object, but panics if the object is not valid or has trouble marshalling
func MustUnmarshal ¶
func MustUnmarshal(obj weave.Persistent, bz []byte)
MustUnmarshal will succeed or panic
Types ¶
type Authenticator ¶
type Authenticator interface { // GetConditions reveals all Conditions fulfilled, // you may want GetAddresses helper GetConditions(weave.Context) []weave.Condition // HasAddress checks if any condition matches this address HasAddress(weave.Context, weave.Address) bool }
Authenticator is an interface we can use to extract authentication info from the context. This should be passed into the constructor of handlers, so we can plug in another authentication system, rather than hardcoding x/auth for all extensions.
type Coin ¶
type Coin struct { // Whole coins, -10^15 < integer < 10^15 Whole int64 `protobuf:"varint,1,opt,name=whole,proto3" json:"whole,omitempty"` // Billionth of coins. 0 <= abs(fractional) < 10^9 // If fractional != 0, must have same sign as integer Fractional int64 `protobuf:"varint,2,opt,name=fractional,proto3" json:"fractional,omitempty"` // Ticker is 3-4 upper-case letters and // all Coins of the same currency can be combined Ticker string `protobuf:"bytes,3,opt,name=ticker,proto3" json:"ticker,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) GetFractional ¶
func (Coin) ID ¶
ID returns a unique identifier. If issuer is empty, then just the Ticker. If issuer is present, then <Issuer>/<Ticker>
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 Coins ¶
type Coins []*Coin
Coins is a
func CombineCoins ¶
CombineCoins creates a Coins containing all given coins. It will sort them and combine duplicates to produce a normalized form regardless of input.
TODO: deprecate in favor of `Coins.Combine()`
func (Coins) Contains ¶
Contains returns true if there is at least that much coin in the Coins. If it returns true, then:
s.Remove(c).IsNonNegative() == true
func (Coins) IsNonNegative ¶
IsNonNegative returns true if all coins are positive, but also accepts an empty Coins
func (Coins) IsPositive ¶
IsPositive returns true there is at least one coin and all coins are positive
type CountingDecorator ¶
CountingDecorator keeps track of number of times called. 2x per call, 1x per call with panic inside
type CountingHandler ¶
CountingHandler keeps track of number of times called. 1x per call
type CtxAuther ¶ added in v0.3.0
type CtxAuther struct {
// contains filtered or unexported fields
}
CtxAuther gets/sets permissions on the given context key
func (CtxAuther) GetConditions ¶ added in v0.4.0
GetConditions returns permissions previously set on this context
func (CtxAuther) HasAddress ¶ added in v0.3.0
HasAddress returns true iff this address is in GetConditions
type EnumHelpers ¶ added in v0.8.0
type EnumHelpers struct{}
type MarshalValidater ¶
type MarshalValidater interface { weave.Marshaller Validater }
MarshalValidater is something that can be validated and serialized
type MultiAuth ¶
type MultiAuth struct {
// contains filtered or unexported fields
}
MultiAuth chains together many Authenticators into one
func ChainAuth ¶
func ChainAuth(impls ...Authenticator) MultiAuth
ChainAuth groups together a series of Authenticator
func (MultiAuth) GetConditions ¶ added in v0.4.0
GetConditions combines all Conditions from all Authenenticators
type TestHelpers ¶
type TestHelpers struct{}
TestHelpers returns helper objects for tests, encapsulated in one object to be easily imported in other packages
func (TestHelpers) Authenticate ¶
func (TestHelpers) Authenticate(perms ...weave.Condition) Authenticator
Authenticate returns an Authenticator that gives permissions to the given addresses
func (TestHelpers) CountingDecorator ¶
func (TestHelpers) CountingDecorator() CountingDecorator
CountingDecorator passes tx along, and counts how many times it was called. Adds one on input down, one on output up, to differentiate panic from error
func (TestHelpers) CountingHandler ¶
func (TestHelpers) CountingHandler() CountingHandler
CountingHandler returns success and counts times called
func (TestHelpers) CtxAuth ¶ added in v0.3.0
func (TestHelpers) CtxAuth(key interface{}) CtxAuther
CtxAuth returns an authenticator that uses the context getting and setting with the given key
func (TestHelpers) ErrorDecorator ¶
func (TestHelpers) ErrorDecorator(err error) weave.Decorator
ErrorDecorator always returns the given error when called
func (TestHelpers) ErrorHandler ¶
func (TestHelpers) ErrorHandler(err error) weave.Handler
ErrorHandler always returns the given error when called
func (TestHelpers) MakeKey ¶
func (TestHelpers) MakeKey() (crypto.Signer, weave.Condition)
MakeKey returns a random PrivateKey and the associated address
func (TestHelpers) MockMsg ¶
func (TestHelpers) MockMsg(bz []byte) weave.Msg
MockMsg returns a weave.Msg object holding these bytes
func (TestHelpers) MockTx ¶
func (TestHelpers) MockTx(msg weave.Msg) weave.Tx
MockTx returns a minimal weave.Tx object holding this Msg
func (TestHelpers) PanicAtHeightDecorator ¶
func (TestHelpers) PanicAtHeightDecorator(h int64) weave.Decorator
PanicAtHeightDecorator will panic if ctx.height >= h
func (TestHelpers) PanicHandler ¶
func (TestHelpers) PanicHandler(err error) weave.Handler
PanicHandler always pancis with the given error when called
func (TestHelpers) TagHandler ¶ added in v0.2.1
func (TestHelpers) TagHandler(key, value []byte, err error) weave.Handler
TagHandler writes a tag to DeliverResult and returns error of nil returns error, but doens't write any tags on CheckTx
func (TestHelpers) Wrap ¶ added in v0.2.1
Wrap wraps the handler with one decorator and returns it as a single handler. Minimal version of ChainDecorators for test cases
func (TestHelpers) WriteDecorator ¶
func (TestHelpers) WriteDecorator(key, value []byte, after bool) weave.Decorator
WriteDecorator will write the given key/value pair to the KVStore, either before or after calling down the stack. Returns (res, err) from child handler untouched
func (TestHelpers) WriteHandler ¶
func (TestHelpers) WriteHandler(key, value []byte, err error) weave.Handler
WriteHandler will write the given key/value pair to the KVStore, and return the error (use nil for success)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package cash is a generated protocol buffer package.
|
Package cash is a generated protocol buffer package. |
Package escrow is a generated protocol buffer package.
|
Package escrow is a generated protocol buffer package. |
Package multisig is a generated protocol buffer package.
|
Package multisig is a generated protocol buffer package. |
Package namecoin is a generated protocol buffer package.
|
Package namecoin is a generated protocol buffer package. |
Package nft is a generated protocol buffer package.
|
Package nft is a generated protocol buffer package. |
blockchain
Package blockchain is a generated protocol buffer package.
|
Package blockchain is a generated protocol buffer package. |
bootstrap_node
Package bootstrap_node is a generated protocol buffer package.
|
Package bootstrap_node is a generated protocol buffer package. |
ticker
Package ticker is a generated protocol buffer package.
|
Package ticker is a generated protocol buffer package. |
username
Package username is a generated protocol buffer package.
|
Package username is a generated protocol buffer package. |
Package sigs is a generated protocol buffer package.
|
Package sigs is a generated protocol buffer package. |
Package validators is a generated protocol buffer package.
|
Package validators is a generated protocol buffer package. |