x

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
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
)
View Source
const (
	CodeInvalidCurrency uint32 = 30
	CodeInvalidCoin            = 31
)

ABCI Response Codes

Variables

View Source
var (
	ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowCodec   = fmt.Errorf("proto: integer overflow")
)
View Source
var IsCC = regexp.MustCompile(`^[A-Z]{3,4}$`).MatchString

IsCC is the RegExp to ensure valid currency codes

Functions

func ErrInvalidCurrency

func ErrInvalidCurrency(cur string, other ...string) error

ErrInvalidCurrency takes one or two currencies that are not proper

func ErrInvalidWallet

func ErrInvalidWallet(msg string) error

func ErrMismatchedSign

func ErrMismatchedSign(coin Coin) error

func ErrOutOfRange

func ErrOutOfRange(coin Coin) error

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

func HasAllAddresses(ctx weave.Context, auth Authenticator, required []weave.Address) bool

HasAllAddresses returns true if all elements in required are also in context.

func HasAllConditions added in v0.4.0

func HasAllConditions(ctx weave.Context, auth Authenticator, required []weave.Condition) bool

HasAllConditions returns true if all elements in required are also in context.

func HasNAddresses added in v0.8.0

func HasNAddresses(ctx weave.Context, auth Authenticator, required []weave.Address, n int) bool

HasNAddresses returns true if at least n elements in requested are also in context.

func HasNConditions added in v0.4.0

func HasNConditions(ctx weave.Context, auth Authenticator, requested []weave.Condition, n int) bool

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 IsEmpty

func IsEmpty(c *Coin) bool

IsEmpty returns true on null or zero amount

func IsInvalidCoinErr

func IsInvalidCoinErr(err error) bool

func IsInvalidCurrencyErr

func IsInvalidCurrencyErr(err error) bool

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 MustMarshal

func MustMarshal(obj weave.Marshaller) []byte

MustMarshal will succeed or panic

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

func MustValidate

func MustValidate(obj Validater)

MustValidate panics if the object is not valid

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 NewCoin

func NewCoin(whole int64, fractional int64,
	ticker string) Coin

NewCoin creates a new coin object

func (Coin) Add

func (c Coin) Add(o Coin) (Coin, error)

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) Clone

func (c *Coin) Clone() *Coin

Clone provides an independent copy of a coin pointer

func (Coin) Compare

func (c Coin) Compare(o Coin) int

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) Descriptor() ([]byte, []int)

func (Coin) Equals

func (c Coin) Equals(o Coin) bool

Equals returns true if all fields are identical

func (*Coin) GetFractional

func (m *Coin) GetFractional() int64

func (*Coin) GetIssuer

func (m *Coin) GetIssuer() string

func (*Coin) GetTicker

func (m *Coin) GetTicker() string

func (*Coin) GetWhole

func (m *Coin) GetWhole() int64

func (Coin) ID

func (c Coin) ID() string

ID returns a unique identifier. If issuer is empty, then just the Ticker. If issuer is present, then <Issuer>/<Ticker>

func (Coin) IsGTE

func (c Coin) IsGTE(o Coin) bool

IsGTE returns true if c is same type and at least as large as o. It assumes they were already normalized.

func (Coin) IsNonNegative

func (c Coin) IsNonNegative() bool

IsNonNegative returns true if the value is 0 or higher

func (Coin) IsPositive

func (c Coin) IsPositive() bool

IsPositive returns true if the value is greater than 0

func (Coin) IsZero

func (c Coin) IsZero() bool

IsZero returns true amounts are 0

func (*Coin) Marshal

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

func (*Coin) MarshalTo

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

func (Coin) Negative

func (c Coin) Negative() Coin

Negative returns the opposite coins value

c.Add(c.Negative()).IsZero() == true

func (*Coin) ProtoMessage

func (*Coin) ProtoMessage()

func (*Coin) Reset

func (m *Coin) Reset()

func (Coin) SameType

func (c Coin) SameType(o Coin) bool

SameType returns true if they have the same currency

func (*Coin) Size

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

func (*Coin) String

func (m *Coin) String() string

func (Coin) Subtract added in v0.9.3

func (c Coin) Subtract(amount Coin) (Coin, error)

Subtract given amount.

func (*Coin) Unmarshal

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

func (Coin) Validate

func (c Coin) Validate() error

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

func (c Coin) WithIssuer(issuer string) Coin

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

func CombineCoins(cs ...Coin) (Coins, error)

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) Add

func (cs Coins) Add(c Coin) (Coins, error)

Add modifies the Coins, to increase the holdings by c

func (Coins) Clone

func (cs Coins) Clone() Coins

Clone returns a copy that can be safely modified

func (Coins) Combine

func (cs Coins) Combine(o Coins) (Coins, error)

Combine will create a new Coins adding all the coins of s and o together.

func (Coins) Contains

func (cs Coins) Contains(c Coin) bool

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) Count

func (cs Coins) Count() int

Count returns the number of unique currencies in the Coins

func (Coins) Equals

func (cs Coins) Equals(o Coins) bool

Equals returns true if both Coinss contain same coins

func (Coins) IsEmpty

func (cs Coins) IsEmpty() bool

IsEmpty returns if nothing is in the Coins

func (Coins) IsNonNegative

func (cs Coins) IsNonNegative() bool

IsNonNegative returns true if all coins are positive, but also accepts an empty Coins

func (Coins) IsPositive

func (cs Coins) IsPositive() bool

IsPositive returns true there is at least one coin and all coins are positive

func (Coins) Subtract

func (cs Coins) Subtract(c Coin) (Coins, error)

Subtract modifies the Coins, to decrease the holdings by c. The resulting Coins may have negative amounts

func (Coins) Validate

func (cs Coins) Validate() error

Validate requires that all coins are in alphabetical order and that each coin is valid in it's own right

Zero amounts should not be present

type CountingDecorator

type CountingDecorator interface {
	GetCount() int
	weave.Decorator
}

CountingDecorator keeps track of number of times called. 2x per call, 1x per call with panic inside

type CountingHandler

type CountingHandler interface {
	GetCount() int
	weave.Handler
}

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

func (a CtxAuther) GetConditions(ctx weave.Context) []weave.Condition

GetConditions returns permissions previously set on this context

func (CtxAuther) HasAddress added in v0.3.0

func (a CtxAuther) HasAddress(ctx weave.Context, addr weave.Address) bool

HasAddress returns true iff this address is in GetConditions

func (CtxAuther) SetConditions added in v0.4.0

func (a CtxAuther) SetConditions(ctx weave.Context, perms ...weave.Condition) weave.Context

SetConditions returns a context with the given permissions set

type EnumHelpers added in v0.8.0

type EnumHelpers struct{}

func (EnumHelpers) AsList added in v0.8.0

func (EnumHelpers) AsList(enum map[string]int32) []string

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

func (m MultiAuth) GetConditions(ctx weave.Context) []weave.Condition

GetConditions combines all Conditions from all Authenenticators

func (MultiAuth) HasAddress added in v0.3.0

func (m MultiAuth) HasAddress(ctx weave.Context, addr weave.Address) bool

HasAddress returns true iff any Authenticator support this

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)

type Validater

type Validater interface {
	Validate() error
}

Validater is any struct that can be validated. Not the same as a Validator, which votes on the blocks.

Directories

Path Synopsis
Package batch is a generated protocol buffer package.
Package batch is a generated protocol buffer package.
Package cash is a generated protocol buffer package.
Package cash is a generated protocol buffer package.
Package currency is a generated protocol buffer package.
Package currency is a generated protocol buffer package.
Package escrow is a generated protocol buffer package.
Package escrow is a generated protocol buffer package.
Package hashlock implements token locking.
Package hashlock implements token locking.
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.
nft
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 paychan is a generated protocol buffer package.
Package paychan 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.

Jump to

Keyboard shortcuts

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