// Normally, Asset Contracts do NOT update / rewrite their contents, since their
// primary goal is for the signature to continue to verify.  But when first creating
// a basket contract, we have to rewrite the contents, which is done here.
bool OTAssetContract::CreateBasket(OTBasket & theBasket, OTPseudonym & theSigner)
{
	Release();

	// Grab a string copy of the basket information.
	theBasket.SaveContractRaw(m_strBasketInfo);
	
	// -------------------------------
	
	// Insert the server's public key as the "contract" key for this basket currency.
	OTString strPubKey, strKeyName("contract"); // todo stop hardcoding
	theSigner.GetPublicKey().GetPublicKey(strPubKey);
	
	InsertNym(strKeyName, strPubKey);

	// todo check the above two return values.
	
	OTASCIIArmor theBasketArmor(m_strBasketInfo);
	// -------------------------------
	m_xmlUnsigned.Concatenate("<?xml version=\"%s\"?>\n\n", "1.0");		
	
	m_xmlUnsigned.Concatenate("<basketContract version=\"%s\">\n\n", m_strVersion.Get());
	m_xmlUnsigned.Concatenate("<basketInfo>\n%s</basketInfo>\n\n", theBasketArmor.Get());
	m_xmlUnsigned.Concatenate("<key name=\"%s\">\n%s</key>\n\n", strKeyName.Get(), strPubKey.Get());

	m_xmlUnsigned.Concatenate("</basketContract>\n");		
	

	// This function assumes that m_xmlUnsigned is ready to be processed.
	// This function only processes that portion of the contract.
	bool bLoaded = LoadContractXML();
	
	if (bLoaded)
	{
		OTString strTemp;

		SignContract(theSigner);
		RewriteContract(strTemp); // this trims

		// This is probably redundant...
//		std::string str_Trim(strTemp.Get());
//		std::string str_Trim2 = OTString::trim(str_Trim);
//		strTemp.Set(str_Trim2.c_str());
		// -----------------------------------
		Release();
		
		LoadContractFromString(strTemp);
		SaveContract();
		
		OTIdentifier NEW_ID;
		CalculateContractID(NEW_ID);
		m_ID = NEW_ID;	
		
		return true;
	}	
	
	return false;
	
}
// RSA / AES
bool OTEnvelope::Seal(const OTPseudonym & theRecipient, const OTString & theContents)
{
	return Seal(theRecipient.GetPublicKey(), theContents);
}