nodeclient

package
v3.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 16 Imported by: 19

Documentation

Index

Constants

View Source
const (
	// EventAPIMilestoneInfoLatest is the name of the latest milestone info event channel.
	EventAPIMilestoneInfoLatest = "milestone-info/latest"
	// EventAPIMilestoneInfoConfirmed is the name of the confirmed milestone info event channel.
	EventAPIMilestoneInfoConfirmed = "milestone-info/confirmed"
	// EventAPIMilestones is the name of the milestone event channel.
	EventAPIMilestones = "milestones"

	// EventAPIBlocks is the name of the received blocks event channel.
	EventAPIBlocks = "blocks"
	// EventAPIBlocksTransaction is the name of the blocks containing transactions event channel.
	EventAPIBlocksTransaction = "blocks/transaction"
	// EventAPIBlocksTransactionTaggedData is the name of the blocks containing transaction with tagged data event channel.
	EventAPIBlocksTransactionTaggedData = "blocks/transaction/tagged-data"
	// EventAPIBlocksTransactionTaggedDataTag is the name of the blocks containing transaction with a specific tagged data event channel.
	EventAPIBlocksTransactionTaggedDataTag = "blocks/transaction/tagged-data/{tag}"
	// EventAPIBlocksTaggedData is the name of the blocks containing tagged data event channel.
	EventAPIBlocksTaggedData = "blocks/tagged-data"
	// EventAPIBlocksTaggedDataTag is the name of the blocks containing a specific tagged data event channel.
	EventAPIBlocksTaggedDataTag = "blocks/tagged-data/{tag}"

	// EventAPITransactionsIncludedBlock is the name of the included transaction block event channel.
	EventAPITransactionsIncludedBlock = "transactions/{transactionId}/included-block"

	// EventAPIBlockMetadata is the name of the block metadata event channel.
	EventAPIBlockMetadata = "block-metadata/{blockId}"
	// EventAPIBlockMetadataReferenced is the name of the referenced blocks metadata event channel.
	EventAPIBlockMetadataReferenced = "block-metadata/referenced"

	// EventAPIOutputs is the name of the outputs event channel.
	EventAPIOutputs = "outputs/{outputId}"
	// EventAPINFTOutputs is the name of the NFT output event channel to retrieve NFT mutations by their ID.
	EventAPINFTOutputs = "outputs/nft/{nftId}"
	// EventAPIAliasOutputs is the name of the Alias output event channel to retrieve Alias mutations by their ID.
	EventAPIAliasOutputs = "outputs/alias/{aliasId}"
	// EventAPIFoundryOutputs is the name of the Foundry output event channel to retrieve Foundry mutations by their ID.
	EventAPIFoundryOutputs = "outputs/foundry/{foundryId}"
	// EventAPIOutputsByUnlockConditionAndAddress is the name of the outputs by unlock condition address event channel.
	EventAPIOutputsByUnlockConditionAndAddress = "outputs/unlock/{condition}/{address}"
	// EventAPISpentOutputsByUnlockConditionAndAddress is the name of the spent outputs by unlock condition address event channel.
	EventAPISpentOutputsByUnlockConditionAndAddress = "outputs/unlock/{condition}/{address}/spent"

	// EventAPIReceipts is the name of the receipts event channel.
	EventAPIReceipts = "receipts"
)
View Source
const (
	MIMEApplicationJSON                   = "application/json"
	MIMEApplicationVendorIOTASerializerV1 = "application/vnd.iota.serializer-v1"
)
View Source
const (
	// IndexerPluginName is the name for the indexer plugin.
	IndexerPluginName = "indexer/v1"

	// MQTTPluginName is the name for the MQTT plugin.
	MQTTPluginName = "mqtt/v1"
)
View Source
const (
	// RouteHealth is the route for querying a node's health status.
	RouteHealth = "/health"

	// RouteRoutes is the route for getting the routes the node supports.
	// GET returns the nodes routes.
	RouteRoutes = "/api/routes"

	// RouteInfo is the route for getting the node info.
	// GET returns the node info.
	RouteInfo = "/api/core/v2/info"

	// RouteTips is the route for getting tips.
	// GET returns the tips.
	RouteTips = "/api/core/v2/tips"

	// RouteBlock is the route for getting a block by its ID.
	// GET returns the block based on the given type in the request "Accept" header.
	// MIMEApplicationJSON => json
	// MIMEVendorIOTASerializer => bytes.
	RouteBlock = "/api/core/v2/blocks/%s"

	// RouteBlockMetadata is the route for getting block metadata by its ID.
	// GET returns block metadata (including info about "promotion/reattachment needed").
	RouteBlockMetadata = "/api/core/v2/blocks/%s/metadata"

	// RouteBlockChildren is the route for getting block IDs of the children of a block, identified by its block ID.
	// GET returns the block IDs of all children.
	RouteBlockChildren = "/api/core/v2/blocks/%s/children"

	// RouteBlocks is the route for creating new blocks.
	// POST creates a single new block and returns the ID.
	// The block is parsed based on the given type in the request "Content-Type" header.
	// MIMEApplicationJSON => json
	// MIMEVendorIOTASerializer => bytes.
	RouteBlocks = "/api/core/v2/blocks"

	// RouteTransactionsIncludedBlock is the route for getting the block that was included in the ledger for a given transaction ID.
	// GET returns the block based on the given type in the request "Accept" header.
	// MIMEApplicationJSON => json
	// MIMEVendorIOTASerializer => bytes.
	RouteTransactionsIncludedBlock = "/api/core/v2/transactions/%s/included-block"

	// RouteMilestoneByID is the route for getting a milestone by its ID.
	// GET returns the milestone.
	RouteMilestoneByID = "/api/core/v2/milestones/%s"

	// RouteMilestoneByIDUTXOChanges is the route for getting all UTXO changes of a milestone by its ID.
	// GET returns the output IDs of all UTXO changes.
	RouteMilestoneByIDUTXOChanges = "/api/core/v2/milestones/%s/utxo-changes"

	// RouteMilestoneByIndex is the route for getting a milestone by its milestoneIndex.
	// GET returns the milestone.
	RouteMilestoneByIndex = "/api/core/v2/milestones/by-index/%d"

	// RouteMilestoneByIndexUTXOChanges is the route for getting all UTXO changes of a milestone by its milestoneIndex.
	// GET returns the output IDs of all UTXO changes.
	RouteMilestoneByIndexUTXOChanges = "/api/core/v2/milestones/%d/utxo-changes"

	// RouteOutput is the route for getting an output by its outputID (transactionHash + outputIndex).
	// GET returns the output based on the given type in the request "Accept" header.
	// MIMEApplicationJSON => json
	// MIMEVendorIOTASerializer => bytes.
	RouteOutput = "/api/core/v2/outputs/%s"

	// RouteOutputMetadata is the route for getting output metadata by its outputID (transactionHash + outputIndex) without getting the data again.
	// GET returns the output metadata.
	RouteOutputMetadata = "/api/core/v2/outputs/%s/metadata"

	// RouteTreasury is the route for getting the current treasury output.
	// GET returns the treasury.
	RouteTreasury = "/api/core/v2/treasury"

	// RouteReceipts is the route for getting all persisted receipts on a node.
	// GET returns the receipts.
	RouteReceipts = "/api/core/v2/receipts"

	// RouteReceiptsMigratedAtIndex is the route for getting all persisted receipts for a given migrated at index on a node.
	// GET returns the receipts for the given migrated at index.
	RouteReceiptsMigratedAtIndex = "/api/core/v2/receipts/%d"

	// RouteComputeWhiteFlagMutations is the route to compute the white flag mutations for the cone of the given parents.
	// POST computes the white flag mutations.
	RouteComputeWhiteFlagMutations = "/api/core/v2/whiteflag"

	// RoutePeer is the route for getting peers by their peerID.
	// GET returns the peer
	// DELETE deletes the peer.
	RoutePeer = "/api/core/v2/peers/%s"

	// RoutePeers is the route for getting all peers of the node.
	// GET returns a list of all peers.
	// POST adds a new peer.
	RoutePeers = "/api/core/v2/peers"
)

