changed to per-method versioning

This commit is contained in:
EntireTwix 2022-12-19 15:45:05 -08:00
parent cc103c7298
commit 83455a0510
16 changed files with 121 additions and 210 deletions

View file

@ -81,16 +81,10 @@ set(RETURN_ON_DEL_VAL false)
set(RETURN_ON_DEL_NAME_VAL "\"\"")
endif()
if(DEFINED API_VERSION)
set(API_VERSION_VAL ${API_VERSION})
if(DEFINED USE_DEPRECATED_ENDPOINTS)
set(USE_DEPRECATED_ENDPOINTS_VAL ${USE_DEPRECATED_ENDPOINTS})
else()
set(API_VERSION_VAL 2)
endif()
if(DEFINED MIN_API_SUPPORT)
set(MIN_API_SUPPORT_VAL ${MIN_API_SUPPORT})
else()
set(MIN_API_SUPPORT_VAL 1)
set(USE_DEPRECATED_ENDPOINTS_VAL true)
endif()
configure_file(ccash_config.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/ccash_config.hpp)

View file

@ -90,14 +90,12 @@ int main(int argc, char **argv)
Op(Bank::VerifyPassword("twix", "root"), "verify pass: ", 1000000);
Op(Bank::ChangePassword("twix", "root"), "change pass: ", 1000000);
#if MAX_LOG_SIZE > 0
#if MIN_API_SUPPORT == 1
#if USE_DEPRECATED_ENDPOINTS
Op(Bank::GetLogs("twix"), "get logs init: ", 1);
Op(Bank::GetLogs("twix"), "get logs cached: ", 1000000);
#endif
#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2)
Op(Bank::GetLogsV2("twix"), "get logs init (v2): ", 1);
Op(Bank::GetLogsV2("twix"), "get logs cached (v2): ", 1000000);
#endif
#endif
Op(Bank::PruneUsers(0, 0), "prune users: ", 1);
Op(Bank::Save(), "saving: ", 1);

View file

@ -28,12 +28,8 @@ if false, when frequency is hit save
*/
#define CONSERVATIVE_DISK_SAVE @CONSERVATIVE_DISK_SAVE_VAL@
// doesnt compile api endpoints above API_VERSION
#define API_VERSION @API_VERSION_VAL@
// doesnt compile api endpoints below MIN_API_SUPPORT
#define MIN_API_SUPPORT @MIN_API_SUPPORT_VAL@
#define MULTI_THREADED @MULTI_THREADED_VAL@
#define ADD_USER_OPEN @ADD_USER_OPEN_VAL@
#define ADD_USER_OPEN @ADD_USER_OPEN_VAL@
#define USE_DEPRECATED_ENDPOINTS @USE_DEPRECATED_ENDPOINTS_VAL@

View file

