Cleanups. Move the sequence number into the middle transaction.

This commit is contained in:
JoelKatz
2012-03-26 18:04:36 -07:00
parent 649e1fda37
commit b72cdbac66
4 changed files with 29 additions and 16 deletions

View File

@@ -18,7 +18,7 @@ enum SOE_Field
sfGeneric=0, sfGeneric=0,
// common fields // common fields
sfFlags, sfSequence, sfExtensions, sfTargetLedger, sfSourceTag, sfIdentifier, sfFlags, sfExtensions, sfTargetLedger, sfSourceTag, sfIdentifier,
sfDestination, sfTarget, sfAmount, sfCurrency, sfDestination, sfTarget, sfAmount, sfCurrency,
sfAmountIn, sfAmountOut, sfCurrencyIn, sfCurrencyOut, sfAmountIn, sfAmountOut, sfCurrencyIn, sfCurrencyOut,
sfInvoiceID, sfInvoiceID,

View File

@@ -8,6 +8,7 @@ SerializedTransaction::SerializedTransaction(TransactionType type)
mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic)); mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic));
mMiddleTxn.giveObject(new STVariableLength("SigningAccount")); mMiddleTxn.giveObject(new STVariableLength("SigningAccount"));
mMiddleTxn.giveObject(new STUInt32("Sequence"));
mMiddleTxn.giveObject(new STUInt8("Type", static_cast<unsigned char>(type))); mMiddleTxn.giveObject(new STUInt8("Type", static_cast<unsigned char>(type)));
mMiddleTxn.giveObject(new STUInt64("Fee")); mMiddleTxn.giveObject(new STUInt64("Fee"));
@@ -28,6 +29,7 @@ SerializedTransaction::SerializedTransaction(SerializerIterator& sit, int length
mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic)); mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic));
mMiddleTxn.giveObject(new STVariableLength("SigningAccount", sit.getVL())); mMiddleTxn.giveObject(new STVariableLength("SigningAccount", sit.getVL()));
mMiddleTxn.giveObject(new STUInt32("Sequence", sit.get32()));
int type=sit.get32(); int type=sit.get32();
mMiddleTxn.giveObject(new STUInt32("Type", type)); mMiddleTxn.giveObject(new STUInt32("Type", type));
@@ -104,32 +106,46 @@ void SerializedTransaction::setSignature(const std::vector<unsigned char>& sig)
uint32 SerializedTransaction::getVersion() const uint32 SerializedTransaction::getVersion() const
{ {
const STUInt32* v=dynamic_cast<const STUInt32*>(mMiddleTxn.peekAtPIndex(0)); const STUInt32* v=dynamic_cast<const STUInt32*>(mMiddleTxn.peekAtPIndex(TransactionIVersion));
if(!v) throw(std::runtime_error("corrupt transaction")); if(!v) throw(std::runtime_error("corrupt transaction"));
return v->getValue(); return v->getValue();
} }
void SerializedTransaction::setVersion(uint32 ver) void SerializedTransaction::setVersion(uint32 ver)
{ {
STUInt32* v=dynamic_cast<STUInt32*>(mMiddleTxn.getPIndex(0)); STUInt32* v=dynamic_cast<STUInt32*>(mMiddleTxn.getPIndex(TransactionIVersion));
if(!v) throw(std::runtime_error("corrupt transaction")); if(!v) throw(std::runtime_error("corrupt transaction"));
v->setValue(ver); v->setValue(ver);
} }
uint64 SerializedTransaction::getTransactionFee() const uint64 SerializedTransaction::getTransactionFee() const
{ {
const STUInt64* v=dynamic_cast<const STUInt64*>(mMiddleTxn.peekAtPIndex(3)); const STUInt64* v=dynamic_cast<const STUInt64*>(mMiddleTxn.peekAtPIndex(TransactionIFee));
if(!v) throw(std::runtime_error("corrupt transaction")); if(!v) throw(std::runtime_error("corrupt transaction"));
return v->getValue(); return v->getValue();
} }
void SerializedTransaction::setTransactionFee(uint64 fee) void SerializedTransaction::setTransactionFee(uint64 fee)
{ {
STUInt64* v=dynamic_cast<STUInt64*>(mMiddleTxn.getPIndex(3)); STUInt64* v=dynamic_cast<STUInt64*>(mMiddleTxn.getPIndex(TransactionIFee));
if(!v) throw(std::runtime_error("corrupt transaction")); if(!v) throw(std::runtime_error("corrupt transaction"));
v->setValue(fee); v->setValue(fee);
} }
uint32 SerializedTransaction::getSequence() const
{
const STUInt32* v=dynamic_cast<const STUInt32*>(mMiddleTxn.peekAtPIndex(TransactionISequence));
if(!v) throw(std::runtime_error("corrupt transaction"));
return v->getValue();
}
void SerializedTransaction::setSequence(uint32 seq)
{
STUInt32* v=dynamic_cast<STUInt32*>(mMiddleTxn.getPIndex(TransactionISequence));
if(!v) throw(std::runtime_error("corrupt transaction"));
v->setValue(seq);
}
int SerializedTransaction::getITFieldIndex(SOE_Field field) const int SerializedTransaction::getITFieldIndex(SOE_Field field) const
{ {
return mInnerTxn.getFieldIndex(field); return mInnerTxn.getFieldIndex(field);

View File

@@ -70,15 +70,15 @@ public:
uint256 getITFieldH256(SOE_Field field) const { return mInnerTxn.getValueFieldH256(field); } uint256 getITFieldH256(SOE_Field field) const { return mInnerTxn.getValueFieldH256(field); }
std::vector<unsigned char> getITFieldVL(SOE_Field field) const { return mInnerTxn.getValueFieldVL(field); } std::vector<unsigned char> getITFieldVL(SOE_Field field) const { return mInnerTxn.getValueFieldVL(field); }
std::vector<TaggedListItem> getITFieldTL(SOE_Field field) const { return mInnerTxn.getValueFieldTL(field); } std::vector<TaggedListItem> getITFieldTL(SOE_Field field) const { return mInnerTxn.getValueFieldTL(field); }
void SetITFieldU8(SOE_Field field, unsigned char v) { return mInnerTxn.setValueFieldU8(field, v); } void setITFieldU8(SOE_Field field, unsigned char v) { return mInnerTxn.setValueFieldU8(field, v); }
void SetITFieldU16(SOE_Field field, uint16 v) { return mInnerTxn.setValueFieldU16(field, v); } void setITFieldU16(SOE_Field field, uint16 v) { return mInnerTxn.setValueFieldU16(field, v); }
void SetITFieldU32(SOE_Field field, uint32 v) { return mInnerTxn.setValueFieldU32(field, v); } void setITFieldU32(SOE_Field field, uint32 v) { return mInnerTxn.setValueFieldU32(field, v); }
void SetITFieldU64(SOE_Field field, uint32 v) { return mInnerTxn.setValueFieldU64(field, v); } void setITFieldU64(SOE_Field field, uint32 v) { return mInnerTxn.setValueFieldU64(field, v); }
void SetITFieldH160(SOE_Field field, const uint160& v) { return mInnerTxn.setValueFieldH160(field, v); } void setITFieldH160(SOE_Field field, const uint160& v) { return mInnerTxn.setValueFieldH160(field, v); }
void SetITFieldH256(SOE_Field field, const uint256& v) { return mInnerTxn.setValueFieldH256(field, v); } void setITFieldH256(SOE_Field field, const uint256& v) { return mInnerTxn.setValueFieldH256(field, v); }
void SetITFieldVL(SOE_Field field, const std::vector<unsigned char>& v) void setITFieldVL(SOE_Field field, const std::vector<unsigned char>& v)
{ return mInnerTxn.setValueFieldVL(field, v); } { return mInnerTxn.setValueFieldVL(field, v); }
void SetITFieldTL(SOE_Field field, const std::vector<TaggedListItem>& v) void setITFieldTL(SOE_Field field, const std::vector<TaggedListItem>& v)
{ return mInnerTxn.setValueFieldTL(field, v); } { return mInnerTxn.setValueFieldTL(field, v); }
// optional field functions // optional field functions

View File

@@ -7,7 +7,6 @@ TransactionFormat InnerTxnFormats[]=
{ {
{ "MakePayment", ttMAKE_PAYMENT, { { "MakePayment", ttMAKE_PAYMENT, {
{ S_FIELD(Flags), STI_UINT16, SOE_FLAGS, 0 }, { S_FIELD(Flags), STI_UINT16, SOE_FLAGS, 0 },
{ S_FIELD(Sequence), STI_UINT32, SOE_REQUIRED, 0 },
{ S_FIELD(Destination), STI_ACCOUNT, SOE_REQUIRED, 0 }, { S_FIELD(Destination), STI_ACCOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(Amount), STI_UINT64, SOE_REQUIRED, 0 }, { S_FIELD(Amount), STI_UINT64, SOE_REQUIRED, 0 },
{ S_FIELD(Currency), STI_HASH160, SOE_IFFLAG, 1 }, { S_FIELD(Currency), STI_HASH160, SOE_IFFLAG, 1 },
@@ -19,7 +18,6 @@ TransactionFormat InnerTxnFormats[]=
}, },
{ "Invoice", ttINVOICE, { { "Invoice", ttINVOICE, {
{ S_FIELD(Flags), STI_UINT16, SOE_FLAGS, 0 }, { S_FIELD(Flags), STI_UINT16, SOE_FLAGS, 0 },
{ S_FIELD(Sequence), STI_UINT32, SOE_REQUIRED, 0 },
{ S_FIELD(Target), STI_ACCOUNT, SOE_REQUIRED, 0 }, { S_FIELD(Target), STI_ACCOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(Amount), STI_UINT64, SOE_REQUIRED, 0 }, { S_FIELD(Amount), STI_UINT64, SOE_REQUIRED, 0 },
{ S_FIELD(Currency), STI_HASH160, SOE_IFFLAG, 1 }, { S_FIELD(Currency), STI_HASH160, SOE_IFFLAG, 1 },
@@ -32,7 +30,6 @@ TransactionFormat InnerTxnFormats[]=
}, },
{ "Offer", ttEXCHANGE_OFFER, { { "Offer", ttEXCHANGE_OFFER, {
{ S_FIELD(Flags), STI_UINT16, SOE_FLAGS, 0 }, { S_FIELD(Flags), STI_UINT16, SOE_FLAGS, 0 },
{ S_FIELD(Sequence), STI_UINT32, SOE_REQUIRED, 0 },
{ S_FIELD(AmountIn), STI_UINT64, SOE_REQUIRED, 0 }, { S_FIELD(AmountIn), STI_UINT64, SOE_REQUIRED, 0 },
{ S_FIELD(CurrencyIn), STI_HASH160, SOE_IFFLAG, 2 }, { S_FIELD(CurrencyIn), STI_HASH160, SOE_IFFLAG, 2 },
{ S_FIELD(AmountOut), STI_UINT64, SOE_REQUIRED, 0 }, { S_FIELD(AmountOut), STI_UINT64, SOE_REQUIRED, 0 },