Ejemplo n.º 1
0
bool OTASCIIArmor::WriteArmoredString(
    String& strOutput,
    const // for "-----BEGIN OT LEDGER-----", str_type would contain "LEDGER"
    std::string str_type, // There's no default, to force you to enter the right
                          // string.
    bool bEscaped) const
{
    const char* szEscape = "- ";

    String strTemp;
    strTemp.Format(
        "%s%s %s-----\n" // "%s-----BEGIN OT ARMORED %s-----\n"
        "Version: Open Transactions %s\n"
        "Comment: "
        "http://opentransactions.org\n\n" // todo
        // hardcoding.
        "%s"                // Should already have a newline at the bottom.
        "%s%s %s-----\n\n", // "%s-----END OT ARMORED %s-----\n"
        bEscaped ? szEscape : "",
        OT_BEGIN_ARMORED, str_type.c_str(), // "%s%s %s-----\n"
        Log::Version(),                     // "Version: Open Transactions %s\n"
        /* No variable */                   // "Comment:
        // http://github.com/FellowTraveler/Open-Transactions/wiki\n\n",
        Get(), //  "%s"     <==== CONTENTS OF THIS OBJECT BEING
               // WRITTEN...
        bEscaped ? szEscape : "", OT_END_ARMORED,
        str_type.c_str()); // "%s%s %s-----\n"

    strOutput.Concatenate("%s", strTemp.Get());

    return true;
}
Ejemplo n.º 2
0
bool AssetContract::DisplayStatistics(String& strContents) const
{
    const String strID(m_ID);

    strContents.Concatenate(" Asset Type:  %s\n"
                            " InstrumentDefinitionID: %s\n"
                            "\n",
                            m_strName.Get(), strID.Get());
    return true;
}
Ejemplo n.º 3
0
void Nym::DisplayStatistics(String& strOutput) const
{
    sLock lock(shared_lock_);
    strOutput.Concatenate("Source for ID:\n%s\n", Source().asString()->Get());
    strOutput.Concatenate("Description: %s\n\n", m_strDescription->Get());
    strOutput.Concatenate("%s", "\n");
    strOutput.Concatenate("==>      Name: %s\n", Alias().c_str());
    strOutput.Concatenate("      Version: %s\n", m_strVersion->Get());
    auto theStringID = String::Factory(ID());
    strOutput.Concatenate("Nym ID: %s\n", theStringID->Get());
}
Ejemplo n.º 4
0
void Nym::GetPrivateCredentials(String& strCredList, String::Map* pmapCredFiles)
    const
{
    Tag tag("nymData");

    tag.add_attribute("version", m_strVersion->Get());

    auto strNymID = String::Factory(m_nymID);

    tag.add_attribute("nymID", strNymID->Get());

    SerializeNymIDSource(tag);

    SaveCredentialsToTag(tag, nullptr, pmapCredFiles);

    std::string str_result;
    tag.output(str_result);

    strCredList.Concatenate("%s", str_result.c_str());
}
Ejemplo n.º 5
0
bool MainFile::SaveMainFileToString(String& strMainFile)
{
    Tag tag("notaryServer");

    // We're on version 2.0 since adding the master key.
    tag.add_attribute("version",
                      OTCachedKey::It()->IsGenerated() ? "2.0" : version_);
    tag.add_attribute("notaryID", server_->m_strNotaryID.Get());
    tag.add_attribute("serverNymID", server_->m_strServerNymID.Get());
    tag.add_attribute("transactionNum",
                      formatLong(server_->transactor_.transactionNumber()));

    if (OTCachedKey::It()->IsGenerated()) // If it exists, then serialize it.
    {
        OTASCIIArmor ascMasterContents;

        if (OTCachedKey::It()->SerializeTo(ascMasterContents)) {
            tag.add_tag("cachedKey", ascMasterContents.Get());
        }
        else
            Log::vError(
                "%s: Failed trying to write master key to notary file.\n",
                __FUNCTION__);
    }

    for (auto& it : server_->transactor_.contractsMap_) {
        Contract* pContract = it.second;
        OT_ASSERT_MSG(nullptr != pContract,
                      "nullptr contract pointer in MainFile::SaveMainFile.\n");

        // This is like the Server's wallet.
        pContract->SaveContractWallet(tag);
    }

    // Save the basket account information

    for (auto& it : server_->transactor_.idToBasketMap_) {
        String strBasketID = it.first.c_str();
        String strBasketAcctID = it.second.c_str();

        const Identifier BASKET_ACCOUNT_ID(strBasketAcctID);
        Identifier BASKET_CONTRACT_ID;

        bool bContractID =
            server_->transactor_.lookupBasketContractIDByAccountID(
                BASKET_ACCOUNT_ID, BASKET_CONTRACT_ID);

        if (!bContractID) {
            Log::vError("%s: Error: Missing Contract ID for basket ID %s\n",
                        __FUNCTION__, strBasketID.Get());
            break;
        }

        String strBasketContractID(BASKET_CONTRACT_ID);

        TagPtr pTag(new Tag("basketInfo"));

        pTag->add_attribute("basketID", strBasketID.Get());
        pTag->add_attribute("basketAcctID", strBasketAcctID.Get());
        pTag->add_attribute("basketContractID", strBasketContractID.Get());

        tag.add_tag(pTag);
    }

    server_->transactor_.voucherAccounts_.Serialize(tag);

    std::string str_result;
    tag.output(str_result);

    strMainFile.Concatenate("%s", str_result.c_str());

    return true;
}