From a03076823b495e09dc4ab848a4f9446b86a913d4 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Mar 2012 09:06:40 -0700 Subject: [PATCH 1/6] Some missing helper functions. --- src/SerializedObject.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SerializedObject.h b/src/SerializedObject.h index 776821ac8..f7670940d 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -48,6 +48,10 @@ public: void giveObject(SerializedType* t) { data.push_back(t); } const boost::ptr_vector& peekData() const { return data; } boost::ptr_vector& peekData() { return data; } + + int getCount() const { return data.size(); } + const SerializedType& peekAt(int offset) const { return data[offset]; } + SerializedType& getAt(int offset) { return data[offset]; } }; From 7e6406a484df066150a31e698155ec17b51fa781 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Mar 2012 09:08:55 -0700 Subject: [PATCH 2/6] Move the table to the implementation. --- src/TransactionFormats.cpp | 46 ++++++++++++++++++++++++++++++++++++++ src/TransactionFormats.h | 44 +----------------------------------- 2 files changed, 47 insertions(+), 43 deletions(-) create mode 100644 src/TransactionFormats.cpp diff --git a/src/TransactionFormats.cpp b/src/TransactionFormats.cpp new file mode 100644 index 000000000..0ad2982b7 --- /dev/null +++ b/src/TransactionFormats.cpp @@ -0,0 +1,46 @@ + +#include "TransactionFormats.h" + +TransactionFormat InnerTxnFormats[]= +{ + { "MakePayment", 0, { + { "Flags", STI_UINT16, SOE_FLAGS, 0 }, + { "Sequence", STI_UINT32, SOE_REQUIRED, 0 }, + { "Destination", STI_ACCOUNT, SOE_REQUIRED, 0 }, + { "Amount", STI_UINT64, SOE_REQUIRED, 0 }, + { "Currency", STI_HASH160, SOE_IFFLAG, 1 }, + { "SourceTag", STI_UINT32, SOE_IFFLAG, 2 }, + { "TargetLedger", STI_UINT32, SOE_IFFLAG, 4 }, + { "InvoiceID", STI_HASH256, SOE_IFFLAG, 8 }, + { "Extensions", STI_TL, SOE_IFFLAG, 32768 }, + { NULL, STI_DONE, SOE_NEVER, -1 } } + }, + { "Invoice", 1, { + { "Flags", STI_UINT16, SOE_FLAGS, 0 }, + { "Sequence", STI_UINT32, SOE_REQUIRED, 0 }, + { "Target", STI_ACCOUNT, SOE_REQUIRED, 0 }, + { "Amount", STI_UINT64, SOE_REQUIRED, 0 }, + { "Currency", STI_HASH160, SOE_IFFLAG, 1 }, + { "SourceTag", STI_UINT32, SOE_IFFLAG, 2 }, + { "Destination", STI_ACCOUNT, SOE_IFFLAG, 4 }, + { "TargetLedger", STI_UINT32, SOE_IFFLAG, 8 }, + { "Identifier", STI_VL, SOE_IFFLAG, 16 }, + { "Extensions", STI_TL, SOE_IFFLAG, 32768 }, + { NULL, STI_DONE, SOE_NEVER, -1 } } + }, + { "Offer", 2, { + { "Flags", STI_UINT16, SOE_FLAGS, 0 }, + { "Sequence", STI_UINT32, SOE_REQUIRED, 0 }, + { "AmountIn", STI_UINT64, SOE_REQUIRED, 0 }, + { "CurrencyIn", STI_HASH160, SOE_IFFLAG, 2 }, + { "AmountOut", STI_UINT64, SOE_REQUIRED, 0 }, + { "CurrencyOut", STI_HASH160, SOE_IFFLAG, 4 }, + { "SourceTag", STI_UINT32, SOE_IFFLAG, 8 }, + { "Destination", STI_ACCOUNT, SOE_IFFLAG, 16 }, + { "TargetLedger", STI_UINT32, SOE_IFFLAG, 32 }, + { "ExpireLedger", STI_UINT32, SOE_IFFLAG, 64 }, + { "Identifier", STI_VL, SOE_IFFLAG, 128 }, + { "Extensions", STI_TL, SOE_IFFLAG, 32768 }, + { NULL, STI_DONE, SOE_NEVER, -1 } } + } +}; diff --git a/src/TransactionFormats.h b/src/TransactionFormats.h index 3064178ad..a0b06283d 100644 --- a/src/TransactionFormats.h +++ b/src/TransactionFormats.h @@ -12,48 +12,6 @@ struct TransactionFormat SOElement elements[16]; }; -TransactionFormat InnerTxnFormats[]= -{ - { "MakePayment", 0, { - { "Flags", STI_UINT16, SOE_FLAGS, 0 }, - { "Sequence", STI_UINT32, SOE_REQUIRED, 0 }, - { "Destination", STI_ACCOUNT, SOE_REQUIRED, 0 }, - { "Amount", STI_UINT64, SOE_REQUIRED, 0 }, - { "Currency", STI_HASH160, SOE_IFFLAG, 1 }, - { "SourceTag", STI_UINT32, SOE_IFFLAG, 2 }, - { "TargetLedger", STI_UINT32, SOE_IFFLAG, 4 }, - { "InvoiceID", STI_HASH256, SOE_IFFLAG, 8 }, - { "Extensions", STI_TL, SOE_IFFLAG, 32768 }, - { NULL, STI_DONE, SOE_NEVER, -1 } } - }, - { "Invoice", 1, { - { "Flags", STI_UINT16, SOE_FLAGS, 0 }, - { "Sequence", STI_UINT32, SOE_REQUIRED, 0 }, - { "Target", STI_ACCOUNT, SOE_REQUIRED, 0 }, - { "Amount", STI_UINT64, SOE_REQUIRED, 0 }, - { "Currency", STI_HASH160, SOE_IFFLAG, 1 }, - { "SourceTag", STI_UINT32, SOE_IFFLAG, 2 }, - { "Destination", STI_ACCOUNT, SOE_IFFLAG, 4 }, - { "TargetLedger", STI_UINT32, SOE_IFFLAG, 8 }, - { "Identifier", STI_VL, SOE_IFFLAG, 16 }, - { "Extensions", STI_TL, SOE_IFFLAG, 32768 }, - { NULL, STI_DONE, SOE_NEVER, -1 } } - }, - { "Offer", 2, { - { "Flags", STI_UINT16, SOE_FLAGS, 0 }, - { "Sequence", STI_UINT32, SOE_REQUIRED, 0 }, - { "AmountIn", STI_UINT64, SOE_REQUIRED, 0 }, - { "CurrencyIn", STI_HASH160, SOE_IFFLAG, 2 }, - { "AmountOut", STI_UINT64, SOE_REQUIRED, 0 }, - { "CurrencyOut", STI_HASH160, SOE_IFFLAG, 4 }, - { "SourceTag", STI_UINT32, SOE_IFFLAG, 8 }, - { "Destination", STI_ACCOUNT, SOE_IFFLAG, 16 }, - { "TargetLedger", STI_UINT32, SOE_IFFLAG, 32 }, - { "ExpireLedger", STI_UINT32, SOE_IFFLAG, 64 }, - { "Identifier", STI_VL, SOE_IFFLAG, 128 }, - { "Extensions", STI_TL, SOE_IFFLAG, 32768 }, - { NULL, STI_DONE, SOE_NEVER, -1 } } - } -}; +extern TransactionFormat InnerTxnFormats[]; #endif From 4b66d24e3af9474ff82c5f5b1a20b3fc5902fb0b Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Mar 2012 09:27:46 -0700 Subject: [PATCH 3/6] Transaction in modifiable form. --- src/SerializedTransaction.h | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/SerializedTransaction.h diff --git a/src/SerializedTransaction.h b/src/SerializedTransaction.h new file mode 100644 index 000000000..d24a3fb76 --- /dev/null +++ b/src/SerializedTransaction.h @@ -0,0 +1,62 @@ +#ifndef __SERIALIZEDTRANSACTION__ +#define __SERIALIZEDTRANSACTION__ + +#include + +#include "uint256.h" +#include "SerializedObject.h" +#include "TransactionFormats.h" + +class SerializedTransaction : public STUObject +{ +protected: + STUVariableLength mSignature; + STUObject mMiddleTxn, mInnerTxn; + TransactionFormat* mFormat; + +public: + SerializedTransaction(SerializerIterator&, int length); + SerializedTransaction(int type); + + // STUObject functions + int getLength() const; + SerializedTypeID getType() const { return STI_TRANSACTION; } + SerializedTransaction* duplicate() const { return new SerializedTransaction(*this); } + std::string getFullText() const; + std::string getText() const; + void add(Serializer& s) const; + + // outer transaction functions / signature functions + std::vector getSignature() const; + void setSignature(const std::vector& s); + uint256 getSigningHash() const; + + // middle transaction functions + uint32 getVersion() const; + void setVersion(uint32); + int getTransactionType() const; + uint64 getTransactionFee() const; + void setTransactionFee(uint64); + + // inner transaction functions + uint16 getFlags() const; + void setFlag(int v); + void clearFlag(int v); + bool isFlag(int v); + + uint32 getSequence() const; + void setSequence(uint32); + + // inner transaction field functions + int getITFieldIndex(const char *) const; + int getITFieldCount() const; + bool getITFieldPresent(int index) const; + const SerializedType& peekITField(int index); + SerializedType& getITField(int index); + void makeITFieldPresent(int index); + + // whole transaction functions + int getTransaction(Serializer& s, bool include_length); +}; + +#endif From ad556a11cf80d595fa0d3da5adfa6935f5998d5d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Mar 2012 09:28:14 -0700 Subject: [PATCH 4/6] Support for transaction type. --- src/SerializedTypes.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index 6c70c9b0a..6ec3d2ab9 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -9,9 +9,15 @@ enum SerializedTypeID { + // special types STI_DONE=-1, STI_NOTPRESENT=0, + + // standard types STI_OBJECT=1, STI_UINT8=2, STI_UINT16=3, STI_UINT32=4, STI_UINT64=5, STI_HASH160=6, STI_HASH256=7, STI_VL=8, STI_TL=8, + + // high level types + STI_TRANSACTION=9 }; class SerializedType From b6f929c8a92b6aa4a3e07820e4472053926dbd88 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Mar 2012 09:31:01 -0700 Subject: [PATCH 5/6] Skeleton. --- src/SerializedTransaction.cpp | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/SerializedTransaction.cpp diff --git a/src/SerializedTransaction.cpp b/src/SerializedTransaction.cpp new file mode 100644 index 000000000..39e1325ef --- /dev/null +++ b/src/SerializedTransaction.cpp @@ -0,0 +1,3 @@ + +#include "SerializedTransaction.h" + From 2c113e8f8e778df02747441339800c4c5c718e8d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Mar 2012 09:31:20 -0700 Subject: [PATCH 6/6] Type for transaction types. --- src/SerializedTransaction.h | 3 ++- src/SerializedTypes.cpp | 1 + src/TransactionFormats.h | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/SerializedTransaction.h b/src/SerializedTransaction.h index d24a3fb76..a983a091e 100644 --- a/src/SerializedTransaction.h +++ b/src/SerializedTransaction.h @@ -10,13 +10,14 @@ class SerializedTransaction : public STUObject { protected: + TransactionType type; STUVariableLength mSignature; STUObject mMiddleTxn, mInnerTxn; TransactionFormat* mFormat; public: SerializedTransaction(SerializerIterator&, int length); - SerializedTransaction(int type); + SerializedTransaction(TransactionType type); // STUObject functions int getLength() const; diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index acdb2d1a2..9366c6415 100644 --- a/src/SerializedTypes.cpp +++ b/src/SerializedTypes.cpp @@ -3,6 +3,7 @@ #include "SerializedTypes.h" #include "SerializedObject.h" +#include "TransactionFormats.h" std::string SerializedType::getFullText() const { diff --git a/src/TransactionFormats.h b/src/TransactionFormats.h index a0b06283d..e4a0d5b0c 100644 --- a/src/TransactionFormats.h +++ b/src/TransactionFormats.h @@ -14,4 +14,11 @@ struct TransactionFormat extern TransactionFormat InnerTxnFormats[]; +enum TransactionType +{ + ttMAKE_PAYMENT=0, + ttNTX_INVOICE=1, + ttEXCHANGE_OFFER=2 +}; + #endif