Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/Networks/Terracoin/Terracoin.Node/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Threading.Tasks;
using Blockcore;
using Blockcore.Builder;
using Blockcore.Configuration;
using Blockcore.Features.BlockStore;
using Blockcore.Features.ColdStaking;
using Blockcore.Features.Consensus;
using Blockcore.Features.Diagnostic;
using Blockcore.Features.MemoryPool;
using Blockcore.Features.Miner;
using Blockcore.Features.NodeHost;
using Blockcore.Features.RPC;
using Blockcore.Utilities;

namespace Terracoin.Daemon
{
public class Program
{
public static async Task Main(string[] args)
{
try
{
var nodeSettings = new NodeSettings(networksSelector: Networks.Networks.Terracoin, args: args);

IFullNodeBuilder nodeBuilder = new FullNodeBuilder()
.UseNodeSettings(nodeSettings)
.UseBlockStore()
.UsePosConsensus()
.UseMempool()
.UseColdStakingWallet()
.AddPowPosMining()
.UseNodeHost()
.AddRPC()
.UseDiagnosticFeature();

IFullNode node = nodeBuilder.Build();

if (node != null)
await node.RunAsync();
}
catch (Exception ex)
{
Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"profiles": {
"TRC (MAIN)": {
"commandName": "Project"
},
"TRC (TEST)": {
"commandName": "Project",
"commandLineArgs": "-testnet"
},
"TRC (MAIN/RPC)": {
"commandName": "Project",
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser"
},
"TRC (TEST/RPC)": {
"commandName": "Project",
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -testnet"
},
"TRC (MAIN/LOCAL/RPC)": {
"commandName": "Project",
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata"
},
"TRC (TEST/LOCAL/RPC)": {
"commandName": "Project",
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -testnet"
},
"TRC (MAIN/LOCAL/RPC/DEFAULT)": {
"commandName": "Project",
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -defaultwalletname=default -defaultwalletpassword=default -unlockdefaultwallet -server"
},
"TRC (TEST/LOCAL/RPC/DEFAULT)": {
"commandName": "Project",
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -defaultwalletname=default -defaultwalletpassword=default -unlockdefaultwallet -server -testnet"
},
"TRC (TEST/NO ASSUME VALID)": {
"commandName": "Project",
"commandLineArgs": "-testnet -assumevalid=0 -checkpoints=false"
}
}
}
36 changes: 36 additions & 0 deletions src/Networks/Terracoin/Terracoin.Node/Terracoin.Node.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeFrameworkVersion>3.1.0</RuntimeFrameworkVersion>
<AssemblyName>Terracoin.Node</AssemblyName>
<OutputType>Exe</OutputType>
<Authors>Blockcore</Authors>
</PropertyGroup>

<PropertyGroup>
<LangVersion>latest</LangVersion>
<ServerGarbageCollection>false</ServerGarbageCollection>
<ConcurrentGarbageCollection>false</ConcurrentGarbageCollection>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blockcore.Features.Base.Persistence.LevelDb" Version="1.*" />
<PackageReference Include="Blockcore.Features.BlockStore.Persistence.LevelDb" Version="1.*" />
<PackageReference Include="Blockcore.Features.Consensus.Persistence.LevelDb" Version="1.*" />
<PackageReference Include="Blockcore.Features.BlockStore" Version="1.*" />
<PackageReference Include="Blockcore.Features.ColdStaking" Version="1.*" />
<PackageReference Include="Blockcore.Features.Consensus" Version="1.*" />
<PackageReference Include="Blockcore.Features.MemoryPool" Version="1.*" />
<PackageReference Include="Blockcore.Features.Miner" Version="1.*" />
<PackageReference Include="Blockcore.Features.RPC" Version="1.*" />
<PackageReference Include="Blockcore.Features.Wallet" Version="1.*" />
<PackageReference Include="Blockcore.Features.Diagnostic" Version="1.*" />
<PackageReference Include="Blockcore.NBitcoin" Version="1.*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Terracoin\Terracoin.csproj" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions src/Networks/Terracoin/Terracoin.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29409.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{306E751B-E744-4141-82A8-8D1062CC39D2}") = "Terracoin.Node", "src\Terracoin.Node\Terracoin.Node.csproj", "{B3BDD0F5-A698-4C60-8373-5B97B5FA612E}"
EndProject
Project("{306E751B-E744-4141-82A8-8D1062CC39D2}") = "Terracoin", "src\Terracoin\Terracoin.csproj", "{EB933638-E641-4F96-9AD7-B57F0C63B5C9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B3BDD0F5-A698-4C60-8373-5B97B5FA612E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3BDD0F5-A698-4C60-8373-5B97B5FA612E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3BDD0F5-A698-4C60-8373-5B97B5FA612E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3BDD0F5-A698-4C60-8373-5B97B5FA612E}.Release|Any CPU.Build.0 = Release|Any CPU
{EB933638-E641-4F96-9AD7-B57F0C63B5C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB933638-E641-4F96-9AD7-B57F0C63B5C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB933638-E641-4F96-9AD7-B57F0C63B5C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB933638-E641-4F96-9AD7-B57F0C63B5C9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E1B84079-3527-45DC-8585-F99BCBA75D57}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Blockcore.Base.Deployments;
using Blockcore.Consensus.ScriptInfo;
using Blockcore.Consensus.TransactionInfo;

namespace Terracoin.Networks.Deployments
{
/// <summary>
/// BIP9 deployments for the Blockcore sample coin network.
/// </summary>
public class TerracoinBIP9Deployments : BIP9DeploymentsArray
{
// The position of each deployment in the deployments array. Note that this is decoupled from the actual position of the flag bit for the deployment in the block version.
public const int TestDummy = 0;
public const int CSV = 1;
public const int Segwit = 2;
public const int ColdStaking = 3;

// The number of deployments.
public const int NumberOfDeployments = 4;

/// <summary>
/// Constructs the BIP9 deployments array.
/// </summary>
public TerracoinBIP9Deployments() : base(NumberOfDeployments)
{
}

/// <summary>
/// Gets the deployment flags to set when the deployment activates.
/// </summary>
/// <param name="deployment">The deployment number.</param>
/// <returns>The deployment flags.</returns>
public override BIP9DeploymentFlags GetFlags(int deployment)
{
var flags = new BIP9DeploymentFlags();

switch (deployment)
{
case ColdStaking:
flags.ScriptFlags |= ScriptVerify.CheckColdStakeVerify;
break;

case CSV:
// Start enforcing BIP68 (sequence locks), BIP112 (CHECKSEQUENCEVERIFY) and BIP113 (Median Time Past) using versionbits logic.
flags.ScriptFlags = ScriptVerify.CheckSequenceVerify;
flags.LockTimeFlags = Transaction.LockTimeFlags.VerifySequence | Transaction.LockTimeFlags.MedianTimePast;
break;

case Segwit:
// Start enforcing WITNESS rules using versionbits logic.
flags.ScriptFlags = ScriptVerify.Witness;
break;
}

return flags;
}
}
}
15 changes: 15 additions & 0 deletions src/Networks/Terracoin/Terracoin/Networks/Networks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Blockcore.Networks;

namespace Terracoin.Networks
{
public static class Networks
{
public static NetworksSelector Terracoin
{
get
{
return new NetworksSelector(() => new TerracoinMain(), () => new TerracoinTest(), () => new TerracoinRegTest());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Collections.Generic;
using System.Linq;
using Blockcore.Consensus.ScriptInfo;
using Blockcore.Consensus.TransactionInfo;
using Blockcore.Networks;
using NBitcoin.BitcoinCore;

namespace Terracoin.Networks.Policies
{
/// <summary>
/// Blockcore sample coin-specific standard transaction definitions.
/// </summary>
public class TerracoinStandardScriptsRegistry : StandardScriptsRegistry
{
// See MAX_OP_RETURN_RELAY in stratisX, <script.h>
public const int MaxOpReturnRelay = 40;

// Need a network-specific version of the template list
private readonly List<ScriptTemplate> standardTemplates = new List<ScriptTemplate>
{
PayToPubkeyHashTemplate.Instance,
PayToPubkeyTemplate.Instance,
PayToScriptHashTemplate.Instance,
PayToMultiSigTemplate.Instance,
new TxNullDataTemplate(MaxOpReturnRelay),
PayToWitTemplate.Instance
};

public override List<ScriptTemplate> GetScriptTemplates => standardTemplates;

public override void RegisterStandardScriptTemplate(ScriptTemplate scriptTemplate)
{
if (!standardTemplates.Any(template => (template.Type == scriptTemplate.Type)))
{
standardTemplates.Add(scriptTemplate);
}
}

public override bool IsStandardTransaction(Transaction tx, Network network)
{
return base.IsStandardTransaction(tx, network);
}

public override bool AreOutputsStandard(Network network, Transaction tx)
{
return base.AreOutputsStandard(network, tx);
}

public override ScriptTemplate GetTemplateFromScriptPubKey(Script script)
{
return standardTemplates.FirstOrDefault(t => t.CheckScriptPubKey(script));
}

public override bool IsStandardScriptPubKey(Network network, Script scriptPubKey)
{
return base.IsStandardScriptPubKey(network, scriptPubKey);
}

public override bool AreInputsStandard(Network network, Transaction tx, CoinsView coinsView)
{
return base.AreInputsStandard(network, tx, coinsView);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Blockcore.Consensus;
using Blockcore.Consensus.Chain;
using Blockcore.Consensus.Rules;
using Blockcore.Features.Consensus.Rules.CommonRules;
using Blockcore.Utilities;
using Microsoft.Extensions.Logging;

namespace Terracoin.Networks.Rules
{
/// <summary>
/// Checks if <see cref="TerracoinMain"/> network block's header has a valid block version.
/// </summary>
public class TerracoinHeaderVersionRule : HeaderVersionRule
{
/// <inheritdoc />
/// <exception cref="ConsensusErrors.BadVersion">Thrown if block's version is outdated or otherwise invalid.</exception>
public override void Run(RuleContext context)
{
Guard.NotNull(context.ValidationContext.ChainedHeaderToValidate, nameof(context.ValidationContext.ChainedHeaderToValidate));

ChainedHeader chainedHeader = context.ValidationContext.ChainedHeaderToValidate;

// A version of precisely 7 is what is currently generated by the legacy C++ nodes.

// The stratisX block validation rules mandate if (!IsProtocolV3(nTime)) && (nVersion > 7), then reject block.
// Further, if (IsProtocolV2(nHeight) && nVersion < 7), then reject block.
// And lastly, if (!IsProtocolV2(nHeight) && nVersion > 6), then reject block.

// Protocol version determination is based on either the block height or timestamp as shown:
// IsProtocolV2(nHeight) { return TestNet() || nHeight > 0; }
// IsProtocolV3(nTime) { return TestNet() || nTime > 1470467000; }

// The mainnet genesis block has nTime = 1470713393, so V3 is applied immediately and this supersedes V2.
// The block versions have therefore been version 7 since genesis on Stratis mainnet.

// Whereas BIP9 mandates that the top bits of version be 001. So a standard node should never generate
// block versions above 7 and below 0x18444000.

// The acceptable common subset of the rules is therefore that the block version must be >= 7.

if (chainedHeader.Header.Version < 7)
{
Logger.LogTrace("(-)[BAD_VERSION]");

ConsensusErrors.BadVersion.Throw();
}
}
}
}
46 changes: 46 additions & 0 deletions src/Networks/Terracoin/Terracoin/Networks/Setup/CoinSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using Blockcore.Consensus.Checkpoints;
using NBitcoin;

namespace Terracoin.Networks.Setup
{
internal class CoinSetup
{
internal string FileNamePrefix;
internal string ConfigFileName;
internal string Magic;
internal int CoinType;
internal decimal PremineReward;
internal decimal PoWBlockReward;
internal decimal PoSBlockReward;
internal int LastPowBlock;
internal string GenesisText;
internal TimeSpan TargetSpacing;
internal uint ProofOfStakeTimestampMask;
internal int PoSVersion;
}

internal class NetworkSetup
{
internal string Name;
internal string RootFolderName;
internal string CoinTicker;
internal int DefaultPort;
internal int DefaultRPCPort;
internal int DefaultAPIPort;
internal int PubKeyAddress;
internal int ScriptAddress;
internal int SecretAddress;
internal uint GenesisTime;
internal uint GenesisNonce;
internal uint GenesisBits;
internal int GenesisVersion;
internal Money GenesisReward;
internal string HashGenesisBlock;
internal string HashMerkleRoot;
internal string[] DNS;
internal string[] Nodes;
internal Dictionary<int, CheckpointInfo> Checkpoints;
}
}
Loading