auth

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2019 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Overview

nolint

Index

Constants

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

Variables

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

	// 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"
)
View Source
var (
	KeyMaxMemoCharacters      = []byte("MaxMemoCharacters")
	KeyTxSigLimit             = []byte("TxSigLimit")
	KeyTxSizeCostPerByte      = []byte("TxSizeCostPerByte")
	KeySigVerifyCostED25519   = []byte("SigVerifyCostED25519")
	KeySigVerifyCostSecp256k1 = []byte("SigVerifyCostSecp256k1")
)

Parameter keys

Functions

func AddressStoreKey added in v0.19.0

func AddressStoreKey(addr sdk.AccAddress) []byte

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

func DefaultTxDecoder added in v0.24.0

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

DefaultTxDecoder logic for standard transaction decoding

func DefaultTxEncoder added in v0.28.1

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

DefaultTxEncoder logic for standard transaction encoding

func EnsureSufficientMempoolFees added in v0.30.0

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 added in v0.30.0

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 added in v0.26.0

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 ParamKeyTable added in v0.31.0

func ParamKeyTable() params.KeyTable

ParamKeyTable for auth module

func ProcessPubKey added in v0.30.0

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 added in v0.15.0

func RegisterBaseAccount(cdc *codec.Codec)

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

func RegisterCodec added in v0.25.0

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers concrete types on the codec

func SetGasMeter added in v0.30.0

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 added in v0.18.0

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 added in v0.30.0

func ValidateGenesis(data GenesisState) error

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

func ValidateMemo added in v0.30.0

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

ValidateMemo validates the memo size.

Types

type Account added in v0.18.0

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 added in v0.30.0

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 added in v0.30.0

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 added in v0.21.0

func ProtoBaseAccount() Account

ProtoBaseAccount - a prototype function for BaseAccount

type AccountDecoder added in v0.18.0

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

AccountDecoder unmarshals account bytes TODO: Think about removing

type AccountKeeper added in v0.25.0

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

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

func NewAccountKeeper added in v0.25.0

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 added in v0.25.0

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

GetAccount implements sdk.AccountKeeper.

func (AccountKeeper) GetNextAccountNumber added in v0.25.0

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

GetNextAccountNumber Returns and increments the global account number counter

func (AccountKeeper) GetParams added in v0.30.0

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

GetParams gets the auth module's parameters.

func (AccountKeeper) GetPubKey added in v0.25.0

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 added in v0.25.0

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 added in v0.25.0

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

IterateAccounts implements sdk.AccountKeeper.

func (AccountKeeper) NewAccount added in v0.25.0

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

NewAccount creates a new account

func (AccountKeeper) NewAccountWithAddress added in v0.25.0

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

NewAccountWithAddress implements sdk.AccountKeeper.

func (AccountKeeper) RemoveAccount added in v0.25.0

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 added in v0.25.0

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

SetAccount implements sdk.AccountKeeper.

func (AccountKeeper) SetParams added in v0.30.0

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 added in v0.19.0

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 added in v0.19.0

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 added in v0.30.0

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 added in v0.30.0

func (acc BaseAccount) String() string

String implements fmt.Stringer

type BaseVestingAccount added in v0.30.0

