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
22 changes: 19 additions & 3 deletions src/rpc/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ void gobject_prepare_help()
"3. time (numeric, required) time this object was created\n"
"4. data-hex (string, required) data in hex string form\n"
"5. use-IS (boolean, optional, default=false) InstantSend lock the collateral, only requiring one chain confirmation\n"
"6. outputHash (string, optional) the single output to submit the proposal fee from\n"
"7. outputIndex (numeric, optional) The output index.\n"
);
}

UniValue gobject_prepare(const JSONRPCRequest& request)
{
if (request.fHelp || (request.params.size() != 5 && request.params.size() != 6))
if (request.fHelp || (request.params.size() != 5 && request.params.size() != 6 && request.params.size() != 8))
gobject_prepare_help();

if (!EnsureWalletIsAvailable(request.fHelp))
Expand Down Expand Up @@ -199,9 +201,23 @@ UniValue gobject_prepare(const JSONRPCRequest& request)

EnsureWalletIsUnlocked();

// If specified, spend this outpoint as the proposal fee
COutPoint outpoint;
outpoint.SetNull();
if (request.params.size() == 8) {
uint256 collateralHash = ParseHashV(request.params[6], "outputHash");
int32_t collateralIndex = ParseInt32V(request.params[7], "outputIndex");
if (collateralHash.IsNull() || collateralIndex < 0) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("invalid hash or index: %s-%d", collateralHash.ToString(), collateralIndex));
}
outpoint = COutPoint(collateralHash, (uint32_t)collateralIndex);
}

CWalletTx wtx;
if (!pwalletMain->GetBudgetSystemCollateralTX(wtx, govobj.GetHash(), govobj.GetMinCollateralFee(), useIS)) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Error making collateral transaction for governance object. Please check your wallet balance and make sure your wallet is unlocked.");
if (!pwalletMain->GetBudgetSystemCollateralTX(wtx, govobj.GetHash(), govobj.GetMinCollateralFee(), useIS, outpoint)) {
std::string err = "Error making collateral transaction for governance object. Please check your wallet balance and make sure your wallet is unlocked.";
if (request.params.size() == 8) err += "Please verify your specified output is valid and is enough for the combined proposal fee and transaction fee.";
Comment thread
UdjinM6 marked this conversation as resolved.
throw JSONRPCError(RPC_INTERNAL_ERROR, err);
}

// -- make our change address
Expand Down
9 changes: 6 additions & 3 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3356,7 +3356,7 @@ bool CWallet::CreateCollateralTransaction(CMutableTransaction& txCollateral, std
return true;
}

bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount amount, bool fUseInstantSend)
bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount amount, bool fUseInstantSend, const COutPoint& outpoint)
{
// make our change address
CReserveKey reservekey(this);
Expand All @@ -3370,8 +3370,11 @@ bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount a
std::vector< CRecipient > vecSend;
vecSend.push_back((CRecipient){scriptChange, amount, false});

CCoinControl *coinControl=NULL;
bool success = CreateTransaction(vecSend, tx, reservekey, nFeeRet, nChangePosRet, strFail, coinControl, true, ALL_COINS, fUseInstantSend);
CCoinControl coinControl;
if (!outpoint.IsNull()) {
coinControl.Select(outpoint);
}
bool success = CreateTransaction(vecSend, tx, reservekey, nFeeRet, nChangePosRet, strFail, &coinControl, true, ALL_COINS, fUseInstantSend);
if(!success){
LogPrintf("CWallet::GetBudgetSystemCollateralTX -- Error: %s\n", strFail);
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
CAmount GetNeedsToBeAnonymizedBalance(CAmount nMinBalance = 0) const;
CAmount GetDenominatedBalance(bool unconfirmed=false) const;

bool GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount amount, bool fUseInstantSend);
bool GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, CAmount amount, bool fUseInstantSend, const COutPoint& outpoint=COutPoint()/*defaults null*/);
Comment thread
nmarley marked this conversation as resolved.

/**
* Insert additional inputs into the transaction by
Expand Down