/** * Copyright (c) 2017-2019 woodser * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Parts of this file are originally copyright (c) 2014-2019, The Monero Project * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * All rights reserved. * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers */ #include "MoneroWallet.h" #include "utils/MoneroUtils.h" #include #include using namespace std; /** * Public library interface. */ namespace monero { // ----------------------- UNDECLARED PRIVATE HELPERS ----------------------- void mergeIncomingTransfer(vector>& transfers, const shared_ptr& transfer) { for (const shared_ptr& aTransfer : transfers) { if (aTransfer->accountIndex.get() == transfer->accountIndex.get() && aTransfer->subaddressIndex.get() == transfer->subaddressIndex.get()) { aTransfer->merge(aTransfer, transfer); return; } } transfers.push_back(transfer); } // ---------------------------- MONERO ACCOUNT ------------------------------ boost::property_tree::ptree MoneroAccount::toPropertyTree() const { boost::property_tree::ptree node; if (index != boost::none) node.put("index", *index); if (primaryAddress != boost::none) node.put("primaryAddress", *primaryAddress); if (balance != boost::none) node.put("balance", *balance); if (unlockedBalance != boost::none) node.put("unlockedBalance", *unlockedBalance); if (!subaddresses.empty()) node.add_child("subaddresses", MoneroUtils::toPropertyTree(subaddresses)); return node; } // -------------------------- MONERO SUBADDRESS ----------------------------- boost::property_tree::ptree MoneroSubaddress::toPropertyTree() const { boost::property_tree::ptree node; if (accountIndex != boost::none) node.put("accountIndex", *accountIndex); if (index != boost::none) node.put("index", *index); if (address != boost::none) node.put("address", *address); if (label != boost::none) node.put("label", *label); if (balance != boost::none) node.put("balance", *balance); if (unlockedBalance != boost::none) node.put("unlockedBalance", *unlockedBalance); if (numUnspentOutputs != boost::none) node.put("numUnspentOutputs", *numUnspentOutputs); if (isUsed != boost::none) node.put("isUsed", *isUsed); if (numBlocksToUnlock != boost::none) node.put("numBlocksToUnlock", *numBlocksToUnlock); return node; } // --------------------------- MONERO TX WALLET ----------------------------- shared_ptr MoneroTxWallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { MTRACE("MoneroTxWallet::copy(const shared_ptr& src, const shared_ptr& tgt)"); return MoneroTxWallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); }; shared_ptr MoneroTxWallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { MTRACE("MoneroTxWallet::copy(const shared_ptr& src, const shared_ptr& tgt)"); if (this != src.get()) throw runtime_error("this != src"); // copy base class MoneroTx::copy(static_pointer_cast(src), static_pointer_cast(tgt)); // copy wallet extensions if (!src->incomingTransfers.empty()) { tgt->incomingTransfers = vector>(); for (const shared_ptr& transfer : src->incomingTransfers) { shared_ptr transferCopy = transfer->copy(transfer, shared_ptr()); transferCopy->tx = tgt; tgt->incomingTransfers.push_back(transferCopy); } } if (src->outgoingTransfer != boost::none) { shared_ptr transferCopy = src->outgoingTransfer.get()->copy(src->outgoingTransfer.get(), make_shared()); transferCopy->tx = tgt; tgt->outgoingTransfer = transferCopy; } tgt->note = src->note; return tgt; }; boost::property_tree::ptree MoneroTxWallet::toPropertyTree() const { boost::property_tree::ptree node = MoneroTx::toPropertyTree(); if (!incomingTransfers.empty()) node.add_child("incomingTransfers", MoneroUtils::toPropertyTree(incomingTransfers)); if (outgoingTransfer != boost::none) node.add_child("outgoingTransfer", (*outgoingTransfer)->toPropertyTree()); if (note != boost::none) node.put("note", *note); return node; } bool MoneroTxWallet::getIsOutgoing() const { return outgoingTransfer != boost::none; } bool MoneroTxWallet::getIsIncoming() const { return !incomingTransfers.empty(); } void MoneroTxWallet::merge(const shared_ptr& self, const shared_ptr& other) { merge(static_pointer_cast(self), static_pointer_cast(other)); } void MoneroTxWallet::merge(const shared_ptr& self, const shared_ptr& other) { if (this != self.get()) throw runtime_error("this != self"); if (self == other) return; // merge base classes MoneroTx::merge(self, other); // merge wallet extensions note = MoneroUtils::reconcile(note, other->note); // merge incoming transfers if (!other->incomingTransfers.empty()) { for (const shared_ptr& transfer : other->incomingTransfers) { // NOTE: not using reference so shared_ptr is not deleted when tx is dereferenced transfer->tx = self; mergeIncomingTransfer(self->incomingTransfers, transfer); } } // merge outgoing transfer if (other->outgoingTransfer != boost::none) { other->outgoingTransfer.get()->tx = self; if (self->outgoingTransfer == boost::none) self->outgoingTransfer = other->outgoingTransfer; else self->outgoingTransfer.get()->merge(self->outgoingTransfer.get(), other->outgoingTransfer.get()); } } // -------------------------- MONERO TX REQUEST ----------------------------- shared_ptr MoneroTxRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { return copy(static_pointer_cast(src), static_pointer_cast(tgt)); }; shared_ptr MoneroTxRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { return copy(static_pointer_cast(src), static_pointer_cast(tgt)); }; shared_ptr MoneroTxRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { MTRACE("MoneroTxRequest::copy(const shared_ptr& src, const shared_ptr& tgt)"); if (this != src.get()) throw runtime_error("this != src"); // copy base class MoneroTxWallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); // copy request extensions tgt->isOutgoing = src->isOutgoing; tgt->isIncoming = src->isIncoming; if (!src->txIds.empty()) tgt->txIds = vector(src->txIds); tgt-> hasPaymentId = src->hasPaymentId; if (!src->paymentIds.empty()) tgt->paymentIds = vector(src->paymentIds); tgt->height = src->height; tgt->minHeight = src->minHeight; tgt->maxHeight = src->maxHeight; tgt->includeOutputs = src->includeOutputs; if (src->transferRequest != boost::none) tgt->transferRequest = src->transferRequest.get()->copy(src->transferRequest.get(), make_shared()); if (src->outputRequest != boost::none) tgt->outputRequest = src->outputRequest.get()->copy(src->outputRequest.get(), make_shared()); }; boost::property_tree::ptree MoneroTxRequest::toPropertyTree() const { boost::property_tree::ptree node = MoneroTxWallet::toPropertyTree(); if (isOutgoing != boost::none) node.put("isOutgoing", *isOutgoing); if (isIncoming != boost::none) node.put("isIncoming", *isIncoming); if (!txIds.empty()) node.add_child("txIds", MoneroUtils::toPropertyTree(txIds)); if (hasPaymentId != boost::none) node.put("hasPaymentId", *hasPaymentId); if (!paymentIds.empty()) node.add_child("paymentIds", MoneroUtils::toPropertyTree(paymentIds)); if (height != boost::none) node.put("height", *height); if (minHeight != boost::none) node.put("minHeight", *minHeight); if (maxHeight != boost::none) node.put("maxHeight", *maxHeight); if (includeOutputs != boost::none) node.put("includeOutputs", *includeOutputs); if (transferRequest != boost::none) node.add_child("transferRequest", (*transferRequest)->toPropertyTree()); return node; } bool MoneroTxRequest::meetsCriteria(MoneroTxWallet* tx) const { if (tx == nullptr) return false; // filter on tx if (id != boost::none && id != tx->id) return false; if (paymentId != boost::none && paymentId != tx->paymentId) return false; if (isConfirmed != boost::none && isConfirmed != tx->isConfirmed) return false; if (inTxPool != boost::none && inTxPool != tx->inTxPool) return false; if (doNotRelay != boost::none && doNotRelay != tx->doNotRelay) return false; if (isFailed != boost::none && isFailed != tx->isFailed) return false; if (isCoinbase != boost::none && isCoinbase != tx->isCoinbase) return false; // at least one transfer must meet transfer request if defined if (transferRequest != boost::none) { bool matchFound = false; if (tx->outgoingTransfer != boost::none && (*transferRequest)->meetsCriteria((*tx->outgoingTransfer).get())) matchFound = true; else if (!tx->incomingTransfers.empty()) { for (const shared_ptr& incomingTransfer : tx->incomingTransfers) { if ((*transferRequest)->meetsCriteria(incomingTransfer.get())) { matchFound = true; break; } } } if (!matchFound) return false; } // filter on having a payment id if (hasPaymentId != boost::none) { if (*hasPaymentId && tx->paymentId == boost::none) return false; if (!*hasPaymentId && tx->paymentId != boost::none) return false; } // filter on incoming if (isIncoming != boost::none && isIncoming != tx->getIsIncoming()) return false; // filter on outgoing if (isOutgoing != boost::none && isOutgoing != tx->getIsOutgoing()) return false; // filter on remaining fields boost::optional txHeight = tx->getHeight(); if (!txIds.empty() && find(txIds.begin(), txIds.end(), *tx->id) == txIds.end()) return false; if (!paymentIds.empty() && (tx->paymentId == boost::none || find(paymentIds.begin(), paymentIds.end(), *tx->paymentId) == paymentIds.end())) return false; if (height != boost::none && (txHeight == boost::none || *txHeight != *height)) return false; if (minHeight != boost::none && (txHeight == boost::none || *txHeight < *minHeight)) return false; if (maxHeight != boost::none && (txHeight == boost::none || *txHeight > *maxHeight)) return false; // transaction meets request criteria return true; } // -------------------------- MONERO DESTINATION ---------------------------- boost::property_tree::ptree MoneroDestination::toPropertyTree() const { boost::property_tree::ptree node; if (address != boost::none) node.put("address", *address); if (amount != boost::none) node.put("amount", *amount); return node; } // ---------------------------- MONERO TRANSFER ----------------------------- shared_ptr MoneroTransfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroTransfer::copy() not implemented"); }; boost::property_tree::ptree MoneroTransfer::toPropertyTree() const { boost::property_tree::ptree node; if (amount != boost::none) node.put("amount", *amount); if (accountIndex != boost::none) node.put("accountIndex", *accountIndex); if (numSuggestedConfirmations != boost::none) node.put("numSuggestedConfirmations", *numSuggestedConfirmations); return node; } void MoneroTransfer::merge(const shared_ptr& self, const shared_ptr& other) { if (this != self.get()) throw runtime_error("this != self"); if (self == other) return; // merge txs if they're different which comes back to merging transfers if (tx != other->tx) { tx->merge(tx, other->tx); return; } // otherwise merge transfer fields accountIndex = MoneroUtils::reconcile(accountIndex, other->accountIndex, "acountIndex"); // TODO monero core: failed tx in pool (after testUpdateLockedDifferentAccounts()) causes non-originating saved wallets to return duplicate incoming transfers but one has amount/numSuggestedConfirmations of 0 if (amount != boost::none && other->amount != boost::none && *amount != *other->amount && (*amount == 0 || *other->amount == 0)) { accountIndex = MoneroUtils::reconcile(accountIndex, other->accountIndex, boost::none, boost::none, true, "acountIndex"); numSuggestedConfirmations = MoneroUtils::reconcile(numSuggestedConfirmations, other->numSuggestedConfirmations, boost::none, boost::none, true, "numSuggestedConfirmations"); MWARNING("WARNING: failed tx in pool causes non-originating wallets to return duplicate incoming transfers but with one amount/numSuggestedConfirmations of 0"); } else { amount = MoneroUtils::reconcile(amount, other->amount, "transfer amount"); numSuggestedConfirmations = MoneroUtils::reconcile(numSuggestedConfirmations, other->numSuggestedConfirmations, boost::none, boost::none, false, "numSuggestedConfirmations"); } } // ----------------------- MONERO INCOMING TRANSFER ------------------------- shared_ptr MoneroIncomingTransfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroIncomingTransfer::copy(transfer) not implemented"); }; shared_ptr MoneroIncomingTransfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroIncomingTransfer::copy(inTransfer) not implemented"); }; boost::optional MoneroIncomingTransfer::getIsIncoming() const { return true; } boost::property_tree::ptree MoneroIncomingTransfer::toPropertyTree() const { boost::property_tree::ptree node = MoneroTransfer::toPropertyTree(); if (subaddressIndex != boost::none) node.put("subaddressIndex", *subaddressIndex); if (address != boost::none) node.put("address", *address); return node; } void MoneroIncomingTransfer::merge(const shared_ptr& self, const shared_ptr& other) { merge(static_pointer_cast(self), static_pointer_cast(other)); } void MoneroIncomingTransfer::merge(const shared_ptr& self, const shared_ptr& other) { if (self == other) return; MoneroTransfer::merge(self, other); subaddressIndex = MoneroUtils::reconcile(subaddressIndex, other->subaddressIndex, "incoming transfer subaddressIndex"); address = MoneroUtils::reconcile(address, other->address); } // ----------------------- MONERO OUTGOING TRANSFER ------------------------- shared_ptr MoneroOutgoingTransfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroOutgoingTransfer::copy(transfer) not implemented"); }; shared_ptr MoneroOutgoingTransfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroOutgoingTransfer::copy(outTransfer) not implemented"); }; boost::optional MoneroOutgoingTransfer::getIsIncoming() const { return false; } boost::property_tree::ptree MoneroOutgoingTransfer::toPropertyTree() const { boost::property_tree::ptree node = MoneroTransfer::toPropertyTree(); if (!subaddressIndices.empty()) node.add_child("subaddressIndices", MoneroUtils::toPropertyTree(subaddressIndices)); if (!addresses.empty()) node.add_child("addresses", MoneroUtils::toPropertyTree(addresses)); if (!destinations.empty()) node.add_child("destinations", MoneroUtils::toPropertyTree(destinations)); return node; } void MoneroOutgoingTransfer::merge(const shared_ptr& self, const shared_ptr& other) { merge(static_pointer_cast(self), static_pointer_cast(other)); } void MoneroOutgoingTransfer::merge(const shared_ptr& self, const shared_ptr& other) { if (self == other) return; MoneroTransfer::merge(self, other); subaddressIndices = MoneroUtils::reconcile(subaddressIndices, other->subaddressIndices); addresses = MoneroUtils::reconcile(addresses, other->addresses); destinations = MoneroUtils::reconcile(destinations, other->destinations); } // ----------------------- MONERO TRANSFER REQUEST -------------------------- shared_ptr MoneroTransferRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { MTRACE("MoneroTransferRequest::copy(const shared_ptr& src, const shared_ptr& tgt"); throw runtime_error("MoneroTransferRequest::copy(transfer) not implemented"); }; shared_ptr MoneroTransferRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { MTRACE("MoneroTransferRequest::copy(const shared_ptr& src, const shared_ptr& tgt)"); throw runtime_error("MoneroTransferRequest::copy(request) not implemented"); }; boost::optional MoneroTransferRequest::getIsIncoming() const { return isIncoming; } boost::property_tree::ptree MoneroTransferRequest::toPropertyTree() const { boost::property_tree::ptree node = MoneroTransfer::toPropertyTree(); if (getIsIncoming() != boost::none) node.put("isIncoming", *getIsIncoming()); if (address != boost::none) node.put("address", *address); if (subaddressIndex != boost::none) node.put("subaddressIndex", *subaddressIndex); if (hasDestinations != boost::none) node.put("hasDestinations", *hasDestinations); if (!subaddressIndices.empty()) node.add_child("subaddressIndices", MoneroUtils::toPropertyTree(subaddressIndices)); if (!addresses.empty()) node.add_child("addresses", MoneroUtils::toPropertyTree(addresses)); if (!destinations.empty()) node.add_child("destinations", MoneroUtils::toPropertyTree(destinations)); return node; } bool MoneroTransferRequest::meetsCriteria(MoneroTransfer* transfer) const { if (transfer == nullptr) throw runtime_error("transfer is null"); if (txRequest != boost::none && (*txRequest)->transferRequest != boost::none) throw runtime_error("Transfer request's tx request cannot have a circular transfer request"); // TODO: could auto detect and handle this. port to java/js // filter on common fields if (getIsIncoming() != boost::none && *getIsIncoming() != *transfer->getIsIncoming()) return false; if (getIsOutgoing() != boost::none && getIsOutgoing() != transfer->getIsOutgoing()) return false; if (amount != boost::none && *amount != *transfer->amount) return false; if (accountIndex != boost::none && *accountIndex != *transfer->accountIndex) return false; // filter on incoming fields MoneroIncomingTransfer* inTransfer = dynamic_cast(transfer); if (inTransfer != nullptr) { if (hasDestinations != boost::none) return false; if (address != boost::none && *address != *inTransfer->address) return false; if (!addresses.empty() && find(addresses.begin(), addresses.end(), *inTransfer->address) == addresses.end()) return false; if (subaddressIndex != boost::none && *subaddressIndex != *inTransfer->subaddressIndex) return false; if (!subaddressIndices.empty() && find(subaddressIndices.begin(), subaddressIndices.end(), *inTransfer->subaddressIndex) == subaddressIndices.end()) return false; } // filter on outgoing fields MoneroOutgoingTransfer* outTransfer = dynamic_cast(transfer); if (outTransfer != nullptr) { // filter on addresses if (address != boost::none && (outTransfer->addresses.empty() || find(outTransfer->addresses.begin(), outTransfer->addresses.end(), *address) == outTransfer->addresses.end())) return false; // TODO: will filter all transfers if they don't contain addresses if (!addresses.empty()) { bool intersects = false; for (const string& addressReq : addresses) { for (const string& address : outTransfer->addresses) { if (addressReq == address) { intersects = true; break; } } } if (!intersects) return false; // must have overlapping addresses } // filter on subaddress indices if (subaddressIndex != boost::none && (outTransfer->subaddressIndices.empty() || find(outTransfer->subaddressIndices.begin(), outTransfer->subaddressIndices.end(), *subaddressIndex) == outTransfer->subaddressIndices.end())) return false; // TODO: will filter all transfers if they don't contain subaddress indices if (!subaddressIndices.empty()) { bool intersects = false; for (const uint32_t& subaddressIndexReq : subaddressIndices) { for (const uint32_t& subaddressIndex : outTransfer->subaddressIndices) { if (subaddressIndexReq == subaddressIndex) { intersects = true; break; } } } if (!intersects) return false; // must have overlapping subaddress indices } // filter on having destinations if (hasDestinations != boost::none) { if (*hasDestinations && outTransfer->destinations.empty()) return false; if (!*hasDestinations && !outTransfer->destinations.empty()) return false; } // filter on destinations TODO: start with test for this // if (this.getDestionations() != null && this.getDestionations() != transfer.getDestionations()) return false; } // validate type if (inTransfer == nullptr && outTransfer == nullptr) throw runtime_error("Transfer must be MoneroIncomingTransfer or MoneroOutgoingTransfer"); // filter with tx request if (txRequest != boost::none && !(*txRequest)->meetsCriteria(transfer->tx.get())) return false; return true; } // ------------------------- MONERO OUTPUT WALLET --------------------------- shared_ptr MoneroOutputWallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { MTRACE("MoneroOutputWallet::copy(output)"); return MoneroOutputWallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); }; shared_ptr MoneroOutputWallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { MTRACE("MoneroOutputWallet::copy(outputWallet)"); if (this != src.get()) throw runtime_error("this != src"); // copy base class MoneroOutputWallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); throw runtime_error("MoneroOutputWallet::copy(outputWallet) not implemented"); }; boost::property_tree::ptree MoneroOutputWallet::toPropertyTree() const { boost::property_tree::ptree node = MoneroOutput::toPropertyTree(); if (accountIndex != boost::none) node.put("accountIndex", *accountIndex); if (subaddressIndex != boost::none) node.put("subaddressIndex", *subaddressIndex); if (isSpent != boost::none) node.put("isSpent", *isSpent); if (isUnlocked != boost::none) node.put("isUnlocked", *isUnlocked); if (isFrozen != boost::none) node.put("isFrozen", *isFrozen); return node; } void MoneroOutputWallet::merge(const shared_ptr& self, const shared_ptr& other) { merge(static_pointer_cast(self), static_pointer_cast(other)); } void MoneroOutputWallet::merge(const shared_ptr& self, const shared_ptr& other) { throw runtime_error("MoneroOutputWallet::merge(self, other) not implemented"); } // ------------------------ MONERO OUTPUT REQUEST --------------------------- shared_ptr MoneroOutputRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroOutputRequest::copy(output) not implemented"); }; shared_ptr MoneroOutputRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroOutputRequest::copy(outputWallet) not implemented"); }; shared_ptr MoneroOutputRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroOutputRequest::copy(outputRequest) not implemented"); }; boost::property_tree::ptree MoneroOutputRequest::toPropertyTree() const { boost::property_tree::ptree node = MoneroOutputWallet::toPropertyTree(); if (!subaddressIndices.empty()) node.add_child("subaddressIndices", MoneroUtils::toPropertyTree(subaddressIndices)); return node; } bool MoneroOutputRequest::meetsCriteria(MoneroOutputWallet* output) const { // filter on output if (accountIndex != boost::none && *accountIndex != *output->accountIndex) return false; if (subaddressIndex != boost::none && *subaddressIndex != *output->subaddressIndex) return false; if (amount != boost::none && *amount != *output->amount) return false; if (isSpent != boost::none && *isSpent != *output->isSpent) return false; if (isUnlocked != boost::none && *isUnlocked != *output->isUnlocked) return false; // filter on output key image if (keyImage != boost::none) { if (output->keyImage == boost::none) return false; if ((*keyImage)->hex != boost::none && ((*output->keyImage)->hex == boost::none || *(*keyImage)->hex != *(*output->keyImage)->hex)) return false; if ((*keyImage)->signature != boost::none && ((*output->keyImage)->signature == boost::none || *(*keyImage)->signature != *(*output->keyImage)->signature)) return false; } // filter on extensions if (!subaddressIndices.empty() && find(subaddressIndices.begin(), subaddressIndices.end(), *output->subaddressIndex) == subaddressIndices.end()) return false; // filter with tx request if (txRequest != boost::none && !(*txRequest)->meetsCriteria(static_pointer_cast(output->tx).get())) return false; // output meets request return true; } // ------------------------- MONERO SEND REQUEST ---------------------------- boost::property_tree::ptree MoneroSendRequest::toPropertyTree() const { boost::property_tree::ptree node; if (!destinations.empty()) node.add_child("destinations", MoneroUtils::toPropertyTree(destinations)); if (paymentId != boost::none) node.put("paymentId", *paymentId); if (priority != boost::none) node.put("priority", *priority); if (mixin != boost::none) node.put("mixin", *mixin); if (ringSize != boost::none) node.put("ringSize", *ringSize); if (accountIndex != boost::none) node.put("accountIndex", *accountIndex); if (!subaddressIndices.empty()) node.add_child("subaddressIndices", MoneroUtils::toPropertyTree(subaddressIndices)); if (unlockTime != boost::none) node.put("unlockTime", *unlockTime); if (canSplit != boost::none) node.put("canSplit", *canSplit); if (doNotRelay != boost::none) node.put("doNotRelay", *doNotRelay); if (note != boost::none) node.put("note", *note); if (recipientName != boost::none) node.put("recipientName", *recipientName); if (belowAmount != boost::none) node.put("belowAmount", *belowAmount); if (sweepEachSubaddress != boost::none) node.put("sweepEachSubaddress", *sweepEachSubaddress); if (keyImage != boost::none) node.put("keyImage", *keyImage); return node; } // ---------------------- MONERO INTEGRATED ADDRESS ------------------------- boost::property_tree::ptree MoneroIntegratedAddress::toPropertyTree() const { boost::property_tree::ptree node; node.put("standardAddress", standardAddress); node.put("paymentId", paymentId); node.put("integratedAddress", integratedAddress); return node; } // -------------------- MONERO KEY IMAGE IMPORT RESULT ---------------------- boost::property_tree::ptree MoneroKeyImageImportResult::toPropertyTree() const { boost::property_tree::ptree node; if (height != boost::none) node.put("height", *height); if (spentAmount != boost::none) node.put("spentAmount", *spentAmount); if (unspentAmount != boost::none) node.put("unspentAmount", *unspentAmount); return node; } // ----------------------------- MONERO CHECK ------------------------------- boost::property_tree::ptree MoneroCheck::toPropertyTree() const { boost::property_tree::ptree node; node.put("isGood", isGood); return node; } // --------------------------- MONERO CHECK TX ------------------------------ boost::property_tree::ptree MoneroCheckTx::toPropertyTree() const { boost::property_tree::ptree node = MoneroCheck::toPropertyTree();; if (inTxPool != boost::none) node.put("inTxPool", *inTxPool); if (numConfirmations != boost::none) node.put("numConfirmations", *numConfirmations); if (receivedAmount != boost::none) node.put("receivedAmount", *receivedAmount); return node; } // ------------------------ MONERO CHECK RESERVE ---------------------------- boost::property_tree::ptree MoneroCheckReserve::toPropertyTree() const { boost::property_tree::ptree node = MoneroCheck::toPropertyTree(); if (totalAmount != boost::none) node.put("totalAmount", *totalAmount); if (unconfirmedSpentAmount != boost::none) node.put("unconfirmedSpentAmount", *unconfirmedSpentAmount); return node; } }