Variables

View Source
var (
	// ErrHTTPBadRequest gets returned for 400 bad request HTTP responses.
	ErrHTTPBadRequest = errors.New("bad request")
	// ErrHTTPInternalServerError gets returned for 500 internal server error HTTP responses.
	ErrHTTPInternalServerError = errors.New("internal server error")
	// ErrHTTPNotFound gets returned for 404 not found error HTTP responses.
	ErrHTTPNotFound = errors.New("not found")
	// ErrHTTPUnauthorized gets returned for 401 unauthorized error HTTP responses.
	ErrHTTPUnauthorized = errors.New("unauthorized")
	// ErrHTTPUnknownError gets returned for unknown error HTTP responses.
	ErrHTTPUnknownError = errors.New("unknown error")
	// ErrHTTPNotImplemented gets returned for 501 not implemented error HTTP responses.
	ErrHTTPNotImplemented = errors.New("operation not implemented/supported/available")
	// ErrHTTPServiceUnavailable gets returned for 503 service unavailable error HTTP responses.
	ErrHTTPServiceUnavailable = errors.New("service unavailable")
)
View Source
var (
	// ErrIndexerPluginNotAvailable is returned when the indexer plugin is not available on the node.
	ErrIndexerPluginNotAvailable = errors.New("indexer plugin not available on the current node")
	// ErrMQTTPluginNotAvailable is returned when the MQTT plugin is not available on the node.
	ErrMQTTPluginNotAvailable = errors.New("mqtt plugin not available on the current node")
)
View Source
var (
	// RequestHeaderHookAcceptJSON is used to set the request "Accept" header to MIMEApplicationJSON.
	RequestHeaderHookAcceptJSON = func(header http.Header) { header.Set("Accept", MIMEApplicationJSON) }
	// RequestHeaderHookAcceptIOTASerializerV1 is used to set the request "Accept" header to MIMEApplicationVendorIOTASerializerV1.
	RequestHeaderHookAcceptIOTASerializerV1 = func(header http.Header) { header.Set("Accept", MIMEApplicationVendorIOTASerializerV1) }
)
View Source
var (
	IndexerAPIRouteBasicOutputs = "/api/" + IndexerPluginName + "/outputs/basic"
	IndexerAPIRouteAliases      = "/api/" + IndexerPluginName + "/outputs/alias"
	IndexerAPIRouteAlias        = "/api/" + IndexerPluginName + "/outputs/alias/%s"
	IndexerAPIRouteFoundries    = "/api/" + IndexerPluginName + "/outputs/foundry"
	IndexerAPIRouteFoundry      = "/api/" + IndexerPluginName + "/outputs/foundry/%s"
	IndexerAPIRouteNFTs         = "/api/" + IndexerPluginName + "/outputs/nft"
	IndexerAPIRouteNFT          = "/api/" + IndexerPluginName + "/outputs/nft/%s"
)

Indexer plugin routes.

View Source
var (
	// ErrEventAPIClientInactive gets returned when an EventAPIClient is inactive.
	ErrEventAPIClientInactive = errors.New("event api client is inactive")
)
View Source
var (
	// ErrIndexerNotFound gets returned when the indexer doesn't find any result.
	// Only applicable to single element queries.
	ErrIndexerNotFound = errors.New("no result found")
)

Functions

This section is empty.

Types

type AddPeerRequest

type AddPeerRequest struct {
	// The libp2p multi address of the peer.
	MultiAddress string `json:"multiAddress"`
	// The alias of to iditify the peer.
	Alias *string `json:"alias,omitempty"`
}

AddPeerRequest defines the request for a POST peer REST API call.

type AliasesQuery

type AliasesQuery struct {
	IndexerCursorParas
	IndexerCreationParas
	IndexerNativeTokenParas

	// Bech32-encoded state controller address that should be searched for.
	StateControllerBech32 string `qs:"stateController,omitempty"`
	// Bech32-encoded governor address that should be searched for.
	GovernorBech32 string `qs:"governor,omitempty"`
	// Filters outputs based on the presence of validated sender.
	SenderBech32 string `qs:"sender,omitempty"`
	// Filters outputs based on the presence of validated issuer.
	IssuerBech32 string `qs:"issuer,omitempty"`
}

AliasesQuery defines parameters for an alias outputs query.

func (*AliasesQuery) OutputType

func (query *AliasesQuery) OutputType() iotago.OutputType

func (*AliasesQuery) SetOffset

func (query *AliasesQuery) SetOffset(cursor *string)

func (*AliasesQuery) URLParas

func (query *AliasesQuery) URLParas() (string, error)

type BasicOutputsQuery

type BasicOutputsQuery struct {
	IndexerCursorParas
	IndexerTimelockParas
	IndexerExpirationParas
	IndexerCreationParas
	IndexerStorageDepositParas
	IndexerNativeTokenParas

	// Bech32-encoded address that should be searched for.
	AddressBech32 string `qs:"address,omitempty"`
	// Filters outputs based on the presence of validated sender.
	SenderBech32 string `qs:"sender,omitempty"`
	// Filters outputs based on matching tag feature.
	Tag string `qs:"tag,omitempty"`
}

BasicOutputsQuery defines parameters for an basic outputs query.

func (*BasicOutputsQuery) OutputType

func (query *BasicOutputsQuery) OutputType() iotago.OutputType

func (*BasicOutputsQuery) SetOffset

func (query *BasicOutputsQuery) SetOffset(cursor *string)

func (*BasicOutputsQuery) URLParas

func (query *BasicOutputsQuery) URLParas() (string, error)

type BlockMetadataResponse

type BlockMetadataResponse struct {
	// The hex encoded ID of the block.
	BlockID string `json:"blockId"`
	// The hex encoded IDs of the parent block references.
	Parents []string `json:"parents"`
	// Whether the block is solid.
	Solid bool `json:"isSolid"`
	// The milestone index that references this block.
	ReferencedByMilestoneIndex iotago.MilestoneIndex `json:"referencedByMilestoneIndex,omitempty"`
	// If this block represents a milestone this is the milestone index
	MilestoneIndex iotago.MilestoneIndex `json:"milestoneIndex,omitempty"`
	// The ledger inclusion state of the transaction payload.
	LedgerInclusionState string `json:"ledgerInclusionState,omitempty"`
	// Whether the block should be promoted.
	ShouldPromote *bool `json:"shouldPromote,omitempty"`
	// Whether the block should be reattached.
	ShouldReattach *bool `json:"shouldReattach,omitempty"`
	// The reason why this block is marked as conflicting.
	ConflictReason uint8 `json:"conflictReason,omitempty"`
	// If this block is referenced by a milestone this returns the index of that block inside the milestone by whiteflag ordering.
	WhiteFlagIndex *uint32 `json:"whiteFlagIndex,omitempty"`
}

BlockMetadataResponse defines the response of a GET block metadata REST API call.

type ChildrenResponse

type ChildrenResponse struct {
	// The hex encoded block ID of the block.
	BlockID string `json:"blockId"`
	// The maximum count of results that are returned by the node.
	MaxResults uint32 `json:"maxResults"`
	// The actual count of results that are returned.
	Count uint32 `json:"count"`
	// The hex encoded IDs of the children of this block.
	Children []string `json:"children"`
}

ChildrenResponse defines the response of a GET children REST API call.

type Client

type Client struct {
	// The base URL for all API calls.
	BaseURL string
	// contains filtered or unexported fields
}

Client is a client for node HTTP REST API endpoints.

func New

func New(baseURL string, opts ...ClientOption) *Client

New returns a new Client using the given base URL.

func (*Client) AddPeer

func (client *Client) AddPeer(ctx context.Context, multiAddress string, alias ...string) (*PeerResponse, error)

AddPeer adds a new peer by libp2p multi address with optional alias.

func (*Client) BlockByBlockID

func (client *Client) BlockByBlockID(ctx context.Context, blockID iotago.BlockID, protoParas *iotago.ProtocolParameters) (*iotago.Block, error)

BlockByBlockID get a block by its block ID from the node.

func (*Client) BlockMetadataByBlockID

func (client *Client) BlockMetadataByBlockID(ctx context.Context, blockID iotago.BlockID) (*BlockMetadataResponse, error)

BlockMetadataByBlockID gets the metadata of a block by its ID from the node.

func (*Client) ChildrenByBlockID

func (client *Client) ChildrenByBlockID(ctx context.Context, parentBlockID iotago.BlockID) (*ChildrenResponse, error)

ChildrenByBlockID gets the BlockIDs of the child blocks of a given block.

func (*Client) ComputeWhiteFlagMutations

func (client *Client) ComputeWhiteFlagMutations(ctx context.Context, index iotago.MilestoneIndex, timestamp uint32, parents iotago.BlockIDs, previousMilestoneID iotago.MilestoneID) (*ComputeWhiteFlagMutationsResponse, error)

ComputeWhiteFlagMutations is the route to compute the white flag mutations for the cone of the given parents. This function returns the merkle tree roots calculated by the node.

func (*Client) Do

func (client *Client) Do(ctx context.Context, method string, route string, reqObj interface{}, resObj interface{}) (*http.Response, error)

Do executes a request against the endpoint. This function is only meant to be used for special routes not covered through the standard API.

func (*Client) DoWithRequestHeaderHook

func (client *Client) DoWithRequestHeaderHook(ctx context.Context, method string, route string, requestHeaderHook RequestHeaderHook, reqObj interface{}, resObj interface{}) (*http.Response, error)

DoWithRequestHeaderHook executes a request against the endpoint. This function is only meant to be used for special routes not covered through the standard API.

func (*Client) EventAPI

func (client *Client) EventAPI(ctx context.Context) (*EventAPIClient, error)

EventAPI returns the EventAPIClient if supported by the node. Returns ErrMQTTPluginNotAvailable if the current node does not support the plugin.

func (*Client) HTTPClient

func (client *Client) HTTPClient() *http.Client

HTTPClient returns the underlying HTTP client.

func (*Client) Health

func (client *Client) Health(ctx context.Context) (bool, error)

Health returns whether the given node is healthy.

func (*Client) Indexer

func (client *Client) Indexer(ctx context.Context) (IndexerClient, error)

Indexer returns the IndexerClient. Returns ErrIndexerPluginNotAvailable if the current node does not support the plugin.

func (*Client) Info

func (client *Client) Info(ctx context.Context) (*InfoResponse, error)

Info gets the info of the node.

func (*Client) MilestoneByID

func (client *Client) MilestoneByID(ctx context.Context, id iotago.MilestoneID) (*iotago.Milestone, error)

MilestoneByID gets a milestone by its ID.

func (*Client) MilestoneByIndex

func (client *Client) MilestoneByIndex(ctx context.Context, index iotago.MilestoneIndex) (*iotago.Milestone, error)

MilestoneByIndex gets a milestone by its index.

func (*Client) MilestoneUTXOChangesByID

func (client *Client) MilestoneUTXOChangesByID(ctx context.Context, id iotago.MilestoneID) (*MilestoneUTXOChangesResponse, error)

MilestoneUTXOChangesByID returns all UTXO changes of a milestone by its ID.

func (*Client) MilestoneUTXOChangesByIndex

func (client *Client) MilestoneUTXOChangesByIndex(ctx context.Context, index iotago.MilestoneIndex) (*MilestoneUTXOChangesResponse, error)

MilestoneUTXOChangesByIndex returns all UTXO changes of a milestone by its milestoneIndex.

func (*Client) NodeSupportsRoute

func (client *Client) NodeSupportsRoute(ctx context.Context, route string) (bool, error)

NodeSupportsRoute gets the routes of the node and checks if the given route is enabled.

func (*Client) OutputByID

func (client *Client) OutputByID(ctx context.Context, outputID iotago.OutputID) (iotago.Output, error)

OutputByID gets an output by its ID from the node.

func (*Client) OutputMetadataByID

func (client *Client) OutputMetadataByID(ctx context.Context, outputID iotago.OutputID) (*OutputMetadataResponse, error)

OutputMetadataByID gets an output's metadata by its ID from the node without getting the output data again.

func (*Client) OutputWithMetadataByID

func (client *Client) OutputWithMetadataByID(ctx context.Context, outputID iotago.OutputID) (*OutputResponse, error)

OutputWithMetadataByID gets an output with its metadata by its ID from the node.

func (*Client) PeerByID

func (client *Client) PeerByID(ctx context.Context, id string) (*PeerResponse, error)

PeerByID gets a peer by its identifier.

func (*Client) Peers

func (client *Client) Peers(ctx context.Context) ([]*PeerResponse, error)

Peers returns a list of all peers.

func (*Client) Receipts

func (client *Client) Receipts(ctx context.Context) ([]*ReceiptTuple, error)

Receipts gets all receipts persisted on the node.

func (*Client) ReceiptsByMigratedAtIndex

func (client *Client) ReceiptsByMigratedAtIndex(ctx context.Context, index iotago.MilestoneIndex) ([]*ReceiptTuple, error)

ReceiptsByMigratedAtIndex gets all receipts for the given migrated at index persisted on the node.

func (*Client) RemovePeerByID

func (client *Client) RemovePeerByID(ctx context.Context, id string) error

RemovePeerByID removes a peer by its identifier.

func (*Client) Routes

func (client *Client) Routes(ctx context.Context) (*RoutesResponse, error)

Routes gets the routes the node supports.

func (*Client) SubmitBlock

func (client *Client) SubmitBlock(ctx context.Context, m *iotago.Block, protoParas *iotago.ProtocolParameters) (iotago.BlockID, error)

SubmitBlock submits the given Block to the node. The node will take care of filling missing information. This function returns the blockID of the finalized block. To get the finalized block you need to call "BlockByBlockID".

func (*Client) Tips

func (client *Client) Tips(ctx context.Context) (*TipsResponse, error)

Tips gets the two tips from the node.

func (*Client) TransactionIncludedBlock

func (client *Client) TransactionIncludedBlock(ctx context.Context, txID iotago.TransactionID, protoParas *iotago.ProtocolParameters) (*iotago.Block, error)

TransactionIncludedBlock get a block that included the given transaction ID in the ledger.

func (*Client) Treasury

func (client *Client) Treasury(ctx context.Context) (*TreasuryResponse, error)

Treasury gets the current treasury.

type ClientOption

type ClientOption func(opts *ClientOptions)

ClientOption is a function setting a Client option.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient sets the used HTTP Client.

func WithRequestURLHook

func WithRequestURLHook(requestURLHook RequestURLHook) ClientOption

WithRequestURLHook is used to modify the URL before sending a request.

func WithUserInfo

func WithUserInfo(userInfo *url.Userinfo) ClientOption

WithUserInfo sets the Userinfo used to add basic auth "Authorization" headers to the requests.

type ClientOptions

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

ClientOptions define options for the Client.

type ComputeWhiteFlagMutationsRequest

type ComputeWhiteFlagMutationsRequest struct {
	// The index of the milestone.
	Index iotago.MilestoneIndex `json:"index"`
	// The timestamp of the milestone.
	Timestamp uint32 `json:"timestamp"`
	// The hex encoded IDs of the parent blocks the milestone references.
	Parents []string `json:"parents"`
	// The hex encoded milestone ID of the previous milestone.
	PreviousMilestoneID string `json:"previousMilestoneId"`
}

ComputeWhiteFlagMutationsRequest defines the request for a POST ComputeWhiteFlagMutations REST API call.

type ComputeWhiteFlagMutationsResponse

type ComputeWhiteFlagMutationsResponse struct {
	// The inclusion merkle tree root as a result of the white flag computation.
	InclusionMerkleRoot iotago.MilestoneMerkleProof
	// The applied merkle tree root as a result of the white flag computation.
	AppliedMerkleRoot iotago.MilestoneMerkleProof
}

ComputeWhiteFlagMutationsResponse defines the response for a POST ComputeWhiteFlagMutations REST API call.

type ComputeWhiteFlagMutationsResponseInternal

type ComputeWhiteFlagMutationsResponseInternal struct {
	// The hex encoded inclusion merkle tree root as a result of the white flag computation.
	InclusionMerkleRoot string `json:"inclusionMerkleRoot"`
	// The hex encoded applied merkle tree root as a result of the white flag computation.
	AppliedMerkleRoot string `json:"appliedMerkleRoot"`
}

ComputeWhiteFlagMutationsResponseInternal defines the internal response for a POST ComputeWhiteFlagMutations REST API call.

type EventAPIClient

type EventAPIClient struct {
	Client *Client

	MQTTClient mqtt.Client
	// The context over the EventChannelsHandle.
	Ctx context.Context
	// A channel up on which errors are returned from within subscriptions or when the connection is lost.
	// Errors are dropped silently if no receiver is listening for them or can consume them fast enough.
	Errors chan error
}

EventAPIClient represents a handle to retrieve channels for node events. Any registration will panic if the EventAPIClient.Ctx is done or the client isn't connected. Multiple calls to the same channel registration will override the previously created channel.

func (*EventAPIClient) AliasOutputsByID

func (eac *EventAPIClient) AliasOutputsByID(aliasID iotago.AliasID) (<-chan *OutputResponse, *EventAPIClientSubscription)

AliasOutputsByID returns a channel of newly created outputs to track the chain mutations of a given Alias.

func (*EventAPIClient) BlockMetadataChange

func (eac *EventAPIClient) BlockMetadataChange(blockID iotago.BlockID) (<-chan *BlockMetadataResponse, *EventAPIClientSubscription)

BlockMetadataChange returns a channel of BlockMetadataResponse each time the given block's state changes.

func (*EventAPIClient) Blocks

func (eac *EventAPIClient) Blocks(protoParas *iotago.ProtocolParameters) (<-chan *iotago.Block, *EventAPIClientSubscription)

Blocks returns a channel of newly received blocks.

func (*EventAPIClient) Close

func (eac *EventAPIClient) Close()

Close disconnects the underlying MQTT client. Call this function to clean up any registered channels.

func (*EventAPIClient) ConfirmedMilestones

func (eac *EventAPIClient) ConfirmedMilestones() (<-chan *MilestoneInfo, *EventAPIClientSubscription)

ConfirmedMilestones returns a channel of infos about newly confirmed milestones.

func (*EventAPIClient) Connect

func (eac *EventAPIClient) Connect(ctx context.Context) error

Connect connects the EventAPIClient to the specified brokers. The EventAPIClient remains active as long as the given context isn't done/canceled.

func (*EventAPIClient) FoundryOutputsByID

func (eac *EventAPIClient) FoundryOutputsByID(foundryID iotago.FoundryID) (<-chan *OutputResponse, *EventAPIClientSubscription)

FoundryOutputsByID returns a channel of newly created outputs to track the chain mutations of a given Foundry.

func (*EventAPIClient) LatestMilestones

func (eac *EventAPIClient) LatestMilestones() (<-chan *MilestoneInfo, *EventAPIClientSubscription)

LatestMilestones returns a channel of infos about newly seen latest milestones.

func (*EventAPIClient) Milestones

func (eac *EventAPIClient) Milestones() (<-chan *iotago.Milestone, *EventAPIClientSubscription)

Milestones returns a channel of newly received milestones.

func (*EventAPIClient) NFTOutputsByID

func (eac *EventAPIClient) NFTOutputsByID(nftID iotago.NFTID) (<-chan *OutputResponse, *EventAPIClientSubscription)

NFTOutputsByID returns a channel of newly created outputs to track the chain mutations of a given NFT.

func (*EventAPIClient) Output

func (eac *EventAPIClient) Output(outputID iotago.OutputID) (<-chan *OutputResponse, *EventAPIClientSubscription)

Output returns a channel which immediately returns the output with the given ID and afterwards when its state changes.

func (*EventAPIClient) OutputsByUnlockConditionAndAddress

func (eac *EventAPIClient) OutputsByUnlockConditionAndAddress(addr iotago.Address, netPrefix iotago.NetworkPrefix, condition EventAPIUnlockCondition) (<-chan *OutputResponse, *EventAPIClientSubscription)

OutputsByUnlockConditionAndAddress returns a channel of newly created outputs on the given unlock condition and address.

func (*EventAPIClient) Receipts

Receipts returns a channel which returns newly applied receipts.

func (*EventAPIClient) ReferencedBlocks

func (eac *EventAPIClient) ReferencedBlocks(protoParas *iotago.ProtocolParameters) (<-chan *iotago.Block, *EventAPIClientSubscription)

ReferencedBlocks returns a channel of newly referenced blocks.

func (*EventAPIClient) ReferencedBlocksMetadata

func (eac *EventAPIClient) ReferencedBlocksMetadata() (<-chan *BlockMetadataResponse, *EventAPIClientSubscription)

ReferencedBlocksMetadata returns a channel of block metadata of newly referenced blocks.

func (*EventAPIClient) SpentOutputsByUnlockConditionAndAddress

func (eac *EventAPIClient) SpentOutputsByUnlockConditionAndAddress(addr iotago.Address, netPrefix iotago.NetworkPrefix, condition EventAPIUnlockCondition) (<-chan *OutputResponse, *EventAPIClientSubscription)

SpentOutputsByUnlockConditionAndAddress returns a channel of newly spent outputs on the given unlock condition and address.

func (*EventAPIClient) TaggedDataBlocks

func (eac *EventAPIClient) TaggedDataBlocks(protoParas *iotago.ProtocolParameters) (<-chan *iotago.Block, *EventAPIClientSubscription)

TaggedDataBlocks returns a channel of blocks containing tagged data containing the given tag.

func (*EventAPIClient) TaggedDataWithTagBlocks

func (eac *EventAPIClient) TaggedDataWithTagBlocks(tag []byte, protoParas *iotago.ProtocolParameters) (<-chan *iotago.Block, *EventAPIClientSubscription)

TaggedDataWithTagBlocks returns a channel of blocks containing tagged data.

func (*EventAPIClient) TransactionBlocks

func (eac *EventAPIClient) TransactionBlocks(protoParas *iotago.ProtocolParameters) (<-chan *iotago.Block, *EventAPIClientSubscription)

TransactionBlocks returns a channel of blocks containing transactions.

func (*EventAPIClient) TransactionIncludedBlock

func (eac *EventAPIClient) TransactionIncludedBlock(txID iotago.TransactionID, protoParas *iotago.ProtocolParameters) (<-chan *iotago.Block, *EventAPIClientSubscription)

TransactionIncludedBlock returns a channel of the included block which carries the transaction with the given ID.

func (*EventAPIClient) TransactionTaggedDataBlocks

func (eac *EventAPIClient) TransactionTaggedDataBlocks(protoParas *iotago.ProtocolParameters) (<-chan *iotago.Block, *EventAPIClientSubscription)

TransactionTaggedDataBlocks returns a channel of blocks containing transactions with tagged data.

func (*EventAPIClient) TransactionTaggedDataWithTagBlocks

func (eac *EventAPIClient) TransactionTaggedDataWithTagBlocks(tag []byte, protoParas *iotago.ProtocolParameters) (<-chan *iotago.Block, *EventAPIClientSubscription)

TransactionTaggedDataWithTagBlocks returns a channel of blocks containing transactions with tagged data containing the given tag.

type EventAPIClientSubscription

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

EventAPIClientSubscription holds any error that happened when trying to subscribe to an event. It also allows to close the subscription to cleanly unsubscribe from the node.

func (*EventAPIClientSubscription) Close

func (s *EventAPIClientSubscription) Close() error

Close allows to close the subscription to cleanly unsubscribe from the node.

func (*EventAPIClientSubscription) Error

func (s *EventAPIClientSubscription) Error() error

Error holds any error that happened when trying to subscribe.

type EventAPIUnlockCondition

type EventAPIUnlockCondition string

EventAPIUnlockCondition denotes the different unlock conditions.

const (
	UnlockConditionAny              EventAPIUnlockCondition = "+"
	UnlockConditionAddress          EventAPIUnlockCondition = "address"
	UnlockConditionStorageReturn    EventAPIUnlockCondition = "storage-return"
	UnlockConditionExpirationReturn EventAPIUnlockCondition = "expiration"
	UnlockConditionStateController  EventAPIUnlockCondition = "state-controller"
	UnlockConditionGovernor         EventAPIUnlockCondition = "governor"
	UnlockConditionImmutableAlias   EventAPIUnlockCondition = "immutable-alias"
)

Unlock conditions.

type FoundriesQuery

type FoundriesQuery struct {
	IndexerCursorParas
	IndexerCreationParas
	IndexerNativeTokenParas

	// Bech32-encoded address that should be searched for.
	AliasAddressBech32 string `qs:"aliasAddress,omitempty"`
}

FoundriesQuery defines parameters for a foundry outputs query.

func (*FoundriesQuery) OutputType

func (query *FoundriesQuery) OutputType() iotago.OutputType

func (*FoundriesQuery) SetOffset

func (query *FoundriesQuery) SetOffset(cursor *string)

func (*FoundriesQuery) URLParas

func (query *FoundriesQuery) URLParas() (string, error)

type GossipHeartbeat

type GossipHeartbeat struct {
	// The solid milestone of the node.
	SolidMilestoneIndex iotago.MilestoneIndex `json:"solidMilestoneIndex"`
	// The milestone index at which the node pruned its data.
	PrunedMilestoneIndex iotago.MilestoneIndex `json:"prunedMilestoneIndex"`
	// The latest known milestone index by the node.
	LatestMilestoneIndex iotago.MilestoneIndex `json:"latestMilestoneIndex"`
	// The amount of currently connected peers.
	ConnectedPeers int `json:"connectedPeers"`
	// The amount of currently connected peers who also
	// are synchronized with the network.
	SyncedPeers int `json:"syncedPeers"`
}

GossipHeartbeat represents a gossip heartbeat message. Peers send each other this gossip protocol message when their state is updated, such as when:

  • a new milestone was received
  • the solid milestone changed
  • the node performed pruning of data

type GossipInfo

type GossipInfo struct {
	// The last received heartbeat by the given node.
	Heartbeat *GossipHeartbeat `json:"heartbeat"`
	// The metrics about sent and received protocol messages.
	Metrics PeerGossipMetrics `json:"metrics"`
}

GossipInfo represents information about an ongoing gossip protocol.

type HTTPErrorResponseEnvelope

type HTTPErrorResponseEnvelope struct {
	Error struct {
		Code    string `json:"code"`
		Message string `json:"message"`
	} `json:"error"`
}

HTTPErrorResponseEnvelope defines the error response schema for node API responses.

type IndexerClient

type IndexerClient interface {
	// Outputs returns a handle to query for outputs.
	Outputs(ctx context.Context, query IndexerQuery) (*IndexerResultSet, error)
	// Alias queries for a specific iotago.AliasOutput by its identifier and returns the ledger index at which this output where available at.
	Alias(ctx context.Context, aliasID iotago.AliasID) (*iotago.OutputID, *iotago.AliasOutput, iotago.MilestoneIndex, error)
	// Foundry queries for a specific iotago.FoundryOutput by its identifier and returns the ledger index at which this output where available at.
	Foundry(ctx context.Context, foundryID iotago.FoundryID) (*iotago.OutputID, *iotago.FoundryOutput, iotago.MilestoneIndex, error)
	// NFT queries for a specific iotago.NFTOutput by its identifier and returns the ledger index at which this output where available at.
	NFT(ctx context.Context, nftID iotago.NFTID) (*iotago.OutputID, *iotago.NFTOutput, iotago.MilestoneIndex, error)
}

IndexerClient is a client which queries the optional indexer functionality of a node.

type IndexerCreationParas

type IndexerCreationParas struct {
	// Return outputs that were created before a certain Unix timestamp.
	CreatedBefore uint32 `qs:"createdBefore,omitempty"`
	// Return outputs that were created after a certain Unix timestamp.
	CreatedAfter uint32 `qs:"createdAfter,omitempty"`
}

IndexerCreationParas define creation time query parameters.

type IndexerCursorParas

type IndexerCursorParas struct {
	// The maximum amount of items returned in one call.
	PageSize int `qs:"pageSize,omitempty"`
	// The offset from which to query from.
	Cursor *string `qs:"cursor,omitempty"`
}

IndexerCursorParas define page size and cursor query parameters.

type IndexerExpirationParas

type IndexerExpirationParas struct {
	// Filters outputs based on the presence of expiration unlock condition.
	HasExpiration *bool `qs:"hasExpiration,omitempty"`
	// Return outputs that expire before a certain Unix timestamp.
	ExpiresBefore uint32 `qs:"expiresBefore,omitempty"`
	// Return outputs that expire after a certain Unix timestamp.
	ExpiresAfter uint32 `qs:"expiresAfter,omitempty"`
	// Filter outputs based on the presence of a specific return address in the expiration unlock condition.
	ExpirationReturnAddressBech32 string `qs:"expirationReturnAddress,omitempty"`
}

IndexerExpirationParas define expiration query parameters.

type IndexerNativeTokenParas

type IndexerNativeTokenParas struct {
	// Filters outputs based on the presence of native tokens in the output.
	HasNativeTokens *bool `qs:"hasNativeTokens,omitempty"`
	// Filter outputs that have at least an amount of native tokens.
	MinNativeTokenCount *uint32 `qs:"minNativeTokenCount,omitempty"`
	// Filter outputs that have at the most an amount of native tokens.
	MaxNativeTokenCount *uint32 `qs:"maxNativeTokenCount,omitempty"`
}

