webapi

package
v0.5.10 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: Apache-2.0 Imports: 57 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MIMEApplicationVendorIOTASerializerV1 = "application/vnd.iota.serializer-v1"
	ProtocolHTTP                          = "http"
	ProtocolHTTPS                         = "https"
	ProtocolWS                            = "ws"
	ProtocolWSS                           = "wss"
)
View Source
const (
	ParameterAddress         = "address"
	ParameterTransactionHash = "txHash"
	ParameterMilestoneIndex  = "index"

	QueryParameterBundle     = "bundle"
	QueryParameterAddress    = "address"
	QueryParameterTag        = "tag"
	QueryParameterApprovee   = "approvee"
	QueryParameterMaxResults = "maxResults"
)
View Source
const (
	// RouteRPCEndpoint is the route for sending RPC requests to the API.
	// POST sends an IOTA legacy API request and returns the results.
	RouteRPCEndpoint = "/"

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

	// RouteMilestoneByIndex is the route for getting a milestone by its milestoneIndex.
	// GET will return the milestone.
	RouteMilestoneByIndex = "/milestones/by-index/:" + ParameterMilestoneIndex

	// RouteTransactions is the route for getting transactions filtered by the given parameters.
	// GET with query parameter returns all txHashes that fit these filter criteria.
	// Query parameters: "bundle", "address", "tag", "approvee", "maxResults"
	// Returns an empty list if no results are found.
	RouteTransactions = "/transactions" // former findTransactions

	// RouteTransaction is the route for getting a transaction.
	// GET will return the transaction.
	RouteTransaction = "/transactions/:" + ParameterTransactionHash

	// RouteTransactionTrytes is the route for getting the trytes of a transaction.
	// GET will return the transaction trytes.
	RouteTransactionTrytes = "/transactions/:" + ParameterTransactionHash + "/trytes" // former getTrytes

	// RouteTransactionMetadata is the route for getting the metadata of a transaction.
	// GET will return the metadata.
	RouteTransactionMetadata = "/transactions/:" + ParameterTransactionHash + "/metadata" // former getInclusionStates

	// RouteAddressBalance is the route for getting the balance of an address.
	// GET will return the balance.
	RouteAddressBalance = "/addresses/:" + ParameterAddress + "/balance" // former getBalances

	// RouteAddressBalance is the route to check whether an address was already spent or not.
	// GET will return true if the address was already spent.
	RouteAddressWasSpent = "/addresses/:" + ParameterAddress + "/was-spent" // former wereAddressesSpentFrom

	// RouteLedgerState is the route to return the current ledger state.
	// GET will return all addresses with their balances.
	RouteLedgerState = "/ledger/state" // former getLedgerState

	// RouteLedgerStateNonMigrated is the route to return the current non-migrated ledger state.
	// GET will return all non-migrated addresses with their balances.
	RouteLedgerStateNonMigrated = "/ledger/state/non-migrated"

	// RouteLedgerStateByIndex is the route to return the ledger state of a given ledger index.
	// GET will return all addresses with their balances.
	RouteLedgerStateByIndex = "/ledger/state/by-index/:" + ParameterMilestoneIndex // former getLedgerState

	// RouteLedgerStateNonMigratedByIndex is the route to return the non-migrated ledger state of a given ledger index.
	// GET will return all non-migrated addresses with their balances.
	RouteLedgerStateNonMigratedByIndex = "/ledger/state/by-index/:" + ParameterMilestoneIndex + "/non-migrated"

	// RouteLedgerDiffByIndex is the route to return the ledger diff of a given ledger index.
	// GET will return all addresses with their diffs.
	RouteLedgerDiffByIndex = "/ledger/diff/by-index/:" + ParameterMilestoneIndex // former getLedgerDiff

	// RouteLedgerDiffExtendedByIndex is the route to return the ledger diff of a given ledger index with extended informations.
	// GET will return all addresses with their diffs, the confirmed transactions and the confirmed bundles.
	RouteLedgerDiffExtendedByIndex = "/ledger/diff-extended/by-index/:" + ParameterMilestoneIndex // former getLedgerDiffExt
)
View Source
const (
	APIRouteRest = "/api/core/v0"
)
View Source
const (
	MIMETextCSV = "text/csv"
)

Variables

