diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 86b31eb..317bb8d 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -93,6 +93,10 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * char eversion1[32] = "01000000"; if(coind->txmessage) strcpy(eversion1, "02000000"); + + const char *coinbase_payload = json_get_string(json_result, "coinbase_payload"); + if(coinbase_payload && strlen(coinbase_payload) > 0) + strcpy(eversion1, "03000500"); char script1[4*1024]; sprintf(script1, "%s%s%s08", eheight, templ->flags, etime); @@ -285,6 +289,64 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * coind->reward = (double)available / 100000000 * coind->reward_mul; return; } + else if(strcmp(coind->symbol, "RTM") == 0) + { + char payees[4]; + int npayees = 1; + char script_dests[4096] = { 0 }; + + json_value* smartnode = json_get_object(json_result, "smartnode"); + debuglog("RTM DETECTED Json: RESULT %s\n", smartnode); + bool smartnode_started = json_get_bool(json_result, "smartnode_payments_started"); + if (smartnode_started && smartnode) + { + for(int i = 0; i < smartnode->u.array.length; i++) + { + const char *payee = json_get_string(smartnode->u.array.values[i], "payee"); + json_int_t amount = json_get_int(smartnode->u.array.values[i], "amount"); + if (payee && amount) { + char script_payee[128] = { 0 }; + npayees++; + available -= amount; + base58_decode(payee, script_payee); + job_pack_tx(coind, script_dests, amount, script_payee); + } + debuglog("SMARTNODE DETECTED Payee: %s\n", payee); + } + } + + json_value* founder = json_get_array(json_result, "founder"); + bool founder_payments_started = json_get_bool(json_result, "founder_payments_started"); + if (founder_payments_started && founder) + { + const char *founder_payee = json_get_string(founder, "payee"); + json_int_t founder_amount = json_get_int(founder, "amount"); + if (founder_payee && founder_amount) + { + char founder_script_payee[128] = { 0 }; + npayees++; + available -= founder_amount; + base58_decode(founder_payee, founder_script_payee); + job_pack_tx(coind, script_dests, founder_amount, founder_script_payee); + } + debuglog("FOUNDER DETECTED Payee: %s\n", founder_payee); + } + + sprintf(payees, "%02x", npayees); + strcat(templ->coinb2, payees); + strcat(templ->coinb2, script_dests); + job_pack_tx(coind, templ->coinb2, available, NULL); + strcat(templ->coinb2, "00000000"); // locktime + if(coinbase_payload && strlen(coinbase_payload) > 0) { + char coinbase_payload_size[18]; + ser_compactsize((unsigned int)(strlen(coinbase_payload) >> 1), coinbase_payload_size); + strcat(templ->coinb2, coinbase_payload_size); + strcat(templ->coinb2, coinbase_payload); + } + + coind->reward = (double)available / 100000000 * coind->reward_mul; + return; + } else if(strcmp(coind->symbol, "TUX") == 0) { char script_payee[1024]; char charity_payee[256] = { 0 }; diff --git a/stratum/util.cpp b/stratum/util.cpp index 92f284a..3687d86 100644 --- a/stratum/util.cpp +++ b/stratum/util.cpp @@ -479,6 +479,26 @@ void ser_number(int n, char *a) // printf("ser_number %d, %s\n", n, a); } +void ser_compactsize(uint64_t nSize, char *a) +{ + if (nSize < 253) + { + sprintf(a, "%02lx", nSize); + } + else if (nSize <= (unsigned short)-1) + { + sprintf(a, "%02x%04lx", 253, nSize); + } + else if (nSize <= (unsigned int)-1) + { + sprintf(a, "%02x%08lx", 254, nSize); + } + else + { + sprintf(a, "%02x%016lx", 255, nSize); + } +} + void ser_string_be(const char *input, char *output, int len) { for(int i=0; i