mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-30 07:25:50 +00:00
It makes much more sense to keep the from account pointer in the transaction
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user