Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Commit

Permalink
Remove FederationFolder logic and use FederationGatewaySettings inste…
Browse files Browse the repository at this point in the history
…ad (#31)

* upgrade nuget 1.1.7 to 1.1.9 and 4.0.0.57 and 4.0.0.58

* add NLog

* added CoinbaseMaturity, PremineReward, pow reward, pos reward and max reorg for the apex network.

* Add new network properties to Apex

* Update ApexNetwork.cs

* Update ApexNetwork.cs

* little code cleanups

* remove the FederationMemberFolder logic, use FederationGatewaySettings instead

* update comment

* remove unused parameters

* Revert "remove unused parameters"

This reverts commit 091504c1821e3050875aeaf681c7dbb3ba9d7e8f.

* remove unused parameters - without unwanted changes this time
  • Loading branch information
monsieurleberre authored and zeptin committed Jun 16, 2018
1 parent ca6330a commit 9f469ee
Show file tree
Hide file tree
Showing 5 changed files with 1,253 additions and 1,265 deletions.
55 changes: 27 additions & 28 deletions Helpers/ApiCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Newtonsoft.Json;
using Stratis.Bitcoin.Features.Wallet.Models;
using Stratis.Bitcoin.Utilities.JsonErrors;
using Stratis.FederatedPeg.Features.MainchainGeneratorServices.Models;

namespace Stratis.FederatedPeg.IntegrationTests
{
Expand All @@ -22,33 +21,33 @@ public JsonContent(object obj) :
}
}

public static async Task InitSidechain(string sidechainName, int apiPortForMainchain, int apiPortForSidechain, int multiSigN, int multiSigM, string folderFedMemberKey)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

var initSidechainRequest = new InitSidechainRequest();
initSidechainRequest.SidechainName = sidechainName;
initSidechainRequest.ApiPortForSidechain = apiPortForSidechain;
initSidechainRequest.MultiSigN = multiSigN;
initSidechainRequest.MultiSigM = multiSigM;
initSidechainRequest.FolderFedMemberKeys = folderFedMemberKey;

var uri = new Uri($"http://localhost:{apiPortForMainchain}/api/MainchainGeneratorServices/init-sidechain");
var request = new JsonContent(initSidechainRequest);
var httpResponseMessage = await client.PostAsync(uri, request);

if (!httpResponseMessage.IsSuccessStatusCode)
{
string content = await httpResponseMessage.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<ErrorResponse>(content);
string message = result.Errors[0].Message;
throw new Exception(message);
}
}
}
//public static async Task InitSidechain(string sidechainName, int apiPortForMainchain, int apiPortForSidechain, int multiSigN, int multiSigM, string folderFedMemberKey)
//{
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Accept.Clear();
// client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

// var initSidechainRequest = new InitSidechainRequest();
// initSidechainRequest.SidechainName = sidechainName;
// initSidechainRequest.ApiPortForSidechain = apiPortForSidechain;
// initSidechainRequest.MultiSigN = multiSigN;
// initSidechainRequest.MultiSigM = multiSigM;
// initSidechainRequest.FolderFedMemberKeys = folderFedMemberKey;

// var uri = new Uri($"http://localhost:{apiPortForMainchain}/api/MainchainGeneratorServices/init-sidechain");
// var request = new JsonContent(initSidechainRequest);
// var httpResponseMessage = await client.PostAsync(uri, request);

// if (!httpResponseMessage.IsSuccessStatusCode)
// {
// string content = await httpResponseMessage.Content.ReadAsStringAsync();
// var result = JsonConvert.DeserializeObject<ErrorResponse>(content);
// string message = result.Errors[0].Message;
// throw new Exception(message);
// }
// }
//}

