Complite action added
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using json = nlohmann::json;
|
||||||
int Deals::HelpCreate() const
|
int Deals::HelpCreate() const
|
||||||
{
|
{
|
||||||
if (isRussian)
|
if (isRussian)
|
||||||
@@ -201,11 +201,11 @@ string Deals::GetDate(const string date) {
|
|||||||
}
|
}
|
||||||
std::time_t utcTimeInSeconds = std::time(nullptr);
|
std::time_t utcTimeInSeconds = std::time(nullptr);
|
||||||
utcTimeInSeconds += append;
|
utcTimeInSeconds += append;
|
||||||
|
|
||||||
|
|
||||||
tm * tmm = gmtime(&utcTimeInSeconds);
|
tm* tmm = gmtime(&utcTimeInSeconds);
|
||||||
char buff[70];
|
char buff[70];
|
||||||
strftime(buff, sizeof buff, "%Y-%m-%d %H:%M:%S UTC", tmm);
|
strftime(buff, sizeof buff, "%Y-%m-%d %H:%M:%S UTC", tmm);
|
||||||
string result = buff;
|
string result = buff;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -214,22 +214,19 @@ string Deals::GetDate(const string date) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Deals::Status()
|
string Deals::CommonStatus() {
|
||||||
{
|
|
||||||
|
|
||||||
string payaddress = parser.getLast();
|
string payaddress = parser.getLast();
|
||||||
/*
|
|
||||||
curl -X POST "https://testnet-dm2.bitdeals.org/api/v1/deal/status" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{"address":"3e251d8fdcfa80adf5a3050064fc4ecb01d304d1"}'
|
|
||||||
*/
|
|
||||||
string data("curl -X POST \"");
|
string data("curl -X POST \"");
|
||||||
data.append(address);
|
data.append(address);
|
||||||
data.append("/api/v1/deal/status\" -H \"Content-Type: application/json\" ");
|
data.append("/api/v1/deal/status\" -H \"Content-Type: application/json\" ");
|
||||||
data.append("-d '{\"address\":\"");
|
data.append("-d \"{\\\"address\\\":\\\"");
|
||||||
data.append(payaddress);
|
data.append(payaddress);
|
||||||
data.append("\"}'");
|
data.append("\\\"}\"");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
int Deals::Status()
|
||||||
|
{
|
||||||
|
string data = CommonStatus();
|
||||||
string result = ExecCommand(data.c_str());
|
string result = ExecCommand(data.c_str());
|
||||||
if (result.length() == 0)
|
if (result.length() == 0)
|
||||||
return NoResponse("");
|
return NoResponse("");
|
||||||
@@ -258,7 +255,63 @@ int Deals::Status()
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int Deals::Complite() { return 0; }
|
int Deals::Complite() {
|
||||||
|
|
||||||
|
string data = CommonStatus();
|
||||||
|
string result = ExecCommand(data.c_str());
|
||||||
|
if (result.length() == 0)
|
||||||
|
return NoResponse("");
|
||||||
|
nlohmann::json jsonData = nlohmann::json::parse(result);
|
||||||
|
nlohmann::json deal = jsonData["deal"];
|
||||||
|
|
||||||
|
string positive = "Positive";
|
||||||
|
int refund = 0;
|
||||||
|
if (parser.cmdOptionExists("-p") || parser.cmdOptionExists("--positive"))
|
||||||
|
{
|
||||||
|
positive = GetVal("-p", "--positive");
|
||||||
|
}
|
||||||
|
if (parser.cmdOptionExists("--refund"))
|
||||||
|
{
|
||||||
|
refund = stoi(parser.getCmdOption("--refund"));
|
||||||
|
}
|
||||||
|
if (parser.cmdOptionExists("-r"))
|
||||||
|
{
|
||||||
|
refund = stoi(parser.getCmdOption("-r"));
|
||||||
|
}
|
||||||
|
|
||||||
|
deal["feedback"]["status"] = positive;
|
||||||
|
if (refund > 0)
|
||||||
|
deal["feedback"]["refund"] = refund;
|
||||||
|
|
||||||
|
string jsf = deal.dump();
|
||||||
|
jsf = ReplaceAll(jsf, "\"", "\\\"");
|
||||||
|
data = "curl -X POST \"";
|
||||||
|
data.append(address);
|
||||||
|
data.append("/api/v1/deal/complete\" -H \"Content-Type: application/json\" ");
|
||||||
|
data.append("-d \"");
|
||||||
|
data.append(jsf);
|
||||||
|
data.append("\"");
|
||||||
|
|
||||||
|
result = ExecCommand(data.c_str());
|
||||||
|
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;
|
||||||
|
|
||||||
|
if (isDebug)
|
||||||
|
ShowDebug(data, decoded, 0, result);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int Deals::Cancel() { return 0; }
|
int Deals::Cancel() { return 0; }
|
||||||
int Deals::Negative() { return 0; }
|
int Deals::Negative() { return 0; }
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ private:
|
|||||||
int Update();
|
int Update();
|
||||||
int Create();
|
int Create();
|
||||||
int Status();
|
int Status();
|
||||||
|
std::string CommonStatus();
|
||||||
int Complite();
|
int Complite();
|
||||||
int Cancel();
|
int Cancel();
|
||||||
int Negative();
|
int Negative();
|
||||||
|
|||||||
@@ -1,14 +1,24 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
std::string Replace(std::string source, std::string from, std::string out) {
|
std::string Replace(std::string source, std::string from, std::string out) {
|
||||||
std::string res("");
|
std::string res("");
|
||||||
size_t start = 0, stop = 0;
|
size_t start = 0, stop = 0;
|
||||||
start = source.find(from);
|
start = source.find(from);
|
||||||
stop = from.length();
|
stop = from.length();
|
||||||
if (start >= 0 ) res = source.replace(start, stop, out);
|
if (start >= 0) res = source.replace(start, stop, out);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) {
|
||||||
|
size_t start_pos = 0;
|
||||||
|
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||||
|
str.replace(start_pos, from.length(), to);
|
||||||
|
start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
int NoResponse(std::string mgs)
|
int NoResponse(std::string mgs)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,6 +54,10 @@ void ShowDebug(std::string url, std::string result, bool success, std::string de
|
|||||||
std::string ReadFile(const char *filename);
|
std::string ReadFile(const char *filename);
|
||||||
/// @breef Replace in string
|
/// @breef Replace in string
|
||||||
std::string Replace(std::string source, std::string from, std::string out);
|
std::string Replace(std::string source, std::string from, std::string out);
|
||||||
|
|
||||||
|
/// @breef Replace all entryes in string
|
||||||
|
std::string ReplaceAll(std::string str, const std::string& from, const std::string& to);
|
||||||
|
|
||||||
/// @breef Вывод сообщения о таймауте или пустой строке ответа
|
/// @breef Вывод сообщения о таймауте или пустой строке ответа
|
||||||
int NoResponse(std::string mgs);
|
int NoResponse(std::string mgs);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user