tx

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 21 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoGasPrice  = errors.New("no known gas price")
	ErrNoGasFactor = errors.New("no known gas factor")
)

Functions

func GetSoftSigner

func GetSoftSigner(slip44 uint, mnemonic string) (crypto.BytesSigner, error)

Get a signer given a SLIP44 value.

func IsGasPriceError added in v1.1.0

func IsGasPriceError(codespace string, code uint32) bool

Helper function to determine if an error is related to too small of a gas price

func IsGasRelatedError added in v1.1.0

func IsGasRelatedError(codespace string, code uint32) bool

Helper function to know if an error had to do with gas.

func IsSuccess added in v1.1.0

func IsSuccess(broadcastResult *txtypes.BroadcastTxResponse) (bool, error)

func IsSuccessTxStatus added in v1.1.0

func IsSuccessTxStatus(txStatus *txtypes.GetTxResponse) bool

Types

type Broadcaster added in v1.1.0

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

func NewDefaultBroadcaster added in v1.1.0

func NewDefaultBroadcaster(
	chainName string,
	bech32Prefix string,
	signer crypto.BytesSigner,
	gasManager GasManager,
	logger *log.Logger,
	rpcClient rpc.RpcClient,
	signingMetadataProvider *SigningMetadataProvider,
	txProvider TxProvider,

	txPollAttempts uint,
	txPollDelay time.Duration,

	retryAttempts uint,
	retryDelay time.Duration,
) (*Broadcaster, error)

Retryable broadcaster with polling and gas management.

func (*Broadcaster) SignAndBroadcast added in v1.1.0

func (b *Broadcaster) SignAndBroadcast(ctx context.Context, msgs []sdk.Msg) (txHash string, err error)

type FileGasPriceProvider added in v1.1.7

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

FileGasPriceProvider writes gas prices to a file by internally wrapping calls to an InMemoryGasPriceProvider.

func (*FileGasPriceProvider) GetGasFactor added in v1.1.7

func (p *FileGasPriceProvider) GetGasFactor(chainName string) (float64, error)

func (*FileGasPriceProvider) GetGasPrice added in v1.1.7

func (p *FileGasPriceProvider) GetGasPrice(chainName string) (float64, error)

func (*FileGasPriceProvider) HasGasFactor added in v1.1.7

func (p *FileGasPriceProvider) HasGasFactor(chainName string) (bool, error)

func (*FileGasPriceProvider) HasGasPrice added in v1.1.7

func (p *FileGasPriceProvider) HasGasPrice(chainName string) (bool, error)

func (*FileGasPriceProvider) SetGasFactor added in v1.1.7

func (p *FileGasPriceProvider) SetGasFactor(chainName string, gasFactor float64) error

func (*FileGasPriceProvider) SetGasPrice added in v1.1.7

func (p *FileGasPriceProvider) SetGasPrice(chainName string, gasPrice float64) error

type GasData added in v1.1.7

type GasData struct {
	GasFactors map[string]float64 `json:"gas_factors"`
	GasPrices  map[string]float64 `json:"gas_prices"`
}

Data format for gas file.

type GasManager

type GasManager interface {
	InitializePrice(chainName string, gasPrice float64) error

	// Get a suggested gas price for the chainName
	GetGasPrice(chainName string) (float64, error)

	// Get a gas factor for the chain name
	GetGasFactor(chainName string) (float64, error)

	// Given a broadcast result for a chainName, update gas prices. Calling with a successful broadcast result is a no-op. Tally successes
	// using ManageTransactionStatus.
	ManageFailingBroadcastResult(chainName string, broadcastResult *txtypes.BroadcastTxResponse) error

	// Manage a transaction status once it has settled on chain. Statuses could be positive or negative.
	ManageIncludedTransactionStatus(chainName string, txStatus *txtypes.GetTxResponse) error

	// Manage a failure in the case a tx was successfully broadcasted, but never landed on chain and we thus are unable to provide a tx status
	ManageInclusionFailure(chainName string) error
}

GasManager interprets tx results and associated outcomes.

func NewGeometricGasManager added in v1.1.0

func NewGeometricGasManager(
	stepSize float64,
	maxStepSize float64,
	scaleFactor float64,
	gasPriceProvider GasPriceProvider,
	logger *log.Logger,
) (GasManager, error)

type GasPriceProvider

type GasPriceProvider interface {
	HasGasPrice(chainName string) (bool, error)
	GetGasPrice(chainName string) (float64, error)
	SetGasPrice(chainName string, gasPrice float64) error

	HasGasFactor(chainName string) (bool, error)
	GetGasFactor(chainName string) (float64, error)
	SetGasFactor(chainName string, gasFactor float64) error
	// contains filtered or unexported methods
}

GasPriceProvider is a simple KV store for gas.

func NewFileGasPriceProvider added in v1.1.7

