From b72cdbac662fcf7e09a88111c1ec3c6f58c95fc1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 26 Mar 2012 18:04:36 -0700 Subject: [PATCH] Cleanups. Move the sequence number into the middle transaction. --- src/SerializedObject.h | 2 +- src/SerializedTransaction.cpp | 24 ++++++++++++++++++++---- src/SerializedTransaction.h | 16 ++++++++-------- src/TransactionFormats.cpp | 3 --- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/SerializedObject.h b/src/SerializedObject.h index 0dacd15f3e..289fd4f310 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -18,7 +18,7 @@ enum SOE_Field sfGeneric=0, // common fields - sfFlags, sfSequence, sfExtensions, sfTargetLedger, sfSourceTag, sfIdentifier, + sfFlags, sfExtensions, sfTargetLedger, sfSourceTag, sfIdentifier, sfDestination, sfTarget, sfAmount, sfCurrency, sfAmountIn, sfAmountOut, sfCurrencyIn, sfCurrencyOut, sfInvoiceID, diff --git a/src/SerializedTransaction.cpp b/src/SerializedTransaction.cpp index c848efeee2..df57ded23c 100644 --- a/src/SerializedTransaction.cpp +++ b/src/SerializedTransaction.cpp @@ -8,6 +8,7 @@ SerializedTransaction::SerializedTransaction(TransactionType type) mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic)); mMiddleTxn.giveObject(new STVariableLength("SigningAccount")); + mMiddleTxn.giveObject(new STUInt32("Sequence")); mMiddleTxn.giveObject(new STUInt8("Type", static_cast(type))); mMiddleTxn.giveObject(new STUInt64("Fee")); @@ -28,6 +29,7 @@ SerializedTransaction::SerializedTransaction(SerializerIterator& sit, int length mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic)); mMiddleTxn.giveObject(new STVariableLength("SigningAccount", sit.getVL())); + mMiddleTxn.giveObject(new STUInt32("Sequence", sit.get32())); int type=sit.get32(); mMiddleTxn.giveObject(new STUInt32("Type", type)); @@ -104,32 +106,46 @@ void SerializedTransaction::setSignature(const std::vector& sig) uint32 SerializedTransaction::getVersion() const { - const STUInt32* v=dynamic_cast(mMiddleTxn.peekAtPIndex(0)); + const STUInt32* v=dynamic_cast(mMiddleTxn.peekAtPIndex(TransactionIVersion)); if(!v) throw(std::runtime_error("corrupt transaction")); return v->getValue(); } void SerializedTransaction::setVersion(uint32 ver) { - STUInt32* v=dynamic_cast(mMiddleTxn.getPIndex(0)); + STUInt32* v=dynamic_cast(mMiddleTxn.getPIndex(TransactionIVersion)); if(!v) throw(std::runtime_error("corrupt transaction")); v->setValue(ver); } uint64 SerializedTransaction::getTransactionFee() const { - const STUInt64* v=dynamic_cast(mMiddleTxn.peekAtPIndex(3)); + const STUInt64* v=dynamic_cast(mMiddleTxn.peekAtPIndex(TransactionIFee)); if(!v) throw(std::runtime_error("corrupt transaction")); return v->getValue(); } void SerializedTransaction::setTransactionFee(uint64 fee) { - STUInt64* v=dynamic_cast(mMiddleTxn.getPIndex(3)); + STUInt64* v=dynamic_cast(mMiddleTxn.getPIndex(TransactionIFee)); if(!v) throw(std::runtime_error("corrupt transaction")); v->setValue(fee); } +uint32 SerializedTransaction::getSequence() const +{ + const STUInt32* v=dynamic_cast(mMiddleTxn.peekAtPIndex(TransactionISequence)); + if(!v) throw(std::runtime_error("corrupt transaction")); + return v->getValue(); +} + +void SerializedTransaction::setSequence(uint32 seq) +{ + STUInt32* v=dynamic_cast(mMiddleTxn.getPIndex(TransactionISequence)); + if(!v) throw(std::runtime_error("corrupt transaction")); + v->setValue(seq); +} + int SerializedTransaction::getITFieldIndex(SOE_Field field) const { return mInnerTxn.getFieldIndex(field); diff --git a/src/SerializedTransaction.h b/src/SerializedTransaction.h index 973909e1d5..7b040de4dc 100644 --- a/src/SerializedTransaction.h +++ b/src/SerializedTransaction.h @@ -70,15 +70,15 @@ public: uint256 getITFieldH256(SOE_Field field) const { return mInnerTxn.getValueFieldH256(field); } std::vector getITFieldVL(SOE_Field field) const { return mInnerTxn.getValueFieldVL(field); } std::vector getITFieldTL(SOE_Field field) const { return mInnerTxn.getValueFieldTL(field); } - 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 SetITFieldU32(SOE_Field field, uint32 v) { return mInnerTxn.setValueFieldU32(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 SetITFieldH256(SOE_Field field, const uint256& v) { return mInnerTxn.setValueFieldH256(field, v); } - void SetITFieldVL(SOE_Field field, const std::vector& 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 setITFieldU32(SOE_Field field, uint32 v) { return mInnerTxn.setValueFieldU32(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 setITFieldH256(SOE_Field field, const uint256& v) { return mInnerTxn.setValueFieldH256(field, v); } + void setITFieldVL(SOE_Field field, const std::vector& v) { return mInnerTxn.setValueFieldVL(field, v); } - void SetITFieldTL(SOE_Field field, const std::vector& v) + void setITFieldTL(SOE_Field field, const std::vector& v) { return mInnerTxn.setValueFieldTL(field, v); } // optional field functions diff --git a/src/TransactionFormats.cpp b/src/TransactionFormats.cpp index 272636b349..455b3a9e46 100644 --- a/src/TransactionFormats.cpp +++ b/src/TransactionFormats.cpp @@ -7,7 +7,6 @@ TransactionFormat InnerTxnFormats[]= { { "MakePayment", ttMAKE_PAYMENT, { { 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(Amount), STI_UINT64, SOE_REQUIRED, 0 }, { S_FIELD(Currency), STI_HASH160, SOE_IFFLAG, 1 }, @@ -19,7 +18,6 @@ TransactionFormat InnerTxnFormats[]= }, { "Invoice", ttINVOICE, { { 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(Amount), STI_UINT64, SOE_REQUIRED, 0 }, { S_FIELD(Currency), STI_HASH160, SOE_IFFLAG, 1 }, @@ -32,7 +30,6 @@ TransactionFormat InnerTxnFormats[]= }, { "Offer", ttEXCHANGE_OFFER, { { 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(CurrencyIn), STI_HASH160, SOE_IFFLAG, 2 }, { S_FIELD(AmountOut), STI_UINT64, SOE_REQUIRED, 0 },