Deals create
This commit is contained in:
130
dm-cli/Deals.cpp
130
dm-cli/Deals.cpp
@@ -93,7 +93,122 @@ int Deals::Update() {
|
|||||||
return Negative();
|
return Negative();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Deals::Create() {
|
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
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
string at;
|
||||||
|
string seller;
|
||||||
|
string customer;
|
||||||
|
string type;
|
||||||
|
string sum;
|
||||||
|
string leave_before;
|
||||||
|
string pay;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
at = GetVal("-a", "--at");
|
||||||
|
seller = GetVal("-s", "--seller");
|
||||||
|
customer = GetVal("-c", "--customer");
|
||||||
|
type = GetVal("-t", "--type");
|
||||||
|
sum = GetVal("-g", "--sum");
|
||||||
|
leave_before = GetVal("-l", "--leave_before");
|
||||||
|
pay = GetVal("-p", "--pay");
|
||||||
|
|
||||||
|
// start curl
|
||||||
|
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);
|
||||||
|
data = Replace(data, string("{{SELLER}}"), seller);
|
||||||
|
data = Replace(data, string("{{CUSTOMER}}"), customer);
|
||||||
|
data = Replace(data, string("{{SUM}}"), sum);
|
||||||
|
|
||||||
|
|
||||||
|
if (pay.length() == 0) {
|
||||||
|
//{{UNTIL}}
|
||||||
|
data = Replace(data, string("{{UNTIL}}"), "");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
string untl(",\"until\": \"");
|
||||||
|
untl.append(pay);
|
||||||
|
untl.append("\"");
|
||||||
|
data = Replace(data, string("{{UNTIL}}"), untl);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leave_before.length() == 0) {
|
||||||
|
//{{FEETBACK}}
|
||||||
|
data = Replace(data, string("{{FEETBACK}}"), "");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
string untl(",\"feedback\": {\"leave-before\": \"");
|
||||||
|
untl.append(leave_before);
|
||||||
|
untl.append("\"}");
|
||||||
|
|
||||||
|
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());
|
||||||
|
nlohmann::json jsonData = nlohmann::json::parse(result);
|
||||||
|
|
||||||
|
std::ostringstream stream;
|
||||||
|
stream << "success: " << jsonData["result"]["success"] << endl;
|
||||||
|
stream << "message: " << jsonData["result"]["message"] << endl;
|
||||||
|
string decoded = stream.str();
|
||||||
|
cout << decoded << endl;
|
||||||
|
string payload = cleanup_html(base64_decode(jsonData["payload"]));
|
||||||
|
if (isDebug)
|
||||||
|
ShowDebug(data, decoded, 1, payload);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,3 +217,18 @@ int Deals::Status() { return 0; }
|
|||||||
int Deals::Complite() { return 0; }
|
int Deals::Complite() { return 0; }
|
||||||
int Deals::Cancel() { return 0; }
|
int Deals::Cancel() { return 0; }
|
||||||
int Deals::Negative() { return 0; }
|
int Deals::Negative() { return 0; }
|
||||||
|
|
||||||
|
string Deals::GetVal(const string first, const string second)
|
||||||
|
{
|
||||||
|
string aval;
|
||||||
|
string res("");
|
||||||
|
if (parser.cmdOptionExists(first)) {
|
||||||
|
aval = parser.getCmdOption(first);
|
||||||
|
if (aval.length() > 0) res = aval;
|
||||||
|
}
|
||||||
|
if (parser.cmdOptionExists(second)) {
|
||||||
|
aval = parser.getCmdOption(second);
|
||||||
|
if (aval.length() > 0) res = aval;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ private:
|
|||||||
int Cancel();
|
int Cancel();
|
||||||
int Negative();
|
int Negative();
|
||||||
|
|
||||||
|
std::string GetVal(const std::string first,const std::string second);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
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("");
|
||||||
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 > -1 && stop) return source.replace(start, stop, out);
|
if (start >= 0 ) res = source.replace(start, stop, out);
|
||||||
return std::string("");
|
return res;
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// LANG=ru_RU.UTF-8
|
// LANG=ru_RU.UTF-8
|
||||||
#define LANG_RU "ru_RU.UTF-8"
|
#define LANG_RU "ru_RU.UTF-8"
|
||||||
#define DEFAULTADDRESS "https://127.0.0.1:4999"
|
#define DEFAULTADDRESS "https://127.0.0.1:4999"
|
||||||
@@ -38,6 +40,9 @@
|
|||||||
#define ACCOUNT_UPDATE_BTM "tpl/accountupdatebtm.txt"
|
#define ACCOUNT_UPDATE_BTM "tpl/accountupdatebtm.txt"
|
||||||
#define ACCOUNT_UPDATE_PGP "tpl/accountupdatepgp.txt"
|
#define ACCOUNT_UPDATE_PGP "tpl/accountupdatepgp.txt"
|
||||||
|
|
||||||
|
#define DEAL_CREATE_TPL "tpl/deal_create.txt"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Show help screen.
|
Show help screen.
|
||||||
*/
|
*/
|
||||||
|
|||||||
3
dm-cli/tpl/deal_create.txt
Normal file
3
dm-cli/tpl/deal_create.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
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}} }'
|
||||||
@@ -80,6 +80,7 @@
|
|||||||
</Text>
|
</Text>
|
||||||
<Text Include="..\dm-cli\tpl\accountupdatebtm.txt" />
|
<Text Include="..\dm-cli\tpl\accountupdatebtm.txt" />
|
||||||
<Text Include="..\dm-cli\tpl\accountupdateurl.txt" />
|
<Text Include="..\dm-cli\tpl\accountupdateurl.txt" />
|
||||||
|
<Text Include="..\dm-cli\tpl\deal_create.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<VCProjectVersion>17.0</VCProjectVersion>
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
|||||||
@@ -140,5 +140,8 @@
|
|||||||
<Text Include="..\dm-cli\deal_negative_en.txt">
|
<Text Include="..\dm-cli\deal_negative_en.txt">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Text>
|
</Text>
|
||||||
|
<Text Include="..\dm-cli\tpl\deal_create.txt">
|
||||||
|
<Filter>Resource Files</Filter>
|
||||||
|
</Text>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user