Commit 55c66483 authored by Sergei Zubov's avatar Sergei Zubov

Merge network registration

parent 4dde29ea
using NBitcoin.DataEncoders;
using NBitcoin.Networks;
namespace NBitcoin
{
public partial class Network
{
/// <summary>
/// The name of the root folder containing the different Stratis blockchains (StratisMain, StratisTest,
/// StratisRegTest).
/// </summary>
protected const string DeStreamRootFolderName = "destream";
/// <summary> The default name used for the Stratis configuration file. </summary>
protected const string DeStreamDefaultConfigFilename = "destream.conf";
protected const int DeStreamMaxTimeOffsetSeconds = 25 * 60;
protected const int DeStreamDefaultMaxTipAgeInSeconds = 2 * 60 * 60;
public const string WalletAddressDeStreamMain = "TPPL2wmtxGzP8U6hQsGkRA9yCMsazB33ft";
public static Network DeStreamMain => NetworksContainer.GetNetwork("DeStreamMain") ??
NetworksContainer.Register(new DeStreamMain());
public static Network DeStreamTest => NetworksContainer.GetNetwork("DeStreamTest") ??
NetworksContainer.Register(new DeStreamTest());
public static Network DeStreamRegTest => NetworksContainer.GetNetwork("DeStreamRegTest") ??
NetworksContainer.Register(new DeStreamRegTest());
internal static Block CreateStratisGenesisBlock(ConsensusFactory consensusFactory, uint nTime, uint nNonce,
uint nBits, int nVersion, Money genesisReward)
{
string pszTimestamp =
"http://www.theonion.com/article/olympics-head-priestess-slits-throat-official-rio--53466";
return CreateStratisGenesisBlock(consensusFactory, pszTimestamp, nTime, nNonce, nBits, nVersion,
genesisReward);
}
private static Block CreateStratisGenesisBlock(ConsensusFactory consensusFactory, string pszTimestamp,
uint nTime, uint nNonce, uint nBits, int nVersion, Money genesisReward)
{
Transaction txNew = consensusFactory.CreateTransaction();
txNew.Version = 1;
txNew.Time = nTime;
txNew.AddInput(new TxIn
{
ScriptSig = new Script(Op.GetPushOp(0), new Op
{
Code = (OpcodeType) 0x1,
PushData = new[] {(byte) 42}
}, Op.GetPushOp(Encoders.ASCII.DecodeData(pszTimestamp)))
});
txNew.AddOutput(new TxOut
{
Value = genesisReward
});
Block genesis = consensusFactory.CreateBlock();
genesis.Header.BlockTime = Utils.UnixTimeToDateTime(nTime);
genesis.Header.Bits = nBits;
genesis.Header.Nonce = nNonce;
genesis.Header.Version = nVersion;
genesis.Transactions.Add(txNew);
genesis.Header.HashPrevBlock = uint256.Zero;
genesis.UpdateMerkleRoot();
return genesis;
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using NBitcoin.DataEncoders;
namespace NBitcoin
{
public abstract class DeStreamNetwork : Network
{
/// <summary>
/// The name of the root folder containing the different Stratis blockchains (StratisMain, StratisTest,
/// StratisRegTest).
/// </summary>
protected const string DeStreamRootFolderName = "destream";
/// <summary> The default name used for the Stratis configuration file. </summary>
protected const string DeStreamDefaultConfigFilename = "destream.conf";
protected const int DeStreamMaxTimeOffsetSeconds = 25 * 60;
protected const int DeStreamDefaultMaxTipAgeInSeconds = 2 * 60 * 60;
protected LinkedList<string> DeStreamWallets;
public string GenesisWalletAddress { get; protected set; }
private LinkedListNode<string> DeStreamWalletsNode { get; set; }
public string DeStreamWallet
{
get
{
DeStreamWalletsNode = DeStreamWalletsNode.NextOrFirst() ?? DeStreamWallets.First;
return DeStreamWalletsNode.Value;
}
}
/// <summary>
/// </summary>
public double DeStreamFeePart { get; set; }
/// <summary>
/// Fee applied to all transactions
/// </summary>
public double FeeRate { get; set; }
/// <summary>
/// Splits fee between miner and DeStream
/// </summary>
/// <param name="fee">Total amount of fees to be split</param>
/// <param name="deStreamFee">DeStream fee part</param>
/// <param name="minerReward">Miner fee part</param>
public void SplitFee(long fee, out long deStreamFee, out long minerReward)
{
deStreamFee = Convert.ToInt64(fee * DeStreamFeePart);
minerReward = fee - deStreamFee;
}
/// <summary>
/// Subtracts fee from sum of fees and transfer funds
/// </summary>
/// <param name="value">Sum of fees and transfer funds</param>
/// <returns>Transfer funds without fees</returns>
public Money SubtractFee(Money value)
{
return Convert.ToInt64(value.Satoshi / (1.0 + FeeRate));
}
public bool IsDeStreamAddress(string address)
{
return DeStreamWallets.Contains(address);
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Text;
using NBitcoin.BouncyCastle.Math;
using NBitcoin.DataEncoders;
namespace NBitcoin.Networks
{
public class DeStreamRegTest : Network
{
public DeStreamRegTest()
{
// TODO: move this to Networks
var messageStart = new byte[4];
messageStart[0] = 0xcd;
messageStart[1] = 0xf2;
messageStart[2] = 0xc0;
messageStart[3] = 0xef;
var magic = BitConverter.ToUInt32(messageStart, 0); // 0xefc0f2cd
this.Name = "DeStreamRegTest";
this.RootFolderName = DeStreamRootFolderName;
this.DefaultConfigFilename = DeStreamDefaultConfigFilename;
this.Magic = magic;
this.DefaultPort = 18444;
this.RPCPort = 18442;
this.MaxTimeOffsetSeconds = DeStreamMaxTimeOffsetSeconds;
this.MaxTipAge = DeStreamDefaultMaxTipAgeInSeconds;
this.Consensus.SubsidyHalvingInterval = 210000;
this.Consensus.MajorityEnforceBlockUpgrade = 750;
this.Consensus.MajorityRejectBlockOutdated = 950;
this.Consensus.MajorityWindow = 1000;
this.Consensus.BuriedDeployments[BuriedDeployments.BIP34] = 0;
this.Consensus.BuriedDeployments[BuriedDeployments.BIP65] = 0;
this.Consensus.BuriedDeployments[BuriedDeployments.BIP66] = 0;
this.Consensus.BIP34Hash = new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
this.Consensus.PowLimit = new Target(uint256.Parse("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
this.Consensus.PowTargetTimespan = TimeSpan.FromSeconds(14 * 24 * 60 * 60); // two weeks
this.Consensus.PowTargetSpacing = TimeSpan.FromSeconds(10 * 60);
this.Consensus.PowAllowMinDifficultyBlocks = true;
this.Consensus.PowNoRetargeting = true;
this.Consensus.RuleChangeActivationThreshold = 1916; // 95% of 2016
this.Consensus.MinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
this.Consensus.LastPOWBlock = 12500;
this.Consensus.IsProofOfStake = true;
this.Consensus.ConsensusFactory = new PosConsensusFactory() { Consensus = this.Consensus };
this.Consensus.ProofOfStakeLimit = new BigInteger(uint256.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
this.Consensus.ProofOfStakeLimitV2 = new BigInteger(uint256.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
this.Consensus.CoinType = 105;
this.Consensus.DefaultAssumeValid = null; // turn off assumevalid for regtest.
Block genesis = CreateStratisGenesisBlock(this.Consensus.ConsensusFactory, 1470467000, 1831645, 0x1e0fffff, 1, Money.Zero);
genesis.Header.Time = 1494909211;
genesis.Header.Nonce = 2433759;
genesis.Header.Bits = this.Consensus.PowLimit;
this.Genesis = genesis;
this.Consensus.HashGenesisBlock = genesis.GetHash();
Assert(this.Consensus.HashGenesisBlock == uint256.Parse("0x93925104d664314f581bc7ecb7b4bad07bcfabd1cfce4256dbd2faddcf53bd1f"));
this.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (65) };
this.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (196) };
this.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (65 + 128) };
this.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC] = new byte[] { 0x01, 0x42 };
this.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC] = new byte[] { 0x01, 0x43 };
this.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY] = new byte[] { (0x04), (0x88), (0xB2), (0x1E) };
this.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY] = new byte[] { (0x04), (0x88), (0xAD), (0xE4) };
this.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE] = new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 };
this.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE] = new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A };
this.Base58Prefixes[(int)Base58Type.STEALTH_ADDRESS] = new byte[] { 0x2a };
this.Base58Prefixes[(int)Base58Type.ASSET_ID] = new byte[] { 23 };
this.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS] = new byte[] { 0x13 };
var encoder = new Bech32Encoder("bc");
this.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
this.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Stratis Bitcoin FullNode</Description>
<AssemblyTitle>Stratis.Bitcoin.Networks</AssemblyTitle>
......@@ -16,11 +15,9 @@
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>3.0.0.0</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<CodeAnalysisRuleSet>..\None.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>..\None.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\NBitcoin\NBitcoin.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment