Exemple #1
0
bool matchContact(const fc::ecc::public_key& pk, bts::addressbook::wallet_contact* matchedContact)
{
  assert(pk.valid());

  auto address_book = bts::get_profile()->get_addressbook();
  try
  {
    auto c = address_book->get_contact_by_public_key(pk);
    if(c)
    {
      *matchedContact = *c;
      return true;
    }
    else
    {
      *matchedContact = bts::addressbook::wallet_contact();
      matchedContact->public_key = pk;
      return false;
    }
  }
  catch (const fc::exception&)
  {
    *matchedContact = bts::addressbook::wallet_contact();
    matchedContact->public_key = pk;
    return false;
  }
}
Exemple #2
0
QString toString(const fc::ecc::public_key& pk, TContactTextFormatting contactFormatting,
  bts::addressbook::contact* matchingContact /*= nullptr*/, bool* isKnownContact /*= nullptr*/)
  {
  assert(pk.valid());

  auto address_book = bts::get_profile()->get_addressbook();
  auto c = address_book->get_contact_by_public_key(pk);
  if (c)
    {
    if(matchingContact != nullptr)
      *matchingContact = *c;
    if(isKnownContact != nullptr)
      *isKnownContact = true;

    switch(contactFormatting)
      {
      case KEYHOTEE_IDENTIFIER:
        return QString(c->dac_id_string.c_str());
      case CONTACT_ALIAS_FULL_NAME:
        return QString(std::string(c->first_name + " " + c->last_name).c_str());
      case FULL_CONTACT_DETAILS:
        return QString(c->get_display_name().c_str());
      default:
        assert(false);
        return QString();
      }
    }
  else
    {
    auto profile = bts::get_profile();
    /// If no contact found try one of registered identities.
    std::vector<bts::addressbook::wallet_identity> identities = profile->identities();
    for(const auto& identity : identities)
      {
      assert(identity.public_key.valid());

      if(identity.public_key == pk)
        {
        if(matchingContact != nullptr)
          *matchingContact = identity;
        if(isKnownContact != nullptr)
          *isKnownContact = true;

        switch(contactFormatting)
          {
          case KEYHOTEE_IDENTIFIER:
            return QString::fromStdString(identity.dac_id_string);
          case CONTACT_ALIAS_FULL_NAME:
            return QString::fromStdString(std::string(identity.first_name + " " + identity.last_name));
          case FULL_CONTACT_DETAILS:
            return QString::fromStdString(identity.get_display_name());
          default:
            assert(false);
            return QString();
          }
        break;
        }
      }

    if(matchingContact != nullptr)
      {
      *matchingContact = bts::addressbook::wallet_contact();
      matchingContact->public_key = pk;
      }

    if(isKnownContact != nullptr)
      *isKnownContact = false;

    /// If code reached this point the publick key is unknown - lets display it as base58
    return QString::fromStdString(pk.to_base58());
    }
  }