handle remaining conversions for AccountManager passing QNetworkReply

This commit is contained in:
Stephen Birarda 2014-10-14 16:16:54 -07:00
parent 46fb7fb4a9
commit e9bcc90166
9 changed files with 16 additions and 63 deletions

View file

@ -861,8 +861,6 @@ void OctreeServer::readPendingDatagram(const QByteArray& receivedPacket, const H
}
} else if (packetType == PacketTypeJurisdictionRequest) {
_jurisdictionSender->queueReceivedPacket(matchingNode, receivedPacket);
} else if (packetType == PacketTypeSignedTransactionPayment) {
handleSignedTransactionPayment(packetType, receivedPacket);
} else if (_octreeInboundPacketProcessor && getOctree()->handlesEditPacketType(packetType)) {
_octreeInboundPacketProcessor->queueReceivedPacket(matchingNode, receivedPacket);
} else {
@ -1245,51 +1243,6 @@ QString OctreeServer::getStatusLink() {
return result;
}
void OctreeServer::handleSignedTransactionPayment(PacketType packetType, const QByteArray& datagram) {
// for now we're not verifying that this is actual payment for any octree edits
// just use the AccountManager to send it up to the data server and have it redeemed
AccountManager& accountManager = AccountManager::getInstance();
const int NUM_BYTES_SIGNED_TRANSACTION_BINARY_MESSAGE = 72;
const int NUM_BYTES_SIGNED_TRANSACTION_BINARY_SIGNATURE = 256;
int numBytesPacketHeader = numBytesForPacketHeaderGivenPacketType(packetType);
// pull out the transaction message in binary
QByteArray messageHex = datagram.mid(numBytesPacketHeader, NUM_BYTES_SIGNED_TRANSACTION_BINARY_MESSAGE).toHex();
// pull out the binary signed message digest
QByteArray signatureHex = datagram.mid(numBytesPacketHeader + NUM_BYTES_SIGNED_TRANSACTION_BINARY_MESSAGE,
NUM_BYTES_SIGNED_TRANSACTION_BINARY_SIGNATURE).toHex();
// setup the QJSONObject we are posting
QJsonObject postObject;
const QString TRANSACTION_OBJECT_MESSAGE_KEY = "message";
const QString TRANSACTION_OBJECT_SIGNATURE_KEY = "signature";
const QString POST_OBJECT_TRANSACTION_KEY = "transaction";
QJsonObject transactionObject;
transactionObject.insert(TRANSACTION_OBJECT_MESSAGE_KEY, QString(messageHex));
transactionObject.insert(TRANSACTION_OBJECT_SIGNATURE_KEY, QString(signatureHex));
postObject.insert(POST_OBJECT_TRANSACTION_KEY, transactionObject);
// setup our callback params
JSONCallbackParameters callbackParameters;
callbackParameters.jsonCallbackReceiver = this;
callbackParameters.jsonCallbackMethod = "handleSignedTransactionPaymentResponse";
accountManager.unauthenticatedRequest("/api/v1/transactions/redeem", QNetworkAccessManager::PostOperation,
callbackParameters, QJsonDocument(postObject).toJson());
}
void OctreeServer::handleSignedTransactionPaymentResponse(const QJsonObject& jsonObject) {
// pull the ID to debug the transaction
QString transactionIDString = jsonObject["data"].toObject()["transaction"].toObject()["id"].toString();
qDebug() << "Redeemed transaction with ID" << transactionIDString << "successfully.";
}
void OctreeServer::sendStatsPacket() {
// TODO: we have too many stats to fit in a single MTU... so for now, we break it into multiple JSON objects and
// send them separately. What we really should do is change the NodeList::sendStatsToDomainServer() to handle the

View file

@ -127,8 +127,6 @@ public slots:
void nodeKilled(SharedNodePointer node);
void sendStatsPacket();
void handleSignedTransactionPaymentResponse(const QJsonObject& jsonObject);
void readPendingDatagrams() { }; // this will not be called since our datagram processing thread will handle
void readPendingDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr);
@ -141,7 +139,6 @@ protected:
QString getConfiguration();
QString getStatusLink();
void handleSignedTransactionPayment(PacketType packetType, const QByteArray& datagram);
void setupDatagramProcessingThread();
int _argc;

View file

@ -565,9 +565,10 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock
if (!isAssignment && allowedUsers.count() > 0) {
// this is an agent, we need to ask them to provide us with their signed username to see if they are allowed in
// we always let in a user who is sending a packet from our local socket or from the localhost address
if (senderSockAddr.getAddress() != LimitedNodeList::getInstance()->getLocalSockAddr().getAddress()
&& senderSockAddr.getAddress() != QHostAddress::LocalHost) {
// if (senderSockAddr.getAddress() != LimitedNodeList::getInstance()->getLocalSockAddr().getAddress()
// && senderSockAddr.getAddress() != QHostAddress::LocalHost) {
if (true) {
bool canConnect = false;
if (allowedUsers.contains(username)) {
@ -943,8 +944,8 @@ void DomainServer::sendPendingTransactionsToServer() {
}
void DomainServer::publicKeyJSONCallback(const QJsonObject& data) {
qDebug() << data;
void DomainServer::publicKeyJSONCallback(QNetworkReply& requestReply) {
}
void DomainServer::transactionJSONCallback(const QJsonObject& data) {

View file

@ -52,7 +52,7 @@ public slots:
/// Called by NodeList to inform us a node has been killed
void nodeKilled(SharedNodePointer node);
void publicKeyJSONCallback(const QJsonObject& data);
void publicKeyJSONCallback(QNetworkReply& requestReply);
void transactionJSONCallback(const QJsonObject& data);
void restart();

View file

@ -364,7 +364,9 @@ void ModelUploader::send() {
_progressBar = NULL;
}
void ModelUploader::checkJSON(const QJsonObject& jsonResponse) {
void ModelUploader::checkJSON(QNetworkReply& requestReply) {
QJsonObject jsonResponse = QJsonDocument::fromJson(requestReply.readAll()).object();
if (jsonResponse.contains("status") && jsonResponse.value("status").toString() == "success") {
qDebug() << "status : success";
JSONCallbackParameters callbackParams;
@ -426,7 +428,7 @@ void ModelUploader::uploadUpdate(qint64 bytesSent, qint64 bytesTotal) {
}
}
void ModelUploader::uploadSuccess(const QJsonObject& jsonResponse) {
void ModelUploader::uploadSuccess(QNetworkReply& requestReply) {
if (_progressDialog) {
_progressDialog->accept();
}

View file

@ -40,9 +40,9 @@ public slots:
void send();
private slots:
void checkJSON(const QJsonObject& jsonResponse);
void checkJSON(QNetworkReply& requestReply);
void uploadUpdate(qint64 bytesSent, qint64 bytesTotal);
void uploadSuccess(const QJsonObject& jsonResponse);
void uploadSuccess(QNetworkReply& requestReply);
void uploadFailed(QNetworkReply& errorReply);
void checkS3();
void processCheck();

View file

@ -192,7 +192,7 @@ void AddressManager::handleAPIResponse(QNetworkReply& requestReply) {
} else {
qDebug() << "Received an address manager API response with no domain key. Cannot parse.";
qDebug() << jsonObject;
qDebug() << responseObject;
}
} else {
// we've been told that this result exists but is offline, emit our signal so the application can handle

View file

@ -69,7 +69,7 @@ void UserActivityLogger::logAction(QString action, QJsonObject details, JSONCall
multipart);
}
void UserActivityLogger::requestFinished(const QJsonObject& object) {
void UserActivityLogger::requestFinished(QNetworkReply& requestReply) {
// qDebug() << object;
}

View file

@ -39,7 +39,7 @@ public slots:
void wentTo(QString destinationType, QString destinationName);
private slots:
void requestFinished(const QJsonObject& object);
void requestFinished(QNetworkReply& requestReply);
void requestError(QNetworkReply& errorReply);
private: