From 363cef6d8a6890fb29be98657dbf1c7b794e63fb Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 30 Jul 2014 17:33:37 -0700 Subject: [PATCH] move satoshi costs to VoxelEditPacketSender --- interface/src/Application.cpp | 31 +++++++++++++++++++ interface/src/Application.h | 2 ++ libraries/networking/src/DomainHandler.cpp | 23 +------------- libraries/networking/src/DomainHandler.h | 10 +----- .../voxels/src/VoxelEditPacketSender.cpp | 7 ++--- libraries/voxels/src/VoxelEditPacketSender.h | 7 +++++ 6 files changed, 44 insertions(+), 36 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9b54b84351..480f215d40 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3788,6 +3788,37 @@ void Application::uploadAttachment() { uploadModel(ATTACHMENT_MODEL); } +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"; + const QString PER_METER_CUBED_COST_KEY = "per-meter-cubed-credits"; + const QString VOXEL_WALLET_UUID = "voxel-wallet"; + + const QJsonObject& voxelObject = domainSettingsObject[VOXEL_SETTINGS_KEY].toObject(); + + qint64 satoshisPerVoxel = 0; + qint64 satoshisPerMeterCubed = 0; + QUuid voxelWalletUUID; + + if (domainSettingsObject.isEmpty()) { + float perVoxelCredits = (float) voxelObject[PER_VOXEL_COST_KEY].toDouble(); + float perMeterCubedCredits = (float) voxelObject[PER_METER_CUBED_COST_KEY].toDouble(); + + satoshisPerVoxel = (qint64) floorf(perVoxelCredits * SATOSHIS_PER_CREDIT); + satoshisPerMeterCubed = (qint64) floorf(perMeterCubedCredits * SATOSHIS_PER_CREDIT); + + voxelWalletUUID = QUuid(voxelObject[VOXEL_WALLET_UUID].toString()); + } + + qDebug() << "Voxel costs are" << satoshisPerVoxel << "per voxel and" << satoshisPerMeterCubed << "per meter cubed"; + qDebug() << "Destination wallet UUID for voxel payments is" << voxelWalletUUID; + + _voxelEditSender.setSatoshisPerVoxel(satoshisPerVoxel); + _voxelEditSender.setSatoshisPerMeterCubed(satoshisPerMeterCubed); + _voxelEditSender.setDestinationWalletUUID(voxelWalletUUID); +} + QString Application::getPreviousScriptLocation() { QString suggestedName; if (_previousScriptLocation.isEmpty()) { diff --git a/interface/src/Application.h b/interface/src/Application.h index a356b26725..54fb25839a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -342,6 +342,8 @@ public slots: void uploadAttachment(); void bumpSettings() { ++_numChangedSettings; } + + void domainSettingsReceived(const QJsonObject& domainSettingsObject); private slots: void timer(); diff --git a/libraries/networking/src/DomainHandler.cpp b/libraries/networking/src/DomainHandler.cpp index 5f20bebd50..1bcf03f477 100644 --- a/libraries/networking/src/DomainHandler.cpp +++ b/libraries/networking/src/DomainHandler.cpp @@ -159,9 +159,7 @@ void DomainHandler::settingsRequestFinished() { _settingsObject = QJsonDocument::fromJson(settingsReply->readAll()).object(); qDebug() << "Received domain settings."; - emit settingsReceived(); - - updateVoxelCosts(); + emit settingsReceived(_settingsObject); // reset failed settings requests to 0, we got them _failedSettingsRequests = 0; @@ -182,25 +180,6 @@ void DomainHandler::settingsRequestFinished() { } } -void DomainHandler::updateVoxelCosts() { - - // 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"; - const QString PER_METER_CUBED_COST_KEY = "per-meter-cubed-credits"; - - if (!_settingsObject.isEmpty()) { - float perVoxelCredits = (float) _settingsObject[VOXEL_SETTINGS_KEY].toObject()[PER_VOXEL_COST_KEY].toDouble(); - float perMeterCubedCredits = (float) _settingsObject[VOXEL_SETTINGS_KEY].toObject()[PER_METER_CUBED_COST_KEY].toDouble(); - - _satoshisPerVoxel = (qint64) floorf(perVoxelCredits * SATOSHIS_PER_CREDIT); - _satoshisPerMeterCubed = (qint64) floorf(perMeterCubedCredits * SATOSHIS_PER_CREDIT); - } else { - _satoshisPerVoxel = 0; - _satoshisPerMeterCubed = 0; - } -} - void DomainHandler::parseDTLSRequirementPacket(const QByteArray& dtlsRequirementPacket) { // figure out the port that the DS wants us to use for us to talk to them with DTLS int numBytesPacketHeader = numBytesForPacketHeader(dtlsRequirementPacket); diff --git a/libraries/networking/src/DomainHandler.h b/libraries/networking/src/DomainHandler.h index 7b7a80b49a..a2b8e2e307 100644 --- a/libraries/networking/src/DomainHandler.h +++ b/libraries/networking/src/DomainHandler.h @@ -62,9 +62,6 @@ public: void parseDTLSRequirementPacket(const QByteArray& dtlsRequirementPacket); - qint64 getSatoshisPerVoxel() const { return _satoshisPerVoxel; } - qint64 getSatoshisPerMeterCubed() const { return _satoshisPerMeterCubed; } - private slots: void completedHostnameLookup(const QHostInfo& hostInfo); void settingsRequestFinished(); @@ -72,14 +69,12 @@ signals: void hostnameChanged(const QString& hostname); void connectedToDomain(const QString& hostname); - void settingsReceived(); + void settingsReceived(const QJsonObject& domainSettingsObject); void settingsReceiveFail(); private: void reset(); - void updateVoxelCosts(); - QUuid _uuid; QString _hostname; HifiSockAddr _sockAddr; @@ -88,9 +83,6 @@ private: QTimer* _handshakeTimer; QJsonObject _settingsObject; int _failedSettingsRequests; - - qint64 _satoshisPerVoxel; - qint64 _satoshisPerMeterCubed; }; #endif // hifi_DomainHandler_h diff --git a/libraries/voxels/src/VoxelEditPacketSender.cpp b/libraries/voxels/src/VoxelEditPacketSender.cpp index ee189f492d..3bb76d17fe 100644 --- a/libraries/voxels/src/VoxelEditPacketSender.cpp +++ b/libraries/voxels/src/VoxelEditPacketSender.cpp @@ -146,15 +146,12 @@ void VoxelEditPacketSender::queueVoxelEditMessages(PacketType type, int numberOf qint64 VoxelEditPacketSender::satoshiCostForMessage(const VoxelDetail& details) { const DomainHandler& domainHandler = NodeList::getInstance()->getDomainHandler(); - qint64 totalSatoshiCost = domainHandler.getSatoshisPerVoxel(); - qint64 costPerMeterCubed = domainHandler.getSatoshisPerMeterCubed(); - - if (totalSatoshiCost == 0 && costPerMeterCubed == 0) { + if (_satoshisPerVoxel == 0 && _satoshisPerMeterCubed == 0) { return 0; } else { float meterScale = details.s * TREE_SCALE; float totalVolume = meterScale * meterScale * meterScale; - return totalSatoshiCost + (qint64) floorf(totalVolume * costPerMeterCubed); + return _satoshisPerVoxel + (qint64) floorf(totalVolume * _satoshisPerMeterCubed); } } diff --git a/libraries/voxels/src/VoxelEditPacketSender.h b/libraries/voxels/src/VoxelEditPacketSender.h index e761812629..560c585ed5 100644 --- a/libraries/voxels/src/VoxelEditPacketSender.h +++ b/libraries/voxels/src/VoxelEditPacketSender.h @@ -51,6 +51,13 @@ public: // My server type is the voxel server virtual char getMyNodeType() const { return NodeType::VoxelServer; } + void setSatoshisPerVoxel(qint64 satoshisPerVoxel) { _satoshisPerVoxel = satoshisPerVoxel; } + void setSatoshisPerMeterCubed(qint64 satoshisPerMeterCubed) { _satoshisPerMeterCubed = satoshisPerMeterCubed; } + qint64 satoshiCostForMessage(const VoxelDetail& details); + +private: + qint64 _satoshisPerVoxel; + qint64 _satoshisPerMeterCubed; }; #endif // hifi_VoxelEditPacketSender_h