Commit 99885838 authored by Pavel Pavlov's avatar Pavel Pavlov

merge blockchain with Stratic

parent 2ec9c439
......@@ -4,6 +4,7 @@ using System.Linq;
using System.Net;
using NBitcoin.BouncyCastle.Math;
using NBitcoin.DataEncoders;
using NBitcoin.Networks;
using NBitcoin.Protocol;
namespace NBitcoin
......@@ -16,306 +17,308 @@ namespace NBitcoin
/// <summary> The default name used for the Stratis configuration file. </summary>
public const string DeStreamDefaultConfigFilename = "destream.conf";
public static Network DeStreamMain => Network.GetNetwork("DeStreamMain") ?? InitDeStreamMain();
public static Network DeStreamTest => Network.GetNetwork("DeStreamTest") ?? InitDeStreamTest();
public static Network DeStreamRegTest => Network.GetNetwork("DeStreamRegTest") ?? InitDeStreamRegTest();
private static Network InitDeStreamMain()
{
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
var messageStart = new byte[4];
messageStart[0] = 0x70;
messageStart[1] = 0x35;
messageStart[2] = 0x22;
messageStart[3] = 0x05;
var magic = BitConverter.ToUInt32(messageStart, 0); //0x5223570;
Network network = new Network
{
Name = "DeStreamMain",
RootFolderName = DeStreamRootFolderName,
DefaultConfigFilename = DeStreamDefaultConfigFilename,
Magic = magic,
DefaultPort = 0xDE01, // 56833,
RPCPort = 0xDE00, // 56832,
MinTxFee = 10000,
FallbackFee = 60000,
MinRelayTxFee = 10000,
MaxTimeOffsetSeconds = StratisMaxTimeOffsetSeconds,
MaxTipAge = StratisDefaultMaxTipAgeInSeconds
};
network.Consensus.SubsidyHalvingInterval = 210000;
network.Consensus.MajorityEnforceBlockUpgrade = 750;
network.Consensus.MajorityRejectBlockOutdated = 950;
network.Consensus.MajorityWindow = 1000;
network.Consensus.BuriedDeployments[BuriedDeployments.BIP34] = 0;
network.Consensus.BuriedDeployments[BuriedDeployments.BIP65] = 0;
network.Consensus.BuriedDeployments[BuriedDeployments.BIP66] = 0;
network.Consensus.BIP34Hash = new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
network.Consensus.PowLimit = new Target(new uint256("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
network.Consensus.PowTargetTimespan = TimeSpan.FromSeconds(14 * 24 * 60 * 60); // two weeks
network.Consensus.PowTargetSpacing = TimeSpan.FromSeconds(10 * 60);
network.Consensus.PowAllowMinDifficultyBlocks = false;
network.Consensus.PowNoRetargeting = false;
network.Consensus.RuleChangeActivationThreshold = 1916; // 95% of 2016
network.Consensus.MinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
network.Consensus.LastPOWBlock = 12500;
network.Consensus.IsProofOfStake = true;
network.Consensus.ConsensusFactory = new PosConsensusFactory() { Consensus = network.Consensus };
network.Consensus.ProofOfStakeLimit = new BigInteger(uint256.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
network.Consensus.ProofOfStakeLimitV2 = new BigInteger(uint256.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
network.Consensus.CoinType = 105;
network.Consensus.DefaultAssumeValid = new uint256("0x55a8205ae4bbf18f4d238c43f43005bd66e0b1f679b39e2c5c62cf6903693a5e"); // 795970
network.genesis = CreateStratisGenesisBlock(network.Consensus.ConsensusFactory, 1470467000, 1831645, 0x1e0fffff, 1, Money.Zero);
network.Consensus.HashGenesisBlock = network.genesis.GetHash();
Assert(network.Consensus.HashGenesisBlock == uint256.Parse("0x0000066e91e46e5a264d42c89e1204963b2ee6be230b443e9159020539d972af"));
Assert(network.genesis.Header.HashMerkleRoot == uint256.Parse("0x65a26bc20b0351aebf05829daefa8f7db2f800623439f3c114257c91447f1518"));
network.Checkpoints = new Dictionary<int, CheckpointInfo>
{
{ 0, new CheckpointInfo(new uint256("0x0000066e91e46e5a264d42c89e1204963b2ee6be230b443e9159020539d972af"), new uint256("0x0000000000000000000000000000000000000000000000000000000000000000")) },
{ 2, new CheckpointInfo(new uint256("0xbca5936f638181e74a5f1e9999c95b0ce77da48c2688399e72bcc53a00c61eff"), new uint256("0x7d61c139a471821caa6b7635a4636e90afcfe5e195040aecbc1ad7d24924db1e")) }, // Premine
{ 50, new CheckpointInfo(new uint256("0x0353b43f4ce80bf24578e7c0141d90d7962fb3a4b4b4e5a17925ca95e943b816"), new uint256("0x7c2af3b10d13f9d2bc6063baaf7f0860d90d870c994378144f9bf85d0d555061")) },
{ 100, new CheckpointInfo(new uint256("0x688468a8aa48cd1c2197e42e7d8acd42760b7e2ac4bcab9d18ac149a673e16f6"), new uint256("0xcf2b1e9e76aaa3d96f255783eb2d907bf6ccb9c1deeb3617149278f0e4a1ab1b")) },
{ 150, new CheckpointInfo(new uint256("0xe4ae9663519abec15e28f68bdb2cb89a739aee22f53d1573048d69141db6ee5d"), new uint256("0xa6c17173e958dc716cc0892ce33dad8bc327963d78a16c436264ceae43d584ce")) },
{ 127500, new CheckpointInfo(new uint256("0x4773ca7512489df22de03aa03938412fab5b46154b05df004b97bcbeaa184078"), new uint256("0x619743c02ebaff06b90fcc5c60c52dba8aa3fdb6ba3800aae697cbb3c5483f17")) },
{ 128943, new CheckpointInfo(new uint256("0x36bcaa27a53d3adf22b2064150a297adb02ac39c24263a5ceb73856832d49679"), new uint256("0xa3a6fd04e41fcaae411a3990aaabcf5e086d2d06c72c849182b27b4de8c2c42a")) },
{ 136601, new CheckpointInfo(new uint256("0xf5c5210c55ff1ef9c04715420a82728e1647f3473e31dc478b3745a97b4a6d10"), new uint256("0x42058fabe21f7b118a9e358eaf9ef574dadefd024244899e71f2f6d618161e16")) }, // Hardfork to V2 - Drifting Bug Fix
{ 170000, new CheckpointInfo(new uint256("0x22b10952e0cf7e85bfc81c38f1490708f195bff34d2951d193cc20e9ca1fc9d5"), new uint256("0xa4942a6c99cba397cf2b18e4b912930fe1e64a7413c3d97c5a926c2af9073091")) },
{ 200000, new CheckpointInfo(new uint256("0x2391dd493be5d0ff0ef57c3b08c73eefeecc2701b80f983054bb262f7a146989"), new uint256("0x253152d129e82c30c584197deb6833502eff3ec2f30014008f75842d7bb48453")) },
{ 250000, new CheckpointInfo(new uint256("0x681c70fab7c1527246138f0cf937f0eb013838b929fbe9a831af02a60fc4bf55"), new uint256("0x24eed95e00c90618aa9d137d2ee273267285c444c9cde62a25a3e880c98a3685")) },
{ 300000, new CheckpointInfo(new uint256("0xd10ca8c2f065a49ae566c7c9d7a2030f4b8b7f71e4c6fc6b2a02509f94cdcd44"), new uint256("0x39c4dd765b49652935524248b4de4ccb604df086d0723bcd81faf5d1c2489304")) },
{ 350000, new CheckpointInfo(new uint256("0xe2b76d1a068c4342f91db7b89b66e0f2146d3a4706c21f3a262737bb7339253a"), new uint256("0xd1dd94985eaaa028c893687a7ddf89143dcf0176918f958c2d01f33d64910399")) },
{ 390000, new CheckpointInfo(new uint256("0x4682737abc2a3257fdf4c3c119deb09cbac75981969e2ffa998b4f76b7c657bb"), new uint256("0xd84b204ee94499ff65262328a428851fb4f4d2741e928cdd088fdf1deb5413b8")) },
{ 394000, new CheckpointInfo(new uint256("0x42857fa2bc15d45cdcaae83411f755b95985da1cb464ee23f6d40936df523e9f"), new uint256("0x2314b336906a2ed2a39cbdf6fc0622530709c62dbb3a3729de17154fc9d1a7c4")) },
{ 528000, new CheckpointInfo(new uint256("0x7aff2c48b398446595d01e27b5cd898087cec63f94ff73f9ad695c6c9bcee33a"), new uint256("0x3bdc865661390c7681b078e52ed3ad3c53ec7cff97b8c45b74abed3ace289fcc")) },
{ 576000, new CheckpointInfo(new uint256("0xe705476b940e332098d1d5b475d7977312ff8c08cbc8256ce46a3e2c6d5408b8"), new uint256("0x10e31bb5e245ea19650280cfd3ac1a76259fa0002d02e861d2ab5df290534b56")) },
};
network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (63) };
network.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (125) };
network.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (63 + 128) };
network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC] = new byte[] { 0x01, 0x42 };
network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC] = new byte[] { 0x01, 0x43 };
network.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY] = new byte[] { (0x04), (0x88), (0xB2), (0x1E) };
network.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY] = new byte[] { (0x04), (0x88), (0xAD), (0xE4) };
network.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE] = new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 };
network.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE] = new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A };
network.Base58Prefixes[(int)Base58Type.STEALTH_ADDRESS] = new byte[] { 0x2a };
network.Base58Prefixes[(int)Base58Type.ASSET_ID] = new byte[] { 23 };
network.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS] = new byte[] { 0x13 };
var encoder = new Bech32Encoder("bc");
network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
network.DNSSeeds.AddRange(new[]
{
new DNSSeedData("node1.destream.io", "node1.destream.io"),
new DNSSeedData("node2.destream.io", "node2.destream.io")
});
var seeds = new[] { "95.128.181.103", "95.128.181.80" };
// Convert the seeds array into usable address objects.
Random rand = new Random();
TimeSpan oneWeek = TimeSpan.FromDays(7);
foreach (string seed in seeds)
{
// It'll only connect to one or two seed nodes because once it connects,
// it'll get a pile of addresses with newer timestamps.
// Seed nodes are given a random 'last seen time' of between one and two weeks ago.
NetworkAddress addr = new NetworkAddress
{
Time = DateTime.UtcNow - (TimeSpan.FromSeconds(rand.NextDouble() * oneWeek.TotalSeconds)) - oneWeek,
Endpoint = Utils.ParseIpEndpoint(seed, network.DefaultPort)
};
network.SeedNodes.Add(addr);
}
Network.Register(network);
return network;
}
public static Network DeStreamMain => NetworksContainer.GetNetwork("DeStreamMain") ?? NetworksContainer.Register(new DeStreamMain());
public static Network DeStreamTest => NetworksContainer.GetNetwork("DeStreamTest") ?? InitDeStreamTest();
public static Network DeStreamRegTest => NetworksContainer.GetNetwork("DeStreamRegTest") ?? InitDeStreamRegTest();
//private static Network InitDeStreamMain()
//{
// // The message start string is designed to be unlikely to occur in normal data.
// // The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// // a large 4-byte int at any alignment.
// var messageStart = new byte[4];
// messageStart[0] = 0x70;
// messageStart[1] = 0x35;
// messageStart[2] = 0x22;
// messageStart[3] = 0x05;
// var magic = BitConverter.ToUInt32(messageStart, 0); //0x5223570;
// Network network = new Network
// {
// Name = "DeStreamMain",
// RootFolderName = DeStreamRootFolderName,
// DefaultConfigFilename = DeStreamDefaultConfigFilename,
// Magic = magic,
// DefaultPort = 0xDE01, // 56833,
// RPCPort = 0xDE00, // 56832,
// MinTxFee = 10000,
// FallbackFee = 60000,
// MinRelayTxFee = 10000,
// MaxTimeOffsetSeconds = StratisMaxTimeOffsetSeconds,
// MaxTipAge = StratisDefaultMaxTipAgeInSeconds
// };
// network.Consensus.SubsidyHalvingInterval = 210000;
// network.Consensus.MajorityEnforceBlockUpgrade = 750;
// network.Consensus.MajorityRejectBlockOutdated = 950;
// network.Consensus.MajorityWindow = 1000;
// network.Consensus.BuriedDeployments[BuriedDeployments.BIP34] = 0;
// network.Consensus.BuriedDeployments[BuriedDeployments.BIP65] = 0;
// network.Consensus.BuriedDeployments[BuriedDeployments.BIP66] = 0;
// network.Consensus.BIP34Hash = new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
// network.Consensus.PowLimit = new Target(new uint256("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
// network.Consensus.PowTargetTimespan = TimeSpan.FromSeconds(14 * 24 * 60 * 60); // two weeks
// network.Consensus.PowTargetSpacing = TimeSpan.FromSeconds(10 * 60);
// network.Consensus.PowAllowMinDifficultyBlocks = false;
// network.Consensus.PowNoRetargeting = false;
// network.Consensus.RuleChangeActivationThreshold = 1916; // 95% of 2016
// network.Consensus.MinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
// network.Consensus.LastPOWBlock = 12500;
// network.Consensus.IsProofOfStake = true;
// network.Consensus.ConsensusFactory = new PosConsensusFactory() { Consensus = network.Consensus };
// network.Consensus.ProofOfStakeLimit = new BigInteger(uint256.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
// network.Consensus.ProofOfStakeLimitV2 = new BigInteger(uint256.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
// network.Consensus.CoinType = 105;
// network.Consensus.DefaultAssumeValid = new uint256("0x55a8205ae4bbf18f4d238c43f43005bd66e0b1f679b39e2c5c62cf6903693a5e"); // 795970
// network.genesis = CreateStratisGenesisBlock(network.Consensus.ConsensusFactory, 1470467000, 1831645, 0x1e0fffff, 1, Money.Zero);
// network.Consensus.HashGenesisBlock = network.genesis.GetHash();
// Assert(network.Consensus.HashGenesisBlock == uint256.Parse("0x0000066e91e46e5a264d42c89e1204963b2ee6be230b443e9159020539d972af"));
// Assert(network.genesis.Header.HashMerkleRoot == uint256.Parse("0x65a26bc20b0351aebf05829daefa8f7db2f800623439f3c114257c91447f1518"));
// network.Checkpoints = new Dictionary<int, CheckpointInfo>
// {
// { 0, new CheckpointInfo(new uint256("0x0000066e91e46e5a264d42c89e1204963b2ee6be230b443e9159020539d972af"), new uint256("0x0000000000000000000000000000000000000000000000000000000000000000")) },
// { 2, new CheckpointInfo(new uint256("0xbca5936f638181e74a5f1e9999c95b0ce77da48c2688399e72bcc53a00c61eff"), new uint256("0x7d61c139a471821caa6b7635a4636e90afcfe5e195040aecbc1ad7d24924db1e")) }, // Premine
// { 50, new CheckpointInfo(new uint256("0x0353b43f4ce80bf24578e7c0141d90d7962fb3a4b4b4e5a17925ca95e943b816"), new uint256("0x7c2af3b10d13f9d2bc6063baaf7f0860d90d870c994378144f9bf85d0d555061")) },
// { 100, new CheckpointInfo(new uint256("0x688468a8aa48cd1c2197e42e7d8acd42760b7e2ac4bcab9d18ac149a673e16f6"), new uint256("0xcf2b1e9e76aaa3d96f255783eb2d907bf6ccb9c1deeb3617149278f0e4a1ab1b")) },
// { 150, new CheckpointInfo(new uint256("0xe4ae9663519abec15e28f68bdb2cb89a739aee22f53d1573048d69141db6ee5d"), new uint256("0xa6c17173e958dc716cc0892ce33dad8bc327963d78a16c436264ceae43d584ce")) },
// { 127500, new CheckpointInfo(new uint256("0x4773ca7512489df22de03aa03938412fab5b46154b05df004b97bcbeaa184078"), new uint256("0x619743c02ebaff06b90fcc5c60c52dba8aa3fdb6ba3800aae697cbb3c5483f17")) },
// { 128943, new CheckpointInfo(new uint256("0x36bcaa27a53d3adf22b2064150a297adb02ac39c24263a5ceb73856832d49679"), new uint256("0xa3a6fd04e41fcaae411a3990aaabcf5e086d2d06c72c849182b27b4de8c2c42a")) },
// { 136601, new CheckpointInfo(new uint256("0xf5c5210c55ff1ef9c04715420a82728e1647f3473e31dc478b3745a97b4a6d10"), new uint256("0x42058fabe21f7b118a9e358eaf9ef574dadefd024244899e71f2f6d618161e16")) }, // Hardfork to V2 - Drifting Bug Fix
// { 170000, new CheckpointInfo(new uint256("0x22b10952e0cf7e85bfc81c38f1490708f195bff34d2951d193cc20e9ca1fc9d5"), new uint256("0xa4942a6c99cba397cf2b18e4b912930fe1e64a7413c3d97c5a926c2af9073091")) },
// { 200000, new CheckpointInfo(new uint256("0x2391dd493be5d0ff0ef57c3b08c73eefeecc2701b80f983054bb262f7a146989"), new uint256("0x253152d129e82c30c584197deb6833502eff3ec2f30014008f75842d7bb48453")) },
// { 250000, new CheckpointInfo(new uint256("0x681c70fab7c1527246138f0cf937f0eb013838b929fbe9a831af02a60fc4bf55"), new uint256("0x24eed95e00c90618aa9d137d2ee273267285c444c9cde62a25a3e880c98a3685")) },
// { 300000, new CheckpointInfo(new uint256("0xd10ca8c2f065a49ae566c7c9d7a2030f4b8b7f71e4c6fc6b2a02509f94cdcd44"), new uint256("0x39c4dd765b49652935524248b4de4ccb604df086d0723bcd81faf5d1c2489304")) },
// { 350000, new CheckpointInfo(new uint256("0xe2b76d1a068c4342f91db7b89b66e0f2146d3a4706c21f3a262737bb7339253a"), new uint256("0xd1dd94985eaaa028c893687a7ddf89143dcf0176918f958c2d01f33d64910399")) },
// { 390000, new CheckpointInfo(new uint256("0x4682737abc2a3257fdf4c3c119deb09cbac75981969e2ffa998b4f76b7c657bb"), new uint256("0xd84b204ee94499ff65262328a428851fb4f4d2741e928cdd088fdf1deb5413b8")) },
// { 394000, new CheckpointInfo(new uint256("0x42857fa2bc15d45cdcaae83411f755b95985da1cb464ee23f6d40936df523e9f"), new uint256("0x2314b336906a2ed2a39cbdf6fc0622530709c62dbb3a3729de17154fc9d1a7c4")) },
// { 528000, new CheckpointInfo(new uint256("0x7aff2c48b398446595d01e27b5cd898087cec63f94ff73f9ad695c6c9bcee33a"), new uint256("0x3bdc865661390c7681b078e52ed3ad3c53ec7cff97b8c45b74abed3ace289fcc")) },
// { 576000, new CheckpointInfo(new uint256("0xe705476b940e332098d1d5b475d7977312ff8c08cbc8256ce46a3e2c6d5408b8"), new uint256("0x10e31bb5e245ea19650280cfd3ac1a76259fa0002d02e861d2ab5df290534b56")) },
// };
// network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (63) };
// network.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (125) };
// network.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (63 + 128) };
// network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC] = new byte[] { 0x01, 0x42 };
// network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC] = new byte[] { 0x01, 0x43 };
// network.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY] = new byte[] { (0x04), (0x88), (0xB2), (0x1E) };
// network.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY] = new byte[] { (0x04), (0x88), (0xAD), (0xE4) };
// network.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE] = new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 };
// network.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE] = new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A };
// network.Base58Prefixes[(int)Base58Type.STEALTH_ADDRESS] = new byte[] { 0x2a };
// network.Base58Prefixes[(int)Base58Type.ASSET_ID] = new byte[] { 23 };
// network.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS] = new byte[] { 0x13 };
// var encoder = new Bech32Encoder("bc");
// network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
// network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
// network.DNSSeeds.AddRange(new[]
// {
// new DNSSeedData("node1.destream.io", "node1.destream.io"),
// new DNSSeedData("node2.destream.io", "node2.destream.io")
// });
// var seeds = new[] { "95.128.181.103", "95.128.181.80" };
// // Convert the seeds array into usable address objects.
// Random rand = new Random();
// TimeSpan oneWeek = TimeSpan.FromDays(7);
// foreach (string seed in seeds)
// {
// // It'll only connect to one or two seed nodes because once it connects,
// // it'll get a pile of addresses with newer timestamps.
// // Seed nodes are given a random 'last seen time' of between one and two weeks ago.
// NetworkAddress addr = new NetworkAddress
// {
// Time = DateTime.UtcNow - (TimeSpan.FromSeconds(rand.NextDouble() * oneWeek.TotalSeconds)) - oneWeek,
// Endpoint = Utils.ParseIpEndpoint(seed, network.DefaultPort)
// };
// network.SeedNodes.Add(addr);
// }
// Network.Register(network);
// return network;
//}
private static Network InitDeStreamTest()
{
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
var messageStart = new byte[4];
messageStart[0] = 0x71;
messageStart[1] = 0x31;
messageStart[2] = 0x21;
messageStart[3] = 0x11;
var magic = BitConverter.ToUInt32(messageStart, 0); // 0x11213171;
Network network = new Network
{
Name = "DeStreamTest",
RootFolderName = DeStreamRootFolderName,
DefaultConfigFilename = DeStreamDefaultConfigFilename,
Magic = magic,
DefaultPort = 0xDE11, //56849,
RPCPort = 0xDE10, //56848,
MaxTimeOffsetSeconds = StratisMaxTimeOffsetSeconds,
MaxTipAge = StratisDefaultMaxTipAgeInSeconds,
MinTxFee = 10000,
FallbackFee = 60000,
MinRelayTxFee = 10000
};
network.Consensus.SubsidyHalvingInterval = 210000;
network.Consensus.MajorityEnforceBlockUpgrade = 750;
network.Consensus.MajorityRejectBlockOutdated = 950;
network.Consensus.MajorityWindow = 1000;
network.Consensus.BuriedDeployments[BuriedDeployments.BIP34] = 0;
network.Consensus.BuriedDeployments[BuriedDeployments.BIP65] = 0;
network.Consensus.BuriedDeployments[BuriedDeployments.BIP66] = 0;
network.Consensus.BIP34Hash = new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
network.Consensus.PowLimit = new Target(new uint256("0000ffff00000000000000000000000000000000000000000000000000000000"));
network.Consensus.PowTargetTimespan = TimeSpan.FromSeconds(14 * 24 * 60 * 60); // two weeks
network.Consensus.PowTargetSpacing = TimeSpan.FromSeconds(10 * 60);
network.Consensus.PowAllowMinDifficultyBlocks = false;
network.Consensus.PowNoRetargeting = false;
network.Consensus.RuleChangeActivationThreshold = 1916; // 95% of 2016
network.Consensus.MinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
network.Consensus.LastPOWBlock = 12500;
network.Consensus.IsProofOfStake = true;
network.Consensus.ConsensusFactory = new PosConsensusFactory() { Consensus = network.Consensus };
network.Consensus.ProofOfStakeLimit = new BigInteger(uint256.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
network.Consensus.ProofOfStakeLimitV2 = new BigInteger(uint256.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
network.Consensus.CoinType = 105;
network.Consensus.DefaultAssumeValid = new uint256("0x98fa6ef0bca5b431f15fd79dc6f879dc45b83ed4b1bbe933a383ef438321958e"); // 372652
Block genesis = CreateStratisGenesisBlock(network.Consensus.ConsensusFactory, 1470467000, 1831645, 0x1e0fffff, 1, Money.Zero);
genesis.Header.Time = 1493909211;
genesis.Header.Nonce = 2433759;
genesis.Header.Bits = network.Consensus.PowLimit;
network.genesis = genesis;
network.Consensus.HashGenesisBlock = genesis.GetHash();
Assert(network.Consensus.HashGenesisBlock == uint256.Parse("0x00000e246d7b73b88c9ab55f2e5e94d9e22d471def3df5ea448f5576b1d156b9"));
network.Checkpoints = new Dictionary<int, CheckpointInfo>
{
{ 0, new CheckpointInfo(new uint256("0x00000e246d7b73b88c9ab55f2e5e94d9e22d471def3df5ea448f5576b1d156b9"), new uint256("0x0000000000000000000000000000000000000000000000000000000000000000")) },
{ 2, new CheckpointInfo(new uint256("0x56959b1c8498631fb0ca5fe7bd83319dccdc6ac003dccb3171f39f553ecfa2f2"), new uint256("0x13f4c27ca813aefe2d9018077f8efeb3766796b9144fcc4cd51803bf4376ab02")) },
{ 50000, new CheckpointInfo(new uint256("0xb42c18eacf8fb5ed94eac31943bd364451d88da0fd44cc49616ffea34d530ad4"), new uint256("0x824934ddc5f935e854ac59ae7f5ed25f2d29a7c3914cac851f3eddb4baf96d78")) },
{ 100000, new CheckpointInfo(new uint256("0xf9e2f7561ee4b92d3bde400d251363a0e8924204c326da7f4ad9ccc8863aad79"), new uint256("0xdef8d92d20becc71f662ee1c32252aca129f1bf4744026b116d45d9bfe67e9fb")) },
{ 115000, new CheckpointInfo(new uint256("0x8496c77060c8a2b5c9a888ade991f25aa33c232b4413594d556daf9043fad400"), new uint256("0x1886430484a9a36b56a7eb8bd25e9ebe4fc8eec8f9a84f5073f71e08f2feac90")) },
{ 163000, new CheckpointInfo(new uint256("0x4e44a9e0119a2e7cbf15e570a3c649a5605baa601d953a465b5ebd1c1982212a"), new uint256("0x0646fc7db8f3426eb209e1228c7d82724faa46a060f5bbbd546683ef30be245c")) },
};
network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (65) };
network.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (196) };
network.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (65 + 128) };
network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC] = new byte[] { 0x01, 0x42 };
network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC] = new byte[] { 0x01, 0x43 };
network.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY] = new byte[] { (0x04), (0x88), (0xB2), (0x1E) };
network.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY] = new byte[] { (0x04), (0x88), (0xAD), (0xE4) };
network.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE] = new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 };
network.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE] = new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A };
network.Base58Prefixes[(int)Base58Type.STEALTH_ADDRESS] = new byte[] { 0x2a };
network.Base58Prefixes[(int)Base58Type.ASSET_ID] = new byte[] { 23 };
network.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS] = new byte[] { 0x13 };
var encoder = new Bech32Encoder("bc");
network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
network.DNSSeeds.AddRange(new[]
{
new DNSSeedData("testnode1.destream.io", "testnode1.destream.io")
});
network.SeedNodes.AddRange(new[]
{
new NetworkAddress(IPAddress.Parse("95.128.181.196"), network.DefaultPort), //peak-srv-12
new NetworkAddress(IPAddress.Parse("40.121.9.206"), network.DefaultPort)
});
Network.Register(network);
return network;
//var messageStart = new byte[4];
//messageStart[0] = 0x71;
//messageStart[1] = 0x31;
//messageStart[2] = 0x21;
//messageStart[3] = 0x11;
//var magic = BitConverter.ToUInt32(messageStart, 0); // 0x11213171;
//Network network = new Network
//{
// Name = "DeStreamTest",
// RootFolderName = DeStreamRootFolderName,
// DefaultConfigFilename = DeStreamDefaultConfigFilename,
// Magic = magic,
// DefaultPort = 0xDE11, //56849,
// RPCPort = 0xDE10, //56848,
// MaxTimeOffsetSeconds = StratisMaxTimeOffsetSeconds,
// MaxTipAge = StratisDefaultMaxTipAgeInSeconds,
// MinTxFee = 10000,
// FallbackFee = 60000,
// MinRelayTxFee = 10000
//};
//network.Consensus.SubsidyHalvingInterval = 210000;
//network.Consensus.MajorityEnforceBlockUpgrade = 750;
//network.Consensus.MajorityRejectBlockOutdated = 950;
//network.Consensus.MajorityWindow = 1000;
//network.Consensus.BuriedDeployments[BuriedDeployments.BIP34] = 0;
//network.Consensus.BuriedDeployments[BuriedDeployments.BIP65] = 0;
//network.Consensus.BuriedDeployments[BuriedDeployments.BIP66] = 0;
//network.Consensus.BIP34Hash = new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
//network.Consensus.PowLimit = new Target(new uint256("0000ffff00000000000000000000000000000000000000000000000000000000"));
//network.Consensus.PowTargetTimespan = TimeSpan.FromSeconds(14 * 24 * 60 * 60); // two weeks
//network.Consensus.PowTargetSpacing = TimeSpan.FromSeconds(10 * 60);
//network.Consensus.PowAllowMinDifficultyBlocks = false;
//network.Consensus.PowNoRetargeting = false;
//network.Consensus.RuleChangeActivationThreshold = 1916; // 95% of 2016
//network.Consensus.MinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
//network.Consensus.LastPOWBlock = 12500;
//network.Consensus.IsProofOfStake = true;
//network.Consensus.ConsensusFactory = new PosConsensusFactory() { Consensus = network.Consensus };
//network.Consensus.ProofOfStakeLimit = new BigInteger(uint256.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
//network.Consensus.ProofOfStakeLimitV2 = new BigInteger(uint256.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
//network.Consensus.CoinType = 105;
//network.Consensus.DefaultAssumeValid = new uint256("0x98fa6ef0bca5b431f15fd79dc6f879dc45b83ed4b1bbe933a383ef438321958e"); // 372652
//Block genesis = CreateStratisGenesisBlock(network.Consensus.ConsensusFactory, 1470467000, 1831645, 0x1e0fffff, 1, Money.Zero);
//genesis.Header.Time = 1493909211;
//genesis.Header.Nonce = 2433759;
//genesis.Header.Bits = network.Consensus.PowLimit;
//network.genesis = genesis;
//network.Consensus.HashGenesisBlock = genesis.GetHash();
//Assert(network.Consensus.HashGenesisBlock == uint256.Parse("0x00000e246d7b73b88c9ab55f2e5e94d9e22d471def3df5ea448f5576b1d156b9"));
//network.Checkpoints = new Dictionary<int, CheckpointInfo>
//{
// { 0, new CheckpointInfo(new uint256("0x00000e246d7b73b88c9ab55f2e5e94d9e22d471def3df5ea448f5576b1d156b9"), new uint256("0x0000000000000000000000000000000000000000000000000000000000000000")) },
// { 2, new CheckpointInfo(new uint256("0x56959b1c8498631fb0ca5fe7bd83319dccdc6ac003dccb3171f39f553ecfa2f2"), new uint256("0x13f4c27ca813aefe2d9018077f8efeb3766796b9144fcc4cd51803bf4376ab02")) },
// { 50000, new CheckpointInfo(new uint256("0xb42c18eacf8fb5ed94eac31943bd364451d88da0fd44cc49616ffea34d530ad4"), new uint256("0x824934ddc5f935e854ac59ae7f5ed25f2d29a7c3914cac851f3eddb4baf96d78")) },
// { 100000, new CheckpointInfo(new uint256("0xf9e2f7561ee4b92d3bde400d251363a0e8924204c326da7f4ad9ccc8863aad79"), new uint256("0xdef8d92d20becc71f662ee1c32252aca129f1bf4744026b116d45d9bfe67e9fb")) },
// { 115000, new CheckpointInfo(new uint256("0x8496c77060c8a2b5c9a888ade991f25aa33c232b4413594d556daf9043fad400"), new uint256("0x1886430484a9a36b56a7eb8bd25e9ebe4fc8eec8f9a84f5073f71e08f2feac90")) },
// { 163000, new CheckpointInfo(new uint256("0x4e44a9e0119a2e7cbf15e570a3c649a5605baa601d953a465b5ebd1c1982212a"), new uint256("0x0646fc7db8f3426eb209e1228c7d82724faa46a060f5bbbd546683ef30be245c")) },
//};
//network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (65) };
//network.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (196) };
//network.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (65 + 128) };
//network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC] = new byte[] { 0x01, 0x42 };
//network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC] = new byte[] { 0x01, 0x43 };
//network.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY] = new byte[] { (0x04), (0x88), (0xB2), (0x1E) };
//network.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY] = new byte[] { (0x04), (0x88), (0xAD), (0xE4) };
//network.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE] = new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 };
//network.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE] = new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A };
//network.Base58Prefixes[(int)Base58Type.STEALTH_ADDRESS] = new byte[] { 0x2a };
//network.Base58Prefixes[(int)Base58Type.ASSET_ID] = new byte[] { 23 };
//network.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS] = new byte[] { 0x13 };
//var encoder = new Bech32Encoder("bc");
//network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
//network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
//network.DNSSeeds.AddRange(new[]
//{
// new DNSSeedData("testnode1.destream.io", "testnode1.destream.io")
//});
//network.SeedNodes.AddRange(new[]
//{
// new NetworkAddress(IPAddress.Parse("95.128.181.196"), network.DefaultPort), //peak-srv-12
// new NetworkAddress(IPAddress.Parse("40.121.9.206"), network.DefaultPort)
//});
//Network.Register(network);
//return network;
return null;
}
private static Network InitDeStreamRegTest()
{
// 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
Network network = new Network
{
Name = "DeStreamRegTest",
RootFolderName = DeStreamRootFolderName,
DefaultConfigFilename = DeStreamDefaultConfigFilename,
Magic = magic,
DefaultPort = 18444,
RPCPort = 18442,
MaxTimeOffsetSeconds = StratisMaxTimeOffsetSeconds,
MaxTipAge = StratisDefaultMaxTipAgeInSeconds
};
network.Consensus.SubsidyHalvingInterval = 210000;
network.Consensus.MajorityEnforceBlockUpgrade = 750;
network.Consensus.MajorityRejectBlockOutdated = 950;
network.Consensus.MajorityWindow = 1000;
network.Consensus.BuriedDeployments[BuriedDeployments.BIP34] = 0;
network.Consensus.BuriedDeployments[BuriedDeployments.BIP65] = 0;
network.Consensus.BuriedDeployments[BuriedDeployments.BIP66] = 0;
network.Consensus.BIP34Hash = new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
network.Consensus.PowLimit = new Target(uint256.Parse("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
network.Consensus.PowTargetTimespan = TimeSpan.FromSeconds(14 * 24 * 60 * 60); // two weeks
network.Consensus.PowTargetSpacing = TimeSpan.FromSeconds(10 * 60);
network.Consensus.PowAllowMinDifficultyBlocks = true;
network.Consensus.PowNoRetargeting = true;
network.Consensus.RuleChangeActivationThreshold = 1916; // 95% of 2016
network.Consensus.MinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
network.Consensus.LastPOWBlock = 12500;
network.Consensus.IsProofOfStake = true;
network.Consensus.ConsensusFactory = new PosConsensusFactory() { Consensus = network.Consensus };
network.Consensus.ProofOfStakeLimit = new BigInteger(uint256.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
network.Consensus.ProofOfStakeLimitV2 = new BigInteger(uint256.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
network.Consensus.CoinType = 105;
network.Consensus.DefaultAssumeValid = null; // turn off assumevalid for regtest.
Block genesis = CreateStratisGenesisBlock(network.Consensus.ConsensusFactory, 1470467000, 1831645, 0x1e0fffff, 1, Money.Zero);
genesis.Header.Time = 1494909211;
genesis.Header.Nonce = 2433759;
genesis.Header.Bits = network.Consensus.PowLimit;
network.genesis = genesis;
network.Consensus.HashGenesisBlock = genesis.GetHash();
Assert(network.Consensus.HashGenesisBlock == uint256.Parse("0x93925104d664314f581bc7ecb7b4bad07bcfabd1cfce4256dbd2faddcf53bd1f"));
network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (65) };
network.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (196) };
network.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (65 + 128) };
network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC] = new byte[] { 0x01, 0x42 };
network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC] = new byte[] { 0x01, 0x43 };
network.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY] = new byte[] { (0x04), (0x88), (0xB2), (0x1E) };
network.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY] = new byte[] { (0x04), (0x88), (0xAD), (0xE4) };
network.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE] = new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 };
network.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE] = new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A };
network.Base58Prefixes[(int)Base58Type.STEALTH_ADDRESS] = new byte[] { 0x2a };
network.Base58Prefixes[(int)Base58Type.ASSET_ID] = new byte[] { 23 };
network.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS] = new byte[] { 0x13 };
var encoder = new Bech32Encoder("bc");
network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
Network.Register(network);
return network;
//var messageStart = new byte[4];
//messageStart[0] = 0xcd;
//messageStart[1] = 0xf2;
//messageStart[2] = 0xc0;
//messageStart[3] = 0xef;
//var magic = BitConverter.ToUInt32(messageStart, 0); // 0xefc0f2cd
//Network network = new Network
//{
// Name = "DeStreamRegTest",
// RootFolderName = DeStreamRootFolderName,
// DefaultConfigFilename = DeStreamDefaultConfigFilename,
// Magic = magic,
// DefaultPort = 18444,
// RPCPort = 18442,
// MaxTimeOffsetSeconds = StratisMaxTimeOffsetSeconds,
// MaxTipAge = StratisDefaultMaxTipAgeInSeconds
//};
//network.Consensus.SubsidyHalvingInterval = 210000;
//network.Consensus.MajorityEnforceBlockUpgrade = 750;
//network.Consensus.MajorityRejectBlockOutdated = 950;
//network.Consensus.MajorityWindow = 1000;
//network.Consensus.BuriedDeployments[BuriedDeployments.BIP34] = 0;
//network.Consensus.BuriedDeployments[BuriedDeployments.BIP65] = 0;
//network.Consensus.BuriedDeployments[BuriedDeployments.BIP66] = 0;
//network.Consensus.BIP34Hash = new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
//network.Consensus.PowLimit = new Target(uint256.Parse("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
//network.Consensus.PowTargetTimespan = TimeSpan.FromSeconds(14 * 24 * 60 * 60); // two weeks
//network.Consensus.PowTargetSpacing = TimeSpan.FromSeconds(10 * 60);
//network.Consensus.PowAllowMinDifficultyBlocks = true;
//network.Consensus.PowNoRetargeting = true;
//network.Consensus.RuleChangeActivationThreshold = 1916; // 95% of 2016
//network.Consensus.MinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
//network.Consensus.LastPOWBlock = 12500;
//network.Consensus.IsProofOfStake = true;
//network.Consensus.ConsensusFactory = new PosConsensusFactory() { Consensus = network.Consensus };
//network.Consensus.ProofOfStakeLimit = new BigInteger(uint256.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
//network.Consensus.ProofOfStakeLimitV2 = new BigInteger(uint256.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false));
//network.Consensus.CoinType = 105;
//network.Consensus.DefaultAssumeValid = null; // turn off assumevalid for regtest.
//Block genesis = CreateStratisGenesisBlock(network.Consensus.ConsensusFactory, 1470467000, 1831645, 0x1e0fffff, 1, Money.Zero);
//genesis.Header.Time = 1494909211;
//genesis.Header.Nonce = 2433759;
//genesis.Header.Bits = network.Consensus.PowLimit;
//network.genesis = genesis;
//network.Consensus.HashGenesisBlock = genesis.GetHash();
//Assert(network.Consensus.HashGenesisBlock == uint256.Parse("0x93925104d664314f581bc7ecb7b4bad07bcfabd1cfce4256dbd2faddcf53bd1f"));
//network.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (65) };
//network.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (196) };
//network.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (65 + 128) };
//network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC] = new byte[] { 0x01, 0x42 };
//network.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC] = new byte[] { 0x01, 0x43 };
//network.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY] = new byte[] { (0x04), (0x88), (0xB2), (0x1E) };
//network.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY] = new byte[] { (0x04), (0x88), (0xAD), (0xE4) };
//network.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE] = new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 };
//network.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE] = new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A };
//network.Base58Prefixes[(int)Base58Type.STEALTH_ADDRESS] = new byte[] { 0x2a };
//network.Base58Prefixes[(int)Base58Type.ASSET_ID] = new byte[] { 23 };
//network.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS] = new byte[] { 0x13 };
//var encoder = new Bech32Encoder("bc");
//network.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
//network.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
//Network.Register(network);
//return network;
return null;
}
}
}
......@@ -56,8 +56,4 @@
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Folder Include="Networks\" />
</ItemGroup>
</Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Text;
using NBitcoin.BouncyCastle.Math;
using NBitcoin.DataEncoders;
using NBitcoin.Protocol;
namespace NBitcoin.Networks
{
public class DeStreamMain : Network
{
/// <summary> The name of the root folder containing the different Stratis blockchains (StratisMain, StratisTest, StratisRegTest). </summary>
public const string DeStreamRootFolderName = "destream";
/// <summary> The default name used for the Stratis configuration file. </summary>
public const string DeStreamDefaultConfigFilename = "destream.conf";
public const int StratisMaxTimeOffsetSeconds = 25 * 60;
public const int StratisDefaultMaxTipAgeInSeconds = 2 * 60 * 60;
public DeStreamMain()
{
var messageStart = new byte[4];
messageStart[0] = 0x70;
messageStart[1] = 0x35;
messageStart[2] = 0x22;
messageStart[3] = 0x05;
var magic = BitConverter.ToUInt32(messageStart, 0);
this.Name = "DeStreamMain";
this.RootFolderName = DeStreamRootFolderName;
this.DefaultConfigFilename = DeStreamDefaultConfigFilename;
this.Magic = magic;
this.DefaultPort = 0xDE01; // 56833,
this.RPCPort = 0xDE00; // 56832,
this.MinTxFee = 10000;
this.FallbackFee = 60000;
this.MinRelayTxFee = 10000;
this.MaxTimeOffsetSeconds = StratisMaxTimeOffsetSeconds;
this.MaxTipAge = StratisDefaultMaxTipAgeInSeconds;
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(new uint256("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
this.Consensus.PowTargetTimespan = TimeSpan.FromSeconds(14 * 24 * 60 * 60); // two weeks
this.Consensus.PowTargetSpacing = TimeSpan.FromSeconds(10 * 60);
this.Consensus.PowAllowMinDifficultyBlocks = false;
this.Consensus.PowNoRetargeting = false;
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 = new uint256("0x55a8205ae4bbf18f4d238c43f43005bd66e0b1f679b39e2c5c62cf6903693a5e"); // 795970
this.Genesis = CreateStratisGenesisBlock(this.Consensus.ConsensusFactory, 1470467000, 1831645, 0x1e0fffff, 1, Money.Zero);
this.Consensus.HashGenesisBlock = this.Genesis.GetHash();
Assert(this.Consensus.HashGenesisBlock == uint256.Parse("0x0000066e91e46e5a264d42c89e1204963b2ee6be230b443e9159020539d972af"));
Assert(this.Genesis.Header.HashMerkleRoot == uint256.Parse("0x65a26bc20b0351aebf05829daefa8f7db2f800623439f3c114257c91447f1518"));
this.Checkpoints = new Dictionary<int, CheckpointInfo>
{
{ 0, new CheckpointInfo(new uint256("0x0000066e91e46e5a264d42c89e1204963b2ee6be230b443e9159020539d972af"), new uint256("0x0000000000000000000000000000000000000000000000000000000000000000")) },
{ 2, new CheckpointInfo(new uint256("0xbca5936f638181e74a5f1e9999c95b0ce77da48c2688399e72bcc53a00c61eff"), new uint256("0x7d61c139a471821caa6b7635a4636e90afcfe5e195040aecbc1ad7d24924db1e")) }, // Premine
{ 50, new CheckpointInfo(new uint256("0x0353b43f4ce80bf24578e7c0141d90d7962fb3a4b4b4e5a17925ca95e943b816"), new uint256("0x7c2af3b10d13f9d2bc6063baaf7f0860d90d870c994378144f9bf85d0d555061")) },
{ 100, new CheckpointInfo(new uint256("0x688468a8aa48cd1c2197e42e7d8acd42760b7e2ac4bcab9d18ac149a673e16f6"), new uint256("0xcf2b1e9e76aaa3d96f255783eb2d907bf6ccb9c1deeb3617149278f0e4a1ab1b")) },
{ 150, new CheckpointInfo(new uint256("0xe4ae9663519abec15e28f68bdb2cb89a739aee22f53d1573048d69141db6ee5d"), new uint256("0xa6c17173e958dc716cc0892ce33dad8bc327963d78a16c436264ceae43d584ce")) },
{ 127500, new CheckpointInfo(new uint256("0x4773ca7512489df22de03aa03938412fab5b46154b05df004b97bcbeaa184078"), new uint256("0x619743c02ebaff06b90fcc5c60c52dba8aa3fdb6ba3800aae697cbb3c5483f17")) },
{ 128943, new CheckpointInfo(new uint256("0x36bcaa27a53d3adf22b2064150a297adb02ac39c24263a5ceb73856832d49679"), new uint256("0xa3a6fd04e41fcaae411a3990aaabcf5e086d2d06c72c849182b27b4de8c2c42a")) },
{ 136601, new CheckpointInfo(new uint256("0xf5c5210c55ff1ef9c04715420a82728e1647f3473e31dc478b3745a97b4a6d10"), new uint256("0x42058fabe21f7b118a9e358eaf9ef574dadefd024244899e71f2f6d618161e16")) }, // Hardfork to V2 - Drifting Bug Fix
{ 170000, new CheckpointInfo(new uint256("0x22b10952e0cf7e85bfc81c38f1490708f195bff34d2951d193cc20e9ca1fc9d5"), new uint256("0xa4942a6c99cba397cf2b18e4b912930fe1e64a7413c3d97c5a926c2af9073091")) },
{ 200000, new CheckpointInfo(new uint256("0x2391dd493be5d0ff0ef57c3b08c73eefeecc2701b80f983054bb262f7a146989"), new uint256("0x253152d129e82c30c584197deb6833502eff3ec2f30014008f75842d7bb48453")) },
{ 250000, new CheckpointInfo(new uint256("0x681c70fab7c1527246138f0cf937f0eb013838b929fbe9a831af02a60fc4bf55"), new uint256("0x24eed95e00c90618aa9d137d2ee273267285c444c9cde62a25a3e880c98a3685")) },
{ 300000, new CheckpointInfo(new uint256("0xd10ca8c2f065a49ae566c7c9d7a2030f4b8b7f71e4c6fc6b2a02509f94cdcd44"), new uint256("0x39c4dd765b49652935524248b4de4ccb604df086d0723bcd81faf5d1c2489304")) },
{ 350000, new CheckpointInfo(new uint256("0xe2b76d1a068c4342f91db7b89b66e0f2146d3a4706c21f3a262737bb7339253a"), new uint256("0xd1dd94985eaaa028c893687a7ddf89143dcf0176918f958c2d01f33d64910399")) },
{ 390000, new CheckpointInfo(new uint256("0x4682737abc2a3257fdf4c3c119deb09cbac75981969e2ffa998b4f76b7c657bb"), new uint256("0xd84b204ee94499ff65262328a428851fb4f4d2741e928cdd088fdf1deb5413b8")) },
{ 394000, new CheckpointInfo(new uint256("0x42857fa2bc15d45cdcaae83411f755b95985da1cb464ee23f6d40936df523e9f"), new uint256("0x2314b336906a2ed2a39cbdf6fc0622530709c62dbb3a3729de17154fc9d1a7c4")) },
{ 528000, new CheckpointInfo(new uint256("0x7aff2c48b398446595d01e27b5cd898087cec63f94ff73f9ad695c6c9bcee33a"), new uint256("0x3bdc865661390c7681b078e52ed3ad3c53ec7cff97b8c45b74abed3ace289fcc")) },
{ 576000, new CheckpointInfo(new uint256("0xe705476b940e332098d1d5b475d7977312ff8c08cbc8256ce46a3e2c6d5408b8"), new uint256("0x10e31bb5e245ea19650280cfd3ac1a76259fa0002d02e861d2ab5df290534b56")) },
};
this.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (63) };
this.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (125) };
this.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (63 + 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;
this.DNSSeeds.AddRange(new[]
{
new DNSSeedData("node1.destream.io", "node1.destream.io"),
new DNSSeedData("node2.destream.io", "node2.destream.io")
});
var seeds = new[] { "95.128.181.103", "95.128.181.80" };
// Convert the seeds array into usable address objects.
Random rand = new Random();
TimeSpan oneWeek = TimeSpan.FromDays(7);
foreach (string seed in seeds)
{
// It'll only connect to one or two seed nodes because once it connects,
// it'll get a pile of addresses with newer timestamps.
// Seed nodes are given a random 'last seen time' of between one and two weeks ago.
NetworkAddress addr = new NetworkAddress
{
Time = DateTime.UtcNow - (TimeSpan.FromSeconds(rand.NextDouble() * oneWeek.TotalSeconds)) - oneWeek,
Endpoint = Utils.ParseIpEndpoint(seed, this.DefaultPort)
};
this.SeedNodes.Add(addr);
}
}
private 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;
}
}
}
......@@ -23,7 +23,7 @@ namespace NBitcoin
{
public TxNullDataTemplate(int maxScriptSize)
{
MaxScriptSizeLimit = maxScriptSize;
this.MaxScriptSizeLimit = maxScriptSize;
}
private static readonly TxNullDataTemplate _Instance = new TxNullDataTemplate(MAX_OP_RETURN_RELAY);
public static TxNullDataTemplate Instance
......@@ -33,17 +33,19 @@ namespace NBitcoin
return _Instance;
}
}
public int MaxScriptSizeLimit
{
get;
private set;
}
protected override bool FastCheckScriptPubKey(Script scriptPubKey, out bool needMoreCheck)
{
var bytes = scriptPubKey.ToBytes(true);
byte[] bytes = scriptPubKey.ToBytes(true);
if(bytes.Length == 0 ||
bytes[0] != (byte)OpcodeType.OP_RETURN ||
bytes.Length > MaxScriptSizeLimit)
bytes.Length > this.MaxScriptSizeLimit)
{
needMoreCheck = false;
return false;
......@@ -51,18 +53,22 @@ namespace NBitcoin
needMoreCheck = true;
return true;
}
protected override bool CheckScriptPubKeyCore(Network network, Script scriptPubKey, Op[] scriptPubKeyOps)
protected override bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPubKeyOps)
{
return scriptPubKeyOps.Skip(1).All(o => o.PushData != null && !o.IsInvalid);
}
public byte[][] ExtractScriptPubKeyParameters(Network network, Script scriptPubKey)
public byte[][] ExtractScriptPubKeyParameters(Script scriptPubKey)
{
bool needMoreCheck;
if(!FastCheckScriptPubKey(scriptPubKey, out needMoreCheck))
return null;
var ops = scriptPubKey.ToOps().ToArray();
if(!CheckScriptPubKeyCore(network, scriptPubKey, ops))
Op[] ops = scriptPubKey.ToOps().ToArray();
if(!CheckScriptPubKeyCore(scriptPubKey, ops))
return null;
return ops.Skip(1).Select(o => o.PushData).ToArray();
}
......@@ -76,15 +82,15 @@ namespace NBitcoin
{
if(data == null)
throw new ArgumentNullException("data");
Op[] ops = new Op[data.Length + 1];
var ops = new Op[data.Length + 1];
ops[0] = OpcodeType.OP_RETURN;
for(int i = 0; i < data.Length; i++)
{
ops[1 + i] = Op.GetPushOp(data[i]);
}
var script = new Script(ops);
if(script.ToBytes(true).Length > MaxScriptSizeLimit)
throw new ArgumentOutOfRangeException("data", "Data in OP_RETURN should have a maximum size of " + MaxScriptSizeLimit + " bytes");
if(script.ToBytes(true).Length > this.MaxScriptSizeLimit)
throw new ArgumentOutOfRangeException("data", "Data in OP_RETURN should have a maximum size of " + this.MaxScriptSizeLimit + " bytes");
return script;
}
......@@ -128,15 +134,15 @@ namespace NBitcoin
}
public Script GenerateScriptPubKey(int sigCount, params PubKey[] keys)
{
List<Op> ops = new List<Op>();
var push = Op.GetPushOp(sigCount);
var ops = new List<Op>();
Op push = Op.GetPushOp(sigCount);
if(!push.IsSmallUInt)
throw new ArgumentOutOfRangeException("sigCount should be less or equal to 16");
ops.Add(push);
var keyCount = Op.GetPushOp(keys.Length);
Op keyCount = Op.GetPushOp(keys.Length);
if(!keyCount.IsSmallUInt)
throw new ArgumentOutOfRangeException("key count should be less or equal to 16");
foreach(var key in keys)
foreach(PubKey key in keys)
{
ops.Add(Op.GetPushOp(key.ToBytes()));
}
......@@ -144,14 +150,14 @@ namespace NBitcoin
ops.Add(OpcodeType.OP_CHECKMULTISIG);
return new Script(ops);
}
protected override bool CheckScriptPubKeyCore(Network network, Script scriptPubKey, Op[] scriptPubKeyOps)
protected override bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPubKeyOps)
{
var ops = scriptPubKeyOps;
Op[] ops = scriptPubKeyOps;
if(ops.Length < 3)
return false;
var sigCount = ops[0].GetInt();
var keyCount = ops[ops.Length - 2].GetInt();
int? sigCount = ops[0].GetInt();
int? keyCount = ops[ops.Length - 2].GetInt();
if(sigCount == null || keyCount == null)
return false;
......@@ -169,20 +175,20 @@ namespace NBitcoin
return ops[ops.Length - 1].Code == OpcodeType.OP_CHECKMULTISIG;
}
public PayToMultiSigTemplateParameters ExtractScriptPubKeyParameters(Network network, Script scriptPubKey)
public PayToMultiSigTemplateParameters ExtractScriptPubKeyParameters(Script scriptPubKey)
{
bool needMoreCheck;
if(!FastCheckScriptPubKey(scriptPubKey, out needMoreCheck))
return null;
var ops = scriptPubKey.ToOps().ToArray();
if(!CheckScriptPubKeyCore(network, scriptPubKey, ops))
Op[] ops = scriptPubKey.ToOps().ToArray();
if(!CheckScriptPubKeyCore(scriptPubKey, ops))
return null;
//already checked in CheckScriptPubKeyCore
var sigCount = ops[0].GetInt().Value;
var keyCount = ops[ops.Length - 2].GetInt().Value;
List<PubKey> keys = new List<PubKey>();
List<byte[]> invalidKeys = new List<byte[]>();
int sigCount = ops[0].GetInt().Value;
int keyCount = ops[ops.Length - 2].GetInt().Value;
var keys = new List<PubKey>();
var invalidKeys = new List<byte[]>();
for(int i = 1; i < keyCount + 1; i++)
{
if(!PubKey.Check(ops[i].PushData, false))
......@@ -210,7 +216,7 @@ namespace NBitcoin
protected override bool FastCheckScriptSig(Script scriptSig, Script scriptPubKey, out bool needMoreCheck)
{
var bytes = scriptSig.ToBytes(true);
byte[] bytes = scriptSig.ToBytes(true);
if(bytes.Length == 0 ||
bytes[0] != (byte)OpcodeType.OP_0)
{
......@@ -233,9 +239,9 @@ namespace NBitcoin
return false;
if(scriptPubKeyOps != null)
{
if(!CheckScriptPubKeyCore(network, scriptPubKey, scriptPubKeyOps))
if(!CheckScriptPubKeyCore(scriptPubKey, scriptPubKeyOps))
return false;
var sigCountExpected = scriptPubKeyOps[0].GetInt();
int? sigCountExpected = scriptPubKeyOps[0].GetInt();
if(sigCountExpected == null)
return false;
return sigCountExpected == scriptSigOps.Length + 1;
......@@ -249,7 +255,7 @@ namespace NBitcoin
bool needMoreCheck;
if(!FastCheckScriptSig(scriptSig, null, out needMoreCheck))
return null;
var ops = scriptSig.ToOps().ToArray();
Op[] ops = scriptSig.ToOps().ToArray();
if(!CheckScriptSigCore(network, scriptSig, ops, null, null))
return null;
try
......@@ -277,9 +283,9 @@ namespace NBitcoin
public Script GenerateScriptSig(IEnumerable<TransactionSignature> signatures)
{
List<Op> ops = new List<Op>();
var ops = new List<Op>();
ops.Add(OpcodeType.OP_0);
foreach(var sig in signatures)
foreach(TransactionSignature sig in signatures)
{
if(sig == null)
ops.Add(OpcodeType.OP_0);
......@@ -304,7 +310,7 @@ namespace NBitcoin
}
public TransactionSignature[] GetMultisigSignatures(Network network)
{
return PayToMultiSigTemplate.Instance.ExtractScriptSigParameters(network, new Script(Pushes.Select(p => Op.GetPushOp(p)).ToArray()));
return PayToMultiSigTemplate.Instance.ExtractScriptSigParameters(network, new Script(this.Pushes.Select(p => Op.GetPushOp(p)).ToArray()));
}
}
//https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki
......@@ -332,7 +338,7 @@ namespace NBitcoin
protected override bool FastCheckScriptPubKey(Script scriptPubKey, out bool needMoreCheck)
{
var bytes = scriptPubKey.ToBytes(true);
byte[] bytes = scriptPubKey.ToBytes(true);
needMoreCheck = false;
return
bytes.Length == 23 &&
......@@ -340,14 +346,14 @@ namespace NBitcoin
bytes[1] == 0x14 &&
bytes[22] == (byte)OpcodeType.OP_EQUAL;
}
protected override bool CheckScriptPubKeyCore(Network network, Script scriptPubKey, Op[] scriptPubKeyOps)
protected override bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPubKeyOps)
{
return true;
}
public Script GenerateScriptSig(Op[] ops, Script redeemScript)
{
var pushScript = Op.GetPushOp(redeemScript._Script);
Op pushScript = Op.GetPushOp(redeemScript._Script);
return new Script(ops.Concat(new[] { pushScript }));
}
public PayToScriptHashSigParameters ExtractScriptSigParameters(Network network, Script scriptSig)
......@@ -362,20 +368,20 @@ namespace NBitcoin
}
public PayToScriptHashSigParameters ExtractScriptSigParameters(Network network, Script scriptSig, Script scriptPubKey)
{
var ops = scriptSig.ToOps().ToArray();
var ops2 = scriptPubKey == null ? null : scriptPubKey.ToOps().ToArray();
Op[] ops = scriptSig.ToOps().ToArray();
Op[] ops2 = scriptPubKey == null ? null : scriptPubKey.ToOps().ToArray();
if(!CheckScriptSigCore(network, scriptSig, ops, scriptPubKey, ops2))
return null;
PayToScriptHashSigParameters result = new PayToScriptHashSigParameters();
var result = new PayToScriptHashSigParameters();
result.RedeemScript = Script.FromBytesUnsafe(ops[ops.Length - 1].PushData);
result.Pushes = ops.Take(ops.Length - 1).Select(o => o.PushData).ToArray();
return result;
}
public Script GenerateScriptSig(byte[][] pushes, Script redeemScript)
{
List<Op> ops = new List<Op>();
foreach(var push in pushes)
var ops = new List<Op>();
foreach(byte[] push in pushes)
ops.Add(Op.GetPushOp(push));
ops.Add(Op.GetPushOp(redeemScript.ToBytes(true)));
return new Script(ops);
......@@ -383,12 +389,12 @@ namespace NBitcoin
public Script GenerateScriptSig(Network network, TransactionSignature[] signatures, Script redeemScript)
{
List<Op> ops = new List<Op>();
PayToMultiSigTemplate multiSigTemplate = new PayToMultiSigTemplate();
bool multiSig = multiSigTemplate.CheckScriptPubKey(network, redeemScript);
var ops = new List<Op>();
var multiSigTemplate = new PayToMultiSigTemplate();
bool multiSig = multiSigTemplate.CheckScriptPubKey(redeemScript);
if(multiSig)
ops.Add(OpcodeType.OP_0);
foreach(var sig in signatures)
foreach(TransactionSignature sig in signatures)
{
ops.Add(sig == null ? OpcodeType.OP_0 : Op.GetPushOp(sig.ToBytes()));
}
......@@ -401,21 +407,21 @@ namespace NBitcoin
}
protected override bool CheckScriptSigCore(Network network, Script scriptSig, Op[] scriptSigOps, Script scriptPubKey, Op[] scriptPubKeyOps)
{
var ops = scriptSigOps;
Op[] ops = scriptSigOps;
if(ops.Length == 0)
return false;
if(!scriptSig.IsPushOnly)
return false;
if(scriptPubKey != null)
{
var expectedHash = ExtractScriptPubKeyParameters(scriptPubKey);
ScriptId expectedHash = ExtractScriptPubKeyParameters(scriptPubKey);
if(expectedHash == null)
return false;
if(expectedHash != Script.FromBytesUnsafe(ops[ops.Length - 1].PushData).Hash)
return false;
}
var redeemBytes = ops[ops.Length - 1].PushData;
byte[] redeemBytes = ops[ops.Length - 1].PushData;
if(redeemBytes.Length > 520)
return false;
return Script.FromBytesUnsafe(ops[ops.Length - 1].PushData).IsValid;
......@@ -475,7 +481,7 @@ namespace NBitcoin
scriptPubKey.ToBytes(true)[scriptPubKey.Length - 1] == 0xac;
}
protected override bool CheckScriptPubKeyCore(Network network, Script scriptPubKey, Op[] scriptPubKeyOps)
protected override bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPubKeyOps)
{
return true;
}
......@@ -493,11 +499,11 @@ namespace NBitcoin
public TransactionSignature ExtractScriptSigParameters(Network network, Script scriptSig)
{
var ops = scriptSig.ToOps().ToArray();
Op[] ops = scriptSig.ToOps().ToArray();
if(!CheckScriptSigCore(network, scriptSig, ops, null, null))
return null;
var data = ops[0].PushData;
byte[] data = ops[0].PushData;
if(!TransactionSignature.ValidLength(data.Length))
return null;
try
......@@ -518,7 +524,7 @@ namespace NBitcoin
protected override bool CheckScriptSigCore(Network network, Script scriptSig, Op[] scriptSigOps, Script scriptPubKey, Op[] scriptPubKeyOps)
{
var ops = scriptSigOps;
Op[] ops = scriptSigOps;
if(ops.Length != 1)
return false;
return ops[0].PushData != null && TransactionSignature.IsValid(network, ops[0].PushData);
......@@ -560,7 +566,7 @@ namespace NBitcoin
/// <returns>The public key</returns>
public PubKey ExtractScriptPubKeyParameters(Script scriptPubKey, bool deepCheck)
{
var result = ExtractScriptPubKeyParameters(scriptPubKey);
PubKey result = ExtractScriptPubKeyParameters(scriptPubKey);
if(result == null || !deepCheck)
return result;
return PubKey.Check(result.ToBytes(true), true) ? result : null;
......@@ -574,7 +580,7 @@ namespace NBitcoin
{
get
{
return PublicKey.WitHash;
return this.PublicKey.WitHash;
}
}
}
......@@ -595,7 +601,7 @@ namespace NBitcoin
{
get
{
return PublicKey.Hash;
return this.PublicKey.Hash;
}
}
#region IDestination Members
......@@ -604,7 +610,7 @@ namespace NBitcoin
{
get
{
return Hash.ScriptPubKey;
return this.Hash.ScriptPubKey;
}
}
......@@ -655,7 +661,7 @@ namespace NBitcoin
protected override bool FastCheckScriptPubKey(Script scriptPubKey, out bool needMoreCheck)
{
var bytes = scriptPubKey.ToBytes(true);
byte[] bytes = scriptPubKey.ToBytes(true);
needMoreCheck = false;
return bytes.Length == 25 &&
bytes[0] == (byte)OpcodeType.OP_DUP &&
......@@ -664,7 +670,7 @@ namespace NBitcoin
bytes[24] == (byte)OpcodeType.OP_CHECKSIG;
}
protected override bool CheckScriptPubKeyCore(Network network, Script scriptPubKey, Op[] scriptPubKeyOps)
protected override bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPubKeyOps)
{
return true;
}
......@@ -678,7 +684,7 @@ namespace NBitcoin
protected override bool CheckScriptSigCore(Network network, Script scriptSig, Op[] scriptSigOps, Script scriptPubKey, Op[] scriptPubKeyOps)
{
var ops = scriptSigOps;
Op[] ops = scriptSigOps;
if(ops.Length != 2)
return false;
return ops[0].PushData != null &&
......@@ -693,7 +699,7 @@ namespace NBitcoin
public PayToPubkeyHashScriptSigParameters ExtractScriptSigParameters(Network network, Script scriptSig)
{
var ops = scriptSig.ToOps().ToArray();
Op[] ops = scriptSig.ToOps().ToArray();
if(!CheckScriptSigCore(network, scriptSig, ops, null, null))
return null;
try
......@@ -723,20 +729,22 @@ namespace NBitcoin
return TxOutType.TX_PUBKEYHASH;
}
}
}
public abstract class ScriptTemplate
{
public virtual bool CheckScriptPubKey(Network network, Script scriptPubKey)
public virtual bool CheckScriptPubKey(Script scriptPubKey)
{
if(scriptPubKey == null)
throw new ArgumentNullException("scriptPubKey");
bool needMoreCheck;
bool result = FastCheckScriptPubKey(scriptPubKey, out needMoreCheck);
if(needMoreCheck)
{
result &= CheckScriptPubKeyCore(network, scriptPubKey, scriptPubKey.ToOps().ToArray());
result &= CheckScriptPubKeyCore(scriptPubKey, scriptPubKey.ToOps().ToArray());
}
return result;
}
......@@ -746,13 +754,13 @@ namespace NBitcoin
return true;
}
protected abstract bool CheckScriptPubKeyCore(Network network, Script scriptPubKey, Op[] scriptPubKeyOps);
protected abstract bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPubKeyOps);
public virtual bool CheckScriptSig(Network network, Script scriptSig, Script scriptPubKey)
{
if(scriptSig == null)
throw new ArgumentNullException("scriptSig");
bool needMoreCheck;
var result = FastCheckScriptSig(scriptSig, scriptPubKey, out needMoreCheck);
bool result = FastCheckScriptSig(scriptSig, scriptPubKey, out needMoreCheck);
if(needMoreCheck)
{
result &= CheckScriptSigCore(network, scriptSig, scriptSig.ToOps().ToArray(), scriptPubKey, scriptPubKey == null ? null : scriptPubKey.ToOps().ToArray());
......@@ -775,7 +783,7 @@ namespace NBitcoin
public class PayToWitPubKeyHashTemplate : PayToWitTemplate
{
static PayToWitPubKeyHashTemplate _Instance;
private static PayToWitPubKeyHashTemplate _Instance;
public new static PayToWitPubKeyHashTemplate Instance
{
get
......@@ -811,19 +819,19 @@ namespace NBitcoin
return GenerateScriptPubKey(address.Hash);
}
public override bool CheckScriptPubKey(Network network, Script scriptPubKey)
public override bool CheckScriptPubKey(Script scriptPubKey)
{
if(scriptPubKey == null)
throw new ArgumentNullException("scriptPubKey");
var bytes = scriptPubKey.ToBytes(true);
byte[] bytes = scriptPubKey.ToBytes(true);
return bytes.Length == 22 && bytes[0] == 0 && bytes[1] == 20;
}
public new WitKeyId ExtractScriptPubKeyParameters(Network network, Script scriptPubKey)
{
if(!CheckScriptPubKey(network, scriptPubKey))
if(!CheckScriptPubKey(scriptPubKey))
return null;
byte[] data = new byte[20];
var data = new byte[20];
Array.Copy(scriptPubKey.ToBytes(true), 2, data, 0, 20);
return new WitKeyId(data);
}
......@@ -863,7 +871,7 @@ namespace NBitcoin
public class PayToWitScriptHashTemplate : PayToWitTemplate
{
static PayToWitScriptHashTemplate _Instance;
private static PayToWitScriptHashTemplate _Instance;
public new static PayToWitScriptHashTemplate Instance
{
get
......@@ -904,18 +912,18 @@ namespace NBitcoin
return GenerateScriptPubKey(address.Hash);
}
public override bool CheckScriptPubKey(Network network, Script scriptPubKey)
public override bool CheckScriptPubKey(Script scriptPubKey)
{
if(scriptPubKey == null)
throw new ArgumentNullException("scriptPubKey");
var bytes = scriptPubKey.ToBytes(true);
byte[] bytes = scriptPubKey.ToBytes(true);
return bytes.Length == 34 && bytes[0] == 0 && bytes[1] == 32;
}
public new WitScriptId ExtractScriptPubKeyParameters(Network network, Script scriptPubKey)
{
if(!CheckScriptPubKey(network, scriptPubKey))
if(!CheckScriptPubKey(scriptPubKey))
return null;
byte[] data = new byte[32];
var data = new byte[32];
Array.Copy(scriptPubKey.ToBytes(true), 2, data, 0, 32);
return new WitScriptId(data);
}
......@@ -930,8 +938,8 @@ namespace NBitcoin
{
if(witScript.PushCount == 0)
return null;
var last = witScript.GetUnsafePush(witScript.PushCount - 1);
Script redeem = new Script(last);
byte[] last = witScript.GetUnsafePush(witScript.PushCount - 1);
var redeem = new Script(last);
if(expectedScriptId != null)
{
if(expectedScriptId != redeem.WitHash)
......@@ -958,7 +966,7 @@ namespace NBitcoin
public class PayToWitTemplate : ScriptTemplate
{
static PayToWitTemplate _Instance;
private static PayToWitTemplate _Instance;
public static PayToWitTemplate Instance
{
get
......@@ -983,16 +991,16 @@ namespace NBitcoin
return scriptSig.Length == 0;
}
public override bool CheckScriptPubKey(Network network, Script scriptPubKey)
public override bool CheckScriptPubKey(Script scriptPubKey)
{
if(scriptPubKey == null)
throw new ArgumentNullException("scriptPubKey");
var bytes = scriptPubKey.ToBytes(true);
byte[] bytes = scriptPubKey.ToBytes(true);
if(bytes.Length < 4 || bytes.Length > 34)
{
return false;
}
var version = bytes[0];
byte version = bytes[0];
if(!ValidSegwitVersion(version))
return false;
return bytes[1] + 2 == bytes.Length;
......@@ -1005,9 +1013,9 @@ namespace NBitcoin
public TxDestination ExtractScriptPubKeyParameters(Network network, Script scriptPubKey)
{
if(!CheckScriptPubKey(network, scriptPubKey))
if(!CheckScriptPubKey(scriptPubKey))
return null;
var ops = scriptPubKey.ToOps().ToArray();
Op[] ops = scriptPubKey.ToOps().ToArray();
if(ops.Length != 2 || ops[1].PushData == null)
return null;
if(ops[0].Code == OpcodeType.OP_0)
......@@ -1021,9 +1029,9 @@ namespace NBitcoin
}
public WitProgramParameters ExtractScriptPubKeyParameters2(Network network, Script scriptPubKey)
{
if(!CheckScriptPubKey(network, scriptPubKey))
if(!CheckScriptPubKey(scriptPubKey))
return null;
var ops = scriptPubKey.ToOps().ToArray();
Op[] ops = scriptPubKey.ToOps().ToArray();
if(ops.Length != 2 || ops[1].PushData == null)
return null;
return new WitProgramParameters()
......@@ -1041,7 +1049,7 @@ namespace NBitcoin
}
}
protected override bool CheckScriptPubKeyCore(Network network, Script scriptPubKey, Op[] scriptPubKeyOps)
protected override bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPubKeyOps)
{
throw new NotImplementedException();
}
......
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