From 36285ef6332beb6ca5926d7b2d12a65395a6f19d Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 7 Jun 2019 18:50:41 -0400 Subject: [PATCH] implemented block header serialization; serializing/deserializing (incomplete) transfers --- src/daemon/MoneroDaemon.cpp | 30 +++++++++++++++++++++++++----- src/daemon/MoneroDaemon.h | 1 + src/wallet/MoneroWallet.cpp | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/daemon/MoneroDaemon.cpp b/src/daemon/MoneroDaemon.cpp index 033ba98..3365a10 100644 --- a/src/daemon/MoneroDaemon.cpp +++ b/src/daemon/MoneroDaemon.cpp @@ -17,15 +17,35 @@ namespace monero { boost::property_tree::ptree MoneroBlockHeader::toPropertyTree() const { cout << "MoneroBlockHeader::toPropertyTree(block)" << endl; - throw runtime_error("not implemented"); + boost::property_tree::ptree node; + if (id != boost::none) node.put("id", *id); + if (height != boost::none) node.put("height", *height); + if (timestamp != boost::none) node.put("timestamp", *timestamp); + if (size != boost::none) node.put("size", *size); + if (weight != boost::none) node.put("weight", *weight); + if (longTermWeight != boost::none) node.put("longTermWeight", *longTermWeight); + if (depth != boost::none) node.put("depth", *depth); + if (difficulty != boost::none) node.put("difficulty", *difficulty); + if (cumulativeDifficulty != boost::none) node.put("cumulativeDifficulty", *height); + if (majorVersion != boost::none) node.put("majorVersion", *majorVersion); + if (minorVersion != boost::none) node.put("minorVersion", *minorVersion); + if (nonce != boost::none) node.put("nonce", *nonce); + if (coinbaseTxId != boost::none) node.put("coinbaseTxId", *coinbaseTxId); + if (numTxs != boost::none) node.put("numTxs", *numTxs); + if (orphanStatus != boost::none) node.put("orphanStatus", *orphanStatus); + if (prevId != boost::none) node.put("prevId", *prevId); + if (reward != boost::none) node.put("reward", *reward); + if (powHash != boost::none) node.put("powHash", *powHash); + return node; } boost::property_tree::ptree MoneroBlock::toPropertyTree() const { cout << "MoneroBlock::toPropertyTree(block)" << endl; - boost::property_tree::ptree node; - if (height != boost::none) node.put("height", *height); // TODO: finish this, add txs - cout << "We should be adding " << txs.size() << " txs" << endl; - node.add_child("txs", MoneroUtils::toPropertyTree(txs)); // TODO: txs is vector> so need to handle + boost::property_tree::ptree node = MoneroBlockHeader::toPropertyTree(); + if (hex != boost::none) node.put("hex", *hex); + if (coinbaseTx != boost::none) node.add_child("coinbaseTx", coinbaseTx->toPropertyTree()); + node.add_child("txs", MoneroUtils::toPropertyTree(txs)); + // TODO: handle txIds return node; } diff --git a/src/daemon/MoneroDaemon.h b/src/daemon/MoneroDaemon.h index 15cacf8..1dc1e00 100644 --- a/src/daemon/MoneroDaemon.h +++ b/src/daemon/MoneroDaemon.h @@ -125,6 +125,7 @@ namespace monero { boost::optional orphanStatus; boost::optional prevId; boost::optional reward; + boost::optional powHash; boost::property_tree::ptree toPropertyTree() const; }; diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index 54675b0..c407304 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -54,7 +54,7 @@ namespace monero { cout << "MoneroTxWallet::toPropertyTree(node)" << endl; boost::property_tree::ptree node = MoneroTx::toPropertyTree(); if (!vouts.empty()) throw runtime_error("vouts not implemented"); - if (!incomingTransfers.empty()) MoneroUtils::toPropertyTree(incomingTransfers); + if (!incomingTransfers.empty()) node.add_child("incomingTransfers", MoneroUtils::toPropertyTree(incomingTransfers)); if (outgoingTransfer != boost::none) throw runtime_error("outgoingTransfers not implemented"); if (numSuggestedConfirmations != boost::none) node.put("numSuggestedConfirmations", *numSuggestedConfirmations); if (note != boost::none) node.put("note", *note);