View Source
var (
	// ErrInvalidParameter defines the invalid parameter error.
	ErrInvalidParameter = echo.NewHTTPError(http.StatusBadRequest, "invalid parameter")

	// ErrNotAcceptable defines the not acceptable error.
	ErrNotAcceptable = echo.NewHTTPError(http.StatusNotAcceptable)
)
View Source
var (
	ErrPrivKeyInvalid   = errors.New("invalid private key")
	ErrNoPrivKeyFound   = errors.New("no private key found")
	ErrInvalidKeyLength = errors.New("invalid key length")
)
View Source
var (
	PLUGIN = node.NewPlugin("WebAPI", node.Enabled, configure, run)
)

PLUGIN WebAPI

Functions

func GetAcceptHeaderContentType

func GetAcceptHeaderContentType(c echo.Context, supportedContentTypes ...string) (string, error)

func GetRequestContentType

func GetRequestContentType(c echo.Context, supportedContentTypes ...string) (string, error)

func GetURL

func GetURL(protocol string, host string, port uint16, path ...string) string

func JSONResponse

func JSONResponse(c echo.Context, statusCode int, result interface{}) error

JSONResponse sends the JSON response with status code.

func LoadOrCreateIdentityPrivateKey

func LoadOrCreateIdentityPrivateKey(privKeyFilePath string, identityPrivKey string) (libp2pcrypto.PrivKey, bool, error)

LoadOrCreateIdentityPrivateKey loads an existing Ed25519 based identity private key or creates a new one and stores it as a PEM file in the p2p store folder.

func NewEcho

func NewEcho(logger *logger.Logger, onHTTPError func(err error, c echo.Context), debugRequestLoggerEnabled bool) *echo.Echo

NewEcho returns a new Echo instance. It hides the banner, adds a default HTTPErrorHandler and the Recover middleware.

func ParseBoolQueryParam

func ParseBoolQueryParam(c echo.Context, paramName string) (bool, error)

func ParseMilestoneIndexParam

func ParseMilestoneIndexParam(c echo.Context, paramName string) (uint64, error)

func ParseUint32QueryParam

func ParseUint32QueryParam(c echo.Context, paramName string, maxValue ...uint32) (uint32, error)

func ParseUnixTimestampQueryParam

func ParseUnixTimestampQueryParam(c echo.Context, paramName string) (time.Time, error)

Types

type AddNeighbors

type AddNeighbors struct {
	Uris []string `json:"uris"`
}

AddNeighbors legacy struct.

type AddNeighborsHornet

type AddNeighborsHornet struct {
	Neighbors []Neighbor `json:"neighbors"`
}

AddNeighborsHornet struct.

type AddNeighborsResponse

type AddNeighborsResponse struct {
	AddedNeighbors int `json:"addedNeighbors"`
	Duration       int `json:"duration"`
}

AddNeighborsResponse struct.

type AddressWithBalance

type AddressWithBalance struct {
	Address trinary.Hash `json:"address"`
	Balance string       `json:"balance"`
}

type ApproverStruct

type ApproverStruct struct {
	TxHash            trinary.Hash `json:"txHash"`
	ReferencedByTrunk bool         `json:"referencedByTrunk"`
}

ApproverStruct struct.

type AttachToTangle

type AttachToTangle struct {
	TrunkTransaction   trinary.Hash     `json:"trunkTransaction"`
	BranchTransaction  trinary.Hash     `json:"branchTransaction"`
	MinWeightMagnitude int              `json:"minWeightMagnitude,omitempty"`
	Trytes             []trinary.Trytes `json:"trytes"`
}

AttachToTangle struct.

type AttachToTangleResponse

type AttachToTangleResponse struct {
	Trytes   []trinary.Trytes `json:"trytes"`
	Duration int              `json:"duration"`
}

AttachToTangleResponse struct.

type BroadcastTransactions

type BroadcastTransactions struct {
	Trytes []trinary.Trytes `json:"trytes"`
}

BroadcastTransactions struct.

type BroadcastTransactionsResponse

type BroadcastTransactionsResponse struct {
	Duration int `json:"duration"`
}

BroadcastTransactionsResponse struct.

type BundleWithValue

type BundleWithValue struct {
	BundleHash trinary.Hash   `json:"bundleHash"`
	TailTxHash trinary.Hash   `json:"tailTxHash"`
	LastIndex  uint64         `json:"lastIndex"`
	Txs        []*TxWithValue `json:"txs"`
}

BundleWithValue struct.

func (*BundleWithValue) Item

func (b *BundleWithValue) Item() Container

type CheckConsistencyResponse

type CheckConsistencyResponse struct {
	State    bool `json:"state"`
	Duration int  `json:"duration"`
}

CheckConsistencyResponse struct

type Container

type Container interface {
	Item() Container
}

Container holds an object.

type CreateSnapshotFile

type CreateSnapshotFile struct {
	TargetIndex milestone.Index `json:"targetIndex"`
}

CreateSnapshotFile struct.

type CreateSnapshotFileResponse

type CreateSnapshotFileResponse struct {
	Duration int `json:"duration"`
}

CreateSnapshotFileResponse struct.

type DebugRequest

type DebugRequest struct {
	Hash             trinary.Hash    `json:"hash"`
	Type             string          `json:"type"`
	TxExists         bool            `json:"txExists"`
	EnqueueTimestamp int64           `json:"enqueueTime"`
	MilestoneIndex   milestone.Index `json:"milestoneIndex"`
}

type EntryPoint

type EntryPoint struct {
	TxHash                    trinary.Hash    `json:"txHash"`
	ConfirmedByMilestoneIndex milestone.Index `json:"confirmedByMilestoneIndex"`
}

EntryPoint struct.

type ErrorReturn

type ErrorReturn struct {
	Error string `json:"error"`
}

ErrorReturn struct.

type FindTransactions

type FindTransactions struct {
	Bundles    []trinary.Hash `json:"bundles"`
	Addresses  []trinary.Hash `json:"addresses"`
	Tags       []trinary.Hash `json:"tags"`
	Approvees  []trinary.Hash `json:"approvees"`
	MaxResults int            `json:"maxresults"`
	ValueOnly  bool           `json:"valueOnly"`
}

FindTransactions struct.

type FindTransactionsResponse

type FindTransactionsResponse struct {
	Hashes   []trinary.Hash `json:"hashes"`
	Duration int            `json:"duration"`
}

FindTransactionsResponse struct.

type GetBalances

type GetBalances struct {
	Addresses []trinary.Hash `json:"addresses"`
}

GetBalances struct.

type GetBalancesResponse

type GetBalancesResponse struct {
	Balances       []string        `json:"balances"`
	References     []trinary.Hash  `json:"references"`
	MilestoneIndex milestone.Index `json:"milestoneIndex"`
	Duration       int             `json:"duration"`
}

GetBalancesResponse struct.

type GetFundsOnSpentAddressesResponse

type GetFundsOnSpentAddressesResponse struct {
	Addresses []*AddressWithBalance `json:"addresses"`
}

GetFundsOnSpentAddressesResponse struct.

type GetInclusionStates

type GetInclusionStates struct {
	Transactions []trinary.Hash `json:"transactions"`
}

GetInclusionStates struct.

type GetInclusionStatesResponse

type GetInclusionStatesResponse struct {
	States   []bool `json:"states"`
	Duration int    `json:"duration"`
}

GetInclusionStatesResponse struct.

type GetLedgerDiff

type GetLedgerDiff struct {
	MilestoneIndex milestone.Index `json:"milestoneIndex"`
}

GetLedgerDiff struct.

type GetLedgerDiffExt

type GetLedgerDiffExt struct {
	MilestoneIndex milestone.Index `json:"milestoneIndex"`
}

GetLedgerDiffExt struct.

type GetLedgerDiffExtResponse

type GetLedgerDiffExtResponse struct {
	ConfirmedTxWithValue      []*TxHashWithValue      `json:"confirmedTxWithValue"`
	ConfirmedBundlesWithValue []*BundleWithValue      `json:"confirmedBundlesWithValue"`
	Diff                      map[trinary.Hash]string `json:"diff"`
	MilestoneIndex            milestone.Index         `json:"milestoneIndex"`
	Duration                  int                     `json:"duration"`
}

GetLedgerDiffExtResponse struct.

type GetLedgerDiffResponse

type GetLedgerDiffResponse struct {
	Diff           map[trinary.Hash]string `json:"diff"`
	MilestoneIndex milestone.Index         `json:"milestoneIndex"`
	Duration       int                     `json:"duration"`
}

GetLedgerDiffResponse struct.

type GetLedgerState

type GetLedgerState struct {
	TargetIndex milestone.Index `json:"targetIndex,omitempty"`
}

GetLedgerState struct.

type GetLedgerStateResponse

type GetLedgerStateResponse struct {
	Balances       map[trinary.Hash]string `json:"balances"`
	MilestoneIndex milestone.Index         `json:"milestoneIndex"`
	Duration       int                     `json:"duration"`
}

GetLedgerStateResponse struct.

type GetMigration

