public static async Task Run() { AuthenticationHeaderValue authHeaderValue = AuthenticationHeaderValue.Parse("Basic R2VrY3RlazpXZWxjMG1lIQ=="); RpcClient client = new RpcClient(new Uri("http://localhost:62390/RpcApi/"), authHeaderValue); RpcRequest request = new RpcRequest("Id1", "CharacterCount", "Test"); RpcResponse response = await client.SendRequestAsync(request, "Strings"); List <RpcRequest> requests = new List <RpcRequest> { request, new RpcRequest("id2", "CharacterCount", "Test2"), new RpcRequest("id3", "CharacterCount", "Test23") }; List <RpcResponse> bulkResponse = await client.SendBulkRequestAsync(requests, "Strings"); IntegerFromSpace responseValue = response.GetResult <IntegerFromSpace>(); if (responseValue == null) { Console.WriteLine("null"); } else { Console.WriteLine(responseValue.Test); } }
/// <summary> /// Calls WebRequest using Unity model. Must be called from coroutine on main thread. Returns RpcResult<TResult> /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="request"></param> /// <returns></returns> public TResult SendRequest <TResult>(RpcRequest request) { JsonSerializerSettings settings = null; var rpcRequestJson = JsonConvert.SerializeObject(request, settings); { var httpWebRequest = (HttpWebRequest)WebRequest.Create(_baseUrl); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(rpcRequestJson); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); RpcResponse responseObject = JsonConvert.DeserializeObject <RpcResponse>(result, settings); return(responseObject.GetResult <TResult>(true, settings)); } } }
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"); }
/// <summary> /// 分类获取账号,1:所有找零账户,2:所有创建账户,3:所有观察者账户,0或者其他:所有账户信息 /// </summary> /// <param name="category"></param> /// <returns></returns> public async Task <OMBase> GetPageAccountCategory(int category, int pageSize = 0, int pageCount = int.MaxValue, bool isSimple = true) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("GetPageAccountCategory", new List <object> { category }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } if (isSimple) { return(response.GetResult <PageAccountSimpleOM>()); } else { return(response.GetResult <PageAccountDetailOM>()); } }
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); }
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); }
public async Task <ChainTipsOM[]> GetChainTips() { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithNoParameters("GetChainTips", 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } ChainTipsOM[] responseValue = response.GetResult <ChainTipsOM[]>(); return(responseValue); }
public async Task <PeerInfoOM[]> GetPeerInfo() { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithNoParameters("GetPeerInfo", 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } PeerInfoOM[] responseValue = response.GetResult <PeerInfoOM[]>(); return(responseValue); }
/// <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); }
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); }
public async Task <AddNodeInfoOM> GetAddedNodeInfo(string ipAddressWithPort) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("GetAddedNodeInfo", new[] { ipAddressWithPort }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } AddNodeInfoOM responseValue = response.GetResult <AddNodeInfoOM>(); return(responseValue); }
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); }
/// <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); }
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); }
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); }
public async Task <ListPageUnspentOM> ListPageUnspent(long minConfirmations, int currentPage, int pageSize, long maxConfirmations = 9999999, long minAmount = 1, long maxAmount = long.MaxValue, bool isDesc = false) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("ListPageUnspent", new List <object> { minConfirmations, currentPage, pageSize, maxConfirmations, minAmount, maxAmount, isDesc }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } ListPageUnspentOM responseValue = response.GetResult <ListPageUnspentOM>(); return(responseValue); }
public async Task <ListSinceBlockOM> ListSinceBlock(string blockHash, long confirmations) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("ListSinceBlock", new List <object> { blockHash, confirmations }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } ListSinceBlockOM responseValue = response.GetResult <ListSinceBlockOM>(); return(responseValue); }
/// <summary> /// /// </summary> /// <param name="toAddress"></param> /// <param name="amount"></param> /// <param name="comment"></param> /// <param name="commentTo"></param> /// <param name="subtractFeeFromAmount"></param> /// <returns></returns> public async Task <string> SendToAddress(string toAddress, long amount, string comment = "", string commentTo = "", bool subtractFeeFromAmount = false) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("SendToAddress", new List <object> { toAddress, amount, comment, commentTo, subtractFeeFromAmount }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } string responseValue = response.GetResult <string>(); return(responseValue); }
public async Task <EstimateRawTransactionOM> EstimateRawTransaction(SendRawTransactionInputsIM[] senders, SendRawTransactionOutputsIM[] receivers, string changeAddress, long feeRate) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("EstimateRawTransaction", new List <object> { senders, receivers, changeAddress, feeRate }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } EstimateRawTransactionOM responseValue = response.GetResult <EstimateRawTransactionOM>(); return(responseValue); }
public async Task <string> GetBlockHash(long height) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("GetBlockHash", new List <object> { height }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } string responseValue = response.GetResult <string>(); return(responseValue); }
public async Task <BlockInfoOM> GenerateNewBlock(string minerName, string address, int format = 0) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("GenerateNewBlock", new List <object> { minerName, address, format }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } BlockInfoOM responseValue = response.GetResult <BlockInfoOM>(); return(responseValue); }
public async Task <bool> LockUnspent(bool isLocked, ListLockUnspentIM[] transaction) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("LockUnspent", new List <object> { isLocked, transaction }, 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); }
/// <summary> /// /// </summary> /// <param name="fromAccount"></param> /// <param name="many"></param> /// <param name="subtractFeeFromAmount"></param> /// <returns></returns> public async Task <TxFeeForSendOM> EstimateTxFeeForSendMany(string fromAccount, SendManyOM[] many, string[] subtractFeeFromAmount = null) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("EstimateTxFeeForSendMany", new List <object> { fromAccount, many, subtractFeeFromAmount }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } TxFeeForSendOM responseValue = response.GetResult <TxFeeForSendOM>(); return(responseValue); }
/// <summary> /// /// </summary> /// <param name="fromAccount"></param> /// <param name="many"></param> /// <param name="subtractFeeFromAmount"></param> /// <returns></returns> public async Task <string> SendMany(string fromAccount, SendManyOM[] many, string[] subtractFeeFromAmount = null) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("SendMany", new List <object> { fromAccount, many, subtractFeeFromAmount }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } string responseValue = response.GetResult <string>(); return(responseValue); }
public async Task <TxOutOM> GetTxOut(string txid, int vout, bool unconfirmed) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("GetTxOut", new List <object> { txid, vout, unconfirmed }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } TxOutOM responseValue = response.GetResult <TxOutOM>(); return(responseValue); }
public async Task <List <UnspentOM> > ListUnspent(int minConfirmations, int maxConfirmations = 9999, string[] addresses = null) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("ListUnspent", new List <object> { minConfirmations, maxConfirmations, addresses }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } List <UnspentOM> responseValue = response.GetResult <List <UnspentOM> >(); return(responseValue); }
public async Task <PayRequestOM> CreateNewPaymentRequest(string accountId, string tag, long amount, string comment) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("CreateNewPaymentRequest", new List <object> { accountId, tag, amount, comment }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } PayRequestOM responseValue = response.GetResult <PayRequestOM>(); return(responseValue); }
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); }
/// <summary> /// /// </summary> /// <param name="toAddress"></param> /// <param name="amount"></param> /// <param name="comment"></param> /// <param name="commentTo"></param> /// <param name="subtractFeeFromAmount"></param> /// <returns></returns> public async Task <TxFeeForSendOM> EstimateTxFeeForSendToAddress(string toAddress, long amount, string comment = "", string commentTo = "", bool subtractFeeFromAmount = false) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri("http://localhost:5006"), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("EstimateTxFeeForSendToAddress", new List <object> { toAddress, amount, comment, commentTo, subtractFeeFromAmount }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } TxFeeForSendOM responseValue = response.GetResult <TxFeeForSendOM>(); return(responseValue); }
public long GetBlockReward(string hash) { //调接口获取奖励 AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri(MiningPoolSetting.API_URI), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("GetBlockReward", new List <object> { hash }, 1); RpcResponse response = client.SendRequestAsync(request).Result; if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } long totalReward = response.GetResult <long>(); return(totalReward); }