Skip to content

Commit

Permalink
Merge pull request #177 from ReserveBlockIO/staging
Browse files Browse the repository at this point in the history
Staging to Main (P2P auctions, NFT Sales, and RSRV Account pre-Commit)
  • Loading branch information
mathis1337 committed Apr 20, 2023
2 parents 92a03ad + 54a288d commit 475b2eb
Show file tree
Hide file tree
Showing 74 changed files with 12,060 additions and 301 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,8 @@ information or see https://opensource.org/licenses/MIT.
* Darren Starr for RIPEMD160 Library
* Brian A. Danielak for Contribution Guidelines
* dotnetstandard for BIP32/39
* Alex Williams for In Memory Variables and network wide audit
* Bitcoin source
* Docnet.Core
* Magick.Net-Q16
* Swagger
* Trillium [Source Code](https://github.com/ReserveBlockIO/Trillium)
* Bitcoin source [Source Code](https://github.com/bitcoin/bitcoin)
24 changes: 22 additions & 2 deletions ReserveBlockCore/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using ReserveBlockCore.P2P;
using System.Runtime.InteropServices;
using Spectre.Console;
using ReserveBlockCore.DST;

namespace ReserveBlockCore.Commands
{
Expand Down Expand Up @@ -54,6 +55,12 @@ internal static async Task<string> ProcessCommand(string command, string? comman
case "/clear":
Console.Clear();
break;
case "/chat":
Console.Clear();
Globals.StopConsoleOutput = true;
_ = Chat.Run();
Globals.StopConsoleOutput = false;
break;
case "/update":
Globals.StopConsoleOutput = true;
await VersionControlService.DownloadLatestRelease();
Expand Down Expand Up @@ -251,7 +258,9 @@ internal static async Task<string> ProcessCommand(string command, string? comman
}
Globals.StopConsoleOutput = false;
break;

case "/test1":
await DSTClient.ConnectToShopForAssets();
break;
case "1": // Genesis Block (check)
var genBlock = BlockchainData.GetGenesisBlock();
BlockchainData.PrintBlock(genBlock);
Expand All @@ -260,6 +269,12 @@ internal static async Task<string> ProcessCommand(string command, string? comman
await BaseCommandServices.CreateAddress();
Console.WriteLine("Please type /menu to return to mainscreen.");
break;
case "2r": // Create Reserve Account Account
Globals.StopConsoleOutput = true;
Console.WriteLine("Please type /menu to return to mainscreen.");
await BaseCommandServices.CreateReserveAddress();
Globals.StopConsoleOutput = false;
break;
case "2hd": // Create HD Wallet
Globals.StopConsoleOutput = true;
var mnemonic = BaseCommandServices.CreateHDWallet();
Expand Down Expand Up @@ -324,7 +339,12 @@ internal static async Task<string> ProcessCommand(string command, string? comman
}
Globals.StopConsoleOutput = false;
break;
case "3hd": // Create HD Wallet
case "3r": // Restore reserve account
Globals.StopConsoleOutput = true;
BaseCommandServices.RestoreReserveAccount();
Globals.StopConsoleOutput = false;
break;
case "3hd": // restore HD Wallet
Globals.StopConsoleOutput = true;
var mnemonicRestore = BaseCommandServices.RestoreHDWallet();
Console.WriteLine("-----------------------HD Wallet Process Result------------------------");
Expand Down
142 changes: 141 additions & 1 deletion ReserveBlockCore/Commands/BaseCommandServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Numerics;
using ReserveBlockCore.EllipticCurve;
using System;
using System.Security.Principal;

namespace ReserveBlockCore.Commands
{
Expand Down Expand Up @@ -911,6 +912,12 @@ public static async Task ValidatorInfo()
}

}

var lastBlockWon = Globals.LastWonBlock;
if(lastBlockWon != null)
{
AnsiConsole.MarkupLine($"Last Block Won: [green]{lastBlockWon.Height}[/] | Time: [yellow]{lastBlockWon.Timestamp.ToLocalDateTimeFromUnix()}[/]");
}
}
else
{
Expand Down Expand Up @@ -1498,6 +1505,46 @@ public static async Task<string> TransferDnr()

}

public static async Task CreateReserveAddress()
{
try
{
Console.WriteLine("Please input a password for your Reserve Account.");
var password = await ReadLineUtility.ReadLine();

AnsiConsole.MarkupLine($"Do you want to store the recovery address in wallet? [green]'y'[/] for [green]yes[/] and [red]'n'[/] for [red]no[/]");
var confirm = await ReadLineUtility.ReadLine();

if(!string.IsNullOrEmpty(password))
{
if(!string.IsNullOrEmpty(confirm))
{
var storeRecoveryKey = confirm.ToLower() == "y" ? true : false;
var result = ReserveAccount.CreateNewReserveAccount(password, storeRecoveryKey);

if(result != null)
{
Console.Clear();
Console.WriteLine("\n\n\nYour Wallet");
Console.WriteLine("======================");
Console.WriteLine("\nAddress :\n{0}", result.Address);
Console.WriteLine("\nRecovery Address:\n{0}", result.RecoveryAddress);
Console.WriteLine("\nPrivate Key:\n{0}", result.PrivateKey);
Console.WriteLine("\nRecovery Private Key:\n{0}", result.RecoveryPrivateKey);
Console.WriteLine("\nRestore Code:\n{0}", result.RestoreCode);
Console.WriteLine("\n - - - - - - - - - - - - - - - - - - - - - - ");
Console.WriteLine("*** Be sure to save private key and Restore Code! ***");
Console.WriteLine("*** Use your private key to restore account! ***");
}
}

}

}
catch(Exception ex) { }

}

public static async Task CreateAddress()
{
if (Globals.HDWallet == true)
Expand Down Expand Up @@ -1668,6 +1715,97 @@ public static async Task<string> DeleteDnr()

}

public static async Task RestoreReserveAccount()
{
try
{
ReserveAccount.ReserveAccountInfo? rInfo = null;

Console.WriteLine("1. Restore from 'Restore Code'.");
Console.WriteLine("2. Restore from two private keys.");
Console.WriteLine("Please choose option 1. to restore from a code, or option 2. to restore from two private keys");

var choice = await ReadLineUtility.ReadLine();

if(!string.IsNullOrEmpty(choice))
{
Console.WriteLine("Please input a password for your Reserve Account.");
var password = await ReadLineUtility.ReadLine();

AnsiConsole.MarkupLine($"Do you want to store the recovery address in wallet? [green]'y'[/] for [green]yes[/] and [red]'n'[/] for [red]no[/]");
var confirm = await ReadLineUtility.ReadLine();

AnsiConsole.MarkupLine($"Do you want to rescan for TXs? [green]'y'[/] for [green]yes[/] and[red]'n'[/] for [red]no[/]");
var rescanForTx = await ReadLineUtility.ReadLine();
var rescan = rescanForTx?.ToLower() == "y" ? true : false;

if (!string.IsNullOrEmpty(password))
{
if (!string.IsNullOrEmpty(confirm))
{
var storeRecoveryKey = confirm.ToLower() == "y" ? true : false;
if (choice == "1")
{
Console.WriteLine("Please input your restore code.");
var restoreCode = await ReadLineUtility.ReadLine();

if(!string.IsNullOrEmpty(restoreCode))
{
var result = await ReserveAccount.RestoreReserveAccount(restoreCode, password, storeRecoveryKey, rescan);
if(result != null)
{
rInfo = new ReserveAccount.ReserveAccountInfo();
rInfo = result;
}
}
}
if (choice == "2")
{
Console.WriteLine("Please input your reserve account private key first.");
var firstKey = await ReadLineUtility.ReadLine();

Console.WriteLine("Please input your recovery account private key now.");
var secondKey = await ReadLineUtility.ReadLine();

if(!string.IsNullOrEmpty(firstKey) && !string.IsNullOrEmpty(secondKey))
{
var result = await ReserveAccount.RestoreReserveAccount(firstKey, secondKey, password, storeRecoveryKey, rescan);
if (result != null)
{
rInfo = new ReserveAccount.ReserveAccountInfo();
rInfo = result;
}
}
}
}
}
}

if(rInfo != null)
{
Console.Clear();
Console.WriteLine("\n\n\nYour Wallet");
Console.WriteLine("======================");
Console.WriteLine("\nAddress :\n{0}", rInfo.Address);
Console.WriteLine("\nRecovery Address:\n{0}", rInfo.RecoveryAddress);
Console.WriteLine("\nPrivate Key:\n{0}", rInfo.PrivateKey);
Console.WriteLine("\nRecovery Private Key:\n{0}", rInfo.RecoveryPrivateKey);
Console.WriteLine("\nRestore Code:\n{0}", rInfo.RestoreCode);
Console.WriteLine("\n - - - - - - - - - - - - - - - - - - - - - - ");
Console.WriteLine("*** Be sure to save private key and Restore Code! ***");
Console.WriteLine("*** Use your private key to restore account! ***");
}
else
{
Console.WriteLine("There was an issue restoring your Reserve Account. Please verify key/code is correct.");
}
}
catch (Exception ex)
{
Console.WriteLine($"Unknown error restoring account. Error: {ex.ToString()}");
}
}

public static string RestoreHDWallet()
{
Console.WriteLine("Please paste your Mnemonic Below...");
Expand Down Expand Up @@ -1720,6 +1858,7 @@ public static void AddBadTx()
foreach (int i in Enum.GetValues(typeof(TransactionType)))
{
Console.WriteLine($"{count} - {i}");
count += 1;
}

var badTxTranType = Console.ReadLine();
Expand Down Expand Up @@ -1980,10 +2119,11 @@ public static void PrintHelpMenu()
table.AddRow("[blue]/findtx[/]", "[green]This is a heavy query to find a specific TX in all blocks.[/]");
table.AddRow("[blue]/vote[/]", "[green]This will start the voting program.[/]");
table.AddRow("[blue]/resblocks[/]", "[green]Resyncs the blocks to ensure you are at max height.[/]");
table.AddRow("[blue]/mother[/]", "[green]This will create a mother host.[/]");
table.AddRow("[blue]/mother[/]", "[green]This will create a mother host. This will also take you main screen for mother after setup.[/]");
table.AddRow("[blue]1[/]", "[green]This will print out the Genesis block[/]");
table.AddRow("[blue]2[/]", "[green]This will create a new account.[/]");
table.AddRow("[blue]2hd[/]", "[green]This will create an HD wallet.[/]");
table.AddRow("[blue]2r[/]", "[green]This will create an Reserve Account.[/]");
table.AddRow("[blue]3[/]", "[green]This will restore an account with a provided key.[/]");
table.AddRow("[blue]3hd[/]", "[green]Restores an HD wallet with a provided Mnemonic (12 or 24 words).[/]");
table.AddRow("[blue]4[/]", "[green]This will start an RBX transactions for coins only.[/]");
Expand Down
54 changes: 52 additions & 2 deletions ReserveBlockCore/Config/Config.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using ReserveBlockCore.Utilities;
using Microsoft.AspNetCore.Hosting.Server;
using ReserveBlockCore.Models;
using ReserveBlockCore.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -38,6 +40,10 @@ public class Config
public bool RefuseToCallSeed { get; set; }
public bool OpenAPI { get; set; }
public bool RunUnsafeCode { get; set; }
public int DSTClientPort { get; set; }
public string? STUNServers { get; set; }
public bool SelfSTUNServer { get; set; }
public int SelfSTUNPort { get; set; }
public static Config ReadConfigFile()
{
var path = GetPathUtility.GetConfigPath();
Expand Down Expand Up @@ -89,6 +95,10 @@ public static Config ReadConfigFile()
config.RefuseToCallSeed = dict.ContainsKey("RefuseToCallSeed") ? Convert.ToBoolean(dict["RefuseToCallSeed"]) : false;
config.OpenAPI = dict.ContainsKey("OpenAPI") ? Convert.ToBoolean(dict["OpenAPI"]) : false;
config.RunUnsafeCode = dict.ContainsKey("RunUnsafeCode") ? Convert.ToBoolean(dict["RunUnsafeCode"]) : false;
config.DSTClientPort = dict.ContainsKey("DSTClientPort") ? Convert.ToInt32(dict["DSTClientPort"]) : 3341;
config.STUNServers = dict.ContainsKey("STUNServers") ? dict["STUNServers"] : null;
config.SelfSTUNServer = dict.ContainsKey("STUN") ? Convert.ToBoolean(dict["STUN"]) : false;
config.DSTClientPort = dict.ContainsKey("SelfSTUNPort") ? Convert.ToInt32(dict["SelfSTUNPort"]) : 3340;


config.AutoDownloadNFTAsset = dict.ContainsKey("AutoDownloadNFTAsset") ? Convert.ToBoolean(dict["AutoDownloadNFTAsset"]) : false;
Expand Down Expand Up @@ -164,6 +174,42 @@ public static void ProcessConfig(Config config)
Globals.RefuseToCallSeed = config.RefuseToCallSeed;
Globals.OpenAPI = Globals.OpenAPI != true ? config.OpenAPI : true;
Globals.RunUnsafeCode = config.RunUnsafeCode;
Globals.DSTClientPort = config.DSTClientPort;
Globals.SelfSTUNPort = config.SelfSTUNPort;
Globals.SelfSTUNServer = Globals.SelfSTUNServer == true ? true : config.SelfSTUNServer;

if (config.STUNServers?.Count() > 0)
{
var serverList = config.STUNServers.Split(',');
foreach( var server in serverList)
{
Globals.STUNServers.Add(new StunServer { ServerIPPort = server, Group = 999, IsNetwork = false });
}
}
else
{
var port = Globals.IsTestNet ? 13340 : 3440;

if(!Globals.IsTestNet)
{
Globals.STUNServers.Add(new StunServer { ServerIPPort = $"162.248.14.123:{port}", Group = 1, IsNetwork = true});
Globals.STUNServers.Add(new StunServer { ServerIPPort = $"144.126.149.104:{port}", Group = 1, IsNetwork = true });
Globals.STUNServers.Add(new StunServer { ServerIPPort = $"144.126.150.118:{port}", Group = 2, IsNetwork = true });
Globals.STUNServers.Add(new StunServer { ServerIPPort = $"89.117.21.39:{port}", Group = 2, IsNetwork = true });
Globals.STUNServers.Add(new StunServer { ServerIPPort = $"89.117.21.40:{port}", Group = 3, IsNetwork = true });
Globals.STUNServers.Add(new StunServer { ServerIPPort = $"209.126.11.92:{port}", Group = 3, IsNetwork = true });
Globals.STUNServers.Add(new StunServer { ServerIPPort = $"149.102.144.58:{port}", Group = 4, IsNetwork = true });
Globals.STUNServers.Add(new StunServer { ServerIPPort = $"194.233.77.39:{port}", Group = 4, IsNetwork = true });
Globals.STUNServers.Add(new StunServer { ServerIPPort = $"185.188.249.117:{port}", Group = 5, IsNetwork = true });
Globals.STUNServers.Add(new StunServer { ServerIPPort = $"154.26.155.35:{port}", Group = 5, IsNetwork = true });

Globals.STUNServers.Add(new StunServer { ServerIPPort = $"173.254.253.106:{port}", Group = 0, IsNetwork = true });
}
else
{
Globals.STUNServers.Add(new StunServer { ServerIPPort = $"162.251.121.150:{port}", Group = 1, IsNetwork = true });
}
}

if (config.TestNet == true)
{
Expand All @@ -173,7 +219,11 @@ public static void ProcessConfig(Config config)
Globals.Port = 13338;
Globals.APIPort = 17292;
Globals.AddressPrefix = 0x89; //address prefix 'x'
Globals.BlockLock = 15;
Globals.V1ValHeight = 200;
Globals.TXHeightRule1 = 200;
Globals.TXHeightRule2 = 200;
Globals.DSTClientPort = 13341;
Globals.SelfSTUNPort = 13340;
}

if (!string.IsNullOrWhiteSpace(config.WalletPassword))
Expand Down
3 changes: 2 additions & 1 deletion ReserveBlockCore/Controllers/ActionFilterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ReserveBlockCore.Controllers
{
public class ActionFilterController : ActionFilterAttribute
{
public static List<string> ApprovedMethodList = new List<string> { "GetDebugInfo", "Mother", "Egg", "CheckStatus", "GetCLIVersion", "GetWalletInfo", "NetworkMetrics" };
public static List<string> ApprovedMethodList = new List<string> { "GetDebugInfo", "Mother", "Egg", "CheckStatus", "GetCLIVersion", "GetWalletInfo", "NetworkMetrics", "SyncBalances" };
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
try
Expand Down Expand Up @@ -104,6 +104,7 @@ public override void OnActionExecuting(ActionExecutingContext filterContext)
"GetIsWalletEncrypted", "GetMyVotes", "GetSingleSmartContract", "GetNFTAssetLocation", "GetCLIVersion", "CheckPasswordNeeded",
"GetBeacons", "GetValidatorInfo", "IsValidating", "NetworkMetrics", "Network", "Height", "LastBlock"};


if(!APIExclusionList.Contains(action))
{
if (Globals.GUI || Globals.LogAPI)
Expand Down
Loading

0 comments on commit 475b2eb

Please sign in to comment.