Пример #1
0
        public void TestRemoteAccountSetTx_Property(bool localSign)
        {
            _remote = new Remote(ServerUrl, localSign);
            var resetEvent = new AutoResetEvent(false);
            AccountSetTxResponse result = null;

            _remote.Connect(_ =>
            {
                var options       = new AccountSetTxOptions();
                options.Account   = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1";
                options.Type      = AccountSetType.Property;
                options.SetFlag   = SetClearFlags.DisallowSWT;
                options.ClearFlag = SetClearFlags.NoFreeze;
                var tx            = _remote.BuildAccountSetTx(options);
                tx.SetSecret("ssGkkAMnKCBkhGVQd9CNzSQv5zdNi");
                tx.AddMemo("Unit Test AccountSet (property) at " + DateTime.Now.ToString());
                tx.Submit(r =>
                {
                    result = r.Result;
                    resetEvent.Set();
                });
            });

            Assert.IsTrue(resetEvent.WaitOne(DeferredWaitingTime));
            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
        }
Пример #2
0
        public void TestRequestServerInfo()
        {
            var deferred = new Task(() => { });

            _remote = new Remote(ServerUrl);
            MessageResult <ServerInfoResponse> response = null;

            _remote.Connect(r =>
            {
                var req = _remote.RequestServerInfo();
                req.Submit(r1 =>
                {
                    response = r1;
                    deferred.Start();
                });
            });
            Assert.IsTrue(deferred.Wait(DeferredWaitingTime));

            Assert.IsNotNull(response);
            var serverInfo = response.Result.Info;

            Assert.IsNotNull(serverInfo);
            Assert.IsNotNull(serverInfo.Ledgers);
            Assert.IsNotNull(serverInfo.Node);
            Assert.IsNotNull(serverInfo.State);
            Assert.IsNotNull(serverInfo.Version);
        }
Пример #3
0
        public void TestRemoteDeployContractTx(bool localSign)
        {
            _remote = new Remote(ServerUrl, localSign);
            var resetEvent = new AutoResetEvent(false);
            DeployContractTxResponse result = null;

            _remote.Connect(_ =>
            {
                var options     = new DeployContractTxOptions();
                options.Account = "jMw3xrkX2ySwdQiEorymyuTLUSSa85wvSr";
                options.Amount  = 0.5;
                options.Payload = "result={}; function Init(t) result=scGetAccountInfo(t) return result end; function foo(t) a={} result=scGetAccountInfo(t) return result end;";
                options.Params  = new[] { "jMw3xrkX2ySwdQiEorymyuTLUSSa85wvSr" };
                var tx          = _remote.DeployContractTx(options);
                tx.SetSecret("snhevp2qBEyPf3n8ZRDMuZGSa3BZ5");
                tx.AddMemo("Unit Test DeployContract at " + DateTime.Now.ToString());
                tx.Submit(r =>
                {
                    result = r.Result;
                    resetEvent.Set();
                });
            });

            Assert.IsTrue(resetEvent.WaitOne(DeferredWaitingTime));
            Assert.IsNotNull(result);
            Assert.AreEqual("tecNO_DST_INSUF_SWT", result.EngineResult);
        }
Пример #4
0
        public void TestRemoteCallContractTx(bool localSign)
        {
            _remote = new Remote(ServerUrl, localSign);
            var resetEvent = new AutoResetEvent(false);
            CallContractTxResponse result = null;

            _remote.Connect(_ =>
            {
                var options         = new CallContractTxOptions();
                options.Account     = "jMw3xrkX2ySwdQiEorymyuTLUSSa85wvSr";
                options.Destination = "jaVDaozkmFzCGwuBYL5wQ3SvhnUrySuofn";
                options.Foo         = "foo";
                options.Params      = new[] { "jMw3xrkX2ySwdQiEorymyuTLUSSa85wvSr" };
                var tx = _remote.CallContractTx(options);
                tx.SetSecret("snhevp2qBEyPf3n8ZRDMuZGSa3BZ5");
                tx.AddMemo("Unit Test DeployContract at " + DateTime.Now.ToString());
                tx.Submit(r =>
                {
                    result = r.Result;
                    resetEvent.Set();
                });
            });

            Assert.IsTrue(resetEvent.WaitOne(DeferredWaitingTime));
            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
            Assert.IsNotNull(result.ContractState);
        }
