Ejemplo n.º 1
0
        public Node(NetworkConfig Configuration)
        {
            // Assign configuration
            Globals = Configuration;

            // Setup logger
            Logger = new Logger()
            {
                LogFile        = Globals.LOG_FILE,
                LogLevel       = Globals.LOG_LEVEL,
                CustomPrefix   = Globals.CUSTOM_PREFIX,
                InfoColor      = Globals.INFO_COLOR,
                ImportantColor = Globals.IMPORTANT_COLOR,
                DebugColor     = Globals.DEBUG_COLOR,
                WarningColor   = Globals.WARNING_COLOR,
                ErrorColor     = Globals.ERROR_COLOR
            };

            // Show ascii art, strictly vanity
            if (!string.IsNullOrEmpty(Globals.ASCII_ART))
            {
                Logger?.Important(Globals.ASCII_ART);
            }
            Logger.ShowPrefix = true;

            // Setup our blockchain handler
            Logger?.WriteLine("Setting up blockchain handler...");
            Blockchain = new BlockchainStorage();

            // Create our P2P server
            Logger?.WriteLine("Setting up P2P server...");
            P2pServer = new P2pServer(Globals.P2P_MAX_PEER_CONNECTIONS);

            // Assign P2P event handlers
            Logger?.WriteLine("Assigning P2P callbacks...");
            AssignCallbacks();

            // Setup our API server
            Logger?.WriteLine("Setting up API server...");
            ApiServer = new ApiServer(Globals.API_MAX_WORKERS)
            {
                Logger = Logger
            };

            // Create an API context
            Logger?.WriteLine("Assigning API method context...");
            ApiServer.AssignMethodContext(new ApiMethods(this));

            // Setup our peer list
            Logger?.WriteLine("Setting up local peer list...");
            SetupPeerList();

            // Assign a unique identifier
            Logger?.WriteLine("Generating identifier...");
            Id = SecureRandom.Integer <ulong>();
        }
