Start tying all these classes together:

This commit is contained in:
JoelKatz
2011-11-18 11:23:06 -08:00
parent 4096bad636
commit fa60ccd2df
8 changed files with 159 additions and 121 deletions

View File

@@ -11,57 +11,54 @@ Transaction::Transaction() : mTransactionID(0), mAccountFrom(0), mAccountTo(0),
{
}
Transaction::Transaction(TransStatus status, LocalAccount &fromLocalAccount, const Account &fromAccount,
uint32 fromSeq, const uint160 &toAccount, uint64 amount, uint32 ident, uint32 ledger) :
mAccountTo(toAccount), mAmount(amount), mFromAccountSeq(fromSeq), mSourceLedger(ledger),
mIdent(ident), mInLedger(0), mStatus(NEW)
Transaction::Transaction(TransStatus status, LocalAccount& fromLocalAccount, Account& fromAccount,
uint32 fromSeq, const uint160& toAccount, uint64 amount, uint32 ident, uint32 ledger) :
mAccountTo(toAccount), mAmount(amount), mFromAccountSeq(fromSeq), mSourceLedger(ledger),
mIdent(ident), mInLedger(0), mStatus(NEW)
{
assert(fromAccount.GetAddress()==fromLocalAccount.mAddress);
assert(fromLocalAccount.mAmount>=amount);
assert((fromSeq+1)==fromLocalAccount.mSeqNum);
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, fromAccount);
}
bool Transaction::sign(LocalAccount &fromLocalAccount, const Account &fromAccount)
bool Transaction::sign(LocalAccount& fromLocalAccount, Account& fromAccount)
{
if( (mAmount==0) || (mSourceLedger==0) || (mAccountTo==0) )
return false;
if((mAccountFrom!=fromLocalAccount.mAddress)||(mAccountFrom!=fromAccount.GetAddress()))
return false;
updateHash();
std::vector<unsigned char> toSign, Signature;
if(!getRawUnsigned(toSign, fromAccount)) return false;
if(!fromLocalAccount.SignRaw(toSign, Signature)) return false;
mSignature=Signature;
return true;
if( (mAmount==0) || (mSourceLedger==0) || (mAccountTo==0) )
return false;
if((mAccountFrom!=fromLocalAccount.mAddress)||(mAccountFrom!=fromAccount.GetAddress()))
return false;
Serializer::pointer signBuf(getRawUnsigned(fromAccount));
if(!signBuf->makeSignature(mSignature, fromLocalAccount.peekPrivKey()))
return false;
signBuf->addRaw(mSignature);
mTransactionID=signBuf->getSHA512Half();
}
bool Transaction::checkSign(const Account &fromAccount) const
bool Transaction::checkSign(Account& fromAccount) const
{
if(mAccountFrom!=fromAccount.GetAddress()) return false;
if(mAccountFrom!=fromAccount.GetAddress()) return false;
std::vector<unsigned char> toSign;
if(!getRawUnsigned(toSign, fromAccount)) return false;
return fromAccount.CheckSignRaw(toSign, mSignature);
Serializer::pointer toSign(getRawUnsigned(fromAccount));
return toSign->checkSignature(mSignature, fromAccount.peekPubKey());
}
bool Transaction::getRawUnsigned(std::vector<unsigned char> &raw, const Account &fromAccount) const
Serializer::pointer Transaction::getRawUnsigned(Account& fromAccount) const
{
raw.clear();
Serializer::pointer ret(new Serializer(104));
ret->add32(0x54584e00u);
ret->addRaw(fromAccount.peekPubKey().GetPubKey());
ret->add64(mAmount);
ret->add32(mFromAccountSeq);
ret->add32(mInLedger);
ret->add32(mIdent);
return ret;
}
#if 0
void Transaction::UpdateHash()
{ // FIXME
vector<unsigned char> buffer;
buffer.resize(trans->ByteSize());
trans->SerializeToArray(&(buffer[0]),buffer.size());
return Hash(buffer.begin(), buffer.end());
void Transaction::updateID(Account& fromAccount)
{
mTransactionID=getRawSigned(fromAccount)->getSHA512Half();
}
#endif