예제 #1
0
// OTCron calls this regularly, which is my chance to expire, etc.
// Child classes will override this, AND call it (to verify valid date range.)
bool OTAgreement::ProcessCron()
{
	// END DATE --------------------------------
	// First call the parent's version (which this overrides) so it has
	// a chance to check its stuff. Currently it checks IsExpired().
	if (!OTCronItem::ProcessCron())
		return false;	// It's expired--removed it from Cron.
	
	
	// START DATE --------------------------------
	// Okay, so it's not expired. But might not have reached START DATE yet...
	if (!VerifyCurrentDate())
		return true;	// The Trade is not yet valid, so we return. BUT, we return 
						//  true, so it will stay on Cron until it BECOMES valid.
	
	
	// Process my Agreement-specific stuff below.--------------------------------
	
	
	return true;
}
예제 #2
0
// OTCron calls this regularly, which is my chance to expire, etc.
// Child classes will override this, AND call it (to verify valid date range.)
bool OTAgreement::ProcessCron()
{
	// END DATE --------------------------------
	// First call the parent's version (which this overrides) so it has
	// a chance to check its stuff. Currently it checks IsExpired().
	if (!ot_super::ProcessCron())
		return false;	// It's expired or flagged--removed it from Cron.
	
	
	// START DATE --------------------------------
	// Okay, so it's NOT expired. But might not have reached START DATE yet...
	// (If not expired, yet current date is not verified, that means it hasn't
	// ENTERED the date range YET.)
	//
	if (!VerifyCurrentDate())
		return true;	// The Trade is not yet valid, so we return. BUT, we return 
						//  true, so it will stay on Cron until it BECOMES valid.
	
	
	// Process my Agreement-specific stuff below.--------------------------------
	
	
	return true;
}
예제 #3
0
// OTCron calls this regularly, which is my chance to expire, etc.
// Return True if I should stay on the Cron list for more processing.
// Return False if I should be removed and deleted.
bool OTTrade::ProcessCron()
{
    // Right now Cron is called 10 times per second.
    // I'm going to slow down all trades so they are once every
    // GetProcessInterval()
    if (GetLastProcessDate() > OT_TIME_ZERO) {
        // (Default ProcessInterval is 1 second, but Trades will use 10 seconds,
        // and Payment Plans will use an hour or day.)
        if (OTTimeGetTimeInterval(OTTimeGetCurrentTime(),
                                  GetLastProcessDate()) <= GetProcessInterval())
            return true;
    }
    
    // Keep a record of the last time this was processed.
    // (NOT saved to storage, only used while the software is running.)
    // (Thus no need to release signatures, sign contract, save contract, etc.)
    SetLastProcessDate(OTTimeGetCurrentTime());

    // PAST END DATE?
    // First call the parent's version (which this overrides) so it has
    // a chance to check its stuff. Currently it checks IsExpired().
    if (!ot_super::ProcessCron())
        return false; // It's expired or flagged for removal--remove it from
                      // Cron.

    // You might ask, why not check here if this trade is flagged for removal?
    // Supposedly the answer is, because it's only below that I have the market
    // pointer,
    // and am able to remove the corresponding trade from the market.
    // Therefore I am adding a hook for "onRemoval" so that Objects such as
    // OTTrade ALWAYS
    // have the opportunity to perform such cleanup, without having to juggle
    // such logic.

    // REACHED START DATE?
    // Okay, so it's not expired. But might not have reached START DATE yet...
    if (!VerifyCurrentDate())
        return true; // The Trade is not yet valid, so we return. BUT, we return
                     //  true, so it will stay on Cron until it BECOMES valid.

    // TRADE-specific stuff below.

    bool bStayOnMarket =
        true; // by default stay on the market (until some rule expires me.)

    Identifier OFFER_MARKET_ID;
    OTMarket* market = nullptr;

    // If the Offer is already active on a market, then I already have a pointer
    // to
    // it. This function returns that pointer. If nullptr, it tries to find the
    // offer on
    // the market and then sets the pointer and returns. If it can't find it, IT
    // TRIES
    // TO ADD IT TO THE MARKET and sets the pointer and returns it.
    OTOffer* offer = GetOffer(
        &OFFER_MARKET_ID, &market); // Both of these parameters are optional.

    // In this case, the offer is NOT on the market.
    // Perhaps it wasn't ready to activate yet.
    if (offer == nullptr) {
        
        // The offer SHOULD HAVE been on the market, since we're within the
        // valid range,
        // and GetOffer adds it when it's not already there.

        //        otErr << "OTTrade::ProcessCron: Offer SHOULD have been on
        // Market. I might ASSERT this.\n"; // comment this out

        // Actually! If it's a Stop Order, then it WOULD be within the valid
        // range, yet would
        // not yet have activated. So I don't want to log some big error every
        // time a stop order
        // checks its prices.
    }
    else if (market == nullptr) {
        
        // todo. (This will already leave a log above in GetOffer somewhere.)
        //        otErr << "OTTrade::ProcessCron: Market was nullptr.\n"; //
        // comment this out
    }
    else // If a valid pointer was returned, that means the offer is on the
           // market.
    {
        // Make sure it hasn't already been flagged by someone else...
        if (IsFlaggedForRemoval()) // This is checked above in
                                   // OTCronItem::ProcessCron().
            bStayOnMarket = false; // I'm leaving the check here in case the
                                   // flag was set since then.

        else // Process it!  <===================
        {
            otInfo << "Processing trade: " << GetTransactionNum() << ".\n";

            bStayOnMarket = market->ProcessTrade(*this, *offer);
            // No need to save the Trade or Offer, since they will
            // be saved inside this call if they are changed.
        }
    }

    // Return True if I should stay on the Cron list for more processing.
    // Return False if I should be removed and deleted.
    return bStayOnMarket; // defaults true, so if false, that means someone is
                          // removing it for a reason.
}