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
18 changes: 9 additions & 9 deletions src/FedKeyPairGen/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 All @@ -31,20 +31,20 @@ public static void OutputMenu()
builder.AppendLine("Menu:");
builder.AppendLine("g Create genesis blocks for Mainnet, Testnet and Regtest.");
builder.AppendLine(" args: [-text=\"<text>\"]");
builder.AppendLine(" text: A bit of text or a url to be included in the genesis block.");
builder.AppendLine(" text: A bit of text or a url to be included in the genesis block.");
builder.AppendLine(" Example: g -text=\"https://www.coindesk.com/apple-co-founder-backs-dorsey-bitcoin-become-webs-currency/\"");
builder.AppendLine("p Create private and public keys for federation members."); // ask members to create public and private -p (for the specfic network) - 1 pubpriv for signing transactions and 1 for pubpriv key for mining
builder.AppendLine(" args: [-passphrase=<passphrase>] [-datadir=<datadir>] [-ismultisig=<bool>] (optional - space character not allowed)");
builder.AppendLine(" passphrase: a passphrase used to derive the private key from the transaction signing mnenmonic");
builder.AppendLine(" datadir: optional arg, directory where private key is saved");
builder.AppendLine(" ismultisig: optional arg, controls output");
builder.AppendLine(" Example: p -passphrase=h@rd2Gu3ss!");
builder.AppendLine(" Example: p -passphrase=h@rd2Gu3ss! -datadir=c:\\dev -ismultisig=true");
builder.AppendLine(" passphrase: a passphrase used to derive the private key from the transaction signing mnenmonic");
builder.AppendLine(" datadir: optional arg, directory where private key is saved");
builder.AppendLine(" ismultisig: optional arg, controls output");
builder.AppendLine(" Example: p -passphrase=h@rd2Gu3ss!");
builder.AppendLine(" Example: p -passphrase=h@rd2Gu3ss! -datadir=c:\\dev -ismultisig=true");
builder.AppendLine("m Create multi signature addresses for the federation wallets.");
builder.AppendLine(" args: [-network=<network>] [-quorum=<quorum>] [-fedpubkeys=<pubkey1, pubkey2, ..>]");
builder.AppendLine(" network: mainnet, testnet or regtest.");
builder.AppendLine(" quorum: The minimum number of federated members needed to sign transactions.");
builder.AppendLine(" fedpubkeys: Federation members' public keys. Must have an odd number of up to fifteen members."); // // fed admin will do -m and number (3 qurom + the public keys for the signing of transactions)
builder.AppendLine(" fedpubkeys: Federation members' public keys. Up to fifteen members."); // // fed admin will do -m and number (3 qurom + the public keys for the signing of transactions)
builder.AppendLine(" Example: m -network=testnet -quorum=2 -fedpubkeys=PublicKey1,PublicKey2,PublicKey3,PublicKey4,PublicKey5");
builder.AppendLine("menu Show this menu.");
builder.AppendLine("exit Close the utility.");
Expand Down Expand Up @@ -73,4 +73,4 @@ public static void OutputErrorLine(string message)
Console.ForegroundColor = colorSaved;
}
}
}
}
19 changes: 10 additions & 9 deletions src/FedKeyPairGen/FederationSetup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@

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

<ItemGroup>
<PackageReference Include="NStratis" Version="4.0.0.73" />
<PackageReference Include="Stratis.Bitcoin.Features.PoA" Version="3.0.0.4-beta" />
<PackageReference Include="Stratis.Bitcoin.Networks" Version="3.0.0.4-beta" />
<PackageReference Include="NStratis" Version="4.0.0.78" />
<PackageReference Include="Stratis.Core.Networks" Version="1.0.2" />
<PackageReference Include="Stratis.Features.PoA" Version="1.0.2" />
<PackageReference Include="Stratis.Features.SmartContracts" Version="1.0.2" />
<PackageReference Include="Stratis.Sidechains.Networks" Version="1.0.2.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Stratis.Sidechains.Networks\Stratis.Sidechains.Networks.csproj" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
30 changes: 5 additions & 25 deletions src/FedKeyPairGen/GenesisMiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,12 @@
using NBitcoin;
using NBitcoin.DataEncoders;
using Stratis.Bitcoin.Features.SmartContracts.PoA;
using Xunit;
using Xunit.Abstractions;
using Stratis.Sidechains.Networks;

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

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

//[Fact]
[Fact(Skip = "This is not a test, it is meant to be run upon creating a network")]
public void Run_MineGenesis()
{
var consensusFactory = new SmartContractPoAConsensusFactory();
string coinbaseText = "https://www.coindesk.com/apple-co-founder-backs-dorsey-bitcoin-become-webs-currency/";
this.output.WriteLine(this.MineGenesisBlocks(consensusFactory, coinbaseText));
}

public string MineGenesisBlocks(SmartContractPoAConsensusFactory consensusFactory, string coinbaseText)
{
var output = new StringBuilder();
Expand All @@ -37,9 +19,9 @@ public string MineGenesisBlocks(SmartContractPoAConsensusFactory consensusFactor

var targets = new Dictionary<uint256, string>
{
{ new uint256("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), "-- MainNet network --" },
{ new uint256("0000ffff00000000000000000000000000000000000000000000000000000000"), "-- TestNet network --" },
{ new uint256("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), "-- RegTest network --" }
{ new Target(CirrusNetwork.NetworksSelector.Mainnet().GenesisBits).ToUInt256(), "-- MainNet network --" },
{ new Target(CirrusNetwork.NetworksSelector.Testnet().GenesisBits).ToUInt256(), "-- TestNet network --" },
{ new Target(CirrusNetwork.NetworksSelector.Regtest().GenesisBits).ToUInt256(), "-- RegTest network --" },
};

foreach (KeyValuePair<uint256, string> target in targets)
Expand All @@ -58,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 @@ -90,11 +72,9 @@ 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;
txNew.Time = unixTime;
txNew.AddInput(new TxIn()
{
ScriptSig = new Script(
Expand Down
34 changes: 2 additions & 32 deletions src/FedKeyPairGen/MultisigAddressCreator.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
using System.Text;
using NBitcoin;
using NBitcoin.DataEncoders;
using Stratis.Bitcoin.Networks;
using Stratis.Sidechains.Networks;
using Xunit;
using Xunit.Abstractions;

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

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

[Fact(Skip = "This is not a test, it is meant to be run upon creating a network")]
public void Run_CreateMultisigAddresses()
{
Network mainchainNetwork = Networks.Stratis.Testnet();
Network sidechainNetwork = FederatedPegNetwork.NetworksSelector.Testnet();

// Create a mnemonic and get the corresponding pubKey.
var pubKeys = new PubKey[1];
var mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve);
pubKeys[0] = mnemonic.DeriveExtKey().PrivateKey.PubKey;

this.output.WriteLine($"Mnemonic - Please note the following 12 words down in a secure place: {string.Join(" ", mnemonic.Words)}");
this.output.WriteLine($"PubKey - Please share the following public key with the person responsible for the sidechain generation: {Encoders.Hex.EncodeData((pubKeys[0]).ToBytes(false))}");

this.output.WriteLine(this.CreateMultisigAddresses(mainchainNetwork, sidechainNetwork, pubKeys));
}

public string CreateMultisigAddresses(Network mainchainNetwork, Network sidechainNetwork, PubKey[] pubKeys, int quorum = 3)
public string CreateMultisigAddresses(Network mainchainNetwork, Network sidechainNetwork)
{
var output = new StringBuilder();

Script payToMultiSig = PayToMultiSigTemplate.Instance.GenerateScriptPubKey(quorum, pubKeys);
Script payToMultiSig = PayToFederationTemplate.Instance.GenerateScriptPubKey(sidechainNetwork.Federations.GetOnlyFederation().Id);
output.AppendLine("Redeem script: " + payToMultiSig.ToString());

BitcoinAddress sidechainMultisigAddress = payToMultiSig.Hash.GetAddress(sidechainNetwork);
Expand Down
Loading