Skip to content

Commit

Permalink
Merge pull request #2 from stratisproject/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
StratisIain authored Nov 3, 2020
2 parents 5441191 + 2d27dff commit 939a129
Show file tree
Hide file tree
Showing 164 changed files with 3,564 additions and 1,933 deletions.
46 changes: 8 additions & 38 deletions Documentation/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
## Prerequisites

To install and run the node, you need
* [.NET Core 2.1](https://www.microsoft.com/net/download/core)
* [.NET Core 3.1](https://www.microsoft.com/net/download/core)
* [Git](https://git-scm.com/)

## Build instructions

### Get the repository and its dependencies

```
git clone https://github.com/stratisproject/StratisBitcoinFullNode.git
cd StratisBitcoinFullNode/src
git clone https://github.com/stratisproject/StratisFullNode.git
cd StratisFullNode/src
```

### Build and run the code
Expand All @@ -31,58 +31,28 @@ So you have 4 options:

1. To run a <b>Stratis</b> node on <b>MainNet</b>, do
```
cd Stratis.StratisD
cd Stratis.StraxD
dotnet run
```

2. To run a <b>Stratis</b> node on <b>TestNet</b>, do
```
cd Stratis.StratisD
dotnet run -testnet
```

3. To run a <b>Bitcoin</b> node on <b>MainNet</b>, do
```
cd Stratis.BitcoinD
dotnet run
```

4. To run a <b>Bitcoin</b> node on <b>TestNet</b>, do
```
cd Stratis.BitcoinD
cd Stratis.StraxD
dotnet run -testnet
```

### Advanced options

You can get a list of command line arguments to pass to the node with the -help command line argument. For example:
```
cd Stratis.StratisD
cd Stratis.StraxD
dotnet run -help
```

### Script
We have a nifty little script that can execute all the previous commands for you, including starting the node.
You just need to edit the file and specify whether you want to run a Stratis or a Bitcoin node, on MainNet or Testnet.
It's located [here](https://gist.github.com/bokobza/e68832f5d7d4102bcb33fcde8d9a72fb#file-build-and-run-a-stratis-node-ps1).

### Faucet
If you need testnet funds (TSTRAT) for testing there is a faucet located [here](https://faucet.stratisplatform.com/).

Docker Containers
-------------------

Two containers are available [here](https://hub.docker.com/u/stratisplatform/)

- stratis-node: Run on the Bitcoin Main or Test networks
- stratis-node-sim: Join our simulation network

Swagger Endpoints
-------------------

Once the node is running, a Swagger interface (web UI for testing an API) is available.

* For Bitcoin: http://localhost:37220/swagger/
* For Stratis: http://localhost:37221/swagger/
* For Bitcoin Testnet: http://localhost:38220/swagger/
* For Stratis Testnet: http://localhost:38221/swagger/
* For Strax: http://localhost:17103/swagger/
* For Strax Testnet: http://localhost:27103/swagger/
2 changes: 1 addition & 1 deletion src/FederationSetup/FederationSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void OutputHeader()
var builder = new StringBuilder();

builder.AppendLine($"Stratis Federation Set up v{Assembly.GetEntryAssembly().GetName().Version}");
builder.AppendLine("Copyright (c) 2018 Stratis Group Limited");
builder.AppendLine("Copyright (c) 2020 Stratis Group Limited");

Console.WriteLine(builder);
}
Expand Down
18 changes: 2 additions & 16 deletions src/FederationSetup/FederationSetup.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>


<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>

<StartupObject>FederationSetup.Program</StartupObject>
<RuntimeIdentifiers>win10-x64;</RuntimeIdentifiers>
<DebugType>Full</DebugType>
<CodeAnalysisRuleSet>..\None.ruleset</CodeAnalysisRuleSet>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.7" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 1 addition & 12 deletions src/FederationSetup/GenesisMiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,11 @@
using NBitcoin.DataEncoders;
using Stratis.Bitcoin.Features.SmartContracts.PoA;
using Stratis.Sidechains.Networks;
using Xunit;
using Xunit.Abstractions;

namespace FederationSetup
{
public class GenesisMiner
{
private readonly ITestOutputHelper output;

public GenesisMiner(ITestOutputHelper output = null)
{
if (output == null) return;
this.output = output;
}

public string MineGenesisBlocks(SmartContractPoAConsensusFactory consensusFactory, string coinbaseText)
{
var output = new StringBuilder();
Expand Down Expand Up @@ -50,7 +40,7 @@ private Block GeneterateBlock(SmartContractPoAConsensusFactory consensusFactory,

private string NetworkOutput(Block genesisBlock, string network, string coinbaseText)
{
var header = (SmartContractPoABlockHeader) genesisBlock.Header;
var header = (SmartContractPoABlockHeader)genesisBlock.Header;

var output = new StringBuilder();
output.AppendLine(network);
Expand Down Expand Up @@ -82,7 +72,6 @@ public static Block MineGenesisBlock(SmartContractPoAConsensusFactory consensusF
throw new ArgumentException($"Parameter '{nameof(genesisReward)}' cannot be null. Example use: 'Money.Coins(50m)'.");

DateTimeOffset time = DateTimeOffset.Now;
uint unixTime = Utils.DateTimeToUnixTime(time);

Transaction txNew = consensusFactory.CreateTransaction();
txNew.Version = (uint)version;
Expand Down
9 changes: 0 additions & 9 deletions src/FederationSetup/MultisigAddressCreator.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
using System.Text;
using NBitcoin;
using Xunit.Abstractions;

namespace FederationSetup
{
public class MultisigAddressCreator
{
private readonly ITestOutputHelper output;

public MultisigAddressCreator(ITestOutputHelper output = null)
{
if (output == null) return;
this.output = output;
}

public string CreateMultisigAddresses(Network mainchainNetwork, Network sidechainNetwork)
{
var output = new StringBuilder();
Expand Down
50 changes: 25 additions & 25 deletions src/FederationSetup/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,30 @@ private static void SwitchCommand(string[] args, string command, string userInpu
switch (command)
{
case SwitchExit:
{
Environment.Exit(0);
break;
}
{
Environment.Exit(0);
break;
}
case SwitchMenu:
{
HandleSwitchMenuCommand(args);
break;
}
{
HandleSwitchMenuCommand(args);
break;
}
case SwitchMineGenesisBlock:
{
HandleSwitchMineGenesisBlockCommand(userInput);
break;
}
{
HandleSwitchMineGenesisBlockCommand(userInput);
break;
}
case SwitchGenerateFedPublicPrivateKeys:
{
HandleSwitchGenerateFedPublicPrivateKeysCommand(args);
break;
}
{
HandleSwitchGenerateFedPublicPrivateKeysCommand(args);
break;
}
case SwitchGenerateMultiSigAddresses:
{
HandleSwitchGenerateMultiSigAddressesCommand(args);
break;
}
{
HandleSwitchGenerateMultiSigAddressesCommand(args);
break;
}
}
}

Expand Down Expand Up @@ -151,17 +151,17 @@ private static void HandleSwitchGenerateFedPublicPrivateKeysCommand(string[] arg
isMultisig = Array.Find(args, element =>
element.StartsWith("-ismultisig=", StringComparison.Ordinal));

if (String.IsNullOrEmpty(passphrase))
if (string.IsNullOrEmpty(passphrase))
throw new ArgumentException("The -passphrase=\"<passphrase>\" argument is missing.");

passphrase = passphrase.Replace("-passphrase=", string.Empty);

//ToDo wont allow for datadir with equal sign
dataDirPath = String.IsNullOrEmpty(dataDirPath)
dataDirPath = string.IsNullOrEmpty(dataDirPath)
? Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
: dataDirPath.Replace("-datadir=", String.Empty);
: dataDirPath.Replace("-datadir=", string.Empty);

if (String.IsNullOrEmpty(isMultisig) || isMultisig.Replace("-ismultisig=", String.Empty) == "true")
if (string.IsNullOrEmpty(isMultisig) || isMultisig.Replace("-ismultisig=", string.Empty) == "true")
{
GeneratePublicPrivateKeys(passphrase, dataDirPath);
}
Expand Down Expand Up @@ -203,7 +203,7 @@ private static void HandleSwitchGenerateMultiSigAddressesCommand(string[] args)
Console.WriteLine(new MultisigAddressCreator().CreateMultisigAddresses(targetMainChain, sideChain));
}

private static void GeneratePublicPrivateKeys(string passphrase, String keyPath, bool isMultiSigOutput = true)
private static void GeneratePublicPrivateKeys(string passphrase, string keyPath, bool isMultiSigOutput = true)
{
// Generate keys for signing.
var mnemonicForSigningKey = new Mnemonic(Wordlist.English, WordCount.Twelve);
Expand Down
2 changes: 0 additions & 2 deletions src/NBitcoin.Tests/NetworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ public void StraxMainIsInitializedCorrectly()
Network network = this.straxMain;

Assert.Empty(network.Checkpoints);
Assert.Empty(network.DNSSeeds);
Assert.Empty(network.SeedNodes);

Assert.Equal("StraxMain", network.Name);
Expand Down Expand Up @@ -400,7 +399,6 @@ public void StraxTestnetIsInitializedCorrectly()
Network network = this.straxTest;

Assert.Empty(network.Checkpoints);
Assert.Empty(network.DNSSeeds);
Assert.Single(network.SeedNodes);

Assert.Equal("StraxTest", network.Name);
Expand Down
26 changes: 26 additions & 0 deletions src/NBitcoin.Tests/key_tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,31 @@ public void key_test_from_bytes()
const String expected = "5Kb8kLf9zgWQnogidDA76MzPL6TsZZY36hWXMssSzNydYXYB9KF";
Assert.True(wifKey.ToString() == expected);
}

[Fact]
[Trait("Core", "Core")]
public void can_always_recover_pubkey_from_signature_when_stopping_at_null()
{
var rand = new Random();
for (int i = 0; i < 1000; i++)
{
var key = new Key();
PosBlock block = new PosBlock(new BlockHeader() { Time = (uint)rand.Next() });
ECDSASignature signature = key.Sign(block.GetHash());
block.BlockSignature = new BlockSignature { Signature = signature.ToDER() };
Assert.True(key.PubKey.Verify(block.GetHash(), new ECDSASignature(block.BlockSignature.Signature)));
signature = ECDSASignature.FromDER(block.BlockSignature.Signature);
bool match = false;
for (int recId = 0; !match; recId++)
{
PubKey pubKeyForSig = PubKey.RecoverFromSignature(recId, signature, block.GetHash(), true);
if (pubKeyForSig == null)
break;

match = pubKeyForSig == key.PubKey;
}
Assert.True(match);
}
}
}
}
7 changes: 6 additions & 1 deletion src/NBitcoin/IStandardScriptsRegistry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using NBitcoin.BitcoinCore;

namespace NBitcoin
Expand All @@ -15,8 +16,12 @@ public interface IStandardScriptsRegistry

bool IsStandardScriptPubKey(Network network, Script scriptPubKey);

bool IsStandardScriptSig(Network network, Script scriptSig, Script scriptPubKey = null);

bool AreInputsStandard(Network network, Transaction tx, CoinsView coinsView);

List<ScriptTemplate> GetScriptTemplates { get; }

ScriptTemplate this[Type key] { get; }
}
}
5 changes: 4 additions & 1 deletion src/NBitcoin/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public abstract class Network
/// The default port on which nodes of this network communicate with external clients.
/// </summary>
public int DefaultPort { get; protected set; }

/// <summary>
/// The default port on which SignalR broadcasts for this network.
/// </summary>
Expand Down Expand Up @@ -433,6 +433,9 @@ public byte[] MagicBytes

public IFederations Federations { get; protected set; }

/// <summary> This is used for reward distribution transactions. </summary>
public string CirrusRewardDummyAddress { get; protected set; }

/// <summary>
/// Mines a new genesis block, to use with a new network.
/// Typically, 3 such genesis blocks need to be created when bootstrapping a new coin: for Main, Test and Reg networks.
Expand Down
12 changes: 6 additions & 6 deletions src/NBitcoin/Policy/StandardTransactionPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public class StandardTransactionPolicy : ITransactionPolicy
/// </summary>
public bool CheckScriptPubKey { get; set; }

private readonly Network network;
protected readonly Network Network;

public StandardTransactionPolicy(Network network)
{
this.network = network;
this.Network = network;
this.ScriptVerify = NBitcoin.ScriptVerify.Standard;
this.MaxTransactionSize = 100000;
// TODO: replace fee params with whats in Network.
Expand All @@ -78,7 +78,7 @@ public TransactionPolicyError[] Check(Transaction transaction, ICoin[] spentCoin
{
if (this.ScriptVerify != null)
{
if (!input.VerifyScript(this.network, coin.TxOut.ScriptPubKey, coin.TxOut.Value, this.ScriptVerify.Value, out ScriptError error))
if (!input.VerifyScript(this.Network, coin.TxOut.ScriptPubKey, coin.TxOut.Value, this.ScriptVerify.Value, out ScriptError error))
{
errors.Add(new ScriptPolicyError(input, error, this.ScriptVerify.Value, coin.TxOut.ScriptPubKey));
}
Expand All @@ -105,7 +105,7 @@ public TransactionPolicyError[] Check(Transaction transaction, ICoin[] spentCoin
foreach (IndexedTxIn input in transaction.Inputs.AsIndexedInputs())
{
ICoin coin = spentCoins.FirstOrDefault(s => s.Outpoint == input.PrevOut);
if (coin != null && coin.GetHashVersion(this.network) != HashVersion.Witness)
if (coin != null && coin.GetHashVersion(this.Network) != HashVersion.Witness)
errors.Add(new InputPolicyError("Malleable input detected", input));
}
}
Expand Down Expand Up @@ -158,7 +158,7 @@ protected virtual void CheckPubKey(Transaction transaction, List<TransactionPoli
{
foreach (Coin txout in transaction.Outputs.AsCoins())
{
ScriptTemplate template = this.network.StandardScriptsRegistry.GetTemplateFromScriptPubKey(txout.ScriptPubKey);
ScriptTemplate template = this.Network.StandardScriptsRegistry.GetTemplateFromScriptPubKey(txout.ScriptPubKey);

if (template == null)
errors.Add(new OutputPolicyError("Non-Standard scriptPubKey", (int)txout.Outpoint.N));
Expand Down Expand Up @@ -187,7 +187,7 @@ public static bool IsOpReturn(byte[] bytes)

public StandardTransactionPolicy Clone()
{
return new StandardTransactionPolicy(this.network)
return new StandardTransactionPolicy(this.Network)
{
MaxTransactionSize = this.MaxTransactionSize,
MaxTxFee = this.MaxTxFee,
Expand Down
Loading

0 comments on commit 939a129

Please sign in to comment.