func NewFileGasPriceProvider(logger *log.Logger, dataDirectory string) (GasPriceProvider, error)

Create a new FileGasProvider which will wrap an in-memory gas price provider

func NewInMemoryGasPriceProvider added in v1.0.14

func NewInMemoryGasPriceProvider() (GasPriceProvider, error)

type InMemoryGasPriceProvider

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

InMemoryGasPriceProvider stores gas prices in memory.

func (*InMemoryGasPriceProvider) GetGasFactor added in v1.1.0

func (gp *InMemoryGasPriceProvider) GetGasFactor(chainName string) (float64, error)

func (*InMemoryGasPriceProvider) GetGasPrice

func (gp *InMemoryGasPriceProvider) GetGasPrice(chainName string) (float64, error)

func (*InMemoryGasPriceProvider) HasGasFactor added in v1.1.0

func (gp *InMemoryGasPriceProvider) HasGasFactor(chainName string) (bool, error)

func (*InMemoryGasPriceProvider) HasGasPrice added in v1.1.0

func (gp *InMemoryGasPriceProvider) HasGasPrice(chainName string) (bool, error)

func (*InMemoryGasPriceProvider) SetGasFactor added in v1.1.0

func (gp *InMemoryGasPriceProvider) SetGasFactor(chainName string, gasFactor float64) error

func (*InMemoryGasPriceProvider) SetGasPrice

func (gp *InMemoryGasPriceProvider) SetGasPrice(chainName string, gasPrice float64) error

type SigningMetadata

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

func (*SigningMetadata) AccountNumber

func (sm *SigningMetadata) AccountNumber() uint64

func (*SigningMetadata) Address

func (sm *SigningMetadata) Address() string

func (*SigningMetadata) ChainID added in v1.0.13

func (sm *SigningMetadata) ChainID() string

func (*SigningMetadata) Sequence

func (sm *SigningMetadata) Sequence() uint64

type SigningMetadataProvider

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

func NewSigningMetadataProvider

func NewSigningMetadataProvider(chainID string, rpcClient rpc.RpcClient) (*SigningMetadataProvider, error)

func (*SigningMetadataProvider) SigningMetadataForAccount

func (sip *SigningMetadataProvider) SigningMetadataForAccount(ctx context.Context, address string) (*SigningMetadata, error)

type SimulationManager

type SimulationManager interface {
	SimulateTx(ctx context.Context, tx authsigning.Tx, gasFactor float64) (*SimulationResult, error)
	SimulateTxBytes(ctx context.Context, txBytes []byte, gasFactor float64) (*SimulationResult, error)
}

SimulationManager manages simulating gas from transactions.

func NewSimulationManager

func NewSimulationManager(rpcClient rpc.RpcClient, txConfig client.TxConfig) (SimulationManager, error)

NewSimulationManager makes a new default simulationManager

type SimulationResult

type SimulationResult struct {
	GasRecommendation int64
}

type TxBroadcaster added in v1.1.0

type TxBroadcaster interface {
	// contains filtered or unexported methods
}

Broadcasts transactions reliably, and with retries

func NewDefaultTxBroadcaster added in v1.1.0

func NewDefaultTxBroadcaster(
	chainName string,
	bech32Prefix string,
	signer crypto.BytesSigner,
	gasManager GasManager,
	logger *log.Logger,
	rpcClient rpc.RpcClient,
	signingMetadataProvider *SigningMetadataProvider,
	txProvider TxProvider,
) (TxBroadcaster, error)

func NewGasTrackingTxBroadcaster added in v1.1.0

func NewGasTrackingTxBroadcaster(
	chainName string,
	gasManager GasManager,
	logger *log.Logger,
	wrappedBroadcaster TxBroadcaster,
) (TxBroadcaster, error)

func NewPollingTxBroadcaster added in v1.1.0

func NewPollingTxBroadcaster(
	attempts uint,
	delay time.Duration,
	logger *log.Logger,
	wrappedBroadcaster TxBroadcaster,
) (TxBroadcaster, error)

func NewRetryableBroadcaster added in v1.1.0

func NewRetryableBroadcaster(
	attempts uint,
	delay time.Duration,
	logger *log.Logger,
	wrappedBroadcaster TxBroadcaster,
) (TxBroadcaster, error)

type TxProvider added in v1.0.14

type TxProvider interface {
	ProvideTx(ctx context.Context, gasPrice, gasFactor float64, messages []sdk.Msg, metadata *SigningMetadata) ([]byte, int64, error)
}

func NewTxProvider added in v1.0.14

func NewTxProvider(bytesSigner crypto.BytesSigner, chainID, feeDenom, memo string, logger *log.Logger, simulationManager SimulationManager, txConfig client.TxConfig) (TxProvider, error)

Jump to

Keyboard shortcuts

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