Documentation
¶
Overview ¶
Package chainstate is the on-chain data service abstraction layer
Index ¶
- Variables
- type ChainService
- type Client
- func (c *Client) Broadcast(ctx context.Context, id, txHex string, timeout time.Duration) error
- func (c *Client) BroadcastMiners() []*minercraft.Miner
- func (c *Client) Close(ctx context.Context)
- func (c *Client) Debug(on bool)
- func (c *Client) DebugLog(text string)
- func (c *Client) HTTPClient() HTTPInterface
- func (c *Client) IsDebug() bool
- func (c *Client) IsNewRelicEnabled() bool
- func (c *Client) MatterCloud() mattercloud.ClientInterface
- func (c *Client) Minercraft() minercraft.ClientInterface
- func (c *Client) Miners() []*minercraft.Miner
- func (c *Client) Network() Network
- func (c *Client) NowNodes() nownodes.ClientInterface
- func (c *Client) QueryMiners() []*minercraft.Miner
- func (c *Client) QueryTimeout() time.Duration
- func (c *Client) QueryTransaction(ctx context.Context, id string, requiredIn RequiredIn, timeout time.Duration) (*TransactionInfo, error)
- func (c *Client) QueryTransactionFastest(ctx context.Context, id string, requiredIn RequiredIn, timeout time.Duration) (*TransactionInfo, error)
- func (c *Client) WhatsOnChain() whatsonchain.ClientInterface
- type ClientInterface
- type ClientOps
- func WithBroadcastMiners(miners []*minercraft.Miner) ClientOps
- func WithCustomMiners(miners []*minercraft.Miner) ClientOps
- func WithDebugging() ClientOps
- func WithHTTPClient(client HTTPInterface) ClientOps
- func WithLogger(customLogger Logger) ClientOps
- func WithMatterCloud(client mattercloud.ClientInterface) ClientOps
- func WithMatterCloudAPIKey(apiKey string) ClientOps
- func WithMinercraft(client minercraft.ClientInterface) ClientOps
- func WithNetwork(network Network) ClientOps
- func WithNewRelic() ClientOps
- func WithNowNodes(client nownodes.ClientInterface) ClientOps
- func WithNowNodesAPIKey(apiKey string) ClientOps
- func WithQueryMiners(miners []*minercraft.Miner) ClientOps
- func WithQueryTimeout(timeout time.Duration) ClientOps
- func WithWhatsOnChain(client whatsonchain.ClientInterface) ClientOps
- type HTTPInterface
- type Logger
- type Network
- type ProviderServices
- type RequiredIn
- type TransactionInfo
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidRequirements = errors.New("requirements are invalid or missing")
ErrInvalidRequirements is when an invalid requirement was given
var ErrInvalidTransactionHex = errors.New("invalid transaction hex")
ErrInvalidTransactionHex is when the transaction hex is missing or invalid
var ErrInvalidTransactionID = errors.New("invalid transaction id")
ErrInvalidTransactionID is when the transaction id is missing or invalid
var ErrMissingBroadcastMiners = errors.New("missing: broadcasting miners")
ErrMissingBroadcastMiners is when broadcasting miners are missing
var ErrMissingQueryMiners = errors.New("missing: query miners")
ErrMissingQueryMiners is when query miners are missing
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
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) BroadcastMiners ¶
func (c *Client) BroadcastMiners() []*minercraft.Miner
BroadcastMiners will return the broadcast miners
func (*Client) HTTPClient ¶
func (c *Client) HTTPClient() HTTPInterface
HTTPClient will return the HTTP client
func (*Client) IsNewRelicEnabled ¶
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) 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 ¶
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
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 WithHTTPClient ¶
func WithHTTPClient(client HTTPInterface) ClientOps
WithHTTPClient will set a custom HTTP client
func WithLogger ¶
WithLogger will set a custom logger
func WithMatterCloud ¶
func WithMatterCloud(client mattercloud.ClientInterface) ClientOps
WithMatterCloud will set a custom MatterCloud client
func WithMatterCloudAPIKey ¶
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 ¶
WithNetwork will set the network to use
func WithNowNodes ¶
func WithNowNodes(client nownodes.ClientInterface) ClientOps
WithNowNodes will set a custom NowNodes client
func WithNowNodesAPIKey ¶
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 ¶
WithQueryTimeout will set a different timeout for transaction querying
func WithWhatsOnChain ¶
func WithWhatsOnChain(client whatsonchain.ClientInterface) ClientOps
WithWhatsOnChain will set a custom WhatsOnChain client
type HTTPInterface ¶
HTTPInterface is the HTTP client interface
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) MatterCloud ¶
func (n Network) MatterCloud() mattercloud.NetworkType
MatterCloud will return the MatterCloud network type
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