Ejemplo n.º 1
0
        public void AddressVerfy()
        {
            bool result = AddressTools.AddressVerfy("main", "fiiimB6yxbLHKU2YuLhSDSjiB5mdWXt51duHBi");

            //bool rbsult = AddressTools.AddressVerfy("test", "fiiit2sTHKSFrYJHo1ddUNNHCKqJnAhjATgr6c");
            Assert.IsTrue(result);
        }
Ejemplo n.º 2
0
        public bool VerfyAddress(string netType, string account)
        {
            bool result = false;

            try
            {
                result = AddressTools.AddressVerfy(netType, account);
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error(ex.Message);
            }
            return(result);
        }
Ejemplo n.º 3
0
        public bool VerfyAddress(NetworkType network, string account)
        {
            bool result = false;

            try
            {
                result = AddressTools.AddressVerfy(network.ToString().ToLower(), account);
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error(ex.ToString());
            }
            return(result);
        }
Ejemplo n.º 4
0
        public async Task TestSendToAddress()
        {
            ApiResponse blockChainResponse = await BlockChainEngineApi.GetBlockChainStatus();

            if (!blockChainResponse.HasError)
            {
                //地址
                string address = "fiiitCPyohiEPn9q11AXCdvVDouoVvgojXBcVj";
                //地址校验
                BlockChainStatus blockChainStatus = blockChainResponse.GetResult <BlockChainStatus>();
                //验证address
                if (AddressTools.AddressVerfy(blockChainStatus.ChainNetwork, address))
                {
                    //判断是否加密
                    ApiResponse transactionResponse = await TransactionApi.GetTxSettings();

                    if (!transactionResponse.HasError)
                    {
                        TransactionFeeSetting settingResult = transactionResponse.GetResult <TransactionFeeSetting>();
                        if (settingResult.Encrypt)
                        {
                            //先解锁
                            string      password       = "******";
                            ApiResponse unlockResponse = await WalletManagementApi.WalletPassphrase(password);

                            if (!unlockResponse.HasError)
                            {
                                ApiResponse response = await TransactionApi.SendToAddress(address, 50000000, "this is your request", "John", false);

                                Assert.IsFalse(response.HasError);
                                string result = response.GetResult <string>();
                                Assert.IsNotNull(result);
                            }
                            ApiResponse lockResponse = await WalletManagementApi.WalletLock();
                        }
                        else
                        {
                            ApiResponse response = await TransactionApi.SendToAddress(address, 50000000, "this is your request", "John", false);

                            Assert.IsFalse(response.HasError);
                            string result = response.GetResult <string>();
                            Assert.IsNotNull(result);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public async Task AddNewAddressBookItem()
        {
            //fiiit6ZgKDM5ZyDYhkSWDsUmRZpkbRQf7NWiKT
            //先根据接口获取网络类型
            ApiResponse blockChainResponse = await BlockChainEngineApi.GetBlockChainStatus();

            if (!blockChainResponse.HasError)
            {
                BlockChainStatus blockChainStatus = blockChainResponse.GetResult <BlockChainStatus>();
                //验证address
                if (AddressTools.AddressVerfy(blockChainStatus.ChainNetwork, "fiiit6ZgKDM5ZyDYhkSWDsUmRZpkbRQf7NWiKT"))
                {
                    ApiResponse addressBookResponse = await AddressBookApi.AddNewAddressBookItem("fiiit6ZgKDM5ZyDYhkSWDsUmRZpkbRQf7NWiKT", "label or comment");

                    if (!addressBookResponse.HasError)
                    {
                        //do something
                    }
                }
            }
        }
Ejemplo n.º 6
0
        static void Run(string[] args)
        {
            var app = new CommandLineApplication(false);

            app.HelpOption("-?|-h|--help");
            app.OnExecute(() =>
            {
                app.ShowHelp();
                return;
            });
            app.Command("mining", command =>
            {
                command.Description = "begin mining";
                command.HelpOption("-?|-h|--help");
                CommandArgument nameArgument    = command.Argument("[minerName]", "minerName");
                CommandArgument addressArgument = command.Argument("[walletAddress]", "walletAddress");
                command.OnExecute(async() =>
                {
                    if (nameArgument != null && !string.IsNullOrEmpty(nameArgument.Value) && addressArgument != null && !string.IsNullOrEmpty(addressArgument.Value))
                    {
                        string name     = nameArgument.Value;
                        string address  = addressArgument.Value;
                        Program program = new Program();
                        BlockChainStatus chainStatus = await program.GetChainStatus();
                        if (chainStatus == null)
                        {
                            app.Out.WriteLine("there is something wrong with the api, you should check the fiiichain");
                            return;
                        }
                        //验证本地区块高度和网络区块高度
                        ApiResponse response = await NetworkApi.GetBlockChainInfo();
                        if (!response.HasError)
                        {
                            BlockChainInfo info = response.GetResult <BlockChainInfo>();
                            if (info.IsRunning)
                            {
                                if (info.RemoteLatestBlockHeight <= info.LocalLastBlockHeight)
                                {
                                    command.Out.WriteLine($"current network is {chainStatus.ChainNetwork}");
                                    //validate wallet address
                                    if (AddressTools.AddressVerfy(chainStatus.ChainNetwork, address))
                                    {
                                        command.Out.WriteLine($"address verify success. prepare to mine");
                                        await BlockMining.MiningAsync(name, address);
                                    }
                                    else
                                    {
                                        command.Out.WriteLine($"address verify fail. address: {address} is invalid");
                                        return;
                                    }
                                }
                                else
                                {
                                    command.Out.WriteLine("Block Chain is in sync, please try it later");
                                    return;
                                }
                            }
                            else
                            {
                                command.Out.WriteLine("Block Chain has stopped");
                                return;
                            }
                        }
                        else
                        {
                            command.Out.WriteLine(response.Error.Message);
                            return;
                        }
                    }
                    else
                    {
                        command.ShowHelp();
                        return;
                    }
                });
            });
            app.Command("height", command =>
            {
                command.Description = "view current block height";
                command.OnExecute(async() =>
                {
                    Program program = new Program();
                    BlockChainStatus chainStatus = await program.GetChainStatus();
                    if (chainStatus == null)
                    {
                        app.Out.WriteLine("there is something wrong with the api, you should check the fiiichain");
                        return;
                    }
                    ApiResponse response = await BlockChainEngineApi.GetBlockCount();
                    if (!response.HasError)
                    {
                        long result = response.GetResult <long>();
                        command.Out.WriteLine($"current block height is {result}");
                    }
                    else
                    {
                        command.Out.WriteLine($"{response.Error.Message}");
                    }
                });
            });
            app.Command("balance", command =>
            {
                command.Description = "view wallet balance";
                command.OnExecute(async() =>
                {
                    Program program = new Program();
                    BlockChainStatus chainStatus = await program.GetChainStatus();
                    if (chainStatus == null)
                    {
                        app.Out.WriteLine("there is something wrong with the api, you should check the fiiichain");
                        return;
                    }
                    ApiResponse response = await UtxoApi.GetTxOutSetInfo();
                    if (!response.HasError)
                    {
                        TxOutSet set = response.GetResult <TxOutSet>();
                        command.Out.WriteLine($"wallet balance is :{set.Total_amount}");
                    }
                });
            });
            app.Command("transaction", command =>
            {
                command.Description            = "view recent transaction record(default 5 content)";
                CommandArgument recordArgument = command.Argument("[count]", "record content");
                command.OnExecute(async() =>
                {
                    if (recordArgument != null && !string.IsNullOrEmpty(recordArgument.Value))
                    {
                        if (int.TryParse(recordArgument.Value, out int count))
                        {
                            Program program = new Program();
                            BlockChainStatus chainStatus = await program.GetChainStatus();
                            if (chainStatus == null)
                            {
                                app.Out.WriteLine("there is something wrong with the api, you should check the fiiichain");
                                return;
                            }
                            ApiResponse response = await TransactionApi.ListTransactions("*", count);
                            if (!response.HasError)
                            {
                                List <Payment> result = response.GetResult <List <Payment> >();
                                if (result != null && result.Count > 0)
                                {
                                    command.Out.WriteLine("recent transaction record blow:");
                                    foreach (var item in result)
                                    {
                                        //time(需要转换为DataTime), comment, amount
                                        string time = new DateTime(1970, 1, 1).AddMilliseconds(item.Time).ToString("yyyy-MM-dd HH:mm:ss");
                                        command.Out.WriteLine($"Time:{time}; Comment:{item.Comment}; Amount:{item.Amount}");
                                    }
                                }
                                else
                                {
                                    command.Out.WriteLine("no recent transaction record.");
                                }
                            }
                        }
                        else
                        {
                            command.ShowHelp();
                        }
                    }
                    else
                    {
                        Program program = new Program();
                        BlockChainStatus chainStatus = await program.GetChainStatus();
                        if (chainStatus == null)
                        {
                            app.Out.WriteLine("there is something wrong with the api, you should check the fiiichain");
                            return;
                        }
                        ApiResponse response = await TransactionApi.ListTransactions();
                        if (!response.HasError)
                        {
                            List <Payment> result = response.GetResult <List <Payment> >();
                            if (result != null && result.Count > 0)
                            {
                                command.Out.WriteLine("recent transaction record blow:");
                                foreach (var item in result)
                                {
                                    //time(需要转换为DataTime), comment, amount
                                    string time = new DateTime(1970, 1, 1).AddMilliseconds(item.Time).ToString("yyyy-MM-dd HH:mm:ss");
                                    command.Out.WriteLine($"Time:{time}; Comment:{item.Comment}; Amount:{item.Amount}");
                                }
                            }
                            else
                            {
                                command.Out.WriteLine("no recent transaction record.");
                            }
                        }
                    }
                });
            });

            /*
             * if (args.Length > 1 && args[0].ToLower() == "fiiipay" && IsContainsCommand(args[1]))
             * {
             *  List<string> list = new List<string>(args);
             *  list.RemoveAt(0);
             *  app.Execute(list.ToArray());
             * }
             */
            if (args != null && args.Length > 0 && IsContainsCommand(args[0]))
            {
                app.Execute(args);
            }
            else
            {
                app.Execute(new[] { "-?" });
            }
        }
Ejemplo n.º 7
0
        void OnRequestCreateUrl(UrlInfo urlInfo)
        {
            if (urlInfo == null)
            {
                return;
            }
            var netstr = OmniCoinSetting.NodeTypeStr;

            if (!AddressTools.AddressVerfy(netstr, urlInfo.Address))
            {
                ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Error_Address));
                return;
            }
            switch (urlInfo.Mode)
            {
            case UrlMode.CreatePay:
                if (UrlInfos.Any(x => x.Address.Equals(urlInfo.Address)))
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Address_Existed));
                    return;
                }
                StaticViewModel.GlobalViewModel.IsLoading = true;
                var result = AddressBookService.Default.UpsertAddrBookItem(urlInfo.Address, urlInfo.Tag);
                if (!result.IsFail)
                {
                    LoadUrls();
                }
                else
                {
                    ShowMessage(result.GetErrorMsg());
                }
                break;

            case UrlMode.Edit:
                if (UrlInfos.Any(x => x.Address.Equals(urlInfo.Address) && x.Id != urlInfo.Id))
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Address_Existed));
                    return;
                }
                var updateResult = AddressBookService.Default.UpsertAddrBookItem(urlInfo.Address, urlInfo.Tag, urlInfo.Id);
                if (!updateResult.IsFail)
                {
                    var selectedUrlinfo = UrlInfos.FirstOrDefault(x => x.Id == urlInfo.Id);
                    if (selectedUrlinfo == null)
                    {
                        UrlInfos.Add(urlInfo);
                    }
                    else
                    {
                        selectedUrlinfo.Tag     = urlInfo.Tag;
                        selectedUrlinfo.Address = urlInfo.Address;
                        selectedUrlinfo.Mode    = urlInfo.Mode;
                        SelectedItem            = selectedUrlinfo;
                    }
                }
                else
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Edit_Fail));
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 8
0
        void OnRequestCreateUrl(UrlInfo urlInfo)
        {
            if (urlInfo == null)
            {
                return;
            }
            var netstr = "mainnet";

            switch (NodeSetting.CurrentNetworkType)
            {
            case Biz.NetworkType.MainnetPort:
                break;

            case Biz.NetworkType.TestNetPort:
                netstr = "testnet";
                break;

            default:
                break;
            }

            if (!AddressTools.AddressVerfy(netstr, urlInfo.Address))
            {
                ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Error_Address));
                return;
            }
            switch (urlInfo.Mode)
            {
            case UrlMode.CreatePay:
                if (UrlInfos.Any(x => x.Address.Equals(urlInfo.Address)))
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Address_Existed));
                    return;
                }
                var result = AddressBookService.Default.AddNewAddressBookItem(urlInfo.Address, urlInfo.Tag);
                if (!result.IsFail)
                {
                    //UrlInfos.Add(urlInfo);
                    LoadUrls();
                }
                else
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Add_Fail));
                }
                break;

            case UrlMode.Edit:
                if (UrlInfos.Any(x => x.Address.Equals(urlInfo.Address) && x.Id != urlInfo.Id))
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Address_Existed));
                    return;
                }
                var updateResult = AddressBookService.Default.AddNewAddressBookItem(urlInfo.Address, urlInfo.Tag);
                if (!updateResult.IsFail)
                {
                    var urlinfo = UrlInfos.FirstOrDefault(x => x.Id == urlInfo.Id);
                    if (urlinfo == null)
                    {
                        UrlInfos.Add(urlInfo);
                    }
                    else
                    {
                        urlinfo.Tag     = urlInfo.Tag;
                        urlinfo.Address = urlInfo.Address;
                    }
                }
                else
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Edit_Fail));
                }
                SelectedItem.Address = urlInfo.Address;
                SelectedItem.Tag     = urlInfo.Tag;
                SelectedItem.Mode    = urlInfo.Mode;
                break;

            default:
                break;
            }
        }
Ejemplo n.º 9
0
        public bool VerfyAddress(string netType, string account)
        {
            bool result = AddressTools.AddressVerfy(netType, account);

            return(result);
        }