public static async Task<string> Mnemonic(int apiPortForSidechain)
{
Expand Down
288 changes: 144 additions & 144 deletions Helpers/IntegrationTestUtils.cs
Original file line number Diff line number Diff line change
@@ -1,144 +1,144 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using NBitcoin;
using Stratis.Bitcoin.Connection;
using Stratis.Bitcoin.Features.Wallet.Interfaces;
using Stratis.Bitcoin.IntegrationTests.Common.EnvironmentMockUpHelpers;
using Stratis.Bitcoin.P2P.Peer;
using Stratis.FederatedPeg.Features.FederationGateway.Interfaces;
using Stratis.FederatedPeg.Features.FederationGateway.Wallet;

//using CoreNode = Stratis.Bitcoin.

namespace Stratis.FederatedPeg.IntegrationTests.Helpers
{
internal class IntegrationTestUtils
{
public static void RunFedKeyPairGen(string name, string passPhrase, string folder = null, [CallerMemberName] string caller = null)
{
if (folder == null) folder = $"Federations\\{caller}";

var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"..\\..\\..\\..\\FedKeyPairGen\\bin\\Release\\PublishOutput\\FedKeyPairGen.dll -name={name} -pass={passPhrase} -folder={folder}",
UseShellExecute = true,
RedirectStandardOutput = false,
RedirectStandardError = false,
CreateNoWindow = true
}
};

//this call assumes you have used DotNet Publish to publish the FedKeyPairGen.
process.Start();
}

public static void DistributeKeys(string memberFolder)
{
var memberFolderManager = new MemberFolderManager(memberFolder);
var members = memberFolderManager.LoadMembers();

int memberFolderName = 1;
foreach (var member in members)
{
//create a folder for the member and copy his files there
//this represents the folder on a federation gateway where a member keeps his keys
//copy his public key
//copy his private key
//copy the multisig public address
//copy the multisig scriptpubkey

//member photo
var mainchainDest = Directory.CreateDirectory($"{memberFolder}\\{memberFolderName}\\Mainchain");
var sidechainDest = Directory.CreateDirectory($"{memberFolder}\\{memberFolderName}\\Sidechain");

File.Copy(Path.Combine(memberFolder, $"PUBLIC_mainchain_{member.Name}.txt"), Path.Combine(mainchainDest.FullName, $"PUBLIC_mainchain_{member.Name}.txt"));
File.Copy(Path.Combine(memberFolder, $"PUBLIC_sidechain_{member.Name}.txt"), Path.Combine(sidechainDest.FullName, $"PUBLIC_sidechain_{member.Name}.txt"));

File.Copy(Path.Combine(memberFolder, $"PRIVATE_DO_NOT_SHARE_mainchain_{member.Name}.txt"), Path.Combine(mainchainDest.FullName, $"PRIVATE_DO_NOT_SHARE_mainchain_{member.Name}.txt"));
File.Copy(Path.Combine(memberFolder, $"PRIVATE_DO_NOT_SHARE_sidechain_{member.Name}.txt"), Path.Combine(sidechainDest.FullName, $"PRIVATE_DO_NOT_SHARE_sidechain_{member.Name}.txt"));

File.Copy(Path.Combine(memberFolder, "Mainchain_ScriptPubKey.txt"), Path.Combine(mainchainDest.FullName, "Mainchain_ScriptPubKey.txt"));
File.Copy(Path.Combine(memberFolder, "Sidechain_ScriptPubKey.txt"), Path.Combine(sidechainDest.FullName, "Sidechain_ScriptPubKey.txt"));

File.Copy(Path.Combine(memberFolder, "Mainchain_Address.txt"), Path.Combine(mainchainDest.FullName, "Mainchain_Address.txt"));
File.Copy(Path.Combine(memberFolder, "Sidechain_Address.txt"), Path.Combine(sidechainDest.FullName, "Sidechain_Address.txt"));

++memberFolderName;
}
}

public static void CreateScriptAndAddress(string memberfolder, Network network)
{
var memberFolderManager = new MemberFolderManager(memberfolder);
var federation = memberFolderManager.LoadFederation(2, 3);
memberFolderManager.OutputScriptPubKeyAndAddress(federation, network);
memberFolderManager.OutputScriptPubKeyAndAddress(federation, network);
}

public static async Task WaitLoop(Func<bool> act)
{
var cancel = new CancellationTokenSource(Debugger.IsAttached ? 15 * 60 * 1000 : 30 * 1000);
while (!act())
{
cancel.Token.ThrowIfCancellationRequested();
await Task.Delay(50);
}
}

public static bool AreNodesSynced(CoreNode node1, CoreNode node2)
{
if (node1.FullNode.Chain.Tip.HashBlock != node2.FullNode.Chain.Tip.HashBlock) return false;
if (node1.FullNode.ChainBehaviorState.ConsensusTip.HashBlock != node2.FullNode.ChainBehaviorState.ConsensusTip.HashBlock) return false;
if (node1.FullNode.GetBlockStoreTip().HashBlock != node2.FullNode.GetBlockStoreTip().HashBlock) return false;
if (node1.FullNode.MempoolManager().InfoAll().Count != node2.FullNode.MempoolManager().InfoAll().Count) return false;
if (node1.FullNode.WalletManager().WalletTipHash != node2.FullNode.WalletManager().WalletTipHash) return false;
if (node1.CreateRPCClient().GetBestBlockHash() != node2.CreateRPCClient().GetBestBlockHash()) return false;
return true;
}

private static IFederationWalletManager GetGeneralWalletManager(CoreNode node)
{
return node.FullNode.NodeService<IFederationWalletManager>();
}

public static bool AreNodeGeneralWalletsSynced(CoreNode node1, CoreNode node2)
{
return IntegrationTestUtils.GetGeneralWalletManager(node1).WalletTipHash == IntegrationTestUtils.GetGeneralWalletManager(node2).WalletTipHash;
}

public static void ResyncGeneralWallet(CoreNode node)
{
var federationWalletSyncManager = node.FullNode.NodeService<IFederationWalletSyncManager>();
federationWalletSyncManager.SyncFromHeight(0);
}

public static bool IsGeneralWalletSyncedToHeight(CoreNode node, int height)
{
var generalWalletManager = node.FullNode.NodeService<IFederationWalletManager>() as FederationWalletManager;
return generalWalletManager.LastBlockHeight() >= height;
}

//todo: duplication
public static void SaveGeneralWallet(CoreNode node, string walletName)
{
var generalWalletManager = node.FullNode.NodeService<IFederationWalletManager>() as FederationWalletManager;
var wallet = generalWalletManager.GetWallet();
generalWalletManager.SaveWallet();
}

public static bool AreConnected(CoreNode node1, CoreNode node2)
{
var connectionManager = node1.FullNode.NodeService<IConnectionManager>();
foreach (INetworkPeer peer in connectionManager.ConnectedPeers)
if (peer.PeerEndPoint.Port == node2.Endpoint.Port) return true;
return false;
}
}
}
//using System;
//using System.Diagnostics;
//using System.IO;
//using System.Runtime.CompilerServices;
//using System.Threading;
//using System.Threading.Tasks;
//using NBitcoin;
//using Stratis.Bitcoin.Connection;
//using Stratis.Bitcoin.Features.Wallet.Interfaces;
//using Stratis.Bitcoin.IntegrationTests.Common.EnvironmentMockUpHelpers;
//using Stratis.Bitcoin.P2P.Peer;
//using Stratis.FederatedPeg.Features.FederationGateway.Interfaces;
//using Stratis.FederatedPeg.Features.FederationGateway.Wallet;

////using CoreNode = Stratis.Bitcoin.

//namespace Stratis.FederatedPeg.IntegrationTests.Helpers
//{
// internal class IntegrationTestUtils
// {
// public static void RunFedKeyPairGen(string name, string passPhrase, string folder = null, [CallerMemberName] string caller = null)
// {
// if (folder == null) folder = $"Federations\\{caller}";

// var process = new Process
// {
// StartInfo = new ProcessStartInfo
// {
// FileName = "dotnet",
// Arguments = $"..\\..\\..\\..\\FedKeyPairGen\\bin\\Release\\PublishOutput\\FedKeyPairGen.dll -name={name} -pass={passPhrase} -folder={folder}",
// UseShellExecute = true,
// RedirectStandardOutput = false,
// RedirectStandardError = false,
// CreateNoWindow = true
// }
// };

// //this call assumes you have used DotNet Publish to publish the FedKeyPairGen.
// process.Start();
// }

// public static void DistributeKeys(string memberFolder)
// {
// var memberFolderManager = new MemberFolderManager(memberFolder);
// var members = memberFolderManager.LoadMembers();

// int memberFolderName = 1;
// foreach (var member in members)
// {
// //create a folder for the member and copy his files there
// //this represents the folder on a federation gateway where a member keeps his keys
// //copy his public key
// //copy his private key
// //copy the multisig public address
// //copy the multisig scriptpubkey

// //member photo
// var mainchainDest = Directory.CreateDirectory($"{memberFolder}\\{memberFolderName}\\Mainchain");
// var sidechainDest = Directory.CreateDirectory($"{memberFolder}\\{memberFolderName}\\Sidechain");

// File.Copy(Path.Combine(memberFolder, $"PUBLIC_mainchain_{member.Name}.txt"), Path.Combine(mainchainDest.FullName, $"PUBLIC_mainchain_{member.Name}.txt"));
// File.Copy(Path.Combine(memberFolder, $"PUBLIC_sidechain_{member.Name}.txt"), Path.Combine(sidechainDest.FullName, $"PUBLIC_sidechain_{member.Name}.txt"));

