MoneroUtils.json_to_binary -> jsonToBinary(), etc;

MoneroTxRequest and MoneroTransferRequest do not extend struct;
use pointers in structs where appropriate, prep for custom
deserialization
This commit is contained in:
woodser
2019-06-03 17:08:28 -04:00
parent eb740de83a
commit 25e0d2befd
5 changed files with 66 additions and 81 deletions
+3 -43
View File
@@ -37,7 +37,7 @@ namespace monero {
* Models a Monero transaction on the blockchain.
*/
struct MoneroTx {
MoneroBlock* block;
unique_ptr<MoneroBlock> block;
string id;
string version;
bool isCoinbase;
@@ -70,51 +70,11 @@ namespace monero {
string rctSigPrunable; // TODO: implement
bool isKeptByBlock;
bool isFailed;
uint32_t lastFailedHeight;
unique_ptr<uint32_t> lastFailedHeight;
string lastFailedId;
uint32_t maxUsedBlockHeight;
unique_ptr<uint32_t> maxUsedBlockHeight;
string maxUsedBlockId;
vector<string> signatures;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(id)
KV_SERIALIZE(version)
KV_SERIALIZE(isCoinbase)
KV_SERIALIZE(paymentId)
KV_SERIALIZE(fee)
KV_SERIALIZE(mixin)
KV_SERIALIZE(doNotRelay)
KV_SERIALIZE(isRelayed)
KV_SERIALIZE(isConfirmed)
KV_SERIALIZE(inTxPool)
KV_SERIALIZE(numConfirmations)
KV_SERIALIZE(unlockTime)
KV_SERIALIZE(lastRelayedTimestamp)
KV_SERIALIZE(receivedTimestamp)
KV_SERIALIZE(isDoubleSpend)
KV_SERIALIZE(key)
KV_SERIALIZE(fullHex)
KV_SERIALIZE(prunedHex)
KV_SERIALIZE(prunableHex)
KV_SERIALIZE(prunableHash)
KV_SERIALIZE(size)
KV_SERIALIZE(weight)
KV_SERIALIZE(vins)
KV_SERIALIZE(vouts)
KV_SERIALIZE(outputIndices)
KV_SERIALIZE(metadata)
KV_SERIALIZE(commonTxSets)
KV_SERIALIZE(extra)
KV_SERIALIZE(rctSignatures)
KV_SERIALIZE(rctSigPrunable)
KV_SERIALIZE(isKeptByBlock)
KV_SERIALIZE(isFailed)
KV_SERIALIZE(lastFailedHeight)
KV_SERIALIZE(lastFailedId)
KV_SERIALIZE(maxUsedBlockHeight)
KV_SERIALIZE(maxUsedBlockId)
KV_SERIALIZE(signatures)
END_KV_SERIALIZE_MAP()
};
/**
+9 -9
View File
@@ -10,23 +10,23 @@ using namespace boost;
using namespace cryptonote;
using namespace MoneroUtils;
void MoneroUtils::json_to_binary(const std::string &buff_json, std::string &buff_bin) {
void MoneroUtils::jsonToBinary(const std::string &json, std::string &bin) {
epee::serialization::portable_storage ps;
ps.load_from_json(buff_json);
ps.store_to_binary(buff_bin);
ps.load_from_json(json);
ps.store_to_binary(bin);
}
void MoneroUtils::binary_to_json(const std::string &buff_bin, std::string &buff_json) {
void MoneroUtils::binaryToJson(const std::string &bin, std::string &json) {
epee::serialization::portable_storage ps;
ps.load_from_binary(buff_bin);
ps.dump_as_json(buff_json);
ps.load_from_binary(bin);
ps.dump_as_json(json);
}
void MoneroUtils::binary_blocks_to_json(const std::string &buff_bin, std::string &buff_json) {
void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json) {
// load binary rpc response to struct
cryptonote::COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response resp_struct;
epee::serialization::load_t_from_binary(resp_struct, buff_bin);
epee::serialization::load_t_from_binary(resp_struct, bin);
// build property tree from deserialized blocks and transactions
boost::property_tree::ptree root;
@@ -71,5 +71,5 @@ void MoneroUtils::binary_blocks_to_json(const std::string &buff_bin, std::string
// convert root to string // TODO: common utility with serial_bridge
std::stringstream ss;
boost::property_tree::write_json(ss, root, false/*pretty*/);
buff_json = ss.str();
json = ss.str();
}
+3 -12
View File
@@ -14,20 +14,11 @@ namespace MoneroUtils
using namespace boost;
using namespace cryptonote;
/**
* TODO.
*/
void json_to_binary(const std::string &buff_json, std::string &buff_bin);
void jsonToBinary(const std::string &json, std::string &bin);
/**
* TODO.
*/
void binary_to_json(const std::string &buff_bin, std::string &buff_json);
void binaryToJson(const std::string &bin, std::string &json);
/**
* TODO.
*/
void binary_blocks_to_json(const std::string &buff_bin, std::string &buff_json);
void binaryBlocksToJson(const std::string &bin, std::string &json);
/**
* Modified from core_rpc_server.cpp to return a string.
-2
View File
@@ -439,8 +439,6 @@ namespace monero {
vector<MoneroTxWallet> MoneroWallet::getTxs(const MoneroTxRequest& request) const {
cout << "getTxs(request)" << endl;
string reqStr = epee::serialization::store_t_to_json(request);
cout << "Tx request: " << reqStr << endl;
throw runtime_error("Not implemented");
}
+51 -15
View File
@@ -89,7 +89,7 @@ namespace monero {
* Models a base transfer of funds to or from the wallet.
*/
struct MoneroTransfer {
MoneroTxWallet* tx;
unique_ptr<MoneroTxWallet> tx;
uint64_t amount;
uint32_t accountIndex;
bool isIncoming;
@@ -117,7 +117,7 @@ namespace monero {
*/
struct MoneroTxWallet : public MoneroTx {
vector<MoneroIncomingTransfer> incomingTransfers;
MoneroOutgoingTransfer* outgoingTransfer;
unique_ptr<MoneroOutgoingTransfer> outgoingTransfer;
uint32_t numSuggestedConfirmations;
string note;
};
@@ -127,15 +127,17 @@ namespace monero {
*
* All transfers are returned except those that do not meet the criteria defined in this request.
*/
struct MoneroTransferRequest : public MoneroTransfer {
bool isIncoming;
struct MoneroTransferRequest {
unique_ptr<uint64_t> amount;
unique_ptr<uint32_t> accountIndex;
unique_ptr<bool> isIncoming;
string address;
vector<string> addresses;
uint32_t subaddressIndex;
unique_ptr<uint32_t> subaddressIndex;
vector<uint32_t> subaddressIndices;
vector<MoneroDestination> destinations;
bool hasDestinations;
MoneroTxRequest* txRequest;
unique_ptr<bool> hasDestinations;
unique_ptr<MoneroTxRequest> txRequest;
};
/**
@@ -143,16 +145,50 @@ namespace monero {
*
* All transactions are returned except those that do not meet the criteria defined in this request.
*/
struct MoneroTxRequest : public MoneroTxWallet {
bool isOutgoing; // TODO: these are going to need to be pointers to indicate no preference
bool isIncoming;
struct MoneroTxRequest {
unique_ptr<MoneroBlock> block;
string id;
string version;
unique_ptr<bool> isCoinbase;
string paymentId;
unique_ptr<uint64_t> fee;
unique_ptr<uint32_t> mixin;
unique_ptr<bool> doNotRelay;
unique_ptr<bool> isRelayed;
unique_ptr<bool> isConfirmed;
unique_ptr<bool> inTxPool;
unique_ptr<uint64_t> numConfirmations;
unique_ptr<uint64_t> unlockTime;
unique_ptr<uint64_t> lastRelayedTimestamp;
unique_ptr<uint64_t> receivedTimestamp;
unique_ptr<bool> isDoubleSpend;
string key;
string fullHex;
string prunedHex;
string prunableHex;
string prunableHash;
unique_ptr<uint32_t> size;
unique_ptr<uint32_t> weight;
vector<MoneroOutput> vins;
vector<MoneroOutput> vouts;
vector<uint32_t> outputIndices;
string metadata;
unique_ptr<bool> isFailed;
vector<MoneroIncomingTransfer> incomingTransfers;
unique_ptr<MoneroOutgoingTransfer> outgoingTransfer;
unique_ptr<uint32_t> numSuggestedConfirmations;
string note;
unique_ptr<bool> isOutgoing;
unique_ptr<bool> isIncoming;
vector<string> txIds;
bool hasPaymentId;
unique_ptr<bool> hasPaymentId;
vector<string> paymentIds;
uint64_t minHeight;
uint64_t maxHeight;
bool includeOutputs;
MoneroTransferRequest* transferRequest;
unique_ptr<uint64_t> minHeight;
unique_ptr<uint64_t> maxHeight;
unique_ptr<uint64_t> includeOutputs;
unique_ptr<MoneroTransferRequest> transferRequest;
};
// --------------------------------- LISTENERS ------------------------------