Skip to content

Commit

Permalink
rpc: verifyrawtransaction set prevout chain heights to mempool token.
Browse files Browse the repository at this point in the history
  • Loading branch information
tecnovert committed Nov 1, 2021
1 parent cbf82ca commit e1e6511
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 21)
define(_CLIENT_VERSION_REVISION, 2)
define(_CLIENT_VERSION_PARTICL, 4)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_RC, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2021)
Expand Down
33 changes: 29 additions & 4 deletions src/wallet/rpchdwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9210,6 +9210,7 @@ static UniValue verifyrawtransaction(const JSONRPCRequest &request)
//{"redeemScript", RPCArg::Type::STR_HEX, /* default */ "", "(required for P2SH or P2WSH)"},
{"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The amount spent"},
{"amount_commitment", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The amount commitment spent"},
{"chainheight", RPCArg::Type::NUM, /* default */ "0x7FFFFFFF", "Height of prevout in chain, mempool height by default"},
},
},
},
Expand All @@ -9218,6 +9219,8 @@ static UniValue verifyrawtransaction(const JSONRPCRequest &request)
{
{"returndecoded", RPCArg::Type::BOOL, /* default */ "false", "Return the decoded txn as a json object."},
{"checkvalues", RPCArg::Type::BOOL, /* default */ "true", "Check amounts and amount commitments match up."},
{"checkoutputs", RPCArg::Type::BOOL, /* default */ "true", "Check tx attributes and outputs."},
{"particlmode", RPCArg::Type::BOOL, /* default */ "true", "Enforce particl tx versions."},
{"spendheight", RPCArg::Type::NUM, /* default */ "chainheight", "Height the tx is spent at, set to current chain height if not provided."},
},
"options"},
Expand Down Expand Up @@ -9254,6 +9257,8 @@ static UniValue verifyrawtransaction(const JSONRPCRequest &request)

bool return_decoded = false;
bool check_values = true;
bool check_outputs = true;
bool particl_mode = true;
int nSpendHeight = -1;
int64_t nSpendTime = 0;

Expand All @@ -9264,6 +9269,8 @@ static UniValue verifyrawtransaction(const JSONRPCRequest &request)
{
{"returndecoded", UniValueType(UniValue::VBOOL)},
{"checkvalues", UniValueType(UniValue::VBOOL)},
{"checkoutputs", UniValueType(UniValue::VBOOL)},
{"particlmode", UniValueType(UniValue::VBOOL)},
{"spendheight", UniValueType(UniValue::VNUM)},
}, true, false);

Expand All @@ -9273,6 +9280,12 @@ static UniValue verifyrawtransaction(const JSONRPCRequest &request)
if (options.exists("checkvalues")) {
check_values = options["checkvalues"].get_bool();
}
if (options.exists("checkoutputs")) {
check_outputs = options["checkoutputs"].get_bool();
}
if (options.exists("particlmode")) {
particl_mode = options["particlmode"].get_bool();
}
if (options.exists("spendheight")) {
nSpendHeight = options["spendheight"].get_int();
}
Expand Down Expand Up @@ -9367,7 +9380,19 @@ static UniValue verifyrawtransaction(const JSONRPCRequest &request)
throw JSONRPCError(RPC_INVALID_PARAMETER, "\"amount\" or \"amount_commitment\" is required");
}

newcoin.nHeight = 1;
if (!coin.IsSpent()) { // IsSpent is true if coin not found
newcoin.nHeight = coin.nHeight;
} else {
if (prevOut.exists("chainheight")) {
newcoin.nHeight = prevOut["chainheight"].get_int();
if (newcoin.nHeight < 1) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "\"chainheight\" Must be >= 1");
}
} else {
// Set to the same height as a tx in the mempool would be
newcoin.nHeight = 0x7FFFFFFF;
}
}
view.AddCoin(out, std::move(newcoin), true);
}
}
Expand Down Expand Up @@ -9398,9 +9423,9 @@ static UniValue verifyrawtransaction(const JSONRPCRequest &request)
const Consensus::Params& consensusParams = Params().GetConsensus();
UniValue result(UniValue::VOBJ);

{
if (check_outputs) {
TxValidationState state;
state.SetStateInfo(nSpendTime, nSpendHeight, consensusParams, true /* particl_mode */, false /* skip_rangeproof */);
state.SetStateInfo(nSpendTime, nSpendHeight, consensusParams, particl_mode, false /* skip_rangeproof */);
if (!CheckTransaction(txConst, state)) {
result.pushKV("outputs_valid", false);
vErrors.push_back("CheckTransaction: \"" + state.GetRejectReason() + "\"");
Expand All @@ -9411,7 +9436,7 @@ static UniValue verifyrawtransaction(const JSONRPCRequest &request)

if (check_values) {
TxValidationState state;
state.SetStateInfo(nSpendTime, nSpendHeight, consensusParams, true /* particl_mode */, false /* skip_rangeproof */);
state.SetStateInfo(nSpendTime, nSpendHeight, consensusParams, particl_mode, false /* skip_rangeproof */);
CAmount nFee = 0;
if (!Consensus::CheckTxInputs(txConst, state, view, nSpendHeight, nFee)) {
result.pushKV("inputs_valid", false);
Expand Down

0 comments on commit e1e6511

Please sign in to comment.