Skip to content

Commit

Permalink
Namecoin / Qt: Show .bit form for d/ names in TransactionRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Dec 30, 2021
1 parent ff02537 commit 753920c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
32 changes: 32 additions & 0 deletions src/names/applications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,35 @@ NamespaceFromName (const valtype& data)

return NamespaceFromName(name);
}

std::string
DescFromName (const std::string& name, NameNamespace ns)
{
switch (ns)
{
case NameNamespace::Domain:
{
const std::string nsStr = NamespaceToString(ns);
const auto nsLen = nsStr.length();

const std::string label = name.substr(nsLen);

return label + ".bit";
}
default:
{
// TODO: Refactor DescFromName and EncodeNameForMessage to avoid double conversion
const valtype vtName = valtype (name.begin (), name.end ());

return EncodeNameForMessage(vtName);
}
}
}

std::string
DescFromName (const valtype& data, NameNamespace ns)
{
std::string name = std::string (data.begin (), data.end ());

return DescFromName(name, ns);
}
3 changes: 3 additions & 0 deletions src/names/applications.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ enum class NameNamespace
NameNamespace NamespaceFromName (const std::string& name);
NameNamespace NamespaceFromName (const valtype& data);

std::string DescFromName (const std::string& name, NameNamespace ns);
std::string DescFromName (const valtype& data, NameNamespace ns);

#endif // H_BITCOIN_NAMES_APPLICATIONS
5 changes: 2 additions & 3 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <interfaces/wallet.h>
#include <key_io.h>
#include <names/applications.h>
#include <names/encoding.h>
#include <script/names.h>
#include <wallet/ismine.h>

Expand Down Expand Up @@ -130,7 +129,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
}

nameSub.nameNamespace = NamespaceFromName(nNameCredit.value().getOpName());
nameSub.address = EncodeNameForMessage(nNameCredit.value().getOpName());
nameSub.address = DescFromName(nNameCredit.value().getOpName(), nameSub.nameNamespace);
}
else
{
Expand All @@ -144,7 +143,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
if(nNameDebit.value().isAnyUpdate())
{
nameSub.nameNamespace = NamespaceFromName(nNameDebit.value().getOpName());
nameSub.address = EncodeNameForMessage(nNameDebit.value().getOpName());
nameSub.address = DescFromName(nNameDebit.value().getOpName(), nameSub.nameNamespace);
}
}

Expand Down

0 comments on commit 753920c

Please sign in to comment.