Close #6 Close #9 add default value param --at silent mode to template. fix PGP signature

This commit is contained in:
Vladimir N. Korotenko
2025-11-18 10:31:48 +03:00
parent 79e97e20ea
commit 4bdbb3e525
3 changed files with 28 additions and 29 deletions

View File

@@ -78,7 +78,8 @@ int AccountUpdate::ProcessUrl(std::string date, std::string signature, std::stri
data = Replace(data, string("{{URLS}}"), urlout);
string result = ExecCommand(data.c_str());
if (result.length() == 0) return NoResponse("");
if (result.length() == 0)
return NoResponse("");
nlohmann::json jsonData = nlohmann::json::parse(result);
std::ostringstream stream;
@@ -100,14 +101,15 @@ int AccountUpdate::ProcessPgp(std::string date, std::string signature, std::stri
data += ReadFile(ACCOUNT_UPDATE_PGP);
string bt("");
bt = parser.getLast();
string pgpencoded = ReplaceAll(pgp, "\n", "\\n");
data = Replace(data, string("{{ADDRESS}}"), address);
data = Replace(data, string("{{BT}}"), bt);
data = Replace(data, string("{{DATE}}"), date);
data = Replace(data, string("{{SIGN}}"), signature);
data = Replace(data, string("{{PGP}}"), pgp);
data = Replace(data, string("{{PGP}}"), pgpencoded);
string result = ExecCommand(data.c_str());
if (result.length() == 0) return NoResponse("");
if (result.length() == 0)
return NoResponse("");
nlohmann::json jsonData = nlohmann::json::parse(result);
std::ostringstream stream;
@@ -136,7 +138,8 @@ int AccountUpdate::ProcessBitmessage(std::string date, std::string signature, st
data = Replace(data, string("{{BTM}}"), btmsg);
string result = ExecCommand(data.c_str());
if (result.length() == 0) return NoResponse("");
if (result.length() == 0)
return NoResponse("");
nlohmann::json jsonData = nlohmann::json::parse(result);
std::ostringstream stream;

View File

@@ -54,7 +54,7 @@ int Deals::HelpDealNegative() const
PrintFile(DEAL_NEGATIVE_EN);
return 0;
}
Deals::Deals(const InputParser& parser, const bool isRussian, const string address, bool isDebug)
Deals::Deals(const InputParser &parser, const bool isRussian, const string address, bool isDebug)
{
this->parser = parser;
this->isRussian = isRussian;
@@ -107,6 +107,8 @@ int Deals::Create()
string pay;
at = GetVal("-a", "--at");
if (at.length() == 0)
at = "https://testnet-dm2.bitdeals.org";
seller = GetVal("-s", "--seller");
customer = GetVal("-c", "--customer");
type = GetVal("-t", "--type");
@@ -170,14 +172,16 @@ int Deals::Create()
return 0;
}
string Deals::GetDate(const string date) {
string Deals::GetDate(const string date)
{
string buffer = date;
/*
-p|--pay { <yyyy-mm-dd> [hh:mm:ss UTC] | <time>[smhd] }
Time for make payment; default: 1d
*/
std::transform(buffer.begin(), buffer.end(), buffer.begin(), ::toupper);
if (buffer.length() < 23) {
if (buffer.length() < 23)
{
char letter = buffer[buffer.length() - 1];
int append = 0;
string numval = buffer.substr(0, buffer.length() - 1);
@@ -202,19 +206,20 @@ string Deals::GetDate(const string date) {
std::time_t utcTimeInSeconds = std::time(nullptr);
utcTimeInSeconds += append;
tm* tmm = gmtime(&utcTimeInSeconds);
tm *tmm = gmtime(&utcTimeInSeconds);
char buff[70];
strftime(buff, sizeof buff, "%Y-%m-%d %H:%M:%S UTC", tmm);
string result = buff;
return result;
}
else {
else
{
return buffer;
}
}
string Deals::CommonStatus() {
string Deals::CommonStatus()
{
string payaddress = parser.getLast();
string data("curl -s -X POST \"");
data.append(address);
@@ -233,7 +238,7 @@ int Deals::Status()
nlohmann::json jsonData = nlohmann::json::parse(result);
std::ostringstream stream;
bool isPayment = false;
string payload = cleanup_html(base64_decode(jsonData["payload"]));
stream << payload << endl;
@@ -242,7 +247,6 @@ int Deals::Status()
{
isPayment = true;
}
string decoded = stream.str();
cout << decoded << endl;
@@ -255,7 +259,8 @@ int Deals::Status()
}
return 0;
}
int Deals::Complite() {
int Deals::Complite()
{
string data = CommonStatus();
string result = ExecCommand(data.c_str());
@@ -296,15 +301,10 @@ int Deals::Complite() {
if (result.length() == 0)
return NoResponse("");
std::ostringstream stream;
stream << "success: " << jsonData["result"]["success"] << endl;
stream << "message: " << jsonData["result"]["message"] << endl;
string decoded = stream.str();
std::cout << decoded << endl;
@@ -312,7 +312,8 @@ int Deals::Complite() {
ShowDebug(data, decoded, 0, result);
return 0;
}
int Deals::Cancel() {
int Deals::Cancel()
{
string data = CommonStatus();
string result = ExecCommand(data.c_str());
if (result.length() == 0)
@@ -351,17 +352,15 @@ int Deals::Cancel() {
stream << "success: " << jsonData["result"]["success"] << endl;
stream << "message: " << jsonData["result"]["message"] << endl;
string decoded = stream.str();
std::cout << decoded << endl;
if (isDebug)
ShowDebug(data, decoded, 0, result);
return 0;
}
int Deals::Negative() {
int Deals::Negative()
{
string data = CommonStatus();
string result = ExecCommand(data.c_str());
if (result.length() == 0)
@@ -400,15 +399,12 @@ int Deals::Negative() {
stream << "success: " << jsonData["result"]["success"] << endl;
stream << "message: " << jsonData["result"]["message"] << endl;
string decoded = stream.str();
std::cout << decoded << endl;
if (isDebug)
ShowDebug(data, decoded, 0, result);
return 0;
}
string Deals::GetVal(const string first, const string second)

View File

@@ -1,3 +1,3 @@
curl -X POST "{{ADDRESS}}/api/v1/deal/create" \
curl -s -X POST "{{ADDRESS}}/api/v1/deal/create" \
-H "Content-Type: application/json" \
-d '{"at":"{{AT}}","type":"{{TYPE}}","seller":{"address": "{{SELLER}}"},"customer":{"address":"{{CUSTOMER}}"},"payment":{"sum":"{{SUM}}" {{UNTIL}} } {{FEETBACK}} }'