Skip to content

Commit

Permalink
Merge pull request #394 from duality-solutions/v2.4.2.0-WIP
Browse files Browse the repository at this point in the history
V2.4.2.0 wip
  • Loading branch information
SvenKercher committed Oct 31, 2019
2 parents 23b4587 + 688bff2 commit fce05e1
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 29 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
**Dynamic CHANGELOG**
-------------------------

**Dynamic v2.4.2.0**

* [BDAP] Set maximum months stored in local accounts db
* [BDAP] Limit acount registration to 100 years
* [Mempool] Don't check if standard tx for BDAP txs in accept to mempool
* [BDAP] Remove maximum months for updated accounts
* [BDAP] Fix add months to block and epoch times
* [Util] Fix epoch to ISO date string conversion
* Bump client and block version to v2.4.2.0
* Increase minimum protocol to v2.4 (71000) or greater
* [Wallet] Check txout instead of entire tx for BDAP


**Dynamic v2.4.1.0**

* [Qt] Update/Add Languages
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/duality-solutions/Dynamic.png?branch=master)](https://travis-ci.org/duality-solutions/Dynamic)

# **Dynamic (DYN) v2.4.1.0**
# **Dynamic (DYN) v2.4.2.0**

![DYN logo](https://github.com/duality-solutions/Dynamic/blob/master/src/qt/res/icons/drk/about.png)

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 2)
define(_CLIENT_VERSION_MINOR, 4)
define(_CLIENT_VERSION_REVISION, 1)
define(_CLIENT_VERSION_REVISION, 2)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2019)
Expand Down
2 changes: 1 addition & 1 deletion contrib/gitian-descriptors/gitian-arm.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: "dynamic-arm-2.4.1.0"
name: "dynamic-arm-2.4.2.0"
enable_cache: true
suites:
- "trusty"
Expand Down
2 changes: 1 addition & 1 deletion contrib/gitian-descriptors/gitian-linux.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: "dynamic-linux-2.4.1.0"
name: "dynamic-linux-2.4.2.0"
enable_cache: true
suites:
- "trusty"
Expand Down
2 changes: 1 addition & 1 deletion contrib/gitian-descriptors/gitian-osx.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: "dynamic-osx-2.4.1.0"
name: "dynamic-osx-2.4.2.0"
enable_cache: true
suites:
- "trusty"
Expand Down
2 changes: 1 addition & 1 deletion contrib/gitian-descriptors/gitian-win.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: "dynamic-2.4.1.0"
name: "dynamic-2.4.2.0"
enable_cache: true
suites:
- "trusty"
Expand Down
1 change: 1 addition & 0 deletions src/bdap/bdap.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static constexpr unsigned int MAX_BDAP_LINK_DATA_SIZE = 1592;
static constexpr uint64_t DEFAULT_LINK_EXPIRE_TIME = 1861920000;
static constexpr int32_t DEFAULT_REGISTRATION_MONTHS = 12; // 1 year
static constexpr bool ENFORCE_BDAP_CREDIT_USE = false; // TODO: Change to true before release
static constexpr uint32_t MAX_REGISTRATION_MONTHS = 1200; // 100 years
static const std::string DEFAULT_PUBLIC_DOMAIN = "bdap.io";
static const std::string DEFAULT_PUBLIC_OU = "public";
static const std::string DEFAULT_ADMIN_OU = "admin";
Expand Down
18 changes: 16 additions & 2 deletions src/bdap/domainentrydb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,13 @@ bool CheckDomainEntryTx(const CTransactionRef& tx, const CScript& scriptOp, cons

uint32_t nMonths;
ParseUInt32(strMonths, &nMonths);
if (nMonths > MAX_REGISTRATION_MONTHS)
nMonths = MAX_REGISTRATION_MONTHS;

int64_t nCurrentEpoch = GetTime();
int64_t nEpochAddMonths = AddMonthsToBlockTime(nBlockTime > 0 ? nBlockTime : nCurrentEpoch, nMonths);
if (nEpochAddMonths < nCurrentEpoch)
nMonths = MAX_REGISTRATION_MONTHS;

if (!GetBDAPFees(OP_BDAP_NEW, OP_BDAP_ACCOUNT_ENTRY, entry.ObjectType(), (uint16_t)nMonths, monthlyFee, oneTimeFee, depositFee)) {
errorMessage = "Failed to get fees to add a new BDAP account";
Expand Down Expand Up @@ -712,12 +719,19 @@ bool CheckDomainEntryTx(const CTransactionRef& tx, const CScript& scriptOp, cons

uint32_t nMonths;
ParseUInt32(strMonths, &nMonths);
if (nMonths >= 10000)
nMonths = 24;
if (nMonths > MAX_REGISTRATION_MONTHS)
nMonths = MAX_REGISTRATION_MONTHS;

int64_t nCurrentEpoch = GetTime();
int64_t nEpochAddMonths = AddMonthsToBlockTime(nBlockTime > 0 ? nBlockTime : nCurrentEpoch, nMonths);
if (nEpochAddMonths < nCurrentEpoch)
nMonths = MAX_REGISTRATION_MONTHS;

if (!GetBDAPFees(OP_BDAP_MODIFY, OP_BDAP_ACCOUNT_ENTRY, entry.ObjectType(), (uint16_t)nMonths, monthlyFee, oneTimeFee, depositFee)) {
errorMessage = "Failed to get fees to add a new BDAP account";
return false;
}

LogPrint("bdap", "%s -- nMonths %d, monthlyFee %d, oneTimeFee %d, depositFee %d\n", __func__,
nMonths, FormatMoney(monthlyFee), FormatMoney(oneTimeFee), FormatMoney(depositFee));
// extract amounts from tx.
Expand Down
27 changes: 23 additions & 4 deletions src/bdap/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "util.h" // for LogPrintf

#include <boost/date_time/posix_time/posix_time.hpp>
#include <ctime>
#include <limits>
#include <map>

Expand Down Expand Up @@ -174,24 +175,42 @@ bool GetBDAPFees(const opcodetype& opCodeAction, const opcodetype& opCodeObject,

int64_t AddMonthsToCurrentEpoch(const short nMonths)
{
struct std::tm epoch_date;
epoch_date.tm_hour = 0; epoch_date.tm_min = 0; epoch_date.tm_sec = 0;
epoch_date.tm_year = 70; epoch_date.tm_mon = 0; epoch_date.tm_mday = 1;

boost::gregorian::date dt = boost::gregorian::day_clock::universal_day();
short nYear = dt.year() + ((dt.month() + nMonths)/12);
short nMonth = (dt.month() + nMonths) % 12;
short nDay = dt.day();
boost::posix_time::time_duration dur = boost::posix_time::ptime(boost::gregorian::date(nYear, nMonth, nDay)) - boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1));
//LogPrintf("%s -- nYear %d, nMonth %d, nDay %d\n", __func__, nYear, nMonth, nDay);
return dur.total_seconds() + SECONDS_PER_DAY;
struct std::tm month_date;
month_date.tm_hour = 0; month_date.tm_min = 0; month_date.tm_sec = 0;
month_date.tm_year = nYear - 1900; month_date.tm_mon = nMonth -1; month_date.tm_mday = nDay;

int64_t seconds = (int64_t)std::difftime(std::mktime(&month_date), std::mktime(&epoch_date));

return seconds + SECONDS_PER_DAY;
}

int64_t AddMonthsToBlockTime(const uint32_t& nBlockTime, const short nMonths)
{
struct std::tm epoch_date;
epoch_date.tm_hour = 0; epoch_date.tm_min = 0; epoch_date.tm_sec = 0;
epoch_date.tm_year = 70; epoch_date.tm_mon = 0; epoch_date.tm_mday = 1;

boost::gregorian::date dt = boost::posix_time::from_time_t(nBlockTime).date();
short nYear = dt.year() + ((dt.month() + nMonths)/12);
short nMonth = (dt.month() + nMonths) % 12;
short nDay = dt.day();
boost::posix_time::time_duration dur = boost::posix_time::ptime(boost::gregorian::date(nYear, nMonth, nDay)) - boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1));
//LogPrintf("%s -- nYear %d, nMonth %d, nDay %d\n", __func__, nYear, nMonth, nDay);
return dur.total_seconds() + SECONDS_PER_DAY;
struct std::tm month_date;
month_date.tm_hour = 0; month_date.tm_min = 0; month_date.tm_sec = 0;
month_date.tm_year = nYear - 1900; month_date.tm_mon = nMonth -1; month_date.tm_mday = nDay;

int64_t seconds = (int64_t)std::difftime(std::mktime(&month_date), std::mktime(&epoch_date));

return seconds + SECONDS_PER_DAY;
}

