Changes to metadata format. Make it easy to add fields that are put in the metadata when they

change or are deleted.
This commit is contained in:
JoelKatz
2012-10-26 13:32:21 -07:00
parent 15547ce839
commit d84cad4b7b
4 changed files with 63 additions and 61 deletions

View File

@@ -319,9 +319,11 @@ bool LedgerEntrySet::threadTx(SLE::ref threadTo, Ledger::ref ledger,
uint32 prevLgrID;
if (!threadTo->thread(mSet.getTxID(), mSet.getLgrSeq(), prevTxID, prevLgrID))
return false;
if (TransactionMetaSet::thread(mSet.getAffectedNode(threadTo->getIndex(), sfModifiedNode),
if (prevTxID.isZero() || TransactionMetaSet::thread(mSet.getAffectedNode(threadTo->getIndex(), sfModifiedNode),
prevTxID, prevLgrID))
return true;
assert(false);
return false;
}
@@ -403,34 +405,26 @@ void LedgerEntrySet::calcRawMeta(Serializer& s, TER result)
assert(origNode);
threadOwners(origNode, mLedger, newMod);
if (origNode->isFieldPresent(sfAmount))
{ // node has an amount, covers ripple state nodes
STAmount amount = origNode->getFieldAmount(sfAmount);
if (amount.isNonZero())
mSet.getAffectedNode(it.first).setFieldAmount(sfPreviousBalance, amount);
amount = curNode->getFieldAmount(sfAmount);
if (amount.isNonZero())
mSet.getAffectedNode(it.first).setFieldAmount(sfFinalBalance, amount);
if (origNode->getType() == ltRIPPLE_STATE)
{
mSet.getAffectedNode(it.first).setFieldAccount(sfLowID,
RippleAddress::createAccountID(origNode->getFieldAmount(sfLowLimit).getIssuer()));
mSet.getAffectedNode(it.first).setFieldAccount(sfHighID,
RippleAddress::createAccountID(origNode->getFieldAmount(sfHighLimit).getIssuer()));
}
STObject finals(sfFinalFields);
BOOST_FOREACH(const SerializedType& obj, *curNode)
{ // search the deleted node for values saved on delete
if (obj.getFName().shouldMetaDel())
finals.addObject(obj);
}
if (!finals.empty())
mSet.getAffectedNode(it.first, *type).addObject(finals);
}
if (origNode->getType() == ltOFFER)
{ // check for non-zero balances
STAmount amount = origNode->getFieldAmount(sfTakerPays);
if (amount.isNonZero())
mSet.getAffectedNode(it.first).setFieldAmount(sfFinalTakerPays, amount);
amount = origNode->getFieldAmount(sfTakerGets);
if (amount.isNonZero())
mSet.getAffectedNode(it.first).setFieldAmount(sfFinalTakerGets, amount);
if ((type == &sfDeletedNode || type == &sfModifiedNode))
{
STObject mods(sfPreviousFields);
BOOST_FOREACH(const SerializedType& obj, *origNode)
{ // search the original node for values saved on modify
if (obj.getFName().shouldMetaMod() && !curNode->hasMatchingEntry(obj))
mods.addObject(obj);
}
if (!mods.empty())
mSet.getAffectedNode(it.first, *type).addObject(mods);
}
if (type == &sfCreatedNode) // if created, thread to owner(s)
@@ -444,28 +438,6 @@ void LedgerEntrySet::calcRawMeta(Serializer& s, TER result)
if (curNode->isThreadedType()) // always thread to self
threadTx(curNode, mLedger, newMod);
}
if (type == &sfModifiedNode)
{
assert(origNode);
if (origNode->isFieldPresent(sfAmount))
{ // node has an amount, covers account root nodes and ripple nodes
STAmount amount = origNode->getFieldAmount(sfAmount);
if (amount != curNode->getFieldAmount(sfAmount))
mSet.getAffectedNode(it.first).setFieldAmount(sfPreviousBalance, amount);
}
if (origNode->getType() == ltOFFER)
{
STAmount amount = origNode->getFieldAmount(sfTakerPays);
if (amount != curNode->getFieldAmount(sfTakerPays))
mSet.getAffectedNode(it.first).setFieldAmount(sfPreviousTakerPays, amount);
amount = origNode->getFieldAmount(sfTakerGets);
if (amount != curNode->getFieldAmount(sfTakerGets))
mSet.getAffectedNode(it.first).setFieldAmount(sfPreviousTakerGets, amount);
}
}
}
// add any new modified nodes to the modification set