public OutputsTests() { _daemonClient = Substitute.For <IDaemonClient>(); _daemonClient.ValidateAddress(Arg.Any <string>()).Returns(new ValidateAddress { IsValid = true }); }
public Outputs(IDaemonClient daemonClient, ICoinConfig coinConfig) { _daemonClient = daemonClient; _coinConfig = coinConfig; List = new List <TxOut>(); }
public Outputs(IDaemonClient daemonClient, ICoinConfig coinConfig) { _daemonClient = daemonClient; _coinConfig = coinConfig; List = new List<TxOut>(); }
public BlockProcessorTests() { // create mockup objects required for tests. _daemonClient = Substitute.For <IDaemonClient>(); _poolConfig = Substitute.For <IPoolConfig>(); _storageLayer = Substitute.For <IStorageLayer>(); }
public PaymentProcessor(IPoolConfig poolConfig, IStorageLayer storageLayer, IDaemonClient daemonClient, IAccountManager accountManager) { _poolConfig = poolConfig; _storageLayer = storageLayer; _daemonClient = daemonClient; _accountManager = accountManager; _logger = Log.ForContext <PaymentProcessor>().ForContext("Component", poolConfig.Coin.Name); if (!_poolConfig.Payments.Enabled) // make sure payments are enabled. { return; } if (!ValidatePoolAddress()) // try to validate the pool wallet. { return; // if we can't, stop the payment processor. } if (!GetPoolAccount()) // get the pool's account name if any. { return; // if we can't, stop the payment processor. } FindPoolZAddress(); Active = true; }
/// <summary> /// Initializes a new instance of the <see cref="ShareManager" /> class. /// </summary> /// <param name="pool"></param> /// <param name="daemonClient"></param> /// <param name="jobTracker"></param> /// <param name="storage"></param> public ShareManager(string pool, IDaemonClient daemonClient, IJobTracker jobTracker, IStorage storage) { _daemonClient = daemonClient; _jobTracker = jobTracker; _storage = storage; _logger = Log.ForContext<ShareManager>().ForContext("Component", pool); }
public HybridStorageLayer(IEnumerable <IStorageProvider> providers, IDaemonClient daemonClient, IPoolConfig poolConfig) { _daemonClient = daemonClient; _logger = Log.ForContext <HybridStorageLayer>().ForContext("Component", poolConfig.Coin.Name); _coin = poolConfig.Coin.Name.ToLower(); // pool's associated coin name. // try loading providers. try { foreach (var provider in providers) { if (provider is IRedisProvider) { _redisProvider = (IRedisProvider)provider; } else if (provider is IMySqlProvider) { _mySqlProvider = (IMySqlProvider)provider; } } IsEnabled = (_redisProvider != null && _mySqlProvider != null); } catch (Exception e) { _logger.Error("Error initializing hybrid storage layer; {0:l}", e.Message); } }
public PaymentProcessor(string pool, IDaemonClient daemonClient, IStorage storage , IWalletConfig walletConfig) { _daemonClient = daemonClient; _storage = storage; _walletConfig = walletConfig; _logger = Log.ForContext<PaymentProcessor>().ForContext("Component", pool); }
public BlockProcessorTests() { // create mockup objects required for tests. _daemonClient = Substitute.For<IDaemonClient>(); _poolConfig = Substitute.For<IPoolConfig>(); _storageLayer = Substitute.For<IStorageLayer>(); }
public BlockProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient) { _poolConfig = poolConfig; _daemonClient = daemonClient; _logger = Log.ForContext <BlockProcessor>().ForContext("Component", poolConfig.Coin.Name); FindPoolAccount(); }
public OutputsTests() { _daemonClient = Substitute.For<IDaemonClient>(); _daemonClient.ValidateAddress(Arg.Any<string>()).Returns(new ValidateAddress { IsValid = true }); _coinConfig = Substitute.For<ICoinConfig>(); _coinConfig.Options.IsProofOfStakeHybrid.Returns(false); }
/// <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. BlockTemplate = blockTemplate; ExtraNonce = extraNonce; PoolConfig = poolConfig; Version = 1;//change version for bitcoin like 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 = (UInt32)Math.Pow(2, 32) - 1, SignatureScript = new SignatureScript( blockTemplate.Height, //blockTemplate.CoinBaseAux.Flags, "", TimeHelpers.NowInUnixTimestamp(), (byte)extraNonce.ExtraNoncePlaceholder.Length, "") } }; // 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); }
/// <summary> /// Gets the specified service name. /// </summary> /// <param name="serviceName">Name of the service.</param> /// <param name="shareManager">The share manager.</param> /// <param name="daemonClient">The daemon client.</param> /// <returns></returns> public IRpcService Get(string serviceName, IShareManager shareManager, IDaemonClient daemonClient) { var @params = new NamedParameterOverloads { {"shareManager", shareManager}, {"daemonClient", daemonClient} }; return _applicationContext.Container.Resolve<IRpcService>(serviceName, @params); }
public JobManager(IDaemonClient daemonClient, IJobTracker jobTracker, IShareManager shareManager, IMinerManager minerManager, IHashAlgorithm hashAlgorithm) { _daemonClient = daemonClient; _jobTracker = jobTracker; _shareManager = shareManager; _minerManager = minerManager; _hashAlgorithm = hashAlgorithm; _jobCounter = new JobCounter(); }
/// <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. 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 the 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); // Final output is witness //https://github.com/slush0/stratum-mining/pull/16/files?diff=unified if (!string.IsNullOrEmpty(BlockTemplate.Default_witness_commitment)) { Outputs.AddWitnessOutput(BlockTemplate.Default_witness_commitment.HexToByteArray()); } }
public IMinerManager Get(IDaemonClient daemonClient) { var @params = new NamedParameterOverloads { {"daemonClient", daemonClient} }; return _applicationContext.Container.Resolve<IMinerManager>(@params); }
/// <summary> /// Initializes a new instance of the <see cref="ShareManager" /> class. /// </summary> /// <param name="poolConfig"></param> /// <param name="daemonClient"></param> /// <param name="jobTracker"></param> /// <param name="storageLayer"></param> /// <param name="blockProcessor"></param> public ShareManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJobTracker jobTracker, IStorageLayer storageLayer, IBlockProcessor blockProcessor) { _poolConfig = poolConfig; _daemonClient = daemonClient; _jobTracker = jobTracker; _storageLayer = storageLayer; _blockProcessor = blockProcessor; _logger = Log.ForContext <ShareManager>().ForContext("Component", poolConfig.Coin.Name); }
public PaymentProcessor(IPoolConfig poolConfig, IStorageLayer storageLayer, IDaemonClient daemonClient, IBlockProcessor blockProcessor) { _poolConfig = poolConfig; _daemonClient = daemonClient; _storageLayer = storageLayer; _blockProcessor = blockProcessor; _logger = Log.ForContext <PaymentProcessor>().ForContext("Component", poolConfig.Coin.Name); }
/// <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="supportTxMessages">if set to <c>true</c> [support tx messages].</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, bool supportTxMessages = false) { DaemonClient = daemonClient; BlockTemplate = blockTemplate; ExtraNonce = extraNonce; SupportTxMessages = supportTxMessages; Version = (UInt32)(supportTxMessages ? 2 : 1); Message = Serializers.SerializeString("https://github.com/CoiniumServ/CoiniumServ"); 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.NowInUnixTime(), (byte) extraNonce.ExtraNoncePlaceholder.Length, "/CoiniumServ/") } }; // transaction outputs Outputs = new Outputs(daemonClient); double blockReward = BlockTemplate.Coinbasevalue; // the amount rewarded by the block. const string poolWallet = "n3Mvrshbf4fMoHzWZkDVbhhx4BLZCcU9oY"; // pool's central wallet address. var rewardRecipients = new Dictionary<string, double> // reward recipients addresses. { {"myxWybbhUkGzGF7yaf2QVNx3hh3HWTya5t", 1} // pool fee }; // generate output transactions for recipients (set in config). foreach (var pair in rewardRecipients) { 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.AddPool(poolWallet, blockReward); }
/// <summary> /// Initializes a new instance of the <see cref="ShareManager" /> class. /// </summary> /// <param name="poolConfig"></param> /// <param name="daemonClient"></param> /// <param name="jobTracker"></param> /// <param name="storageLayer"></param> public ShareManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJobTracker jobTracker, IStorageLayer storageLayer) { _poolConfig = poolConfig; _daemonClient = daemonClient; _jobTracker = jobTracker; _storageLayer = storageLayer; _logger = Log.ForContext<ShareManager>().ForContext("Component", poolConfig.Coin.Name); FindPoolAccount(); }
public IBlockProcessor GetBlockProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient) { var @params = new NamedParameterOverloads { { "poolConfig", poolConfig }, { "daemonClient", daemonClient }, }; return(_applicationContext.Container.Resolve <IBlockProcessor>(@params)); }
public BlockProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient, IStorageLayer storageLayer) { _poolConfig = poolConfig; _daemonClient = daemonClient; _storageLayer = storageLayer; _logger = Log.ForContext <BlockProcessor>().ForContext("Component", poolConfig.Coin.Name); FindPoolAccount(); Active = true; }
public MinerManager(IPoolConfig poolConfig, IDaemonClient daemonClient) { _minerConfig = poolConfig.Miner; _metaConfig = poolConfig.Meta; _daemonClient = daemonClient; _stratumServerConfig = poolConfig.Stratum; _miners = new Dictionary <int, IMiner>(); _logger = Log.ForContext <MinerManager>().ForContext("Component", poolConfig.Coin.Name); }
public MinerManager(IPoolConfig poolConfig, IStorageLayer storageLayer, IAccountManager accountManager, IDaemonClient daemonClient) { _poolConfig = poolConfig; _storageLayer = storageLayer; _accountManager = accountManager; _daemonClient = daemonClient; _miners = new Dictionary <int, IMiner>(); _logger = Log.ForContext <MinerManager>().ForContext("Component", poolConfig.Coin.Name); }
/// <summary> /// Initializes a new instance of the <see cref="ShareManager" /> class. /// </summary> /// <param name="poolConfig"></param> /// <param name="daemonClient"></param> /// <param name="jobTracker"></param> /// <param name="storageLayer"></param> public ShareManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJobTracker jobTracker, IStorageLayer storageLayer) { _poolConfig = poolConfig; _daemonClient = daemonClient; _jobTracker = jobTracker; _storageLayer = storageLayer; _logger = Log.ForContext <ShareManager>().ForContext("Component", poolConfig.Coin.Name); FindPoolAccount(); }
public JobManagerTests() { // mock objects. _daemon = Substitute.For <IDaemonClient>(); // create objects to be used. _jobManager = new MoneroJobManager(); _poolContext = new MoneroPoolContext(); Setup(); }
// todo: add %51 hash power detection support. public NetworkInfo(IDaemonClient daemonClient, IHashAlgorithm hashAlgorithm, IPoolConfig poolConfig) { _daemonClient = daemonClient; _hashAlgorithm = hashAlgorithm; _poolConfig = poolConfig; _logger = Log.ForContext <NetworkInfo>().ForContext("Component", poolConfig.Coin.Name); Recache(); // recache the data initially. PrintNetworkInfo(); DetectProofOfStakeCoin(); // detect if we are running on a proof-of-stake coin. }
/// <summary> /// Gets the specified daemon client. /// </summary> /// <param name="jobTracker">The job manager.</param> /// <param name="daemonClient"></param> /// <param name="storage"></param> /// <returns></returns> public IShareManager Get(IDaemonClient daemonClient, IJobTracker jobTracker, IStorage storage) { var @params = new NamedParameterOverloads { {"daemonClient", daemonClient}, {"jobTracker", jobTracker}, {"storage", storage} }; return _applicationContext.Container.Resolve<IShareManager>(@params); }
public BlockProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient, IStorageLayer storageLayer) { _poolConfig = poolConfig; _daemonClient = daemonClient; _storageLayer = storageLayer; _logger = Log.ForContext<BlockProcessor>().ForContext("Component", poolConfig.Coin.Name); FindPoolAccount(); Active = true; }
public PaymentProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient, IStorage storage, IBlockProcessor blockProcessor) { _daemonClient = daemonClient; _storage = storage; _blockProcessor = blockProcessor; _walletConfig = poolConfig.Wallet; _rewardsConfig = poolConfig.Rewards; _logger = Log.ForContext <PaymentProcessor>().ForContext("Component", poolConfig.Coin.Name); }
public INetworkInfo GetNetworkInfo(IDaemonClient daemonClient, IHashAlgorithm hashAlgorithm, IPoolConfig poolConfig) { var @params = new NamedParameterOverloads { { "daemonClient", daemonClient }, { "hashAlgorithm", hashAlgorithm }, { "poolConfig", poolConfig }, }; return(_applicationContext.Container.Resolve <INetworkInfo>(@params)); }
public PerPool(IPoolConfig poolConfig, IDaemonClient daemonClient,IMinerManager minerManager, IHashAlgorithm hashAlgorithm, IBlocks blockStatistics, IStorage storage) { Config = poolConfig; _daemonClient = daemonClient; _minerManager = minerManager; Blocks = blockStatistics; _storage = storage; _response = new ExpandoObject(); _shareMultiplier = Math.Pow(2, 32) / hashAlgorithm.Multiplier; }
public IShareManager GetShareManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJobTracker jobTracker, IStorageLayer storageLayer) { var @params = new NamedParameterOverloads { { "poolConfig", poolConfig }, { "daemonClient", daemonClient }, { "jobTracker", jobTracker }, { "storageLayer", storageLayer } }; return(_applicationContext.Container.Resolve <IShareManager>(@params)); }
public NetworkInfo(IDaemonClient daemonClient, IHashAlgorithm hashAlgorithm, IPoolConfig poolConfig) { _daemonClient = daemonClient; _hashAlgorithm = hashAlgorithm; _poolConfig = poolConfig; _logger = Log.ForContext <NetworkInfo>().ForContext("Component", poolConfig.Coin.Name); DetectProofOfStakeCoin(); // detect if we are running on a proof-of-stake coin. DetectSubmitBlockSupport(); // detect if the coin daemon supports submitblock call. Recache(); // recache the data initially. PrintNetworkInfo(); // print the collected network info. }
public NetworkInfo(IDaemonClient daemonClient, IHashAlgorithm hashAlgorithm, IPoolConfig poolConfig) { _daemonClient = daemonClient; _hashAlgorithm = hashAlgorithm; _poolConfig = poolConfig; _logger = Log.ForContext<NetworkInfo>().ForContext("Component", poolConfig.Coin.Name); DetectProofOfStakeCoin(); // detect if we are running on a proof-of-stake coin. DetectSubmitBlockSupport(); // detect if the coin daemon supports submitblock call. Recache(); // recache the data initially. PrintNetworkInfo(); // print the collected network info. }
public IPaymentProcessor GetPaymentProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient, IStorage storage, IBlockProcessor blockProcessor) { var @params = new NamedParameterOverloads { { "poolConfig", poolConfig }, { "daemonClient", daemonClient }, { "storage", storage }, { "blockProcessor", blockProcessor }, }; return(_applicationContext.Container.Resolve <IPaymentProcessor>(@params)); }
/// <summary> /// Gets the specified daemon client. /// </summary> /// <param name="daemonClient">The daemon client.</param> /// <param name="jobTracker"></param> /// <param name="shareManager"></param> /// <param name="minerManager">The miner manager.</param> /// <param name="hashAlgorithm"></param> /// <returns></returns> public IJobManager Get(IDaemonClient daemonClient, IJobTracker jobTracker, IShareManager shareManager, IMinerManager minerManager, IHashAlgorithm hashAlgorithm) { var @params = new NamedParameterOverloads { {"daemonClient", daemonClient}, {"jobTracker", jobTracker}, {"shareManager", shareManager}, {"minerManager", minerManager}, {"hashAlgorithm", hashAlgorithm} }; return _applicationContext.Container.Resolve<IJobManager>(@params); }
/// <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. 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); }
private Timer _blockPollerTimer; // timer for polling new blocks. public JobManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJobTracker jobTracker, IShareManager shareManager, IMinerManager minerManager, IHashAlgorithm hashAlgorithm) { _daemonClient = daemonClient; _jobTracker = jobTracker; _shareManager = shareManager; _minerManager = minerManager; _hashAlgorithm = hashAlgorithm; _poolConfig = poolConfig; _jobCounter = new JobCounter(); // todo make this ioc based too. _logger = Log.ForContext <JobManager>().ForContext("Component", poolConfig.Coin.Name); }
/// <summary> /// Initialize mock objects. /// </summary> public PoolTests() { // factory mockup. _objectFactory = Substitute.For<IObjectFactory>(); // pool-config mockup. _config = Substitute.For<IPoolConfig>(); _config.Daemon.Valid.Returns(true); // daemon client mockup. _daemonClient = _objectFactory.GetDaemonClient(_config.Coin.Name, _config.Daemon); _daemonClient.GetInfo().Returns(new Info()); _daemonClient.GetMiningInfo().Returns(new MiningInfo()); }
private Timer _reBroadcastTimer; // timer for rebroadcasting jobs after an pre-configured idle perioud. #endregion Fields #region Constructors public JobManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJobTracker jobTracker, IShareManager shareManager, IMinerManager minerManager, IHashAlgorithm hashAlgorithm) { _daemonClient = daemonClient; _jobTracker = jobTracker; _shareManager = shareManager; _minerManager = minerManager; _hashAlgorithm = hashAlgorithm; _poolConfig = poolConfig; _jobCounter = new JobCounter(); // todo make this ioc based too. _logger = Log.ForContext<JobManager>().ForContext("Component", poolConfig.Coin.Name); }
public IPerPool GetPerPoolStats(IPoolConfig poolConfig, IDaemonClient daemonClient, IMinerManager minerManager, IHashAlgorithm hashAlgorithm, IBlocksCount blockStatistics, IStorage storage) { var @params = new NamedParameterOverloads { { "poolConfig", poolConfig }, { "daemonClient", daemonClient }, { "minerManager", minerManager }, { "hashAlgorithm", hashAlgorithm }, { "blockStatistics", blockStatistics }, { "storage", storage }, }; return(_applicationContext.Container.Resolve <IPerPool>(@params)); }
public PerPool(IPoolConfig poolConfig, IConfigManager configManager, IDaemonClient daemonClient, IMinerManager minerManager, IHashAlgorithm hashAlgorithm, IBlocksCount blockStatistics, IStorage storage) { Config = poolConfig; _statisticsConfig = configManager.WebServerConfig.Statistics; _daemonClient = daemonClient; _minerManager = minerManager; _storage = storage; Blocks = blockStatistics; Workers = new Dictionary <string, double>(); _response = new ExpandoObject(); _shareMultiplier = Math.Pow(2, 32) / hashAlgorithm.Multiplier; }
private void InitDaemon() { if (Config.Daemon == null || Config.Daemon.Valid == false) { _logger.Error("Coin daemon configuration is not valid!"); return; } _daemonClient = _objectFactory.GetDaemonClient(Config); HashAlgorithm = _objectFactory.GetHashAlgorithm(Config.Coin.Algorithm); NetworkInfo = _objectFactory.GetNetworkInfo(_daemonClient, HashAlgorithm, Config); _shareMultiplier = Math.Pow(2, 32) / HashAlgorithm.Multiplier; // will be used in hashrate calculation. }
/// <summary> /// Initialize mock objects. /// </summary> public PoolTests() { // factory mockup. _objectFactory = Substitute.For <IObjectFactory>(); // pool-config mockup. _config = Substitute.For <IPoolConfig>(); _config.Daemon.Valid.Returns(true); // daemon client mockup. _daemonClient = _objectFactory.GetDaemonClient(_config); _daemonClient.GetInfo().Returns(new Info()); _daemonClient.GetMiningInfo().Returns(new MiningInfo()); }
public IJobManager GetJobManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJobTracker jobTracker, IShareManager shareManager, IMinerManager minerManager, IHashAlgorithm hashAlgorithm) { var @params = new NamedParameterOverloads { { "poolConfig", poolConfig }, { "daemonClient", daemonClient }, { "jobTracker", jobTracker }, { "shareManager", shareManager }, { "minerManager", minerManager }, { "hashAlgorithm", hashAlgorithm }, }; return(_applicationContext.Container.Resolve <IJobManager>(@params)); }
private void InitDaemon() { if (Config.Daemon == null || Config.Daemon.Valid == false) { _logger.Error("Coin daemon configuration is not valid!"); return; } _daemonClient = _objectFactory.GetDaemonClient(Config); _hashAlgorithm = _objectFactory.GetHashAlgorithm(Config.Coin.Algorithm); try { var info = _daemonClient.GetInfo(); _logger.Information("Coin symbol: {0:l} algorithm: {1:l} " + "Coin version: {2} protocol: {3} wallet: {4} " + "Daemon network: {5:l} peers: {6} blocks: {7} errors: {8:l} ", Config.Coin.Symbol, Config.Coin.Algorithm, info.Version, info.ProtocolVersion, info.WalletVersion, info.Testnet ? "testnet" : "mainnet", info.Connections, info.Blocks, string.IsNullOrEmpty(info.Errors) ? "none" : info.Errors); } catch (RpcException e) { _logger.Error("Can not read getinfo(): {0:l}", e.Message); return; } try { // try reading mininginfo(), some coins may not support it. var miningInfo = _daemonClient.GetMiningInfo(); _logger.Information("Network difficulty: {0:0.00000000} block difficulty: {1:0.00} Network hashrate: {2:l} ", miningInfo.Difficulty, miningInfo.Difficulty * _hashAlgorithm.Multiplier, miningInfo.NetworkHashps.GetReadableHashrate()); } catch (RpcException e) { _logger.Error("Can not read mininginfo() - the coin may not support the request: {0:l}", e.Message); } }
public JobManager(string pool, IDaemonClient daemonClient, IJobTracker jobTracker, IShareManager shareManager, IMinerManager minerManager, IHashAlgorithm hashAlgorithm, IWalletConfig walletConfig, IRewardsConfig rewardsConfig) { _daemonClient = daemonClient; _jobTracker = jobTracker; _shareManager = shareManager; _minerManager = minerManager; _hashAlgorithm = hashAlgorithm; _walletConfig = walletConfig; _rewardsConfig = rewardsConfig; _jobCounter = new JobCounter(); // todo make this ioc based too. _logger = Log.ForContext<JobManager>().ForContext("Component", pool); }
public PaymentProcessor(IPoolConfig poolConfig, IStorageLayer storageLayer, IDaemonClient daemonClient, IAccountManager accountManager) { _poolConfig = poolConfig; _storageLayer = storageLayer; _daemonClient = daemonClient; _accountManager = accountManager; _logger = Log.ForContext<PaymentProcessor>().ForContext("Component", poolConfig.Coin.Name); if (!_poolConfig.Payments.Enabled) // make sure payments are enabled. return; if (!ValidatePoolAddress()) // try to validate the pool wallet. return; // if we can't, stop the payment processor. if (!GetPoolAccount()) // get the pool's account name if any. return; // if we can't, stop the payment processor. Active = true; }
public HybridStorage(IEnumerable<IStorageProvider> providers, IDaemonClient daemonClient, IPoolConfig poolConfig) { _daemonClient = daemonClient; _logger = Log.ForContext<HybridStorage>().ForContext("Component", poolConfig.Coin.Name); _coin = poolConfig.Coin.Name.ToLower(); // pool's associated coin name. // try loading providers. try { foreach (var provider in providers) { if (provider is IRedisProvider) _redisProvider = (IRedisProvider)provider; else if (provider is IMySqlProvider) _mySqlProvider = (IMySqlProvider)provider; } IsEnabled = (_redisProvider != null && _mySqlProvider != null); } catch (Exception e) { _logger.Error("Error initializing hybrid storage; {0:l}", e.Message); } }
public GenerationTransactionTests() { // daemon client _daemonClient = Substitute.For<IDaemonClient>(); _daemonClient.ValidateAddress(Arg.Any<string>()).Returns(new ValidateAddress { IsValid = true }); // block template const string json = "{\"result\":{\"version\":2,\"previousblockhash\":\"e9bbcc9b46ed98fd4850f2d21e85566defdefad3453460caabc7a635fc5a1261\",\"transactions\":[],\"coinbaseaux\":{\"flags\":\"062f503253482f\"},\"coinbasevalue\":5000000000,\"target\":\"0000004701b20000000000000000000000000000000000000000000000000000\",\"mintime\":1402660580,\"mutable\":[\"time\",\"transactions\",\"prevblock\"],\"noncerange\":\"00000000ffffffff\",\"sigoplimit\":20000,\"sizelimit\":1000000,\"curtime\":1402661060,\"bits\":\"1d4701b2\",\"height\":302526},\"error\":null,\"id\":1}"; var @object = JsonConvert.DeserializeObject<DaemonResponse<BlockTemplate>>(json); _blockTemplate = @object.Result; // extra nonce _extraNonce = new ExtraNonce(0); // signature script _signatureScript = new SignatureScript( _blockTemplate.Height, _blockTemplate.CoinBaseAux.Flags, 1402661059432, (byte)_extraNonce.ExtraNoncePlaceholder.Length, "/nodeStratum/"); // use the same output data within our sample data. _outputs = new Outputs(_daemonClient); double blockReward = 5000000000; // the amount rewarded by the block. // sample recipient const string recipient = "mrwhWEDnU6dUtHZJ2oBswTpEdbBHgYiMji"; var amount = blockReward * 0.01; blockReward -= amount; _outputs.AddRecipient(recipient, amount); // sample pool wallet const string poolWallet = "mk8JqN1kNWju8o3DXEijiJyn7iqkwktAWq"; _outputs.AddPool(poolWallet, blockReward); }
/// <summary> /// Initializes a new instance of the <see cref="Pool" /> class. /// </summary> /// <param name="hashAlgorithmFactory">The hash algorithm factory.</param> /// <param name="serverFactory">The server factory.</param> /// <param name="serviceFactory">The service factory.</param> /// <param name="client">The client.</param> /// <param name="minerManagerFactory">The miner manager factory.</param> /// <param name="jobTrackerFactory"></param> /// <param name="jobManagerFactory">The job manager factory.</param> /// <param name="shareManagerFactory">The share manager factory.</param> /// <param name="storageManagerFactory"></param> /// <param name="globalConfigFactory"></param> public Pool( IHashAlgorithmFactory hashAlgorithmFactory, IServerFactory serverFactory, IServiceFactory serviceFactory, IDaemonClient client, IMinerManagerFactory minerManagerFactory, IJobTrackerFactory jobTrackerFactory, IJobManagerFactory jobManagerFactory, IShareManagerFactory shareManagerFactory, IStorageFactory storageManagerFactory, IGlobalConfigFactory globalConfigFactory) { Enforce.ArgumentNotNull(hashAlgorithmFactory, "IHashAlgorithmFactory"); Enforce.ArgumentNotNull(serverFactory, "IServerFactory"); Enforce.ArgumentNotNull(serviceFactory, "IServiceFactory"); Enforce.ArgumentNotNull(client, "IDaemonClient"); Enforce.ArgumentNotNull(minerManagerFactory, "IMinerManagerFactory"); Enforce.ArgumentNotNull(jobTrackerFactory, "IJobTrackerFactory"); Enforce.ArgumentNotNull(jobManagerFactory, "IJobManagerFactory"); Enforce.ArgumentNotNull(shareManagerFactory, "IShareManagerFactory"); Enforce.ArgumentNotNull(storageManagerFactory, "IStorageFactory"); Enforce.ArgumentNotNull(globalConfigFactory, "IGlobalConfigFactory"); _daemonClient = client; _minerManagerFactory = minerManagerFactory; _jobManagerFactory = jobManagerFactory; _jobTrackerFactory = jobTrackerFactory; _shareManagerFactory = shareManagerFactory; _serverFactory = serverFactory; _serviceFactory = serviceFactory; _hashAlgorithmFactory = hashAlgorithmFactory; _storageManagerFactory = storageManagerFactory; _globalConfigFactory = globalConfigFactory; GenerateInstanceId(); }
/// <summary> /// Initializes a new instance of the <see cref="ShareManager" /> class. /// </summary> /// <param name="daemonClient"></param> /// <param name="jobTracker"></param> /// <param name="storage"></param> public ShareManager(IDaemonClient daemonClient, IJobTracker jobTracker, IStorage storage) { _daemonClient = daemonClient; _jobTracker = jobTracker; _storage = storage; }
public IStorageLayer GetStorageLayer(string type, IEnumerable<IStorageProvider> providers, IDaemonClient daemonClient, IPoolConfig poolConfig) { var @params = new NamedParameterOverloads { {"providers", providers}, {"daemonClient", daemonClient}, {"poolConfig", poolConfig} }; return type != StorageLayers.Empty ? _applicationContext.Container.Resolve<IStorageLayer>(type, @params) : _applicationContext.Container.Resolve<IStorageLayer>(type); }
public SerializerTests() { // daemon client _daemonClient = Substitute.For<IDaemonClient>(); _daemonClient.ValidateAddress(Arg.Any<string>()).Returns(new ValidateAddress { IsValid = true }); // block template const string json = "{\"result\":{\"version\":2,\"previousblockhash\":\"1c4eb88e47564cb796b5c6648c74bec51d7215ac12fc4168b14827aac74a8062\",\"transactions\":[{\"data\":\"010000000332a82e92f522deee69b09e27858ba9b87585f2a4913ef71018df40909032fdc3000000006a473044022019ca05cb880a04f0d842268b7e75ac6d2695fc544df033e3daeb29239251a8970220031f6336767f2ea617347484e1290ec0bdcc71056ea2d3084e75384905250ec50121030dd394118fb66ca288bff71d8ea762678783b005770f7f9ba4128233191e0847ffffffff086747cbd339b21b950774186091653a7b8f5751b00a906ff6f5561b3a6fcee6010000006b4830450221009ae1ba9a216d313cc592fc2c1ef08f1e0e555a32b6c1b305f685ac882d38356b0220243106bbb5bb76dde142e574cba8f30c1e2f7059e8e9161770396fbd2b50420f0121030dd394118fb66ca288bff71d8ea762678783b005770f7f9ba4128233191e0847ffffffffe2f15804b1e41c36c925c6f64f219b2bdb3c9fbff4c97a4f0e8c7f31d7e6f2af000000006b48304502200be8894fdd7f5c19be248a979c08bbf2395f606e038c3e02c0266474c03699ab022100ff5de87086e487410f5d7b68012655ca6d814f0caeb9ca42d9c425a90f68b3030121030dd394118fb66ca288bff71d8ea762678783b005770f7f9ba4128233191e0847ffffffff02a0f01900000000001976a9141c50209a1dfdf53313d237b75e9aeb553ca1dfda88ac00e1f505000000001976a914cbb9a3e7a7c1651b1006f876f08b40be85b274f588ac00000000\",\"hash\":\"dc3a80ec6c45aa489453b2c4abf6761eb6656d949e26d01793458c166640e5f3\",\"depends\":[],\"fee\":0,\"sigops\":2}],\"coinbaseaux\":{\"flags\":\"062f503253482f\"},\"coinbasevalue\":5000000000,\"target\":\"00000048d4f70000000000000000000000000000000000000000000000000000\",\"mintime\":1403691059,\"mutable\":[\"time\",\"transactions\",\"prevblock\"],\"noncerange\":\"00000000ffffffff\",\"sigoplimit\":20000,\"sizelimit\":1000000,\"curtime\":1403691825,\"bits\":\"1d48d4f7\",\"height\":315152},\"error\":null,\"id\":1}"; var @object = JsonConvert.DeserializeObject<DaemonResponse<BlockTemplate>>(json); _blockTemplate = @object.Result; // extra nonce _extraNonce = Substitute.For<ExtraNonce>((UInt32)0); // signature script _signatureScript = Substitute.For<SignatureScript>( _blockTemplate.Height, _blockTemplate.CoinBaseAux.Flags, 1403691824760, (byte)_extraNonce.ExtraNoncePlaceholder.Length, "/nodeStratum/"); // outputs _outputs = Substitute.For<Outputs>(_daemonClient); double blockReward = 5000000000; // the amount rewarded by the block. // sample reward recipient var rewardsConfig = Substitute.For<IRewardsConfig>(); var amount = blockReward * 0.01; blockReward -= amount; var rewards = new Dictionary<string, float> { { "mrwhWEDnU6dUtHZJ2oBswTpEdbBHgYiMji", (float)amount } }; rewardsConfig.GetEnumerator().Returns(rewards.GetEnumerator()); foreach (var pair in rewards) { _outputs.AddRecipient(pair.Key, pair.Value); } // sample pool wallet var walletConfig = Substitute.For<IWalletConfig>(); walletConfig.Adress.Returns("mk8JqN1kNWju8o3DXEijiJyn7iqkwktAWq"); _outputs.AddPoolWallet(walletConfig.Adress, blockReward); // generation transaction. _generationTransaction = Substitute.For<GenerationTransaction>(_extraNonce, _daemonClient, _blockTemplate, walletConfig, rewardsConfig, false); _generationTransaction.Inputs.First().SignatureScript = _signatureScript; _generationTransaction.Outputs = _outputs; _generationTransaction.Create(); // job counter _jobCounter = Substitute.For<IJobCounter>(); _jobCounter.Next().Returns((UInt64)2); // hash algorithm _hashAlgorithm = Substitute.For<IHashAlgorithm>(); // create the job _job = Substitute.For<Job>(_jobCounter.Next(), _hashAlgorithm, _blockTemplate, _generationTransaction); }
public OutputsTests() { _daemonClient = Substitute.For<IDaemonClient>(); _daemonClient.ValidateAddress(Arg.Any<string>()).Returns(new ValidateAddress { IsValid = true }); }
public IPaymentProcessor GetPaymentProcessor(IPoolConfig poolConfig, IStorageLayer storageLayer, IDaemonClient daemonClient, IAccountManager accountManager) { var @params = new NamedParameterOverloads { {"poolConfig", poolConfig}, {"storageLayer", storageLayer}, {"daemonClient", daemonClient}, {"accountManager", accountManager}, }; return _applicationContext.Container.Resolve<IPaymentProcessor>(@params); }
public IShareManager GetShareManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJobTracker jobTracker, IStorageLayer storageLayer) { var @params = new NamedParameterOverloads { {"poolConfig", poolConfig}, {"daemonClient", daemonClient}, {"jobTracker", jobTracker}, {"storageLayer", storageLayer} }; return _applicationContext.Container.Resolve<IShareManager>(@params); }
public JobTests() { // daemon client _daemonClient = Substitute.For<IDaemonClient>(); _daemonClient.ValidateAddress(Arg.Any<string>()).Returns(new ValidateAddress { IsValid = true }); // block template const string json = "{\"result\":{\"version\":2,\"previousblockhash\":\"22a9174d9db64f1919febc9577167764c301b755768b675291f7d34454561e9e\",\"transactions\":[],\"coinbaseaux\":{\"flags\":\"062f503253482f\"},\"coinbasevalue\":5000000000,\"target\":\"0000002bd7c30000000000000000000000000000000000000000000000000000\",\"mintime\":1402922277,\"mutable\":[\"time\",\"transactions\",\"prevblock\"],\"noncerange\":\"00000000ffffffff\",\"sigoplimit\":20000,\"sizelimit\":1000000,\"curtime\":1402922598,\"bits\":\"1d2bd7c3\",\"height\":305349},\"error\":null,\"id\":1}"; var @object = JsonConvert.DeserializeObject<DaemonResponse<BlockTemplate>>(json); _blockTemplate = @object.Result; // extra nonce _extraNonce = new ExtraNonce(0); // signature script _signatureScript = new SignatureScript( _blockTemplate.Height, _blockTemplate.CoinBaseAux.Flags, 1402922597281, (byte) _extraNonce.ExtraNoncePlaceholder.Length, "/nodeStratum/"); // pool config _poolConfig = Substitute.For<IPoolConfig>(); // create coin config. var coinConfig = Substitute.For<ICoinConfig>(); coinConfig.Options.TxMessageSupported.Returns(false); coinConfig.Options.IsProofOfStakeHybrid.Returns(false); _poolConfig.Coin.Returns(coinConfig); // outputs _outputs = Substitute.For<Outputs>(_daemonClient, coinConfig); double blockReward = 5000000000; // the amount rewarded by the block. // create rewards config. var rewardsConfig = Substitute.For<IRewardsConfig>(); _poolConfig.Rewards.Returns(rewardsConfig); // create sample reward var amount = blockReward * 0.01; blockReward -= amount; var rewards = new Dictionary<string, float> { {"mrwhWEDnU6dUtHZJ2oBswTpEdbBHgYiMji", (float) amount} }; rewardsConfig.GetEnumerator().Returns(rewards.GetEnumerator()); foreach (var pair in rewards) { _outputs.AddRecipient(pair.Key, pair.Value); } // create wallet config. var walletConfig = Substitute.For<IWalletConfig>(); _poolConfig.Wallet.Returns(walletConfig); // create sample pool central wallet output. walletConfig.Adress.Returns("mk8JqN1kNWju8o3DXEijiJyn7iqkwktAWq"); _outputs.AddPoolWallet(walletConfig.Adress, blockReward); // job counter _jobCounter = Substitute.For<JobCounter>(); // generation transaction. _generationTransaction = new GenerationTransaction(_extraNonce, _daemonClient, _blockTemplate, _poolConfig); _generationTransaction.Inputs.First().SignatureScript = _signatureScript; _generationTransaction.Outputs = _outputs; _generationTransaction.Create(); // hash algorithm _hashAlgorithm = new Scrypt(); }