4
4
5
5
#include " bdap/domainentrydb.h"
6
6
7
+ #include " amount.h"
7
8
#include " base58.h"
9
+ #include " bdap/fees.h"
8
10
#include " coins.h"
9
11
#include " bdap/utils.h"
10
12
#include " validation.h"
@@ -351,12 +353,30 @@ static bool CommonDataCheck(const CDomainEntry& entry, const vchCharString& vvch
351
353
return false ;
352
354
}
353
355
356
+ if (vvchOpParameters.size () != 3 )
357
+ {
358
+ errorMessage = " CommonDataCheck failed! Not enough parameters." ;
359
+ return false ;
360
+ }
361
+
354
362
if (entry.GetFullObjectPath () != stringFromVch (vvchOpParameters[0 ]))
355
363
{
356
364
errorMessage = " CommonDataCheck failed! Script operation parameter does not match entry entry object." ;
357
365
return false ;
358
366
}
359
367
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
+
360
380
if (entry.DomainComponent != vchDefaultDomainName)
361
381
{
362
382
errorMessage = " CommonDataCheck failed! Must use default domain." ;
@@ -378,7 +398,7 @@ static bool CommonDataCheck(const CDomainEntry& entry, const vchCharString& vvch
378
398
return true ;
379
399
}
380
400
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,
382
402
std::string& errorMessage, bool fJustCheck )
383
403
{
384
404
if (!CommonDataCheck (entry, vvchOpParameters, errorMessage))
@@ -415,7 +435,7 @@ bool CheckNewDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scrip
415
435
return FlushLevelDB ();
416
436
}
417
437
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,
419
439
std::string& errorMessage, bool fJustCheck )
420
440
{
421
441
if (vvchOpParameters.size () == 0 ) {
@@ -473,7 +493,7 @@ bool CheckDeleteDomainEntryTxInputs(const CDomainEntry& entry, const CScript& sc
473
493
return FlushLevelDB ();
474
494
}
475
495
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 ,
477
497
std::string& errorMessage, bool fJustCheck )
478
498
{
479
499
// if exists, check for owner's signature
@@ -523,7 +543,12 @@ bool CheckUpdateDomainEntryTxInputs(const CDomainEntry& entry, const CScript& sc
523
543
return error (errorMessage.c_str ());
524
544
}
525
545
}
526
-
546
+ if (nMonths < 10000 ) {
547
+ entry.nExpireTime = prevDomainEntry.nExpireTime + AddMonthsToBlockTime (nBlockTime, nMonths);
548
+ }
549
+ else {
550
+ entry.nExpireTime = nMonths;
551
+ }
527
552
if (!pDomainEntryDB->UpdateDomainEntry (entry.vchFullObjectPath (), entry))
528
553
{
529
554
errorMessage = " CheckUpdateDomainEntryTxInputs: - Error updating entry in LevelDB; this update operation failed!" ;
@@ -533,7 +558,7 @@ bool CheckUpdateDomainEntryTxInputs(const CDomainEntry& entry, const CScript& sc
533
558
return FlushLevelDB ();
534
559
}
535
560
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,
537
562
std::string& errorMessage, bool fJustCheck )
538
563
{
539
564
// check name in operation matches entry data in leveldb
@@ -542,45 +567,17 @@ bool CheckMoveDomainEntryTxInputs(const CDomainEntry& entry, const CScript& scri
542
567
return false ;
543
568
}
544
569
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
-
573
570
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 )
575
572
{
576
573
if (tx->IsCoinBase () && !fJustCheck && !bSanityCheck)
577
574
{
578
575
LogPrintf (" *Trying to add BDAP entry in coinbase transaction, skipping..." );
579
576
return true ;
580
577
}
581
578
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
+
584
581
// unserialize BDAP from txn, check if the entry is valid and does not conflict with a previous entry
585
582
CDomainEntry entry;
586
583
std::vector<unsigned char > vchData;
@@ -606,16 +603,114 @@ bool CheckDomainEntryTx(const CTransactionRef& tx, const CScript& scriptOp, cons
606
603
entry.txHash = tx->GetHash ();
607
604
entry.nHeight = nHeight;
608
605
}
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
+
610
658
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
+
612
667
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
+
616
712
return CheckMoveDomainEntryTxInputs (entry, scriptOp, vvchArgs, errorMessage, fJustCheck );
617
- else if (strOperationType == " bdap_revoke_account" )
618
- return CheckRevokeDomainEntryTxInputs (entry, scriptOp, vvchArgs, errorMessage, fJustCheck );
713
+ }
619
714
620
715
return false ;
621
716
}
0 commit comments