Esempio n. 1
0
        public static async Task Run()
        {
            AuthenticationHeaderValue authHeaderValue = AuthenticationHeaderValue.Parse("Basic R2VrY3RlazpXZWxjMG1lIQ==");
            RpcClient   client   = new RpcClient(new Uri("http://localhost:62390/RpcApi/"), authHeaderValue);
            RpcRequest  request  = RpcRequest.WithParameterList("CharacterCount", new[] { "Test" }, "Id1");
            RpcResponse response = await client.SendRequestAsync(request, "Strings");

            List <RpcRequest> requests = new List <RpcRequest>
            {
                request,
                RpcRequest.WithParameterList("CharacterCount", new[] { "Test2" }, "Id2"),
                RpcRequest.WithParameterList("CharacterCount", new[] { "Test23" }, "Id3")
            };
            List <RpcResponse> bulkResponse = await client.SendBulkRequestAsync(requests, "Strings");

            IntegerFromSpace responseValue = response.GetResult <IntegerFromSpace>();

            if (responseValue == null)
            {
                Console.WriteLine("null");
            }
            else
            {
                Console.WriteLine(responseValue.Test);
            }

            var additionalHeaders = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Accept-Encoding", "gzip")
            };
            var compressedClient   = new RpcClient(new Uri("http://localhost:62390/RpcApi/"), authHeaderValue, headers: additionalHeaders);
            var compressedRequest  = RpcRequest.WithParameterList("CharacterCount", new[] { "Test" }, "Id1");
            var compressedResponse = await compressedClient.SendRequestAsync(request, "Strings");
        }
Esempio n. 2
0
        public async Task InvokeRequest_OptionalParameter_Valid()
        {
            DefaultRpcInvoker invoker         = this.GetInvoker();
            IServiceProvider  serviceProvider = this.GetServiceProvider();
            IRouteContext     routeContext    = this.GetRouteContext <TestRouteClass>();


            //No params specified
            RpcRequest  stringRequest = RpcRequest.WithNoParameters("Optional", "1");
            RpcResponse response      = await invoker.InvokeRequestAsync(stringRequest, RpcPath.Default, routeContext);

            RpcResponse resultResponse = Assert.IsType <RpcResponse>(response);

            Assert.Null(resultResponse.Result);
            Assert.False(resultResponse.HasError);

            //Param is empty
            stringRequest = RpcRequest.WithParameterList("Optional", new object[0], "1");
            response      = await invoker.InvokeRequestAsync(stringRequest, RpcPath.Default, routeContext);

            resultResponse = Assert.IsType <RpcResponse>(response);
            Assert.Null(resultResponse.Result);
            Assert.False(resultResponse.HasError);


            //Param is a string
            stringRequest = RpcRequest.WithParameterList("Optional", new[] { JToken.FromObject("Test") }, "1");
            response      = await invoker.InvokeRequestAsync(stringRequest, RpcPath.Default, routeContext);

            resultResponse = Assert.IsType <RpcResponse>(response);
            Assert.NotNull(resultResponse.Result);
            Assert.Equal("Test", resultResponse.Result);
        }
Esempio n. 3
0
        //https://github.com/edjCase/JsonRpc

        static void Main(string[] args)
        {
            var url = "http://localhost:59385/Items/";
            IRpcTransportClient transportClient = new HttpRpcTransportClient();
            RpcClient           client          = new RpcClient(new Uri(url), transportClient: transportClient);
            RpcRequest          request         = RpcRequest.WithParameterList("Get", null, "Id1");
            RpcResponse <Item>  response        = client.SendRequestAsync <Item>(request).GetAwaiter().GetResult();

            Console.WriteLine($"response.Result.Id: {response.Result.Id} | response.Result.Name: {response.Result.Name}");
        }
Esempio n. 4
0
        public async Task InvokeRequest_AmbiguousRequest_ErrorResponse()
        {
            RpcRequest stringRequest = RpcRequest.WithParameterList("AmbiguousMethod", new object[] { JToken.FromObject(1) }, "1");

            IRouteContext     routeContext = this.GetRouteContext <TestRouteClass>();
            DefaultRpcInvoker invoker      = this.GetInvoker();
            RpcResponse       response     = await invoker.InvokeRequestAsync(stringRequest, RpcPath.Default, routeContext);

            Assert.NotNull(response.Error);
            Assert.Equal((int)RpcErrorCode.MethodNotFound, response.Error.Code);
        }
Esempio n. 5
0
        public async Task DeletePaymentRequestsByIds(long[] ids)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithParameterList("DeletePaymentRequestsByIds", new[] { ids }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
        }
Esempio n. 6
0
        public async Task InvokeRequest_StringParam_ParseAsGuidType()
        {
            Guid       randomGuid    = Guid.NewGuid();
            RpcRequest stringRequest = RpcRequest.WithParameterList("GuidTypeMethod", new[] { JToken.FromObject(randomGuid.ToString()) }, "1");

            IRouteContext     routeContext   = this.GetRouteContext <TestRouteClass>();
            DefaultRpcInvoker invoker        = this.GetInvoker();
            RpcResponse       stringResponse = await invoker.InvokeRequestAsync(stringRequest, RpcPath.Default, routeContext);


            Assert.Equal(randomGuid, stringResponse.Result);
        }
Esempio n. 7
0
        public void SendRpcRequest(string methodName, object[] parameters = null)
        {
            AutoResetEvent autoResetEvent = new AutoResetEvent(false);
            RpcRequest     request        = RpcRequest.WithParameterList(methodName, parameters, "Id1");
            RpcResponse    result         = RunAsync(client.SendRequestAsync(request));

            if (result.HasError)
            {
                var errorMsg = string.Format("error at Rpc Method \"{0}\" errorCode {1}, errorMsg {2}", methodName, result.Error.Code, result.Error.Message);
                throw new Exception(errorMsg);
            }
        }
Esempio n. 8
0
        private static async Task Test4()
        {
            IRpcTransportClient      transportClient = new HttpRpcTransportClient(() => Task.FromResult(IntegrationTestRunner.authHeaderValue));
            RpcClient                client          = new RpcClient(new Uri(url), transportClient: transportClient);
            RpcRequest               request         = RpcRequest.WithParameterList("CharacterCount", new[] { "Test" }, "Id1");
            RpcResponse <TestObject> response        = await client.SendRequestAsync <TestObject>(request);

            if (response.Result.Test != 4)
            {
                throw new Exception("Test 1 failed.");
            }
        }
Esempio n. 9
0
        public async Task AddNode(string ipAddressWithPort)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithParameterList("AddNode", new[] { ipAddressWithPort }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
        }
Esempio n. 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public async Task RestoreWalletBackup(string filePath, string password = null)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithParameterList("RestoreWalletBackup", new[] { filePath, password }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
        }
Esempio n. 11
0
        public async Task SubmitBlock(string blockData)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithParameterList("SubmitBlock", new [] { blockData }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
        }
Esempio n. 12
0
        private static async Task Test1()
        {
            RpcClient client = RpcClient.Builder(new Uri(url))
                               .UsingAuthHeader(IntegrationTestRunner.authHeaderValue)
                               .Build();
            RpcRequest request = RpcRequest.WithParameterList("CharacterCount", new[] { "Test" }, "Id1");
            RpcResponse <TestObject> response = await client.SendAsync <TestObject>(request);

            if (response.Result.Test != 4)
            {
                throw new Exception("Test 1 failed.");
            }
        }
Esempio n. 13
0
        public async Task <PaymentOM[]> GetPaymentInfoInMemPool(string txid)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithParameterList("GetPaymentInfoInMemPool", new[] { txid }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            PaymentOM[] responseValue = response.GetResult <PaymentOM[]>();
            return(responseValue);
        }
Esempio n. 14
0
        public async Task InvokeRequest_AsyncMethod_Valid()
        {
            RpcRequest stringRequest = RpcRequest.WithParameterList("AddAsync", new object[] { JToken.FromObject(1), JToken.FromObject(1) }, "1");

            IRouteContext     routeContext = this.GetRouteContext <TestRouteClass>();
            DefaultRpcInvoker invoker      = this.GetInvoker();

            RpcResponse response = await invoker.InvokeRequestAsync(stringRequest, RpcPath.Default, routeContext);

            RpcResponse resultResponse = Assert.IsType <RpcResponse>(response);

            Assert.NotNull(resultResponse.Result);
            Assert.Equal(2, resultResponse.Result);
        }
