コード例 #1
0
        /// <summary>
        /// Test tcp connect.
        /// </summary>
        /// <returns></returns>
        public static bool TestTcpHost(string host, int port, int timeout)
        {
            bool status            = false;
            Task taskCheckSeedNode = Task.Run(async() => status = await CheckTcp.CheckTcpClientAsync(host, port));

            taskCheckSeedNode.Wait(timeout);
            return(status);
        }
コード例 #2
0
        /// <summary>
        ///     Permit to check new remote node host.
        /// </summary>
        /// <param name="ip"></param>
        public static async System.Threading.Tasks.Task <string> CheckNewRemoteNodeHostAsync(string ip)
        {
            InCheckingNewRemoteNode = true;
            var statusPing = CheckPing.CheckPingHost(ip);

            if (statusPing != -1)
            {
#if DEBUG
                Console.WriteLine("From Xiropht-Connector-All: ping status: " + ip + " " + statusPing + " ms.");
#endif
                var statusTcp = await CheckTcp.CheckTcpClientAsync(ip, ClassConnectorSetting.RemoteNodePort);

                if (statusTcp)
                {
                    if (ListRemoteNodeChecked.Count > 0)
                    {
                        var exist = false;
                        for (var i = 0; i < ListRemoteNodeChecked.Count - 1; i++)
                        {
                            if (ListRemoteNodeChecked[i].Item1 == ip)
                            {
                                exist = true;
                            }
                        }
                        if (!exist)
                        {
                            ListRemoteNodeChecked.Add(new Tuple <string, int>(ip, statusPing));
                            return(ClassRemoteNodeStatus.StatusNew);
                        }

                        return(ClassRemoteNodeStatus.StatusAlive);
                    }

                    ListRemoteNodeChecked.Add(new Tuple <string, int>(ip, statusPing));
                    return(ClassRemoteNodeStatus.StatusNew);
                }
            }

            InCheckingNewRemoteNode = false;
            return(ClassRemoteNodeStatus.StatusDead);
        }
