mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Handle all the weird edge cases, such as:
A remote transaction is received *from* a local account. We neeed to update our balance and sequence tracking. A local transaction loses to a conflict.
This commit is contained in:
50
Wallet.cpp
50
Wallet.cpp
@@ -812,3 +812,53 @@ void Wallet::syncToLedger(bool force, Ledger* ledger)
|
||||
}
|
||||
if(mLedger<ledger->getLedgerSeq()) mLedger=ledger->getLedgerSeq();
|
||||
}
|
||||
|
||||
void Wallet::applyTransaction(Transaction::pointer txn)
|
||||
{
|
||||
TransStatus st=txn->getStatus();
|
||||
bool shouldBePaid=(st==INCLUDED) || (st==HELD) || (st==NEW);
|
||||
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
std::map<uint160, LocalAccount::pointer>::iterator lac=mAccounts.find(txn->getFromAccount());
|
||||
if(lac==mAccounts.end()) return;
|
||||
|
||||
if ( (st!=INVALID) && (lac->second->getTxnSeq()==txn->getFromAccountSeq()) )
|
||||
lac->second->incTxnSeq();
|
||||
|
||||
std::map<uint256, LocalTransaction::pointer>::iterator ltx=mTransactions.find(txn->getID());
|
||||
if(ltx==mTransactions.end())
|
||||
{ // we don't have this transactions
|
||||
if(shouldBePaid)
|
||||
{ // we need it
|
||||
LocalTransaction::pointer nlt(new
|
||||
LocalTransaction(txn->getToAccount(), txn->getAmount(), txn->getIdent()));
|
||||
nlt->setTransaction(txn);
|
||||
mTransactions.insert(std::make_pair<uint256, LocalTransaction::pointer>(txn->getID(), nlt));
|
||||
lac->second->debit(txn->getAmount());
|
||||
ltx->second->setPaid();
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // we have this transaction in some form (ltx->second)
|
||||
if( (st==COMMITTED) || (st==INVALID) )
|
||||
{ // we need to remove it
|
||||
if(ltx->second->isPaid())
|
||||
{
|
||||
lac->second->credit(txn->getAmount());
|
||||
ltx->second->setUnpaid();
|
||||
}
|
||||
mTransactions.erase(txn->getID());
|
||||
}
|
||||
else if(ltx->second->isPaid() && !shouldBePaid)
|
||||
{ // we paid for this transaction and it didn't happen
|
||||
lac->second->credit(txn->getAmount());
|
||||
ltx->second->setUnpaid();
|
||||
}
|
||||
else if(!ltx->second->isPaid() && shouldBePaid)
|
||||
{ // this transaction happened, and we haven't paid locally
|
||||
lac->second->debit(txn->getAmount());
|
||||
ltx->second->setPaid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user