Browse Source

Migrate Zcash-specific code to UniValue

v1.0.9-lin
Jack Grigg 7 years ago
parent
commit
0d37ae3a59
No known key found for this signature in database GPG Key ID: 6A6914DAFBEA00DA
  1. 1
      src/Makefile.gtest.include
  2. 39
      src/asyncrpcoperation.cpp
  3. 16
      src/asyncrpcoperation.h
  4. 8
      src/gtest/json_test_vectors.cpp
  5. 7
      src/gtest/json_test_vectors.h
  6. 17
      src/gtest/test_jsonspirit.cpp
  7. 34
      src/gtest/test_merkletree.cpp
  8. 8
      src/gtest/test_proofs.cpp
  9. 9
      src/gtest/test_rpc.cpp
  10. 10
      src/rpcblockchain.cpp
  11. 12
      src/rpcmining.cpp
  12. 4
      src/rpcmisc.cpp
  13. 16
      src/rpcrawtransaction.cpp
  14. 1
      src/test/alert_tests.cpp
  15. 86
      src/test/rpc_wallet_tests.cpp
  16. 77
      src/wallet/asyncrpcoperation_sendmany.cpp
  17. 26
      src/wallet/asyncrpcoperation_sendmany.h
  18. 28
      src/wallet/rpcdump.cpp
  19. 138
      src/wallet/rpcwallet.cpp

1
src/Makefile.gtest.include

@ -18,7 +18,6 @@ zcash_gtest_SOURCES += \
wallet/gtest/test_wallet_zkeys.cpp
endif
zcash_gtest_SOURCES += \
gtest/test_jsonspirit.cpp \
gtest/test_tautology.cpp \
gtest/test_equihash.cpp \
gtest/test_joinsplit.cpp \

39
src/asyncrpcoperation.cpp

@ -13,7 +13,6 @@
#include <chrono>
using namespace std;
using namespace json_spirit;
static boost::uuids::random_generator uuidgen;
@ -109,34 +108,34 @@ void AsyncRPCOperation::main() {
*/
// Otherwise, if the operation was a success:
Value v("We have a result!");
UniValue v(UniValue::VSTR, "We have a result!");
set_result(v);
set_state(OperationStatus::SUCCESS);
}
/**
* Return the error of the completed operation as a Value object.
* If there is no error, return null Value.
* Return the error of the completed operation as a UniValue object.
* If there is no error, return null UniValue.
*/
Value AsyncRPCOperation::getError() const {
UniValue AsyncRPCOperation::getError() const {
if (!isFailed()) {
return Value::null;
return NullUniValue;
}
std::lock_guard<std::mutex> guard(lock_);
Object error;
UniValue error(UniValue::VOBJ);
error.push_back(Pair("code", this->error_code_));
error.push_back(Pair("message", this->error_message_));
return Value(error);
return error;
}
/**
* Return the result of the completed operation as a Value object.
* If the operation did not succeed, return null Value.
* Return the result of the completed operation as a UniValue object.
* If the operation did not succeed, return null UniValue.
*/
Value AsyncRPCOperation::getResult() const {
UniValue AsyncRPCOperation::getResult() const {
if (!isSuccess()) {
return Value::null;
return NullUniValue;
}
std::lock_guard<std::mutex> guard(lock_);
@ -145,24 +144,24 @@ Value AsyncRPCOperation::getResult() const {
/**
* Returns a status Value object.
* Returns a status UniValue object.
* If the operation has failed, it will include an error object.
* If the operation has succeeded, it will include the result value.
* If the operation was cancelled, there will be no error object or result value.
*/
Value AsyncRPCOperation::getStatus() const {
UniValue AsyncRPCOperation::getStatus() const {
OperationStatus status = this->getState();
Object obj;
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("id", this->id_));
obj.push_back(Pair("status", OperationStatusMap[status]));
obj.push_back(Pair("creation_time", this->creation_time_));
// TODO: Issue #1354: There may be other useful metadata to return to the user.
Value err = this->getError();
if (!err.is_null()) {
UniValue err = this->getError();
if (!err.isNull()) {
obj.push_back(Pair("error", err.get_obj()));
}
Value result = this->getResult();
if (!result.is_null()) {
UniValue result = this->getResult();
if (!result.isNull()) {
obj.push_back(Pair("result", result));
// Include execution time for successful operation
@ -170,7 +169,7 @@ Value AsyncRPCOperation::getStatus() const {
obj.push_back(Pair("execution_secs", elapsed_seconds.count()));
}
return Value(obj);
return obj;
}
/**

16
src/asyncrpcoperation.h

@ -15,13 +15,9 @@
#include <utility>
#include <future>
#include "json/json_spirit_value.h"
#include "json/json_spirit_utils.h"
#include "json/json_spirit_reader_template.h"
#include "json/json_spirit_writer_template.h"
#include "univalue/univalue.h"
using namespace std;
using namespace json_spirit;
/**
* AsyncRPCOperation objects are submitted to the AsyncRPCQueue for processing.
@ -67,11 +63,11 @@ public:
}
// Override this method to add data to the default status object.
virtual Value getStatus() const;
virtual UniValue getStatus() const;
Value getError() const;
UniValue getError() const;
Value getResult() const;
UniValue getResult() const;
std::string getStateAsString() const;
@ -114,7 +110,7 @@ protected:
// internal state. Currently, all operations are executed in a single-thread
// by a single worker.
mutable std::mutex lock_; // lock on this when read/writing non-atomics
Value result_;
UniValue result_;
int error_code_;
std::string error_message_;
std::atomic<OperationStatus> state_;
@ -137,7 +133,7 @@ protected:
this->error_message_ = errorMessage;
}
void set_result(Value v) {
void set_result(UniValue v) {
std::lock_guard<std::mutex> guard(lock_);
this->result_ = v;
}

8
src/gtest/json_test_vectors.cpp

@ -1,14 +1,14 @@
#include "json_test_vectors.h"
Array
UniValue
read_json(const std::string& jsondata)
{
Value v;
UniValue v;
if (!read_string(jsondata, v) || v.type() != array_type)
if (!(v.read(jsondata) && v.isArray()))
{
ADD_FAILURE();
return Array();
return UniValue(UniValue::VARR);
}
return v.get_array();
}

7
src/gtest/json_test_vectors.h

@ -5,12 +5,9 @@
#include "serialize.h"
#include "streams.h"
#include "json/json_spirit_reader_template.h"
#include "json/json_spirit_utils.h"
#include "json/json_spirit_writer_template.h"
#include "univalue/univalue.h"
using namespace json_spirit;
Array
UniValue
read_json(const std::string& jsondata);
// #define PRINT_JSON 1

17
src/gtest/test_jsonspirit.cpp

@ -1,17 +0,0 @@
#include <gtest/gtest.h>
#include "json/json_spirit_reader_template.h"
using namespace json_spirit;
// This test checks if we have fixed a stack overflow problem with json_spirit.
// It was possible to try and create an unlimited number of nested compound elements.
// Without the fix in json_spirit_reader_template.h, this test will segfault.
TEST(json_spirit_tests, nested_input_segfault) {
std::vector<char> v (100000);
std::fill (v.begin(),v.end(), '[');
std::string s(v.begin(), v.end());
Value value;
bool b = json_spirit::read_string(s, value);
ASSERT_FALSE(b);
}

34
src/gtest/test_merkletree.cpp

@ -57,18 +57,18 @@ void expect_ser_test_vector(B& b, const C& c, const A& tree) {
template<typename Tree, typename Witness>
void test_tree(
Array commitment_tests,
Array root_tests,
Array ser_tests,
Array witness_ser_tests,
Array path_tests
UniValue commitment_tests,
UniValue root_tests,
UniValue ser_tests,
UniValue witness_ser_tests,
UniValue path_tests
)
{
Array::iterator commitment_iterator = commitment_tests.begin();
Array::iterator root_iterator = root_tests.begin();
Array::iterator ser_iterator = ser_tests.begin();
Array::iterator witness_ser_iterator = witness_ser_tests.begin();
Array::iterator path_iterator = path_tests.begin();
vector<UniValue>::iterator commitment_iterator = commitment_tests.getValues().begin();
vector<UniValue>::iterator root_iterator = root_tests.getValues().begin();
vector<UniValue>::iterator ser_iterator = ser_tests.getValues().begin();
vector<UniValue>::iterator witness_ser_iterator = witness_ser_tests.getValues().begin();
vector<UniValue>::iterator path_iterator = path_tests.getValues().begin();
Tree tree;
@ -193,18 +193,18 @@ void test_tree(
}
TEST(merkletree, vectors) {
Array root_tests = read_json(std::string(json_tests::merkle_roots, json_tests::merkle_roots + sizeof(json_tests::merkle_roots)));
Array ser_tests = read_json(std::string(json_tests::merkle_serialization, json_tests::merkle_serialization + sizeof(json_tests::merkle_serialization)));
Array witness_ser_tests = read_json(std::string(json_tests::merkle_witness_serialization, json_tests::merkle_witness_serialization + sizeof(json_tests::merkle_witness_serialization)));
Array path_tests = read_json(std::string(json_tests::merkle_path, json_tests::merkle_path + sizeof(json_tests::merkle_path)));
Array commitment_tests = read_json(std::string(json_tests::merkle_commitments, json_tests::merkle_commitments + sizeof(json_tests::merkle_commitments)));
UniValue root_tests = read_json(std::string(json_tests::merkle_roots, json_tests::merkle_roots + sizeof(json_tests::merkle_roots)));
UniValue ser_tests = read_json(std::string(json_tests::merkle_serialization, json_tests::merkle_serialization + sizeof(json_tests::merkle_serialization)));
UniValue witness_ser_tests = read_json(std::string(json_tests::merkle_witness_serialization, json_tests::merkle_witness_serialization + sizeof(json_tests::merkle_witness_serialization)));
UniValue path_tests = read_json(std::string(json_tests::merkle_path, json_tests::merkle_path + sizeof(json_tests::merkle_path)));
UniValue commitment_tests = read_json(std::string(json_tests::merkle_commitments, json_tests::merkle_commitments + sizeof(json_tests::merkle_commitments)));
test_tree<ZCTestingIncrementalMerkleTree, ZCTestingIncrementalWitness>(commitment_tests, root_tests, ser_tests, witness_ser_tests, path_tests);
}
TEST(merkletree, emptyroots) {
Array empty_roots = read_json(std::string(json_tests::merkle_roots_empty, json_tests::merkle_roots_empty + sizeof(json_tests::merkle_roots_empty)));
Array::iterator root_iterator = empty_roots.begin();
UniValue empty_roots = read_json(std::string(json_tests::merkle_roots_empty, json_tests::merkle_roots_empty + sizeof(json_tests::merkle_roots_empty)));
vector<UniValue>::iterator root_iterator = empty_roots.getValues().begin();
libzcash::EmptyMerkleRoots<64, libzcash::SHA256Compress> emptyroots;

8
src/gtest/test_proofs.cpp

@ -629,8 +629,8 @@ TEST(proofs, g2_deserialization)
TEST(proofs, g1_test_vectors)
{
Array v = read_json(std::string(json_tests::g1_compressed, json_tests::g1_compressed + sizeof(json_tests::g1_compressed)));
Array::iterator v_iterator = v.begin();
UniValue v = read_json(std::string(json_tests::g1_compressed, json_tests::g1_compressed + sizeof(json_tests::g1_compressed)));
std::vector<UniValue>::iterator v_iterator = v.getValues().begin();
curve_G1 e = curve_Fr("34958239045823") * curve_G1::one();
for (size_t i = 0; i < 10000; i++) {
@ -646,8 +646,8 @@ TEST(proofs, g1_test_vectors)
TEST(proofs, g2_test_vectors)
{
Array v = read_json(std::string(json_tests::g2_compressed, json_tests::g2_compressed + sizeof(json_tests::g2_compressed)));
Array::iterator v_iterator = v.begin();
UniValue v = read_json(std::string(json_tests::g2_compressed, json_tests::g2_compressed + sizeof(json_tests::g2_compressed)));
std::vector<UniValue>::iterator v_iterator = v.getValues().begin();
curve_G2 e = curve_Fr("34958239045823") * curve_G2::one();
for (size_t i = 0; i < 10000; i++) {

9
src/gtest/test_rpc.cpp

@ -1,6 +1,5 @@
#include <gtest/gtest.h>
#include "json/json_spirit_value.h"
#include "json/json_spirit_utils.h"
#include "univalue/univalue.h"
#include "chain.h"
#include "chainparams.h"
@ -10,7 +9,7 @@
#include "streams.h"
#include "utilstrencodings.h"
extern json_spirit::Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false);
extern UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false);
TEST(rpc, check_blockToJSON_returns_minified_solution) {
SelectParams(CBaseChainParams::TESTNET);
@ -24,6 +23,6 @@ TEST(rpc, check_blockToJSON_returns_minified_solution) {
CBlockIndex index {block};
index.nHeight = 1391;
json_spirit::Object obj = blockToJSON(block, &index);
EXPECT_EQ("009f44ff7505d789b964d6817734b8ce1377d456255994370d06e59ac99bd5791b6ad174a66fd71c70e60cfc7fd88243ffe06f80b1ad181625f210779c745524629448e25348a5fce4f346a1735e60fdf53e144c0157dbc47c700a21a236f1efb7ee75f65b8d9d9e29026cfd09048233175202b211b9a49de4ab46f1cac71b6ea57a686377bd612378746e70c61a659c9cd683269e9c2a5cbc1d19f1149345302bbd0a1e62bf4bab01e9caeea789a1519441a61b146de35a4cc75dbdf01029127e311ad5073e7e96397f47226a7df9df66b2086b70756db013bbaeb068260157014b2602fc7dc71336e1439c887d2742d9730b4e79b08ec7839c3e2a037ae1565d04e05e351bb3531e5ef42cf7b71ca1482a9205245dd41f4db0f71644f8bdb88e845558537c03834c06ac83f336651e54e2edfc12e15ea9b7ea2c074e6155654d44c4d3bd90d9511050e9ad87d170db01448e5be6f45419cd86008978db5e3ceab79890234f992648d69bf1053855387db646ccdee5575c65f81dd0f670b016d9f9a84707d91f77b862f697b8bb08365ba71fbe6bfa47af39155a75ebdcb1e5d69f59c40c9e3a64988c1ec26f7f5159eef5c244d504a9e46125948ecc389c2ec3028ac4ff39ffd66e7743970819272b21e0c2df75b308bc62896873952147e57ed79446db4cdb5a563e76ec4c25899d41128afb9a5f8fc8063621efb7a58b9dd666d30c73e318cdcf3393bfec200e160f500e645f7baac263db99fa4a7c1cb4fea219fc512193102034d379f244c21a81821301b8d47c90247713a3e902c762d7bafa6cdb744eeb6d3b50dd175599d02b6e9f5bbda59366e04862aa765135968426e7ac0116de7351940dc57c0ae451d63f667e39891bc81e09e6c76f6f8a7582f7447c6f5945f717b0e52a7e3dd0c6db4061362123cc53fd8ede4abed4865201dc4d8eb4e5d48baa565183b69a5304a44c0600bb24dcaeee9d95ceebd27c1b0a33e0b46f23797d7d7907300b2bb7d62ef2fc5aa139250c73930c621bb5f41fc235534ee8014dfaddd5245aeb01198420ba7b5c076545329c94d54fa725a8e807579f5f0cc9d98170598023268f5930893620190275e6b3c6f5181e36310a9a475208316911d78f917d724c5946c553b7ec042c563c540114b6b78bd4c6e808ee391a4a9d93e127032983c5b3708037b14aa604cfb034e7c8b0ffdd6936446fe80216178506a87402653a373926eeff66e704daf992a0a9a5c3ad80566c0339be9e5b8e35b3b3226b2f7767e20d992ea6c3d6e322eca37b0c7f7e60060802f5abcc1975841365cadbdc3867063addfc803766ae525375ecddee61f9df9ffcd20343c83ab82b0e91de039c59cb435c8d3159cc338b4901f40c9b5c27043bcf2bd5fa9b685b65c9ba5a1e11a51dd3f773051560341f9ec81d05bf259e2d4b7161f896fbb6812cfc924a32120b7367d5e40439e267adda6a1315bb0d6200ce6a503174c8d2a638ea6fd6b1f486d68db11bdca63c4f4a725d1ab6231ea875484e70b27d293c05803386924f283d4c12bb953474d92b7dd43d2d97193bd96281ebb63fa075d2f9ecd310c70ee1d97b5330bd8fb5791c5943ecf084e5f2c83915acac57519c46b166136068d6f9ec0dd598616e32c591128ce13705a283ca39d5b211409600e07b3713113374d9700207a45394eac5b3b7afc9b1b2bad7d89fd3f35f6b2413ce615ee7869b3569009403b96fdacdb32ef0a7e5229e2b666d51e95bdfb009b892e88bde70621a9b6509f068781392df4bdbc5723bb15071993f0d9a11575af5ff6ef85eaea39bc86805b35d8beee91b779354147f2d85304b8b49d053e7444fdd3deb9d16de331f2552af5b3be7766bb8f3f6a78c62148efb231f2268", json_spirit::find_value(obj, "solution").get_str());
UniValue obj = blockToJSON(block, &index);
EXPECT_EQ("009f44ff7505d789b964d6817734b8ce1377d456255994370d06e59ac99bd5791b6ad174a66fd71c70e60cfc7fd88243ffe06f80b1ad181625f210779c745524629448e25348a5fce4f346a1735e60fdf53e144c0157dbc47c700a21a236f1efb7ee75f65b8d9d9e29026cfd09048233175202b211b9a49de4ab46f1cac71b6ea57a686377bd612378746e70c61a659c9cd683269e9c2a5cbc1d19f1149345302bbd0a1e62bf4bab01e9caeea789a1519441a61b146de35a4cc75dbdf01029127e311ad5073e7e96397f47226a7df9df66b2086b70756db013bbaeb068260157014b2602fc7dc71336e1439c887d2742d9730b4e79b08ec7839c3e2a037ae1565d04e05e351bb3531e5ef42cf7b71ca1482a9205245dd41f4db0f71644f8bdb88e845558537c03834c06ac83f336651e54e2edfc12e15ea9b7ea2c074e6155654d44c4d3bd90d9511050e9ad87d170db01448e5be6f45419cd86008978db5e3ceab79890234f992648d69bf1053855387db646ccdee5575c65f81dd0f670b016d9f9a84707d91f77b862f697b8bb08365ba71fbe6bfa47af39155a75ebdcb1e5d69f59c40c9e3a64988c1ec26f7f5159eef5c244d504a9e46125948ecc389c2ec3028ac4ff39ffd66e7743970819272b21e0c2df75b308bc62896873952147e57ed79446db4cdb5a563e76ec4c25899d41128afb9a5f8fc8063621efb7a58b9dd666d30c73e318cdcf3393bfec200e160f500e645f7baac263db99fa4a7c1cb4fea219fc512193102034d379f244c21a81821301b8d47c90247713a3e902c762d7bafa6cdb744eeb6d3b50dd175599d02b6e9f5bbda59366e04862aa765135968426e7ac0116de7351940dc57c0ae451d63f667e39891bc81e09e6c76f6f8a7582f7447c6f5945f717b0e52a7e3dd0c6db4061362123cc53fd8ede4abed4865201dc4d8eb4e5d48baa565183b69a5304a44c0600bb24dcaeee9d95ceebd27c1b0a33e0b46f23797d7d7907300b2bb7d62ef2fc5aa139250c73930c621bb5f41fc235534ee8014dfaddd5245aeb01198420ba7b5c076545329c94d54fa725a8e807579f5f0cc9d98170598023268f5930893620190275e6b3c6f5181e36310a9a475208316911d78f917d724c5946c553b7ec042c563c540114b6b78bd4c6e808ee391a4a9d93e127032983c5b3708037b14aa604cfb034e7c8b0ffdd6936446fe80216178506a87402653a373926eeff66e704daf992a0a9a5c3ad80566c0339be9e5b8e35b3b3226b2f7767e20d992ea6c3d6e322eca37b0c7f7e60060802f5abcc1975841365cadbdc3867063addfc803766ae525375ecddee61f9df9ffcd20343c83ab82b0e91de039c59cb435c8d3159cc338b4901f40c9b5c27043bcf2bd5fa9b685b65c9ba5a1e11a51dd3f773051560341f9ec81d05bf259e2d4b7161f896fbb6812cfc924a32120b7367d5e40439e267adda6a1315bb0d6200ce6a503174c8d2a638ea6fd6b1f486d68db11bdca63c4f4a725d1ab6231ea875484e70b27d293c05803386924f283d4c12bb953474d92b7dd43d2d97193bd96281ebb63fa075d2f9ecd310c70ee1d97b5330bd8fb5791c5943ecf084e5f2c83915acac57519c46b166136068d6f9ec0dd598616e32c591128ce13705a283ca39d5b211409600e07b3713113374d9700207a45394eac5b3b7afc9b1b2bad7d89fd3f35f6b2413ce615ee7869b3569009403b96fdacdb32ef0a7e5229e2b666d51e95bdfb009b892e88bde70621a9b6509f068781392df4bdbc5723bb15071993f0d9a11575af5ff6ef85eaea39bc86805b35d8beee91b779354147f2d85304b8b49d053e7444fdd3deb9d16de331f2552af5b3be7766bb8f3f6a78c62148efb231f2268", find_value(obj, "solution").get_str());
}

10
src/rpcblockchain.cpp

@ -494,7 +494,7 @@ UniValue verifychain(const UniValue& params, bool fHelp)
}
/** Implementation of IsSuperMajority with better feedback */
Object SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired, const Consensus::Params& consensusParams)
static UniValue SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired, const Consensus::Params& consensusParams)
{
int nFound = 0;
CBlockIndex* pstart = pindex;
@ -505,7 +505,7 @@ Object SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired,
pstart = pstart->pprev;
}
Object rv;
UniValue rv(UniValue::VOBJ);
rv.push_back(Pair("status", nFound >= nRequired));
rv.push_back(Pair("found", nFound));
rv.push_back(Pair("required", nRequired));
@ -513,9 +513,9 @@ Object SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired,
return rv;
}
Object SoftForkDesc(const std::string &name, int version, CBlockIndex* pindex, const Consensus::Params& consensusParams)
static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex* pindex, const Consensus::Params& consensusParams)
{
Object rv;
UniValue rv(UniValue::VOBJ);
rv.push_back(Pair("id", name));
rv.push_back(Pair("version", version));
rv.push_back(Pair("enforce", SoftForkMajorityDesc(version, pindex, consensusParams.nMajorityEnforceBlockUpgrade, consensusParams)));
@ -576,7 +576,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
const Consensus::Params& consensusParams = Params().GetConsensus();
CBlockIndex* tip = chainActive.Tip();
Array softforks;
UniValue softforks(UniValue::VARR);
softforks.push_back(SoftForkDesc("bip34", 2, tip, consensusParams));
softforks.push_back(SoftForkDesc("bip66", 3, tip, consensusParams));
softforks.push_back(SoftForkDesc("bip65", 4, tip, consensusParams));

12
src/rpcmining.cpp

@ -74,7 +74,7 @@ int64_t GetNetworkHashPS(int lookup, int height) {
return (int64_t)(workDiff.getdouble() / timeDiff);
}
Value getlocalsolps(const Array& params, bool fHelp)
UniValue getlocalsolps(const UniValue& params, bool fHelp)
{
if (fHelp)
throw runtime_error(
@ -92,7 +92,7 @@ Value getlocalsolps(const Array& params, bool fHelp)
return GetLocalSolPS();
}
Value getnetworksolps(const Array& params, bool fHelp)
UniValue getnetworksolps(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 2)
throw runtime_error(
@ -647,7 +647,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
Value txCoinbase = NullUniValue;
UniValue txCoinbase = NullUniValue;
UniValue transactions(UniValue::VARR);
map<uint256, int64_t> setTxIndex;
int i = 0;
@ -709,7 +709,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
result.push_back(Pair("transactions", transactions));
if (coinbasetxn) {
assert(txCoinbase.type() == obj_type);
assert(txCoinbase.isObject());
result.push_back(Pair("coinbasetxn", txCoinbase));
} else {
result.push_back(Pair("coinbaseaux", aux));
@ -868,7 +868,7 @@ UniValue estimatepriority(const UniValue& params, bool fHelp)
return mempool.estimatePriority(nBlocks);
}
Value getblocksubsidy(const Array& params, bool fHelp)
UniValue getblocksubsidy(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error(
@ -897,7 +897,7 @@ Value getblocksubsidy(const Array& params, bool fHelp)
nFoundersReward = nReward/5;
nReward -= nFoundersReward;
}
Object result;
UniValue result(UniValue::VOBJ);
result.push_back(Pair("miner", ValueFromAmount(nReward)));
result.push_back(Pair("founders", ValueFromAmount(nFoundersReward)));
return result;

4
src/rpcmisc.cpp

@ -214,7 +214,7 @@ UniValue validateaddress(const UniValue& params, bool fHelp)
}
Value z_validateaddress(const Array& params, bool fHelp)
UniValue z_validateaddress(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
@ -261,7 +261,7 @@ Value z_validateaddress(const Array& params, bool fHelp)
// address is invalid, nop here as isValid is false.
}
Object ret;
UniValue ret(UniValue::VOBJ);
ret.push_back(Pair("isvalid", isValid));
if (isValid)
{

16
src/rpcrawtransaction.cpp

@ -55,11 +55,11 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fInclud
}
Array TxJoinSplitToJSON(const CTransaction& tx) {
Array vjoinsplit;
UniValue TxJoinSplitToJSON(const CTransaction& tx) {
UniValue vjoinsplit(UniValue::VARR);
for (unsigned int i = 0; i < tx.vjoinsplit.size(); i++) {
const JSDescription& jsdescription = tx.vjoinsplit[i];
Object joinsplit;
UniValue joinsplit(UniValue::VOBJ);
joinsplit.push_back(Pair("vpub_old", ValueFromAmount(jsdescription.vpub_old)));
joinsplit.push_back(Pair("vpub_new", ValueFromAmount(jsdescription.vpub_new)));
@ -67,7 +67,7 @@ Array TxJoinSplitToJSON(const CTransaction& tx) {
joinsplit.push_back(Pair("anchor", jsdescription.anchor.GetHex()));
{
Array nullifiers;
UniValue nullifiers(UniValue::VARR);
BOOST_FOREACH(const uint256 nf, jsdescription.nullifiers) {
nullifiers.push_back(nf.GetHex());
}
@ -75,7 +75,7 @@ Array TxJoinSplitToJSON(const CTransaction& tx) {
}
{
Array commitments;
UniValue commitments(UniValue::VARR);
BOOST_FOREACH(const uint256 commitment, jsdescription.commitments) {
commitments.push_back(commitment.GetHex());
}
@ -86,7 +86,7 @@ Array TxJoinSplitToJSON(const CTransaction& tx) {
joinsplit.push_back(Pair("randomSeed", jsdescription.randomSeed.GetHex()));
{
Array macs;
UniValue macs(UniValue::VARR);
BOOST_FOREACH(const uint256 mac, jsdescription.macs) {
macs.push_back(mac.GetHex());
}
@ -98,7 +98,7 @@ Array TxJoinSplitToJSON(const CTransaction& tx) {
joinsplit.push_back(Pair("proof", HexStr(ssProof.begin(), ssProof.end())));
{
Array ciphertexts;
UniValue ciphertexts(UniValue::VARR);
for (const ZCNoteEncryption::Ciphertext ct : jsdescription.ciphertexts) {
ciphertexts.push_back(HexStr(ct.begin(), ct.end()));
}
@ -145,7 +145,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
}
entry.push_back(Pair("vout", vout));
Array vjoinsplit = TxJoinSplitToJSON(tx);
UniValue vjoinsplit = TxJoinSplitToJSON(tx);
entry.push_back(Pair("vjoinsplit", vjoinsplit));
if (!hashBlock.IsNull()) {

1
src/test/alert_tests.cpp

@ -27,7 +27,6 @@
#include <boost/filesystem/operations.hpp>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
#include "json/json_spirit_reader_template.h"
#include "key.h"
#include "alertkeys.h"

86
src/test/rpc_wallet_tests.cpp

@ -40,7 +40,7 @@ extern UniValue CallRPC(string args);
extern CWallet* pwalletMain;
bool find_error(const Object& objError, const std::string& expected) {
bool find_error(const UniValue& objError, const std::string& expected) {
return find_value(objError, "message").get_str().find(expected) != string::npos;
}
@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
UniValue arr = retValue.get_array();
BOOST_CHECK_EQUAL(4, arr.size());
bool notFound = true;
for (auto a : arr) {
for (auto a : arr.getValues()) {
notFound &= CBitcoinAddress(a.get_str()).Get() != demoAddress.Get();
}
BOOST_CHECK(!notFound);
@ -254,17 +254,17 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
BOOST_CHECK_THROW(CallRPC("getblocksubsidy too many args"), runtime_error);
BOOST_CHECK_THROW(CallRPC("getblocksubsidy -1"), runtime_error);
BOOST_CHECK_NO_THROW(retValue = CallRPC("getblocksubsidy 50000"));
Object obj = retValue.get_obj();
BOOST_CHECK(find_value(obj, "miner") == 10.0);
BOOST_CHECK(find_value(obj, "founders") == 2.5);
UniValue obj = retValue.get_obj();
BOOST_CHECK_EQUAL(find_value(obj, "miner").get_real(), 10.0);
BOOST_CHECK_EQUAL(find_value(obj, "founders").get_real(), 2.5);
BOOST_CHECK_NO_THROW(retValue = CallRPC("getblocksubsidy 1000000"));
obj = retValue.get_obj();
BOOST_CHECK(find_value(obj, "miner") == 6.25);
BOOST_CHECK(find_value(obj, "founders") == 0.0);
BOOST_CHECK_EQUAL(find_value(obj, "miner").get_real(), 6.25);
BOOST_CHECK_EQUAL(find_value(obj, "founders").get_real(), 0.0);
BOOST_CHECK_NO_THROW(retValue = CallRPC("getblocksubsidy 2000000"));
obj = retValue.get_obj();
BOOST_CHECK(find_value(obj, "miner") == 3.125);
BOOST_CHECK(find_value(obj, "founders") == 0.0);
BOOST_CHECK_EQUAL(find_value(obj, "miner").get_real(), 3.125);
BOOST_CHECK_EQUAL(find_value(obj, "founders").get_real(), 0.0);
}
BOOST_AUTO_TEST_CASE(rpc_wallet_getbalance)
@ -305,7 +305,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_validateaddress)
LOCK2(cs_main, pwalletMain->cs_wallet);
Value retValue;
UniValue retValue;
// Check number of args
BOOST_CHECK_THROW(CallRPC("z_validateaddress"), runtime_error);
@ -318,7 +318,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_validateaddress)
// This address is not valid, it belongs to another network
BOOST_CHECK_NO_THROW(retValue = CallRPC("z_validateaddress ztaaga95QAPyp1kSQ1hD2kguCpzyMHjxWZqaYDEkzbvo7uYQYAw2S8X4Kx98AvhhofMtQL8PAXKHuZsmhRcanavKRKmdCzk"));
Object resultObj = retValue.get_obj();
UniValue resultObj = retValue.get_obj();
bool b = find_value(resultObj, "isvalid").get_bool();
BOOST_CHECK_EQUAL(b, false);
@ -485,7 +485,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importwallet)
BOOST_AUTO_TEST_CASE(rpc_wallet_z_importexport)
{
LOCK2(cs_main, pwalletMain->cs_wallet);
Value retValue;
UniValue retValue;
int n1 = 1000; // number of times to import/export
int n2 = 1000; // number of addresses to create and list
@ -516,12 +516,12 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importexport)
// Verify we can list the keys imported
BOOST_CHECK_NO_THROW(retValue = CallRPC("z_listaddresses"));
Array arr = retValue.get_array();
UniValue arr = retValue.get_array();
BOOST_CHECK(arr.size() == n1);
// Put addresses into a set
std::unordered_set<std::string> myaddrs;
for (Value element : arr) {
for (UniValue element : arr.getValues()) {
myaddrs.insert(element.get_str());
}
@ -543,7 +543,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importexport)
// Create a set from them
std::unordered_set<std::string> listaddrs;
for (Value element : arr) {
for (UniValue element : arr.getValues()) {
listaddrs.insert(element.get_str());
}
@ -582,7 +582,7 @@ public:
start_execution_clock();
std::this_thread::sleep_for(std::chrono::milliseconds(naptime));
stop_execution_clock();
set_result(Value("done"));
set_result(UniValue(UniValue::VSTR, "done"));
set_state(OperationStatus::SUCCESS);
}
};
@ -621,8 +621,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_async_operations)
BOOST_CHECK_EQUAL(op1->isReady(), false);
BOOST_CHECK_EQUAL(op1->isFailed(), false);
BOOST_CHECK_EQUAL(op1->isSuccess(), true);
BOOST_CHECK(op1->getError() == Value::null );
BOOST_CHECK(op1->getResult().is_null() == false );
BOOST_CHECK_EQUAL(op1->getError().isNull(), true);
BOOST_CHECK_EQUAL(op1->getResult().isNull(), false);
BOOST_CHECK_EQUAL(op1->getStateAsString(), "success");
BOOST_CHECK_NE(op1->getStateAsString(), "executing");
@ -782,12 +782,12 @@ BOOST_AUTO_TEST_CASE(rpc_z_getoperations)
// Check if too many args
BOOST_CHECK_THROW(CallRPC("z_listoperationids toomany args"), runtime_error);
Value retValue;
UniValue retValue;
BOOST_CHECK_NO_THROW(retValue = CallRPC("z_listoperationids"));
BOOST_CHECK(retValue.get_array().size() == 2);
BOOST_CHECK_NO_THROW(retValue = CallRPC("z_getoperationstatus"));
Array array = retValue.get_array();
UniValue array = retValue.get_array();
BOOST_CHECK(array.size() == 2);
// idempotent
@ -795,18 +795,18 @@ BOOST_AUTO_TEST_CASE(rpc_z_getoperations)
array = retValue.get_array();
BOOST_CHECK(array.size() == 2);
for (Value v : array) {
Object obj = v.get_obj();
Value id = find_value(obj, "id");
for (UniValue v : array.getValues()) {
UniValue obj = v.get_obj();
UniValue id = find_value(obj, "id");
Value result;
UniValue result;
// removes result from internal storage
BOOST_CHECK_NO_THROW(result = CallRPC("z_getoperationresult [\"" + id.get_str() + "\"]"));
Array resultArray = result.get_array();
UniValue resultArray = result.get_array();
BOOST_CHECK(resultArray.size() == 1);
Object resultObj = resultArray.front().get_obj();
Value resultId = find_value(resultObj, "id");
UniValue resultObj = resultArray[0].get_obj();
UniValue resultId = find_value(resultObj, "id");
BOOST_CHECK_EQUAL(id.get_str(), resultId.get_str());
// verify the operation has been removed
@ -885,26 +885,26 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_parameters)
// Test constructor of AsyncRPCOperation_sendmany
try {
std::shared_ptr<AsyncRPCOperation> operation(new AsyncRPCOperation_sendmany("",{}, {}, -1));
} catch (const Object& objError) {
} catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "Minconf cannot be negative"));
}
try {
std::shared_ptr<AsyncRPCOperation> operation(new AsyncRPCOperation_sendmany("",{}, {}, 1));
} catch (const Object& objError) {
} catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "From address parameter missing"));
}
try {
std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_sendmany("tmRr6yJonqGK23UVhrKuyvTpF8qxQQjKigJ", {}, {}, 1) );
} catch (const Object& objError) {
} catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "No recipients"));
}
try {
std::vector<SendManyRecipient> recipients = { SendManyRecipient("dummy",1.0, "") };
std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_sendmany("INVALID", recipients, {}, 1) );
} catch (const Object& objError) {
} catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "payment address is invalid"));
}
@ -912,7 +912,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_parameters)
try {
std::vector<SendManyRecipient> recipients = { SendManyRecipient("dummy",1.0, "") };
std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_sendmany("zcMuhvq8sEkHALuSU2i4NbNQxshSAYrpCExec45ZjtivYPbuiFPwk6WHy4SvsbeZ4siy1WheuRGjtaJmoD1J8bFqNXhsG6U", recipients, {}, 1) );
} catch (const Object& objError) {
} catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "payment address is for wrong network type"));
}
@ -921,7 +921,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_parameters)
try {
std::vector<SendManyRecipient> recipients = { SendManyRecipient("dummy",1.0, "") };
std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_sendmany("ztjiDe569DPNbyTE6TSdJTaSDhoXEHLGvYoUnBU1wfVNU52TEyT6berYtySkd21njAeEoh8fFJUT42kua9r8EnhBaEKqCpP", recipients, {}, 1) );
} catch (const Object& objError) {
} catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "no spending key found for zaddr"));
}
}
@ -934,7 +934,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
LOCK(pwalletMain->cs_wallet);
Value retValue;
UniValue retValue;
// add keys manually
BOOST_CHECK_NO_THROW(retValue = CallRPC("getnewaddress"));
@ -986,7 +986,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
try {
proxy.get_memo_from_hex_string(bigmemo);
} catch (const Object& objError) {
} catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "too big"));
}
@ -996,7 +996,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
try {
proxy.get_memo_from_hex_string(badmemo);
} catch (const Object& objError) {
} catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "hexadecimal format"));
}
@ -1007,7 +1007,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
std::string oddmemo(v.begin(), v.end());
try {
proxy.get_memo_from_hex_string(oddmemo);
} catch (const Object& objError) {
} catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "hexadecimal format"));
}
}
@ -1062,7 +1062,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
// Raw joinsplit is a zaddr->zaddr
{
std::string raw = "020000000000000000000100000000000000001027000000000000183a0d4c46c369078705e39bcfebee59a978dbd210ce8de3efc9555a03fbabfd3cea16693d730c63850d7e48ccde79854c19adcb7e9dcd7b7d18805ee09083f6b16e1860729d2d4a90e2f2acd009cf78b5eb0f4a6ee4bdb64b1262d7ce9eb910c460b02022991e968d0c50ee44908e4ccccbc591d0053bcca154dd6d6fc400a29fa686af4682339832ccea362a62aeb9df0d5aa74f86a1e75ac0f48a8ccc41e0a940643c6c33e1d09223b0a46eaf47a1bb4407cfc12b1dcf83a29c0cef51e45c7876ca5b9e5bae86d92976eb3ef68f29cd29386a8be8451b50f82bf9da10c04651868655194da8f6ed3d241bb5b5ff93a3e2bbe44644544d88bcde5cc35978032ee92699c7a61fcbb395e7583f47e698c4d53ede54f956629400bf510fb5e22d03158cc10bdcaaf29e418ef18eb6480dd9c8b9e2a377809f9f32a556ef872febd0021d4ad013aa9f0b7255e98e408d302abefd33a71180b720271835b487ab309e160b06dfe51932120fb84a7ede16b20c53599a11071592109e10260f265ee60d48c62bfe24074020e9b586ce9e9356e68f2ad1a9538258234afe4b83a209f178f45202270eaeaeecaf2ce3100b2c5a714f75f35777a9ebff5ebf47059d2bbf6f3726190216468f2b152673b766225b093f3a2f827c86d6b48b42117fec1d0ac38dd7af700308dcfb02eba821612b16a2c164c47715b9b0c93900893b1aba2ea03765c94d87022db5be06ab338d1912e0936dfe87586d0a8ee49144a6cd2e306abdcb652faa3e0222739deb23154d778b50de75069a4a2cce1208cd1ced3cb4744c9888ce1c2fcd2e66dc31e62d3aa9e423d7275882525e9981f92e84ac85975b8660739407efbe1e34c2249420fde7e17db3096d5b22e83d051d01f0e6e7690dca7d168db338aadf0897fedac10de310db2b1bff762d322935dddbb60c2efb8b15d231fa17b84630371cb275c209f0c4c7d0c68b150ea5cd514122215e3f7fcfb351d69514788d67c2f3c8922581946e3a04bdf1f07f15696ca76eb95b10698bf1188fd882945c57657515889d042a6fc45d38cbc943540c4f0f6d1c45a1574c81f3e42d1eb8702328b729909adee8a5cfed7c79d54627d1fd389af941d878376f7927b9830ca659bf9ab18c5ca5192d52d02723008728d03701b8ab3e1c4a3109409ec0b13df334c7deec3523eeef4c97b5603e643de3a647b873f4c1b47fbfc6586ba66724f112e51fc93839648005043620aa3ce458e246d77977b19c53d98e3e812de006afc1a79744df236582943631d04cc02941ac4be500e4ed9fb9e3e7cc187b1c4050fad1d9d09d5fd70d5d01d615b439d8c0015d2eb10398bcdbf8c4b2bd559dbe4c288a186aed3f86f608da4d582e120c4a896e015e2241900d1daeccd05db968852677c71d752bec46de9962174b46f980e8cc603654daf8b98a3ee92dac066033954164a89568b70b1780c2ce2410b2f816dbeddb2cd463e0c8f21a52cf6427d9647a6fd4bafa8fb4cd4d47ac057b0160bee86c6b2fb8adce214c2bcdda277512200adf0eaa5d2114a2c077b009836a68ec254bfe56f51d147b9afe2ddd9cb917c0c2de19d81b7b8fd9f4574f51fa1207630dc13976f4d7587c962f761af267de71f3909a576e6bedaf6311633910d291ac292c467cc8331ef577aef7646a5d949322fa0367a49f20597a13def53136ee31610395e3e48d291fd8f58504374031fe9dcfba5e06086ebcf01a9106f6a4d6e16e19e4c5bb893f7da79419c94eca31a384be6fa1747284dee0fc3bbc8b1b860172c10b29c1594bb8c747d7fe05827358ff2160f49050001625ffe2e880bd7fc26cd0ffd89750745379a8e862816e08a5a2008043921ab6a4976064ac18f7ee37b6628bc0127d8d5ebd3548e41d8881a082d86f20b32e33094f15a0e6ea6074b08c6cd28142de94713451640a55985051f5577eb54572699d838cb34a79c8939e981c0c277d06a6e2ce69ccb74f8a691ff08f81d8b99e6a86223d29a2b7c8e7b041aba44ea678ae654277f7e91cbfa79158b989164a3d549d9f4feb0cc43169699c13e321fe3f4b94258c75d198ff9184269cd6986c55409e07528c93f64942c6c283ce3917b4bf4c3be2fe3173c8c38cccb35f1fbda0ca88b35a599c0678cb22aa8eabea8249dbd2e4f849fffe69803d299e435ebcd7df95854003d8eda17a74d98b4be0e62d45d7fe48c06a6f464a14f8e0570077cc631279092802a89823f031eef5e1028a6d6fdbd502869a731ee7d28b4d6c71b419462a30d31442d3ee444ffbcbd16d558c9000c97e949c2b1f9d6f6d8db7b9131ebd963620d3fc8595278d6f8fdf49084325373196d53e64142fa5a23eccd6ef908c4d80b8b3e6cc334b7f7012103a3682e4678e9b518163d262a39a2c1a69bf88514c52b7ccd7cc8dc80e71f7c2ec0701cff982573eb0c2c4daeb47fa0b586f4451c10d1da2e5d182b03dd067a5e971b3a6138ca6667aaf853d2ac03b80a1d5870905f2cfb6c78ec3c3719c02f973d638a0f973424a2b0f2b0023f136d60092fe15fba4bc180b9176bd0ff576e053f1af6939fe9ca256203ffaeb3e569f09774d2a6cbf91873e56651f4d6ff77e0b5374b0a1a201d7e523604e0247644544cc571d48c458a4f96f45580b";
Object obj;
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("rawtxn", raw));
// we have the spending key for the dummy recipient zaddr1
@ -1080,9 +1080,9 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
// Verify test mode is returning output (since no input taddrs, signed and unsigned are the same).
BOOST_CHECK_NO_THROW( proxy.sign_send_raw_transaction(obj) );
Value result = operation->getResult();
BOOST_CHECK(!result.is_null());
Object resultObj = result.get_obj();
UniValue result = operation->getResult();
BOOST_CHECK(!result.isNull());
UniValue resultObj = result.get_obj();
std::string hex = find_value(resultObj, "hex").get_str();
BOOST_CHECK_EQUAL(hex, raw);
}
@ -1150,7 +1150,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_zkeys)
{
LOCK2(cs_main, pwalletMain->cs_wallet);
Value retValue;
UniValue retValue;
int n = 100;
// wallet should currently be empty
@ -1165,7 +1165,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_zkeys)
// Verify we can list the keys imported
BOOST_CHECK_NO_THROW(retValue = CallRPC("z_listaddresses"));
Array arr = retValue.get_array();
UniValue arr = retValue.get_array();
BOOST_CHECK(arr.size() == n);
// Verify that the wallet encryption RPC is disabled

77
src/wallet/asyncrpcoperation_sendmany.cpp

@ -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;
}

26
src/wallet/asyncrpcoperation_sendmany.h

@ -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);
}

28
src/wallet/rpcdump.cpp

@ -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(

138
src/wallet/rpcwallet.cpp

@ -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) {

Loading…
Cancel
Save