The first part of their function has a more elaborate and accurate error message and explanation about the JSON inputs/outputs. We could do well to imitate this, having informative error messages is important.
// use a dummy coins view to store the user provided transaction inputs
CCoinsView viewDummyTemp;
CCoinsViewCache viewTemp(&viewDummyTemp);
if (request.params.size() > 1) {
std::vector<PrevTxsEntry> prevTxsParsed = ParsePrevTxs(request.params[1]);
InputsToView(prevTxsParsed, viewTemp);
}
int blockHeight = 0;
if (request.params.size() > 2) {
blockHeight = request.params[2].get_int();
}
UniValue txObj(UniValue::VOBJ);
int populateResult = -3331;
{
LOCK2(cs_main, cs_tx_cache);
// temporarily switch global coins view cache for transaction inputs
std::swap(view, viewTemp);
// then get the results
populateResult = populateRPCTransactionObject(tx, uint256(), txObj, "", false, "", blockHeight, pWallet.get());
// and restore the original, unpolluted coins view cache
std::swap(viewTemp, view);
}
if (populateResult != 0) PopulateFailure(populateResult);
return txObj;
}
Basically identical to our code except for two things we commented. The block height part deals with the parameter that parses the tx according to the rules of a past block but defaults to the present block. The Swap part is taking UXTO info out of memory so people don't have to provide that in the parameter. We need to troubleshoot our issue there to make this work for us.
Here's what Omni does with this:
The first part of their function has a more elaborate and accurate error message and explanation about the JSON inputs/outputs. We could do well to imitate this, having informative error messages is important.
Then:
CTransaction tx = ParseTransaction(request.params[0]);
}
Basically identical to our code except for two things we commented. The block height part deals with the parameter that parses the tx according to the rules of a past block but defaults to the present block. The Swap part is taking UXTO info out of memory so people don't have to provide that in the parameter. We need to troubleshoot our issue there to make this work for us.