public Client( INodeClient node, Identity identity, Action <Payload> Func) { _node = node; _identity = identity; Announce = Func; }
private static async Task <bool> SubmitMinedBlock( INodeClient nodeClient, string minerAddress, int maxRetries, string blockDataHash, DateTime dateCreated, ulong nonce, string computedHash) { MinedBlock block = new MinedBlock { BlockDataHash = blockDataHash, DateCreated = dateCreated.Iso8601Formatted(), Nonce = nonce.ToString(), BlockHash = computedHash }; Response <Block> response; int retries = 0; do { retries++; response = await nodeClient.SubmitMinedBlock(block, minerAddress).ConfigureAwait(false); } while (response.Status == Status.Failed && retries < maxRetries); return(response.Status == Status.Success); }
private async static Task CallQueryCustomer(INodeClient nodeClient) { System.Console.WriteLine("------------------------------QueryCustomer----------------------------------"); try { var result = await nodeClient.CallServiceAsync(10001, 4, null, typeof(List <Customer>), 1000 * 3, null); var customers = (List <Customer>)result.ReturnVal; foreach (var customer in customers) { System.Console.WriteLine($"Result=Id: {customer.Id}, Name: {customer.Name}, Birthday: {customer.Birthday.ToString("yyyy-MM-dd")}"); } } catch (RequestTimeoutExcption ex) { System.Console.WriteLine($"Timeout: RequestId={ex.Request.Id}"); } catch (ServiceCallException ex) { System.Console.WriteLine($"Service call exception: ExceptionId={ex.ExceptionId}, ExceptionMessage={ex.Message}"); } catch (Exception ex) { System.Console.WriteLine($"Error: {ex.Message}"); } }
/// <summary> /// 向容器中添加NodeClient对象 /// </summary> /// <param name="nodeClient"></param> public virtual void Add(INodeClient nodeClient) { lock (nodeClientListLockObj) { NodeClientList.Add(nodeClient); } }
private async Task <List <BlockContract> > GetAllBlocks(string peerUrl, int maxRetries) { if (!_peerNodeClients.ContainsKey(peerUrl)) { return(new List <BlockContract>()); } INodeClient nodeClient = _peerNodeClients[peerUrl]; Response <List <BlockContract> > response; int retries = 0; do { retries++; response = await nodeClient.GetAllBlocks().ConfigureAwait(false); } while (response.Status == Status.Failed && retries < maxRetries); if (response.Status == Status.Success) { return(response.Payload); } else { return(new List <BlockContract>()); } }
private static async Task <MiningJob> GetMiningJob( INodeClient nodeClient, string minerAddress) { Response <MiningJob> response; do { response = await nodeClient.GetMiningJob(minerAddress).ConfigureAwait(false); } while (response.Status == Status.Failed); return(response.Payload); }
private async Task SendCreateTransactionRequest( CreateTransactionRequest request, string peerUrl, int maxRetries) { if (!_peerNodeClients.ContainsKey(peerUrl)) { return; } INodeClient nodeClient = _peerNodeClients[peerUrl]; Response <TransactionContract> response; int retries = 0; do { retries++; response = await nodeClient.CreateTransaction(request).ConfigureAwait(false); } while (response.Status == Status.Failed && retries < maxRetries); }
private async Task SendNewBlockNotification( NewBlockNotification notification, string peerUrl, int maxRetries) { if (!_peerNodeClients.ContainsKey(peerUrl)) { return; } INodeClient nodeClient = _peerNodeClients[peerUrl]; Response <EmptyPayload> response; int retries = 0; do { retries++; response = await nodeClient.NotifyNewBlock(notification).ConfigureAwait(false); } while (response.Status == Status.Failed && retries < maxRetries); }
private async static Task CallAddCustomer(INodeClient nodeClient) { System.Console.WriteLine("------------------------------AddCustomer----------------------------------"); try { var customer1 = new Customer() { Id = 1, Name = "Michael", Birthday = new DateTime(1999, 1, 1) }; var task1 = nodeClient.CallServiceAsync(10001, 2, new object[] { customer1 }, null, 1000 * 3, null); var customer2 = new Customer() { Id = 2, Name = "Jane", Birthday = new DateTime(2001, 5, 10) }; var task2 = nodeClient.CallServiceAsync(10001, 2, new object[] { customer2 }, null, 1000 * 3, null); await Task.WhenAll(task1, task2); System.Console.WriteLine($"Add customer success"); } catch (RequestTimeoutExcption ex) { System.Console.WriteLine($"Timeout: RequestId={ex.Request.Id}"); } catch (ServiceCallException ex) { System.Console.WriteLine($"Service call exception: ExceptionId={ex.ExceptionId}, ExceptionMessage={ex.Message}"); } catch (Exception ex) { System.Console.WriteLine($"Error: {ex.Message}"); } }
private async static Task CallGetServiceName(INodeClient nodeClient) { System.Console.WriteLine("------------------------------GetServiceName----------------------------------"); try { var result = await nodeClient.CallServiceAsync(10001, 1, null, typeof(string), 1000 * 3, null); System.Console.WriteLine($"Result={result.ReturnVal}"); } catch (RequestTimeoutExcption ex) { System.Console.WriteLine($"Timeout: RequestId={ex.Request.Id}"); } catch (ServiceCallException ex) { System.Console.WriteLine($"Service call exception: ExceptionId={ex.ExceptionId}, ExceptionMessage={ex.Message}"); } catch (Exception ex) { System.Console.WriteLine($"Error: {ex.Message}"); } }
private async static Task CallRemoveAllCustomer(INodeClient nodeClient) { System.Console.WriteLine("------------------------------RemoveAllCustomer----------------------------------"); try { await nodeClient.CallServiceAsync(10001, 6, null, null, 1000 * 3, null); System.Console.WriteLine($"Remove all customer success"); } catch (RequestTimeoutExcption ex) { System.Console.WriteLine($"Timeout: RequestId={ex.Request.Id}"); } catch (ServiceCallException ex) { System.Console.WriteLine($"Service call exception: ExceptionId={ex.ExceptionId}, ExceptionMessage={ex.Message}"); } catch (Exception ex) { System.Console.WriteLine($"Error: {ex.Message}"); } }
/// <summary> /// 添加Client /// </summary> /// <param name="nodeClient">nodeClient实例</param> public virtual IServiceProxy AddClient(INodeClient nodeClient) { nodeClientContainer.Add(nodeClient); logger.LogInformation($"Add client success. ProxyName={ProxyName}, Host={nodeClient.Host}, Port={nodeClient.Port}, LocalHost={nodeClient.LocalHost}, LocalPort={nodeClient.LocalPort}"); return(this); }
public HealthProvider(INodeClient nodeClient) { _nodeClient = nodeClient; }
public NodesController(INodeClient nodeClient) { _nodeClient = nodeClient ?? throw new System.ArgumentNullException(nameof(nodeClient)); }