Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple refactoring in general. #69

Draft
wants to merge 2 commits into
base: staging
Choose a base branch
from
Draft
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
31 changes: 13 additions & 18 deletions Discreet/Coin/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public uint Size()
return size;
}

/* for testing purposes only */
public static Block BuildRandom(StealthAddress[] addresses, int[] numOutputs)
private static Block BuildTransactions(
List<FullTransaction> txs,
StealthAddress[] addresses,
int[] numOutputs)
{
List<FullTransaction> txs = new();

for (int i = 0; i < addresses.Length; i++)
{
for (int j = 0; j < numOutputs[i] / 16; j++)
Expand All @@ -128,24 +128,19 @@ public static Block BuildRandom(StealthAddress[] addresses, int[] numOutputs)
return Build(txs, null, default);
}

public static Block BuildRandomPlus(StealthAddress[] addresses, int[] numOutputs, List<FullTransaction> txExtras)
/* for testing purposes only */
public static Block BuildRandom(StealthAddress[] addresses, int[] numOutputs)
{
List<FullTransaction> txs = txExtras;
List<FullTransaction> txs = new();

for (int i = 0; i < addresses.Length; i++)
{
for (int j = 0; j < numOutputs[i] / 16; j++)
{
txs.Add(Transaction.GenerateRandomNoSpend(addresses[i], 16).ToFull());
}
return BuildTransactions(txs, addresses, numOutputs);
}

if (numOutputs[i] % 16 != 0)
{
txs.Add(Transaction.GenerateRandomNoSpend(addresses[i], numOutputs[i] % 16).ToFull());
}
}
public static Block BuildRandomPlus(StealthAddress[] addresses, int[] numOutputs, List<FullTransaction> txExtras)
{
List<FullTransaction> txs = txExtras;

return Build(txs, null, default);
return BuildTransactions(txs, addresses, numOutputs);
}

public static Block Build(List<FullTransaction> txs, StealthAddress miner, Key signingKey)
Expand Down
43 changes: 25 additions & 18 deletions Discreet/Daemon/Daemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -852,31 +852,38 @@ public void BuildGenesis()
Logger.Info("Successfully created the genesis block.");
}

/// <summary>
/// AskBootstrapNode repeatedly asks the user for a valid bootstrap node
/// address, until the user provides a valid address.
/// </summary>
/// <param name="config">An object holding the node's configuration.</param>
/// <returns>A validated address.</returns>
private static string AskBootstrapNode(DaemonConfig config)
{
while (true)
{
try
{
Console.Write("Boostrap node: ");
IPAddress[] resolvedDNS = Dns.GetHostAddresses(Console.ReadLine());

return resolvedDNS[0].ToString();
}
catch (Exception)
{
Logger.Error("Not a valid bootstrap node. Network might be temporarily down for maintenance.");
}
}
}

public static Daemon Init()
{
var config = DaemonConfig.GetConfig();
DebugMode = config.DbgConfig.DebugMode.Value;

if (config.BootstrapNode == null)
{

bool didResolve = false;

while (!didResolve)
{
try
{
Console.Write("Boostrap node: ");
IPAddress[] resolvedDNS = Dns.GetHostAddresses(Console.ReadLine());

config.BootstrapNode = resolvedDNS[0].ToString();
didResolve = true;
}
catch (Exception)
{
Logger.Error("Not a valid bootstrap node. Network might be temporarily down for maintenance.");
}
}
config.BootstrapNode = AskBootstrapNode(config);
}

DaemonConfig.SetConfig(config);
Expand Down