Esempio n. 15
0
        /// <summary>
        /// change password
        /// </summary>
        /// <param name="oldPassword"></param>
        /// <param name="newPassword"></param>
        /// <returns></returns>
        public async Task WalletPassphraseChange(string oldPassword, string newPassword)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient  client  = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("WalletPassphraseChange", new List <object> {
                oldPassword, newPassword
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
        }
Esempio n. 16
0
        public async Task InvokeRequest_Int64RequestParam_ConvertToInt32Param()
        {
            RpcRequest stringRequest = RpcRequest.WithParameterList("IntParameter", new object[] { JToken.FromObject(1L) }, "1");

            IRouteContext     routeContext = this.GetRouteContext <TestRouteClass>();
            DefaultRpcInvoker invoker      = this.GetInvoker();

            RpcResponse response = await invoker.InvokeRequestAsync(stringRequest, RpcPath.Default, routeContext);

            RpcResponse resultResponse = Assert.IsType <RpcResponse>(response);

            Assert.NotNull(resultResponse.Result);
            Assert.Equal(1, resultResponse.Result);
        }
Esempio n. 17
0
        public async Task AddNewAddressBookItem(string address, string label)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient  client  = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("AddNewAddressBookItem", new List <object> {
                address, label
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
        }
Esempio n. 18
0
        public async Task SetAccountTag(string address, string tag)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient  client  = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("SetAccountTag", new List <object> {
                address, tag
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
        }
Esempio n. 19
0
        public async Task <AccountInfoOM[]> GetAddressesByTag(string tag = "")
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithParameterList("GetAddressesByTag", new[] { tag }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            AccountInfoOM[] responseValue = response.GetResult <AccountInfoOM[]>();
            return(responseValue);
        }
Esempio n. 20
0
        /// <summary>
        /// disables/enables all P2P network activity
        /// </summary>
        /// <param name="isActivity">Set to true to enable all P2P network activity. Set to false to disable all P2P network activity</param>
        /// <returns></returns>
        public async Task SetNetworkActive(bool isActivity)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient  client  = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("SetNetworkActive", new List <object> {
                isActivity
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
        }
Esempio n. 21
0
        public async Task <bool> WalletPassphrase(string password)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithParameterList("WalletPassphrase", new[] { password }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            bool result = response.GetResult <bool>();

            return(result);
        }
Esempio n. 22
0
        public async Task <AddressInfoOM> ValidateAddress(string address)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithParameterList("ValidateAddress", new[] { address }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            AddressInfoOM responseValue = response.GetResult <AddressInfoOM>();

            return(responseValue);
        }
Esempio n. 23
0
        /// <summary>
        /// 如果节点不在节点列表中会返回false
        /// </summary>
        /// <param name="ipAddressWithPort"></param>
        /// <returns></returns>
        public async Task <bool> DisconnectNode(string ipAddressWithPort)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithParameterList("DisconnectNode", new[] { ipAddressWithPort }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            bool responseValue = response.GetResult <bool>();

            return(responseValue);
        }
Esempio n. 24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="transactionFeePerKilobyte"></param>
        /// <returns></returns>
        public async Task SetTxFee(long transactionFeePerKilobyte)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            //List<object> list = transactionFeePerKilobyte.ToList().ConvertAll(s => (object)s);
            RpcClient  client  = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("SetTxFee", new List <object> {
                transactionFeePerKilobyte
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
        }
Esempio n. 25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="confirmations"></param>
        /// <returns></returns>
        public async Task SetConfirmations(long confirmations)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            //List<object> list = confirmations.ToList().ConvertAll(s => (object)s);
            RpcClient  client  = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("SetConfirmations", new List <object> {
                confirmations
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
        }
Esempio n. 26
0
        public async Task <AccountInfoOM> GetNewAddress(string tag)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient   client   = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json");
            RpcRequest  request  = RpcRequest.WithParameterList("GetNewAddress", new[] { tag }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            AccountInfoOM responseValue = response.GetResult <AccountInfoOM>();

            return(responseValue);
        }
Esempio n. 27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="account">The name of an account to get transactinos from. Use an empty string ("") to get transactions for the default account. Default is * to get transactions for all accounts.</param>
        /// <param name="count">The number of the most recent transactions to list. Default is 10</param>
        /// <param name="skip">The number of the most recent transactions which should not be returned. Allows for pagination of results. Default is 0</param>
        /// <param name="includeWatchOnly">If set to true, include watch-only addresses in details and calculations as if they were regular addresses belonging to the wallet. If set to false(the default), treat watch-only addresses as if they didn’t belong to this wallet</param>
        /// <returns></returns>
        public async Task <PaymentOM[]> ListTransactions(string account = "*", long count = 10, int skip = 0, bool includeWatchOnly = true)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient  client  = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("ListTransactions", new List <object> {
                account, count, skip, includeWatchOnly
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            PaymentOM[] responseValue = response.GetResult <PaymentOM[]>();
            return(responseValue);
        }
Esempio n. 28
0
        public async Task <PaymentOM[]> ListFilterTrans(FilterIM filter, int count, int skip = 0, bool includeWatchOnly = true)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient  client  = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("ListFilterTrans", new List <object> {
                filter, count, skip, includeWatchOnly
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            PaymentOM[] responseValue = response.GetResult <PaymentOM[]>();
            return(responseValue);
        }
Esempio n. 29
0
        public async Task <BlockHeaderOM> GetBlockHeader(string hash, int formate = 0)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient  client  = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("GetBlockHeader", new List <object> {
                hash, formate
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            BlockHeaderOM responseValue = response.GetResult <BlockHeaderOM>();

            return(responseValue);
        }
Esempio n. 30
0
        public async Task <MessageOM> SignMessage(string address, string message)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient  client  = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("SignMessage", new List <object> {
                address, message
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            MessageOM responseValue = response.GetResult <MessageOM>();

            return(responseValue);
        }