From db25cd9d2c6139674e9066f81e54725f6223a0d7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 30 Jul 2014 18:07:08 -0700 Subject: [PATCH] call PaymentManager when an OctreeEditPacketSender needs to pay --- interface/src/Application.cpp | 17 ++++++++++--- interface/src/PaymentManager.cpp | 24 ++++++++++++++++++ interface/src/PaymentManager.h | 25 +++++++++++++++++++ libraries/octree/src/OctreeEditPacketSender.h | 2 +- 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 interface/src/PaymentManager.cpp create mode 100644 interface/src/PaymentManager.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d30cd63105..a099231654 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -69,6 +69,7 @@ #include "InterfaceVersion.h" #include "Menu.h" #include "ModelUploader.h" +#include "PaymentManager.h" #include "Util.h" #include "devices/MIDIManager.h" #include "devices/OculusManager.h" @@ -237,10 +238,17 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(audioThread, SIGNAL(started()), &_audio, SLOT(start())); audioThread->start(); + + const DomainHandler& domainHandler = nodeList->getDomainHandler(); - connect(&nodeList->getDomainHandler(), SIGNAL(hostnameChanged(const QString&)), SLOT(domainChanged(const QString&))); - connect(&nodeList->getDomainHandler(), SIGNAL(connectedToDomain(const QString&)), SLOT(connectedToDomain(const QString&))); - connect(&nodeList->getDomainHandler(), &DomainHandler::settingsReceived, this, &Application::domainSettingsReceived); + connect(&domainHandler, SIGNAL(hostnameChanged(const QString&)), SLOT(domainChanged(const QString&))); + connect(&domainHandler, SIGNAL(connectedToDomain(const QString&)), SLOT(connectedToDomain(const QString&))); + connect(&domainHandler, &DomainHandler::settingsReceived, this, &Application::domainSettingsReceived); + + // 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; @@ -3790,6 +3798,7 @@ void Application::uploadAttachment() { } void Application::domainSettingsReceived(const QJsonObject& domainSettingsObject) { + // from the domain-handler, figure out the satoshi cost per voxel and per meter cubed const QString VOXEL_SETTINGS_KEY = "voxels"; const QString PER_VOXEL_COST_KEY = "per-voxel-credits"; @@ -3802,7 +3811,7 @@ void Application::domainSettingsReceived(const QJsonObject& domainSettingsObject qint64 satoshisPerMeterCubed = 0; QUuid voxelWalletUUID; - if (domainSettingsObject.isEmpty()) { + if (!domainSettingsObject.isEmpty()) { float perVoxelCredits = (float) voxelObject[PER_VOXEL_COST_KEY].toDouble(); float perMeterCubedCredits = (float) voxelObject[PER_METER_CUBED_COST_KEY].toDouble(); diff --git a/interface/src/PaymentManager.cpp b/interface/src/PaymentManager.cpp new file mode 100644 index 0000000000..f4d23fca30 --- /dev/null +++ b/interface/src/PaymentManager.cpp @@ -0,0 +1,24 @@ +// +// 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 "PaymentManager.h" + +PaymentManager& PaymentManager::getInstance() { + static PaymentManager sharedInstance; + return sharedInstance; +} + +void PaymentManager::sendSignedPayment(qint64 satoshiAmount, const QUuid& nodeUUID, const QUuid& destinationWalletUUID) { + qDebug() << "Paying" << satoshiAmount << "satoshis to" << destinationWalletUUID << "via" << nodeUUID; +} \ No newline at end of file diff --git a/interface/src/PaymentManager.h b/interface/src/PaymentManager.h new file mode 100644 index 0000000000..67419a39a4 --- /dev/null +++ b/interface/src/PaymentManager.h @@ -0,0 +1,25 @@ +// +// 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/libraries/octree/src/OctreeEditPacketSender.h b/libraries/octree/src/OctreeEditPacketSender.h index 7b39a1d785..a11c626003 100644 --- a/libraries/octree/src/OctreeEditPacketSender.h +++ b/libraries/octree/src/OctreeEditPacketSender.h @@ -83,7 +83,7 @@ public: virtual char getMyNodeType() const = 0; virtual void adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew) { }; - bool hasDestinationWalletUUID() const { return _destinationWalletUUID.isNull(); } + bool hasDestinationWalletUUID() const { return !_destinationWalletUUID.isNull(); } void setDestinationWalletUUID(const QUuid& destinationWalletUUID) { _destinationWalletUUID = destinationWalletUUID; } const QUuid& getDestinationWalletUUID() { return _destinationWalletUUID; }