diff --git a/package-lock.json b/package-lock.json index efafc3a0..aa4251fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "blockcoreindexer", - "version": "0.0.3", + "version": "0.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4775afb7..cc169339 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blockcoreindexer", - "version": "0.0.3", + "version": "0.0.4", "license": "MIT", "author": { "name": "Blockcore", diff --git a/src/Blockcore.Indexer.Tests/Blockcore.Indexer.Tests.csproj b/src/Blockcore.Indexer.Tests/Blockcore.Indexer.Tests.csproj index 62a8e353..09a8d904 100644 --- a/src/Blockcore.Indexer.Tests/Blockcore.Indexer.Tests.csproj +++ b/src/Blockcore.Indexer.Tests/Blockcore.Indexer.Tests.csproj @@ -7,6 +7,7 @@ + diff --git a/src/Blockcore.Indexer/Blockcore.Indexer.csproj b/src/Blockcore.Indexer/Blockcore.Indexer.csproj index 72470de1..c0e9c8e3 100644 --- a/src/Blockcore.Indexer/Blockcore.Indexer.csproj +++ b/src/Blockcore.Indexer/Blockcore.Indexer.csproj @@ -17,12 +17,13 @@ + + - diff --git a/src/Blockcore.Indexer/Operations/Types/SyncConnection.cs b/src/Blockcore.Indexer/Operations/Types/SyncConnection.cs index 27231ca4..4f8d95e3 100644 --- a/src/Blockcore.Indexer/Operations/Types/SyncConnection.cs +++ b/src/Blockcore.Indexer/Operations/Types/SyncConnection.cs @@ -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) }; @@ -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 { @@ -98,9 +91,14 @@ public SyncConnection(IOptions config, IOptions 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); } diff --git a/src/Blockcore.Indexer/Settings/NetworkSettings.cs b/src/Blockcore.Indexer/Settings/NetworkSettings.cs index a37c69f7..d441edbb 100644 --- a/src/Blockcore.Indexer/Settings/NetworkSettings.cs +++ b/src/Blockcore.Indexer/Settings/NetworkSettings.cs @@ -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; }