celestia

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2022 License: MIT Imports: 9 Imported by: 0

README

Celestia node API

Golang wrapper over Celestia node API. Library implements API from the docs.

Install

go get github.com/dipdup-net/celestia-node-api

Usage

First, create API structure

api := NewAPI("base URL to Celestia node API")

API endpoints are implemented in library

// Head - returns the tip (head) of the node's current chain.
func (api API) Head(ctx context.Context) (response HeaderResponse, err error)

// Header - returns the header of the given `height`.
func (api API) Header(ctx context.Context, height uint64) (response HeaderResponse, err error) 

// NamespaceData - returns original messages of the given namespace ID `namespaceID` from the given block `height`.
func (api API) NamespaceData(ctx context.Context, namespaceID string, height uint64) (response NamespaceData, err error)

// NamespaceShares - returns shares of the given namespace ID `namespaceID` from the latest block (chain head).
func (api API) NamespaceShares(ctx context.Context, namespaceID string) (response NamespaceData, err error)

// NamespaceSharesByHeight - returns shares of the given namespace ID `namespaceID` from the block of the given `height`.
func (api API) NamespaceSharesByHeight(ctx context.Context, namespaceID string, height uint64) (response NamespaceShares, err error)

// DataAvailable - returns whether data is available at a specific block `height` and the probability that it is available based on the amount of samples collected.
func (api API) DataAvailable(ctx context.Context, height uint64) (response DataAvailableResponse, err error)

// Balance - returns the balance of the default account address of the node.
func (api API) Balance(ctx context.Context) (response Balance, err error)

// BalanceOf - returns the balance of the default account address of the node.
func (api API) BalanceOf(ctx context.Context, address string) (response Balance, err error)

// SubmitTx - submits the given transaction to a running instance of celestia-app.
func (api API) SubmitTx(ctx context.Context, tx SubmitTx) (response SubmittedTx, err error)

// SubmitPfd - Constructs, signs and submits a PayForData message to a running instance of celestia-app. The body of the /submit_pfd request should contain the hex-encoded namespace_id, the hex-encoded data, and the gas_limit as a uint64.
func (api API) SubmitPfd(ctx context.Context, tx SubmitPfd) (response SubmittedPfd, err error)

Example

package main

import (
	"context"
	"log"
	"time"
)

func main() {
	api := NewAPI("base URL to Celestia node API")

	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
	defer cancel()
	head, err := api.Head(ctx)
	if err != nil {
		log.Panic(err)
	}

	log.Printf("%##v", head)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NamespaceID

func NamespaceID(base64Value string) (string, error)

NamespaceID -

Types

type API

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

API - wrapper of celestia node API.

func NewAPI

func NewAPI(baseURL string) API

NewAPI - constructor of API

func (API) Balance

func (api API) Balance(ctx context.Context) (response Balance, err error)

Balance - returns the balance of the default account address of the node.

func (API) BalanceOf

func (api API) BalanceOf(ctx context.Context, address string) (response Balance, err error)

BalanceOf - returns the balance of the default account address of the node.

func (API) DataAvailable

func (api API) DataAvailable(ctx context.Context, height uint64) (response DataAvailableResponse, err error)

DataAvailable - returns whether data is available at a specific block `height` and the probability that it is available based on the amount of samples collected.

func (API) Head

func (api API) Head(ctx context.Context) (response HeaderResponse, err error)

Head - returns the tip (head) of the node's current chain.

func (API) Header

func (api API) Header(ctx context.Context, height uint64) (response HeaderResponse, err error)

Header - returns the header of the given `height`.

func (API) NamespaceData

func (api API) NamespaceData(ctx context.Context, namespaceID string, height uint64) (response NamespaceData, err error)

NamespaceData - returns original messages of the given namespace ID `namespaceID` from the given block `height`.

func (API) NamespaceShares

func (api API) NamespaceShares(ctx context.Context, namespaceID string) (response NamespaceData, err error)

NamespaceShares - returns shares of the given namespace ID `namespaceID` from the latest block (chain head).

func (API) NamespaceSharesByHeight

func (api API) NamespaceSharesByHeight(ctx context.Context, namespaceID string, height uint64) (response NamespaceShares, err error)

NamespaceSharesByHeight - returns shares of the given namespace ID `namespaceID` from the block of the given `height`.

func (API) SubmitPfd

func (api API) SubmitPfd(ctx context.Context, tx SubmitPfd) (response SubmittedPfd, err error)

SubmitPfd - Constructs, signs and submits a PayForData message to a running instance of celestia-app. The body of the /submit_pfd request should contain the hex-encoded namespace_id, the hex-encoded data, and the gas_limit as a uint64.

func (API) SubmitTx

func (api API) SubmitTx(ctx context.Context, tx SubmitTx) (response SubmittedTx, err error)

SubmitTx - submits the given transaction to a running instance of celestia-app.

type Attribute

type Attribute struct {
	Key   string `json:"key"`
	Value string `json:"value"`
	Index *bool  `json:"index"`
}

Attribute -

func (Attribute) IsIndex

func (attr Attribute) IsIndex() bool

IsIndex -

type Balance

type Balance struct {
	Denom  string          `json:"denom"`
	Amount decimal.Decimal `json:"amount"`
}

Balance -

type BlockID

type BlockID struct {
	Hash  string       `json:"hash"`
	Parts BlockIDParts `json:"parts"`
}

BlockID -

type BlockIDParts

type BlockIDParts struct {
	Total int    `json:"total"`
	Hash  string `json:"hash"`
}

BlockIDParts -

type Commit

type Commit struct {
	Height     uint64      `json:"height"`
	Round      int         `json:"round"`
	BlockID    BlockID     `json:"block_id"`
	Signatures []Signature `json:"signatures"`
}

Commit -

type Dah

type Dah struct {
	RowRoots    []string `json:"row_roots"`
	ColumnRoots []string `json:"column_roots"`
}

Dah -

type DataAvailableResponse

type DataAvailableResponse struct {
	Available                 bool   `json:"available"`
	ProbabilityOfAvailability string `json:"probability_of_availability"`
}

DataAvailableResponse -

type Event

type Event struct {
	Type       string      `json:"type"`
	Attributes []Attribute `json:"attributes"`
}

Event -

type Header struct {
	Version            Version   `json:"version"`
	ChainID            string    `json:"chain_id"`
	Height             uint64    `json:"height"`
	Time               time.Time `json:"time"`
	LastBlockID        BlockID   `json:"last_block_id"`
	LastCommitHash     string    `json:"last_commit_hash"`
	DataHash           string    `json:"data_hash"`
	ValidatorsHash     string    `json:"validators_hash"`
	NextValidatorsHash string    `json:"next_validators_hash"`
	ConsensusHash      string    `json:"consensus_hash"`
	AppHash            string    `json:"app_hash"`
	LastResultsHash    string    `json:"last_results_hash"`
	EvidenceHash       string    `json:"evidence_hash"`
	ProposerAddress    string    `json:"proposer_address"`
}

Header -

type HeaderResponse

type HeaderResponse struct {
	Header       Header       `json:"header"`
	Commit       Commit       `json:"commit"`
	ValidatorSet ValidatorSet `json:"validator_set"`
	Dah          Dah          `json:"dah"`
}

HeaderResponse -

type Log

type Log struct {
	MsgIndex int64   `json:"msg_index"`
	Events   []Event `json:"events"`
}

Log -

type NamespaceData

type NamespaceData struct {
	Data   []string `json:"data,omitempty"`
	Height uint64   `json:"height"`
}

NamespaceData -

func (NamespaceData) GetBytes

func (nd NamespaceData) GetBytes() ([][]byte, error)

GetBytes - returns array of bytes array from `Data` field of `NamespaceData` response

type NamespaceShares

type NamespaceShares struct {
	Shares []string `json:"shares,omitempty"`
	Height uint64   `json:"height"`
}

NamespaceShares -

type Signature

type Signature struct {
	BlockIDFlag      uint64    `json:"block_id_flag"`
	ValidatorAddress string    `json:"validator_address"`
	Timestamp        time.Time `json:"timestamp"`
	Signature        string    `json:"signature"`
}

Signature -

type SubmitPfd

type SubmitPfd struct {
	NamespaceID string `json:"namespace_id"`
	Data        string `json:"data"`
	GasLimit    uint64 `json:"gas_limit"`
}

SubmitPfd -

type SubmitTx

type SubmitTx struct {
	Tx string `json:"tx"`
}

SubmitTx -

type SubmittedPfd

type SubmittedPfd struct {
	Height int     `json:"height"`
	Txhash string  `json:"txhash"`
	Data   string  `json:"data"`
	RawLog string  `json:"raw_log"`
	Logs   []Log   `json:"logs"`
	Events []Event `json:"events"`
}

SubmittedPfd -

type SubmittedTx

type SubmittedTx struct {
	Txhash    string `json:"txhash"`
	Codespace string `json:"codespace"`
	Code      int64  `json:"code"`
	RawLog    string `json:"raw_log"`
	Logs      []Log  `json:"logs,omitempty"`
	GasWanted uint64 `json:"gas_wanted"`
}

SubmittedTx -

type Validator

type Validator struct {
	Address          string `json:"address"`
	PubKey           string `json:"pub_key"`
	VotingPower      int    `json:"voting_power"`
	ProposerPriority int    `json:"proposer_priority"`
}

Validator -

type ValidatorSet

type ValidatorSet struct {
	Validators []Validator `json:"validators"`
	Proposer   Validator   `json:"proposer"`
}

ValidatorSet -

type Version

type Version struct {
	Block int `json:"block"`
}

Version -

Jump to

Keyboard shortcuts

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