Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ class Chain
//! Always false when non-standard transactions are accepted.
virtual bool isNonStandardSpecialTx(const CTransactionRef& tx, std::string& reason) = 0;

//! Whether v24 hard fork rules apply to the next block, which is what
//! enables version 2 asset lock transactions by consensus.
virtual bool isV24Active() = 0;

//! Check if any block has been pruned.
virtual bool havePruned() = 0;

Expand Down
5 changes: 5 additions & 0 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,11 @@ class ChainImpl : public Chain
if (!m_node.mempool || !m_node.mempool->m_require_standard) return false;
return !IsStandardSpecialTx(*tx, reason);
}
bool isV24Active() override
{
LOCK(::cs_main);
return DeploymentActiveAfter(chainman().ActiveChain().Tip(), chainman(), Consensus::DEPLOYMENT_V24);
}
bool havePruned() override
{
LOCK(::cs_main);
Expand Down
13 changes: 10 additions & 3 deletions src/wallet/rpc/spend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <consensus/validation.h>
#include <core_io.h>
#include <interfaces/chain.h>
#include <key_io.h>
#include <policy/policy.h>
#include <rpc/rawtransaction_util.h>
Expand All @@ -22,7 +23,7 @@
#include <map>

namespace wallet {
static void ParseRecipients(const UniValue& address_amounts, const UniValue& subtract_fee_outputs, std::vector<CRecipient>& recipients)
static void ParseRecipients(interfaces::Chain& chain, const UniValue& address_amounts, const UniValue& subtract_fee_outputs, std::vector<CRecipient>& recipients)
{
// A Platform address and a base58 address can encode the same hash, so recipients
// are deduplicated by the script they pay rather than by the decoded destination.
Expand All @@ -40,6 +41,12 @@ static void ParseRecipients(const UniValue& address_amounts, const UniValue& sub
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY,
strprintf("Invalid Dash address: %s (%s)", address, error_msg));
}
if (!chain.isV24Active()) {
throw JSONRPCError(RPC_INVALID_PARAMETER,
strprintf("Invalid param for %s, paying a Platform address requires an asset lock "
"transaction of version 2, which is only valid after v24 activation",
address));
}
script_pub_key = GetScriptForPlatformDestination(platform_dest);
} else {
script_pub_key = GetScriptForDestination(dest);
Expand Down Expand Up @@ -316,7 +323,7 @@ RPCHelpMan sendtoaddress()
}

std::vector<CRecipient> recipients;
ParseRecipients(address_amounts, subtractFeeFromAmount, recipients);
ParseRecipients(pwallet->chain(), address_amounts, subtractFeeFromAmount, recipients);
const bool verbose{request.params[11].isNull() ? false : request.params[11].get_bool()};

return SendMoney(*pwallet, coin_control, recipients, mapValue, verbose);
Expand Down Expand Up @@ -412,7 +419,7 @@ RPCHelpMan sendmany()
SetFeeEstimateMode(*pwallet, coin_control, /*conf_target=*/request.params[8], /*estimate_mode=*/request.params[9], /*fee_rate=*/request.params[10], /*override_min_fee=*/false);

std::vector<CRecipient> recipients;
ParseRecipients(sendTo, subtractFeeFromAmount, recipients);
ParseRecipients(pwallet->chain(), sendTo, subtractFeeFromAmount, recipients);
const bool verbose{request.params[11].isNull() ? false : request.params[11].get_bool()};

return SendMoney(*pwallet, coin_control, recipients, std::move(mapValue), verbose);
Expand Down
6 changes: 6 additions & 0 deletions test/functional/feature_asset_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,12 @@ def test_asset_locks_v2_pre_v24(self, node_wallet, node, pubkey):
result_expected={'allowed': False, 'reject-reason': 'bad-assetlocktx-version-2'})
self.log.info("v2 asset lock correctly rejected pre-v24")

self.log.info("Spending RPCs refuse to pay a Platform address before the fork")
assert_raises_rpc_error(-8, "only valid after v24 activation", node_wallet.sendtoaddress,
encode_platform_p2pkh('tdash', hash160(pubkey)), 1)
assert_raises_rpc_error(-8, "only valid after v24 activation", node_wallet.sendmany, "",
{encode_platform_p2pkh('tdash', hash160(pubkey)): 1})

Comment thread
coderabbitai[bot] marked this conversation as resolved.
def test_asset_locks_v2(self, node_wallet, node, pubkey):
self.log.info("Testing asset lock v2 after v24 activation...")
assert softfork_active(node_wallet, 'v24')
Expand Down
Loading