chainstate

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: MIT Imports: 13 Imported by: 3

Documentation

Overview

Package chainstate is the on-chain data service abstraction layer

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidRequirements = errors.New("requirements are invalid or missing")

ErrInvalidRequirements is when an invalid requirement was given

View Source
var ErrInvalidTransactionHex = errors.New("invalid transaction hex")

ErrInvalidTransactionHex is when the transaction hex is missing or invalid

View Source
var ErrInvalidTransactionID = errors.New("invalid transaction id")

ErrInvalidTransactionID is when the transaction id is missing or invalid

View Source
var ErrMissingBroadcastMiners = errors.New("missing: broadcasting miners")

ErrMissingBroadcastMiners is when broadcasting miners are missing

View Source
var ErrMissingQueryMiners = errors.New("missing: query miners")

ErrMissingQueryMiners is when query miners are missing

View Source
var ErrTransactionIDMismatch = errors.New("result tx id did not match provided tx id")

ErrTransactionIDMismatch is when the returned tx does not match the expected given tx id

View Source
var ErrTransactionNotFound = errors.New("transaction not found using all chain providers")

ErrTransactionNotFound is when a transaction was not found in any on-chain provider

Functions

This section is empty.

Types

type ChainService

type ChainService interface {
	Broadcast(ctx context.Context, id, txHex string, timeout time.Duration) error
	QueryTransaction(
		ctx context.Context, id string, requiredIn RequiredIn, timeout time.Duration,
	) (*TransactionInfo, error)
	QueryTransactionFastest(
		ctx context.Context, id string, requiredIn RequiredIn, timeout time.Duration,
	) (*TransactionInfo, error)
}

ChainService is the chain related methods

type Client

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

Client is the client (configuration)

func (*Client) Broadcast

func (c *Client) Broadcast(ctx context.Context, id, txHex string, timeout time.Duration) error

Broadcast will attempt to broadcast a transaction

func (*Client) BroadcastMiners

func (c *Client) BroadcastMiners() []*minercraft.Miner

BroadcastMiners will return the broadcast miners

func (*Client) Close

func (c *Client) Close(ctx context.Context)

Close will close the client and any open connections

func (*Client) Debug

func (c *Client) Debug(on bool)

Debug will set the debug flag

func (*Client) DebugLog

func (c *Client) DebugLog(text string)

DebugLog will display verbose logs

func (*Client) HTTPClient

func (c *Client) HTTPClient() HTTPInterface

HTTPClient will return the HTTP client

func (*Client) IsDebug

func (c *Client) IsDebug() bool

IsDebug will return if debugging is enabled

func (*Client) IsNewRelicEnabled

func (c *Client) IsNewRelicEnabled() bool

IsNewRelicEnabled will return if new relic is enabled

func (*Client) MatterCloud

func (c *Client) MatterCloud() mattercloud.ClientInterface

MatterCloud will return the MatterCloud client

func (*Client) Minercraft

func (c *Client) Minercraft() minercraft.ClientInterface

Minercraft will return the Minercraft client

func (*Client) Miners

func (c *Client) Miners() []*minercraft.Miner

Miners will return the miners (default or custom)

func (*Client) Network

func (c *Client) Network() Network

Network will return the current network

func (*Client) NowNodes

func (c *Client) NowNodes() nownodes.ClientInterface

NowNodes will return the NowNodes client

func (*Client) QueryMiners

func (c *Client) QueryMiners() []*minercraft.Miner

QueryMiners will return the query miners

func (*Client) QueryTimeout

func (c *Client) QueryTimeout() time.Duration

QueryTimeout will return the query timeout

func (*Client) QueryTransaction

func (c *Client) QueryTransaction(
	ctx context.Context, id string, requiredIn RequiredIn, timeout time.Duration,
) (*TransactionInfo, error)

QueryTransaction will get the transaction info from all providers returning the "first" valid result

Note: this is slow, but follows a specific order: mAPI -> WhatsOnChain -> MatterCloud -> NowNodes

func (*Client) QueryTransactionFastest

func (c *Client) QueryTransactionFastest(
	ctx context.Context, id string, requiredIn RequiredIn, timeout time.Duration,
) (*TransactionInfo, error)

QueryTransactionFastest will get the transaction info from ALL provider(s) returning the "fastest" valid result

Note: this is fast but could abuse each provider based on how excessive this method is used

func (*Client) WhatsOnChain

func (c *Client) WhatsOnChain() whatsonchain.ClientInterface

WhatsOnChain will return the WhatsOnChain client

type ClientInterface

type ClientInterface interface {
	ChainService
	ProviderServices
	BroadcastMiners() []*minercraft.Miner
	Close(ctx context.Context)
	Debug(on bool)
	DebugLog(text string)
	HTTPClient() HTTPInterface
	IsDebug() bool
	IsNewRelicEnabled() bool
	Miners() []*minercraft.Miner
	Network() Network
	QueryMiners() []*minercraft.Miner
	QueryTimeout() time.Duration
}

ClientInterface is the chainstate client interface

func NewClient

func NewClient(ctx context.Context, opts ...ClientOps) (ClientInterface, error)

NewClient creates a new client for all on-chain functionality

If no options are given, it will use the defaultClientOptions() ctx may contain a NewRelic txn (or one will be created)

type ClientOps

type ClientOps func(c *clientOptions)

ClientOps allow functional options to be supplied that overwrite default client options.

func WithBroadcastMiners

func WithBroadcastMiners(miners []*minercraft.Miner) ClientOps

WithBroadcastMiners will set a list of miners for broadcasting

func WithCustomMiners

func WithCustomMiners(miners []*minercraft.Miner) ClientOps

WithCustomMiners will overwrite the default list of miners in Minercraft

func WithDebugging

func WithDebugging() ClientOps

WithDebugging will enable debugging mode

func WithHTTPClient

func WithHTTPClient(client HTTPInterface) ClientOps

WithHTTPClient will set a custom HTTP client

func WithLogger

func WithLogger(customLogger Logger) ClientOps

WithLogger will set a custom logger

func WithMatterCloud

func WithMatterCloud(client mattercloud.ClientInterface) ClientOps

WithMatterCloud will set a custom MatterCloud client

func WithMatterCloudAPIKey

func WithMatterCloudAPIKey(apiKey string) ClientOps

WithMatterCloudAPIKey will set a custom MatterCloud API key

func WithMinercraft

func WithMinercraft(client minercraft.ClientInterface) ClientOps

WithMinercraft will set a custom Minercraft client

func WithNetwork

func WithNetwork(network Network) ClientOps

WithNetwork will set the network to use

func WithNewRelic

func WithNewRelic() ClientOps

WithNewRelic will enable the NewRelic wrapper

func WithNowNodes

func WithNowNodes(client nownodes.ClientInterface) ClientOps

WithNowNodes will set a custom NowNodes client

func WithNowNodesAPIKey

func WithNowNodesAPIKey(apiKey string) ClientOps

WithNowNodesAPIKey will set a custom NowNodes API key

func WithQueryMiners

func WithQueryMiners(miners []*minercraft.Miner) ClientOps

WithQueryMiners will set a list of miners for querying transactions

func WithQueryTimeout

func WithQueryTimeout(timeout time.Duration) ClientOps

WithQueryTimeout will set a different timeout for transaction querying

func WithWhatsOnChain

func WithWhatsOnChain(client whatsonchain.ClientInterface) ClientOps

WithWhatsOnChain will set a custom WhatsOnChain client

func WithWhatsOnChainAPIKey added in v0.1.1

func WithWhatsOnChainAPIKey(apiKey string) ClientOps

WithWhatsOnChainAPIKey will set a custom WhatsOnChain API key

type HTTPInterface

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

HTTPInterface is the HTTP client interface

type Logger

type Logger interface {
	Info(ctx context.Context, message string, params ...interface{})
}

Logger is the logger interface for debug messages

type Network

type Network string

Network is the supported Bitcoin networks

const (
	MainNet       Network = mainNet // Main public network
	StressTestNet Network = stn     // Stress Test Network (https://bitcoinscaling.io/)
	TestNet       Network = testNet // Test public network
)

Supported networks

func (Network) Alternate

func (n Network) Alternate() string

Alternate is the alternate string version

func (Network) MatterCloud

func (n Network) MatterCloud() mattercloud.NetworkType

MatterCloud will return the MatterCloud network type

func (Network) String

func (n Network) String() string

String is the string version of network

func (Network) WhatsOnChain

func (n Network) WhatsOnChain() whatsonchain.NetworkType

WhatsOnChain will return the WhatsOnChain network type

type ProviderServices

type ProviderServices interface {
	MatterCloud() mattercloud.ClientInterface
	Minercraft() minercraft.ClientInterface
	NowNodes() nownodes.ClientInterface
	WhatsOnChain() whatsonchain.ClientInterface
}

ProviderServices is the chainstate providers interface

type RequiredIn

type RequiredIn string

RequiredIn is the requirements for querying transaction information

const (
	// RequiredInMempool is the transaction in mempool? (minimum requirement for a valid response)
	RequiredInMempool RequiredIn = requiredInMempool

	// RequiredOnChain is the transaction in on-chain? (minimum requirement for a valid response)
	RequiredOnChain RequiredIn = requiredOnChain
)

type TransactionInfo

type TransactionInfo struct {
	BlockHash     string `json:"block_hash,omitempty"`    // mAPI, WOC
	BlockHeight   int64  `json:"block_height"`            // mAPI, WOC
	Confirmations int64  `json:"confirmations,omitempty"` // mAPI, WOC
	ID            string `json:"id"`                      // Transaction ID (Hex)
	MinerID       string `json:"miner_id,omitempty"`      // mAPI ONLY - miner_id found
	Provider      string `json:"provider,omitempty"`      // Provider is our internal source
}

TransactionInfo is the universal information about the transaction found from a chain provider

Jump to

Keyboard shortcuts

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