From ff7adc43bee185f4ff39617dbab8bee51bbe1dfb Mon Sep 17 00:00:00 2001 From: AaronCai Date: Mon, 20 Feb 2023 15:06:13 +0800 Subject: [PATCH] add BTSC support --- stratum/client_submit.cpp | 10 +++---- stratum/coinbase.cpp | 58 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index 26ae172f5..a789baf81 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -558,8 +558,8 @@ bool client_submit(YAAMP_CLIENT* client, json_value* json_params) if (!client_ask_stats(client)) client->stats = false; } - double share_diff = diff_to_target(hash_int); - double coin_diff = diff_to_target(coin_target); + uint64_t share_diff = diff_to_target(hash_int); + uint64_t coin_diff = diff_to_target(coin_target); // if (g_current_algo->diff_multiplier != 0) { // share_diff = share_diff / g_current_algo->diff_multiplier; // } @@ -572,14 +572,14 @@ bool client_submit(YAAMP_CLIENT* client, json_value* json_params) if (map_it != hash_map.end()) { if (map_it->second < share_diff) { hash_map[map_it->first] = share_diff; - debuglog("%s => submit %s (uid %d) with session max DIFF = %.3f / %.3f\n", job->coind->symbol,client->sock->ip, client->userid, + debuglog("%s => submit %s (uid %d) with session max DIFF = %08lx / %08lx\n", job->coind->symbol,client->sock->ip, client->userid, share_diff , coin_diff); } } else { hash_map[job->coind->symbol] = share_diff; - debuglog("%s => submit %s (uid %d) with session max DIFF = %.3f / %.3f\n", job->coind->symbol, client->sock->ip, client->userid, - share_diff , coin_diff); + debuglog("%s => submit %s (uid %d) with session max DIFF = %08lx / %08lx\n", job->coind->symbol, client->sock->ip, client->userid, + share_diff, coin_diff); } //if (fmod(share_diff, 9) < 1) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 16506a49a..2cea78005 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -828,6 +828,64 @@ void coinbase_create(YAAMP_COIND* coind, YAAMP_JOB_TEMPLATE* templ, json_value* return; } + else if (strcmp(coind->symbol, "BTSC") == 0) + { + char payees[4]; + int npayees = 1; + char script_dests[4096] = { 0 }; + + json_value* smartnode = json_get_object(json_result, "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, "FITA") == 0) { char payees[4];