pchain

package
v0.1.45 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpImportAvax                 = "IMPORT_AVAX"
	OpExportAvax                 = "EXPORT_AVAX"
	OpAddValidator               = "ADD_VALIDATOR"
	OpAddPermissionlessValidator = "ADD_PERMISSIONLESS_VALIDATOR"
	OpAddDelegator               = "ADD_DELEGATOR"
	OpAddPermissionlessDelegator = "ADD_PERMISSIONLESS_DELEGATOR"
	OpRewardValidator            = "REWARD_VALIDATOR"
	OpCreateChain                = "CREATE_CHAIN"
	OpCreateSubnet               = "CREATE_SUBNET"
	OpAddSubnetValidator         = "ADD_SUBNET_VALIDATOR"
	OpRemoveSubnetValidator      = "REMOVE_SUBNET_VALIDATOR"
	OpTransformSubnetValidator   = "TRANSFORM_SUBNET_VALIDATOR"
	OpAdvanceTime                = "ADVANCE_TIME"
	OpBase                       = "BASE"
	OpTransferSubnetOwnership    = "TRANSFER_SUBNET_OWNERSHIP"

	OpTypeImport      = "IMPORT"
	OpTypeExport      = "EXPORT"
	OpTypeInput       = "INPUT"
	OpTypeOutput      = "OUTPUT"
	OpTypeStakeOutput = "STAKE"
	OpTypeReward      = "REWARD"

	MetadataOpType           = "type"
	MetadataTxType           = "tx_type"
	MetadataStakingTxID      = "staking_tx_id"
	MetadataValidatorNodeID  = "validator_node_id"
	MetadataStakingStartTime = "staking_start_time"
	MetadataStakingEndTime   = "staking_end_time"
	MetadataMessage          = "message"
	MetadataSigner           = "signer"

	MetadataValidatorRewards       = "validator_rewards"
	MetadataValidatorRewardsOwner  = "validator_rewards_owner"
	MetadataDelegationRewardsOwner = "delegation_rewards_owner"
	MetadataDelegatorRewardsOwner  = "delegator_rewards_owner"
	MetadataDelegationRewards      = "delegation_rewards"
	MetadataDelegationFeeRewards   = "delegation_fee_rewards"
	MetadataSubnetID               = "subnet_id"

	SubAccountTypeSharedMemory       = "shared_memory"
	SubAccountTypeUnlocked           = "unlocked"
	SubAccountTypeLockedStakeable    = "locked_stakeable"
	SubAccountTypeLockedNotStakeable = "locked_not_stakeable"
	SubAccountTypeStaked             = "staked"
)

Variables

Functions

func BuildTx

func BuildTx(
	opType string,
	matches []*parser.Match,
	payloadMetadata Metadata,
	codec codec.Manager,
	avaxAssetID ids.ID,
) (*txs.Tx, []*types.AccountIdentifier, error)

BuildTx constructs a P-chain Tx based on the provided operation type, Rosetta matches and metadata This method is only used during construction.

func GetTxDependenciesIDs added in v0.1.42

func GetTxDependenciesIDs(tx txs.UnsignedTx) ([]ids.ID, error)

GetTxDependenciesIDs generates the list of transaction ids used in the inputs to given unsigned transaction this list is then used to fetch the dependency transactions in order to extract source addresses as this information is not part of the transaction objects on chain.

func ParseRosettaTxs

func ParseRosettaTxs(
	parserCfg TxParserConfig,
	txs []*txs.Tx,
	dependencyTxs BlockTxDependencies,
) ([]*types.Transaction, error)

Types

type BlockTxDependencies

type BlockTxDependencies map[ids.ID]*SingleTxDependency

func (BlockTxDependencies) GetReferencedAccounts

func (bd BlockTxDependencies) GetReferencedAccounts(hrp string) (map[string]*types.AccountIdentifier, error)

GetReferencedAccounts extracts destination accounts from given dependency transactions

type ExportMetadata

type ExportMetadata struct {
	DestinationChain   string `json:"destination_chain"`
	DestinationChainID ids.ID `json:"destination_chain_id"`
}

ExportMetadata contain response fields returned by /construction/metadata for P-chain Export transactions

type ImportExportOptions

type ImportExportOptions struct {
	SourceChain      string `json:"source_chain"`
	DestinationChain string `json:"destination_chain"`
}

ImportExportOptions contain response fields returned by /construction/preprocess for P-chain Import/Export transactions

type ImportMetadata

