Migrate Zcash-specific code to UniValue
This commit is contained in:
@@ -29,16 +29,16 @@
|
||||
|
||||
using namespace libzcash;
|
||||
|
||||
int find_output(Object obj, int n) {
|
||||
Value outputMapValue = find_value(obj, "outputmap");
|
||||
if (outputMapValue.type() != array_type) {
|
||||
int find_output(UniValue obj, int n) {
|
||||
UniValue outputMapValue = find_value(obj, "outputmap");
|
||||
if (!outputMapValue.isArray()) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Missing outputmap for JoinSplit operation");
|
||||
}
|
||||
|
||||
Array outputMap = outputMapValue.get_array();
|
||||
UniValue outputMap = outputMapValue.get_array();
|
||||
assert(outputMap.size() == ZC_NUM_JS_OUTPUTS);
|
||||
for (size_t i = 0; i < outputMap.size(); i++) {
|
||||
if (outputMap[i] == n) {
|
||||
if (outputMap[i].get_int() == n) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
|
||||
std::vector<SendManyRecipient> zOutputs,
|
||||
int minDepth,
|
||||
CAmount fee,
|
||||
Value contextInfo) :
|
||||
UniValue contextInfo) :
|
||||
fromaddress_(fromAddress), t_outputs_(tOutputs), z_outputs_(zOutputs), mindepth_(minDepth), fee_(fee), contextinfo_(contextInfo)
|
||||
{
|
||||
assert(fee_ >= 0);
|
||||
@@ -94,7 +94,7 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
|
||||
|
||||
// Log the context info i.e. the call parameters to z_sendmany
|
||||
if (LogAcceptCategory("zrpcunsafe")) {
|
||||
LogPrint("zrpcunsafe", "%s: z_sendmany initialized (params=%s)\n", getId(), json_spirit::write_string( contextInfo, false));
|
||||
LogPrint("zrpcunsafe", "%s: z_sendmany initialized (params=%s)\n", getId(), contextInfo.write());
|
||||
} else {
|
||||
LogPrint("zrpc", "%s: z_sendmany initialized\n", getId());
|
||||
}
|
||||
@@ -114,7 +114,7 @@ void AsyncRPCOperation_sendmany::main() {
|
||||
|
||||
try {
|
||||
success = main_impl();
|
||||
} catch (const Object& objError) {
|
||||
} catch (const UniValue& objError) {
|
||||
int code = find_value(objError, "code").get_int();
|
||||
std::string message = find_value(objError, "message").get_str();
|
||||
set_error_code(code);
|
||||
@@ -307,7 +307,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
||||
);
|
||||
}
|
||||
|
||||
Object obj;
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("rawtxn", EncodeHexTx(tx_)));
|
||||
sign_send_raw_transaction(obj);
|
||||
return true;
|
||||
@@ -385,7 +385,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
||||
}
|
||||
|
||||
// Create joinsplits, where each output represents a zaddr recipient.
|
||||
Object obj;
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
while (zOutputsDeque.size() > 0) {
|
||||
AsyncJoinSplitInfo info;
|
||||
info.vpub_old = 0;
|
||||
@@ -434,7 +434,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
||||
* SCENARIO #3
|
||||
* Part 1: Add to the transparent value pool.
|
||||
*/
|
||||
Object obj;
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
CAmount jsChange = 0; // this is updated after each joinsplit
|
||||
int changeOutputIndex = -1; // this is updated after each joinsplit if jsChange > 0
|
||||
bool minersFeeProcessed = false;
|
||||
@@ -757,42 +757,47 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
||||
* Sign and send a raw transaction.
|
||||
* Raw transaction as hex string should be in object field "rawtxn"
|
||||
*/
|
||||
void AsyncRPCOperation_sendmany::sign_send_raw_transaction(Object obj)
|
||||
void AsyncRPCOperation_sendmany::sign_send_raw_transaction(UniValue obj)
|
||||
{
|
||||
// Sign the raw transaction
|
||||
Value rawtxnValue = find_value(obj, "rawtxn");
|
||||
if (rawtxnValue.is_null()) {
|
||||
UniValue rawtxnValue = find_value(obj, "rawtxn");
|
||||
if (rawtxnValue.isNull()) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Missing hex data for raw transaction");
|
||||
}
|
||||
std::string rawtxn = rawtxnValue.get_str();
|
||||
|
||||
Value signResultValue = signrawtransaction({Value(rawtxn)}, false);
|
||||
Object signResultObject = signResultValue.get_obj();
|
||||
Value completeValue = find_value(signResultObject, "complete");
|
||||
UniValue params = UniValue(UniValue::VARR);
|
||||
params.push_back(rawtxn);
|
||||
UniValue signResultValue = signrawtransaction(params, false);
|
||||
UniValue signResultObject = signResultValue.get_obj();
|
||||
UniValue completeValue = find_value(signResultObject, "complete");
|
||||
bool complete = completeValue.get_bool();
|
||||
if (!complete) {
|
||||
// TODO: #1366 Maybe get "errors" and print array vErrors into a string
|
||||
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Failed to sign transaction");
|
||||
}
|
||||
|
||||
Value hexValue = find_value(signResultObject, "hex");
|
||||
if (hexValue.is_null()) {
|
||||
UniValue hexValue = find_value(signResultObject, "hex");
|
||||
if (hexValue.isNull()) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Missing hex data for signed transaction");
|
||||
}
|
||||
std::string signedtxn = hexValue.get_str();
|
||||
|
||||
// Send the signed transaction
|
||||
if (!testmode) {
|
||||
Value sendResultValue = sendrawtransaction({Value(signedtxn)}, false);
|
||||
if (sendResultValue.is_null()) {
|
||||
params.clear();
|
||||
params.setArray();
|
||||
params.push_back(signedtxn);
|
||||
UniValue sendResultValue = sendrawtransaction(params, false);
|
||||
if (sendResultValue.isNull()) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Send raw transaction did not return an error or a txid.");
|
||||
}
|
||||
|
||||
std::string txid = sendResultValue.get_str();
|
||||
|
||||
Object o;
|
||||
UniValue o(UniValue::VOBJ);
|
||||
o.push_back(Pair("txid", txid));
|
||||
set_result(Value(o));
|
||||
set_result(o);
|
||||
} else {
|
||||
// Test mode does not send the transaction to the network.
|
||||
|
||||
@@ -800,11 +805,11 @@ void AsyncRPCOperation_sendmany::sign_send_raw_transaction(Object obj)
|
||||
CTransaction tx;
|
||||
stream >> tx;
|
||||
|
||||
Object o;
|
||||
UniValue o(UniValue::VOBJ);
|
||||
o.push_back(Pair("test", 1));
|
||||
o.push_back(Pair("txid", tx.GetHash().ToString()));
|
||||
o.push_back(Pair("hex", signedtxn));
|
||||
set_result(Value(o));
|
||||
set_result(o);
|
||||
}
|
||||
|
||||
// Keep the signed transaction so we can hash to the same txid
|
||||
@@ -891,7 +896,7 @@ bool AsyncRPCOperation_sendmany::find_unspent_notes() {
|
||||
return true;
|
||||
}
|
||||
|
||||
Object AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info) {
|
||||
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info) {
|
||||
std::vector<boost::optional < ZCIncrementalWitness>> witnesses;
|
||||
uint256 anchor;
|
||||
{
|
||||
@@ -902,7 +907,7 @@ Object AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info)
|
||||
}
|
||||
|
||||
|
||||
Object AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info, std::vector<JSOutPoint> & outPoints) {
|
||||
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info, std::vector<JSOutPoint> & outPoints) {
|
||||
std::vector<boost::optional < ZCIncrementalWitness>> witnesses;
|
||||
uint256 anchor;
|
||||
{
|
||||
@@ -912,7 +917,7 @@ Object AsyncRPCOperation_sendmany::perform_joinsplit(AsyncJoinSplitInfo & info,
|
||||
return perform_joinsplit(info, witnesses, anchor);
|
||||
}
|
||||
|
||||
Object AsyncRPCOperation_sendmany::perform_joinsplit(
|
||||
UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
|
||||
AsyncJoinSplitInfo & info,
|
||||
std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
|
||||
uint256 anchor)
|
||||
@@ -1033,8 +1038,8 @@ Object AsyncRPCOperation_sendmany::perform_joinsplit(
|
||||
encryptedNote2 = HexStr(ss2.begin(), ss2.end());
|
||||
}
|
||||
|
||||
Array arrInputMap;
|
||||
Array arrOutputMap;
|
||||
UniValue arrInputMap(UniValue::VARR);
|
||||
UniValue arrOutputMap(UniValue::VARR);
|
||||
for (size_t i = 0; i < ZC_NUM_JS_INPUTS; i++) {
|
||||
arrInputMap.push_back(inputMap[i]);
|
||||
}
|
||||
@@ -1042,7 +1047,7 @@ Object AsyncRPCOperation_sendmany::perform_joinsplit(
|
||||
arrOutputMap.push_back(outputMap[i]);
|
||||
}
|
||||
|
||||
Object obj;
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("encryptednote1", encryptedNote1));
|
||||
obj.push_back(Pair("encryptednote2", encryptedNote2));
|
||||
obj.push_back(Pair("rawtxn", HexStr(ss.begin(), ss.end())));
|
||||
@@ -1118,15 +1123,15 @@ boost::array<unsigned char, ZC_MEMO_SIZE> AsyncRPCOperation_sendmany::get_memo_f
|
||||
/**
|
||||
* Override getStatus() to append the operation's input parameters to the default status object.
|
||||
*/
|
||||
Value AsyncRPCOperation_sendmany::getStatus() const {
|
||||
Value v = AsyncRPCOperation::getStatus();
|
||||
if (contextinfo_.is_null()) {
|
||||
UniValue AsyncRPCOperation_sendmany::getStatus() const {
|
||||
UniValue v = AsyncRPCOperation::getStatus();
|
||||
if (contextinfo_.isNull()) {
|
||||
return v;
|
||||
}
|
||||
|
||||
Object obj = v.get_obj();
|
||||
UniValue obj = v.get_obj();
|
||||
obj.push_back(Pair("method", "z_sendmany"));
|
||||
obj.push_back(Pair("params", contextinfo_ ));
|
||||
return Value(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,17 +11,17 @@
|
||||
#include "primitives/transaction.h"
|
||||
#include "zcash/JoinSplit.hpp"
|
||||
#include "zcash/Address.hpp"
|
||||
#include "json/json_spirit_value.h"
|
||||
#include "wallet.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <tuple>
|
||||
|
||||
#include "univalue/univalue.h"
|
||||
|
||||
// Default transaction fee if caller does not specify one.
|
||||
#define ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE 10000
|
||||
|
||||
using namespace libzcash;
|
||||
using namespace json_spirit;
|
||||
|
||||
// A recipient is a tuple of address, amount, memo (optional if zaddr)
|
||||
typedef std::tuple<std::string, CAmount, std::string> SendManyRecipient;
|
||||
@@ -50,7 +50,7 @@ struct WitnessAnchorData {
|
||||
|
||||
class AsyncRPCOperation_sendmany : public AsyncRPCOperation {
|
||||
public:
|
||||
AsyncRPCOperation_sendmany(std::string fromAddress, std::vector<SendManyRecipient> tOutputs, std::vector<SendManyRecipient> zOutputs, int minDepth, CAmount fee = ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE, Value contextInfo = Value::null);
|
||||
AsyncRPCOperation_sendmany(std::string fromAddress, std::vector<SendManyRecipient> tOutputs, std::vector<SendManyRecipient> zOutputs, int minDepth, CAmount fee = ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE, UniValue contextInfo = NullUniValue);
|
||||
virtual ~AsyncRPCOperation_sendmany();
|
||||
|
||||
// We don't want to be copied or moved around
|
||||
@@ -61,14 +61,14 @@ public:
|
||||
|
||||
virtual void main();
|
||||
|
||||
virtual Value getStatus() const;
|
||||
virtual UniValue getStatus() const;
|
||||
|
||||
bool testmode = false; // Set to true to disable sending txs and generating proofs
|
||||
|
||||
private:
|
||||
friend class TEST_FRIEND_AsyncRPCOperation_sendmany; // class for unit testing
|
||||
|
||||
Value contextinfo_; // optional data to include in return value from getStatus()
|
||||
UniValue contextinfo_; // optional data to include in return value from getStatus()
|
||||
|
||||
CAmount fee_;
|
||||
int mindepth_;
|
||||
@@ -100,18 +100,18 @@ private:
|
||||
bool main_impl();
|
||||
|
||||
// JoinSplit without any input notes to spend
|
||||
Object perform_joinsplit(AsyncJoinSplitInfo &);
|
||||
UniValue perform_joinsplit(AsyncJoinSplitInfo &);
|
||||
|
||||
// JoinSplit with input notes to spend (JSOutPoints))
|
||||
Object perform_joinsplit(AsyncJoinSplitInfo &, std::vector<JSOutPoint> & );
|
||||
UniValue perform_joinsplit(AsyncJoinSplitInfo &, std::vector<JSOutPoint> & );
|
||||
|
||||
// JoinSplit where you have the witnesses and anchor
|
||||
Object perform_joinsplit(
|
||||
UniValue perform_joinsplit(
|
||||
AsyncJoinSplitInfo & info,
|
||||
std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
|
||||
uint256 anchor);
|
||||
|
||||
void sign_send_raw_transaction(Object obj); // throws exception if there was an error
|
||||
void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error
|
||||
|
||||
};
|
||||
|
||||
@@ -157,15 +157,15 @@ public:
|
||||
return delegate->main_impl();
|
||||
}
|
||||
|
||||
Object perform_joinsplit(AsyncJoinSplitInfo &info) {
|
||||
UniValue perform_joinsplit(AsyncJoinSplitInfo &info) {
|
||||
return delegate->perform_joinsplit(info);
|
||||
}
|
||||
|
||||
Object perform_joinsplit(AsyncJoinSplitInfo &info, std::vector<JSOutPoint> &v ) {
|
||||
UniValue perform_joinsplit(AsyncJoinSplitInfo &info, std::vector<JSOutPoint> &v ) {
|
||||
return delegate->perform_joinsplit(info, v);
|
||||
}
|
||||
|
||||
Object perform_joinsplit(
|
||||
UniValue perform_joinsplit(
|
||||
AsyncJoinSplitInfo & info,
|
||||
std::vector<boost::optional < ZCIncrementalWitness>> witnesses,
|
||||
uint256 anchor)
|
||||
@@ -173,7 +173,7 @@ public:
|
||||
return delegate->perform_joinsplit(info, witnesses, anchor);
|
||||
}
|
||||
|
||||
void sign_send_raw_transaction(Object obj) {
|
||||
void sign_send_raw_transaction(UniValue obj) {
|
||||
delegate->sign_send_raw_transaction(obj);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ using namespace std;
|
||||
void EnsureWalletIsUnlocked();
|
||||
bool EnsureWalletIsAvailable(bool avoidException);
|
||||
|
||||
Value dumpwallet_impl(const Array& params, bool fHelp, bool fDumpZKeys);
|
||||
Value importwallet_impl(const Array& params, bool fHelp, bool fImportZKeys);
|
||||
UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys);
|
||||
UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys);
|
||||
|
||||
|
||||
std::string static EncodeDumpTime(int64_t nTime) {
|
||||
@@ -220,10 +220,10 @@ UniValue importaddress(const UniValue& params, bool fHelp)
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
Value z_importwallet(const Array& params, bool fHelp)
|
||||
UniValue z_importwallet(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
@@ -266,7 +266,7 @@ UniValue importwallet(const UniValue& params, bool fHelp)
|
||||
return importwallet_impl(params, fHelp, false);
|
||||
}
|
||||
|
||||
Value importwallet_impl(const Array& params, bool fHelp, bool fImportZKeys)
|
||||
UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys)
|
||||
{
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
@@ -419,10 +419,10 @@ UniValue dumpprivkey(const UniValue& params, bool fHelp)
|
||||
|
||||
|
||||
|
||||
Value z_exportwallet(const Array& params, bool fHelp)
|
||||
UniValue z_exportwallet(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
@@ -461,7 +461,7 @@ UniValue dumpwallet(const UniValue& params, bool fHelp)
|
||||
return dumpwallet_impl(params, fHelp, false);
|
||||
}
|
||||
|
||||
Value dumpwallet_impl(const Array& params, bool fHelp, bool fDumpZKeys)
|
||||
UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys)
|
||||
{
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
@@ -547,10 +547,10 @@ Value dumpwallet_impl(const Array& params, bool fHelp, bool fDumpZKeys)
|
||||
}
|
||||
|
||||
|
||||
Value z_importkey(const Array& params, bool fHelp)
|
||||
UniValue z_importkey(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||
throw runtime_error(
|
||||
@@ -586,7 +586,7 @@ Value z_importkey(const Array& params, bool fHelp)
|
||||
{
|
||||
// Don't throw error in case a key is already there
|
||||
if (pwalletMain->HaveSpendingKey(addr))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
pwalletMain->MarkDirty();
|
||||
|
||||
@@ -604,14 +604,14 @@ Value z_importkey(const Array& params, bool fHelp)
|
||||
}
|
||||
}
|
||||
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
|
||||
Value z_exportkey(const Array& params, bool fHelp)
|
||||
UniValue z_exportkey(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
|
||||
@@ -39,13 +39,13 @@ using namespace std;
|
||||
|
||||
using namespace libzcash;
|
||||
|
||||
extern Array TxJoinSplitToJSON(const CTransaction& tx);
|
||||
extern UniValue TxJoinSplitToJSON(const CTransaction& tx);
|
||||
|
||||
int64_t nWalletUnlockTime;
|
||||
static CCriticalSection cs_nWalletUnlockTime;
|
||||
|
||||
// Private method:
|
||||
Value z_getoperationstatus_IMPL(const Array&, bool);
|
||||
UniValue z_getoperationstatus_IMPL(const UniValue&, bool);
|
||||
|
||||
std::string HelpRequiringPassphrase()
|
||||
{
|
||||
@@ -2413,7 +2413,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
||||
return results;
|
||||
}
|
||||
|
||||
Value zc_sample_joinsplit(const json_spirit::Array& params, bool fHelp)
|
||||
UniValue zc_sample_joinsplit(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp) {
|
||||
throw runtime_error(
|
||||
@@ -2441,10 +2441,10 @@ Value zc_sample_joinsplit(const json_spirit::Array& params, bool fHelp)
|
||||
return HexStr(ss.begin(), ss.end());
|
||||
}
|
||||
|
||||
Value zc_benchmark(const json_spirit::Array& params, bool fHelp)
|
||||
UniValue zc_benchmark(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp)) {
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
if (fHelp || params.size() < 2) {
|
||||
@@ -2532,9 +2532,9 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp)
|
||||
}
|
||||
}
|
||||
|
||||
Array results;
|
||||
UniValue results(UniValue::VARR);
|
||||
for (auto time : sample_times) {
|
||||
Object result;
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("runningtime", time));
|
||||
results.push_back(result);
|
||||
}
|
||||
@@ -2542,10 +2542,10 @@ Value zc_benchmark(const json_spirit::Array& params, bool fHelp)
|
||||
return results;
|
||||
}
|
||||
|
||||
Value zc_raw_receive(const json_spirit::Array& params, bool fHelp)
|
||||
UniValue zc_raw_receive(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp)) {
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
if (fHelp || params.size() != 2) {
|
||||
@@ -2563,7 +2563,7 @@ Value zc_raw_receive(const json_spirit::Array& params, bool fHelp)
|
||||
);
|
||||
}
|
||||
|
||||
RPCTypeCheck(params, boost::assign::list_of(str_type)(str_type));
|
||||
RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VSTR));
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
@@ -2614,7 +2614,7 @@ Value zc_raw_receive(const json_spirit::Array& params, bool fHelp)
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss << npt;
|
||||
|
||||
Object result;
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("amount", ValueFromAmount(decrypted_note.value)));
|
||||
result.push_back(Pair("note", HexStr(ss.begin(), ss.end())));
|
||||
result.push_back(Pair("exists", (bool) witnesses[0]));
|
||||
@@ -2623,10 +2623,10 @@ Value zc_raw_receive(const json_spirit::Array& params, bool fHelp)
|
||||
|
||||
|
||||
|
||||
Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
|
||||
UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp)) {
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
if (fHelp || params.size() != 5) {
|
||||
@@ -2659,8 +2659,8 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
|
||||
if (!DecodeHexTx(tx, params[0].get_str()))
|
||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
|
||||
|
||||
Object inputs = params[1].get_obj();
|
||||
Object outputs = params[2].get_obj();
|
||||
UniValue inputs = params[1].get_obj();
|
||||
UniValue outputs = params[2].get_obj();
|
||||
|
||||
CAmount vpub_old(0);
|
||||
CAmount vpub_new(0);
|
||||
@@ -2677,9 +2677,8 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
|
||||
std::vector<SpendingKey> keys;
|
||||
std::vector<uint256> commitments;
|
||||
|
||||
BOOST_FOREACH(const Pair& s, inputs)
|
||||
{
|
||||
CZCSpendingKey spendingkey(s.value_.get_str());
|
||||
for (const string& name_ : inputs.getKeys()) {
|
||||
CZCSpendingKey spendingkey(inputs[name_].get_str());
|
||||
SpendingKey k = spendingkey.Get();
|
||||
|
||||
keys.push_back(k);
|
||||
@@ -2687,7 +2686,7 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
|
||||
NotePlaintext npt;
|
||||
|
||||
{
|
||||
CDataStream ssData(ParseHexV(s.name_, "note"), SER_NETWORK, PROTOCOL_VERSION);
|
||||
CDataStream ssData(ParseHexV(name_, "note"), SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssData >> npt;
|
||||
}
|
||||
|
||||
@@ -2720,11 +2719,10 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
|
||||
vjsin.push_back(JSInput());
|
||||
}
|
||||
|
||||
BOOST_FOREACH(const Pair& s, outputs)
|
||||
{
|
||||
CZCPaymentAddress pubaddr(s.name_);
|
||||
for (const string& name_ : outputs.getKeys()) {
|
||||
CZCPaymentAddress pubaddr(name_);
|
||||
PaymentAddress addrTo = pubaddr.Get();
|
||||
CAmount nAmount = AmountFromValue(s.value_);
|
||||
CAmount nAmount = AmountFromValue(outputs[name_]);
|
||||
|
||||
vjsout.push_back(JSOutput(addrTo, nAmount));
|
||||
}
|
||||
@@ -2804,17 +2802,17 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
|
||||
encryptedNote2 = HexStr(ss2.begin(), ss2.end());
|
||||
}
|
||||
|
||||
Object result;
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("encryptednote1", encryptedNote1));
|
||||
result.push_back(Pair("encryptednote2", encryptedNote2));
|
||||
result.push_back(Pair("rawtxn", HexStr(ss.begin(), ss.end())));
|
||||
return result;
|
||||
}
|
||||
|
||||
Value zc_raw_keygen(const json_spirit::Array& params, bool fHelp)
|
||||
UniValue zc_raw_keygen(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp)) {
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
if (fHelp || params.size() != 0) {
|
||||
@@ -2842,7 +2840,7 @@ Value zc_raw_keygen(const json_spirit::Array& params, bool fHelp)
|
||||
CZCSpendingKey spendingkey(k);
|
||||
std::string viewing_hex = HexStr(viewing.begin(), viewing.end());
|
||||
|
||||
Object result;
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("zcaddress", pubaddr.ToString()));
|
||||
result.push_back(Pair("zcsecretkey", spendingkey.ToString()));
|
||||
result.push_back(Pair("zcviewingkey", viewing_hex));
|
||||
@@ -2850,10 +2848,10 @@ Value zc_raw_keygen(const json_spirit::Array& params, bool fHelp)
|
||||
}
|
||||
|
||||
|
||||
Value z_getnewaddress(const Array& params, bool fHelp)
|
||||
UniValue z_getnewaddress(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() > 0)
|
||||
throw runtime_error(
|
||||
@@ -2877,10 +2875,10 @@ Value z_getnewaddress(const Array& params, bool fHelp)
|
||||
}
|
||||
|
||||
|
||||
Value z_listaddresses(const Array& params, bool fHelp)
|
||||
UniValue z_listaddresses(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
@@ -2899,7 +2897,7 @@ Value z_listaddresses(const Array& params, bool fHelp)
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
Array ret;
|
||||
UniValue ret(UniValue::VARR);
|
||||
std::set<libzcash::PaymentAddress> addresses;
|
||||
pwalletMain->GetPaymentAddresses(addresses);
|
||||
for (auto addr : addresses ) {
|
||||
@@ -2959,10 +2957,10 @@ CAmount getBalanceZaddr(std::string address, int minDepth = 1) {
|
||||
}
|
||||
|
||||
|
||||
Value z_listreceivedbyaddress(const Array& params, bool fHelp)
|
||||
UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size()==0 || params.size() >2)
|
||||
throw runtime_error(
|
||||
@@ -3005,11 +3003,11 @@ Value z_listreceivedbyaddress(const Array& params, bool fHelp)
|
||||
}
|
||||
|
||||
|
||||
Array result;
|
||||
UniValue result(UniValue::VARR);
|
||||
std::vector<CNotePlaintextEntry> entries;
|
||||
pwalletMain->GetFilteredNotes(entries, fromaddress, nMinDepth, false);
|
||||
for (CNotePlaintextEntry & entry : entries) {
|
||||
Object obj;
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("txid",entry.jsop.hash.ToString()));
|
||||
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value))));
|
||||
std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end());
|
||||
@@ -3020,10 +3018,10 @@ Value z_listreceivedbyaddress(const Array& params, bool fHelp)
|
||||
}
|
||||
|
||||
|
||||
Value z_getbalance(const Array& params, bool fHelp)
|
||||
UniValue z_getbalance(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size()==0 || params.size() >2)
|
||||
throw runtime_error(
|
||||
@@ -3082,10 +3080,10 @@ Value z_getbalance(const Array& params, bool fHelp)
|
||||
}
|
||||
|
||||
|
||||
Value z_gettotalbalance(const Array& params, bool fHelp)
|
||||
UniValue z_gettotalbalance(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
@@ -3125,17 +3123,17 @@ Value z_gettotalbalance(const Array& params, bool fHelp)
|
||||
CAmount nBalance = getBalanceTaddr("", nMinDepth);
|
||||
CAmount nPrivateBalance = getBalanceZaddr("", nMinDepth);
|
||||
CAmount nTotalBalance = nBalance + nPrivateBalance;
|
||||
Object result;
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("transparent", FormatMoney(nBalance, false)));
|
||||
result.push_back(Pair("private", FormatMoney(nPrivateBalance, false)));
|
||||
result.push_back(Pair("total", FormatMoney(nTotalBalance, false)));
|
||||
return result;
|
||||
}
|
||||
|
||||
Value z_getoperationresult(const Array& params, bool fHelp)
|
||||
UniValue z_getoperationresult(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
@@ -3152,10 +3150,10 @@ Value z_getoperationresult(const Array& params, bool fHelp)
|
||||
return z_getoperationstatus_IMPL(params, true);
|
||||
}
|
||||
|
||||
Value z_getoperationstatus(const Array& params, bool fHelp)
|
||||
UniValue z_getoperationstatus(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
@@ -3172,20 +3170,20 @@ Value z_getoperationstatus(const Array& params, bool fHelp)
|
||||
return z_getoperationstatus_IMPL(params, false);
|
||||
}
|
||||
|
||||
Value z_getoperationstatus_IMPL(const Array& params, bool fRemoveFinishedOperations=false)
|
||||
UniValue z_getoperationstatus_IMPL(const UniValue& params, bool fRemoveFinishedOperations=false)
|
||||
{
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
|
||||
std::set<AsyncRPCOperationId> filter;
|
||||
if (params.size()==1) {
|
||||
Array ids = params[0].get_array();
|
||||
for (Value & v : ids) {
|
||||
UniValue ids = params[0].get_array();
|
||||
for (UniValue & v : ids.getValues()) {
|
||||
filter.insert(v.get_str());
|
||||
}
|
||||
}
|
||||
bool useFilter = (filter.size()>0);
|
||||
|
||||
Array ret;
|
||||
UniValue ret(UniValue::VARR);
|
||||
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
|
||||
std::vector<AsyncRPCOperationId> ids = q->getAllOperationIds();
|
||||
|
||||
@@ -3200,7 +3198,7 @@ Value z_getoperationstatus_IMPL(const Array& params, bool fRemoveFinishedOperati
|
||||
// throw JSONRPCError(RPC_INVALID_PARAMETER, "No operation exists for that id.");
|
||||
}
|
||||
|
||||
Value status = operation->getStatus();
|
||||
UniValue status = operation->getStatus();
|
||||
|
||||
if (fRemoveFinishedOperations) {
|
||||
// Caller is only interested in retrieving finished results
|
||||
@@ -3213,13 +3211,19 @@ Value z_getoperationstatus_IMPL(const Array& params, bool fRemoveFinishedOperati
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<UniValue> arrTmp = ret.getValues();
|
||||
|
||||
// sort results chronologically by creation_time
|
||||
std::sort(ret.begin(), ret.end(), [](Value a, Value b) -> bool {
|
||||
std::sort(arrTmp.begin(), arrTmp.end(), [](UniValue a, UniValue b) -> bool {
|
||||
const int64_t t1 = find_value(a.get_obj(), "creation_time").get_int64();
|
||||
const int64_t t2 = find_value(b.get_obj(), "creation_time").get_int64();
|
||||
return t1 < t2;
|
||||
});
|
||||
|
||||
ret.clear();
|
||||
ret.setArray();
|
||||
ret.push_backV(arrTmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -3234,10 +3238,10 @@ Value z_getoperationstatus_IMPL(const Array& params, bool fRemoveFinishedOperati
|
||||
#define CTXIN_SPEND_DUST_SIZE 148
|
||||
#define CTXOUT_REGULAR_SIZE 34
|
||||
|
||||
Value z_sendmany(const Array& params, bool fHelp)
|
||||
UniValue z_sendmany(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() < 2 || params.size() > 4)
|
||||
throw runtime_error(
|
||||
@@ -3287,7 +3291,7 @@ Value z_sendmany(const Array& params, bool fHelp)
|
||||
}
|
||||
}
|
||||
|
||||
Array outputs = params[1].get_array();
|
||||
UniValue outputs = params[1].get_array();
|
||||
|
||||
if (outputs.size()==0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, amounts array is empty.");
|
||||
@@ -3300,15 +3304,13 @@ Value z_sendmany(const Array& params, bool fHelp)
|
||||
std::vector<SendManyRecipient> zaddrRecipients;
|
||||
CAmount nTotalOut = 0;
|
||||
|
||||
BOOST_FOREACH(Value& output, outputs)
|
||||
{
|
||||
if (output.type() != obj_type)
|
||||
for (const UniValue& o : outputs.getValues()) {
|
||||
if (!o.isObject())
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected object");
|
||||
const Object& o = output.get_obj();
|
||||
|
||||
// sanity check, report error if unknown key-value pairs
|
||||
for (const Pair& p : o) {
|
||||
std::string s = p.name_;
|
||||
for (const string& name_ : o.getKeys()) {
|
||||
std::string s = name_;
|
||||
if (s != "address" && s != "amount" && s!="memo")
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown key: ")+s);
|
||||
}
|
||||
@@ -3330,9 +3332,9 @@ Value z_sendmany(const Array& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+address);
|
||||
setAddress.insert(address);
|
||||
|
||||
Value memoValue = find_value(o, "memo");
|
||||
UniValue memoValue = find_value(o, "memo");
|
||||
string memo;
|
||||
if (!memoValue.is_null()) {
|
||||
if (!memoValue.isNull()) {
|
||||
memo = memoValue.get_str();
|
||||
if (!isZaddr) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Memo can not be used with a taddr. It can only be used with a zaddr.");
|
||||
@@ -3344,7 +3346,7 @@ Value z_sendmany(const Array& params, bool fHelp)
|
||||
}
|
||||
}
|
||||
|
||||
Value av = find_value(o, "amount");
|
||||
UniValue av = find_value(o, "amount");
|
||||
CAmount nAmount = AmountFromValue( av );
|
||||
if (nAmount < 0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, amount must be positive");
|
||||
@@ -3407,12 +3409,12 @@ Value z_sendmany(const Array& params, bool fHelp)
|
||||
}
|
||||
|
||||
// Use input parameters as the optional context info to be returned by z_getoperationstatus and z_getoperationresult.
|
||||
Object o;
|
||||
UniValue o(UniValue::VOBJ);
|
||||
o.push_back(Pair("fromaddress", params[0]));
|
||||
o.push_back(Pair("amounts", params[1]));
|
||||
o.push_back(Pair("minconf", nMinDepth));
|
||||
o.push_back(Pair("fee", std::stod(FormatMoney(nFee))));
|
||||
Value contextInfo = Value(o);
|
||||
UniValue contextInfo = o;
|
||||
|
||||
// Create operation and add to global queue
|
||||
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
|
||||
@@ -3423,10 +3425,10 @@ Value z_sendmany(const Array& params, bool fHelp)
|
||||
}
|
||||
|
||||
|
||||
Value z_listoperationids(const Array& params, bool fHelp)
|
||||
UniValue z_listoperationids(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return Value::null;
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
@@ -3453,7 +3455,7 @@ Value z_listoperationids(const Array& params, bool fHelp)
|
||||
useFilter = true;
|
||||
}
|
||||
|
||||
Array ret;
|
||||
UniValue ret(UniValue::VARR);
|
||||
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
|
||||
std::vector<AsyncRPCOperationId> ids = q->getAllOperationIds();
|
||||
for (auto id : ids) {
|
||||
|
||||
Reference in New Issue
Block a user