miningcore

package module
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: MIT Imports: 10 Imported by: 0

README

go-miningcore-api

testing lint GoDoc Go Report Card

About

This is a go wrapper around the miningcore api. It implements the miningcore api v2, which also returns meta object, on all available endpoints.

Install

$ go get github.com/stratumfarm/go-miningcore-client

Usage

package main

import (
	"context"
	"fmt"

	"github.com/stratumfarm/go-miningcore-client"
)

func main() {
    c := miningcore.New(
        "https://localhost:8443",
        miningcore.WithTimeout(time.Second * 5),
        miningcore.WithoutTLSVerfiy(),
    )

    pools, statusCode, err := c.GetPools(context.Background())
    if err != nil {
        fmt.Println(statusCode, err)
    }

    for _, v := range pools {
        fmt.Println(v)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiCoinConfig

type ApiCoinConfig struct {
	Type          string `json:"type"`
	Name          string `json:"name"`
	Symbol        string `json:"symbol"`
	Website       string `json:"website"`
	Family        string `json:"family"`
	Algorithm     string `json:"algorithm"`
	Twitter       string `json:"twitter"`
	Discord       string `json:"discord"`
	Telegram      string `json:"telegram"`
	CanonicalName string `json:"canonicalName"`
}

type ApiPoolPaymentProcessingConfig

type ApiPoolPaymentProcessingConfig struct {
	Enabled        bool                   `json:"enabled"`
	MinimumPayment float64                `json:"minimumPayment"`
	PayoutScheme   string                 `json:"payoutScheme"`
	Extra          map[string]interface{} `json:"extra"`
}

type BalanceChange

type BalanceChange struct {
	PoolId  string  `json:"poolId"`
	Address string  `json:"address"`
	Amount  float64 `json:"amount"`
	Usage   string  `json:"usage"`
	Created string  `json:"created"`
}

type BalanceChangeRes added in v0.2.1

type BalanceChangeRes struct {
	*Meta
	Result []*BalanceChange `json:"result"`
}

type Block

type Block struct {
	PoolID                      string  `json:"poolId"`
	BlockHeight                 int64   `json:"blockHeight"`
	NetworkDifficulty           float64 `json:"networkDifficulty"`
	Status                      string  `json:"status"`
	Type                        string  `json:"type"`
	ConfirmationProgress        float64 `json:"confirmationProgress"`
	Effort                      float64 `json:"effort"`
	TransactionConfirmationData string  `json:"transactionConfirmationData"`
	Reward                      float64 `json:"reward"`
	InfoLink                    string  `json:"infoLink"`
	Hash                        string  `json:"hash"`
	Miner                       string  `json:"miner"`
	Source                      string  `json:"source"`
	Created                     string  `json:"created"`
}

type BlockFoundMessage

type BlockFoundMessage struct {
	BlockMessage
	Miner             string `json:"miner"`
	MinerExplorerLink string `json:"minerExplorerLink"`
	Source            string `json:"source"`
}

type BlockMessage

type BlockMessage struct {
	PoolID      string `json:"poolId"`
	BlockHeight uint64 `json:"blockHeight"`
	Symbol      string `json:"symbol"`
	Name        string `json:"name"`
}

type BlockUnlockProgressMessage

type BlockUnlockProgressMessage struct {
	BlockMessage
	Progress float64 `json:"progress"`
	Effort   float64 `json:"effort"`
}

type BlockUnlockedMessage

type BlockUnlockedMessage struct {
	BlockMessage
	BlockType         string  `json:"blockType"`
	BlockHash         string  `json:"blockHash"`
	Reward            float64 `json:"reward"`
	Effort            float64 `json:"effort"`
	Miner             string  `json:"miner"`
	ExplorerLink      string  `json:"explorerLink"`
	MinerExplorerLink string  `json:"minerExplorerLink"`
}

type BlockchainStats

type BlockchainStats struct {
	NetworkType          string  `json:"networkType"`
	NetworkHashrate      float64 `json:"networkHashrate"`
	NetworkDifficulty    float64 `json:"networkDifficulty"`
	NextNetworkTarget    string  `json:"nextNetworkTarget"`
	NextNetworkBits      string  `json:"nextNetworkBits"`
	LastNetworkBlockTime string  `json:"lastNetworkBlockTime"`
	BlockHeight          int64   `json:"blockHeight"`
	ConnectedPeers       int32   `json:"connectedPeers"`
	RewardType           string  `json:"rewardType"`
}

type BlocksRes added in v0.2.0

type BlocksRes struct {
	*Meta
	Result []*Block `json:"result"`
}

type ChainHeightMessage

type ChainHeightMessage struct {
	BlockMessage
}

type Client

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

Client represents a client for the miningcore API.

func New

func New(url string, opts ...ClientOpts) *Client

New creates a new client for the miningcore API.

func (*Client) GetMiner

func (c *Client) GetMiner(ctx context.Context, id, addr string, params ...map[string]string) (*MinerStats, int, error)

GetMiner returns information about a specific miner from a pool. This endpoints allows to specify the performance mode using the`perfMode` parameter. Possible values are:

"Hour"
"Day"
"Month"

func (*Client) GetMinerBalanceChanges

func (c *Client) GetMinerBalanceChanges(ctx context.Context, id, addr string, params ...map[string]string) (*BalanceChangeRes, int, error)

GetMinerBalanceChanges returns a list of balance changes of a miner. This endpoint implements pagination using the `page` and `perPage` parameters.

func (*Client) GetMinerDailyEarnings

func (c *Client) GetMinerDailyEarnings(ctx context.Context, id, addr string, params ...map[string]string) (*DailyEarningRes, int, error)

GetMinerDailyEarnings returns a list of daily earnings of a miner. This endpoint implements pagination using the `page` and `perPage` parameters.

func (*Client) GetMinerPayments

func (c *Client) GetMinerPayments(ctx context.Context, id, addr string, params ...map[string]string) (*PaymentRes, int, error)

GetMinerPayments returns a list of payments of a miner. This endpoint implements pagination using the `page` and `perPage` parameters.

func (*Client) GetMinerPerformance added in v0.3.1

func (c *Client) GetMinerPerformance(ctx context.Context, id, addr string, params ...map[string]string) ([]*WorkerStats, int, error)

GetMinerPerformance returns a list of performance samples of a miner. This endpoints allows to specify the sample range using the`sampleRange` parameter. Possible values are:

"Hour"
"Day"
"Month"

func (*Client) GetMinerSettings added in v0.2.0

func (c *Client) GetMinerSettings(ctx context.Context, id, addr string) (*MinerSettings, int, error)

GetMinerSettings returns the current miner settings of a pool.

func (*Client) GetMiners added in v0.2.0

func (c *Client) GetMiners(ctx context.Context, id string, params ...map[string]string) ([]*MinerPerformanceStats, int, error)

GetMiners returns a list of all miners from a pool. This endpoint implements pagination using the `page` and `perPage` parameters.

func (*Client) GetPerformance added in v0.2.0

func (c *Client) GetPerformance(ctx context.Context, id string, params ...map[string]string) ([]*PoolPerformance, int, error)

GetPerformance returns a list of performance stats of a pool. This endpoint allows to specify the sample range using the `r` parameter and the sample interval using the `i` parameter. Possible values for `r` are:

"Hour"
"Day"
"Month"

Possible values for `i` are:

"Hour"
"Day"

func (*Client) GetPool

func (c *Client) GetPool(ctx context.Context, id string) (*PoolInfo, int, error)

GetPool returns information about a specific pool.

func (*Client) GetPoolBlocks

func (c *Client) GetPoolBlocks(ctx context.Context, id string, params ...map[string]string) (*BlocksRes, int, error)

GetPoolBlocks returns a list of blocks found by a pool. This endpoint implements pagination using the `page` and `perPage` parameters.

func (*Client) GetPoolPayments

func (c *Client) GetPoolPayments(ctx context.Context, id string, params ...map[string]string) (*PaymentRes, int, error)

GetPoolPayments returns a list of payments made by a pool. This endpoint implements pagination using the `page` and `perPage` parameters.

func (*Client) GetPools

func (c *Client) GetPools(ctx context.Context) ([]*PoolInfo, int, error)

GetPools returns a list of all available pools.

func (*Client) PostMinerSettings added in v0.2.0

func (c *Client) PostMinerSettings(ctx context.Context, id, addr string, settings *MinerSettingsUpdateReq) (*MinerSettings, int, error)

PostMinerSettings updates the miner settings of a pool.

func (*Client) UnmarshalMiner added in v0.3.0

func (c *Client) UnmarshalMiner(ctx context.Context, id, addr string, res any, params ...map[string]string) (int, error)

func (*Client) UnmarshalMinerBalanceChanges added in v0.3.0

func (c *Client) UnmarshalMinerBalanceChanges(ctx context.Context, id, addr string, res any, params ...map[string]string) (int, error)

func (*Client) UnmarshalMinerDailyEarnings added in v0.3.0

func (c *Client) UnmarshalMinerDailyEarnings(ctx context.Context, id, addr string, res any, params ...map[string]string) (int, error)

func (*Client) UnmarshalMinerPayments added in v0.3.0

func (c *Client) UnmarshalMinerPayments(ctx context.Context, id, addr string, res any, params ...map[string]string) (int, error)

func (*Client) UnmarshalMinerPerformance added in v0.3.1

func (c *Client) UnmarshalMinerPerformance(ctx context.Context, id, addr string, res any, params ...map[string]string) (int, error)

func (*Client) UnmarshalMinerSettings added in v0.3.0

func (c *Client) UnmarshalMinerSettings(ctx context.Context, id, addr string, res any) (int, error)

func (*Client) UnmarshalMiners added in v0.3.0

func (c *Client) UnmarshalMiners(ctx context.Context, id string, res any, params ...map[string]string) (int, error)

func (*Client) UnmarshalPool added in v0.3.0

func (c *Client) UnmarshalPool(ctx context.Context, id string, res any) (int, error)

func (*Client) UnmarshalPoolBlocks added in v0.3.0

func (c *Client) UnmarshalPoolBlocks(ctx context.Context, id string, res any, params ...map[string]string) (int, error)

func (*Client) UnmarshalPoolPayments added in v0.3.0

func (c *Client) UnmarshalPoolPayments(ctx context.Context, id string, res any, params ...map[string]string) (int, error)

func (*Client) UnmarshalPoolPerformance added in v0.3.0

func (c *Client) UnmarshalPoolPerformance(ctx context.Context, id string, res any, params ...map[string]string) (int, error)

func (*Client) UnmarshalPools added in v0.3.0

func (c *Client) UnmarshalPools(ctx context.Context, res any) (int, error)

func (*Client) UnmarshalPostMinerSettings added in v0.3.2

func (c *Client) UnmarshalPostMinerSettings(ctx context.Context, id, addr string, settings any, res any) (int, error)

type ClientOpts

type ClientOpts func(*Client)

ClientOpts are options for the client.

func WithJSONDecoder added in v0.3.3

func WithJSONDecoder(decoder func(data []byte, v interface{}) error) ClientOpts

WithJSONDecoder sets the JSON decoder for the client.

func WithJSONEncoder added in v0.3.3

func WithJSONEncoder(encoder func(v interface{}) ([]byte, error)) ClientOpts

WithJSONEncoder sets the JSON encoder for the client.

func WithTimeout

func WithTimeout(t time.Duration) ClientOpts

WithTimout sets the default request timeout

func WithoutTLSVerfiy

func WithoutTLSVerfiy() ClientOpts

WithoutTLSVerify disables TLS verification.

type DailyEarning

type DailyEarning struct {
	Amount float64 `json:"amount"`
	Date   string  `json:"date"`
}

type DailyEarningRes added in v0.2.1

type DailyEarningRes struct {
	*Meta
	Result []*DailyEarning `json:"result"`
}

type HashRateUpdateMessage

type HashRateUpdateMessage struct {
	PoolID   string  `json:"poolId"`
	Hashrate float64 `json:"hashrate"`
	Miner    string  `json:"miner"`
	Worker   string  `json:"worker"`
}

type Meta added in v0.2.0

type Meta struct {
	PageCount           int64    `json:"pageCount"`
	Success             bool     `json:"success"`
	ResponseMessageType int64    `json:"responseMessageType,omitempty"`
	ResponseMessageId   string   `json:"responseMessageId,omitempty"`
	ResponseMessageArgs []string `json:"responseMessageArgs,omitempty"`
}

type MinerPerformanceStats

type MinerPerformanceStats struct {
	Miner           string  `json:"miner"`
	Hashrate        float64 `json:"hashrate"`
	SharesPerSecond float64 `json:"sharesPerSecond"`
}

type MinerSettings added in v0.2.0

type MinerSettings struct {
	PaymentThreshold float64 `json:"paymentThreshold"`
}

type MinerSettingsUpdateReq added in v0.2.0

type MinerSettingsUpdateReq struct {
	IPAddress string         `json:"ipAddress"`
	Settings  *MinerSettings `json:"settings"`
}

type MinerStats

type MinerStats struct {
	PendingShares      int64          `json:"pendingShares"`
	PendingBalance     float64        `json:"pendingBalance"`
	TotalPaid          float64        `json:"totalPaid"`
	TodayPaid          float64        `json:"todayPaid"`
	LastPayment        string         `json:"lastPayment"`
	LastPaymentLink    string         `json:"lastPaymentLink"`
	Performance        *WorkerStats   `json:"performance"`
	PerformanceSamples []*WorkerStats `json:"performanceSamples"`
}

type Payment

type Payment struct {
	Coin                        string  `json:"coin,omitempty"`
	Address                     string  `json:"address,omitempty"`
	AddressInfoLink             string  `json:"addressInfoLink,omitempty"`
	Amount                      float64 `json:"amount,omitempty"`
	TransactionConfirmationData string  `json:"transactionConfirmationData,omitempty"`
	TransactionInfoLink         string  `json:"transactionInfoLink,omitempty"`
	Created                     string  `json:"created,omitempty"`
}

type PaymentMessage

type PaymentMessage struct {
	PoolID          string   `json:"poolId"`
	Symbol          string   `json:"symbol"`
	TxFee           float64  `json:"txFee"`
	TxIDs           []string `json:"txIds"`
	TxExplorerLinks []string `json:"txExplorerLinks"`
	RecipientsCount int      `json:"recipientsCount"`
	Amount          float64  `json:"amount"`
	Error           error    `json:"error"`
}

type PaymentRes added in v0.2.1

type PaymentRes struct {
	*Meta
	Result []*Payment `json:"result"`
}

type PoolEndpoint

type PoolEndpoint struct {
	ListenAddress    string                  `json:"listenAddress"`
	Name             string                  `json:"name"`
	Difficulty       float64                 `json:"difficulty"`
	TCPProxyProtocol *TCPProxyProtocolConfig `json:"tcpProxyProtocol"`
	VarDiff          *VarDiffConfig          `json:"varDiff"`
	TLS              bool                    `json:"tls"`
	TLSAuto          bool                    `json:"tlsAuto"`
	TLSPfxFile       string                  `json:"tlsPfxFile"`
	TLSPfxPassword   string                  `json:"tlsPfxPassword"`
}

type PoolInfo

type PoolInfo struct {
	ID                      string                          `json:"id"`
	Coin                    *ApiCoinConfig                  `json:"coin"`
	Ports                   map[string]PoolEndpoint         `json:"ports"`
	PaymentProcessing       *ApiPoolPaymentProcessingConfig `json:"paymentProcessing"`
	ShareBasedBanning       *PoolShareBasedBanningConfig    `json:"shareBasedBanning"`
	ClientConnectionTimeout int32                           `json:"clientConnectionTimeout"`
	JobRebroadcastTimeout   int32                           `json:"jobRebroadcastTimeout"`
	BlockRefreshInterval    int32                           `json:"blockRefreshInterval"`
	PoolFeePercent          float64                         `json:"poolFeePercent"`
	Address                 string                          `json:"address"`
	AddressInfoLink         string                          `json:"addressInfoLink"`
	PoolStats               *PoolStats                      `json:"poolStats"`
	NetworkStats            *BlockchainStats                `json:"networkStats"`
	TopMiners               []*MinerPerformanceStats        `json:"topMiners"`
	TotalPaid               float64                         `json:"totalPaid"`
	TotalBlocks             int32                           `json:"totalBlocks"`
	LastPoolBlockTime       string                          `json:"lastPoolBlockTime"`
	APIEndpoint             string                          `json:"apiEndpoint"`
}

type PoolPerformance added in v0.2.0

type PoolPerformance struct {
	PoolHashrate         float64 `json:"poolHashrate"`
	ConnectedMiners      int32   `json:"connectedMiners"`
	ValidSharesPerSecond int32   `json:"validSharesPerSecond"`
	NetworkHashrate      float64 `json:"networkHashrate"`
	NetworkDifficulty    float64 `json:"networkDifficulty"`
	Created              string  `json:"created"`
}

type PoolShareBasedBanningConfig

type PoolShareBasedBanningConfig struct {
	Enabeld         bool    `json:"enabled"`
	CheckThresghold int32   `json:"checkThreshold"`
	InvalidPercent  float64 `json:"invalidPercent"`
	Time            int32   `json:"time"`
}

type PoolStats

type PoolStats struct {
	LastPoolBlockTime string `json:"lastPoolBlockTime"`
	ConnectedMiners   int32  `json:"connectedMiners"`
	PoolHashrate      int64  `json:"poolHashrate"`
	SharesPerSecond   int32  `json:"sharesPerSecond"`
}

type RawMessage

type RawMessage struct {
	Type string `json:"type"`
}

type TCPProxyProtocolConfig

type TCPProxyProtocolConfig struct {
	Enable         bool     `json:"enable"`
	Mandatory      bool     `json:"mandatory"`
	ProxyAddresses []string `json:"proxyAddresses"`
}

type VarDiffConfig

type VarDiffConfig struct {
	MinDiff         float64 `json:"minDiff"`
	MaxDiff         float64 `json:"maxDiff"`
	MaxDelta        float64 `json:"maxDelta"`
	TargetTime      float64 `json:"targetTime"`
	RetargetTime    float64 `json:"retargetTime"`
	VariancePercent float64 `json:"variancePercent"`
}

type WebsocketMsg

type WebsocketMsg string
const (
	WsBlockFound            WebsocketMsg = "blockfound"
	WsNewChainHeight        WebsocketMsg = "newchainheight"
	WsPayment               WebsocketMsg = "payment"
	WsBlockUnlockedProgress WebsocketMsg = "blockunlockedprogress"
	WsHashrateUpdated       WebsocketMsg = "hashrateupdated"
)

type WorkerPerformanceStats

type WorkerPerformanceStats struct {
	Hashrate         float64 `json:"hashrate"`
	ReportedHashrate float64 `json:"reportedHashrate"`
	SharesPerSecond  float64 `json:"sharesPerSecond"`
}

type WorkerStats

type WorkerStats struct {
	Created string                             `json:"created"`
	Workers map[string]*WorkerPerformanceStats `json:"workers"`
}

Jump to

Keyboard shortcuts

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