示例#1
0
/// If transaction #87, in reference to #74, is in the inbox, you can remove it
/// by calling this function and passing in 74.
///
bool OTLedger::RemovePendingTransaction(long lTransactionNum) // if false, transaction wasn't found.
{	
	// loop through the items that make up this transaction.
	OTTransaction * pTransaction = NULL;
	
	mapOfTransactions::iterator it;
	
	for (mapOfTransactions::iterator ii = m_mapTransactions.begin(); ii != m_mapTransactions.end(); ++ii)
	{
		it = ii;
		
		pTransaction = (*ii).second;
		
		OT_ASSERT(NULL != pTransaction);
		
		bool bCorrectType = false;
		
		switch (pTransaction->GetType()) 
		{
			case OTTransaction::pending:
			case OTTransaction::transferReceipt:
			case OTTransaction::chequeReceipt:
				bCorrectType = true;
				break;
			default:
				break;
		}
		
		if (bCorrectType && pTransaction->GetReferenceToNum() == lTransactionNum)
			break;
		else
			pTransaction = NULL;
		
	}
	
	// If it's not already on the list, then there's nothing to remove.
	if ( NULL == pTransaction )
	{
		OTLog::vError("OTLedger::RemovePendingTransaction: Attempt to remove Transaction from ledger,\n"
					  "when not already there: (the number in reference to) %ld\n",
					  lTransactionNum);
		return false;
	}
	// Otherwise, if it WAS already there, remove it properly.
	else 
	{		
		m_mapTransactions.erase(it);
		delete pTransaction;
		return true;		
	}
	
	return false;
}
示例#2
0
// Return a count of all the transactions in this ledger that are IN REFERENCE TO a specific trans#.
//
// Might want to change this so that it only counts ACCEPTED receipts.
//
int OTLedger::GetTransactionCountInRefTo(const long lReferenceNum)
{
    int nCount = 0;
    
	for (mapOfTransactions::iterator ii = m_mapTransactions.begin(); ii != m_mapTransactions.end(); ++ii)
	{
		OTTransaction * pTransaction = (*ii).second;
		OT_ASSERT(NULL != pTransaction);
		
        if (pTransaction->GetReferenceToNum() == lReferenceNum)
            nCount++;
	}
	
	return nCount;
}
示例#3
0
// If you TRANSFER REQUEST to me (transaction #1), then the server will create a 
// PENDING transaction in my inbox (transaction #41) and a PENDING transaction in 
// your outbox (also transaction #41) which both contain a copy of transaction#1 in their
// "In Reference To" ascii-armored field.
//
// The above function would look up #41 in my inbox, or #41 in your outbox, but
// you could NOT pass #1 to that function and get a pointer back. You'd get NULL.
// But the below function specifically returns the pointer of a transaction ONLY
// IF THE "IN REFERENCE TO" Transaction ID matches the one passed in (such as #1
// in the example above.
// If it can't find anything, it will return NULL.
OTTransaction * OTLedger::GetPendingTransaction(long lTransactionNum)
{
	// loop through the items that make up this transaction.
	OTTransaction * pTransaction = NULL;
	
	for (mapOfTransactions::iterator ii = m_mapTransactions.begin(); ii != m_mapTransactions.end(); ++ii)
	{
		pTransaction = (*ii).second;
		
		OT_ASSERT(NULL != pTransaction);
		
		if (pTransaction->GetReferenceToNum() == lTransactionNum)
			return pTransaction;
	}
	
	return NULL;
}
示例#4
0
// Find the finalReceipt in this Inbox, that has lTransactionNum as its "in reference to".
// This is useful for cases where a marketReceipt or paymentReceipt has been found,
// yet the transaction # for that receipt isn't on my issued list... it's been closed.
// Normally this would be a problem: why is it in my inbox then? Because those receipts
// are still valid as long as there is a "FINAL RECEIPT" in the same inbox, that references
// the same original transaction that they do.  The below function makes it easy to find that
// final receipt, if it exists.
//
OTTransaction * OTLedger::GetFinalReceipt(long lReferenceNum)
{
	// loop through the items that make up this transaction.
	OTTransaction * pTransaction = NULL;
	
	for (mapOfTransactions::iterator ii = m_mapTransactions.begin(); ii != m_mapTransactions.end(); ++ii)
	{
		pTransaction = (*ii).second;
		
		OT_ASSERT(NULL != pTransaction);
		
        if (OTTransaction::finalReceipt != pTransaction->GetType()) // <=======
            continue;
        // ---------------------------------
		if (pTransaction->GetReferenceToNum() == lReferenceNum)
			return pTransaction;
	}
	
	return NULL;
}
示例#5
0
// If my outbox has a pending transfer, #1901, referencing 1884, and then the 
// recipient accepts it with his #781, referencing 1884, then it will pop into my inbox
// as a transfer receipt, #1902 (say) and referencing 781. Attached to that
// transfer receipt is a copy of the actual #781, which is in reference to 1884.
//
// Why does this matter? Because when I am verifying a balance agreement, and an
// outbox item 1901/1884 is missing, that means there is probably a corresponding 
// transferReceipt in the Inbox. In that case, I START with #1901 referencing 1884 (from
// the outbox) and I need to FIND #1902, in reference to 781, referencing 1884 in the inbox.
//
// Therefore, loop through all items and filter by transfer receipt. For each, load its
// Reference string (containing the acceptPending) and get ITS ReferenceNum() to compare
// to the one passed in.
//
// Therefore 1884 would be passed in, and the appropriate transferReceipt will be returned.
//
OTTransaction * OTLedger::GetTransferReceipt(long lTransactionNum)
{
	// loop through the items that make up this transaction.
	OTTransaction * pTransaction = NULL;
	
	for (mapOfTransactions::iterator ii = m_mapTransactions.begin(); ii != m_mapTransactions.end(); ++ii)
	{
		pTransaction = (*ii).second;
		
		OT_ASSERT(NULL != pTransaction);
		
		if (OTTransaction::transferReceipt == pTransaction->GetType())
		{
			OTString strReference;
			pTransaction->GetReferenceString(strReference);
			
			OTItem * pOriginalItem = OTItem::CreateItemFromString(strReference, 
																  pTransaction->GetPurportedServerID(), 
																  pTransaction->GetReferenceToNum()); 
			OT_ASSERT(NULL != pOriginalItem);
			OTCleanup<OTItem> theItemAngel(*pOriginalItem);
			
			if (pOriginalItem->GetType() != OTItem::acceptPending) 
			{
				OTLog::Error("OTLedger::GetTransferReceipt: Wrong item type attached to transferReceipt!\n");
				return NULL;
			}
			else 
			{
				if (pOriginalItem->GetReferenceToNum() == lTransactionNum)
					return pTransaction; // FOUND IT!
			}
		}
	}
	
	return NULL;
}