Skip to content

Commit

Permalink
stratum: handle Tuxcoin DonationSubsidy (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
bleach86 authored and tpruvot committed Jan 30, 2019
1 parent 94d3ba1 commit c3ecd27
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions stratum/coinbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,54 @@ 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, "TUX") == 0) {
char script_payee[1024];
char charity_payee[256] = { 0 };
const char *payee = json_get_string(json_result, "donation_payee");
if(payee != NULL){
sprintf(coind->charity_address, "%s", payee);
} else {
sprintf(coind->charity_address, "%s", "");
}

if(strlen(coind->charity_address) > 0){
char script_payee[1024];
char charity_payee[256] = { 0 };
sprintf(charity_payee, "%s", coind->charity_address);
if (strlen(charity_payee) == 0)
stratumlog("ERROR %s has no charity_address set!\n", coind->name);

base58_decode(charity_payee, script_payee);

json_int_t charity_amount = json_get_int(json_result, "donation_amount");
coind->charity_amount = charity_amount;

if (templ->has_segwit_txs) {
strcat(templ->coinb2, "03"); // 3 outputs (nulldata + fees + miner)
strcat(templ->coinb2, commitment);
} else {
strcat(templ->coinb2, "02");
}
job_pack_tx(coind, templ->coinb2, available, NULL);

char echarity_amount[32];
encode_tx_value(echarity_amount, charity_amount);
strcat(templ->coinb2, echarity_amount);
char coinb2_part[1024] = { 0 };
char coinb2_len[3] = { 0 };
sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee);
sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF);
strcat(templ->coinb2, coinb2_len);
strcat(templ->coinb2, coinb2_part);
debuglog("pack tx %s\n", coinb2_part);
strcat(templ->coinb2, "00000000"); // locktime

coind->reward = (double)available/100000000*coind->reward_mul;
//debuglog("INFO %s block available %f, charity %f miner %f\n", coind->symbol,
// (double) available/1e8, (double) charity_amount/1e8, coind->reward);
return;
}
}

// 2 txs are required on these coins, one for foundation (dev fees)
if(coind->charity_percent && !coind->hasmasternodes)
Expand Down

0 comments on commit c3ecd27

Please sign in to comment.