/// <summary> /// Creates a new instance of generation transaction. /// </summary> /// <param name="extraNonce">The extra nonce.</param> /// <param name="daemonClient">The daemon client.</param> /// <param name="blockTemplate">The block template.</param> /// <param name="poolConfig">The associated pool's configuration</param> /// <remarks> /// Reference implementations: /// https://github.com/zone117x/node-stratum-pool/blob/b24151729d77e0439e092fe3a1cdbba71ca5d12e/lib/transactions.js /// https://github.com/Crypto-Expert/stratum-mining/blob/master/lib/coinbasetx.py /// </remarks> public GenerationTransaction(IExtraNonce extraNonce, IDaemonClient daemonClient, IBlockTemplate blockTemplate, IPoolConfig poolConfig) { // TODO: we need a whole refactoring here. // we should use DI and it shouldn't really require daemonClient connection to function. bool found = false; string address = ""; int permille = 0; foreach (var pair in poolConfig.Rewards) { address = pair.Key; permille = (int)(pair.Value * 10); found = true; break; } Coinbase tx; if (found) { tx = daemonClient.CreateCoinbaseForAddressWithPoolFee(poolConfig.Wallet.Adress, blockTemplate.Height, address, permille); } else { tx = daemonClient.CreateCoinbaseForAddress(poolConfig.Wallet.Adress, blockTemplate.Height); } /*Console.WriteLine("Coinbase1 {0}", tx.coinbasepart1); * Console.WriteLine("Coinbase2 {0}", tx.coinbasepart2);*/ InitialStr = tx.coinbasepart1; FinalStr = tx.coinbasepart2; /* * BlockTemplate = blockTemplate; * ExtraNonce = extraNonce; * PoolConfig = poolConfig; * * Version = blockTemplate.Version; * TxMessage = Serializers.SerializeString(poolConfig.Meta.TxMessage); * LockTime = 0; * * // transaction inputs * Inputs = new List<TxIn> * { * new TxIn * { * PreviousOutput = new OutPoint * { * Hash = Hash.ZeroHash, * Index = (UInt32) Math.Pow(2, 32) - 1 * }, * Sequence = 0x0, * SignatureScript = * new SignatureScript( * blockTemplate.Height, * blockTemplate.CoinBaseAux.Flags, * TimeHelpers.NowInUnixTimestamp(), * (byte) extraNonce.ExtraNoncePlaceholder.Length, * "/CoiniumServ/") * } * }; * * // transaction outputs * Outputs = new Outputs(daemonClient, poolConfig.Coin); * * double blockReward = BlockTemplate.Coinbasevalue; // the amount rewarded by the block. * * // generate output transactions for recipients (set in config). * foreach (var pair in poolConfig.Rewards) * { * var amount = blockReward * pair.Value / 100; // calculate the amount he recieves based on the percent of his shares. * blockReward -= amount; * * Outputs.AddRecipient(pair.Key, amount); * } */ // send the remaining coins to pool's central wallet. //Outputs.AddPoolWallet(poolConfig.Wallet.Adress, blockReward); }