Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
Arthur Britto
2012-03-19 12:16:01 -07:00
7 changed files with 129 additions and 41 deletions

View File

@@ -48,6 +48,10 @@ public:
void giveObject(SerializedType* t) { data.push_back(t); }
const boost::ptr_vector<SerializedType>& peekData() const { return data; }
boost::ptr_vector<SerializedType>& 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]; }
};

View File

@@ -0,0 +1,3 @@
#include "SerializedTransaction.h"

View File

@@ -0,0 +1,63 @@
#ifndef __SERIALIZEDTRANSACTION__
#define __SERIALIZEDTRANSACTION__
#include <vector>
#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<unsigned char> getSignature() const;
void setSignature(const std::vector<unsigned char>& 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

View File

@@ -3,6 +3,7 @@
#include "SerializedTypes.h"
#include "SerializedObject.h"
#include "TransactionFormats.h"
std::string SerializedType::getFullText() const
{

View File

@@ -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

View File

@@ -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 } }
}
};

View File

@@ -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