@ -4,11 +4,10 @@
become: true
pre_tasks:
- name: load variables
ansible.builtin.include_vars: '{{ item }}'
ansible.builtin.include_vars: "{{ item }}"
with_first_found:
- "default.yml"
tasks:
- name: refresh packages update
yum:
@ -24,20 +23,30 @@
- name: install dependencies
yum:
name: [git, gcc, gcc-c++, libuuid-devel, openssl-devel, zlib-devel, jsoncpp-devel, cmake]
name:
[
git,
gcc,
gcc-c++,
libuuid-devel,
openssl-devel,
zlib-devel,
jsoncpp-devel,
cmake,
]
state: present
when: ansible_os_family == "RedHat"
- name: clone CCash repository
git:
repo: https://github.com/EntireTwix/CCash.git
dest: '{{BUILD_DIR}}/CCash'
dest: "{{BUILD_DIR}}/CCash"
recursive: true
update: false
- name: Make lib base64
community.general.make:
chdir: '{{BUILD_DIR}}/CCash/third_party/base64'
chdir: "{{BUILD_DIR}}/CCash/third_party/base64"
params:
AVX2_CFLAGS: -mavx2
SSSE3_CFLAGS: -mssse3
@ -45,37 +54,36 @@
SSE42_CFLAGS: -msse4.2
AVX_CFLAGS: -mavx
- name: create build dir
- name: create build dir
file:
path: '{{BUILD_DIR}}/CCash/build'
path: "{{BUILD_DIR}}/CCash/build"
state: directory
- name: Cmake CCash
ansible.builtin.command:
chdir: '{{BUILD_DIR}}/CCash/build'
chdir: "{{BUILD_DIR}}/CCash/build"
cmd: |
cmake -DDROGON_CONFIG_LOC="{{ BUILD_DIR }}/CCash/config/config.json" -DUSER_SAVE_LOC="{{ BUILD_DIR }}/CCash/config/users.dat" -DAPI_VERSION="{{ API_VERSION }}" -DMIN_API_SUPPORT="{{ MIN_API_SUPPORT }}" ..
cmake -DDROGON_CONFIG_LOC="{{ BUILD_DIR }}/CCash/config/config.json" -DUSER_SAVE_LOC="{{ BUILD_DIR }}/CCash/config/users.dat" -DUSE_DEPRECATED_ENDPOINTS="{{ USE_DEPRECATED_ENDPOINTS }}" ..
- name: make CCash
community.general.make:
chdir: '{{BUILD_DIR}}/CCash/build'
chdir: "{{BUILD_DIR}}/CCash/build"
params:
NUM_THREADS: '-j{{ ansible_processor_vcpus }}'
NUM_THREADS: "-j{{ ansible_processor_vcpus }}"
- name: create users file
ansible.builtin.command:
chdir: '{{BUILD_DIR}}/CCash/build/'
chdir: "{{BUILD_DIR}}/CCash/build/"
cmd: ./bank
creates: '{{ BUILD_DIR }}/CCash/config/users.dat'
creates: "{{ BUILD_DIR }}/CCash/config/users.dat"
- name: chmod +x ssl.sh
ansible.builtin.file:
mode: u+x
path: '{{BUILD_DIR}}/CCash/config/ssl.sh'
path: "{{BUILD_DIR}}/CCash/config/ssl.sh"
- name: generate default ssl
ansible.builtin.command:
chdir: '{{BUILD_DIR}}/CCash/config/'
cmd: './ssl.sh'
chdir: "{{BUILD_DIR}}/CCash/config/"
cmd: "./ssl.sh"
- name: create service file
ansible.builtin.copy:
@ -93,4 +101,4 @@
[Install]
WantedBy=multi-user.target
dest: /etc/systemd/system/ccash.service
dest: /etc/systemd/system/ccash.service

View file

@ -1,6 +1,5 @@
---
BUILD_DIR: '/root'
BUILD_DIR: "/root"
ADMIN_A: "admin"
SAVE_FREQ: "2"
API_VERSION: "2"
MIN_API_SUPPORT: "1"
USE_DEPRECATED_ENDPOINTS: "true"

View file

@ -64,19 +64,18 @@ mkdir build
cd build
```
### CMake Flags
### CMake Variables
there are multiple flags responsible configuring CCash:
| name | default | description | pros | cons |
| :--------------------- | :------------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | -------------------------------------------------------- |
| USER_SAVE_LOC | "config/users.dat" | where the users are saved | `N/A` | `N/A` |
| DROGON_CONFIG_LOC | "config/config.json" | where the config is located | `N/A` | `N/A` |
| MAX_LOG_SIZE | 100 | max number of logs per user, last `n` transactions. If both this and pre log are toggled to 0 logs will not be compiled. | large history | higher memory usage |
| CONSERVATIVE_DISK_SAVE | `true` | when `true` only saves when changes are made | low # of disk operations | some atomic overhead |
| MULTI_THREADED | `true` | when `true` the program is compiled to utilize `n` threads which corresponds to how many Cores your CPU has, plus 1 for saving | speed | memory lock overhead is wasteful on single core machines |
| RETURN_ON_DEL_NAME | `N/A` | when defined, return on delete will be toggled and any accounts deleted will send their funds to the defined account, this prevent currency destruction | prevents destruction of currency | deleting accounts is made slower |
| ADD_USER_OPEN | `true` | anybody can make a new account, if set to false only admins can add accounts via `AdminAddUser()` | `N/A` | spamming new users |
| API_VERSION | 2 | the maximum api version's endpoints to be compiled. By default `API_VERSION` is set to the newest version | `N/A` | `N/A` |
| MIN_API_SUPPORT | 1 | the minimum api version's endpoints to be compiled. By default set to 1 for full backwards compatibility, setting to the same value as `API_VERSION` would disable backwards compatiblity | `N/A` | `N/A` |
| name | default | description | pros | cons |
| :----------------------- | :------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | -------------------------------------------------------- |
| USER_SAVE_LOC | "config/users.dat" | where the users are saved | `N/A` | `N/A` |
| DROGON_CONFIG_LOC | "config/config.json" | where the config is located | `N/A` | `N/A` |
| MAX_LOG_SIZE | 100 | max number of logs per user, last `n` transactions. If both this and pre log are toggled to 0 logs will not be compiled. | large history | higher memory usage |
| CONSERVATIVE_DISK_SAVE | `true` | when `true` only saves when changes are made | low # of disk operations | some atomic overhead |
| MULTI_THREADED | `true` | when `true` the program is compiled to utilize `n` threads which corresponds to how many Cores your CPU has, plus 1 for saving | speed | memory lock overhead is wasteful on single core machines |
| RETURN_ON_DEL_NAME | `N/A` | when defined, return on delete will be toggled and any accounts deleted will send their funds to the defined account, this prevent currency destruction | prevents destruction of currency | deleting accounts is made slower |
| ADD_USER_OPEN | `true` | anybody can make a new account, if set to false only admins can add accounts via `AdminAddUser()` | `N/A` | spamming new users |
| USE_DEPRECATED_ENDPOINTS | `true` | some endpoints have newer versions making them obsolete but old programs might still call these endpoints so they are simply marked deprecated. | supports old programs | old endpoints can be ineffecient |
EXAMPLE:
```

