mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin
This commit is contained in:
@@ -359,19 +359,16 @@ STAmount* STAmount::construct(SerializerIterator& sit, const char *name)
|
||||
if ((value < cMinValue) || (value > cMaxValue) || (offset < cMinOffset) || (offset > cMaxOffset))
|
||||
throw std::runtime_error("invalid currency value");
|
||||
|
||||
sapResult = new STAmount(name, uCurrencyID, value, offset, isNegative);
|
||||
sapResult = new STAmount(name, uCurrencyID, uIssuerID, value, offset, isNegative);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (offset != 512)
|
||||
throw std::runtime_error("invalid currency value");
|
||||
|
||||
sapResult = new STAmount(name, uCurrencyID);
|
||||
sapResult = new STAmount(name, uCurrencyID, uIssuerID);
|
||||
}
|
||||
|
||||
if (sapResult)
|
||||
sapResult->setIssuer(uIssuerID);
|
||||
|
||||
return sapResult;
|
||||
}
|
||||
|
||||
@@ -522,7 +519,7 @@ STAmount& STAmount::operator-=(const STAmount& a)
|
||||
STAmount STAmount::operator-(void) const
|
||||
{
|
||||
if (mValue == 0) return *this;
|
||||
return STAmount(name, mCurrency, mValue, mOffset, mIsNative, !mIsNegative);
|
||||
return STAmount(name, mCurrency, mIssuer, mValue, mOffset, mIsNative, !mIsNegative);
|
||||
}
|
||||
|
||||
STAmount& STAmount::operator=(uint64 v)
|
||||
@@ -620,9 +617,9 @@ STAmount operator+(const STAmount& v1, const STAmount& v2)
|
||||
|
||||
int64 fv = vv1 + vv2;
|
||||
if (fv >= 0)
|
||||
return STAmount(v1.name, v1.mCurrency, fv, ov1, false);
|
||||
return STAmount(v1.name, v1.mCurrency, v1.mIssuer, fv, ov1, false);
|
||||
else
|
||||
return STAmount(v1.name, v1.mCurrency, -fv, ov1, true);
|
||||
return STAmount(v1.name, v1.mCurrency, v1.mIssuer, -fv, ov1, true);
|
||||
}
|
||||
|
||||
STAmount operator-(const STAmount& v1, const STAmount& v2)
|
||||
@@ -652,9 +649,9 @@ STAmount operator-(const STAmount& v1, const STAmount& v2)
|
||||
|
||||
int64 fv = vv1 - vv2;
|
||||
if (fv >= 0)
|
||||
return STAmount(v1.name, v1.mCurrency, fv, ov1, false);
|
||||
return STAmount(v1.name, v1.mCurrency, v1.mIssuer, fv, ov1, false);
|
||||
else
|
||||
return STAmount(v1.name, v1.mCurrency, -fv, ov1, true);
|
||||
return STAmount(v1.name, v1.mCurrency, v1.mIssuer, -fv, ov1, true);
|
||||
}
|
||||
|
||||
STAmount STAmount::divide(const STAmount& num, const STAmount& den, const uint160& uCurrencyID, const uint160& uIssuerID)
|
||||
|
||||
13
src/FieldNames.cpp
Normal file
13
src/FieldNames.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
#include "FieldNames.h"
|
||||
|
||||
#define FIELD(name, type, index) { sf##name, #name, STI_##type, index },
|
||||
#define TYPE(name, type, index)
|
||||
|
||||
FieldName FieldNames[]=
|
||||
{
|
||||
#include "SerializeProto.h"
|
||||
};
|
||||
|
||||
#undef FIELD
|
||||
#undef TYPE
|
||||
16
src/FieldNames.h
Normal file
16
src/FieldNames.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef __FIELDNAMES__
|
||||
#define __FIELDNAMES__
|
||||
|
||||
#include "SerializedTypes.h"
|
||||
#include "SerializedObject.h"
|
||||
|
||||
struct FieldName
|
||||
{
|
||||
SOE_Field field;
|
||||
const char *fieldName;
|
||||
SerializedTypeID fieldType;
|
||||
int fieldValue;
|
||||
int fieldID;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -349,14 +349,17 @@ void LedgerEntrySet::calcRawMeta(Serializer& s)
|
||||
switch (it->second.mAction)
|
||||
{
|
||||
case taaMODIFY:
|
||||
Log(lsTRACE) << "Modified Node " << it->first;
|
||||
nType = TMNModifiedNode;
|
||||
break;
|
||||
|
||||
case taaDELETE:
|
||||
Log(lsTRACE) << "Deleted Node " << it->first;
|
||||
nType = TMNDeletedNode;
|
||||
break;
|
||||
|
||||
case taaCREATE:
|
||||
Log(lsTRACE) << "Created Node " << it->first;
|
||||
nType = TMNCreatedNode;
|
||||
break;
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ LedgerEntryFormat LedgerFormats[]=
|
||||
{ S_FIELD(Domain), STI_VL, SOE_IFFLAG, 32 },
|
||||
{ S_FIELD(PublishHash), STI_HASH256, SOE_IFFLAG, 64 },
|
||||
{ S_FIELD(PublishSize), STI_UINT32, SOE_IFFLAG, 128 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "Contract", ltCONTRACT, {
|
||||
@@ -37,7 +36,6 @@ LedgerEntryFormat LedgerFormats[]=
|
||||
{ S_FIELD(FundCode), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(RemoveCode), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(ExpireCode), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "DirectoryNode", ltDIR_NODE, {
|
||||
@@ -45,20 +43,17 @@ LedgerEntryFormat LedgerFormats[]=
|
||||
{ S_FIELD(Indexes), STI_VECTOR256, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(IndexNext), STI_UINT64, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(IndexPrevious), STI_UINT64, SOE_IFFLAG, 2 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "GeneratorMap", ltGENERATOR_MAP, {
|
||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||
{ S_FIELD(Generator), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "Nickname", ltNICKNAME, {
|
||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||
{ S_FIELD(Account), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(MinimumOffer), STI_AMOUNT, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "Offer", ltOFFER, {
|
||||
@@ -73,7 +68,6 @@ LedgerEntryFormat LedgerFormats[]=
|
||||
{ S_FIELD(LastTxnID), STI_HASH256, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(LastTxnSeq), STI_UINT32, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Expiration), STI_UINT32, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "RippleState", ltRIPPLE_STATE, {
|
||||
@@ -89,7 +83,6 @@ LedgerEntryFormat LedgerFormats[]=
|
||||
{ S_FIELD(LowQualityOut), STI_UINT32, SOE_IFFLAG, 2 },
|
||||
{ S_FIELD(HighQualityIn), STI_UINT32, SOE_IFFLAG, 4 },
|
||||
{ S_FIELD(HighQualityOut), STI_UINT32, SOE_IFFLAG, 8 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ NULL, ltINVALID }
|
||||
|
||||
127
src/SerializeProto.h
Normal file
127
src/SerializeProto.h
Normal file
@@ -0,0 +1,127 @@
|
||||
// This is not really a header file, but it can be used as one with
|
||||
// appropriate #define statements.
|
||||
|
||||
// types (common)
|
||||
TYPE("Int32", UINT32, 1)
|
||||
TYPE("Int64", UINT64, 2)
|
||||
TYPE("Hash128", HASH128, 3)
|
||||
TYPE("Hash256", HASH256, 4)
|
||||
// 5 is reserved
|
||||
TYPE("Amount", AMOUNT, 6)
|
||||
TYPE("VariableLength", VL, 7)
|
||||
TYPE("Account", ACCOUNT, 8)
|
||||
// 9-13 are reserved
|
||||
TYPE("Object", OBJECT, 14)
|
||||
TYPE("Array", ARRAY, 15)
|
||||
|
||||
// types (uncommon)
|
||||
TYPE("Int8", UINT8, 16)
|
||||
TYPE("Int16", UINT16, 17)
|
||||
TYPE("Hash160", HASH160, 18)
|
||||
TYPE("PathSet", PATHSET, 19)
|
||||
TYPE("Vector256", VECTOR256, 20)
|
||||
|
||||
|
||||
|
||||
// 8-bit integers
|
||||
FIELD(CloseResolution, UINT8, 1)
|
||||
|
||||
// 32-bit integers (common)
|
||||
FIELD(Flags, UINT32, 1)
|
||||
FIELD(SourceTag, UINT32, 2)
|
||||
FIELD(Sequence, UINT32, 3)
|
||||
FIELD(LastTxnSeq, UINT32, 4)
|
||||
FIELD(LedgerSequence, UINT32, 5)
|
||||
FIELD(CloseTime, UINT32, 6)
|
||||
FIELD(ParentCloseTime, UINT32, 7)
|
||||
FIELD(SigningTime, UINT32, 8)
|
||||
FIELD(Expiration, UINT32, 9)
|
||||
FIELD(TransferRate, UINT32, 10)
|
||||
FIELD(PublishSize, UINT32, 11)
|
||||
|
||||
// 32-bit integers (uncommon)
|
||||
FIELD(HighQualityIn, UINT32, 16)
|
||||
FIELD(HighQualityOut, UINT32, 17)
|
||||
FIELD(LowQualityIn, UINT32, 18)
|
||||
FIELD(LowQualityOut, UINT32, 19)
|
||||
FIELD(QualityIn, UINT32, 20)
|
||||
FIELD(QualityOut, UINT32, 21)
|
||||
FIELD(StampEscrow, UINT32, 22)
|
||||
FIELD(BondAmount, UINT32, 23)
|
||||
FIELD(LoadFee, UINT32, 24)
|
||||
FIELD(OfferSequence, UINT32, 25)
|
||||
|
||||
// 64-bit integers
|
||||
FIELD(IndexNext, UINT64, 1)
|
||||
FIELD(IndexPrevious, UINT64, 2)
|
||||
FIELD(BookNode, UINT64, 3)
|
||||
FIELD(OwnerNode, UINT64, 4)
|
||||
FIELD(BaseFee, UINT64, 5)
|
||||
|
||||
// 128-bit
|
||||
FIELD(EmailHash, HASH128, 2)
|
||||
|
||||
// 256-bit (common)
|
||||
FIELD(LedgerHash, HASH256, 1)
|
||||
FIELD(ParentHash, HASH256, 2)
|
||||
FIELD(TransactionHash, HASH256, 3)
|
||||
FIELD(AccountHash, HASH256, 4)
|
||||
FIELD(LastTxnID, HASH256, 5)
|
||||
FIELD(WalletLocator, HASH256, 6)
|
||||
FIELD(PublishHash, HASH256, 7)
|
||||
|
||||
// 256-bit (uncommon)
|
||||
FIELD(BookDirectory, HASH256, 16)
|
||||
FIELD(InvoiceID, HASH256, 17)
|
||||
FIELD(Nickname, HASH256, 18)
|
||||
|
||||
// currency amount (common)
|
||||
FIELD(Amount, AMOUNT, 1)
|
||||
FIELD(Balance, AMOUNT, 2)
|
||||
FIELD(LimitAmount, AMOUNT, 3)
|
||||
FIELD(TakerPays, AMOUNT, 4)
|
||||
FIELD(TakerGets, AMOUNT, 5)
|
||||
FIELD(LowLimit, AMOUNT, 6)
|
||||
FIELD(HighLimit, AMOUNT, 7)
|
||||
FIELD(SendMax, AMOUNT, 9)
|
||||
|
||||
// current amount (uncommon)
|
||||
FIELD(MinimumOffer, AMOUNT, 16)
|
||||
FIELD(RippleEscrow, AMOUNT, 17)
|
||||
|
||||
// variable length
|
||||
FIELD(PublicKey, VL, 1)
|
||||
FIELD(MessageKey, VL, 2)
|
||||
FIELD(SigningKey, VL, 3)
|
||||
FIELD(Signature, VL, 4)
|
||||
FIELD(Generator, VL, 5)
|
||||
FIELD(Domain, VL, 6)
|
||||
FIELD(FundCode, VL, 7)
|
||||
FIELD(RemoveCode, VL, 8)
|
||||
FIELD(ExpireCode, VL, 9)
|
||||
FIELD(CreateCode, VL, 10)
|
||||
|
||||
// account
|
||||
FIELD(Account, ACCOUNT, 1)
|
||||
FIELD(Owner, ACCOUNT, 2)
|
||||
FIELD(Destination, ACCOUNT, 3)
|
||||
FIELD(Issuer, ACCOUNT, 4)
|
||||
FIELD(HighID, ACCOUNT, 5)
|
||||
FIELD(LowID, ACCOUNT, 6)
|
||||
FIELD(Target, ACCOUNT, 7)
|
||||
FIELD(AuthorizedKey, ACCOUNT, 8)
|
||||
|
||||
// path set
|
||||
FIELD(Paths, PATHSET, 1)
|
||||
|
||||
// vector of 256-bit
|
||||
FIELD(Indexes, VECTOR256, 1)
|
||||
|
||||
// inner object
|
||||
// OBJECT/1 is reserved for end of object
|
||||
FIELD(MiddleTransaction, OBJECT, 2)
|
||||
FIELD(InnerTransaction, OBJECT, 3)
|
||||
|
||||
// array of objects
|
||||
// ARRAY/1 is reserved for end of array
|
||||
FIELD(SigningAccounts, ARRAY, 2)
|
||||
@@ -18,97 +18,16 @@ enum SOE_Type
|
||||
SOE_IFNFLAG = 3 // present if flag not set
|
||||
};
|
||||
|
||||
// JED: seems like there would be a better way to do this
|
||||
// maybe something that inherits from SerializedTransaction
|
||||
enum SOE_Field
|
||||
{
|
||||
sfInvalid = -1,
|
||||
sfGeneric = 0,
|
||||
|
||||
// common fields
|
||||
sfAcceptExpire,
|
||||
sfAcceptRate,
|
||||
sfAcceptStart,
|
||||
sfAccount,
|
||||
sfAmount,
|
||||
sfAuthorizedKey,
|
||||
sfBalance,
|
||||
sfBondAmount,
|
||||
sfBookDirectory,
|
||||
sfBookNode,
|
||||
sfBorrowExpire,
|
||||
sfBorrowRate,
|
||||
sfBorrowStart,
|
||||
sfBorrower,
|
||||
sfCreateCode,
|
||||
sfCloseTime,
|
||||
sfCurrency,
|
||||
sfCurrencyIn,
|
||||
sfCurrencyOut,
|
||||
sfDestination,
|
||||
sfDomain,
|
||||
sfEmailHash,
|
||||
sfExpiration,
|
||||
sfExpireCode,
|
||||
sfExtensions,
|
||||
sfFirstNode,
|
||||
sfFlags,
|
||||
sfFundCode,
|
||||
sfGenerator,
|
||||
sfGeneratorID,
|
||||
sfHash,
|
||||
sfHighID,
|
||||
sfHighLimit,
|
||||
sfHighQualityIn,
|
||||
sfHighQualityOut,
|
||||
sfIdentifier,
|
||||
sfIndexes,
|
||||
sfIndexNext,
|
||||
sfIndexPrevious,
|
||||
sfInvoiceID,
|
||||
sfIssuer,
|
||||
sfLastNode,
|
||||
sfLastTxnID,
|
||||
sfLastTxnSeq,
|
||||
sfLedgerHash,
|
||||
sfLimitAmount,
|
||||
sfLowID,
|
||||
sfLowLimit,
|
||||
sfLowQualityIn,
|
||||
sfLowQualityOut,
|
||||
sfMessageKey,
|
||||
sfMinimumOffer,
|
||||
sfNextAcceptExpire,
|
||||
sfNextAcceptRate,
|
||||
sfNextAcceptStart,
|
||||
sfNextTransitExpire,
|
||||
sfNextTransitRate,
|
||||
sfNextTransitStart,
|
||||
sfNickname,
|
||||
sfOfferSequence,
|
||||
sfOwner,
|
||||
sfOwnerNode,
|
||||
sfPaths,
|
||||
sfPubKey,
|
||||
sfPublishHash,
|
||||
sfPublishSize,
|
||||
sfQualityIn,
|
||||
sfQualityOut,
|
||||
sfRemoveCode,
|
||||
sfRippleEscrow,
|
||||
sfSendMax,
|
||||
sfSequence,
|
||||
sfSignature,
|
||||
sfSigningKey,
|
||||
sfSigningTime,
|
||||
sfSourceTag,
|
||||
sfStampEscrow,
|
||||
sfTakerGets,
|
||||
sfTakerPays,
|
||||
sfTarget,
|
||||
sfTransferRate,
|
||||
sfVersion,
|
||||
sfWalletLocator,
|
||||
#define FIELD(name, type, index) sf##name,
|
||||
#define TYPE(name, type, index)
|
||||
#include "SerializeProto.h"
|
||||
#undef FIELD
|
||||
#undef TYPE
|
||||
|
||||
// test fields
|
||||
sfTest1, sfTest2, sfTest3, sfTest4
|
||||
|
||||
@@ -15,25 +15,28 @@ enum SerializedTypeID
|
||||
STI_DONE = -1,
|
||||
STI_NOTPRESENT = 0,
|
||||
|
||||
// standard types
|
||||
STI_OBJECT = 1,
|
||||
STI_UINT8 = 2,
|
||||
STI_UINT16 = 3,
|
||||
STI_UINT32 = 4,
|
||||
STI_UINT64 = 5,
|
||||
STI_HASH128 = 6,
|
||||
STI_HASH160 = 7,
|
||||
STI_HASH256 = 8,
|
||||
STI_VL = 9,
|
||||
STI_TL = 10,
|
||||
STI_AMOUNT = 11,
|
||||
STI_PATHSET = 12,
|
||||
STI_VECTOR256 = 13,
|
||||
// common types
|
||||
STI_UINT32 = 1,
|
||||
STI_UINT64 = 2,
|
||||
STI_HASH128 = 3,
|
||||
STI_HASH256 = 4,
|
||||
STI_TL = 5,
|
||||
STI_AMOUNT = 6,
|
||||
STI_VL = 7,
|
||||
STI_ACCOUNT = 8,
|
||||
STI_OBJECT = 14,
|
||||
STI_ARRAY = 15,
|
||||
|
||||
// uncommon types
|
||||
STI_UINT8 = 16,
|
||||
STI_UINT16 = 17,
|
||||
STI_HASH160 = 18,
|
||||
STI_PATHSET = 19,
|
||||
STI_VECTOR256 = 20,
|
||||
|
||||
// high level types
|
||||
STI_ACCOUNT = 100,
|
||||
STI_TRANSACTION = 101,
|
||||
STI_LEDGERENTRY = 102
|
||||
STI_TRANSACTION = 100001,
|
||||
STI_LEDGERENTRY = 100002
|
||||
};
|
||||
|
||||
enum PathFlags
|
||||
@@ -247,9 +250,9 @@ protected:
|
||||
STAmount(const char *name, uint64 value, bool isNegative)
|
||||
: SerializedType(name), mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNegative)
|
||||
{ ; }
|
||||
STAmount(const char *n, const uint160& cur, uint64 val, int off, bool isNative, bool isNegative)
|
||||
: SerializedType(n), mCurrency(cur), mValue(val), mOffset(off), mIsNative(isNative), mIsNegative(isNegative)
|
||||
{ ; }
|
||||
STAmount(const char *n, const uint160& cur, const uint160& iss, uint64 val, int off, bool isNat, bool isNeg)
|
||||
: SerializedType(n), mCurrency(cur), mIssuer(iss), mValue(val), mOffset(off),
|
||||
mIsNative(isNat), mIsNegative(isNeg) { ; }
|
||||
|
||||
uint64 toUInt64() const;
|
||||
static uint64 muldiv(uint64, uint64, uint64);
|
||||
@@ -269,8 +272,9 @@ public:
|
||||
{ canonicalize(); }
|
||||
|
||||
// YYY This should probably require issuer too.
|
||||
STAmount(const char* n, const uint160& currency, uint64 v = 0, int off = 0, bool isNeg = false) :
|
||||
SerializedType(n), mCurrency(currency), mValue(v), mOffset(off), mIsNegative(isNeg)
|
||||
STAmount(const char* n, const uint160& currency, const uint160& issuer,
|
||||
uint64 v = 0, int off = 0, bool isNeg = false) :
|
||||
SerializedType(n), mCurrency(currency), mIssuer(issuer), mValue(v), mOffset(off), mIsNegative(isNeg)
|
||||
{ canonicalize(); }
|
||||
|
||||
STAmount(const char* n, int64 v);
|
||||
|
||||
@@ -154,6 +154,57 @@ uint256 Serializer::get256(int offset) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Serializer::addFieldID(int type, int name)
|
||||
{
|
||||
int ret = mData.size();
|
||||
assert((type > 0) && (type < 256) && (name > 0) && (name < 256));
|
||||
if (type < 16)
|
||||
{
|
||||
if (name < 16) // common type, common name
|
||||
mData.push_back(static_cast<unsigned char>((type << 4) | name));
|
||||
else
|
||||
{ // common type, uncommon name
|
||||
mData.push_back(static_cast<unsigned char>(type << 4));
|
||||
mData.push_back(static_cast<unsigned char>(name));
|
||||
}
|
||||
}
|
||||
else if (name < 16)
|
||||
{ // uncommon type, common name
|
||||
mData.push_back(static_cast<unsigned char>(name));
|
||||
mData.push_back(static_cast<unsigned char>(type));
|
||||
}
|
||||
else
|
||||
{ // uncommon type, uncommon name
|
||||
mData.push_back(static_cast<unsigned char>(0));
|
||||
mData.push_back(static_cast<unsigned char>(type));
|
||||
mData.push_back(static_cast<unsigned char>(name));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Serializer::getFieldID(int& type, int & name, int offset) const
|
||||
{
|
||||
if (!get8(type, offset))
|
||||
return false;
|
||||
name = type & 15;
|
||||
type >>= 4;
|
||||
if (type == 0)
|
||||
{ // uncommon type
|
||||
if (!get8(type, ++offset))
|
||||
return false;
|
||||
if ((type == 0) || (type < 16))
|
||||
return false;
|
||||
}
|
||||
if (name == 0)
|
||||
{ // uncommon name
|
||||
if (!get8(name, ++offset))
|
||||
return false;
|
||||
if ((name == 0) || (name < 16))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int Serializer::add8(unsigned char byte)
|
||||
{
|
||||
int ret = mData.size();
|
||||
@@ -535,6 +586,17 @@ int SerializerIterator::getBytesLeft()
|
||||
return mSerializer.size() - mPos;
|
||||
}
|
||||
|
||||
void SerializerIterator::getFieldID(int& type, int& field)
|
||||
{
|
||||
if (!mSerializer.getFieldID(type, field, mPos))
|
||||
throw std::runtime_error("invalid serializer getFieldID");
|
||||
++mPos;
|
||||
if (type >= 16)
|
||||
++mPos;
|
||||
if (field >= 16)
|
||||
++mPos;
|
||||
}
|
||||
|
||||
unsigned char SerializerIterator::get8()
|
||||
{
|
||||
int val;
|
||||
|
||||
@@ -67,6 +67,9 @@ public:
|
||||
bool getTaggedList(std::list<TaggedListItem>&, int offset, int& length) const;
|
||||
bool getTaggedList(std::vector<TaggedListItem>&, int offset, int& length) const;
|
||||
|
||||
bool getFieldID(int& type, int& name, int offset) const;
|
||||
int addFieldID(int type, int name);
|
||||
|
||||
// normal hash functions
|
||||
uint160 getRIPEMD160(int size=-1) const;
|
||||
uint256 getSHA256(int size=-1) const;
|
||||
@@ -156,6 +159,8 @@ public:
|
||||
uint160 get160();
|
||||
uint256 get256();
|
||||
|
||||
void getFieldID(int& type, int& field);
|
||||
|
||||
std::vector<unsigned char> getRaw(int iLength);
|
||||
|
||||
std::vector<unsigned char> getVL();
|
||||
|
||||
@@ -194,7 +194,7 @@ Transaction::pointer Transaction::setClaim(
|
||||
const std::vector<unsigned char>& vucSignature)
|
||||
{
|
||||
mTransaction->setITFieldVL(sfGenerator, vucGenerator);
|
||||
mTransaction->setITFieldVL(sfPubKey, vucPubKey);
|
||||
mTransaction->setITFieldVL(sfPublicKey, vucPubKey);
|
||||
mTransaction->setITFieldVL(sfSignature, vucSignature);
|
||||
|
||||
sign(naPrivateKey);
|
||||
@@ -455,7 +455,7 @@ Transaction::pointer Transaction::setPasswordSet(
|
||||
{
|
||||
mTransaction->setITFieldAccount(sfAuthorizedKey, naAuthKeyID);
|
||||
mTransaction->setITFieldVL(sfGenerator, vucGenerator);
|
||||
mTransaction->setITFieldVL(sfPubKey, vucPubKey);
|
||||
mTransaction->setITFieldVL(sfPublicKey, vucPubKey);
|
||||
mTransaction->setITFieldVL(sfSignature, vucSignature);
|
||||
|
||||
sign(naPrivateKey);
|
||||
@@ -542,7 +542,7 @@ Transaction::pointer Transaction::setWalletAdd(
|
||||
{
|
||||
mTransaction->setITFieldAmount(sfAmount, saAmount);
|
||||
mTransaction->setITFieldAccount(sfAuthorizedKey, naAuthKeyID);
|
||||
mTransaction->setITFieldVL(sfPubKey, naNewPubKey.getAccountPublic());
|
||||
mTransaction->setITFieldVL(sfPublicKey, naNewPubKey.getAccountPublic());
|
||||
mTransaction->setITFieldVL(sfSignature, vucSignature);
|
||||
|
||||
sign(naPrivateKey);
|
||||
|
||||
@@ -30,7 +30,7 @@ TER TransactionEngine::setAuthorized(const SerializedTransaction& txn, bool bMus
|
||||
//
|
||||
|
||||
std::vector<unsigned char> vucCipher = txn.getITFieldVL(sfGenerator);
|
||||
std::vector<unsigned char> vucPubKey = txn.getITFieldVL(sfPubKey);
|
||||
std::vector<unsigned char> vucPubKey = txn.getITFieldVL(sfPublicKey);
|
||||
std::vector<unsigned char> vucSignature = txn.getITFieldVL(sfSignature);
|
||||
NewcoinAddress naAccountPublic = NewcoinAddress::createAccountPublic(vucPubKey);
|
||||
|
||||
@@ -620,7 +620,7 @@ TER TransactionEngine::doWalletAdd(const SerializedTransaction& txn)
|
||||
{
|
||||
std::cerr << "WalletAdd>" << std::endl;
|
||||
|
||||
const std::vector<unsigned char> vucPubKey = txn.getITFieldVL(sfPubKey);
|
||||
const std::vector<unsigned char> vucPubKey = txn.getITFieldVL(sfPublicKey);
|
||||
const std::vector<unsigned char> vucSignature = txn.getITFieldVL(sfSignature);
|
||||
const uint160 uAuthKeyID = txn.getITFieldAccount(sfAuthorizedKey);
|
||||
const NewcoinAddress naMasterPubKey = NewcoinAddress::createAccountPublic(vucPubKey);
|
||||
|
||||
@@ -15,16 +15,14 @@ TransactionFormat InnerTxnFormats[]=
|
||||
{ S_FIELD(TransferRate), STI_UINT32, SOE_IFFLAG, 32 },
|
||||
{ S_FIELD(PublishHash), STI_HASH256, SOE_IFFLAG, 64 },
|
||||
{ S_FIELD(PublishSize), STI_UINT32, SOE_IFFLAG, 128 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "Claim", ttCLAIM, {
|
||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||
{ S_FIELD(Generator), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(PubKey), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(PublicKey), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Signature), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "CreditSet", ttCREDIT_SET, {
|
||||
@@ -34,7 +32,6 @@ TransactionFormat InnerTxnFormats[]=
|
||||
{ S_FIELD(LimitAmount), STI_AMOUNT, SOE_IFFLAG, 2 },
|
||||
{ S_FIELD(QualityIn), STI_UINT32, SOE_IFFLAG, 4 },
|
||||
{ S_FIELD(QualityOut), STI_UINT32, SOE_IFFLAG, 8 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
/*
|
||||
@@ -45,7 +42,6 @@ TransactionFormat InnerTxnFormats[]=
|
||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(Destination), STI_ACCOUNT, SOE_IFFLAG, 2 },
|
||||
{ S_FIELD(Identifier), STI_VL, SOE_IFFLAG, 4 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
*/
|
||||
@@ -55,7 +51,6 @@ TransactionFormat InnerTxnFormats[]=
|
||||
{ S_FIELD(MinimumOffer), STI_AMOUNT, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(Signature), STI_VL, SOE_IFFLAG, 2 },
|
||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 4 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "OfferCreate", ttOFFER_CREATE, {
|
||||
@@ -64,31 +59,27 @@ TransactionFormat InnerTxnFormats[]=
|
||||
{ S_FIELD(TakerGets), STI_AMOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(Expiration), STI_UINT32, SOE_IFFLAG, 2 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "OfferCancel", ttOFFER_CANCEL, {
|
||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||
{ S_FIELD(OfferSequence), STI_UINT32, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "PasswordFund", ttPASSWORD_FUND, {
|
||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||
{ S_FIELD(Destination), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "PasswordSet", ttPASSWORD_SET, {
|
||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||
{ S_FIELD(AuthorizedKey), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Generator), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(PubKey), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(PublicKey), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Signature), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "Payment", ttPAYMENT, {
|
||||
@@ -99,17 +90,15 @@ TransactionFormat InnerTxnFormats[]=
|
||||
{ S_FIELD(Paths), STI_PATHSET, SOE_IFFLAG, 2 },
|
||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 4 },
|
||||
{ S_FIELD(InvoiceID), STI_HASH256, SOE_IFFLAG, 8 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "WalletAdd", ttWALLET_ADD, {
|
||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||
{ S_FIELD(Amount), STI_AMOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(AuthorizedKey), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(PubKey), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(PublicKey), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Signature), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "Contract", ttCONTRACT, {
|
||||
@@ -122,13 +111,11 @@ TransactionFormat InnerTxnFormats[]=
|
||||
{ S_FIELD(FundCode), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(RemoveCode), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(ExpireCode), STI_VL, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ "Contract", ttCONTRACT_REMOVE, {
|
||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||
{ S_FIELD(Target), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
{ NULL, ttINVALID }
|
||||
|
||||
Reference in New Issue
Block a user