diff --git a/src/SerializedObject.h b/src/SerializedObject.h index 776821ac82..f7670940db 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]; } }; diff --git a/src/SerializedTransaction.cpp b/src/SerializedTransaction.cpp new file mode 100644 index 0000000000..39e1325ef1 --- /dev/null +++ b/src/SerializedTransaction.cpp @@ -0,0 +1,3 @@ + +#include "SerializedTransaction.h" + diff --git a/src/SerializedTransaction.h b/src/SerializedTransaction.h new file mode 100644 index 0000000000..a983a091e6 --- /dev/null +++ b/src/SerializedTransaction.h @@ -0,0 +1,63 @@ +#ifndef __SERIALIZEDTRANSACTION__ +#define __SERIALIZEDTRANSACTION__ + +#include + +#include "uint256.h" +#include "SerializedObject.h" +#include "TransactionFormats.h" + +class SerializedTransaction : public STUObject +{ +protected: + TransactionType type; + STUVariableLength mSignature; + STUObject mMiddleTxn, mInnerTxn; + TransactionFormat* mFormat; + +public: + SerializedTransaction(SerializerIterator&, int length); + SerializedTransaction(TransactionType 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 diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index acdb2d1a28..9366c6415a 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/SerializedTypes.h b/src/SerializedTypes.h index 6c70c9b0a3..6ec3d2ab91 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 diff --git a/src/TransactionFormats.cpp b/src/TransactionFormats.cpp new file mode 100644 index 0000000000..0ad2982b7c --- /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 3064178ad0..e4a0d5b0c0 100644 --- a/src/TransactionFormats.h +++ b/src/TransactionFormats.h @@ -12,48 +12,13 @@ struct TransactionFormat SOElement elements[16]; }; -TransactionFormat InnerTxnFormats[]= +extern TransactionFormat InnerTxnFormats[]; + +enum TransactionType { - { "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 } } - } + ttMAKE_PAYMENT=0, + ttNTX_INVOICE=1, + ttEXCHANGE_OFFER=2 }; #endif