add parser to 1D format

This commit is contained in:
Vladimir N. Korotenko
2025-11-15 12:30:25 +03:00
parent 014c04fce1
commit b4a2cf2ecf
6 changed files with 57 additions and 4 deletions

View File

@@ -10,6 +10,7 @@
#include "cleanHtml.h" #include "cleanHtml.h"
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
#include <ctime>
using namespace std; using namespace std;
@@ -131,6 +132,7 @@ int Deals::Create()
} }
else else
{ {
pay = GetDate(pay);
string untl(",\"until\": \""); string untl(",\"until\": \"");
untl.append(pay); untl.append(pay);
untl.append("\""); untl.append("\"");
@@ -144,7 +146,7 @@ int Deals::Create()
} }
else else
{ {
leave_before = GetDate(leave_before);
string untl(",\"feedback\": {\"leave-before\": \""); string untl(",\"feedback\": {\"leave-before\": \"");
untl.append(leave_before); untl.append(leave_before);
untl.append("\"}"); untl.append("\"}");
@@ -168,6 +170,49 @@ int Deals::Create()
return 0; return 0;
} }
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) {
char letter = buffer[buffer.length() - 1];
int append = 0;
string numval = buffer.substr(0, buffer.length() - 1);
int num = stoi(numval);
switch (letter)
{
case 'S':
append = num;
break;
case 'M':
append = num * 60;
break;
case 'H':
append = num * 60 * 60;
break;
case 'D':
append = num * 24 * 60 * 60;
break;
default:
break;
}
std::time_t utcTimeInSeconds = std::time(nullptr);
utcTimeInSeconds += append;
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 {
return buffer;
}
}
int Deals::Status() int Deals::Status()
{ {

View File

@@ -30,7 +30,7 @@ private:
int Negative(); int Negative();
std::string GetVal(const std::string first,const std::string second); std::string GetVal(const std::string first,const std::string second);
std::string GetDate(const std::string date);
}; };
#endif #endif

Binary file not shown.

View File

@@ -1 +1,3 @@
dm-cli deal create -a https://test.com -s mnumHs9HQMrw2Q1iKLNnx9NzExS7nMLmyp -c mraXx7JrmAmuKypdJ1vseQBXySsdRZE5AC -t Prepayment -s 0.1 -l 14d -p 1d dm-cli deal create -a https://test.com -s mnumHs9HQMrw2Q1iKLNnx9NzExS7nMLmyp -c mraXx7JrmAmuKypdJ1vseQBXySsdRZE5AC -t Prepayment -s 0.1 -l 14d -p 1d
dm-cli --address https://testnet-dm2.bitdeals.org deal status 3e251d8fdcfa80adf5a3050064fc4ecb01d304d1

View File

@@ -45,9 +45,12 @@
<ClCompile Include="..\dm-cli\ShowDebug.cpp" /> <ClCompile Include="..\dm-cli\ShowDebug.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\dm-cli\check.sh" />
<None Include="..\dm-cli\createdistr.sh" />
<None Include="..\dm-cli\Makefile"> <None Include="..\dm-cli\Makefile">
<DeploymentContent>true</DeploymentContent> <DeploymentContent>true</DeploymentContent>
</None> </None>
<None Include="..\dm-cli\test.cmd" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="..\dm-cli\account_status_en.txt"> <Text Include="..\dm-cli\account_status_en.txt">

View File

@@ -88,6 +88,9 @@
<None Include="..\dm-cli\Makefile"> <None Include="..\dm-cli\Makefile">
<Filter>Resource Files</Filter> <Filter>Resource Files</Filter>
</None> </None>
<None Include="..\dm-cli\test.cmd" />
<None Include="..\dm-cli\createdistr.sh" />
<None Include="..\dm-cli\check.sh" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="..\dm-cli\main_help_ru.txt"> <Text Include="..\dm-cli\main_help_ru.txt">