auth

package
v0.34.7 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

nolint

Index

Constants

View Source
const (
	// StoreKey is string representation of the store key for auth
	StoreKey = "acc"

	// FeeStoreKey is a string representation of the store key for fees
	FeeStoreKey = "fee"

	// QuerierRoute is the querier route for acc
	QuerierRoute = StoreKey
)
View Source
const (
	DefaultMaxMemoCharacters      uint64 = 256
	DefaultTxSigLimit             uint64 = 7
	DefaultTxSizeCostPerByte      uint64 = 10
	DefaultSigVerifyCostED25519   uint64 = 590
	DefaultSigVerifyCostSecp256k1 uint64 = 1000
)

Default parameter values

View Source
const DefaultParamspace = "auth"

DefaultParamspace defines the default auth module parameter subspace

View Source
const (
	QueryAccount = "account"
)

query endpoints supported by the auth Querier

Variables

View Source
var (
	KeyMaxMemoCharacters      = []byte("MaxMemoCharacters")
	KeyTxSigLimit             = []byte("TxSigLimit")
	KeyTxSizeCostPerByte      = []byte("TxSizeCostPerByte")
	KeySigVerifyCostED25519   = []byte("SigVerifyCostED25519")
	KeySigVerifyCostSecp256k1 = []byte("SigVerifyCostSecp256k1")
)

Parameter keys

View Source
var (
	// AddressStoreKeyPrefix prefix for account-by-address store
	AddressStoreKeyPrefix = []byte{0x01}
)

Functions

func AddressStoreKey

func AddressStoreKey(addr sdk.AccAddress) []byte

AddressStoreKey turn an address to key used to get it from the account store

func DefaultTxDecoder

func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder

DefaultTxDecoder logic for standard transaction decoding

func DefaultTxEncoder

func DefaultTxEncoder(cdc *codec.Codec) sdk.TxEncoder

DefaultTxEncoder logic for standard transaction encoding

func EnsureSufficientMempoolFees

func EnsureSufficientMempoolFees(ctx sdk.Context, stdFee StdFee) sdk.Result

EnsureSufficientMempoolFees verifies that the given transaction has supplied enough fees to cover a proposer's minimum fees. A result object is returned indicating success or failure.

Contract: This should only be called during CheckTx as it cannot be part of consensus.

func GetSignBytes

func GetSignBytes(chainID string, stdTx StdTx, acc Account, genesis bool) []byte

GetSignBytes returns a slice of bytes to sign over for a given transaction and an account.

func InitGenesis

func InitGenesis(ctx sdk.Context, ak AccountKeeper, fck FeeCollectionKeeper, data GenesisState)

InitGenesis - Init store state from genesis data

func NewAnteHandler

func NewAnteHandler(ak AccountKeeper, fck FeeCollectionKeeper) sdk.AnteHandler

NewAnteHandler returns an AnteHandler that checks and increments sequence numbers, checks signatures & account numbers, and deducts fees from the first signer.

func NewQuerier

func NewQuerier(keeper AccountKeeper) sdk.Querier

creates a querier for auth REST endpoints

func ParamKeyTable

func ParamKeyTable() params.KeyTable

ParamKeyTable for auth module

func ProcessPubKey

func ProcessPubKey(acc Account, sig StdSignature, simulate bool) (crypto.PubKey, sdk.Result)

ProcessPubKey verifies that the given account address matches that of the StdSignature. In addition, it will set the public key of the account if it has not been set.

func RegisterBaseAccount

func RegisterBaseAccount(cdc *codec.Codec)

RegisterBaseAccount most users shouldn't use this, but this comes in handy for tests.

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers concrete types on the codec

func SetGasMeter

func SetGasMeter(simulate bool, ctx sdk.Context, gasLimit uint64) sdk.Context

SetGasMeter returns a new context with a gas meter set from a given context.

func StdSignBytes

func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, msgs []sdk.Msg, memo string) []byte

StdSignBytes returns the bytes to sign for a transaction.

func ValidateGenesis

func ValidateGenesis(data GenesisState) error

ValidateGenesis performs basic validation of auth genesis data returning an error for any failed validation criteria.

func ValidateMemo

func ValidateMemo(stdTx StdTx, params Params) sdk.Result

ValidateMemo validates the memo size.

Types

