cnc

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: Apache-2.0 Imports: 9 Imported by: 16

README

go-cnc

celestia-node REST client in Go.

Contributing

We welcome your contributions! Everyone is welcome to contribute, whether it's in the form of code, documentation, bug reports, feature requests, or anything else.

If you're looking for issues to work on, try looking at the good first issue list. Issues with this tag are suitable for a new external contributor and is a great way to find something you can help with!

See the contributing guide for more details.

Please join our Community Discord to ask questions, discuss your ideas, and connect with other contributors.

Code of Conduct

See our Code of Conduct here.

Documentation

Overview

Package cnrc implements a Celestia Node REST Client

Index

Constants

View Source
const (
	// NamespaveVersionSize is the size of a namespace version in bytes.
	NamespaceVersionSize = 1

	// NamespaceIDSize is the size of a namespace ID in bytes.
	NamespaceIDSize = 28

	// NamespaceSize is the size of a namespace (version + ID) in bytes.
	NamespaceSize = NamespaceVersionSize + NamespaceIDSize

	// NamespaceVersionZero is the first namespace version.
	NamespaceVersionZero = uint8(0)

	// NamespaceVersionMax is the max namespace version.
	NamespaceVersionMax = math.MaxUint8

	// NamespaceZeroPrefixSize is the number of `0` bytes that are prefixed to
	// namespace IDs for version 0.
	NamespaceVersionZeroPrefixSize = 18

	// NamespaceVersionZeroIDSize is the number of bytes available for
	// user-specified namespace ID in a namespace ID for version 0.
	NamespaceVersionZeroIDSize = NamespaceIDSize - NamespaceVersionZeroPrefixSize
)

Variables

View Source
var (
	// NamespaceVersionZeroPrefix is the prefix of a namespace ID for version 0.
	NamespaceVersionZeroPrefix = bytes.Repeat([]byte{0}, NamespaceVersionZeroPrefixSize)

	// TxNamespace is the namespace reserved for transaction data.
	TxNamespace = MustNewV0([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 1})

	// IntermediateStateRootsNamespace is the namespace reserved for
	// intermediate state root data.
	IntermediateStateRootsNamespace = MustNewV0([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 2})

	// PayForBlobNamespace is the namespace reserved for PayForBlobs transactions.
	PayForBlobNamespace = MustNewV0([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 4})

	// ReservedPaddingNamespace is the namespace used for padding after all
	// reserved namespaces. In practice this padding is after transactions
	// (ordinary and PFBs) but before blobs.
	ReservedPaddingNamespace = MustNewV0([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 255})

	// MaxReservedNamespace is lexicographically the largest namespace that is
	// reserved for protocol use.
	MaxReservedNamespace = MustNewV0([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 255})

	// TailPaddingNamespace is the namespace reserved for tail padding. All data
	// with this namespace will be ignored.
	TailPaddingNamespace = Namespace{
		Version: math.MaxUint8,
		ID:      append(bytes.Repeat([]byte{0xFF}, NamespaceIDSize-1), 0xFE),
	}

	// ParitySharesNamespace is the namespace reserved for erasure coded data.
	ParitySharesNamespace = Namespace{
		Version: math.MaxUint8,
		ID:      bytes.Repeat([]byte{0xFF}, NamespaceIDSize),
	}
)

Functions

This section is empty.

Types

type ABCIMessageLog

type ABCIMessageLog struct {
	MsgIndex uint32 `protobuf:"varint,1,opt,name=msg_index,json=msgIndex,proto3" json:"msg_index,omitempty"`
	Log      string `protobuf:"bytes,2,opt,name=log,proto3" json:"log,omitempty"`
	// Events contains a slice of Event objects that were emitted during some
	// execution.
	Events StringEvents `protobuf:"bytes,3,rep,name=events,proto3,castrepeated=StringEvents" json:"events"`
}

ABCIMessageLog defines a structure containing an indexed tx ABCI message log.

type ABCIMessageLogs

type ABCIMessageLogs []ABCIMessageLog

ABCIMessageLogs represents a slice of ABCIMessageLog.

type Attribute

type Attribute struct {
	Key   string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
}

Attribute defines an attribute wrapper where the key and value are strings instead of raw bytes.

type Client

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

func NewClient

func NewClient(baseURL string, options ...Option) (*Client, error)

func (*Client) Balance

func (c *Client) Balance(ctx context.Context) error

func (*Client) Header

func (c *Client) Header(ctx context.Context, height uint64) error

func (*Client) NamespacedData

func (c *Client) NamespacedData(ctx context.Context, namespace Namespace, height uint64) ([][]byte, error)

func (*Client) NamespacedShares

func (c *Client) NamespacedShares(ctx context.Context, namespace Namespace, height uint64) ([][]byte, error)

func (*Client) SubmitPFB added in v0.3.0

func (c *Client) SubmitPFB(ctx context.Context, namespace Namespace, data []byte, fee int64, gasLimit uint64) (*TxResponse, error)

func (*Client) SubmitTx

func (c *Client) SubmitTx(ctx context.Context, tx []byte) error

type Namespace added in v0.4.1

type Namespace struct {
	Version uint8
	ID      []byte
}

func From added in v0.4.1

func From(b []byte) (Namespace, error)

