Type json improvements

This commit is contained in:
JoelKatz
2012-10-01 00:55:16 -07:00
parent b973f3509c
commit c6aa3b2678
5 changed files with 34 additions and 7 deletions

View File

@@ -86,13 +86,18 @@ LedgerEntryFormat LedgerFormats[]=
{ NULL, ltINVALID }
};
LedgerEntryFormat* getLgrFormat(LedgerEntryType t)
{
return getLgrFormat(t);
}
LedgerEntryFormat* getLgrFormat(int t)
{
LedgerEntryFormat* f = LedgerFormats;
while (f->t_name != NULL)
{
if (f->t_type == t) return f;
if (f->t_type == t)
return f;
++f;
}
return NULL;

View File

@@ -48,5 +48,6 @@ struct LedgerEntryFormat
extern LedgerEntryFormat LedgerFormats[];
extern LedgerEntryFormat* getLgrFormat(LedgerEntryType t);
extern LedgerEntryFormat* getLgrFormat(int t);
#endif
// vim:ts=4

View File

@@ -5,6 +5,8 @@
#include "SerializedTypes.h"
#include "SerializedObject.h"
#include "TransactionFormats.h"
#include "LedgerFormats.h"
#include "FieldNames.h"
#include "Log.h"
#include "NewcoinAddress.h"
#include "utils.h"
@@ -50,6 +52,18 @@ STUInt16* STUInt16::construct(SerializerIterator& u, SField::ref name)
std::string STUInt16::getText() const
{
if (getFName() == sfLedgerEntryType)
{
LedgerEntryFormat *f = getLgrFormat(value);
if (f != NULL)
return f->t_name;
}
if (getFName() == sfTransactionType)
{
TransactionFormat *f = getTxnFormat(value);
if (f != NULL)
return f->t_name;
}
return boost::lexical_cast<std::string>(value);
}

View File

@@ -100,14 +100,20 @@ TransactionFormat InnerTxnFormats[]=
{ NULL, ttINVALID }
};
TransactionFormat* getTxnFormat(TransactionType t)
TransactionFormat* getTxnFormat(TransactionType t)
{
TransactionFormat* f = InnerTxnFormats;
while (f->t_name != NULL)
return getTxnFormat(t);
}
TransactionFormat* getTxnFormat(int t)
{
TransactionFormat* f = InnerTxnFormats;
while (f->t_name != NULL)
{
if (f->t_type == t) return f;
if (f->t_type == t)
return f;
++f;
}
return NULL;
return NULL;
}
// vim:ts=4

View File

@@ -46,5 +46,6 @@ const uint32 tfNoRippleDirect = 0x00080000;
extern TransactionFormat InnerTxnFormats[];
extern TransactionFormat* getTxnFormat(TransactionType t);
extern TransactionFormat* getTxnFormat(int t);
#endif
// vim:ts=4