628 bool bSendCommand =
false;
629 bool bSendPayload =
false;
631 OTMessage theMessage;
633 bool bHandledIt =
false;
663 "COMMAND to the server...)\n CHECKSUM: " << nChecksum <<
"\n";
666 else if (buf[0] ==
'2') {
675 otOut <<
"(User has instructed to send a size "
677 "command** to the server...)\n";
681 else if (buf[0] ==
'3') {
682 otOut <<
"(User has instructed to create a signed XML message "
683 "and send it to the server...)\n";
697 theMessage.SaveContract();
712 if (!bHandledIt && m_pNym && m_pServerContract) {
715 otOut <<
"(User has instructed to send a checkServerID "
716 "command to the server...)\n";
722 *m_pServerContract,
nullptr) >
729 otErr <<
"Error processing checkServerID command in "
730 "ProcessMessage: " << buf[0] <<
"\n";
734 else if (buf[0] ==
'r') {
735 otOut <<
"(User has instructed to send a createUserAccount "
736 "command to the server...)\n";
742 *m_pServerContract,
nullptr) >
749 otErr <<
"Error processing createUserAccount command in "
750 "ProcessMessage: " << buf[0] <<
"\n";
758 else if (buf[0] ==
'u') {
759 otOut <<
"(User has instructed to send a checkUser command "
760 "to the server...)\n";
765 *m_pNym, *m_pServerContract,
773 otErr <<
"Error processing checkUser command in "
774 "ProcessMessage: " << buf[0] <<
"\n";
778 else if (buf[0] ==
'a') {
779 otOut <<
"(User has instructed to send a createAccount "
780 "command to the server...)\n";
793 otErr <<
"Error processing createAccount command in "
794 "ProcessMessage: " << buf[0] <<
"\n";
798 else if (!strcmp(buf,
"issue\n")) {
799 otOut <<
"(User has instructed to send an issueAssetType "
800 "command to the server...)\n";
806 *m_pServerContract,
nullptr) >
813 otErr <<
"Error processing issueAssetType command in "
814 "ProcessMessage: " << buf[0] <<
"\n";
818 else if (!strcmp(buf,
"basket\n")) {
819 otOut <<
"(User has instructed to send an issueBasket "
820 "command to the server...)\n";
825 *m_pNym, *m_pServerContract,
833 otErr <<
"Error processing issueBasket command in "
834 "ProcessMessage: " << buf[0] <<
"\n";
838 else if (!strcmp(buf,
"exchange\n")) {
839 otOut <<
"(User has instructed to send an exchangeBasket "
840 "command to the server...)\n";
846 *m_pServerContract,
nullptr) >
853 otErr <<
"Error processing exchangeBasket command in "
854 "ProcessMessage: " << buf[0] <<
"\n";
858 else if (!strcmp(buf,
"offer\n")) {
859 otOut <<
"(User has instructed to send a marketOffer "
860 "command to the server...)\n";
865 *m_pNym, *m_pServerContract,
873 otErr <<
"Error processing marketOffer command in "
874 "ProcessMessage: " << buf[0] <<
"\n";
878 else if (!strcmp(buf,
"setassetname\n")) {
879 otOut <<
"(User has instructed to set an Asset Contract's "
880 "client-side name...)\n";
895 else if (!strcmp(buf,
"setservername\n")) {
896 otOut <<
"(User has instructed to set a Server Contract's "
897 "client-side name...)\n";
903 *m_pServerContract,
nullptr) >
912 else if (!strcmp(buf,
"setnymname\n")) {
914 <<
"(User has instructed to set a Nym's client-side name...)\n";
919 *m_pNym, *m_pServerContract,
929 else if (!strcmp(buf,
"setaccountname\n")) {
930 otOut <<
"(User wants to set an Asset Account's client-side "
937 *m_pServerContract,
nullptr) >
946 else if (buf[0] ==
's') {
947 otOut <<
"(User has instructed to send a sendUserMessage "
948 "command to the server...)\n";
954 *m_pServerContract,
nullptr) >
961 otErr <<
"Error processing sendUserMessage command in "
962 "ProcessMessage: " << buf[0] <<
"\n";
966 else if (buf[0] ==
'y') {
967 otOut <<
"(User has instructed to send a getNymbox command "
968 "to the server...)\n";
973 *m_pNym, *m_pServerContract,
981 otErr <<
"Error processing getNymbox command in "
982 "ProcessMessage: " << buf[0] <<
"\n";
986 else if (buf[0] ==
'i') {
987 otOut <<
"(User has instructed to send a getInbox command "
988 "to the server...)\n";
1000 otErr <<
"Error processing getInbox command in ProcessMessage: "
1005 else if (buf[0] ==
'o') {
1006 otOut <<
"(User has instructed to send a getOutbox command "
1007 "to the server...)\n";
1012 *m_pNym, *m_pServerContract,
1016 bSendCommand =
true;
1017 bSendPayload =
true;
1020 otErr <<
"Error processing getOutbox command in "
1021 "ProcessMessage: " << buf[0] <<
"\n";
1025 else if (buf[0] ==
'q') {
1026 otOut <<
"User has instructed to deposit a cheque...\n";
1031 theMessage, *m_pNym,
1032 *m_pServerContract,
nullptr) >
1035 bSendCommand =
true;
1036 bSendPayload =
true;
1039 otErr <<
"Error processing deposit cheque command in "
1040 "ProcessMessage: " << buf[0] <<
"\n";
1044 else if (buf[0] ==
'v') {
1045 otOut <<
"User has instructed to withdraw a voucher (like "
1046 "a cashier's cheque)...\n";
1051 theMessage, *m_pNym,
1052 *m_pServerContract,
nullptr) >
1055 bSendCommand =
true;
1056 bSendPayload =
true;
1059 otErr <<
"Error processing withdraw voucher command in "
1060 "ProcessMessage: " << buf[0] <<
"\n";
1064 else if (buf[0] ==
'w') {
1065 otOut <<
"(User has instructed to withdraw cash...)\n";
1070 theMessage, *m_pNym,
1071 *m_pServerContract,
nullptr) >
1074 bSendCommand =
true;
1075 bSendPayload =
true;
1078 otErr <<
"Error processing withdraw command in ProcessMessage: "
1083 else if (buf[0] ==
'd') {
1084 otOut <<
"(User has instructed to deposit cash tokens...)\n";
1089 theMessage, *m_pNym,
1090 *m_pServerContract,
nullptr) >
1093 bSendCommand =
true;
1094 bSendPayload =
true;
1097 otErr <<
"Error processing deposit command in ProcessMessage: "
1102 else if (!strcmp(buf,
"plan\n")) {
1103 otOut <<
"User has instructed to activate a payment plan...\n";
1108 *m_pNym, *m_pServerContract,
1112 bSendCommand =
true;
1113 bSendPayload =
true;
1116 otErr <<
"Error processing payment plan command in "
1117 "ProcessMessage: " << buf[0] <<
"\n";
1121 else if (buf[0] ==
'p') {
1122 otOut <<
"(User has instructed to deposit a purse "
1123 "containing cash...)\n";
1128 theMessage, *m_pNym,
1129 *m_pServerContract,
nullptr) >
1132 bSendCommand =
true;
1133 bSendPayload =
true;
1136 otErr <<
"Error processing deposit command in ProcessMessage: "
1141 else if (!strcmp(buf,
"test\n")) {
1142 otOut <<
"(User has instructed to perform a test...)\n";
1147 OTString strMessage(
1148 "Well well well, this is just a little bit of "
1149 "plaintext.\nNotice there are NO NEWLINES at the start.\n"
1150 "I'm just trying to make it as long as i can, so that\nI "
1151 "can test the envelope and armor functionality.\n");
1153 otOut <<
"MESSAGE:\n------>" << strMessage <<
"<--------\n";
1155 OTASCIIArmor ascMessage(strMessage);
1157 otOut <<
"ASCII ARMOR:\n------>" << ascMessage <<
"<--------\n";
1159 OTEnvelope theEnvelope;
1160 theEnvelope.Seal(*m_pNym, strMessage);
1162 ascMessage.Release();
1164 theEnvelope.GetAsciiArmoredData(ascMessage);
1166 otOut <<
"ENCRYPTED PLAIN TEXT AND THEN ASCII "
1167 "ARMOR:\n------>" << ascMessage <<
"<--------\n";
1169 strMessage.Release();
1171 OTEnvelope the2Envelope(ascMessage);
1172 the2Envelope.Open(*m_pNym, strMessage);
1174 otOut <<
"DECRYPTED PLAIN TEXT:\n------>" << strMessage
1177 OTEnvelope the3Envelope;
1178 the3Envelope.Seal(*m_pNym, strMessage.Get());
1180 ascMessage.Release();
1182 the3Envelope.GetAsciiArmoredData(ascMessage);
1184 otOut <<
"RE-ENCRYPTED PLAIN TEXT AND THEN ASCII "
1185 "ARMOR:\n------>" << ascMessage <<
"<--------\n";
1187 strMessage.Release();
1189 OTEnvelope the4Envelope(ascMessage);
1190 the4Envelope.Open(*m_pNym, strMessage);
1192 otOut <<
"RE-DECRYPTED PLAIN TEXT:\n------>" << strMessage
1195 OTEnvelope the5Envelope;
1196 the5Envelope.Seal(*m_pNym, strMessage.Get());
1198 ascMessage.Release();
1200 the3Envelope.GetAsciiArmoredData(ascMessage);
1202 otOut <<
"RE-RE-ENCRYPTED PLAIN TEXT AND THEN ASCII "
1203 "ARMOR:\n------>" << ascMessage <<
"<--------\n";
1205 strMessage.Release();
1207 OTEnvelope the6Envelope(ascMessage);
1208 the6Envelope.Open(*m_pNym, strMessage);
1210 otOut <<
"RE-RE-DECRYPTED PLAIN TEXT:\n------>" << strMessage
1217 else if (!strcmp(buf,
"get\n")) {
1218 otOut <<
"(User has instructed to send a getAccount "
1219 "command to the server...)\n";
1224 *m_pNym, *m_pServerContract,
1228 bSendCommand =
true;
1229 bSendPayload =
true;
1232 otErr <<
"Error processing getAccount command in "
1233 "ProcessMessage: " << buf[0] <<
"\n";
1237 else if (!strcmp(buf,
"getcontract\n")) {
1238 otOut <<
"(User has instructed to send a getContract "
1239 "command to the server...)\n";
1244 *m_pNym, *m_pServerContract,
1248 bSendCommand =
true;
1249 bSendPayload =
true;
1252 otErr <<
"Error processing getContract command in "
1253 "ProcessMessage: " << buf[0] <<
"\n";
1257 else if (!strcmp(buf,
"signcontract\n")) {
1258 otOut <<
"Is the contract a server contract, or an asset "
1260 OTString strContractType;
1261 strContractType.OTfgets(std::cin);
1263 char cContractType =
's';
1264 bool bIsAssetContract = strContractType.At(0, cContractType);
1266 if (bIsAssetContract) {
1267 if (
'S' == cContractType ||
's' == cContractType)
1268 bIsAssetContract =
false;
1270 otOut <<
"Is the contract properly escaped already? (If "
1271 "escaped, all lines beginning with ----- will "
1272 "instead appear as - ----- ) [y\n]: ";
1279 strEscape.OTfgets(std::cin);
1282 bool bEscaped = strEscape.At(0, cEscape);
1285 if (
'N' == cEscape ||
'n' == cEscape) bEscaped =
false;
1288 otOut <<
"Please enter an unsigned asset contract; "
1289 "terminate with ~ on a new line:\n> ";
1290 OTString strContract;
1291 char decode_buffer[200];
1295 decode_buffer[0] = 0;
1298 fgets(decode_buffer,
sizeof(decode_buffer) - 1, stdin)) &&
1299 (decode_buffer[0] !=
'~')) {
1300 if (!bEscaped && decode_buffer[0] ==
'-') {
1301 strContract.Concatenate(
"- ");
1303 strContract.Concatenate(
"%s", decode_buffer);
1310 }
while (decode_buffer[0] !=
'~');
1312 OTServerContract theServerContract;
1313 OTAssetContract theAssetContract;
1315 OTContract* pContract =
1317 ?
dynamic_cast<OTContract*
>(&theAssetContract)
1318 : dynamic_cast<OTContract*>(&theServerContract);
1320 pContract->CreateContract(strContract, *m_pNym);
1323 strContract.Release();
1324 pContract->SaveContractRaw(strContract);
1326 otOut <<
".\n..\n...\n....\n.....\n......\n.......\n........\n....."
1327 "....\n\nNEW CONTRACT:\n\n" << strContract <<
"\n";
1331 else if (!strcmp(buf,
"getmint\n")) {
1332 otOut <<
"(User has instructed to send a getMint command "
1333 "to the server...)\n";
1341 bSendCommand =
true;
1342 bSendPayload =
true;
1345 otErr <<
"Error processing getMint command in ProcessMessage: "
1350 else if (buf[0] ==
't') {
1351 otOut <<
"(User has instructed to send a Transfer command "
1352 "(Notarize Transactions) to the server...)\n";
1357 theMessage, *m_pNym,
1358 *m_pServerContract,
nullptr) >
1361 bSendCommand =
true;
1362 bSendPayload =
true;
1365 otErr <<
"Error processing notarizeTransactions command "
1366 "in ProcessMessage: " << buf[0] <<
"\n";
1370 else if (buf[0] ==
'g') {
1371 otOut <<
"(User has instructed to send a getRequest "
1372 "command to the server...)\n";
1377 *m_pNym, *m_pServerContract,
1381 bSendCommand =
true;
1382 bSendPayload =
true;
1385 otErr <<
"Error processing getRequest command in "
1386 "ProcessMessage: " << buf[0] <<
"\n";
1390 else if (buf[0] ==
'n') {
1407 int64_t lTransactionNumber =
1408 ((strlen(buf) > 2) ? atol(&(buf[2])) : 0);
1410 if (lTransactionNumber > 0) {
1411 OTString strServerID;
1418 otOut <<
"Transaction number " << lTransactionNumber
1419 <<
" added to both lists "
1420 "(on client side.)\n";
1423 otOut <<
"(User has instructed to send a "
1424 "getTransactionNum command to the "
1430 theMessage, *m_pNym,
1431 *m_pServerContract,
nullptr) >
1434 bSendCommand =
true;
1435 bSendPayload =
true;
1438 otErr <<
"Error processing getTransactionNum command "
1439 "in ProcessMessage: " << buf[0] <<
"\n";
1450 else if (!bHandledIt) {
1454 if (bSendCommand && bSendPayload) {
EXPORT OT_BYTE CalcChecksum(OT_BYTE *buffer, uint32_t size)
#define OT_CMD_HEADER_SIZE
OTLOG_IMPORT OTLogStream otOut
EXPORT int32_t ProcessUserCommand(OT_CLIENT_CMD_TYPE requestedCommand, OTMessage &theMessage, OTPseudonym &theNym, const OTServerContract &theServer, const OTAccount *pAccount=nullptr, int64_t lTransactionAmount=0, OTAssetContract *pMyAssetContract=nullptr, const OTIdentifier *pHisNymID=nullptr, const OTIdentifier *pHisAcctID=nullptr)
EXPORT bool SignContractWithFirstNymOnList(OTContract &theContract)
EXPORT bool AddTransactionNum(OTPseudonym &SIGNER_NYM, const OTString &strServerID, int64_t lTransNum, bool bSave)
void ProcessMessageOut(const char *buf, const int32_t *pnExpectReply)
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
OTLOG_IMPORT OTLogStream otErr