public void UpdateBlock(IPersistedBlock block) { try { if (!IsEnabled) { return; } using (var connection = new MySqlConnection(_mySqlProvider.ConnectionString)) { connection.Execute( @"UPDATE Block SET Orphaned = @orphaned, Confirmed = @confirmed, Accounted = @accounted, Reward = @reward WHERE Height = @height", new { orphaned = block.Status == BlockStatus.Orphaned, confirmed = block.Status == BlockStatus.Confirmed, accounted = block.Accounted, reward = block.Reward, height = block.Height }); } } catch (Exception e) { _logger.Error("An exception occured while updating block; {0:l}", e.Message); } }
public void UpdateBlock(IPersistedBlock block) { try { if (!IsEnabled) return; using (var connection = new MySqlConnection(_mySqlProvider.ConnectionString)) { connection.Execute( @"UPDATE Block SET Orphaned = @orphaned, Confirmed = @confirmed, Accounted = @accounted, Reward = @reward WHERE Height = @height", new { orphaned = block.Status == BlockStatus.Orphaned, confirmed = block.Status == BlockStatus.Confirmed, accounted = block.Accounted, reward = block.Reward, height = block.Height }); } } catch (Exception e) { _logger.Error("An exception occured while updating block; {0:l}", e.Message); } }
public Payment(IPersistedBlock block, int accountId, decimal amount) { BlockId = (int)block.Height; AccountId = accountId; Amount = amount; Completed = false; }
public PaymentRound(IPersistedBlock block, IRewardsConfig rewardsConfig) { Block = block; RewardsConfig = rewardsConfig; Payouts = new Dictionary <string, decimal>(); Shares = new Dictionary <string, double>(); }
public Payment(IPersistedBlock block, int accountId, decimal amount) { BlockId = (int)block.Height; AccountId = accountId; Amount = amount; Completed = false; }
public void MoveOrphanedShares(IPersistedBlock block) { try { if (!IsEnabled || !_redisProvider.IsConnected) { return; } if (block.Status == BlockStatus.Confirmed || block.Status == BlockStatus.Pending) { return; } var round = string.Format("{0}:shares:round:{1}", _coin, block.Height); // rounds shares key. var current = string.Format("{0}:shares:round:current", _coin); // current round key. //_client.StartPipeTransaction(); // batch the commands as atomic. // add shares to current round again. foreach (var entry in _redisProvider.Client.HGetAll(round)) { _redisProvider.Client.HIncrByFloat(current, entry.Key, double.Parse(entry.Value, CultureInfo.InvariantCulture)); } _redisProvider.Client.Del(round); // delete the round shares. //_client.EndPipe(); // execute the batch commands. } catch (Exception e) { _logger.Error("An exception occurred while moving shares: {0:l}", e.Message); } }
public Dictionary <string, double> GetShares(IPersistedBlock block) { var shares = new Dictionary <string, double>(); try { if (!IsEnabled || !_redisProvider.IsConnected) { return(shares); } var key = string.Format("{0}:shares:round:{1}", _coin, block.Height); var hashes = _redisProvider.Client.HGetAll(key); foreach (var hash in hashes) { shares.Add(hash.Key, double.Parse(hash.Value, CultureInfo.InvariantCulture)); } } catch (Exception e) { _logger.Error("An exception occurred while getting shares for round; {0:l}", e.Message); } return(shares); }
private void QueryBlock(ref IPersistedBlock block) { var blockInfo = _blockProcessor.GetBlock(block.BlockHash); // query the block. if (blockInfo == null || blockInfo.Confirmations == -1) // make sure the block exists and is accepted. { block.Status = BlockStatus.Orphaned; return; } // calculate our expected generation transactions's hash var expectedTxHash = block.TransactionHash; // expected transaction hash var genTxHash = blockInfo.Tx.First(); // read the hash of very first (generation transaction) of the block // make sure our calculated and reported generation tx hashes match. if (expectedTxHash != genTxHash) { block.Status = BlockStatus.Orphaned; return; } var genTx = _blockProcessor.GetGenerationTransaction(blockInfo); // get the generation transaction. // get the output transaction that targets pools central wallet. var poolOutput = _blockProcessor.GetPoolOutput(genTx); // make sure we have a valid reference to poolOutput if (poolOutput == null) { block.Status = BlockStatus.Orphaned; return; } block.SetReward((decimal)poolOutput.Amount); // set the reward of the block to miners. switch (poolOutput.Category) { case "immature": block.Status = BlockStatus.Pending; break; case "orphan": block.Status = BlockStatus.Orphaned; break; case "generate": block.Status = BlockStatus.Confirmed; break; } // TODO: add back these. // total amount of coins contained in the block. // candidate.Amount = transaction.Details.Sum(output => (decimal)output.Amount); // candidate.Reward = (decimal) poolOutput.Amount; }
public PaymentRound(IPersistedBlock block, IStorageLayer storageLayer, IAccountManager accountManager) { Block = block; _storageLayer = storageLayer; _accountManager = accountManager; Payments = new List <IPayment>(); _shares = _storageLayer.GetShares(Block); // load the shares for the round. CalculatePayments(); // calculate the per-user payments. }
public PaymentRound(IPersistedBlock block, IStorageLayer storageLayer, IAccountManager accountManager) { Block = block; _storageLayer = storageLayer; _accountManager = accountManager; Payments = new List<IPayment>(); _shares = _storageLayer.GetShares(Block); // load the shares for the round. CalculatePayments(); // calculate the per-user payments. }
public IPaymentRound GetPaymentRound(IPersistedBlock block, IStorageLayer storageLayer, IAccountManager accountManager) { var @params = new NamedParameterOverloads { { "block", block }, { "storageLayer", storageLayer }, { "accountManager", accountManager } }; return(_applicationContext.Container.Resolve <IPaymentRound>(@params)); }
private Block GetBlockInfo(IPersistedBlock block) { try { return(_daemonClient.GetBlock(block.BlockHash)); // query the block. } catch (RpcTimeoutException e) { _logger.Error(e, "RpcTimeoutException while getting block from daemon"); // on rpc-timeout exception, let block stay in pending status so we can query it again later. block.Status = BlockStatus.Pending; return(null); } catch (RpcConnectionException e) { _logger.Error(e, "RpcConnectionException while getting block from daemon"); // on rpc-connection exception, let block stay in pending status so we can query it again later. block.Status = BlockStatus.Pending; return(null); } catch (RpcErrorException e) { _logger.Error(e, "RpcErrorException while getting block from daemon"); // block not found if (e.Code == (int)RpcErrorCode.RPC_INVALID_ADDRESS_OR_KEY) { block.Status = BlockStatus.Orphaned; // orphan the block if block does not exist. } // if we got an error that we do not handle else { block.Status = BlockStatus.Pending; // let the block in pending status so we can query it again later. _logger.Error("Unhandled rpc-error: {0:l}", e.Message); } return(null); } catch (RpcException e) { block.Status = BlockStatus.Pending; // and let block stay in pending status so we can query it again later. _logger.Error("Unhandled rpc-exception: {0:l}", e.Message); return(null); } }
private Transaction GetGenerationTx(IPersistedBlock block) { try { return(_daemonClient.GetTransaction(block.TransactionHash)); // query the transaction } catch (RpcTimeoutException e) { _logger.Error(e, "RpcTimeoutException while GetGenerationTx"); // on rpc-timeout exception, let block stay in pending status so we can query it again later. block.Status = BlockStatus.Pending; return(null); } catch (RpcConnectionException e) { _logger.Error(e, "RpcConnectionException while GetGenerationTx"); // on rpc-connection exception, let block stay in pending status so we can query it again later. block.Status = BlockStatus.Pending; return(null); } catch (RpcErrorException e) { _logger.Error(e, "RpcErrorException while GetGenerationTx"); // Invalid or non-wallet transaction id if (e.Code == (int)RpcErrorCode.RPC_INVALID_ADDRESS_OR_KEY) { block.Status = BlockStatus.Orphaned; // orphan the block if block does not exist. } // if we got an error that we do not handle else { block.Status = BlockStatus.Pending; // let the block in pending status so we can query it again later. _logger.Error("Unhandled rpc-error: {0:l}", e.Message); } return(null); } catch (RpcException e) { block.Status = BlockStatus.Pending; // and let block stay in pending status so we can query it again later. _logger.Error("Unhandled rpc-exception: {0:l}", e.Message); return(null); } }
public void MoveOrphanedShares(IPersistedBlock block) { return; }
public void MoveOrphanedShares(IPersistedBlock block) { // this function is not supported as this functionality is handled by mpos itself. throw new NotSupportedException(); }
public Dictionary <string, double> GetShares(IPersistedBlock block) { // this function is not supported as this functionality is only required by payment processors which mpos itself is already one so and handles itself. throw new NotSupportedException(); }
private void QueryBlock(IPersistedBlock block) { var blockInfo = GetBlockInfo(block); // query the block. if (blockInfo == null) // make sure we got a valid blockInfo response before continuing on return; // in case we have a null, status will be already decided by GetBlockInfo() function. if (blockInfo.Confirmations == -1) // check if block is orphaned already. { block.Status = BlockStatus.Orphaned; return; } // calculate our expected generation transactions's hash var expectedTxHash = block.TransactionHash; // expected transaction hash var genTxHash = blockInfo.Tx.First(); // read the hash of very first (generation transaction) of the block // make sure our calculated and reported generation tx hashes match. if (expectedTxHash != genTxHash) { block.Status = BlockStatus.Orphaned; return; } // get the generation transaction. var genTx = GetGenerationTx(block); if (genTx == null) // make sure we were able to read the generation transaction return; // in case we have a null, status will be already decided by GetGenerationTx() function. // get the output transaction that targets pools central wallet. var poolOutput = genTx.GetPoolOutput(_poolConfig.Wallet.Adress, _poolAccount); // make sure we have a valid reference to poolOutput if (poolOutput == null) { block.Status = BlockStatus.Orphaned; return; } // set the reward of the block to miners. block.Reward = (decimal) poolOutput.Amount; // find the block status switch (poolOutput.Category) { case "immature": block.Status = BlockStatus.Pending; break; case "orphan": block.Status = BlockStatus.Orphaned; break; case "generate": block.Status = BlockStatus.Confirmed; break; } }
public void UpdateBlock(IPersistedBlock block) { return; }
private void QueryBlock(IPersistedBlock block) { var blockInfo = GetBlockInfo(block); // query the block. if (blockInfo == null) // make sure we got a valid blockInfo response before continuing on { return; // in case we have a null, status will be already decided by GetBlockInfo() function. } if (blockInfo.Confirmations == -1) // check if block is orphaned already. { block.Status = BlockStatus.Orphaned; return; } // calculate our expected generation transactions's hash var expectedTxHash = block.TransactionHash; // expected transaction hash var genTxHash = blockInfo.Tx.First(); // read the hash of very first (generation transaction) of the block // make sure our calculated and reported generation tx hashes match. if (expectedTxHash != genTxHash) { block.Status = BlockStatus.Orphaned; return; } // get the generation transaction. var genTx = GetGenerationTx(block); if (genTx == null) // make sure we were able to read the generation transaction { return; // in case we have a null, status will be already decided by GetGenerationTx() function. } // get the output transaction that targets pools central wallet. var poolOutput = genTx.GetPoolOutput(_poolConfig.Wallet.Address, _poolAccount); // make sure we have a valid reference to poolOutput if (poolOutput == null) { block.Status = BlockStatus.Orphaned; return; } // set the reward of the block to miners. block.Reward = (decimal)poolOutput.Amount; // find the block status switch (poolOutput.Category) { case "immature": block.Status = BlockStatus.Pending; break; case "orphan": block.Status = BlockStatus.Orphaned; break; case "generate": block.Status = BlockStatus.Confirmed; break; } }
public void UpdateBlock(IPersistedBlock block) { // this function is not supported as this functionality is handled by mpos itself. }
public void MoveOrphanedShares(IPersistedBlock block) { try { if (!IsEnabled || !_redisProvider.IsConnected) return; if (block.Status == BlockStatus.Confirmed || block.Status == BlockStatus.Pending) return; var round = string.Format("{0}:shares:round:{1}", _coin, block.Height); // rounds shares key. var current = string.Format("{0}:shares:round:current", _coin); // current round key. //_client.StartPipeTransaction(); // batch the commands as atomic. // add shares to current round again. foreach (var entry in _redisProvider.Client.HGetAll(round)) { _redisProvider.Client.HIncrByFloat(current, entry.Key, double.Parse(entry.Value, CultureInfo.InvariantCulture)); } _redisProvider.Client.Del(round); // delete the round shares. //_client.EndPipe(); // execute the batch commands. } catch (Exception e) { _logger.Error("An exception occured while moving shares: {0:l}", e.Message); } }
public void MoveOrphanedShares(IPersistedBlock block) { // this function is not supported as this functionality is handled by mpos itself. throw new NotSupportedException(); }
public Dictionary<string, double> GetShares(IPersistedBlock block) { // this function is not supported as this functionality is only required by payment processors which mpos itself is already one so and handles itself. throw new NotSupportedException(); }
public void UpdateBlock(IPersistedBlock block) { // this function is not supported as this functionality is handled by mpos itself. }
public void MoveOrphanedShares(IPersistedBlock block) { return; }
public Dictionary<string, double> GetShares(IPersistedBlock block) { return new Dictionary<string, double>(); }
public void UpdateBlock(IPersistedBlock block) { return; }
public IPaymentRound GetPaymentRound(IPersistedBlock block, IStorageLayer storageLayer, IAccountManager accountManager) { var @params = new NamedParameterOverloads { {"block", block}, {"storageLayer", storageLayer}, {"accountManager", accountManager} }; return _applicationContext.Container.Resolve<IPaymentRound>(@params); }
public PaymentRound(IPersistedBlock block) { Block = block; Payouts = new Dictionary <string, decimal>(); Shares = new Dictionary <string, double>(); }
private Transaction GetGenerationTx(IPersistedBlock block) { try { return _daemonClient.GetTransaction(block.TransactionHash); // query the transaction } catch (RpcTimeoutException) { // on rpc-timeout exception, let block stay in pending status so we can query it again later. block.Status = BlockStatus.Pending; return null; } catch (RpcConnectionException) { // on rpc-connection exception, let block stay in pending status so we can query it again later. block.Status = BlockStatus.Pending; return null; } catch (RpcErrorException e) { // Invalid or non-wallet transaction id if (e.Code == (int) RpcErrorCode.RPC_INVALID_ADDRESS_OR_KEY) block.Status = BlockStatus.Orphaned; // orphan the block if block does not exist. // if we got an error that we do not handle else { block.Status = BlockStatus.Pending; // let the block in pending status so we can query it again later. _logger.Error("Unhandled rpc-error: {0:l}", e.Message); } return null; } catch (RpcException e) { block.Status = BlockStatus.Pending; // and let block stay in pending status so we can query it again later. _logger.Error("Unhandled rpc-exception: {0:l}", e.Message); return null; } }
public Dictionary<string, double> GetShares(IPersistedBlock block) { var shares = new Dictionary<string, double>(); try { if (!IsEnabled || !_redisProvider.IsConnected) return shares; var key = string.Format("{0}:shares:round:{1}", _coin, block.Height); var hashes = _redisProvider.Client.HGetAll(key); foreach (var hash in hashes) { shares.Add(hash.Key, double.Parse(hash.Value, CultureInfo.InvariantCulture)); } } catch (Exception e) { _logger.Error("An exception occured while getting shares for round; {0:l}", e.Message); } return shares; }
public Dictionary <string, double> GetShares(IPersistedBlock block) { return(new Dictionary <string, double>()); }