type Account

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

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

	GetAccountNumber() uint64
	SetAccountNumber(uint64) error

	GetSequence() uint64
	SetSequence(uint64) error

	GetCoins() sdk.Coins
	SetCoins(sdk.Coins) error

	// Calculates the amount of coins that can be sent to other accounts given
	// the current time.
	SpendableCoins(blockTime time.Time) sdk.Coins

	// Ensure that account implements stringer
	String() string
}

Account is an interface used to store coins at a given address within state. It presumes a notion of sequence numbers for replay protection, a notion of account numbers for replay protection for previously pruned accounts, and a pubkey for authentication purposes.

Many complex conditions can be used in the concrete struct which implements Account.

func DeductFees

func DeductFees(blockTime time.Time, acc Account, fee StdFee) (Account, sdk.Result)

DeductFees deducts fees from the given account.

NOTE: We could use the CoinKeeper (in addition to the AccountKeeper, because the CoinKeeper doesn't give us accounts), but it seems easier to do this.

func GetSignerAcc

func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) (Account, sdk.Result)

GetSignerAcc returns an account for a given address that is expected to sign a transaction.

func ProtoBaseAccount

func ProtoBaseAccount() Account

ProtoBaseAccount - a prototype function for BaseAccount

type AccountDecoder

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

AccountDecoder unmarshals account bytes TODO: Think about removing

type AccountKeeper

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

AccountKeeper encodes/decodes accounts using the go-amino (binary) encoding/decoding library.

func NewAccountKeeper

func NewAccountKeeper(
	cdc *codec.Codec, key sdk.StoreKey, paramstore params.Subspace, proto func() Account,
) AccountKeeper

NewAccountKeeper returns a new sdk.AccountKeeper that uses go-amino to (binary) encode and decode concrete sdk.Accounts. nolint

func (AccountKeeper) GetAccount

func (ak AccountKeeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) Account

GetAccount implements sdk.AccountKeeper.

func (AccountKeeper) GetAllAccounts

func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) []Account

GetAllAccounts returns all accounts in the accountKeeper.

func (AccountKeeper) GetNextAccountNumber

func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64

GetNextAccountNumber Returns and increments the global account number counter

func (AccountKeeper) GetParams

func (ak AccountKeeper) GetParams(ctx sdk.Context) (params Params)

GetParams gets the auth module's parameters.

func (AccountKeeper) GetPubKey

func (ak AccountKeeper) GetPubKey(ctx sdk.Context, addr sdk.AccAddress) (crypto.PubKey, sdk.Error)

GetPubKey Returns the PubKey of the account at address

func (AccountKeeper) GetSequence

func (ak AccountKeeper) GetSequence(ctx sdk.Context, addr sdk.AccAddress) (uint64, sdk.Error)

GetSequence Returns the Sequence of the account at address

func (AccountKeeper) IterateAccounts

func (ak AccountKeeper) IterateAccounts(ctx sdk.Context, process func(Account) (stop bool))

IterateAccounts implements sdk.AccountKeeper.

func (AccountKeeper) NewAccount

func (ak AccountKeeper) NewAccount(ctx sdk.Context, acc Account) Account

NewAccount creates a new account

func (AccountKeeper) NewAccountWithAddress

func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) Account

NewAccountWithAddress implements sdk.AccountKeeper.

func (AccountKeeper) RemoveAccount

func (ak AccountKeeper) RemoveAccount(ctx sdk.Context, acc Account)

RemoveAccount removes an account for the account mapper store. NOTE: this will cause supply invariant violation if called

func (AccountKeeper) SetAccount

func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc Account)

SetAccount implements sdk.AccountKeeper.

func (AccountKeeper) SetParams

func (ak AccountKeeper) SetParams(ctx sdk.Context, params Params)

SetParams sets the auth module's parameters.

type BaseAccount

type BaseAccount struct {
	Address       sdk.AccAddress `json:"address"`
	Coins         sdk.Coins      `json:"coins"`
	PubKey        crypto.PubKey  `json:"public_key"`
	AccountNumber uint64         `json:"account_number"`
	Sequence      uint64         `json:"sequence"`
}

BaseAccount - a base account structure. This can be extended by embedding within in your AppAccount. However one doesn't have to use BaseAccount as long as your struct implements Account.

func NewBaseAccountWithAddress

func NewBaseAccountWithAddress(addr sdk.AccAddress) BaseAccount

NewBaseAccountWithAddress - returns a new base account with a given address

func (*BaseAccount) GetAccountNumber

func (acc *BaseAccount) GetAccountNumber() uint64

GetAccountNumber - Implements Account

