Skip to content

Commit

Permalink
Migrate Blockcore Explorer to Blockcore.NBitcoin
Browse files Browse the repository at this point in the history
- Adds support for referencing chain packages directly.
  • Loading branch information
sondreb committed Apr 20, 2020
1 parent add700c commit 6227c7c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blockcoreindexer",
"version": "0.0.3",
"version": "0.0.4",
"license": "MIT",
"author": {
"name": "Blockcore",
Expand Down
1 change: 1 addition & 0 deletions src/Blockcore.Indexer.Tests/Blockcore.Indexer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blockcore.NBitcoin" Version="1.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
Expand Down
3 changes: 2 additions & 1 deletion src/Blockcore.Indexer/Blockcore.Indexer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blockcore.NBitcoin" Version="1.0.4" />
<PackageReference Include="Blockcore.Networks.Xds" Version="1.0.4" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NStratis" Version="4.0.0.77" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.0.0" />
Expand Down
86 changes: 42 additions & 44 deletions src/Blockcore.Indexer/Operations/Types/SyncConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,40 @@ public NetworkConfig(IndexerSettings config, ChainSettings chainConfig, NetworkS

var consensusFactory = (ConsensusFactory)Activator.CreateInstance(Type.GetType(networkConfig.NetworkConsensusFactoryType));

Consensus = new ConsensusConfig(config, consensusFactory);
Consensus = new NBitcoin.Consensus(
consensusFactory: consensusFactory,
consensusOptions: null,
coinType: 0,
hashGenesisBlock: uint256.Zero,
subsidyHalvingInterval: 0,
majorityEnforceBlockUpgrade: 0,
majorityRejectBlockOutdated: 0,
majorityWindow: 0,
buriedDeployments: null,
bip9Deployments: null,
bip34Hash: uint256.Zero,
minerConfirmationWindow: 0,
maxReorgLength: 0,
defaultAssumeValid: uint256.Zero,
maxMoney: 0,
coinbaseMaturity: 0,
premineHeight: 0,
premineReward: 0,
proofOfWorkReward: 0,
targetTimespan: TimeSpan.Zero,
targetSpacing: TimeSpan.Zero,
powAllowMinDifficultyBlocks: false,
posNoRetargeting: false,
powNoRetargeting: false,
powLimit: new Target(uint256.Zero),
minimumChainWork: null,
isProofOfStake: consensusFactory is PosConsensusFactory,
lastPowBlock: 0,
proofOfStakeLimit: null,
proofOfStakeLimitV2: null,
proofOfStakeReward: 0,
proofOfStakeTimestampMask: 0x0000003F // 64 sec
);

Base58Prefixes = new byte[12][];
Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (networkConfig.NetworkPubkeyAddressPrefix) };
Expand All @@ -35,46 +68,6 @@ public NetworkConfig(IndexerSettings config, ChainSettings chainConfig, NetworkS
}
}

public class ConsensusConfig : Consensus
{
public ConsensusConfig(IndexerSettings config, ConsensusFactory consensusFactory) : base(
consensusFactory: consensusFactory,
consensusOptions: null,
coinType: 0,
hashGenesisBlock: uint256.Zero,
subsidyHalvingInterval: 0,
majorityEnforceBlockUpgrade: 0,
majorityRejectBlockOutdated: 0,
majorityWindow: 0,
buriedDeployments: null,
bip9Deployments: null,
bip34Hash: uint256.Zero,
ruleChangeActivationThreshold: 0,
minerConfirmationWindow: 0,
maxReorgLength: 0,
defaultAssumeValid: uint256.Zero,
maxMoney: 0,
coinbaseMaturity: 0,
premineHeight: 0,
premineReward: 0,
proofOfWorkReward: 0,
powTargetTimespan: TimeSpan.Zero,
powTargetSpacing: TimeSpan.Zero,
powAllowMinDifficultyBlocks: false,
posNoRetargeting: false,
powNoRetargeting: false,
powLimit: new Target(uint256.Zero),
minimumChainWork: null,
isProofOfStake: consensusFactory is PosConsensusFactory,
lastPowBlock: 0,
proofOfStakeLimit: null,
proofOfStakeLimitV2: null,
proofOfStakeReward: 0
)
{
}
}

[Serializable]
public class SyncConnection
{
Expand All @@ -98,9 +91,14 @@ public SyncConnection(IOptions<IndexerSettings> config, IOptions<ChainSettings>
Secure = configuration.RpcSecure;
StartBlockIndex = configuration.StartBlockIndex;

// This can be replaced with a specific the network class of a specific coin
// Or use the config values to simulate the network class.
Network = new NetworkConfig(configuration, chainConfiguration, networkConfiguration);
if (string.IsNullOrWhiteSpace(networkConfiguration.NetworkType))
{
Network = new NetworkConfig(configuration, chainConfiguration, networkConfiguration);
}
else
{
Network = (Network)Activator.CreateInstance(Type.GetType(networkConfiguration.NetworkType));
}

RecentItems = new Buffer<(DateTime Inserted, TimeSpan Duration, long Size)>(5000);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Blockcore.Indexer/Settings/NetworkSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public class NetworkSettings
{
public string NetworkConsensusFactoryType { get; set; }

public string NetworkType { get; set; }

public byte NetworkPubkeyAddressPrefix { get; set; }

public byte NetworkScriptAddressPrefix { get; set; }
Expand Down

0 comments on commit 6227c7c

Please sign in to comment.