stratum: handle p2sh addresses for all coinbase variants

allow to mine on non-legacy addresses....
This commit is contained in:
Tanguy Pruvot 2018-06-24 13:53:12 +02:00
parent b6f212ee6c
commit ca0c6271a0

View file

@ -14,24 +14,6 @@ static void encode_tx_value(char *encoded, json_int_t value)
TX_VALUE(value, 32), TX_VALUE(value, 40), TX_VALUE(value, 48), TX_VALUE(value, 56)); TX_VALUE(value, 32), TX_VALUE(value, 40), TX_VALUE(value, 48), TX_VALUE(value, 56));
} }
static void job_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char *key)
{
int ol = strlen(data);
char evalue[32];
encode_tx_value(evalue, amount);
sprintf(data+strlen(data), "%s", evalue);
if(coind->pos && !key)
sprintf(data+strlen(data), "2321%sac", coind->pubkey);
else
sprintf(data+strlen(data), "1976a914%s88ac", key? key: coind->script_pubkey);
// debuglog("pack tx %s\n", data+ol);
// debuglog("pack tx %lld\n", amount);
}
static void p2sh_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char *payee) static void p2sh_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char *payee)
{ {
char evalue[32]; char evalue[32];
@ -45,6 +27,29 @@ static void p2sh_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char
strcat(data, coinb2_part); strcat(data, coinb2_part);
} }
static void job_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char *key)
{
int ol = strlen(data);
char evalue[32];
if(coind->p2sh_address && !key) {
p2sh_pack_tx(coind, data, amount, coind->script_pubkey);
return;
}
encode_tx_value(evalue, amount);
sprintf(data+strlen(data), "%s", evalue);
if(coind->pos && !key)
sprintf(data+strlen(data), "2321%sac", coind->pubkey);
else
sprintf(data+strlen(data), "1976a914%s88ac", key? key: coind->script_pubkey);
// debuglog("pack tx %s\n", data+ol);
// debuglog("pack tx %lld\n", amount);
}
void coinbase_aux(YAAMP_JOB_TEMPLATE *templ, char *aux_script) void coinbase_aux(YAAMP_JOB_TEMPLATE *templ, char *aux_script)
{ {
vector<string> hashlist = coind_aux_hashlist(templ->auxs, templ->auxs_size); vector<string> hashlist = coind_aux_hashlist(templ->auxs, templ->auxs_size);
@ -324,11 +329,10 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *
available -= amount; available -= amount;
base58_decode(payee, script_payee); base58_decode(payee, script_payee);
bool superblock_use_p2sh = (strcmp(coind->symbol, "MAC") == 0); bool superblock_use_p2sh = (strcmp(coind->symbol, "MAC") == 0);
if(superblock_use_p2sh) { if(superblock_use_p2sh)
p2sh_pack_tx(coind, script_dests, amount, script_payee); p2sh_pack_tx(coind, script_dests, amount, script_payee);
} else { else
job_pack_tx(coind, script_dests, amount, script_payee); job_pack_tx(coind, script_dests, amount, script_payee);
}
//debuglog("%s superblock %s %u\n", coind->symbol, payee, amount); //debuglog("%s superblock %s %u\n", coind->symbol, payee, amount);
} }
} }
@ -342,22 +346,17 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *
available -= amount; available -= amount;
base58_decode(payee, script_payee); base58_decode(payee, script_payee);
bool masternode_use_p2sh = (strcmp(coind->symbol, "MAC") == 0); bool masternode_use_p2sh = (strcmp(coind->symbol, "MAC") == 0);
if(masternode_use_p2sh) { if(masternode_use_p2sh)
p2sh_pack_tx(coind, script_dests, amount, script_payee); p2sh_pack_tx(coind, script_dests, amount, script_payee);
} else { else
job_pack_tx(coind, script_dests, amount, script_payee); job_pack_tx(coind, script_dests, amount, script_payee);
}
} }
} }
sprintf(payees, "%02x", npayees); sprintf(payees, "%02x", npayees);
strcat(templ->coinb2, payees); strcat(templ->coinb2, payees);
if (templ->has_segwit_txs) strcat(templ->coinb2, commitment); if (templ->has_segwit_txs) strcat(templ->coinb2, commitment);
strcat(templ->coinb2, script_dests); strcat(templ->coinb2, script_dests);
if (coind->p2sh_address) { // "MAC 0.16" job_pack_tx(coind, templ->coinb2, available, NULL);
p2sh_pack_tx(coind, templ->coinb2, available, coind->script_pubkey);
} else {
job_pack_tx(coind, templ->coinb2, available, NULL);
}
strcat(templ->coinb2, "00000000"); // locktime strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available/100000000*coind->reward_mul; coind->reward = (double)available/100000000*coind->reward_mul;
//debuglog("%s %d dests %s\n", coind->symbol, npayees, script_dests); //debuglog("%s %d dests %s\n", coind->symbol, npayees, script_dests);