func (BaseAccount) GetAddress

func (acc BaseAccount) GetAddress() sdk.AccAddress

GetAddress - Implements sdk.Account.

func (*BaseAccount) GetCoins

func (acc *BaseAccount) GetCoins() sdk.Coins

GetCoins - Implements sdk.Account.

func (BaseAccount) GetPubKey

func (acc BaseAccount) GetPubKey() crypto.PubKey

GetPubKey - Implements sdk.Account.

func (*BaseAccount) GetSequence

func (acc *BaseAccount) GetSequence() uint64

GetSequence - Implements sdk.Account.

func (*BaseAccount) SetAccountNumber

func (acc *BaseAccount) SetAccountNumber(accNumber uint64) error

SetAccountNumber - Implements Account

func (*BaseAccount) SetAddress

func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error

SetAddress - Implements sdk.Account.

func (*BaseAccount) SetCoins

func (acc *BaseAccount) SetCoins(coins sdk.Coins) error

SetCoins - Implements sdk.Account.

func (*BaseAccount) SetPubKey

func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error

SetPubKey - Implements sdk.Account.

func (*BaseAccount) SetSequence

func (acc *BaseAccount) SetSequence(seq uint64) error

SetSequence - Implements sdk.Account.

func (*BaseAccount) SpendableCoins

func (acc *BaseAccount) SpendableCoins(_ time.Time) sdk.Coins

SpendableCoins returns the total set of spendable coins. For a base account, this is simply the base coins.

func (BaseAccount) String

func (acc BaseAccount) String() string

String implements fmt.Stringer

type BaseVestingAccount

type BaseVestingAccount struct {
	*BaseAccount

	OriginalVesting  sdk.Coins `json:"original_vesting"`  // coins in account upon initialization
	DelegatedFree    sdk.Coins `json:"delegated_free"`    // coins that are vested and delegated
	DelegatedVesting sdk.Coins `json:"delegated_vesting"` // coins that vesting and delegated

	EndTime int64 `json:"end_time"` // when the coins become unlocked
}

BaseVestingAccount implements the VestingAccount interface. It contains all the necessary fields needed for any vesting account implementation.

func (BaseVestingAccount) GetDelegatedFree

func (bva BaseVestingAccount) GetDelegatedFree() sdk.Coins

GetDelegatedFree returns a vesting account's delegation amount that is not vesting.

func (BaseVestingAccount) GetDelegatedVesting

func (bva BaseVestingAccount) GetDelegatedVesting() sdk.Coins

GetDelegatedVesting returns a vesting account's delegation amount that is still vesting.

func (BaseVestingAccount) GetOriginalVesting

func (bva BaseVestingAccount) GetOriginalVesting() sdk.Coins

GetOriginalVesting returns a vesting account's original vesting amount

func (BaseVestingAccount) String

func (bva BaseVestingAccount) String() string

String implements fmt.Stringer

func (*BaseVestingAccount) TrackUndelegation

func (bva *BaseVestingAccount) TrackUndelegation(amount sdk.Coins)

TrackUndelegation tracks an undelegation amount by setting the necessary values by which delegated vesting and delegated vesting need to decrease and by which amount the base coins need to increase. The resulting base coins are returned.

NOTE: The undelegation (bond refund) amount may exceed the delegated vesting (bond) amount due to the way undelegation truncates the bond refund, which can increase the validator's exchange rate (tokens/shares) slightly if the undelegated tokens are non-integral.

CONTRACT: The account's coins and undelegation coins must be sorted.

type ContinuousVestingAccount

type ContinuousVestingAccount struct {
	*BaseVestingAccount

	StartTime int64 `json:"start_time"` // when the coins start to vest
}

ContinuousVestingAccount implements the VestingAccount interface. It continuously vests by unlocking coins linearly with respect to time.

func NewContinuousVestingAccount

func NewContinuousVestingAccount(
	baseAcc *BaseAccount, StartTime, EndTime int64,
) *ContinuousVestingAccount

NewContinuousVestingAccount returns a new ContinuousVestingAccount

func (*ContinuousVestingAccount) GetEndTime

func (cva *ContinuousVestingAccount) GetEndTime() int64

GetEndTime returns the time when vesting ends for a continuous vesting account.

func (*ContinuousVestingAccount) GetStartTime

func (cva *ContinuousVestingAccount) GetStartTime() int64

GetStartTime returns the time when vesting starts for a continuous vesting account.

func (ContinuousVestingAccount) GetVestedCoins

