diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index e354574..d297684 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -34,19 +34,16 @@ For projects that support adding a Nuget reference you may paste the following * ConnectedBankService * InvalidBlocksService * TransactionsService - * UpgradeNoticeService * ValidatorService 2. Common * 3. Validator * AccountsService - * BankBlockService * ConfigService * ConnectedBankService * PrimaryValidatorUpdatedService * TransactionService - * UpgradeRequestService * ValidatorService * ValidatorConfirmationBlockService @@ -77,10 +74,8 @@ Description ## ConfigService ## ConfirmationService ## ConnectedBankService -## ConnectionRequestService ## InvalidBlocksService ## TransactionService -## UpgradeNoticeService ## ValidatorService ## Bank Exceptions (BNK) @@ -109,14 +104,11 @@ Description Thenewboston.Validator.Api Thenewboston.Validator.Models ## AccountsService -## BankBlockService ## ConfigService ## ConfirmationService ## ConnectedBankService -## ConnectionRequestService ## PrimaryValidatorUpdatedService ## TransactionService -## UpgradeRequestService ## ValidatorService ## ValidatorConfirmationBlockService ## Validator Exceptions (VLD) diff --git a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs index 006929d..d9bef8a 100644 --- a/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/BankConfirmationBlockServiceTests.cs @@ -47,70 +47,6 @@ private PaginatedResponseModel CreateMockBankConfirmation }; } - private ConfirmationBlock CreateMockConfirmationBlockMessage() - { - return new ConfirmationBlock() - { - Message = new ConfirmationBlockMessage() - { - Block = new ConfirmationBankBlock() - { - AccountNumber = "0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb", - Message = new ConfirmationBankBlockMessage() - { - BalanceKey = "e6a41b658e17ab2db4355176c8160de6a66b07e5cbdd85244b55b38b4fd26e92", - Transactions = new List() - { - new ConfirmationBankBlockTransaction() - { - Amount = "4", - Recipient = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc" - }, - new ConfirmationBankBlockTransaction() - { - Amount = "1", - Recipient = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8" - }, - new ConfirmationBankBlockTransaction() - { - Amount = "4", - Recipient = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314" - } - } - } - }, - Signature = "d857184b7d3121a8f9dccab09062fafc82dd0fb30a5d53e19ab25a587171bb9c6b33858353cd3ff7ddc1ad2bfc59a885e85827799bcfc082fd048f9bf34bd404" - }, - UpdatedBalances = new List() - { - new ConfirmationUpdatedBalanceRecord() - { - AccountNumber = "0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb", - Balance = "4294967014", - BalanceLock = "729ce6ce619aeedf260221c7687c51d8a6845fbb5407b11c8cd26eaa7c8a6125" - }, - new ConfirmationUpdatedBalanceRecord() - { - AccountNumber = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc", - Balance = "191", - }, - new ConfirmationUpdatedBalanceRecord() - { - AccountNumber = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8", - Balance = "18", - }, - new ConfirmationUpdatedBalanceRecord() - { - AccountNumber = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314", - Balance = "72", - } - }, - BlockIdentifier = "4c9595b2b661a23e665256d6826ae940bd4ea82bef0c1ba7b3104e40a4c42b91", - NodeIdentifier = "3afdf37573f1a511def0bd85553404b7091a76bcd79cdcebba1310527b167521", - Signature = "b4d335fa7662216acba06c18d93c6cfb688c8057cbe9193ddc8e6fb3702ba1d979e43b09e06c6c7c38358bbee5243dc37a52c5212298c2259be48285e3da130c" - }; - } - #endregion #region Mock Service @@ -128,17 +64,6 @@ private IBankConfirmationBlockService BuildConfirmationBlockGetMock() return service; } - private IBankConfirmationBlockService BuildConfirmationBlockPostMock() - { - var requestSenderMock = new Mock(); - - requestSenderMock.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.Created)); - - IBankConfirmationBlockService service = new BankConfirmationBlockService(requestSenderMock.Object); - return service; - } - #endregion #region Tests @@ -153,14 +78,6 @@ public async void BankConfirmationBlockReturnedAsync() Assert.Equal(expectedResult, actualResult); } - [Fact] - public async void BankConfirmationBlockMessagePostedAsync() - { - var service = BuildConfirmationBlockPostMock(); - var response = await service.PostConfirmationBlockAsync(CreateMockConfirmationBlockMessage()); - Assert.True(response.StatusCode == System.Net.HttpStatusCode.Created); - } - #endregion } } diff --git a/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs index 7767ac6..9ca5989 100644 --- a/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/BlocksServiceTests.cs @@ -48,14 +48,14 @@ private Block CreateMockBlockMessage() BalanceKey = "ce51f0d9facaa7d3e69657429dd3f961ce70077a8efb53dcda508c7c0a19d2e3", Transactions = new List() { new BlockTransaction() { - Amount = "12.5", + Amount = 12.5, Recipient = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc" }, new BlockTransaction() { - Amount = "1", Recipient = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8" + Amount = 1, Recipient = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8" }, new BlockTransaction() { - Amount = "4", Recipient = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314" + Amount = 4, Recipient = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314" } } }, diff --git a/src/Thenewboston.Tests/Bank/Api/ConnectionRequestServiceTest.cs b/src/Thenewboston.Tests/Bank/Api/ConnectionRequestServiceTest.cs deleted file mode 100644 index f19c88b..0000000 --- a/src/Thenewboston.Tests/Bank/Api/ConnectionRequestServiceTest.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Moq; -using Thenewboston.Bank.Api; -using Thenewboston.Bank.Models; -using Thenewboston.Common.Http; -using Xunit; - -namespace Thenewboston.Tests.Bank.Api -{ - public class ConnectionRequestServiceTest - { - public ConnectionRequest CreateMockConnectionRequest() - { - return new ConnectionRequest() - { - Message = new ConnectionRequestMessage() - { - IpAddress = "192.168.1.232", - Port = "8000", - Protocol = "http" - }, - NodeIdentifier = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1", - Signature = "3c88665e123e7e25a8b9d9592f3269ab4efc4bcba989a103a898e2625933261b1cccdaf2f52eca9c58d2bf033968ab6b702089bca8fc6e0c80b3b002a5e05b03" - }; - } - - public IConnectionRequestService ConnectionRequestAcceptsMock() - { - var requestSender = new Mock(); - var httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - - requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(httpResponse); - - var service = new ConnectionRequestService(requestSender.Object); - return service; - } - - public IConnectionRequestService ConnectionRequestRejectsMock() - { - var requestSender = new Mock(); - var httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); - - requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(httpResponse); - - var service = new ConnectionRequestService(requestSender.Object); - return service; - } - - [Fact] - public async Task UpgradeRequestNodeAcceptsTest() - { - var service = ConnectionRequestAcceptsMock(); - var result = await service.PostConnectionRequestAsync(CreateMockConnectionRequest()); - var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - Assert.Equal(expectedResult.StatusCode, result.StatusCode); - } - - [Fact] - public async Task UpgradeRequestNodeRejectsTest() - { - var service = ConnectionRequestRejectsMock(); - var result = await service.PostConnectionRequestAsync(CreateMockConnectionRequest()); - var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); - Assert.Equal(expectedResult.StatusCode, result.StatusCode); - } - } -} diff --git a/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs index 7f65dba..d02e623 100644 --- a/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/InvalidBlockServiceTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; @@ -41,18 +41,7 @@ public async void GetInvalidBlockWithPageOnlyPaginationReturnedSuccessCodeandDat Assert.Equal("2bcd53c5-19f9-4226-ab04-3dfb17c3a1fe", invalidBankBlocks.Results.ElementAt(0).Id); } } - public class SendInvalidBankBlocksAsync - { - [Fact] - public async void SendInvalidBlockReturnedSuccessCodeandData() - { - var service = BuildBankInvalidServiceMock(); - var invalidBankBlocks = await service.SendInvalidBlocksToBankAsync( new BankInvalidBlockRequest()); - Assert.Equal("2bcd53c5-19f9-4226-ab04-3dfb17c3a1fe", invalidBankBlocks.Id); - } - } - private static List INVALID_BLOCK_TEST_DATA = new List { new BankInvalidBlock @@ -99,13 +88,7 @@ private static InvalidBlocksService BuildBankInvalidServiceMock() .Setup(x => x.GetAsync(It.IsAny())) .Returns(Task.FromResult(getAllResponse)); - var postResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - postResponse.Content = new StringContent(JsonConvert.SerializeObject(INVALID_BLOCK_TEST_DATA.First()), Encoding.UTF8, "application/json"); - //TODO Setup for more Scenarios - requestSender - .Setup(x => x.PostAsync( "/invalid_blocks", It.IsAny())) - .Returns(Task.FromResult(postResponse)); requestSender .Setup(x => x.GetAsync(It.IsRegex(@"\/invalid_blocks\?offset=[0-9]*&limit=[0-9]*"))) .Returns(Task.FromResult(getAllResponse)); requestSender diff --git a/src/Thenewboston.Tests/Bank/Api/UpgradeNoticeTests.cs b/src/Thenewboston.Tests/Bank/Api/UpgradeNoticeTests.cs deleted file mode 100644 index 746013b..0000000 --- a/src/Thenewboston.Tests/Bank/Api/UpgradeNoticeTests.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Moq; -using Newtonsoft.Json; -using Thenewboston.Bank.Api; -using Thenewboston.Bank.Models; -using Thenewboston.Common.Http; -using Xunit; - -namespace Thenewboston.Tests.Bank.Api -{ - public class UpgradeNoticeTests - { - // *************************************** - // Bank Upgrade Notice Tests * - // Created 11/27/2020 based on available * - // documentation * - // *************************************** - - #region Mock Test Models - - private UpgradeNotice CreateUpgradeNoticeModelMock() - { - return new UpgradeNotice() - { - Message = new UpgradeNoticeMessage() - { - BankNodeIdentifier = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1" - }, - NodeIdentifier = "59479a31c3b91d96bb7a0b3e07f18d4bf301f1bb0bde05f8d36d9611dcbe7cbf", - Signature = "e9862cf176523449417b5f3426cb7bf0a3813ef04fae3330faa50b6468d9da9c55967a24c40040eaa6bc33843804bda9a0307bffe906ed8c7b2a55c15dabaa0d" - }; - } - - #endregion - - #region Mock Services - - public IUpgradeNoticeService BuildUpgradeNoticeServiceServerAcceptsMock() - { - var requestSender = new Mock(); - var serializedContent = new StringContent(JsonConvert.SerializeObject(CreateUpgradeNoticeModelMock())); - var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - - requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(response); - - return new UpgradeNoticeService(requestSender.Object); - } - - public IUpgradeNoticeService BuildUpgradeNoticeServiceServerRejectsMock() - { - var requestSender = new Mock(); - var serializedContent = new StringContent(JsonConvert.SerializeObject(CreateUpgradeNoticeModelMock())); - var response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); - - requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(response); - - return new UpgradeNoticeService(requestSender.Object); - } - - #endregion - - #region Tests - - [Fact] - public async Task UpgradeNoticeBankAcceptsTest() - { - var service = BuildUpgradeNoticeServiceServerAcceptsMock(); - var result = await service.PostUpgradeNoticeAsync(CreateUpgradeNoticeModelMock()); - var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - Assert.Equal(expectedResult.StatusCode, result.StatusCode); - } - - [Fact] - public async Task UpgradeNoticeBankRejectsTest() - { - var service = BuildUpgradeNoticeServiceServerRejectsMock(); - var result = await service.PostUpgradeNoticeAsync(CreateUpgradeNoticeModelMock()); - var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); - Assert.Equal(expectedResult.StatusCode, result.StatusCode); - } - - #endregion - } -} diff --git a/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs b/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs deleted file mode 100644 index ef1a1e0..0000000 --- a/src/Thenewboston.Tests/Bank/Api/UpgradeRequestTests.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Moq; -using Thenewboston.Common.Http; -using Thenewboston.Validator.Api; -using Thenewboston.Validator.Api.Models; -using Thenewboston.Validator.Models; -using Xunit; - -namespace Thenewboston.Tests.Bank.Api -{ - public class UpgradeRequestTests - { - - // *************************************** - // Validator Upgrade Request Tests * - // Created 11/27/2020 based on available * - // documentation * - // *************************************** - - #region Upgrade Request Mock Models - - public UpgradeRequest CreateMockUpgradeRequest() - { - return new UpgradeRequest() - { - Message = new UpgradeRequestMessage() - { - ValidatorNodeIdentifier = "59479a31c3b91d96bb7a0b3e07f18d4bf301f1bb0bde05f8d36d9611dcbe7cbf" - }, - NodeIdentifier = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1", - Signature = "90a365d1950b1765b973d3d21d763f9bea7eb1f9d1f33d6e9c3f8eb4803022f97ad3173474707b4786e556cccf4ca0a0e81d18edb655b090967c96c22c40140a" - }; - } - - #endregion - - #region Upgrade Request Mock Services - - public IUpgradeRequestService BuildUpgradeRequestServiceNodeAcceptsMock() - { - var requestSender = new Mock(); - var httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - - requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(httpResponse); - - var service = new UpgradeRequestService(requestSender.Object); - return service; - } - - public IUpgradeRequestService BuildUpgradeRequestServiceNodeRejectsMock() - { - var requestSender = new Mock(); - var httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); - - requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(httpResponse); - - var service = new UpgradeRequestService(requestSender.Object); - return service; - } - - #endregion - - #region Tests - - [Fact] - public async Task UpgradeRequestNodeAcceptsTest() - { - var service = BuildUpgradeRequestServiceNodeAcceptsMock(); - var result = await service.PostUpgradeRequestAsync(CreateMockUpgradeRequest()); - var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - Assert.Equal(expectedResult.StatusCode, result.StatusCode); - } - - [Fact] - public async Task UpgradeRequestNodeRejectsTest() - { - var service = BuildUpgradeRequestServiceNodeRejectsMock(); - var result = await service.PostUpgradeRequestAsync(CreateMockUpgradeRequest()); - var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); - Assert.Equal(expectedResult.StatusCode, result.StatusCode); - } - - #endregion - } -} diff --git a/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs index 548c1c2..c7801ce 100644 --- a/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ValidatorConfirmationServiceTests.cs @@ -37,18 +37,6 @@ public class ValidatorConfirmationServiceTests }; } - private BankValidatorConfirmationService CreateMockValidatorConfirmationServiceMessage() - { - return new BankValidatorConfirmationService() { - Message = new ValidatorConfirmationServiceMessage() { - End = DateTime.Parse("2020-07-09T22:10:25Z"), Start = DateTime.Parse("2020-08-09T22:10:25Z") - }, - NodeIdentifier = "59479a31c3b91d96bb7a0b3e07f18d4bf301f1bb0bde05f8d36d9611dcbe7cbf", - Signature = - "2a4b90e97566d4c46cb302e8297841ebe0b9f5ce6f30217721dedb4bfdc48944d14f46032e33246b6a60a942bc48fd9541057b7b1c635d4346436deab9f4bf01" - }; - } - #endregion #region Mock Service @@ -68,16 +56,6 @@ private IValidatorConfirmationService BuildValidatorConfirmationServiceGetMock() return service; } - private IValidatorConfirmationService BuildValidatorConfirmationServicePostMock() - { - var requestSenderMock = new Mock(); - requestSenderMock.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.Created)); - - IValidatorConfirmationService service = new Thenewboston.Bank.Api.ValidatorConfirmationService(requestSenderMock.Object); - return service; - } - #endregion #region Tests @@ -92,15 +70,6 @@ public async void ConfirmationServiceReturnedAsync() Assert.Equal(expectedResult, actualResult); } - [Fact] - public async void BlockPostedAsync() - { - var service = BuildValidatorConfirmationServicePostMock(); - var response = - await service.PostValidatorConfirmationServiceAsync(CreateMockValidatorConfirmationServiceMessage()); - Assert.True(response.StatusCode == System.Net.HttpStatusCode.Created); - } - #endregion } } \ No newline at end of file diff --git a/src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs b/src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs index b937c77..c79bebb 100644 --- a/src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs +++ b/src/Thenewboston.Tests/Bank/Api/ValidatorServiceTests.cs @@ -37,7 +37,7 @@ public async void ListOfValidatorsIsReturned() AccountNumber = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314", IpAddress = "192.168.1.74", NodeIdentifier = "3afdf37573f1a511def0bd85553404b7091a76bcd79cdcebba1310527b167521", - Port = "8000", + Port = 8000, Protocol = "http", Version = "v1.0", DefaultTransactionFee = 4, @@ -52,7 +52,7 @@ public async void ListOfValidatorsIsReturned() AccountNumber = "4d2ec91f37bc553bc538e91195669b666e26b2ea3e4e31507e38102a758d4f86", IpAddress = "86.168.1.23", NodeIdentifier = "59479a31c3b91d96bb7a0b3e07f18d4bf301f1bb0bde05f8d36d9611dcbe7cbf", - Port = "80", + Port = 80, Protocol = "http", Version = "v1.0", DefaultTransactionFee = 2, @@ -86,7 +86,7 @@ public async void ValidatorIsPatched() AccountNumber = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314", IpAddress = "192.168.1.74", NodeIdentifier = "3afdf37573f1a511def0bd85553404b7091a76bcd79cdcebba1310527b167521", - Port = "8000", + Port = 8000, Protocol = "http", Version = "v1.0", DefaultTransactionFee = 4, diff --git a/src/Thenewboston.Tests/Validator/Api/AccountsServiceTests.cs b/src/Thenewboston.Tests/Validator/Api/AccountsServiceTests.cs index 34a8bec..1a42651 100644 --- a/src/Thenewboston.Tests/Validator/Api/AccountsServiceTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/AccountsServiceTests.cs @@ -39,7 +39,7 @@ public async void AccountBalanceIsReturned() var balance = await service.GetAccountBalanceAsync("9eca00a5-d925-454c-a8d6-ecbb26ec2f76"); - Assert.Equal("4294967051.0000000000000000", balance.Balance); + Assert.Equal(4294967051.0000000000000000, balance.Balance); } } @@ -70,14 +70,14 @@ public static AccountsService BuildValidatorServiceMock() { Id = "9eca00a5-d925-454c-a8d6-ecbb26ec2f76", AccountNumber = "4d2ec91f37bc553bc538e91195669b666e26b2ea3e4e31507e38102a758d4f86", - Balance = "4294967051.0000000000000000", + Balance = 4294967051.0000000000000000, BalanceLock = "21cfd80a31930e801e97d34e3f00a7d9b5c01b2fb531a5ac14cd59d10ab446c8" }, new ValidatorAccount { Id = "ae4d43b0-5c34-4e56-8266-0e3531268815", AccountNumber = "a29baa6ba36f6db707f8f8dacfa82d5e8a28fa616e8cc96cf6d7790f551d79f2", - Balance = "175.0000000000000000", + Balance = 175.0000000000000000, BalanceLock = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc" } } diff --git a/src/Thenewboston.Tests/Validator/Api/BankBlockServiceTest.cs b/src/Thenewboston.Tests/Validator/Api/BankBlockServiceTest.cs deleted file mode 100644 index 3a33f10..0000000 --- a/src/Thenewboston.Tests/Validator/Api/BankBlockServiceTest.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System.Collections.Generic; -using System.Net.Http; -using Moq; -using Thenewboston.Common.Http; -using Thenewboston.Common.Models; -using Thenewboston.Validator.Api; -using Thenewboston.Validator.Models; -using Xunit; - -namespace Thenewboston.Tests.Validator.Api -{ - public class BankBlockServiceTest - { - #region Test Models - private ValidatorBankBlock CreateMockBankBlock() - { - return new ValidatorBankBlock() - { - BankBlock = new Block() - { - AccountNumber = "0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb", - Message = new BlockMessage() - { - BalanceKey = "ee7a6d21feb2905605f9af446566e003decec3de2f55a6eff9815d41fcde59e0", - Transactions = new List() - { - new BlockTransaction() { - Amount = "4.125", - Recipient = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc" - }, - new BlockTransaction() { - Amount = "1", - Recipient = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8" - }, - new BlockTransaction() { - Amount = "4", - Recipient = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314" - } - } - }, - Signature = "e8b5215193cd5f91029b2a7a9ff2426b0a9fc0032f5a0f74ec0e6cc2f3ac9f20acd170f90e1557e561c85d34daa37d0cec90901f3d4c9579700847f67de22a05" - }, - NodeIdentifier = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1", - Signature = "4f019d36d362f09960399fe51dd67d7ddbee27d73994558cf4015bb13260957f861afaa1694d40fd0397ed2a889834d8a20bff4c3417bbde383e2cd4e219cb0f" - }; - } - - #endregion - - #region Mock Service - - private IBankBlockService BuildBankBlockPostMock() - { - var requestSenderMock = new Mock(); - - requestSenderMock.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.Created)); - - IBankBlockService service = new BankBlockService(requestSenderMock.Object); - return service; - } - - #endregion - - #region Tests - - [Fact] - public async void BankConfirmationBlockMessagePostedAsync() - { - var service = BuildBankBlockPostMock(); - var response = await service.PostBankBlockAsync(CreateMockBankBlock()); - Assert.True(response.StatusCode == System.Net.HttpStatusCode.Created); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Thenewboston.Tests/Validator/Api/ConnectionRequestServiceTest.cs b/src/Thenewboston.Tests/Validator/Api/ConnectionRequestServiceTest.cs deleted file mode 100644 index 630771d..0000000 --- a/src/Thenewboston.Tests/Validator/Api/ConnectionRequestServiceTest.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Moq; -using Thenewboston.Common.Http; -using Thenewboston.Validator.Api; -using Thenewboston.Validator.Models; -using Xunit; - -namespace Thenewboston.Tests.Validator.Api -{ - public class ConnectionRequestServiceTest - { - public ConnectionRequest CreateMockConnectionRequest() - { - return new ConnectionRequest() - { - Message = new ConnectionRequestMessage() - { - IpAddress = "192.168.1.232", - Port = "8000", - Protocol = "http" - }, - NodeIdentifier = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1", - Signature = "3c88665e123e7e25a8b9d9592f3269ab4efc4bcba989a103a898e2625933261b1cccdaf2f52eca9c58d2bf033968ab6b702089bca8fc6e0c80b3b002a5e05b03" - }; - } - - public IConnectionRequestService ConnectionRequestAcceptsMock() - { - var requestSender = new Mock(); - var httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - - requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(httpResponse); - - var service = new ConnectionRequestService(requestSender.Object); - return service; - } - - public IConnectionRequestService ConnectionRequestRejectsMock() - { - var requestSender = new Mock(); - var httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); - - requestSender.Setup(s => s.PostAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(httpResponse); - - var service = new ConnectionRequestService(requestSender.Object); - return service; - } - - [Fact] - public async Task UpgradeRequestNodeAcceptsTest() - { - var service = ConnectionRequestAcceptsMock(); - var result = await service.PostConnectionRequestAsync(CreateMockConnectionRequest()); - var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.OK); - Assert.Equal(expectedResult.StatusCode, result.StatusCode); - } - - [Fact] - public async Task UpgradeRequestNodeRejectsTest() - { - var service = ConnectionRequestRejectsMock(); - var result = await service.PostConnectionRequestAsync(CreateMockConnectionRequest()); - var expectedResult = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); - Assert.Equal(expectedResult.StatusCode, result.StatusCode); - } - } -} diff --git a/src/Thenewboston.Tests/Validator/Api/PrimaryValidatorUpdatedTests.cs b/src/Thenewboston.Tests/Validator/Api/PrimaryValidatorUpdatedTests.cs index 38b0fd4..f6d7c60 100644 --- a/src/Thenewboston.Tests/Validator/Api/PrimaryValidatorUpdatedTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/PrimaryValidatorUpdatedTests.cs @@ -26,7 +26,7 @@ private PrimaryValidatorUpdatedModel CreateMockPrimaryValidatorUpdatedModel() Message = new PrimaryValidatorUpdatedMessage() { IPAddress = "192.168.1.20", - Port = "8000", + Port = 8000, Protocol = "http" }, NodeIdentifier = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1", diff --git a/src/Thenewboston.Tests/Validator/Api/ValidatorConfirmationBlockTests.cs b/src/Thenewboston.Tests/Validator/Api/ValidatorConfirmationBlockTests.cs index ee53e38..b0ced81 100644 --- a/src/Thenewboston.Tests/Validator/Api/ValidatorConfirmationBlockTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/ValidatorConfirmationBlockTests.cs @@ -38,17 +38,17 @@ private ConfirmationBlock CreateMockConfirmationBlock() { new ConfirmationBankBlockTransaction() { - Amount = "4", + Amount = 4, Recipient = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc" }, new ConfirmationBankBlockTransaction() { - Amount = "1", + Amount = 1, Recipient = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8" }, new ConfirmationBankBlockTransaction() { - Amount = "4", + Amount = 4, Recipient = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314" } } @@ -61,23 +61,23 @@ private ConfirmationBlock CreateMockConfirmationBlock() new ConfirmationUpdatedBalanceRecord() { AccountNumber = "0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb", - Balance = "4294967014", + Balance = 4294967014, BalanceLock = "729ce6ce619aeedf260221c7687c51d8a6845fbb5407b11c8cd26eaa7c8a6125" }, new ConfirmationUpdatedBalanceRecord() { AccountNumber = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc", - Balance = "191", + Balance = 191, }, new ConfirmationUpdatedBalanceRecord() { AccountNumber = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8", - Balance = "18", + Balance = 18, }, new ConfirmationUpdatedBalanceRecord() { AccountNumber = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314", - Balance = "72", + Balance = 72, } }, BlockIdentifier = "4c9595b2b661a23e665256d6826ae940bd4ea82bef0c1ba7b3104e40a4c42b91", @@ -100,17 +100,17 @@ private ConfirmationBlockResponse CreateMockConfirmationBlockResponse() { new ConfirmationBankBlockTransaction() { - Amount = "60", + Amount = 60, Recipient = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc" }, new ConfirmationBankBlockTransaction() { - Amount = "1", + Amount = 1, Recipient = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8" }, new ConfirmationBankBlockTransaction() { - Amount = "4", + Amount = 4, Recipient = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314" } } @@ -123,23 +123,23 @@ private ConfirmationBlockResponse CreateMockConfirmationBlockResponse() new ConfirmationUpdatedBalanceRecord() { AccountNumber = "0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb", - Balance = "4294967014", + Balance = 4294967014, BalanceLock = "" }, new ConfirmationUpdatedBalanceRecord() { AccountNumber = "484b3176c63d5f37d808404af1a12c4b9649cd6f6769f35bdf5a816133623fbc", - Balance = "191" + Balance = 191 }, new ConfirmationUpdatedBalanceRecord() { AccountNumber = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8", - Balance = "18" + Balance = 18 }, new ConfirmationUpdatedBalanceRecord() { AccountNumber = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314", - Balance = "72" + Balance = 72 } } }; diff --git a/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs b/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs index 3f080d8..ff72848 100644 --- a/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs +++ b/src/Thenewboston.Tests/Validator/Api/ValidatorsServiceTests.cs @@ -37,7 +37,7 @@ public async void ListOfValidatorsIsReturned() AccountNumber = "ad1f8845c6a1abb6011a2a434a079a087c460657aad54329a84b406dce8bf314", IpAddress = "192.168.1.74", NodeIdentifier = "3afdf37573f1a511def0bd85553404b7091a76bcd79cdcebba1310527b167521", - Port = "8000", + Port = 8000, Protocol = "http", Version = "v1.0", DefaultTransactionFee = 4, @@ -52,7 +52,7 @@ public async void ListOfValidatorsIsReturned() AccountNumber = "4d2ec91f37bc553bc538e91195669b666e26b2ea3e4e31507e38102a758d4f86", IpAddress = "86.168.1.23", NodeIdentifier = "59479a31c3b91d96bb7a0b3e07f18d4bf301f1bb0bde05f8d36d9611dcbe7cbf", - Port = "80", + Port = 80, Protocol = "http", Version = "v1.0", DefaultTransactionFee = 2, diff --git a/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs b/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs index b3739e0..c08590a 100644 --- a/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs +++ b/src/Thenewboston/Bank/Api/BankConfirmationBlockService.cs @@ -46,27 +46,5 @@ public async Task> GetAllBankConfi return result; } - - /// NOTE: Not implemented in the app layer as this is functionality for the validator, therefore not needed in any apps. - /// - /// Provides a facility for a confirmation validator to post a new to the - /// receiving bank. - /// - /// - /// - public async Task 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; - } } } diff --git a/src/Thenewboston/Bank/Api/ConnectionRequestService.cs b/src/Thenewboston/Bank/Api/ConnectionRequestService.cs deleted file mode 100644 index a5e5c83..0000000 --- a/src/Thenewboston/Bank/Api/ConnectionRequestService.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Thenewboston.Bank.Models; -using Thenewboston.Common.Http; - -namespace Thenewboston.Bank.Api -{ - public class ConnectionRequestService : IConnectionRequestService - { - IHttpRequestSender _requestSender; - - public ConnectionRequestService(IHttpRequestSender requestSender) - { - _requestSender = requestSender; - } - - public async Task 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; - } - } -} diff --git a/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs b/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs index 28f0c0f..f569707 100644 --- a/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs +++ b/src/Thenewboston/Bank/Api/IBankConfirmationBlockService.cs @@ -9,6 +9,5 @@ namespace Thenewboston.Bank.Api public interface IBankConfirmationBlockService { public Task> GetAllBankConfiramtionBlocksAsync(int offset, int limit); - public Task PostConfirmationBlockAsync(ConfirmationBlock confirmationBlock); } } diff --git a/src/Thenewboston/Bank/Api/IConnectionRequestService.cs b/src/Thenewboston/Bank/Api/IConnectionRequestService.cs deleted file mode 100644 index 9f03052..0000000 --- a/src/Thenewboston/Bank/Api/IConnectionRequestService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Thenewboston.Bank.Models; - -namespace Thenewboston.Bank.Api -{ - public interface IConnectionRequestService - { - Task PostConnectionRequestAsync(ConnectionRequest connectionNotice); - } -} diff --git a/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs b/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs index 764674f..a620dee 100644 --- a/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs +++ b/src/Thenewboston/Bank/Api/IInvalidBlocksService.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; + +using System.Threading.Tasks; using Thenewboston.Bank.Api.Models; using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; @@ -7,8 +8,6 @@ namespace Thenewboston.Bank.Api { public interface IInvalidBlocksService { - Task> GetInvalidBankBlocksAsync(int offset, int limit); - Task SendInvalidBlocksToBankAsync(BankInvalidBlockRequest model); - + Task> GetInvalidBankBlocksAsync(int offset, int limit); } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/IUpgradeNoticeService.cs b/src/Thenewboston/Bank/Api/IUpgradeNoticeService.cs deleted file mode 100644 index b7019ce..0000000 --- a/src/Thenewboston/Bank/Api/IUpgradeNoticeService.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Thenewboston.Bank.Models; - -namespace Thenewboston.Bank.Api -{ - public interface IUpgradeNoticeService - { - Task PostUpgradeNoticeAsync(UpgradeNotice upgradeNotice); - } -} diff --git a/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs b/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs index 5d59720..1541d6d 100644 --- a/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs +++ b/src/Thenewboston/Bank/Api/IValidatorConfirmationService.cs @@ -11,8 +11,5 @@ public interface IValidatorConfirmationService public Task> GetValidatorConfirmationServicesAsync( int offset, int limit); - - public Task PostValidatorConfirmationServiceAsync( - BankValidatorConfirmationService service); } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs index 6e6bf0a..af3735e 100644 --- a/src/Thenewboston/Bank/Api/InvalidBlocksService.cs +++ b/src/Thenewboston/Bank/Api/InvalidBlocksService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -32,15 +32,5 @@ public async Task> GetInvalidBankBlocks return JsonConvert.DeserializeObject>(responseContent); } - public async Task 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(responseContent); - } } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Api/Models/BankInvalidBlockRequest.cs b/src/Thenewboston/Bank/Api/Models/BankInvalidBlockRequest.cs index 065d8f4..6eb78c6 100644 --- a/src/Thenewboston/Bank/Api/Models/BankInvalidBlockRequest.cs +++ b/src/Thenewboston/Bank/Api/Models/BankInvalidBlockRequest.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Numerics; +using Newtonsoft.Json; namespace Thenewboston.Bank.Api.Models { @@ -50,7 +51,7 @@ public class BlockMessage public class BlockTransactions { [JsonProperty("amount")] - public double Amount { get; set; } + public BigDecimal Amount { get; set; } [JsonProperty("recipient")] public string Recipient { get; set; } diff --git a/src/Thenewboston/Bank/Api/Models/BankNode.cs b/src/Thenewboston/Bank/Api/Models/BankNode.cs index 465cead..338bf6e 100644 --- a/src/Thenewboston/Bank/Api/Models/BankNode.cs +++ b/src/Thenewboston/Bank/Api/Models/BankNode.cs @@ -17,7 +17,7 @@ public class BankNode public string NodeIdentifier { get; set; } [JsonProperty(PropertyName = "port")] - public int Port { get; set; } + public int? Port { get; set; } [JsonProperty(PropertyName = "protocol")] public string Protocol { get; set; } diff --git a/src/Thenewboston/Bank/Api/TransactionsService.cs b/src/Thenewboston/Bank/Api/TransactionsService.cs index ea90d5c..f1f1abd 100644 --- a/src/Thenewboston/Bank/Api/TransactionsService.cs +++ b/src/Thenewboston/Bank/Api/TransactionsService.cs @@ -5,7 +5,8 @@ using Thenewboston.Bank.Models; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; - +using Thenewboston.Common.Math; + namespace Thenewboston.Bank.Api { public class TransactionsService : ITransactionsService @@ -37,9 +38,13 @@ public async Task> GetAllTransactionsAsy { //TODO: create specific exception throw new Exception(); - } + } + + var settings = new JsonSerializerSettings(); + settings.FloatParseHandling = FloatParseHandling.Decimal; + settings.Converters.Add(new JsonBigDecimalConverter()); - var result = JsonConvert.DeserializeObject>(stringResult); + var result = JsonConvert.DeserializeObject>(stringResult, settings); return result; } diff --git a/src/Thenewboston/Bank/Api/UpgradeNoticeService.cs b/src/Thenewboston/Bank/Api/UpgradeNoticeService.cs deleted file mode 100644 index 480ed67..0000000 --- a/src/Thenewboston/Bank/Api/UpgradeNoticeService.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Thenewboston.Bank.Models; -using Thenewboston.Common.Http; - -namespace Thenewboston.Bank.Api -{ - public class UpgradeNoticeService : IUpgradeNoticeService - { - IHttpRequestSender _requestSender; - - public UpgradeNoticeService(IHttpRequestSender requestSender) - { - _requestSender = requestSender; - } - - public async Task 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; - } - } -} diff --git a/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs b/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs index 7a8392e..92221ed 100644 --- a/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs +++ b/src/Thenewboston/Bank/Api/ValidatorConfirmationService.cs @@ -47,22 +47,5 @@ public ValidatorConfirmationService(IHttpRequestSender requestSender) return result; } - - public async Task PostValidatorConfirmationServiceAsync( - BankValidatorConfirmationService service) - { - var httpContent = - new StringContent(JsonConvert.SerializeObject(service), Encoding.UTF8, "application/json"); - var request = await _requestSender.PostAsync("/blocks", httpContent); - - if (!request.IsSuccessStatusCode) - { - // TODO: Create specific exception - throw new Exception(); - } - - var response = new HttpResponseMessage(System.Net.HttpStatusCode.Created); - return response; - } } } \ No newline at end of file diff --git a/src/Thenewboston/Bank/Models/BankTransaction.cs b/src/Thenewboston/Bank/Models/BankTransaction.cs index c80799b..223d796 100644 --- a/src/Thenewboston/Bank/Models/BankTransaction.cs +++ b/src/Thenewboston/Bank/Models/BankTransaction.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Numerics; +using Newtonsoft.Json; namespace Thenewboston.Bank.Models { @@ -13,7 +14,7 @@ public class BankTransaction public string Recipient { get; set; } - public decimal Amount { get; set; } + public BigDecimal Amount { get; set; } } } diff --git a/src/Thenewboston/Bank/Models/BankValidator.cs b/src/Thenewboston/Bank/Models/BankValidator.cs index c6549ab..91eb311 100644 --- a/src/Thenewboston/Bank/Models/BankValidator.cs +++ b/src/Thenewboston/Bank/Models/BankValidator.cs @@ -23,7 +23,7 @@ public class BankValidator public string IpAddress { get; set; } [JsonProperty(PropertyName = "port")] - public string Port { get; set; } + public int? Port { get; set; } [JsonProperty(PropertyName = "version")] public string Version { get; set; } diff --git a/src/Thenewboston/Bank/Models/ConnectionRequestMessage.cs b/src/Thenewboston/Bank/Models/ConnectionRequestMessage.cs index 4d002d2..9441dd0 100644 --- a/src/Thenewboston/Bank/Models/ConnectionRequestMessage.cs +++ b/src/Thenewboston/Bank/Models/ConnectionRequestMessage.cs @@ -11,7 +11,7 @@ public class ConnectionRequestMessage public string IpAddress { get; set; } [JsonProperty(PropertyName = "port")] - public string Port { get; set; } + public int? Port { get; set; } [JsonProperty(PropertyName = "protocol")] public string Protocol { get; set; } diff --git a/src/Thenewboston/Common/Math/BigDecimal.cs b/src/Thenewboston/Common/Math/BigDecimal.cs index 38e7a82..72c74b8 100644 --- a/src/Thenewboston/Common/Math/BigDecimal.cs +++ b/src/Thenewboston/Common/Math/BigDecimal.cs @@ -419,8 +419,13 @@ public int CompareTo(BigDecimal other) public bool Equals(BigDecimal other) { return this._scale == other._scale && this._unscaledValue == other._unscaledValue; - } - - #endregion - } + } + + #endregion + + public static BigDecimal Parse(string str) + { + return new BigDecimal(Convert.ToDouble(str)); + } + } } \ No newline at end of file diff --git a/src/Thenewboston/Common/Math/JsonBigDecimalConverter.cs b/src/Thenewboston/Common/Math/JsonBigDecimalConverter.cs new file mode 100644 index 0000000..ed9a6cb --- /dev/null +++ b/src/Thenewboston/Common/Math/JsonBigDecimalConverter.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using System.Text; +using Newtonsoft.Json; + +namespace Thenewboston.Common.Math +{ + public class JsonBigDecimalConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + { + return (objectType == typeof(BigDecimal)); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + return BigDecimal.Parse(reader.Value.ToString()); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Thenewboston/Common/Models/BlockTransaction.cs b/src/Thenewboston/Common/Models/BlockTransaction.cs index cebb961..b2cb617 100644 --- a/src/Thenewboston/Common/Models/BlockTransaction.cs +++ b/src/Thenewboston/Common/Models/BlockTransaction.cs @@ -1,3 +1,4 @@ +using System.Numerics; using Newtonsoft.Json; namespace Thenewboston.Common.Models @@ -5,7 +6,7 @@ namespace Thenewboston.Common.Models public class BlockTransaction { [JsonProperty(PropertyName ="amount")] - public string Amount { get; set; } + public BigDecimal Amount { get; set; } [JsonProperty(PropertyName ="recipient")] public string Recipient { get; set; } diff --git a/src/Thenewboston/Common/Models/ConfirmationBankBlockTransaction.cs b/src/Thenewboston/Common/Models/ConfirmationBankBlockTransaction.cs index 0c0edd8..fff8b91 100644 --- a/src/Thenewboston/Common/Models/ConfirmationBankBlockTransaction.cs +++ b/src/Thenewboston/Common/Models/ConfirmationBankBlockTransaction.cs @@ -1,11 +1,12 @@ -using Newtonsoft.Json; +using System.Numerics; +using Newtonsoft.Json; namespace Thenewboston.Common.Models { public class ConfirmationBankBlockTransaction { [JsonProperty(PropertyName ="amount")] - public string Amount { get; set; } + public BigDecimal Amount { get; set; } [JsonProperty(PropertyName ="recipient")] public string Recipient { get; set; } diff --git a/src/Thenewboston/Common/Models/ConfirmationUpdatedBalanceRecord.cs b/src/Thenewboston/Common/Models/ConfirmationUpdatedBalanceRecord.cs index c743884..a26b4c2 100644 --- a/src/Thenewboston/Common/Models/ConfirmationUpdatedBalanceRecord.cs +++ b/src/Thenewboston/Common/Models/ConfirmationUpdatedBalanceRecord.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Numerics; +using Newtonsoft.Json; namespace Thenewboston.Common.Models { @@ -9,7 +10,7 @@ public class ConfirmationUpdatedBalanceRecord public string AccountNumber { get; set; } [JsonProperty(PropertyName ="balance")] - public string Balance { get; set; } + public BigDecimal Balance { get; set; } [JsonProperty(PropertyName ="balance_lock")] public string BalanceLock { get; set; } diff --git a/src/Thenewboston/Common/Models/Node.cs b/src/Thenewboston/Common/Models/Node.cs index 0a4583e..6659708 100644 --- a/src/Thenewboston/Common/Models/Node.cs +++ b/src/Thenewboston/Common/Models/Node.cs @@ -20,7 +20,7 @@ public abstract class Node public string IpAddress { get; set; } [JsonProperty(PropertyName = "port")] - public string Port { get; set; } + public int? Port { get; set; } [JsonProperty(PropertyName = "version")] public string Version { get; set; } diff --git a/src/Thenewboston/Nodes/Validator.cs b/src/Thenewboston/Nodes/Validator.cs index 6e42f68..8314966 100644 --- a/src/Thenewboston/Nodes/Validator.cs +++ b/src/Thenewboston/Nodes/Validator.cs @@ -12,7 +12,6 @@ namespace Thenewboston.Nodes public class Validator { private readonly IAccountsService _accountsService; - private readonly IBankBlockService _bankBlockService; // need to ask someone private readonly IBankConfirmationService _bankConfirmationService; private readonly IConfigService _configService; private readonly IConnectedBanksService _connectedBanksService; @@ -23,7 +22,6 @@ public Validator(string ip, int port) { var requestSender = new SimpleHttpRequestSender($"{ip}:{port}"); _accountsService = new AccountsService(requestSender); - _bankBlockService = new BankBlockService(requestSender); _bankConfirmationService = new BankConfirmationService(requestSender); _configService = new ConfigService(requestSender); _connectedBanksService = new ConnectedBanksService(requestSender); diff --git a/src/Thenewboston/Thenewboston.csproj b/src/Thenewboston/Thenewboston.csproj index 5294083..da83c4e 100644 --- a/src/Thenewboston/Thenewboston.csproj +++ b/src/Thenewboston/Thenewboston.csproj @@ -8,7 +8,6 @@ true - diff --git a/src/Thenewboston/Validator/Api/AccountsService.cs b/src/Thenewboston/Validator/Api/AccountsService.cs index 1f2994d..1f83892 100644 --- a/src/Thenewboston/Validator/Api/AccountsService.cs +++ b/src/Thenewboston/Validator/Api/AccountsService.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using Thenewboston.Common.Api.Models; using Thenewboston.Common.Http; +using Thenewboston.Common.Math; using Thenewboston.Validator.Models; namespace Thenewboston.Validator.Api @@ -35,7 +36,11 @@ public async Task> GetAccountsAsync(int throw new Exception(); } - var result = JsonConvert.DeserializeObject>(stringResult); + var settings = new JsonSerializerSettings(); + settings.FloatParseHandling = FloatParseHandling.Decimal; + settings.Converters.Add(new JsonBigDecimalConverter()); + + var result = JsonConvert.DeserializeObject>(stringResult, settings); return result; } @@ -58,7 +63,11 @@ public async Task GetAccountBalanceAsync(string account throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResult); + var settings = new JsonSerializerSettings(); + settings.FloatParseHandling = FloatParseHandling.Decimal; + settings.Converters.Add(new JsonBigDecimalConverter()); + + var result = JsonConvert.DeserializeObject(stringResult, settings); return result; } diff --git a/src/Thenewboston/Validator/Api/BankBlockService.cs b/src/Thenewboston/Validator/Api/BankBlockService.cs deleted file mode 100644 index 35d3133..0000000 --- a/src/Thenewboston/Validator/Api/BankBlockService.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Thenewboston.Common.Http; -using Thenewboston.Validator.Models; - - -namespace Thenewboston.Validator.Api -{ - public class BankBlockService : IBankBlockService - { - private readonly IHttpRequestSender _requestSender; - - public BankBlockService(IHttpRequestSender requestSender) - { - _requestSender = requestSender; - } - - public async Task PostBankBlockAsync(ValidatorBankBlock block) - { - var httpContent = new StringContent(JsonConvert.SerializeObject(block), Encoding.UTF8, "application/json"); - var request = await _requestSender.PostAsync("/bank_blocks", httpContent); - - if(!request.IsSuccessStatusCode) - { - // TODO: Create specific exception - throw new Exception(); - } - - var response = new HttpResponseMessage(System.Net.HttpStatusCode.Created); - return response; - } - } -} \ No newline at end of file diff --git a/src/Thenewboston/Validator/Api/ConnectionRequestService.cs b/src/Thenewboston/Validator/Api/ConnectionRequestService.cs deleted file mode 100644 index f8d6358..0000000 --- a/src/Thenewboston/Validator/Api/ConnectionRequestService.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Thenewboston.Common.Http; -using Thenewboston.Validator.Models; - -namespace Thenewboston.Validator.Api -{ - public class ConnectionRequestService : IConnectionRequestService - { - IHttpRequestSender _requestSender; - - public ConnectionRequestService(IHttpRequestSender requestSender) - { - _requestSender = requestSender; - } - - public async Task 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; - } - } -} diff --git a/src/Thenewboston/Validator/Api/IBankBlockService.cs b/src/Thenewboston/Validator/Api/IBankBlockService.cs deleted file mode 100644 index 25d51c2..0000000 --- a/src/Thenewboston/Validator/Api/IBankBlockService.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Thenewboston.Validator.Models; - -namespace Thenewboston.Validator.Api -{ - public interface IBankBlockService - { - public Task PostBankBlockAsync(ValidatorBankBlock block); - } -} \ No newline at end of file diff --git a/src/Thenewboston/Validator/Api/IConnectionRequestService.cs b/src/Thenewboston/Validator/Api/IConnectionRequestService.cs deleted file mode 100644 index c7ba538..0000000 --- a/src/Thenewboston/Validator/Api/IConnectionRequestService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Thenewboston.Validator.Models; - -namespace Thenewboston.Validator.Api -{ - public interface IConnectionRequestService - { - Task PostConnectionRequestAsync(ConnectionRequest connectionNotice); - } -} diff --git a/src/Thenewboston/Validator/Api/IUpgradeRequestService.cs b/src/Thenewboston/Validator/Api/IUpgradeRequestService.cs deleted file mode 100644 index 6899779..0000000 --- a/src/Thenewboston/Validator/Api/IUpgradeRequestService.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Thenewboston.Validator.Api.Models; -using Thenewboston.Validator.Models; - -namespace Thenewboston.Validator.Api -{ - public interface IUpgradeRequestService - { - public Task PostUpgradeRequestAsync(UpgradeRequest upgradeRequest); - } -} diff --git a/src/Thenewboston/Validator/Api/Models/ValidatorResponseModel.cs b/src/Thenewboston/Validator/Api/Models/ValidatorResponseModel.cs index 54f78e7..97e1d9f 100644 --- a/src/Thenewboston/Validator/Api/Models/ValidatorResponseModel.cs +++ b/src/Thenewboston/Validator/Api/Models/ValidatorResponseModel.cs @@ -23,7 +23,7 @@ public class ValidatorResponseModel public string IpAddress { get; set; } [JsonProperty(PropertyName = "port")] - public string Port { get; set; } + public int? Port { get; set; } [JsonProperty(PropertyName = "version")] public string Version { get; set; } diff --git a/src/Thenewboston/Validator/Api/UpgradeRequestService.cs b/src/Thenewboston/Validator/Api/UpgradeRequestService.cs deleted file mode 100644 index 8a551fe..0000000 --- a/src/Thenewboston/Validator/Api/UpgradeRequestService.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Thenewboston.Common.Http; -using Thenewboston.Validator.Api.Models; -using Thenewboston.Validator.Models; - -namespace Thenewboston.Validator.Api -{ - public class UpgradeRequestService : IUpgradeRequestService - { - private readonly IHttpRequestSender _requestSender; - - public UpgradeRequestService(IHttpRequestSender requestSender) - { - _requestSender = requestSender; - } - - /// - /// Posts a new upgrade request to a confirmation validator requesting that it upgrade to a Primary Validator. - /// Requesting bank will pass a - /// - /// - /// NOTE: 200: Ok - Validator has accepted the upgrade request, 400: Bad Request - Validator has rejected the upgrade - public async Task 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; - } - } -} diff --git a/src/Thenewboston/Validator/Api/ValidatorConfirmationBlockService.cs b/src/Thenewboston/Validator/Api/ValidatorConfirmationBlockService.cs index d4cfc2d..3456f50 100644 --- a/src/Thenewboston/Validator/Api/ValidatorConfirmationBlockService.cs +++ b/src/Thenewboston/Validator/Api/ValidatorConfirmationBlockService.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Newtonsoft.Json; using Thenewboston.Common.Http; +using Thenewboston.Common.Math; using Thenewboston.Common.Models; namespace Thenewboston.Validator.Api @@ -44,7 +45,11 @@ public async Task PostConfirmationBlockAsync(Confirma throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResult); + var settings = new JsonSerializerSettings(); + settings.FloatParseHandling = FloatParseHandling.Decimal; + settings.Converters.Add(new JsonBigDecimalConverter()); + + var result = JsonConvert.DeserializeObject(stringResult, settings); return result; } @@ -74,7 +79,11 @@ public async Task GetQueuedConfirmationBlockAsync(string bloc throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResult); + var settings = new JsonSerializerSettings(); + settings.FloatParseHandling = FloatParseHandling.Decimal; + settings.Converters.Add(new JsonBigDecimalConverter()); + + var result = JsonConvert.DeserializeObject(stringResult, settings); return result; } @@ -104,7 +113,11 @@ public async Task GetValidConfirmationBlockAsync(string block throw new Exception(); } - var result = JsonConvert.DeserializeObject(stringResult); + var settings = new JsonSerializerSettings(); + settings.FloatParseHandling = FloatParseHandling.Decimal; + settings.Converters.Add(new JsonBigDecimalConverter()); + + var result = JsonConvert.DeserializeObject(stringResult, settings); return result; } diff --git a/src/Thenewboston/Validator/Models/ConnectionRequestMessage.cs b/src/Thenewboston/Validator/Models/ConnectionRequestMessage.cs index a48232c..422da70 100644 --- a/src/Thenewboston/Validator/Models/ConnectionRequestMessage.cs +++ b/src/Thenewboston/Validator/Models/ConnectionRequestMessage.cs @@ -11,7 +11,7 @@ public class ConnectionRequestMessage public string IpAddress { get; set; } [JsonProperty(PropertyName = "port")] - public string Port { get; set; } + public int? Port { get; set; } [JsonProperty(PropertyName = "protocol")] public string Protocol { get; set; } diff --git a/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedMessage.cs b/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedMessage.cs index 6cea70c..2860c16 100644 --- a/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedMessage.cs +++ b/src/Thenewboston/Validator/Models/PrimaryValidatorUpdatedMessage.cs @@ -8,7 +8,7 @@ public class PrimaryValidatorUpdatedMessage public string IPAddress { get; set; } [JsonProperty(PropertyName ="port")] - public string Port { get; set; } + public int? Port { get; set; } [JsonProperty(PropertyName ="protocol")] public string Protocol { get; set; } diff --git a/src/Thenewboston/Validator/Models/ValidatorAccount.cs b/src/Thenewboston/Validator/Models/ValidatorAccount.cs index 7bcc1a2..75113a9 100644 --- a/src/Thenewboston/Validator/Models/ValidatorAccount.cs +++ b/src/Thenewboston/Validator/Models/ValidatorAccount.cs @@ -9,7 +9,7 @@ public class ValidatorAccount public string AccountNumber { get; set; } - public string Balance { get; set; } + public BigDecimal Balance { get; set; } public string BalanceLock { get; set; } } diff --git a/src/Thenewboston/Validator/Models/ValidatorAccountBalance.cs b/src/Thenewboston/Validator/Models/ValidatorAccountBalance.cs index 9ad7a67..92f795b 100644 --- a/src/Thenewboston/Validator/Models/ValidatorAccountBalance.cs +++ b/src/Thenewboston/Validator/Models/ValidatorAccountBalance.cs @@ -1,7 +1,9 @@ -namespace Thenewboston.Validator.Models +using System.Numerics; + +namespace Thenewboston.Validator.Models { public class ValidatorAccountBalance { - public string Balance { get; set; } + public BigDecimal Balance { get; set; } } } diff --git a/src/Thenewboston/Validator/Models/ValidatorBank.cs b/src/Thenewboston/Validator/Models/ValidatorBank.cs index d8284c9..491781d 100644 --- a/src/Thenewboston/Validator/Models/ValidatorBank.cs +++ b/src/Thenewboston/Validator/Models/ValidatorBank.cs @@ -14,7 +14,7 @@ public class ValidatorBank public string NodeIdentifier { get; set; } [JsonProperty(PropertyName = "port")] - public int Port { get; set; } + public int? Port { get; set; } [JsonProperty(PropertyName = "protocol")] public string Protocol { get; set; }