Co-Authored-By: Charon <charon@lethean.io> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
// Copyright (c) 2017-2026 Lethean (https://lt.hn)
|
|
//
|
|
// Licensed under the European Union Public Licence (EUPL) version 1.2.
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
package rpc
|
|
|
|
import "fmt"
|
|
|
|
// GetInfo returns the daemon status.
|
|
// Uses flags=0 for the cheapest query (no expensive calculations).
|
|
func (c *Client) GetInfo() (*DaemonInfo, error) {
|
|
params := struct {
|
|
Flags uint64 `json:"flags"`
|
|
}{Flags: 0}
|
|
var resp struct {
|
|
DaemonInfo
|
|
Status string `json:"status"`
|
|
}
|
|
if err := c.call("getinfo", params, &resp); err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.Status != "OK" {
|
|
return nil, fmt.Errorf("getinfo: status %q", resp.Status)
|
|
}
|
|
return &resp.DaemonInfo, nil
|
|
}
|
|
|
|
// GetHeight returns the current blockchain height.
|
|
// Uses the legacy /getheight endpoint (not available via /json_rpc).
|
|
func (c *Client) GetHeight() (uint64, error) {
|
|
var resp struct {
|
|
Height uint64 `json:"height"`
|
|
Status string `json:"status"`
|
|
}
|
|
if err := c.legacyCall("/getheight", struct{}{}, &resp); err != nil {
|
|
return 0, err
|
|
}
|
|
if resp.Status != "OK" {
|
|
return 0, fmt.Errorf("getheight: status %q", resp.Status)
|
|
}
|
|
return resp.Height, nil
|
|
}
|
|
|
|
// GetBlockCount returns the total number of blocks (height of top block + 1).
|
|
func (c *Client) GetBlockCount() (uint64, error) {
|
|
var resp struct {
|
|
Count uint64 `json:"count"`
|
|
Status string `json:"status"`
|
|
}
|
|
if err := c.call("getblockcount", struct{}{}, &resp); err != nil {
|
|
return 0, err
|
|
}
|
|
if resp.Status != "OK" {
|
|
return 0, fmt.Errorf("getblockcount: status %q", resp.Status)
|
|
}
|
|
return resp.Count, nil
|
|
}
|