Added GetMinerData rpc call

This commit is contained in:
DataHoarder 2023-03-03 10:53:08 +01:00
parent b6ca970f30
commit 0adf4de11a
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
2 changed files with 31 additions and 42 deletions

View file

@ -16,6 +16,7 @@ const (
methodGetBlockHeaderByHash = "get_block_header_by_hash"
methodGetBlockHeaderByHeight = "get_block_header_by_height"
methodGetBlockTemplate = "get_block_template"
methodGetMinerData = "get_miner_data"
methodGetCoinbaseTxSum = "get_coinbase_tx_sum"
methodGetConnections = "get_connections"
methodGetFeeEstimate = "get_fee_estimate"
@ -33,7 +34,6 @@ const (
// GetAlternateChains displays alternative chains seen by the node.
//
// (restricted).
//
func (c *Client) GetAlternateChains(
ctx context.Context,
) (*GetAlternateChainsResult, error) {
@ -51,7 +51,6 @@ func (c *Client) GetAlternateChains(
// about the use of each RPC method and endpoint.
//
// (restricted).
//
func (c *Client) RPCAccessTracking(
ctx context.Context,
) (*RPCAccessTrackingResult, error) {
@ -66,7 +65,6 @@ func (c *Client) RPCAccessTracking(
}
// HardForkInfo looks up informaiton about the last hard fork.
//
func (c *Client) HardForkInfo(
ctx context.Context,
) (*HardForkInfoResult, error) {
@ -83,7 +81,6 @@ func (c *Client) HardForkInfo(
// GetBans retrieves the list of banned IPs.
//
// (restricted).
//
func (c *Client) GetBans(ctx context.Context) (*GetBansResult, error) {
resp := &GetBansResult{}
@ -108,7 +105,6 @@ type SetBansRequestParameters struct {
// SetBans bans a particular host.
//
// (restricted).
//
func (c *Client) SetBans(
ctx context.Context, params SetBansRequestParameters,
) (*SetBansResult, error) {
@ -125,7 +121,6 @@ func (c *Client) SetBans(
// GetVersion retrieves the version of monerod that the node uses.
//
// (restricted).
//
func (c *Client) GetVersion(ctx context.Context) (*GetVersionResult, error) {
resp := &GetVersionResult{}
@ -139,7 +134,6 @@ func (c *Client) GetVersion(ctx context.Context) (*GetVersionResult, error) {
// GenerateBlocksRequestParameters is the set of parameters to be passed to the
// GenerateBlocks RPC method.
//
type GenerateBlocksRequestParameters struct {
// AmountOfBlocks is the number of blocks to be generated.
//
@ -165,7 +159,6 @@ type GenerateBlocksRequestParameters struct {
// Difficulty is set permanently to 1 for regtest.
//
// (restricted).
//
func (c *Client) GenerateBlocks(
ctx context.Context, params GenerateBlocksRequestParameters,
) (*GenerateBlocksResult, error) {
@ -223,7 +216,6 @@ func (c *Client) RelayTx(
}
// GetBlockTemplate gets a block template on which mining a new block.
//
func (c *Client) GetBlockTemplate(
ctx context.Context, walletAddress string, reserveSize uint,
) (*GetBlockTemplateResult, error) {
@ -241,6 +233,17 @@ func (c *Client) GetBlockTemplate(
return resp, nil
}
func (c *Client) GetMinerData(ctx context.Context) (*GetMinerDataResult, error) {
resp := &GetMinerDataResult{}
err := c.JSONRPC(ctx, methodGetMinerData, nil, resp)
if err != nil {
return nil, fmt.Errorf("jsonrpc: %w", err)
}
return resp, nil
}
func (c *Client) GetConnections(
ctx context.Context,
) (*GetConnectionsResult, error) {
@ -256,7 +259,6 @@ func (c *Client) GetConnections(
// GetInfo retrieves general information about the state of the node and the
// network.
//
func (c *Client) GetInfo(ctx context.Context) (*GetInfoResult, error) {
resp := &GetInfoResult{}
@ -298,7 +300,6 @@ func (c *Client) GetCoinbaseTxSum(
}
// InnerJSON parses the content of the JSON embedded in `GetBlockResult`.
//
func (j *GetBlockResult) InnerJSON() (*GetBlockResultJSON, error) {
res := &GetBlockResultJSON{}
@ -329,7 +330,6 @@ func (c *Client) GetBlockHeadersRange(
// GetBlockHeaderByHeight retrieves block header information for either one or
// multiple blocks.
//
func (c *Client) GetBlockHeaderByHeight(
ctx context.Context, height uint64,
) (*GetBlockHeaderByHeightResult, error) {
@ -348,7 +348,6 @@ func (c *Client) GetBlockHeaderByHeight(
// GetBlockHeaderByHash retrieves block header information for either one or
// multiple blocks.
//
func (c *Client) GetBlockHeaderByHash(
ctx context.Context, hashes []string,
) (*GetBlockHeaderByHashResult, error) {
@ -367,7 +366,6 @@ func (c *Client) GetBlockHeaderByHash(
// GetBlockRequestParameters represents the set of possible parameters that can
// be used for submitting a call to the `get_block` jsonrpc method.
//
type GetBlockRequestParameters struct {
Height uint64 `json:"height,omitempty"`
Hash string `json:"hash,omitempty"`
@ -375,7 +373,6 @@ type GetBlockRequestParameters struct {
// GetBlock fetches full block information from a block at a particular hash OR
// height.
//
func (c *Client) GetBlock(
ctx context.Context, params GetBlockRequestParameters,
) (*GetBlockResult, error) {

View file

@ -2,7 +2,6 @@ package daemon
// RPCResultFooter contains the set of fields that every RPC result message
// will contain.
//
type RPCResultFooter struct {
// Status dictates whether the request worked or not. "OK" means good.
//
@ -27,7 +26,6 @@ type RPCResultFooter struct {
// GetAlternateChainsResult is the result of a call to the GetAlternateChains
// RPC method.
//
type GetAlternateChainsResult struct {
// Chains is the array of alternate chains seen by the node.
//
@ -76,7 +74,6 @@ type GetAlternateChainsResult struct {
// AccessTrackingResult is the result of a call to the RPCAccessTracking RPC
// method.
//
type RPCAccessTrackingResult struct {
Data []struct {
// Count is the number of times that the monero daemon received
@ -103,7 +100,6 @@ type RPCAccessTrackingResult struct {
}
// HardForkInfoResult is the result of a call to the HardForkInfo RPC method.
//
type HardForkInfoResult struct {
// EarliestHeight is the earliest height at which <version> is allowed.
//
@ -146,7 +142,6 @@ type HardForkInfoResult struct {
}
// GetVersionResult is the result of a call to the GetVersion RPC method.
//
type GetVersionResult struct {
Release bool `json:"release"`
Version uint64 `json:"version"`
@ -155,7 +150,6 @@ type GetVersionResult struct {
}
// GetBansResult is the result of a call to the GetBans RPC method.
//
type GetBansResult struct {
// Bans contains the list of nodes banned by this node.
//
@ -179,14 +173,12 @@ type GetBansResult struct {
}
// SetBansResult is the result of a call to the SetBans RPC method.
//
type SetBansResult struct {
RPCResultFooter `json:",inline"`
}
// GetFeeEstimateResult is the result of a call to the GetFeeEstimate RPC
// method.
//
type GetFeeEstimateResult struct {
// Fee is the per kB fee estimate.
//
@ -201,7 +193,6 @@ type GetFeeEstimateResult struct {
}
// GetInfoResult is the result of a call to the GetInfo RPC method.
//
type GetInfoResult struct {
AdjustedTime uint64 `json:"adjusted_time"`
AltBlocksCount int `json:"alt_blocks_count"`
@ -247,7 +238,6 @@ type GetInfoResult struct {
// GetBlockTemplateResult is the result of a call to the GetBlockTemplate RPC
// method.
//
type GetBlockTemplateResult struct {
// BlockhashingBlob is the blob on which to try to find a valid nonce.
//
@ -281,6 +271,25 @@ type GetBlockTemplateResult struct {
RPCResultFooter `json:",inline"`
}
// GetMinerDataResult is the result of a call to the GetMinerData RPC
// method.
type GetMinerDataResult struct {
MajorVersion uint8 `json:"major_version"`
Height uint64 `json:"height"`
PrevId string `json:"prev_id"`
SeedHash string `json:"seed_hash"`
Difficulty uint64 `json:"difficulty"`
MedianWeight uint64 `json:"median_weight"`
AlreadyGeneratedCoins uint64 `json:"already_generated_coins"`
MedianTimestamp uint64 `json:"median_timestamp"`
TxBacklog []struct {
Id string `json:"id"`
BlobSize uint64 `json:"blob_size"`
Weight uint64 `json:"weight"`
Fee uint64 `json:"fee"`
} `json:"tx_backlog"`
}
type Peer struct {
Host string `json:"host"`
ID uint64 `json:"id"`
@ -292,7 +301,6 @@ type Peer struct {
}
// GetPeerListResult is the result of a call to the GetPeerList RPC method.
//
type GetPeerListResult struct {
GrayList []Peer `json:"gray_list"`
WhiteList []Peer `json:"white_list"`
@ -302,7 +310,6 @@ type GetPeerListResult struct {
// GetConnectionsResult is the result of a call to the GetConnections RPC
// method.
//
type GetConnectionsResult struct {
Connections []struct {
Address string `json:"address"`
@ -344,7 +351,6 @@ type GetOutsResult struct {
}
// GetHeightResult is the result of a call to the GetHeight RPC method.
//
type GetHeightResult struct {
Hash string `json:"hash"`
Height uint64 `json:"height"`
@ -353,7 +359,6 @@ type GetHeightResult struct {
}
// GetNetStatsResult is the result of a call to the GetNetStats RPC method.
//
type GetNetStatsResult struct {
StartTime int64 `json:"start_time"`
TotalBytesIn uint64 `json:"total_bytes_in"`
@ -366,7 +371,6 @@ type GetNetStatsResult struct {
// GetPublicNodesResult is the result of a call to the GetPublicNodes RPC
// method.
//
type GetPublicNodesResult struct {
WhiteList []Peer `json:"white"`
GrayList []Peer `json:"gray"`
@ -376,7 +380,6 @@ type GetPublicNodesResult struct {
// GenerateBlocksResult is the result of a call to the GenerateBlocks RPC
// method.
//
type GenerateBlocksResult struct {
Blocks []string `json:"blocks"`
Height int `json:"height"`
@ -385,7 +388,6 @@ type GenerateBlocksResult struct {
}
// GetBlockCountResult is the result of a call to the GetBlockCount RPC method.
//
type GetBlockCountResult struct {
Count uint64 `json:"count"`
@ -393,14 +395,12 @@ type GetBlockCountResult struct {
}
// RelayTxResult is the result of a call to the RelayTx RPC method.
//
type RelayTxResult struct {
RPCResultFooter `json:",inline"`
}
// GetCoinbaseTxSumResult is the result of a call to the GetCoinbaseTxSum RPC
// method.
//
type GetCoinbaseTxSumResult struct {
EmissionAmount int64 `json:"emission_amount"`
EmissionAmountTop64 int `json:"emission_amount_top64"`
@ -520,7 +520,6 @@ type BlockHeader struct {
}
// GetBlockResult is the result of a call to the GetBlock RPC method.
//
type GetBlockResult struct {
// Blob is a hexadecimal representation of the block.
//
@ -543,7 +542,6 @@ type GetBlockResult struct {
}
// GetBlockResultJSON is the internal json-formatted block information.
//
type GetBlockResultJSON struct {
// MajorVersion (same as in the block header)
//
@ -624,7 +622,6 @@ func (c *GetBlockResultJSON) MinerOutputs() uint64 {
}
// SyncInfoResult is the result of a call to the SyncInfo RPC method.
//
type SyncInfoResult struct {
Credits uint64 `json:"credits"`
@ -670,7 +667,6 @@ type SyncInfoResult struct {
// GetLastBlockHeaderResult is the result of a call to the GetLastBlockHeader
// RPC method.
//
type GetLastBlockHeaderResult struct {
BlockHeader BlockHeader `json:"block_header"`
@ -679,7 +675,6 @@ type GetLastBlockHeaderResult struct {
// GetBlockHeadersRangeResult is the result of a call to the
// GetBlockHeadersRange RPC method.
//
type GetBlockHeadersRangeResult struct {
Headers []BlockHeader `json:"headers"`
@ -688,7 +683,6 @@ type GetBlockHeadersRangeResult struct {
// GetBlockHeaderByHeightResult is the result of a call to the
// GetBlockHeaderByHeight RPC method.
//
type GetBlockHeaderByHeightResult struct {
BlockHeader BlockHeader `json:"block_header"`
@ -697,7 +691,6 @@ type GetBlockHeaderByHeightResult struct {
// GetBlockHeaderByHashResult is the result of a call to the
// GetBlockHeaderByHash RPC method.
//
type GetBlockHeaderByHashResult struct {
BlockHeader BlockHeader `json:"block_header"`
BlockHeaders []BlockHeader `json:"block_headers"`
@ -727,7 +720,6 @@ type MiningStatusResult struct {
// GetTransactionPoolStatsResult is the result of a call to the
// GetTransactionPoolStats RPC method.
//
type GetTransactionPoolStatsResult struct {
PoolStats struct {
BytesMax uint64 `json:"bytes_max"`