|
|
@ -28,6 +28,7 @@ type RPCClient struct { |
|
|
|
Name string |
|
|
|
Name string |
|
|
|
sick bool |
|
|
|
sick bool |
|
|
|
client *http.Client |
|
|
|
client *http.Client |
|
|
|
|
|
|
|
info atomic.Value |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type GetBlockTemplateReply struct { |
|
|
|
type GetBlockTemplateReply struct { |
|
|
@ -38,6 +39,14 @@ type GetBlockTemplateReply struct { |
|
|
|
PrevHash string `json:"prev_hash"` |
|
|
|
PrevHash string `json:"prev_hash"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type GetInfoReply struct { |
|
|
|
|
|
|
|
IncomingConnections int64 `json:"incoming_connections_count"` |
|
|
|
|
|
|
|
OutgoingConnections int64 `json:"outgoing_connections_count"` |
|
|
|
|
|
|
|
Status string `json:"status"` |
|
|
|
|
|
|
|
Height int64 `json:"height"` |
|
|
|
|
|
|
|
TxPoolSize int64 `json:"tx_pool_size"` |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type JSONRpcResp struct { |
|
|
|
type JSONRpcResp struct { |
|
|
|
Id *json.RawMessage `json:"id"` |
|
|
|
Id *json.RawMessage `json:"id"` |
|
|
|
Result *json.RawMessage `json:"result"` |
|
|
|
Result *json.RawMessage `json:"result"` |
|
|
@ -71,6 +80,19 @@ func (r *RPCClient) GetBlockTemplate(reserveSize int, address string) (*GetBlock |
|
|
|
return reply, err |
|
|
|
return reply, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (r *RPCClient) GetInfo() (*GetInfoReply, error) { |
|
|
|
|
|
|
|
params := make(map[string]interface{}) |
|
|
|
|
|
|
|
rpcResp, err := r.doPost(r.Url.String(), "get_info", params) |
|
|
|
|
|
|
|
var reply *GetInfoReply |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if rpcResp.Result != nil { |
|
|
|
|
|
|
|
err = json.Unmarshal(*rpcResp.Result, &reply) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return reply, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (r *RPCClient) SubmitBlock(hash string) (*JSONRpcResp, error) { |
|
|
|
func (r *RPCClient) SubmitBlock(hash string) (*JSONRpcResp, error) { |
|
|
|
return r.doPost(r.Url.String(), "submitblock", []string{hash}) |
|
|
|
return r.doPost(r.Url.String(), "submitblock", []string{hash}) |
|
|
|
} |
|
|
|
} |
|
|
@ -145,3 +167,16 @@ func (r *RPCClient) markAlive() { |
|
|
|
} |
|
|
|
} |
|
|
|
r.Unlock() |
|
|
|
r.Unlock() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (r *RPCClient) UpdateInfo() (*GetInfoReply, error) { |
|
|
|
|
|
|
|
info, err := r.GetInfo() |
|
|
|
|
|
|
|
if err == nil { |
|
|
|
|
|
|
|
r.info.Store(info) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return info, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (r *RPCClient) Info() *GetInfoReply { |
|
|
|
|
|
|
|
reply, _ := r.info.Load().(*GetInfoReply) |
|
|
|
|
|
|
|
return reply |
|
|
|
|
|
|
|
} |
|
|
|