Commit 6cb9d329 authored by Sergei Zubov's avatar Sergei Zubov

Add random select of fee address

Sending all fees to same address will make funds on that address
unspendable - it will never be enough confirmations on top of last
transactions. Taking random address from pool will prevent this issue.
parent b5070c9a
...@@ -9,12 +9,20 @@ namespace NBitcoin ...@@ -9,12 +9,20 @@ namespace NBitcoin
{ {
public abstract partial class Network public abstract partial class Network
{ {
// TODO: Implement custom circular collection private readonly LinkedList<string> _deStreamWallets = new LinkedList<string>(new []
public readonly IReadOnlyCollection<string> DeStreamWallets = new ReadOnlyCollection<string>(new List<string>()
{ {
"DQAa8Fg1ytS5wiXbn1qToRpe9wYSQhCAWc", "DQAa8Fg1ytS5wiXbn1qToRpe9wYSQhCAWc",
"DMoFqYQNfsoorMbmTbyErxk43ev9B2EuEe", "DMoFqYQNfsoorMbmTbyErxk43ev9B2EuEe",
}); }.OrderBy(p => Guid.NewGuid()));
private LinkedListNode<string> DeStreamWalletsNode => this._deStreamWallets.First;
public string DeStreamWallet => this.DeStreamWalletsNode.NextOrFirst().Value;
public bool IsDeStreamAddress(string address)
{
return this._deStreamWallets.Contains(address);
}
/// <summary> /// <summary>
/// ///
......
using System.Collections.Generic;
namespace NBitcoin
{
internal static class CircularLinkedList
{
public static LinkedListNode<T> NextOrFirst<T>(this LinkedListNode<T> current)
{
if (current?.List != null) return current.Next ?? current.List.First;
return null;
}
public static LinkedListNode<T> PreviousOrLast<T>(this LinkedListNode<T> current)
{
if (current?.List != null) return current.Previous ?? current.List.Last;
return null;
}
}
}
\ No newline at end of file
...@@ -37,9 +37,8 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules ...@@ -37,9 +37,8 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
private long GetActualFee(Block block) private long GetActualFee(Block block)
{ {
IList<TxOut> outputsToFeeWallet = block.Transactions[BlockStake.IsProofOfStake(block) ? 1 : 0].Outputs IList<TxOut> outputsToFeeWallet = block.Transactions[BlockStake.IsProofOfStake(block) ? 1 : 0].Outputs
.Where(p => .Where(p => this.Parent.Network.IsDeStreamAddress(p.ScriptPubKey
this.Parent.Network.DeStreamWallets.Any(q => .GetDestinationAddress(this.Parent.Network)?.ToString())).ToList();
q == p.ScriptPubKey.GetDestinationAddress(this.Parent.Network)?.ToString())).ToList();
if (outputsToFeeWallet.Count() != 1) if (outputsToFeeWallet.Count() != 1)
throw new Exception(); throw new Exception();
......
...@@ -44,7 +44,7 @@ namespace Stratis.Bitcoin.Features.Miner ...@@ -44,7 +44,7 @@ namespace Stratis.Bitcoin.Features.Miner
return; return;
Script deStreamAddressKey = new KeyId(new uint160(Encoders.Base58Check Script deStreamAddressKey = new KeyId(new uint160(Encoders.Base58Check
.DecodeData(this.network.DeStreamWallets.First()) .DecodeData(this.network.DeStreamWallet)
.Skip(this.network.Base58Prefixes[(int) Base58Type.PUBKEY_ADDRESS].Length).ToArray())).ScriptPubKey; .Skip(this.network.Base58Prefixes[(int) Base58Type.PUBKEY_ADDRESS].Length).ToArray())).ScriptPubKey;
context.CoinstakeContext.CoinstakeTx.AddOutput(new TxOut(Money.Zero, deStreamAddressKey)); context.CoinstakeContext.CoinstakeTx.AddOutput(new TxOut(Money.Zero, deStreamAddressKey));
......
...@@ -81,7 +81,7 @@ namespace Stratis.Bitcoin.Features.Miner ...@@ -81,7 +81,7 @@ namespace Stratis.Bitcoin.Features.Miner
base.CreateCoinbase(); base.CreateCoinbase();
Script deStreamAddressKey = new KeyId(new uint160(Encoders.Base58Check Script deStreamAddressKey = new KeyId(new uint160(Encoders.Base58Check
.DecodeData(this.Network.DeStreamWallets.First()) .DecodeData(this.Network.DeStreamWallet)
.Skip(this.Network.Base58Prefixes[(int) Base58Type.PUBKEY_ADDRESS].Length).ToArray())).ScriptPubKey; .Skip(this.Network.Base58Prefixes[(int) Base58Type.PUBKEY_ADDRESS].Length).ToArray())).ScriptPubKey;
this.coinbase.AddOutput(new TxOut(Money.Zero, deStreamAddressKey)); this.coinbase.AddOutput(new TxOut(Money.Zero, deStreamAddressKey));
} }
......
...@@ -81,7 +81,7 @@ namespace Stratis.Bitcoin.Features.Miner ...@@ -81,7 +81,7 @@ namespace Stratis.Bitcoin.Features.Miner
base.CreateCoinbase(); base.CreateCoinbase();
Script deStreamAddressKey = new KeyId(new uint160(Encoders.Base58Check Script deStreamAddressKey = new KeyId(new uint160(Encoders.Base58Check
.DecodeData(this.Network.DeStreamWallets.First()) .DecodeData(this.Network.DeStreamWallet)
.Skip(this.Network.Base58Prefixes[(int) Base58Type.PUBKEY_ADDRESS].Length).ToArray())).ScriptPubKey; .Skip(this.Network.Base58Prefixes[(int) Base58Type.PUBKEY_ADDRESS].Length).ToArray())).ScriptPubKey;
this.coinbase.AddOutput(new TxOut(Money.Zero, deStreamAddressKey)); this.coinbase.AddOutput(new TxOut(Money.Zero, deStreamAddressKey));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment