예제 #1
0
        public async Task <IJsonResponse <RootObject <bool> > > Settxfee(decimal amount)
        {
            var data = Create(RPCMethod.setTxFee);

            data.AddParameter(amount);
            JsonRequest <RootObject <bool> > request = new PostRequest <RootObject <bool> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #2
0
        public async Task <IJsonResponse <RootObject <TransactionResponse> > > GetTransaction(string txid)
        {
            var data = Create(RPCMethod.getTransaction);

            data.AddParameter(txid);
            JsonRequest <RootObject <TransactionResponse> > request = new PostRequest <RootObject <TransactionResponse> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #3
0
        public async Task <IJsonResponse <RootObject <object> > > ListSinceBlock(string blockhash)
        {
            var data = Create(RPCMethod.listSinceBlock);

            data.AddParameter(blockhash);
            JsonRequest <RootObject <object> > request = new PostRequest <RootObject <object> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #4
0
        public async Task <IJsonResponse <RootObject <decimal> > > GetReceivedByAddress(string address)
        {
            var data = Create(RPCMethod.getReceivedByAddress);

            data.AddParameter(address);
            JsonRequest <RootObject <decimal> > request = new PostRequest <RootObject <decimal> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #5
0
        public async Task <IJsonResponse <RootObject <object> > > GetBlockHash(int index)
        {
            var data = Create(RPCMethod.getBlockHash);

            data.AddParameter(index);
            JsonRequest <RootObject <object> > request = new PostRequest <RootObject <object> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #6
0
        public async Task <IJsonResponse <RootObject <object> > > GetAddressesByAccount(string account)
        {
            var data = Create(RPCMethod.getAddressesByAccount);

            data.AddParameter(account);
            JsonRequest <RootObject <object> > request = new PostRequest <RootObject <object> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #7
0
        public async Task <IJsonResponse <RootObject <string> > > Encryptwallet(string oldpassphase, string newpassphrase)
        {
            var data = Create(RPCMethod.walletPassphraseChange);

            data.AddParameter(oldpassphase);
            data.AddParameter(newpassphrase);
            JsonRequest <RootObject <string> > request = new PostRequest <RootObject <string> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #8
0
        public async Task <IJsonResponse <RootObject <object> > > WalletPassphrase(string passphase, int timeoutSec = 10)
        {
            var data = Create(RPCMethod.walletPassphrase);

            data.AddParameter(passphase);
            data.AddParameter(timeoutSec);
            JsonRequest <RootObject <object> > request = new PostRequest <RootObject <object> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #9
0
        public async Task <IJsonResponse <RootObject <object> > > Signmessage(string address, string message)
        {
            var data = Create(RPCMethod.signMessage);

            data.AddParameter(address);
            data.AddParameter(message);
            JsonRequest <RootObject <object> > request = new PostRequest <RootObject <object> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #10
0
        public async Task <IJsonResponse <RootObject <object> > > Setgenerate(bool generate, int genproclimit = -1)
        {
            var data = Create(RPCMethod.setGenerate);

            data.AddParameter(generate);
            data.AddParameter(genproclimit);
            JsonRequest <RootObject <object> > request = new PostRequest <RootObject <object> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #11
0
        public async Task <IJsonResponse <RootObject <object> > > ListReceivedByAddress(int minConf = 1, bool includeEmpty = false)
        {
            var data = Create(RPCMethod.listReceivedByAddress);

            data.AddParameter(minConf);
            data.AddParameter(includeEmpty);
            JsonRequest <RootObject <object> > request = new PostRequest <RootObject <object> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #12
0
        public async Task <IJsonResponse <RootObject <object> > > ImportPrivKey(string key, string label)
        {
            var data = Create(RPCMethod.importPrivKey);

            data.AddParameter(key);
            data.AddParameter(label);
            JsonRequest <RootObject <object> > request = new PostRequest <RootObject <object> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #13
0
        public async Task <IJsonResponse <RootObject <object> > > ListTransactions(string account, int count = 10, int from = 0)
        {
            var data = Create(RPCMethod.listTransactions);

            data.AddParameter(account);
            data.AddParameter(count);
            data.AddParameter(from);
            JsonRequest <RootObject <object> > request = new PostRequest <RootObject <object> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #14
0
        public async Task <IJsonResponse <RootObject <object> > > SendToAddress(string address, decimal amount, string comment, string commentTo)
        {
            var data = Create(RPCMethod.sendToAddress);

            data.AddParameter(address);
            data.AddParameter(amount);
            data.AddParameter(comment);
            data.AddParameter(commentTo);
            JsonRequest <RootObject <object> > request = new PostRequest <RootObject <object> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #15
0
        public async Task <IJsonResponse <RootObject <object> > > Move(string fromAccount, string toAccount, decimal amount, string comment, int minConf = 1)
        {
            var data = Create(RPCMethod.move);

            data.AddParameter(fromAccount);
            data.AddParameter(toAccount);
            data.AddParameter(amount);
            data.AddParameter(minConf);
            data.AddParameter(comment);
            JsonRequest <RootObject <object> > request = new PostRequest <RootObject <object> >(client, $"{url}:{port}", data);

            return(await request.Invoke());
        }
예제 #16
0
        private async Task <T> GetResponseAsync <T>(object request, Uri requestUri)
        {
            var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri);

            httpRequestMessage.Headers.Accept.Clear();
            httpRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(JsonContentType));
            httpRequestMessage.Headers.Add("Client", $"Autoaddress2.0SDK {AssemblyVersion}");

            EnsureHttpClient();

            var completionOption  = HttpCompletionOption.ResponseContentRead;
            var cancellationToken = CancellationToken.None;

            PreRequest?.Invoke(this, new PreRequestEventArgs(request, httpRequestMessage));

            HttpResponseMessage response = await _httpClient.SendAsync(httpRequestMessage, completionOption, cancellationToken).ConfigureAwait(false);

            string content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            PostRequest?.Invoke(this, new PostRequestEventArgs(response, content));

            if (!response.IsSuccessStatusCode)
            {
                if ((int)response.StatusCode == 429)
                {
                    throw new TooManyRequestsException(response.ReasonPhrase);
                }

                AutoaddressException autoaddressException = GetAutoaddressException(response.StatusCode, httpRequestMessage.RequestUri, content);

                if (autoaddressException != null)
                {
                    throw autoaddressException;
                }

                // guard
                response.EnsureSuccessStatusCode();

                throw new InvalidOperationException();
            }

            string result = ParseJson(content);

            return(JsonConvert.DeserializeObject <T>(result));
        }