types

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ZeroRat = NewRat(0) // Rat{big.NewRat(0, 1)}
	OneRat  = NewRat(1) // Rat{big.NewRat(1, 1)}
)

nolint - common values

Functions

func CodeToDefaultMsg

func CodeToDefaultMsg(code CodeType) string

NOTE: Don't stringer this, we'll put better messages in later.

func NewRatFromDecimal

func NewRatFromDecimal(decimalStr string) (f Rat, err Error)

create a rational from decimal string or integer string

func StdSignBytes

func StdSignBytes(chainID string, sequences []int64, fee StdFee, msg Msg) []byte

StdSignBytes returns the bytes to sign for a transaction. TODO: change the API to just take a chainID and StdTx ?

Types

type Account

type Account interface {
	GetAddress() Address
	SetAddress(Address) error // errors if already set.

	GetPubKey() crypto.PubKey // can return nil.
	SetPubKey(crypto.PubKey) error

	GetSequence() int64
	SetSequence(int64) error

	GetCoins() Coins
	SetCoins(Coins) error

	Get(key interface{}) (value interface{}, err error)
	Set(key interface{}, value interface{}) error
}

Account is a standard account using a sequence number for replay protection and a pubkey for authentication.

type AccountDecoder

type AccountDecoder func(accountBytes []byte) (Account, error)

AccountDecoder unmarshals account bytes

type AccountMapper

type AccountMapper interface {
	NewAccountWithAddress(ctx Context, addr Address) Account
	GetAccount(ctx Context, addr Address) Account
	SetAccount(ctx Context, acc Account)
}

AccountMapper stores and retrieves accounts from stores retrieved from the context.

type Address

type Address = cmn.HexBytes

Address in go-crypto style

func FeePayer

func FeePayer(tx Tx) Address

FeePayer returns the address responsible for paying the fees for the transactions. It's the first address returned by msg.GetSigners(). If GetSigners() is empty, this panics.

func GetAddress

func GetAddress(address string) (addr Address, err error)

create an Address from a string

type AnteHandler

type AnteHandler func(ctx Context, tx Tx) (newCtx Context, result Result, abort bool)

If newCtx.IsZero(), ctx is used instead.

type BeginBlocker

