state

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package state provides a structure for celestia-node's ability to access state-relevant information from as well as submit transactions/messages to the celestia network.

This package contains one main interface, `Accessor`, that defines the methods available for both accessing and updating state on the celestia network.

`Accessor` will contain three different implementations:

  1. Implementation over a gRPC connection with a celestia-core node called `CoreAccess`.
  2. Implementation over a libp2p stream with a state-providing node.
  3. Implementation over a local running instance of the celestia-application (this feature will be implemented in *Full* nodes).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccAddress added in v0.3.1

type AccAddress = sdk.AccAddress

AccAddress is an alias to the AccAddress type from Cosmos-SDK.

type Accessor

type Accessor interface {
	// Start starts the state Accessor.
	Start(context.Context) error
	// Stop stops the state Accessor.
	Stop(context.Context) error

	// Balance retrieves the Celestia coin balance for the node's account/signer
	// and verifies it against the corresponding block's AppHash.
	Balance(ctx context.Context) (*Balance, error)
	// BalanceForAddress retrieves the Celestia coin balance for the given address and verifies
	// the returned balance against the corresponding block's AppHash.
	//
	// NOTE: the balance returned is the balance reported by the block right before
	// the node's current head (head-1). This is due to the fact that for block N, the block's
	// `AppHash` is the result of applying the previous block's transaction list.
	BalanceForAddress(ctx context.Context, addr Address) (*Balance, error)

	// Transfer sends the given amount of coins from default wallet of the node to the given account address.
	Transfer(ctx context.Context, to AccAddress, amount math.Int, gasLimit uint64) (*TxResponse, error)
	// SubmitTx submits the given transaction/message to the
	// Celestia network and blocks until the tx is included in
	// a block.
	SubmitTx(ctx context.Context, tx Tx) (*TxResponse, error)
	// SubmitPayForData builds, signs and submits a PayForData transaction.
	SubmitPayForData(ctx context.Context, nID namespace.ID, data []byte, gasLim uint64) (*TxResponse, error)

	// CancelUnbondingDelegation cancels a user's pending undelegation from a validator.
	CancelUnbondingDelegation(
		ctx context.Context,
		valAddr ValAddress,
		amount,
		height Int,
		gasLim uint64,
	) (*TxResponse, error)
	// BeginRedelegate sends a user's delegated tokens to a new validator for redelegation.
	BeginRedelegate(ctx context.Context, srcValAddr, dstValAddr ValAddress, amount Int, gasLim uint64) (*TxResponse, error)
	// Undelegate undelegates a user's delegated tokens, unbonding them from the current validator.
	Undelegate(ctx context.Context, delAddr ValAddress, amount Int, gasLim uint64) (*TxResponse, error)
	// Delegate sends a user's liquid tokens to a validator for delegation.
	Delegate(ctx context.Context, delAddr ValAddress, amount Int, gasLim uint64) (*TxResponse, error)

	// QueryDelegation retrieves the delegation information between a delegator and a validator.
	QueryDelegation(ctx context.Context, valAddr ValAddress) (*types.QueryDelegationResponse, error)
	// QueryUnbonding retrieves the unbonding status between a delegator and a validator.
	QueryUnbonding(ctx context.Context, valAddr ValAddress) (*types.QueryUnbondingDelegationResponse, error)
	// QueryRedelegations retrieves the status of the redelegations between a delegator and a validator.
	QueryRedelegations(ctx context.Context, srcValAddr, dstValAddr ValAddress) (*types.QueryRedelegationsResponse, error)
}

Accessor represents the behaviors necessary for a user to query for state-related information and submit transactions/ messages to the Celestia network.

type Address

type Address = sdk.Address

Address is an alias to the Address type from Cosmos-SDK.

type Balance

type Balance = sdk.Coin

Balance is an alias to the Coin type from Cosmos-SDK.

type CoreAccessor

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

CoreAccessor implements Accessor over a gRPC connection with a celestia-core node.

func NewCoreAccessor

func NewCoreAccessor(
	signer *apptypes.KeyringSigner,
	getter header.Head,
	coreIP,
	rpcPort string,
	grpcPort string,
) *CoreAccessor

NewCoreAccessor dials the given celestia-core endpoint and constructs and returns a new CoreAccessor with the active connection.

func (*CoreAccessor) Balance

func (ca *CoreAccessor) Balance(ctx context.Context) (*Balance, error)

func (*CoreAccessor) BalanceForAddress

func (ca *CoreAccessor) BalanceForAddress(ctx context.Context, addr Address) (*Balance, error)

func (*CoreAccessor) BeginRedelegate

func (ca *CoreAccessor) BeginRedelegate(
	ctx context.Context,
	srcValAddr,
	dstValAddr ValAddress,
	amount Int,
	gasLim uint64,
) (*TxResponse, error)

func (*CoreAccessor) CancelUnbondingDelegation

func (ca *CoreAccessor) CancelUnbondingDelegation(
	ctx context.Context,
	valAddr ValAddress,
	amount,
	height Int,
	gasLim uint64,
) (*TxResponse, error)

func (*CoreAccessor) Delegate

