Skip to content

Commit

Permalink
[RPC] Use new opcode for P2CS after v6 enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed May 11, 2021
1 parent 8eefab5 commit 45ebfee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/sapling/sapling_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ struct SendManyRecipient
{}

// Transparent recipient: P2CS
SendManyRecipient(const CKeyID& ownerKey, const CKeyID& stakerKey, const CAmount& amount):
transparentRecipient(CTxOut(amount, GetScriptForStakeDelegation(stakerKey, ownerKey)))
SendManyRecipient(const CKeyID& ownerKey, const CKeyID& stakerKey, const CAmount& amount, bool fV6Enforced):
transparentRecipient(CTxOut(amount, fV6Enforced ? GetScriptForStakeDelegation(stakerKey, ownerKey)
: GetScriptForStakeDelegationLOF(stakerKey, ownerKey)))
{}

// Transparent recipient: multisig
Expand Down
8 changes: 6 additions & 2 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,12 +1147,16 @@ UniValue CreateColdStakeDelegation(const UniValue& params, CTransactionRef& txNe
ownerAddressStr = EncodeDestination(ownerAddr);
}

// Use new opcode after v6.0 enforcement (!TODO: remove after enforcement)
bool fV6Enforced = Params().GetConsensus().NetworkUpgradeActive(chainActive.Height(), Consensus::UPGRADE_V6_0);

// Create the transaction
const bool fUseShielded = (params.size() > 5) && params[5].get_bool();
if (!fUseShielded) {
// Delegate transparent coins
CAmount nFeeRequired;
CScript scriptPubKey = GetScriptForStakeDelegation(*stakeKey, ownerKey);
CScript scriptPubKey = fV6Enforced ? GetScriptForStakeDelegation(*stakeKey, ownerKey)
: GetScriptForStakeDelegationLOF(*stakeKey, ownerKey);
if (!pwalletMain->CreateTransaction(scriptPubKey, nValue, txNew, reservekey, nFeeRequired, strError, nullptr, ALL_COINS, (CAmount)0, fUseDelegated)) {
if (nValue + nFeeRequired > currBalance)
strError = strprintf("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired));
Expand All @@ -1167,7 +1171,7 @@ UniValue CreateColdStakeDelegation(const UniValue& params, CTransactionRef& txNe
if (!consensus.NetworkUpgradeActive(nextBlockHeight, Consensus::UPGRADE_V5_0)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, Sapling not active yet");
}
std::vector<SendManyRecipient> recipients = {SendManyRecipient(ownerKey, *stakeKey, nValue)};
std::vector<SendManyRecipient> recipients = {SendManyRecipient(ownerKey, *stakeKey, nValue, fV6Enforced)};
SaplingOperation operation(consensus, nextBlockHeight, pwalletMain);
OperationResult res = operation.setSelectShieldedCoins(true)
->setRecipients(recipients)
Expand Down

0 comments on commit 45ebfee

Please sign in to comment.