Author

Topic: New alt - nSubsidy issue - FIXED (Read 466 times)

legendary
Activity: 1007
Merit: 1000
October 20, 2016, 08:04:13 PM
#3
Thank you for taking the time out to give advice on this issue Smiley
Strangely, adding the else statements allowed it to finally work for me, however as its simply testing I will 100% give your advice a try Smiley

I am currently looking at some other coin sources to see more elegant ways of applying the halving schedule. However to fully 'clean' the code the way I want to its going to take me quite awhile, I have very little experience in c++, but am learning along the way and will be taking pointers from the source of some coins I really like on how things SHOULD be applied.

Is this closer to what you mean?

  if(nHeight > 1440)
    {
        nSubsidy = 230 * COIN;
     }


*EDIT*
Thank you again for your advice Smiley I have trimmed down the code removing all of my && statements and the else's as per your suggestion. You were absolutely right that I had simply bloated the code with extras that didnt need to be there. Basically, in trying to 'cover all angles' I ended up overthinking and overcoding.

I still plan on tidying the code up even more and hopefully manage to work it into 1 or 2 if statements (one for the first 1440, and one for the rest), aswell as many other things I'd love to learn to implement from other coins. Just basic features for now (irc, BE in-wallet, cpu miner in-wallet, and eventually an algo change) but all leading up to hopefully bigger better things Smiley

STILL NO RELEASE PLANS - Learning for future projects
legendary
Activity: 2548
Merit: 1054
CPU Web Mining 🕸️ on webmining.io
October 20, 2016, 03:40:51 PM
#2
Hello Smiley
I am currently in the process of building my own coin. I have been following multiple guides (some for the code modding, some for windows compiling, etc) and have gotten to a point where my code builds properly for both windows (mxe or mingw) and linux ,what a job that was! My original goal was to complete start to finish without asking for forum help... but im stumped.

My Issue:
I have my code set for a block halving every 1mil blocks, with 1440 (one day) blocks at 1 coin for a fair distribution start. Yet no matter what I do to the code, my blocks do not change reward with the coded schedule, similar to the 42coin issue where it never stopped lol

int64_t GetProofOfWorkReward(int64_t nFees)
{

    int64_t nSubsidy = 0;

    if (pindexBest->nHeight+1 >= 0 && pindexBest->nHeight+1 <= 1440)
    {
     nSubsidy = 1 * COIN;
    }

    if (pindexBest->nHeight+1 >= 1440 && pindexBest->nHeight+1 <= 1001440)
    {
     nSubsidy = 230 * COIN;
    }

    if (pindexBest->nHeight+1 >= 1001441 && pindexBest->nHeight+1 <= 2001440)
    {
     nSubsidy = 115 * COIN;
    }

    if (pindexBest->nHeight+1 >= 2001441 && pindexBest->nHeight+1 <= 3001440)
    {
     nSubsidy = 57.5 * COIN;
    }

    if (pindexBest->nHeight+1 >= 3001441 && pindexBest->nHeight+1 <= 4001440)
    {
     nSubsidy = 28.75 * COIN;
    }

 return nSubsidy;



FIXED
needed to add 'else' before each if.. stupid mistake but good to know Smiley I will continue updating with any common errors and fixes I encounter for future coin-builders Smiley

You don't need all the elses. There a lot more efficient ways to do this, though

Every condition that is true will change the reward so it will go through all checks anyway. Get rid of all the &&s, bring nHeight into the function, and do it properly

I changed one thing to get you started, but you do not need to write the word else in this function at all
legendary
Activity: 1007
Merit: 1000
October 20, 2016, 02:37:02 PM
#1
Hello Smiley
I am currently in the process of building my own coin. I have been following multiple guides (some for the code modding, some for windows compiling, etc) and have gotten to a point where my code builds properly for both windows (mxe or mingw) and linux ,what a job that was! My original goal was to complete start to finish without asking for forum help... but im stumped.

My Issue:
I have my code set for a block halving every 1mil blocks, with 1440 (one day) blocks at 1 coin for a fair distribution start. Yet no matter what I do to the code, my blocks do not change reward with the coded schedule, similar to the 42coin issue where it never stopped lol

int64_t GetProofOfWorkReward(int64_t nFees)
{

    int64_t nSubsidy;

    if (pindexBest->nHeight+1 >= 0 && pindexBest->nHeight+1 <= 1440)
    {
     nSubsidy = 1 * COIN;
    }

    if (pindexBest->nHeight+1 >= 1440 && pindexBest->nHeight+1 <= 1001440)
    {
     nSubsidy = 230 * COIN;
    }

    if (pindexBest->nHeight+1 >= 1001441 && pindexBest->nHeight+1 <= 2001440)
    {
     nSubsidy = 115 * COIN;
    }

    if (pindexBest->nHeight+1 >= 2001441 && pindexBest->nHeight+1 <= 3001440)
    {
     nSubsidy = 57.5 * COIN;
    }

    if (pindexBest->nHeight+1 >= 3001441 && pindexBest->nHeight+1 <= 4001440)
    {
     nSubsidy = 28.75 * COIN;
    }

    else
    {
     nSubsidy = 0 * COIN;
    }


FIXED
needed to add 'else' before each if.. stupid mistake but good to know Smiley I will continue updating with any common errors and fixes I encounter for future coin-builders Smiley
Jump to: