github.com/mavryk-network/mvgo@v1.19.9/rpc/chain.go (about)

     1  // Copyright (c) 2022 Blockwatch Data Inc.
     2  // Author: alex@blockwatch.cc
     3  
     4  package rpc
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/mavryk-network/mvgo/mavryk"
    10  )
    11  
    12  // GetChainId returns the chain id (i.e. network id).
    13  // https://protocol.mavryk.org/shell/rpc.html#get-chains-chain-id-chain-id
    14  func (c *Client) GetChainId(ctx context.Context) (mavryk.ChainIdHash, error) {
    15  	var id mavryk.ChainIdHash
    16  	err := c.Get(ctx, "chains/main/chain_id", &id)
    17  	return id, err
    18  }
    19  
    20  type Status struct {
    21  	Bootstrapped bool   `json:"bootstrapped"`
    22  	SyncState    string `json:"sync_state"`
    23  }
    24  
    25  // GetStatus returns whether the node is bootstrapped (i.e. has downloaded
    26  // the full chain) and in sync.
    27  // https://protocol.mavryk.org/shell/rpc.html#get-chains-chain-id-is-bootstrapped
    28  func (c *Client) GetStatus(ctx context.Context) (Status, error) {
    29  	var s Status
    30  	err := c.Get(ctx, "chains/main/is_bootstrapped", &s)
    31  	return s, err
    32  }
    33  
    34  type NodeVersion struct {
    35  	Major int `json:"major"`
    36  	Minor int `json:"minor"`
    37  	// AdditionalInfo string `json:"additional_info"` // v015
    38  	// AdditionalInfo map[string]any `json:"additional_info"` // v016+
    39  }
    40  
    41  type NetworkVersion struct {
    42  	ChainName            string `json:"chain_name"`
    43  	DistributedDbVersion int    `json:"distributed_db_version"`
    44  	P2pVersion           int    `json:"p2p_version"`
    45  }
    46  
    47  type CommitInfo struct {
    48  	CommitHash string `json:"commit_hash"`
    49  	CommitDate string `json:"commit_date"`
    50  }
    51  
    52  type VersionInfo struct {
    53  	NodeVersion    NodeVersion    `json:"version"`
    54  	NetworkVersion NetworkVersion `json:"network_version"`
    55  	CommitInfo     CommitInfo     `json:"commit_info"`
    56  }
    57  
    58  // GetVersion returns node's version info.
    59  // https://protocol.mavryk.org/shell/rpc.html#get-version
    60  func (c *Client) GetVersionInfo(ctx context.Context) (VersionInfo, error) {
    61  	var v VersionInfo
    62  	err := c.Get(ctx, "version", &v)
    63  	return v, err
    64  }