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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Eliminate BlockrewardMultiplier and read actual block-reward from coinbase-tx * Log bitcoin family shares with actual stratum diff * sslstream disposing was still not 100% ensured * PAC coin support * Config overridable coinbase tx comments * Improved Http connection pooling * Publish Hashrate updated notification on WebSocket * More block notification properties * camelcase enum serialization * Fix <code>sendmany</code> RPC rounding problems with Bitcoin Core 0.17 * Dash v13 support * Enhance pool/blocks API with block state parameter support * x22i hash support * Payee support * Ban on SSL handshake error
- Loading branch information
Oliver Weichhold
authored
Nov 23, 2018
1 parent
ea5ddee
commit 21356c8
Showing
62 changed files
with
4,368 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
*.user | ||
*.sln.docstates | ||
.vs/ | ||
.vscode/ | ||
|
||
[Dd]ebug/ | ||
[Rr]elease/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using Autofac; | ||
using AutoMapper; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Miningcore.Api.Extensions; | ||
using Miningcore.Api.Responses; | ||
using Miningcore.Blockchain; | ||
using Miningcore.Configuration; | ||
using Miningcore.Extensions; | ||
using Miningcore.Mining; | ||
using Miningcore.Persistence; | ||
using Miningcore.Persistence.Model; | ||
using Miningcore.Persistence.Model.Projections; | ||
using Miningcore.Persistence.Repositories; | ||
using Miningcore.Time; | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
|
||
namespace Miningcore.Api.Controllers | ||
{ | ||
[Route("api")] | ||
[ApiController] | ||
public class ClusterApiController : ControllerBase | ||
{ | ||
public ClusterApiController(IComponentContext ctx) | ||
{ | ||
clusterConfig = ctx.Resolve<ClusterConfig>(); | ||
cf = ctx.Resolve<IConnectionFactory>(); | ||
statsRepo = ctx.Resolve<IStatsRepository>(); | ||
blocksRepo = ctx.Resolve<IBlockRepository>(); | ||
paymentsRepo = ctx.Resolve<IPaymentRepository>(); | ||
mapper = ctx.Resolve<IMapper>(); | ||
clock = ctx.Resolve<IMasterClock>(); | ||
pools = ctx.Resolve<ConcurrentDictionary<string, IMiningPool>>(); | ||
enabledPools = new HashSet<string>(clusterConfig.Pools.Where(x => x.Enabled).Select(x => x.Id)); | ||
} | ||
|
||
private readonly ClusterConfig clusterConfig; | ||
private readonly IConnectionFactory cf; | ||
private readonly IStatsRepository statsRepo; | ||
private readonly IBlockRepository blocksRepo; | ||
private readonly IPaymentRepository paymentsRepo; | ||
private readonly IMapper mapper; | ||
private readonly IMasterClock clock; | ||
private readonly ConcurrentDictionary<string, IMiningPool> pools; | ||
private readonly HashSet<string> enabledPools; | ||
|
||
#region Actions | ||
|
||
[HttpGet("blocks")] | ||
public async Task<Responses.Block[]> PageBlocksPagedAsync( | ||
[FromQuery] int page, [FromQuery] int pageSize, [FromQuery] BlockStatus[] state) | ||
{ | ||
var blockStates = state != null && state.Length > 0 ? | ||
state : | ||
new[] { BlockStatus.Confirmed, BlockStatus.Pending, BlockStatus.Orphaned }; | ||
|
||
var blocks = (await cf.Run(con => blocksRepo.PageBlocksAsync(con, blockStates, page, pageSize))) | ||
.Select(mapper.Map<Responses.Block>) | ||
.Where(x=> enabledPools.Contains(x.PoolId)) | ||
.ToArray(); | ||
|
||
// enrich blocks | ||
var blocksByPool = blocks.GroupBy(x => x.PoolId); | ||
|
||
foreach (var poolBlocks in blocksByPool) | ||
{ | ||
var pool = GetPoolNoThrow(poolBlocks.Key); | ||
|
||
if (pool == null) | ||
continue; | ||
|
||
var blockInfobaseDict = pool.Template.ExplorerBlockLinks; | ||
|
||
// compute infoLink | ||
if (blockInfobaseDict != null) | ||
{ | ||
foreach (var block in poolBlocks) | ||
{ | ||
blockInfobaseDict.TryGetValue(!string.IsNullOrEmpty(block.Type) ? block.Type : "block", out var blockInfobaseUrl); | ||
|
||
if (!string.IsNullOrEmpty(blockInfobaseUrl)) | ||
{ | ||
if (blockInfobaseUrl.Contains(CoinMetaData.BlockHeightPH)) | ||
block.InfoLink = blockInfobaseUrl.Replace(CoinMetaData.BlockHeightPH, block.BlockHeight.ToString(CultureInfo.InvariantCulture)); | ||
else if (blockInfobaseUrl.Contains(CoinMetaData.BlockHashPH) && !string.IsNullOrEmpty(block.Hash)) | ||
block.InfoLink = blockInfobaseUrl.Replace(CoinMetaData.BlockHashPH, block.Hash); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return blocks; | ||
} | ||
|
||
#endregion // Actions | ||
|
||
private PoolConfig GetPoolNoThrow(string poolId) | ||
{ | ||
if (string.IsNullOrEmpty(poolId)) | ||
return null; | ||
|
||
var pool = clusterConfig.Pools.FirstOrDefault(x => x.Id == poolId && x.Enabled); | ||
return pool; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.