Ejemplo n.º 1
0
        private bool AskAPI()
        {
            ushort i = 0;

            Console.WriteLine("Before we can begin, we need to set up the API params for bitmessage.");
            Console.WriteLine("You need to enable the API first, before you continue here.");
            Console.WriteLine("See this Article for help: https://bitmessage.org/wiki/API");
            Console.WriteLine();
            Console.WriteLine("Enter Bitmessage API Settings below:");
            Console.Write("IP Address: ");
            string IP = Console.ReadLine();

            Console.Write("Port: ");
            string Port = Console.ReadLine();

            Console.Write("Username: "******"Password: "******"Shop address: ");
            Addr = Console.ReadLine();

            //Verify values quick and dirty
            if (IP.Length > 0 && Port.Length > 0 && UN.Length > 0 && PW.Length > 0 && ushort.TryParse(Port, out i) && Addr.Length > 0)
            {
                QuickSettings.Set("API-ADDR", IP + ":" + Port);
                QuickSettings.Set("API-NAME", UN);
                QuickSettings.Set("API-PASS", PW);
                QuickSettings.Set("BM-ADDR", Addr);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public void Start()
        {
            if (T != null)
            {
                Stop();
            }

            GenericServerLog(this, GenericLogType.Info, false, "Starting Bitmessage server");

            //Check if API has been set
            if (!QuickSettings.Has("API-ADDR") || !QuickSettings.Has("API-NAME") || !QuickSettings.Has("API-PASS") || !QuickSettings.Has("BM-ADDR"))
            {
                if (!AskAPI())
                {
                    GenericServerLog(this, GenericLogType.Fatal, true, "API Settings for Bitmessage have not been made. Please configure Bitmessage Plugin");
                    throw new Exception("API Settings for Bitmessage have not been made. Please configure Bitmessage Plugin");
                }
            }

            Addr   = QuickSettings.Get("BM-ADDR");
            BA     = (BitAPI)XmlRpcProxyGen.Create(typeof(BitAPI));
            BA.Url = string.Format("http://{0}/", QuickSettings.Get("API-ADDR"));
            BA.Headers.Add("Authorization", "Basic " + JsonConverter.B64enc(string.Format("{0}:{1}", QuickSettings.Get("API-NAME"), QuickSettings.Get("API-PASS"))));

            try
            {
                if (BA.helloWorld("A", "B") != "A-B")
                {
                    GenericServerLog(this, GenericLogType.Error, true, "API Settings for Bitmessage are wrong. The API seems to answer, but the answer is incorrect. Please check settings");
                    throw new Exception("API Settings for Bitmessage are wrong. The API seems to answer, but the answer is incorrect. Please check settings");
                }
            }
            catch
            {
                GenericServerLog(this, GenericLogType.Error, true, "Cannot contact Bitmessage API. Verify the client is running, has the API enabled and the settings are correct");
                throw new Exception("Cannot contact Bitmessage API. Verify the client is running, has the API enabled and the settings are correct");
            }
            T = new Thread(run);
            T.IsBackground = true;
            T.Start();
        }