From 74a465ec14ad667ed74ab6358dc115863febbbc0 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 5 Jun 2019 11:47:57 -0400 Subject: [PATCH] implemented basic field serialization for all tx request fields --- src/utils/MoneroUtils.cpp | 75 +++++++++++++++++++++++++++++---------- src/utils/MoneroUtils.h | 2 ++ 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/src/utils/MoneroUtils.cpp b/src/utils/MoneroUtils.cpp index 5e25345..98cdfe3 100644 --- a/src/utils/MoneroUtils.cpp +++ b/src/utils/MoneroUtils.cpp @@ -151,30 +151,69 @@ boost::property_tree::ptree MoneroUtils::toPropertyTree(const MoneroSubaddress& boost::property_tree::ptree MoneroUtils::txToPropertyTree(const MoneroTx& tx) { cout << "txToPropertyTree(tx)" << endl; boost::property_tree::ptree txNode; + if (tx.block != nullptr) txNode.put("id", *tx.id); if (tx.id != nullptr) txNode.put("id", *tx.id); -// if (subaddress.accountIndex != nullptr) subaddressNode.put("accountIndex", *subaddress.accountIndex); -// if (subaddress.index != nullptr) subaddressNode.put("index", *subaddress.index); -// if (subaddress.address != nullptr) subaddressNode.put("address", *subaddress.address); -// if (subaddress.label != nullptr) subaddressNode.put("label", *subaddress.label); -// if (subaddress.balance != nullptr) subaddressNode.put("balance", *subaddress.balance); -// if (subaddress.unlockedBalance != nullptr) subaddressNode.put("unlockedBalance", *subaddress.unlockedBalance); -// if (subaddress.numUnspentOutputs != nullptr) subaddressNode.put("numUnspentOutputs", *subaddress.numUnspentOutputs); -// if (subaddress.isUsed != nullptr) subaddressNode.put("isUsed", *subaddress.isUsed); -// if (subaddress.numBlocksToUnlock != nullptr) subaddressNode.put("numBlocksToUnlock", *subaddress.numBlocksToUnlock); + if (tx.version != nullptr) txNode.put("version", *tx.version); + if (tx.isCoinbase != nullptr) txNode.put("isCoinbase", *tx.isCoinbase); + if (tx.paymentId != nullptr) txNode.put("paymentId", *tx.paymentId); + if (tx.fee != nullptr) txNode.put("fee", *tx.fee); + if (tx.mixin != nullptr) txNode.put("mixin", *tx.mixin); + if (tx.doNotRelay != nullptr) txNode.put("doNotRelay", *tx.doNotRelay); + if (tx.isRelayed != nullptr) txNode.put("isRelayed", *tx.isRelayed); + if (tx.isConfirmed != nullptr) txNode.put("isConfirmed", *tx.isConfirmed); + if (tx.inTxPool != nullptr) txNode.put("inTxPool", *tx.inTxPool); + if (tx.numConfirmations != nullptr) txNode.put("numConfirmations", *tx.numConfirmations); + if (tx.unlockTime != nullptr) txNode.put("unlockTime", *tx.unlockTime); + if (tx.lastRelayedTimestamp != nullptr) txNode.put("lastRelayedTimestamp", *tx.lastRelayedTimestamp); + if (tx.receivedTimestamp != nullptr) txNode.put("receivedTimestamp", *tx.receivedTimestamp); + if (tx.isDoubleSpend != nullptr) txNode.put("isDoubleSpend", *tx.isDoubleSpend); + if (tx.key != nullptr) txNode.put("key", *tx.key); + if (tx.fullHex != nullptr) txNode.put("fullHex", *tx.fullHex); + if (tx.prunedHex != nullptr) txNode.put("prunedHex", *tx.prunedHex); + if (tx.prunableHex != nullptr) txNode.put("prunableHex", *tx.prunableHex); + if (tx.prunableHash != nullptr) txNode.put("prunableHash", *tx.prunableHash); + if (tx.size != nullptr) txNode.put("size", *tx.size); + if (tx.weight != nullptr) txNode.put("weight", *tx.weight); + if (!tx.vins.empty()) throw runtime_error("not implemented"); + if (!tx.vouts.empty()) throw runtime_error("not implemented"); + if (!tx.outputIndices.empty()) throw runtime_error("not implemented"); + if (tx.metadata != nullptr) txNode.put("metadata", *tx.metadata); + if (tx.commonTxSets != nullptr) throw runtime_error("not implemented"); + if (!tx.extra.empty()) throw runtime_error("not implemented"); + if (tx.rctSignatures != nullptr) throw runtime_error("not implemented"); + if (tx.rctSigPrunable != nullptr) throw runtime_error("not implemented"); + if (tx.isKeptByBlock != nullptr) txNode.put("isKeptByBlock", *tx.isKeptByBlock); + if (tx.isFailed != nullptr) txNode.put("isFailed", *tx.isFailed); + if (tx.lastFailedHeight != nullptr) txNode.put("lastFailedHeight", *tx.lastFailedHeight); + if (tx.lastFailedId != nullptr) txNode.put("lastFailedId", *tx.lastFailedId); + if (tx.maxUsedBlockHeight != nullptr) txNode.put("maxUsedBlockHeight", *tx.maxUsedBlockHeight); + if (tx.maxUsedBlockId != nullptr) txNode.put("maxUsedBlockId", *tx.maxUsedBlockId); + if (!tx.signatures.empty()) throw runtime_error("not implemented"); return txNode; } boost::property_tree::ptree MoneroUtils::txWalletToPropertyTree(const MoneroTxWallet& tx) { cout << "txWalletToPropertyTree(tx)" << endl; boost::property_tree::ptree txNode = txToPropertyTree(tx); -// if (subaddress.accountIndex != nullptr) subaddressNode.put("accountIndex", *subaddress.accountIndex); -// if (subaddress.index != nullptr) subaddressNode.put("index", *subaddress.index); -// if (subaddress.address != nullptr) subaddressNode.put("address", *subaddress.address); -// if (subaddress.label != nullptr) subaddressNode.put("label", *subaddress.label); -// if (subaddress.balance != nullptr) subaddressNode.put("balance", *subaddress.balance); -// if (subaddress.unlockedBalance != nullptr) subaddressNode.put("unlockedBalance", *subaddress.unlockedBalance); -// if (subaddress.numUnspentOutputs != nullptr) subaddressNode.put("numUnspentOutputs", *subaddress.numUnspentOutputs); -// if (subaddress.isUsed != nullptr) subaddressNode.put("isUsed", *subaddress.isUsed); -// if (subaddress.numBlocksToUnlock != nullptr) subaddressNode.put("numBlocksToUnlock", *subaddress.numBlocksToUnlock); + if (!tx.vouts.empty()) throw runtime_error("not implemented"); + if (!tx.incomingTransfers.empty()) throw runtime_error("not implemented"); + if (tx.outgoingTransfer != nullptr) throw runtime_error("not implemented"); + if (tx.numSuggestedConfirmations != nullptr) txNode.put("numSuggestedConfirmations", *tx.numSuggestedConfirmations); + if (tx.note != nullptr) txNode.put("note", *tx.note); + return txNode; +} + +boost::property_tree::ptree MoneroUtils::txRequestToPropertyTree(const MoneroTxRequest& tx) { + cout << "txWalletToPropertyTree(tx)" << endl; + boost::property_tree::ptree txNode = txWalletToPropertyTree(tx); + if (tx.isOutgoing != nullptr) txNode.put("isOutgoing", *tx.isOutgoing); + if (tx.isIncoming != nullptr) txNode.put("isIncoming", *tx.isIncoming); + if (!tx.txIds.empty()) throw runtime_error("not implemented"); + if (tx.hasPaymentId != nullptr) txNode.put("hasPaymentId", *tx.hasPaymentId); + if (!tx.paymentIds.empty()) throw runtime_error("not implemented"); + if (tx.minHeight != nullptr) txNode.put("minHeight", *tx.minHeight); + if (tx.maxHeight != nullptr) txNode.put("maxHeight", *tx.maxHeight); + if (tx.includeOutputs != nullptr) txNode.put("includeOutputs", *tx.includeOutputs); + if (tx.transferRequest != nullptr) throw runtime_error("not implemented"); return txNode; } diff --git a/src/utils/MoneroUtils.h b/src/utils/MoneroUtils.h index 011e838..af4611e 100644 --- a/src/utils/MoneroUtils.h +++ b/src/utils/MoneroUtils.h @@ -70,6 +70,8 @@ namespace MoneroUtils boost::property_tree::ptree txWalletToPropertyTree(const MoneroTxWallet& tx); + boost::property_tree::ptree txRequestToPropertyTree(const MoneroTxRequest& tx); + // // TODO: template implementation here, could move to MoneroUtils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation template boost::property_tree::ptree toPropertyTree(const vector types) { cout << "toPropertyTree(types)" << endl;