示例#1
0
// The trade stores a copy of the Offer in string form.
// This function verifies that offer against the trade,
// and also verifies the signature on the offer.
//
// The Nym's ID is compared to offer's SenderNymID, and then the Signature
// is checked
// on the offer.  It also compares the server ID, asset and currency IDs,
// transaction #, etc
// between this trade and the offer, in order to fully verify the offer's
// authenticity.
//
bool OTTrade::VerifyOffer(OTOffer& offer) const
{
    // At this point, I have a working, loaded, model of the Offer.
    // Let's verify the thing.

    if (GetTransactionNum() != offer.GetTransactionNum()) {
        otErr << "While verifying offer, failed matching transaction number.\n";
        return false;
    }
    else if (GetNotaryID() != offer.GetNotaryID()) {
        otErr << "While verifying offer, failed matching Notary ID.\n";
        return false;
    }
    else if (GetInstrumentDefinitionID() !=
               offer.GetInstrumentDefinitionID()) {
        otErr << "While verifying offer, failed matching instrument definition "
                 "ID.\n";
        return false;
    }
    else if (GetCurrencyID() != offer.GetCurrencyID()) {
        otErr << "While verifying offer, failed matching currency type ID.\n";
        return false;
    }

    // the Offer validates properly for this Trade.
    //
    return true;
}
示例#2
0
// The trade stores a copy of the Offer in string form.
// This function verifies that offer against the trade,
// and also verifies the signature on the offer.
//
// The Nym's ID is compared to theOffer's SenderUserID, and then the Signature is checked
// on the offer.  It also compares the server ID, asset and currency IDs, transaction #, etc
// between this trade and the offer, in order to fully verify the offer's authenticity.
//
bool OTTrade::VerifyOffer(OTOffer & theOffer)
{
	// At this point, I have a working, loaded, model of the Offer.
	// Let's verify the thing.
	
	if (GetTransactionNum() != theOffer.GetTransactionNum())
	{
		OTLog::Error("While verifying offer, failed matching transaction number.\n");
		return false;
	}
	else if (GetServerID() != theOffer.GetServerID())
	{
		OTLog::Error("While verifying offer, failed matching Server ID.\n");
		return false;
	}
	else if (GetAssetID() != theOffer.GetAssetID())
	{
		OTLog::Error("While verifying offer, failed matching asset type ID.\n");
		return false;
	}
	else if (GetCurrencyID() != theOffer.GetCurrencyID())
	{
		OTLog::Error("While verifying offer, failed matching currency type ID.\n");
		return false;
	}
	
	// the Offer validates properly for this Trade.
	return true;
}
示例#3
0
// This is called by the client side. First you call MakeOffer() to set up the Offer,
// then you call IssueTrade() and pass the Offer into it here.
bool OTTrade::IssueTrade(OTOffer & theOffer, char cStopSign/*=0*/, long lStopPrice/*=0*/)
{
	// Make sure the Stop Sign is within parameters (0, '<', or '>')
	if ((cStopSign ==  0 )	||
		(cStopSign == '<')	||
		(cStopSign == '>'))
		m_cStopSign = cStopSign;
	else
	{
		OTLog::vError("Bad data in Stop Sign while issuing trade: %c\n", cStopSign);
		return false;
	}
	
	// Make sure, if this IS a Stop order, that the price is within parameters and set.
	if ((m_cStopSign == '<')	||
		(m_cStopSign == '>'))
	{
		if (0 >= lStopPrice)
		{
			OTLog::Error("Expected Stop Price for trade.\n");
			return false;
		}
		
		m_lStopPrice = lStopPrice;
	}

	m_nTradesAlreadyDone	= 0;
	
	SetCreationDate(time(NULL)); // This time is set to TODAY NOW  (OTCronItem)
	
	// ------------------------------------------------------------------------
	
	// Validate the Server ID, Asset Type ID, Currency Type ID, and Date Range.
	if ((GetServerID()			!= theOffer.GetServerID())		||
		(GetCurrencyID()		!= theOffer.GetCurrencyID())	||
		(GetAssetID()			!= theOffer.GetAssetID())		||
		
		(theOffer.GetValidFrom() <	0)							||
		(theOffer.GetValidTo()	 < theOffer.GetValidFrom())	)
	{
		return false;
	}
	
//	m_CURRENCY_TYPE_ID // This is already set in the constructors of this and the offer. (And compared.)
//	m_CURRENCY_ACCT_ID // This is already set in the constructor of this.
	
	// Set the (now validated) date range as per the Offer.
	SetValidFrom(theOffer.GetValidFrom());
	SetValidTo(theOffer.GetValidTo());
	
	// Get the transaction number from the Offer.
	SetTransactionNum(theOffer.GetTransactionNum());
	
	// Save a copy of the offer, in XML form, here on this Trade.
	OTString strOffer(theOffer);
	m_strOffer.Set(strOffer);
	
	return true;
}
示例#4
0
// This is called by the client side. First you call MakeOffer() to set up the
// Offer,
// then you call IssueTrade() and pass the Offer into it here.
bool OTTrade::IssueTrade(OTOffer& offer, char stopSign, int64_t stopPrice)
{
    // Make sure the Stop Sign is within parameters (0, '<', or '>')
    if ((stopSign == 0) || (stopSign == '<') || (stopSign == '>'))
        stopSign_ = stopSign;
    else {
        otErr << "Bad data in Stop Sign while issuing trade: " << stopSign
              << "\n";
        return false;
    }

    // Make sure, if this IS a Stop order, that the price is within parameters
    // and set.
    if ((stopSign_ == '<') || (stopSign_ == '>')) {
        if (0 >= stopPrice) {
            otErr << "Expected Stop Price for trade.\n";
            return false;
        }

        stopPrice_ = stopPrice;
    }

    tradesAlreadyDone_ = 0;

    SetCreationDate(
        OTTimeGetCurrentTime()); // This time is set to TODAY NOW  (OTCronItem)

    // Validate the Notary ID, Instrument Definition ID, Currency Type ID, and
    // Date Range.
    if ((GetNotaryID() != offer.GetNotaryID()) ||
        (GetCurrencyID() != offer.GetCurrencyID()) ||
        (GetInstrumentDefinitionID() != offer.GetInstrumentDefinitionID()) ||
        (offer.GetValidFrom() < OT_TIME_ZERO) ||
        (offer.GetValidTo() < offer.GetValidFrom())) {
        return false;
    }

    //    currencyTypeID_ // This is already set in the constructors of this
    // and the offer. (And compared.)
    //    currencyAcctID_ // This is already set in the constructor of this.

    // Set the (now validated) date range as per the Offer.
    SetValidFrom(offer.GetValidFrom());
    SetValidTo(offer.GetValidTo());

    // Get the transaction number from the Offer.
    SetTransactionNum(offer.GetTransactionNum());

    // Save a copy of the offer, in XML form, here on this Trade.
    String strOffer(offer);
    marketOffer_.Set(strOffer);

    return true;
}