implemented block header serialization;

serializing/deserializing (incomplete) transfers
This commit is contained in:
woodser
2019-06-07 18:50:41 -04:00
parent 723b969334
commit 36285ef633
3 changed files with 27 additions and 6 deletions
+25 -5
View File
@@ -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<shared_ptr<MoneroTx>> 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;
}
+1
View File
@@ -125,6 +125,7 @@ namespace monero {
boost::optional<bool> orphanStatus;
boost::optional<string> prevId;
boost::optional<uint64_t> reward;
boost::optional<string> powHash;
boost::property_tree::ptree toPropertyTree() const;
};
+1 -1
View File
@@ -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);