src/assetallocation.cpp
// revert allocation to previous state and remove 
revert allocation to previous state and remove
revert allocation to previous state and remove
bool RevertAssetAllocation(const CAssetAllocationTuple &assetAllocationToRemove, const CAsset &asset, const uint256 &txHash, const int& nHeight, sorted_vector<CAssetAllocationTuple> &revertedAssetAllocations) {
	passetallocationdb->EraseISArrivalTime(assetAllocationToRemove, txHash);
	if (revertedAssetAllocations.find(assetAllocationToRemove) != revertedAssetAllocations.end())
		return true;
	string errorMessage = "";
	CAssetAllocation dbAssetAllocation;
	if (!passetallocationdb->ReadLastAssetAllocation(assetAllocationToRemove, dbAssetAllocation)) {
		dbAssetAllocation.vchAliasOrAddress = assetAllocationToRemove.vchAliasOrAddress;
		dbAssetAllocation.vchAsset = assetAllocationToRemove.vchAsset;
		dbAssetAllocation.nLastInterestClaimHeight = nHeight;
		dbAssetAllocation.nHeight = nHeight;
		dbAssetAllocation.fInterestRate = asset.fInterestRate;
	}
	if (!passetallocationdb->WriteAssetAllocation(dbAssetAllocation, 0, 0, asset, INT64_MAX, "", "", false))
	{
		errorMessage = "MARTKIST_ASSET_ALLOCATION_CONSENSUS_ERROR: ERRCODE: 1000 - " + _("Failed to write to asset allocation DB");
		return error(errorMessage.c_str());
	}
	revertedAssetAllocations.insert(assetAllocationToRemove);
	sorted_vector<CAssetAllocationTuple>::const_iterator it = assetAllocationConflicts.find(assetAllocationToRemove);
	if (it != assetAllocationConflicts.end()) {
		assetAllocationConflicts.V.erase(const_iterator_cast(assetAllocationConflicts.V, it));
	}
	return true;
}
bool RevertAssetAllocation ( const CAssetAllocationTuple & assetAllocationToRemove , const CAsset & asset , const uint256 & txHash , const int & nHeight , sorted_vector < CAssetAllocationTuple > & revertedAssetAllocations ) { passetallocationdb -> EraseISArrivalTime ( assetAllocationToRemove , txHash ) ; if ( revertedAssetAllocations . find ( assetAllocationToRemove ) != revertedAssetAllocations . end ( ) ) return true ; string errorMessage = " " ; CAssetAllocation dbAssetAllocation ; if ( ! passetallocationdb -> ReadLastAssetAllocation ( assetAllocationToRemove , dbAssetAllocation ) ) { dbAssetAllocation . vchAliasOrAddress = assetAllocationToRemove . vchAliasOrAddress ; dbAssetAllocation . vchAsset = assetAllocationToRemove . vchAsset ; dbAssetAllocation . nLastInterestClaimHeight = nHeight ; dbAssetAllocation . nHeight = nHeight ; dbAssetAllocation . fInterestRate = asset . fInterestRate ; } if ( ! passetallocationdb -> WriteAssetAllocation ( dbAssetAllocation , 0 , 0 , asset , INT64_MAX , " " , " " , false ) ) { errorMessage = " " + _ ( " " ) ; return error ( errorMessage . c_str ( ) ) ; } revertedAssetAllocations . insert ( assetAllocationToRemove ) ; sorted_vector < CAssetAllocationTuple > :: const_iterator it = assetAllocationConflicts . find ( assetAllocationToRemove ) ; if ( it != assetAllocationConflicts . end ( ) ) { assetAllocationConflicts . V . erase ( const_iterator_cast ( assetAllocationConflicts . V , it ) ) ; } return true ; }
revert allocation to previous state and remove
revert allocation to previous state and remove
// remove the sender arrival time from this tx // only revert asset allocation once // write the state back to previous state // TODO make this based on txid/allocation tuple since we may have multiple conflicts within an asset allocation that need to be cleared seperately // remove the conflict once we revert since it is assumed to be resolved on POW