From 0903f5e433eea42fab8584ae923a28ba2d690022 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 24 Apr 2012 04:42:49 -0700 Subject: [PATCH] Be clear about what's an account and what's a public key. --- src/SerializedTransaction.cpp | 23 ++++++++++++----------- src/SerializedTransaction.h | 8 ++++---- src/Transaction.cpp | 14 +++++++------- src/TransactionEngine.cpp | 2 +- src/TransactionFormats.h | 2 +- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/SerializedTransaction.cpp b/src/SerializedTransaction.cpp index 205ac767e2..49c45f1e86 100644 --- a/src/SerializedTransaction.cpp +++ b/src/SerializedTransaction.cpp @@ -7,7 +7,7 @@ SerializedTransaction::SerializedTransaction(TransactionType type) : mType(type) if (mFormat == NULL) throw std::runtime_error("invalid transaction type"); mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic)); - mMiddleTxn.giveObject(new STVariableLength("SigningAccount")); + mMiddleTxn.giveObject(new STVariableLength("SigningPubKey")); mMiddleTxn.giveObject(new STUInt32("Sequence")); mMiddleTxn.giveObject(new STUInt8("Type", static_cast(type))); mMiddleTxn.giveObject(new STUInt64("Fee")); @@ -28,7 +28,7 @@ SerializedTransaction::SerializedTransaction(SerializerIterator& sit, int length throw std::runtime_error("Transaction has invalid magic"); mMiddleTxn.giveObject(new STUInt32("Magic", TransactionMagic)); - mMiddleTxn.giveObject(new STVariableLength("SigningAccount", sit.getVL())); + mMiddleTxn.giveObject(new STVariableLength("SigningPubKey", sit.getVL())); mMiddleTxn.giveObject(new STUInt32("Sequence", sit.get32())); mType = static_cast(sit.get32()); @@ -44,7 +44,7 @@ SerializedTransaction::SerializedTransaction(SerializerIterator& sit, int length void SerializedTransaction::updateSourceAccount() { NewcoinAddress a; - a.setAccountPublic(peekRawSigningAccount()); + a.setAccountPublic(peekSigningPubKey()); mSourceAccount.setAccountID(a.getAccountID()); } @@ -194,35 +194,36 @@ void SerializedTransaction::setSequence(uint32 seq) v->setValue(seq); } -std::vector SerializedTransaction::getRawSigningAccount() const +std::vector SerializedTransaction::getSigningPubKey() const { const STVariableLength* v = - dynamic_cast(mMiddleTxn.peekAtPIndex(TransactionISigningAccount)); + dynamic_cast(mMiddleTxn.peekAtPIndex(TransactionISigningPubKey)); if (!v) throw std::runtime_error("corrupt transaction"); return v->getValue(); } -const std::vector& SerializedTransaction::peekRawSigningAccount() const +const std::vector& SerializedTransaction::peekSigningPubKey() const { const STVariableLength* v= - dynamic_cast(mMiddleTxn.peekAtPIndex(TransactionISigningAccount)); + dynamic_cast(mMiddleTxn.peekAtPIndex(TransactionISigningPubKey)); if (!v) throw std::runtime_error("corrupt transaction"); return v->peekValue(); } -std::vector& SerializedTransaction::peekRawSigningAccount() +std::vector& SerializedTransaction::peekSigningPubKey() { - STVariableLength* v = dynamic_cast(mMiddleTxn.getPIndex(TransactionISigningAccount)); + STVariableLength* v = dynamic_cast(mMiddleTxn.getPIndex(TransactionISigningPubKey)); if (!v) throw std::runtime_error("corrupt transaction"); return v->peekValue(); } -void SerializedTransaction::setSigningAccount(const std::vector& s) +const NewcoinAddress& SerializedTransaction::setSigningPubKey(const std::vector& s) { - STVariableLength* v = dynamic_cast(mMiddleTxn.getPIndex(TransactionISigningAccount)); + STVariableLength* v = dynamic_cast(mMiddleTxn.getPIndex(TransactionISigningPubKey)); if (!v) throw std::runtime_error("corrupt transaction"); v->setValue(s); updateSourceAccount(); + return mSourceAccount; } uint160 SerializedTransaction::getITFieldAccount(SOE_Field field) const diff --git a/src/SerializedTransaction.h b/src/SerializedTransaction.h index 00c221bef0..fe6609518b 100644 --- a/src/SerializedTransaction.h +++ b/src/SerializedTransaction.h @@ -52,10 +52,10 @@ public: void setTransactionFee(uint64); const NewcoinAddress& getSourceAccount() const { return mSourceAccount; } - std::vector getRawSigningAccount() const; - const std::vector& peekRawSigningAccount() const; - std::vector& peekRawSigningAccount(); - void setSigningAccount(const std::vector& s); + std::vector getSigningPubKey() const; + const std::vector& peekSigningPubKey() const; + std::vector& peekSigningPubKey(); + const NewcoinAddress& setSigningPubKey(const std::vector& s); std::string getTransactionType() const { return mFormat->t_name; } // inner transaction functions diff --git a/src/Transaction.cpp b/src/Transaction.cpp index 9066391864..0097d736ea 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -23,7 +23,7 @@ Transaction::Transaction(LocalAccount::pointer fromLocalAccount, const NewcoinAd mFromPubKey = fromLocalAccount->getPublicKey(); assert(mFromPubKey); - mTransaction->setSigningAccount(mFromPubKey->GetPubKey()); + mTransaction->setSigningPubKey(mFromPubKey->GetPubKey()); mTransaction->setSequence(accountState->getSeq()); assert(mTransaction->getSequence() != 0); @@ -59,7 +59,7 @@ Transaction::Transaction(SerializedTransaction::pointer sit, bool validate) : mS try { - pubKey = mTransaction->getRawSigningAccount(); + pubKey = mTransaction->peekSigningPubKey(); mTransactionID = mTransaction->getTransactionID(); mAccountFrom = mTransaction->getSourceAccount(); } @@ -109,17 +109,17 @@ Transaction::Transaction(const NewcoinAddress& fromID, const NewcoinAddress& toI uint32 ident, const std::vector& signature, uint32 ledgerSeq, TransStatus st) : mAccountFrom(fromID), mFromPubKey(pubKey), mInLedger(ledgerSeq), mStatus(st) { - mTransaction=boost::make_shared(ttMAKE_PAYMENT); + mTransaction = boost::make_shared(ttMAKE_PAYMENT); mTransaction->setSignature(signature); mTransaction->setTransactionFee(fee); - mTransaction->setSigningAccount(pubKey->GetPubKey()); + mTransaction->setSigningPubKey(pubKey->GetPubKey()); mTransaction->setSequence(fromSeq); - if(fromLedger!=0) + if (fromLedger != 0) { mTransaction->makeITFieldPresent(sfTargetLedger); mTransaction->setITFieldU32(sfTargetLedger, fromLedger); } - if(ident!=0) + if (ident != 0) { mTransaction->makeITFieldPresent(sfSourceTag); mTransaction->setITFieldU32(sfSourceTag, ident); @@ -131,7 +131,7 @@ Transaction::Transaction(const NewcoinAddress& fromID, const NewcoinAddress& toI bool Transaction::sign(LocalAccount::pointer fromLocalAccount) { - CKey::pointer privateKey=fromLocalAccount->getPrivateKey(); + CKey::pointer privateKey = fromLocalAccount->getPrivateKey(); if(!privateKey) { #ifdef DEBUG diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index 38624d4045..52a3a1abc2 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -11,7 +11,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran // extract signing key CKey acctKey; - if (!acctKey.SetPubKey(txn.getRawSigningAccount())) return terINVALID; + if (!acctKey.SetPubKey(txn.peekSigningPubKey())) return terINVALID; // check signature if (!txn.checkSign(acctKey)) return terINVALID; diff --git a/src/TransactionFormats.h b/src/TransactionFormats.h index 08887de169..eb5efaf180 100644 --- a/src/TransactionFormats.h +++ b/src/TransactionFormats.h @@ -20,7 +20,7 @@ struct TransactionFormat const int32 TransactionMagic=0x54584E00; -const int TransactionIVersion=0, TransactionISigningAccount=1, TransactionISequence=2; +const int TransactionIVersion=0, TransactionISigningPubKey=1, TransactionISequence=2; const int TransactionIType=3, TransactionIFee=4; const int TransactionMinLen=32;