Skip to content

Commit b258cf1

Browse files
authored
Merge pull request duality-solutions#340 from duality-solutions/v2.4.19-BDAP-Fees2
v2.4.19 BDAP Fee Schedule
2 parents 3df4e8d + 1bd4fa6 commit b258cf1

28 files changed

+518
-225
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
22

33
[![Build Status](https://travis-ci.org/duality-solutions/Dynamic.png?branch=master)](https://travis-ci.org/duality-solutions/Dynamic)
4-
[![Stories in Ready](https://badge.waffle.io/duality-solutions/Dynamic.png?label=ready&title=Ready)](https://waffle.io/duality-solutions/Dynamic)
5-
6-
Graph on Pull Request History
7-
====================================
8-
9-
[![Throughput Graph](https://graphs.waffle.io/duality-solutions/Dynamic/throughput.svg)](https://waffle.io/duality-solutions/Dynamic/metrics/throughput)
104

115
# **Dynamic (DYN) v2.4.0.0**
126

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ DYNAMIC_CORE_H = \
8282
bdap/domainentrydb.h \
8383
bdap/certificate.h \
8484
bdap/entrycheckpoints.h \
85+
bdap/fees.h \
8586
bdap/identity.h \
8687
bdap/linking.h \
8788
bdap/linkingdb.h \
@@ -269,6 +270,7 @@ libdynamic_server_a_SOURCES = \
269270
bdap/domainentrydb.cpp \
270271
bdap/certificate.cpp \
271272
bdap/entrycheckpoints.cpp \
273+
bdap/fees.cpp \
272274
bdap/identity.cpp \
273275
bdap/linking.cpp \
274276
bdap/linkingdb.cpp \

src/amount.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typedef int64_t CAmount;
1717

1818
static const CAmount COIN = 100000000;
1919
static const CAmount CENT = 1000000;
20+
static const CAmount BDAP_CREDIT = 100001; //= 0.00100001 DYN. Matches lowest PrivateSend denomination
2021

2122
extern const std::string CURRENCY_UNIT;
2223

src/bdap/bdap.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ namespace BDAP {
1818
BDAP_ORGANIZATIONAL_UNIT = 5,
1919
BDAP_CERTIFICATE = 6,
2020
BDAP_AUDIT = 7,
21-
BDAP_CHANNEL = 8,
22-
BDAP_CHECKPOINT = 9,
21+
BDAP_SIDECHAIN = 8,
22+
BDAP_SIDECHAIN_CHECKPOINT = 9,
2323
BDAP_LINK_REQUEST = 10,
2424
BDAP_LINK_ACCEPT = 11,
2525
BDAP_IDENTITY = 12,
@@ -53,7 +53,9 @@ static constexpr unsigned int DHT_HEX_PUBLIC_KEY_LENGTH = 64; // Ed25519 pubke
5353
static constexpr unsigned int MAX_BDAP_LINK_MESSAGE = 256;
5454
static constexpr unsigned int MAX_BDAP_SIGNATURE_PROOF = 90; // TODO (bdap): Update to 65 or use MAX_SIGNATURE_LENGTH when you start a new chain.
5555
static constexpr unsigned int MAX_BDAP_LINK_DATA_SIZE = 1592;
56-
static constexpr unsigned int DEFAULT_REGISTRATION_DAYS = 731; // 2 years
56+
static constexpr uint64_t DEFAULT_LINK_EXPIRE_TIME = 1861920000;
57+
static constexpr int32_t DEFAULT_REGISTRATION_MONTHS = 24; // 2 years
58+
static constexpr bool ENFORCE_BDAP_FEES = false; // ********** TODO (BDAP): Update to true after a new testnet.
5759
static const std::string DEFAULT_PUBLIC_DOMAIN = "bdap.io";
5860
static const std::string DEFAULT_PUBLIC_OU = "public";
5961
static const std::string DEFAULT_ADMIN_OU = "admin";

src/bdap/domainentry.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define DYNAMIC_BDAP_DOMAINENTRY_H
77

88
#include "bdap.h"
9+
#include "bdap/utils.h"
910
#include "amount.h"
1011
#include "consensus/params.h"
1112
#include "primitives/transaction.h"
@@ -38,12 +39,6 @@ class CTxMemPool;
3839

3940
using namespace BDAP;
4041

41-
namespace BDAP {
42-
std::string GetObjectTypeString(unsigned int nObjectType);
43-
unsigned int GetObjectTypeInt(BDAP::ObjectType ObjectType);
44-
BDAP::ObjectType GetObjectTypeEnum(unsigned int nObjectType);
45-
}
46-
4742
class CDomainEntryDefaultParameters {
4843
public:
4944
void InitialiseAdminOwners(); //DEFAULT_ADMIN_DOMAIN

src/bdap/domainentrydb.cpp

Lines changed: 138 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
#include "bdap/domainentrydb.h"
66

7+
#include "amount.h"
78
#include "base58.h"
9+
#include "bdap/fees.h"
810
#include "coins.h"
911
#include "bdap/utils.h"
1012
#include "validation.h"
@@ -351,12 +353,30 @@ static bool CommonDataCheck(const CDomainEntry& entry, const vchCharString& vvch
351353
return false;
352354
}
353355

356+
if (vvchOpParameters.size() != 3)
357+
{
358+
errorMessage = "CommonDataCheck failed! Not enough parameters.";
359+
return false;
360+
}
361+
354362
if (entry.GetFullObjectPath() != stringFromVch(vvchOpParameters[0]))
355363
{
356364
errorMessage = "CommonDataCheck failed! Script operation parameter does not match entry entry object.";
357365
return false;
358366
}
359367

368+
if (entry.DHTPublicKey != vvchOpParameters[1])
369+
{
370+
errorMessage = "CommonDataCheck failed! DHT public key mismatch.";
371+
return false;
372+
}
373+
374+
if (vvchOpParameters[2].size() > 10)
375+
{
376+
errorMessage = "CommonDataCheck failed! Expire date or expire months invalid.";
377+
return false;
378+
}
379+
360380
if (entry.DomainComponent != vchDefaultDomainName)
361381
{
362382
errorMessage = "CommonDataCheck failed! Must use default domain.";
@@ -378,7 +398,7 @@ static bool CommonDataCheck(const CDomainEntry& entry, const vchCharString& vvch
378398
return true;
379399
}
380400

381-
bool CheckNewDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters, const uint256& txHash,
401+
static bool CheckNewDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters, const uint256& txHash,
382402
std::string& errorMessage, bool fJustCheck)
383403
{
384404
if (!CommonDataCheck(entry, vvchOpParameters, errorMessage))
@@ -415,7 +435,7 @@ bool CheckNewDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scrip
415435
return FlushLevelDB();
416436
}
417437

418-
bool CheckDeleteDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters,
438+
static bool CheckDeleteDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters,
419439
std::string& errorMessage, bool fJustCheck)
420440
{
421441
if (vvchOpParameters.size() == 0) {
@@ -473,7 +493,7 @@ bool CheckDeleteDomainEntryTxInputs(const CDomainEntry& entry, const CScript& sc
473493
return FlushLevelDB();
474494
}
475495

476-
bool CheckUpdateDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters, const uint256& txHash,
496+
static bool CheckUpdateDomainEntryTxInputs(CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters, const uint256& txHash, const int& nMonths, const uint32_t& nBlockTime,
477497
std::string& errorMessage, bool fJustCheck)
478498
{
479499
//if exists, check for owner's signature
@@ -523,7 +543,12 @@ bool CheckUpdateDomainEntryTxInputs(const CDomainEntry& entry, const CScript& sc
523543
return error(errorMessage.c_str());
524544
}
525545
}
526-
546+
if (nMonths < 10000) {
547+
entry.nExpireTime = prevDomainEntry.nExpireTime + AddMonthsToBlockTime(nBlockTime, nMonths);
548+
}
549+
else {
550+
entry.nExpireTime = nMonths;
551+
}
527552
if (!pDomainEntryDB->UpdateDomainEntry(entry.vchFullObjectPath(), entry))
528553
{
529554
errorMessage = "CheckUpdateDomainEntryTxInputs: - Error updating entry in LevelDB; this update operation failed!";
@@ -533,7 +558,7 @@ bool CheckUpdateDomainEntryTxInputs(const CDomainEntry& entry, const CScript& sc
533558
return FlushLevelDB();
534559
}
535560

536-
bool CheckMoveDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters,
561+
static bool CheckMoveDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters,
537562
std::string& errorMessage, bool fJustCheck)
538563
{
539564
//check name in operation matches entry data in leveldb
@@ -542,45 +567,17 @@ bool CheckMoveDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scri
542567
return false;
543568
}
544569

545-
bool CheckExecuteDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters,
546-
std::string& errorMessage, bool fJustCheck)
547-
{
548-
//check name in operation matches entry data in leveldb
549-
//check if exists already
550-
//if exists, check for owner's signature
551-
return false;
552-
}
553-
554-
bool CheckBindDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters,
555-
std::string& errorMessage, bool fJustCheck)
556-
{
557-
//check names in operation matches entry data in leveldb
558-
//check if request or accept response
559-
//check if names exists already
560-
//if exists, check for owner's signature
561-
return false;
562-
}
563-
564-
bool CheckRevokeDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters,
565-
std::string& errorMessage, bool fJustCheck)
566-
{
567-
//check name in operation matches entry data in leveldb
568-
//check if names exists already
569-
//if exists, check for fluid signature
570-
return false;
571-
}
572-
573570
bool CheckDomainEntryTx(const CTransactionRef& tx, const CScript& scriptOp, const int& op1, const int& op2, const std::vector<std::vector<unsigned char> >& vvchArgs,
574-
bool fJustCheck, int nHeight, std::string& errorMessage, bool bSanityCheck)
571+
const bool fJustCheck, const int& nHeight, const uint32_t& nBlockTime, const bool bSanityCheck, std::string& errorMessage)
575572
{
576573
if (tx->IsCoinBase() && !fJustCheck && !bSanityCheck)
577574
{
578575
LogPrintf("*Trying to add BDAP entry in coinbase transaction, skipping...");
579576
return true;
580577
}
581578

582-
LogPrint("bdap", "%s -- *** BDAP nHeight=%d, chainActive.Tip()=%d, op1=%s, op2=%s, hash=%s justcheck=%s\n", __func__, nHeight, chainActive.Tip()->nHeight, BDAPFromOp(op1).c_str(), BDAPFromOp(op2).c_str(), tx->GetHash().ToString().c_str(), fJustCheck ? "JUSTCHECK" : "BLOCK");
583-
579+
LogPrintf("%s -- *** BDAP nHeight=%d, chainActive.Tip()=%d, op1=%s, op2=%s, hash=%s justcheck=%s\n", __func__, nHeight, chainActive.Tip()->nHeight, BDAPFromOp(op1).c_str(), BDAPFromOp(op2).c_str(), tx->GetHash().ToString().c_str(), fJustCheck ? "JUSTCHECK" : "BLOCK");
580+
584581
// unserialize BDAP from txn, check if the entry is valid and does not conflict with a previous entry
585582
CDomainEntry entry;
586583
std::vector<unsigned char> vchData;
@@ -606,16 +603,114 @@ bool CheckDomainEntryTx(const CTransactionRef& tx, const CScript& scriptOp, cons
606603
entry.txHash = tx->GetHash();
607604
entry.nHeight = nHeight;
608605
}
609-
if (strOperationType == "bdap_new_account")
606+
607+
CAmount monthlyFee, oneTimeFee, depositFee;
608+
if (strOperationType == "bdap_new_account") {
609+
if (vvchArgs.size() != 3) {
610+
errorMessage = "Failed to get fees to add a new BDAP account";
611+
return false;
612+
}
613+
int nMonths = CScriptNum(vvchArgs[2], false, 10).getint();
614+
if (nMonths >= 10000)
615+
nMonths = 24;
616+
if (nMonths < 10000 && !GetBDAPFees(OP_BDAP_NEW, OP_BDAP_ACCOUNT_ENTRY, entry.ObjectType(), nMonths, monthlyFee, oneTimeFee, depositFee)) {
617+
errorMessage = "Failed to get fees to add a new BDAP account";
618+
return false;
619+
}
620+
// extract amounts from tx.
621+
CAmount dataAmount, opAmount;
622+
if (!ExtractAmountsFromTx(tx, dataAmount, opAmount)) {
623+
errorMessage = "Unable to extract BDAP amounts from transaction";
624+
return false;
625+
}
626+
// check if fees equal or exceed tx amounts. Use ENFORCE_BDAP_FEES for now. If ENFORCE_BDAP_FEES = false, just print the error.
627+
if (monthlyFee > dataAmount) {
628+
if (ENFORCE_BDAP_FEES) {
629+
errorMessage = "Invalid BDAP monthly registration fee amount for new BDAP account";
630+
return false;
631+
}
632+
else {
633+
LogPrintf("%s -- Invalid BDAP monthly registration fee amount for new BDAP account. Monthly paid %d but should be %d. Fees not enforced.\n", __func__, dataAmount, monthlyFee);
634+
}
635+
}
636+
else {
637+
LogPrintf("%s -- *** Valid BDAP monthly registration fee amount for new BDAP account. Monthly paid %d, should be %d.\n", __func__, dataAmount, monthlyFee);
638+
}
639+
if (depositFee > opAmount) {
640+
if (ENFORCE_BDAP_FEES) {
641+
errorMessage = "Invalid BDAP deposit fee amount for new BDAP account";
642+
return false;
643+
}
644+
else {
645+
LogPrintf("%s -- Invalid BDAP deposit fee amount for new BDAP account. Deposit paid %d but should be %d. Fees not enforced.\n", __func__, opAmount, depositFee);
646+
}
647+
}
648+
else {
649+
LogPrintf("%s -- *** Valid BDAP deposit fee amount for new BDAP account. Deposit paid %d, should be %d\n", __func__, opAmount, depositFee);
650+
}
651+
if (nMonths < 10000) {
652+
entry.nExpireTime = AddMonthsToBlockTime(nBlockTime, nMonths);
653+
}
654+
else {
655+
entry.nExpireTime = nMonths;
656+
}
657+
610658
return CheckNewDomainEntryTxInputs(entry, scriptOp, vvchArgs, tx->GetHash(), errorMessage, fJustCheck);
611-
else if (strOperationType == "bdap_delete_account")
659+
}
660+
else if (strOperationType == "bdap_delete_account") {
661+
uint16_t nMonths = 0;
662+
if (!GetBDAPFees(OP_BDAP_DELETE, OP_BDAP_ACCOUNT_ENTRY, entry.ObjectType(), nMonths, monthlyFee, oneTimeFee, depositFee)) {
663+
errorMessage = "Failed to get fees to delete a BDAP account";
664+
return false;
665+
}
666+
612667
return CheckDeleteDomainEntryTxInputs(entry, scriptOp, vvchArgs, errorMessage, fJustCheck);
613-
else if (strOperationType == "bdap_update_account")
614-
return CheckUpdateDomainEntryTxInputs(entry, scriptOp, vvchArgs, tx->GetHash(), errorMessage, fJustCheck);
615-
else if (strOperationType == "bdap_move_account")
668+
}
669+
else if (strOperationType == "bdap_update_account") {
670+
if (vvchArgs.size() != 3) {
671+
errorMessage = "Failed to get fees to add a new BDAP account";
672+
return false;
673+
}
674+
int nMonths = CScriptNum(vvchArgs[2], false, 10).getint();
675+
if (nMonths >= 10000)
676+
nMonths = 24;
677+
if (!GetBDAPFees(OP_BDAP_MODIFY, OP_BDAP_ACCOUNT_ENTRY, entry.ObjectType(), nMonths, monthlyFee, oneTimeFee, depositFee)) {
678+
errorMessage = "Failed to get fees to add a new BDAP account";
679+
return false;
680+
}
681+
// extract amounts from tx.
682+
CAmount dataAmount, opAmount;
683+
if (!ExtractAmountsFromTx(tx, dataAmount, opAmount)) {
684+
errorMessage = "Unable to extract BDAP amounts from transaction";
685+
return false;
686+
}
687+
// check if fees equal or exceed tx amounts. Use ENFORCE_BDAP_FEES for now. If ENFORCE_BDAP_FEES = false, just print the error.
688+
if (monthlyFee + oneTimeFee + depositFee > dataAmount + opAmount) {
689+
if (ENFORCE_BDAP_FEES) {
690+
errorMessage = "Invalid BDAP deposit fee amount for updated BDAP account";
691+
return false;
692+
}
693+
else {
694+
LogPrintf("%s -- Invalid BDAP deposit fee amount for updated BDAP account. Total paid %d but should be %d. Fees not enforced.\n", __func__,
695+
(dataAmount + opAmount), (monthlyFee + oneTimeFee + depositFee));
696+
}
697+
}
698+
else {
699+
LogPrintf("%s -- *** Valid BDAP deposit fee amount for updated BDAP account. Total paid %d, should be %d\n", __func__,
700+
(dataAmount + opAmount), (monthlyFee + oneTimeFee + depositFee));
701+
}
702+
// Add previous expire date plus additional months
703+
return CheckUpdateDomainEntryTxInputs(entry, scriptOp, vvchArgs, tx->GetHash(), nMonths, nBlockTime, errorMessage, fJustCheck);
704+
}
705+
else if (strOperationType == "bdap_move_account") {
706+
uint16_t nMonths = 0;
707+
if (!GetBDAPFees(OP_BDAP_MODIFY_RDN, OP_BDAP_ACCOUNT_ENTRY, entry.ObjectType(), nMonths, monthlyFee, oneTimeFee, depositFee)) {
708+
errorMessage = "Failed to get fees to move a BDAP account to another domain";
709+
return false;
710+
}
711+
616712
return CheckMoveDomainEntryTxInputs(entry, scriptOp, vvchArgs, errorMessage, fJustCheck);
617-
else if (strOperationType == "bdap_revoke_account")
618-
return CheckRevokeDomainEntryTxInputs(entry, scriptOp, vvchArgs, errorMessage, fJustCheck);
713+
}
619714

620715
return false;
621716
}

src/bdap/domainentrydb.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,8 @@ bool DeleteDomainEntry(const CDomainEntry& entry);
4646
bool CheckDomainEntryDB();
4747
bool FlushLevelDB();
4848
void CleanupLevelDB(int& nRemoved);
49-
bool CheckNewDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters, const uint256& txHash,
50-
std::string& errorMessage, bool fJustCheck);
51-
bool CheckDeleteDomainEntryTxInputs(const CTransaction& tx, const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters,
52-
std::string& errorMessage, bool fJustCheck);
53-
bool CheckUpdateDomainEntryTxInputs(const CTransaction& tx, const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters, const uint256& txHash,
54-
std::string& errorMessage, bool fJustCheck);
55-
bool CheckMoveDomainEntryTxInputs(const CTransaction& tx, const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters,
56-
std::string& errorMessage, bool fJustCheck);
57-
bool CheckExecuteDomainEntryTxInputs(const CTransaction& tx, const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters,
58-
std::string& errorMessage, bool fJustCheck);
59-
bool CheckBindDomainEntryTxInputs(const CTransaction& tx, const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters,
60-
std::string& errorMessage, bool fJustCheck);
61-
bool CheckRevokeDomainEntryTxInputs(const CTransaction& tx, const CDomainEntry& entry, const CScript& scriptOp, const vchCharString& vvchOpParameters,
62-
std::string& errorMessage, bool fJustCheck);
6349
bool CheckDomainEntryTx(const CTransactionRef& tx, const CScript& scriptOp, const int& op1, const int& op2, const std::vector<std::vector<unsigned char> >& vvchArgs,
64-
bool fJustCheck, int nHeight, std::string& errorMessage, bool bSanityCheck);
50+
const bool fJustCheck, const int& nHeight, const uint32_t& nBlockTime, const bool bSanityCheck, std::string& errorMessage);
6551

6652
extern CDomainEntryDB *pDomainEntryDB;
6753

0 commit comments

Comments
 (0)