api

package
v1.0.1-lp-billion-1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package api provides an API object for interacting with IRI nodes.

Index

Constants

View Source
const (
	QuorumHigh   = 0.95
	QuorumMedium = 0.75
	QuorumLow    = 0.60
)

package quorum levels

View Source
const DefaultLocalIRIURI = "http://localhost:14265"

DefaultLocalIRIURI is the default URI used when none is given in HTTPClientSettings.

View Source
const MinimumQuorumThreshold = 0.5

MinimumQuorumThreshold is the minimum threshold the quorum settings must have.

Variables

View Source
var (
	ErrInvalidQuorumThreshold                 = errors.New("quorum threshold is set too low, must be >0.5")
	ErrQuorumNotReached                       = errors.New("the quorum didn't reach a satisfactory result")
	ErrExceededNoResponseTolerance            = errors.New("exceeded no-response tolerance for quorum")
	ErrNotEnoughNodesForQuorum                = errors.New("at least 2 nodes must be defined for quorum")
	ErrNoLatestSolidSubtangleInfo             = errors.New("no latest solid subtangle info found")
	ErrExceededMaxSubtangleMilestoneDelta     = errors.New("exceeded max subtangle milestone delta between nodes")
	ErrNonOkStatusCodeSubtangleMilestoneQuery = errors.New("non ok status code for subtangle milestone query")
)

errors produced by the quorum http provider

Functions

This section is empty.

Types

type API

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

API defines an object encapsulating the communication to connected nodes and API calls.

func ComposeAPI

func ComposeAPI(settings Settings, createProvider ...CreateProviderFunc) (*API, error)

ComposeAPI composes a new API from the given settings and provider. If no provider function is supplied, then the default http provider is used. Settings must not be nil.

func (*API) AddNeighbors

func (api *API) AddNeighbors(uris ...string) (int64, error)

AddNeighbors adds a list of neighbors to the connected IRI node. Assumes addNeighbors command is available on the node. AddNeighbors has only a temporary effect until the node relaunches.

func (*API) AttachToTangle

func (api *API) AttachToTangle(trunkTxHash Hash, branchTxHash Hash, mwm uint64, trytes []Trytes) ([]Trytes, error)

AttachToTangle performs the Proof-of-Work required to attach a transaction to the Tangle by calling the attachToTangle IRI API command. Returns a list of transaction trytes and overwrites the following fields: Hash, Nonce, AttachmentTimestamp, AttachmentTimestampLowerBound, AttachmentTimestampUpperBound.

If a Proof-of-Work function is supplied when composing the API, then that function is used instead of using the connected node.

func (*API) BroadcastBundle

func (api *API) BroadcastBundle(tailTxHash Hash) ([]Trytes, error)

BroadcastBundle re-broadcasts all transactions in a bundle given the tail transaction hash. It might be useful when transactions did not properly propagate, particularly in the case of large bundles.

func (*API) BroadcastTransactions

func (api *API) BroadcastTransactions(trytes ...Trytes) ([]Trytes, error)

BroadcastTransactions broadcasts a list of attached transaction trytes to the network. Tip-selection and Proof-of-Work must be done first by calling GetTransactionsToApprove and AttachToTangle or an equivalent attach method.

You may use this method to increase odds of effective transaction propagation.

Persist the transaction trytes in local storage before calling this command for first time, to ensure that reattachment is possible, until your bundle has been included.

func (*API) CheckConsistency

func (api *API) CheckConsistency(hashes ...Hash) (bool, string, error)

CheckConsistency checks if a transaction is consistent or a set of transactions are co-consistent.

Co-consistent transactions and the transactions that they approve (directly or indirectly), are not conflicting with each other and the rest of the ledger.

As long as a transaction is consistent, it might be accepted by the network. In case a transaction is inconsistent, it will not be accepted and a reattachment is required by calling ReplayBundle().

func (*API) FindTransactionObjects

func (api *API) FindTransactionObjects(query FindTransactionsQuery) (transaction.Transactions, error)

FindTransactionObjects searches for transactions given a query object with addresses, tags and approvees fields. Multiple query fields are supported and FindTransactionObjects returns the intersection of results.

func (*API) FindTransactions

func (api *API) FindTransactions(query FindTransactionsQuery) (Hashes, error)

FindTransactions searches for transaction hashes. It allows to search for transactions by passing a query object with addresses, bundle hashes, tags and/or approvees fields. Multiple query fields are supported and FindTransactions returns the intersection of the results.

func (*API) GetAccountData

func (api *API) GetAccountData(seed Trytes, options GetAccountDataOptions) (*AccountData, error)

GetAccountData returns an AccountData object containing account information about addresses, transactions, inputs and total account balance. Deprecated: Use a solution which uses local persistence to keep the account data.

func (*API) GetBalances

func (api *API) GetBalances(addresses Hashes, tips ...Hash) (*Balances, error)

GetBalances fetches confirmed balances of the given addresses at the latest solid milestone.

func (*API) GetBundle

func (api *API) GetBundle(tailTxHash Hash) (bundle.Bundle, error)

GetBundle fetches and validates the bundle given a tail transaction hash by calling TraverseBundle and traversing through trunk transactions.

func (*API) GetBundlesFromAddresses

func (api *API) GetBundlesFromAddresses(addresses Hashes, inclusionState ...bool) (bundle.Bundles, error)

GetBundlesFromAddresses fetches all bundles from the given addresses and optionally sets the confirmed property on each transaction using GetLatestInclusion. This function does not validate the bundles.

func (*API) GetInclusionStates

func (api *API) GetInclusionStates(txHashes Hashes) ([]bool, error)

GetInclusionStates fetches inclusion states (confirmation state) of a given list of transactions.

func (*API) GetInputObjects

func (api *API) GetInputObjects(addresses Hashes, balances []uint64, start uint64, secLvl SecurityLevel) Inputs

GetInputObjects creates an Input object using the given addresses, balances, start index and security level.

func (*API) GetInputs

func (api *API) GetInputs(seed Trytes, options GetInputsOptions) (*Inputs, error)

GetInputs creates and returns an Inputs object by generating addresses and fetching their latest balance.

func (*API) GetLatestInclusion

func (api *API) GetLatestInclusion(txHashes Hashes) ([]bool, error)

GetLatestInclusion fetches inclusion states of the given transactions by calling GetInclusionStates using the latest solid subtangle milestone from GetNodeInfo. Deprecated: GetLatestInclusion exists only for historical reason where GetInclusionStates could return inclusion state for the given hashes against a list of tips. As GetInclusionStates now only checks whether transactions are marked as confirmed, this function is no longer needed and is only kept around for backwards compatibility. Calling this function is equivalent to calling GetInclusionStates.

func (*API) GetLatestSolidSubtangleMilestone

func (api *API) GetLatestSolidSubtangleMilestone() (*GetLatestSolidSubtangleMilestoneResponse, error)

GetLatestSolidSubtangleMilestone returns the latest subtangle milestone.

func (*API) GetNeighbors

func (api *API) GetNeighbors() (Neighbors, error)

GetNeighbors returns the list of connected neighbors of the connected node.

func (*API) GetNewAddress

func (api *API) GetNewAddress(seed Trytes, options GetNewAddressOptions) (Hashes, error)

GetNewAddress generates and returns a new address by calling FindTransactions and WereAddressesSpentFrom until the first unused address is detected. This stops working after a snapshot.

If the "total" parameter is supplied in the options, then this function simply generates the specified address range without doing any I/O.

It is suggested that the library user keeps track of used addresses and directly generates addresses from the stored information instead of relying on GetNewAddress.

func (*API) GetNodeInfo

func (api *API) GetNodeInfo() (*GetNodeInfoResponse, error)

GetNodeInfo returns information about the connected node.

func (*API) GetTransactionObjects

func (api *API) GetTransactionObjects(hashes ...Hash) (transaction.Transactions, error)

GetTransactionObjects fetches transaction objects given an array of transaction hashes.

func (*API) GetTransactionsToApprove

func (api *API) GetTransactionsToApprove(depth uint64, reference ...Hash) (*TransactionsToApprove, error)

GetTransactionsToApprove does the tip selection via the connected node.

Returns a pair of approved transactions which are chosen randomly after validating the transaction trytes, the signatures and cross-checking for conflicting transactions.

Tip selection is executed by a Random Walk (RW) starting at random point in the given depth, ending up to the pair of selected tips. For more information about tip selection please refer to the whitepaper (http://iotatoken.com/IOTA_Whitepaper.pdf).

The reference option allows to select tips in a way that the reference transaction is being approved too. This is useful for promoting transactions, for example with PromoteTransaction().

func (*API) GetTransfers

func (api *API) GetTransfers(seed Trytes, options GetTransfersOptions) (bundle.Bundles, error)

GetTransfers returns bundles which operated on the given address range specified by the supplied options.

func (*API) GetTrytes

func (api *API) GetTrytes(hashes ...Hash) ([]Trytes, error)

GetTrytes fetches the transaction trytes given a list of transaction hashes.

func (*API) InterruptAttachToTangle

func (api *API) InterruptAttachToTangle() error

InterruptAttachToTangle interrupts the currently ongoing Proof-of-Work on the connected node.

func (*API) IsAddressUsed

func (api *API) IsAddressUsed(address Hash) (bool, error)

IsAddressUsed checks whether an address is used via FindTransactions and WereAddressesSpentFrom.

func (*API) IsPromotable

func (api *API) IsPromotable(tailTxHash Hash) (bool, error)

IsPromotable checks if a transaction is promotable by calling the checkConsistency IRI API command and verifying that attachmentTimestamp is above a lower bound. Lower bound is calculated based on the number of milestones issued since transaction attachment.

func (*API) PrepareTransfers

func (api *API) PrepareTransfers(seed Trytes, transfers bundle.Transfers, opts PrepareTransfersOptions) ([]Trytes, error)

PrepareTransfers prepares the transaction trytes by generating a bundle, filling in transfers and inputs, adding remainder and signing all input transactions.

func (*API) PromoteTransaction

func (api *API) PromoteTransaction(tailTxHash Hash, depth uint64, mwm uint64, spamTransfers bundle.Transfers, options PromoteTransactionOptions) (transaction.Transactions, error)

PromoteTransaction promotes a transaction by adding other transactions (spam by default) on top of it. If an optional Context is supplied, PromoteTransaction() will promote the given transaction until the Context is done/cancelled. If no Context is provided, PromoteTransaction() will create one promote transaction.

func (*API) RemoveNeighbors

func (api *API) RemoveNeighbors(uris ...string) (int64, error)

RemoveNeighbors removes a list of neighbors from the connected IRI node. This method has a temporary effect until the IRI node relaunches.

func (*API) ReplayBundle

func (api *API) ReplayBundle(tailTxHash Hash, depth uint64, mwm uint64, reference ...Hash) (bundle.Bundle, error)

ReplayBundle reattaches a transfer to the Tangle by selecting tips & performing the Proof-of-Work again. Reattachments are useful in case original transactions are pending and can be done securely as many times as needed.

func (*API) SendTransfer

func (api *API) SendTransfer(seed Trytes, depth uint64, mwm uint64, transfers bundle.Transfers, options *SendTransfersOptions) (bundle.Bundle, error)

SendTransfer calls PrepareTransfers and then sends off the bundle via SendTrytes.

func (*API) SendTrytes

func (api *API) SendTrytes(trytes []Trytes, depth uint64, mwm uint64, reference ...Hash) (bundle.Bundle, error)

SendTrytes performs Proof-of-Work, stores and then broadcasts the given transactions and returns them.

func (*API) StoreAndBroadcast

func (api *API) StoreAndBroadcast(trytes []Trytes) ([]Trytes, error)

StoreAndBroadcast first stores and the broadcasts the given transactions.

func (*API) StoreTransactions

func (api *API) StoreTransactions(trytes ...Trytes) ([]Trytes, error)

StoreTransactions persists a list of attached transaction trytes in the store of the connected node. Tip-selection and Proof-of-Work must be done first by calling GetTransactionsToApprove and AttachToTangle or an equivalent attach method.

Persist the transaction trytes in local storage before calling this command, to ensure reattachment is possible, until your bundle has been included.

Any transactions stored with this command will eventually be erased as a result of a snapshot.

func (*API) TraverseBundle

func (api *API) TraverseBundle(trunkTxHash Hash, bndl bundle.Bundle) (bundle.Bundle, error)

TraverseBundle fetches the bundle of a given tail transaction by traversing through the trunk transactions. It does not validate the bundle.

func (*API) WereAddressesSpentFrom

func (api *API) WereAddressesSpentFrom(addresses ...Hash) ([]bool, error)

WereAddressesSpentFrom checks whether the given addresses were already spent.

type AccountData

type AccountData struct {
	Addresses     Hashes
	Inputs        []Input
	Transfers     bundle.Bundles
	Transactions  Hashes
	LatestAddress Hash
	Balance       uint64
}

AccountData is an object containing an account's current state derived from the available data given by nodes during the current snapshot epoch. Deprecated: Use a solution which uses local persistence to keep the account data.

type AddNeighborsCommand

type AddNeighborsCommand struct {
	Command
	URIs []string `json:"uris"`
}

AddNeighborsCommand represents the payload to the AddNeighbor API call.

type AddNeighborsResponse

type AddNeighborsResponse struct {
	AddedNeighbors int64
	Duration       int64
}

AddNeighborsResponse is the response from the AddNeighbor API call.

type AttachToTangleCommand

type AttachToTangleCommand struct {
	Command
	TrunkTransaction   Hash     `json:"trunkTransaction"`
	BranchTransaction  Hash     `json:"branchTransaction"`
	MinWeightMagnitude uint64   `json:"minWeightMagnitude"`
	Trytes             []Trytes `json:"trytes"`
}

AttachToTangleCommand represents the payload to the AttachToTangle API call.

type AttachToTangleResponse

type AttachToTangleResponse struct {
	Trytes []Trytes `json:"trytes"`
}

AttachToTangleResponse is the response from the AttachToTangle API call.

type Balance

type Balance = uint64

Balance represents a non negative balance.

type Balances

type Balances struct {
	Balances       []uint64 `json:"balances"`
	Milestone      string   `json:"milestone"`
	MilestoneIndex int64    `json:"milestoneIndex"`
}

Balances represents the payload of the GetBalances API (with parsed balances instead of strings).

type BroadcastTransactionsCommand

type BroadcastTransactionsCommand struct {
	Command
	Trytes []Trytes `json:"trytes"`
}

BroadcastTransactionsCommand represents the payload to the BroadcastTransactions API call.

type CheckConsistencyCommand

type CheckConsistencyCommand struct {
	Command
	Tails Hashes `json:"tails"`
}

CheckConsistencyCommand represents the payload to the CheckConsistency API call.

type CheckConsistencyResponse

type CheckConsistencyResponse struct {
	State bool   `json:"state"`
	Info  string `json:"info"`
}

CheckConsistencyResponse is the response from the CheckConsistency API call.

type Command

type Command struct {
	Command IRICommand `json:"command"`
}

func (*Command) Cmd

func (c *Command) Cmd() IRICommand

type Commander

type Commander interface {
	Cmd() IRICommand
}

type CreateProviderFunc

type CreateProviderFunc func(settings interface{}) (Provider, error)

CreateProviderFunc is a function which creates a new Provider given some settings.

type ErrRequestError

type ErrRequestError struct {
	Code         int    `json:"code"`
	ErrorMessage string `json:"error"`
	Exception    string `json:"exception"`
}

ErrRequestError encapsulates errors given by the connected node or parse errors.

func (*ErrRequestError) Error

func (er *ErrRequestError) Error() string

type FindTransactionsCommand

type FindTransactionsCommand struct {
	FindTransactionsQuery
	Command
}

FindTransactionsCommand represents the payload to the FindTransactions API call.

type FindTransactionsQuery

type FindTransactionsQuery struct {
	Addresses Hashes   `json:"addresses,omitempty"`
	Approvees Hashes   `json:"approvees,omitempty"`
	Bundles   Hashes   `json:"bundles,omitempty"`
	Tags      []Trytes `json:"tags,omitempty"`
}

FindTransactionsQuery represents the payload to the FindTransactions API call. Using multiple fields will return the intersection of the found results.

type FindTransactionsResponse

type FindTransactionsResponse struct {
	Hashes Hashes `json:"hashes"`
}

FindTransactionsResponse is the response from the FindTransactions API call.

type GetAccountDataOptions

type GetAccountDataOptions struct {
	// The index from which to start creating addresses from.
	Start uint64
	// The index up to which to generate addresses to.
	End *uint64
	// The security level used for generating addresses.
	Security SecurityLevel
}

GetAccountDataOptions are options for when creating a new AccountData object via GetAccountData(). Deprecated: Use a solution which uses local persistence to keep the account data.

type GetBalancesCommand

type GetBalancesCommand struct {
	Command
	Addresses Hashes `json:"addresses"`
	Tips      []Hash `json:"tips,omitempty"`
}

GetBalancesCommand represents the payload to the GetBalances API call.

type GetBalancesResponse

type GetBalancesResponse struct {
	Balances       []string `json:"balances"`
	Duration       int64    `json:"duration"`
	Milestone      string   `json:"milestone"`
	MilestoneIndex int64    `json:"milestoneIndex"`
}

GetBalancesResponse is the response from the GetBalances API call.

type GetInclusionStatesCommand

type GetInclusionStatesCommand struct {
	Command
	Transactions Hashes `json:"transactions"`
}

GetInclusionStatesCommand represents the payload to the GetInclusionStates API call.

type GetInclusionStatesResponse

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

GetInclusionStatesResponse is the response from the GetInclusionStates API call.

type GetInputsOptions

type GetInputsOptions struct {
	// The index to start from.
	Start uint64
	// The index up to which to generate addresses to.
	End *uint64
	// A threshold which must be fulfilled by the gathered Inputs.
	// GetInputs() will return an error if this value can't be fulfilled.
	Threshold *uint64
	// The security level used for generating new addresses.
	Security SecurityLevel
}

GetInputsOptions are options for when gathering Inputs via GetInputs().

func (GetInputsOptions) ToGetNewAddressOptions

func (gio GetInputsOptions) ToGetNewAddressOptions() GetNewAddressOptions

ToGetNewAddressOptions converts GetInputsOptions to GetNewAddressOptions.

type GetLatestSolidSubtangleMilestoneCommand

type GetLatestSolidSubtangleMilestoneCommand struct {
	Command
}

GetLatestSolidSubtangleMilestoneCommand represents the payload to the GetNodeInfo API call.

type GetLatestSolidSubtangleMilestoneResponse

type GetLatestSolidSubtangleMilestoneResponse struct {
	LatestSolidSubtangleMilestone      Hash  `json:"latestSolidSubtangleMilestone"`
	LatestSolidSubtangleMilestoneIndex int64 `json:"latestSolidSubtangleMilestoneIndex"`
}

GetLatestSolidSubtangleMilestoneResponse is the response from the GetNodeInfo API call but reduced to just the latest subtangle milestone data.

type GetNeighborsCommand

type GetNeighborsCommand struct {
	Command
}

GetNeighborsCommand represents the payload to the GetNeighbors API call.

type GetNeighborsResponse

type GetNeighborsResponse struct {
	Neighbors Neighbors `json:"neighbors"`
}

GetNeighborsResponse is the response from the GetNeighbors API call.

type GetNewAddressOptions

type GetNewAddressOptions struct {
	// The index from which to start creating addresses from.
	Index uint64
	// The security level used for generating new addresses.
	Security SecurityLevel
	// The total amount of addresses to generate.
	Total *uint64
	// Whether to return all generated addresses and not just the new address.
	ReturnAll bool
}

GetNewAddressOptions are options for when generating new addresses via GetNewAddress().

type GetNodeInfoCommand

type GetNodeInfoCommand struct {
	Command
}

GetNodeInfoCommand represents the payload to the GetNodeInfo API call.

type GetNodeInfoResponse

type GetNodeInfoResponse struct {
	AppName                            string `json:"appName"`
	AppVersion                         string `json:"appVersion"`
	Duration                           int64  `json:"duration"`
	JREAvailableProcessors             int64  `json:"jreAvailableProcessors"`
	JREFreeMemory                      int64  `json:"jreFreeMemory"`
	JREMaxMemory                       int64  `json:"jreMaxMemory"`
	JRETotalMemory                     int64  `json:"jreTotalMemory"`
	LatestMilestone                    Hash   `json:"latestMilestone"`
	LatestMilestoneIndex               int64  `json:"latestMilestoneIndex"`
	LatestSolidSubtangleMilestone      Hash   `json:"latestSolidSubtangleMilestone"`
	LatestSolidSubtangleMilestoneIndex int64  `json:"latestSolidSubtangleMilestoneIndex"`
	Neighbors                          int64  `json:"neighbors"`
	PacketsQueueSize                   int64  `json:"packetsQueueSize"`
	Time                               int64  `json:"time"`
	Tips                               int64  `json:"tips"`
	TransactionsToRequest              int64  `json:"transactionsToRequest"`
}

GetNodeInfoResponse is the response from the GetNodeInfo API call.

type GetTransactionsToApproveCommand

type GetTransactionsToApproveCommand struct {
	Command
	Depth     uint64 `json:"depth"`
	Reference Hash   `json:"reference,omitempty"`
}

GetTransactionsToApproveCommand represents the payload to the GetTransactionsToApprove API call.

type GetTransactionsToApproveResponse

type GetTransactionsToApproveResponse struct {
	TransactionsToApprove
	Duration int64 `json:"duration"`
}

GetTransactionsToApproveResponse is the response from the GetTransactionsToApprove API call.

type GetTransfersOptions

type GetTransfersOptions struct {
	// The index from which to start creating addresses from.
	Start uint64
	// The index up to which to generate addresses to.
	End *uint64
	// Whether to set the Persistence property on retrieved transactions.
	InclusionStates bool
	// The security level used for generating new addresses.
	Security SecurityLevel
}

GetTransfersOptions are options for when gathering Bundles via GetTransfers().

func (GetTransfersOptions) ToGetNewAddressOptions

func (gto GetTransfersOptions) ToGetNewAddressOptions() GetNewAddressOptions

ToGetNewAddressOptions converts GetTransfersOptions to GetNewAddressOptions.

type GetTrytesCommand

type GetTrytesCommand struct {
	Command
	Hashes Hashes `json:"hashes"`
}

GetTrytesCommand represents the payload to the GetTrytes API call.

type GetTrytesResponse

type GetTrytesResponse struct {
	Trytes []Trytes `json:"trytes"`
}

GetTrytesResponse is the response from the GetTrytes API call.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient defines an object being able to do Http calls.

type HTTPClientSettings

type HTTPClientSettings struct {
	// The URI endpoint to connect to. Defaults to DefaultLocalIRIURI if empty.
	URI string
	// The underlying HTTPClient to use. Defaults to http.DefaultClient.
	Client HTTPClient
	// The Proof-of-Work implementation function. Defaults to use the AttachToTangle IRI API call.
	LocalProofOfWorkFunc pow.ProofOfWorkFunc
}

HTTPClientSettings defines a set of settings for when constructing a new Http Provider.

func (HTTPClientSettings) ProofOfWorkFunc

func (hcs HTTPClientSettings) ProofOfWorkFunc() pow.ProofOfWorkFunc

ProofOfWorkFunc returns the defined Proof-of-Work function.

type IRICommand

type IRICommand string

IRICommand defines a command name for IRI API calls.

const (
	GetNodeInfoCmd              IRICommand = "getNodeInfo"
	GetNeighborsCmd             IRICommand = "getNeighbors"
	AddNeighborsCmd             IRICommand = "addNeighbors"
	RemoveNeighborsCmd          IRICommand = "removeNeighbors"
	FindTransactionsCmd         IRICommand = "findTransactions"
	GetTrytesCmd                IRICommand = "getTrytes"
	GetInclusionStatesCmd       IRICommand = "getInclusionStates"
	GetBalancesCmd              IRICommand = "getBalances"
	GetTransactionsToApproveCmd IRICommand = "getTransactionsToApprove"
	AttachToTangleCmd           IRICommand = "attachToTangle"
	InterruptAttachToTangleCmd  IRICommand = "interruptAttachToTangle"
	BroadcastTransactionsCmd    IRICommand = "broadcastTransactions"
	StoreTransactionsCmd        IRICommand = "storeTransactions"
	CheckConsistencyCmd         IRICommand = "checkConsistency"
	WereAddressesSpentFromCmd   IRICommand = "wereAddressesSpentFrom"
)

API command names.

type Input

type Input struct {
	Balance
	Address  Hash
	KeyIndex uint64
	Security SecurityLevel
}

Input is an address from which to withdraw the total available balance to fulfill a transfer's overall output value.

type Inputs

type Inputs struct {
	Inputs       []Input
	TotalBalance uint64
}

Inputs is a set of Input(s) and the total balance from them.

type InterruptAttachToTangleCommand

type InterruptAttachToTangleCommand struct {
	Command
}

InterruptAttachToTangleCommand represents the payload to the InterruptAttachToTangle API call.

type Neighbor

type Neighbor struct {
	Address                     string
	NumberOfAllTransactions     int64
	NumberOfInvalidTransactions int64
	NumberOfNewTransactions     int64
}

Neighbor is a node which is connected to the current connected node and gossips transactions with it.

type Neighbors

type Neighbors = []Neighbor

Neighbors is a slice of Neighbor.

type PrepareTransfersOptions

type PrepareTransfersOptions struct {
	// Inputs to fulfill the transfer's output sum. If no Inputs are provided, they are collected after
	// a best effort method (not recommended). Provided inputs are not checked for spent state.
	Inputs []Input
	// The security level used when no Inputs and/or remainder address are supplied for computing
	// the corresponding addresses.
	Security SecurityLevel
	// The timestamp to use for each transaction in the resulting bundle.
	Timestamp *uint64
	// The address to send the remainder balance too. If no remainder address is supplied, then
	// the next available address is computed after a best effort method using the first Input's key index.
	RemainderAddress *Hash
}

PrepareTransfersOptions are options for when preparing transfers via PrepareTransfers().

type PromoteTransactionOptions

type PromoteTransactionOptions struct {
	// When given a Context, PromoteTransaction() will create new promotion transactions until
	// the Context is done.
	Ctx context.Context
	// Delay between promotions. Only used if a Context is given.
	Delay *time.Duration
}

PromoteTransactionOptions are options for when promoting a transaction via PromoteTransaction().

type Provider

type Provider interface {
	// Send sends the given command and injects the result into the given out parameter.
	Send(cmd interface{}, out interface{}) error
	// SetSettings sets the settings for the provider.
	SetSettings(settings interface{}) error
}

A Provider is able to send API commands.

func NewHTTPClient

func NewHTTPClient(settings interface{}) (Provider, error)

NewHTTPClient creates a new Http Provider.

func NewQuorumHTTPClient

func NewQuorumHTTPClient(settings interface{}) (Provider, error)

NewQuorumHTTPClient creates a new quorum based Http Provider.

type QuorumDefaults

type QuorumDefaults struct {
	WereAddressesSpentFrom *bool
	GetInclusionStates     *bool
	GetBalances            *uint64
}

QuorumDefaults defines optional default values when a quorum couldn't be reached.

type QuorumHTTPClient

type QuorumHTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

QuorumHTTPClient defines an object being able to do Http calls.

type QuorumHTTPClientSettings

type QuorumHTTPClientSettings struct {
	// The threshold/majority percentage which must be reached in the responses
	// to form a quorum. Define the threshold as 0<x<1, i.e. 0.8 => 80%.
	// A threshold of 1 would mean that all nodes must give the same response.
	Threshold float64

	// Defines the max percentage of nodes which can fail to give a response
	// when a quorum is built. For example, if 4 nodes are specified and
	// a NoResponseTolerance of 0.25/25% is set, then 1 node of those 4
	// is tolerated to fail to give a response and the quorum is built.
	NoResponseTolerance float64

	// For certain commands for which a quorum doesn't make sense
	// this node will be used. For example GetTransactionsToApprove
	// would always fail when queried via a quorum.
	// If no PrimaryNode is set, then a node is randomly selected from Nodes
	// for executing calls for which no quorum can be done.
	// The primary node is not used for forming the quorum and must be
	// explicitly set in the Nodes field a second time.
	PrimaryNode *string

	// The nodes to which the client connects to.
	Nodes []string

	// The underlying HTTPClient to use. Defaults to http.DefaultClient.
	Client HTTPClient

	// The Proof-of-Work implementation function. Defaults to use the AttachToTangle IRI API call.
	LocalProofOfWorkFunc pow.ProofOfWorkFunc

	// A list of commands which will be executed in quorum even though they are not
	// particularly made for such scenario. Good candidates are 'BroadcastTransactionsCmd'
	// or 'StoreTransactionsCmd'
	ForceQuorumSend map[IRICommand]struct{}

	// When querying for the latest solid subtangle milestone in quorum, MaxSubtangleMilestoneDelta
	// defines how far apart the highest and lowest latest solid subtangle milestone are allowed
	// to be a apart. A low MaxSubtangleMilestoneDelta ensures that the nodes have mostly the same ledger state.
	// A high MaxSubtangleMilestoneDelta allows for higher desynchronisation between the used nodes.
	// Recommended value is 1, meaning that the highest and lowest latest solid subtangle milestones
	// must only be apart max. 1 index.
	MaxSubtangleMilestoneDelta uint64

	// Default values which are returned when no quorum could be reached
	// for certain types of calls.
	Defaults *QuorumDefaults
}

QuorumHTTPClientSettings defines a set of settings for when constructing a new Http Provider.

func (QuorumHTTPClientSettings) ProofOfWorkFunc

func (hcs QuorumHTTPClientSettings) ProofOfWorkFunc() pow.ProofOfWorkFunc

ProofOfWorkFunc returns the defined Proof-of-Work function.

type QuorumLevel

type QuorumLevel float64

QuorumLevel defines the percentage needed for a quorum.

type RemoveNeighborsCommand

type RemoveNeighborsCommand struct {
	Command
	URIs []string `json:"uris"`
}

RemoveNeighborsCommand represents the payload to the RemoveNeighbors API call.

type RemoveNeighborsResponse

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

RemoveNeighborsResponse is the response from the RemoveNeighbors API call.

type SendTransfersOptions

type SendTransfersOptions struct {
	PrepareTransfersOptions
	// A hash of a transaction to use as reference in GetTransactionsToApprove().
	Reference *Hash
}

SendTransfersOptions are options for when sending bundle transaction trytes via SendTransfer().

type Settings

type Settings interface {
	ProofOfWorkFunc() pow.ProofOfWorkFunc
}

Settings can supply different options for Provider creation.

type StoreTransactionsCommand

type StoreTransactionsCommand struct {
	Command
	Trytes []Trytes `json:"trytes"`
}

StoreTransactionsCommand represents the payload to the StoreTransactions API call.

type TransactionsToApprove

type TransactionsToApprove struct {
	TrunkTransaction  Hash
	BranchTransaction Hash
}

TransactionsToApprove represents tips which can be approved by a new transaction.

type WereAddressesSpentFromCommand

type WereAddressesSpentFromCommand struct {
	Command
	Addresses Hashes `json:"addresses"`
}

WereAddressesSpentFromCommand represents the payload to the WereAddressesSpentFrom API call.

type WereAddressesSpentFromResponse

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

WereAddressesSpentFromResponse is the response from the WereAddressesSpentFrom API call.

Directories

Path Synopsis
integration

Jump to

Keyboard shortcuts

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