diff --git a/Account.h b/Account.h index 260fb6361f..ee4763c773 100644 --- a/Account.h +++ b/Account.h @@ -1,19 +1,24 @@ #ifndef __ACCOUNT__ #define __ACCOUNT__ +#include +#include "key.h" #include "uint256.h" class Account { +public: + typedef boost::shared_ptr pointer; + private: uint160 mAddress; CKey pubKey; public: - bool CheckSignRaw(const std::vector &toSign, + bool checkSignRaw(const std::vector &toSign, const std::vector &signature) const; - const uint160& GetAddress(void) const { return mAddress; } + const uint160& getAddress(void) const { return mAddress; } CKey& peekPubKey() { return pubKey; } }; diff --git a/Transaction.cpp b/Transaction.cpp index d25d8c76b4..844c319935 100644 --- a/Transaction.cpp +++ b/Transaction.cpp @@ -16,41 +16,44 @@ Transaction::Transaction(TransStatus status, LocalAccount& fromLocalAccount, Acc mAccountTo(toAccount), mAmount(amount), mFromAccountSeq(fromSeq), mSourceLedger(ledger), mIdent(ident), mInLedger(0), mStatus(NEW) { - assert(fromAccount.GetAddress()==fromLocalAccount.mAddress); + assert(fromAccount.getAddress()==fromLocalAccount.mAddress); assert(fromLocalAccount.mAmount>=amount); assert((fromSeq+1)==fromLocalAccount.mSeqNum); - mAccountFrom=fromAccount.GetAddress(); - sign(fromLocalAccount, fromAccount); + mAccountFrom=fromAccount.getAddress(); + sign(fromLocalAccount); } -bool Transaction::sign(LocalAccount& fromLocalAccount, Account& fromAccount) +bool Transaction::sign(LocalAccount& fromLocalAccount) { if( (mAmount==0) || (mSourceLedger==0) || (mAccountTo==0) ) return false; - if((mAccountFrom!=fromLocalAccount.mAddress)||(mAccountFrom!=fromAccount.GetAddress())) + if(mpAccountFrom == Account::pointer()) + return false; + if((mpAccountFrom->getAddress()!=fromLocalAccount.mAddress) || (mAccountFrom!=mpAccountFrom->getAddress())) return false; - Serializer::pointer signBuf(getRawUnsigned(fromAccount)); + Serializer::pointer signBuf(getRawUnsigned()); if(!signBuf->makeSignature(mSignature, fromLocalAccount.peekPrivKey())) return false; signBuf->addRaw(mSignature); mTransactionID=signBuf->getSHA512Half(); } -bool Transaction::checkSign(Account& fromAccount) const +bool Transaction::checkSign() const { - if(mAccountFrom!=fromAccount.GetAddress()) return false; + if(mpAccountFrom == Account::pointer()) return false; + if(mpAccountFrom->getAddress()!=mAccountFrom) return false; - Serializer::pointer toSign(getRawUnsigned(fromAccount)); - return toSign->checkSignature(mSignature, fromAccount.peekPubKey()); + Serializer::pointer toSign(getRawUnsigned()); + return toSign->checkSignature(mSignature, mpAccountFrom->peekPubKey()); } -Serializer::pointer Transaction::getRawUnsigned(Account& fromAccount) const +Serializer::pointer Transaction::getRawUnsigned() const { Serializer::pointer ret(new Serializer(104)); ret->add32(0x54584e00u); - ret->addRaw(fromAccount.peekPubKey().GetPubKey()); + ret->addRaw(mpAccountFrom->peekPubKey().GetPubKey()); ret->add64(mAmount); ret->add32(mFromAccountSeq); ret->add32(mInLedger); @@ -58,7 +61,15 @@ Serializer::pointer Transaction::getRawUnsigned(Account& fromAccount) const return ret; } -void Transaction::updateID(Account& fromAccount) +Serializer::pointer Transaction::getRawSigned() const { - mTransactionID=getRawSigned(fromAccount)->getSHA512Half(); + Serializer::pointer ret(getRawUnsigned()); + ret->addRaw(mSignature); + return ret; +} + +void Transaction::updateID() +{ + if( (mpAccountFrom!=Account::pointer()) && (mpAccountFrom->getAddress()==mAccountFrom)) + mTransactionID=getRawSigned()->getSHA512Half(); } diff --git a/Transaction.h b/Transaction.h index e717cb81a8..b41079fd75 100644 --- a/Transaction.h +++ b/Transaction.h @@ -1,13 +1,15 @@ #ifndef __TRANSACTION__ #define __TRANSACTION__ +#include +#include +#include + #include "uint256.h" #include "newcoin.pb.h" #include "Hanko.h" #include "Serializer.h" -#include -#include -#include +#include "Account.h" /* We could have made something that inherited from the protobuf transaction but this seemed simpler @@ -41,6 +43,8 @@ private: uint32 mInLedger; TransStatus mStatus; + Account::pointer mpAccountFrom; + public: Transaction(); Transaction(const std::vector rawTransaction); @@ -48,12 +52,14 @@ public: Transaction(TransStatus Status, LocalAccount& fromLocal, Account& from, uint32 fromSeq, const uint160& to, uint64 amount, uint32 ident, uint32 ledger); - bool sign(LocalAccount& fromLocalAccount, Account& fromAccount); - bool checkSign(Account& fromAccount) const; - void updateID(Account& fromAccount); + void setFromAccountPointer(Account::pointer af) { mpAccountFrom=af; } - Serializer::pointer getRawUnsigned(Account& from) const; - Serializer::pointer getRawSigned(Account& from) const; + bool sign(LocalAccount& fromLocalAccount); + bool checkSign() const; + void updateID(); + + Serializer::pointer getRawUnsigned() const; + Serializer::pointer getRawSigned() const; const uint256& getID() const { return mTransactionID; } const uint160& getFromAccount() const { return mAccountFrom; }