miner

package
v0.0.0-...-ab07e92 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNewKey

func CreateNewKey(filePath, password string) (accounts.Account, error)

CreateNewKey generates a new key and stores it in a keystore file, returning the account.

func ExportPrivateKey

func ExportPrivateKey(ks *keystore.KeyStore, account accounts.Account, password string) (string, error)

ExportPrivateKey exports the private key for a given account from the keystore

func GetPublicIP

func GetPublicIP() (string, error)

func GetSystemServiceTypes

func GetSystemServiceTypes(endpoint string) ([]uint64, error)

GetSystemServiceTypes - Simulates retrieving service types.

func IsMinerRegistered

func IsMinerRegistered(endpoint string, minerAddress string) (bool, error)

IsMinerRegistered checks if a miner is registered in the network

func LoadKey

func LoadKey(filePath, password string) (accounts.Account, error)

LoadKey loads a key from a keystore file using the provided password and returns the account.

func PromptPassword

func PromptPassword(confirm bool) (string, error)

PromptPassword requests a password from the user and optionally confirms it.

func QueryRPC

func QueryRPC(endpoint string, queryContent string) (string, error)

QueryRPC makes an RPC query to the given endpoint with the provided query content

func QueryRPCStatus

func QueryRPCStatus(rpcEndpoint string) error

QueryRPCStatus sends a GET request to the RPC endpoint and checks the response

Types

type Miner

type Miner struct {
	RPCStatus   int // 0 for stale, 1 for active
	RPCEndpoint string
	Wallet      struct {
		Keystore *keystore.KeyStore
		Password string
	}
	KeyFilePath  string
	IP           string   `json:"ip"`
	Status       uint8    `json:"status"`
	MinerName    string   `json:"miner_name"`
	ServiceTypes []uint64 `json:"service_types"`
	ServicePort  uint64   `json:"service_port"`
}

func NewMiner

func NewMiner(rpcEndpoint, keyFilePath string) *Miner

NewMiner initializes a new Miner with the given RPC endpoint and keystore path

func (*Miner) Initialize

func (m *Miner) Initialize() error

Initialize checks or creates a key, sets up the wallet, and updates the RPC status

func (*Miner) RegisterMiner

func (m *Miner) RegisterMiner() error

func (*Miner) ToAddress

func (m *Miner) ToAddress() (common.Address, error)

ToAddress returns the Ethereum address associated with the miner's primary account. It creates a new account if none exist in the keystore.

func (*Miner) ToAddressHex

func (m *Miner) ToAddressHex() (string, error)

ToAddressHex returns the Ethereum address in hexadecimal string format

func (*Miner) UpdateRPCStatus

func (m *Miner) UpdateRPCStatus() error

UpdateRPCStatus checks the RPC status and updates the Miner struct

type MinerRegistrationRequest

type MinerRegistrationRequest struct {
	MinerName    string   `json:"miner_name"`    // The name of the miner
	ServiceTypes []uint64 `json:"service_types"` // An array of service type identifiers
	ServicePort  uint64   `json:"service_port"`  // The network port the miner uses
	IP           string   `json:"ip"`            // The IP address of the miner
	Status       uint8    `json:"status"`        // The operational status of the miner
}

MinerRegistrationRequest represents the data required to register a miner.

type MinerResponse

type MinerResponse struct {
	Jsonrpc string `json:"jsonrpc"`
	ID      int    `json:"id"`
	Result  struct {
		Response struct {
			Code      int         `json:"code"`
			Log       string      `json:"log"`
			Key       string      `json:"key"`
			Value     string      `json:"value"`
			Height    string      `json:"height"`
			ProofOps  interface{} `json:"proofOps"`
			Codespace string      `json:"codespace"`
		} `json:"response"`
	} `json:"result"`
}

MinerResponse defines the JSON response structure for miner registration checks

type RPCResponse

type RPCResponse struct {
	Jsonrpc string `json:"jsonrpc"`
	ID      int    `json:"id"`
	Result  struct {
		NodeInfo struct {
			ProtocolVersion struct {
				P2P   string `json:"p2p"`
				Block string `json:"block"`
				App   string `json:"app"`
			} `json:"protocol_version"`

			ID         string `json:"id"`
			ListenAddr string `json:"listen_addr"`
			Network    string `json:"network"`
			Version    string `json:"version"`
			Channels   string `json:"channels"`
			Moniker    string `json:"moniker"`
			Other      struct {
				TxIndex    string `json:"tx_index"`
				RPCAddress string `json:"rpc_address"`
			} `json:"other"`
		} `json:"node_info"`
		SyncInfo struct {
			LatestBlockHash     string `json:"latest_block_hash"`
			LatestAppHash       string `json:"latest_app_hash"`
			LatestBlockHeight   string `json:"latest_block_height"`
			LatestBlockTime     string `json:"latest_block_time"`
			EarliestBlockHash   string `json:"earliest_block_hash"`
			EarliestAppHash     string `json:"earliest_app_hash"`
			EarliestBlockHeight string `json:"earliest_block_height"`
			EarliestBlockTime   string `json:"earliest_block_time"`
			CatchingUp          bool   `json:"catching_up"`
		} `json:"sync_info"`
		ValidatorInfo struct {
			Address string `json:"address"`
			PubKey  struct {
				Type  string `json:"type"`
				Value string `json:"value"`
			} `json:"pub_key"`
			VotingPower string `json:"voting_power"`
		} `json:"validator_info"`
	} `json:"result"`
}

RPCResponse defines the expected JSON response structure

Jump to

Keyboard shortcuts

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