uint16_t MonthsFromBlockToExpire(const uint32_t& nBlockTime, const uint64_t& nExpireTime)
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! These need to be macros, as clientversion.cpp's and dynamic*-res.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 2
#define CLIENT_VERSION_MINOR 4
#define CLIENT_VERSION_REVISION 1
#define CLIENT_VERSION_REVISION 2
#define CLIENT_VERSION_BUILD 0

//! Set to true for release, false for prerelease or test build
Expand Down
4 changes: 1 addition & 3 deletions src/qt/bdapaccounttablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ class BdapAccountTablePriv
// "common_name", "object_full_path"
if (keyName == "common_name") getName = result[i].getValues()[j].get_str();
if (keyName == "object_full_path") getPath = result[i].getValues()[j].get_str();
//if (keyName == "expires_on") getExpirationDate = std::to_string(result[i].getValues()[j].get_int64());
if (keyName == "expires_on") getExpirationDate = DateTimeStrFormat("%Y-%m-%d", result[i].getValues()[j].get_int64());

if (keyName == "expires_on") getExpirationDate = FormatISO8601Date(result[i].getValues()[j].get_int64());
}

//add row if all criteria have been met
Expand Down
6 changes: 3 additions & 3 deletions src/qt/bdapuserdetaildialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ void BdapUserDetailDialog::populateValues(BDAP::ObjectType accountType, const st
if (keyName == "dht_publickey") publicKey = result.getValues()[i].get_str();
if (keyName == "link_address") linkAddress = result.getValues()[i].get_str();
if (keyName == "txid") txId = result.getValues()[i].get_str();
if (keyName == "expires_on") expirationDate = DateTimeStrFormat("%Y-%m-%d", result.getValues()[i].get_int64());
if (keyName == "expired") expired = ((result.getValues()[i].get_bool())?"true":"false");
if (keyName == "time") timeValue = DateTimeStrFormat("%Y-%m-%d %H:%M", result.getValues()[i].get_int64());
if (keyName == "expires_on") expirationDate = FormatISO8601Date(result.getValues()[i].get_int64());
if (keyName == "expired") expired = ((result.getValues()[i].get_bool()) ? "true":"false");
if (keyName == "time") timeValue = FormatISO8601Date(result.getValues()[i].get_int64());
} //for i