View file

@ -1,28 +1,24 @@
[PREVIOUS PAGE](how_to/endpoints.md) | [NEXT PAGE](../features/user_side.md)
## Key
| description | symbol |
| :-------------------: | :----------------- |
| supported | :heavy_check_mark: |
| calls older endpoints | ⚠ |
| calls newer endpoints | :x: |
Just because a service calls old endpoints, doesn't mean the service will not work under that version of CCash. As long as the `MIN_API_SUPPORT` is less than or equal to the required version's endpoints, then the connected service can call the old CCash endpoints. **By default `MIN_API_SUPPORT` is 1 (complete backwards compatibility) making all ⚠ effectively :heavy_check_mark:**.
| description | symbol |
| :-----------------------: | :----------------- |
| supported | :heavy_check_mark: |
| uses deprecated endpoints | ⚠ |
## General
| author | name | v1 | v2 | image |
| :-------------------------------------- | ----------------------------------------------------------- | :----------------: | :---: | :-------------------------------------------------------------------------------------------------------------: |
| [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) | :heavy_check_mark: | ⚠ | |
| author | name | v1 | 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) | [Discord Bot](https://github.com/Expand-sys/ccashbot) | :heavy_check_mark: | |
| [ArcNyxx](https://github.com/ArcNyxx) | [CCash CLI](https://github.com/ArcNyxx/ccash_cmd) | | |
## Minecraft
| author | name | v1 | v2 | image |
| :------------------------------------------ | --------------------------------------------------------------------------- | :----------------: | :----------------: | :-------------------------------------------------------------------------------------------------------------: |
| [Reactified](https://github.com/Reactified) | [Shop](https://github.com/Reactified/rpm/tree/main/packages/ccash-shop) | :heavy_check_mark: | ⚠ | ![image](https://user-images.githubusercontent.com/31377881/120050327-de163700-bfd1-11eb-9d5a-f75c003e867c.png) |
| [Reactified](https://github.com/Reactified) | [Wallet](https://github.com/Reactified/rpm/tree/main/packages/ccash-wallet) | :heavy_check_mark: | ⚠ | ![image](https://user-images.githubusercontent.com/31377881/121338034-fb041180-c8d1-11eb-8640-b18c141eb980.png) |
| [Reactified](https://github.com/Reactified) | [ATM](https://github.com/Reactified/rpm/tree/main/packages/ccash-bank) | :heavy_check_mark: | ⚠ | ![image](https://user-images.githubusercontent.com/31377881/121277361-4d6b1100-c885-11eb-87c8-cfebcf58da4f.png) |
| [STBoyden](https://github.com/STBoyden) | Commodities Exchange (in-development) | :x: | :heavy_check_mark: | |
| author | name | support | image |
| :------------------------------------------ | --------------------------------------------------------------------------- | :----------------: | :-------------------------------------------------------------------------------------------------------------: |
| [Reactified](https://github.com/Reactified) | [Shop](https://github.com/Reactified/rpm/tree/main/packages/ccash-shop) | :heavy_check_mark: | ![image](https://user-images.githubusercontent.com/31377881/120050327-de163700-bfd1-11eb-9d5a-f75c003e867c.png) |
| [Reactified](https://github.com/Reactified) | [Wallet](https://github.com/Reactified/rpm/tree/main/packages/ccash-wallet) | ⚠ | ![image](https://user-images.githubusercontent.com/31377881/121338034-fb041180-c8d1-11eb-8640-b18c141eb980.png) |
| [Reactified](https://github.com/Reactified) | [ATM](https://github.com/Reactified/rpm/tree/main/packages/ccash-bank) | :heavy_check_mark: | ![image](https://user-images.githubusercontent.com/31377881/121277361-4d6b1100-c885-11eb-87c8-cfebcf58da4f.png) |
| [STBoyden](https://github.com/STBoyden) | Commodities Exchange (in-development) | :heavy_check_mark: | |
## Desired
| idea | description |

View file

@ -1,11 +1,11 @@
[PREVIOUS PAGE](explanation.md) | [NEXT PAGE](endpoints.md)
note: all CCash version's API are backwards compatible, so while a language's API may not support the newest CCash endpoints it can still use the old endpoints.
| author | language | | v1 endpoints | v2 endpoints |
| :------------------------------------------- | :------: | ------------------------------------------------------------------- | :----------------: | :----------: |
| [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | :heavy_check_mark: | :x: |
| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | :heavy_check_mark: | :x: |
| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | :heavy_check_mark: | :x: |
CCash is backwards compatible, so even if a language API does not support the newester version it can still call the old endpoints.
| author | language | | newest CCash supported version |
| :------------------------------------------- | :------: | ------------------------------------------------------------------- | :----------------------------: |
| [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | `v1.4.3` |
| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | `v1.4.3` |
| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | `v1.4.3` |
for example here is a demo program for the lua API by SpaceCat

View file

@ -10,21 +10,20 @@
`A` - Admin, same as `U` but in addition requires username supplied be equal to the admin account username
:heavy_check_mark:
:x:
⚠ - Deprecated endpoint
:no_entry: - Defunct endpoint
## all error responses have JSON string along with them to describe
## all endpoint paths start with api/v{n} where n is whatever version you're requesting e.g api/v2
### Usage endpoints
| name | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U |
| :------------- | ------------------------------------------------------------------------------ | -------------------------------- | ------------------------ | :---------: | :------------: | :--------------: | :------------------------------------------------------------------------: | :----------------: | :----------------: | :---: | :----------------: |
| GetBal | retrieving the balance of a given user, `{name}` | `N/A` | user/balance?name={name} | `GET` | 200 | uint32 | the user's balance | :heavy_check_mark: | :x: | :x: | :x: |
| GetLog | retrieves the logs of a given user, length varies by server configuration | `N/A` | user/log | `GET` | 200 | array of objects | [{"to":string, "from":string, "amount":uint32, "time":int64}] | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: |
| GetLogV2 | retrieves the logs of a given user, length varies by server configuration | `N/A` | user/log | `GET` | 200 | array of objects | [{"counterparty":string, "receiving":bool, "amount":uint32, "time":int64}] | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: |
| SendFunds | sends funds from the authenticated user to the user `{name}` given in the json | {"name":string, "amount":uint32} | user/transfer | `POST` | 200 | uint32 | the user's balance after the transaction | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: |
| VerifyPassword | verifies the credentials, used for connected services for ease of use | `N/A` | 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 | `v1.2.3` | 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 | `v1.2.3` | 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 | `v1.5.3` | 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":bool, "amount":uint32, "time":int64}] | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: |
| SendFunds | `v1.2.3` | 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 | `v1.2.3` | 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 |
@ -35,22 +34,13 @@
| SendFunds | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| VerifyPassword | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: |
### Usage endpoint support
| name | v1 | v2 |
| :------------- | :----------------: | :----------------: |
| GetBal | :heavy_check_mark: | :heavy_check_mark: |
| GetLog | :heavy_check_mark: | :x: |
| GetLogV2 | :x: | :heavy_check_mark: |
| SendFunds | :heavy_check_mark: | :heavy_check_mark: |
| VerifyPassword | :heavy_check_mark: | :heavy_check_mark: |
### Meta Usage endpoints
| name | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U |
| :------------------ | -------------------------------------------------------------------------------------------------- | ------------------------------- | -------------------------- | :---------: | :------------: | :---------: | :----------------------------: | :----------------: | :----------------: | :----------------: | :----------------: |
| ChangePassword | changes the password of the Authenticated user | {"pass":string} | user/change_password | `PATCH` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: |
| AdminChangePassword | changes the password of a given user `{name}` | {"name":string,"pass":string} | admin/user/change_password | `PATCH` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| SetBal | sets the balance of a given user `{name}` | {"name":string,"amount":uint32} | admin/set_balance | `PATCH` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| ImpactBal | modifies the user `{name}`'s balance by `{amount}` if positive itll add, if negative itll subtract | {"name":string,"amount":int64} | admin/impact_balance | `POST` | 200 | uint32 | new balance after modification | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| name | added on | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U |
| :------------------ | :------: | -------------------------------------------------------------------------------------------------- | ------------------------------- | --------------------------------- | :---------: | :------------: | :---------: | :----------------------------: | :----------------: | :----------------: | :----------------: | :----------------: |
| ChangePassword | `v1.2.3` | changes the password of the Authenticated user | {"pass":string} | api/v1/user/change_password | `PATCH` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: |
| AdminChangePassword | `v1.2.3` | changes the password of a given user `{name}` | {"name":string,"pass":string} | api/v1/admin/user/change_password | `PATCH` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| SetBal | `v1.2.3` | sets the balance of a given user `{name}` | {"name":string,"amount":uint32} | api/v1/admin/set_balance | `PATCH` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| ImpactBal | `v1.2.3` | modifies the user `{name}`'s balance by `{amount}` if positive itll add, if negative itll subtract | {"name":string,"amount":int64} | api/v1/admin/impact_balance | `POST` | 200 | uint32 | new balance after modification | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
### Meta Usage endpoint errors
| name | 400 | 401 | 404 | 406 |
@ -60,23 +50,15 @@
| SetBal | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| ImpactBal | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
### Meta Usage endpoint support
| name | v1 | v2 |
| :------------------ | :----------------: | :----------------: |
| ChangePassword | :heavy_check_mark: | :heavy_check_mark: |
| AdminChangePassword | :heavy_check_mark: | :heavy_check_mark: |
| SetBal | :heavy_check_mark: | :heavy_check_mark: |
| ImpactBal | :heavy_check_mark: | :heavy_check_mark: |
### Sytem Usage endpoints
| name | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U |
| :----------------- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- | ----------------------- | :---------: | :------------: | :---------: | :---------------------------------------------------------------------------------------------------------: | :----------------: | :----------------: | :----------------: | :---: |
| Help | redirects to GitHub projects Docs | `N/A` | help | `GET` | 301 | `N/A` | `N/A` | :x: | :x: | :x: | :x: |
| Close | saves & closes the CCash webserver | `N/A` | admin/shutdown | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: |
| Contains | checks wether a user exists | `N/A` | user/exists?name={name} | `GET` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :x: | :x: | :x: |
| AdminVerifyAccount | checks wether a user is the admin | `N/A` | admin/verify_account | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: |
| PruneUsers | deletes users with most recent transactions older then `{time}` (if logs are enabled) and have less money then `{amount}` | {"time":int64,"amount":uint32} or just {"amount":uint32} | admin/prune_users | `POST` | 200 | uint64 | number of users deleted | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| ApiProperties | properties of the given instance | `N/A` | api/properties | `GET` | 200 | json object | {"version":uint64,"min_version":uint64_t,"max_log":uint64} and "return_on_del":string if feature is enabled | :heavy_check_mark: | :x: | :x: | :x: |
| name | added on | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U |
| :----------------- | :------: | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- | ------------------------------ | :---------: | :------------: | :---------: | :---------------------------------------------------------------------------------------------------------: | :----------------: | :----------------: | :----------------: | :---: |
| Help | `v0.1` | redirects to GitHub projects Docs | `N/A` | api/help | `GET` | 301 | `N/A` | `N/A` | :x: | :x: | :x: | :x: |
| Close | `v1.2.3` | saves & closes the CCash webserver | `N/A` | api/v1/admin/shutdown | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: |
| Contains | `v1.2.3` | checks wether a user exists | `N/A` | api/v1/user/exists?name={name} | `GET` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :x: | :x: | :x: |
| AdminVerifyAccount | `v1.2.3` | checks wether a user is the admin | `N/A` | api/v1/admin/verify_account | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: |
| PruneUsers | `v1.2.3` | deletes users with most recent transactions older then `{time}` (if logs are enabled) and have less money then `{amount}` | {"time":int64,"amount":uint32} or just {"amount":uint32} | api/v1/admin/prune_users | `POST` | 200 | uint64 | number of users deleted | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| ApiProperties | `v1.2.3` | properties of the given instance | `N/A` | api/properties | `GET` | 200 | json object | {"version":uint64,"min_version":uint64_t,"max_log":uint64} and "return_on_del":string if feature is enabled | :heavy_check_mark: | :x: | :x: | :x: |
### System Usage endpoin errors
| name | 401 | 404 | 406 |
@ -88,16 +70,6 @@
| PruneUsers | :heavy_check_mark: | :x: | :heavy_check_mark: |
| ApiProperties | :x: | :x: | :x: |
### System Usage endpoint support
| name | v1 | v2 |
| :----------------- | :----------------: | :----------------: |
| Help | `N/A` | `N/A` |
| Close | :heavy_check_mark: | :heavy_check_mark: |
| Contains | :heavy_check_mark: | :heavy_check_mark: |
| AdminVerifyAccount | :heavy_check_mark: | :heavy_check_mark: |
| PruneUsers | :heavy_check_mark: | :heavy_check_mark: |
| ApiProperties | `N/A` | `N/A` |
### Username Requirements
Valid
* lowercase letters
@ -106,12 +78,12 @@ Valid
* Length must be atleast 3 and at most 16 characters.
### User Management endpoints
| name | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U |
| :----------- | --------------------------------------- | --------------------------------------------- | ------------------- | :---------: | :------------: | :---------: | :----------: | :----------------: | :----------------: | :----------------: | :----------------: |
| AddUser | adding a user with a balance of 0 | {"name":string,"pass":string} | user/register | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
| AdminAddUser | adding a user with an arbitrary balance | {"name":string,"amount":uint32,"pass":string} | admin/user/register | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| DelSelf | deletes a user | `N/A` | user/delete | `DELETE` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: |
| AdminDelUser | deletes a given user `{name}` | {"name":string} | admin/user/delete | `DELETE` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| name | added on | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U |
| :----------- | :------: | --------------------------------------- | --------------------------------------------- | -------------------------- | :---------: | :------------: | :---------: | :----------: | :----------------: | :----------------: | :----------------: | :----------------: |
| AddUser | `v1.2.3` | adding a user with a balance of 0 | {"name":string,"pass":string} | api/v1/user/register | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
| AdminAddUser | `v1.2.3` | adding a user with an arbitrary balance | {"name":string,"amount":uint32,"pass":string} | api/v1/admin/user/register | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| DelSelf | `v1.2.3` | deletes a user | `N/A` | api/v1/user/delete | `DELETE` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: |
| AdminDelUser | `v1.2.3` | deletes a given user `{name}` | {"name":string} | api/v1/admin/user/delete | `DELETE` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
### User Management endpoint errors
| name | 400 | 401 | 404 | 406 | 409 |
@ -120,11 +92,3 @@ Valid
| AdminAddUser | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: |
| DelSelf | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: |
| AdminDelUser | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
### User Management endpoint support
| name | v1 | v2 |
| :----------- | :----------------: | :----------------: |
| AddUser | :heavy_check_mark: | :heavy_check_mark: |
| AdminAddUser | :heavy_check_mark: | :heavy_check_mark: |
| DelSelf | :heavy_check_mark: | :heavy_check_mark: |
| AdminDelUser | :heavy_check_mark: | :heavy_check_mark: |

View file

@ -45,13 +45,10 @@ public:
static BankResponse GetBal(const std::string &name) noexcept;
#if MAX_LOG_SIZE > 0
#if MIN_API_SUPPORT == 1
#if USE_DEPRECATED_ENDPOINTS
static BankResponse GetLogs(const std::string &name) noexcept;
#endif
#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2)
static BankResponse GetLogsV2(const std::string &name) noexcept;
#endif
#endif
static BankResponse SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount) noexcept;

View file

@ -12,10 +12,10 @@ class api : public HttpController<api>
{
public:
static void GetBal(req_args, const std::string &name);
#if USE_DEPRECATED_ENDPOINTS
static void GetLogs(req_args);
#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2)
static void GetLogsV2(req_args);
#endif
static void GetLogsV2(req_args);
static void SendFunds(req_args);
static void VerifyPassword(req_args);
@ -41,13 +41,18 @@ public:
METHOD_ADD(api::Help, "/help", Get, Options);
METHOD_ADD(api::ApiProperties, "/properties", Get, Options);
#if MIN_API_SUPPORT == 1
//Usage
METHOD_ADD(api::GetBal, "/v1/user/balance?name={name}", Get, Options, "JsonFilter<false>");
#if MAX_LOG_SIZE > 0
#if USE_DEPRECATED_ENDPOINTS
METHOD_ADD(api::GetLogs, "/v1/user/log", Get, Options, "JsonFilter<false>", "UserFilter<true, false>");
#endif
METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter<false>", "UserFilter<true, false>");
#else
#if USE_DEPRECATED_ENDPOINTS
METHOD_ADD(api::GetLogs, "/v1/user/log", Get, Options, "JsonFilter<false>");
#endif
METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter<false>");
#endif
METHOD_ADD(api::SendFunds, "/v1/user/transfer", Post, Options, "JsonFilter<true>", "UserFilter<true, false>"); //expects ["name"](string) and ["amount"](uint32)
METHOD_ADD(api::VerifyPassword, "/v1/user/verify_password", Post, Options, "UserFilter<false, false>", "JsonFilter<false>");
@ -69,37 +74,6 @@ public:
METHOD_ADD(api::AdminAddUser, "/v1/admin/user/register", Post, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) ["amount"](uint32) ["pass"](string)
METHOD_ADD(api::DelSelf, "/v1/user/delete", Delete, Options, "UserFilter<true, false>", "JsonFilter<false>");
METHOD_ADD(api::AdminDelUser, "/v1/admin/user/delete", Delete, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string)
#endif
#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2)
//Usage
METHOD_ADD(api::GetBal, "/v2/user/balance?name={name}", Get, Options, "JsonFilter<false>");
#if MAX_LOG_SIZE > 0
METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter<false>", "UserFilter<true, false>");
#else
METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter<false>");
#endif
METHOD_ADD(api::SendFunds, "/v2/user/transfer", Post, Options, "JsonFilter<true>", "UserFilter<true, false>"); //expects ["name"](string) and ["amount"](uint32)
METHOD_ADD(api::VerifyPassword, "/v2/user/verify_password", Post, Options, "UserFilter<false, false>", "JsonFilter<false>");
//Meta Usage
METHOD_ADD(api::ChangePassword, "/v2/user/change_password", Patch, Options, "JsonFilter<true>", "UserFilter<true, false>"); //expects ["pass"](string)
METHOD_ADD(api::AdminChangePassword, "/v2/admin/user/change_password", Patch, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) and ["pass"](string)
METHOD_ADD(api::SetBal, "/v2/admin/set_balance", Patch, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) and ["amount"](uint32)
METHOD_ADD(api::ImpactBal, "/v2/admin/impact_balance", Post, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) and ["amount"](uint32)
//System Usage
METHOD_ADD(api::Close, "/v2/admin/shutdown", Post, Options, "UserFilter<false, true>", "JsonFilter<false>");
METHOD_ADD(api::Contains, "/v2/user/exists?name={name}", Get, Options, "JsonFilter<false>");
METHOD_ADD(api::AdminVerifyAccount, "/v2/admin/verify_account", Post, Options, "UserFilter<false, true>", "JsonFilter<false>");
METHOD_ADD(api::PruneUsers, "/v2/admin/prune_users", Post, "UserFilter<false, true>", "JsonFilter<true>"); //expects ["time"](int64) and ["amount"](uint32)
//User Managment
METHOD_ADD(api::AddUser, "/v2/user/register", Post, Options); //expects ["name"](string) ["pass"](string)
METHOD_ADD(api::AdminAddUser, "/v2/admin/user/register", Post, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) ["amount"](uint32) ["pass"](string)
METHOD_ADD(api::DelSelf, "/v2/user/delete", Delete, Options, "UserFilter<true, false>", "JsonFilter<false>");
METHOD_ADD(api::AdminDelUser, "/v2/admin/user/delete", Delete, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string)
#endif
METHOD_LIST_END
};

View file

@ -11,25 +11,20 @@ struct Log
{
private:
#if MIN_API_SUPPORT == 1
#if USE_DEPRECATED_ENDPOINTS
ChangeFlag<true> log_flag;
std::string log_snapshot = "null";
#endif
#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2)
ChangeFlag<true> log_flag_v2;
std::string log_snapshot_v2 = "null";
#endif
public:
std::deque<Transaction> data;
#if MIN_API_SUPPORT == 1
#if USE_DEPRECATED_ENDPOINTS
std::string GetLogs(const std::string& name) noexcept;
#endif
#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2)
std::string GetLogsV2() noexcept;
#endif
void AddTrans(const std::string &counterparty_str, bool receiving, uint32_t amount, time_t time) noexcept;
};

View file

@ -34,7 +34,7 @@ int main(int argc, char **argv)
uint8_t temp[16]{16, 0, 0, 0, 4};
users_save.write((char *)temp, 16);
users_save.close();
std::cout << "User save file generated\nUsage: sudo ./bank <admin account name> <saving frequency in minutes> [daemon flag]\n";
std::cout << "User save file generated\nUsage: sudo ./bank <admin account name> <saving frequency in minutes> [daemon flag {default: false}]\n";
}
else
{
@ -44,7 +44,7 @@ int main(int argc, char **argv)
}
if (argc < 3)
{
std::cerr << "Usage: sudo ./bank <admin account> <saving frequency in minutes> [daemon flag]\n";
std::cerr << "Usage: sudo ./bank <admin account> <saving frequency in minutes> [daemon flag {default: false}]\n";
return 0;
}
if (geteuid() != 0)
@ -54,7 +54,6 @@ int main(int argc, char **argv)
}
const unsigned long saving_freq = std::stoul(std::string(argv[2]));
std::cout
<< "\nAPI Version : " << API_VERSION
<< "\n\nAVX : " << (__builtin_cpu_supports("avx") ? "enabled" : "disabled")
<< "\nAVX 2 : " << (__builtin_cpu_supports("avx2") ? "enabled" : "disabled")
<< "\nSSE 2 : " << (__builtin_cpu_supports("sse2") ? "enabled" : "disabled")

View file

@ -85,9 +85,10 @@ BankResponse Bank::GetBal(const std::string &name) noexcept
return {k200OK, std::to_string(res)};
}
}
#if MAX_LOG_SIZE > 0
#if MIN_API_SUPPORT == 1
#if USE_DEPRECATED_ENDPOINTS
BankResponse Bank::GetLogs(const std::string &name) noexcept
{
BankResponse res;
@ -102,7 +103,6 @@ BankResponse Bank::GetLogs(const std::string &name) noexcept
}
#endif
#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2)
BankResponse Bank::GetLogsV2(const std::string &name) noexcept
{
BankResponse res;
@ -115,7 +115,6 @@ BankResponse Bank::GetLogsV2(const std::string &name) noexcept
return res;
}
}
#endif
#endif
@ -241,6 +240,7 @@ BankResponse Bank::PruneUsers(uint32_t threshold_bal) noexcept
#else
if (Bank::users.erase_if(u.first, [threshold_time, threshold_bal, &deleted_count](User &u) {
#endif
return ((!u.log.data.size() || u.log.data.back().time < threshold_time) && u.balance < threshold_bal);
#else
@ -250,8 +250,8 @@ BankResponse Bank::PruneUsers(uint32_t threshold_bal) noexcept
#else
if (Bank::users.erase_if(u.first, [threshold_bal, &deleted_count](User &u) {
#endif
return (u.balance < threshold_bal);
return (u.balance < threshold_bal);
#endif
}))
{

View file

@ -28,7 +28,7 @@ void api::GetBal(req_args, const std::string &name)
RESPONSE_PARSE(Bank::GetBal(name));
}
#if MIN_API_SUPPORT == 1
#if USE_DEPRECATED_ENDPOINTS
void api::GetLogs(req_args)
{
#if MAX_LOG_SIZE > 0
@ -42,7 +42,6 @@ void api::GetLogs(req_args)
}
#endif
#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2)
void api::GetLogsV2(req_args)
{
#if MAX_LOG_SIZE > 0
@ -54,7 +53,6 @@ void api::GetLogsV2(req_args)
callback(resp);
#endif
}
#endif
void api::SendFunds(req_args)
{
@ -220,7 +218,7 @@ void api::AdminVerifyAccount(req_args)
}
void api::ApiProperties(req_args)
{
std::string info = "{\"version\":" + std::to_string(API_VERSION) + ",\"min_version\":" + std::to_string(MIN_API_SUPPORT) + ",\"max_log\":" + std::to_string(MAX_LOG_SIZE) + ",\"add_user_open\":" + std::to_string(ADD_USER_OPEN);
std::string info = "{\"max_log\":" + std::to_string(MAX_LOG_SIZE) + ",\"add_user_open\":" + std::to_string(ADD_USER_OPEN);
if constexpr (RETURN_ON_DEL)
{
info += ",\"return_on_del\":\"" + std::string(return_account) + "\"}";

View file

@ -2,14 +2,10 @@
void Log::AddTrans(const std::string &counterparty_str, bool receiving, uint32_t amount, time_t time) noexcept
{
#if MIN_API_SUPPORT == 1
#if USE_DEPRECATED_ENDPOINTS
log_flag.SetChangesOn();
#endif
#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2)
log_flag_v2.SetChangesOn();
#endif
if (data.size() == MAX_LOG_SIZE)
{
@ -18,7 +14,7 @@ void Log::AddTrans(const std::string &counterparty_str, bool receiving, uint32_t
data.emplace_back(counterparty_str, receiving, amount, time);
}
#if MIN_API_SUPPORT == 1
#if USE_DEPRECATED_ENDPOINTS
std::string Log::GetLogs(const std::string& name) noexcept
{
if (log_flag.GetChangeState() && data.size()) //if there are changes
@ -51,7 +47,6 @@ std::string Log::GetLogs(const std::string& name) noexcept
}
#endif
#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2)
std::string Log::GetLogsV2() noexcept
{
if (log_flag_v2.GetChangeState() && data.size()) //if there are changes
@ -68,9 +63,9 @@ 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 += "\",\"receiving\":"; //15
log_snapshot_v2 += std::to_string(data[i].receiving); //4
log_snapshot_v2 += ",\"amount\":"; //11
log_snapshot_v2 += ",\"amount\":"; //11
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?
@ -82,4 +77,3 @@ std::string Log::GetLogsV2() noexcept
return log_snapshot_v2;
}
#endif