mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Make accounts there own type
so we can add new functionality and so they can display properly. Cleanups and missing helper function.
This commit is contained in:
@@ -28,10 +28,8 @@ SerializedType* STObject::makeDefaultObject(SerializedTypeID id, const char *nam
|
||||
case STI_TL:
|
||||
return new STTaggedList(name);
|
||||
|
||||
#if 0
|
||||
case STI_ACCOUNT: // CHECKME: Should an account be variable length?
|
||||
return new STVariableLength(name);
|
||||
#endif
|
||||
case STI_ACCOUNT:
|
||||
return new STAccount(name);
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
@@ -63,11 +61,9 @@ SerializedType* STObject::makeDeserializedObject(SerializedTypeID id, const char
|
||||
case STI_TL:
|
||||
return STTaggedList::construct(sit, name);
|
||||
|
||||
#if 0
|
||||
case STI_ACCOUNT: // CHECKME: Should an account be variable length?
|
||||
return STVariableLength::construct(sit, name);
|
||||
case STI_ACCOUNT:
|
||||
return STAccount::construct(sit, name);
|
||||
|
||||
#endif
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -99,6 +99,11 @@ std::vector<unsigned char> SerializedTransaction::getSignature() const
|
||||
return mSignature.getValue();
|
||||
}
|
||||
|
||||
const std::vector<unsigned char>& SerializedTransaction::peekSignature() const
|
||||
{
|
||||
return mSignature.peekValue();
|
||||
}
|
||||
|
||||
bool SerializedTransaction::sign(CKey& key)
|
||||
{
|
||||
return key.Sign(getSigningHash(), mSignature.peekValue());
|
||||
@@ -156,6 +161,36 @@ void SerializedTransaction::setSequence(uint32 seq)
|
||||
v->setValue(seq);
|
||||
}
|
||||
|
||||
std::vector<unsigned char> SerializedTransaction::getSigningAccount() const
|
||||
{
|
||||
const STVariableLength* v=
|
||||
dynamic_cast<const STVariableLength*>(mMiddleTxn.peekAtPIndex(TransactionISigningAccount));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
return v->getValue();
|
||||
}
|
||||
|
||||
const std::vector<unsigned char>& SerializedTransaction::peekSigningAccount() const
|
||||
{
|
||||
const STVariableLength* v=
|
||||
dynamic_cast<const STVariableLength*>(mMiddleTxn.peekAtPIndex(TransactionISigningAccount));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
return v->peekValue();
|
||||
}
|
||||
|
||||
std::vector<unsigned char>& SerializedTransaction::peekSigningAccount()
|
||||
{
|
||||
STVariableLength* v=dynamic_cast<STVariableLength*>(mMiddleTxn.getPIndex(TransactionISigningAccount));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
return v->peekValue();
|
||||
}
|
||||
|
||||
void SerializedTransaction::setSigningAccount(const std::vector<unsigned char>& s)
|
||||
{
|
||||
STVariableLength* v=dynamic_cast<STVariableLength*>(mMiddleTxn.getPIndex(TransactionISigningAccount));
|
||||
if(!v) throw(std::runtime_error("corrupt transaction"));
|
||||
v->setValue(s);
|
||||
}
|
||||
|
||||
int SerializedTransaction::getITFieldIndex(SOE_Field field) const
|
||||
{
|
||||
return mInnerTxn.getFieldIndex(field);
|
||||
|
||||
@@ -34,6 +34,7 @@ public:
|
||||
|
||||
// outer transaction functions / signature functions
|
||||
std::vector<unsigned char> getSignature() const;
|
||||
const std::vector<unsigned char>& peekSignature() const;
|
||||
void setSignature(const std::vector<unsigned char>& s);
|
||||
uint256 getSigningHash() const;
|
||||
|
||||
@@ -44,6 +45,8 @@ public:
|
||||
uint64 getTransactionFee() const;
|
||||
void setTransactionFee(uint64);
|
||||
std::vector<unsigned char> getSigningAccount() const;
|
||||
const std::vector<unsigned char>& peekSigningAccount() const;
|
||||
std::vector<unsigned char>& peekSigningAccount();
|
||||
void setSigningAccount(const std::vector<unsigned char>& s);
|
||||
|
||||
// inner transaction functions
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "SerializedTypes.h"
|
||||
#include "SerializedObject.h"
|
||||
#include "TransactionFormats.h"
|
||||
#include "NewcoinAddress.h"
|
||||
|
||||
std::string SerializedType::getFullText() const
|
||||
{
|
||||
@@ -104,6 +105,44 @@ int STVariableLength::getLength() const
|
||||
return Serializer::encodeLengthLength(value.size()) + value.size();
|
||||
}
|
||||
|
||||
std::string STAccount::getText() const
|
||||
{
|
||||
uint160 u;
|
||||
NewcoinAddress a;
|
||||
if(!getValueH160(u)) return STVariableLength::getText();
|
||||
a.setAccountID(u);
|
||||
return a.humanAccountPublic();
|
||||
}
|
||||
|
||||
STAccount* STAccount::construct(SerializerIterator& u, const char *name)
|
||||
{
|
||||
STAccount *ret=new STAccount(u.getVL());
|
||||
if(!ret->isValueH160())
|
||||
{
|
||||
delete ret;
|
||||
throw(std::runtime_error("invalid account in transaction"));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool STAccount::isValueH160() const
|
||||
{
|
||||
return peekValue().size() == (160/8);
|
||||
}
|
||||
|
||||
void STAccount::setValueH160(const uint160& v)
|
||||
{
|
||||
peekValue().empty();
|
||||
peekValue().insert(peekValue().end(), v.begin(), v.end());
|
||||
}
|
||||
|
||||
bool STAccount::getValueH160(uint160& v) const
|
||||
{
|
||||
if(!isValueH160()) return false;
|
||||
memcpy(v.begin(), &(peekValue().front()), 32);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string STTaggedList::getText() const
|
||||
{
|
||||
std::string ret;
|
||||
@@ -128,3 +167,4 @@ int STTaggedList::getLength() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ enum SerializedTypeID
|
||||
STI_HASH160=6, STI_HASH256=7, STI_VL=8, STI_TL=9,
|
||||
|
||||
// high level types
|
||||
STI_TRANSACTION=10
|
||||
STI_ACCOUNT=10, STI_TRANSACTION=10
|
||||
};
|
||||
|
||||
class SerializedType
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
|
||||
int getLength() const { return 1; }
|
||||
SerializedTypeID getType() const { return STI_UINT8; }
|
||||
STUInt8 *duplicate() const { return new STUInt8(name, value); }
|
||||
STUInt8* duplicate() const { return new STUInt8(name, value); }
|
||||
std::string getText() const;
|
||||
void add(Serializer& s) const { s.add8(value); }
|
||||
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
|
||||
int getLength() const { return 2; }
|
||||
SerializedTypeID getType() const { return STI_UINT16; }
|
||||
STUInt16 *duplicate() const { return new STUInt16(name, value); }
|
||||
STUInt16* duplicate() const { return new STUInt16(name, value); }
|
||||
std::string getText() const;
|
||||
void add(Serializer& s) const { s.add16(value); }
|
||||
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
|
||||
int getLength() const { return 4; }
|
||||
SerializedTypeID getType() const { return STI_UINT32; }
|
||||
STUInt32 *duplicate() const { return new STUInt32(name, value); }
|
||||
STUInt32* duplicate() const { return new STUInt32(name, value); }
|
||||
std::string getText() const;
|
||||
void add(Serializer& s) const { s.add32(value); }
|
||||
|
||||
@@ -133,7 +133,7 @@ public:
|
||||
|
||||
int getLength() const { return 8; }
|
||||
SerializedTypeID getType() const { return STI_UINT64; }
|
||||
STUInt64 *duplicate() const { return new STUInt64(name, value); }
|
||||
STUInt64* duplicate() const { return new STUInt64(name, value); }
|
||||
std::string getText() const;
|
||||
void add(Serializer& s) const { s.add64(value); }
|
||||
|
||||
@@ -158,8 +158,8 @@ public:
|
||||
|
||||
int getLength() const { return 20; }
|
||||
SerializedTypeID getType() const { return STI_HASH160; }
|
||||
STHash160 *duplicate() const { return new STHash160(name, value); }
|
||||
std::string getText() const;
|
||||
STHash160* duplicate() const { return new STHash160(name, value); }
|
||||
virtual std::string getText() const;
|
||||
void add(Serializer& s) const { s.add160(value); }
|
||||
|
||||
const uint160& getValue() const { return value; }
|
||||
@@ -183,7 +183,7 @@ public:
|
||||
|
||||
int getLength() const { return 32; }
|
||||
SerializedTypeID getType() const { return STI_HASH256; }
|
||||
STHash256 *duplicate() const { return new STHash256(name, value); }
|
||||
STHash256* duplicate() const { return new STHash256(name, value); }
|
||||
std::string getText() const;
|
||||
void add(Serializer& s) const { s.add256(value); }
|
||||
|
||||
@@ -208,9 +208,9 @@ public:
|
||||
static STVariableLength* construct(SerializerIterator&, const char *name=NULL);
|
||||
|
||||
int getLength() const;
|
||||
SerializedTypeID getType() const { return STI_VL; }
|
||||
STVariableLength *duplicate() const { return new STVariableLength(name, value); }
|
||||
std::string getText() const;
|
||||
virtual SerializedTypeID getType() const { return STI_VL; }
|
||||
virtual STVariableLength* duplicate() const { return new STVariableLength(name, value); }
|
||||
virtual std::string getText() const;
|
||||
void add(Serializer& s) const { s.addVL(value); }
|
||||
|
||||
const std::vector<unsigned char>& peekValue() const { return value; }
|
||||
@@ -222,6 +222,25 @@ public:
|
||||
STVariableLength& operator=(const std::vector<unsigned char>& v) { value=v; return *this; }
|
||||
};
|
||||
|
||||
class STAccount : public STVariableLength
|
||||
{
|
||||
public:
|
||||
|
||||
STAccount(const std::vector<unsigned char>& v) : STVariableLength(v) { ; }
|
||||
STAccount(const char *n, const std::vector<unsigned char>& v) : STVariableLength(n, v) { ; }
|
||||
STAccount(const char *n) : STVariableLength(n) { ; }
|
||||
STAccount() { ; }
|
||||
static STAccount* construct(SerializerIterator&, const char *name=NULL);
|
||||
|
||||
SerializedTypeID getType() const { return STI_ACCOUNT; }
|
||||
virtual STAccount* duplicate() const { return new STAccount(name, value); }
|
||||
std::string getText() const;
|
||||
|
||||
void setValueH160(const uint160& v);
|
||||
bool getValueH160(uint160&) const;
|
||||
bool isValueH160() const;
|
||||
};
|
||||
|
||||
class STTaggedList : public SerializedType
|
||||
{
|
||||
protected:
|
||||
@@ -237,7 +256,7 @@ public:
|
||||
|
||||
int getLength() const;
|
||||
SerializedTypeID getType() const { return STI_TL; }
|
||||
STTaggedList *duplicate() const { return new STTaggedList(name, value); }
|
||||
STTaggedList* duplicate() const { return new STTaggedList(name, value); }
|
||||
std::string getText() const;
|
||||
void add(Serializer& s) const { if(s.addTaggedList(value)<0) throw(0); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user