Skip to content

Commit

Permalink
Update coinbase.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolin1579 committed Jun 26, 2021
1 parent a99a3d7 commit 36cf1e3
Showing 1 changed file with 85 additions and 24 deletions.
109 changes: 85 additions & 24 deletions stratum/coinbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,48 +940,109 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *
char payees[4];
int npayees = 1;
char script_dests[4096] = { 0 };
//
char script_payee[128] = { 0 };

json_value* masternode = json_get_object(json_result, "masternode");
bool masternode_started = json_get_bool(json_result, "masternode_payments_started");
if (masternode_started && masternode)
{
if (json_is_array(masternode))
{
for(int i = 0; i < masternode->u.array.length; i++)
{
const char *payee = json_get_string(masternode->u.array.values[i], "payee");
const char *script = json_get_string(masternode->u.array.values[i], "script");
json_int_t amount = json_get_int(masternode->u.array.values[i], "amount");
if (!amount) continue;
if (script)
{
npayees++;
available -= amount;
script_pack_tx(coind, script_dests, amount, script);
}
else if (payee)
{
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
//debuglog("%s masternode %s %u\n", coind->symbol, payee, amount);
}
}
}
else
{
const char *payee = json_get_string(masternode, "payee");
json_int_t amount = json_get_int(masternode, "amount");
if (payee && amount)
{
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
}
}
}

json_value* fundreward = json_get_array(json_result, "fundreward");
if (fundreward)
{
const char *fundreward_payee = json_get_string(fundreward, "payee");
json_int_t fundreward_amount = json_get_int(fundreward, "amount");
if (fundreward_payee && fundreward_amount)
const char *fund_payee = json_get_string(fundreward, "payee");
json_int_t fund_amount = json_get_int(fundreward, "amount");
if (fund_payee && fund_amount)
{
char script_payee[128] = { 0 };
npayees++;
available -= fundreward_amount;
base58_decode(fundreward_payee, script_payee);
job_pack_tx(coind, script_dests, fundreward_amount, script_payee);
}
}
json_value* masternode = json_get_object(json_result, "masternode");
bool masternode_enabled = json_get_bool(json_result, "masternode_payments_enforced");
if (masternode_enabled && masternode)
{
bool started = json_get_bool(json_result, "masternode_payments_started");
const char *payee = json_get_string(masternode, "payee");
json_int_t amount = json_get_int(masternode, "amount");
if (started && payee && amount) {
char script_payee[128] = { 0 };
npayees++;
available -= amount;
base58_decode(payee, script_payee);
job_pack_tx(coind, script_dests, amount, script_payee);
if (json_is_array(fundreward))
{
for(int i = 0; i < fundreward->u.array.length; i++)
{
const char *fund_payee = json_get_string(fundreward->u.array.values[i], "payee");
const char *script = json_get_string(fundreward->u.array.values[i], "script");
json_int_t fund_amount = json_get_int(fundreward->u.array.values[i], "amount");
if (!fund_amount) continue;
if (script)
{
npayees++;
available -= fund_amount;
script_pack_tx(coind, script_dests, fund_amount, script);
}
else if (fund_payee)
{
npayees++;
available -= fund_amount;
base58_decode(fund_payee, script_payee);
job_pack_tx(coind, script_dests, fund_amount, script_payee);
}
}
}
else
{
const char *fund_payee = json_get_string(fundreward, "payee");
json_int_t fund_amount = json_get_int(fundreward, "amount");
if (fund_payee && fund_amount)
{
npayees++;
available -= fund_amount;
base58_decode(fund_payee, script_payee);
job_pack_tx(coind, script_dests, fund_amount, script_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;
}
Expand Down

0 comments on commit 36cf1e3

Please sign in to comment.