Ejemplo n.º 2
0
        internal static ulong GetBlockReward(NetworkConfig Globals, byte MajorVersion, uint MedianSize,
                                             uint BlockSize, ulong AlreadyGeneratedUnits, ulong Fee, out ulong EmissionChange)
        {
            // Check if we are at unit capacity
            if (AlreadyGeneratedUnits <= Globals.CURRENCY_TOTAL_SUPPLY)
            {
                throw new Exception("Total units has been reached");
            }

            // Calculate base reward
            ulong BaseReward = Globals.CURRENCY_GENESIS_REWARD;

            if (AlreadyGeneratedUnits > 0)
            {
                BaseReward = (Globals.CURRENCY_TOTAL_SUPPLY - AlreadyGeneratedUnits) >> Globals.CURRENCY_EMISSION_FACTOR;
            }

            // Calculate reward zone

            // TODO - define these in a more appropriate spot (in core they are in the config)
            uint BlockGrantedFullRewardZone = 10_000;

            if (MajorVersion == Constants.BLOCK_MAJOR_VERSION_2)
            {
                BlockGrantedFullRewardZone = 20_000;
            }
            else if (MajorVersion >= Constants.BLOCK_MAJOR_VERSION_3)
            {
                BlockGrantedFullRewardZone = 100_000;
            }
            MedianSize = Math.Max(MedianSize, BlockGrantedFullRewardZone);

            // Calculate penalties
            ulong PenalizedBaseReward = GetPenalizedAmount(BaseReward, MedianSize, BlockSize);
            ulong PenalizedFee        = Fee;

            if (MajorVersion >= Constants.BLOCK_MAJOR_VERSION_2)
            {
                PenalizedFee = GetPenalizedAmount(Fee, MedianSize, BlockSize);
            }

            // Calculate emission change
            EmissionChange = PenalizedBaseReward - (Fee - PenalizedFee);

            // Return reward result
            return(PenalizedBaseReward + PenalizedFee);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes this node with the specified network configuration
        /// </summary>
        /// <param name="Configuration">A class containing all global information this node needs to operate</param>
        public Node(NetworkConfig Configuration)
        {
            // Assign configuration
            Globals = Configuration;

            // Generate identifier
            Id = SecureRandom.Integer <ulong>();

            // Setup and start logger
            Logger = new Logger()
            {
                LogFile        = Globals.LOG_FILE,
                LogLevel       = Globals.LOG_LEVEL,
                CustomPrefix   = Globals.CUSTOM_PREFIX,
                ImportantColor = Globals.IMPORTANT_COLOR,
                InfoColor      = Globals.INFO_COLOR,
                ErrorColor     = Globals.ERROR_COLOR,
                WarningColor   = Globals.WARNING_COLOR,
                DebugColor     = Globals.DEBUG_COLOR
            };

            // Setup blockchain cache
            Blockchain = new BlockchainCache(Globals)
            {
                Logger = Logger
            };

            // Create our P2P server
            P2pServer = new P2pServer(Globals.P2P_WORKERS, Globals.P2P_MAX_PEER_CONNECTIONS)
            {
                ConnectionTimeout = Globals.P2P_CONNECTION_TIMEOUT
            };

            // Setup our API server
            ApiServer = new ApiServer(Globals.API_WORKERS, Globals.API_PASSWORD)
            {
                Logger = Logger
            };

            // Setup done, set node to stopped
            Stopped = true;
        }
Ejemplo n.º 4
0
 // Initializes a new blockchain storage
 internal BlockchainCache(NetworkConfig Config)
 {
     // Assign network config
     Globals = Config;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes this node with the specified network configuration
        /// </summary>
        /// <param name="Configuration">A class containing all global information this node needs to operate</param>
        public Node(NetworkConfig Configuration)
        {
            // Assign configuration
            Globals = Configuration;

            // Setup logger
            Logger = new Logger()
            {
                LogFile        = Globals.LOG_FILE,
                LogLevel       = Globals.LOG_LEVEL,
                CustomPrefix   = Globals.CUSTOM_PREFIX,
                InfoColor      = Globals.INFO_COLOR,
                ImportantColor = Globals.IMPORTANT_COLOR,
                DebugColor     = Globals.DEBUG_COLOR,
                WarningColor   = Globals.WARNING_COLOR,
                ErrorColor     = Globals.ERROR_COLOR
            };

            // Show ascii art, strictly vanity
            if (!string.IsNullOrEmpty(Globals.ASCII_ART))
            {
                Logger?.Important(Globals.ASCII_ART);
            }
            Logger.ShowPrefix = true;

            // Setup our database
            Logger?.WriteLine("Setting up local storage...");
            if (!Directory.Exists(Globals.DATABASE_DIRECTORY))
            {
                Logger?.WriteLine("Creating directories...");
                Directory.CreateDirectory(Globals.DATABASE_DIRECTORY);
            }
            switch (Globals.DATABASE_TYPE)
            {
            case DatabaseType.SQLITE:
                DatabaseLocation = CombinePath(Globals.DATABASE_DIRECTORY, Globals.DATABASE_LOCATION);
                Database         = new Sqlite(DatabaseLocation);
                break;

            default:
                throw new ArgumentException("Invalid or non-specified database type");
            }

            // Setup our blockchain handler
            Logger?.WriteLine("Setting up blockchain handler...");
            Blockchain = new Blockchain()
            {
                Logger = Logger
            };

            // Create our P2P server
            Logger?.WriteLine("Setting up P2P server...");
            P2pServer = new P2pServer(Globals.P2P_MAX_PEER_CONNECTIONS);

            // Assign P2P event handlers
            Logger?.WriteLine("Assigning P2P callbacks...");
            AssignCallbacks();

            // Setup our API server
            Logger?.WriteLine("Setting up API server...");
            ApiServer = new ApiServer(Globals.API_MAX_WORKERS)
            {
                Logger = Logger
            };

            // Create an API context
            Logger?.WriteLine("Assigning API method context...");
            ApiServer.AssignMethodContext(new ApiMethods(this));

            // Setup our peer list
            Logger?.WriteLine("Setting up local peer list...");
            SetupPeerList();

            // Assign a unique identifier
            Logger?.WriteLine("Generating identifier...");
            Id = SecureRandom.Integer <ulong>();
        }