This function sets up "theMessage" so that it is ready to be sent out to the server. If you want to set up a checkServerID command and send it to the server, then you just call this to get the OTMessage object all set up and ready to be sent. returns -1 if error, don't send message. returns 0 if NO error, but still, don't send message. returns 1 if message is sent but there's not request number returns >0 for processInbox, containing the number that was there before processing. returns >0 for nearly everything else, containing the request number itself.
8916 OTIdentifier CONTRACT_ID;
8917 OTString strNymID, strContractID, strServerID, strNymPublicKey,
8919 int64_t lRequestNumber = 0;
8921 theNym.GetIdentifier(strNymID);
8922 theServer.GetIdentifier(strServerID);
8924 const OTIdentifier SERVER_ID(strServerID);
8926 if (
nullptr != pAccount) {
8927 pAccount->GetIdentifier(strAccountID);
8929 if (pAccount->GetPurportedServerID() != SERVER_ID) {
8930 otErr <<
"OTClient::ProcessUserCommand: "
8931 "pAccount->GetPurportedServerID() doesn't match "
8932 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
8938 bool bSendCommand =
false;
8939 int64_t lReturnValue = 0;
8942 switch (requestedCommand) {
8945 OTString strAuthentKey, strEncryptionKey;
8947 theNym.GetPublicAuthKey().GetPublicKey(strAuthentKey);
8948 theNym.GetPublicEncrKey().GetPublicKey(strEncryptionKey);
8951 theMessage.m_strCommand =
"checkServerID";
8952 theMessage.m_strNymID = strNymID;
8955 theMessage.m_strServerID = strServerID;
8956 theMessage.m_strNymPublicKey =
8959 theMessage.m_strNymID2 = strEncryptionKey;
8963 theMessage.m_strRequestNum.Format(
8969 theMessage.SignContract(theNym);
8978 theMessage.SaveContract();
8980 bSendCommand =
true;
8990 OTDB::StringMap* pMap =
dynamic_cast<OTDB::StringMap*
>(pStorable.get());
8991 if (
nullptr == pMap)
8992 otErr << __FUNCTION__ <<
": Error: failed trying to load or create "
8993 "a STORED_OBJ_STRING_MAP.\n";
8996 OTString strCredList;
9000 if (theNym.GetMasterCredentialCount() > 0) {
9001 theNym.GetPublicCredentials(strCredList, &theMap);
9005 OTString strMasterCredID;
9006 const bool bAddedMaster =
9007 theNym.AddNewMasterCredential(strMasterCredID);
9009 if (bAddedMaster && strMasterCredID.Exists() &&
9010 (theNym.GetMasterCredentialCount() > 0)) {
9011 otOut << __FUNCTION__
9012 <<
": Adding new keyCredential to master credential: "
9013 << strMasterCredID <<
"\n";
9015 const OTIdentifier theMasterCredID(strMasterCredID);
9017 const bool bAddedSubkey =
9018 theNym.AddNewSubkey(theMasterCredID);
9021 theNym.SaveCredentialList();
9022 theNym.GetPublicCredentials(strCredList, &theMap);
9025 otErr << __FUNCTION__ <<
": Failed trying to add new "
9026 "keyCredential to new Master "
9030 otErr << __FUNCTION__ <<
": Failed trying to add new "
9031 "master credential (for Nym who "
9032 "doesn't have one yet.)\n";
9037 if (strCredList.Exists() && (!theMap.empty())) {
9039 const bool bSuccessEncoding = (str_Encoded.size() > 0);
9040 if (bSuccessEncoding) {
9041 theMessage.m_ascPayload.SetString(
9043 theMessage.m_ascPayload2.Set(
9044 str_Encoded.c_str());
9050 if (!theMessage.m_ascPayload.Exists() ||
9051 !theMessage.m_ascPayload2.Exists()) {
9052 otErr << __FUNCTION__ <<
": Failed trying to assemble a "
9053 "createUserAccount message: This Nym has "
9054 "no credentials to use for registration. "
9055 "Convert this Nym first to the new "
9056 "credential system, then try again.\n";
9060 theMessage.m_strCommand =
"createUserAccount";
9061 theMessage.m_strNymID = strNymID;
9062 theMessage.m_strServerID = strServerID;
9077 theMessage.m_strRequestNum.Format(
9081 theMessage.SignContract(theNym);
9085 theMessage.SaveContract();
9087 bSendCommand =
true;
9096 theMessage.m_strCommand =
"getRequest";
9097 theMessage.m_strNymID = strNymID;
9098 theMessage.m_strServerID = strServerID;
9100 theMessage.m_strRequestNum.Format(
9104 theMessage.SignContract(theNym);
9108 theMessage.SaveContract();
9110 bSendCommand =
true;
9145 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
9146 theMessage.m_strRequestNum.Format(
9147 "%lld", lRequestNumber);
9148 theNym.IncrementRequestNum(theNym, strServerID);
9156 theMessage.m_strCommand =
"deleteUserAccount";
9157 theMessage.m_strNymID = strNymID;
9158 theMessage.m_strServerID = strServerID;
9159 theMessage.SetAcknowledgments(theNym);
9164 theMessage.SignContract(theNym);
9168 theMessage.SaveContract();
9170 bSendCommand =
true;
9171 lReturnValue = lRequestNumber;
9175 otOut <<
"Please enter a NymID (for recipient): ";
9180 strNymID2.OTfgets(std::cin);
9182 otOut <<
"Enter recipient's public key:\n> ";
9184 OTASCIIArmor theArmoredText;
9185 char decode_buffer[200];
9188 decode_buffer[0] = 0;
9190 if (!fgets(decode_buffer,
sizeof(decode_buffer) - 1, stdin)) {
9191 theArmoredText.Concatenate(
"%s\n", decode_buffer);
9198 }
while (strlen(decode_buffer) > 1);
9200 decode_buffer[0] =
'\0';
9201 OTString strPlaintext;
9203 otOut <<
"Please enter a plaintext message, terminate with ~ on a new "
9207 if (!fgets(decode_buffer,
sizeof(decode_buffer), stdin) &&
9208 decode_buffer[0] !=
'~') {
9209 strPlaintext.Concatenate(
"%s", decode_buffer);
9212 }
while (decode_buffer[0] !=
'~');
9215 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
9216 theMessage.m_strRequestNum.Format(
9217 "%lld", lRequestNumber);
9218 theNym.IncrementRequestNum(theNym, strServerID);
9223 theMessage.m_strCommand =
"sendUserMessage";
9224 theMessage.m_strNymID = strNymID;
9225 theMessage.m_strNymID2 = strNymID2;
9226 theMessage.m_strServerID = strServerID;
9227 theMessage.SetAcknowledgments(theNym);
9231 OTEnvelope theEnvelope;
9235 if (theArmoredText.Exists() && !pPubkey->SetPublicKey(theArmoredText)) {
9236 otOut <<
"Failed setting public key.\n";
9238 else if (strPlaintext.Exists() &&
9239 theEnvelope.Seal(*pPubkey, strPlaintext) &&
9240 theEnvelope.GetAsciiArmoredData(theMessage.m_ascPayload)) {
9242 theMessage.SignContract(theNym);
9246 theMessage.SaveContract();
9249 bSendCommand =
true;
9250 lReturnValue = lRequestNumber;
9255 OTMessage* pMessage =
new OTMessage;
9259 pMessage->m_strCommand =
"outmailMessage";
9260 pMessage->m_strNymID = strNymID;
9261 pMessage->m_strNymID2 = strNymID2;
9262 pMessage->m_strServerID = strServerID;
9263 pMessage->m_strRequestNum.Format(
"%lld", lRequestNumber);
9265 pMessage->SetAcknowledgments(theNym);
9269 pMessage->m_ascPayload.SetString(strPlaintext);
9271 pMessage->SignContract(theNym);
9272 pMessage->SaveContract();
9274 theNym.AddOutmail(*pMessage);
9277 OTPseudonym& extraNym = theNym;
9278 theNym.SaveSignedNymfile(extraNym);
9281 otOut <<
"Failed sealing envelope.\n";
9286 otOut <<
"Please enter a NymID: ";
9291 strNymID2.OTfgets(std::cin);
9294 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
9295 theMessage.m_strRequestNum.Format(
9296 "%lld", lRequestNumber);
9297 theNym.IncrementRequestNum(theNym, strServerID);
9302 theMessage.m_strCommand =
"checkUser";
9303 theMessage.m_strNymID = strNymID;
9304 theMessage.m_strNymID2 = strNymID2;
9305 theMessage.m_strServerID = strServerID;
9306 theMessage.SetAcknowledgments(theNym);
9311 theMessage.SignContract(theNym);
9315 theMessage.SaveContract();
9317 bSendCommand =
true;
9318 lReturnValue = lRequestNumber;
9327 OTString strSourceContract;
9329 otOut <<
"Please enter currency contract, terminate with ~ on a new "
9331 char decode_buffer[200];
9334 if (!fgets(decode_buffer,
sizeof(decode_buffer), stdin) &&
9335 decode_buffer[0] !=
'~') {
9336 strSourceContract.Concatenate(
"%s", decode_buffer);
9339 }
while (decode_buffer[0] !=
'~');
9369 OTAssetContract theAssetContract;
9371 if (theAssetContract.LoadContractFromString(strSourceContract)) {
9376 theAssetContract.CalculateContractID(newID);
9377 theAssetContract.SetIdentifier(newID);
9380 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
9381 theMessage.m_strRequestNum.Format(
9382 "%lld", lRequestNumber);
9383 theNym.IncrementRequestNum(theNym, strServerID);
9389 theMessage.m_strCommand =
"issueAssetType";
9390 theMessage.m_strNymID = strNymID;
9391 theMessage.m_strServerID = strServerID;
9392 theMessage.SetAcknowledgments(theNym);
9397 newID.GetString(theMessage.m_strAssetID);
9400 OTString strAssetContract(theAssetContract);
9401 theMessage.m_ascPayload.SetString(strAssetContract);
9404 theMessage.SignContract(theNym);
9408 theMessage.SaveContract();
9410 bSendCommand =
true;
9411 lReturnValue = lRequestNumber;
9416 OTString strFilename(
9417 theMessage.m_strAssetID.Get());
9424 OTAssetContract* pContract =
9425 new OTAssetContract(theMessage.m_strAssetID, strFoldername,
9426 strFilename, theMessage.m_strAssetID);
9435 if (pContract->LoadContractFromString(strSourceContract) &&
9436 pContract->VerifyContract()) {
9438 OTWallet* pWallet =
nullptr;
9440 if (
nullptr != (pWallet = m_pWallet)) {
9441 pWallet->AddAssetContract(*pContract);
9452 pContract =
nullptr;
9464 const OTIdentifier USER_ID(theNym);
9466 OTString strBasketInfo, strNymID(USER_ID);
9467 OTString str_BASKET_CONTRACT_ID, str_MAIN_ACCOUNT_ID, strTemp;
9470 otOut <<
"Enter the basket's Asset Type ID (aka Contract ID): ";
9471 str_BASKET_CONTRACT_ID.OTfgets(std::cin);
9474 otOut <<
"Enter an ACCOUNT ID of yours for an account that has the "
9475 "same asset type: ";
9476 str_MAIN_ACCOUNT_ID.OTfgets(std::cin);
9477 OTIdentifier MAIN_ACCOUNT_ID(str_MAIN_ACCOUNT_ID);
9480 OTString strDirection;
9481 otOut <<
"Are you exchanging in or out? [in]: ";
9482 strDirection.OTfgets(std::cin);
9484 const bool bDirection =
9485 (strDirection.Compare(
"in") || strDirection.Compare(
"In"));
9489 OTString strContractPath(str_BASKET_CONTRACT_ID.Get());
9490 std::unique_ptr<OTAssetContract> pContract(
9491 new OTAssetContract(str_BASKET_CONTRACT_ID, strFoldername,
9492 strContractPath, str_BASKET_CONTRACT_ID));
9495 if (pContract->LoadContract() && pContract->VerifyContract()) {
9502 if (pContract->GetBasketInfo().GetLength() &&
9503 theBasket.LoadContractFromString(pContract->GetBasketInfo())) {
9510 if (theNym.GetTransactionNumCount(SERVER_ID) <
9511 (2 + theBasket.Count())) {
9512 otOut << __FUNCTION__ <<
": Trying to exchange basket: you "
9513 "don't have enough transaction "
9514 "numbers to perform the "
9518 int64_t lStoredTransactionNumber = 0;
9519 bool bGotTransNum = theNym.GetNextTransactionNum(
9520 theNym, strServerID,
9521 lStoredTransactionNumber);
9525 OTTransaction* pTransaction =
9527 USER_ID, MAIN_ACCOUNT_ID, SERVER_ID,
9529 lStoredTransactionNumber);
9538 pTransaction->AddItem(*pItem);
9546 OTAccount* pMainAccount =
9551 std::unique_ptr<OTLedger> pInbox(
9552 pMainAccount->LoadInbox(theNym));
9553 std::unique_ptr<OTLedger> pOutbox(
9554 pMainAccount->LoadOutbox(theNym));
9556 if (
nullptr == pInbox) {
9557 otOut <<
"Failed loading inbox!\n";
9561 theNym.AddTransactionNum(theNym, strServerID,
9562 lStoredTransactionNumber,
9565 else if (
nullptr == pOutbox) {
9566 otOut <<
"Failed loading outbox!\n";
9570 theNym.AddTransactionNum(theNym, strServerID,
9571 lStoredTransactionNumber,
9576 int32_t nTransferMultiple = 0;
9578 Basket theRequestBasket(
9580 theBasket.GetMinimumTransfer());
9582 theRequestBasket.SetExchangingIn(bDirection);
9585 otOut <<
"The minimum transfer amount for this "
9587 << theBasket.GetMinimumTransfer()
9588 <<
". You may only exchange in multiples of "
9589 "it.\nChoose any multiple [1]: ";
9590 strTemp.OTfgets(std::cin);
9591 nTransferMultiple = atoi(strTemp.Get());
9593 if (nTransferMultiple <= 0) nTransferMultiple = 1;
9595 theRequestBasket.SetTransferMultiple(
9602 int64_t lClosingTransactionNo = 0;
9603 theNym.GetNextTransactionNum(
9604 theNym, strServerID,
9605 lClosingTransactionNo);
9607 theRequestBasket.SetClosingNum(
9608 lClosingTransactionNo);
9614 for (int32_t i = 0; i < theBasket.Count(); i++) {
9617 BasketItem* pItem = theBasket.At(i);
9623 OTString str_SUB_CONTRACT_ID(
9624 pItem->SUB_CONTRACT_ID);
9625 otOut <<
"\nBasket currency type (Asset Type) #"
9626 << (i + 1) <<
" is:\n"
9627 << str_SUB_CONTRACT_ID
9628 <<
"\n\nPlease enter your own existing "
9629 "Account ID of the same asset type: ";
9630 OTString str_TEMP_ACCOUNT_ID;
9631 str_TEMP_ACCOUNT_ID.OTfgets(std::cin);
9632 OTIdentifier TEMP_ACCOUNT_ID(
9633 str_TEMP_ACCOUNT_ID);
9662 int64_t lSubClosingTransactionNo =
9665 theNym.GetNextTransactionNum(
9666 theNym, strServerID,
9667 lSubClosingTransactionNo);
9668 theRequestBasket.AddRequestSubContract(
9669 pItem->SUB_CONTRACT_ID, TEMP_ACCOUNT_ID,
9670 lSubClosingTransactionNo);
9675 theRequestBasket.SetRequestAccountID(
9681 theRequestBasket.SignContract(theNym);
9682 theRequestBasket.SaveContractRaw(strBasketInfo);
9684 pItem->SetAttachment(strBasketInfo);
9688 pItem->SignContract(theNym);
9689 pItem->SaveContract();
9695 OTItem* pBalanceItem =
9696 pInbox->GenerateBalanceStatement(
9699 *pTransaction, theNym, *pMainAccount,
9707 pTransaction->AddItem(
9713 pTransaction->SignContract(theNym);
9714 pTransaction->SaveContract();
9717 OTLedger theLedger(USER_ID, MAIN_ACCOUNT_ID,
9719 theLedger.GenerateLedger(
9720 MAIN_ACCOUNT_ID, SERVER_ID,
9724 theLedger.AddTransaction(*pTransaction);
9727 theLedger.SignContract(theNym);
9728 theLedger.SaveContract();
9731 OTString strLedger(theLedger);
9732 OTASCIIArmor ascLedger;
9738 ascLedger.SetString(strLedger);
9742 theNym.GetCurrentRequestNum(strServerID,
9744 theMessage.m_strRequestNum.Format(
9747 theNym.IncrementRequestNum(
9748 theNym, strServerID);
9753 theMessage.m_strCommand =
"notarizeTransactions";
9754 theMessage.m_strNymID = strNymID;
9755 theMessage.m_strServerID = strServerID;
9756 theMessage.SetAcknowledgments(
9761 theMessage.m_strAcctID = str_MAIN_ACCOUNT_ID;
9762 theMessage.m_ascPayload = ascLedger;
9764 OTIdentifier NYMBOX_HASH;
9765 const std::string str_server(strServerID.Get());
9766 const bool bNymboxHash =
9767 theNym.GetNymboxHash(str_server, NYMBOX_HASH);
9770 NYMBOX_HASH.GetString(
9771 theMessage.m_strNymboxHash);
9773 otErr <<
"Failed getting NymboxHash from Nym "
9774 "for server: " << str_server <<
"\n";
9777 theMessage.SignContract(theNym);
9781 theMessage.SaveContract();
9783 bSendCommand =
true;
9784 lReturnValue = lRequestNumber;
9788 otErr <<
"SUPPOSEDLY transaction numbers were "
9789 "available, but the call failed...\n";
9797 otOut <<
"Error loading basket info from asset contract. Are "
9798 "you SURE this is a basket currency?\n";
9802 otOut <<
"Failure loading or verifying " << strContractPath <<
"\n";
9807 OTString strTemp, strBasketInfo;
9810 otOut <<
"How many different asset types will compose this new basket? "
9812 strTemp.OTfgets(std::cin);
9813 int32_t nBasketCount = atoi(strTemp.Get());
9814 if (0 >= nBasketCount) nBasketCount = 2;
9817 otOut <<
"If your basket has a minimum transfer amount of 100, you "
9818 "might have 2 or 3 sub-currencies,\nwith the first being a "
9819 "minimum of 2 gold, the second being a minimum of 50 dollars, "
9820 "and the\nthird being a minimum of 30 silver. In this "
9821 "example, 100 units of the basket currency is\ntransferrable "
9822 "in or out of the basket currency, in return for 2 gold, 50 "
9823 "dollars, and 30 silver.\nAs those are only the *minimum* "
9824 "amounts, you could also transfer (in or out) in *any* "
9825 "multiple of\nthose numbers.\n\n";
9826 otOut <<
"What is the minimum transfer amount for the basket currency "
9829 strTemp.OTfgets(std::cin);
9830 int64_t lMinimumTransferAmount = atoi(strTemp.Get());
9831 if (0 == lMinimumTransferAmount) lMinimumTransferAmount = 100;
9835 Basket theBasket(nBasketCount, lMinimumTransferAmount);
9838 for (int32_t i = 0; i < nBasketCount; i++) {
9839 otOut <<
"Enter contract ID # " << (i + 1) <<
": ";
9841 strTemp.OTfgets(std::cin);
9843 OTIdentifier SUB_CONTRACT_ID(strTemp.Get());
9847 otOut <<
"Enter minimum transfer amount for that asset type: ";
9849 strTemp.OTfgets(std::cin);
9851 lMinimumTransferAmount = atol(strTemp.Get());
9855 theBasket.AddSubContract(SUB_CONTRACT_ID, lMinimumTransferAmount);
9868 theBasket.SignContract(theNym);
9869 theBasket.SaveContractRaw(strBasketInfo);
9891 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
9892 theMessage.m_strRequestNum.Format(
9893 "%lld", lRequestNumber);
9894 theNym.IncrementRequestNum(theNym, strServerID);
9899 theMessage.m_strCommand =
"issueBasket";
9900 theMessage.m_strNymID = strNymID;
9901 theMessage.m_strServerID = strServerID;
9902 theMessage.SetAcknowledgments(theNym);
9906 theMessage.m_ascPayload.SetString(strBasketInfo);
9909 theMessage.SignContract(theNym);
9913 theMessage.SaveContract();
9915 bSendCommand =
true;
9916 lReturnValue = lRequestNumber;
9920 otOut <<
"Please enter an asset type (contract ID): ";
9923 OTString strAssetID;
9924 strAssetID.OTfgets(std::cin);
9927 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
9928 theMessage.m_strRequestNum.Format(
9929 "%lld", lRequestNumber);
9930 theNym.IncrementRequestNum(theNym, strServerID);
9935 theMessage.m_strCommand =
"createAccount";
9936 theMessage.m_strNymID = strNymID;
9937 theMessage.m_strServerID = strServerID;
9938 theMessage.SetAcknowledgments(theNym);
9942 theMessage.m_strAssetID =
9946 theMessage.SignContract(theNym);
9950 theMessage.SaveContract();
9952 bSendCommand =
true;
9953 lReturnValue = lRequestNumber;
9957 OTString strFromAcct;
9959 if (
nullptr == pAccount) {
9960 otOut <<
"Please enter an asset Account ID (FROM acct): ";
9963 strFromAcct.OTfgets(std::cin);
9965 if (strFromAcct.GetLength() < 2)
return (-1);
9967 const OTIdentifier ACCOUNT_ID(strFromAcct);
9969 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
9970 pAccount->GetIdentifier(strFromAcct);
9971 CONTRACT_ID = pAccount->GetAssetTypeID();
9972 CONTRACT_ID.GetString(strContractID);
9975 strFromAcct.Get())) !=
nullptr) {
9976 pAccount->GetIdentifier(strFromAcct);
9977 CONTRACT_ID = pAccount->GetAssetTypeID();
9978 CONTRACT_ID.GetString(strContractID);
9981 otErr <<
"Unable to transfer without a 'FROM' account. Try "
9982 "adding: --myacct ACCOUNT_ID\n";
9987 pAccount->GetIdentifier(strFromAcct);
9988 CONTRACT_ID = pAccount->GetAssetTypeID();
9989 CONTRACT_ID.GetString(strContractID);
9992 if (pAccount->GetPurportedServerID() != SERVER_ID) {
9993 otErr <<
"OTClient::ProcessUserCommand: "
9994 "pAccount->GetPurportedServerID() doesn't match "
9995 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
9999 OTString strRecipientAcct;
10001 if (
nullptr == pHisAcctID) {
10003 <<
"Enter Recipient's asset account ID (no partial IDs here): ";
10007 strRecipientAcct.OTfgets(std::cin);
10009 if (strRecipientAcct.GetLength() < 2)
return (-1);
10012 pHisAcctID->GetString(strRecipientAcct);
10015 OTIdentifier HIS_ACCT_ID(strRecipientAcct);
10017 OTString strAmount;
10018 if (0 == lTransactionAmount) {
10019 otOut <<
"Please enter an amount: ";
10022 strAmount.OTfgets(std::cin);
10025 const int64_t lTotalAmount =
10026 (0 == lTransactionAmount)
10028 (atol(strAmount.Exists() ? strAmount.Get() :
"0"))
10029 : lTransactionAmount;
10031 OTIdentifier ACCT_FROM_ID(strFromAcct), USER_ID(theNym);
10033 int64_t lStoredTransactionNumber = 0;
10034 bool bGotTransNum = theNym.GetNextTransactionNum(
10035 theNym, strServerID, lStoredTransactionNumber);
10040 if (bGotTransNum) {
10044 lStoredTransactionNumber);
10051 pItem->SetAmount(lTotalAmount);
10054 "Just testing the notes...blah blah blah blah blah blah");
10055 pItem->SetNote(strNote);
10058 pItem->SignContract(theNym);
10059 pItem->SaveContract();
10061 pTransaction->AddItem(*pItem);
10065 std::unique_ptr<OTLedger> pInbox(pAccount->LoadInbox(theNym));
10066 std::unique_ptr<OTLedger> pOutbox(pAccount->LoadOutbox(theNym));
10068 if (
nullptr == pInbox) {
10069 otOut <<
"Failed loading inbox!\n";
10073 theNym.AddTransactionNum(theNym, strServerID,
10074 lStoredTransactionNumber,
10077 else if (
nullptr == pOutbox) {
10078 otOut <<
"Failed loading outbox!\n";
10082 theNym.AddTransactionNum(theNym, strServerID,
10083 lStoredTransactionNumber,
10103 OT_ASSERT(
nullptr != pOutboxTransaction);
10105 OTString strItem(*pItem);
10106 pOutboxTransaction->SetReferenceString(
10110 pOutboxTransaction->SetReferenceToNum(
10111 pItem->GetTransactionNum());
10119 pOutbox->AddTransaction(
10120 *pOutboxTransaction);
10126 OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
10127 atol(strAmount.Get()) * (-1), *pTransaction, theNym,
10128 *pAccount, *pOutbox);
10133 pTransaction->AddItem(*pBalanceItem);
10140 pTransaction->SignContract(theNym);
10141 pTransaction->SaveContract();
10144 OTLedger theLedger(USER_ID, ACCT_FROM_ID, SERVER_ID);
10145 theLedger.GenerateLedger(ACCT_FROM_ID, SERVER_ID,
10150 theLedger.AddTransaction(*pTransaction);
10153 theLedger.SignContract(theNym);
10154 theLedger.SaveContract();
10157 OTString strLedger(theLedger);
10158 OTASCIIArmor ascLedger;
10163 ascLedger.SetString(strLedger);
10166 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
10167 theMessage.m_strRequestNum.Format(
10168 "%lld", lRequestNumber);
10169 theNym.IncrementRequestNum(
10170 theNym, strServerID);
10174 theMessage.m_strCommand =
"notarizeTransactions";
10175 theMessage.m_strNymID = strNymID;
10176 theMessage.m_strServerID = strServerID;
10177 theMessage.SetAcknowledgments(
10181 theMessage.m_strAcctID = strFromAcct;
10182 theMessage.m_ascPayload = ascLedger;
10184 OTIdentifier NYMBOX_HASH;
10185 const std::string str_server(strServerID.Get());
10186 const bool bNymboxHash =
10187 theNym.GetNymboxHash(str_server, NYMBOX_HASH);
10190 NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
10192 otErr <<
"Failed getting NymboxHash from Nym for server: "
10193 << str_server <<
"\n";
10196 theMessage.SignContract(theNym);
10200 theMessage.SaveContract();
10202 bSendCommand =
true;
10203 lReturnValue = lRequestNumber;
10208 otOut <<
"No transaction numbers were available. Suggest "
10209 "requesting the server for one.\n";
10216 otOut <<
"Please enter an Asset Type ID: ";
10219 OTString strContractID;
10220 strContractID.OTfgets(std::cin);
10222 const OTIdentifier theTargetID(strContractID);
10224 OTAssetContract* pTargetContract =
10227 if (
nullptr != pTargetContract) {
10228 otOut <<
"Enter the new client-side \"name\" label for that asset "
10232 OTString strNewName;
10233 strNewName.OTfgets(std::cin);
10235 pTargetContract->
SetName(strNewName);
10241 otOut <<
"No Asset Contract found with that ID. Try 'load'.\n";
10249 otOut <<
"Please enter a Server ID: ";
10252 OTString strContractID;
10253 strContractID.OTfgets(std::cin);
10255 const OTIdentifier theTargetID(strContractID);
10257 OTServerContract* pTargetContract =
10260 if (
nullptr != pTargetContract) {
10261 otOut <<
"Enter the new client-side \"name\" label for that "
10262 "transaction server: ";
10265 OTString strNewName;
10266 strNewName.OTfgets(std::cin);
10268 pTargetContract->
SetName(strNewName);
10275 otOut <<
"No Server Contract found with that ID. Try 'load'.\n";
10283 otOut <<
"Please enter a Nym ID: ";
10287 strNymID.OTfgets(std::cin);
10289 const OTIdentifier theTargetNymID(strNymID);
10291 OTPseudonym* pTargetNym = m_pWallet->
GetNymByID(theTargetNymID);
10293 if (
nullptr != pTargetNym) {
10294 otOut <<
"Enter the new client-side \"name\" label for that Nym: ";
10297 OTString strNewName;
10298 strNewName.OTfgets(std::cin);
10300 OTString strOldName(pTargetNym->GetNymName());
10304 if (pTargetNym->SaveSignedNymfile(theNym))
10311 pTargetNym->SetNymName(strOldName);
10314 otOut <<
"No Nym found with that ID. Try 'load'.\n";
10321 otOut <<
"Please enter an asset account ID: ";
10324 OTString strAcctID;
10325 strAcctID.OTfgets(std::cin);
10327 if (strAcctID.GetLength() < 2)
return (-1);
10329 const OTIdentifier theAccountID(strAcctID);
10331 OTAccount* pTheAccount = m_pWallet->
GetAccount(theAccountID);
10333 if (
nullptr != pTheAccount) {
10334 otOut <<
"Enter the new client-side \"name\" label for that "
10338 OTString strNewName;
10339 strNewName.OTfgets(std::cin);
10341 pTheAccount->SetName(strNewName);
10342 pTheAccount->ReleaseSignatures();
10344 pTheAccount->SignContract(theNym);
10345 pTheAccount->SaveAccount();
10350 otOut <<
"No account found with that ID. Try 'load'.\n";
10357 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
10358 theMessage.m_strRequestNum.Format(
10359 "%lld", lRequestNumber);
10360 theNym.IncrementRequestNum(theNym, strServerID);
10365 theMessage.m_strCommand =
"getNymbox";
10366 theMessage.m_strNymID = strNymID;
10367 theMessage.m_strServerID = strServerID;
10368 theMessage.SetAcknowledgments(theNym);
10373 theMessage.SignContract(theNym);
10377 theMessage.SaveContract();
10379 bSendCommand =
true;
10380 lReturnValue = lRequestNumber;
10385 OTString strFromAcct;
10387 if (
nullptr == pAccount) {
10388 otOut <<
"Please enter an asset Account ID (to get its INBOX): ";
10391 strFromAcct.OTfgets(std::cin);
10393 if (strFromAcct.GetLength() < 2)
return (-1);
10395 const OTIdentifier ACCOUNT_ID(strFromAcct);
10397 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
10398 pAccount->GetIdentifier(strFromAcct);
10399 CONTRACT_ID = pAccount->GetAssetTypeID();
10400 CONTRACT_ID.GetString(strContractID);
10403 strFromAcct.Get())) !=
nullptr) {
10404 pAccount->GetIdentifier(strFromAcct);
10405 CONTRACT_ID = pAccount->GetAssetTypeID();
10406 CONTRACT_ID.GetString(strContractID);
10409 otErr <<
"Unable to download Inbox without an account ID. Try "
10410 "adding: --myacct ACCOUNT_ID\n";
10415 pAccount->GetIdentifier(strFromAcct);
10416 CONTRACT_ID = pAccount->GetAssetTypeID();
10417 CONTRACT_ID.GetString(strContractID);
10420 if (pAccount->GetPurportedServerID() != SERVER_ID) {
10421 otErr <<
"OTClient::ProcessUserCommand: "
10422 "pAccount->GetPurportedServerID() doesn't match "
10423 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
10427 OTString strAcctID;
10428 OTIdentifier theAccountID;
10430 pAccount->GetIdentifier(theAccountID);
10431 theAccountID.GetString(strAcctID);
10434 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
10435 theMessage.m_strRequestNum.Format(
10436 "%lld", lRequestNumber);
10437 theNym.IncrementRequestNum(theNym, strServerID);
10442 theMessage.m_strCommand =
"getInbox";
10443 theMessage.m_strNymID = strNymID;
10444 theMessage.m_strServerID = strServerID;
10445 theMessage.SetAcknowledgments(theNym);
10449 theMessage.m_strAcctID = strAcctID;
10452 theMessage.SignContract(theNym);
10456 theMessage.SaveContract();
10458 bSendCommand =
true;
10459 lReturnValue = lRequestNumber;
10464 OTString strFromAcct;
10466 if (
nullptr == pAccount) {
10467 otOut <<
"Please enter an asset Account ID (to get its OUTBOX): ";
10470 strFromAcct.OTfgets(std::cin);
10472 if (strFromAcct.GetLength() < 2)
return (-1);
10474 const OTIdentifier ACCOUNT_ID(strFromAcct);
10476 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
10477 pAccount->GetIdentifier(strFromAcct);
10478 CONTRACT_ID = pAccount->GetAssetTypeID();
10479 CONTRACT_ID.GetString(strContractID);
10482 strFromAcct.Get())) !=
nullptr) {
10483 pAccount->GetIdentifier(strFromAcct);
10484 CONTRACT_ID = pAccount->GetAssetTypeID();
10485 CONTRACT_ID.GetString(strContractID);
10488 otErr <<
"Unable to download outbox without account ID. Try "
10489 "adding: --myacct ACCOUNT_ID\n";
10494 pAccount->GetIdentifier(strFromAcct);
10495 CONTRACT_ID = pAccount->GetAssetTypeID();
10496 CONTRACT_ID.GetString(strContractID);
10499 if (pAccount->GetPurportedServerID() != SERVER_ID) {
10500 otErr <<
"OTClient::ProcessUserCommand: "
10501 "pAccount->GetPurportedServerID() doesn't match "
10502 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
10506 OTString strAcctID;
10507 OTIdentifier theAccountID;
10509 pAccount->GetIdentifier(theAccountID);
10510 theAccountID.GetString(strAcctID);
10513 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
10514 theMessage.m_strRequestNum.Format(
10515 "%lld", lRequestNumber);
10516 theNym.IncrementRequestNum(theNym, strServerID);
10521 theMessage.m_strCommand =
"getOutbox";
10522 theMessage.m_strNymID = strNymID;
10523 theMessage.m_strServerID = strServerID;
10524 theMessage.SetAcknowledgments(theNym);
10528 theMessage.m_strAcctID = strAcctID;
10531 theMessage.SignContract(theNym);
10535 theMessage.SaveContract();
10537 bSendCommand =
true;
10538 lReturnValue = lRequestNumber;
10570 const OTIdentifier MY_NYM_ID(theNym);
10573 OTLedger theNymbox(MY_NYM_ID, MY_NYM_ID, SERVER_ID);
10575 bool bSuccess =
false;
10576 bool bLoadedNymbox = theNymbox.LoadNymbox();
10577 bool bVerifiedNymbox =
10578 bLoadedNymbox ? theNymbox.VerifyAccount(theNym) :
false;
10579 bool bIsEmpty = theNymbox.GetTransactionCount() < 1;
10581 if (!bLoadedNymbox)
10582 otOut <<
"OTClient::ProcessUserCommand::processEntireNymbox: "
10583 "Failed loading Nymbox: " << strNymID <<
" \n";
10584 else if (!bVerifiedNymbox)
10585 otOut <<
"OTClient::ProcessUserCommand::processEntireNymbox: "
10586 "Failed verifying Nymbox: " << strNymID <<
" \n";
10587 else if (!bIsEmpty)
10589 theNym, theMessage);
10593 otOut <<
"OTClient::ProcessUserCommand::processEntireNymbox: "
10594 "Nymbox (" << strNymID
10595 <<
") is empty (so, skipping processNymbox.)\n";
10597 otOut <<
"OTClient::ProcessUserCommand::processEntireNymbox: "
10598 "Failed trying to accept the entire Nymbox.\n";
10602 theMessage.SignContract(theNym);
10606 theMessage.SaveContract();
10608 bSendCommand =
true;
10617 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
10618 theMessage.m_strRequestNum.Format(
10619 "%lld", lRequestNumber);
10620 theNym.IncrementRequestNum(theNym, strServerID);
10625 theMessage.m_strCommand =
"processNymbox";
10626 theMessage.m_strNymID = strNymID;
10627 theMessage.m_strServerID = strServerID;
10628 theMessage.SetAcknowledgments(theNym);
10632 OTIdentifier EXISTING_NYMBOX_HASH;
10633 const std::string str_server_id(strServerID.Get());
10635 const bool bSuccess =
10636 theNym.GetNymboxHash(str_server_id, EXISTING_NYMBOX_HASH);
10639 EXISTING_NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
10642 theMessage.SignContract(theNym);
10646 theMessage.SaveContract();
10648 bSendCommand =
true;
10649 lReturnValue = lRequestNumber;
10657 const OTIdentifier MY_NYM_ID(theNym);
10659 OTString strFromAcct;
10661 if (
nullptr == pAccount) {
10663 <<
"Please enter an asset Account ID (to PROCESS its INBOX): ";
10666 strFromAcct.OTfgets(std::cin);
10668 if (strFromAcct.GetLength() < 2)
return (-1);
10670 const OTIdentifier ACCOUNT_ID(strFromAcct);
10672 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
10673 pAccount->GetIdentifier(strFromAcct);
10674 CONTRACT_ID = pAccount->GetAssetTypeID();
10675 CONTRACT_ID.GetString(strContractID);
10678 strFromAcct.Get())) !=
nullptr) {
10679 pAccount->GetIdentifier(strFromAcct);
10680 CONTRACT_ID = pAccount->GetAssetTypeID();
10681 CONTRACT_ID.GetString(strContractID);
10684 otErr <<
"Unable to process inbox without account ID. Try "
10685 "adding: --myacct ACCOUNT_ID\n";
10690 pAccount->GetIdentifier(strFromAcct);
10691 CONTRACT_ID = pAccount->GetAssetTypeID();
10692 CONTRACT_ID.GetString(strContractID);
10695 if (pAccount->GetPurportedServerID() != SERVER_ID) {
10696 otErr <<
"OTClient::ProcessUserCommand: "
10697 "pAccount->GetPurportedServerID() doesn't match "
10698 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
10702 OTIdentifier theAccountID;
10703 pAccount->GetIdentifier(theAccountID);
10706 OTLedger theInbox(MY_NYM_ID, theAccountID, SERVER_ID);
10708 bool bLoadedInbox = theInbox.LoadInbox();
10710 bool bVerifiedInbox =
10711 (bLoadedInbox ? theInbox.VerifyAccount(theNym) :
false);
10715 bool bSuccess = (bLoadedInbox && bVerifiedInbox &&
10717 theNym, theMessage, *pAccount));
10722 theMessage.SignContract(theNym);
10726 theMessage.SaveContract();
10728 bSendCommand =
true;
10731 otOut <<
"OTClient::processEntireInbox: Failure Inbox: Loading ("
10732 << (bLoadedInbox ?
"Success" :
"Failure") <<
"), verifying ("
10733 << (bVerifiedInbox ?
"Success" :
"Failure")
10734 <<
"), or accepting (" << (bSuccess ?
"Success" :
"Failure")
10735 <<
") entire Inbox.\n";
10744 OTString strFromAcct;
10746 if (
nullptr == pAccount) {
10748 <<
"Please enter an asset Account ID (to PROCESS its INBOX): ";
10751 strFromAcct.OTfgets(std::cin);
10753 if (strFromAcct.GetLength() < 2)
return (-1);
10755 const OTIdentifier ACCOUNT_ID(strFromAcct);
10757 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
10758 pAccount->GetIdentifier(strFromAcct);
10759 CONTRACT_ID = pAccount->GetAssetTypeID();
10760 CONTRACT_ID.GetString(strContractID);
10763 strFromAcct.Get())) !=
nullptr) {
10764 pAccount->GetIdentifier(strFromAcct);
10765 CONTRACT_ID = pAccount->GetAssetTypeID();
10766 CONTRACT_ID.GetString(strContractID);
10769 otErr <<
"Unable to process inbox without account ID. Try "
10770 "adding: --myacct ACCOUNT_ID\n";
10775 pAccount->GetIdentifier(strFromAcct);
10776 CONTRACT_ID = pAccount->GetAssetTypeID();
10777 CONTRACT_ID.GetString(strContractID);
10780 if (pAccount->GetPurportedServerID() != SERVER_ID) {
10781 otErr <<
"OTClient::ProcessUserCommand: "
10782 "pAccount->GetPurportedServerID() doesn't match "
10783 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
10787 OTString strAcctID;
10788 OTIdentifier theAccountID;
10790 pAccount->GetIdentifier(theAccountID);
10791 theAccountID.GetString(strAcctID);
10806 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
10807 theMessage.m_strRequestNum.Format(
10808 "%lld", lRequestNumber);
10809 theNym.IncrementRequestNum(theNym, strServerID);
10814 theMessage.m_strCommand =
"processInbox";
10815 theMessage.m_strNymID = strNymID;
10816 theMessage.m_strServerID = strServerID;
10817 theMessage.SetAcknowledgments(theNym);
10821 theMessage.m_strAcctID = strAcctID;
10823 OTIdentifier NYMBOX_HASH;
10824 const std::string str_server(strServerID.Get());
10825 const bool bNymboxHash = theNym.GetNymboxHash(str_server, NYMBOX_HASH);
10828 NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
10830 otErr <<
"Failed getting NymboxHash from Nym for server: "
10831 << str_server <<
"\n";
10834 theMessage.SignContract(theNym);
10838 theMessage.SaveContract();
10840 bSendCommand =
true;
10841 lReturnValue = lRequestNumber;
10845 OTString strFromAcct;
10847 if (
nullptr == pAccount) {
10848 otOut <<
"Please enter an asset Account ID (to download its "
10849 "intermediary file): ";
10852 strFromAcct.OTfgets(std::cin);
10854 if (strFromAcct.GetLength() < 2)
return (-1);
10856 const OTIdentifier ACCOUNT_ID(strFromAcct);
10858 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
10859 pAccount->GetIdentifier(strFromAcct);
10860 CONTRACT_ID = pAccount->GetAssetTypeID();
10861 CONTRACT_ID.GetString(strContractID);
10864 strFromAcct.Get())) !=
nullptr) {
10865 pAccount->GetIdentifier(strFromAcct);
10866 CONTRACT_ID = pAccount->GetAssetTypeID();
10867 CONTRACT_ID.GetString(strContractID);
10870 otErr <<
"Unable to download account without account ID. Try "
10871 "adding: --myacct ACCOUNT_ID\n";
10876 pAccount->GetIdentifier(strFromAcct);
10877 CONTRACT_ID = pAccount->GetAssetTypeID();
10878 CONTRACT_ID.GetString(strContractID);
10881 if (pAccount->GetPurportedServerID() != SERVER_ID) {
10882 otErr <<
"OTClient::ProcessUserCommand: "
10883 "pAccount->GetPurportedServerID() doesn't match "
10884 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
10888 OTString strAcctID;
10889 OTIdentifier theAccountID;
10891 pAccount->GetIdentifier(theAccountID);
10892 theAccountID.GetString(strAcctID);
10895 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
10896 theMessage.m_strRequestNum.Format(
10897 "%lld", lRequestNumber);
10898 theNym.IncrementRequestNum(theNym, strServerID);
10903 theMessage.m_strCommand =
"getAccount";
10904 theMessage.m_strNymID = strNymID;
10905 theMessage.m_strServerID = strServerID;
10906 theMessage.SetAcknowledgments(theNym);
10910 theMessage.m_strAcctID = strAcctID;
10913 theMessage.SignContract(theNym);
10917 theMessage.SaveContract();
10919 bSendCommand =
true;
10920 lReturnValue = lRequestNumber;
10924 otOut <<
"Please enter an asset type ID: ";
10927 OTString strAssetID;
10928 strAssetID.OTfgets(std::cin);
10930 if (strAssetID.GetLength() < 2)
return (-1);
10933 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
10934 theMessage.m_strRequestNum.Format(
10935 "%lld", lRequestNumber);
10936 theNym.IncrementRequestNum(theNym, strServerID);
10941 theMessage.m_strCommand =
"getContract";
10942 theMessage.m_strNymID = strNymID;
10943 theMessage.m_strServerID = strServerID;
10944 theMessage.SetAcknowledgments(theNym);
10948 theMessage.m_strAssetID = strAssetID;
10951 theMessage.SignContract(theNym);
10955 theMessage.SaveContract();
10957 bSendCommand =
true;
10958 lReturnValue = lRequestNumber;
10962 otOut <<
"Please enter an asset type ID: ";
10965 OTString strAssetID;
10966 strAssetID.OTfgets(std::cin);
10968 if (strAssetID.GetLength() < 2)
return (-1);
10971 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
10972 theMessage.m_strRequestNum.Format(
10973 "%lld", lRequestNumber);
10974 theNym.IncrementRequestNum(theNym, strServerID);
10979 theMessage.m_strCommand =
"getMint";
10980 theMessage.m_strNymID = strNymID;
10981 theMessage.m_strServerID = strServerID;
10982 theMessage.SetAcknowledgments(theNym);
10986 theMessage.m_strAssetID = strAssetID;
10989 theMessage.SignContract(theNym);
10993 theMessage.SaveContract();
10995 bSendCommand =
true;
10996 lReturnValue = lRequestNumber;
11000 OTString strFromAcct;
11002 if (
nullptr == pAccount) {
11003 otOut <<
"Please enter an asset Account ID to deposit your tokens "
11007 strFromAcct.OTfgets(std::cin);
11009 if (strFromAcct.GetLength() < 2)
return (-1);
11011 const OTIdentifier ACCOUNT_ID(strFromAcct);
11013 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
11014 pAccount->GetIdentifier(strFromAcct);
11015 CONTRACT_ID = pAccount->GetAssetTypeID();
11016 CONTRACT_ID.GetString(strContractID);
11019 strFromAcct.Get())) !=
nullptr) {
11020 pAccount->GetIdentifier(strFromAcct);
11021 CONTRACT_ID = pAccount->GetAssetTypeID();
11022 CONTRACT_ID.GetString(strContractID);
11025 otErr <<
"Unable to deposit tokens without an account. Try "
11026 "adding: --myacct ACCOUNT_ID\n";
11031 pAccount->GetIdentifier(strFromAcct);
11032 CONTRACT_ID = pAccount->GetAssetTypeID();
11033 CONTRACT_ID.GetString(strContractID);
11036 if (pAccount->GetPurportedServerID() != SERVER_ID) {
11037 otErr <<
"OTClient::ProcessUserCommand: "
11038 "pAccount->GetPurportedServerID() doesn't match "
11039 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
11043 const OTIdentifier ACCT_FROM_ID(strFromAcct), USER_ID(theNym);
11045 Purse thePurse(SERVER_ID, CONTRACT_ID);
11047 const OTPseudonym* pServerNym = theServer.GetContractPublicNym();
11049 int64_t lStoredTransactionNumber = 0;
11050 bool bGotTransNum =
false;
11052 std::unique_ptr<OTLedger> pInbox(pAccount->LoadInbox(theNym));
11053 std::unique_ptr<OTLedger> pOutbox(pAccount->LoadOutbox(theNym));
11055 if (
nullptr == pInbox) {
11056 otOut <<
"Failed loading inbox!\n";
11060 if (
nullptr == pOutbox) {
11061 otOut <<
"Failed loading outbox!\n";
11065 bGotTransNum = theNym.GetNextTransactionNum(theNym, strServerID,
11066 lStoredTransactionNumber);
11067 if (!bGotTransNum) {
11068 otOut <<
"No Transaction Numbers were available. Try requesting "
11069 "the server for a new one.\n";
11076 theNym.AddTransactionNum(theNym, strServerID,
11077 lStoredTransactionNumber,
11082 bool bSuccess =
false;
11087 lStoredTransactionNumber);
11094 OTString strNote(
"Deposit this cash, please!");
11095 pItem->SetNote(strNote);
11097 otOut <<
"How many tokens would you like to deposit? ";
11098 OTString strTokenCount;
11099 strTokenCount.OTfgets(std::cin);
11100 const int32_t nTokenCount = atoi(strTokenCount.Get());
11102 OTNym_or_SymmetricKey theNymAsOwner(theNym),
11103 theServerNymAsOwner(*pServerNym);
11105 for (int32_t nTokenIndex = 1; nTokenIndex <= nTokenCount;
11107 otOut <<
"Please enter plaintext token # " << nTokenIndex
11108 <<
"; terminate with ~ on a new line:\n> ";
11110 char decode_buffer[200];
11114 decode_buffer[0] = 0;
11116 if (!fgets(decode_buffer,
sizeof(decode_buffer) - 1, stdin) &&
11117 (decode_buffer[0] !=
'~')) {
11118 strToken.Concatenate(
"%s", decode_buffer);
11125 }
while (decode_buffer[0] !=
'~');
11132 std::unique_ptr<Token> pToken(
11136 if (
nullptr != pToken)
11149 pToken->ReassignOwnership(theNymAsOwner,
11150 theServerNymAsOwner)) {
11151 otErr <<
"Error re-assigning ownership of token (to "
11157 otLog3 <<
"Success re-assigning ownership of token (to "
11162 pToken->ReleaseSignatures();
11163 pToken->SignContract(theNym);
11164 pToken->SaveContract();
11166 thePurse.Push(theServerNymAsOwner, *pToken);
11168 int64_t lTemp = pItem->GetAmount();
11169 pItem->SetAmount(lTemp + pToken->GetDenomination());
11173 otErr <<
"Error loading token from string.\n";
11178 thePurse.SignContract(theNym);
11179 thePurse.SaveContract();
11183 thePurse.SaveContractRaw(strPurse);
11186 pItem->SetAttachment(
11190 pItem->SignContract(theNym);
11191 pItem->SaveContract();
11195 pTransaction->AddItem(*pItem);
11203 OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
11204 pItem->GetAmount(), *pTransaction, theNym, *pAccount, *pOutbox);
11209 pTransaction->AddItem(
11216 pTransaction->SignContract(theNym);
11217 pTransaction->SaveContract();
11220 OTLedger theLedger(USER_ID, ACCT_FROM_ID, SERVER_ID);
11221 theLedger.GenerateLedger(ACCT_FROM_ID, SERVER_ID,
11225 theLedger.AddTransaction(*pTransaction);
11230 theLedger.SignContract(theNym);
11231 theLedger.SaveContract();
11234 OTString strLedger(theLedger);
11235 OTASCIIArmor ascLedger(strLedger);
11240 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
11241 theMessage.m_strRequestNum.Format(
11242 "%lld", lRequestNumber);
11243 theNym.IncrementRequestNum(theNym, strServerID);
11249 theMessage.m_strCommand =
"notarizeTransactions";
11250 theMessage.m_strNymID = strNymID;
11251 theMessage.m_strServerID = strServerID;
11252 theMessage.SetAcknowledgments(theNym);
11257 theMessage.m_strAcctID = strFromAcct;
11258 theMessage.m_ascPayload = ascLedger;
11260 OTIdentifier NYMBOX_HASH;
11261 const std::string str_server(strServerID.Get());
11262 const bool bNymboxHash =
11263 theNym.GetNymboxHash(str_server, NYMBOX_HASH);
11266 NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
11268 otErr <<
"Failed getting NymboxHash from Nym for server: "
11269 << str_server <<
"\n";
11272 theMessage.SignContract(theNym);
11276 theMessage.SaveContract();
11278 bSendCommand =
true;
11279 lReturnValue = lRequestNumber;
11285 theNym.AddTransactionNum(theNym, strServerID,
11286 lStoredTransactionNumber,
11291 delete pTransaction;
11292 pTransaction =
nullptr;
11297 OTString strFromAcct;
11299 if (
nullptr == pAccount) {
11300 otOut <<
"Please enter an asset Account ID: ";
11303 strFromAcct.OTfgets(std::cin);
11305 if (strFromAcct.GetLength() < 2)
return (-1);
11307 const OTIdentifier ACCOUNT_ID(strFromAcct);
11309 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
11310 pAccount->GetIdentifier(strFromAcct);
11311 CONTRACT_ID = pAccount->GetAssetTypeID();
11312 CONTRACT_ID.GetString(strContractID);
11315 strFromAcct.Get())) !=
nullptr) {
11316 pAccount->GetIdentifier(strFromAcct);
11317 CONTRACT_ID = pAccount->GetAssetTypeID();
11318 CONTRACT_ID.GetString(strContractID);
11321 otErr <<
"Unable to deposit without an account. Try adding: "
11322 "--myacct ACCOUNT_ID\n";
11327 pAccount->GetIdentifier(strFromAcct);
11328 CONTRACT_ID = pAccount->GetAssetTypeID();
11329 CONTRACT_ID.GetString(strContractID);
11332 if (pAccount->GetPurportedServerID() != SERVER_ID) {
11333 otErr <<
"OTClient::ProcessUserCommand: "
11334 "pAccount->GetPurportedServerID() doesn't match "
11335 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
11341 const OTIdentifier ACCT_FROM_ID(strFromAcct), USER_ID(theNym);
11343 Purse thePurse(SERVER_ID, CONTRACT_ID);
11345 const OTPseudonym* pServerNym = theServer.GetContractPublicNym();
11347 Purse theSourcePurse(thePurse);
11349 OTString strAssetTypeID;
11362 if (
nullptr == pMyAssetContract) {
11363 OTString strSourcePurse;
11365 otOut <<
"Please enter a plaintext purse (of the same asset type "
11366 "as the account), \nand terminate with a ~ (tilde "
11367 "character) on a new line:\n> ";
11368 char decode_buffer[200];
11372 decode_buffer[0] = 0;
11374 if (!fgets(decode_buffer,
sizeof(decode_buffer) - 1, stdin) &&
11375 (decode_buffer[0] !=
'~')) {
11376 strSourcePurse.Concatenate(
"%s", decode_buffer);
11383 }
while (decode_buffer[0] !=
'~');
11386 theSourcePurse.LoadContractFromString(strSourcePurse)) {
11387 otOut <<
"Failure trying to load purse from string provided by "
11394 theSourcePurse.GetAssetID().GetString(strAssetTypeID);
11397 pMyAssetContract->GetIdentifier(strAssetTypeID);
11399 bool bLoadedSourcePurse = theSourcePurse.LoadPurse(
11400 strServerID.Get(), strNymID.Get(), strAssetTypeID.Get());
11402 if (!bLoadedSourcePurse) {
11403 otOut <<
"Deposit purse: Failure trying to load purse from "
11404 "local storage:\nServer " << strServerID <<
" Nym "
11405 << strNymID <<
" Asset Type " << strAssetTypeID <<
"\n";
11409 otOut <<
"WARNING: This operation is very low-level. Once you "
11410 "deposit the purse in local storage,\nyou need to "
11411 "erase the purse file from local storage, since the "
11412 "tokens within it are\nall spent. (Otherwise, when "
11413 "you withdraw again, good tokens would be mixed in "
11414 "with\nthe spent ones, and then you'll have to sit "
11415 "there depositing them one-by-one, in order\nto sort "
11416 "it all out.\n (So just use the GUI and save yourself "
11417 "the trouble.)\n\nDeposit purse: using purse from "
11418 "local storage.\n Server " << strServerID <<
" Nym "
11419 << strNymID <<
" Asset Type " << strAssetTypeID <<
"\n";
11421 theSourcePurse.GetAssetID().GetString(strAssetTypeID);
11426 const OTIdentifier ASSET_TYPE_ID(strAssetTypeID);
11428 if (ASSET_TYPE_ID != CONTRACT_ID) {
11429 otOut <<
"Asset ID on purse didn't match asset ID on account. "
11430 "\nTry: --myacct ACCT_ID (to specify a different "
11431 "account.)\nTo use the purse in local storage, try: "
11432 "--mypurse ASSET_TYPE_ID\nFYI, if you PREFER to provide "
11433 "the purse from user input, OT *will* ask you to\ninput a "
11434 "purse when doing this, just as long as --mypurse is NOT "
11435 "provided. (And\nthat includes the defaultmypurse value "
11436 "stored in ~/.ot/command-line-ot.opt)\n\n";
11446 int64_t lStoredTransactionNumber = 0;
11447 bool bGotTransNum =
false;
11449 std::unique_ptr<OTLedger> pInbox(pAccount->LoadInbox(theNym));
11450 std::unique_ptr<OTLedger> pOutbox(pAccount->LoadOutbox(theNym));
11452 if (
nullptr == pInbox) {
11453 otOut <<
"Failed loading inbox!\n";
11457 if (
nullptr == pOutbox) {
11458 otOut <<
"Failed loading outbox!\n";
11462 bGotTransNum = theNym.GetNextTransactionNum(theNym, strServerID,
11463 lStoredTransactionNumber);
11464 if (!bGotTransNum) {
11465 otOut <<
"No Transaction Numbers were available. Try requesting "
11466 "the server for a new one.\n";
11473 theNym.AddTransactionNum(theNym, strServerID,
11474 lStoredTransactionNumber,
11479 bool bSuccess =
false;
11484 lStoredTransactionNumber);
11491 OTString strNote(
"Deposit this cash, please!");
11492 pItem->SetNote(strNote);
11494 OTNym_or_SymmetricKey theNymAsOwner(theNym),
11495 theServerNymAsOwner(*pServerNym);
11497 while (!theSourcePurse.IsEmpty()) {
11498 std::unique_ptr<Token> pToken(theSourcePurse.Pop(theNym));
11515 pToken->ReassignOwnership(theNymAsOwner,
11516 theServerNymAsOwner)) {
11517 otErr <<
"Error re-assigning ownership of token (to "
11523 otLog3 <<
"Success re-assigning ownership of token (to "
11528 pToken->ReleaseSignatures();
11529 pToken->SignContract(theNym);
11530 pToken->SaveContract();
11532 thePurse.Push(theServerNymAsOwner,
11535 int64_t lTemp = pItem->GetAmount();
11538 pToken->GetDenomination());
11542 otErr <<
"Error loading token from purse.\n";
11549 thePurse.SignContract(theNym);
11550 thePurse.SaveContract();
11555 thePurse.SaveContractRaw(strPurse);
11558 pItem->SetAttachment(
11562 pItem->SignContract(theNym);
11563 pItem->SaveContract();
11567 pTransaction->AddItem(*pItem);
11575 OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
11576 pItem->GetAmount(), *pTransaction, theNym, *pAccount, *pOutbox);
11581 pTransaction->AddItem(
11588 pTransaction->SignContract(theNym);
11589 pTransaction->SaveContract();
11592 OTLedger theLedger(USER_ID, ACCT_FROM_ID, SERVER_ID);
11593 theLedger.GenerateLedger(ACCT_FROM_ID, SERVER_ID,
11597 theLedger.AddTransaction(*pTransaction);
11602 theLedger.SignContract(theNym);
11603 theLedger.SaveContract();
11606 OTString strLedger(theLedger);
11607 OTASCIIArmor ascLedger(strLedger);
11612 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
11613 theMessage.m_strRequestNum.Format(
11614 "%lld", lRequestNumber);
11615 theNym.IncrementRequestNum(theNym, strServerID);
11621 theMessage.m_strCommand =
"notarizeTransactions";
11622 theMessage.m_strNymID = strNymID;
11623 theMessage.m_strServerID = strServerID;
11624 theMessage.SetAcknowledgments(theNym);
11629 theMessage.m_strAcctID = strFromAcct;
11630 theMessage.m_ascPayload = ascLedger;
11632 OTIdentifier NYMBOX_HASH;
11633 const std::string str_server(strServerID.Get());
11634 const bool bNymboxHash =
11635 theNym.GetNymboxHash(str_server, NYMBOX_HASH);
11638 NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
11640 otErr <<
"Failed getting NymboxHash from Nym for server: "
11641 << str_server <<
"\n";
11644 theMessage.SignContract(theNym);
11648 theMessage.SaveContract();
11650 bSendCommand =
true;
11651 lReturnValue = lRequestNumber;
11656 theNym.AddTransactionNum(theNym, strServerID,
11657 lStoredTransactionNumber,
11662 delete pTransaction;
11663 pTransaction =
nullptr;
11669 OTString strFromAcct;
11671 if (
nullptr == pAccount) {
11672 otOut <<
"Please enter an asset Account ID (to deposit to): ";
11675 strFromAcct.OTfgets(std::cin);
11677 if (strFromAcct.GetLength() < 2)
return (-1);
11679 const OTIdentifier ACCOUNT_ID(strFromAcct);
11681 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
11682 pAccount->GetIdentifier(strFromAcct);
11683 CONTRACT_ID = pAccount->GetAssetTypeID();
11684 CONTRACT_ID.GetString(strContractID);
11687 strFromAcct.Get())) !=
nullptr) {
11688 pAccount->GetIdentifier(strFromAcct);
11689 CONTRACT_ID = pAccount->GetAssetTypeID();
11690 CONTRACT_ID.GetString(strContractID);
11693 otErr <<
"Unable to deposit without an account. Try adding: "
11694 "--myacct ACCOUNT_ID\n";
11699 pAccount->GetIdentifier(strFromAcct);
11700 CONTRACT_ID = pAccount->GetAssetTypeID();
11701 CONTRACT_ID.GetString(strContractID);
11704 if (pAccount->GetPurportedServerID() != SERVER_ID) {
11705 otErr <<
"OTClient::ProcessUserCommand: "
11706 "pAccount->GetPurportedServerID() doesn't match "
11707 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
11711 const OTIdentifier ACCT_FROM_ID(strFromAcct), USER_ID(theNym);
11713 OTCheque theCheque(SERVER_ID, CONTRACT_ID);
11715 otOut <<
"Please enter plaintext cheque, terminate with ~ on a new "
11717 OTString strCheque;
11718 char decode_buffer[200];
11722 decode_buffer[0] = 0;
11724 if (!fgets(decode_buffer,
sizeof(decode_buffer) - 1, stdin) &&
11725 (decode_buffer[0] !=
'~')) {
11726 strCheque.Concatenate(
"%s", decode_buffer);
11733 }
while (decode_buffer[0] !=
'~');
11735 int64_t lStoredTransactionNumber = 0;
11736 bool bGotTransNum = theNym.GetNextTransactionNum(
11737 theNym, strServerID, lStoredTransactionNumber);
11739 if (!bGotTransNum) {
11740 otOut <<
"No Transaction Numbers were available. Try requesting "
11741 "the server for a new one.\n";
11743 else if (theCheque.LoadContractFromString(strCheque)) {
11744 if (theCheque.HasRecipient() &&
11745 (theCheque.GetRecipientUserID() != USER_ID)) {
11746 const OTString strRecipientNym(theCheque.GetRecipientUserID());
11747 otOut <<
"This cheque is made out to the Nym: "
11749 <<
" (and that is NOT you, so you can't deposit it!)\n "
11750 "You are: " << strNymID <<
" \n";
11753 theNym.AddTransactionNum(theNym, strServerID,
11754 lStoredTransactionNumber,
11760 OTTransaction* pTransaction =
11762 USER_ID, ACCT_FROM_ID, SERVER_ID,
11770 OTString strNote(
"Deposit this cheque, please!");
11771 pItem->SetNote(strNote);
11773 strCheque.Release();
11774 theCheque.SaveContractRaw(strCheque);
11778 pItem->SetAttachment(strCheque);
11782 pItem->SignContract(theNym);
11783 pItem->SaveContract();
11787 pTransaction->AddItem(*pItem);
11791 std::unique_ptr<OTLedger> pInbox(pAccount->LoadInbox(theNym));
11792 std::unique_ptr<OTLedger> pOutbox(pAccount->LoadOutbox(theNym));
11794 if (
nullptr == pInbox) {
11795 otOut <<
"Failed loading inbox!\n";
11799 theNym.AddTransactionNum(theNym, strServerID,
11800 lStoredTransactionNumber,
11803 else if (
nullptr == pOutbox) {
11804 otOut <<
"Failed loading outbox!\n";
11808 theNym.AddTransactionNum(theNym, strServerID,
11809 lStoredTransactionNumber,
11817 OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
11818 theCheque.GetAmount(), *pTransaction, theNym, *pAccount,
11824 pTransaction->AddItem(*pBalanceItem);
11831 pTransaction->SignContract(theNym);
11832 pTransaction->SaveContract();
11835 OTLedger theLedger(USER_ID, ACCT_FROM_ID, SERVER_ID);
11836 theLedger.GenerateLedger(
11837 ACCT_FROM_ID, SERVER_ID,
11840 theLedger.AddTransaction(*pTransaction);
11847 theLedger.SignContract(theNym);
11848 theLedger.SaveContract();
11851 OTString strLedger(theLedger);
11852 OTASCIIArmor ascLedger(strLedger);
11855 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
11856 theMessage.m_strRequestNum.Format(
11857 "%lld", lRequestNumber);
11858 theNym.IncrementRequestNum(
11859 theNym, strServerID);
11863 theMessage.m_strCommand =
"notarizeTransactions";
11864 theMessage.m_strNymID = strNymID;
11865 theMessage.m_strServerID = strServerID;
11866 theMessage.SetAcknowledgments(
11871 theMessage.m_strAcctID = strFromAcct;
11872 theMessage.m_ascPayload = ascLedger;
11874 OTIdentifier NYMBOX_HASH;
11875 const std::string str_server(strServerID.Get());
11876 const bool bNymboxHash =
11877 theNym.GetNymboxHash(str_server, NYMBOX_HASH);
11880 NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
11883 <<
"Failed getting NymboxHash from Nym for server: "
11884 << str_server <<
"\n";
11887 theMessage.SignContract(theNym);
11891 theMessage.SaveContract();
11893 bSendCommand =
true;
11894 lReturnValue = lRequestNumber;
11903 theNym.AddTransactionNum(theNym, strServerID,
11904 lStoredTransactionNumber,
11913 OTString strFromAcct;
11915 if (
nullptr == pAccount) {
11916 otOut <<
"This is like a banker's cheque, aka cashier's "
11917 "cheque.\nPlease enter an asset Account ID (FROM acct): ";
11920 strFromAcct.OTfgets(std::cin);
11922 if (strFromAcct.GetLength() < 2)
return (-1);
11924 const OTIdentifier ACCOUNT_ID(strFromAcct);
11926 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
11927 pAccount->GetIdentifier(strFromAcct);
11928 CONTRACT_ID = pAccount->GetAssetTypeID();
11929 CONTRACT_ID.GetString(strContractID);
11932 strFromAcct.Get())) !=
nullptr) {
11933 pAccount->GetIdentifier(strFromAcct);
11934 CONTRACT_ID = pAccount->GetAssetTypeID();
11935 CONTRACT_ID.GetString(strContractID);
11938 otErr <<
"Unable to purchase voucher without a 'FROM' account. "
11939 "Try adding: --myacct ACCOUNT_ID\n";
11944 pAccount->GetIdentifier(strFromAcct);
11945 CONTRACT_ID = pAccount->GetAssetTypeID();
11946 CONTRACT_ID.GetString(strContractID);
11949 const OTIdentifier ACCOUNT_ID(strFromAcct);
11951 if (pAccount->GetPurportedServerID() != SERVER_ID) {
11952 otErr <<
"OTClient::ProcessUserCommand: "
11953 "pAccount->GetPurportedServerID() doesn't match "
11954 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
11957 OTString strRecipientNym;
11959 if (
nullptr == pHisNymID) {
11960 otOut <<
"Enter Recipient's Nym ID (full ID -- no partials here.) "
11961 "Blank IS allowed: ";
11965 strRecipientNym.OTfgets(std::cin);
11972 pHisNymID->GetString(strRecipientNym);
11977 const OTIdentifier MY_NYM_ID(theNym);
11978 const OTIdentifier HIS_NYM_ID(strRecipientNym);
11980 OTString strAmount;
11981 if (0 == lTransactionAmount) {
11982 otOut <<
"Please enter an amount: ";
11985 strAmount.OTfgets(std::cin);
11988 const int64_t lTotalAmount =
11989 (0 == lTransactionAmount)
11991 (atol(strAmount.Exists() ? strAmount.Get() :
"0"))
11992 : lTransactionAmount;
11993 int64_t lWithdrawTransNum = 0, lVoucherTransNum = 0;
11995 bool bGotTransNum1 = theNym.GetNextTransactionNum(theNym, strServerID,
11996 lWithdrawTransNum);
11997 bool bGotTransNum2 =
11998 theNym.GetNextTransactionNum(theNym, strServerID, lVoucherTransNum);
12000 if (!bGotTransNum1 || !bGotTransNum2) {
12001 otOut << __FUNCTION__ <<
": Not enough Transaction Numbers were "
12002 "available. (Suggest requesting the "
12003 "server for more.)\n";
12006 theNym.AddTransactionNum(theNym, strServerID, lWithdrawTransNum,
12009 theNym.AddTransactionNum(theNym, strServerID, lVoucherTransNum,
12014 otOut <<
"Enter a memo for your check: ";
12015 OTString strChequeMemo;
12016 strChequeMemo.OTfgets(std::cin);
12027 OTCheque theRequestVoucher(SERVER_ID, CONTRACT_ID);
12028 bool bIssueCheque = theRequestVoucher.IssueCheque(
12029 lTotalAmount, lVoucherTransNum, VALID_FROM, VALID_TO,
12030 ACCOUNT_ID, MY_NYM_ID, strChequeMemo,
12031 (strRecipientNym.GetLength() > 2) ? &(HIS_NYM_ID) :
nullptr);
12033 std::unique_ptr<OTLedger> pInbox(pAccount->LoadInbox(theNym));
12034 std::unique_ptr<OTLedger> pOutbox(pAccount->LoadOutbox(theNym));
12036 if (
nullptr == pInbox) {
12037 otOut <<
"Failed loading inbox!\n";
12041 theNym.AddTransactionNum(theNym, strServerID, lWithdrawTransNum,
12043 theNym.AddTransactionNum(theNym, strServerID, lVoucherTransNum,
12046 else if (
nullptr == pOutbox) {
12047 otOut <<
"Failed loading outbox!\n";
12051 theNym.AddTransactionNum(theNym, strServerID, lWithdrawTransNum,
12053 theNym.AddTransactionNum(theNym, strServerID, lVoucherTransNum,
12056 else if (bIssueCheque) {
12058 OTTransaction* pTransaction =
12060 MY_NYM_ID, ACCOUNT_ID, SERVER_ID,
12067 pItem->SetAmount(lTotalAmount);
12068 OTString strNote(
"Withdraw Voucher: ");
12069 pItem->SetNote(strNote);
12073 OTString strVoucher;
12074 theRequestVoucher.SignContract(theNym);
12075 theRequestVoucher.SaveContract();
12076 theRequestVoucher.SaveContractRaw(strVoucher);
12077 pItem->SetAttachment(strVoucher);
12082 pItem->SignContract(theNym);
12083 pItem->SaveContract();
12085 pTransaction->AddItem(*pItem);
12092 OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
12093 lTotalAmount * (-1), *pTransaction, theNym, *pAccount,
12096 if (
nullptr != pBalanceItem)
12097 pTransaction->AddItem(*pBalanceItem);
12103 pTransaction->SignContract(theNym);
12104 pTransaction->SaveContract();
12107 OTLedger theLedger(MY_NYM_ID, ACCOUNT_ID, SERVER_ID);
12108 theLedger.GenerateLedger(ACCOUNT_ID, SERVER_ID,
12113 theLedger.AddTransaction(*pTransaction);
12116 theLedger.SignContract(theNym);
12117 theLedger.SaveContract();
12120 OTString strLedger(theLedger);
12121 OTASCIIArmor ascLedger;
12126 ascLedger.SetString(strLedger);
12129 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
12130 theMessage.m_strRequestNum.Format(
12131 "%lld", lRequestNumber);
12132 theNym.IncrementRequestNum(
12133 theNym, strServerID);
12137 theMessage.m_strCommand =
"notarizeTransactions";
12138 theMessage.m_strNymID = strNymID;
12139 theMessage.m_strServerID = strServerID;
12140 theMessage.SetAcknowledgments(
12144 theMessage.m_strAcctID = strFromAcct;
12145 theMessage.m_ascPayload = ascLedger;
12147 OTIdentifier NYMBOX_HASH;
12148 const std::string str_server(strServerID.Get());
12149 const bool bNymboxHash =
12150 theNym.GetNymboxHash(str_server, NYMBOX_HASH);
12153 NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
12155 otErr <<
"Failed getting NymboxHash from Nym for server: "
12156 << str_server <<
"\n";
12159 theMessage.SignContract(theNym);
12163 theMessage.SaveContract();
12165 bSendCommand =
true;
12166 lReturnValue = lRequestNumber;
12171 theNym.AddTransactionNum(theNym, strServerID, lWithdrawTransNum,
12173 theNym.AddTransactionNum(theNym, strServerID, lVoucherTransNum,
12193 OTString strFromAcct;
12195 if (
nullptr == pAccount) {
12196 otOut <<
"Please enter an Asset Account ID: ";
12199 strFromAcct.OTfgets(std::cin);
12201 if (strFromAcct.GetLength() < 2)
return (-1);
12203 const OTIdentifier ACCOUNT_ID(strFromAcct);
12205 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
12206 pAccount->GetIdentifier(strFromAcct);
12207 CONTRACT_ID = pAccount->GetAssetTypeID();
12208 CONTRACT_ID.GetString(strContractID);
12211 strFromAcct.Get())) !=
nullptr) {
12212 pAccount->GetIdentifier(strFromAcct);
12213 CONTRACT_ID = pAccount->GetAssetTypeID();
12214 CONTRACT_ID.GetString(strContractID);
12217 otErr <<
"Unable to withdraw without account. Try adding: "
12218 "--myacct ACCOUNT_ID\n";
12223 pAccount->GetIdentifier(strFromAcct);
12224 CONTRACT_ID = pAccount->GetAssetTypeID();
12225 CONTRACT_ID.GetString(strContractID);
12228 if (pAccount->GetPurportedServerID() != SERVER_ID) {
12229 otErr <<
"OTClient::ProcessUserCommand: "
12230 "pAccount->GetPurportedServerID() doesn't match "
12231 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
12235 OTString strAmount;
12236 if (0 == lTransactionAmount) {
12237 otOut <<
"Please enter an amount: ";
12240 strAmount.OTfgets(std::cin);
12243 const int64_t lTotalAmount =
12244 (0 == lTransactionAmount)
12246 (atol(strAmount.Exists() ? strAmount.Get() :
"0"))
12247 : lTransactionAmount;
12248 int64_t lAmount = lTotalAmount;
12251 const OTIdentifier ACCT_FROM_ID(strFromAcct), USER_ID(theNym);
12253 int64_t lStoredTransactionNumber = 0;
12254 bool bGotTransNum =
false;
12256 std::unique_ptr<OTLedger> pInbox(pAccount->LoadInbox(theNym));
12257 std::unique_ptr<OTLedger> pOutbox(pAccount->LoadOutbox(theNym));
12259 if (
nullptr == pInbox) {
12260 otOut <<
"Failed loading inbox!\n";
12263 else if (
nullptr == pOutbox) {
12264 otOut <<
"Failed loading outbox!\n";
12268 bGotTransNum = theNym.GetNextTransactionNum(theNym, strServerID,
12269 lStoredTransactionNumber);
12270 if (!bGotTransNum) {
12271 otOut <<
"No Transaction Numbers were available. Suggest "
12272 "requesting the server for a new one.\n";
12279 lStoredTransactionNumber);
12285 pItem->SetAmount(lTotalAmount);
12286 OTString strNote(
"Gimme cash!");
12287 pItem->SetNote(strNote);
12289 const OTPseudonym* pServerNym = theServer.GetContractPublicNym();
12290 std::unique_ptr<Mint> pMint(
12293 if (pServerNym && pMint->LoadMint() &&
12294 pMint->VerifyMint((OTPseudonym&)*pServerNym)) {
12295 Purse* pPurse =
new Purse(SERVER_ID, CONTRACT_ID);
12296 Purse* pPurseMyCopy =
new Purse(SERVER_ID, CONTRACT_ID);
12303 int64_t lTokenAmount = 0;
12304 while ((lTokenAmount = pMint->GetLargestDenomination(lAmount)) >
12306 lAmount -= lTokenAmount;
12313 std::unique_ptr<Token> pToken(
12315 *pPurse, theNym, *pMint, lTokenAmount));
12319 pToken->SignContract(theNym);
12320 pToken->SaveContract();
12327 pPurse->Push(*pServerNym, *pToken);
12335 pToken->ReleaseSignatures();
12336 pToken->SetSavePrivateKeys();
12338 pToken->SignContract(theNym);
12339 pToken->SaveContract();
12341 pPurseMyCopy->Push(theNym, *pToken);
12346 pPurse->SignContract(theNym);
12347 pPurse->SaveContract();
12351 pPurse->SaveContractRaw(strPurse);
12354 pItem->SetAttachment(
12357 pPurseMyCopy->SignContract(
12359 pPurseMyCopy->SaveContract();
12379 pItem->SignContract(theNym);
12380 pItem->SaveContract();
12382 pTransaction->AddItem(*pItem);
12390 OTItem* pBalanceItem = pInbox->GenerateBalanceStatement(
12391 lTotalAmount * (-1), *pTransaction, theNym, *pAccount,
12397 pTransaction->AddItem(
12404 pTransaction->SignContract(theNym);
12405 pTransaction->SaveContract();
12408 OTLedger theLedger(USER_ID, ACCT_FROM_ID, SERVER_ID);
12409 theLedger.GenerateLedger(ACCT_FROM_ID, SERVER_ID,
12413 theLedger.AddTransaction(*pTransaction);
12416 theLedger.SignContract(theNym);
12417 theLedger.SaveContract();
12420 OTString strLedger(theLedger);
12421 OTASCIIArmor ascLedger;
12425 ascLedger.SetString(strLedger);
12428 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
12429 theMessage.m_strRequestNum.Format(
12430 "%lld", lRequestNumber);
12431 theNym.IncrementRequestNum(theNym, strServerID);
12437 theMessage.m_strCommand =
"notarizeTransactions";
12438 theMessage.m_strNymID = strNymID;
12439 theMessage.m_strServerID = strServerID;
12440 theMessage.SetAcknowledgments(theNym);
12445 theMessage.m_strAcctID = strFromAcct;
12446 theMessage.m_ascPayload = ascLedger;
12448 OTIdentifier NYMBOX_HASH;
12449 const std::string str_server(strServerID.Get());
12450 const bool bNymboxHash =
12451 theNym.GetNymboxHash(str_server, NYMBOX_HASH);
12454 NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
12456 otErr <<
"Failed getting NymboxHash from Nym for server: "
12457 << str_server <<
"\n";
12460 theMessage.SignContract(theNym);
12464 theMessage.SaveContract();
12466 bSendCommand =
true;
12467 lReturnValue = lRequestNumber;
12472 theNym.AddTransactionNum(theNym, strServerID,
12473 lStoredTransactionNumber,
12481 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
12482 theMessage.m_strRequestNum.Format(
12483 "%lld", lRequestNumber);
12484 theNym.IncrementRequestNum(theNym, strServerID);
12489 theMessage.m_strCommand =
"getTransactionNum";
12490 theMessage.m_strNymID = strNymID;
12491 theMessage.m_strServerID = strServerID;
12492 theMessage.SetAcknowledgments(theNym);
12496 OTIdentifier NYMBOX_HASH;
12497 const std::string str_server(strServerID.Get());
12498 const bool bNymboxHash = theNym.GetNymboxHash(str_server, NYMBOX_HASH);
12501 NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
12503 otErr <<
"Failed getting NymboxHash from Nym for server: "
12504 << str_server <<
"\n";
12507 theMessage.SignContract(theNym);
12511 theMessage.SaveContract();
12513 bSendCommand =
true;
12514 lReturnValue = lRequestNumber;
12518 if (theNym.GetTransactionNumCount(strServerID) < 3) {
12519 otOut <<
"You need at least 3 transaction numbers to do this (You "
12520 "don't have enough.)\n";
12523 int64_t lStoredTransactionNumber = 0,
12524 lClosingTransactionNoAssetAcct = 0,
12525 lClosingTransactionNoCurrencyAcct = 0;
12526 bool bGotTransNum = theNym.GetNextTransactionNum(
12527 theNym, strServerID, lStoredTransactionNumber,
false);
12528 bool bGotClosingNumAssetAcct = theNym.GetNextTransactionNum(
12529 theNym, strServerID, lClosingTransactionNoAssetAcct,
false);
12530 bool bGotClosingNumCurrencyAcct = theNym.GetNextTransactionNum(
12531 theNym, strServerID, lClosingTransactionNoCurrencyAcct,
true);
12533 if (!bGotTransNum || !bGotClosingNumAssetAcct ||
12534 !bGotClosingNumCurrencyAcct) {
12535 otOut <<
"Strange... had enough transcation numbers, but error "
12536 "trying to get one (or both.)\n";
12539 theNym.AddTransactionNum(theNym, strServerID,
12540 lStoredTransactionNumber,
false);
12542 if (bGotClosingNumAssetAcct)
12543 theNym.AddTransactionNum(theNym, strServerID,
12544 lClosingTransactionNoAssetAcct,
12547 if (bGotClosingNumCurrencyAcct)
12548 theNym.AddTransactionNum(theNym, strServerID,
12549 lClosingTransactionNoCurrencyAcct,
12552 if (bGotTransNum || bGotClosingNumAssetAcct ||
12553 bGotClosingNumCurrencyAcct)
12554 theNym.SaveSignedNymfile(theNym);
12557 OTString str_ASSET_TYPE_ID, str_CURRENCY_TYPE_ID,
12558 str_ASSET_ACCT_ID, str_CURRENCY_ACCT_ID;
12561 otOut <<
"Enter the Asset Type ID of the market you want to "
12563 str_ASSET_TYPE_ID.OTfgets(std::cin);
12566 otOut <<
"Enter an ACCOUNT ID of yours for an account of the "
12567 "same asset type: ";
12568 str_ASSET_ACCT_ID.OTfgets(std::cin);
12574 otOut <<
"Enter the Currency Type ID of the market you want to "
12576 str_CURRENCY_TYPE_ID.OTfgets(std::cin);
12579 otOut <<
"Enter an ACCOUNT ID of yours, for an account of that "
12580 "same currency type: ";
12581 str_CURRENCY_ACCT_ID.OTfgets(std::cin);
12586 int64_t lTotalAssetsOnOffer = 0, lMinimumIncrement = 0,
12589 otOut <<
"What is the market granularity (or 'scale')? [1]: ";
12591 strTemp.OTfgets(std::cin);
12592 int64_t lMarketScale = atol(strTemp.Get());
12594 if (lMarketScale < 1) lMarketScale = 1;
12596 otOut <<
"What is the minimum increment per trade? (will be "
12597 "multiplied by the scale) [1]: ";
12599 strTemp.OTfgets(std::cin);
12600 lMinimumIncrement = atol(strTemp.Get());
12602 lMinimumIncrement *= lMarketScale;
12605 if (lMinimumIncrement < 1) lMinimumIncrement = lMarketScale;
12607 otOut <<
"How many assets total do you have available for sale "
12608 "or purchase?\n(Will be multiplied by minimum "
12609 "increment) [1]: ";
12611 strTemp.OTfgets(std::cin);
12612 lTotalAssetsOnOffer = atol(strTemp.Get());
12617 if (lTotalAssetsOnOffer < 1)
12618 lTotalAssetsOnOffer = lMinimumIncrement;
12621 otOut <<
"The Market Scale is: " << lMarketScale
12622 <<
"\nWhat is your price limit, in currency, PER "
12623 "SCALE of assets?\nThat is, what is the lowest "
12624 "amount of currency you'd sell for, (if "
12625 "selling)\nOr the highest amount you'd pay (if "
12626 "you are buying).\nAgain, PER SCALE: ";
12628 strTemp.OTfgets(std::cin);
12629 lPriceLimit = atol(strTemp.Get());
12631 if (lPriceLimit < 1)
12632 otOut <<
"Price must be at least 1.\n\n";
12638 bool bBuyingOrSelling;
12639 OTString strDirection;
12640 otOut <<
"Are you in the market to buy the asset type, or to "
12642 strDirection.OTfgets(std::cin);
12644 if (strDirection.Compare(
"sell") ||
12645 strDirection.Compare(
"Sell"))
12646 bBuyingOrSelling =
true;
12648 bBuyingOrSelling =
false;
12650 OTIdentifier USER_ID(strNymID),
12651 ASSET_TYPE_ID(str_ASSET_TYPE_ID),
12652 CURRENCY_TYPE_ID(str_CURRENCY_TYPE_ID),
12653 ASSET_ACCT_ID(str_ASSET_ACCT_ID),
12654 CURRENCY_ACCT_ID(str_CURRENCY_ACCT_ID);
12656 OTOffer theOffer(SERVER_ID, ASSET_TYPE_ID, CURRENCY_TYPE_ID,
12659 bool bCreateOffer = theOffer.MakeOffer(
12662 lTotalAssetsOnOffer,
12666 lStoredTransactionNumber);
12670 if (bCreateOffer) {
12671 bCreateOffer = theOffer.SignContract(theNym);
12673 if (bCreateOffer) bCreateOffer = theOffer.SaveContract();
12676 OTTrade theTrade(SERVER_ID, ASSET_TYPE_ID, ASSET_ACCT_ID,
12677 USER_ID, CURRENCY_TYPE_ID, CURRENCY_ACCT_ID);
12679 bool bIssueTrade = theTrade.IssueTrade(theOffer);
12682 theTrade.AddClosingTransactionNo(
12683 lClosingTransactionNoAssetAcct);
12684 theTrade.AddClosingTransactionNo(
12685 lClosingTransactionNoCurrencyAcct);
12687 bIssueTrade = theTrade.SignContract(theNym);
12689 if (bIssueTrade) bIssueTrade = theTrade.SaveContract();
12692 if (bCreateOffer && bIssueTrade) {
12694 OTTransaction* pTransaction =
12696 USER_ID, ASSET_ACCT_ID, SERVER_ID,
12698 lStoredTransactionNumber);
12704 &CURRENCY_ACCT_ID);
12716 theTrade.SaveContractRaw(strTrade);
12720 pItem->SetAttachment(strTrade);
12726 pItem->SignContract(theNym);
12727 pItem->SaveContract();
12731 pTransaction->AddItem(*pItem);
12740 OTItem* pStatementItem =
12741 theNym.GenerateTransactionStatement(*pTransaction);
12747 pTransaction->AddItem(*pStatementItem);
12755 pTransaction->SignContract(theNym);
12756 pTransaction->SaveContract();
12759 OTLedger theLedger(USER_ID, ASSET_ACCT_ID, SERVER_ID);
12760 theLedger.GenerateLedger(
12761 ASSET_ACCT_ID, SERVER_ID,
12764 theLedger.AddTransaction(*pTransaction);
12771 theLedger.SignContract(theNym);
12772 theLedger.SaveContract();
12775 OTString strLedger(theLedger);
12776 OTASCIIArmor ascLedger(strLedger);
12779 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
12780 theMessage.m_strRequestNum.Format(
12781 "%lld", lRequestNumber);
12782 theNym.IncrementRequestNum(
12783 theNym, strServerID);
12787 theMessage.m_strCommand =
"notarizeTransactions";
12788 theMessage.m_strNymID = strNymID;
12789 theMessage.m_strServerID = strServerID;
12790 theMessage.SetAcknowledgments(
12795 theMessage.m_strAcctID = str_ASSET_ACCT_ID;
12796 theMessage.m_ascPayload = ascLedger;
12798 OTIdentifier NYMBOX_HASH;
12799 const std::string str_server(strServerID.Get());
12800 const bool bNymboxHash =
12801 theNym.GetNymboxHash(str_server, NYMBOX_HASH);
12804 NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
12807 <<
"Failed getting NymboxHash from Nym for server: "
12808 << str_server <<
"\n";
12811 theMessage.SignContract(theNym);
12815 theMessage.SaveContract();
12817 bSendCommand =
true;
12818 lReturnValue = lRequestNumber;
12821 if (!bSendCommand) {
12824 theNym.AddTransactionNum(theNym, strServerID,
12825 lStoredTransactionNumber,
12827 theNym.AddTransactionNum(theNym, strServerID,
12828 lClosingTransactionNoAssetAcct,
12830 theNym.AddTransactionNum(theNym, strServerID,
12831 lClosingTransactionNoCurrencyAcct,
12841 otOut <<
"Is the contract a server contract, or an asset contract "
12843 OTString strContractType;
12844 strContractType.OTfgets(std::cin);
12846 char cContractType =
's';
12847 bool bIsAssetContract = strContractType.At(0, cContractType);
12849 if (bIsAssetContract) {
12850 if (
'S' == cContractType ||
's' == cContractType)
12851 bIsAssetContract =
false;
12855 <<
"Is the contract properly escaped already? (If escaped, all "
12856 "lines beginning with ----- will instead appear as - ----- "
12865 OTString strEscape;
12866 strEscape.OTfgets(std::cin);
12868 char cEscape =
'n';
12869 bool bEscaped = strEscape.At(0, cEscape);
12872 if (
'N' == cEscape ||
'n' == cEscape) bEscaped =
false;
12875 otOut <<
"Please enter an unsigned asset contract; terminate with "
12878 OTString strContract;
12879 char decode_buffer[200];
12883 decode_buffer[0] = 0;
12885 if (!fgets(decode_buffer,
sizeof(decode_buffer) - 1, stdin) &&
12886 (decode_buffer[0] !=
'~')) {
12887 if (!bEscaped && decode_buffer[0] ==
'-') {
12888 strContract.Concatenate(
"- ");
12890 strContract.Concatenate(
"%s", decode_buffer);
12897 }
while (decode_buffer[0] !=
'~');
12899 OTServerContract theServerContract;
12900 OTAssetContract theAssetContract;
12902 OTContract* pContract =
12904 ?
dynamic_cast<OTContract*
>(&theAssetContract)
12905 : dynamic_cast<OTContract*>(&theServerContract);
12907 pContract->CreateContract(strContract, theNym);
12910 strContract.Release();
12911 pContract->SaveContractRaw(strContract);
12914 pContract->GetIdentifier(strNewID);
12916 otOut <<
".\n..\n...\n....\n.....\n......\n.......\n........\n....."
12918 "\n\nNEW CONTRACT ID: " << strNewID <<
"\n\n";
12920 std::cout << strContract << std::endl;
12927 OTString strFromAcct;
12929 if (
nullptr == pAccount) {
12930 otOut <<
"Please enter an Asset Account ID (to draw the cheque "
12934 strFromAcct.OTfgets(std::cin);
12936 if (strFromAcct.GetLength() < 2)
return (-1);
12938 const OTIdentifier ACCOUNT_ID(strFromAcct);
12940 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
12941 pAccount->GetIdentifier(strFromAcct);
12942 CONTRACT_ID = pAccount->GetAssetTypeID();
12943 CONTRACT_ID.GetString(strContractID);
12946 strFromAcct.Get())) !=
nullptr) {
12947 pAccount->GetIdentifier(strFromAcct);
12948 CONTRACT_ID = pAccount->GetAssetTypeID();
12949 CONTRACT_ID.GetString(strContractID);
12952 otErr <<
"Unable to write cheque without account to draw from. "
12953 "On comand line, try adding: --myacct ACCOUNT_ID\n";
12958 pAccount->GetIdentifier(strFromAcct);
12959 CONTRACT_ID = pAccount->GetAssetTypeID();
12960 CONTRACT_ID.GetString(strContractID);
12963 const OTIdentifier ACCOUNT_ID(strFromAcct);
12965 if (pAccount->GetPurportedServerID() != SERVER_ID) {
12966 otErr <<
"OTClient::ProcessUserCommand: "
12967 "pAccount->GetPurportedServerID() doesn't match "
12968 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
12972 OTString strRecipientNym;
12974 if (
nullptr == pHisNymID) {
12975 otOut <<
"Enter Recipient's Nym ID (full ID -- no partials here.) "
12976 "Blank IS allowed: ";
12980 strRecipientNym.OTfgets(std::cin);
12987 pHisNymID->GetString(strRecipientNym);
12992 const OTIdentifier MY_NYM_ID(theNym);
12994 const OTIdentifier HIS_NYM_ID(strRecipientNym);
12996 OTString strAmount;
12997 if (0 == lTransactionAmount) {
12998 otOut <<
"Please enter an amount: ";
13001 strAmount.OTfgets(std::cin);
13004 const int64_t lTotalAmount =
13005 (0 == lTransactionAmount)
13007 (atol(strAmount.Exists() ? strAmount.Get() :
"0"))
13008 : lTransactionAmount;
13020 int64_t lTransactionNumber = 0;
13023 theNym.GetNextTransactionNum(theNym, strServerID,
13024 lTransactionNumber)) {
13025 otOut <<
"Cheques are written offline, but you still need a "
13026 "transaction number\n(and you have none, currently.) Try "
13027 "using 'n' to request another transaction number.\n";
13031 OTCheque theCheque(pAccount->GetRealServerID(),
13032 pAccount->GetAssetTypeID());
13035 otOut <<
"Enter a memo for your check: ";
13036 OTString strChequeMemo;
13037 strChequeMemo.OTfgets(std::cin);
13040 otOut <<
" 6 minutes == 360 Seconds\n10 minutes == 600 "
13041 "Seconds\n1 hour == 3600 Seconds\n1 day == "
13042 " 86400 Seconds\n30 days == 2592000 Seconds\n3 months "
13043 "== 7776000 Seconds\n6 months == 15552000 Seconds\n\n";
13045 int64_t lExpirationInSeconds =
13047 otOut <<
"How many seconds before cheque expires? (defaults to 1 hour: "
13048 << lExpirationInSeconds <<
"): ";
13050 strTemp.OTfgets(std::cin);
13052 if (strTemp.GetLength() > 1) lExpirationInSeconds = atol(strTemp.Get());
13057 otOut <<
"Cheque may be cashed STARTING date (defaults to now, in "
13058 "seconds) [" << VALID_FROM <<
"]: ";
13060 strTemp.OTfgets(std::cin);
13062 if (strTemp.GetLength() > 2)
13066 VALID_FROM, lExpirationInSeconds);
13068 bool bIssueCheque = theCheque.IssueCheque(
13069 lTotalAmount, lTransactionNumber, VALID_FROM, VALID_TO, ACCOUNT_ID,
13070 MY_NYM_ID, strChequeMemo,
13071 (strRecipientNym.GetLength() > 2)
13075 if (bIssueCheque) {
13076 theCheque.SignContract(theNym);
13077 theCheque.SaveContract();
13079 OTString strCheque(theCheque);
13081 otOut <<
"\n\nOUTPUT (writeCheque):\n\n\n";
13084 std::cout << strCheque << std::endl;
13087 otOut <<
"Failed trying to issue the cheque!\n";
13091 theNym.AddTransactionNum(theNym, strServerID, lTransactionNumber,
13100 OTString strMerchantAcct;
13102 if (
nullptr == pAccount) {
13104 <<
"You are the Merchant, proposing this payment plan so "
13105 "your customer can confirm it.\nAfter this command, use "
13106 "'confirm' (customer) to confirm it, and then activate "
13108 "using\n'plan' (customer) from the OT prompt, or "
13109 "'--activateplan' from the command line.\n\nEnter the "
13110 "Merchant's (your) Asset Account ID that the payments "
13114 strMerchantAcct.OTfgets(std::cin);
13116 if (strMerchantAcct.GetLength() < 2)
return -1;
13118 const OTIdentifier ACCOUNT_ID(strMerchantAcct);
13120 if ((pAccount = m_pWallet->
GetAccount(ACCOUNT_ID)) !=
nullptr) {
13121 pAccount->GetIdentifier(strMerchantAcct);
13122 CONTRACT_ID = pAccount->GetAssetTypeID();
13123 CONTRACT_ID.GetString(strContractID);
13126 strMerchantAcct.Get())) !=
nullptr) {
13127 pAccount->GetIdentifier(strMerchantAcct);
13128 CONTRACT_ID = pAccount->GetAssetTypeID();
13129 CONTRACT_ID.GetString(strContractID);
13133 <<
"Unable to propose payment plan without account to "
13134 "pay to. Try adding: --myacct ACCOUNT_ID\n";
13139 pAccount->GetIdentifier(strMerchantAcct);
13140 CONTRACT_ID = pAccount->GetAssetTypeID();
13141 CONTRACT_ID.GetString(strContractID);
13144 const OTIdentifier MY_ACCT_ID(strMerchantAcct);
13146 if (pAccount->GetPurportedServerID() != SERVER_ID) {
13147 otErr <<
"OTClient::ProcessUserCommand: "
13148 "pAccount->GetPurportedServerID() doesn't match "
13149 "SERVER_ID.\n(Try adding: --server SERVER_ID)\n";
13162 OTString strCustomerAcct;
13164 if (
nullptr == pHisAcctID) {
13165 otOut <<
"Enter Customer's Asset Account ID that payments will "
13166 "come FROM (no partials): ";
13170 strCustomerAcct.OTfgets(std::cin);
13172 if (strCustomerAcct.GetLength() < 2)
return -1;
13175 pHisAcctID->GetString(strCustomerAcct);
13178 const OTIdentifier HIS_ACCT_ID(strCustomerAcct);
13183 OTString strCustomerNym;
13185 if (
nullptr == pHisNymID) {
13186 otOut <<
"Enter Customer's Nym ID (full ID -- no partials "
13191 strCustomerNym.OTfgets(std::cin);
13193 if (strCustomerNym.GetLength() < 2)
return -1;
13196 pHisNymID->GetString(strCustomerNym);
13201 const OTIdentifier MY_NYM_ID(theNym);
13203 const OTIdentifier HIS_NYM_ID(strCustomerNym);
13208 OTString strConsideration, strTemp;
13210 otOut <<
"Enter a memo describing consideration for the payment "
13212 strConsideration.OTfgets(std::cin);
13228 if (theNym.GetTransactionNumCount(strServerID) < 2) {
13230 <<
"Payment Plans are written offline, but you still need "
13232 "2 transaction numbers\n(and you don't, currently.) Try "
13233 "using 'n' to request another transaction number.\n";
13246 OTPaymentPlan thePlan(pAccount->GetRealServerID(),
13247 pAccount->GetAssetTypeID(), HIS_ACCT_ID,
13248 HIS_NYM_ID, MY_ACCT_ID, MY_NYM_ID);
13252 <<
" 6 minutes == 360 Seconds\n10 minutes == "
13254 "Seconds\n1 hour == 3600 Seconds\n1 day "
13256 " 86400 Seconds\n30 days == 2592000 Seconds\n3 "
13257 "months == 7776000 Seconds\n6 months == "
13258 "15552000 Seconds\n\n";
13260 int64_t lExpirationInSeconds =
13262 otOut <<
"How many seconds before payment plan expires? (defaults "
13264 "day: " << lExpirationInSeconds <<
"): ";
13266 strTemp.OTfgets(std::cin);
13268 if (strTemp.GetLength() > 1)
13269 lExpirationInSeconds = atol(strTemp.Get());
13274 otOut <<
"Payment plan becomes valid for processing STARTING "
13275 "date\n(defaults to now, in seconds) [" << VALID_FROM
13278 strTemp.OTfgets(std::cin);
13280 if (strTemp.GetLength() > 2)
13284 VALID_FROM, lExpirationInSeconds);
13290 bool bSuccessSetAgreement = thePlan.SetProposal(
13291 theNym, strConsideration, VALID_FROM, VALID_TO);
13293 if (!bSuccessSetAgreement) {
13294 otOut <<
"Failed trying to set the proposal!\n";
13299 bool bSuccessSetInitialPayment =
true;
13302 bool bSuccessSetPaymentPlan =
13306 otOut <<
"What is the Initial Payment Amount, if any? [0]: ";
13308 strTemp.OTfgets(std::cin);
13309 int64_t lInitialPayment = atol(strTemp.Get());
13311 if (lInitialPayment > 0) {
13315 otOut <<
"From the Start Date forward, how int64_t until the "
13316 "Initial Payment should charge?\n(defaults to one "
13318 "in seconds) [" << PAYMENT_DELAY <<
"]: ";
13320 strTemp.OTfgets(std::cin);
13322 if ((strTemp.GetLength() > 1) && atol(strTemp.Get()) > 0)
13325 bSuccessSetInitialPayment =
13326 thePlan.SetInitialPayment(lInitialPayment, PAYMENT_DELAY);
13329 if (!bSuccessSetInitialPayment) {
13330 otOut <<
"Failed trying to set the initial payment!\n";
13334 thePlan.HarvestClosingNumbers(
13340 otOut <<
"What is the regular payment amount, if any? [0]: ";
13342 strTemp.OTfgets(std::cin);
13343 int64_t lRegularPayment = atol(strTemp.Get());
13345 if (lRegularPayment > 0)
13352 <<
"From the Start Date forward, how int64_t until the "
13353 "Regular Payments start?\n(defaults to two minutes, in "
13354 "seconds) [" << PAYMENT_DELAY <<
"]: ";
13356 strTemp.OTfgets(std::cin);
13358 if ((strTemp.GetLength() > 1) && atol(strTemp.Get()) > 0)
13364 otOut <<
"Once payments begin, how much time should elapse "
13366 "each payment?\n(defaults to thirty seconds) ["
13367 << PAYMENT_PERIOD <<
"]: ";
13369 strTemp.OTfgets(std::cin);
13371 if ((strTemp.GetLength() > 1) && atol(strTemp.Get()) > 0)
13377 otOut <<
"From start date, do you want the plan to expire "
13379 "certain maximum time?\n(defaults to 0 for no) ["
13380 << PLAN_LENGTH <<
"]: ";
13382 strTemp.OTfgets(std::cin);
13384 if (strTemp.GetLength() > 1)
13388 <<
"Should there be some maximum number of payments? (Zero "
13389 "for no maximum.) [0]: ";
13391 strTemp.OTfgets(std::cin);
13392 int32_t nMaxPayments = atoi(strTemp.Get());
13394 bSuccessSetPaymentPlan = thePlan.SetPaymentPlan(
13395 lRegularPayment, PAYMENT_DELAY, PAYMENT_PERIOD, PLAN_LENGTH,
13399 if (!bSuccessSetPaymentPlan) {
13400 otOut <<
"Failed trying to set the payment plan!\n";
13404 thePlan.HarvestClosingNumbers(
13410 thePlan.SignContract(theNym);
13411 thePlan.SaveContract();
13413 OTString strPlan(thePlan);
13416 <<
"\n\n(Make sure to have your Customer 'confirm' the payment "
13417 "plan, before he activates it at the server using the "
13419 "command in the OT prompt, or --activateplan at the "
13420 "command-line):\n\n";
13422 std::cout << strPlan << std::endl;
13431 <<
"(You are the customer, confirming a payment plan that the "
13432 "merchant has just sent you.)\n\n";
13434 OTPaymentPlan thePlan;
13437 <<
"Please enter plaintext payment plan. Terminate with ~ on a "
13440 char decode_buffer[200];
13444 decode_buffer[0] = 0;
13446 if (!fgets(decode_buffer,
sizeof(decode_buffer) - 1, stdin) &&
13447 (decode_buffer[0] !=
'~')) {
13448 strPlan.Concatenate(
"%s", decode_buffer);
13455 }
while (decode_buffer[0] !=
'~');
13457 if (!thePlan.LoadContractFromString(strPlan)) {
13458 otOut <<
"Unable to load payment plan from string.\n";
13462 OTPseudonym* pCustomerNym =
13463 m_pWallet->
GetNymByID(thePlan.GetSenderUserID());
13465 if (
nullptr == pCustomerNym) {
13466 otOut <<
"The customer Nym on this payment plan (you, "
13468 "wasn't found in the wallet. Try 'load'.\n";
13471 OTPseudonym* pMerchantNym =
13472 m_pWallet->
GetNymByID(thePlan.GetRecipientUserID());
13482 thePlan.Confirm(*pCustomerNym, pMerchantNym,
13483 &thePlan.GetRecipientUserID())) {
13484 otOut <<
"Error while confirming payment plan. Sorry.\n";
13488 thePlan.SignContract(*pCustomerNym);
13489 thePlan.SaveContract();
13491 OTString strOutput(thePlan);
13494 <<
"\n\nMake sure to submit the payment plan to the server, to "
13495 "activate it:\n\n";
13502 std::cout << strOutput << std::endl;
13509 const OTIdentifier USER_ID(theNym);
13511 OTPaymentPlan thePlan;
13513 otOut <<
"Please enter plaintext payment plan. Terminate with ~ on a "
13516 char decode_buffer[200];
13520 decode_buffer[0] = 0;
13522 if (!fgets(decode_buffer,
sizeof(decode_buffer) - 1, stdin) &&
13523 (decode_buffer[0] !=
'~')) {
13524 strPlan.Concatenate(
"%s", decode_buffer);
13531 }
while (decode_buffer[0] !=
'~');
13533 if (thePlan.LoadContractFromString(strPlan)) {
13534 const OTIdentifier ACCOUNT_ID(thePlan.GetSenderAcctID());
13536 OTAccount* pSenderAccount = m_pWallet->
GetAccount(ACCOUNT_ID);
13538 if (
nullptr == pSenderAccount) {
13539 otOut <<
"There is no account loaded on this wallet with that "
13540 "sender acct ID, sorry.\n";
13542 if ((
nullptr != pAccount) && (pSenderAccount != pAccount)) {
13543 otOut <<
"This Payment Plan is already confirmed, yet now you "
13544 "try to activate it, and you \nhave supplied a "
13545 "different account ID than the one that originally "
13546 "confirmed it.\nPerhaps it's just an unfortunate "
13547 "default in your ~/.ot/command-line-ot.opt file.\nBe "
13548 "explicit, and use: --myacct <acct_id>\n";
13551 OTString strFromAcct(ACCOUNT_ID);
13554 OTTransaction* pTransaction =
13556 USER_ID, ACCOUNT_ID, SERVER_ID,
13558 thePlan.GetTransactionNum());
13566 thePlan.SaveContractRaw(strPlan);
13570 pItem->SetAttachment(strPlan);
13574 pItem->SignContract(theNym);
13575 pItem->SaveContract();
13579 pTransaction->AddItem(*pItem);
13587 OTItem* pStatementItem =
13588 theNym.GenerateTransactionStatement(*pTransaction);
13593 pTransaction->AddItem(*pStatementItem);
13600 pTransaction->SignContract(theNym);
13601 pTransaction->SaveContract();
13604 OTLedger theLedger(USER_ID, ACCOUNT_ID, SERVER_ID);
13605 theLedger.GenerateLedger(ACCOUNT_ID, SERVER_ID,
13610 theLedger.AddTransaction(*pTransaction);
13616 theLedger.SignContract(theNym);
13617 theLedger.SaveContract();
13620 OTString strLedger(theLedger);
13621 OTASCIIArmor ascLedger(strLedger);
13624 theNym.GetCurrentRequestNum(strServerID, lRequestNumber);
13625 theMessage.m_strRequestNum.Format(
13626 "%lld", lRequestNumber);
13627 theNym.IncrementRequestNum(
13628 theNym, strServerID);
13632 theMessage.m_strCommand =
"notarizeTransactions";
13633 theMessage.m_strNymID = strNymID;
13634 theMessage.m_strServerID = strServerID;
13635 theMessage.SetAcknowledgments(
13639 theMessage.m_strAcctID = strFromAcct;
13640 theMessage.m_ascPayload = ascLedger;
13642 OTIdentifier NYMBOX_HASH;
13643 const std::string str_server(strServerID.Get());
13644 const bool bNymboxHash =
13645 theNym.GetNymboxHash(str_server, NYMBOX_HASH);
13648 NYMBOX_HASH.GetString(theMessage.m_strNymboxHash);
13650 otErr <<
"Failed getting NymboxHash from Nym for server: "
13651 << str_server <<
"\n";
13654 theMessage.SignContract(theNym);
13658 theMessage.SaveContract();
13660 lReturnValue = lRequestNumber;
13665 otOut <<
"Unable to load payment plan from string. Sorry.\n";
std::map< std::string, std::string > Map
static EXPORT OTAsymmetricKey * KeyFactory()
EXPORT Storable * CreateObject(StoredObjectType eType)
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
int32_t CalcReturnVal(const int64_t &lRequestNumber)
static EXPORT Mint * MintFactory()
EXPORT OTAccount * GetAccountPartialMatch(std::string PARTIAL_ID)
#define OT_TIME_HOUR_IN_SECONDS
EXPORT OTAssetContract * GetAssetContract(const OTIdentifier &theContractID)
time64_t OTTimeAddTimeInterval(time64_t lhs, int64_t rhs)
EXPORT void AddPendingWithdrawal(const Purse &thePurse)
OTLOG_IMPORT OTLogStream otOut
void SetNymName(const OTString &strName)
OTLOG_IMPORT OTLogStream otLog3
EXPORT bool GetAccount(int32_t iIndex, OTIdentifier &THE_ID, OTString &THE_NAME)
time64_t OTTimeGetTimeFromSeconds(int64_t seconds)
static EXPORT const OTString & Contract()
#define OT_TIME_SIX_MONTHS_IN_SECONDS
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
EXPORT std::string EncodeObject(Storable &theContents)
#define OT_TIME_DAY_IN_SECONDS
static EXPORT Token * InstantiateAndGenerateTokenRequest(const Purse &thePurse, const OTPseudonym &theNym, Mint &theMint, int64_t lDenomination, int32_t nTokenCount=Token::GetMinimumPrototokenCount())
time64_t OTTimeGetCurrentTime()
EXPORT OTPseudonym * GetNymByID(const OTIdentifier &NYM_ID)
bool AcceptEntireNymbox(OTLedger &theNymbox, const OTIdentifier &theServerID, const OTServerContract &theServerContract, OTPseudonym &theNym, OTMessage &theMessage)
EXPORT bool SaveWallet(const char *szFilename=nullptr)
bool AcceptEntireInbox(OTLedger &theInbox, const OTIdentifier &theServerID, const OTServerContract &theServerContract, OTPseudonym &theNym, const OTMessage &theMessage, const OTAccount &theAccount)
OTLOG_IMPORT OTLogStream otErr
#define OT_TIME_MINUTE_IN_SECONDS
static EXPORT Token * TokenFactory(OTString strInput)
int64_t OTTimeGetSecondsFromTime(time64_t time)
EXPORT OTServerContract * GetServerContract(const OTIdentifier &SERVER_ID)
EXPORT void SetName(const OTString &strName)