func (ca *CoreAccessor) Delegate(
	ctx context.Context,
	delAddr ValAddress,
	amount Int,
	gasLim uint64,
) (*TxResponse, error)

func (*CoreAccessor) QueryDelegation added in v0.3.1

func (ca *CoreAccessor) QueryDelegation(
	ctx context.Context,
	valAddr ValAddress,
) (*stakingtypes.QueryDelegationResponse, error)

func (*CoreAccessor) QueryRedelegations added in v0.3.1

func (ca *CoreAccessor) QueryRedelegations(
	ctx context.Context,
	srcValAddr,
	dstValAddr ValAddress,
) (*stakingtypes.QueryRedelegationsResponse, error)

func (*CoreAccessor) QueryUnbonding added in v0.3.1

func (*CoreAccessor) Start

func (ca *CoreAccessor) Start(ctx context.Context) error

func (*CoreAccessor) Stop

func (ca *CoreAccessor) Stop(context.Context) error

func (*CoreAccessor) SubmitPayForData

func (ca *CoreAccessor) SubmitPayForData(
	ctx context.Context,
	nID namespace.ID,
	data []byte,
	gasLim uint64,
) (*TxResponse, error)

func (*CoreAccessor) SubmitTx

func (ca *CoreAccessor) SubmitTx(ctx context.Context, tx Tx) (*TxResponse, error)

func (*CoreAccessor) SubmitTxWithBroadcastMode

func (ca *CoreAccessor) SubmitTxWithBroadcastMode(
	ctx context.Context,
	tx Tx,
	mode sdktx.BroadcastMode,
) (*TxResponse, error)

func (*CoreAccessor) Transfer

func (ca *CoreAccessor) Transfer(
	ctx context.Context,
	addr AccAddress,
	amount Int,
	gasLim uint64,
) (*TxResponse, error)

func (*CoreAccessor) Undelegate

func (ca *CoreAccessor) Undelegate(
	ctx context.Context,
	delAddr ValAddress,
	amount Int,
	gasLim uint64,
) (*TxResponse, error)

type Int

type Int = math.Int

Int is an alias to the Int type from Cosmos-SDK.

type Service

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

Service can access state-related information via the given Accessor.

func NewService

func NewService(accessor Accessor) *Service

NewService constructs a new state Service.

func (*Service) Balance

func (s *Service) Balance(ctx context.Context) (*Balance, error)

func (*Service) BalanceForAddress

func (s *Service) BalanceForAddress(ctx context.Context, addr Address) (*Balance, error)

func (*Service) BeginRedelegate

func (s *Service) BeginRedelegate(
	ctx context.Context,
	srcValAddr,
	dstValAddr ValAddress,
	amount Int,
	gasLim uint64,
) (*TxResponse, error)

func (*Service) CancelUnbondingDelegation

func (s *Service) CancelUnbondingDelegation(
	ctx context.Context,
	valAddr ValAddress,
	amount,
	height Int,
	gasLim uint64,
) (*TxResponse, error)

func (*Service) Delegate

func (s *Service) Delegate(ctx context.Context, delAddr ValAddress, amount Int, gasLim uint64) (*TxResponse, error)

func (*Service) IsStopped

func (s *Service) IsStopped() bool

IsStopped checks if context was canceled.

func (*Service) QueryDelegation added in v0.3.1

func (s *Service) QueryDelegation(
	ctx context.Context,
	valAddr ValAddress,
) (*types.QueryDelegationResponse, error)

func (*Service) QueryRedelegations added in v0.3.1

func (s *Service) QueryRedelegations(
	ctx context.Context,
	srcValAddr,
	dstValAddr ValAddress,
) (*types.QueryRedelegationsResponse, error)

func (*Service) QueryUnbonding added in v0.3.1

func (s *Service) QueryUnbonding(
	ctx context.Context,
	valAddr ValAddress,
) (*types.QueryUnbondingDelegationResponse, error)

func (*Service) Start

func (s *Service) Start(context.Context) error

func (*Service) Stop

func (s *Service) Stop(context.Context) error

func (*Service) SubmitPayForData

func (s *Service) SubmitPayForData(
	ctx context.Context,
	nID namespace.ID,
	data []byte,
	gasLim uint64,
) (*TxResponse, error)

func (*Service) SubmitTx

func (s *Service) SubmitTx(ctx context.Context, tx Tx) (*TxResponse, error)

func (*Service) Transfer

func (s *Service) Transfer(ctx context.Context, to AccAddress, amount Int, gasLimit uint64) (*TxResponse, error)

func (*Service) Undelegate

func (s *Service) Undelegate(ctx context.Context, delAddr ValAddress, amount Int, gasLim uint64) (*TxResponse, error)

type Tx

type Tx = coretypes.Tx

Tx is an alias to the Tx type from celestia-core.

type TxResponse

type TxResponse = sdk.TxResponse

TxResponse is an alias to the TxResponse type from Cosmos-SDK.

type ValAddress added in v0.3.1

type ValAddress = sdk.ValAddress

ValAddress is an alias to the ValAddress type from Cosmos-SDK.

Jump to

Keyboard shortcuts

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