This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 681
/
ClusterConfigExtensions.cs
198 lines (154 loc) · 5.3 KB
/
ClusterConfigExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System.Globalization;
using System.Numerics;
using Autofac;
using JetBrains.Annotations;
using Miningcore.Crypto;
using Miningcore.Crypto.Hashing.Algorithms;
using NBitcoin;
using Newtonsoft.Json;
namespace Miningcore.Configuration;
public abstract partial class CoinTemplate
{
public T As<T>() where T : CoinTemplate
{
return (T) this;
}
public abstract string GetAlgorithmName();
/// <summary>
/// json source file where this template originated from
/// </summary>
[JsonIgnore]
public string Source { get; set; }
}
public partial class BitcoinTemplate
{
public BitcoinTemplate()
{
coinbaseHasherValue = new Lazy<IHashAlgorithm>(() =>
HashAlgorithmFactory.GetHash(ComponentContext, CoinbaseHasher));
headerHasherValue = new Lazy<IHashAlgorithm>(() =>
HashAlgorithmFactory.GetHash(ComponentContext, HeaderHasher));
blockHasherValue = new Lazy<IHashAlgorithm>(() =>
HashAlgorithmFactory.GetHash(ComponentContext, BlockHasher));
posBlockHasherValue = new Lazy<IHashAlgorithm>(() =>
HashAlgorithmFactory.GetHash(ComponentContext, PoSBlockHasher));
}
private readonly Lazy<IHashAlgorithm> coinbaseHasherValue;
private readonly Lazy<IHashAlgorithm> headerHasherValue;
private readonly Lazy<IHashAlgorithm> blockHasherValue;
private readonly Lazy<IHashAlgorithm> posBlockHasherValue;
public IComponentContext ComponentContext { get; [UsedImplicitly] init; }
public IHashAlgorithm CoinbaseHasherValue => coinbaseHasherValue.Value;
public IHashAlgorithm HeaderHasherValue => headerHasherValue.Value;
public IHashAlgorithm BlockHasherValue => blockHasherValue.Value;
public IHashAlgorithm PoSBlockHasherValue => posBlockHasherValue.Value;
public BitcoinNetworkParams GetNetwork(ChainName chain)
{
if(Networks == null || Networks.Count == 0)
return null;
if(chain == ChainName.Mainnet)
return Networks["main"];
else if(chain == ChainName.Testnet)
return Networks["test"];
else if(chain == ChainName.Regtest)
return Networks["regtest"];
throw new NotSupportedException("unsupported network type");
}
#region Overrides of CoinTemplate
public override string GetAlgorithmName()
{
var hash = HeaderHasherValue;
if(hash.GetType() == typeof(DigestReverser))
return ((DigestReverser) hash).Upstream.GetType().Name;
return hash.GetType().Name;
}
#endregion
}
public partial class EquihashCoinTemplate
{
public partial class EquihashNetworkParams
{
public EquihashNetworkParams()
{
diff1Value = new Lazy<Org.BouncyCastle.Math.BigInteger>(() =>
{
if(string.IsNullOrEmpty(Diff1))
throw new InvalidOperationException("Diff1 has not yet been initialized");
return new Org.BouncyCastle.Math.BigInteger(Diff1, 16);
});
diff1BValue = new Lazy<BigInteger>(() =>
{
if(string.IsNullOrEmpty(Diff1))
throw new InvalidOperationException("Diff1 has not yet been initialized");
return BigInteger.Parse(Diff1, NumberStyles.HexNumber);
});
}
private readonly Lazy<Org.BouncyCastle.Math.BigInteger> diff1Value;
private readonly Lazy<BigInteger> diff1BValue;
[JsonIgnore]
public Org.BouncyCastle.Math.BigInteger Diff1Value => diff1Value.Value;
[JsonIgnore]
public BigInteger Diff1BValue => diff1BValue.Value;
[JsonIgnore]
public ulong FoundersRewardSubsidySlowStartShift => FoundersRewardSubsidySlowStartInterval / 2;
[JsonIgnore]
public ulong LastFoundersRewardBlockHeight => FoundersRewardSubsidyHalvingInterval + FoundersRewardSubsidySlowStartShift - 1;
}
public EquihashNetworkParams GetNetwork(ChainName chain)
{
if(chain == ChainName.Mainnet)
return Networks["main"];
else if(chain == ChainName.Testnet)
return Networks["test"];
else if(chain == ChainName.Regtest)
return Networks["regtest"];
throw new NotSupportedException("unsupported network type");
}
#region Overrides of CoinTemplate
public override string GetAlgorithmName()
{
// TODO: return variant
return "Equihash";
}
#endregion
}
public partial class CryptonoteCoinTemplate
{
#region Overrides of CoinTemplate
public override string GetAlgorithmName()
{
// switch(Hash)
// {
// case CryptonightHashType.RandomX:
// return "RandomX";
// }
return Hash.ToString();
}
#endregion
}
public partial class EthereumCoinTemplate
{
#region Overrides of CoinTemplate
public override string GetAlgorithmName()
{
return "Ethhash";
}
#endregion
}
public partial class ErgoCoinTemplate
{
#region Overrides of CoinTemplate
public override string GetAlgorithmName()
{
return "Autolykos";
}
#endregion
}
public partial class PoolConfig
{
/// <summary>
/// Back-reference to coin template for this pool
/// </summary>
[JsonIgnore]
public CoinTemplate Template { get; set; }
}