Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #211 from FellowTraveler/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
FellowTraveler committed Jan 26, 2016
2 parents 416f329 + b587a7b commit 8d922a8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 179 deletions.
4 changes: 2 additions & 2 deletions src/core/handlers/contacthandler.cpp
Expand Up @@ -859,8 +859,8 @@ bool MTContactHandler::upsertClaim(opentxs::Nym& nym, const opentxs::Claim& clai
qu->bind (":claim_sectionBlah", claim_section);
qu->bind (":claim_typeBlah", claim_type);
qu->bind (":claim_valueBlah", claim_value);
qu->bind (":claim_startBlah", claim_start);
qu->bind (":claim_endBlah", claim_end);
qu->bind (":claim_startBlah", QVariant::fromValue(claim_start));
qu->bind (":claim_endBlah", QVariant::fromValue(claim_end));
qu->bind (":claim_attributesBlah", qstrAttributes);
qu->bind (":claim_att_activeBlah", (claim_att_active ? 1 : 0));
qu->bind (":claim_att_primaryBlah", (claim_att_primary ? 1 : 0));
Expand Down
8 changes: 4 additions & 4 deletions src/core/moneychanger.cpp
Expand Up @@ -2705,7 +2705,7 @@ void Moneychanger::AddPaymentBasedOnNotification(const std::string & str_acct_id
// The primary key is the "display txn ID"
//
bool Moneychanger::AddPaymentToPmntArchive(opentxs::OTRecord& recordmt, const bool bCanDeleteRecord/*=true*/)
{
{
ModelPayments::PaymentFlags flags = ModelPayments::NoFlags;

QPointer<ModelPayments> pModel = DBHandler::getInstance()->getPaymentModel();
Expand Down Expand Up @@ -4571,7 +4571,7 @@ void Moneychanger::ServerContractNotify(std::string id)

if (nullptr != pWallet)
{
opentxs::OTServerContract * pContract = pWallet->GetServerContract(ot_id);
opentxs::ServerContract * pContract = pWallet->GetServerContract(ot_id);

// Found it! The contract is already in the wallet.
if (nullptr != pContract)
Expand All @@ -4592,11 +4592,11 @@ void Moneychanger::ServerContractNotify(std::string id)
//
// However, I DO need to ADD the contract to the wallet...
//
opentxs::OTServerContract * pContract = opentxs::OTAPI_Wrap::OTAPI()->LoadServerContract(ot_id);
opentxs::ServerContract * pContract = opentxs::OTAPI_Wrap::OTAPI()->LoadServerContract(ot_id);

if (nullptr != pContract)
{
pWallet->AddServerContract(*pContract); // Takes ownership.
pWallet->AddServerContract(pContract); // Takes ownership.
pWallet->SaveWallet();

emit newServerAdded(QString::fromStdString(id));
Expand Down
172 changes: 19 additions & 153 deletions src/gui/widgets/serverdetails.cpp
Expand Up @@ -7,15 +7,15 @@

#include <gui/widgets/wizardaddcontract.hpp>

#include <opentxs/client/OpenTransactions.hpp>
#include <opentxs/client/OTAPI.hpp>
#include <opentxs/client/OTAPI_Exec.hpp>

#include <opentxs/client/OTWallet.hpp>
#include <opentxs/core/OTStorage.hpp>

#include <opentxs/core/util/OTFolders.hpp>

#include <opentxs/core/contract/ServerContract.hpp>
#include <opentxs/core/crypto/OTASCIIArmor.hpp>
#include <opentxs/core/crypto/OTCachedKey.hpp>
#include <opentxs/core/util/OTFolders.hpp>

#include <quazip/quazip.h>
#include <quazip/quazipfile.h>
Expand Down Expand Up @@ -662,153 +662,13 @@ void MTServerDetails::AddButtonClicked()
QString qstrXMLContents = theWizard.field("contractXML").toString();
QString qstrNymID = theWizard.field("NymID").toString();

std::string strContractID = opentxs::OTAPI_Wrap::It()->CreateServerContract(qstrNymID.toStdString(),
qstrXMLContents.toStdString());
std::string strContractID;

if (strContractID.empty() || "" == strContractID) {
QMessageBox::warning(this, tr("Failed Creating Contract"),
tr("Unable to create contract. Perhaps the XML contents were bad?"));
return;
}
else {
std::string strNewContract = opentxs::OTAPI_Wrap::It()->GetServer_Contract(strContractID);

if (strNewContract.empty() || "" == strNewContract) {
QMessageBox::warning(this, tr("Unable to Load"),
tr("While the contract was apparently created, Moneychanger is unable to load it up. (Strange.)"));
return;
}
else // Success.
{
// Need to zip up whatever extra files will be needed by the server.
// Including the transport keys and the master key from the wallet.

// Let's make a list, based on the opentxs-notary when you start it up
// with an empty data folder:

/*
* 1. A wallet where you have already created one nym and a new notary server contract.
2. The entire credentials folder. OR at least, the Signer Nym’s credentials folder.
*/
// 3. The Notary ID.
// 4. The Signer Nym ID for the notary server contract.
// 5. The Cached key from the wallet.
// 6. Notary Contract. (Signed by Signer.)

// 2. The entire credentials folder. OR at least, the Signer Nym’s credentials folder.
//
std::string str_formed_path;
int64_t nFormPath = opentxs::OTDB::FormPathString(str_formed_path, opentxs::OTFolders::Credential().Get(),
qstrNymID.toStdString());
QString dir_path(QString::fromStdString(str_formed_path));

QDir dirToZip(dir_path);
// --------------------------
QString filenameZipFile;
QDir selectedDir("/tmp");

while (filenameZipFile.isEmpty())
{
QFileDialog dialog(this, tr("Save Credentials Zipfile"), "/tmp/New_Notary_SignerNym_Credentials.zip", tr("Zipfiles (*.zip)"));
dialog.setAcceptMode(QFileDialog::AcceptSave);
if (dialog.exec()) {
QStringList filenames = dialog.selectedFiles();
filenameZipFile = filenames.at(0);
selectedDir = dialog.directory();
}
}
// --------------------------
// while (filenameZipFile.isEmpty())
// filenameZipFile = QFileDialog::getSaveFileName(this, tr("Save Credentials Zipfile"),
// "New_Notary_SignerNym_Credentials.zip",
// tr("Zipfiles (*.zip)"));

if (!archive(filenameZipFile, dirToZip, QString("New Notary Signer Nym Credentials")))
QMessageBox::information(this, tr("Failed Zipping Credentials"),
QString("%1%2").arg(tr("There was an error while trying to zip up the new Signer Nym's credential directory. "
"(The new server will need those credentials.) "
"Therefore you will have to copy the directory yourself by hand. Its location: ")).arg(dir_path));
// --------------------------
// 3. The Notary ID.
//
// std::string strContractID
// --------------------------
// 4. The Signer Nym ID for the notary server contract.
//
// QString qstrNymID
// ------------------------------------------------
// 5. The Cached key from the wallet.
//
opentxs::OTASCIIArmor ascCachedKey;

if (!opentxs::OTCachedKey::It()->SerializeTo(ascCachedKey))
QMessageBox::information(this, tr("Failed getting cached master key"),
tr("Failed to retrieve the cached master key from wallet.xml in the client_data folder. "
"You will have to base64-decode that file yourself (using 'opentxs decode') and then "
"copy the base64-encoded cached master key from it, since the new server will need that key. "
"Just look for the <cachedKey> tag inside the wallet.xml file."));
// --------------------------
// 6. Notary Contract. (Signed by Signer.)
//
// std::string strNewContract
// ------------------------------------------------
// Write the IDs, etc to an output file to be pasted into the notary's creation process.
//
QString outputFilename;

while (outputFilename.isEmpty())
{
QString tempFilename = QString("%1/%2").arg(selectedDir.absolutePath()).arg("New_Notary_Creation_File.txt");
QFileDialog dialog(this, tr("Save Results File"), tempFilename, tr("Text files (*.txt)"));
dialog.setAcceptMode(QFileDialog::AcceptSave);
if (dialog.exec()) {
QStringList filenames = dialog.selectedFiles();
outputFilename = filenames.at(0);
selectedDir = dialog.directory();
}
}
// while (outputFilename.isEmpty())
// outputFilename = QFileDialog::getSaveFileName(this, tr("Save Results File"),
// "New_Notary_Creation_File.txt",
// tr("Text files (*.txt)"));
QFile outputFile(outputFilename);
outputFile.open(QIODevice::WriteOnly);

// Check it opened OK
if(!outputFile.isOpen())
{
QMessageBox::information(this, tr("Failed opening output file"), QString(tr("Unable to open '%1' for output.")).arg(outputFilename));
}
else
{
// Point a QTextStream object at the file
QTextStream outStream(&outputFile);

// Write the lines to the file

outStream << "Notary ID: " << strContractID.c_str() << "\n\n"; // Notary ID

outStream << "Signer Nym ID: " << qstrNymID << "\n\n"; // Signer Nym ID

outStream << "Cached Master Key:\n" << ascCachedKey.Get() << "\n\n"; // Cached master key from the wallet.

outStream << strNewContract.c_str() << "\n"; // The new server contract.

// Close the file
outputFile.close();
}
// ------------------------------------------------
QString qstrContractID = QString::fromStdString(strContractID);
QString qstrContractName = QString::fromStdString(opentxs::OTAPI_Wrap::It()->GetServer_Name(strContractID));

m_pOwner->m_map.insert(qstrContractID,
qstrContractName);
m_pOwner->SetPreSelected(qstrContractID);
// ------------------------------------------------
emit newServerAdded(qstrContractID);
return;
}
}
} // bIsCreating is true.
} // Wizard "OK" was clicked.
}
Expand Down Expand Up @@ -837,19 +697,25 @@ void MTServerDetails::refresh(QString strID, QString strName)
ui->verticalLayout->insertWidget(0, pHeaderWidget);
m_pHeaderWidget = pHeaderWidget;
// ----------------------------------
QString qstrContents = QString::fromStdString(opentxs::OTAPI_Wrap::It()->LoadServerContract(strID.toStdString()));
opentxs::OTWallet* pWallet =
pWallet = opentxs::OTAPI_Wrap::OTAPI()->GetWallet(__FUNCTION__);

if (nullptr == pWallet) { return; }

opentxs::ServerContract* contract =
pWallet->GetServerContract(strID.toStdString());

if (nullptr == contract) {return; }

QString qstrNymID("");
qstrNymID = QString::fromStdString(contract->ID().Get());

QString qstrContents = QString::fromStdString(contract->Terms().Get());

if (m_pPlainTextEdit)
m_pPlainTextEdit->setPlainText(qstrContents);
// ----------------------------------
QString qstrNymID("");

if (!qstrContents.isEmpty()) {
std::string str_signer_nym = opentxs::OTAPI_Wrap::It()->GetSignerNymID(qstrContents.toStdString());

if (!str_signer_nym.empty())
qstrNymID = QString::fromStdString(str_signer_nym);
}
// ----------------------------------
ui->lineEditID ->setText(strID);
ui->lineEditName ->setText(strName);
Expand Down
18 changes: 0 additions & 18 deletions src/rpc/mcrpcservice.cpp
Expand Up @@ -534,24 +534,6 @@ QJsonValue MCRPCService::calculateContractID(QString Username, QString APIKey,
return QJsonValue(object);
}

QJsonValue MCRPCService::createServerContract(QString Username, QString APIKey,
QString NymID, QString XMLContents)
{
if(!validateAPIKey(Username, APIKey)){
QJsonObject object{{"Error", "Invalid API Key"}};
return QJsonValue(object);
}
if(!opentxs::OTAPI_Wrap::It()->IsValidID(NymID.toStdString())){
QJsonObject object{{"Error", "Invalid NymID"}};
return QJsonValue(object);
}

std::string result = opentxs::OTAPI_Wrap::It()->CreateServerContract(NymID.toStdString(),
XMLContents.toStdString());
QJsonObject object{{"CreateServerContractResult", QString(result.c_str())}};
return QJsonValue(object);
}

QJsonValue MCRPCService::createAssetContract(QString Username, QString APIKey,
QString NymID, QString XMLContents)
{
Expand Down
2 changes: 0 additions & 2 deletions src/rpc/mcrpcservice.h
Expand Up @@ -80,8 +80,6 @@ public Q_SLOTS:
QString Contract);
QJsonValue calculateContractID(QString Username, QString APIKey,
QString Contract);
QJsonValue createServerContract(QString Username, QString APIKey,
QString NymID, QString XMLContents);
QJsonValue createAssetContract(QString Username, QString APIKey,
QString NymID, QString XMLContents);
QJsonValue getServerContract(QString Username, QString APIKey,
Expand Down

0 comments on commit 8d922a8

Please sign in to comment.