// File.Copy(Path.Combine(memberFolder, $"PRIVATE_DO_NOT_SHARE_mainchain_{member.Name}.txt"), Path.Combine(mainchainDest.FullName, $"PRIVATE_DO_NOT_SHARE_mainchain_{member.Name}.txt"));
// File.Copy(Path.Combine(memberFolder, $"PRIVATE_DO_NOT_SHARE_sidechain_{member.Name}.txt"), Path.Combine(sidechainDest.FullName, $"PRIVATE_DO_NOT_SHARE_sidechain_{member.Name}.txt"));

// File.Copy(Path.Combine(memberFolder, "Mainchain_ScriptPubKey.txt"), Path.Combine(mainchainDest.FullName, "Mainchain_ScriptPubKey.txt"));
// File.Copy(Path.Combine(memberFolder, "Sidechain_ScriptPubKey.txt"), Path.Combine(sidechainDest.FullName, "Sidechain_ScriptPubKey.txt"));

// File.Copy(Path.Combine(memberFolder, "Mainchain_Address.txt"), Path.Combine(mainchainDest.FullName, "Mainchain_Address.txt"));
// File.Copy(Path.Combine(memberFolder, "Sidechain_Address.txt"), Path.Combine(sidechainDest.FullName, "Sidechain_Address.txt"));

// ++memberFolderName;
// }
// }

// public static void CreateScriptAndAddress(string memberfolder, Network network)
// {
// var memberFolderManager = new MemberFolderManager(memberfolder);
// var federation = memberFolderManager.LoadFederation(2, 3);
// memberFolderManager.OutputScriptPubKeyAndAddress(federation, network);
// memberFolderManager.OutputScriptPubKeyAndAddress(federation, network);
// }

// public static async Task WaitLoop(Func<bool> act)
// {
// var cancel = new CancellationTokenSource(Debugger.IsAttached ? 15 * 60 * 1000 : 30 * 1000);
// while (!act())
// {
// cancel.Token.ThrowIfCancellationRequested();
// await Task.Delay(50);
// }
// }

// public static bool AreNodesSynced(CoreNode node1, CoreNode node2)
// {
// if (node1.FullNode.Chain.Tip.HashBlock != node2.FullNode.Chain.Tip.HashBlock) return false;
// if (node1.FullNode.ChainBehaviorState.ConsensusTip.HashBlock != node2.FullNode.ChainBehaviorState.ConsensusTip.HashBlock) return false;
// if (node1.FullNode.GetBlockStoreTip().HashBlock != node2.FullNode.GetBlockStoreTip().HashBlock) return false;
// if (node1.FullNode.MempoolManager().InfoAll().Count != node2.FullNode.MempoolManager().InfoAll().Count) return false;
// if (node1.FullNode.WalletManager().WalletTipHash != node2.FullNode.WalletManager().WalletTipHash) return false;
// if (node1.CreateRPCClient().GetBestBlockHash() != node2.CreateRPCClient().GetBestBlockHash()) return false;
// return true;
// }

// private static IFederationWalletManager GetGeneralWalletManager(CoreNode node)
// {
// return node.FullNode.NodeService<IFederationWalletManager>();
// }

// public static bool AreNodeGeneralWalletsSynced(CoreNode node1, CoreNode node2)
// {
// return IntegrationTestUtils.GetGeneralWalletManager(node1).WalletTipHash == IntegrationTestUtils.GetGeneralWalletManager(node2).WalletTipHash;
// }

// public static void ResyncGeneralWallet(CoreNode node)
// {
// var federationWalletSyncManager = node.FullNode.NodeService<IFederationWalletSyncManager>();
// federationWalletSyncManager.SyncFromHeight(0);
// }

// public static bool IsGeneralWalletSyncedToHeight(CoreNode node, int height)
// {
// var generalWalletManager = node.FullNode.NodeService<IFederationWalletManager>() as FederationWalletManager;
// return generalWalletManager.LastBlockHeight() >= height;
// }

// //todo: duplication
// public static void SaveGeneralWallet(CoreNode node, string walletName)
// {
// var generalWalletManager = node.FullNode.NodeService<IFederationWalletManager>() as FederationWalletManager;
// var wallet = generalWalletManager.GetWallet();
// generalWalletManager.SaveWallet();
// }

// public static bool AreConnected(CoreNode node1, CoreNode node2)
// {
// var connectionManager = node1.FullNode.NodeService<IConnectionManager>();
// foreach (INetworkPeer peer in connectionManager.ConnectedPeers)
// if (peer.PeerEndPoint.Port == node2.Endpoint.Port) return true;
// return false;
// }
// }
//}
Loading

0 comments on commit 9f469ee

Please sign in to comment.