From 70ac88e894eebf1bce5952ea292744217c8826b1 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Fri, 23 Dec 2022 19:03:08 -0800 Subject: [PATCH 1/4] :sparkles: receiving does not have to be a json field --- src/log.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/log.cpp b/src/log.cpp index 6b734a0..c01eb44 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -53,7 +53,7 @@ std::string Log::GetLogsV2() noexcept { log_snapshot_v2.resize(0); //re-generate snapshot - size_t predicted_size = ((77 + max_name_size) * data.size()) + 1; + size_t predicted_size = ((59 + max_name_size) * data.size()) + 1; if (log_snapshot_v2.capacity() < predicted_size) { log_snapshot_v2.reserve(predicted_size); @@ -63,9 +63,8 @@ std::string Log::GetLogsV2() noexcept { log_snapshot_v2 += "{\"counterparty\":\""; //17 log_snapshot_v2 += data[i].counterparty; //max_name_size? - log_snapshot_v2 += "\",\"receiving\":"; //15 - log_snapshot_v2 += (data[i].receiving)?"true":"false"; //4 log_snapshot_v2 += ",\"amount\":"; //11 + if (!data[i].receiving) { log_snapshot_v2 += '-'; } //1 log_snapshot_v2 += std::to_string(data[i].amount); //10? log_snapshot_v2 += ",\"time\":"; //8 log_snapshot_v2 += std::to_string(data[i].time); //10? From 6e6d722f9fb24ac319ac28b7dc0d060797a231a3 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Fri, 23 Dec 2022 19:05:26 -0800 Subject: [PATCH 2/4] :memo: 157 bytes -> 139 --- docs/connected_services/existing_services.md | 2 +- docs/features/user_side.md | 2 +- main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/connected_services/existing_services.md b/docs/connected_services/existing_services.md index 261ad87..926a9c7 100644 --- a/docs/connected_services/existing_services.md +++ b/docs/connected_services/existing_services.md @@ -10,7 +10,7 @@ ## General | author | name | support | image | | :-------------------------------------- | ----------------------------------------------------------- | :----------------: | :-------------------------------------------------------------------------------------------------------------: | -| [Expand](https://github.com/Expand-sys) | [Web Frontend](https://github.com/Expand-sys/ccashfrontend) | ⚠ | ![image](https://user-images.githubusercontent.com/31377881/121337724-afe9fe80-c8d1-11eb-8851-23ec5e74cd26.png) | +| [Expand](https://github.com/Expand-sys) | [Web Frontend](https://github.com/Expand-sys/ccashfrontend) | :heavy_check_mark: | ![image](https://user-images.githubusercontent.com/31377881/121337724-afe9fe80-c8d1-11eb-8851-23ec5e74cd26.png) | | [Expand](https://github.com/Expand-sys) | [Discord Bot](https://github.com/Expand-sys/ccashbot) | :heavy_check_mark: | | | [ArcNyxx](https://github.com/ArcNyxx) | [CCash CLI](https://github.com/ArcNyxx/ccash_cmd) | ⚠ | | diff --git a/docs/features/user_side.md b/docs/features/user_side.md index bfb9aa7..4a0a17f 100644 --- a/docs/features/user_side.md +++ b/docs/features/user_side.md @@ -7,7 +7,7 @@ Capable of processing thousands of requests per second, with little slow down as user size grows to the millions. #### Lightweight -* Low memory usage at 8 MB baseline, and 157 bytes per new log. +* Low memory usage at 8 MB baseline, and 139 bytes per new log. * Extremely low CPU usage in the single digits of %. * Small save files at typically a couple kb, easily shareable. ## Accessibility diff --git a/main.cpp b/main.cpp index 4e0fc31..8d0aa2a 100644 --- a/main.cpp +++ b/main.cpp @@ -74,7 +74,7 @@ int main(int argc, char **argv) size_t num_of_logs = Bank::NumOfLogs(); size_t num_of_users = Bank::NumOfUsers(); std::cout << "\n\nLoaded " << num_of_users << " Users ~" << (float)(sizeof(User) * num_of_users) / 1048576 << "MB" - << "\nLoaded " << num_of_logs << " Logs ~" << (float)(num_of_logs * (93 + sizeof(Transaction) + max_name_size)) / 1048576 << "MB" //93:cached response per log(heap), sizeof(Transaction), max_name_size:counterparty(heap) + << "\nLoaded " << num_of_logs << " Logs ~" << (float)(num_of_logs * (75 + sizeof(Transaction) + max_name_size)) / 1048576 << "MB" //75:cached response per log(heap), sizeof(Transaction), max_name_size:counterparty(heap) << "\nLoaded " << Bank::SumBal() << " C$H" << std::endl; //flushing before EventLoop From 705a746a3c4e8a2019f831163227357604220e6e Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Fri, 23 Dec 2022 19:06:31 -0800 Subject: [PATCH 3/4] :memo: 157 bytes -> 139 --- docs/building.md | 2 +- docs/connected_services/existing_services.md | 2 +- docs/features/user_side.md | 2 +- main.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/building.md b/docs/building.md index 5eb8579..5440600 100644 --- a/docs/building.md +++ b/docs/building.md @@ -5,7 +5,7 @@ as CCash is very lightweight it can run on practically any device but here are some tips: * single core machines should toggle `MULTI_THREADED` to `false` * if your server is sufficiently active, such that each time save frequency is met, changes having been made is highly likely then `CONSERVATIVE_DISK_SAVE` should be toggled to `false` -* `MAX_LOG_SIZE` should be adjusted as it takes up the most memory usage/storage of the ledger's features at 157 bytes in memory and 43 bytes in disk at default settings on the current version, so 6678 logs per MB of RAM. Setting to 0 will disable logs +* `MAX_LOG_SIZE` should be adjusted as it takes up the most memory usage/storage of the ledger's features at 139 bytes in memory and 43 bytes in disk at default settings on the current version, so 6678 logs per MB of RAM. Setting to 0 will disable logs * with no users memory usage is ~8.47 MB * saving frequency being set to 0 will disable frequency saving and only save on close * make backups of your save files! diff --git a/docs/connected_services/existing_services.md b/docs/connected_services/existing_services.md index 261ad87..926a9c7 100644 --- a/docs/connected_services/existing_services.md +++ b/docs/connected_services/existing_services.md @@ -10,7 +10,7 @@ ## General | author | name | support | image | | :-------------------------------------- | ----------------------------------------------------------- | :----------------: | :-------------------------------------------------------------------------------------------------------------: | -| [Expand](https://github.com/Expand-sys) | [Web Frontend](https://github.com/Expand-sys/ccashfrontend) | ⚠ | ![image](https://user-images.githubusercontent.com/31377881/121337724-afe9fe80-c8d1-11eb-8851-23ec5e74cd26.png) | +| [Expand](https://github.com/Expand-sys) | [Web Frontend](https://github.com/Expand-sys/ccashfrontend) | :heavy_check_mark: | ![image](https://user-images.githubusercontent.com/31377881/121337724-afe9fe80-c8d1-11eb-8851-23ec5e74cd26.png) | | [Expand](https://github.com/Expand-sys) | [Discord Bot](https://github.com/Expand-sys/ccashbot) | :heavy_check_mark: | | | [ArcNyxx](https://github.com/ArcNyxx) | [CCash CLI](https://github.com/ArcNyxx/ccash_cmd) | ⚠ | | diff --git a/docs/features/user_side.md b/docs/features/user_side.md index bfb9aa7..4a0a17f 100644 --- a/docs/features/user_side.md +++ b/docs/features/user_side.md @@ -7,7 +7,7 @@ Capable of processing thousands of requests per second, with little slow down as user size grows to the millions. #### Lightweight -* Low memory usage at 8 MB baseline, and 157 bytes per new log. +* Low memory usage at 8 MB baseline, and 139 bytes per new log. * Extremely low CPU usage in the single digits of %. * Small save files at typically a couple kb, easily shareable. ## Accessibility diff --git a/main.cpp b/main.cpp index 4e0fc31..8d0aa2a 100644 --- a/main.cpp +++ b/main.cpp @@ -74,7 +74,7 @@ int main(int argc, char **argv) size_t num_of_logs = Bank::NumOfLogs(); size_t num_of_users = Bank::NumOfUsers(); std::cout << "\n\nLoaded " << num_of_users << " Users ~" << (float)(sizeof(User) * num_of_users) / 1048576 << "MB" - << "\nLoaded " << num_of_logs << " Logs ~" << (float)(num_of_logs * (93 + sizeof(Transaction) + max_name_size)) / 1048576 << "MB" //93:cached response per log(heap), sizeof(Transaction), max_name_size:counterparty(heap) + << "\nLoaded " << num_of_logs << " Logs ~" << (float)(num_of_logs * (75 + sizeof(Transaction) + max_name_size)) / 1048576 << "MB" //75:cached response per log(heap), sizeof(Transaction), max_name_size:counterparty(heap) << "\nLoaded " << Bank::SumBal() << " C$H" << std::endl; //flushing before EventLoop From 396b676ee522c9a836b6d1224fa99a1897aa5abf Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Fri, 23 Dec 2022 19:32:28 -0800 Subject: [PATCH 4/4] :memo: updating GetLogsV2 docs --- docs/building.md | 2 +- docs/connected_services/how_to/endpoints.md | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/building.md b/docs/building.md index 5440600..9f00af1 100644 --- a/docs/building.md +++ b/docs/building.md @@ -5,7 +5,7 @@ as CCash is very lightweight it can run on practically any device but here are some tips: * single core machines should toggle `MULTI_THREADED` to `false` * if your server is sufficiently active, such that each time save frequency is met, changes having been made is highly likely then `CONSERVATIVE_DISK_SAVE` should be toggled to `false` -* `MAX_LOG_SIZE` should be adjusted as it takes up the most memory usage/storage of the ledger's features at 139 bytes in memory and 43 bytes in disk at default settings on the current version, so 6678 logs per MB of RAM. Setting to 0 will disable logs +* `MAX_LOG_SIZE` should be adjusted as it takes up the most memory usage/storage of the ledger's features at 139 bytes in memory and 43 bytes in disk at default settings on the current version, so 7543 logs per MB of RAM. Setting to 0 will disable logs * with no users memory usage is ~8.47 MB * saving frequency being set to 0 will disable frequency saving and only save on close * make backups of your save files! diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index e0d5cd4..dd76a7b 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -17,13 +17,13 @@ ## all error responses have JSON string along with them to describe ### Usage endpoints -| name | added on | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U | -| :------------- | :------: | ------------------------------------------------------------------------------ | -------------------------------- | ------------------------------- | :---------: | :------------: | :--------------: | :---------------------------------------------------------------------------: | :----------------: | :----------------: | :---: | :----------------: | -| GetBal | `v2.3.0` | retrieving the balance of a given user, `{name}` | `N/A` | api/v1/user/balance?name={name} | `GET` | 200 | uint32 | the user's balance | :heavy_check_mark: | :x: | :x: | :x: | -| GetLog | `v2.3.0` | retrieves the logs of a given user, length varies by server configuration | `N/A` | ⚠ api/v1/user/log | `GET` | 200 | array of objects | [{"to":string, "from":string, "amount":uint32, "time":int64}] | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | -| GetLogV2 | `v2.5.1` | retrieves the logs of a given user, length varies by server configuration | `N/A` | api/v2/user/log | `GET` | 200 | array of objects | [{"counterparty":string, "receiving":boolean, "amount":uint32, "time":int64}] | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | -| SendFunds | `v2.3.0` | sends funds from the authenticated user to the user `{name}` given in the json | {"name":string, "amount":uint32} | api/v1/user/transfer | `POST` | 200 | uint32 | the user's balance after the transaction | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | -| VerifyPassword | `v2.3.0` | verifies the credentials, used for connected services for ease of use | `N/A` | api/v1/user/verify_password | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | +| name | added on | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U | +| :------------- | :------: | ------------------------------------------------------------------------------ | -------------------------------- | ------------------------------- | :---------: | :------------: | :--------------: | :-----------------------------------------------------------: | :----------------: | :----------------: | :---: | :----------------: | +| GetBal | `v2.3.0` | retrieving the balance of a given user, `{name}` | `N/A` | api/v1/user/balance?name={name} | `GET` | 200 | uint32 | the user's balance | :heavy_check_mark: | :x: | :x: | :x: | +| GetLog | `v2.3.0` | retrieves the logs of a given user, length varies by server configuration | `N/A` | ⚠ api/v1/user/log | `GET` | 200 | array of objects | [{"to":string, "from":string, "amount":uint32, "time":int64}] | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | +| GetLogV2 | `v2.5.1` | retrieves the logs of a given user, length varies by server configuration | `N/A` | api/v2/user/log | `GET` | 200 | array of objects | [{"counterparty":string, "amount":int64, "time":int64}] | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | +| SendFunds | `v2.3.0` | sends funds from the authenticated user to the user `{name}` given in the json | {"name":string, "amount":uint32} | api/v1/user/transfer | `POST` | 200 | uint32 | the user's balance after the transaction | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | +| VerifyPassword | `v2.3.0` | verifies the credentials, used for connected services for ease of use | `N/A` | api/v1/user/verify_password | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | ### Usage enpoint errors | name | 400 | 401 | 404 | 406 |