IndexerNativeTokenParas define native token based query parameters.

type IndexerQuery

type IndexerQuery interface {
	// SetOffset sets the offset for the query.
	SetOffset(offset *string)
	// URLParas returns the query parameters as URL encoded query parameters.
	URLParas() (string, error)
	// OutputType returns the output type for which the query is for.
	OutputType() iotago.OutputType
}

IndexerQuery is a query executed against the indexer.

type IndexerResponse

type IndexerResponse struct {
	// The ledger index at which these outputs where available at.
	LedgerIndex iotago.MilestoneIndex `json:"ledgerIndex"`
	// The maximum count of results that are returned by the node.
	PageSize int `json:"pageSize"`
	// The output IDs (transaction hash + output index) of the found outputs.
	Items iotago.HexOutputIDs `json:"items"`
	// The cursor to use for getting the next results.
	Cursor *string `json:"cursor"`
}

IndexerResponse is the standard successful response by the indexer.

type IndexerResultSet

type IndexerResultSet struct {

	// The error which has occurred during querying.
	Error error
	// The response from the indexer after calling Next().
	Response *IndexerResponse
	// contains filtered or unexported fields
}

IndexerResultSet is a handle for indexer queries.

func (*IndexerResultSet) Next

func (resultSet *IndexerResultSet) Next() bool

Next runs the next query against the indexer. Returns false if there are no more results to collect.

func (*IndexerResultSet) Outputs

func (resultSet *IndexerResultSet) Outputs() (iotago.Outputs, error)

Outputs collects/fetches the outputs result from the query.

type IndexerStorageDepositParas

type IndexerStorageDepositParas struct {
	// Filters outputs based on the presence of storage deposit return unlock condition.
	HasStorageDepositReturn *bool `qs:"hasStorageDepositReturn,omitempty"`
	// Filter outputs based on the presence of a specific return address in the storage deposit return unlock condition.
	StorageDepositReturnAddressBech32 string `qs:"storageDepositReturnAddress,omitempty"`
}

IndexerStorageDepositParas define storage deposit based query parameters.

type IndexerTimelockParas

type IndexerTimelockParas struct {
	// Filters outputs based on the presence of timelock unlock condition.
	HasTimelock *bool `qs:"hasTimelock,omitempty"`
	// Return outputs that are timelocked before a certain Unix timestamp.
	TimelockedBefore uint32 `qs:"timelockedBefore,omitempty"`
	// Return outputs that are timelocked after a certain Unix timestamp.
	TimelockedAfter uint32 `qs:"timelockedAfter,omitempty"`
}

IndexerTimelockParas define timelock query parameters.

type InfoResBaseToken

type InfoResBaseToken struct {
	// The base token name.
	Name string `json:"name"`
	// The base token ticker symbol.
	TickerSymbol string `json:"tickerSymbol"`
	// The base token unit.
	Unit string `json:"unit"`
	// The base token subunit.
	Subunit string `json:"subunit,omitempty"`
	// The base token amount of decimals.
	Decimals uint32 `json:"decimals"`
	// The base token uses the metric prefix.
	UseMetricPrefix bool `json:"useMetricPrefix"`
}

InfoResBaseToken defines the info res base token information.

type InfoResMetrics

type InfoResMetrics struct {
	// The current rate of new blocks per second.
	BlocksPerSecond float64 `json:"blocksPerSecond"`
	// The current rate of referenced blocks per second.
	ReferencedBlocksPerSecond float64 `json:"referencedBlocksPerSecond"`
	// The ratio of referenced blocks in relation to new blocks of the last confirmed milestone.
	ReferencedRate float64 `json:"referencedRate"`
}

InfoResMetrics defines info res metrics information.

type InfoResMilestone

type InfoResMilestone struct {
	// The index of the milestone.
	Index iotago.MilestoneIndex `json:"index"`
	// The unix time of the milestone payload.
	Timestamp uint32 `json:"timestamp,omitempty"`
	// The IO of the milestone.
	MilestoneID string `json:"milestoneId,omitempty"`
}

InfoResMilestone defines the info res milestone information.

type InfoResStatus

type InfoResStatus struct {
	// Whether the node is healthy.
	IsHealthy bool `json:"isHealthy"`
	// The latest known milestone index.
	LatestMilestone InfoResMilestone `json:"latestMilestone"`
	// The current confirmed milestone's index.
	ConfirmedMilestone InfoResMilestone `json:"confirmedMilestone"`
	// The milestone index at which the last pruning commenced.
	PruningIndex iotago.MilestoneIndex `json:"pruningIndex"`
}

InfoResStatus defines info res status information.

type InfoResponse

type InfoResponse struct {
	// The name of the node software.
	Name string `json:"name"`
	// The semver version of the node software.
	Version string `json:"version"`
	// Status information.
	Status InfoResStatus `json:"status"`
	// Protocol information.
	Protocol iotago.ProtocolParameters `json:"protocol"`
	// BaseToken information.
	BaseToken *InfoResBaseToken `json:"baseToken"`
	// Metrics information.
	Metrics InfoResMetrics `json:"metrics"`
	// The features this node exposes.
	Features []string `json:"features"`
}

InfoResponse defines the response of a GET info REST API call.

type MilestoneInfo

type MilestoneInfo struct {
	Index       iotago.MilestoneIndex `json:"index"`
	Timestamp   uint32                `json:"timestamp"`
	MilestoneID string                `json:"milestoneId"`
}

MilestoneInfo is an informative struct holding a milestone index, milestone ID and timestamp.

type MilestoneUTXOChangesResponse

type MilestoneUTXOChangesResponse struct {
	// The index of the milestone.
	Index iotago.MilestoneIndex `json:"index"`
	// The output IDs (transaction hash + output index) of the newly created outputs.
	CreatedOutputs []string `json:"createdOutputs"`
	// The output IDs (transaction hash + output index) of the consumed (spent) outputs.
	ConsumedOutputs []string `json:"consumedOutputs"`
}

MilestoneUTXOChangesResponse defines the response of a GET milestone UTXO changes REST API call.

type NFTsQuery