type ImportMetadata struct {
	SourceChainID ids.ID `json:"source_chain_id"`
}

ImportMetadata contain response fields returned by /construction/metadata for P-chain Import transactions

type Metadata

type Metadata struct {
	NetworkID    uint32 `json:"network_id"`
	BlockchainID ids.ID `json:"blockchain_id"`
	*ImportMetadata
	*ExportMetadata
	*StakingMetadata
}

Metadata contains metadata values returned by /construction/metadata for P-chain transactions

type OperationMetadata

type OperationMetadata struct {
	Type       string   `json:"type"`
	SigIndices []uint32 `json:"sig_indices,omitempty"`
	Locktime   uint64   `json:"locktime"`
	Threshold  uint32   `json:"threshold,omitempty"`
}

OperationMetadata contains metadata fields specific to individual Rosetta operations as opposed to transactions

func ParseOpMetadata

func ParseOpMetadata(metadata map[string]interface{}) (*OperationMetadata, error)

ParseOpMetadata creates an OperationMetadata from given generic metadata map

type SingleTxDependency

type SingleTxDependency struct {
	// [Tx] has some of its outputs spent as
	// input from a tx dependent on it
	Tx *txs.Tx

	// Staker txs are rewarded at the end of staking period
	// with some utxos appended to staker txs' ones.
	// [RewardUTXOs] collects those reward utxos
	RewardUTXOs []*avax.UTXO
	// contains filtered or unexported fields
}

SingleTxDependency represents a single dependency of a give transaction

func (*SingleTxDependency) GetUtxos

func (d *SingleTxDependency) GetUtxos() map[avax.UTXOID]*avax.UTXO

type StakingMetadata

type StakingMetadata struct {
	NodeID                  string   `json:"node_id"`
	BLSPublicKey            string   `json:"bls_public_key"`
	BLSProofOfPossession    string   `json:"bls_proof_of_possession"`
	ValidationRewardsOwners []string `json:"reward_addresses"`
	DelegationRewardsOwners []string `json:"delegator_reward_addresses"`
	Start                   uint64   `json:"start"` // TODO: Remove Post-Durango
	End                     uint64   `json:"end"`
	Subnet                  string   `json:"subnet"`
	Shares                  uint32   `json:"shares"`
	Locktime                uint64   `json:"locktime"`
	Threshold               uint32   `json:"threshold"`
}

StakingMetadata contain response fields returned by /construction/metadata for P-chain AddValidator/AddDelegator transactions

type StakingOptions

type StakingOptions struct {
	NodeID                  string   `json:"node_id"`
	BLSPublicKey            string   `json:"bls_public_key"`
	BLSProofOfPossession    string   `json:"bls_proof_of_possession"`
	ValidationRewardsOwners []string `json:"reward_addresses"`
	DelegationRewardsOwners []string `json:"delegator_reward_addresses"`
	Start                   uint64   `json:"start"` // TODO: Remove Post-Durango
	End                     uint64   `json:"end"`
	Subnet                  string   `json:"subnet"`
	Shares                  uint32   `json:"shares"`
	Locktime                uint64   `json:"locktime"`
	Threshold               uint32   `json:"threshold"`
}

StakingOptions contain response fields returned by /construction/preprocess for P-chain AddValidator/AddDelegator transactions

type TxParser

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

TxParser parses P-chain transactions and generate corresponding Rosetta operations

func NewTxParser

func NewTxParser(
	cfg TxParserConfig,
	inputTxAccounts map[string]*types.AccountIdentifier,
	dependencyTxs BlockTxDependencies,
) (*TxParser, error)

NewTxParser returns a new transaction parser

func (*TxParser) Parse

func (t *TxParser) Parse(signedTx *txs.Tx) (*types.Transaction, error)

Parse converts the given unsigned P-chain tx to corresponding Rosetta Transaction

type TxParserConfig

type TxParserConfig struct {
	// IsConstruction indicates if parsing is done as part of construction or /block endpoints
	IsConstruction bool
	// Hrp used for address formatting
	Hrp string

	// ChainIDs maps chain id to chain id alias mappings
	// ChainIDs may provided by TxParser called or lazily initialized,
	// as soon as pChainClient is ready to serve requests
	ChainIDs map[ids.ID]constants.ChainIDAlias

	// AvaxAssetID contains asset id for AVAX currency
	AvaxAssetID ids.ID
	// PChainClient holds a P-chain client, used to lookup asset descriptions for non-AVAX assets
	PChainClient client.PChainClient
}

Jump to

Keyboard shortcuts

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