platform

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package pchain provides the P-Chain (Platform) adapter for the LINEAR chain indexer. Handles validators, delegators, subnets, and staking operations.

Index

Constants

View Source
const (
	DefaultRPCEndpoint = "http://localhost:9650/ext/bc/P"
	DefaultHTTPPort    = 4100
)

Variables

This section is empty.

Functions

func NewConfig

func NewConfig() chain.Config

NewConfig creates a default P-Chain indexer configuration

Types

type Adapter

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

Adapter implements chain.Adapter for P-Chain

func New

func New(rpcEndpoint string) *Adapter

New creates a new P-Chain adapter

func (*Adapter) GetBlockByHeight

func (a *Adapter) GetBlockByHeight(ctx context.Context, height uint64) (json.RawMessage, error)

GetBlockByHeight implements chain.Adapter

func (*Adapter) GetBlockByID

func (a *Adapter) GetBlockByID(ctx context.Context, id string) (json.RawMessage, error)

GetBlockByID implements chain.Adapter

func (*Adapter) GetBlockchains

func (a *Adapter) GetBlockchains(ctx context.Context) ([]Blockchain, error)

GetBlockchains fetches all blockchains from RPC

func (*Adapter) GetCurrentValidators

func (a *Adapter) GetCurrentValidators(ctx context.Context, netID string) ([]Validator, error)

GetCurrentValidators fetches current validators from RPC

func (*Adapter) GetNets

func (a *Adapter) GetNets(ctx context.Context) ([]Net, error)

GetNets fetches all chains from RPC.

func (*Adapter) GetPendingValidators

func (a *Adapter) GetPendingValidators(ctx context.Context, netID string) ([]Validator, error)

GetPendingValidators fetches pending validators from RPC

func (*Adapter) GetRecentBlocks

func (a *Adapter) GetRecentBlocks(ctx context.Context, limit int) ([]json.RawMessage, error)

GetRecentBlocks implements chain.Adapter

func (*Adapter) GetStats

func (a *Adapter) GetStats(ctx context.Context, store storage.Store) (map[string]interface{}, error)

GetStats implements chain.Adapter - returns P-Chain specific statistics

func (*Adapter) InitSchema

func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error

InitSchema implements chain.Adapter - creates P-Chain specific tables

func (*Adapter) ParseBlock

func (a *Adapter) ParseBlock(data json.RawMessage) (*chain.Block, error)

ParseBlock implements chain.Adapter

func (*Adapter) SyncValidators

func (a *Adapter) SyncValidators(ctx context.Context, store storage.Store) error

SyncValidators syncs validator data from RPC to database

type Blockchain

type Blockchain struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	NetID string `json:"netID"`
	VMID  string `json:"vmID"`
}

Blockchain represents a P-Chain blockchain

type Delegator

type Delegator struct {
	TxID            string `json:"txID"`
	NodeID          string `json:"nodeID"`
	StartTime       string `json:"startTime"`
	EndTime         string `json:"endTime"`
	StakeAmount     string `json:"stakeAmount"`
	PotentialReward string `json:"potentialReward"`
	RewardOwner     string `json:"rewardOwner,omitempty"`
}

Delegator represents a P-Chain delegator

type Net

type Net struct {
	ID          string   `json:"id"`
	ControlKeys []string `json:"controlKeys"`
	Threshold   string   `json:"threshold"`
}

Net represents a P-Chain network/chain

type PChainBlock

type PChainBlock struct {
	ID        string     `json:"id"`
	ParentID  string     `json:"parentID"`
	Height    uint64     `json:"height"`
	Timestamp int64      `json:"timestamp"` // Unix timestamp
	Txs       []PChainTx `json:"txs"`
}

PChainBlock represents a P-Chain block from RPC

type PChainTx

type PChainTx struct {
	ID          string          `json:"id"`
	Type        string          `json:"type"`
	Inputs      json.RawMessage `json:"inputs,omitempty"`
	Outputs     json.RawMessage `json:"outputs,omitempty"`
	Credentials json.RawMessage `json:"credentials,omitempty"`
	// Validator-specific fields
	NodeID    string `json:"nodeID,omitempty"`
	StartTime int64  `json:"startTime,omitempty"`
	EndTime   int64  `json:"endTime,omitempty"`
	Weight    uint64 `json:"weight,omitempty"`
	NetID     string `json:"netID,omitempty"` // For subnet operations
}

PChainTx represents a P-Chain transaction

type Validator

type Validator struct {
	TxID            string      `json:"txID"`
	NodeID          string      `json:"nodeID"`
	StartTime       string      `json:"startTime"`
	EndTime         string      `json:"endTime"`
	Weight          string      `json:"weight"`
	StakeAmount     string      `json:"stakeAmount,omitempty"` // Deprecated, use Weight
	PotentialReward string      `json:"potentialReward"`
	DelegationFee   string      `json:"delegationFee"`
	Uptime          string      `json:"uptime"`
	Connected       bool        `json:"connected"`
	Delegators      []Delegator `json:"delegators,omitempty"`
}

Validator represents a P-Chain validator

Jump to

Keyboard shortcuts

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