From returns a namespace from the provided byte slice.

func MustNew added in v0.4.1

func MustNew(version uint8, id []byte) Namespace

MustNew returns a new namespace with the provided version and id. It panics if the provided version or id are not supported.

func MustNewV0 added in v0.4.1

func MustNewV0(id []byte) Namespace

MustNewV0 returns a new namespace with version 0 and the provided id. This function panics if the provided id is not exactly NamespaceVersionZeroIDSize bytes.

func New added in v0.4.1

func New(version uint8, id []byte) (Namespace, error)

New returns a new namespace with the provided version and id.

func (Namespace) Bytes added in v0.4.1

func (n Namespace) Bytes() []byte

Bytes returns this namespace as a byte slice.

func (Namespace) Equals added in v0.4.1

func (n Namespace) Equals(n2 Namespace) bool

func (Namespace) IsGreaterOrEqualThan added in v0.4.1

func (n Namespace) IsGreaterOrEqualThan(n2 Namespace) bool

func (Namespace) IsGreaterThan added in v0.4.1

func (n Namespace) IsGreaterThan(n2 Namespace) bool

func (Namespace) IsLessOrEqualThan added in v0.4.1

func (n Namespace) IsLessOrEqualThan(n2 Namespace) bool

func (Namespace) IsLessThan added in v0.4.1

func (n Namespace) IsLessThan(n2 Namespace) bool

func (Namespace) IsParityShares added in v0.4.1

func (n Namespace) IsParityShares() bool

func (Namespace) IsPayForBlob added in v0.4.1

func (n Namespace) IsPayForBlob() bool

func (Namespace) IsReserved added in v0.4.1

func (n Namespace) IsReserved() bool

func (Namespace) IsReservedPadding added in v0.4.1

func (n Namespace) IsReservedPadding() bool

func (Namespace) IsTailPadding added in v0.4.1

func (n Namespace) IsTailPadding() bool

func (Namespace) IsTx added in v0.4.1

func (n Namespace) IsTx() bool

func (Namespace) Repeat added in v0.4.1

func (n Namespace) Repeat(times int) []Namespace

func (Namespace) ValidateBlobNamespace added in v0.4.1

func (n Namespace) ValidateBlobNamespace() error

ValidateBlobNamespace returns an error if this namespace is not a valid blob namespace.

type Option

type Option func(*Client) error

func WithTimeout

func WithTimeout(timeout time.Duration) Option

type StringEvent

type StringEvent struct {
	Type       string      `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
	Attributes []Attribute `protobuf:"bytes,2,rep,name=attributes,proto3" json:"attributes"`
}

StringEvent defines en Event object wrapper where all the attributes contain key/value pairs that are strings instead of raw bytes.

type StringEvents

type StringEvents []StringEvent

StringAttributes defines a slice of StringEvents objects.

type SubmitPFBRequest added in v0.3.0

type SubmitPFBRequest struct {
	NamespaceID string `json:"namespace_id"`
	Data        string `json:"data"`
	Fee         int64  `json:"fee"`
	GasLimit    uint64 `json:"gas_limit"`
}

SubmitPFBRequest represents a request to submit a PayForBlob transaction.

type TxResponse

type TxResponse struct {
	// The block height
	Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"`
	// The transaction hash.
	TxHash string `protobuf:"bytes,2,opt,name=txhash,proto3" json:"txhash,omitempty"`
	// Namespace for the Code
	Codespace string `protobuf:"bytes,3,opt,name=codespace,proto3" json:"codespace,omitempty"`
	// Response code.
	Code uint32 `protobuf:"varint,4,opt,name=code,proto3" json:"code,omitempty"`
	// Result bytes, if any.
	Data string `protobuf:"bytes,5,opt,name=data,proto3" json:"data,omitempty"`
	// The output of the application's logger (raw string). May be
	// non-deterministic.
	RawLog string `protobuf:"bytes,6,opt,name=raw_log,json=rawLog,proto3" json:"raw_log,omitempty"`
	// The output of the application's logger (typed). May be non-deterministic.
	Logs ABCIMessageLogs `protobuf:"bytes,7,rep,name=logs,proto3,castrepeated=ABCIMessageLogs" json:"logs"`
	// Additional information. May be non-deterministic.
	Info string `protobuf:"bytes,8,opt,name=info,proto3" json:"info,omitempty"`
	// Amount of gas requested for transaction.
	GasWanted int64 `protobuf:"varint,9,opt,name=gas_wanted,json=gasWanted,proto3" json:"gas_wanted,omitempty"`
	// Amount of gas consumed by transaction.
	GasUsed int64 `protobuf:"varint,10,opt,name=gas_used,json=gasUsed,proto3" json:"gas_used,omitempty"`
	// The request transaction bytes.
	Tx *types.Any `protobuf:"bytes,11,opt,name=tx,proto3" json:"tx,omitempty"`
	// Time of the previous block. For heights > 1, it's the weighted median of
	// the timestamps of the valid votes in the block.LastCommit. For height == 1,
	// it's genesis time.
	Timestamp string `protobuf:"bytes,12,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
}

TxResponse defines a structure containing relevant tx data and metadata. The tags are stringified and the log is JSON decoded.

Jump to

Keyboard shortcuts

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