/// <summary> /// Posts a new <see cref="CommonConfirmationBlockMessage"/> containing information pertaining to a validator's block confirmation /// and returns a <see cref="ConfirmationBlockResponse"/> /// </summary> /// <param name="confirmationBlockMessage">Message containing the validator's confirmation block info</param> /// <returns></returns> public async Task <ConfirmationBlockResponse> PostConfiramtionBlockAsync(ConfirmationBlock confirmationBlockMessage) { var jsonConfirmationBlockMessage = JsonConvert.SerializeObject(confirmationBlockMessage); var httpContent = new StringContent(jsonConfirmationBlockMessage, Encoding.UTF8, "application/json"); var response = await _requestSender.PostAsync("/confirmation_block", httpContent); if (!response.IsSuccessStatusCode) { // TODO: Add specific exceptions throw new Exception(); } var stringResult = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(stringResult)) { // TODO: Add specific exceptions throw new Exception(); } var result = JsonConvert.DeserializeObject <ConfirmationBlockResponse>(stringResult); return(result); }
public async Task <BankInvalidBlock> SendInvalidBlocksToBankAsync(BankInvalidBlockRequest model) { var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); var response = await _requestSender.PostAsync("/invalid_blocks", content); if (!response.IsSuccessStatusCode) { throw new Exception("Error Sending Invalid Block to Bank"); } var responseContent = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <BankInvalidBlock>(responseContent)); }
/// <summary> /// Provides a facility for a confirmation validator to post a new <see cref="ConfirmationBlock"/> to the /// receiving bank. /// </summary> /// <param name="confirmationBlock"></param> /// <returns><see cref="HttpResponseMessage"/></returns> public async Task <HttpResponseMessage> PostConfirmationBlockAsync(ConfirmationBlock confirmationBlock) { var httpContent = new StringContent(JsonConvert.SerializeObject(confirmationBlock), Encoding.UTF8, "application/json"); var request = await _requestSender.PostAsync("/confirmation_blocks", httpContent); if (!request.IsSuccessStatusCode) { // TODO: Create specific exception throw new Exception(); } var response = new HttpResponseMessage(System.Net.HttpStatusCode.Created); return(response); }
/// <summary> /// Posts a new upgrade request to a confirmation validator requesting that it upgrade to a Primary Validator. /// Requesting bank will pass a <see cref="UpgradeRequest"/> /// </summary> /// <param name="upgradeRequest"></param> /// <returns><see cref="HttpResponseMessage"/>NOTE: 200: Ok - Validator has accepted the upgrade request, 400: Bad Request - Validator has rejected the upgrade</returns> public async Task <HttpResponseMessage> PostUpgradeRequestAsync(UpgradeRequest upgradeRequest) { if (upgradeRequest is null) { // TODO: Create specific exception throw new Exception(); } var httpContent = new StringContent(JsonConvert.SerializeObject(upgradeRequest), Encoding.UTF8, "application/json"); var jsonString = await httpContent.ReadAsStringAsync(); if (string.IsNullOrEmpty(jsonString)) { // TODO: Create specific exception throw new Exception(); } var response = await _requestSender.PostAsync("/upgrade_request/", httpContent); return(response); }
/// <summary> /// Notifies a validator on the network that a bank has upgraded its primary validator. /// </summary> /// <param name="validatorUpdatedModel"></param> /// <returns>200: Ok - Validator will follow bank and sync to the new primary validator or 400: /// - Bad Request - The validator will not follow the bank and will remain on its current network</returns> public async Task <HttpResponseMessage> PostPrimaryValidatorUpdatedAsync(PrimaryValidatorUpdatedModel validatorUpdatedModel) { if (validatorUpdatedModel is null) { // TODO: Create specific exception throw new Exception(); } var httpContent = new StringContent(JsonConvert.SerializeObject(validatorUpdatedModel)); var stringContent = await httpContent.ReadAsStringAsync(); if (string.IsNullOrEmpty(stringContent)) { // TODO: Create specific exception throw new Exception(); } var response = await _requestSender.PostAsync("primary_validator_updated", httpContent); return(response); }
public async Task <HttpResponseMessage> PostConnectionRequestAsync(ConnectionRequest connectionNotice) { if (connectionNotice is null) { // TODO: Create specific exception throw new Exception(); } var httpContent = new StringContent(JsonConvert.SerializeObject(connectionNotice)); var jsonString = await httpContent.ReadAsStringAsync(); if (string.IsNullOrEmpty(jsonString)) { // TODO: Create specific exception throw new Exception(); } var result = await _requestSender.PostAsync("/connection_requests", httpContent); return(result); }
public async Task <HttpResponseMessage> PostUpgradeNoticeAsync(UpgradeNotice upgradeNotice) { if (upgradeNotice is null) { // TODO: Create specific exception throw new Exception(); } var httpContent = new StringContent(JsonConvert.SerializeObject(upgradeNotice)); var jsonString = await httpContent.ReadAsStringAsync(); if (string.IsNullOrEmpty(jsonString)) { // TODO: Create specific exception throw new Exception(); } var result = await _requestSender.PostAsync($"/upgrade_notice/{upgradeNotice.NodeIdentifier}", httpContent); return(result); }