types

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ABCI error codes
	ABCICodeOK ABCICodeType = 0

	// Base error codes
	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
	CodeOutOfGas          CodeType = 12
	CodeMemoTooLarge      CodeType = 13

	// CodespaceRoot is a codespace for error codes in this file only.
	// Notice that 0 is an "unset" codespace, which can be overridden with
	// Error.WithDefaultCodespace().
	CodespaceUndefined CodespaceType = 0
	CodespaceRoot      CodespaceType = 1

	// Maximum reservable codespace (2^16 - 1)
	MaximumCodespace CodespaceType = 65535
)

SDK error codes

Variables

This section is empty.

Functions

func AccAddressFromBech32

func AccAddressFromBech32(address string) (addr types.Address, err error)

create an AccAddress from a bech32 string

func AccAddressFromHex

func AccAddressFromHex(address string) (addr types.Address, err error)
"fmt"

"github.com/QOSGroup/qbase/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/encoding/amino"

"github.com/tendermint/tendermint/libs/bech32"

)

// Bech32 prefixes const (

// expected address length
AddrLen = 20

// Bech32 prefixes
Bech32PrefixAccPub  = "pub"
Bech32PrefixValAddr = "cosmosvaladdr"
Bech32PrefixValPub  = "cosmosvalpub"

)

//__________________________________________________________

// AccAddress a wrapper around bytes meant to represent an account address // When marshaled to a string or json, it uses bech32 type AccAddress []byte

create an AccAddress from a hex string

func CodeToDefaultMsg

func CodeToDefaultMsg(code CodeType) string

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

func GetFromBech32

func GetFromBech32(bech32str, prefix string) ([]byte, error)

// Marshal needed for protobuf compatibility

func (bz AccAddress) Marshal() ([]byte, error) {
	return bz, nil
}

// Unmarshal needed for protobuf compatibility

func (bz *AccAddress) Unmarshal(data []byte) error {
	*bz = data
	return nil
}

// Marshals to JSON using Bech32

func (bz AccAddress) MarshalJSON() ([]byte, error) {
	return json.Marshal(bz.String())
}

// Unmarshals from JSON assuming Bech32 encoding

func (bz *AccAddress) UnmarshalJSON(data []byte) error {
	var s string
	err := json.Unmarshal(data, &s)
	if err != nil {
		return nil
	}

	bz2, err := AccAddressFromBech32(s)
	if err != nil {
		return err
	}
	*bz = bz2
	return nil
}

// Allow it to fulfill various interfaces in light-client, etc...

func (bz AccAddress) Bytes() []byte {
	return bz
}
func (bz AccAddress) String() string {
	bech32Addr, err := bech32.ConvertAndEncode(types.PREF_ADD, bz.Bytes())
	if err != nil {
		panic(err)
	}
	return bech32Addr
}

// For Printf / Sprintf, returns bech32 when using %s

func (bz AccAddress) Format(s fmt.State, verb rune) {
	switch verb {
	case 's':
		s.Write([]byte(fmt.Sprintf("%s", bz.String())))
	case 'p':
		s.Write([]byte(fmt.Sprintf("%p", bz)))
	default:
		s.Write([]byte(fmt.Sprintf("%X", []byte(bz))))
	}
}

//__________________________________________________________

// AccAddress a wrapper around bytes meant to represent a validator address // (from over ABCI). When marshaled to a string or json, it uses bech32 type ValAddress []byte

// create a ValAddress from a hex string

func ValAddressFromHex(address string) (addr ValAddress, err error) {
	if len(address) == 0 {
		return addr, errors.New("decoding bech32 address failed: must provide an address")
	}
	bz, err := hex.DecodeString(address)
	if err != nil {
		return nil, err
	}
	return ValAddress(bz), nil
}

// create a ValAddress from a bech32 string

func ValAddressFromBech32(address string) (addr ValAddress, err error) {
	bz, err := GetFromBech32(address, Bech32PrefixValAddr)
	if err != nil {
		return nil, err
	}
	return ValAddress(bz), nil
}

// Marshal needed for protobuf compatibility

func (bz ValAddress) Marshal() ([]byte, error) {
	return bz, nil
}

// Unmarshal needed for protobuf compatibility

func (bz *ValAddress) Unmarshal(data []byte) error {
	*bz = data
	return nil
}

// Marshals to JSON using Bech32

func (bz ValAddress) MarshalJSON() ([]byte, error) {
	return json.Marshal(bz.String())
}

// Unmarshals from JSON assuming Bech32 encoding

func (bz *ValAddress) UnmarshalJSON(data []byte) error {
	var s string
	err := json.Unmarshal(data, &s)
	if err != nil {
		return nil
	}

	bz2, err := ValAddressFromBech32(s)
	if err != nil {
		return err
	}
	*bz = bz2
	return nil
}

// Allow it to fulfill various interfaces in light-client, etc...

func (bz ValAddress) Bytes() []byte {
	return bz
}
func (bz ValAddress) String() string {
	bech32Addr, err := bech32.ConvertAndEncode(Bech32PrefixValAddr, bz.Bytes())
	if err != nil {
		panic(err)
	}
	return bech32Addr
}

// For Printf / Sprintf, returns bech32 when using %s

func (bz ValAddress) Format(s fmt.State, verb rune) {
	switch verb {
	case 's':
		s.Write([]byte(fmt.Sprintf("%s", bz.String())))
	case 'p':
		s.Write([]byte(fmt.Sprintf("%p", bz)))
	default:
		s.Write([]byte(fmt.Sprintf("%X", []byte(bz))))
	}
}

// Bech32ifyAccPub takes AccountPubKey and returns the bech32 encoded string

func Bech32ifyAccPub(pub crypto.PubKey) (string, error) {
	return bech32.ConvertAndEncode(Bech32PrefixAccPub, pub.Bytes())
}

// MustBech32ifyAccPub panics on bech32-encoding failure

func MustBech32ifyAccPub(pub crypto.PubKey) string {
	enc, err := Bech32ifyAccPub(pub)
	if err != nil {
		panic(err)
	}
	return enc
}

// Bech32ifyValPub returns the bech32 encoded string for a validator pubkey

func Bech32ifyValPub(pub crypto.PubKey) (string, error) {
	return bech32.ConvertAndEncode(Bech32PrefixValPub, pub.Bytes())
}

// MustBech32ifyValPub panics on bech32-encoding failure

func MustBech32ifyValPub(pub crypto.PubKey) string {
	enc, err := Bech32ifyValPub(pub)
	if err != nil {
		panic(err)
	}
	return enc
}

// create a Pubkey from a string

func GetAccPubKeyBech32(address string) (pk crypto.PubKey, err error) {
	bz, err := GetFromBech32(address, Bech32PrefixAccPub)
	if err != nil {
		return nil, err
	}

	pk, err = cryptoAmino.PubKeyFromBytes(bz)
	if err != nil {
		return nil, err
	}

	return pk, nil
}

// create an Pubkey from a string, panics on error

func MustGetAccPubKeyBech32(address string) (pk crypto.PubKey) {
	pk, err := GetAccPubKeyBech32(address)
	if err != nil {
		panic(err)
	}
	return pk
}

// decode a validator public key into a PubKey

func GetValPubKeyBech32(pubkey string) (pk crypto.PubKey, err error) {
	bz, err := GetFromBech32(pubkey, Bech32PrefixValPub)
	if err != nil {
		return nil, err
	}

	pk, err = cryptoAmino.PubKeyFromBytes(bz)
	if err != nil {
		return nil, err
	}

	return pk, nil
}

// create an Pubkey from a string, panics on error

func MustGetValPubKeyBech32(address string) (pk crypto.PubKey) {
	pk, err := GetValPubKeyBech32(address)
	if err != nil {
		panic(err)
	}
	return pk
}

decode a bytestring from a bech32-encoded string

Types

type ABCICodeType

type ABCICodeType uint32

ABCICodeType - combined codetype / codespace

func ToABCICode

func ToABCICode(space CodespaceType, code CodeType) ABCICodeType

get the abci code from the local code and codespace

func (ABCICodeType) IsOK

func (code ABCICodeType) IsOK() bool

IsOK - is everything okay?

type CodeType

type CodeType uint16

CodeType - code identifier within codespace

type CodespaceType

