From a00c4a9ee5c8420fe4d30305aee84608df28b1ab Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 2 Jul 2019 20:29:22 -0400 Subject: [PATCH] MoneroCheck fields are optional; make error messages consistent with rpc --- src/wallet/MoneroWallet.cpp | 44 +++++++++++++++++++++++--------- src/wallet/MoneroWalletModel.cpp | 10 ++++---- src/wallet/MoneroWalletModel.h | 10 ++++---- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index 3849290..6aa6009 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -1291,7 +1291,7 @@ namespace monero { cout << "MoneroWallet::getTxNote" << endl; cryptonote::blobdata txBlob; if (!epee::string_tools::parse_hexstr_to_binbuff(txId, txBlob) || txBlob.size() != sizeof(crypto::hash)) { - throw runtime_error("Tx id has invalid format"); + throw runtime_error("TX ID has invalid format"); } crypto::hash txHash = *reinterpret_cast(txBlob.data()); return wallet2->get_tx_note(txHash); @@ -1301,7 +1301,7 @@ namespace monero { cout << "MoneroWallet::setTxNote" << endl; cryptonote::blobdata txBlob; if (!epee::string_tools::parse_hexstr_to_binbuff(txId, txBlob) || txBlob.size() != sizeof(crypto::hash)) { - throw runtime_error("Tx id has invalid format"); + throw runtime_error("TX ID has invalid format"); } crypto::hash txHash = *reinterpret_cast(txBlob.data()); wallet2->set_tx_note(txHash, note); @@ -1357,7 +1357,7 @@ namespace monero { // validate and parse tx id hash crypto::hash txHash; if (!epee::string_tools::hex_to_pod(txId, txHash)) { - throw runtime_error("Tx id has invalid format"); + throw runtime_error("TX ID has invalid format"); } // get tx key and additional keys @@ -1382,7 +1382,7 @@ namespace monero { // validate and parse tx id crypto::hash txHash; if (!epee::string_tools::hex_to_pod(txId, txHash)) { - throw runtime_error("Tx id has invalid format"); + throw runtime_error("TX ID has invalid format"); } // validate and parse tx key @@ -1414,9 +1414,15 @@ namespace monero { } // initialize and return tx check using wallet2 + uint64_t receivedAmount; + bool inTxPool; + uint64_t numConfirmations; + wallet2->check_tx_key(txHash, tx_key, additionalTxKeys, info.address, receivedAmount, inTxPool, numConfirmations); shared_ptr checkTx = shared_ptr(new MoneroCheckTx()); - wallet2->check_tx_key(txHash, tx_key, additionalTxKeys, info.address, checkTx->receivedAmount, checkTx->inTxPool, checkTx->numConfirmations); checkTx->isGood = true; // check is good if we get this far + checkTx->receivedAmount = receivedAmount; + checkTx->inTxPool = inTxPool; + checkTx->numConfirmations = numConfirmations; return checkTx; } @@ -1425,7 +1431,7 @@ namespace monero { // validate and parse tx id hash crypto::hash txHash; if (!epee::string_tools::hex_to_pod(txId, txHash)) { - throw runtime_error("Tx id has invalid format"); + throw runtime_error("TX ID has invalid format"); } // validate and parse address @@ -1444,7 +1450,7 @@ namespace monero { // validate and parse tx id crypto::hash txHash; if (!epee::string_tools::hex_to_pod(txId, txHash)) { - throw runtime_error("Tx id has invalid format"); + throw runtime_error("TX ID has invalid format"); } // validate and parse address @@ -1455,7 +1461,15 @@ namespace monero { // initialize and return tx check using wallet2 shared_ptr checkTx = shared_ptr(new MoneroCheckTx()); - checkTx->isGood = wallet2->check_tx_proof(txHash, info.address, info.is_subaddress, message, signature, checkTx->receivedAmount, checkTx->inTxPool, checkTx->numConfirmations); + uint64_t receivedAmount; + bool inTxPool; + uint64_t numConfirmations; + checkTx->isGood = wallet2->check_tx_proof(txHash, info.address, info.is_subaddress, message, signature, receivedAmount, inTxPool, numConfirmations); + if (checkTx->isGood) { + checkTx->receivedAmount = receivedAmount; + checkTx->inTxPool = inTxPool; + checkTx->numConfirmations = numConfirmations; + } return checkTx; } @@ -1465,7 +1479,7 @@ namespace monero { // validate and parse tx id crypto::hash txHash; if (!epee::string_tools::hex_to_pod(txId, txHash)) { - throw runtime_error("Tx id has invalid format"); + throw runtime_error("TX ID has invalid format"); } // return spend proof signature @@ -1478,11 +1492,11 @@ namespace monero { // validate and parse tx id crypto::hash txHash; if (!epee::string_tools::hex_to_pod(txId, txHash)) { - throw runtime_error("Tx id has invalid format"); + throw runtime_error("TX ID has invalid format"); } // check spend proof - wallet2->check_spend_proof(txHash, message, signature); + return wallet2->check_spend_proof(txHash, message, signature); } string MoneroWallet::getReserveProofWallet(const string& message) const { @@ -1509,7 +1523,13 @@ namespace monero { // initialize check reserve using wallet2 shared_ptr checkReserve = shared_ptr(new MoneroCheckReserve()); - checkReserve->isGood = wallet2->check_reserve_proof(info.address, message, signature, checkReserve->totalAmount, checkReserve->unconfirmedSpentAmount); + uint64_t totalAmount; + uint64_t unconfirmedSpentAmount; + checkReserve->isGood = wallet2->check_reserve_proof(info.address, message, signature, totalAmount, unconfirmedSpentAmount); + if (checkReserve->isGood) { + checkReserve->totalAmount = totalAmount; + checkReserve->unconfirmedSpentAmount = unconfirmedSpentAmount; + } return checkReserve; } diff --git a/src/wallet/MoneroWalletModel.cpp b/src/wallet/MoneroWalletModel.cpp index 3d1adbf..1045c58 100644 --- a/src/wallet/MoneroWalletModel.cpp +++ b/src/wallet/MoneroWalletModel.cpp @@ -421,9 +421,9 @@ namespace monero { boost::property_tree::ptree MoneroCheckTx::toPropertyTree() const { boost::property_tree::ptree node = MoneroCheck::toPropertyTree();; - node.put("inTxPool", inTxPool); - node.put("numConfirmations", numConfirmations); - node.put("receivedAmount", receivedAmount); + 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; } @@ -431,8 +431,8 @@ namespace monero { boost::property_tree::ptree MoneroCheckReserve::toPropertyTree() const { boost::property_tree::ptree node = MoneroCheck::toPropertyTree(); - node.put("totalAmount", totalAmount); - node.put("unconfirmedSpentAmount", unconfirmedSpentAmount); + if (totalAmount != boost::none) node.put("totalAmount", *totalAmount); + if (unconfirmedSpentAmount != boost::none) node.put("unconfirmedSpentAmount", *unconfirmedSpentAmount); return node; } } diff --git a/src/wallet/MoneroWalletModel.h b/src/wallet/MoneroWalletModel.h index 042f465..da5f9a4 100644 --- a/src/wallet/MoneroWalletModel.h +++ b/src/wallet/MoneroWalletModel.h @@ -279,9 +279,9 @@ namespace monero { * Results from checking a transaction key. */ struct MoneroCheckTx : public MoneroCheck { - bool inTxPool; - uint64_t numConfirmations; - uint64_t receivedAmount; + boost::optional inTxPool; + boost::optional numConfirmations; + boost::optional receivedAmount; boost::property_tree::ptree toPropertyTree() const; }; @@ -290,8 +290,8 @@ namespace monero { * Results from checking a reserve proof. */ struct MoneroCheckReserve : public MoneroCheck { - uint64_t totalAmount; - uint64_t unconfirmedSpentAmount; + boost::optional totalAmount; + boost::optional unconfirmedSpentAmount; boost::property_tree::ptree toPropertyTree() const; };