type BeginBlocker func(ctx Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock

run code before the transactions in a block

type CacheKVStore

type CacheKVStore interface {
	KVStore

	// Writes operations to underlying KVStore
	Write()
}

CacheKVStore cache-wraps a KVStore. After calling .Write() on the CacheKVStore, all previously created CacheKVStores on the object expire.

type CacheMultiStore

type CacheMultiStore interface {
	MultiStore
	Write() // Writes operations to underlying KVStore
}

From MultiStore.CacheMultiStore()....

type CacheWrap

type CacheWrap interface {

	// Write syncs with the underlying store.
	Write()

	// CacheWrap recursively wraps again.
	CacheWrap() CacheWrap
}

CacheWrap() makes the most appropriate cache-wrap. For example, IAVLStore.CacheWrap() returns a CacheKVStore.

CacheWrap() should not return a Committer, since Commit() on cache-wraps make no sense. It can return KVStore, HeapStore, SpaceStore, etc.

type CacheWrapper

type CacheWrapper interface {
	CacheWrap() CacheWrap
}

type CodeType

type CodeType uint32

ABCI Response Code

const (
	CodeOK                CodeType = 0
	CodeInternal          CodeType = 1
	CodeTxDecode          CodeType = 2
	CodeInvalidSequence   CodeType = 3
	CodeUnauthorized      CodeType = 4
	CodeInsufficientFunds CodeType = 5
	CodeUnknownRequest    CodeType = 6
	CodeInvalidAddress    CodeType = 7
	CodeInvalidPubKey     CodeType = 8
	CodeUnknownAddress    CodeType = 9
	CodeInsufficientCoins CodeType = 10
	CodeInvalidCoins      CodeType = 11

	CodeGenesisParse CodeType = 0xdead // TODO: remove ? // why remove?
)

ABCI Response Codes Base SDK reserves 0 - 99.

func (CodeType) IsOK

func (code CodeType) IsOK() bool

is everything okay?

type Coin

type Coin struct {
	Denom  string `json:"denom"`
	Amount int64  `json:"amount"`
}

Coin hold some amount of one currency

func ParseCoin

func ParseCoin(coinStr string) (coin Coin, err error)

ParseCoin parses a cli input for one coin type, returning errors if invalid. This returns an error on an empty string as well.

func (Coin) IsEqual

func (coin Coin) IsEqual(other Coin) bool

IsEqual returns true if the two sets of Coins have the same value

func (Coin) IsGTE

func (coin Coin) IsGTE(other Coin) bool

IsGTE returns true if they are the same type and the receiver is an equal or greater value

func (Coin) IsNotNegative

func (coin Coin) IsNotNegative() bool

IsNotNegative returns true if coin amount is not negative

func (Coin) IsPositive

func (coin Coin) IsPositive() bool

IsPositive returns true if coin amount is positive

func (Coin) IsZero

func (coin Coin) IsZero() bool

IsZero returns if this represents no money

func (Coin) Minus

func (coin Coin) Minus(coinB Coin) Coin

Subtracts amounts of two coins with same denom

func (Coin) Plus

func (coin Coin) Plus(coinB Coin) Coin

Adds amounts of two coins with same denom

func (Coin) SameDenomAs

func (coin Coin) SameDenomAs(other Coin) bool

SameDenomAs returns true if the two coins are the same denom

func (Coin) String

func (coin Coin) String() string

String provides a human-readable representation of a coin

type Coins

type Coins []Coin

Coins is a set of Coin, one per currency

func ParseCoins

func ParseCoins(coinsStr string) (coins Coins, err error)

ParseCoins will parse out a list of coins separated by commas. If nothing is provided, it returns nil Coins. Returned coins are sorted.

func (Coins) AmountOf

func (coins Coins) AmountOf(denom string) int64

Returns the amount of a denom from coins

func (Coins) IsEqual

func (coins Coins) IsEqual(coinsB Coins) bool

IsEqual returns true if the two sets of Coins have the same value

func (Coins) IsGTE

func (coins Coins) IsGTE(coinsB Coins) bool

IsGTE returns True iff coins is NonNegative(), and for every currency in coinsB, the currency is present at an equal or greater amount in coinsB

func (Coins) IsNotNegative

func (coins Coins) IsNotNegative() bool

IsNotNegative returns true if there is no currency with a negative value (even no coins is true here)

func (Coins) IsPositive

func (coins Coins) IsPositive() bool

IsPositive returns true if there is at least one coin, and all currencies have a positive value

func (Coins) IsValid

func (coins Coins) IsValid() bool

IsValid asserts the Coins are sorted, and don't have 0 amounts

func (Coins) IsZero

func (coins Coins) IsZero() bool

IsZero returns true if there are no coins or all coins are zero.

func (Coins) Len

func (coins Coins) Len() int

nolint

func (Coins) Less

func (coins Coins) Less(i, j int) bool

func (Coins) Minus

func (coins Coins) Minus(coinsB Coins) Coins

Minus subtracts a set of coins from another (adds the inverse)

func (Coins) Negative

func (coins Coins) Negative() Coins

Negative returns a set of coins with all amount negative

func (Coins) Plus

func (coins Coins) Plus(coinsB Coins) Coins

Plus combines two sets of coins CONTRACT: Plus will never return Coins where one Coin has a 0 amount.

func (Coins) Sort

func (coins Coins) Sort() Coins

Sort is a helper function to sort the set of coins inplace

func (Coins) String

func (coins Coins) String() string

func (Coins) Swap

func (coins Coins) Swap(i, j int)

type CommitID

type CommitID struct {
	Version int64
	Hash    []byte
}

CommitID contains the tree version number and its merkle root.

func (CommitID) IsZero

func (cid CommitID) IsZero() bool

func (CommitID) String

func (cid CommitID) String() string

type CommitKVStore

type CommitKVStore interface {
	Committer
	KVStore
}

Stores of MultiStore must implement CommitStore.

type CommitMultiStore

type CommitMultiStore interface {
	Committer
	MultiStore

	// Mount a store of type using the given db.
	// If db == nil, the new store will use the CommitMultiStore db.
	MountStoreWithDB(key StoreKey, typ StoreType, db dbm.DB)

	// Panics on a nil key.
	GetCommitStore(key StoreKey) CommitStore

	// Panics on a nil key.
	GetCommitKVStore(key StoreKey) CommitKVStore

	// Load the latest persisted version.  Called once after all
	// calls to Mount*Store() are complete.
	LoadLatestVersion() error

	// Load a specific persisted version.  When you load an old
	// version, or when the last commit attempt didn't complete,
	// the next commit after loading must be idempotent (return the
	// same commit id).  Otherwise the behavior is undefined.
	LoadVersion(ver int64) error
}

A non-cache MultiStore.

type CommitStore

type CommitStore interface {
	Committer
	Store
}

Stores of MultiStore must implement CommitStore.

type Committer

type Committer interface {
	Commit() CommitID
	LastCommitID() CommitID
}

something that can persist to disk

type Context

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

The intent of Context is for it to be an immutable object that can be cloned and updated cheaply with WithValue() and passed forward to the next decorator or handler. For example,

func MsgHandler(ctx Context, tx Tx) Result {
	...
	ctx = ctx.WithValue(key, value)
	...
}

func NewContext

func NewContext(ms MultiStore, header abci.Header, isCheckTx bool, txBytes []byte) Context

create a new context

func (Context) BlockHeader

func (c Context) BlockHeader() abci.Header

nolint

func (Context) BlockHeight

func (c Context) BlockHeight() int64

func (Context) ChainID

func (c Context) ChainID() string

func (Context) GetOp

func (c Context) GetOp(ver int64) (Op, bool)

Returns false if ver <= 0 || ver > len(c.pst.ops). The first operation is version 1.

func (Context) IsCheckTx

func (c Context) IsCheckTx() bool

func (Context) IsZero

func (c Context) IsZero() bool

is context nil

func (Context) KVStore

func (c Context) KVStore(key StoreKey) KVStore

KVStore fetches a KVStore from the MultiStore.

func (Context) TxBytes

func (c Context) TxBytes() []byte

func (Context) Value

func (c Context) Value(key interface{}) interface{}

context value for the provided key

func (Context) WithBlockHeader

func (c Context) WithBlockHeader(header abci.Header) Context

func (Context) WithBlockHeight

func (c Context) WithBlockHeight(height int64) Context

func (Context) WithCacheWrapper

func (c Context) WithCacheWrapper(key interface{}, value CacheWrapper) Context

func (Context) WithChainID

func (c Context) WithChainID(chainID string) Context

func (Context) WithCloner

func (c Context) WithCloner(key interface{}, value cloner) Context

func (Context) WithInt32

func (c Context) WithInt32(key interface{}, value int32) Context

func (Context) WithIsCheckTx

func (c Context) WithIsCheckTx(isCheckTx bool) Context

func (Context) WithMultiStore

func (c Context) WithMultiStore(ms MultiStore) Context

func (Context) WithProtoMsg

func (c Context) WithProtoMsg(key interface{}, value proto.Message) Context

func (Context) WithString

func (c Context) WithString(key interface{}, value string) Context

func (Context) WithTxBytes

func (c Context) WithTxBytes(txBytes []byte) Context

func (Context) WithUint32

func (c Context) WithUint32(key interface{}, value uint32) Context

func (Context) WithUint64

func (c Context) WithUint64(key interface{}, value uint64) Context

func (Context) WithValue

func (c Context) WithValue(key interface{}, value interface{}) Context

nolint

type EndBlocker

type EndBlocker func(ctx Context, req abci.RequestEndBlock) abci.ResponseEndBlock

run code after the transactions in a block and return updates to the validator set

type Error

type Error interface {
	Error() string
	ABCICode() CodeType
	ABCILog() string
	Trace(msg string) Error
	TraceCause(cause error, msg string) Error
	Cause() error
	Result() Result
	QueryResult() abci.ResponseQuery
}

sdk Error type

func ErrGenesisParse

func ErrGenesisParse(msg string) Error

func ErrInsufficientCoins

func ErrInsufficientCoins(msg string) Error

func ErrInsufficientFunds

func ErrInsufficientFunds(msg string) Error

func ErrInternal

func ErrInternal(msg string) Error

nolint

func ErrInvalidAddress

func ErrInvalidAddress(msg string) Error

func ErrInvalidCoins

func ErrInvalidCoins(msg string) Error

func ErrInvalidPubKey

func ErrInvalidPubKey(msg string) Error

func ErrInvalidSequence

func ErrInvalidSequence(msg string) Error

func ErrTxDecode

func ErrTxDecode(msg string) Error

func ErrUnauthorized

func ErrUnauthorized(msg string) Error

func ErrUnknownAddress

func ErrUnknownAddress(msg string) Error

func ErrUnknownRequest

func ErrUnknownRequest(msg string) Error

func NewError

func NewError(code CodeType, msg string) Error

type Handler

type Handler func(ctx Context, msg Msg) Result

core function variable which application runs for transactions

type InitChainer

type InitChainer func(ctx Context, req abci.RequestInitChain) abci.ResponseInitChain

initialize application state at genesis

type InitGenesis

type InitGenesis func(ctx Context, data json.RawMessage) error

Run only once on chain initialization, should write genesis state to store or throw an error if some required information was not provided, in which case the application will panic.

type Iterator

type Iterator = dbm.Iterator

Alias iterator to db's Iterator for convenience.

type KVStore

type KVStore interface {
	Store

	// Get returns nil iff key doesn't exist. Panics on nil key.
	Get(key []byte) []byte

	// Has checks if a key exists. Panics on nil key.
	Has(key []byte) bool

	// Set sets the key. Panics on nil key.
	Set(key, value []byte)

	// Delete deletes the key. Panics on nil key.
	Delete(key []byte)

	// Iterator over a domain of keys in ascending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	Iterator(start, end []byte) Iterator

	// Iterator over a domain of keys in descending order. End is exclusive.
	// Start must be greater than end, or the Iterator is invalid.
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	ReverseIterator(start, end []byte) Iterator
}

KVStore is a simple interface to get/set data

type KVStoreKey

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

KVStoreKey is used for accessing substores. Only the pointer value should ever be used - it functions as a capabilities key.

func NewKVStoreKey

func NewKVStoreKey(name string) *KVStoreKey

NewKVStoreKey returns a new pointer to a KVStoreKey. Use a pointer so keys don't collide.

func (*KVStoreKey) Name

func (key *KVStoreKey) Name() string

func (*KVStoreKey) String

func (key *KVStoreKey) String() string

type Msg

type Msg interface {

	// Return the message type.
	// Must be alphanumeric or empty.
	Type() string

	// Get some property of the Msg.
	Get(key interface{}) (value interface{})

	// Get the canonical byte representation of the Msg.
	GetSignBytes() []byte

	// ValidateBasic does a simple validation check that
	// doesn't require access to any other information.
	ValidateBasic() Error

	// Signers returns the addrs of signers that must sign.
	// CONTRACT: All signatures must be present to be valid.
	// CONTRACT: Returns addrs in some deterministic order.
	GetSigners() []Address
}

Transactions messages must fulfill the Msg

type MultiStore

type MultiStore interface {
	Store

	// Cache wrap MultiStore.
	// NOTE: Caller should probably not call .Write() on each, but
	// call CacheMultiStore.Write().
	CacheMultiStore() CacheMultiStore

	// Convenience for fetching substores.
	GetStore(StoreKey) Store
	GetKVStore(StoreKey) KVStore
}

type Op

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

XXX add description

type Queryable

type Queryable interface {
	Query(abci.RequestQuery) abci.ResponseQuery
}

Queryable allows a Store to expose internal state to the abci.Query interface. Multistore can route requests to the proper Store.

This is an optional, but useful extension to any CommitStore

type Rat

type Rat struct {
	Num   int64 `json:"num"`
	Denom int64 `json:"denom"`
}

Rat - extend big.Rat NOTE: never use new(Rat) or else we will panic unmarshalling into the nil embedded big.Rat

func NewRat

func NewRat(num int64, denom ...int64) Rat

New - create a new Rat from integers func NewRat(Numerator int64, Denominator ...int64) Rat { switch len(Denominator) { case 0: return Rat{big.NewRat(Numerator, 1)} case 1: return Rat{big.NewRat(Numerator, Denominator[0])} default: panic("improper use of New, can only have one denominator") } }

func ToRat

func ToRat(r *big.Rat) Rat

nolint

func (Rat) Add

func (r Rat) Add(r2 Rat) Rat

func (Rat) Equal

func (r Rat) Equal(r2 Rat) bool

func (Rat) Evaluate

func (r Rat) Evaluate() int64

evaluate the rational using bankers rounding

func (Rat) EvaluateBig

func (r Rat) EvaluateBig() *big.Int

evaluate the rational using bankers rounding

func (Rat) GT

func (r Rat) GT(r2 Rat) bool

func (Rat) GetRat

func (r Rat) GetRat() *big.Rat

func (Rat) Inv

func (r Rat) Inv() Rat

func (Rat) IsZero

func (r Rat) IsZero() bool

func (Rat) LT

func (r Rat) LT(r2 Rat) bool

func (Rat) Mul

func (r Rat) Mul(r2 Rat) Rat

func (Rat) Quo

func (r Rat) Quo(r2 Rat) Rat

func (Rat) Round

func (r Rat) Round(precisionFactor int64) Rat

round Rat with the provided precisionFactor

func (Rat) Sub

func (r Rat) Sub(r2 Rat) Rat

func (Rat) ToLeftPadded

func (r Rat) ToLeftPadded(totalDigits int8) string

TODO panic if negative or if totalDigits < len(initStr)??? evaluate as an integer and return left padded string

type Result

type Result struct {

	// Code is the response code, is stored back on the chain.
	Code CodeType

	// Data is any data returned from the app.
	Data []byte

	// Log is just debug information. NOTE: nondeterministic.
	Log string

	// GasWanted is the maximum units of work we allow this tx to perform.
	GasWanted int64

	// GasUsed is the amount of gas actually consumed. NOTE: not used.
	GasUsed int64

	// Tx fee amount and denom.
	FeeAmount int64
	FeeDenom  string

	// Changes to the validator set.
	ValidatorUpdates []abci.Validator

	// Tags are used for transaction indexing and pubsub.
	Tags []cmn.KVPair
}

Result is the union of ResponseDeliverTx and ResponseCheckTx.

func (Result) IsOK

func (res Result) IsOK() bool

TODO: In the future, more codes may be OK.

type StdFee

type StdFee struct {
	Amount Coins `json"amount"`
	Gas    int64 `json"gas"`
}

StdFee includes the amount of coins paid in fees and the maximum gas to be used by the transaction. The ratio yields an effective "gasprice", which must be above some miminum to be accepted into the mempool.

func NewStdFee

func NewStdFee(gas int64, amount ...Coin) StdFee

func (StdFee) Bytes

func (fee StdFee) Bytes() []byte

fee bytes for signing later

type StdSignDoc

type StdSignDoc struct {
	ChainID   string  `json:"chain_id"`
	Sequences []int64 `json:"sequences"`
	FeeBytes  []byte  `json:"fee_bytes"`
	MsgBytes  []byte  `json:"msg_bytes"`
	AltBytes  []byte  `json:"alt_bytes"`
}

StdSignDoc is replay-prevention structure. It includes the result of msg.GetSignBytes(), as well as the ChainID (prevent cross chain replay) and the Sequence numbers for each signature (prevent inchain replay and enforce tx ordering per account).

type StdSignMsg

type StdSignMsg struct {
	ChainID   string
	Sequences []int64
	Fee       StdFee
	Msg       Msg
}

StdSignMsg is a convenience structure for passing along a Msg with the other requirements for a StdSignDoc before it is signed. For use in the CLI.

func (StdSignMsg) Bytes

func (msg StdSignMsg) Bytes() []byte

get message bytes

type StdSignature

type StdSignature struct {
	crypto.PubKey    `json:"pub_key"` // optional
	crypto.Signature `json:"signature"`
	Sequence         int64 `json:"sequence"`
}

Standard Signature

type StdTx

type StdTx struct {
	Msg        `json:"msg"`
	Fee        StdFee         `json:"fee"`
	Signatures []StdSignature `json:"signatures"`
}

StdTx is a standard way to wrap a Msg with Fee and Signatures. NOTE: the first signature is the FeePayer (Signatures must not be nil).

func NewStdTx

func NewStdTx(msg Msg, fee StdFee, sigs []StdSignature) StdTx

func (StdTx) GetMsg

func (tx StdTx) GetMsg() Msg

nolint

func (StdTx) GetSignatures

func (tx StdTx) GetSignatures() []StdSignature

type Store

type Store interface {
	GetStoreType() StoreType
	CacheWrapper
}

type StoreKey

type StoreKey interface {
	Name() string
	String() string
}

StoreKey is a key used to index stores in a MultiStore.

type StoreType

type StoreType int

kind of store

const (
	//nolint
	StoreTypeMulti StoreType = iota
	StoreTypeDB
	StoreTypeIAVL
)

type TestMsg

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

msg type for testing

func NewTestMsg

func NewTestMsg(addrs ...Address) *TestMsg

func (*TestMsg) Get

func (msg *TestMsg) Get(key interface{}) (value interface{})

func (*TestMsg) GetSignBytes

func (msg *TestMsg) GetSignBytes() []byte

func (*TestMsg) GetSigners

func (msg *TestMsg) GetSigners() []Address

func (*TestMsg) Type

func (msg *TestMsg) Type() string

nolint

func (*TestMsg) ValidateBasic

func (msg *TestMsg) ValidateBasic() Error

type Tx

type Tx interface {

	// Gets the Msg.
	GetMsg() Msg

	// Signatures returns the signature of signers who signed the Msg.
	// CONTRACT: Length returned is same as length of
	// pubkeys returned from MsgKeySigners, and the order
	// matches.
	// CONTRACT: If the signature is missing (ie the Msg is
	// invalid), then the corresponding signature is
	// .Empty().
	GetSignatures() []StdSignature
}

Transactions objects must fulfill the Tx

type TxDecoder

type TxDecoder func(txBytes []byte) (Tx, Error)

TxDeocder unmarshals transaction bytes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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