coin

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2017 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

nolint

Index

Constants

View Source
const (
	//NameCoin - name space of the coin module
	NameCoin = "coin"
	// CostSend is GasAllocation per input/output
	CostSend = uint64(10)
	// CostCredit is GasAllocation of a credit allocation
	CostCredit = uint64(20)
)
View Source
const (
	ByteSend   = 0x20
	TypeSend   = NameCoin + "/send"
	ByteCredit = 0x21
	TypeCredit = NameCoin + "/credit"
)

we reserve the 0x20-0x3f range for standard modules

Variables

This section is empty.

Functions

func ChainAddr

func ChainAddr(addr sdk.Actor) sdk.Actor

ChainAddr collapses all addresses from another chain into one, so we can keep an over-all balance

TODO: is there a better way to do this?

func ErrInsufficientCredit

func ErrInsufficientCredit() errors.TMError

func ErrInsufficientFunds

func ErrInsufficientFunds() errors.TMError

func ErrInvalidAddress

func ErrInvalidAddress() errors.TMError

func ErrInvalidCoins

func ErrInvalidCoins() errors.TMError

func ErrNoAccount

func ErrNoAccount() errors.TMError

func ErrNoInputs

func ErrNoInputs() errors.TMError

func ErrNoOutputs

func ErrNoOutputs() errors.TMError

func IsAddressErr

func IsAddressErr(err error) bool

func IsCoinErr

func IsCoinErr(err error) bool

func IsInputErr

func IsInputErr(err error) bool

here are some generic handlers to grab classes of errors based on code

func IsInsufficientCreditErr

func IsInsufficientCreditErr(err error) bool

func IsInsufficientFundsErr

func IsInsufficientFundsErr(err error) bool

func IsInvalidAddressErr

func IsInvalidAddressErr(err error) bool

func IsInvalidCoinsErr

func IsInvalidCoinsErr(err error) bool

func IsNoAccountErr

func IsNoAccountErr(err error) bool

func IsNoInputsErr

func IsNoInputsErr(err error) bool

func IsNoOutputsErr

func IsNoOutputsErr(err error) bool

func IsOutputErr

func IsOutputErr(err error) bool

func NewCreditTx

func NewCreditTx(debitor sdk.Actor, credit Coins) sdk.Tx

NewCreditTx - modify the credit granted to a given account

func NewSendOneTx

func NewSendOneTx(sender, recipient sdk.Actor, amount Coins) sdk.Tx

NewSendOneTx is a helper for the standard (?) case where there is exactly one sender and one recipient

func NewSendTx

func NewSendTx(in []TxInput, out []TxOutput) sdk.Tx

NewSendTx - construct arbitrary multi-in, multi-out sendtx

Types

type Account

type Account struct {
	// Coins is how much is on the account
	Coins Coins `json:"coins"`
	// Credit is how much has been "fronted" to the account
	// (this is usually 0 except for trusted chains)
	Credit Coins `json:"credit"`
}

Account - coin account structure

func GetAccount

func GetAccount(store state.SimpleDB, addr sdk.Actor) (Account, error)

GetAccount - Get account from store and address

type AccountWithKey

type AccountWithKey struct {
	Key      crypto.PrivKey
	Sequence uint32
	Account
}

AccountWithKey is a helper for tests, that includes and account along with the private key to access it.

func NewAccountWithKey

func NewAccountWithKey(coins Coins) *AccountWithKey

NewAccountWithKey creates an account with the given balance and a random private key

func (*AccountWithKey) Actor

func (a *AccountWithKey) Actor() sdk.Actor

Actor returns the basecoin actor associated with this account

func (*AccountWithKey) Address

func (a *AccountWithKey) Address() []byte

Address returns the public key address for this account

func (*AccountWithKey) MakeOption

func (a *AccountWithKey) MakeOption() string

MakeOption returns a string to use with InitState to initialize this account

This is intended for use in test cases

func (*AccountWithKey) NextSequence

func (a *AccountWithKey) NextSequence() uint32

NextSequence returns the next sequence to sign with

type Coin

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

Coin hold some amount of one currency

func ParseCoin

func ParseCoin(str string) (Coin, 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) 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) IsZero

func (coin Coin) IsZero() bool

IsZero returns if this represents no money

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 ChangeCoins

func ChangeCoins(store state.SimpleDB, addr sdk.Actor, coins Coins) (Coins, error)

ChangeCoins changes the money, returns error if it would be negative

func CheckCoins

func CheckCoins(store state.SimpleDB, addr sdk.Actor, coins Coins) (Coins, error)

CheckCoins makes sure there are funds, but doesn't change anything

func ParseCoins

func ParseCoins(str string) (Coins, error)

ParseCoins will parse out a list of coins separated by commas. If nothing is provided, it returns an empty array

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

func (coins Coins) IsNonnegative() bool

IsNonnegative 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

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 to sets of coins

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

func (Coins) Sort

func (coins Coins) Sort()

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 CreditTx

type CreditTx struct {
	Debitor sdk.Actor `json:"debitor"`
	// Credit is the amount to change the credit...
	// This may be negative to remove some over-issued credit,
	// but can never bring the credit or the balance to negative
	Credit Coins `json:"credit"`
}

CreditTx - this allows a special issuer to give an account credit Satisfies: TxInner

func (CreditTx) ValidateBasic

func (tx CreditTx) ValidateBasic() error

ValidateBasic - used to satisfy TxInner

func (CreditTx) Wrap

func (tx CreditTx) Wrap() sdk.Tx

Wrap - used to satisfy TxInner

type GenesisAccount

type GenesisAccount struct {
	Address data.Bytes `json:"address"`
	// this from types.Account (don't know how to embed this properly)
	PubKey  crypto.PubKey `json:"pub_key"` // May be nil, if not known.
	Balance Coins         `json:"coins"`
}

GenesisAccount - genesis account parameters

func (GenesisAccount) GetAddr

func (g GenesisAccount) GetAddr() ([]byte, error)

GetAddr - Get the address of the genesis account

func (GenesisAccount) ToAccount

func (g GenesisAccount) ToAccount() Account

ToAccount - GenesisAccount struct to a basecoin Account

type Handler

type Handler struct {
	stack.PassInitValidate
}

Handler includes an accountant

func NewHandler

func NewHandler() Handler

NewHandler - new accountant handler for the coin module

func (Handler) AssertDispatcher

func (Handler) AssertDispatcher()

AssertDispatcher - to fulfill Dispatchable interface

func (Handler) CheckTx

func (h Handler) CheckTx(ctx sdk.Context, store state.SimpleDB,
	tx sdk.Tx, _ sdk.Checker) (res sdk.CheckResult, err error)

CheckTx checks if there is enough money in the account

func (Handler) DeliverTx

func (h Handler) DeliverTx(ctx sdk.Context, store state.SimpleDB,
	tx sdk.Tx, cb sdk.Deliver) (res sdk.DeliverResult, err error)

DeliverTx moves the money

func (Handler) InitState

func (h Handler) InitState(l log.Logger, store state.SimpleDB,
	module, key, value string, cb sdk.InitStater) (log string, err error)

InitState - sets the genesis account balance

func (Handler) Name

func (Handler) Name() string

Name - return name space

type HandlerInfo

type HandlerInfo struct {
	Issuer sdk.Actor `json:"issuer"`
}

HandlerInfo - this is global info on the coin handler

type SendTx

type SendTx struct {
	Inputs  []TxInput  `json:"inputs"`
	Outputs []TxOutput `json:"outputs"`
}

SendTx - high level transaction of the coin module Satisfies: TxInner

func (SendTx) String

func (tx SendTx) String() string

func (SendTx) ValidateBasic

func (tx SendTx) ValidateBasic() error

ValidateBasic - validate the send transaction

func (SendTx) Wrap

func (tx SendTx) Wrap() sdk.Tx

Wrap - used to satisfy TxInner

type TxInput

type TxInput struct {
	Address sdk.Actor `json:"address"`
	Coins   Coins     `json:"coins"`
}

TxInput - expected coin movement outputs, used with SendTx

func NewTxInput

func NewTxInput(addr sdk.Actor, coins Coins) TxInput

NewTxInput - create a transaction input, used with SendTx

func (TxInput) String

func (txIn TxInput) String() string

func (TxInput) ValidateBasic

func (txIn TxInput) ValidateBasic() error

ValidateBasic - validate transaction input

type TxOutput

type TxOutput struct {
	Address sdk.Actor `json:"address"`
	Coins   Coins     `json:"coins"`
}

TxOutput - expected coin movement output, used with SendTx

func NewTxOutput

func NewTxOutput(addr sdk.Actor, coins Coins) TxOutput

NewTxOutput - create a transaction output, used with SendTx

func (TxOutput) String

func (txOut TxOutput) String() string

func (TxOutput) ValidateBasic

func (txOut TxOutput) ValidateBasic() error

ValidateBasic - validate transaction output

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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