From 18ca0ebb2157586947906e5a8ee33e60cb1da9d4 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 20 Mar 2012 11:21:40 -0700 Subject: [PATCH] Don't use 'magic numbers' for transaction types. Extra transaction constants. getFormat function. --- src/TransactionFormats.cpp | 20 ++++++++++++++++---- src/TransactionFormats.h | 25 +++++++++++++++---------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/TransactionFormats.cpp b/src/TransactionFormats.cpp index 0ad2982b7c..ce11a294d9 100644 --- a/src/TransactionFormats.cpp +++ b/src/TransactionFormats.cpp @@ -3,7 +3,7 @@ TransactionFormat InnerTxnFormats[]= { - { "MakePayment", 0, { + { "MakePayment", ttMAKE_PAYMENT, { { "Flags", STI_UINT16, SOE_FLAGS, 0 }, { "Sequence", STI_UINT32, SOE_REQUIRED, 0 }, { "Destination", STI_ACCOUNT, SOE_REQUIRED, 0 }, @@ -15,7 +15,7 @@ TransactionFormat InnerTxnFormats[]= { "Extensions", STI_TL, SOE_IFFLAG, 32768 }, { NULL, STI_DONE, SOE_NEVER, -1 } } }, - { "Invoice", 1, { + { "Invoice", ttINVOICE, { { "Flags", STI_UINT16, SOE_FLAGS, 0 }, { "Sequence", STI_UINT32, SOE_REQUIRED, 0 }, { "Target", STI_ACCOUNT, SOE_REQUIRED, 0 }, @@ -28,7 +28,7 @@ TransactionFormat InnerTxnFormats[]= { "Extensions", STI_TL, SOE_IFFLAG, 32768 }, { NULL, STI_DONE, SOE_NEVER, -1 } } }, - { "Offer", 2, { + { "Offer", ttEXCHANGE_OFFER, { { "Flags", STI_UINT16, SOE_FLAGS, 0 }, { "Sequence", STI_UINT32, SOE_REQUIRED, 0 }, { "AmountIn", STI_UINT64, SOE_REQUIRED, 0 }, @@ -42,5 +42,17 @@ TransactionFormat InnerTxnFormats[]= { "Identifier", STI_VL, SOE_IFFLAG, 128 }, { "Extensions", STI_TL, SOE_IFFLAG, 32768 }, { NULL, STI_DONE, SOE_NEVER, -1 } } - } + }, + { NULL, ttINVALID } }; + +TransactionFormat* getFormat(TransactionType t) +{ + TransactionFormat* f=InnerTxnFormats; + while(f->t_name!=NULL) + { + if(f->t_type==t) return f; + f++; + } + return NULL; +} diff --git a/src/TransactionFormats.h b/src/TransactionFormats.h index e4a0d5b0c0..52e91e1c9d 100644 --- a/src/TransactionFormats.h +++ b/src/TransactionFormats.h @@ -5,20 +5,25 @@ #define STI_ACCOUNT STI_HASH160 -struct TransactionFormat -{ - const char *t_name; - int t_id; - SOElement elements[16]; -}; - -extern TransactionFormat InnerTxnFormats[]; - enum TransactionType { + ttINVALID=-1, ttMAKE_PAYMENT=0, - ttNTX_INVOICE=1, + ttINVOICE=1, ttEXCHANGE_OFFER=2 }; +struct TransactionFormat +{ + const char *t_name; + TransactionType t_type; + SOElement elements[16]; +}; + +const int32 TransactionMagic=0x54583000; +const int TransactionMinLen=32; +const int TransactionMaxLen=1048576; + +extern TransactionFormat InnerTxnFormats[]; +extern TransactionFormat* getFormat(TransactionType t); #endif