Пример #5
0
        public void TestRemoteOfferCreateTx_Sell(bool localSign)
        {
            _remote = new Remote(ServerUrl, localSign);
            var resetEvent = new AutoResetEvent(false);
            OfferCreateTxResponse result = null;

            _remote.Connect(_ =>
            {
                var options       = new OfferCreateTxOptions();
                options.Type      = OfferType.Sell;
                options.Account   = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1";
                options.TakerGets = Amount.SWT("0.5");
                options.TakerPays = new Amount("CNY", "jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS", "100.01");
                var tx            = _remote.BuildOfferCreateTx(options);
                tx.SetSecret("ssGkkAMnKCBkhGVQd9CNzSQv5zdNi");
                tx.AddMemo("Unit Test OfferCreate (sell) at " + DateTime.Now.ToString());
                tx.Submit(r =>
                {
                    result = r.Result;
                    resetEvent.Set();
                });
            });

            Assert.IsTrue(resetEvent.WaitOne(DeferredWaitingTime));
            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
        }
Пример #6
0
        public void TestRequestPathFind()
        {
            var deferred = new Task(() => { });

            _remote = new Remote(ServerUrl);
            MessageResult <PathFindResponse> response = null;

            _remote.Connect(r =>
            {
                var options         = new PathFindOptions();
                options.Account     = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1";
                options.Destination = "jBKaXuYemkAb5HytZgosAcWgWDZbBvz6KR";
                options.Amount      = new Amount("CNY", "jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS", "0.1");
                var req             = _remote.RequestPathFind(options);
                req.Submit(r1 =>
                {
                    response = r1;
                    deferred.Start();
                });
            });
            Assert.IsTrue(deferred.Wait(DeferredWaitingTime));

            Assert.IsNotNull(response);
            var result = response.Result;

            Assert.IsNotNull(result);
            Assert.AreEqual("j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1", result.Source);
            Assert.AreEqual("jBKaXuYemkAb5HytZgosAcWgWDZbBvz6KR", result.Destination);
        }
Пример #7
0
        public void TestRequestLedgerClosed()
        {
            var deferred = new Task(() => { });

            _remote = new Remote(ServerUrl);
            MessageResult <LedgerClosedResponse> response = null;

            _remote.Connect(r =>
            {
                var req = _remote.RequestLedgerClosed();
                req.Submit(r1 =>
                {
                    response = r1;
                    deferred.Start();
                });
            });
            Assert.IsTrue(deferred.Wait(DeferredWaitingTime));

            Assert.IsNotNull(response);
            var ledger = response.Result;

            Assert.IsNotNull(ledger);
            Assert.IsTrue(ledger.LedgerIndex > 0);
            Assert.IsNotNull(ledger.LedgerHash);
        }
Пример #8
0
        public void TestRemotePaymentTx(bool localSign)
        {
            _remote = new Remote(ServerUrl, localSign);
            var resetEvent           = new AutoResetEvent(false);
            PaymentTxResponse result = null;

            _remote.Connect(_ =>
            {
                var options     = new PaymentTxOptions();
                options.Account = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1";
                options.To      = "jBKaXuYemkAb5HytZgosAcWgWDZbBvz6KR";
                options.Amount  = Amount.SWT("0.5");
                var tx          = _remote.BuildPaymentTx(options);
                tx.SetSecret("ssGkkAMnKCBkhGVQd9CNzSQv5zdNi");
                tx.AddMemo("Unit Test PaymentTx at " + DateTime.Now.ToString());
                tx.Submit(r =>
                {
                    result = r.Result;
                    resetEvent.Set();
                });
            });

            Assert.IsTrue(resetEvent.WaitOne(DeferredWaitingTime));
            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
        }
Пример #9
0
        public void TestRemoteRelationTx_RelationDel(bool localSign)
        {
            _remote = new Remote(ServerUrl, localSign);
            var resetEvent            = new AutoResetEvent(false);
            RelationTxResponse result = null;

            _remote.Connect(_ =>
            {
                var options     = new RelationTxOptions();
                options.Account = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1";
                options.Type    = RelationType.Unfreeze;
                options.Target  = "jMw3xrkX2ySwdQiEorymyuTLUSSa85wvSr";
                options.Limit   = new Amount("CNY", "jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS", "100");
                var tx          = _remote.BuildRelationTx(options);
                tx.SetSecret("ssGkkAMnKCBkhGVQd9CNzSQv5zdNi");
                tx.AddMemo("Unit Test relation (relation del) at " + DateTime.Now.ToString());
                tx.Submit(r =>
                {
                    result = r.Result;
                    resetEvent.Set();
                });
            });

            Assert.IsTrue(resetEvent.WaitOne(DeferredWaitingTime));
            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
        }
Пример #10
0
        public void TestRequestAccountTx()
        {
            var deferred = new Task(() => { });

            _remote = new Remote(ServerUrl);
            MessageResult <AccountTxResponse> response = null;

            _remote.Connect(r =>
            {
                var options     = new AccountTxOptions();
                options.Limit   = 1;
                options.Account = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1";
                var req         = _remote.RequestAccountTx(options);
                req.Submit(r1 =>
                {
                    response = r1;
                    deferred.Start();
                });
            });
            Assert.IsTrue(deferred.Wait(DeferredWaitingTime));

            Assert.IsNotNull(response);
            var result = response.Result;

            Assert.IsNotNull(result);
            Assert.AreEqual("j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1", result.Account);
            Assert.IsNotNull(result.Transactions);
            Assert.IsNotNull(result.Marker);
        }
Пример #11
0
        public void TestRequestTasksAsync()
        {
            var deferred = new Task(() => { });
            var remote   = new Remote(ServerUrl);

            object[] results = new object[3];
            remote.Connect(r =>
            {
                if (r.Exception != null)
                {
                    deferred.Start();
                }
                else
                {
                    var t1 = remote.RequestServerInfo().SubmitAsync();
                    var t2 = remote.RequestLedgerClosed().SubmitAsync();
                    var t3 = remote.RequestLedger().SubmitAsync();

                    Task.WhenAll(t1, t2, t3).ContinueWith(p =>
                    {
                        results[0] = t1.Result.Result;
                        results[1] = t2.Result.Result;
                        results[2] = t3.Result.Result;
                        deferred.Start();
                    });
                }
            });

            Assert.IsTrue(deferred.Wait(DeferredWaitingTime * 3));

            Assert.IsInstanceOfType(results[0], typeof(ServerInfoResponse));
            Assert.IsInstanceOfType(results[1], typeof(LedgerClosedResponse));
            Assert.IsInstanceOfType(results[2], typeof(LedgerResponse));
        }
Пример #12
0
        public void TestRemoteOfferCancelTx(bool localSign)
        {
            _remote = new Remote(ServerUrl, localSign);
            var resetEvent = new AutoResetEvent(false);
            OfferCancelTxResponse result = null;

            _remote.Connect(_ =>
            {
                var options      = new OfferCancelTxOptions();
                options.Account  = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1";
                options.Sequence = 1;
                var tx           = _remote.BuildOfferCancelTx(options);
                tx.SetSecret("ssGkkAMnKCBkhGVQd9CNzSQv5zdNi");
                tx.AddMemo("Unit Test OfferCancel at " + DateTime.Now.ToString());
                tx.Submit(r =>
                {
                    result = r.Result;
                    resetEvent.Set();
                });
            });

            Assert.IsTrue(resetEvent.WaitOne(DeferredWaitingTime));
            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
        }
Пример #13
0
        public void TestTransactionTasksAsync_LocalSign()
        {
            var deferred = new Task(() => { });
            var remote   = new Remote(ServerUrl, true);

            object result     = null;
            var    resetEvent = new System.Threading.AutoResetEvent(false);

            remote.Connect(r =>
            {
                var options     = new PaymentTxOptions();
                options.Account = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1";
                options.To      = "jMw3xrkX2ySwdQiEorymyuTLUSSa85wvSr";
                options.Amount  = Amount.SWT("0.5");
                var tx          = remote.BuildPaymentTx(options);
                tx.SetSecret("ssGkkAMnKCBkhGVQd9CNzSQv5zdNi");
                var task = tx.SubmitAsync();
                task.ContinueWith(_ =>
                {
                    result = task.Result.Result;
                    resetEvent.Set();
                });
            });
            resetEvent.WaitOne();

            Assert.IsNotNull(result);
        }
Пример #14
0
        public void TestConnectResponse()
        {
            var remote = new Remote("");

            remote.SetMockServer(new MockServer(remote, "Connect.json", false));
            MessageResult <ConnectResponse> response = null;
            var deferred = new Task(() => { });

            remote.Connect(r =>
            {
                response = r;
                deferred.Start();
            });

            Assert.IsTrue(deferred.Wait(DeferredWaitingTime));

            Assert.IsNotNull(response.Result);
            var result = response.Result;

            Assert.AreEqual(10, result.FeeBase);
            Assert.AreEqual(10, result.FeeRef);
            Assert.AreEqual("iZ2848appwoZ", result.HostId);
            Assert.AreEqual("EA11FCEE992292106808E2D3B124EF6C63B7EDE4E094177F96785F8D6AC8344B", result.LedgerHash);
            Assert.AreEqual((uint)1640880, result.LedgerIndex);
            Assert.AreEqual(Utils.UnixTimeToDateTime(579432630), result.LedgerTime);
            Assert.AreEqual(256, result.LoadBase);
            Assert.AreEqual(256, result.LoadFactor);
            Assert.AreEqual("n9M1PrHjWz6GV6y6zaJk1UrPe3cik7hgvnoDAGNpyieQFA5BwfXq", result.PubkeyNode);
            Assert.AreEqual(10000000, result.ReserveBase);
            Assert.AreEqual(1000000, result.ReserveInc);
            Assert.AreEqual("proposing", result.Status);
            Assert.AreEqual("1439816-1640880", result.ValidatedLedgers);
        }
Пример #15
0
        public void TestRequestAccountTums()
        {
            var deferred = new Task(() => { });

            _remote = new Remote(ServerUrl);
            MessageResult <AccountTumsResponse> response = null;

            _remote.Connect(r =>
            {
                var options     = new AccountTumsOptions();
                options.Account = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1";
                var req         = _remote.RequestAccountTums(options);
                req.Submit(r1 =>
                {
                    response = r1;
                    deferred.Start();
                });
            });
            Assert.IsTrue(deferred.Wait(DeferredWaitingTime));

            Assert.IsNotNull(response);
            var result = response.Result;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.SendCurrencies);
            Assert.IsNotNull(result.ReceiveCurrencies);
        }
Пример #16
0
        public void TestRequestOrderBook()
        {
            var deferred = new Task(() => { });

            _remote = new Remote(ServerUrl);
            MessageResult <OrderBookResponse> response = null;

            _remote.Connect(r =>
            {
                var options   = new OrderBookOptions();
                options.Limit = 1;
                options.Gets  = Amount.SWT();
                options.Pays  = new Amount("CNY", "jBciDE8Q3uJjf111VeiUNM775AMKHEbBLS");
                var req       = _remote.RequestOrderBook(options);
                req.Submit(r1 =>
                {
                    response = r1;
                    deferred.Start();
                });
            });
            Assert.IsTrue(deferred.Wait(DeferredWaitingTime));

            Assert.IsNotNull(response);
            var result = response.Result;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Offers);
        }
Пример #17
0
        public void TestRemoteAccountSetTx_Delegate(bool localSign)
        {
            _remote = new Remote(ServerUrl, localSign);
            var resetEvent = new AutoResetEvent(false);
            AccountSetTxResponse result = null;

            _remote.Connect(_ =>
            {
                var options         = new AccountSetTxOptions();
                options.Account     = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1";
                options.Type        = AccountSetType.Delegate;
                options.DelegateKey = "jMw3xrkX2ySwdQiEorymyuTLUSSa85wvSr";
                var tx = _remote.BuildAccountSetTx(options);
                tx.SetSecret("ssGkkAMnKCBkhGVQd9CNzSQv5zdNi");
                tx.AddMemo("Unit Test AccountSet (delegate) at " + DateTime.Now.ToString());
                tx.Submit(r =>
                {
                    result = r.Result;
                    resetEvent.Set();
                });
            });

            Assert.IsTrue(resetEvent.WaitOne(DeferredWaitingTime));
            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
        }
Пример #18
0
        static void RemoteExample(Remote remote)
        {
            remote.Connect("ws://localhost:5556").Wait();

            remote.RemoteCall <int>("fizz", "Print", "Hello from C#!").Wait();
            Log.LogInformation("4 + 3 = ? (Remote call)");
            int result = remote.RemoteCall <int>("fazz", "AddTwo", new AddNumbers()
            {
                A = 4,
                B = 3,
            }).GetAwaiter().GetResult().Value;

            Log.LogInformation($"  4 + 3 = {result}");
        }
Пример #19
0
    private IEnumerator LoginCoroutine(string user)
    {
        _Status = "Connecting ...";

        Game game = Game.GetInstance();

        game.ClearRemote();

        Packet.Config pc     = game.GetNetworkConfig();
        Remote        remote = new Remote();

        remote.Connect(pc.host, pc.port);
        remote.ProcessEvents();
        yield return(new WaitForSeconds(0.1f));

        for (int i = 0; i < 10; i++)
        {
            if (remote.Connected())
            {
                break;
            }
            if (remote.ConnectFailed())
            {
                break;
            }

            remote.ProcessEvents();
            yield return(new WaitForSeconds(i * 0.1f));
        }

        if (remote.Connected())
        {
            _Status = "Connected ...";

            // send login
            Packet packet = remote.GetPacket();
            packet.SendLogin(user);

            game.SetRemote(remote);

            _Status = "Loading ...";
            Application.LoadLevel("Chat");
        }
        else
        {
            _Status = "Connect Fail ...";
        }
    }
Пример #20
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - -

        private void Connect()
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("Connect:begin");
            }

            StateChange(SyncState.Connecting);
            Local.Connect();
            Remote.Connect();
            StateChange(SyncState.Connected);

            if (log.IsDebugEnabled)
            {
                log.Debug("Connect:end");
            }
        }
Пример #21
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            ClearResult();

            DisconnectImp();

            _remote = new JingTum.Lib.Remote(txtServerUrl.Text, chkLocalSign.Checked);
            _remote.ServerStatusChanged += _remote_ServerStatusChanged;
            _remote.Connect(result =>
            {
                ShowResult(result);
                if (result != null)
                {
                    UpdateTabsEnabled(true);
                }
            });
        }
Пример #22
0
        public void TestRequestTx()
        {
            var deferred = new Task(() => { });

            _remote = new Remote(ServerUrl);
            MessageResult <TxResponse> response = null;

            _remote.Connect(r =>
            {
                var options = new TxOptions();
                // tx for active account "jMw3xrkX2ySwdQiEorymyuTLUSSa85wvSr" in test server
                options.Hash = "3B92FD6E5A950BEFC7DB6F220CF162236148F01F8FA61C3CFA11CD1ECCC195CC";
                var req      = _remote.RequestTx(options);
                req.Submit(r1 =>
                {
                    response = r1;
                    deferred.Start();
                });
            });
            Assert.IsTrue(deferred.Wait(DeferredWaitingTime));

            Assert.IsNotNull(response);
            var tx = response.Result;

            Assert.IsNotNull(tx);
            Assert.AreEqual("3B92FD6E5A950BEFC7DB6F220CF162236148F01F8FA61C3CFA11CD1ECCC195CC", tx.Hash);
            Assert.AreEqual("jHb9CJAWyB4jr91VRWn96DkukG4bwdtyTh", tx.Account);
            Assert.AreEqual("jMw3xrkX2ySwdQiEorymyuTLUSSa85wvSr", tx.Destination);
            Assert.AreEqual(new Amount {
                Currency = "SWT", Issuer = "", Value = "10000"
            }, tx.Amount);
            Assert.AreEqual(TransactionType.Payment, tx.TransactionType);

            var txr = tx.TxResult as SentTxResult;

            Assert.IsNotNull(txr);
            Assert.AreEqual("3B92FD6E5A950BEFC7DB6F220CF162236148F01F8FA61C3CFA11CD1ECCC195CC", txr.Hash);
            Assert.AreEqual("jMw3xrkX2ySwdQiEorymyuTLUSSa85wvSr", txr.CounterParty);
            Assert.AreEqual(new Amount {
                Currency = "SWT", Issuer = "", Value = "10000"
            }, txr.Amount);
            Assert.AreEqual(TxResultType.Sent, txr.Type);
        }
Пример #23
0
        public void TestConnect()
        {
            var deferred = new Task(() => { });

            _remote = new Remote(ServerUrl);
            MessageResult <ConnectResponse> response = null;

            _remote.Connect(r =>
            {
                response = r;
                deferred.Start();
            });
            Assert.IsTrue(deferred.Wait(DeferredWaitingTime));

            Assert.IsTrue(_remote.IsConnected);
            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Result);
            Assert.IsNotNull(response.Message);
            Assert.IsNull(response.Exception);
        }
Пример #24
0
        public void TestFailedConnect()
        {
            var deferred = new Task(() => { });
            var fakeUrl  = @"ws://123.456.789.1:5020";

            _remote = new Remote(fakeUrl);
            MessageResult <ConnectResponse> response = null;

            _remote.Connect(r =>
            {
                response = r;
                deferred.Start();
            });
            Assert.IsTrue(deferred.Wait(DeferredWaitingTime));

            Assert.IsFalse(_remote.IsConnected);
            Assert.IsNull(response.Result);
            Assert.IsNull(response.Message);
            Assert.IsInstanceOfType(response.Exception, typeof(SocketException));
        }
Пример #25
0
        public override void Execute(string[] Args)
        {
            Program.Print("Saljem podatke na stranicu...");

            string mac = Program.ArgValue(Args, "mac"), pass = Program.ArgValue(Args, "pass");

            Program.PUBLIC_IP = Program.HtmlResponse("https://ifconfig.me/ip");
            JSONElement json = JSON.Parse(Program.HtmlResponse("http://alantr7.uwebweb.com/alan/request/device.php", $"device={mac}&password={pass}"));

            if (json.c["status"].ToString() == "success")
            {
                string ip = json.c["ip"].ToString();

                Program.Print("IP preuzet. Povezivanje...");
                Remote.Connect(ip, mac).Wait();
            }
            else
            {
                Program.Print($"Greska: " + json.c["error"].ToString());
            }
        }
Пример #26
0
    private void LoginThread(string user)
    {
        Game game = Game.GetInstance();

        game.ClearRemote();

        Packet.Config pc     = game.GetNetworkConfig();
        Remote        remote = new Remote();

        remote.Connect(pc.host, pc.port);
        remote.ProcessEvents();
        Thread.Sleep(1000);
        for (int i = 0; i < 10; i++)
        {
            if (remote.Connected())
            {
                break;
            }
            if (remote.ConnectFailed())
            {
                break;
            }

            remote.ProcessEvents();
            Thread.Sleep(50 * i);
        }

        if (!remote.Connected())
        {
            return;
        }

        // send login
        Packet packet = remote.GetPacket();

        packet.SendLogin(user);

        game.SetRemote(remote);
    }
Пример #27
0
        private void button1_Click(object sender, EventArgs e)
        {
            var secret  = textBox2.Text;
            var address = textBox3.Text;
            var url     = textBox1.Text;

            if (string.IsNullOrEmpty(url))
            {
                MessageBox.Show("Please input host url.");
                return;
            }

            try
            {
                Wallet wallet = null;
                if (!string.IsNullOrEmpty(secret))
                {
                    wallet        = Wallet.FromSecret(secret);
                    Global.Wallet = wallet;
                }
                else if (string.IsNullOrEmpty(address))
                {
                    MessageBox.Show("Please input account address.");
                    return;
                }
                else
                {
                    Global.Account = address;
                }

                var       remote    = new Remote(url, false);
                var       task      = new Task(() => { });
                Exception connectEx = null;
                remote.Connect(result => {
                    if (result.Exception != null)
                    {
                        connectEx = result.Exception;
                    }
                    else
                    {
                        Global.Connection = result.Result;
                    }
                    task.Start();
                });

                task.Wait();
                if (connectEx != null)
                {
                    throw connectEx;
                }

                var old = Global.Remote;
                Global.Remote = remote;
                old?.Dispose();
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #28
0
        public void TestRequestLedger()
        {
            var deferred = new Task(() => { });

            _remote = new Remote(ServerUrl);
            MessageResult <LedgerResponse> response = null;

            _remote.Connect(r =>
            {
                // closed ledger
                var req = _remote.RequestLedger();
                req.Submit(r1 =>
                {
                    response = r1;
                    deferred.Start();
                });
            });
            Assert.IsTrue(deferred.Wait(DeferredWaitingTime));

            Assert.IsNotNull(response);
            var ledger = response.Result.Ledger;

            Assert.IsNotNull(ledger);
            Assert.IsTrue(ledger.LedgerIndex > 0);
            Assert.IsNotNull(ledger.LedgerHash);

            var ledgerIndex = ledger.LedgerIndex;
            var ledgerHash  = ledger.LedgerHash;

            deferred = new Task(() => { });
            response = null;
            var options = new LedgerOptions();

            options.LedgerIndex = ledgerIndex;
            _remote.RequestLedger(options).Submit(r =>
            {
                response = r;
                deferred.Start();
            });
            Assert.IsTrue(deferred.Wait(DeferredWaitingTime * 2));

            Assert.IsNotNull(response);
            ledger = response.Result.Ledger;
            Assert.IsNotNull(ledger);
            Assert.AreEqual(ledgerIndex, ledger.LedgerIndex);
            Assert.AreEqual(ledgerHash, ledger.LedgerHash);

            deferred             = new Task(() => { });
            response             = null;
            options.Accounts     = true;
            options.Transactions = true;
            _remote.RequestLedger(options).Submit(r =>
            {
                response = r;
                deferred.Start();
            });
            Assert.IsTrue(deferred.Wait(DeferredWaitingTime * 2));

            Assert.IsNotNull(response);
            ledger = response.Result.Ledger;
            Assert.IsNotNull(ledger);
            Assert.AreEqual(ledgerIndex, ledger.LedgerIndex);
            Assert.AreEqual(ledgerHash, ledger.LedgerHash);
            Assert.IsNotNull(ledger.Transactions);  // has transactions data
            Assert.IsNotNull(ledger.AccountStates); // has accountStates data
        }