type BaseVestingAccount struct {
	*BaseAccount

	OriginalVesting  sdk.Coins // coins in account upon initialization
	DelegatedFree    sdk.Coins // coins that are vested and delegated
	DelegatedVesting sdk.Coins // coins that vesting and delegated

	EndTime int64 // 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 added in v0.30.0

func (bva BaseVestingAccount) GetDelegatedFree() sdk.Coins

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

func (BaseVestingAccount) GetDelegatedVesting added in v0.30.0

func (bva BaseVestingAccount) GetDelegatedVesting() sdk.Coins

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

func (BaseVestingAccount) GetOriginalVesting added in v0.30.0

func (bva BaseVestingAccount) GetOriginalVesting() sdk.Coins

GetOriginalVesting returns a vesting account's original vesting amount

func (BaseVestingAccount) String added in v0.30.0

func (bva BaseVestingAccount) String() string

String implements fmt.Stringer

func (*BaseVestingAccount) TrackUndelegation added in v0.30.0

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.

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

type ContinuousVestingAccount added in v0.30.0

type ContinuousVestingAccount struct {
	*BaseVestingAccount

	StartTime int64 // when the coins start to vest
}

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

func NewContinuousVestingAccount added in v0.30.0

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

NewContinuousVestingAccount returns a new ContinuousVestingAccount

func (*ContinuousVestingAccount) GetEndTime added in v0.30.0

func (cva *ContinuousVestingAccount) GetEndTime() int64

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

func (*ContinuousVestingAccount) GetStartTime added in v0.30.0

func (cva *ContinuousVestingAccount) GetStartTime() int64

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

func (ContinuousVestingAccount) GetVestedCoins added in v0.30.0

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 added in v0.30.0

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 added in v0.30.0

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 added in v0.30.0

func (cva ContinuousVestingAccount) String() string

func (*ContinuousVestingAccount) TrackDelegation added in v0.30.0

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 added in v0.30.0

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 added in v0.30.0

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

NewDelayedVestingAccount returns a DelayedVestingAccount

func (*DelayedVestingAccount) GetEndTime added in v0.30.0

func (dva *DelayedVestingAccount) GetEndTime() int64

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

func (*DelayedVestingAccount) GetStartTime added in v0.30.0

func (dva *DelayedVestingAccount) GetStartTime() int64

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

func (DelayedVestingAccount) GetVestedCoins added in v0.30.0

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 added in v0.30.0

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 added in v0.30.0

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 added in v0.30.0

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 added in v0.18.0

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 added in v0.18.0

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

NewFeeCollectionKeeper returns a new FeeCollectionKeeper

func (FeeCollectionKeeper) AddCollectedFees added in v0.25.0

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

AddCollectedFees - add to the fee pool

func (FeeCollectionKeeper) ClearCollectedFees added in v0.18.0

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

ClearCollectedFees - clear the fee pool

func (FeeCollectionKeeper) GetCollectedFees added in v0.18.0

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

GetCollectedFees - retrieves the collected fee pool

type GenesisState added in v0.26.0

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 added in v0.26.0

func DefaultGenesisState() GenesisState

DefaultGenesisState - Return a default genesis state

func ExportGenesis added in v0.26.0

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

ExportGenesis returns a GenesisState for a given context and keeper

func NewGenesisState added in v0.26.0

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

NewGenesisState - Create a new genesis state

type Params added in v0.30.0

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 added in v0.30.0

func DefaultParams() Params

DefaultParams returns a default set of parameters.

func (Params) Equal added in v0.30.0

func (p Params) Equal(p2 Params) bool

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

func (*Params) ParamSetPairs added in v0.31.0

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 added in v0.30.0

func (p Params) String() string

String implements the stringer interface.

type StdFee added in v0.18.0

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 added in v0.18.0

func NewStdFee(gas uint64, amount sdk.Coins) StdFee

NewStdFee returns a new instance of StdFee

func (StdFee) Bytes added in v0.18.0

func (fee StdFee) Bytes() []byte

Bytes for signing later

type StdSignDoc added in v0.18.0

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 added in v0.18.0

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

StdSignature represents a sig

type StdTx added in v0.18.0

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 added in v0.18.0

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

func (StdTx) GetMemo added in v0.20.0

func (tx StdTx) GetMemo() string

GetMemo returns the memo

func (StdTx) GetMsgs added in v0.20.0

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

GetMsgs returns the all the transaction's messages.

func (StdTx) GetSignatures added in v0.18.0

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 added in v0.20.0

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 added in v0.27.0

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 added in v0.30.0

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
cli

Jump to

Keyboard shortcuts

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