types

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2017 License: Apache-2.0 Imports: 14 Imported by: 19

Documentation

Index

Constants

View Source
const (
	// Account transactions
	TxTypeSend = byte(0x01)
	TxTypeApp  = byte(0x02)
	TxNameSend = "send"
	TxNameApp  = "app"
)

Types of Tx implementations

Variables

This section is empty.

Functions

func AccountKey added in v0.5.0

func AccountKey(addr []byte) []byte

func LegibleBytes

func LegibleBytes(data []byte) string

func SetAccount added in v0.5.0

func SetAccount(store KVStore, addr []byte, acc *Account)

func SignTx added in v0.4.0

func SignTx(chainID string, tx *SendTx, accs ...PrivAccount)

func TxID

func TxID(chainID string, tx Tx) []byte

Types

type Account

type Account struct {
	PubKey   crypto.PubKey `json:"pub_key"` // May be nil, if not known.
	Sequence int           `json:"sequence"`
	Balance  Coins         `json:"coins"`
}

func GetAccount added in v0.5.0

func GetAccount(store KVStore, addr []byte) *Account

func (*Account) Copy

func (acc *Account) Copy() *Account

func (*Account) String

func (acc *Account) String() string

type AccountGetter

type AccountGetter interface {
	GetAccount(addr []byte) *Account
}

type AccountGetterSetter

type AccountGetterSetter interface {
	GetAccount(addr []byte) *Account
	SetAccount(addr []byte, acc *Account)
}

type AccountSetter

type AccountSetter interface {
	SetAccount(addr []byte, acc *Account)
}

type AppTx

type AppTx struct {
	Gas   int64           `json:"gas"`   // Gas
	Fee   Coin            `json:"fee"`   // Fee
	Name  string          `json:"type"`  // Which plugin
	Input TxInput         `json:"input"` // Hmmm do we want coins?
	Data  json.RawMessage `json:"data"`
}

func (*AppTx) AssertIsTx

func (_ *AppTx) AssertIsTx()

func (*AppTx) SetSignature

func (tx *AppTx) SetSignature(sig crypto.Signature) bool

func (*AppTx) SignBytes

func (tx *AppTx) SignBytes(chainID string) []byte

func (*AppTx) String

func (tx *AppTx) String() string

type CallContext

type CallContext struct {
	CallerAddress []byte   // Caller's Address (hash of PubKey)
	CallerAccount *Account // Caller's Account, w/ fee & TxInputs deducted
	Coins         Coins    // The coins that the caller wishes to spend, excluding fees
}

func NewCallContext

func NewCallContext(callerAddress []byte, callerAccount *Account, coins Coins) CallContext

type Coin

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

func ParseCoin added in v0.4.0

func ParseCoin(str string) (Coin, error)

func (Coin) String

func (coin Coin) String() string

type Coins

type Coins []Coin

func ParseCoins added in v0.4.0

func ParseCoins(str string) (Coins, error)

func (Coins) IsEqual

func (coinsA Coins) IsEqual(coinsB Coins) bool

func (Coins) IsGTE

func (coinsA Coins) IsGTE(coinsB Coins) bool

func (Coins) IsNonnegative

func (coins Coins) IsNonnegative() bool

func (Coins) IsPositive

func (coins Coins) IsPositive() bool

func (Coins) IsValid

func (coins Coins) IsValid() bool

Must be sorted, and not have 0 amounts

func (Coins) IsZero

func (coins Coins) IsZero() bool

func (Coins) Len added in v0.5.0

func (c Coins) Len() int

func (Coins) Less added in v0.5.0

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

func (Coins) Minus

func (coinsA Coins) Minus(coinsB Coins) Coins

func (Coins) Negative

func (coins Coins) Negative() Coins

func (Coins) Plus

func (coinsA Coins) Plus(coinsB Coins) Coins

TODO: handle empty coins! Currently appends an empty coin ...

func (Coins) Sort added in v0.5.0

func (c Coins) Sort()

func (Coins) String added in v0.4.0

func (coins Coins) String() string

func (Coins) Swap added in v0.5.0

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

type KVCache

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

A Cache that enforces deterministic sync order.

func NewKVCache

func NewKVCache(store KVStore) *KVCache

NOTE: If store is nil, creates a new MemKVStore

func (*KVCache) ClearLogLines

func (kvc *KVCache) ClearLogLines()

func (*KVCache) Get

func (kvc *KVCache) Get(key []byte) (value []byte)

func (*KVCache) GetLogLines

func (kvc *KVCache) GetLogLines() []string

func (*KVCache) Reset

func (kvc *KVCache) Reset() *KVCache

func (*KVCache) Set

func (kvc *KVCache) Set(key []byte, value []byte)

func (*KVCache) SetLogging

func (kvc *KVCache) SetLogging()

func (*KVCache) Sync

func (kvc *KVCache) Sync()

