Пример #1
0
        /// <summary>
        /// Enable console command line.
        /// </summary>
        public static void EnableConsoleCommandLine()
        {
            ThreadConsoleCommandLine = new Thread(async delegate()
            {
                while (!Program.Exit)
                {
                    string commandLine = Console.ReadLine();
                    if (Program.Exit)
                    {
                        break;
                    }
                    try
                    {
                        var splitCommandLine = commandLine.Split(new char[0], StringSplitOptions.None);
                        switch (splitCommandLine[0])
                        {
                        case ClassConsoleCommandLineEnumeration.CommandLineHelp:
                            ClassConsole.ConsoleWriteLine(ClassConsoleCommandLineEnumeration.CommandLineHelp + " -> show list of command lines.", ClassConsoleColorEnumeration.IndexConsoleMagentaLog, Program.LogLevel);
                            ClassConsole.ConsoleWriteLine(ClassConsoleCommandLineEnumeration.CommandLineCreateWallet + " -> permit to create a new wallet manualy.", ClassConsoleColorEnumeration.IndexConsoleMagentaLog, Program.LogLevel);
                            ClassConsole.ConsoleWriteLine(ClassConsoleCommandLineEnumeration.CommandLineRestoreWallet + " -> permit to restore a wallet manualy. Syntax: " + ClassConsoleCommandLineEnumeration.CommandLineRestoreWallet + " wallet_address", ClassConsoleColorEnumeration.IndexConsoleMagentaLog, Program.LogLevel);
                            ClassConsole.ConsoleWriteLine(ClassConsoleCommandLineEnumeration.CommandLineSaveWallet + " -> permit to save manually the database of wallets.", ClassConsoleColorEnumeration.IndexConsoleMagentaLog, Program.LogLevel);
                            ClassConsole.ConsoleWriteLine(ClassConsoleCommandLineEnumeration.CommandLineLogLevel + " -> change log level. Max log level: " + ClassConsole.MaxLogLevel, ClassConsoleColorEnumeration.IndexConsoleMagentaLog, Program.LogLevel);
                            break;

                        case ClassConsoleCommandLineEnumeration.CommandLineCreateWallet:

                            using (var walletCreatorObject = new ClassWalletCreator())
                            {
                                new Thread(async delegate()
                                {
                                    if (!await walletCreatorObject.StartWalletConnectionAsync(ClassWalletPhase.Create, ClassUtility.MakeRandomWalletPassword()))
                                    {
                                        ClassConsole.ConsoleWriteLine("RPC Wallet cannot create a new wallet.", ClassConsoleColorEnumeration.IndexConsoleRedLog, Program.LogLevel);
                                    }
                                }).Start();


                                while (walletCreatorObject.WalletCreateResult == ClassWalletCreatorEnumeration.WalletCreatorPending)
                                {
                                    Thread.Sleep(100);
                                }
                                switch (walletCreatorObject.WalletCreateResult)
                                {
                                case ClassWalletCreatorEnumeration.WalletCreatorError:
                                    ClassConsole.ConsoleWriteLine("RPC Wallet cannot create a new wallet.", ClassConsoleColorEnumeration.IndexConsoleRedLog, Program.LogLevel);
                                    break;

                                case ClassWalletCreatorEnumeration.WalletCreatorSuccess:
                                    ClassConsole.ConsoleWriteLine("RPC Wallet successfully create a new wallet.", ClassConsoleColorEnumeration.IndexConsoleGreenLog, Program.LogLevel);
                                    ClassConsole.ConsoleWriteLine("New wallet address generated: " + walletCreatorObject.WalletAddressResult, ClassConsoleColorEnumeration.IndexConsoleBlueLog, Program.LogLevel);
                                    break;
                                }
                            }

                            break;

                        case ClassConsoleCommandLineEnumeration.CommandLineRestoreWallet:

                            if (splitCommandLine.Length < 2)
                            {
                                ClassConsole.ConsoleWriteLine("Please, put the wallet address to restore.", ClassConsoleColorEnumeration.IndexConsoleRedLog, Program.LogLevel);
                            }
                            else
                            {
                                if (ClassRpcDatabase.RpcDatabaseContent.ContainsKey(splitCommandLine[1]))
                                {
                                    using (var walletCreatorObject = new ClassWalletCreator())
                                    {
                                        new Thread(async delegate()
                                        {
                                            if (!await walletCreatorObject.StartWalletConnectionAsync(ClassWalletPhase.Restore, ClassUtility.MakeRandomWalletPassword(), ClassRpcDatabase.RpcDatabaseContent[splitCommandLine[1]].GetWalletPrivateKey(), splitCommandLine[1]))
                                            {
                                                ClassConsole.ConsoleWriteLine("RPC Wallet cannot restore your wallet: " + splitCommandLine[1], ClassConsoleColorEnumeration.IndexConsoleRedLog, Program.LogLevel);
                                            }
                                        }).Start();


                                        while (walletCreatorObject.WalletCreateResult == ClassWalletCreatorEnumeration.WalletCreatorPending)
                                        {
                                            Thread.Sleep(100);
                                        }
                                        switch (walletCreatorObject.WalletCreateResult)
                                        {
                                        case ClassWalletCreatorEnumeration.WalletCreatorError:
                                            ClassConsole.ConsoleWriteLine("RPC Wallet cannot restore a wallet: " + splitCommandLine[1], ClassConsoleColorEnumeration.IndexConsoleRedLog, Program.LogLevel);
                                            break;

                                        case ClassWalletCreatorEnumeration.WalletCreatorSuccess:
                                            ClassConsole.ConsoleWriteLine("RPC Wallet successfully restore wallet: " + splitCommandLine[1], ClassConsoleColorEnumeration.IndexConsoleGreenLog, Program.LogLevel);
                                            ClassConsole.ConsoleWriteLine("RPC Wallet execute save the database of wallets..", ClassConsoleColorEnumeration.IndexConsoleYellowLog, Program.LogLevel);
                                            if (await ClassRpcDatabase.SaveWholeRpcWalletDatabaseFile())
                                            {
                                                ClassConsole.ConsoleWriteLine("RPC Wallet save of the database of wallets done successfully.", ClassConsoleColorEnumeration.IndexConsoleGreenLog, Program.LogLevel);
                                            }
                                            else
                                            {
                                                ClassConsole.ConsoleWriteLine("RPC Wallet save of the database of wallets failed, please retry by command line: " + ClassConsoleCommandLineEnumeration.CommandLineSaveWallet, ClassConsoleColorEnumeration.IndexConsoleGreenLog, Program.LogLevel);
                                            }
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    ClassConsole.ConsoleWriteLine("Please, put a valid wallet address stored on the database of your rpc wallet to restore. " + splitCommandLine[1] + " not exist.", ClassConsoleColorEnumeration.IndexConsoleRedLog, Program.LogLevel);
                                }
                            }
                            break;

                        case ClassConsoleCommandLineEnumeration.CommandLineSaveWallet:
                            if (await ClassRpcDatabase.SaveWholeRpcWalletDatabaseFile())
                            {
                                ClassConsole.ConsoleWriteLine("RPC Wallet save of the database of wallets done successfully.", ClassConsoleColorEnumeration.IndexConsoleGreenLog, Program.LogLevel);
                            }
                            else
                            {
                                ClassConsole.ConsoleWriteLine("RPC Wallet save of the database of wallets failed, please retry by command line: " + ClassConsoleCommandLineEnumeration.CommandLineSaveWallet, ClassConsoleColorEnumeration.IndexConsoleGreenLog, Program.LogLevel);
                            }
                            break;

                        case ClassConsoleCommandLineEnumeration.CommandLineLogLevel:
                            if (splitCommandLine.Length > 1)
                            {
                                if (int.TryParse(splitCommandLine[1], out var logLevel))
                                {
                                    if (logLevel < 0)
                                    {
                                        logLevel = 0;
                                    }
                                    else
                                    {
                                        if (logLevel > ClassConsole.MaxLogLevel)
                                        {
                                            logLevel = ClassConsole.MaxLogLevel;
                                        }
                                    }
                                    ClassConsole.ConsoleWriteLine("New log level " + Program.LogLevel + " -> " + logLevel, ClassConsoleColorEnumeration.IndexConsoleMagentaLog, Program.LogLevel);
                                    Program.LogLevel = logLevel;
                                }
                            }
                            else
                            {
                                ClassConsole.ConsoleWriteLine("Please select a log level.", ClassConsoleColorEnumeration.IndexConsoleRedLog, Program.LogLevel);
                            }
                            break;

                        case ClassConsoleCommandLineEnumeration.CommandLineExit:
                            Program.Exit = true;
                            ClassConsole.ConsoleWriteLine("Closing RPC Wallet..", ClassConsoleColorEnumeration.IndexConsoleRedLog, Program.LogLevel);
                            ClassApi.StopApiHttpServer();
                            if (ClassRpcSetting.RpcWalletEnableRemoteNodeSync)
                            {
                                ClassWalletUpdater.DisableAutoUpdateWallet();
                            }
                            ClassRemoteSync.StopRpcWalletToSync();
                            if (Program.ThreadRemoteNodeSync != null && (Program.ThreadRemoteNodeSync.IsAlive || Program.ThreadRemoteNodeSync != null))
                            {
                                Program.ThreadRemoteNodeSync.Abort();
                                GC.SuppressFinalize(Program.ThreadRemoteNodeSync);
                            }
                            ClassConsole.ConsoleWriteLine("Waiting end of save RPC Wallet Database..", ClassConsoleColorEnumeration.IndexConsoleYellowLog, Program.LogLevel);
                            while (ClassRpcDatabase.InSave)
                            {
                                Thread.Sleep(100);
                            }
                            ClassConsole.ConsoleWriteLine("Waiting end of save RPC Wallet Sync Database..", ClassConsoleColorEnumeration.IndexConsoleYellowLog, Program.LogLevel);
                            while (ClassSyncDatabase.InSave)
                            {
                                Thread.Sleep(100);
                            }
                            ClassLog.StopLogSystem();
                            ClassConsole.ConsoleWriteLine("RPC Wallet is successfully stopped, press ENTER to exit.", ClassConsoleColorEnumeration.IndexConsoleBlueLog, Program.LogLevel);
                            Console.ReadLine();
                            Process.GetCurrentProcess().Kill();
                            break;
                        }
                        if (Program.Exit)
                        {
                            break;
                        }
                    }
                    catch (Exception error)
                    {
                        ClassConsole.ConsoleWriteLine("Error command line exception: " + error.Message, ClassConsoleColorEnumeration.IndexConsoleRedLog, Program.LogLevel);
                        ClassConsole.ConsoleWriteLine("For get help use command line " + ClassConsoleCommandLineEnumeration.CommandLineHelp, ClassConsoleColorEnumeration.IndexConsoleRedLog, Program.LogLevel);
                    }
                }
            });
            ThreadConsoleCommandLine.Start();
        }
Пример #2
0
        /// <summary>
        /// Handle get request received from client.
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        private async Task HandlePacketHttpAsync(string packet)
        {
            if (packet.Contains("|"))
            {
                var splitPacket = packet.Split(new[] { "|" }, StringSplitOptions.None);

                switch (splitPacket[0])
                {
                case ClassApiEnumeration.UpdateWalletByAddress:
                    if (ClassRpcDatabase.RpcDatabaseContent.ContainsKey(splitPacket[1]))
                    {
                        if (!ClassRpcDatabase.RpcDatabaseContent[splitPacket[1]].GetWalletUpdateStatus())
                        {
                            await ClassWalletUpdater.UpdateWallet(splitPacket[1]);

                            Dictionary <string, string> walletUpdateContent = new Dictionary <string, string>()
                            {
                                { "wallet_address", splitPacket[1] },
                                { "wallet_balance", ClassRpcDatabase.RpcDatabaseContent[splitPacket[1]].GetWalletBalance() },
                                { "wallet_pending_balance", ClassRpcDatabase.RpcDatabaseContent[splitPacket[1]].GetWalletPendingBalance() },
                                { "wallet_unique_id", ClassRpcDatabase.RpcDatabaseContent[splitPacket[1]].GetWalletUniqueId() },
                                { "wallet_unique_anonymous_id", ClassRpcDatabase.RpcDatabaseContent[splitPacket[1]].GetWalletAnonymousUniqueId() },
                            };
                            await BuildAndSendHttpPacketAsync(string.Empty, true, walletUpdateContent);

                            break;
                        }
                        else
                        {
                            await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletBusyOnUpdate);
                        }
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                    }
                    break;

                case ClassApiEnumeration.UpdateWalletByIndex:
                    if (int.TryParse(splitPacket[1], out var walletIndexUpdate))
                    {
                        int  counter = 0;
                        bool found   = false;
                        foreach (var walletObject in ClassRpcDatabase.RpcDatabaseContent)
                        {
                            counter++;
                            if (counter == walletIndexUpdate)
                            {
                                found = true;
                                if (!walletObject.Value.GetWalletUpdateStatus())
                                {
                                    await ClassWalletUpdater.UpdateWallet(walletObject.Key);

                                    Dictionary <string, string> walletUpdateContent = new Dictionary <string, string>()
                                    {
                                        { "wallet_address", walletObject.Key },
                                        { "wallet_balance", walletObject.Value.GetWalletBalance() },
                                        { "wallet_pending_balance", walletObject.Value.GetWalletPendingBalance() },
                                        { "wallet_unique_id", walletObject.Value.GetWalletUniqueId() },
                                        { "wallet_unique_anonymous_id", walletObject.Value.GetWalletAnonymousUniqueId() },
                                    };
                                    await BuildAndSendHttpPacketAsync(string.Empty, true, walletUpdateContent);

                                    break;
                                }
                                else
                                {
                                    await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletBusyOnUpdate);

                                    break;
                                }
                            }
                        }
                        if (!found)
                        {
                            await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                        }
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                    }
                    break;

                case ClassApiEnumeration.GetWalletAddressByIndex:
                    if (int.TryParse(splitPacket[1], out var walletIndex))
                    {
                        bool found   = false;
                        int  counter = 0;
                        foreach (var walletObject in ClassRpcDatabase.RpcDatabaseContent)
                        {
                            counter++;
                            if (counter == walletIndex)
                            {
                                found = true;
                                await BuildAndSendHttpPacketAsync(walletObject.Key);

                                break;
                            }
                        }
                        if (!found)
                        {
                            await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                        }
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                    }
                    break;

                case ClassApiEnumeration.GetWalletBalanceByIndex:
                    if (int.TryParse(splitPacket[1], out var walletIndex2))
                    {
                        bool found   = false;
                        int  counter = 0;
                        foreach (var walletObject in ClassRpcDatabase.RpcDatabaseContent)
                        {
                            counter++;
                            if (counter == walletIndex2)
                            {
                                found = true;
                                Dictionary <string, string> walletBalanceContent = new Dictionary <string, string>()
                                {
                                    { "wallet_address", walletObject.Key },
                                    { "wallet_balance", walletObject.Value.GetWalletBalance() },
                                    { "wallet_pending_balance", walletObject.Value.GetWalletPendingBalance() }
                                };
                                await BuildAndSendHttpPacketAsync(null, true, walletBalanceContent);

                                break;
                            }
                        }
                        if (!found)
                        {
                            await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                        }
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                    }
                    break;

                case ClassApiEnumeration.GetWalletBalanceByWalletAddress:
                    if (ClassRpcDatabase.RpcDatabaseContent.ContainsKey(splitPacket[1]))
                    {
                        Dictionary <string, string> walletBalanceContent = new Dictionary <string, string>()
                        {
                            { "wallet_address", splitPacket[1] },
                            { "wallet_balance", ClassRpcDatabase.RpcDatabaseContent[splitPacket[1]].GetWalletBalance() },
                            { "wallet_pending_balance", ClassRpcDatabase.RpcDatabaseContent[splitPacket[1]].GetWalletPendingBalance() }
                        };
                        await BuildAndSendHttpPacketAsync(null, true, walletBalanceContent);
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                    }
                    break;

                case ClassApiEnumeration.SendTransactionByWalletAddress:
                    if (splitPacket.Length >= 6)
                    {
                        var walletAddressSource = splitPacket[1];
                        var amount              = splitPacket[2];
                        var fee                 = splitPacket[3];
                        var anonymousOption     = splitPacket[4];
                        var walletAddressTarget = splitPacket[5];
                        if (anonymousOption == "1")
                        {
                            string result = await ClassWalletUpdater.ProceedTransactionTokenRequestAsync(walletAddressSource, amount, fee, walletAddressTarget, true);

                            var splitResult = result.Split(new[] { "|" }, StringSplitOptions.None);
                            Dictionary <string, string> walletTransactionContent = new Dictionary <string, string>()
                            {
                                { "result", splitResult[0] },
                                { "hash", splitResult[1].ToLower() },
                                { "wallet_balance", ClassRpcDatabase.RpcDatabaseContent[walletAddressSource].GetWalletBalance() },
                                { "wallet_pending_balance", ClassRpcDatabase.RpcDatabaseContent[walletAddressSource].GetWalletPendingBalance() }
                            };
                            await BuildAndSendHttpPacketAsync(string.Empty, true, walletTransactionContent);
                        }
                        else
                        {
                            string result = await ClassWalletUpdater.ProceedTransactionTokenRequestAsync(walletAddressSource, amount, fee, walletAddressTarget, false);

                            var splitResult = result.Split(new[] { "|" }, StringSplitOptions.None);
                            Dictionary <string, string> walletTransactionContent = new Dictionary <string, string>()
                            {
                                { "result", splitResult[0] },
                                { "hash", splitResult[1].ToLower() },
                                { "wallet_balance", ClassRpcDatabase.RpcDatabaseContent[walletAddressSource].GetWalletBalance() },
                                { "wallet_pending_balance", ClassRpcDatabase.RpcDatabaseContent[walletAddressSource].GetWalletPendingBalance() }
                            };
                            await BuildAndSendHttpPacketAsync(string.Empty, true, walletTransactionContent);
                        }
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.PacketNotExist);
                    }
                    break;

                case ClassApiEnumeration.CreateWallet:
                    if (long.TryParse(splitPacket[1], out var timeout))
                    {
                        var dateTimeEnd = DateTimeOffset.Now.ToUnixTimeSeconds() + timeout;

                        bool success = false;
                        while (dateTimeEnd >= DateTimeOffset.Now.ToUnixTimeSeconds())
                        {
                            using (var walletCreatorObject = new ClassWalletCreator())
                            {
                                await Task.Run(async delegate
                                {
                                    if (!await walletCreatorObject.StartWalletConnectionAsync(ClassWalletPhase.Create, ClassUtility.MakeRandomWalletPassword()))
                                    {
                                        ClassConsole.ConsoleWriteLine("RPC Wallet cannot create a new wallet.", ClassConsoleColorEnumeration.IndexConsoleRedLog, Program.LogLevel);
                                    }
                                }).ConfigureAwait(false);

                                while (walletCreatorObject.WalletCreateResult == ClassWalletCreatorEnumeration.WalletCreatorPending)
                                {
                                    await Task.Delay(100);
                                }
                                switch (walletCreatorObject.WalletCreateResult)
                                {
                                case ClassWalletCreatorEnumeration.WalletCreatorSuccess:
                                    success = true;
                                    await BuildAndSendHttpPacketAsync(walletCreatorObject.WalletAddressResult);

                                    dateTimeEnd = DateTimeOffset.Now.ToUnixTimeSeconds();
                                    break;
                                }
                            }
                        }
                        if (!success)
                        {
                            await BuildAndSendHttpPacketAsync(ClassApiEnumeration.CreateWalletError);
                        }
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.CreateWalletError);
                    }
                    break;

                case ClassApiEnumeration.GetWalletTotalTransactionByIndex:
                    if (int.TryParse(splitPacket[1], out var walletIndex3))
                    {
                        bool found   = false;
                        int  counter = 0;
                        foreach (var walletObject in ClassRpcDatabase.RpcDatabaseContent)
                        {
                            counter++;
                            if (counter == walletIndex3)
                            {
                                found = true;
                                Dictionary <string, string> walletTotalTransactionContent = new Dictionary <string, string>()
                                {
                                    { "wallet_address", walletObject.Key },
                                    { "wallet_total_transaction", "" + walletObject.Value.GetWalletTotalTransactionSync() }
                                };
                                await BuildAndSendHttpPacketAsync(null, true, walletTotalTransactionContent);

                                break;
                            }
                        }
                        if (!found)
                        {
                            await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                        }
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                    }
                    break;

                case ClassApiEnumeration.GetWalletTotalAnonymousTransactionByIndex:
                    if (int.TryParse(splitPacket[1], out var walletIndex4))
                    {
                        bool found   = false;
                        int  counter = 0;
                        foreach (var walletObject in ClassRpcDatabase.RpcDatabaseContent)
                        {
                            counter++;
                            if (counter == walletIndex4)
                            {
                                found = true;
                                Dictionary <string, string> walletTotalAnonymousTransactionContent = new Dictionary <string, string>()
                                {
                                    { "wallet_address", walletObject.Key },
                                    { "wallet_total_anonymous_transaction", "" + walletObject.Value.GetWalletTotalAnonymousTransactionSync() }
                                };
                                await BuildAndSendHttpPacketAsync(null, true, walletTotalAnonymousTransactionContent);

                                break;
                            }
                        }
                        if (!found)
                        {
                            await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                        }
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                    }
                    break;

                case ClassApiEnumeration.GetWalletTotalTransactionByWalletAddress:
                    if (ClassRpcDatabase.RpcDatabaseContent.ContainsKey(splitPacket[1]))
                    {
                        Dictionary <string, string> walletTotalTransactionContent = new Dictionary <string, string>()
                        {
                            { "wallet_address", splitPacket[1] },
                            { "wallet_total_transaction", "" + ClassRpcDatabase.RpcDatabaseContent[splitPacket[1]].GetWalletTotalTransactionSync() }
                        };
                        await BuildAndSendHttpPacketAsync(null, true, walletTotalTransactionContent);
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                    }
                    break;

                case ClassApiEnumeration.GetWalletTotalAnonymousTransactionByWalletAddress:
                    if (ClassRpcDatabase.RpcDatabaseContent.ContainsKey(splitPacket[1]))
                    {
                        Dictionary <string, string> walletTotalAnonymousTransactionContent = new Dictionary <string, string>()
                        {
                            { "wallet_address", splitPacket[1] },
                            { "wallet_total_anonymous_transaction", "" + ClassRpcDatabase.RpcDatabaseContent[splitPacket[1]].GetWalletTotalAnonymousTransactionSync() }
                        };
                        await BuildAndSendHttpPacketAsync(null, true, walletTotalAnonymousTransactionContent);
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                    }
                    break;

                case ClassApiEnumeration.GetWalletTransaction:
                    if (ClassRpcDatabase.RpcDatabaseContent.ContainsKey(splitPacket[1]))
                    {
                        if (int.TryParse(splitPacket[2], out var transactionIndex))
                        {
                            if (transactionIndex == 0)
                            {
                                transactionIndex++;
                            }
                            string transaction = ClassRpcDatabase.RpcDatabaseContent[splitPacket[1]].GetWalletTransactionSyncByIndex(transactionIndex);
                            if (transaction != null)
                            {
                                var splitTransaction = transaction.Split(new[] { "#" }, StringSplitOptions.None);
                                var type             = splitTransaction[1];
                                var hash             = splitTransaction[2];
                                var walletDst        = splitTransaction[3];
                                var amount           = splitTransaction[4];
                                var fee              = splitTransaction[5];
                                var timestampSend    = splitTransaction[6];
                                var timestampRecv    = splitTransaction[7];
                                var blockchainHeight = splitTransaction[8];

                                Dictionary <string, string> walletTransactionContent = new Dictionary <string, string>()
                                {
                                    { "index", "" + transactionIndex },
                                    { "type", splitTransaction[0] },
                                    { "mode", type },
                                    { "hash", hash },
                                    { "wallet_dst_or_src", walletDst },
                                    { "amount", amount },
                                    { "fee", fee },
                                    { "timestamp_send", timestampSend },
                                    { "timestamp_recv", timestampRecv },
                                    { "blockchain_height", blockchainHeight }
                                };
                                await BuildAndSendHttpPacketAsync(null, true, walletTransactionContent);
                            }
                            else
                            {
                                await BuildAndSendHttpPacketAsync(ClassApiEnumeration.IndexNotExist);
                            }
                        }
                        else
                        {
                            await BuildAndSendHttpPacketAsync(ClassApiEnumeration.IndexNotExist);
                        }
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                    }
                    break;

                case ClassApiEnumeration.GetWalletAnonymousTransaction:
                    if (ClassRpcDatabase.RpcDatabaseContent.ContainsKey(splitPacket[1]))
                    {
                        if (int.TryParse(splitPacket[2], out var transactionIndex))
                        {
                            if (transactionIndex == 0)
                            {
                                transactionIndex++;
                            }
                            string transaction = ClassRpcDatabase.RpcDatabaseContent[splitPacket[1]].GetWalletAnonymousTransactionSyncByIndex(transactionIndex);
                            if (transaction != null)
                            {
                                var splitTransaction = transaction.Split(new[] { "#" }, StringSplitOptions.None);
                                var type             = splitTransaction[1];
                                var hash             = splitTransaction[2];
                                var walletDst        = splitTransaction[3];
                                var amount           = splitTransaction[4];
                                var fee              = splitTransaction[5];
                                var timestampSend    = splitTransaction[6];
                                var timestampRecv    = splitTransaction[7];
                                var blockchainHeight = splitTransaction[8];

                                Dictionary <string, string> walletAnonymousTransactionContent = new Dictionary <string, string>()
                                {
                                    { "index", "" + transactionIndex },
                                    { "type", splitTransaction[0] },
                                    { "mode", type },
                                    { "hash", hash },
                                    { "wallet_dst_or_src", walletDst },
                                    { "amount", amount },
                                    { "fee", fee },
                                    { "timestamp_send", timestampSend },
                                    { "timestamp_recv", timestampRecv },
                                    { "blockchain_height", blockchainHeight }
                                };
                                await BuildAndSendHttpPacketAsync(null, true, walletAnonymousTransactionContent);
                            }
                            else
                            {
                                await BuildAndSendHttpPacketAsync(ClassApiEnumeration.IndexNotExist);
                            }
                        }
                        else
                        {
                            await BuildAndSendHttpPacketAsync(ClassApiEnumeration.IndexNotExist);
                        }
                    }
                    else
                    {
                        await BuildAndSendHttpPacketAsync(ClassApiEnumeration.WalletNotExist);
                    }
                    break;

                default:
                    await BuildAndSendHttpPacketAsync(ClassApiEnumeration.PacketNotExist);

                    break;
                }
            }
            else
            {
                switch (packet)
                {
                case ClassApiEnumeration.GetTotalWalletIndex:
                    await BuildAndSendHttpPacketAsync("" + ClassRpcDatabase.RpcDatabaseContent.Count);

                    break;

                case ClassApiEnumeration.CreateWallet:
                    using (var walletCreatorObject = new ClassWalletCreator())
                    {
                        await Task.Factory.StartNew(async delegate
                        {
                            if (!await walletCreatorObject.StartWalletConnectionAsync(ClassWalletPhase.Create, ClassUtility.MakeRandomWalletPassword()))
                            {
                                ClassConsole.ConsoleWriteLine("RPC Wallet cannot create a new wallet.", ClassConsoleColorEnumeration.IndexConsoleRedLog, Program.LogLevel);
                            }
                        }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Current).ConfigureAwait(false);

                        while (walletCreatorObject.WalletCreateResult == ClassWalletCreatorEnumeration.WalletCreatorPending)
                        {
                            await Task.Delay(100);
                        }
                        switch (walletCreatorObject.WalletCreateResult)
                        {
                        case ClassWalletCreatorEnumeration.WalletCreatorError:
                            await BuildAndSendHttpPacketAsync(ClassApiEnumeration.CreateWalletError);

                            break;

                        case ClassWalletCreatorEnumeration.WalletCreatorSuccess:
                            await BuildAndSendHttpPacketAsync(walletCreatorObject.WalletAddressResult);

                            break;
                        }
                    }
                    break;

                default:
                    await BuildAndSendHttpPacketAsync(ClassApiEnumeration.PacketNotExist);

                    break;
                }
            }
        }