type CodespaceType uint16

CodespaceType - codespace identifier

type Coin

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

Coin hold some amount of one currency

func NewCoin

func NewCoin(denom string, amount Int) Coin

func NewInt64Coin

func NewInt64Coin(denom string, amount int64) Coin

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

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 Error

type Error interface {

	// convenience
	TraceSDK(format string, args ...interface{}) Error

	// set codespace
	WithDefaultCodespace(CodespaceType) Error

	Code() CodeType
	Codespace() CodespaceType
	ABCILog() string
	ABCICode() ABCICodeType
	Result() Result
	QueryResult() abci.ResponseQuery
	// contains filtered or unexported methods
}

sdk Error type

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 ErrMemoTooLarge

func ErrMemoTooLarge(msg string) Error

func ErrOutOfGas

func ErrOutOfGas(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(codespace CodespaceType, code CodeType, format string, args ...interface{}) Error

NewError - create an error.

type Int

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

Int wraps integer with 256 bit range bound Checks overflow, underflow and division by zero Exists in range from -(2^255-1) to 2^255-1

func MinInt

func MinInt(i1, i2 Int) Int

Return the minimum of the ints

func NewInt

func NewInt(n int64) Int

NewInt constructs Int from int64

func NewIntFromBigInt

func NewIntFromBigInt(i *big.Int) Int

NewIntFromBigInt constructs Int from big.Int

func NewIntFromString

func NewIntFromString(s string) (res Int, ok bool)

NewIntFromString constructs Int from string

func NewIntWithDecimal

func NewIntWithDecimal(n int64, dec int) Int

NewIntWithDecimal constructs Int with decimal Result value is n*10^dec

func OneInt

func OneInt() Int

OneInt returns Int value with one

func ZeroInt

func ZeroInt() Int

ZeroInt returns Int value with zero

func (Int) Add

func (i Int) Add(i2 Int) (res Int)

Add adds Int from another

func (Int) AddRaw

func (i Int) AddRaw(i2 int64) Int

AddRaw adds int64 to Int

func (Int) BigInt

func (i Int) BigInt() *big.Int

BigInt converts Int to big.Int

func (Int) Div

func (i Int) Div(i2 Int) (res Int)

Div divides Int with Int

func (Int) DivRaw

func (i Int) DivRaw(i2 int64) Int

DivRaw divides Int with int64

func (Int) Equal

func (i Int) Equal(i2 Int) bool

Equal compares two Ints

func (Int) GT

func (i Int) GT(i2 Int) bool

GT returns true if first Int is greater than second

func (Int) Int64

func (i Int) Int64() int64

Int64 converts Int to int64 Panics if the value is out of range

func (Int) IsInt64

func (i Int) IsInt64() bool

IsInt64 returns true if Int64() not panics

func (Int) IsZero

func (i Int) IsZero() bool

IsZero returns true if Int is zero

func (Int) LT

func (i Int) LT(i2 Int) bool

LT returns true if first Int is lesser than second

func (Int) MarshalAmino

func (i Int) MarshalAmino() (string, error)

MarshalAmino defines custom encoding scheme

func (Int) MarshalJSON

func (i Int) MarshalJSON() ([]byte, error)

MarshalJSON defines custom encoding scheme

func (Int) Mod

func (i Int) Mod(i2 Int) Int

Mod returns remainder after dividing with Int

func (Int) ModRaw

func (i Int) ModRaw(i2 int64) Int

ModRaw returns remainder after dividing with int64

func (Int) Mul

func (i Int) Mul(i2 Int) (res Int)

Mul multiples two Ints

func (Int) MulRaw

func (i Int) MulRaw(i2 int64) Int

MulRaw multipies Int and int64

func (Int) Neg

func (i Int) Neg() (res Int)

Neg negates Int

func (Int) Sign

func (i Int) Sign() int

Sign returns sign of Int

func (Int) String

func (i Int) String() string

Human readable string

func (Int) Sub

func (i Int) Sub(i2 Int) (res Int)

Sub subtracts Int from another

func (Int) SubRaw

func (i Int) SubRaw(i2 int64) Int

SubRaw subtracts int64 from Int

func (*Int) UnmarshalAmino

func (i *Int) UnmarshalAmino(text string) error

UnmarshalAmino defines custom decoding scheme

func (*Int) UnmarshalJSON

func (i *Int) UnmarshalJSON(bz []byte) error

UnmarshalJSON defines custom decoding scheme

type Result

type Result struct {

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

	// 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: unimplemented
	GasUsed int64

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

	// Tags are used for transaction indexing and pubsub.
	Tags types.Tags
}

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 Uint

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

Int wraps integer with 256 bit range bound Checks overflow, underflow and division by zero Exists in range from 0 to 2^256-1

func MinUint

func MinUint(i1, i2 Uint) Uint

Return the minimum of the Uints

func NewUint

func NewUint(n uint64) Uint

NewUint constructs Uint from int64

func NewUintFromBigInt

func NewUintFromBigInt(i *big.Int) Uint

NewUintFromBigUint constructs Uint from big.Uint

func NewUintFromString

func NewUintFromString(s string) (res Uint, ok bool)

NewUintFromString constructs Uint from string

func NewUintWithDecimal

func NewUintWithDecimal(n uint64, dec int) Uint

NewUintWithDecimal constructs Uint with decimal Result value is n*10^dec

func OneUint

func OneUint() Uint

OneUint returns Uint value with one

func ZeroUint

func ZeroUint() Uint

ZeroUint returns Uint value with zero

func (Uint) Add

func (i Uint) Add(i2 Uint) (res Uint)

Add adds Uint from another

func (Uint) AddRaw

func (i Uint) AddRaw(i2 uint64) Uint

AddRaw adds uint64 to Uint

func (Uint) BigInt

func (i Uint) BigInt() *big.Int

BigInt converts Uint to big.Unt

func (Uint) Div

func (i Uint) Div(i2 Uint) (res Uint)

Div divides Uint with Uint

func (Uint) DivRaw

func (i Uint) DivRaw(i2 uint64) Uint

Div divides Uint with uint64

func (Uint) Equal

func (i Uint) Equal(i2 Uint) bool

Equal compares two Uints

func (Uint) GT

func (i Uint) GT(i2 Uint) bool

GT returns true if first Uint is greater than second

func (Uint) IsUint64

func (i Uint) IsUint64() bool

IsUint64 returns true if Uint64() not panics

func (Uint) IsZero

func (i Uint) IsZero() bool

IsZero returns true if Uint is zero

func (Uint) LT

func (i Uint) LT(i2 Uint) bool

LT returns true if first Uint is lesser than second

func (Uint) MarshalAmino

func (i Uint) MarshalAmino() (string, error)

MarshalAmino defines custom encoding scheme

func (Uint) MarshalJSON

func (i Uint) MarshalJSON() ([]byte, error)

MarshalJSON defines custom encoding scheme

func (Uint) Mod

func (i Uint) Mod(i2 Uint) Uint

Mod returns remainder after dividing with Uint

func (Uint) ModRaw

func (i Uint) ModRaw(i2 uint64) Uint

ModRaw returns remainder after dividing with uint64

func (Uint) Mul

func (i Uint) Mul(i2 Uint) (res Uint)

Mul multiples two Uints

func (Uint) MulRaw

func (i Uint) MulRaw(i2 uint64) Uint

MulRaw multipies Uint and uint64

func (Uint) Sign

func (i Uint) Sign() int

Sign returns sign of Uint

func (Uint) String

func (i Uint) String() string

Human readable string

func (Uint) Sub

func (i Uint) Sub(i2 Uint) (res Uint)

Sub subtracts Uint from another

func (Uint) SubRaw

func (i Uint) SubRaw(i2 uint64) Uint

SubRaw subtracts uint64 from Uint

func (Uint) Uint64

func (i Uint) Uint64() uint64

Uint64 converts Uint to uint64 Panics if the value is out of range

func (*Uint) UnmarshalAmino

func (i *Uint) UnmarshalAmino(text string) error

UnmarshalAmino defines custom decoding scheme

func (*Uint) UnmarshalJSON

func (i *Uint) UnmarshalJSON(bz []byte) error

UnmarshalJSON defines custom decoding scheme

Jump to

Keyboard shortcuts

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