type GetMigration struct {
	MilestoneIndex milestone.Index `json:"milestoneIndex"`
}

type GetNeighborsResponse

type GetNeighborsResponse struct {
	Neighbors []*peer.Info `json:"neighbors"`
	Duration  int          `json:"duration"`
}

GetNeighborsResponse struct.

type GetNodeAPIConfigurationResponse

type GetNodeAPIConfigurationResponse struct {
	MaxFindTransactions int             `json:"maxFindTransactions"`
	MaxRequestsList     int             `json:"maxRequestsList"`
	MaxGetTrytes        int             `json:"maxGetTrytes"`
	MaxBodyLength       int             `json:"maxBodyLength"`
	MilestoneStartIndex milestone.Index `json:"milestoneStartIndex"`
	Duration            int             `json:"duration"`
}

GetNodeAPIConfigurationResponse struct.

type GetNodeInfoResponse

type GetNodeInfoResponse struct {
	AppName                            string          `json:"appName"`
	AppVersion                         string          `json:"appVersion"`
	NodeAlias                          string          `json:"nodeAlias,omitempty"`
	LatestMilestone                    trinary.Hash    `json:"latestMilestone"`
	LatestMilestoneIndex               milestone.Index `json:"latestMilestoneIndex"`
	LatestSolidSubtangleMilestone      trinary.Hash    `json:"latestSolidSubtangleMilestone"`
	LatestSolidSubtangleMilestoneIndex milestone.Index `json:"latestSolidSubtangleMilestoneIndex"`
	IsSynced                           bool            `json:"isSynced"`
	Health                             bool            `json:"isHealthy"`
	MilestoneStartIndex                milestone.Index `json:"milestoneStartIndex"`
	LastSnapshottedMilestoneIndex      milestone.Index `json:"lastSnapshottedMilestoneIndex"`
	Neighbors                          uint            `json:"neighbors"`
	Time                               int64           `json:"time"`
	Tips                               uint32          `json:"tips"`
	TransactionsToRequest              int             `json:"transactionsToRequest"`
	Features                           []string        `json:"features"`
	CoordinatorAddress                 trinary.Hash    `json:"coordinatorAddress"`
	Duration                           int             `json:"duration"`
}

GetNodeInfoResponse struct.

type GetRequestsResponse

type GetRequestsResponse struct {
	Requests []*DebugRequest `json:"requests"`
}

GetRequestsResponse struct.

type GetTipInfo

type GetTipInfo struct {
	TailTransaction trinary.Hash `json:"tailTransaction"`
}

GetTipInfo struct.

type GetTipInfoResponse

type GetTipInfoResponse struct {
	Confirmed      bool `json:"confirmed"`
	Conflicting    bool `json:"conflicting"`
	ShouldPromote  bool `json:"shouldPromote"`
	ShouldReattach bool `json:"shouldReattach"`
	Duration       int  `json:"duration"`
}

GetTipInfoResponse struct.

type GetTransactionsToApprove

type GetTransactionsToApprove struct {
	Depth     uint         `json:"depth"`
	Reference trinary.Hash `json:"reference"`
}

GetTransactionsToApprove struct.

type GetTransactionsToApproveResponse

type GetTransactionsToApproveResponse struct {
	TrunkTransaction  trinary.Hash `json:"trunkTransaction"`
	BranchTransaction trinary.Hash `json:"branchTransaction"`
	Duration          int          `json:"duration"`
}

GetTransactionsToApproveResponse struct.

type GetTrytes

type GetTrytes struct {
	Hashes []trinary.Hash `json:"hashes"`
}

GetTrytes struct.

type GetTrytesResponse

type GetTrytesResponse struct {
	Trytes   []trinary.Trytes `json:"trytes"`
	Duration int              `json:"duration"`
}

GetTrytesResponse struct.

type GetWhiteFlagConfirmationResponse

type GetWhiteFlagConfirmationResponse struct {
	// The trytes of the milestone bundle.
	MilestoneBundle []trinary.Trytes `json:"milestoneBundle"`
	// The included bundles of the white-flag confirmation in their DFS order.
	IncludedBundles [][]trinary.Trytes `json:"includedBundles"`
}

GetWhiteFlagConfirmationResponse defines the response of a getWhiteFlagConfirmation HTTP API call.

type HTTPErrorResponse

type HTTPErrorResponse struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

HTTPErrorResponse defines the error struct for the HTTPErrorResponseEnvelope.

type HTTPErrorResponseEnvelope

