From 7860aa5b870d89eff4f26e95bd8207340d5ea44f Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 31 Jul 2014 11:41:49 -0700 Subject: [PATCH] add some error messages to PaymentManager --- interface/src/PaymentManager.cpp | 50 +++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/interface/src/PaymentManager.cpp b/interface/src/PaymentManager.cpp index 84f5e96fc9..a0c05f34b3 100644 --- a/interface/src/PaymentManager.cpp +++ b/interface/src/PaymentManager.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -27,22 +28,37 @@ PaymentManager& PaymentManager::getInstance() { void PaymentManager::sendSignedPayment(qint64 satoshiAmount, const QUuid& nodeUUID, const QUuid& destinationWalletUUID) { - // setup a signed wallet transaction - const qint64 DEFAULT_TRANSACTION_EXPIRY_SECONDS = 60; - qint64 currentTimestamp = QDateTime::currentDateTimeUtc().toTime_t(); - SignedWalletTransaction newTransaction(destinationWalletUUID, satoshiAmount, - currentTimestamp, DEFAULT_TRANSACTION_EXPIRY_SECONDS); + QByteArray walletPrivateKeyByteArray = Menu::getInstance()->getWalletPrivateKey(); - // send the signed transaction to the redeeming node - QByteArray transactionByteArray = byteArrayWithPopulatedHeader(PacketTypeSignedTransactionPayment); - - // append the binary message and the signed message digest - transactionByteArray.append(newTransaction.binaryMessage()); - transactionByteArray.append(newTransaction.signedMessageDigest()); - - qDebug() << "Paying" << satoshiAmount << "satoshis to" << destinationWalletUUID << "via" << nodeUUID; - - // use the NodeList to send that to the right node - NodeList* nodeList = NodeList::getInstance(); - nodeList->writeDatagram(transactionByteArray, nodeList->nodeWithUUID(nodeUUID)); + if (!walletPrivateKeyByteArray.isEmpty()) { + // setup a signed wallet transaction + const qint64 DEFAULT_TRANSACTION_EXPIRY_SECONDS = 60; + qint64 currentTimestamp = QDateTime::currentDateTimeUtc().toTime_t(); + SignedWalletTransaction newTransaction(destinationWalletUUID, satoshiAmount, + currentTimestamp, DEFAULT_TRANSACTION_EXPIRY_SECONDS); + + // send the signed transaction to the redeeming node + QByteArray transactionByteArray = byteArrayWithPopulatedHeader(PacketTypeSignedTransactionPayment); + + // append the binary message and the signed message digest + transactionByteArray.append(newTransaction.binaryMessage()); + QByteArray signedMessageDigest = newTransaction.signedMessageDigest(); + + if (!signedMessageDigest.isEmpty()) { + transactionByteArray.append(signedMessageDigest); + + qDebug() << "Paying" << satoshiAmount << "satoshis to" << destinationWalletUUID << "via" << nodeUUID; + + // use the NodeList to send that to the right node + NodeList* nodeList = NodeList::getInstance(); + nodeList->writeDatagram(transactionByteArray, nodeList->nodeWithUUID(nodeUUID)); + } else { + qDebug() << "Payment of" << satoshiAmount << "satoshis to" << destinationWalletUUID << "via" << nodeUUID << + "cannot be sent because there was an error signing the transaction."; + } + + } else { + qDebug() << "Payment of" << satoshiAmount << "satoshis to" << destinationWalletUUID << "via" << nodeUUID << + "cannot be sent because there is no stored wallet private key."; + } } \ No newline at end of file