move satoshi costs to VoxelEditPacketSender

This commit is contained in:
Stephen Birarda 2014-07-30 17:33:37 -07:00
parent eba92eb517
commit 363cef6d8a
6 changed files with 44 additions and 36 deletions

View file

@ -3788,6 +3788,37 @@ void Application::uploadAttachment() {
uploadModel(ATTACHMENT_MODEL); 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 Application::getPreviousScriptLocation() {
QString suggestedName; QString suggestedName;
if (_previousScriptLocation.isEmpty()) { if (_previousScriptLocation.isEmpty()) {

View file

@ -342,6 +342,8 @@ public slots:
void uploadAttachment(); void uploadAttachment();
void bumpSettings() { ++_numChangedSettings; } void bumpSettings() { ++_numChangedSettings; }
void domainSettingsReceived(const QJsonObject& domainSettingsObject);
private slots: private slots:
void timer(); void timer();

View file

@ -159,9 +159,7 @@ void DomainHandler::settingsRequestFinished() {
_settingsObject = QJsonDocument::fromJson(settingsReply->readAll()).object(); _settingsObject = QJsonDocument::fromJson(settingsReply->readAll()).object();
qDebug() << "Received domain settings."; qDebug() << "Received domain settings.";
emit settingsReceived(); emit settingsReceived(_settingsObject);
updateVoxelCosts();
// reset failed settings requests to 0, we got them // reset failed settings requests to 0, we got them
_failedSettingsRequests = 0; _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) { 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 // figure out the port that the DS wants us to use for us to talk to them with DTLS
int numBytesPacketHeader = numBytesForPacketHeader(dtlsRequirementPacket); int numBytesPacketHeader = numBytesForPacketHeader(dtlsRequirementPacket);

View file

@ -62,9 +62,6 @@ public:
void parseDTLSRequirementPacket(const QByteArray& dtlsRequirementPacket); void parseDTLSRequirementPacket(const QByteArray& dtlsRequirementPacket);
qint64 getSatoshisPerVoxel() const { return _satoshisPerVoxel; }
qint64 getSatoshisPerMeterCubed() const { return _satoshisPerMeterCubed; }
private slots: private slots:
void completedHostnameLookup(const QHostInfo& hostInfo); void completedHostnameLookup(const QHostInfo& hostInfo);
void settingsRequestFinished(); void settingsRequestFinished();
@ -72,14 +69,12 @@ signals:
void hostnameChanged(const QString& hostname); void hostnameChanged(const QString& hostname);
void connectedToDomain(const QString& hostname); void connectedToDomain(const QString& hostname);
void settingsReceived(); void settingsReceived(const QJsonObject& domainSettingsObject);
void settingsReceiveFail(); void settingsReceiveFail();
private: private:
void reset(); void reset();
void updateVoxelCosts();
QUuid _uuid; QUuid _uuid;
QString _hostname; QString _hostname;
HifiSockAddr _sockAddr; HifiSockAddr _sockAddr;
@ -88,9 +83,6 @@ private:
QTimer* _handshakeTimer; QTimer* _handshakeTimer;
QJsonObject _settingsObject; QJsonObject _settingsObject;
int _failedSettingsRequests; int _failedSettingsRequests;
qint64 _satoshisPerVoxel;
qint64 _satoshisPerMeterCubed;
}; };
#endif // hifi_DomainHandler_h #endif // hifi_DomainHandler_h

View file

@ -146,15 +146,12 @@ void VoxelEditPacketSender::queueVoxelEditMessages(PacketType type, int numberOf
qint64 VoxelEditPacketSender::satoshiCostForMessage(const VoxelDetail& details) { qint64 VoxelEditPacketSender::satoshiCostForMessage(const VoxelDetail& details) {
const DomainHandler& domainHandler = NodeList::getInstance()->getDomainHandler(); const DomainHandler& domainHandler = NodeList::getInstance()->getDomainHandler();
qint64 totalSatoshiCost = domainHandler.getSatoshisPerVoxel(); if (_satoshisPerVoxel == 0 && _satoshisPerMeterCubed == 0) {
qint64 costPerMeterCubed = domainHandler.getSatoshisPerMeterCubed();
if (totalSatoshiCost == 0 && costPerMeterCubed == 0) {
return 0; return 0;
} else { } else {
float meterScale = details.s * TREE_SCALE; float meterScale = details.s * TREE_SCALE;
float totalVolume = meterScale * meterScale * meterScale; float totalVolume = meterScale * meterScale * meterScale;
return totalSatoshiCost + (qint64) floorf(totalVolume * costPerMeterCubed); return _satoshisPerVoxel + (qint64) floorf(totalVolume * _satoshisPerMeterCubed);
} }
} }

View file

@ -51,6 +51,13 @@ public:
// My server type is the voxel server // My server type is the voxel server
virtual char getMyNodeType() const { return NodeType::VoxelServer; } virtual char getMyNodeType() const { return NodeType::VoxelServer; }
void setSatoshisPerVoxel(qint64 satoshisPerVoxel) { _satoshisPerVoxel = satoshisPerVoxel; }
void setSatoshisPerMeterCubed(qint64 satoshisPerMeterCubed) { _satoshisPerMeterCubed = satoshisPerMeterCubed; }
qint64 satoshiCostForMessage(const VoxelDetail& details); qint64 satoshiCostForMessage(const VoxelDetail& details);
private:
qint64 _satoshisPerVoxel;
qint64 _satoshisPerMeterCubed;
}; };
#endif // hifi_VoxelEditPacketSender_h #endif // hifi_VoxelEditPacketSender_h