Starting tying into serializer code.

This commit is contained in:
JoelKatz
2011-11-17 22:05:13 -08:00
parent 8ae29a3f06
commit b7046ae6f3
2 changed files with 26 additions and 25 deletions

View File

@@ -21,36 +21,36 @@ Transaction::Transaction(TransStatus status, LocalAccount &fromLocalAccount, con
assert((fromSeq+1)==fromLocalAccount.mSeqNum); assert((fromSeq+1)==fromLocalAccount.mSeqNum);
mAccountFrom=fromAccount.GetAddress(); mAccountFrom=fromAccount.GetAddress();
Sign(fromLocalAccount, fromAccount); sign(fromLocalAccount, fromAccount);
} }
bool Transaction::Sign(LocalAccount &fromLocalAccount, const Account &fromAccount) bool Transaction::sign(LocalAccount &fromLocalAccount, const Account &fromAccount)
{ {
if( (mAmount==0) || (mSourceLedger==0) || (mAccountTo==0) ) if( (mAmount==0) || (mSourceLedger==0) || (mAccountTo==0) )
return false; return false;
if((mAccountFrom!=fromLocalAccount.mAddress)||(mAccountFrom!=fromAccount.GetAddress())) if((mAccountFrom!=fromLocalAccount.mAddress)||(mAccountFrom!=fromAccount.GetAddress()))
return false; return false;
UpdateHash(); updateHash();
std::vector<unsigned char> toSign, Signature; std::vector<unsigned char> toSign, Signature;
if(!GetRawUnsigned(toSign, fromAccount)) return false; if(!getRawUnsigned(toSign, fromAccount)) return false;
if(!fromLocalAccount.SignRaw(toSign, Signature)) return false; if(!fromLocalAccount.SignRaw(toSign, Signature)) return false;
mSignature=Signature; mSignature=Signature;
return true; return true;
} }
bool Transaction::CheckSign(const Account &fromAccount) const bool Transaction::checkSign(const Account &fromAccount) const
{ {
if(mAccountFrom!=fromAccount.GetAddress()) return false; if(mAccountFrom!=fromAccount.GetAddress()) return false;
std::vector<unsigned char> toSign; std::vector<unsigned char> toSign;
if(!GetRawUnsigned(toSign, fromAccount)) return false; if(!getRawUnsigned(toSign, fromAccount)) return false;
return fromAccount.CheckSignRaw(toSign, mSignature); return fromAccount.CheckSignRaw(toSign, mSignature);
} }
bool Transaction::GetRawUnsigned(std::vector<unsigned char> &raw, const Account &fromAccount) const bool Transaction::getRawUnsigned(std::vector<unsigned char> &raw, const Account &fromAccount) const
{ {
raw.clear(); raw.clear();

View File

@@ -4,6 +4,7 @@
#include "uint256.h" #include "uint256.h"
#include "newcoin.pb.h" #include "newcoin.pb.h"
#include "Hanko.h" #include "Hanko.h"
#include "Serializer.h"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp> #include <boost/enable_shared_from_this.hpp>
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
@@ -46,28 +47,28 @@ public:
Transaction(); Transaction();
Transaction(const std::vector<unsigned char> rawTransaction); Transaction(const std::vector<unsigned char> rawTransaction);
Transaction(const std::string sqlReply); Transaction(const std::string sqlReply);
Transaction(TransStatus Status, LocalAccount &fromLocal, const Account &from, Transaction(TransStatus Status, LocalAccount& fromLocal, const Account& from,
uint32 fromSeq, const uint160 &to, uint64 amount, uint32 ident, uint32 ledger); uint32 fromSeq, const uint160& to, uint64 amount, uint32 ident, uint32 ledger);
bool Sign(LocalAccount &fromLocalAccount, const Account &fromAccount); bool sign(LocalAccount& fromLocalAccount, const Account& fromAccount);
bool CheckSign(const Account &fromAccount) const; bool checkSign(const Account& fromAccount) const;
bool GetRawUnsigned(std::vector<unsigned char> &raw, const Account &from) const; Serializer::pointer getRawUnsigned(const Account& from) const;
bool GetRawSigned(std::vector<unsigned char> &raw, const Account &from) const; Serializer::pointer getRawSigned(const Account& from) const;
const uint256& GetID() const { return mTransactionID; } const uint256& getID() const { return mTransactionID; }
const uint160& GetFromAccount() const { return mAccountFrom; } const uint160& getFromAccount() const { return mAccountFrom; }
const uint160& GetToAccount() const { return mAccountTo; } const uint160& getToAccount() const { return mAccountTo; }
uint64 GetAmount() const { return mAmount; } uint64 getAmount() const { return mAmount; }
uint32 GetFromAccountSeq() const { return mFromAccountSeq; } uint32 getFromAccountSeq() const { return mFromAccountSeq; }
uint32 GetSourceLedger() const { return mSourceLedger; } uint32 getSourceLedger() const { return mSourceLedger; }
uint32 GetIdent() const { return mIdent; } uint32 getIdent() const { return mIdent; }
const std::vector<unsigned char>& GetSignature() const { return mSignature; } const std::vector<unsigned char>& getSignature() const { return mSignature; }
uint32 GetLedger() const { return mInLedger; } uint32 getLedger() const { return mInLedger; }
TransStatus GetStatus() const { return mStatus; } TransStatus getStatus() const { return mStatus; }
void SetStatus(TransStatus st); void setStatus(TransStatus st);
void SetLedger(uint32 Ledger); void setLedger(uint32 Ledger);
bool operator<(const Transaction &) const; bool operator<(const Transaction &) const;
bool operator>(const Transaction &) const; bool operator>(const Transaction &) const;