diff --git a/pkg/node/lethean.go b/pkg/node/lethean.go index 39bbfc7..4a80fbf 100644 --- a/pkg/node/lethean.go +++ b/pkg/node/lethean.go @@ -19,9 +19,8 @@ const ( LetheanMainnetPool = "stratum+tcp://pool.lthn.io:3333" ) -// ChainInfo holds basic chain state from the daemon RPC. -// -// info, err := node.GetChainInfo("http://127.0.0.1:46941") +// info, err := node.GetChainInfo("http://127.0.0.1:46941") +// if info.Synced { log("height:", info.Height) } type ChainInfo struct { Height uint64 `json:"height"` Aliases int `json:"alias_count"` @@ -30,9 +29,8 @@ type ChainInfo struct { Difficulty uint64 `json:"difficulty"` } -// PoolGateway is a mining pool discovered from chain aliases. -// -// pools := node.DiscoverPools("http://127.0.0.1:46941") +// pools := node.DiscoverPools("http://127.0.0.1:46941") +// for _, pool := range pools { log(pool.Name, pool.Endpoint) } type PoolGateway struct { Name string `json:"name"` Address string `json:"address"` @@ -40,9 +38,8 @@ type PoolGateway struct { Endpoint string `json:"endpoint"` } -// GetChainInfo queries the daemon for basic chain state. -// -// info, err := node.GetChainInfo("http://127.0.0.1:46941") +// info, err := node.GetChainInfo("http://127.0.0.1:46941") +// if err == nil && info.Synced { log("chain height:", info.Height) } func GetChainInfo(daemonURL string) (*ChainInfo, error) { body := `{"jsonrpc":"2.0","id":"0","method":"getinfo","params":{}}` response, err := http.Post(daemonURL+"/json_rpc", "application/json", strings.NewReader(body)) @@ -62,10 +59,8 @@ func GetChainInfo(daemonURL string) (*ChainInfo, error) { return &result.Result, nil } -// DiscoverPools queries the chain for aliases with cap=pool and returns -// pool endpoints that miners can connect to. -// -// pools := node.DiscoverPools("http://127.0.0.1:46941") +// pools := node.DiscoverPools("http://127.0.0.1:46941") +// for _, pool := range pools { log(pool.Name, pool.Endpoint) } func DiscoverPools(daemonURL string) []PoolGateway { body := `{"jsonrpc":"2.0","id":"0","method":"get_all_alias_details","params":{}}` response, err := http.Post(daemonURL+"/json_rpc", "application/json", strings.NewReader(body)) @@ -102,9 +97,8 @@ func DiscoverPools(daemonURL string) []PoolGateway { return pools } -// DiscoverGateways returns all gateway nodes from chain aliases. -// -// gateways := node.DiscoverGateways("http://127.0.0.1:46941") +// gateways := node.DiscoverGateways("http://127.0.0.1:46941") +// for _, gw := range gateways { log(gw.Name, gw.Endpoint) } func DiscoverGateways(daemonURL string) []PoolGateway { body := `{"jsonrpc":"2.0","id":"0","method":"get_all_alias_details","params":{}}` response, err := http.Post(daemonURL+"/json_rpc", "application/json", strings.NewReader(body))