remove old mechanism for octree payments

This commit is contained in:
Stephen Birarda 2014-10-14 11:38:50 -07:00
parent 912512936e
commit d0f91c5c2e
5 changed files with 0 additions and 213 deletions

View file

@ -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;

View file

@ -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 <QtCore/QDateTime>
#include <QtCore/QDebug>
#include <QtCore/QUuid>
#include <Menu.h>
#include <NodeList.h>
#include <PacketHeaders.h>
#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.";
}
}

View file

@ -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 <QtCore/QObject>
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

View file

@ -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 <QtCore/QCryptographicHash>
#include <QtCore/QDebug>
#include <QtCore/QFile>
#include <openssl/bio.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <AccountManager.h>
#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<const char*>(&_messageTimestamp), sizeof(_messageTimestamp));
messageBinary.append(reinterpret_cast<const char*>(&_expiryDelta), sizeof(_expiryDelta));
messageBinary.append(AccountManager::getInstance().getAccountInfo().getWalletID().toRfc4122());
messageBinary.append(_destinationUUID.toRfc4122());
messageBinary.append(reinterpret_cast<const char*>(&_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<const unsigned char*>(digestToEncrypt.constData()),
reinterpret_cast<unsigned char*>(encryptedDigest.data()),
rsaPrivateKey, RSA_PKCS1_PADDING);
// free the two structures used
BIO_free(privateKeyBIO);
RSA_free(rsaPrivateKey);
return (encryptReturn != -1) ? encryptedDigest : QByteArray();
}

View file

@ -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 <WalletTransaction.h>
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