type HTTPErrorResponseEnvelope struct {
	Error HTTPErrorResponse `json:"error"`
}

HTTPErrorResponseEnvelope defines the error response schema for node API responses.

type Neighbor

type Neighbor struct {
	Identity   string `json:"identity"`
	Alias      string `json:"alias"`
	PreferIPv6 bool   `json:"prefer_ipv6"`
}

Neighbor struct.

type PruneDatabase

type PruneDatabase struct {
	TargetIndex milestone.Index `json:"targetIndex"`
	Depth       milestone.Index `json:"depth"`
}

PruneDatabase struct.

type PruneDatabaseResponse

type PruneDatabaseResponse struct {
	Duration int `json:"duration"`
}

PruneDatabaseResponse struct.

type RemoveNeighbors

type RemoveNeighbors struct {
	Uris []string `json:"uris"`
}

RemoveNeighbors struct.

type RemoveNeighborsResponse

type RemoveNeighborsResponse struct {
	RemovedNeighbors uint `json:"removedNeighbors"`
	Duration         int  `json:"duration"`
}

RemoveNeighborsResponse struct.

type Request

type Request struct {
	Command string `json:"command"`
}

Request struct.

type SearchConfirmedApprover

type SearchConfirmedApprover struct {
	TxHash          trinary.Hash `json:"txHash"`
	SearchMilestone bool         `json:"searchMilestone"`
}

SearchConfirmedApprover struct.

type SearchConfirmedApproverResponse

type SearchConfirmedApproverResponse struct {
	ConfirmedTxHash           trinary.Hash      `json:"confirmedTxHash"`
	ConfirmedByMilestoneIndex milestone.Index   `json:"confirmedByMilestoneIndex"`
	TanglePath                []*ApproverStruct `json:"tanglePath"`
	TanglePathLength          int               `json:"tanglePathLength"`
}

SearchConfirmedApproverResponse struct.

type SearchEntryPoint

type SearchEntryPoint struct {
	TxHash trinary.Hash `json:"txHash"`
}

SearchEntryPoint struct.

type SearchEntryPointResponse

type SearchEntryPointResponse struct {
	TanglePath       []*TransactionWithApprovers `json:"tanglePath"`
	EntryPoints      []*EntryPoint               `json:"entryPoints"`
	TanglePathLength int                         `json:"tanglePathLength"`
}

SearchEntryPointResponse struct.

type StoreTransactions

type StoreTransactions struct {
	Trytes []trinary.Trytes `json:"trytes"`
}

StoreTransactions struct.

type TransactionWithApprovers

type TransactionWithApprovers struct {
	TxHash            trinary.Hash `json:"txHash"`
	TrunkTransaction  trinary.Hash `json:"trunkTransaction"`
	BranchTransaction trinary.Hash `json:"branchTransaction"`
}

type TxHashWithValue

type TxHashWithValue struct {
	TxHash     trinary.Hash `json:"txHash"`
	TailTxHash trinary.Hash `json:"tailTxHash"`
	BundleHash trinary.Hash `json:"bundleHash"`
	Address    trinary.Hash `json:"address"`
	Value      string       `json:"value"`
}

TxHashWithValue struct.

func (*TxHashWithValue) Item

func (tx *TxHashWithValue) Item() Container

type TxWithValue

type TxWithValue struct {
	TxHash  trinary.Hash `json:"txHash"`
	Address trinary.Hash `json:"address"`
	Index   uint64       `json:"index"`
	Value   string       `json:"value"`
}

TxWithValue struct.

func (*TxWithValue) Item

func (tx *TxWithValue) Item() Container

type WebAPIServer

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

func NewWebAPIServer

func NewWebAPIServer(
	e *echo.Echo,
	log *logger.Logger,
	rpcEndpointsPublic []string,
	maxResults int) *WebAPIServer

func (*WebAPIServer) HasRPCEndpoint

func (s *WebAPIServer) HasRPCEndpoint(endpoint string) bool

func (*WebAPIServer) SetFeatures

func (s *WebAPIServer) SetFeatures(features []string)

type WereAddressesSpentFrom

type WereAddressesSpentFrom struct {
	Addresses []trinary.Hash `json:"addresses"`
}

WereAddressesSpentFrom struct.

type WereAddressesSpentFromResponse

type WereAddressesSpentFromResponse struct {
	States   []bool `json:"states"`
	Duration int    `json:"duration"`
}

WereAddressesSpentFromResponse struct.

Jump to

Keyboard shortcuts

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