Skip to content

Commit

Permalink
Merge pull request #1016 from qtumproject/time/get_block_fix
Browse files Browse the repository at this point in the history
Fix get block rpc for verbosity level 3
  • Loading branch information
qtum-neil authored Aug 30, 2023
2 parents 11f8b41 + 662433e commit db201ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry

// If available, use Undo data to calculate the fee. Note that txundo == nullptr
// for coinbase transactions and for transactions where undo data is unavailable.
const bool have_undo = txundo != nullptr && !tx.IsCoinStake();
const bool have_undo = txundo != nullptr;
CAmount amt_total_in = 0;
CAmount amt_total_out = 0;
bool isCoinStake = tx.IsCoinStake();

for (unsigned int i = 0; i < tx.vin.size(); i++) {
const CTxIn& txin = tx.vin[i];
Expand All @@ -212,14 +213,17 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
const Coin& prev_coin = txundo->vprevout[i];
const CTxOut& prev_txout = prev_coin.out;

amt_total_in += prev_txout.nValue;
if(!isCoinStake)
{
amt_total_in += prev_txout.nValue;
}

if (verbosity == TxVerbosity::SHOW_DETAILS_AND_PREVOUT) {
UniValue o_script_pub_key(UniValue::VOBJ);
ScriptToUniv(prev_txout.scriptPubKey, /*out=*/o_script_pub_key, /*include_hex=*/true, /*include_address=*/true);

UniValue p(UniValue::VOBJ);
p.pushKV("generated", bool(prev_coin.fCoinBase));
p.pushKV("generated", bool(prev_coin.fCoinBase || prev_coin.fCoinStake));
p.pushKV("height", uint64_t(prev_coin.nHeight));
p.pushKV("value", ValueFromAmount(prev_txout.nValue));
p.pushKV("scriptPubKey", o_script_pub_key);
Expand All @@ -245,13 +249,13 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
out.pushKV("scriptPubKey", o);
vout.push_back(out);

if (have_undo) {
if (have_undo && !isCoinStake) {
amt_total_out += txout.nValue;
}
}
entry.pushKV("vout", vout);

if (have_undo) {
if (have_undo && !isCoinStake) {
const CAmount fee = amt_total_in - amt_total_out;
CHECK_NONFATAL(MoneyRange(fee));
entry.pushKV("fee", ValueFromAmount(fee));
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ const RPCResult getblock_vin{
{RPCResult::Type::ELISION, "", "The same output as verbosity = 2"},
{RPCResult::Type::OBJ, "prevout", "(Only if undo information is available)",
{
{RPCResult::Type::BOOL, "generated", "Coinbase or not"},
{RPCResult::Type::BOOL, "generated", "Coinbase or not, coinstake or not"},
{RPCResult::Type::NUM, "height", "The height of the prevout"},
{RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT},
{RPCResult::Type::OBJ, "scriptPubKey", "",
Expand Down

0 comments on commit db201ca

Please sign in to comment.