Author

Topic: An altcoin that sends some of the block reward to the developer wallets (Read 359 times)

jr. member
Activity: 244
Merit: 1
I've actually managed to do this now, but I the problem is the validation tests fail. Any ideas which validation rules this may have broken. Turns out the validation file is 4000 lines long, yikes.
jr. member
Activity: 244
Merit: 1
I'm developing an altcoin for learning purposes, and I'm experimenting with the bitcoin source code so that I can learn the ins and outs of this stuff.

My latest challenge to myself is to develop and altcoin that gives some of the mining reward to a developer wallet whenever any miner successfully mines the block.
I'm thinking the mining reward should be 50 coins, 49 of those will go to the miner, but 1 of those coins will go into the developer wallet, lets say.

Poking around with the code lead me to `miner.cpp`, around line 190.

  
Code:
 CMutableTransaction coinbaseTx;
    coinbaseTx.vin.resize(1);
    coinbaseTx.vin[0].prevout.SetNull();
    coinbaseTx.vout.resize(1);
    coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
    coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
    coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
    pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
    pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
    pblocktemplate->vTxFees[0] = -nFees;

It seems as though I would need to add a new output to
Code:
coinbaseTx.vout
which would be the 1 coin output given to the developer.

Is this correct?

If so, how would I set up this new output? I can't simply add the public key of the developer wallet somewhere as I need to generate a scriptPubKey to do this. However, I'm not sure exactly how this would be done.

I am assuming that I would have to change the
Code:
coinbaseTx.vout.resize(1)
to  
Code:
coinbaseTx.vout.resize(2)
, then add the new output in there. I'm assuming I would have to decrease the value of the first output that is given to the miner as the block reward. Am I correct in assuming that scriptPubKeyIn is the miners scriptPubKey?

I'm sure that I would also have to change the consensus rules to check that new blocks entering the network indeed give an output of 1 coin to the developers, as part of the coinbase reward. If they do not include this in they coinbase transaction, then they would surely be rejected.

I'm not really sure how to add this new output on the coinbase transaction, to a fixed wallet. Any help would be greatly appreciated -

happy to donate a few satoshis to someone who gives me an answer I can use BTC  Grin Grin Grin
Jump to: