Documentation ¶
Index ¶
- Constants
- Variables
- type Fetcher
- func (f *Fetcher) AccountBalance(ctx context.Context, network *types.NetworkIdentifier, ...) (*types.BlockIdentifier, []*types.Amount, []*types.Coin, map[string]interface{}, ...)
- func (f *Fetcher) AccountBalanceRetry(ctx context.Context, network *types.NetworkIdentifier, ...) (*types.BlockIdentifier, []*types.Amount, []*types.Coin, map[string]interface{}, ...)
- func (f *Fetcher) Block(ctx context.Context, network *types.NetworkIdentifier, ...) (*types.Block, error)
- func (f *Fetcher) BlockRetry(ctx context.Context, network *types.NetworkIdentifier, ...) (*types.Block, error)
- func (f *Fetcher) ConstructionCombine(ctx context.Context, network *types.NetworkIdentifier, ...) (string, error)
- func (f *Fetcher) ConstructionDerive(ctx context.Context, network *types.NetworkIdentifier, ...) (string, map[string]interface{}, error)
- func (f *Fetcher) ConstructionHash(ctx context.Context, network *types.NetworkIdentifier, ...) (*types.TransactionIdentifier, error)
- func (f *Fetcher) ConstructionMetadata(ctx context.Context, network *types.NetworkIdentifier, ...) (map[string]interface{}, error)
- func (f *Fetcher) ConstructionParse(ctx context.Context, network *types.NetworkIdentifier, signed bool, ...) ([]*types.Operation, []string, map[string]interface{}, error)
- func (f *Fetcher) ConstructionPayloads(ctx context.Context, network *types.NetworkIdentifier, ...) (string, []*types.SigningPayload, error)
- func (f *Fetcher) ConstructionPreprocess(ctx context.Context, network *types.NetworkIdentifier, ...) (map[string]interface{}, error)
- func (f *Fetcher) ConstructionSubmit(ctx context.Context, network *types.NetworkIdentifier, ...) (*types.TransactionIdentifier, map[string]interface{}, error)
- func (f *Fetcher) InitializeAsserter(ctx context.Context) (*types.NetworkIdentifier, *types.NetworkStatusResponse, error)
- func (f *Fetcher) Mempool(ctx context.Context, network *types.NetworkIdentifier) ([]*types.TransactionIdentifier, error)
- func (f *Fetcher) MempoolTransaction(ctx context.Context, network *types.NetworkIdentifier, ...) (*types.Transaction, map[string]interface{}, error)
- func (f *Fetcher) NetworkList(ctx context.Context, metadata map[string]interface{}) (*types.NetworkListResponse, error)
- func (f *Fetcher) NetworkListRetry(ctx context.Context, metadata map[string]interface{}) (*types.NetworkListResponse, error)
- func (f *Fetcher) NetworkOptions(ctx context.Context, network *types.NetworkIdentifier, ...) (*types.NetworkOptionsResponse, error)
- func (f *Fetcher) NetworkOptionsRetry(ctx context.Context, network *types.NetworkIdentifier, ...) (*types.NetworkOptionsResponse, error)
- func (f *Fetcher) NetworkStatus(ctx context.Context, network *types.NetworkIdentifier, ...) (*types.NetworkStatusResponse, error)
- func (f *Fetcher) NetworkStatusRetry(ctx context.Context, network *types.NetworkIdentifier, ...) (*types.NetworkStatusResponse, error)
- func (f *Fetcher) UnsafeBlock(ctx context.Context, network *types.NetworkIdentifier, ...) (*types.Block, error)
- func (f *Fetcher) UnsafeTransactions(ctx context.Context, network *types.NetworkIdentifier, ...) ([]*types.Transaction, error)
- type Option
- func WithAsserter(asserter *asserter.Asserter) Option
- func WithClient(client *client.APIClient) Option
- func WithInsecureTLS() Option
- func WithMaxRetries(maxRetries uint64) Option
- func WithRetryElapsedTime(retryElapsedTime time.Duration) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTransactionConcurrency(concurrency uint64) Option
Constants ¶
const ( // DefaultElapsedTime is the default limit on time // spent retrying a fetch. DefaultElapsedTime = 1 * time.Minute // DefaultRetries is the default number of times to // attempt a retry on a failed request. DefaultRetries = 10 // DefaultHTTPTimeout is the default timeout for // HTTP requests. DefaultHTTPTimeout = 10 * time.Second // DefaultTransactionConcurrency is the default // number of transactions a Fetcher will try to // get concurrently when populating a block (if // transactions are not included in the original // block fetch). DefaultTransactionConcurrency = 8 // DefaultUserAgent is the default userAgent // to populate on requests to a Rosetta server. DefaultUserAgent = "rosetta-sdk-go" )
Variables ¶
var ( // ErrExhaustedRetries is returned when a fetch with retries // fails because it was attempted too many times. ErrExhaustedRetries = errors.New("retries exhausted") )
Functions ¶
This section is empty.
Types ¶
type Fetcher ¶
type Fetcher struct { // Asserter is a public variable because // it can be used to determine if a retrieved // types.Operation is successful and should // be applied. Asserter *asserter.Asserter // contains filtered or unexported fields }
Fetcher contains all logic to communicate with a Rosetta Server.
func (*Fetcher) AccountBalance ¶
func (f *Fetcher) AccountBalance( ctx context.Context, network *types.NetworkIdentifier, account *types.AccountIdentifier, block *types.PartialBlockIdentifier, ) (*types.BlockIdentifier, []*types.Amount, []*types.Coin, map[string]interface{}, error)
AccountBalance returns the validated response from the AccountBalance method. If a block is provided, a historical lookup is performed.
func (*Fetcher) AccountBalanceRetry ¶
func (f *Fetcher) AccountBalanceRetry( ctx context.Context, network *types.NetworkIdentifier, account *types.AccountIdentifier, block *types.PartialBlockIdentifier, ) (*types.BlockIdentifier, []*types.Amount, []*types.Coin, map[string]interface{}, error)
AccountBalanceRetry retrieves the validated AccountBalance with a specified number of retries and max elapsed time. If a block is provided, a historical lookup is performed.
func (*Fetcher) Block ¶
func (f *Fetcher) Block( ctx context.Context, network *types.NetworkIdentifier, blockIdentifier *types.PartialBlockIdentifier, ) (*types.Block, error)
Block returns the validated response from the block method. This function will automatically fetch any transactions that were not returned by the call to fetch the block.
func (*Fetcher) BlockRetry ¶
func (f *Fetcher) BlockRetry( ctx context.Context, network *types.NetworkIdentifier, blockIdentifier *types.PartialBlockIdentifier, ) (*types.Block, error)
BlockRetry retrieves a validated Block with a specified number of retries and max elapsed time.
func (*Fetcher) ConstructionCombine ¶ added in v0.3.0
func (f *Fetcher) ConstructionCombine( ctx context.Context, network *types.NetworkIdentifier, unsignedTransaction string, signatures []*types.Signature, ) (string, error)
ConstructionCombine creates a network-specific transaction from an unsigned transaction and an array of provided signatures.
The signed transaction returned from this method will be sent to the `/construction/submit` endpoint by the caller.
func (*Fetcher) ConstructionDerive ¶ added in v0.3.0
func (f *Fetcher) ConstructionDerive( ctx context.Context, network *types.NetworkIdentifier, publicKey *types.PublicKey, metadata map[string]interface{}, ) (string, map[string]interface{}, error)
ConstructionDerive returns the network-specific address associated with a public key.
Blockchains that require an on-chain action to create an account should not implement this method.
func (*Fetcher) ConstructionHash ¶ added in v0.3.0
func (f *Fetcher) ConstructionHash( ctx context.Context, network *types.NetworkIdentifier, signedTransaction string, ) (*types.TransactionIdentifier, error)
ConstructionHash returns the network-specific transaction hash for a signed transaction.
func (*Fetcher) ConstructionMetadata ¶
func (f *Fetcher) ConstructionMetadata( ctx context.Context, network *types.NetworkIdentifier, options map[string]interface{}, ) (map[string]interface{}, error)
ConstructionMetadata returns the validated response from the ConstructionMetadata method.
func (*Fetcher) ConstructionParse ¶ added in v0.3.0
func (f *Fetcher) ConstructionParse( ctx context.Context, network *types.NetworkIdentifier, signed bool, transaction string, ) ([]*types.Operation, []string, map[string]interface{}, error)
ConstructionParse is called on both unsigned and signed transactions to understand the intent of the formulated transaction.
This is run as a sanity check before signing (after `/construction/payloads`) and before broadcast (after `/construction/combine`).
func (*Fetcher) ConstructionPayloads ¶ added in v0.3.0
func (f *Fetcher) ConstructionPayloads( ctx context.Context, network *types.NetworkIdentifier, operations []*types.Operation, metadata map[string]interface{}, ) (string, []*types.SigningPayload, error)
ConstructionPayloads is called with an array of operations and the response from `/construction/metadata`. It returns an unsigned transaction blob and a collection of payloads that must be signed by particular addresses using a certain SignatureType.
The array of operations provided in transaction construction often times can not specify all "effects" of a transaction (consider invoked transactions in Ethereum). However, they can deterministically specify the "intent" of the transaction, which is sufficient for construction. For this reason, parsing the corresponding transaction in the Data API (when it lands on chain) will contain a superset of whatever operations were provided during construction.
func (*Fetcher) ConstructionPreprocess ¶ added in v0.3.0
func (f *Fetcher) ConstructionPreprocess( ctx context.Context, network *types.NetworkIdentifier, operations []*types.Operation, metadata map[string]interface{}, ) (map[string]interface{}, error)
ConstructionPreprocess is called prior to `/construction/payloads` to construct a request for any metadata that is needed for transaction construction given (i.e. account nonce).
The request returned from this method will be used by the caller (in a different execution environment) to call the `/construction/metadata` endpoint.
func (*Fetcher) ConstructionSubmit ¶
func (f *Fetcher) ConstructionSubmit( ctx context.Context, network *types.NetworkIdentifier, signedTransaction string, ) (*types.TransactionIdentifier, map[string]interface{}, error)
ConstructionSubmit returns the validated response from the ConstructionSubmit method.
func (*Fetcher) InitializeAsserter ¶
func (f *Fetcher) InitializeAsserter( ctx context.Context, ) ( *types.NetworkIdentifier, *types.NetworkStatusResponse, error, )
InitializeAsserter creates an Asserter for validating responses. The Asserter is created by fetching the NetworkStatus and NetworkOptions from a Rosetta server.
If there is more than one network supported by the Rosetta server, the first network returned by NetworkList is used as the default network.
This method should be called before making any validated client requests.
func (*Fetcher) Mempool ¶
func (f *Fetcher) Mempool( ctx context.Context, network *types.NetworkIdentifier, ) ([]*types.TransactionIdentifier, error)
Mempool returns the validated response from the Mempool method.
func (*Fetcher) MempoolTransaction ¶
func (f *Fetcher) MempoolTransaction( ctx context.Context, network *types.NetworkIdentifier, transaction *types.TransactionIdentifier, ) (*types.Transaction, map[string]interface{}, error)
MempoolTransaction returns the validated response from the MempoolTransaction method.
func (*Fetcher) NetworkList ¶ added in v0.1.2
func (f *Fetcher) NetworkList( ctx context.Context, metadata map[string]interface{}, ) (*types.NetworkListResponse, error)
NetworkList returns the validated response from the NetworList method.
func (*Fetcher) NetworkListRetry ¶ added in v0.1.2
func (f *Fetcher) NetworkListRetry( ctx context.Context, metadata map[string]interface{}, ) (*types.NetworkListResponse, error)
NetworkListRetry retrieves the validated NetworkList with a specified number of retries and max elapsed time.
func (*Fetcher) NetworkOptions ¶ added in v0.1.2
func (f *Fetcher) NetworkOptions( ctx context.Context, network *types.NetworkIdentifier, metadata map[string]interface{}, ) (*types.NetworkOptionsResponse, error)
NetworkOptions returns the validated response from the NetworList method.
func (*Fetcher) NetworkOptionsRetry ¶ added in v0.1.2
func (f *Fetcher) NetworkOptionsRetry( ctx context.Context, network *types.NetworkIdentifier, metadata map[string]interface{}, ) (*types.NetworkOptionsResponse, error)
NetworkOptionsRetry retrieves the validated NetworkOptions with a specified number of retries and max elapsed time.
func (*Fetcher) NetworkStatus ¶
func (f *Fetcher) NetworkStatus( ctx context.Context, network *types.NetworkIdentifier, metadata map[string]interface{}, ) (*types.NetworkStatusResponse, error)
NetworkStatus returns the validated response from the NetworkStatus method.
func (*Fetcher) NetworkStatusRetry ¶
func (f *Fetcher) NetworkStatusRetry( ctx context.Context, network *types.NetworkIdentifier, metadata map[string]interface{}, ) (*types.NetworkStatusResponse, error)
NetworkStatusRetry retrieves the validated NetworkStatus with a specified number of retries and max elapsed time.
func (*Fetcher) UnsafeBlock ¶
func (f *Fetcher) UnsafeBlock( ctx context.Context, network *types.NetworkIdentifier, blockIdentifier *types.PartialBlockIdentifier, ) (*types.Block, error)
UnsafeBlock returns the unvalidated response from the Block method. This function will automatically fetch any transactions that were not returned by the call to fetch the block.
func (*Fetcher) UnsafeTransactions ¶
func (f *Fetcher) UnsafeTransactions( ctx context.Context, network *types.NetworkIdentifier, block *types.BlockIdentifier, transactionIdentifiers []*types.TransactionIdentifier, ) ([]*types.Transaction, error)
UnsafeTransactions returns the unvalidated response from the BlockTransaction method. UnsafeTransactions fetches all provided types.TransactionIdentifiers concurrently (with the number of threads specified by txConcurrency). If any fetch fails, this function will return an error.
type Option ¶ added in v0.1.2
type Option func(f *Fetcher)
Option is used to overwrite default values in Fetcher construction. Any Option not provided falls back to the default value.
func WithAsserter ¶ added in v0.1.2
WithAsserter sets the asserter.Asserter on construction so it does not need to be initialized.
func WithClient ¶ added in v0.1.2
WithClient overrides the default client.APIClient.
func WithInsecureTLS ¶ added in v0.3.0
func WithInsecureTLS() Option
WithInsecureTLS overrides the default TLS security settings to allow insecure certificates on an HTTPS connection.
This should ONLY be used when debugging a Rosetta API implementation. Using this option can lead to a man-in-the-middle attack!!
func WithMaxRetries ¶ added in v0.1.2
WithMaxRetries overrides the default number of retries on a request.
func WithRetryElapsedTime ¶ added in v0.1.2
WithRetryElapsedTime overrides the default max elapsed time to retry a request.
func WithTimeout ¶ added in v0.3.3
WithTimeout overrides the default HTTP timeout.
func WithTransactionConcurrency ¶ added in v0.1.2
WithTransactionConcurrency overrides the default transaction concurrency.