Статус сделки
This commit is contained in:
8
dm-cli/.vscode/launch.json
vendored
8
dm-cli/.vscode/launch.json
vendored
@@ -12,11 +12,9 @@
|
||||
"args": [ "--address",
|
||||
"https://testnet-dm2.bitdeals.org",
|
||||
"--debug",
|
||||
"account", "update",
|
||||
"-d", "2020-01-01",
|
||||
"-s", "IEF1ysyhu8ps0m5xSJaZZg/5hBylmcWQQggkGO7yNN8iMf/EA2O287kxi58xCDDtxvdsC0TWqylVE5MT5CouamU=",
|
||||
"--pgp", "$PGP",
|
||||
"mnumHs9HQMrw2Q1iKLNnx9NzExS7nMLmyp"],
|
||||
"deal",
|
||||
"status",
|
||||
"3e251d8fdcfa80adf5a3050064fc4ecb01d304d1"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [],
|
||||
|
||||
132
dm-cli/Deals.cpp
132
dm-cli/Deals.cpp
@@ -13,7 +13,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
int Deals::HelpCreate() const {
|
||||
int Deals::HelpCreate() const
|
||||
{
|
||||
if (isRussian)
|
||||
PrintFile(DEALS_RU);
|
||||
else
|
||||
@@ -43,7 +44,6 @@ int Deals::HelpDealCancel() const
|
||||
else
|
||||
PrintFile(DEAL_CANCEL_EN);
|
||||
return 0;
|
||||
|
||||
}
|
||||
int Deals::HelpDealNegative() const
|
||||
{
|
||||
@@ -75,12 +75,12 @@ int Deals::Process()
|
||||
if (parser.cmdOptionExists("deal") && this->parser.cmdOptionExists("negative") && this->parser.cmdOptionExists("--help"))
|
||||
return this->HelpDealNegative();
|
||||
|
||||
|
||||
return Update();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Deals::Update() {
|
||||
int Deals::Update()
|
||||
{
|
||||
if (parser.cmdOptionExists("deal") && this->parser.cmdOptionExists("create"))
|
||||
return Create();
|
||||
if (parser.cmdOptionExists("deal") && this->parser.cmdOptionExists("status"))
|
||||
@@ -94,28 +94,8 @@ int Deals::Update() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Deals::Create() {
|
||||
/*
|
||||
Использование: dm-cli deal create [параметры]
|
||||
|
||||
Создать новую сделку
|
||||
|
||||
[smhd] означает секунды, минуты, часы, дни.
|
||||
Например: --leave-before 2020-01-01, or --leave-before 10d.
|
||||
|
||||
-a|--at Сайт проведения сделки
|
||||
-s|--seller Продавец в сделке
|
||||
-c|--customer Покупатель в сделке
|
||||
-t|--type [prepayment|postpayment]
|
||||
Тип сделки
|
||||
-s|--sum Сумма сделки в BTC
|
||||
-l|--leave-before { <гггг-мм-дд> [чч:мм:сс UTC] | <время>[smhd] }
|
||||
Время окончания сделки (длительность сделки), по умолчанию: 14d
|
||||
-p|--pay { <гггг-мм-дд> [чч:мм:сс UTC] | <время>[smhd] }
|
||||
Время для оплаты сделки; по умолчанию: 1d
|
||||
|
||||
*/
|
||||
|
||||
int Deals::Create()
|
||||
{
|
||||
|
||||
string at;
|
||||
string seller;
|
||||
@@ -125,8 +105,6 @@ int Deals::Create() {
|
||||
string leave_before;
|
||||
string pay;
|
||||
|
||||
|
||||
|
||||
at = GetVal("-a", "--at");
|
||||
seller = GetVal("-s", "--seller");
|
||||
customer = GetVal("-c", "--customer");
|
||||
@@ -139,7 +117,6 @@ int Deals::Create() {
|
||||
string data("");
|
||||
data += ReadFile(DEAL_CREATE_TPL);
|
||||
|
||||
|
||||
data = Replace(data, string("{{ADDRESS}}"), address);
|
||||
data = Replace(data, string("{{AT}}"), at);
|
||||
data = Replace(data, string("{{TYPE}}"), type);
|
||||
@@ -147,24 +124,26 @@ int Deals::Create() {
|
||||
data = Replace(data, string("{{CUSTOMER}}"), customer);
|
||||
data = Replace(data, string("{{SUM}}"), sum);
|
||||
|
||||
|
||||
if (pay.length() == 0) {
|
||||
if (pay.length() == 0)
|
||||
{
|
||||
//{{UNTIL}}
|
||||
data = Replace(data, string("{{UNTIL}}"), "");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
string untl(",\"until\": \"");
|
||||
untl.append(pay);
|
||||
untl.append("\"");
|
||||
data = Replace(data, string("{{UNTIL}}"), untl);
|
||||
|
||||
}
|
||||
|
||||
if (leave_before.length() == 0) {
|
||||
if (leave_before.length() == 0)
|
||||
{
|
||||
//{{FEETBACK}}
|
||||
data = Replace(data, string("{{FEETBACK}}"), "");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
|
||||
string untl(",\"feedback\": {\"leave-before\": \"");
|
||||
untl.append(leave_before);
|
||||
@@ -173,29 +152,9 @@ int Deals::Create() {
|
||||
data = Replace(data, string("{{FEETBACK}}"), untl);
|
||||
}
|
||||
|
||||
/*
|
||||
"payment": {
|
||||
"address": "<string>",
|
||||
"until": "<datetime>",
|
||||
"sum": "<double>"
|
||||
},
|
||||
"feedback": {
|
||||
"leave-before": "<datetime>",
|
||||
"status": "<string>",
|
||||
"comments": "<string>"
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
curl -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}} }'
|
||||
*/
|
||||
|
||||
|
||||
|
||||
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;
|
||||
@@ -208,13 +167,52 @@ int Deals::Create() {
|
||||
ShowDebug(data, decoded, 1, payload);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Deals::Status()
|
||||
{
|
||||
|
||||
int Deals::Status() { return 0; }
|
||||
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 \"");
|
||||
data.append(address);
|
||||
data.append("/api/v1/deal/status\" -H \"Content-Type: application/json\" ");
|
||||
data.append("-d '{\"address\":\"");
|
||||
data.append(payaddress);
|
||||
data.append("\"}'");
|
||||
|
||||
string result = ExecCommand(data.c_str());
|
||||
if (result.length() == 0)
|
||||
return NoResponse("");
|
||||
nlohmann::json jsonData = nlohmann::json::parse(result);
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << "success: " << jsonData["result"]["success"] << endl;
|
||||
stream << "message: " << jsonData["result"]["message"] << endl;
|
||||
bool isPayment = false;
|
||||
string payload = cleanup_html(base64_decode(jsonData["payload"]));
|
||||
// order: Paid, order: Completed, order: Executed
|
||||
if (payload.find("Paid") >= 0 || payload.find("Completed") >= 0 || payload.find("Executed") >= 0)
|
||||
{
|
||||
isPayment = true;
|
||||
}
|
||||
stream << "order: " << isPayment << endl;
|
||||
|
||||
string decoded = stream.str();
|
||||
cout << decoded << endl;
|
||||
|
||||
if (isDebug)
|
||||
ShowDebug(data, decoded, 1, payload);
|
||||
if (parser.cmdOptionExists("-i") || parser.cmdOptionExists("--is-paid"))
|
||||
{
|
||||
return isPayment;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int Deals::Complite() { return 0; }
|
||||
int Deals::Cancel() { return 0; }
|
||||
int Deals::Negative() { return 0; }
|
||||
@@ -223,13 +221,17 @@ string Deals::GetVal(const string first, const string second)
|
||||
{
|
||||
string aval;
|
||||
string res("");
|
||||
if (parser.cmdOptionExists(first)) {
|
||||
if (parser.cmdOptionExists(first))
|
||||
{
|
||||
aval = parser.getCmdOption(first);
|
||||
if (aval.length() > 0) res = aval;
|
||||
if (aval.length() > 0)
|
||||
res = aval;
|
||||
}
|
||||
if (parser.cmdOptionExists(second)) {
|
||||
if (parser.cmdOptionExists(second))
|
||||
{
|
||||
aval = parser.getCmdOption(second);
|
||||
if (aval.length() > 0) res = aval;
|
||||
if (aval.length() > 0)
|
||||
res = aval;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ std::string cleanup_html(std::string const &encoded_string)
|
||||
ret = encoded_string.substr(start, last - start);
|
||||
|
||||
size_t b = 0;
|
||||
for (int a = b; a < ret.length(); a++)
|
||||
for (int a = b; a < (int)(ret.length()); a++)
|
||||
{
|
||||
if (ret[a] == '<')
|
||||
{
|
||||
for (int b = a; b < ret.length(); b++)
|
||||
for (int b = a; b < (int)ret.length(); b++)
|
||||
{
|
||||
if (ret[b] == '>')
|
||||
{
|
||||
|
||||
@@ -54,7 +54,7 @@ void ShowDebug(std::string url, std::string result, bool success, std::string de
|
||||
std::string ReadFile(const char *filename);
|
||||
/// @breef Replace in string
|
||||
std::string Replace(std::string source, std::string from, std::string out);
|
||||
|
||||
/// @breef Вывод сообщения о таймауте или пустой строке ответа
|
||||
int NoResponse(std::string mgs);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,7 +32,8 @@ bool IsRuLang()
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int r = system("curl");
|
||||
// TODO: in windows create folder in disk contains source file eg: project folder is d:\prj\src create folder d:\dev and add empty file null
|
||||
int r = system("curl > /dev/null 2>&1");
|
||||
if (r == 2) {
|
||||
//OK
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user