コード例 #3
0
        /// <summary>
        /// Enable auto update wallet system.
        /// </summary>
        public static void EnableAutoUpdateWallet()
        {
            if (ThreadAutoUpdateWallet != null && (ThreadAutoUpdateWallet.IsAlive || ThreadAutoUpdateWallet != null))
            {
                ThreadAutoUpdateWallet.Abort();
                GC.SuppressFinalize(ThreadAutoUpdateWallet);
            }

            ThreadAutoUpdateWallet = new Thread(delegate()
            {
                while (!Program.Exit)
                {
                    if (ClassRpcDatabase.RpcDatabaseContent.Count > 0)
                    {
                        try
                        {
                            foreach (var walletObject in ClassRpcDatabase.RpcDatabaseContent)
                            {
                                if (Program.Exit)
                                {
                                    break;
                                }
                                string getSeedNodeRandom = string.Empty;
                                bool seedNodeSelected    = false;
                                foreach (var seedNode in ClassConnectorSetting.SeedNodeIp)
                                {
                                    getSeedNodeRandom      = seedNode.Key;
                                    Task taskCheckSeedNode = Task.Run(async() => seedNodeSelected = await CheckTcp.CheckTcpClientAsync(seedNode.Key, ClassConnectorSetting.SeedNodeTokenPort));
                                    taskCheckSeedNode.Wait(ClassConnectorSetting.MaxTimeoutConnect);
                                    if (seedNodeSelected)
                                    {
                                        break;
                                    }
                                }
                                if (seedNodeSelected)
                                {
                                    if (!walletObject.Value.GetWalletUpdateStatus() && walletObject.Value.GetLastWalletUpdate() <= DateTimeOffset.Now.ToUnixTimeSeconds())
                                    {
                                        walletObject.Value.SetLastWalletUpdate(DateTimeOffset.Now.ToUnixTimeSeconds() + ClassRpcSetting.WalletUpdateInterval);
                                        walletObject.Value.SetWalletOnUpdateStatus(true);
                                        UpdateWalletTarget(getSeedNodeRandom, walletObject.Key);
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                    Thread.Sleep(1000);
                }
            });
            ThreadAutoUpdateWallet.Start();
        }
コード例 #4
0
        /// <summary>
        /// Send a transaction with token system with a selected wallet address, amount and fee.
        /// </summary>
        /// <param name="walletAddress"></param>
        /// <returns></returns>
        public static async Task <string> ProceedTransactionTokenRequestAsync(string walletAddress, string amount, string fee, string walletAddressTarget, bool anonymous)
        {
            if (anonymous)
            {
                ClassConsole.ConsoleWriteLine("Attempt to send an anonymous transaction from wallet address " + walletAddress + " of amount " + amount + " " + ClassConnectorSetting.CoinNameMin + " fee " + fee + " " + ClassConnectorSetting.CoinNameMin + " and anonymous fee option of: " + ClassConnectorSetting.MinimumWalletTransactionAnonymousFee + " " + ClassConnectorSetting.CoinNameMin + " to target -> " + walletAddressTarget, ClassConsoleColorEnumeration.IndexConsoleYellowLog, ClassConsoleLogLevelEnumeration.LogLevelWalletObject);
            }
            else
            {
                ClassConsole.ConsoleWriteLine("Attempt to send transaction from wallet address " + walletAddress + " of amount " + amount + " " + ClassConnectorSetting.CoinNameMin + " fee " + fee + " " + ClassConnectorSetting.CoinNameMin + " to target -> " + walletAddressTarget, ClassConsoleColorEnumeration.IndexConsoleYellowLog, ClassConsoleLogLevelEnumeration.LogLevelWalletObject);
            }
            if (ClassRpcDatabase.RpcDatabaseContent.ContainsKey(walletAddress))
            {
                if (!ClassRpcDatabase.RpcDatabaseContent[walletAddress].GetWalletUpdateStatus() && !ClassRpcDatabase.RpcDatabaseContent[walletAddress].GetWalletOnSendTransactionStatus())
                {
                    ClassRpcDatabase.RpcDatabaseContent[walletAddress].SetWalletOnSendTransactionStatus(true);
                    decimal balanceFromDatabase = decimal.Parse(ClassRpcDatabase.RpcDatabaseContent[walletAddress].GetWalletBalance().Replace(".", ","), NumberStyles.Currency, Program.GlobalCultureInfo);
                    decimal balanceFromRequest  = decimal.Parse(amount.Replace(".", ","), NumberStyles.Currency, Program.GlobalCultureInfo);
                    decimal feeFromRequest      = decimal.Parse(fee.Replace(".", ","), NumberStyles.Currency, Program.GlobalCultureInfo);

                    ClassRpcDatabase.RpcDatabaseContent[walletAddress].SetLastWalletUpdate(DateTimeOffset.Now.ToUnixTimeSeconds());
                    string getSeedNodeRandom = string.Empty;
                    bool   seedNodeSelected  = false;
                    foreach (var seedNode in ClassConnectorSetting.SeedNodeIp)
                    {
                        getSeedNodeRandom = seedNode.Key;
                        Task taskCheckSeedNode = Task.Run(async() => seedNodeSelected = await CheckTcp.CheckTcpClientAsync(getSeedNodeRandom, ClassConnectorSetting.SeedNodeTokenPort));
                        taskCheckSeedNode.Wait(ClassConnectorSetting.MaxTimeoutConnect);
                        if (seedNodeSelected)
                        {
                            break;
                        }
                    }
                    if (seedNodeSelected)
                    {
                        try
                        {
                            return(await SendWalletTransactionTokenAsync(getSeedNodeRandom, walletAddress, walletAddressTarget, amount, fee, anonymous));
                        }
                        catch (Exception error)
                        {
                            ClassConsole.ConsoleWriteLine("Error on send transaction from wallet: " + ClassRpcDatabase.RpcDatabaseContent[walletAddress] + " exception: " + error.Message, ClassConsoleColorEnumeration.IndexConsoleRedLog, ClassConsoleLogLevelEnumeration.LogLevelWalletObject);
                            ClassRpcDatabase.RpcDatabaseContent[walletAddress].SetWalletOnSendTransactionStatus(false);
                            return(ClassRpcWalletCommand.SendTokenTransactionRefused + "|None");
                        }
                    }
                    else
                    {
                        ClassConsole.ConsoleWriteLine("Error on send transaction from wallet: " + ClassRpcDatabase.RpcDatabaseContent[walletAddress] + " exception: can't connect on each seed nodes checked.", ClassConsoleColorEnumeration.IndexConsoleRedLog, ClassConsoleLogLevelEnumeration.LogLevelWalletObject);
                        ClassRpcDatabase.RpcDatabaseContent[walletAddress].SetWalletOnSendTransactionStatus(false);
                        return(ClassRpcWalletCommand.SendTokenTransactionRefused + "|None");
                    }
                }
                else
                {
                    if (ClassRpcDatabase.RpcDatabaseContent[walletAddress].GetWalletUpdateStatus())
                    {
                        return(RpcTokenNetworkWalletBusyOnUpdate + "|None");
                    }
                    else
                    {
                        return(ClassRpcWalletCommand.SendTokenTransactionBusy + "|None");
                    }
                }
            }

            return(RpcTokenNetworkWalletAddressNotExist + "|None");
        }
コード例 #5
0
        /// <summary>
        /// Update Wallet target
        /// </summary>
        /// <param name="walletAddress"></param>
        /// <returns></returns>
        public static async Task UpdateWallet(string walletAddress)
        {
            string getSeedNodeRandom = string.Empty;
            bool   seedNodeSelected  = false;

            foreach (var seedNode in ClassConnectorSetting.SeedNodeIp)
            {
                getSeedNodeRandom = seedNode.Key;
                Task taskCheckSeedNode = Task.Run(async() => seedNodeSelected = await CheckTcp.CheckTcpClientAsync(seedNode.Key, ClassConnectorSetting.SeedNodeTokenPort));
                taskCheckSeedNode.Wait(ClassConnectorSetting.MaxTimeoutConnect);
                if (seedNodeSelected)
                {
                    break;
                }
            }
            if (seedNodeSelected)
            {
                ClassRpcDatabase.RpcDatabaseContent[walletAddress].SetWalletOnUpdateStatus(true);
                await GetWalletBalanceTokenAsync(getSeedNodeRandom, walletAddress);

                ClassRpcDatabase.RpcDatabaseContent[walletAddress].SetWalletOnUpdateStatus(false);
            }
        }