func (cva ContinuousVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coins

GetVestedCoins returns the total number of vested coins. If no coins are vested, nil is returned.

func (ContinuousVestingAccount) GetVestingCoins

func (cva ContinuousVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins

GetVestingCoins returns the total number of vesting coins. If no coins are vesting, nil is returned.

func (ContinuousVestingAccount) SpendableCoins

func (cva ContinuousVestingAccount) SpendableCoins(blockTime time.Time) sdk.Coins

SpendableCoins returns the total number of spendable coins per denom for a continuous vesting account.

func (ContinuousVestingAccount) String

func (cva ContinuousVestingAccount) String() string

func (*ContinuousVestingAccount) TrackDelegation

func (cva *ContinuousVestingAccount) TrackDelegation(blockTime time.Time, amount sdk.Coins)

TrackDelegation tracks a desired delegation amount by setting the appropriate values for the amount of delegated vesting, delegated free, and reducing the overall amount of base coins.

type DelayedVestingAccount

type DelayedVestingAccount struct {
	*BaseVestingAccount
}

DelayedVestingAccount implements the VestingAccount interface. It vests all coins after a specific time, but non prior. In other words, it keeps them locked until a specified time.

func NewDelayedVestingAccount

func NewDelayedVestingAccount(baseAcc *BaseAccount, EndTime int64) *DelayedVestingAccount

NewDelayedVestingAccount returns a DelayedVestingAccount

func (*DelayedVestingAccount) GetEndTime

func (dva *DelayedVestingAccount) GetEndTime() int64

GetEndTime returns the time when vesting ends for a delayed vesting account.

func (*DelayedVestingAccount) GetStartTime

func (dva *DelayedVestingAccount) GetStartTime() int64

GetStartTime returns zero since a delayed vesting account has no start time.

func (DelayedVestingAccount) GetVestedCoins

func (dva DelayedVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coins

GetVestedCoins returns the total amount of vested coins for a delayed vesting account. All coins are only vested once the schedule has elapsed.

func (DelayedVestingAccount) GetVestingCoins

func (dva DelayedVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins

GetVestingCoins returns the total number of vesting coins for a delayed vesting account.

func (DelayedVestingAccount) SpendableCoins

func (dva DelayedVestingAccount) SpendableCoins(blockTime time.Time) sdk.Coins

SpendableCoins returns the total number of spendable coins for a delayed vesting account.

func (*DelayedVestingAccount) TrackDelegation

func (dva *DelayedVestingAccount) TrackDelegation(blockTime time.Time, amount sdk.Coins)

TrackDelegation tracks a desired delegation amount by setting the appropriate values for the amount of delegated vesting, delegated free, and reducing the overall amount of base coins.

type FeeCollectionKeeper

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

FeeCollectionKeeper handles collection of fees in the anteHandler and setting of MinFees for different fee tokens

func NewFeeCollectionKeeper

func NewFeeCollectionKeeper(cdc *codec.Codec, key sdk.StoreKey) FeeCollectionKeeper

NewFeeCollectionKeeper returns a new FeeCollectionKeeper

func (FeeCollectionKeeper) AddCollectedFees

func (fck FeeCollectionKeeper) AddCollectedFees(ctx sdk.Context, coins sdk.Coins) sdk.Coins

AddCollectedFees - add to the fee pool

func (FeeCollectionKeeper) ClearCollectedFees

func (fck FeeCollectionKeeper) ClearCollectedFees(ctx sdk.Context)

ClearCollectedFees - clear the fee pool

func (FeeCollectionKeeper) GetCollectedFees

func (fck FeeCollectionKeeper) GetCollectedFees(ctx sdk.Context) sdk.Coins

GetCollectedFees - retrieves the collected fee pool

type GenesisState

type GenesisState struct {
	CollectedFees sdk.Coins `json:"collected_fees"`
	Params        Params    `json:"params"`
}

GenesisState - all auth state that must be provided at genesis

func DefaultGenesisState

func DefaultGenesisState() GenesisState

DefaultGenesisState - Return a default genesis state

func ExportGenesis

func ExportGenesis(ctx sdk.Context, ak AccountKeeper, fck FeeCollectionKeeper) GenesisState

ExportGenesis returns a GenesisState for a given context and keeper

func NewGenesisState

func NewGenesisState(collectedFees sdk.Coins, params Params) GenesisState

NewGenesisState - Create a new genesis state

type Params

type Params struct {
	MaxMemoCharacters      uint64 `json:"max_memo_characters"`
	TxSigLimit             uint64 `json:"tx_sig_limit"`
	TxSizeCostPerByte      uint64 `json:"tx_size_cost_per_byte"`
	SigVerifyCostED25519   uint64 `json:"sig_verify_cost_ed25519"`
	SigVerifyCostSecp256k1 uint64 `json:"sig_verify_cost_secp256k1"`
}

Params defines the parameters for the auth module.

func DefaultParams

func DefaultParams() Params

DefaultParams returns a default set of parameters.

func (Params) Equal

func (p Params) Equal(p2 Params) bool

Equal returns a boolean determining if two Params types are identical.

func (*Params) ParamSetPairs

func (p *Params) ParamSetPairs() params.ParamSetPairs

ParamSetPairs implements the ParamSet interface and returns all the key/value pairs pairs of auth module's parameters. nolint

func (Params) String

func (p Params) String() string

String implements the stringer interface.

type QueryAccountParams

type QueryAccountParams struct {
	Address sdk.AccAddress
}

defines the params for query: "custom/acc/account"

func NewQueryAccountParams

func NewQueryAccountParams(addr sdk.AccAddress) QueryAccountParams

type StdFee

type StdFee struct {
	Amount sdk.Coins `json:"amount"`
	Gas    uint64    `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 uint64, amount sdk.Coins) StdFee

NewStdFee returns a new instance of StdFee

func (StdFee) Bytes

func (fee StdFee) Bytes() []byte

Bytes for signing later

func (StdFee) GasPrices

func (fee StdFee) GasPrices() sdk.DecCoins

GasPrices returns the gas prices for a StdFee.

NOTE: The gas prices returned are not the true gas prices that were originally part of the submitted transaction because the fee is computed as fee = ceil(gasWanted * gasPrices).

type StdSignDoc

type StdSignDoc struct {
	AccountNumber uint64            `json:"account_number"`
	ChainID       string            `json:"chain_id"`
	Fee           json.RawMessage   `json:"fee"`
	Memo          string            `json:"memo"`
	Msgs          []json.RawMessage `json:"msgs"`
	Sequence      uint64            `json:"sequence"`
}

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 StdSignature

type StdSignature struct {
	crypto.PubKey `json:"pub_key"` // optional
	Signature     []byte           `json:"signature"`
}

StdSignature represents a sig

type StdTx

type StdTx struct {
	Msgs       []sdk.Msg      `json:"msg"`
	Fee        StdFee         `json:"fee"`
	Signatures []StdSignature `json:"signatures"`
	Memo       string         `json:"memo"`
}

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

func NewStdTx

func NewStdTx(msgs []sdk.Msg, fee StdFee, sigs []StdSignature, memo string) StdTx

func (StdTx) GetMemo

func (tx StdTx) GetMemo() string

GetMemo returns the memo

func (StdTx) GetMsgs

func (tx StdTx) GetMsgs() []sdk.Msg

GetMsgs returns the all the transaction's messages.

func (StdTx) GetSignatures

func (tx StdTx) GetSignatures() []StdSignature

GetSignatures returns the signature of signers who signed the Msg. GetSignatures 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().

func (StdTx) GetSigners

func (tx StdTx) GetSigners() []sdk.AccAddress

GetSigners returns the addresses that must sign the transaction. Addresses are returned in a deterministic order. They are accumulated from the GetSigners method for each Msg in the order they appear in tx.GetMsgs(). Duplicate addresses will be omitted.

func (StdTx) ValidateBasic

func (tx StdTx) ValidateBasic() sdk.Error

ValidateBasic does a simple and lightweight validation check that doesn't require access to any other information.

type VestingAccount

type VestingAccount interface {
	Account

	// Delegation and undelegation accounting that returns the resulting base
	// coins amount.
	TrackDelegation(blockTime time.Time, amount sdk.Coins)
	TrackUndelegation(amount sdk.Coins)

	GetVestedCoins(blockTime time.Time) sdk.Coins
	GetVestingCoins(blockTime time.Time) sdk.Coins

	GetStartTime() int64
	GetEndTime() int64

	GetOriginalVesting() sdk.Coins
	GetDelegatedFree() sdk.Coins
	GetDelegatedVesting() sdk.Coins
}

VestingAccount defines an account type that vests coins via a vesting schedule.

Directories

Path Synopsis
client
cli

Jump to

Keyboard shortcuts

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