mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Merge branch 'master' into unl
This commit is contained in:
@@ -31,7 +31,7 @@ protected:
|
||||
boost::ptr_vector<SerializedType> data;
|
||||
|
||||
public:
|
||||
STUObject() : type(NULL) { ; }
|
||||
STUObject(const char *n=NULL) : SerializedType(n), type(NULL) { ; }
|
||||
STUObject(SOType *t) : type(t) { ; }
|
||||
STUObject(SOType *t, SerializerIterator& u);
|
||||
virtual ~STUObject() { ; }
|
||||
|
||||
@@ -1,3 +1,91 @@
|
||||
|
||||
#include "SerializedTransaction.h"
|
||||
|
||||
SerializedTransaction::SerializedTransaction(TransactionType type)
|
||||
{
|
||||
mFormat=getFormat(type);
|
||||
if(mFormat==NULL) throw(std::runtime_error("invalid transaction type"));
|
||||
|
||||
mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic));
|
||||
mMiddleTxn.giveObject(new STVariableLength("Signature")); // signature
|
||||
mMiddleTxn.giveObject(new STUInt8("Type", static_cast<unsigned char>(type)));
|
||||
|
||||
SOElement* elem=mFormat->elements;
|
||||
while(elem->e_id!=STI_DONE)
|
||||
{
|
||||
if( (elem->e_type==SOE_IFFLAG) || (elem->e_type==SOE_IFNFLAG) )
|
||||
mInnerTxn.giveObject(new STUObject(elem->e_name));
|
||||
else switch(elem->e_id)
|
||||
{
|
||||
case STI_UINT16:
|
||||
mInnerTxn.giveObject(new STUInt16(elem->e_name));
|
||||
break;
|
||||
case STI_UINT32:
|
||||
mInnerTxn.giveObject(new STUInt32(elem->e_name));
|
||||
break;
|
||||
case STI_UINT64:
|
||||
mInnerTxn.giveObject(new STUInt64(elem->e_name));
|
||||
case STI_HASH160:
|
||||
case STI_HASH256:
|
||||
case STI_VL:
|
||||
mInnerTxn.giveObject(new STVariableLength(elem->e_name));
|
||||
break;
|
||||
case STI_TL:
|
||||
mInnerTxn.giveObject(new STTaggedList(elem->e_name));
|
||||
break;
|
||||
#if 0
|
||||
case STI_ACCOUNT: // CHECKME: Should an account be variable length?
|
||||
mInnerTxn.giveObject(new STVariableLength(elem->e_name));
|
||||
break;
|
||||
#endif
|
||||
default: throw(std::runtime_error("invalid transaction element"));
|
||||
}
|
||||
elem++;
|
||||
}
|
||||
}
|
||||
|
||||
SerializedTransaction::SerializedTransaction(SerializerIterator& sit, int length)
|
||||
{
|
||||
if(length==0) length=sit.get32();
|
||||
if( (length<TransactionMinLen) || (length>TransactionMaxLen) )
|
||||
throw(std::runtime_error("Transaction length invalid"));
|
||||
|
||||
mSignature.setValue(sit.getVL());
|
||||
|
||||
if(sit.get32()!=TransactionMagic)
|
||||
throw(std::runtime_error("Transaction has invalid magic"));
|
||||
|
||||
mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic));
|
||||
mMiddleTxn.giveObject(new STVariableLength("Signature", sit.getVL()));
|
||||
mMiddleTxn.giveObject(new STUInt32("Type", sit.get32()));
|
||||
|
||||
// WRITEME
|
||||
}
|
||||
|
||||
int SerializedTransaction::getLength() const
|
||||
{
|
||||
return mSignature.getLength() + mMiddleTxn.getLength() + mInnerTxn.getLength();
|
||||
}
|
||||
|
||||
std::string SerializedTransaction::getFullText() const
|
||||
{ // WRITEME: Add transaction ID
|
||||
std::string ret="{";
|
||||
ret+=mSignature.getFullText();
|
||||
ret+=mMiddleTxn.getFullText();
|
||||
ret+=mInnerTxn.getFullText();
|
||||
ret+="}";
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string SerializedTransaction::getText() const
|
||||
{
|
||||
std::string ret="{";
|
||||
ret+=mSignature.getText();
|
||||
ret+=mMiddleTxn.getText();
|
||||
ret+=mInnerTxn.getText();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SerializedTransaction::add(Serializer& s) const
|
||||
{
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class SerializedTransaction : public STUObject
|
||||
{
|
||||
protected:
|
||||
TransactionType type;
|
||||
STUVariableLength mSignature;
|
||||
STVariableLength mSignature;
|
||||
STUObject mMiddleTxn, mInnerTxn;
|
||||
TransactionFormat* mFormat;
|
||||
|
||||
|
||||
@@ -89,22 +89,22 @@ static std::string hex(const std::vector<unsigned char>& value)
|
||||
return std::string(psz, psz + value.size()*2);
|
||||
}
|
||||
|
||||
std::string STUVariableLength::getText() const
|
||||
std::string STVariableLength::getText() const
|
||||
{
|
||||
return hex(value);
|
||||
}
|
||||
|
||||
STUVariableLength* STUVariableLength::construct(SerializerIterator& u)
|
||||
STVariableLength* STVariableLength::construct(SerializerIterator& u)
|
||||
{
|
||||
return new STUVariableLength(u.getVL());
|
||||
return new STVariableLength(u.getVL());
|
||||
}
|
||||
|
||||
int STUVariableLength::getLength() const
|
||||
int STVariableLength::getLength() const
|
||||
{
|
||||
return Serializer::encodeLengthLength(value.size()) + value.size();
|
||||
}
|
||||
|
||||
std::string STUTaggedList::getText() const
|
||||
std::string STTaggedList::getText() const
|
||||
{
|
||||
std::string ret;
|
||||
for(std::vector<TaggedListItem>::const_iterator it=value.begin(); it!=value.end(); ++it)
|
||||
@@ -116,12 +116,12 @@ std::string STUTaggedList::getText() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
STUTaggedList* STUTaggedList::construct(SerializerIterator& u)
|
||||
STTaggedList* STTaggedList::construct(SerializerIterator& u)
|
||||
{
|
||||
return new STUTaggedList(u.getTaggedList());
|
||||
return new STTaggedList(u.getTaggedList());
|
||||
}
|
||||
|
||||
int STUTaggedList::getLength() const
|
||||
int STTaggedList::getLength() const
|
||||
{
|
||||
int ret=Serializer::getTaggedListLength(value);
|
||||
if(ret<0) throw(0);
|
||||
|
||||
@@ -14,10 +14,10 @@ enum SerializedTypeID
|
||||
|
||||
// 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,
|
||||
STI_HASH160=6, STI_HASH256=7, STI_VL=8, STI_TL=9,
|
||||
|
||||
// high level types
|
||||
STI_TRANSACTION=9
|
||||
STI_TRANSACTION=10
|
||||
};
|
||||
|
||||
class SerializedType
|
||||
@@ -56,6 +56,7 @@ protected:
|
||||
public:
|
||||
|
||||
STUInt8(unsigned char v=0) : value(v) { ; }
|
||||
STUInt8(const char *n, unsigned char v=0) : SerializedType(n), value(v) { ; }
|
||||
static STUInt8* construct(SerializerIterator&);
|
||||
|
||||
int getLength() const { return 1; }
|
||||
@@ -79,6 +80,7 @@ protected:
|
||||
public:
|
||||
|
||||
STUInt16(uint16 v=0) : value(v) { ; }
|
||||
STUInt16(const char *n, uint16 v=0) : SerializedType(n), value(v) { ; }
|
||||
static STUInt16* construct(SerializerIterator&);
|
||||
|
||||
int getLength() const { return 2; }
|
||||
@@ -102,6 +104,7 @@ protected:
|
||||
public:
|
||||
|
||||
STUInt32(uint32 v=0) : value(v) { ; }
|
||||
STUInt32(const char *n, uint32 v=0) : SerializedType(n), value(v) { ; }
|
||||
static STUInt32* construct(SerializerIterator&);
|
||||
|
||||
int getLength() const { return 4; }
|
||||
@@ -125,6 +128,7 @@ protected:
|
||||
public:
|
||||
|
||||
STUInt64(uint64 v=0) : value(v) { ; }
|
||||
STUInt64(const char *n, uint64 v=0) : SerializedType(n), value(v) { ; }
|
||||
static STUInt64* construct(SerializerIterator&);
|
||||
|
||||
int getLength() const { return 8; }
|
||||
@@ -147,7 +151,8 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
STUHash160(const uint160& v) : value(v) { ; }
|
||||
STUHash160(const uint160& v=uint160()) : value(v) { ; }
|
||||
STUHash160(const char *n, const uint160& v=uint160()) : SerializedType(n), value(v) { ; }
|
||||
STUHash160() { ; }
|
||||
static STUHash160* construct(SerializerIterator&);
|
||||
|
||||
@@ -172,6 +177,7 @@ protected:
|
||||
public:
|
||||
|
||||
STUHash256(const uint256& v) : value(v) { ; }
|
||||
STUHash256(const char *n, const uint256& v=uint256()) : SerializedType(n), value(v) { ; }
|
||||
STUHash256() { ; }
|
||||
static STUHash256* construct(SerializerIterator&);
|
||||
|
||||
@@ -188,46 +194,50 @@ public:
|
||||
STUHash256& operator=(const uint256& v) { value=v; return *this; }
|
||||
};
|
||||
|
||||
class STUVariableLength
|
||||
class STVariableLength : public SerializedType
|
||||
{ // variable length byte string protected:
|
||||
protected:
|
||||
std::vector<unsigned char> value;
|
||||
|
||||
public:
|
||||
|
||||
STUVariableLength(const std::vector<unsigned char>& v) : value(v) { ; }
|
||||
STUVariableLength() { ; }
|
||||
static STUVariableLength* construct(SerializerIterator&);
|
||||
STVariableLength(const std::vector<unsigned char>& v) : value(v) { ; }
|
||||
STVariableLength(const char *n, const std::vector<unsigned char>& v) : SerializedType(n), value(v) { ; }
|
||||
STVariableLength(const char *n) : SerializedType(n) { ; }
|
||||
STVariableLength() { ; }
|
||||
static STVariableLength* construct(SerializerIterator&);
|
||||
|
||||
int getLength() const;
|
||||
SerializedTypeID getType() const { return STI_VL; }
|
||||
STUVariableLength *duplicate() const { return new STUVariableLength(value); }
|
||||
STVariableLength *duplicate() const { return new STVariableLength(value); }
|
||||
std::string getText() const;
|
||||
virtual void add(Serializer& s) const { s.addVL(value); }
|
||||
|
||||
const std::vector<unsigned char>& peekValue() const { return value; }
|
||||
std::vector<unsigned char>& peekValue() { return value; }
|
||||
std::vector<unsigned char> getValue() const { return value; }
|
||||
void setValue(std::vector<unsigned char>& v) { value=v; }
|
||||
void setValue(const std::vector<unsigned char>& v) { value=v; }
|
||||
|
||||
operator std::vector<unsigned char>() const { return value; }
|
||||
STUVariableLength& operator=(const std::vector<unsigned char>& v) { value=v; return *this; }
|
||||
STVariableLength& operator=(const std::vector<unsigned char>& v) { value=v; return *this; }
|
||||
};
|
||||
|
||||
class STUTaggedList
|
||||
class STTaggedList : public SerializedType
|
||||
{
|
||||
protected:
|
||||
std::vector<TaggedListItem> value;
|
||||
|
||||
public:
|
||||
|
||||
STUTaggedList(const std::vector<TaggedListItem>& v) : value(v) { ; }
|
||||
STUTaggedList() { ; }
|
||||
static STUTaggedList* construct(SerializerIterator&);
|
||||
STTaggedList() { ; }
|
||||
STTaggedList(const char *n) : SerializedType(n) { ; }
|
||||
STTaggedList(const std::vector<TaggedListItem>& v) : value(v) { ; }
|
||||
STTaggedList(const char *n, const std::vector<TaggedListItem>& v) : SerializedType(n), value(v) { ; }
|
||||
static STTaggedList* construct(SerializerIterator&);
|
||||
|
||||
int getLength() const;
|
||||
SerializedTypeID getType() const { return STI_TL; }
|
||||
STUTaggedList *duplicate() const { return new STUTaggedList(value); }
|
||||
STTaggedList *duplicate() const { return new STTaggedList(value); }
|
||||
std::string getText() const;
|
||||
virtual void add(Serializer& s) const { if(s.addTaggedList(value)<0) throw(0); }
|
||||
|
||||
@@ -235,7 +245,7 @@ public:
|
||||
std::vector<TaggedListItem>& peekValue() { return value; }
|
||||
std::vector<TaggedListItem> getValue() const { return value; }
|
||||
|
||||
void setValue(std::vector<TaggedListItem>& v) { value=v; }
|
||||
void setValue(const std::vector<TaggedListItem>& v) { value=v; }
|
||||
|
||||
int getItemCount() const { return value.size(); }
|
||||
bool isEmpty() const { return value.empty(); }
|
||||
@@ -244,7 +254,7 @@ public:
|
||||
void addItem(const TaggedListItem& v) { value.push_back(v); }
|
||||
|
||||
operator std::vector<TaggedListItem>() const { return value; }
|
||||
STUTaggedList& operator=(const std::vector<TaggedListItem>& v) { value=v; return *this; }
|
||||
STTaggedList& operator=(const std::vector<TaggedListItem>& v) { value=v; return *this; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user