Browse Source

RPC: Include non-default goals in reply to "coin" command

Luke Dashjr 11 years ago
parent
commit
db0d4722a6
3 changed files with 40 additions and 26 deletions
  1. 36 26
      api.c
  2. 2 0
      miner.c
  3. 2 0
      miner.h

+ 36 - 26
api.c

@@ -26,6 +26,8 @@
 #include <unistd.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/types.h>
 
 
+#include <uthash.h>
+
 #include "compat.h"
 #include "compat.h"
 #include "deviceapi.h"
 #include "deviceapi.h"
 #ifdef USE_LIBMICROHTTPD
 #ifdef USE_LIBMICROHTTPD
@@ -170,11 +172,9 @@ static const char ISJSON = '{';
 #define JSON_PGAS	JSON1 _PGAS JSON2
 #define JSON_PGAS	JSON1 _PGAS JSON2
 #define JSON_CPUS	JSON1 _CPUS JSON2
 #define JSON_CPUS	JSON1 _CPUS JSON2
 #define JSON_NOTIFY	JSON1 _NOTIFY JSON2
 #define JSON_NOTIFY	JSON1 _NOTIFY JSON2
-#define JSON_DEVDETAILS	JSON1 _DEVDETAILS JSON2
 #define JSON_CLOSE	JSON3
 #define JSON_CLOSE	JSON3
 #define JSON_MINESTATS	JSON1 _MINESTATS JSON2
 #define JSON_MINESTATS	JSON1 _MINESTATS JSON2
 #define JSON_CHECK	JSON1 _CHECK JSON2
 #define JSON_CHECK	JSON1 _CHECK JSON2
-#define JSON_MINECOIN	JSON1 _MINECOIN JSON2
 #define JSON_DEBUGSET	JSON1 _DEBUGSET JSON2
 #define JSON_DEBUGSET	JSON1 _DEBUGSET JSON2
 #define JSON_SETCONFIG	JSON1 _SETCONFIG JSON2
 #define JSON_SETCONFIG	JSON1 _SETCONFIG JSON2
 #define JSON_END	JSON4 JSON5
 #define JSON_END	JSON4 JSON5
@@ -3063,35 +3063,45 @@ static void minecoin(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __may
 {
 {
 	struct api_data *root = NULL;
 	struct api_data *root = NULL;
 	char buf[TMPBUFSIZ];
 	char buf[TMPBUFSIZ];
-	bool io_open;
 
 
 	message(io_data, MSG_MINECOIN, 0, NULL, isjson);
 	message(io_data, MSG_MINECOIN, 0, NULL, isjson);
-	io_open = io_add(io_data, isjson ? COMSTR JSON_MINECOIN : _MINECOIN COMSTR);
 
 
+	struct mining_goal_info *goal, *tmpgoal;
+	bool precom = false;
+	HASH_ITER(hh, mining_goals, goal, tmpgoal)
+	{
+		if (goal->is_default)
+			io_add(io_data, isjson ? COMSTR JSON1 _MINECOIN JSON2 : _MINECOIN COMSTR);
+		else
+		{
+			sprintf(buf, isjson ? COMSTR JSON1 _MINECOIN "%u" JSON2 : _MINECOIN "%u" COMSTR, goal->id);
+			io_add(io_data, buf);
+		}
+		
 #ifdef USE_SCRYPT
 #ifdef USE_SCRYPT
-	if (opt_scrypt)
-		root = api_add_const(root, "Hash Method", SCRYPTSTR, false);
-	else
+		if (opt_scrypt)
+			root = api_add_const(root, "Hash Method", SCRYPTSTR, false);
+		else
 #endif
 #endif
-		root = api_add_const(root, "Hash Method", SHA256STR, false);
-
-	cg_rlock(&ch_lock);
-	struct mining_goal_info * const goal = get_mining_goal("default");
-	struct blockchain_info * const blkchain = goal->blkchain;
-	struct block_info * const blkinfo = blkchain->currentblk;
-	root = api_add_time(root, "Current Block Time", &blkinfo->first_seen_time, true);
-	char fullhash[(sizeof(blkinfo->prevblkhash) * 2) + 1];
-	blkhashstr(fullhash, blkinfo->prevblkhash);
-	root = api_add_string(root, "Current Block Hash", fullhash, true);
-	cg_runlock(&ch_lock);
-
-	root = api_add_bool(root, "LP", &have_longpoll, false);
-	root = api_add_diff(root, "Network Difficulty", &goal->current_diff, true);
-
-	root = print_data(root, buf, isjson, false);
-	io_add(io_data, buf);
-	if (isjson && io_open)
-		io_close(io_data);
+			root = api_add_const(root, "Hash Method", SHA256STR, false);
+
+		cg_rlock(&ch_lock);
+		struct blockchain_info * const blkchain = goal->blkchain;
+		struct block_info * const blkinfo = blkchain->currentblk;
+		root = api_add_time(root, "Current Block Time", &blkinfo->first_seen_time, true);
+		char fullhash[(sizeof(blkinfo->prevblkhash) * 2) + 1];
+		blkhashstr(fullhash, blkinfo->prevblkhash);
+		root = api_add_string(root, "Current Block Hash", fullhash, true);
+		cg_runlock(&ch_lock);
+
+		root = api_add_bool(root, "LP", &have_longpoll, false);
+		root = api_add_diff(root, "Network Difficulty", &goal->current_diff, true);
+		
+		root = print_data(root, buf, isjson, precom);
+		io_add(io_data, buf);
+		if (isjson)
+			io_add(io_data, JSON_CLOSE);
+	}
 }
 }
 
 
 static void debugstate(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
 static void debugstate(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)

+ 2 - 0
miner.c

@@ -1009,6 +1009,7 @@ int mining_goals_name_cmp(const struct mining_goal_info * const a, const struct
 
 
 struct mining_goal_info *get_mining_goal(const char * const name)
 struct mining_goal_info *get_mining_goal(const char * const name)
 {
 {
+	static unsigned next_goal_id;
 	struct mining_goal_info *goal;
 	struct mining_goal_info *goal;
 	HASH_FIND_STR(mining_goals, name, goal);
 	HASH_FIND_STR(mining_goals, name, goal);
 	if (!goal)
 	if (!goal)
@@ -1025,6 +1026,7 @@ struct mining_goal_info *get_mining_goal(const char * const name)
 		HASH_ADD(hh, blkchain->blocks, prevblkhash, sizeof(dummy_block->prevblkhash), dummy_block);
 		HASH_ADD(hh, blkchain->blocks, prevblkhash, sizeof(dummy_block->prevblkhash), dummy_block);
 		
 		
 		*goal = (struct mining_goal_info){
 		*goal = (struct mining_goal_info){
+			.id = next_goal_id++,
 			.name = strdup(name),
 			.name = strdup(name),
 			.is_default = !strcmp(name, "default"),
 			.is_default = !strcmp(name, "default"),
 			.blkchain = blkchain,
 			.blkchain = blkchain,

+ 2 - 0
miner.h

@@ -1142,6 +1142,7 @@ struct blockchain_info {
 };
 };
 
 
 struct mining_goal_info {
 struct mining_goal_info {
+	unsigned id;
 	char *name;
 	char *name;
 	bool is_default;
 	bool is_default;
 	
 	
@@ -1207,6 +1208,7 @@ extern int opt_log_interval;
 extern unsigned long long global_hashrate;
 extern unsigned long long global_hashrate;
 extern unsigned unittest_failures;
 extern unsigned unittest_failures;
 extern double best_diff;
 extern double best_diff;
+extern struct mining_goal_info *mining_goals;
 
 
 struct curl_ent {
 struct curl_ent {
 	CURL *curl;
 	CURL *curl;