Skip to content

Commit

Permalink
Merge pull request #143 from ReserveBlockIO/dev
Browse files Browse the repository at this point in the history
Dev to main
  • Loading branch information
mathis1337 committed Feb 6, 2023
2 parents 3040048 + 8746463 commit 28de841
Show file tree
Hide file tree
Showing 25 changed files with 577 additions and 110 deletions.
Binary file modified Assemblies/LiteDB.dll
Binary file not shown.
67 changes: 67 additions & 0 deletions RBXBuildInstructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,70 @@ Once that is installed follow steps below.
6. dotnet publish -c Release -r osx-x64 --output ./rbxpublished **please note the 'osx-x64' can be changed if you are on a different architecture like arm.
7. cd rbxpublished
8. dotnet ReserveBlockCore


## Build RIDs

## Windows ##

### Windows, not version-specific ###
* win-x64
* win-x86
* win-arm64
### Windows 7 / Windows Server 2008 R2 ###
* win7-x64
* win7-x86
### Windows 8.1 / Windows Server 2012 R2 ###
* win81-x64
* win81-x86
### Windows 11 / Windows Server 2022 / Windows 10 / Windows Server 2016 ###
* win10-x64
* win10-x86
* win10-arm64

## Linux ##

### Linux, not distribution-specific ###
* linux-x64 (Most desktop distributions like CentOS, Debian, Fedora, Ubuntu, and derivatives)
* linux-musl-x64 (Lightweight distributions using musl like Alpine Linux)
* linux-arm (Linux distributions running on Arm like Raspbian on Raspberry Pi Model 2+)
* linux-arm64 (Linux distributions running on 64-bit Arm like Ubuntu Server 64-bit on Raspberry Pi Model 3+)

### Red Hat Enterprise Linux ###
* rhel-x64 (Superseded by linux-x64 for RHEL above version 6)
* rhel.6-x64

### Tizen ###
* tizen
* tizen.4.0.0
* tizen.5.0.0
* tizen.5.5.0
* tizen.6.0.0
* tizen.6.5.0
* tizen.7.0.0

## Mac ##

### macOS, not version-specific ###
* osx-x64 (Minimum OS version is macOS 10.12 Sierra)
### macOS 10.10 Yosemite ###
* osx.10.10-x64
### macOS 10.11 El Capitan ###
* osx.10.11-x64
### macOS 10.12 Sierra ###
* osx.10.12-x64
### macOS 10.13 High Sierra ###
* osx.10.13-x64
### macOS 10.14 Mojave ###
* osx.10.14-x64
### macOS 10.15 Catalina ###
* osx.10.15-x64
### macOS 11.0 Big Sur ###
* osx.11.0-x64
* osx.11.0-arm64
### macOS 12 Monterey ###
* osx.12-x64
* osx.12-arm64
### macOS 13 Ventura ###
* osx.13-x64
* osx.13-arm64
1 change: 1 addition & 0 deletions ReserveBlockCore/Commands/BaseCommandServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,7 @@ public static void PrintInfo()
table.AddColumn(new TableColumn(new Panel("Description"))).Centered();

table.AddRow("[blue]CLI Version[/]", $"[green]{Globals.CLIVersion}[/]");
table.AddRow("[blue]GitHub Version[/]", $"[green]{Globals.GitHubVersion}[/]");
table.AddRow("[blue]Network[/]", $"[green]{network}[/]");
table.AddRow("[blue]Port[/]", $"[green]{Globals.Port}[/]");
table.AddRow("[blue]OS[/]", $"[green]{osDesc}[/]");
Expand Down
3 changes: 3 additions & 0 deletions ReserveBlockCore/Config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Config
public string? CustomPath { get; set; }
public bool LogAPI { get; set; }
public bool RefuseToCallSeed { get; set; }
public bool OpenAPI { get; set; }

public static Config ReadConfigFile()
{
Expand Down Expand Up @@ -86,6 +87,7 @@ public static Config ReadConfigFile()
config.PasswordClearTime = dict.ContainsKey("PasswordClearTime") ? Convert.ToInt32(dict["PasswordClearTime"]) : 10;
config.LogAPI = dict.ContainsKey("LogAPI") ? Convert.ToBoolean(dict["LogAPI"]) : false;
config.RefuseToCallSeed = dict.ContainsKey("RefuseToCallSeed") ? Convert.ToBoolean(dict["RefuseToCallSeed"]) : false;
config.OpenAPI = dict.ContainsKey("OpenAPI") ? Convert.ToBoolean(dict["OpenAPI"]) : false;


config.AutoDownloadNFTAsset = dict.ContainsKey("AutoDownloadNFTAsset") ? Convert.ToBoolean(dict["AutoDownloadNFTAsset"]) : false;
Expand Down Expand Up @@ -159,6 +161,7 @@ public static void ProcessConfig(Config config)
Globals.AutoDownloadNFTAsset = config.AutoDownloadNFTAsset;
Globals.LogAPI = config.LogAPI;
Globals.RefuseToCallSeed = config.RefuseToCallSeed;
Globals.OpenAPI = Globals.OpenAPI != true ? config.OpenAPI : true;


if (config.TestNet == true)
Expand Down
2 changes: 1 addition & 1 deletion ReserveBlockCore/Controllers/ActionFilterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public override void OnActionExecuting(ActionExecutingContext filterContext)
"GetAllLocalTX", "GetSuccessfulLocalTX", "GetFailedLocalTX", "GetPendingLocalTX", "GetMinedLocalTX", "GetAllTopics",
"GetActiveTopics", "GetInactiveTopics", "GetMyTopics", "GetAllSmartContracts", "GetMintedSmartContracts", "CheckStatus",
"GetIsWalletEncrypted", "GetMyVotes", "GetSingleSmartContract", "GetNFTAssetLocation", "GetCLIVersion", "CheckPasswordNeeded",
"GetBeacons", "GetValidatorInfo"};
"GetBeacons", "GetValidatorInfo", "IsValidating"};

if(!APIExclusionList.Contains(action))
{
Expand Down
65 changes: 64 additions & 1 deletion ReserveBlockCore/Controllers/TXV1Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,63 @@ public async Task<string> GetAddressNonce(string address)
return output;
}

/// <summary>
/// Returns transaction from entire chain.
/// Warning this uses parallelism so only use if you system can handle this.
/// </summary>
/// <param name="txHash"></param>
/// <returns></returns>
[HttpGet("GetNetworkTXByHash/{txHash}")]
public async Task<string> GetNetworkTXByHash(string txHash)
{
var output = "";
var coreCount = Environment.ProcessorCount;
if (coreCount >= 4)
{
if (!string.IsNullOrEmpty(txHash))
{
try
{
txHash = txHash.Replace(" ", "");//removes any whitespace before or after in case left in.
var blocks = BlockchainData.GetBlocks();
var height = Convert.ToInt32(Globals.LastBlock.Height);
bool resultFound = false;

var integerList = Enumerable.Range(0, height + 1);
Parallel.ForEach(integerList, new ParallelOptions { MaxDegreeOfParallelism = coreCount == 4 ? 2 : 4 }, (blockHeight, loopState) =>
{
var block = blocks.Query().Where(x => x.Height == blockHeight).FirstOrDefault();
if (block != null)
{
var txs = block.Transactions.ToList();
var result = txs.Where(x => x.Hash == txHash).FirstOrDefault();
if (result != null)
{
resultFound = true;
output = JsonConvert.SerializeObject(new { Success = true, Message = result });
loopState.Break();
}
}
});

if (!resultFound)
output = JsonConvert.SerializeObject(new { Success = false, Message = "No transaction found with that hash." });
}
catch (Exception ex)
{
output = JsonConvert.SerializeObject(new { Success = false, Message = $"Error Performing Query: {ex.ToString()}" });
}

}
}
else
{
output = JsonConvert.SerializeObject(new { Success = false, Message = "The current system does not have enough physical/logical cores to safely run a query of this magnitude." });
}

return output;
}

/// <summary>
/// Creates a minting tranasctions
/// </summary>
Expand Down Expand Up @@ -599,9 +656,11 @@ public async Task<string> GetTxHash([FromBody] object jsonData)
if(tx != null)
{
tx.ToAddress = tx.ToAddress.ToAddressNormalize();
tx.Amount = tx.Amount.ToNormalizeDecimal();

tx.Build();

output = JsonConvert.SerializeObject(new { Result = "Success", Message = $"TX Fee Calculated", Hash = tx.Hash });
output = JsonConvert.SerializeObject(new { Result = "Success", Message = $"Hash Calculated.", Hash = tx.Hash });
}
else
{
Expand Down Expand Up @@ -673,6 +732,8 @@ public async Task<string> VerifyRawTransaction([FromBody] object jsonData)
if (transaction != null)
{
transaction.ToAddress = transaction.ToAddress.ToAddressNormalize();
transaction.Amount = transaction.Amount.ToNormalizeDecimal();

var result = await TransactionValidatorService.VerifyTX(transaction);
if (result.Item1 == true)
{
Expand Down Expand Up @@ -717,6 +778,8 @@ public async Task<string> SendRawTransaction([FromBody] object jsonData)
if (transaction != null)
{
transaction.ToAddress = transaction.ToAddress.ToAddressNormalize();
transaction.Amount = transaction.Amount.ToNormalizeDecimal();

var result = await TransactionValidatorService.VerifyTX(transaction);
if (result.Item1 == true)
{
Expand Down
21 changes: 20 additions & 1 deletion ReserveBlockCore/Controllers/V1Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,9 @@ public async Task<string> GetWalletInfo()
new { BlockHeight = blockHeight, PeerCount = peerCount, BlocksDownloading = (Globals.BlocksDownloadSlim.CurrentCount == 0).ToString(),
IsResyncing = Globals.IsResyncing.ToString(), IsChainSynced = Globals.IsChainSynced.ToString(),
ChainCorrupted = Globals.DatabaseCorruptionDetected.ToString(), DuplicateValIP = Globals.DuplicateAdjIP,
DuplicateValAddress = Globals.DuplicateAdjAddr, NFTFilesReadyEPN = Globals.NFTFilesReadyEPN, ConnectedToMother = Globals.ConnectToMother.ToString(), UpToDate = Globals.UpToDate}
DuplicateValAddress = Globals.DuplicateAdjAddr, NFTFilesReadyEPN = Globals.NFTFilesReadyEPN,
ConnectedToMother = Globals.ConnectToMother.ToString(), UpToDate = Globals.UpToDate, BlockVersion = BlockVersionUtility.GetBlockVersion(Globals.LastBlock.Height),
TimeInSync = Globals.TimeInSync.ToString(), TimeSyncError = Globals.TimeSyncError }
};

output = JsonConvert.SerializeObject(walletInfo);
Expand Down Expand Up @@ -602,6 +604,23 @@ public async Task<string> GetAllAddresses()
return output;
}

/// <summary>
/// Dumps out network metrics
/// </summary>
/// <returns></returns>
[HttpGet("NetworkMetrics")]
public async Task<string> NetworkMetrics()
{
var output = "[]"; // this will only display if command not recognized.
var currentTime = TimeUtil.GetTime();
var currentDiff = (currentTime - Globals.LastBlockAddedTimestamp).ToString();

output = JsonConvert.SerializeObject(new { BlockDiffAvg = BlockDiffService.CalculateAverage().ToString("#.##"), BlockLastReceived = Globals.LastBlockAddedTimestamp.ToLocalDateTimeFromUnix(),
BlockLastDelay = Globals.BlockTimeDiff.ToString(), TimeSinceLastBlockSeconds = currentDiff, BlocksAveraged = $"{Globals.BlockDiffQueue.Count().ToString()}/3456"});

return output;
}

/// <summary>
/// Dumps out a validator owned address.
/// </summary>
Expand Down
32 changes: 2 additions & 30 deletions ReserveBlockCore/Data/AccountData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,36 +230,8 @@ public static void PrintWalletAccounts()
}
else
{
Console.Clear();
Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop);
Console.WriteLine("ReserveBlock Main Menu");
Console.WriteLine("|======================================|");
Console.WriteLine("| 1. Genesis Block (Check) |");
Console.WriteLine("| 2. Create Account |");
Console.WriteLine("| 2hd. Create HD Wallet |");
Console.WriteLine("| 3. Restore Account |");
Console.WriteLine("| 3hd. Restore HD Wallet |");
Console.WriteLine("| 4. Send Coins |");
Console.WriteLine("| 5. Get Latest Block |");
Console.WriteLine("| 6. Transaction History |");
Console.WriteLine("| 7. Wallet Address(es) Info |");
Console.WriteLine("| 8. Startup Masternode |");
Console.WriteLine("| 9. Search Block |");
Console.WriteLine("| 10. Enable API (Turn On and Off) |");
Console.WriteLine("| 11. Stop Masternode |");
Console.WriteLine("| 12. Import Smart Contract (disabled) |");
Console.WriteLine("| 13. Voting |");
Console.WriteLine("| 14. Exit |");
Console.WriteLine("|======================================|");
Console.WriteLine("|type /help for menu options |");
Console.WriteLine("|type /menu to come back to main area |");
Console.WriteLine("|======================================|");

Console.WriteLine("********************************************************************");
Console.WriteLine("You do not have any accounts yet. Please choose option 2 to create a new account.");


}
StartupService.MainMenu(true);
}

}
public static void WalletInfo(Account account)
Expand Down
10 changes: 10 additions & 0 deletions ReserveBlockCore/Data/BlockchainData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ public static async void AddBlock(Block block)
var currentTime = TimeUtil.GetTime();
Globals.BlockTimeDiff = currentTime - Globals.LastBlockAddedTimestamp;
Globals.LastBlockAddedTimestamp = currentTime;
_ = BlockDiffService.UpdateQueue(Globals.BlockTimeDiff);
blocks.InsertSafe(block);
}
else
Expand Down Expand Up @@ -369,6 +370,15 @@ public static void PrintBlock(Block block)
Console.WriteLine(" * Size............: {0}", block.Size);
Console.WriteLine(" * Craft Time : {0}", block.BCraftTime);

Console.WriteLine($"");
Console.WriteLine("\n===========\nBlock Metrics:");
var currentTime = TimeUtil.GetTime();
var currentDiff = (currentTime - Globals.LastBlockAddedTimestamp).ToString();
Console.WriteLine($"Block Diff Avg: {BlockDiffService.CalculateAverage().ToString("#.##")} secs. Avg of: {Globals.BlockDiffQueue.Count()}/3456 Blocks.");
Console.WriteLine($"Block Last Received: {Globals.LastBlockAddedTimestamp.ToLocalDateTimeFromUnix()}");
Console.WriteLine($"Block Last Delay: {Globals.BlockTimeDiff}");
Console.WriteLine($"Current block delay: {currentDiff}");


}
}
Expand Down
22 changes: 22 additions & 0 deletions ReserveBlockCore/Extensions/GenericExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ public static long ToUnixTimeSeconds(this DateTime obj)
long unixTime = ((DateTimeOffset)obj).ToUnixTimeSeconds();
return unixTime;
}

public static decimal ToNormalizeDecimal(this decimal value)
{
var amountCheck = value % 1 == 0;
var amountFormat = 0M;
if (amountCheck)
{
var amountStr = value.ToString("0.0");
amountFormat = decimal.Parse(amountStr);

return amountFormat;
}

return value;
}

public static DateTime ToLocalDateTimeFromUnix(this long unixTime)
{
DateTime frDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
frDateTime = frDateTime.AddSeconds(unixTime).ToLocalTime();
return frDateTime;
}
public static int ToInt32(this string obj)
{
int value;
Expand Down
10 changes: 8 additions & 2 deletions ReserveBlockCore/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ static Globals()
public static int Port = 3338;
public static int APIPort = 7292;
public static int MajorVer = 3;
public static int MinorVer = 1;
public static int MinorVer = 2;
public static int BuildVer = 0;
public static int ValidatorIssueCount = 0;
public static bool ValidatorSending = true;
public static bool ValidatorReceiving = true;
public static List<string> ValidatorErrorMessages = new List<string>();
public static long ValidatorLastBlockHeight = 0;
public static string GitHubVersion = "beta2.3";
public static string GitHubVersion = "beta3.2";
public static string GitHubApiURL = "https://api.github.com/";
public static string GitHubRBXRepoURL = "repos/ReserveBlockIO/ReserveBlock-Core/releases/latest";
public static string GitHubLatestReleaseVersion = "";
Expand All @@ -79,6 +79,8 @@ static Globals()
public static string StartArguments = "";
public static DateTime NewUpdateLastChecked = DateTime.UtcNow.AddHours(-2);
public static SecureString? APIToken = null;
public static int TimeSyncDiff = 0;
public static DateTime TimeSyncLastDate = DateTime.Now;

public static string Platform = "";
public static string ValidatorAddress = "";
Expand Down Expand Up @@ -127,8 +129,11 @@ static Globals()
public static bool ExplorerValDataLastSendSuccess = false;
public static bool LogAPI = false;
public static bool RefuseToCallSeed = false;
public static bool OpenAPI = false;
public static bool NFTFilesReadyEPN = false; // nft files ready, encryption password needed
public static bool NFTsDownloading = false;
public static bool TimeInSync = true;
public static bool TimeSyncError = false;

public static CancellationToken CancelledToken;

Expand All @@ -142,6 +147,7 @@ static Globals()
public static ConcurrentDictionary<string, Beacons> Beacons = new ConcurrentDictionary<string, Beacons>();
public static ConcurrentBag<string> RejectAssetExtensionTypes = new ConcurrentBag<string>();
public static ConcurrentDictionary<string, BeaconNodeInfo> Beacon = new ConcurrentDictionary<string, BeaconNodeInfo>();
public static ConcurrentQueue<int> BlockDiffQueue = new ConcurrentQueue<int>();

public static SecureString EncryptPassword = new SecureString();
public static SecureString? MotherPassword = null;
Expand Down
1 change: 1 addition & 0 deletions ReserveBlockCore/Models/TransactionBroadcast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class TransactionBroadcast
public string Hash { get; set; }
public bool IsBroadcastedToAdj { get; set; }
public bool IsBroadcastedToVal { get; set; }
public int RebroadcastCount { get; set; }
public Transaction Transaction { get; set; }
}
}
Loading

0 comments on commit 28de841

Please sign in to comment.