diff --git a/src/core_write.cpp b/src/core_write.cpp index ffad7897ff..2edee784bb 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -334,7 +334,10 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_add } if (calculate_fee) { - const CAmount fee = amt_total_in - amt_total_out; + CAmount fee = amt_total_in - amt_total_out; + if (tx.IsPlatformTransfer()) { + fee = CHECK_NONFATAL(GetTxPayload(tx))->getFee(); + } CHECK_NONFATAL(MoneyRange(fee)); entry.pushKV("fee", ValueFromAmount(fee)); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 411d6cb75d..409d24c879 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -49,6 +49,7 @@ #include #include +#include #include #include #include @@ -2450,6 +2451,11 @@ static RPCHelpMan getblockstats() } CAmount txfee = tx_total_in - tx_total_out; + + if (tx->IsPlatformTransfer()) { + txfee = CHECK_NONFATAL(GetTxPayload(*tx))->getFee(); + } + CHECK_NONFATAL(MoneyRange(txfee)); if (do_medianfee) { fee_array.push_back(txfee); diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index ee5fcbdea0..cecaa6cbfb 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include @@ -406,6 +407,11 @@ static RPCHelpMan masternode_payments() if (tx->IsCoinBase()) { continue; } + if (tx->IsPlatformTransfer()) { + nBlockFees += CHECK_NONFATAL(GetTxPayload(*tx))->getFee(); + continue; + } + CAmount nValueIn{0}; for (const auto& txin : tx->vin) { uint256 blockHashTmp; diff --git a/test/functional/feature_asset_locks.py b/test/functional/feature_asset_locks.py index f802edd056..ff6ac61289 100755 --- a/test/functional/feature_asset_locks.py +++ b/test/functional/feature_asset_locks.py @@ -370,6 +370,7 @@ class AssetLocksTest(DashTestFramework): self.wait_for_sporks_same() txid = self.send_tx(asset_unlock_tx) + assert_equal(node.getmempoolentry(txid)['fee'], Decimal("0.0007")) is_id = node_wallet.sendtoaddress(node_wallet.getnewaddress(), 1) for node in self.nodes: self.wait_for_instantlock(is_id, node) @@ -407,6 +408,9 @@ class AssetLocksTest(DashTestFramework): self.mempool_size -= 2 self.check_mempool_size() block_asset_unlock = node.getrawtransaction(asset_unlock_tx.rehash(), 1)['blockhash'] + self.log.info("Checking rpc `getblock` and `getblockstats` succeeds as they use own fee calculation mechanism") + assert_equal(node.getblockstats(node.getblockcount())['maxfee'], tiny_amount) + node.getblock(block_asset_unlock, 2) self.send_tx(asset_unlock_tx, expected_error = "Transaction already in block chain",