From 53a1cfc109beffff2e815d9c40138297ac50f88a Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Mon, 15 Apr 2024 10:44:29 -0600 Subject: [PATCH 01/12] add test action for epoch time formatting testing only action --- contracts/fio.address/fio.address.abi | 10 ++++++++++ contracts/fio.address/fio.address.cpp | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/contracts/fio.address/fio.address.abi b/contracts/fio.address/fio.address.abi index 67d38e65..028ce21b 100644 --- a/contracts/fio.address/fio.address.abi +++ b/contracts/fio.address/fio.address.abi @@ -154,6 +154,16 @@ } ] }, + { + "name": "fmtepochtm", + "base": "", + "fields": [ + { + "name": "epochtmseconds", + "type": "int64" + } + ] + }, { "name": "updcryptkey", "base": "", diff --git a/contracts/fio.address/fio.address.cpp b/contracts/fio.address/fio.address.cpp index 861f89cd..e23710e8 100644 --- a/contracts/fio.address/fio.address.cpp +++ b/contracts/fio.address/fio.address.cpp @@ -932,8 +932,23 @@ namespace fioio { +//TESTINGONLY DO NOT DELIVER + [[eosio::action]] + void + fmtepochtm(const int64_t &epochtmseconds) { + + struct tm timeinfo; + fioio::convertfiotime(epochtmseconds, &timeinfo); + std::string timebuffer = fioio::tmstringformat(timeinfo); + + const string response_string = string("{\"status\": \"OK\",\"timeresult\":\"") + + timebuffer + string("\"") + string("}"); + + send_response(response_string.c_str()); + } + //TESTINGONLY DO NOT DELIVER [[eosio::action]] @@ -2731,6 +2746,9 @@ namespace fioio { }; EOSIO_DISPATCH(FioNameLookup,(regaddress)(addaddress)(remaddress)(remalladdr)(regdomain)(renewdomain)(renewaddress) + //TESTING ONLY DO NOT DELIVER + (fmtepochtm) + //TESTING ONLY DO NOT deliver (setdomainpub)(burnexpired)(burndomain)(decrcounter)(bind2eosio)(burnaddress)(xferdomain)(xferaddress)(addbundles)(xferescrow) (addnft)(remnft)(remallnfts)(burnnfts)(regdomadd)(updcryptkey)) } From f956fd69f6bc248054eac9e1fdf8ffd60c6786b5 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Mon, 15 Apr 2024 11:38:21 -0600 Subject: [PATCH 02/12] add action add action --- contracts/fio.address/fio.address.abi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contracts/fio.address/fio.address.abi b/contracts/fio.address/fio.address.abi index 028ce21b..8455955b 100644 --- a/contracts/fio.address/fio.address.abi +++ b/contracts/fio.address/fio.address.abi @@ -787,6 +787,11 @@ "type": "decrcounter", "ricardian_contract": "" }, + { + "name": "fmtepochtm", + "type": "fmtepochtm", + "ricardian_contract": "" + }, { "name": "regaddress", "type": "regaddress", From f7dca88c564313df53ee3904b48f1f1f2531f1b9 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Tue, 16 Apr 2024 10:47:09 -0600 Subject: [PATCH 03/12] prototype new epoch time conversion prototype new epoch time conversion --- contracts/fio.common/fiotime.hpp | 53 +++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/contracts/fio.common/fiotime.hpp b/contracts/fio.common/fiotime.hpp index c02e3c27..eb38d965 100644 --- a/contracts/fio.common/fiotime.hpp +++ b/contracts/fio.common/fiotime.hpp @@ -51,7 +51,58 @@ namespace fioio { return timebuffer; } - int convertfiotime(long long t, struct tm *tm) { + + //temporary code for new computations of epoch times + bool isLeapYear(int year) { + return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)); + } + + + + void dateTimeStructFromEpoch(long epochTime, struct tm& resultTime) { + const long secondsPerDay = 86400; + const long secondsPerYear = 31536000; + const long secondsPerLeapYear = 31622400; + const long epochYear = 1970; + // Calculate year + long totalDays = epochTime / secondsPerDay; + int year = epochYear + totalDays / 365; + int leapYears = (year - epochYear) / 4 - (year - epochYear) / 100 + (year - epochYear) / 400; + // Adjust for leap years + totalDays -= leapYears; + while (totalDays < 0 || (isLeapYear(year + 1) && totalDays >= 366) || (!isLeapYear(year + 1) && totalDays >= 365)) { + totalDays -= isLeapYear(year + 1) ? 366 : 365; + year++; + } + // Calculate month and day + int daysInMonth[] = {31, 28 + isLeapYear(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + int month = 1; + while (totalDays >= daysInMonth[month - 1]) { + totalDays -= daysInMonth[month - 1]; + month++; + } + // Calculate day + int day = totalDays + 1; + // Calculate hour, minute, and second + int remainingSeconds = epochTime % secondsPerDay; + int hour = remainingSeconds / 3600; + int minute = (remainingSeconds % 3600) / 60; + int second = remainingSeconds % 60; / + // Populate the tm struct + resultTime.tm_sec = second; + resultTime.tm_min = minute; + resultTime.tm_hour = hour; + resultTime.tm_mday = day; + resultTime.tm_mon = month - 1; + resultTime.tm_year = year - 1900; + } + + + + + + + int convertfiotime(long long t, struct tm *tm) { long long days, secs; int remdays, remsecs, remyears; int qc_cycles, c_cycles, q_cycles; From 075fe03f7330ef119cd99a542de0e4768af3f03f Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Tue, 16 Apr 2024 10:50:11 -0600 Subject: [PATCH 04/12] typo typo --- contracts/fio.common/fiotime.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/fio.common/fiotime.hpp b/contracts/fio.common/fiotime.hpp index eb38d965..89c7423d 100644 --- a/contracts/fio.common/fiotime.hpp +++ b/contracts/fio.common/fiotime.hpp @@ -87,7 +87,7 @@ namespace fioio { int remainingSeconds = epochTime % secondsPerDay; int hour = remainingSeconds / 3600; int minute = (remainingSeconds % 3600) / 60; - int second = remainingSeconds % 60; / + int second = remainingSeconds % 60; // Populate the tm struct resultTime.tm_sec = second; resultTime.tm_min = minute; From 3bec62e2ddbaacd3d77e4c7f0333d592a3d038ec Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Tue, 16 Apr 2024 11:09:31 -0600 Subject: [PATCH 05/12] call the prototype call the prototype --- contracts/fio.address/fio.address.cpp | 3 ++- contracts/fio.common/fiotime.hpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/fio.address/fio.address.cpp b/contracts/fio.address/fio.address.cpp index e23710e8..1dd1caf1 100644 --- a/contracts/fio.address/fio.address.cpp +++ b/contracts/fio.address/fio.address.cpp @@ -940,7 +940,8 @@ namespace fioio { struct tm timeinfo; - fioio::convertfiotime(epochtmseconds, &timeinfo); + // fioio::convertfiotime(epochtmseconds, &timeinfo); + fioio::dateTimeStructFromEpoch(epochtmseconds, &timeinfo); std::string timebuffer = fioio::tmstringformat(timeinfo); const string response_string = string("{\"status\": \"OK\",\"timeresult\":\"") + diff --git a/contracts/fio.common/fiotime.hpp b/contracts/fio.common/fiotime.hpp index 89c7423d..416987f0 100644 --- a/contracts/fio.common/fiotime.hpp +++ b/contracts/fio.common/fiotime.hpp @@ -87,7 +87,7 @@ namespace fioio { int remainingSeconds = epochTime % secondsPerDay; int hour = remainingSeconds / 3600; int minute = (remainingSeconds % 3600) / 60; - int second = remainingSeconds % 60; + int second = remainingSeconds % 60; // Populate the tm struct resultTime.tm_sec = second; resultTime.tm_min = minute; From 84b8f4d0278aebd39a9f70612a93d4d227e2edf9 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Tue, 16 Apr 2024 11:12:17 -0600 Subject: [PATCH 06/12] reference access reference access --- contracts/fio.common/fiotime.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/fio.common/fiotime.hpp b/contracts/fio.common/fiotime.hpp index 416987f0..2055c86f 100644 --- a/contracts/fio.common/fiotime.hpp +++ b/contracts/fio.common/fiotime.hpp @@ -59,7 +59,7 @@ namespace fioio { - void dateTimeStructFromEpoch(long epochTime, struct tm& resultTime) { + void dateTimeStructFromEpoch(long epochTime, struct tm *resultTime) { const long secondsPerDay = 86400; const long secondsPerYear = 31536000; const long secondsPerLeapYear = 31622400; @@ -89,12 +89,12 @@ namespace fioio { int minute = (remainingSeconds % 3600) / 60; int second = remainingSeconds % 60; // Populate the tm struct - resultTime.tm_sec = second; - resultTime.tm_min = minute; - resultTime.tm_hour = hour; - resultTime.tm_mday = day; - resultTime.tm_mon = month - 1; - resultTime.tm_year = year - 1900; + resultTime->tm_sec = second; + resultTime->tm_min = minute; + resultTime->tm_hour = hour; + resultTime->tm_mday = day; + resultTime->tm_mon = month - 1; + resultTime->tm_year = year - 1900; } From e49b599f56aba43a5ecfcf08de6f45c6085f7c5c Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Tue, 16 Apr 2024 13:24:44 -0600 Subject: [PATCH 07/12] bugfix for first three months of year bug fix for first three months of year --- contracts/fio.address/fio.address.cpp | 3 +- contracts/fio.common/fiotime.hpp | 64 ++++++--------------------- 2 files changed, 15 insertions(+), 52 deletions(-) diff --git a/contracts/fio.address/fio.address.cpp b/contracts/fio.address/fio.address.cpp index 1dd1caf1..3131caab 100644 --- a/contracts/fio.address/fio.address.cpp +++ b/contracts/fio.address/fio.address.cpp @@ -940,8 +940,7 @@ namespace fioio { struct tm timeinfo; - // fioio::convertfiotime(epochtmseconds, &timeinfo); - fioio::dateTimeStructFromEpoch(epochtmseconds, &timeinfo); + fioio::convertfiotime(epochtmseconds, &timeinfo); std::string timebuffer = fioio::tmstringformat(timeinfo); const string response_string = string("{\"status\": \"OK\",\"timeresult\":\"") + diff --git a/contracts/fio.common/fiotime.hpp b/contracts/fio.common/fiotime.hpp index 2055c86f..a36796c6 100644 --- a/contracts/fio.common/fiotime.hpp +++ b/contracts/fio.common/fiotime.hpp @@ -52,54 +52,7 @@ namespace fioio { } - //temporary code for new computations of epoch times - bool isLeapYear(int year) { - return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)); - } - - - - void dateTimeStructFromEpoch(long epochTime, struct tm *resultTime) { - const long secondsPerDay = 86400; - const long secondsPerYear = 31536000; - const long secondsPerLeapYear = 31622400; - const long epochYear = 1970; - // Calculate year - long totalDays = epochTime / secondsPerDay; - int year = epochYear + totalDays / 365; - int leapYears = (year - epochYear) / 4 - (year - epochYear) / 100 + (year - epochYear) / 400; - // Adjust for leap years - totalDays -= leapYears; - while (totalDays < 0 || (isLeapYear(year + 1) && totalDays >= 366) || (!isLeapYear(year + 1) && totalDays >= 365)) { - totalDays -= isLeapYear(year + 1) ? 366 : 365; - year++; - } - // Calculate month and day - int daysInMonth[] = {31, 28 + isLeapYear(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - int month = 1; - while (totalDays >= daysInMonth[month - 1]) { - totalDays -= daysInMonth[month - 1]; - month++; - } - // Calculate day - int day = totalDays + 1; - // Calculate hour, minute, and second - int remainingSeconds = epochTime % secondsPerDay; - int hour = remainingSeconds / 3600; - int minute = (remainingSeconds % 3600) / 60; - int second = remainingSeconds % 60; - // Populate the tm struct - resultTime->tm_sec = second; - resultTime->tm_min = minute; - resultTime->tm_hour = hour; - resultTime->tm_mday = day; - resultTime->tm_mon = month - 1; - resultTime->tm_year = year - 1900; - } - - - - + int convertfiotime(long long t, struct tm *tm) { @@ -157,15 +110,26 @@ namespace fioio { return -1; tm->tm_year = years + 2000; - tm->tm_mon = months + 3; + int tmonth = months+3; + if (tmonth > 11){ + tm->tm_year = years + 2000 + 1; + } + + tm->tm_mon = tmonth % 11; + /* if (tm->tm_mon >= 12) { tm->tm_mon -= 12; - //tm->tm_year++; + if(tm->tm_mon == 00){ // some unknown but that makes the 12th month 00. tm->tm_mon = 12; } } + + if((tm->tm_mon >= 0) && (tm->tm_mon <= 3)){ + tm->tm_year++; + } + */ tm->tm_mday = remdays + 1; tm->tm_wday = wday; tm->tm_yday = yday; From 88670faa7001163476aacd68780f313022782d31 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Tue, 16 Apr 2024 13:36:49 -0600 Subject: [PATCH 08/12] mod 12 not 11 mod 12 not 11 --- contracts/fio.common/fiotime.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/fio.common/fiotime.hpp b/contracts/fio.common/fiotime.hpp index a36796c6..b4ac8221 100644 --- a/contracts/fio.common/fiotime.hpp +++ b/contracts/fio.common/fiotime.hpp @@ -52,7 +52,7 @@ namespace fioio { } - + int convertfiotime(long long t, struct tm *tm) { @@ -115,7 +115,7 @@ namespace fioio { tm->tm_year = years + 2000 + 1; } - tm->tm_mon = tmonth % 11; + tm->tm_mon = tmonth % 12; /* if (tm->tm_mon >= 12) { tm->tm_mon -= 12; From 31e217c08697de460d0bbe56ea26b080db16ff2c Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Tue, 16 Apr 2024 14:15:37 -0600 Subject: [PATCH 09/12] make months 0 based. make months 0 based --- contracts/fio.common/fiotime.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/fio.common/fiotime.hpp b/contracts/fio.common/fiotime.hpp index b4ac8221..45778ecc 100644 --- a/contracts/fio.common/fiotime.hpp +++ b/contracts/fio.common/fiotime.hpp @@ -26,7 +26,7 @@ namespace fioio { if (timeinfo.tm_mon < 10) { timebuffer.append("0"); } - timebuffer.append(to_string(timeinfo.tm_mon)); + timebuffer.append(to_string(timeinfo.tm_mon+1)); timebuffer.append("-"); if (timeinfo.tm_mday < 10) { timebuffer.append("0"); @@ -110,7 +110,7 @@ namespace fioio { return -1; tm->tm_year = years + 2000; - int tmonth = months+3; + int tmonth = months-1+3; if (tmonth > 11){ tm->tm_year = years + 2000 + 1; } From efff61a131e2030a678a7a141ef8acd30bb54cbd Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Tue, 16 Apr 2024 14:34:33 -0600 Subject: [PATCH 10/12] fix bug on prefix 0 bug on prefix 0 --- contracts/fio.common/fiotime.hpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/contracts/fio.common/fiotime.hpp b/contracts/fio.common/fiotime.hpp index 45778ecc..b2b03b2a 100644 --- a/contracts/fio.common/fiotime.hpp +++ b/contracts/fio.common/fiotime.hpp @@ -23,9 +23,10 @@ namespace fioio { std::string tmstringformat(struct tm timeinfo) { std::string timebuffer = to_string(timeinfo.tm_year); timebuffer.append("-"); - if (timeinfo.tm_mon < 10) { + if (timeinfo.tm_mon+1 < 10) { timebuffer.append("0"); } + //tm_mon is 0 based timebuffer.append(to_string(timeinfo.tm_mon+1)); timebuffer.append("-"); if (timeinfo.tm_mday < 10) { @@ -116,20 +117,6 @@ namespace fioio { } tm->tm_mon = tmonth % 12; - /* - if (tm->tm_mon >= 12) { - tm->tm_mon -= 12; - - - if(tm->tm_mon == 00){ // some unknown but that makes the 12th month 00. - tm->tm_mon = 12; - } - } - - if((tm->tm_mon >= 0) && (tm->tm_mon <= 3)){ - tm->tm_year++; - } - */ tm->tm_mday = remdays + 1; tm->tm_wday = wday; tm->tm_yday = yday; From 0219a27dc5ccdc78259f1b6ccef5952f236556e8 Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Wed, 17 Apr 2024 09:20:41 -0600 Subject: [PATCH 11/12] clarify the month value logistics clairify the month value logistics. --- contracts/fio.common/fiotime.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/fio.common/fiotime.hpp b/contracts/fio.common/fiotime.hpp index b2b03b2a..aa8fbbb0 100644 --- a/contracts/fio.common/fiotime.hpp +++ b/contracts/fio.common/fiotime.hpp @@ -111,7 +111,8 @@ namespace fioio { return -1; tm->tm_year = years + 2000; - int tmonth = months-1+3; + //ajust month for using march 1 2000 as our leapoch + int tmonth = months+2; if (tmonth > 11){ tm->tm_year = years + 2000 + 1; } From b8e51b2666413876a935c3989900c31559c3a16e Mon Sep 17 00:00:00 2001 From: Ed Rotthoff Date: Wed, 17 Apr 2024 09:59:25 -0600 Subject: [PATCH 12/12] remove test only code remove test only code for epoch time formatting --- contracts/fio.address/fio.address.abi | 15 --------------- contracts/fio.address/fio.address.cpp | 26 -------------------------- 2 files changed, 41 deletions(-) diff --git a/contracts/fio.address/fio.address.abi b/contracts/fio.address/fio.address.abi index 8455955b..67d38e65 100644 --- a/contracts/fio.address/fio.address.abi +++ b/contracts/fio.address/fio.address.abi @@ -154,16 +154,6 @@ } ] }, - { - "name": "fmtepochtm", - "base": "", - "fields": [ - { - "name": "epochtmseconds", - "type": "int64" - } - ] - }, { "name": "updcryptkey", "base": "", @@ -787,11 +777,6 @@ "type": "decrcounter", "ricardian_contract": "" }, - { - "name": "fmtepochtm", - "type": "fmtepochtm", - "ricardian_contract": "" - }, { "name": "regaddress", "type": "regaddress", diff --git a/contracts/fio.address/fio.address.cpp b/contracts/fio.address/fio.address.cpp index 3131caab..2f26da85 100644 --- a/contracts/fio.address/fio.address.cpp +++ b/contracts/fio.address/fio.address.cpp @@ -928,29 +928,6 @@ namespace fioio { //FIP-39 end - - - - -//TESTINGONLY DO NOT DELIVER - [[eosio::action]] - void - fmtepochtm(const int64_t &epochtmseconds) { - - - - struct tm timeinfo; - fioio::convertfiotime(epochtmseconds, &timeinfo); - std::string timebuffer = fioio::tmstringformat(timeinfo); - - const string response_string = string("{\"status\": \"OK\",\"timeresult\":\"") + - timebuffer + string("\"") + string("}"); - - send_response(response_string.c_str()); - } - //TESTINGONLY DO NOT DELIVER - - [[eosio::action]] void regaddress(const string &fio_address, const string &owner_fio_public_key, const int64_t &max_fee, @@ -2746,9 +2723,6 @@ namespace fioio { }; EOSIO_DISPATCH(FioNameLookup,(regaddress)(addaddress)(remaddress)(remalladdr)(regdomain)(renewdomain)(renewaddress) - //TESTING ONLY DO NOT DELIVER - (fmtepochtm) - //TESTING ONLY DO NOT deliver (setdomainpub)(burnexpired)(burndomain)(decrcounter)(bind2eosio)(burnaddress)(xferdomain)(xferaddress)(addbundles)(xferescrow) (addnft)(remnft)(remallnfts)(burnnfts)(regdomadd)(updcryptkey)) }