Unit Noso.General
Description
Unit for general functions.
Uses
- Classes
- fileutil
- fphttpclient
- IdGlobal
- IdTCPClient
- Math
- Noso.Debug
- opensslsockets
- Process
- StrUtils
- SysUtils
- Zipper
Overview
Classes, Interfaces, Objects and Records
| Name | Description |
|---|---|
Record TMultiOrderData |
Record structure for multi-order data |
Packed Record TOrderData |
Record structure for order data |
Class TStreamHelper |
TStream helper class for string manipulation in streams |
Functions and Procedures
function AppFileName(): String; |
function CombineTextFiles(FileList: TStringArray; const Destination: String; DeleteSources: Boolean = True): Boolean; |
function CreateEmptyFile(const FileName: String): Boolean; |
function ExtractMasternodesText(const Text: String): String; |
function GetCirculatingSupply(const Block: Integer): Int64; |
function GetCommand(const Line: String): String; |
function GetCustomFee(const Block: Integer): Int64; |
function GetDevPercentage(Block: Integer): Integer; |
function GetMasterNodesPercentage(const Block: Integer; const MainnetMode: String = 'NORMAL'): Integer; |
function GetMaximumToSend(const Amount: Int64): Int64; |
function GetMinimumFeeForAmount(const Amount: Int64): Int64; |
function GetParameter(const Line: String; const ParamNumber: Int64; const Delimiter: String = ' '): String; |
function GetPoSPercentage(const Block: Integer): Integer; |
function GetProtocolCommand(const Line: String): String; |
function GetStackRequired(const Block: Integer): Int64; |
function HashRateToReadable(const Speed: Int64): String; |
function IntToCurrency(const Value: Int64): String; |
function IsValidIP(const IpAddress: String): Boolean; |
function LoadTextFromDisk(const FileName: TFileName): String; |
function OrderToString(const Order: TOrderData): String; |
function OSVersion: String; |
function RequestLineToPeer(const Host: String; const Port: Integer; const Command: String): String; |
function RequestToPeer(const HostAndPort, Command: String): String; |
procedure RunExternalProgram(const ProgramToRun: String); |
function SaveTextToDisk(const FileName: TFileName; const Text: String): Boolean; |
function SendApiRequest(const Url: String): String; |
function SendFileViaTCP(const FileName, Message, Host: String; const Port: Integer): Boolean; |
function ToNegative(const Number: Int64): Int64; |
function TryCopyFile(const Source, Destination: String): Boolean; |
function TryDeleteFile(const FileName: String): Boolean; |
function UnzipFile(const FileName: String; DeleteFile: Boolean): Boolean; |
Types
TBlockOrders = specialize TArray<TOrderData>; |
TStringArray = specialize TArray<String>; |
Description
Functions and Procedures
function AppFileName(): String; |
|
Returns the name of the application executable without the path.
Example: var AppName: String; begin AppName := AppFileName(); Writeln('The application file name is: ', AppName); end; ReturnsThe file name of the application executable. |
function CombineTextFiles(FileList: TStringArray; const Destination: String; DeleteSources: Boolean = True): Boolean; |
|
Combines multiple text files into one destination file.
Example: var Success: Boolean; Files: TStringArray; begin Files := ['file1.txt', 'file2.txt', 'file3.txt']; Success := CombineTextFiles(Files, 'combined.txt', True); if Success then Writeln('Files combined successfully!') else Writeln('Failed to combine the files.'); end; Parameters
Returns
|
function CreateEmptyFile(const FileName: String): Boolean; |
|
Creates an empty file on disk.
Example: var Success: Boolean; begin Success := CreateEmptyFile('emptyfile.txt'); if Success then Writeln('Empty file created successfully!') else Writeln('Failed to create the file.'); end; Parameters
Returns
|
function ExtractMasternodesText(const Text: String): String; |
|
Extracts the masternode's text in a string.
Parameters
ReturnsThe substring after the '$' character. |
function GetCirculatingSupply(const Block: Integer): Int64; |
|
Calculates the circulating supply of Noso based on the blockchain block number.
Parameters
ReturnsThe circulating supply as an Int64 value. |
function GetCommand(const Line: String): String; |
|
Extracts the command from the first parameter of the input string.
This function extracts the first parameter from a delimited string and converts it to uppercase.
Parameters
ReturnsThe first parameter of the string, converted to uppercase. |
function GetCustomFee(const Block: Integer): Int64; |
|
Returns the custom fee.
Parameters
ReturnsThe custom fee as an Int64 value. |
function GetDevPercentage(Block: Integer): Integer; |
|
Returns the developer percentage.
Parameters
ReturnsThe developer percentage for the specified block, as a number from 0 to 10000. |
function GetMasterNodesPercentage(const Block: Integer; const MainnetMode: String = 'NORMAL'): Integer; |
|
Calculates the percentage of master nodes based on the current block number and mode.
Parameters
ReturnsThe percentage of master nodes. |
function GetMaximumToSend(const Amount: Int64): Int64; |
|
Returns the maximum amount that can be sent for a specific amount.
Parameters
ReturnsThe maximum amount. |
function GetMinimumFeeForAmount(const Amount: Int64): Int64; |
|
Returns the minimum fee that can be paid for a specific amount.
Parameters
ReturnsThe minimum fee. |
function GetParameter(const Line: String; const ParamNumber: Int64; const Delimiter: String = ' '): String; |
|
Extracts a specific parameter from a delimited string
Parameters
ReturnsThe extracted parameter, or an empty string if not found |
function GetPoSPercentage(const Block: Integer): Integer; |
|
Returns the PoS percentage.
Parameters
ReturnsThe PoS percentage for the specified block, as a number from 0 to 10000. |
function GetProtocolCommand(const Line: String): String; |
|
Extracts the protocol command from the input string.
This function extracts the protocol command from a delimited string and converts it to uppercase.
Parameters
ReturnsThe protocol command, converted to uppercase. |
function GetStackRequired(const Block: Integer): Int64; |
|
Returns the stack required for Noso.
Parameters
ReturnsThe stack size as an Int64 value. |
function HashRateToReadable(const Speed: Int64): String; |
|
Converts an integer hashrate into a human-readable format.
The function formats the hashrate into Gh/s, Mh/s, kh/s, or h/s based on its magnitude.
var HashRate: Int64; begin HashRate := 5000000000; WriteLn('Hash rate: ', HashRateToReadable(HashRate)); // 5,00 Gh/s HashRate := 234000000; WriteLn('Hash rate: ', HashRateToReadable(HashRate)); // 234,00 Mh/s HashRate := 740000; WriteLn('Hash rate: ', HashRateToReadable(HashRate)); // 740,00 Kh/s HashRate := 21240; WriteLn('Hash rate: ', HashRateToReadable(HashRate)); // 21,24 Kh/s HashRate := 240; WriteLn('Hash rate: ', HashRateToReadable(HashRate)); // 240 h/s HashRate := 56; WriteLn('Hash rate: ', HashRateToReadable(HashRate)); // 56 h/s end. Parameters
ReturnsA string representing the human-readable hashrate. |
function IntToCurrency(const Value: Int64): String; |
|
Converts an integer value to a currency format with two decimal places.
The function formats the value as a string with thousands separators and a decimal point.
var Value: Int64; FormattedCurrency: String; begin Value := -10230456789; FormattedCurrency := IntToCurrency(Value); WriteLn('Currency: ', FormattedCurrency); // -102.30456789 end. Parameters
ReturnsA string representing the formatted currency value. |
function IsValidIP(const IpAddress: String): Boolean; |
|
Validates an IP address.
if not IsValidIP('127.0.0.1') then Writeln('localhost is not valid!'); if not IsValidIP('192.168.100.1') then Writeln('Private IP is not valid!'); if IsValidIP('142.250.186.35') then Writeln('Google IP is valid!'); Parameters
Returns
|
function LoadTextFromDisk(const FileName: TFileName): String; |
|
Loads text from a file on disk.
Example: var FileText: String; begin FileText := LoadTextFromDisk('example.txt'); if FileText <> '' then Writeln('File loaded successfully: ', FileText) else Writeln('Failed to load the file.'); end; Parameters
ReturnsThe content of the file as a string, or an empty string in case of failure. |
function OrderToString(const Order: TOrderData): String; |
|
Converts an order record to a formatted string.
Example: var OrderString: String; MyOrder: TOrderData; begin MyOrder := GetOrder(); // Could be any order. Writeln('Order as string: ', OrderToString(MyOrder)); end; Parameters
ReturnsA string representing the order. |
function OSVersion: String; |
|
Returns the OS name as a string. |
function RequestLineToPeer(const Host: String; const Port: Integer; const Command: String): String; |
|
Send a command to peer via TCP and return the response.
Example: var Response: String; begin Response := RequestLineToPeer('192.168.1.100', 8080, 'GET_INFO'); if Response <> '' then WriteLn('Response from peer: ', Response) else WriteLn('Failed to get a response from peer.'); end; Parameters
ReturnsThe response from the peer as a string. |
function RequestToPeer(const HostAndPort, Command: String): String; |
|
Send a command to a peer using a combined Host:Port string.
Example: var Response: String; begin Response := RequestToPeer('example.com:9000', 'PING'); if Response <> '' then WriteLn('Response from peer: ', Response) else WriteLn('Failed to get a response from peer.'); end; Parameters
ReturnsThe response from the peer as a string. |
procedure RunExternalProgram(const ProgramToRun: String); |
|
Runs an external program or script based on the operating system. The procedure handles environment variables and executes the given program or script.
begin RunExternalProgram('notepad.exe'); end. Parameters
|
function SaveTextToDisk(const FileName: TFileName; const Text: String): Boolean; |
|
Saves a given text to a file on disk.
Example: var Success: Boolean; begin Success := SaveTextToDisk('example.txt', 'This is some example text.'); if Success then Writeln('File saved successfully!') else Writeln('Failed to save the file.'); end; Parameters
Returns
|
function SendApiRequest(const Url: String): String; |
|
Send HTTP GET request to the specified URL.
Example: var ApiResponse: String; begin ApiResponse := SendApiRequest('https://api.example.com/data'); if ApiResponse <> '' then WriteLn('API Response: ', ApiResponse) else WriteLn('Failed to get a response from the API.'); end; Parameters
ReturnsThe response from the API as a string. |
function SendFileViaTCP(const FileName, Message, Host: String; const Port: Integer): Boolean; |
|
Sends a file to a peer via TCP, preceded by a message.
Example: var Success: Boolean; begin Success := SendFileViaTCP('example.txt', 'Sending file', '192.168.1.10', 8080); if Success then Writeln('File sent successfully!') else Writeln('Failed to send the file.'); end; Parameters
Returns
|
function ToNegative(const Number: Int64): Int64; |
|
Calculates the negative absolute value of a number.
Writeln(ToNegative(-10)); // -10 Writeln(ToNegative(0)); // 0 Writeln(ToNegative(25)); // -25 Parameters
ReturnsThe negated number if Number is positive, or Number otherwise. |
function TryCopyFile(const Source, Destination: String): Boolean; |
|
Copies a file from source to destination.
Example: var Success: Boolean; begin Success := TryCopyFile('source.txt', 'destination.txt'); if Success then Writeln('File copied successfully!') else Writeln('Failed to copy the file.'); end; Parameters
Returns
|
function TryDeleteFile(const FileName: String): Boolean; |
|
Attempts to delete a file safely.
Example: var Success: Boolean; begin Success := TryDeleteFile('example.txt'); if Success then Writeln('File deleted successfully!') else Writeln('Failed to delete the file.'); end; Parameters
Returns
|
function UnzipFile(const FileName: String; DeleteFile: Boolean): Boolean; |
|
Unzips a file and optionally deletes the source file.
Example: var Success: Boolean; begin Success := UnzipFile('archive.zip', True); if Success then Writeln('File unzipped and deleted successfully!') else Writeln('Failed to unzip the file.'); end; Parameters
Returns
|
Types
TBlockOrders = specialize TArray<TOrderData>; |
|
Dynamic array of TOrderData records |
TStringArray = specialize TArray<String>; |
|
Dynamic array of strings |
Generated by PasDoc 0.16.0-snapshot.