type NFTsQuery struct {
	IndexerCursorParas
	IndexerTimelockParas
	IndexerExpirationParas
	IndexerStorageDepositParas
	IndexerNativeTokenParas
	IndexerCreationParas

	// Bech32-encoded address that should be searched for.
	AddressBech32 string `qs:"address,omitempty"`
	// Filters outputs based on the presence of validated sender.
	SenderBech32 string `qs:"sender,omitempty"`
	// Filters outputs based on the presence of validated issuer.
	IssuerBech32 string `qs:"issuer,omitempty"`
	// Filters outputs based on matching tag feature.
	Tag string `qs:"tag,omitempty"`
}

NFTsQuery defines parameters for an NFT outputs query.

func (*NFTsQuery) OutputType

func (query *NFTsQuery) OutputType() iotago.OutputType

func (*NFTsQuery) SetOffset

func (query *NFTsQuery) SetOffset(cursor *string)

func (*NFTsQuery) URLParas

func (query *NFTsQuery) URLParas() (string, error)

type OutputMetadataResponse

type OutputMetadataResponse struct {
	// The hex encoded ID of the block.
	BlockID string `json:"blockId"`
	// The hex encoded transaction id from which this output originated.
	TransactionID string `json:"transactionId"`
	// The index of the output.
	OutputIndex uint16 `json:"outputIndex"`
	// Whether this output is spent.
	Spent bool `json:"isSpent"`
	// The milestone index at which this output was spent.
	MilestoneIndexSpent iotago.MilestoneIndex `json:"milestoneIndexSpent,omitempty"`
	// The milestone timestamp this output was spent.
	MilestoneTimestampSpent uint32 `json:"milestoneTimestampSpent,omitempty"`
	// The transaction this output was spent with.
	TransactionIDSpent string `json:"transactionIdSpent,omitempty"`
	// The milestone index at which this output was booked into the ledger.
	MilestoneIndexBooked iotago.MilestoneIndex `json:"milestoneIndexBooked"`
	// The milestone timestamp this output was booked in the ledger.
	MilestoneTimestampBooked uint32 `json:"milestoneTimestampBooked"`
	// The ledger index at which this output was available at.
	LedgerIndex iotago.MilestoneIndex `json:"ledgerIndex"`
}

OutputMetadataResponse defines the response of a GET outputs metadata REST API call.

func (*OutputMetadataResponse) TxID

TxID returns the TransactionID.

type OutputResponse

type OutputResponse struct {
	Metadata *OutputMetadataResponse `json:"metadata"`
	// The output in its serialized form.
	RawOutput *json.RawMessage `json:"output"`
}

OutputResponse defines the response of a GET outputs REST API call.

func (*OutputResponse) Output

func (nor *OutputResponse) Output() (iotago.Output, error)

Output deserializes the RawOutput to an Output.

type PeerGossipMetrics

type PeerGossipMetrics struct {
	// The total amount of received new blocks.
	NewBlocks uint32 `json:"newBlocks"`
	// The total amount of received known blocks.
	KnownBlocks uint32 `json:"knownBlocks"`
	// The total amount of received blocks.
	ReceivedBlocks uint32 `json:"receivedBlocks"`
	// The total amount of received block requests.
	ReceivedBlockRequests uint32 `json:"receivedBlockRequests"`
	// The total amount of received milestone requests.
	ReceivedMilestoneRequests uint32 `json:"receivedMilestoneRequests"`
	// The total amount of received heartbeats.
	ReceivedHeartbeats uint32 `json:"receivedHeartbeats"`
	// The total amount of sent blocks.
	SentBlocks uint32 `json:"sentBlocks"`
	// The total amount of sent block request.
	SentBlockRequests uint32 `json:"sentBlockRequests"`
	// The total amount of sent milestone request.
	SentMilestoneRequests uint32 `json:"sentMilestoneRequests"`
	// The total amount of sent heartbeats.
	SentHeartbeats uint32 `json:"sentHeartbeats"`
	// The total amount of packets which couldn't be sent.
	DroppedPackets uint32 `json:"droppedPackets"`
}

PeerGossipMetrics defines the peer gossip metrics.

type PeerResponse

type PeerResponse struct {
	// The libp2p identifier of the peer.
	ID string `json:"id"`
	// The libp2p multi addresses of the peer.
	MultiAddresses []string `json:"multiAddresses"`
	// The alias to identify the peer.
	Alias *string `json:"alias,omitempty"`
	// The relation (static, autopeered) of the peer.
	Relation string `json:"relation"`
	// Whether the peer is connected.
	Connected bool `json:"connected"`
	// The gossip related information about this peer.
	Gossip *GossipInfo `json:"gossip,omitempty"`
}

PeerResponse defines the response of a GET peer REST API call.

type RawDataEnvelope

type RawDataEnvelope struct {
	// The encapsulated binary data.
	Data []byte
}

RawDataEnvelope is used internally to encapsulate binary data.

type ReceiptTuple

type ReceiptTuple struct {
	Receipt        *iotago.ReceiptMilestoneOpt `json:"receipt"`
	MilestoneIndex iotago.MilestoneIndex       `json:"milestoneIndex"`
}

ReceiptTuple represents a receipt and the milestone index in which it was contained.

type ReceiptsResponse

type ReceiptsResponse struct {
	Receipts []*ReceiptTuple `json:"receipts"`
}

ReceiptsResponse defines the response for receipts GET related REST API calls.

type RequestHeaderHook

type RequestHeaderHook func(header http.Header)

RequestHeaderHook is a function to modify the request header before sending a request.

type RequestURLHook

type RequestURLHook func(url string) string

RequestURLHook is a function to modify the URL before sending a request.

type RoutesResponse

type RoutesResponse struct {
	Routes []string `json:"routes"`
}

RoutesResponse defines the response of a GET routes REST API call.

type TipsResponse

type TipsResponse struct {
	// The hex encoded block IDs of the tips.
	TipsHex []string `json:"tips"`
}

TipsResponse defines the response of a GET tips REST API call.

func (*TipsResponse) Tips

func (ntr *TipsResponse) Tips() (iotago.BlockIDs, error)

Tips returns the hex encoded tips as BlockIDs.

type TreasuryResponse

type TreasuryResponse struct {
	MilestoneID string `json:"milestoneId"`
	Amount      string `json:"amount"`
}

TreasuryResponse defines the response of a GET treasury REST API call.

Jump to

Keyboard shortcuts

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