Documentation
¶
Index ¶
- Constants
- func AccAddressFromBech32(address string) (addr types.Address, err error)
- func AccAddressFromHex(address string) (addr types.Address, err error)
- func CodeToDefaultMsg(code CodeType) string
- func GetFromBech32(bech32str, prefix string) ([]byte, error)
- type ABCICodeType
- type CodeType
- type CodespaceType
- type Coin
- func (coin Coin) IsEqual(other Coin) bool
- func (coin Coin) IsGTE(other Coin) bool
- func (coin Coin) IsNotNegative() bool
- func (coin Coin) IsPositive() bool
- func (coin Coin) IsZero() bool
- func (coin Coin) Minus(coinB Coin) Coin
- func (coin Coin) Plus(coinB Coin) Coin
- func (coin Coin) SameDenomAs(other Coin) bool
- func (coin Coin) String() string
- type Coins
- func (coins Coins) AmountOf(denom string) Int
- func (coins Coins) IsEqual(coinsB Coins) bool
- func (coins Coins) IsGTE(coinsB Coins) bool
- func (coins Coins) IsNotNegative() bool
- func (coins Coins) IsPositive() bool
- func (coins Coins) IsValid() bool
- func (coins Coins) IsZero() bool
- func (coins Coins) Len() int
- func (coins Coins) Less(i, j int) bool
- func (coins Coins) Minus(coinsB Coins) Coins
- func (coins Coins) Negative() Coins
- func (coins Coins) Plus(coinsB Coins) Coins
- func (coins Coins) Sort() Coins
- func (coins Coins) String() string
- func (coins Coins) Swap(i, j int)
- type Error
- func ErrInsufficientCoins(msg string) Error
- func ErrInsufficientFunds(msg string) Error
- func ErrInternal(msg string) Error
- func ErrInvalidAddress(msg string) Error
- func ErrInvalidCoins(msg string) Error
- func ErrInvalidPubKey(msg string) Error
- func ErrInvalidSequence(msg string) Error
- func ErrMemoTooLarge(msg string) Error
- func ErrOutOfGas(msg string) Error
- func ErrTxDecode(msg string) Error
- func ErrUnauthorized(msg string) Error
- func ErrUnknownAddress(msg string) Error
- func ErrUnknownRequest(msg string) Error
- func NewError(codespace CodespaceType, code CodeType, format string, args ...interface{}) Error
- type Int
- func (i Int) Add(i2 Int) (res Int)
- func (i Int) AddRaw(i2 int64) Int
- func (i Int) BigInt() *big.Int
- func (i Int) Div(i2 Int) (res Int)
- func (i Int) DivRaw(i2 int64) Int
- func (i Int) Equal(i2 Int) bool
- func (i Int) GT(i2 Int) bool
- func (i Int) Int64() int64
- func (i Int) IsInt64() bool
- func (i Int) IsZero() bool
- func (i Int) LT(i2 Int) bool
- func (i Int) MarshalAmino() (string, error)
- func (i Int) MarshalJSON() ([]byte, error)
- func (i Int) Mod(i2 Int) Int
- func (i Int) ModRaw(i2 int64) Int
- func (i Int) Mul(i2 Int) (res Int)
- func (i Int) MulRaw(i2 int64) Int
- func (i Int) Neg() (res Int)
- func (i Int) Sign() int
- func (i Int) String() string
- func (i Int) Sub(i2 Int) (res Int)
- func (i Int) SubRaw(i2 int64) Int
- func (i *Int) UnmarshalAmino(text string) error
- func (i *Int) UnmarshalJSON(bz []byte) error
- type Result
- type Uint
- func (i Uint) Add(i2 Uint) (res Uint)
- func (i Uint) AddRaw(i2 uint64) Uint
- func (i Uint) BigInt() *big.Int
- func (i Uint) Div(i2 Uint) (res Uint)
- func (i Uint) DivRaw(i2 uint64) Uint
- func (i Uint) Equal(i2 Uint) bool
- func (i Uint) GT(i2 Uint) bool
- func (i Uint) IsUint64() bool
- func (i Uint) IsZero() bool
- func (i Uint) LT(i2 Uint) bool
- func (i Uint) MarshalAmino() (string, error)
- func (i Uint) MarshalJSON() ([]byte, error)
- func (i Uint) Mod(i2 Uint) Uint
- func (i Uint) ModRaw(i2 uint64) Uint
- func (i Uint) Mul(i2 Uint) (res Uint)
- func (i Uint) MulRaw(i2 uint64) Uint
- func (i Uint) Sign() int
- func (i Uint) String() string
- func (i Uint) Sub(i2 Uint) (res Uint)
- func (i Uint) SubRaw(i2 uint64) Uint
- func (i Uint) Uint64() uint64
- func (i *Uint) UnmarshalAmino(text string) error
- func (i *Uint) UnmarshalJSON(bz []byte) error
Constants ¶
const ( // ABCI error codes ABCICodeOK ABCICodeType = 0 // Base error codes CodeOK CodeType = 0 CodeInternal CodeType = 1 CodeTxDecode CodeType = 2 CodeInvalidSequence CodeType = 3 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 ¶
create an AccAddress from a bech32 string
func AccAddressFromHex ¶
"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 ¶
NOTE: Don't stringer this, we'll put better messages in later. nolint: gocyclo
func GetFromBech32 ¶
// 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
type Coin ¶
Coin hold some amount of one currency
func NewInt64Coin ¶
func ParseCoin ¶
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 ¶
IsGTE returns true if they are the same type and the receiver is an equal or greater value
func (Coin) IsNotNegative ¶
IsNotNegative returns true if coin amount is not negative
func (Coin) IsPositive ¶
IsPositive returns true if coin amount is positive
func (Coin) SameDenomAs ¶
SameDenomAs returns true if the two coins are the same denom
type Coins ¶
type Coins []Coin
Coins is a set of Coin, one per currency
func ParseCoins ¶
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) IsGTE ¶
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 ¶
IsNotNegative returns true if there is no currency with a negative value (even no coins is true here)
func (Coins) IsPositive ¶
IsPositive returns true if there is at least one coin, and all currencies have a positive value
func (Coins) Plus ¶
Plus combines two sets of coins CONTRACT: Plus will never return Coins where one Coin has a 0 amount.
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 ErrInsufficientFunds ¶
func ErrInvalidAddress ¶
func ErrInvalidCoins ¶
func ErrInvalidPubKey ¶
func ErrInvalidSequence ¶
func ErrMemoTooLarge ¶
func ErrOutOfGas ¶
func ErrTxDecode ¶
func ErrUnauthorized ¶
func ErrUnknownAddress ¶
func ErrUnknownRequest ¶
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 NewIntFromBigInt ¶
NewIntFromBigInt constructs Int from big.Int
func NewIntFromString ¶
NewIntFromString constructs Int from string
func NewIntWithDecimal ¶
NewIntWithDecimal constructs Int with decimal Result value is n*10^dec
func (Int) MarshalAmino ¶
MarshalAmino defines custom encoding scheme
func (Int) MarshalJSON ¶
MarshalJSON defines custom encoding scheme
func (*Int) UnmarshalAmino ¶
UnmarshalAmino defines custom decoding scheme
func (*Int) UnmarshalJSON ¶
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.
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 NewUintFromBigInt ¶
NewUintFromBigUint constructs Uint from big.Uint
func NewUintFromString ¶
NewUintFromString constructs Uint from string
func NewUintWithDecimal ¶
NewUintWithDecimal constructs Uint with decimal Result value is n*10^dec
func (Uint) MarshalAmino ¶
MarshalAmino defines custom encoding scheme
func (Uint) MarshalJSON ¶
MarshalJSON defines custom encoding scheme
func (*Uint) UnmarshalAmino ¶
UnmarshalAmino defines custom decoding scheme
func (*Uint) UnmarshalJSON ¶
UnmarshalJSON defines custom decoding scheme