ui->lineEditOID->setText(QString::fromStdString(oid));
Expand Down
17 changes: 11 additions & 6 deletions src/rpc/domainentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ static UniValue AddDomainEntry(const JSONRPCRequest& request, BDAP::ObjectType b
if (!ParseInt32(request.params[2].get_str(), &nMonths))
throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3505 - " + _("Error converting registration months to int, only whole numbers allowed (no decimals)"));
if (nMonths <= 0)
throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3505 - " + _("Error: registration months must be greater than 0"));
throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3506 - " + _("Error: registration months must be greater than 0"));
if (nMonths > MAX_REGISTRATION_MONTHS)
throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3507 - " + _("Error: Registration period can not be more than 1,200 months (100 years)"));
}

CharString data;
Expand Down Expand Up @@ -104,7 +106,7 @@ static UniValue AddDomainEntry(const JSONRPCRequest& request, BDAP::ObjectType b
// check BDAP values
std::string strMessage;
if (!txDomainEntry.ValidateValues(strMessage))
throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3506 - " + strMessage);
throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3508 - " + strMessage);

bool fUseInstantSend = false;
//if (dnodeman.EnoughActiveForInstandSend() && sporkManager.IsSporkActive(SPORK_2_INSTANTSEND_ENABLED))
Expand All @@ -117,7 +119,7 @@ static UniValue AddDomainEntry(const JSONRPCRequest& request, BDAP::ObjectType b

UniValue oName(UniValue::VOBJ);
if(!BuildBDAPJson(txDomainEntry, oName))
throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3507 - " + _("Failed to read from BDAP JSON object"));
throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3509 - " + _("Failed to read from BDAP JSON object"));

if (LogAcceptCategory("bdap")) {
// make sure we can deserialize the transaction from the scriptData and get a valid CDomainEntry class
Expand Down Expand Up @@ -448,8 +450,11 @@ static UniValue UpdateDomainEntry(const JSONRPCRequest& request, BDAP::ObjectTyp
if (request.params.size() >= 3) {
if (!ParseInt32(request.params[2].get_str(), &nMonths))
throw std::runtime_error("BDAP_UPDATE_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3702 - " + _("Error converting registration days to int"));
if (nMonths < 0)
throw std::runtime_error("BDAP_UPDATE_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3703 - " + _("Error: registration months must be greater than or equal to zero"));
if (nMonths > MAX_REGISTRATION_MONTHS)
throw std::runtime_error("BDAP_UPDATE_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3704 - " + _("Error: Registration period can not be more than 1,200 months (100 years)"));
}
//txUpdatedEntry.nExpireTime = AddMonthsToCurrentEpoch((short)nMonths);

CharString data;
txUpdatedEntry.Serialize(data);
Expand Down Expand Up @@ -479,7 +484,7 @@ static UniValue UpdateDomainEntry(const JSONRPCRequest& request, BDAP::ObjectTyp
// check BDAP values
std::string strMessage;
if (!txUpdatedEntry.ValidateValues(strMessage))
throw std::runtime_error("BDAP_UPDATE_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3703 - " + strMessage);
throw std::runtime_error("BDAP_UPDATE_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3705 - " + strMessage);

bool fUseInstantSend = false;
//if (dnodeman.EnoughActiveForInstandSend() && sporkManager.IsSporkActive(SPORK_2_INSTANTSEND_ENABLED))
Expand All @@ -492,7 +497,7 @@ static UniValue UpdateDomainEntry(const JSONRPCRequest& request, BDAP::ObjectTyp

UniValue oName(UniValue::VOBJ);
if(!BuildBDAPJson(txUpdatedEntry, oName))
throw std::runtime_error("BDAP_UPDATE_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3704 - " + _("Failed to read from BDAP JSON object"));
throw std::runtime_error("BDAP_UPDATE_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3706 - " + _("Failed to read from BDAP JSON object"));

if (LogAcceptCategory("bdap")) {
// make sure we can deserialize the transaction from the scriptData and get a valid CDomainEntry class
Expand Down
24 changes: 24 additions & 0 deletions src/utiltime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/thread.hpp>

#include <ctime>

static int64_t nMockTime = 0; //! For unit testing

int64_t GetTime()
Expand Down Expand Up @@ -107,3 +109,25 @@ std::string DurationToDHMS(int64_t nDurationTime)
return strprintf("%02dh:%02dm:%02ds", hours, minutes, seconds);
return strprintf("%02dm:%02ds", minutes, seconds);
}

std::string FormatISO8601DateTime(int64_t nTime) {
struct tm ts;
time_t time_val = nTime;
#ifdef _MSC_VER
gmtime_s(&ts, &time_val);
#else
gmtime_r(&time_val, &ts);
#endif
return strprintf("%04i-%02i-%02iT%02i:%02i:%02iZ", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
}

std::string FormatISO8601Date(int64_t nTime) {
struct tm ts;
time_t time_val = nTime;
#ifdef _MSC_VER
gmtime_s(&ts, &time_val);
#else
gmtime_r(&time_val, &ts);
#endif
return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday);
}
6 changes: 6 additions & 0 deletions src/utiltime.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ void MilliSleep(int64_t n);

std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime);
std::string DurationToDHMS(int64_t nDurationTime);
/**
* ISO 8601 formatting is preferred. Use the FormatISO8601{DateTime,Date}
* helper functions if possible.
*/
std::string FormatISO8601DateTime(int64_t nTime);
std::string FormatISO8601Date(int64_t nTime);

#endif // DYNAMIC_UTILTIME_H
4 changes: 3 additions & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,9 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
if (tx.nVersion == BDAP_TX_VERSION && !sporkManager.IsSporkActive(SPORK_30_ACTIVATE_BDAP))
return state.DoS(0, false, REJECT_NONSTANDARD, "inactive-spork-bdap-tx");

bool fIsBDAP = false;
if (tx.nVersion == BDAP_TX_VERSION) {
fIsBDAP = true;
CScript scriptBDAPOp;
std::vector<std::vector<unsigned char>> vvch;
int op1, op2;
Expand Down Expand Up @@ -1106,7 +1108,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C

// Rather not work on nonstandard transactions (unless -testnet/-regtest)
std::string reason;
if (fRequireStandard && !IsStandardTx(tx, reason) && !fluidTransaction)
if (fRequireStandard && !fIsBDAP && !IsStandardTx(tx, reason) && !fluidTransaction)
return state.DoS(0, false, REJECT_NONSTANDARD, reason);

// Only accept nLockTime-using transactions that can be mined in the next
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static const int INIT_PROTO_VERSION = 209;
static const int GETHEADERS_VERSION = 60800;

//! disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION = 70900;
static const int MIN_PEER_PROTO_VERSION = 71000;

//! nTime field added to CAddress, starting with this version;
//! if possible, avoid requesting addresses nodes older than this
Expand Down
2 changes: 1 addition & 1 deletion src/versionbits.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/** What block version to use for new blocks (pre versionbits) */
static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION = 4;
/** What bits to set in version for versionbits blocks */
static const int32_t VERSIONBITS_TOP_BITS = 0x24100000UL;
static const int32_t VERSIONBITS_TOP_BITS = 0x24200000UL;
/** What bitmask determines whether versionbits is in use */
static const int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL;
/** Total bits available for versionbits */
Expand Down
5 changes: 4 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2372,6 +2372,9 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache) const
for (unsigned int i = 0; i < tx->vout.size(); i++) {
if (!pwallet->IsSpent(hashTx, i)) {
const CTxOut& txout = tx->vout[i];
if (txout.IsBDAP())
continue;

nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE);
if (!MoneyRange(nCredit))
throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
Expand Down Expand Up @@ -2631,7 +2634,7 @@ CAmount CWallet::GetBalance() const
LOCK2(cs_main, cs_wallet);
for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) {
const CWalletTx* pcoin = &(*it).second;
if (pcoin->IsTrusted() && !pcoin->IsBDAP())
if (pcoin->IsTrusted())
nTotal += pcoin->GetAvailableCredit();
}
}
Expand Down

0 comments on commit fce05e1

Please sign in to comment.