int test_merkle() { vector<string> hash; hash.push_back(""); hash.push_back("999d2c8bb6bda0bf784d9ebeb631d711dbbbfe1bc006ea13d6ad0d6a2649a971"); hash.push_back("3f92594d5a3d7b4df29d7dd7c46a0dac39a96e751ba0fc9bab5435ea5e22a19d"); hash.push_back("a5633f03855f541d8e60a6340fc491d49709dc821f3acb571956a856637adcb6"); hash.push_back("28d97c850eaf917a4c76c02474b05b70a197eaefb468d21c22ed110afe8ec9e0"); vector<string> res = merkle_steps(hash); string mr = merkle_with_first(res, "d43b669fb42cfa84695b844c0402d410213faa4f3e66cb7248f688ff19d5e5f7"); printf("mr: %s\n", mr.c_str()); // 82293f182d5db07d08acf334a5a907012bbb9990851557ac0ec028116081bd5a }
YAAMP_JOB_TEMPLATE *coind_create_template(YAAMP_COIND *coind) { if(coind->usememorypool) return coind_create_template_memorypool(coind); char params[4*1024] = "[{}]"; if(!strcmp(coind->symbol, "PPC")) strcpy(params, "[]"); json_value *json = rpc_call(&coind->rpc, "getblocktemplate", params); if(!json || json->type == json_null) { coind_error(coind, "getblocktemplate"); return NULL; } json_value *json_result = json_get_object(json, "result"); if(!json_result || json_result->type == json_null) { coind_error(coind, "getblocktemplate"); json_value_free(json); return NULL; } json_value *json_tx = json_get_array(json_result, "transactions"); if(!json_tx) { coind_error(coind, "getblocktemplate"); json_value_free(json); return NULL; } json_value *json_coinbaseaux = json_get_object(json_result, "coinbaseaux"); if(!json_coinbaseaux) { coind_error(coind, "getblocktemplate"); json_value_free(json); return NULL; } YAAMP_JOB_TEMPLATE *templ = new YAAMP_JOB_TEMPLATE; memset(templ, 0, sizeof(YAAMP_JOB_TEMPLATE)); templ->created = time(NULL); templ->value = json_get_int(json_result, "coinbasevalue"); templ->height = json_get_int(json_result, "height"); sprintf(templ->version, "%08x", (unsigned int)json_get_int(json_result, "version")); sprintf(templ->ntime, "%08x", (unsigned int)json_get_int(json_result, "curtime")); strcpy(templ->nbits, json_get_string(json_result, "bits")); strcpy(templ->prevhash_hex, json_get_string(json_result, "previousblockhash")); strcpy(templ->flags, json_get_string(json_coinbaseaux, "flags")); // debuglog("%s ntime %s\n", coind->symbol, templ->ntime); // uint64_t target = decode_compact(json_get_string(json_result, "bits")); // coind->difficulty = target_to_diff(target); // string_lower(templ->ntime); // string_lower(templ->nbits); // char target[1024]; // strcpy(target, json_get_string(json_result, "target")); // uint64_t coin_target = decode_compact(templ->nbits); // debuglog("%s\n", templ->nbits); // debuglog("%s\n", target); // debuglog("0000%016llx\n", coin_target); if(coind->isaux) { json_value_free(json); coind_getauxblock(coind); return templ; } ////////////////////////////////////////////////////////////////////////////////////////// vector<string> txhashes; txhashes.push_back(""); for(int i = 0; i < json_tx->u.array.length; i++) { const char *p = json_get_string(json_tx->u.array.values[i], "hash"); char hash_be[1024]; memset(hash_be, 0, 1024); string_be(p, hash_be); txhashes.push_back(hash_be); const char *d = json_get_string(json_tx->u.array.values[i], "data"); templ->txdata.push_back(d); } templ->txmerkles[0] = 0; templ->txcount = txhashes.size(); templ->txsteps = merkle_steps(txhashes); vector<string>::const_iterator i; for(i = templ->txsteps.begin(); i != templ->txsteps.end(); ++i) sprintf(templ->txmerkles + strlen(templ->txmerkles), "\"%s\",", (*i).c_str()); if(templ->txmerkles[0]) templ->txmerkles[strlen(templ->txmerkles)-1] = 0; // debuglog("merkle transactions %d [%s]\n", templ->txcount, templ->txmerkles); ser_string_be2(templ->prevhash_hex, templ->prevhash_be, 8); if(!coind->pos) coind_aux_build_auxs(templ); coinbase_create(coind, templ, json_result); json_value_free(json); return templ; }