From d0f91c5c2e67a2f2ce1fac43681ef993652d67b2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 14 Oct 2014 11:38:50 -0700 Subject: [PATCH] remove old mechanism for octree payments --- interface/src/Application.cpp | 6 -- interface/src/PaymentManager.cpp | 64 ----------------- interface/src/PaymentManager.h | 25 ------- interface/src/SignedWalletTransaction.cpp | 86 ----------------------- interface/src/SignedWalletTransaction.h | 32 --------- 5 files changed, 213 deletions(-) delete mode 100644 interface/src/PaymentManager.cpp delete mode 100644 interface/src/PaymentManager.h delete mode 100644 interface/src/SignedWalletTransaction.cpp delete mode 100644 interface/src/SignedWalletTransaction.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index af108dc947..4e5d3c9e96 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -73,7 +73,6 @@ #include "InterfaceVersion.h" #include "Menu.h" #include "ModelUploader.h" -#include "PaymentManager.h" #include "Util.h" #include "devices/MIDIManager.h" #include "devices/OculusManager.h" @@ -251,11 +250,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(&domainHandler, &DomainHandler::settingsReceived, this, &Application::domainSettingsReceived); connect(&domainHandler, &DomainHandler::hostnameChanged, Menu::getInstance(), &Menu::clearLoginDialogDisplayedFlag); - // hookup VoxelEditSender to PaymentManager so we can pay for octree edits - const PaymentManager& paymentManager = PaymentManager::getInstance(); - connect(&_voxelEditSender, &VoxelEditPacketSender::octreePaymentRequired, - &paymentManager, &PaymentManager::sendSignedPayment); - // update our location every 5 seconds in the data-server, assuming that we are authenticated with one const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * 1000; diff --git a/interface/src/PaymentManager.cpp b/interface/src/PaymentManager.cpp deleted file mode 100644 index a0c05f34b3..0000000000 --- a/interface/src/PaymentManager.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// -// PaymentManager.cpp -// interface/src -// -// Created by Stephen Birarda on 2014-07-30. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include -#include -#include - -#include -#include -#include - -#include "SignedWalletTransaction.h" - -#include "PaymentManager.h" - -PaymentManager& PaymentManager::getInstance() { - static PaymentManager sharedInstance; - return sharedInstance; -} - -void PaymentManager::sendSignedPayment(qint64 satoshiAmount, const QUuid& nodeUUID, const QUuid& destinationWalletUUID) { - - QByteArray walletPrivateKeyByteArray = Menu::getInstance()->getWalletPrivateKey(); - - 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 diff --git a/interface/src/PaymentManager.h b/interface/src/PaymentManager.h deleted file mode 100644 index 67419a39a4..0000000000 --- a/interface/src/PaymentManager.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// PaymentManager.h -// interface/src -// -// Created by Stephen Birarda on 2014-07-30. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_PaymentManager_h -#define hifi_PaymentManager_h - -#include - -class PaymentManager : public QObject { - Q_OBJECT -public: - static PaymentManager& getInstance(); -public slots: - void sendSignedPayment(qint64 satoshiAmount, const QUuid& nodeUUID, const QUuid& destinationWalletUUID); -}; - -#endif // hifi_PaymentManager_h \ No newline at end of file diff --git a/interface/src/SignedWalletTransaction.cpp b/interface/src/SignedWalletTransaction.cpp deleted file mode 100644 index 8a0d4e6fdb..0000000000 --- a/interface/src/SignedWalletTransaction.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// -// SignedWalletTransaction.cpp -// interface/src -// -// Created by Stephen Birarda on 2014-07-11. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include -#include -#include - -#include -#include -#include - -#include - -#include "Menu.h" - -#include "SignedWalletTransaction.h" - -SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount, - qint64 messageTimestamp, qint64 expiryDelta) : - WalletTransaction(destinationUUID, amount), - _messageTimestamp(messageTimestamp), - _expiryDelta(expiryDelta) -{ - -} - -QByteArray SignedWalletTransaction::binaryMessage() { - // build the message using the components of this transaction - - // UUID, source UUID, destination UUID, message timestamp, expiry delta, amount - QByteArray messageBinary; - - messageBinary.append(_uuid.toRfc4122()); - - messageBinary.append(reinterpret_cast(&_messageTimestamp), sizeof(_messageTimestamp)); - messageBinary.append(reinterpret_cast(&_expiryDelta), sizeof(_expiryDelta)); - - messageBinary.append(AccountManager::getInstance().getAccountInfo().getWalletID().toRfc4122()); - - messageBinary.append(_destinationUUID.toRfc4122()); - - messageBinary.append(reinterpret_cast(&_amount), sizeof(_amount)); - - return messageBinary; -} - -QByteArray SignedWalletTransaction::hexMessage() { - return binaryMessage().toHex(); -} - -QByteArray SignedWalletTransaction::messageDigest() { - return QCryptographicHash::hash(hexMessage(), QCryptographicHash::Sha256).toHex(); -} - -QByteArray SignedWalletTransaction::signedMessageDigest() { - // pull the current private key from menu into RSA structure in memory - QByteArray privateKeyByteArray = Menu::getInstance()->getWalletPrivateKey(); - - BIO* privateKeyBIO = NULL; - RSA* rsaPrivateKey = NULL; - - privateKeyBIO = BIO_new_mem_buf(privateKeyByteArray.data(), privateKeyByteArray.size()); - PEM_read_bio_RSAPrivateKey(privateKeyBIO, &rsaPrivateKey, NULL, NULL); - - QByteArray digestToEncrypt = messageDigest(); - QByteArray encryptedDigest(RSA_size(rsaPrivateKey), 0); - - int encryptReturn = RSA_private_encrypt(digestToEncrypt.size(), - reinterpret_cast(digestToEncrypt.constData()), - reinterpret_cast(encryptedDigest.data()), - rsaPrivateKey, RSA_PKCS1_PADDING); - - // free the two structures used - BIO_free(privateKeyBIO); - RSA_free(rsaPrivateKey); - - return (encryptReturn != -1) ? encryptedDigest : QByteArray(); -} \ No newline at end of file diff --git a/interface/src/SignedWalletTransaction.h b/interface/src/SignedWalletTransaction.h deleted file mode 100644 index 6bc66a535e..0000000000 --- a/interface/src/SignedWalletTransaction.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// SignedWalletTransaction.h -// interfac/src -// -// Created by Stephen Birarda on 2014-07-11. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_SignedWalletTransaction_h -#define hifi_SignedWalletTransaction_h - -#include - -class SignedWalletTransaction : public WalletTransaction { - Q_OBJECT -public: - SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount, qint64 messageTimestamp, qint64 expiryDelta); - - QByteArray binaryMessage(); - QByteArray hexMessage(); - QByteArray messageDigest(); - QByteArray signedMessageDigest(); - -private: - qint64 _messageTimestamp; - qint64 _expiryDelta; -}; - -#endif // hifi_SignedWalletTransaction_h \ No newline at end of file