Update the store with the values from the cache

type KVStore

type KVStore interface {
	Set(key, value []byte)
	Get(key []byte) (value []byte)
}

type MemKVStore

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

func NewMemKVStore

func NewMemKVStore() *MemKVStore

func (*MemKVStore) Get

func (mkv *MemKVStore) Get(key []byte) (value []byte)

func (*MemKVStore) Set

func (mkv *MemKVStore) Set(key []byte, value []byte)

type Plugin

type Plugin interface {

	// Name of this plugin, should be short.
	Name() string

	// Run a transaction from ABCI DeliverTx
	RunTx(store KVStore, ctx CallContext, txBytes []byte) (res abci.Result)

	// Other ABCI message handlers
	SetOption(store KVStore, key, value string) (log string)
	InitChain(store KVStore, vals []*abci.Validator)
	BeginBlock(store KVStore, hash []byte, header *abci.Header)
	EndBlock(store KVStore, height uint64) abci.ResponseEndBlock
}

type Plugins

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

func NewPlugins

func NewPlugins() *Plugins

func (*Plugins) GetByName

func (pgz *Plugins) GetByName(name string) Plugin

func (*Plugins) GetList

func (pgz *Plugins) GetList() []Plugin

func (*Plugins) RegisterPlugin

func (pgz *Plugins) RegisterPlugin(plugin Plugin)

type PrivAccount

type PrivAccount struct {
	crypto.PrivKey
	Account
}

func MakeAcc added in v0.4.0

func MakeAcc(secret string) PrivAccount

func PrivAccountFromSecret

func PrivAccountFromSecret(secret string) PrivAccount

Creates a PrivAccount from secret. The amount is not set.

func RandAccounts

func RandAccounts(num int, minAmount int64, maxAmount int64) []PrivAccount

Make `num` random accounts

type SendTx

type SendTx struct {
	Gas     int64      `json:"gas"` // Gas
	Fee     Coin       `json:"fee"` // Fee
	Inputs  []TxInput  `json:"inputs"`
	Outputs []TxOutput `json:"outputs"`
}

func MakeSendTx added in v0.5.0

func MakeSendTx(seq int, accOut PrivAccount, accsIn ...PrivAccount) *SendTx

func (*SendTx) AssertIsTx

func (_ *SendTx) AssertIsTx()

func (*SendTx) SetSignature

func (tx *SendTx) SetSignature(addr []byte, sig crypto.Signature) bool

func (*SendTx) SignBytes

func (tx *SendTx) SignBytes(chainID string) []byte

func (*SendTx) String

func (tx *SendTx) String() string

type Tx

type Tx interface {
	AssertIsTx()
	SignBytes(chainID string) []byte
}

Tx (Transaction) is an atomic operation on the ledger state.

Account Types:

  • SendTx Send coins to address
  • AppTx Send a msg to a contract that runs in the vm

type TxInput

type TxInput struct {
	Address   data.Bytes       `json:"address"`   // Hash of the PubKey
	Coins     Coins            `json:"coins"`     //
	Sequence  int              `json:"sequence"`  // Must be 1 greater than the last committed TxInput
	Signature crypto.Signature `json:"signature"` // Depends on the PubKey type and the whole Tx
	PubKey    crypto.PubKey    `json:"pub_key"`   // Is present iff Sequence == 0
}

func Accs2TxInputs added in v0.4.0

func Accs2TxInputs(seq int, accs ...PrivAccount) []TxInput

func NewTxInput

func NewTxInput(pubKey crypto.PubKey, coins Coins, sequence int) TxInput

func (TxInput) String

func (txIn TxInput) String() string

func (TxInput) ValidateBasic

func (txIn TxInput) ValidateBasic() abci.Result

type TxOutput

type TxOutput struct {
	Address data.Bytes `json:"address"` // Hash of the PubKey
	Coins   Coins      `json:"coins"`   //
}

func Accs2TxOutputs added in v0.4.0

func Accs2TxOutputs(accs ...PrivAccount) []TxOutput

turn a list of accounts into basic list of transaction outputs

func (TxOutput) ChainAndAddress added in v0.5.0

func (txOut TxOutput) ChainAndAddress() ([]byte, []byte, abci.Result)

An output destined for another chain may be formatted as `chainID/address`. ChainAndAddress returns the chainID prefix and the address. If there is no chainID prefix, the first returned value is nil.

func (TxOutput) String

func (txOut TxOutput) String() string

func (TxOutput) ValidateBasic

func (txOut TxOutput) ValidateBasic() abci.Result

type TxS

type TxS struct {
	Tx `json:"unwrap"`
}

TxS add json serialization to Tx

func (TxS) MarshalJSON

func (p TxS) MarshalJSON() ([]byte, error)

func (*TxS) UnmarshalJSON

func (p *TxS) UnmarshalJSON(data []byte) (err error)

Jump to

Keyboard shortcuts

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