message: Changed submit candidate to retry sending to bitcoind. Before only once.
diff: @@ -417,6 +417,7 @@ static UniValue CpuMineBlock(const UniValue &params, bool &found)
  header.nNonce = std::rand();
  //printf("searching...target: %s\n",arith_uint256().SetCompact(header.nBits).GetHex().c_str());
  + printf("Mining...\n");
  int64_t start = GetTime();
  while ((GetTime() < start + (NEW_CANDIDATE_INTERVAL*1000))&&!found)
  @@ -439,11 +440,49 @@ static UniValue CpuMineBlock(const UniValue &params, bool &found)
  }
  +static UniValue RPCSubmitSolution(UniValue& solution,int& nblocks)
  +{
  + //Throws exceptions
  + UniValue reply = CallRPC("submitminingsolution", solution);
  + const UniValue &error = find_value(reply, "error");
  +
  + if (!error.isNull())
  + return reply; //Error
  +
  + UniValue result= find_value(reply, "result");
  +
  + if (result.isNull())
  + return reply; //Error
  +
  + bool accepted = result["accepted"].get_bool();
  + string message = result["message"].get_str();
  +
  + if(!accepted)
  + {
  + fprintf(stderr,"Block Candidate rejected. Error: %s\n",message.c_str());
  + }
  + else
  + {
  + printf("Block Candidate accepted.\n");
  + }
  +
  + //Will not get here if Exceptions above:
  + if(nblocks>0)
  + nblocks--; //Processed a block
  +
  + solution.setNull();
  +
  + return reply;
  +}
  +
  int CpuMiner(void)
  {
  //TODO add -nblocks to help msg
  int nblocks = GetArg("-nblocks", -1); //-1 mine forever
  + UniValue mineresult;
  + bool found = false;
  +
  if(0==nblocks)
  {
  printf("Nothing to do for zero (0) blocks\n");
  @@ -465,7 +504,20 @@ int CpuMiner(void)
  try
  {
  UniValue params;
  - reply = CallRPC("getstratum", params);
  + if(found)
  + {
  + //Submit the solution.
  + //Called here so all exceptions are handled properly below.
  + reply = RPCSubmitSolution(mineresult,nblocks);
  + if(nblocks == 0)
  + return 0; //Done mining exit program
  + found = false; //Mine again
  + }
  +
  + if(!found)
  + {
  + reply = CallRPC("getminingcandidate", params);
  + }
  // Parse reply
  result = find_value(reply, "result");
  @@ -579,7 +631,6 @@ int CpuMiner(void)
  if(nblocks>0)
  nblocks--;
  -
  }
  }
  }
  