@@ -109,7 +109,7 @@ int GetProgram(json& walletInfo)
109109 walletInfo[" ProgramID" ] = programID;
110110 life = GetProgramLifeLeft ();
111111 cons.MiningPrint ();
112- cons.WriteLine (" Program life is " + std::to_string (life));
112+ cons.WriteLine (" Program life is " + std::to_string (life) + " mins. " );
113113 break ;
114114 }
115115 }
@@ -237,6 +237,8 @@ void CreateTransaction(P2P& p2p, json& walletInfo, double& amount){
237237// Check every single block to make sure the nonce is valid, the hash matches the earlier and later blocks, and each transaction has a valid signature.
238238bool IsChainValid (P2P& p2p, json& walletInfo)
239239{
240+ cons.BlockCheckerPrint ();
241+ cons.WriteLine (" Validating blockchain..." );
240242 try {
241243 /* while (FileCount("./wwwdata/blockchain/") < walletInfo["BlockchainLength"])
242244 {
@@ -332,10 +334,11 @@ bool IsChainValid(P2P& p2p, json& walletInfo)
332334 }
333335 catch (const std::exception& e)
334336 {
335- if (constants::debugPrint == true ) {
337+ // if (constants::debugPrint == true) {
338+ std::cerr << " \n " ;
336339 ERRORMSG (" Error\n " << e.what ());
337- }
338- cons.ExitError (" Failure, exiting 854" );
340+ // }
341+ // cons.ExitError("Failure, exiting 854");
339342 }
340343
341344 // Then process the rest of the blocks
@@ -355,7 +358,9 @@ bool IsChainValid(P2P& p2p, json& walletInfo)
355358 bool changedBlockData = false ;
356359 json o = json::parse (content);
357360
361+ std::string rewardedAddress; // The address that is awarded the gas fees and block reward
358362
363+ // Make sure block is up-to-date
359364 if (o[" _version" ] == nullptr || o[" _version" ] == " " || o[" _version" ] != BLOCK_VERSION)
360365 {
361366 UpgradeBlock (o);
@@ -431,6 +436,7 @@ bool IsChainValid(P2P& p2p, json& walletInfo)
431436 if ((std::string)walletInfo[" Address" ] == toAddr) { // If this is the receiving address, then give reward
432437 tmpFunds2 += amount;
433438 }
439+ rewardedAddress = toAddr;
434440 continue ;
435441 }
436442
@@ -464,6 +470,8 @@ bool IsChainValid(P2P& p2p, json& walletInfo)
464470 }
465471 else if ((std::string)walletInfo[" Address" ] == toAddr)
466472 tmpFunds2 += amount;
473+ else if (rewardedAddress == (std::string)walletInfo[" Address" ]) // If you are the one that mined this block, add gas fees
474+ tmpFunds2 += (float )o[" transactions" ][tr][" tx" ][" transactionFee" ];
467475 }
468476
469477 // Update funds and transaction number
@@ -492,26 +500,32 @@ bool IsChainValid(P2P& p2p, json& walletInfo)
492500 }
493501 }
494502
495- cons.WriteLine ();
503+ // cons.WriteLine();
496504 walletInfo[" Funds" ] = tmpFunds;
505+ cons.Write (" \r " );
506+ cons.BlockCheckerPrint ();
507+ cons.Write (" Done! \n " );
497508 return true ;
498509 }
499510 catch (const std::exception& e)
500511 {
501512 ERRORMSG (" Error validating chain:\n " << e.what ());
502513 }
514+ cons.Write (" \r " );
515+ cons.BlockCheckerPrint ();
516+ cons.Write (" Done! (there were problems) \n " );
503517 return false ;
504518}
505519
506520
507521// Calculates the difficulty of the next block by looking at the past 720 blocks,
508522// and averaging the time it took between each block to keep it within the 2 min (120 second) range
509523std::string CalculateDifficulty (json& walletInfo) {
510- std::string targetDifficulty = " 0000000FFFFFF000000000000000000000000000000000000000000000000000 " ;
524+ std::string targetDifficulty = " 000000FFFFFF0000000000000000000000000000000000000000000000000000 " ;
511525
512526 int blockCount = FileCount (" ./wwwdata/blockchain/" );
513527
514- // Default difficulty 7 for the first 720 blocks
528+ // Default difficulty 6 for the first 720 blocks
515529 if (blockCount <= 721 ) {
516530 walletInfo[" targetDifficulty" ] = targetDifficulty;
517531 walletInfo[" MineDifficulty" ] = ExtractPaddedChars (targetDifficulty, ' 0' );
@@ -621,17 +635,21 @@ void CreateSuperblock() {
621635 buffert << tt.rdbuf ();
622636 json o = json::parse (buffert.str ());
623637
638+ std::string rewardedAddress; // The address that is awarded the gas fees and block reward
639+
624640 // Add / subtract value from each address in the transactions
625641 for (int tr = 0 ; tr < o[" transactions" ].size (); tr++) {
626642 std::string fromAddr = (std::string)o[" transactions" ][tr][" tx" ][" fromAddr" ];
627643 std::string toAddr = (std::string)o[" transactions" ][tr][" tx" ][" toAddr" ];
628644 double amount = o[" transactions" ][tr][" tx" ][" amount" ];
645+ double transactionFee = o[" transactions" ][tr][" tx" ][" transactionFee" ];
629646
630647 if (tr == 0 ) {
631648 if (walletBalances.contains (toAddr))
632649 walletBalances[toAddr] += amount;
633650 else
634651 walletBalances[toAddr] = amount;
652+ rewardedAddress = toAddr;
635653 }
636654 else {
637655 if (walletBalances.contains (fromAddr))
@@ -643,6 +661,11 @@ void CreateSuperblock() {
643661 walletBalances[toAddr] += amount;
644662 else
645663 walletBalances[toAddr] = amount;
664+
665+ if (walletBalances.contains (rewardedAddress))
666+ walletBalances[rewardedAddress] += transactionFee;
667+ else
668+ walletBalances[rewardedAddress] = transactionFee;
646669 }
647670 }
648671 }
@@ -776,6 +799,19 @@ json UpgradeBlock(json& b)
776799 b[" _version" ] = " v0.7.0-alpha-coin" ;
777800 }
778801
802+ // // v0.7.1-alpha-coin
803+ // // Changes:
804+ // // * Enforce transactionFee variable
805+ // // * Update version
806+ // if (IsVersionGreaterOrEqual(currentVersion, "v0.7.1-alpha-coin") == false)
807+ // {
808+ // // Add transactionFee to each transaction
809+ // for (int tr = 0; tr < b["transactions"].size(); tr++) {
810+ // b["transactions"][tr]["tx"]["transactionFee"] = 0.0;
811+ // }
812+ // b["_version"] = "v0.7.1-alpha-coin";
813+ // }
814+
779815
780816
781817
0 commit comments