auth

package
v0.30.0-dev0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2019 License: Apache-2.0 Imports: 18 Imported by: 3,545

Documentation

Overview

nolint

Index

Constants

View Source
const (
	DefaultMemoCostPerByte        sdk.Gas = 3
	DefaultMaxMemoCharacters      uint64  = 256
	DefaultTxSigLimit             uint64  = 7
	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 (
	// 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 (
	KeyMemoCostPerByte        = []byte("MemoCostPerByte")
	KeyMaxMemoCharacters      = []byte("MaxMemoCharacters")
	KeyTxSigLimit             = []byte("TxSigLimit")
	KeySigVerifyCostED25519   = []byte("SigVerifyCostED25519")
	KeySigVerifyCostSecp256k1 = []byte("SigVerifyCostSecp256k1")
)

Parameter keys

Functions

func AddressStoreKey

func AddressStoreKey(addr sdk.AccAddress) []byte

Turn an address to key used to get it from the account store

func DefaultTxDecoder

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

logic for standard transaction decoding

func DefaultTxEncoder

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

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. An result object is returned indicating success or failure.

TODO: Account for transaction size.

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

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

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

func ParamTypeTable() params.TypeTable

ParamTable for staking 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)

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

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

Register concrete types on codec codec for default AppAccount

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

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

ValidateMemo validates the memo and if successful consumes gas for verification.

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

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

Prototype function for BaseAccount

type AccountDecoder added in v0.18.0

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

AccountDecoder unmarshals account bytes

type AccountKeeper

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

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

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

Implements sdk.AccountKeeper.

func (AccountKeeper) GetNextAccountNumber added in v0.25.0

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

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)

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)

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

Implements sdk.AccountKeeper.

func (AccountKeeper) NewAccount added in v0.25.0

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

New Account

func (AccountKeeper) NewAccountWithAddress added in v0.25.0

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

Implaements 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.

func (AccountKeeper) SetAccount added in v0.25.0

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

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. There are examples of this in: examples/basecoin/types/account.go. However one doesn't have to use BaseAccount as long as your struct implements Account.

func NewBaseAccountWithAddress

func NewBaseAccountWithAddress(addr sdk.AccAddress) BaseAccount

func (*BaseAccount) GetAccountNumber added in v0.19.0

func (acc *BaseAccount) GetAccountNumber() uint64

Implements Account

func (BaseAccount) GetAddress added in v0.2.0

func (acc BaseAccount) GetAddress() sdk.AccAddress

Implements sdk.Account.

func (*BaseAccount) GetCoins added in v0.2.0

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

Implements sdk.Account.

func (BaseAccount) GetPubKey added in v0.2.0

func (acc BaseAccount) GetPubKey() crypto.PubKey

Implements sdk.Account.

func (*BaseAccount) GetSequence added in v0.2.0

func (acc *BaseAccount) GetSequence() uint64

Implements sdk.Account.

func (*BaseAccount) SetAccountNumber added in v0.19.0

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

Implements Account

func (*BaseAccount) SetAddress added in v0.2.0

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

Implements sdk.Account.

func (*BaseAccount) SetCoins added in v0.2.0

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

Implements sdk.Account.

func (*BaseAccount) SetPubKey added in v0.2.0

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

Implements sdk.Account.

func (*BaseAccount) SetSequence added in v0.2.0

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

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

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

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
}

This 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

func (FeeCollectionKeeper) AddCollectedFees added in v0.25.0

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

add to the fee pool

func (FeeCollectionKeeper) ClearCollectedFees added in v0.18.0

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

clear the fee pool

func (FeeCollectionKeeper) GetCollectedFees added in v0.18.0

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

retrieves the collected fee pool

type GenesisState

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

GenesisState - all auth state that must be provided at genesis

func DefaultGenesisState

func DefaultGenesisState() GenesisState

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

Create a new genesis state

type Params

type Params struct {
	MemoCostPerByte        sdk.Gas
	MaxMemoCharacters      uint64
	TxSigLimit             uint64 // max total number of signatures per tx
	SigVerifyCostED25519   uint64
	SigVerifyCostSecp256k1 uint64
}

Params defines the parameters for the auth module.

func DefaultParams

func DefaultParams() Params

DefaultParams returns a default set of parameters.

func MustUnmarshalParams added in v0.30.0

func MustUnmarshalParams(cdc *codec.Codec, value []byte) Params

MustUnmarshalParams deserializes raw Params bytes into a Params structure. It will panic upon failure.

func UnmarshalParams added in v0.30.0

func UnmarshalParams(cdc *codec.Codec, value []byte) (params Params, err error)

UnmarshalParams deserializes raw Params bytes into a Params structure. It will return an error upon failure.

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

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

KeyValuePairs implements the ParamSet interface and returns all the key/value 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

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

func (StdFee) Bytes added in v0.18.0

func (fee StdFee) Bytes() []byte

fee bytes for signing later

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"`
}

Standard Signature

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

func (tx StdTx) GetMemo() string

nolint

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

Signatures 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
}

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