mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-19 08:08:39 +02:00
add MoneroUtils.serialize(vector<MoneroBlock>);
model unique_ptr -> shared_ptr;
This commit is contained in:
@@ -37,7 +37,7 @@ namespace monero {
|
||||
* Models a Monero transaction on the blockchain.
|
||||
*/
|
||||
struct MoneroTx {
|
||||
unique_ptr<MoneroBlock> block;
|
||||
shared_ptr<MoneroBlock> block;
|
||||
string id;
|
||||
string version;
|
||||
bool isCoinbase;
|
||||
@@ -70,9 +70,9 @@ namespace monero {
|
||||
string rctSigPrunable; // TODO: implement
|
||||
bool isKeptByBlock;
|
||||
bool isFailed;
|
||||
unique_ptr<uint32_t> lastFailedHeight;
|
||||
shared_ptr<uint32_t> lastFailedHeight;
|
||||
string lastFailedId;
|
||||
unique_ptr<uint32_t> maxUsedBlockHeight;
|
||||
shared_ptr<uint32_t> maxUsedBlockHeight;
|
||||
string maxUsedBlockId;
|
||||
vector<string> signatures;
|
||||
};
|
||||
|
||||
+28
-24
@@ -34,34 +34,34 @@ void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json)
|
||||
boost::property_tree::ptree txsNodes; // array of txs per block (array of array)
|
||||
for (int blockIdx = 0; blockIdx < resp_struct.blocks.size(); blockIdx++) {
|
||||
|
||||
// parse and validate block
|
||||
cryptonote::block block;
|
||||
if (cryptonote::parse_and_validate_block_from_blob(resp_struct.blocks[blockIdx].block, block)) {
|
||||
// parse and validate block
|
||||
cryptonote::block block;
|
||||
if (cryptonote::parse_and_validate_block_from_blob(resp_struct.blocks[blockIdx].block, block)) {
|
||||
|
||||
// add block node to blocks node
|
||||
boost::property_tree::ptree blockNode;
|
||||
blockNode.put("", cryptonote::obj_to_json_str(block)); // TODO: no pretty print
|
||||
blocksNode.push_back(std::make_pair("", blockNode));
|
||||
// add block node to blocks node
|
||||
boost::property_tree::ptree blockNode;
|
||||
blockNode.put("", cryptonote::obj_to_json_str(block)); // TODO: no pretty print
|
||||
blocksNode.push_back(std::make_pair("", blockNode));
|
||||
} else {
|
||||
throw std::runtime_error("failed to parse block blob at index " + std::to_string(blockIdx));
|
||||
}
|
||||
|
||||
// parse and validate txs
|
||||
boost::property_tree::ptree txsNode;
|
||||
for (int txIdx = 0; txIdx < resp_struct.blocks[blockIdx].txs.size(); txIdx++) {
|
||||
cryptonote::transaction tx;
|
||||
if (cryptonote::parse_and_validate_tx_from_blob(resp_struct.blocks[blockIdx].txs[txIdx], tx)) {
|
||||
|
||||
// add tx node to txs node
|
||||
boost::property_tree::ptree txNode;
|
||||
//std::cout << "PRUNED:\n" << MoneroUtils::get_pruned_tx_json(tx) << "\n";
|
||||
txNode.put("", MoneroUtils::get_pruned_tx_json(tx)); // TODO: no pretty print
|
||||
txsNode.push_back(std::make_pair("", txNode));
|
||||
} else {
|
||||
throw std::runtime_error("failed to parse block blob at index " + std::to_string(blockIdx));
|
||||
}
|
||||
|
||||
// parse and validate txs
|
||||
boost::property_tree::ptree txsNode;
|
||||
for (int txIdx = 0; txIdx < resp_struct.blocks[blockIdx].txs.size(); txIdx++) {
|
||||
cryptonote::transaction tx;
|
||||
if (cryptonote::parse_and_validate_tx_from_blob(resp_struct.blocks[blockIdx].txs[txIdx], tx)) {
|
||||
|
||||
// add tx node to txs node
|
||||
boost::property_tree::ptree txNode;
|
||||
//std::cout << "PRUNED:\n" << MoneroUtils::get_pruned_tx_json(tx) << "\n";
|
||||
txNode.put("", MoneroUtils::get_pruned_tx_json(tx)); // TODO: no pretty print
|
||||
txsNode.push_back(std::make_pair("", txNode));
|
||||
} else {
|
||||
throw std::runtime_error("failed to parse tx blob at index " + std::to_string(txIdx));
|
||||
}
|
||||
}
|
||||
txsNodes.push_back(std::make_pair("", txsNode)); // array of array of transactions, one array per block
|
||||
}
|
||||
txsNodes.push_back(std::make_pair("", txsNode)); // array of array of transactions, one array per block
|
||||
}
|
||||
root.add_child("blocks", blocksNode);
|
||||
root.add_child("txs", txsNodes);
|
||||
@@ -73,3 +73,7 @@ void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json)
|
||||
boost::property_tree::write_json(ss, root, false/*pretty*/);
|
||||
json = ss.str();
|
||||
}
|
||||
|
||||
string MoneroUtils::serialize(vector<MoneroBlock> blocks) {
|
||||
throw runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef MoneroUtils_h
|
||||
#define MoneroUtils_h
|
||||
|
||||
#include "wallet/MoneroWallet.h"
|
||||
#include "cryptonote_basic/cryptonote_basic.h"
|
||||
#include "serialization/keyvalue_serialization.h" // TODO: consolidate with other binary deps?
|
||||
#include "storages/portable_storage.h"
|
||||
@@ -20,6 +21,8 @@ namespace MoneroUtils
|
||||
|
||||
void binaryBlocksToJson(const std::string &bin, std::string &json);
|
||||
|
||||
string serialize(vector<MoneroBlock> blocks);
|
||||
|
||||
/**
|
||||
* Modified from core_rpc_server.cpp to return a string.
|
||||
*/
|
||||
|
||||
+33
-33
@@ -89,7 +89,7 @@ namespace monero {
|
||||
* Models a base transfer of funds to or from the wallet.
|
||||
*/
|
||||
struct MoneroTransfer {
|
||||
unique_ptr<MoneroTxWallet> tx;
|
||||
shared_ptr<MoneroTxWallet> tx;
|
||||
uint64_t amount;
|
||||
uint32_t accountIndex;
|
||||
bool isIncoming;
|
||||
@@ -117,7 +117,7 @@ namespace monero {
|
||||
*/
|
||||
struct MoneroTxWallet : public MoneroTx {
|
||||
vector<MoneroIncomingTransfer> incomingTransfers;
|
||||
unique_ptr<MoneroOutgoingTransfer> outgoingTransfer;
|
||||
shared_ptr<MoneroOutgoingTransfer> outgoingTransfer;
|
||||
uint32_t numSuggestedConfirmations;
|
||||
string note;
|
||||
};
|
||||
@@ -128,16 +128,16 @@ namespace monero {
|
||||
* All transfers are returned except those that do not meet the criteria defined in this request.
|
||||
*/
|
||||
struct MoneroTransferRequest {
|
||||
unique_ptr<uint64_t> amount;
|
||||
unique_ptr<uint32_t> accountIndex;
|
||||
unique_ptr<bool> isIncoming;
|
||||
shared_ptr<uint64_t> amount;
|
||||
shared_ptr<uint32_t> accountIndex;
|
||||
shared_ptr<bool> isIncoming;
|
||||
string address;
|
||||
vector<string> addresses;
|
||||
unique_ptr<uint32_t> subaddressIndex;
|
||||
shared_ptr<uint32_t> subaddressIndex;
|
||||
vector<uint32_t> subaddressIndices;
|
||||
vector<MoneroDestination> destinations;
|
||||
unique_ptr<bool> hasDestinations;
|
||||
unique_ptr<MoneroTxRequest> txRequest;
|
||||
shared_ptr<bool> hasDestinations;
|
||||
shared_ptr<MoneroTxRequest> txRequest;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -146,49 +146,49 @@ namespace monero {
|
||||
* All transactions are returned except those that do not meet the criteria defined in this request.
|
||||
*/
|
||||
struct MoneroTxRequest {
|
||||
unique_ptr<MoneroBlock> block;
|
||||
shared_ptr<MoneroBlock> block;
|
||||
string id;
|
||||
string version;
|
||||
unique_ptr<bool> isCoinbase;
|
||||
shared_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;
|
||||
shared_ptr<uint64_t> fee;
|
||||
shared_ptr<uint32_t> mixin;
|
||||
shared_ptr<bool> doNotRelay;
|
||||
shared_ptr<bool> isRelayed;
|
||||
shared_ptr<bool> isConfirmed;
|
||||
shared_ptr<bool> inTxPool;
|
||||
shared_ptr<uint64_t> numConfirmations;
|
||||
shared_ptr<uint64_t> unlockTime;
|
||||
shared_ptr<uint64_t> lastRelayedTimestamp;
|
||||
shared_ptr<uint64_t> receivedTimestamp;
|
||||
shared_ptr<bool> isDoubleSpend;
|
||||
string key;
|
||||
string fullHex;
|
||||
string prunedHex;
|
||||
string prunableHex;
|
||||
string prunableHash;
|
||||
unique_ptr<uint32_t> size;
|
||||
unique_ptr<uint32_t> weight;
|
||||
shared_ptr<uint32_t> size;
|
||||
shared_ptr<uint32_t> weight;
|
||||
vector<MoneroOutput> vins;
|
||||
vector<MoneroOutput> vouts;
|
||||
vector<uint32_t> outputIndices;
|
||||
string metadata;
|
||||
unique_ptr<bool> isFailed;
|
||||
shared_ptr<bool> isFailed;
|
||||
|
||||
vector<MoneroIncomingTransfer> incomingTransfers;
|
||||
unique_ptr<MoneroOutgoingTransfer> outgoingTransfer;
|
||||
unique_ptr<uint32_t> numSuggestedConfirmations;
|
||||
shared_ptr<MoneroOutgoingTransfer> outgoingTransfer;
|
||||
shared_ptr<uint32_t> numSuggestedConfirmations;
|
||||
string note;
|
||||
|
||||
unique_ptr<bool> isOutgoing;
|
||||
unique_ptr<bool> isIncoming;
|
||||
shared_ptr<bool> isOutgoing;
|
||||
shared_ptr<bool> isIncoming;
|
||||
vector<string> txIds;
|
||||
unique_ptr<bool> hasPaymentId;
|
||||
shared_ptr<bool> hasPaymentId;
|
||||
vector<string> paymentIds;
|
||||
unique_ptr<uint64_t> minHeight;
|
||||
unique_ptr<uint64_t> maxHeight;
|
||||
unique_ptr<uint64_t> includeOutputs;
|
||||
unique_ptr<MoneroTransferRequest> transferRequest;
|
||||
shared_ptr<uint64_t> minHeight;
|
||||
shared_ptr<uint64_t> maxHeight;
|
||||
shared_ptr<uint64_t> includeOutputs;
|
||||
shared_ptr<MoneroTransferRequest> transferRequest;
|
||||
};
|
||||
|
||||
// --------------------------------- LISTENERS ------------------------------
|
||||
|
||||
Reference in New Issue
Block a user