peptide

package
v0.0.0-...-051ef74 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGenTxGas = 200000000
)

Variables

View Source
var DefaultConsensusParams = &tmproto.ConsensusParams{
	Block: &tmproto.BlockParams{
		MaxBytes: 200000,
		MaxGas:   200000000,
	},
	Evidence: &tmproto.EvidenceParams{
		MaxAgeNumBlocks: 302400,
		MaxAgeDuration:  504 * time.Hour,
		MaxBytes:        10000,
	},
	Validator: &tmproto.ValidatorParams{
		PubKeyTypes: []string{
			tmtypes.ABCIPubKeyTypeEd25519,
		},
	},
}

Functions

func GenTx

func GenTx(
	gen client.TxConfig,
	msgs []sdk.Msg,
	feeAmt sdk.Coins,
	gas uint64,
	chainID string,
	r *rand.Rand,
	signerAccounts ...*SignerAccount,
) (sdk.Tx, error)

GenTx generates a signed mock transaction. func GenTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey) (sdk.Tx, error) {

func MergeBalances

func MergeBalances(balancesSlice ...[]banktypes.Balance) []banktypes.Balance

func MustGetClientResponse

func MustGetClientResponse[T Response](resp T, app QueryClient, req Request, url string) T

MustGetClientResponse is a helper function that sends a query to an abci query client and unmarshals the response into the provided response type. It panics if the query fails or if the response cannot be unmarshaled.

func MustGetResponse

func MustGetResponse[T Response](resp T, app QueryableApp, req Request, url string) (T, uint32)

MustGetResponse is a helper function that sends a query to a chain App and unmarshals the response into the provided response type. It panics if the query fails or if the response cannot be unmarshaled.

func MustGetResponseWithHeight

func MustGetResponseWithHeight[T Response](resp T, app QueryableApp, req Request, url string, height int64) T

MustGetResponseWithHeight is a helper function that sends a query to a chain App and unmarshals the response into the provided response type. It panics if the query fails or if the response cannot be unmarshaled.

func MustIntFromString

func MustIntFromString(s string) sdk.Int

func MustUnmarshalResultData

func MustUnmarshalResultData(codec codec.Codec, data []byte, ptr codec.ProtoMarshaler)

MustUnmarshalResultData unmarshals sdk.Result data to a provided response type or panics.

func NewDefaultValidatorSet

func NewDefaultValidatorSet() *tmtypes.ValidatorSet

NewDefaultValidatorSet returns a ValidatorSet with one random Validator

func NewValidatorSet

func NewValidatorSet(count int) *tmtypes.ValidatorSet

NewValidatorSet returns a default ValidatorSet with `count` random Validators

func QueryApp

func QueryApp[T Response](resp T, app QueryClient, req Request, url string, height int64) (T, error)

QueryApp is a helper function that sends a query to an abci query client and unmarshals the response into the provided response type. It returns the response and an error if the query fails or if the response cannot be unmarshaled.

func UnmarshalResultData

func UnmarshalResultData(codec codec.Codec, data []byte, ptr codec.ProtoMarshaler) error

UnmarshalResultData unmarshals sdk.Result data to a provided response type.

Types

type AccountI

type AccountI = authtypes.AccountI

type GenesisAccount

type GenesisAccount = authtypes.GenesisAccount

type PeptideApp

type PeptideApp struct {
	// App is the ABCI-compatible App
	// TODO: IMPORT YOUR ABCI APP HERE
	*app.App

	ValSet         *tmtypes.ValidatorSet
	EncodingConfig *params.EncodingConfig

	ChainId              string
	BondDenom            string
	VotingPowerReduction sdk.Int
	// contains filtered or unexported fields
}

PeptideApp extends the ABCI-compatible App with additional op-stack L2 chain features

func New

func New(chainID string, dir string, db tmdb.DB, logger tmlog.Logger) *PeptideApp

func NewWithOptions

func NewWithOptions(options PeptideAppOptions, logger tmlog.Logger) *PeptideApp

New creates application instance with in-memory database and disabled logging.

func (*PeptideApp) Clone

func (a *PeptideApp) Clone() *PeptideApp

Clone returns a new PeptideApp with genesis state from the current PeptideApp. The new app will have the same validator set `ValSet` as the current app. Note the new PeptideApp is not committed yet. Call CommitAndBeginBlock to commit.

Useful for testing module genesis export/import.

func (*PeptideApp) CommitAndBeginNextBlock

func (a *PeptideApp) CommitAndBeginNextBlock(timestamp eth.Uint64Quantity) *PeptideApp

Commit pending changes to chain state and start a new block. Will error if there is no deliverState, eg. InitChain is not called before first block.

func (*PeptideApp) CurrentHeader

func (a *PeptideApp) CurrentHeader() *tmproto.Header

CurrentHeader is the header that is being built, which is not committed yet

func (*PeptideApp) DefaultGenesis

func (a *PeptideApp) DefaultGenesis() app.GenesisState

DefaultGenesis create a default GenesisState, which is a map with module name as keys and JSON-marshaled genesisState per module as values

func (*PeptideApp) ExportGenesis

func (a *PeptideApp) ExportGenesis() app.GenesisState

ExportGenesis returns a copy of the app's genesis state

func (*PeptideApp) GetAccount

func (a *PeptideApp) GetAccount(addr sdk.AccAddress) AccountI

Return account from committed state

func (*PeptideApp) GetETH

func (a *PeptideApp) GetETH(addr sdk.AccAddress, height int64) (*sdkmath.Int, error)

GetETH returns the ETH balance of an account in wei

func (*PeptideApp) ImportAppStateAndValidators

func (a *PeptideApp) ImportAppStateAndValidators(
	exported *servertypes.ExportedApp,
) abci.ResponseInitChain

ImportAppStateAndValidators imports the application state, init height, and validators from ExportedApp defined by the chain App

func (*PeptideApp) Init

func (a *PeptideApp) Init(appState []byte, initialHeight int64, genesisTime time.Time) *tmproto.Header

This is what initiates the chain app initialisation. It's only meant to be called when the genesis is being sealed so the genesis block can be produced. - It triggers a call into the base app's InitChain() - Commits the app state to disk so it can be persisted across executions - Returns a "genesis header" with the genesis block height and app state hash

func (*PeptideApp) InitChainWithEmptyGenesis

func (a *PeptideApp) InitChainWithEmptyGenesis() abci.ResponseInitChain

func (*PeptideApp) InitChainWithGenesisState

func (a *PeptideApp) InitChainWithGenesisState(state app.GenesisState) abci.ResponseInitChain

func (*PeptideApp) InitChainWithGenesisStateAndHeight

func (a *PeptideApp) InitChainWithGenesisStateAndHeight(state []byte, height int64) abci.ResponseInitChain

func (*PeptideApp) LastHeader

func (a *PeptideApp) LastHeader() *tmproto.Header

LastHeader is the header that was committed, either as a genesis block header or the latest committed block header

func (*PeptideApp) MultiDelegationGenesis

func (a *PeptideApp) MultiDelegationGenesis(
	genAccs []GenesisAccount,
	balances []banktypes.Balance,
	delegators SignerAccounts,
	validators SignerAccounts,
	delegations ValidatorSetDelegation,
) app.GenesisState

MultiDelegationGenesis creates a genesis with given genesis accounts `genAccs` and validators, and delegations. Each validator must be delegated with staking tokens ≥ 1 voting power, ie. a.ReductionVotingPower x 1. `delegations` must be the same length as `validators`, where its index is for validators.

func (*PeptideApp) MultiSignAndDeliverMsgs

func (a *PeptideApp) MultiSignAndDeliverMsgs(
	signers []*SignerAccount,
	msgs ...sdk.Msg,
) (sdk.Tx, *sdk.Result, *sdk.GasInfo, error)

MultiSignAndDeliverMsgs signs a list of Msgs `msg` with multiple `signers`, and delivers it to the chain app

func (*PeptideApp) NewUncachedContextWithHeight

func (a *PeptideApp) NewUncachedContextWithHeight(height int64) context.Context

Return a SDK context wrapped in Go context, which is required by GRPC handler

func (*PeptideApp) NewUncachedSdkContext

func (a *PeptideApp) NewUncachedSdkContext() sdk.Context

Return a Cosmos-SDK context

func (*PeptideApp) NewWrappedUncachedContext

func (a *PeptideApp) NewWrappedUncachedContext() context.Context

Return a SDK context wrapped in Go context, which is required by GRPC handler

func (*PeptideApp) OnCommit

func (a *PeptideApp) OnCommit(timestamp eth.Uint64Quantity)

OnCommit updates the last header and current header after App Commit or InitChain

func (*PeptideApp) ReportMetrics

func (a *PeptideApp) ReportMetrics()

func (*PeptideApp) Resume

func (a *PeptideApp) Resume(lastHeader *tmproto.Header, genesisState []byte) error

Resume the normal activity after a (chain) restart. It sets the required pointers according to the last known header (that comes from the block store) and calls into the base app's BeginBlock()

func (*PeptideApp) RollbackToHeight

func (a *PeptideApp) RollbackToHeight(height int64) error

Rolls back the app state (i.e. commit multi store from the base app) to the specified height (version) If successful, the latest committed version is that of "height"

func (*PeptideApp) RunMsgs

func (a *PeptideApp) RunMsgs(ctx sdk.Context, msgs ...sdk.Msg) (*sdk.Result, error)

RunMsgs execute a list of L1 Msgs that are not signed by any L2 account NOTE: these msgs must be executed at the beginning of a block, before any L2 txs are executed

Logic is similar to ABCI app tx execution, but adjusted for L1 deposit txs TODO: cache context in case of revert

func (*PeptideApp) SignAndDeliverMsgs

func (a *PeptideApp) SignAndDeliverMsgs(
	signer *SignerAccount,
	msgs ...sdk.Msg,
) (sdk.Tx, *sdk.Result, *sdk.GasInfo, error)

SignAndDeliverMsgs signs a list of Msgs `msg` with a single `signer`, and delivers it to the chain app

func (*PeptideApp) SignMsgs

func (a *PeptideApp) SignMsgs(signers []*SignerAccount, msg ...sdk.Msg) (sdk.Tx, error)

SignMsgs signs a list of Msgs `msg` with `signers`

func (*PeptideApp) SimpleGenesis

func (a *PeptideApp) SimpleGenesis(
	genAccs SignerAccounts,
	valAccs SignerAccounts,
	balances ...banktypes.Balance,
) app.GenesisState

SimpleGenesis creates a genesis with given genesis accounts `genAccs` and one derived validator. The first genesis account is used for delegation with bond amount of 1 voting power.

`balances` should include staking tokens for all transactor accounts in `genAccs`. If left empty, `a.VotingPowerReduction` ie. 1 voting power worth staking tokens will be added for each account.

Validators are saved in `a.ValSet` for block production later.

func (*PeptideApp) WrapSDKContext

func (a *PeptideApp) WrapSDKContext(ctx sdk.Context) context.Context

Convert a SDK context to Go context

type PeptideAppOptions

type PeptideAppOptions struct {
	DB                  tmdb.DB
	HomePath            string
	ChainID             string
	IAVLDisableFastNode bool
	IAVLLazyLoading     bool
}

type PrivKey

type PrivKey = cryptotypes.PrivKey

type QueryClient

type QueryClient interface {
	QuerySync(req abci.RequestQuery) (*abci.ResponseQuery, error)
}

type QueryableApp

type QueryableApp interface {
	Query(req abci.RequestQuery) (res abci.ResponseQuery)
}

type Request

type Request interface {
	Marshal() ([]byte, error)
}

type Response

type Response interface {
	Unmarshal(resp []byte) error
}

type SignerAccount

type SignerAccount struct {
	GenesisAccount
	PrivKey
}

func NewEd25519SignerAccount

func NewEd25519SignerAccount(acctNumber, seqNumber uint64) *SignerAccount

NewEd25519SignerAccount creates a new SignerAccount with the given account number and sequence number baced by ed25519

func NewSecp256k1SignerAccount

func NewSecp256k1SignerAccount(acctNumber, seqNumber uint64) *SignerAccount

NewSecp256k1SignerAccount creates a new SignerAccount with the given account number and sequence number

func NewSignerAccount

func NewSignerAccount(genesisAccount GenesisAccount, privKey PrivKey) *SignerAccount

func (*SignerAccount) MarshalJSON

func (sa *SignerAccount) MarshalJSON() ([]byte, error)

func (*SignerAccount) UnmarshalJSON

func (sa *SignerAccount) UnmarshalJSON(bz []byte) error

type SignerAccounts

type SignerAccounts []*SignerAccount

func NewSignerAccounts

func NewSignerAccounts(n uint64, startingSeqNum uint64) SignerAccounts

NewSignerAccounts creates a list of Secp256k1 SignerAccount with the given number of accounts `n` and starting sequence number `startingSeqNum`

func NewValidatorSignerAccounts

func NewValidatorSignerAccounts(n uint64, startingSeqNum uint64) SignerAccounts

NewSignerAccounts creates a list of ed25519 SignerAccount with the given number of accounts `n` and starting sequence number `startingSeqNum`

func (SignerAccounts) Addresses

func (a SignerAccounts) Addresses() []string

Addresses return a slice of bech32 encoded addresses prefixed with `Bech32PrefixAccAddr`

func (SignerAccounts) GetGenesisAccounts

func (a SignerAccounts) GetGenesisAccounts() []GenesisAccount

func (SignerAccounts) NewBalances

func (a SignerAccounts) NewBalances(denom string, amount sdk.Int) []banktypes.Balance

type SingleDelegation

type SingleDelegation struct {
	AccountIndex int
	Amount       math.Int
}

type TxSigner

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

TxSigner represents a group of signers that can sign a transaction. all tx related configs can be cached and can be changed when needed.

func NewTxSigner

func NewTxSigner(
	txConfig client.TxConfig,
	feeAmt sdk.Coins,
	gas uint64,
	chainID string,
) TxSigner

NewTxSigner creates a new TxSigner.

func (*TxSigner) AddSigner

func (s *TxSigner) AddSigner(accNum, accSeq uint64, priv cryptotypes.PrivKey)

AddSinger adds a signer to the TxSigner.

func (TxSigner) SignTx

func (s TxSigner) SignTx(memo string, msgs ...sdk.Msg) (sdk.Tx, error)

SignTx signs a transaction.

type ValidatorDelegation

type ValidatorDelegation []SingleDelegation

type ValidatorSetDelegation

type ValidatorSetDelegation []ValidatorDelegation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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