From 1f983322a1fcff00944ce34bd1ef643836190761 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 16:39:32 -0800 Subject: [PATCH 01/73] :sparkles: updated fbe for new transaction struct --- fbe/user_model/bank_dom.cpp | 22 ++++++----- fbe/user_model/bank_dom.h | 42 ++++++++++---------- fbe/user_model/bank_dom_final_models.cpp | 36 +++++++++-------- fbe/user_model/bank_dom_final_models.h | 8 ++-- fbe/user_model/bank_dom_models.cpp | 50 ++++++++++++------------ fbe/user_model/bank_dom_models.h | 8 ++-- fbe/user_model/fbe.cpp | 16 +++++++- fbe/user_model/fbe.h | 37 +++++++++++++----- fbe/user_model/fbe_final_models.cpp | 4 +- fbe/user_model/fbe_final_models.h | 4 +- fbe/user_model/fbe_final_models.inl | 12 +++--- fbe/user_model/fbe_models.cpp | 4 +- fbe/user_model/fbe_models.h | 4 +- fbe/user_model/fbe_models.inl | 12 +++--- 14 files changed, 157 insertions(+), 102 deletions(-) diff --git a/fbe/user_model/bank_dom.cpp b/fbe/user_model/bank_dom.cpp index d4e60c0..2b5541a 100644 --- a/fbe/user_model/bank_dom.cpp +++ b/fbe/user_model/bank_dom.cpp @@ -1,22 +1,24 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: user_model.fbe -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ #include "bank_dom.h" namespace bank_dom { Transaction::Transaction() - : from("") - , to("") + : counterparty("") + , receiving(false) , amount((uint32_t)0ull) , time((uint64_t)0ull) {} -Transaction::Transaction(const std::string& arg_from, const std::string& arg_to, uint32_t arg_amount, uint64_t arg_time) - : from(arg_from) - , to(arg_to) +Transaction::Transaction(const std::string& arg_counterparty, bool arg_receiving, uint32_t arg_amount, uint64_t arg_time) + : counterparty(arg_counterparty) + , receiving(arg_receiving) , amount(arg_amount) , time(arg_time) {} @@ -36,8 +38,8 @@ bool Transaction::operator<(const Transaction& other) const noexcept void Transaction::swap(Transaction& other) noexcept { using std::swap; - swap(from, other.from); - swap(to, other.to); + swap(counterparty, other.counterparty); + swap(receiving, other.receiving); swap(amount, other.amount); swap(time, other.time); } @@ -45,8 +47,8 @@ void Transaction::swap(Transaction& other) noexcept std::ostream& operator<<(std::ostream& stream, const Transaction& value) { stream << "Transaction("; - stream << "from="; stream << "\"" << value.from << "\""; - stream << ",to="; stream << "\"" << value.to << "\""; + stream << "counterparty="; stream << "\"" << value.counterparty << "\""; + stream << ",receiving="; stream << (value.receiving ? "true" : "false"); stream << ",amount="; stream << value.amount; stream << ",time="; stream << value.time; stream << ")"; diff --git a/fbe/user_model/bank_dom.h b/fbe/user_model/bank_dom.h index 04f8375..75014ef 100644 --- a/fbe/user_model/bank_dom.h +++ b/fbe/user_model/bank_dom.h @@ -1,7 +1,9 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: user_model.fbe -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ #pragma once @@ -27,15 +29,15 @@ namespace bank_dom { struct Transaction { - std::string from; - std::string to; + std::string counterparty; + bool receiving; uint32_t amount; uint64_t time; size_t fbe_type() const noexcept { return 1; } Transaction(); - Transaction(const std::string& arg_from, const std::string& arg_to, uint32_t arg_amount, uint64_t arg_time); + Transaction(const std::string& arg_counterparty, bool arg_receiving, uint32_t arg_amount, uint64_t arg_time); Transaction(const Transaction& other) = default; Transaction(Transaction&& other) = default; ~Transaction() = default; @@ -60,10 +62,12 @@ struct Transaction } // namespace bank_dom -namespace std { +#if defined(FMT_VERSION) && (FMT_VERSION >= 90000) +template <> struct fmt::formatter : ostream_formatter {}; +#endif template<> -struct hash +struct std::hash { typedef bank_dom::Transaction argument_type; typedef size_t result_type; @@ -75,8 +79,6 @@ struct hash } }; -} // namespace std - namespace bank_dom { struct Logs @@ -111,10 +113,12 @@ struct Logs } // namespace bank_dom -namespace std { +#if defined(FMT_VERSION) && (FMT_VERSION >= 90000) +template <> struct fmt::formatter : ostream_formatter {}; +#endif template<> -struct hash +struct std::hash { typedef bank_dom::Logs argument_type; typedef size_t result_type; @@ -126,8 +130,6 @@ struct hash } }; -} // namespace std - namespace bank_dom { struct User @@ -164,10 +166,12 @@ struct User } // namespace bank_dom -namespace std { +#if defined(FMT_VERSION) && (FMT_VERSION >= 90000) +template <> struct fmt::formatter : ostream_formatter {}; +#endif template<> -struct hash +struct std::hash { typedef bank_dom::User argument_type; typedef size_t result_type; @@ -179,8 +183,6 @@ struct hash } }; -} // namespace std - namespace bank_dom { struct Global @@ -216,10 +218,12 @@ struct Global } // namespace bank_dom -namespace std { +#if defined(FMT_VERSION) && (FMT_VERSION >= 90000) +template <> struct fmt::formatter : ostream_formatter {}; +#endif template<> -struct hash +struct std::hash { typedef bank_dom::Global argument_type; typedef size_t result_type; @@ -231,8 +235,6 @@ struct hash } }; -} // namespace std - namespace bank_dom { } // namespace bank_dom diff --git a/fbe/user_model/bank_dom_final_models.cpp b/fbe/user_model/bank_dom_final_models.cpp index cc15906..41ac0bb 100644 --- a/fbe/user_model/bank_dom_final_models.cpp +++ b/fbe/user_model/bank_dom_final_models.cpp @@ -1,15 +1,17 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: user_model.fbe -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ #include "bank_dom_final_models.h" namespace FBE { FinalModel<::bank_dom::Transaction>::FinalModel(FBEBuffer& buffer, size_t offset) noexcept : _buffer(buffer), _offset(offset) - , from(buffer, 0) - , to(buffer, 0) + , counterparty(buffer, 0) + , receiving(buffer, 0) , amount(buffer, 0) , time(buffer, 0) {} @@ -17,8 +19,8 @@ FinalModel<::bank_dom::Transaction>::FinalModel(FBEBuffer& buffer, size_t offset size_t FinalModel<::bank_dom::Transaction>::fbe_allocation_size(const ::bank_dom::Transaction& fbe_value) const noexcept { size_t fbe_result = 0 - + from.fbe_allocation_size(fbe_value.from) - + to.fbe_allocation_size(fbe_value.to) + + counterparty.fbe_allocation_size(fbe_value.counterparty) + + receiving.fbe_allocation_size(fbe_value.receiving) + amount.fbe_allocation_size(fbe_value.amount) + time.fbe_allocation_size(fbe_value.time) ; @@ -38,14 +40,14 @@ size_t FinalModel<::bank_dom::Transaction>::verify_fields() const noexcept size_t fbe_current_offset = 0; size_t fbe_field_size; - from.fbe_offset(fbe_current_offset); - fbe_field_size = from.verify(); + counterparty.fbe_offset(fbe_current_offset); + fbe_field_size = counterparty.verify(); if (fbe_field_size == std::numeric_limits::max()) return std::numeric_limits::max(); fbe_current_offset += fbe_field_size; - to.fbe_offset(fbe_current_offset); - fbe_field_size = to.verify(); + receiving.fbe_offset(fbe_current_offset); + fbe_field_size = receiving.verify(); if (fbe_field_size == std::numeric_limits::max()) return std::numeric_limits::max(); fbe_current_offset += fbe_field_size; @@ -79,13 +81,13 @@ size_t FinalModel<::bank_dom::Transaction>::get_fields(::bank_dom::Transaction& size_t fbe_current_size = 0; size_t fbe_field_size; - from.fbe_offset(fbe_current_offset); - fbe_field_size = from.get(fbe_value.from); + counterparty.fbe_offset(fbe_current_offset); + fbe_field_size = counterparty.get(fbe_value.counterparty); fbe_current_offset += fbe_field_size; fbe_current_size += fbe_field_size; - to.fbe_offset(fbe_current_offset); - fbe_field_size = to.get(fbe_value.to); + receiving.fbe_offset(fbe_current_offset); + fbe_field_size = receiving.get(fbe_value.receiving); fbe_current_offset += fbe_field_size; fbe_current_size += fbe_field_size; @@ -116,13 +118,13 @@ size_t FinalModel<::bank_dom::Transaction>::set_fields(const ::bank_dom::Transac size_t fbe_current_size = 0; size_t fbe_field_size; - from.fbe_offset(fbe_current_offset); - fbe_field_size = from.set(fbe_value.from); + counterparty.fbe_offset(fbe_current_offset); + fbe_field_size = counterparty.set(fbe_value.counterparty); fbe_current_offset += fbe_field_size; fbe_current_size += fbe_field_size; - to.fbe_offset(fbe_current_offset); - fbe_field_size = to.set(fbe_value.to); + receiving.fbe_offset(fbe_current_offset); + fbe_field_size = receiving.set(fbe_value.receiving); fbe_current_offset += fbe_field_size; fbe_current_size += fbe_field_size; diff --git a/fbe/user_model/bank_dom_final_models.h b/fbe/user_model/bank_dom_final_models.h index 335df6f..089d0f1 100644 --- a/fbe/user_model/bank_dom_final_models.h +++ b/fbe/user_model/bank_dom_final_models.h @@ -1,7 +1,9 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: user_model.fbe -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ #pragma once @@ -60,8 +62,8 @@ private: mutable size_t _offset; public: - FinalModel from; - FinalModel to; + FinalModel counterparty; + FinalModel receiving; FinalModel amount; FinalModel time; }; diff --git a/fbe/user_model/bank_dom_models.cpp b/fbe/user_model/bank_dom_models.cpp index 9d18299..c62f767 100644 --- a/fbe/user_model/bank_dom_models.cpp +++ b/fbe/user_model/bank_dom_models.cpp @@ -1,24 +1,26 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: user_model.fbe -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ #include "bank_dom_models.h" namespace FBE { FieldModel<::bank_dom::Transaction>::FieldModel(FBEBuffer& buffer, size_t offset) noexcept : _buffer(buffer), _offset(offset) - , from(buffer, 4 + 4) - , to(buffer, from.fbe_offset() + from.fbe_size()) - , amount(buffer, to.fbe_offset() + to.fbe_size()) + , counterparty(buffer, 4 + 4) + , receiving(buffer, counterparty.fbe_offset() + counterparty.fbe_size()) + , amount(buffer, receiving.fbe_offset() + receiving.fbe_size()) , time(buffer, amount.fbe_offset() + amount.fbe_size()) {} size_t FieldModel<::bank_dom::Transaction>::fbe_body() const noexcept { size_t fbe_result = 4 + 4 - + from.fbe_size() - + to.fbe_size() + + counterparty.fbe_size() + + receiving.fbe_size() + amount.fbe_size() + time.fbe_size() ; @@ -37,8 +39,8 @@ size_t FieldModel<::bank_dom::Transaction>::fbe_extra() const noexcept _buffer.shift(fbe_struct_offset); size_t fbe_result = fbe_body() - + from.fbe_extra() - + to.fbe_extra() + + counterparty.fbe_extra() + + receiving.fbe_extra() + amount.fbe_extra() + time.fbe_extra() ; @@ -75,17 +77,17 @@ bool FieldModel<::bank_dom::Transaction>::verify_fields(size_t fbe_struct_size) { size_t fbe_current_size = 4 + 4; - if ((fbe_current_size + from.fbe_size()) > fbe_struct_size) + if ((fbe_current_size + counterparty.fbe_size()) > fbe_struct_size) return true; - if (!from.verify()) + if (!counterparty.verify()) return false; - fbe_current_size += from.fbe_size(); + fbe_current_size += counterparty.fbe_size(); - if ((fbe_current_size + to.fbe_size()) > fbe_struct_size) + if ((fbe_current_size + receiving.fbe_size()) > fbe_struct_size) return true; - if (!to.verify()) + if (!receiving.verify()) return false; - fbe_current_size += to.fbe_size(); + fbe_current_size += receiving.fbe_size(); if ((fbe_current_size + amount.fbe_size()) > fbe_struct_size) return true; @@ -141,17 +143,17 @@ void FieldModel<::bank_dom::Transaction>::get_fields(::bank_dom::Transaction& fb { size_t fbe_current_size = 4 + 4; - if ((fbe_current_size + from.fbe_size()) <= fbe_struct_size) - from.get(fbe_value.from, ""); + if ((fbe_current_size + counterparty.fbe_size()) <= fbe_struct_size) + counterparty.get(fbe_value.counterparty, ""); else - fbe_value.from = ""; - fbe_current_size += from.fbe_size(); + fbe_value.counterparty = ""; + fbe_current_size += counterparty.fbe_size(); - if ((fbe_current_size + to.fbe_size()) <= fbe_struct_size) - to.get(fbe_value.to, ""); + if ((fbe_current_size + receiving.fbe_size()) <= fbe_struct_size) + receiving.get(fbe_value.receiving, false); else - fbe_value.to = ""; - fbe_current_size += to.fbe_size(); + fbe_value.receiving = false; + fbe_current_size += receiving.fbe_size(); if ((fbe_current_size + amount.fbe_size()) <= fbe_struct_size) amount.get(fbe_value.amount, (uint32_t)0ull); @@ -203,8 +205,8 @@ void FieldModel<::bank_dom::Transaction>::set(const ::bank_dom::Transaction& fbe void FieldModel<::bank_dom::Transaction>::set_fields(const ::bank_dom::Transaction& fbe_value) noexcept { - from.set(fbe_value.from); - to.set(fbe_value.to); + counterparty.set(fbe_value.counterparty); + receiving.set(fbe_value.receiving); amount.set(fbe_value.amount); time.set(fbe_value.time); } diff --git a/fbe/user_model/bank_dom_models.h b/fbe/user_model/bank_dom_models.h index 311a1a1..c98f52b 100644 --- a/fbe/user_model/bank_dom_models.h +++ b/fbe/user_model/bank_dom_models.h @@ -1,7 +1,9 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: user_model.fbe -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ #pragma once @@ -72,8 +74,8 @@ private: size_t _offset; public: - FieldModel from; - FieldModel to; + FieldModel counterparty; + FieldModel receiving; FieldModel amount; FieldModel time; }; diff --git a/fbe/user_model/fbe.cpp b/fbe/user_model/fbe.cpp index 59d516a..c11db02 100644 --- a/fbe/user_model/fbe.cpp +++ b/fbe/user_model/fbe.cpp @@ -1,10 +1,24 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: FBE -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ #include "fbe.h" +#if defined(_WIN32) || defined(_WIN64) +#include +#include +#undef DELETE +#undef ERROR +#undef HOST_NOT_FOUND +#undef Yield +#undef min +#undef max +#undef uuid_t +#endif + namespace FBE { std::string buffer_t::base64encode() const diff --git a/fbe/user_model/fbe.h b/fbe/user_model/fbe.h index b6d11be..46384d3 100644 --- a/fbe/user_model/fbe.h +++ b/fbe/user_model/fbe.h @@ -1,7 +1,9 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: FBE -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ #pragma once @@ -41,7 +43,6 @@ #include #undef HOST_NOT_FOUND #elif defined(_WIN32) || defined(_WIN64) -#include #undef DELETE #undef ERROR #undef HOST_NOT_FOUND @@ -321,10 +322,20 @@ private: } // namespace FBE -namespace std { +#if defined(FMT_VERSION) && (FMT_VERSION >= 90000) +template <> +struct fmt::formatter : formatter +{ + template + auto format(const FBE::decimal_t& value, FormatContext& ctx) const + { + return formatter::format((double)value, ctx); + } +}; +#endif template <> -struct hash +struct std::hash { typedef FBE::decimal_t argument_type; typedef size_t result_type; @@ -337,8 +348,6 @@ struct hash } }; -} // namespace std - namespace FBE { // Register a new enum-based flags macro @@ -530,10 +539,20 @@ private: } // namespace FBE -namespace std { +#if defined(FMT_VERSION) && (FMT_VERSION >= 90000) +template <> +struct fmt::formatter : formatter +{ + template + auto format(const FBE::uuid_t& value, FormatContext& ctx) const + { + return formatter::format(value.string(), ctx); + } +}; +#endif template <> -struct hash +struct std::hash { typedef FBE::uuid_t argument_type; typedef size_t result_type; @@ -548,8 +567,6 @@ struct hash } }; -} // namespace std - namespace FBE { // Fast Binary Encoding buffer based on the dynamic byte buffer diff --git a/fbe/user_model/fbe_final_models.cpp b/fbe/user_model/fbe_final_models.cpp index 27902f8..3e90925 100644 --- a/fbe/user_model/fbe_final_models.cpp +++ b/fbe/user_model/fbe_final_models.cpp @@ -1,7 +1,9 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: FBE -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ #include "fbe_final_models.h" diff --git a/fbe/user_model/fbe_final_models.h b/fbe/user_model/fbe_final_models.h index f032be0..4c0457f 100644 --- a/fbe/user_model/fbe_final_models.h +++ b/fbe/user_model/fbe_final_models.h @@ -1,7 +1,9 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: FBE -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ #pragma once diff --git a/fbe/user_model/fbe_final_models.inl b/fbe/user_model/fbe_final_models.inl index d3035a8..0ef2274 100644 --- a/fbe/user_model/fbe_final_models.inl +++ b/fbe/user_model/fbe_final_models.inl @@ -1,7 +1,9 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: FBE -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ namespace FBE { @@ -536,8 +538,8 @@ inline size_t FinalModelMap::get(std::map& values) c FinalModel fbe_model_value(_buffer, fbe_offset() + 4); for (size_t i = fbe_map_size; i-- > 0;) { - TKey key; - TValue value; + TKey key = TKey(); + TValue value = TValue(); size_t offset_key = fbe_model_key.get(key); fbe_model_key.fbe_shift(offset_key); fbe_model_value.fbe_shift(offset_key); @@ -568,8 +570,8 @@ inline size_t FinalModelMap::get(std::unordered_map& FinalModel fbe_model_value(_buffer, fbe_offset() + 4); for (size_t i = fbe_map_size; i-- > 0;) { - TKey key; - TValue value; + TKey key = TKey(); + TValue value = TValue(); size_t offset_key = fbe_model_key.get(key); fbe_model_key.fbe_shift(offset_key); fbe_model_value.fbe_shift(offset_key); diff --git a/fbe/user_model/fbe_models.cpp b/fbe/user_model/fbe_models.cpp index dd4ecb9..949f484 100644 --- a/fbe/user_model/fbe_models.cpp +++ b/fbe/user_model/fbe_models.cpp @@ -1,7 +1,9 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: FBE -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ #include "fbe_models.h" diff --git a/fbe/user_model/fbe_models.h b/fbe/user_model/fbe_models.h index 9326a5d..968f789 100644 --- a/fbe/user_model/fbe_models.h +++ b/fbe/user_model/fbe_models.h @@ -1,7 +1,9 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: FBE -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ #pragma once diff --git a/fbe/user_model/fbe_models.inl b/fbe/user_model/fbe_models.inl index 1ddba97..d3b671e 100644 --- a/fbe/user_model/fbe_models.inl +++ b/fbe/user_model/fbe_models.inl @@ -1,7 +1,9 @@ +//------------------------------------------------------------------------------ // Automatically generated by the Fast Binary Encoding compiler, do not modify! // https://github.com/chronoxor/FastBinaryEncoding // Source: FBE -// Version: 1.7.0.0 +// FBE version: 1.14.1.0 +//------------------------------------------------------------------------------ namespace FBE { @@ -618,8 +620,8 @@ inline void FieldModelMap::get(std::map& values) con auto fbe_model = (*this)[0]; for (size_t i = fbe_map_size; i-- > 0;) { - TKey key; - TValue value; + TKey key = TKey(); + TValue value = TValue(); fbe_model.first.get(key); fbe_model.second.get(value); values.emplace(key, value); @@ -640,8 +642,8 @@ inline void FieldModelMap::get(std::unordered_map& v auto fbe_model = (*this)[0]; for (size_t i = fbe_map_size; i-- > 0;) { - TKey key; - TValue value; + TKey key = TKey(); + TValue value = TValue(); fbe_model.first.get(key); fbe_model.second.get(value); values.emplace(key, value); From 47d544070b9c729492a937d8f3dd8e4c3e21f1e3 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 16:40:07 -0800 Subject: [PATCH 02/73] :bulb: comment error and API_VERSION incremented --- ccash_config.hpp.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ccash_config.hpp.in b/ccash_config.hpp.in index 3c6cfca..9e58e4d 100644 --- a/ccash_config.hpp.in +++ b/ccash_config.hpp.in @@ -3,7 +3,7 @@ // Setting to 0 does not compile logging (useful for if disk/memory is very valuable) #define MAX_LOG_SIZE @MAX_LOG_SIZE_VAL@ -//default to minecraft usernames +// Default to minecraft usernames constexpr unsigned min_name_size = 3; constexpr unsigned max_name_size = 16; @@ -29,13 +29,13 @@ if false, when frequency is hit save #define CONSERVATIVE_DISK_SAVE @CONSERVATIVE_DISK_SAVE_VAL@ /* -example, when set to 2 -version 1 will not work +e.g when set to 2 +version 1 will work version 2 will work -version 3 will work +version 3 will not work etc */ -#define API_VERSION 1 +#define API_VERSION 2 #define MULTI_THREADED @MULTI_THREADED_VAL@ From 7387156d15fb3aaaed9fe54f2141c3669915d032 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 16:41:08 -0800 Subject: [PATCH 03/73] :fire: unessasary macro --- include/bank_api.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/bank_api.h b/include/bank_api.h index 82b28dd..aa2bf55 100644 --- a/include/bank_api.h +++ b/include/bank_api.h @@ -37,7 +37,6 @@ public: METHOD_LIST_BEGIN -#if API_VERSION >= 1 //Usage METHOD_ADD(api::GetBal, "/v1/user/balance?name={name}", Get, Options, "JsonFilter"); #if MAX_LOG_SIZE > 0 @@ -67,7 +66,6 @@ public: METHOD_ADD(api::AdminAddUser, "/v1/admin/user/register", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) ["amount"](uint32) ["pass"](string) METHOD_ADD(api::DelSelf, "/v1/user/delete", Delete, Options, "UserFilter", "JsonFilter"); METHOD_ADD(api::AdminDelUser, "/v1/admin/user/delete", Delete, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) -#endif METHOD_LIST_END }; \ No newline at end of file From ab27971d8edcb3d19698d60e5468fb7d7145ec64 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 16:41:27 -0800 Subject: [PATCH 04/73] :bulb: comment clarification --- include/bank.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/bank.h b/include/bank.h index 28e0a65..d3556de 100644 --- a/include/bank.h +++ b/include/bank.h @@ -31,8 +31,8 @@ private: static ChangeFlag save_flag; #endif - //must grab as shared if the operation is gonna modify "users"'s size or can be caught in a intermediary state such as SendFunds() - //must grab as unique if the operation is gonna user iterators + // must grab as shared if the operation is gonna modify "users"'s size or can be caught in a intermediary state such as SendFunds() + // must grab as unique if the operation is gonna use user iterators static std::shared_mutex iter_lock; public: From b584f5b4d516e566bdb84331c72a7b65d1672477 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 17:06:13 -0800 Subject: [PATCH 05/73] :sparkles: improved Transaction structure --- fbe/user_model.fbe | 4 +-- include/bank.h | 3 +++ include/bank_api.h | 11 ++++++-- include/log.h | 10 ++++++-- include/transaction.h | 14 ++++++++-- src/bank.cpp | 20 ++++++++++++--- src/bank_api.cpp | 16 +++++++++--- src/log.cpp | 59 +++++++++++++++++++++++++++++++++---------- src/transaction.cpp | 2 +- src/user.cpp | 4 +-- 10 files changed, 110 insertions(+), 33 deletions(-) diff --git a/fbe/user_model.fbe b/fbe/user_model.fbe index 59a5c00..374d322 100644 --- a/fbe/user_model.fbe +++ b/fbe/user_model.fbe @@ -2,8 +2,8 @@ package bank_dom struct Transaction { - string from = ""; - string to = ""; + string counterparty = ""; + bool receiving = false; uint32 amount = 0; timestamp time; } diff --git a/include/bank.h b/include/bank.h index d3556de..85f23d0 100644 --- a/include/bank.h +++ b/include/bank.h @@ -45,6 +45,9 @@ public: static BankResponse GetBal(const std::string &name) noexcept; #if MAX_LOG_SIZE > 0 static BankResponse GetLogs(const std::string &name) noexcept; +#if API_VERSION >= 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; static bool VerifyPassword(const std::string &name, const std::string_view &attempt) noexcept; diff --git a/include/bank_api.h b/include/bank_api.h index aa2bf55..cf631f5 100644 --- a/include/bank_api.h +++ b/include/bank_api.h @@ -11,9 +11,11 @@ using namespace drogon; class api : public HttpController { public: -#if API_VERSION >= 1 static void GetBal(req_args, const std::string &name); static void GetLogs(req_args); +#if API_VERSION >= 2 + static void GetLogsV2(req_args); +#endif static void SendFunds(req_args); static void VerifyPassword(req_args); @@ -33,7 +35,6 @@ public: static void AdminAddUser(req_args); static void DelSelf(req_args); static void AdminDelUser(req_args); -#endif METHOD_LIST_BEGIN @@ -41,8 +42,14 @@ public: METHOD_ADD(api::GetBal, "/v1/user/balance?name={name}", Get, Options, "JsonFilter"); #if MAX_LOG_SIZE > 0 METHOD_ADD(api::GetLogs, "/v1/user/log", Get, Options, "JsonFilter", "UserFilter"); +#if API_VERSION >= 2 + METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter", "UserFilter"); +#endif #else METHOD_ADD(api::GetLogs, "/v1/user/log", Get, Options, "JsonFilter"); +#if API_VERSION >= 2 + METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter"); +#endif #endif METHOD_ADD(api::SendFunds, "/v1/user/transfer", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) METHOD_ADD(api::VerifyPassword, "/v1/user/verify_password", Post, Options, "UserFilter", "JsonFilter"); diff --git a/include/log.h b/include/log.h index 11f828e..31a5936 100644 --- a/include/log.h +++ b/include/log.h @@ -12,10 +12,16 @@ struct Log private: ChangeFlag log_flag; std::string log_snapshot = "null"; +#if API_VERSION >= 2 + std::string log_snapshot_v2 = "null"; +#endif public: std::deque data; - std::string GetLogs() noexcept; - void AddTrans(const std::string &from, const std::string &to, uint32_t amount, time_t time) noexcept; + std::string GetLogs(const std::string& name) noexcept; +#if API_VERSION >= 2 + std::string GetLogsV2() noexcept; +#endif + void AddTrans(const std::string &counterparty_str, bool receiving, uint32_t amount, time_t time) noexcept; }; diff --git a/include/transaction.h b/include/transaction.h index c4c5805..0bb43ce 100644 --- a/include/transaction.h +++ b/include/transaction.h @@ -5,10 +5,20 @@ struct Transaction { - std::string from = "", to = ""; + std::string counterparty = ""; + bool receiving = false; uint32_t amount = 0; time_t time = 0; Transaction() noexcept; - Transaction(const std::string &from_str, const std::string &to_str, uint32_t amount, time_t time) noexcept; + Transaction(const std::string &counterparty_str, bool receiving, uint32_t amount, time_t time) noexcept; }; + +/* +TODO: v1 vs v2 functionality +TODO: FBE + +TODO: v2/api +TODO: update stats on run (203 bytes) +TODO: update Docs +*/ \ No newline at end of file diff --git a/src/bank.cpp b/src/bank.cpp index 2fac56a..1089806 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -89,7 +89,19 @@ BankResponse Bank::GetBal(const std::string &name) noexcept BankResponse Bank::GetLogs(const std::string &name) noexcept { BankResponse res; - if (!Bank::users.modify_if(name, [&res](User &u) { res = {k200OK, u.log.GetLogs()}; })) + if (!Bank::users.modify_if(name, [&name, &res](User &u) { res = {k200OK, u.log.GetLogs(name)}; })) + { + return {k404NotFound, "\"User not found\""}; + } + else + { + return res; + } +} +BankResponse Bank::GetLogsV2(const std::string &name) noexcept +{ + BankResponse res; + if (!Bank::users.modify_if(name, [&name, &res](User &u) { res = {k200OK, u.log.GetLogsV2()}; })) { return {k404NotFound, "\"User not found\""}; } @@ -123,7 +135,7 @@ BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_nam if (!Bank::users.modify_if(a_name, [&a_name, &b_name, &res, amount](User &a) #endif { - //if A can afford it + //if "A" can afford it if (a.balance < amount) { res = {k400BadRequest, "\"Insufficient funds\""}; @@ -132,7 +144,7 @@ BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_nam { a.balance -= amount; #if MAX_LOG_SIZE > 0 - a.log.AddTrans(a_name, b_name, amount, current_time); + a.log.AddTrans(b_name, false, amount, current_time); #endif res = {k200OK, std::to_string(a.balance)}; } @@ -145,7 +157,7 @@ BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_nam #if MAX_LOG_SIZE > 0 Bank::users.modify_if(b_name, [current_time, &a_name, &b_name, amount](User &b) { b.balance += amount; - b.log.AddTrans(a_name, b_name, amount, current_time); + b.log.AddTrans(a_name, true, amount, current_time); }); #else Bank::users.modify_if(b_name, [amount](User &b) { b.balance += amount; }); diff --git a/src/bank_api.cpp b/src/bank_api.cpp index 24e7c99..60ac43b 100644 --- a/src/bank_api.cpp +++ b/src/bank_api.cpp @@ -6,7 +6,7 @@ #define CORS resp->addHeader("Access-Control-Allow-Origin", "*") -static thread_local ondemand::parser parser; +thread_local ondemand::parser parser; #define SIMD_JSON_GEN \ simdjson::padded_string input(req->getBody()); \ ondemand::document doc; @@ -24,8 +24,6 @@ static thread_local ondemand::parser parser; #define NAME_PARAM req->getParameter("name") -#if API_VERSION >= 1 - //Usage void api::GetBal(req_args, const std::string &name) { @@ -42,6 +40,17 @@ void api::GetLogs(req_args) callback(resp); #endif } +void api::GetLogsV2(req_args) +{ +#if MAX_LOG_SIZE > 0 + RESPONSE_PARSE(Bank::GetLogsV2(NAME_PARAM)); +#else + auto resp = HttpResponse::newCustomHttpResponse(BankResponse{k404NotFound, "\"Logs are Disabled\""}); + CORS; + CACHE_FOREVER; + callback(resp); +#endif +} void api::SendFunds(req_args) { SIMD_JSON_GEN; @@ -344,4 +353,3 @@ void api::AdminDelUser(req_args) } RESPONSE_PARSE(std::move(res)); } -#endif diff --git a/src/log.cpp b/src/log.cpp index ec2e8b6..35f4fb7 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -1,22 +1,22 @@ #include "log.h" -void Log::AddTrans(const std::string &from, const std::string &to, uint32_t amount, time_t time) noexcept +void Log::AddTrans(const std::string &counterparty_str, bool receiving, uint32_t amount, time_t time) noexcept { log_flag.SetChangesOn(); if (data.size() == MAX_LOG_SIZE) { data.pop_back(); } - data.emplace_back(from, to, amount, time); + data.emplace_back(counterparty_str, receiving, amount, time); } -std::string Log::GetLogs() noexcept +std::string Log::GetLogs(const std::string& name) noexcept { if (log_flag.GetChangeState() && data.size()) //if there are changes { log_snapshot.resize(0); //re-generate snapshot - size_t predicted_size = ((59 + (2 * max_name_size)) * data.size()) + 1; + size_t predicted_size = ((57 + (2 * max_name_size)) * data.size()) + 1; if (log_snapshot.capacity() < predicted_size) { log_snapshot.reserve(predicted_size); @@ -24,18 +24,49 @@ std::string Log::GetLogs() noexcept log_snapshot = '['; //1 for (size_t i = 0; i < data.size(); ++i) { - log_snapshot += "{\"to\":\""; //8 - log_snapshot += data[i].to; //max_name_size? - log_snapshot += "\",\"from\":\""; //10 - log_snapshot += data[i].from; //max_name_size? - log_snapshot += "\",\"amount\":"; //12 - log_snapshot += std::to_string(data[i].amount); //10? - log_snapshot += ",\"time\":"; //8 - log_snapshot += std::to_string(data[i].time); //10? - log_snapshot += "},"; //2 + log_snapshot += "{\"to\":\""; //7 + log_snapshot += data[i].receiving? name : data[i].counterparty; //max_name_size? + log_snapshot += "\",\"from\":\""; //10 + log_snapshot += data[i].receiving? data[i].counterparty : name; //max_name_size? + log_snapshot += "\",\"amount\":"; //11 + log_snapshot += std::to_string(data[i].amount); //10? + log_snapshot += ",\"time\":"; //8 + log_snapshot += std::to_string(data[i].time); //10? + log_snapshot += "},"; //2 } log_snapshot.back() = ']'; log_flag.SetChangesOff(); } + return log_snapshot; -} \ No newline at end of file +} +std::string Log::GetLogsV2() noexcept +{ + if (log_flag.GetChangeState() && data.size()) //if there are changes + { + log_snapshot_v2.resize(0); + //re-generate snapshot + size_t predicted_size = ((77 + max_name_size) * data.size()) + 1; + if (log_snapshot_v2.capacity() < predicted_size) + { + log_snapshot_v2.reserve(predicted_size); + } + log_snapshot_v2 = '['; //1 + for (size_t i = 0; i < data.size(); ++i) + { + log_snapshot += "{\"counterparty\":\""; //17 + log_snapshot += data[i].counterparty; //max_name_size? + log_snapshot += "\",\"receiving\":\""; //15 + log_snapshot += std::to_string(data[i].receiving); //4 + log_snapshot += "\",\"amount\":"; //11 + log_snapshot += std::to_string(data[i].amount); //10? + log_snapshot += ",\"time\":"; //8 + log_snapshot += std::to_string(data[i].time); //10? + log_snapshot += "},"; //2 + } + log_snapshot_v2.back() = ']'; + log_flag.SetChangesOff(); + } + + return log_snapshot_v2; +} diff --git a/src/transaction.cpp b/src/transaction.cpp index c0c1456..afd5d0e 100644 --- a/src/transaction.cpp +++ b/src/transaction.cpp @@ -1,4 +1,4 @@ #include "transaction.h" Transaction::Transaction() noexcept {}; -Transaction::Transaction(const std::string &from_str, const std::string &to_str, uint32_t amount, time_t time_val) noexcept : from(from_str), to(to_str), amount(amount), time(time_val) {} +Transaction::Transaction(const std::string &counterparty_str, bool receiving, uint32_t amount, time_t time) noexcept : counterparty(counterparty_str), receiving(receiving), amount(amount), time(time) {} diff --git a/src/user.cpp b/src/user.cpp index 074c13b..b5e1f82 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -29,7 +29,7 @@ User::User(const bank_dom::User &u) noexcept : balance(u.balance), password(u.pa for (; i < u.logs.value().data.size(); ++i) { const bank_dom::Transaction &temp = u.logs.value().data[i]; - log.data.emplace_front(temp.from, temp.to, temp.amount, temp.time); + log.data.emplace_front(temp.counterparty, temp.receiving, temp.amount, temp.time); } } #endif @@ -43,7 +43,7 @@ bank_dom::User User::Encode() const noexcept save_log.data.reserve(this->log.data.size()); for (const Transaction &t : this->log.data) { - save_log.data.emplace_back(t.from, t.to, t.amount, t.time); + save_log.data.emplace_back(t.counterparty, t.receiving, t.amount, t.time); } return bank_dom::User(balance, password, save_log); } From cf4ba5ccfabd964e1f331330b5ce23c7167fd55e Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 17:14:41 -0800 Subject: [PATCH 06/73] api_version related changes --- src/bank.cpp | 2 ++ src/bank_api.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/bank.cpp b/src/bank.cpp index 1089806..f4ee554 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -98,6 +98,7 @@ BankResponse Bank::GetLogs(const std::string &name) noexcept return res; } } +#if API_VERSION >= 2 BankResponse Bank::GetLogsV2(const std::string &name) noexcept { BankResponse res; @@ -111,6 +112,7 @@ BankResponse Bank::GetLogsV2(const std::string &name) noexcept } } #endif +#endif BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount) noexcept { if (!amount) diff --git a/src/bank_api.cpp b/src/bank_api.cpp index 60ac43b..1da47a3 100644 --- a/src/bank_api.cpp +++ b/src/bank_api.cpp @@ -40,6 +40,7 @@ void api::GetLogs(req_args) callback(resp); #endif } +#if API_VERSION >= 2 void api::GetLogsV2(req_args) { #if MAX_LOG_SIZE > 0 @@ -51,6 +52,7 @@ void api::GetLogsV2(req_args) callback(resp); #endif } +#endif void api::SendFunds(req_args) { SIMD_JSON_GEN; From 4fd3eb2bd82949cc3d3c757b2de225ffb2b15c2d Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 17:34:52 -0800 Subject: [PATCH 07/73] :memo: updated stats on log size in memory/disk --- docs/building.md | 2 +- docs/connected_services/existing_services.md | 3 ++- docs/features/user_side.md | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/building.md b/docs/building.md index b9248c3..f374124 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 ~203 bytes in memory and ~104 bytes in disk at default settings, so 5165 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 ~157 bytes in memory and ~43 bytes in disk at default settings, so 6678 logs per Mb of RAM. Setting to 0 will disable logs * with no users memory usage is 8.47 Mb * Saving frequency (a runtime argument) 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 c9d2b07..51ae364 100644 --- a/docs/connected_services/existing_services.md +++ b/docs/connected_services/existing_services.md @@ -21,4 +21,5 @@ | Market | a platform to buy and sell items. | | Anonymous Payments | a service that allows for sending of funds annoymously, by first sending them to an intermediate account that is receiving and sending from many wallets as to obfuscate the fund's origin. | | Gambling | physical or digital casino. | -| Shipping | the infastructure to quickly send items across long distances. | \ No newline at end of file +| Shipping | the infastructure to quickly send items across long distances. | +| Mod | a server-side mod | \ No newline at end of file diff --git a/docs/features/user_side.md b/docs/features/user_side.md index 1a1513d..009fb81 100644 --- a/docs/features/user_side.md +++ b/docs/features/user_side.md @@ -8,7 +8,7 @@ Capable of processing thousands of requests per second, with no slow down as use #### Lightweight -Low memory usage at 8 Mb baseline, and 203 bytes per new log. +Low memory usage at 8 Mb baseline, and 157 bytes per new log. Anecdotally I typically expierenced <1% CPU usage. From e100444042580f545538f3a1e086bdbfa483b00c Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 17:35:22 -0800 Subject: [PATCH 08/73] :fire: temporary comment --- include/transaction.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/include/transaction.h b/include/transaction.h index 0bb43ce..e7c1bc1 100644 --- a/include/transaction.h +++ b/include/transaction.h @@ -13,12 +13,3 @@ struct Transaction Transaction() noexcept; Transaction(const std::string &counterparty_str, bool receiving, uint32_t amount, time_t time) noexcept; }; - -/* -TODO: v1 vs v2 functionality -TODO: FBE - -TODO: v2/api -TODO: update stats on run (203 bytes) -TODO: update Docs -*/ \ No newline at end of file From 49816dc18cb8427d51e1ecdb8f2514527b9e6d1a Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 17:35:36 -0800 Subject: [PATCH 09/73] updated at launch stats --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 270f319..8f6c499 100644 --- a/main.cpp +++ b/main.cpp @@ -73,7 +73,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 * (91 + 80 + (max_name_size * 2))) / 1048576 << "Mb" //91:string representation(heap), sizeof(Transaction), max_name_size*2:filled to&from(heap) + << "\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 " << Bank::SumBal() << " C$H" << std::endl; //flushing before EventLoop From a068502643f2a501e8f5bba6fa5c710b9ee56ca9 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 17:41:38 -0800 Subject: [PATCH 10/73] :memo: updated endpoint logs for new GetLogV2 --- docs/connected_services/how_to/endpoints.md | 27 ++++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index eb9c9a8..0f28af9 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -16,29 +16,32 @@ ## all error responses have JSON string along with them to describe ### 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` | api/v1/user/balance?name={name} | `GET` | 200 | uint32 | the user's balance | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | -| GetLog | 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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | -| SendFunds | 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: | :heavy_multiplication_x: | :heavy_check_mark: | -| VerifyPassword | 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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | +| 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` | api/v1/user/balance?name={name} | `GET` | 200 | uint32 | the user's balance | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | +| GetLog | 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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | +| GetLogV2 | 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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | +| SendFunds | 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: | :heavy_multiplication_x: | :heavy_check_mark: | +| VerifyPassword | 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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | ### Usage enpoint errors | name | 400 | 401 | 404 | 406 | | :------------- | :----------------------: | :----------------------: | :----------------------: | :----------------: | | GetBal | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_check_mark: | | GetLog | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | +| GetLogV2 | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | SendFunds | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | VerifyPassword | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | ### Usage endpoint support `v` denoting the API version -| name | v1 | -| :------------- | :----------------: | -| GetBal | :heavy_check_mark: | -| GetLog | :heavy_check_mark: | -| SendFunds | :heavy_check_mark: | -| VerifyPassword | :heavy_check_mark: | +| name | v1 | v2 | +| :------------- | :-----------------------: | :----------------------: | +| GetBal | :heavy_check_mark: | :heavy_multiplication_x: | +| GetLog | :heavy_check_mark: | :heavy_multiplication_x: | +| GetLogV2 | ::heavy_multiplication_x: | :heavy_multiplication_x: | +| SendFunds | :heavy_check_mark: | :heavy_multiplication_x: | +| VerifyPassword | :heavy_check_mark: | :heavy_multiplication_x: | ### Meta Usage endpoints | name | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U | From ecb602d6f2d3e5a79122e69c7bf1439b20a7077e Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 17:43:43 -0800 Subject: [PATCH 11/73] :memo: --- docs/connected_services/how_to/endpoints.md | 50 ++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index 0f28af9..d3aabe9 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -35,13 +35,13 @@ ### Usage endpoint support `v` denoting the API version -| name | v1 | v2 | -| :------------- | :-----------------------: | :----------------------: | -| GetBal | :heavy_check_mark: | :heavy_multiplication_x: | -| GetLog | :heavy_check_mark: | :heavy_multiplication_x: | -| GetLogV2 | ::heavy_multiplication_x: | :heavy_multiplication_x: | -| SendFunds | :heavy_check_mark: | :heavy_multiplication_x: | -| VerifyPassword | :heavy_check_mark: | :heavy_multiplication_x: | +| name | v1 | v2 | +| :------------- | :----------------------: | :----------------: | +| GetBal | :heavy_check_mark: | :heavy_check_mark: | +| GetLog | :heavy_check_mark: | :heavy_check_mark: | +| GetLogV2 | :heavy_multiplication_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 | @@ -60,12 +60,12 @@ | ImpactBal | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | ### Meta Usage endpoint support -| name | v1 | -| :------------------ | :----------------: | -| ChangePassword | :heavy_check_mark: | -| AdminChangePassword | :heavy_check_mark: | -| SetBal | :heavy_check_mark: | -| ImpactBal | :heavy_check_mark: | +| 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 | @@ -88,12 +88,12 @@ | ApiProperties | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | ### System Usage endpoint support -| name | v1 | -| :----------------- | :----------------: | -| Help | :heavy_check_mark: | -| Close | :heavy_check_mark: | -| Contains | :heavy_check_mark: | -| AdminVerifyAccount | :heavy_check_mark: | +| name | v1 | v2 | +| :----------------- | :----------------: | :----------------: | +| Help | :heavy_check_mark: | :heavy_check_mark: | +| Close | :heavy_check_mark: | :heavy_check_mark: | +| Contains | :heavy_check_mark: | :heavy_check_mark: | +| AdminVerifyAccount | :heavy_check_mark: | :heavy_check_mark: | ### Username Requirements Valid @@ -119,9 +119,9 @@ Valid | AdminDelUser | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: | ### User Management endpoint support -| name | v1 | -| :----------- | :----------------: | -| AddUser | :heavy_check_mark: | -| AdminAddUser | :heavy_check_mark: | -| DelSelf | :heavy_check_mark: | -| AdminDelUser | :heavy_check_mark: | +| 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: | From d2f0989a15221fdbddb2bcd64789367ef0fb3b18 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 17:45:31 -0800 Subject: [PATCH 12/73] :memo: noting that existing apis dont support v2 --- docs/connected_services/how_to/APIs.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 65d189d..80de04b 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -1,11 +1,11 @@ [PREVIOUS PAGE](explanation.md) | [NEXT PAGE](endpoints.md) -| author | language | | v1 | -| :-------------------------------------------------------- | :------: | ------------------------------------------------------------------------- | :----------------------: | -| [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | :heavy_check_mark: | -| [Luke](https://github.com/LukeeeeBennett/ccash-client-js) | JS | [ccash client js](https://github.com/LukeeeeBennett/ccash-client-js) | :heavy_multiplication_x: | -| [Doggo](https://github.com/FearlessDoggo21) | Python | [CCashPythonClient](https://github.com/FearlessDoggo21/CCashPythonClient) | :heavy_check_mark: | -| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | :heavy_check_mark: | +| author | language | | v1 | v2 | +| :-------------------------------------------------------- | :------: | ------------------------------------------------------------------------- | :----------------------: | :----------------------: | +| [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | :heavy_check_mark: | :heavy_multiplication_x: | +| [Luke](https://github.com/LukeeeeBennett/ccash-client-js) | JS | [ccash client js](https://github.com/LukeeeeBennett/ccash-client-js) | :heavy_multiplication_x: | :heavy_multiplication_x: | +| [Doggo](https://github.com/FearlessDoggo21) | Python | [CCashPythonClient](https://github.com/FearlessDoggo21/CCashPythonClient) | :heavy_check_mark: | :heavy_multiplication_x: | +| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | :heavy_check_mark: | :heavy_multiplication_x: | for example here is a demo program for the lua API by SpaceCat From 52677f0576cb6053559ee96290635811b8e881cc Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 18:02:14 -0800 Subject: [PATCH 13/73] API_VERSION settable from cmake --- CMakeLists.txt | 8 ++++++++ ccash_config.hpp.in | 2 +- docs/building.md | 20 ++++++++++---------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ba9430..188e7ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,14 @@ set(RETURN_ON_DEL_VAL false) set(RETURN_ON_DEL_NAME_VAL "\"\"") endif() +if(DEFINED API_VERSION) +set(RETURN_ON_DEL_VAL true) +set(RETURN_ON_DEL_NAME_VAL API_VERSION) +else() +set(RETURN_ON_DEL_VAL false) +set(RETURN_ON_DEL_NAME_VAL 2) +endif() + configure_file(ccash_config.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/ccash_config.hpp) target_include_directories(${PROJECT_NAME} PUBLIC include) diff --git a/ccash_config.hpp.in b/ccash_config.hpp.in index 9e58e4d..99a9967 100644 --- a/ccash_config.hpp.in +++ b/ccash_config.hpp.in @@ -35,7 +35,7 @@ version 2 will work version 3 will not work etc */ -#define API_VERSION 2 +#define API_VERSION @API_VERSION@ #define MULTI_THREADED @MULTI_THREADED_VAL@ diff --git a/docs/building.md b/docs/building.md index f374124..c8d2c66 100644 --- a/docs/building.md +++ b/docs/building.md @@ -66,16 +66,16 @@ cd build ### CMake Flags there are multiple flags responsible configuring CCash: -| name | default | description | pros | cons | -| :--------------------- | :-----------: | ------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | -------------------------------------------------------- | -| USER_SAVE_LOC | "users.dat" | where the users are saved | `N/A` | `N/A` | -| DROGON_CONFIG_LOC | "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 | - +| 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 | api versions are backwards compatible, e.g if set to 2, v1 and v2 api endpoints will be compiled, but v3 would not. By default `API_VERSION` is set to the newest version | `N/A` | `N/A` | EXAMPLE: ``` From d46fe685599da17804fdefea02edbf6134a1daf1 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 18:12:00 -0800 Subject: [PATCH 14/73] :memo: --- docs/FAQ.md | 10 ++++++---- docs/building.md | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index ae023b1..83088e6 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -4,6 +4,7 @@ #### A : You can with [build docs](https://github.com/EntireTwix/CCash/blob/main/docs/building.md) you can build from source or use the Docker package. + #### Q : Why is my username invalid #### A : Usernames are restricted by minecraft's requirements * lowercase letters @@ -12,30 +13,31 @@ * Length must be atleast 3 and at most 16 characters. + #### Q : Is this a crypto like krist? #### A : CCash isn't a crypto, the economy you decide to implement is entirely up to you. + #### Q : Why isnt this on a database? #### A : Because this usecase requires none of the features a database would offer. + #### Q : People are making too many accounts maliciously to fill up space on my server! #### A : Consider disabling `ADD_USER_OPEN` in the [build proccess](https://github.com/EntireTwix/CCash/blob/main/docs/building.md). -#### Q : People are making too many transactions filling up space on my server! -#### A : Consider setting the variable `MAX_LOG_SIZE` to 0 in the [build proccess](https://github.com/EntireTwix/CCash/blob/main/docs/building.md). - #### Q : My instance is taking up too much RAM #### A : Reduce log size. + #### Q : My instance is taking up too much disk spac #### A : Use the prune users endpoint to dead accounts or you can reduce log size but should be a last resort. + #### Q : My instance is slow #### A : Toggling off logs will increase performance. On some devices multi threading increases performance, on others the overhead isn't worth the benefit. - diff --git a/docs/building.md b/docs/building.md index c8d2c66..aae4dfa 100644 --- a/docs/building.md +++ b/docs/building.md @@ -10,7 +10,7 @@ as CCash is very lightweight it can run on practically any device but here are s * Saving frequency (a runtime argument) being set to 0 will disable frequency saving and only save on close * make backups of your save files -## Docker +## Docker & Ansible If you want to use the docker package, deploy information can be found [here](deploy.md) ## Drogon Depedencies From 4892ec265563d07389a64eaebcb884020e1fb805 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 18:13:00 -0800 Subject: [PATCH 15/73] :memo: --- docs/FAQ.md | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 83088e6..85041cb 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -1,43 +1,36 @@ [PREVIOUS PAGE](building.md) -#### Q : How do I setup a CCash instance -#### A : You can with [build docs](https://github.com/EntireTwix/CCash/blob/main/docs/building.md) you can build from source or use the Docker package. +Q : How do I setup a CCash instance +A : You can with [build docs](https://github.com/EntireTwix/CCash/blob/main/docs/building.md) you can build from source or use the Docker package. - -#### Q : Why is my username invalid -#### A : Usernames are restricted by minecraft's requirements +Q : Why is my username invalid +A : Usernames are restricted by minecraft's requirements * lowercase letters * numbers * _ * Length must be atleast 3 and at most 16 characters. - -#### Q : Is this a crypto like krist? -#### A : CCash isn't a crypto, the economy you decide to implement is entirely up to you. +Q : Is this a crypto like krist? +A : CCash isn't a crypto, the economy you decide to implement is entirely up to you. - -#### Q : Why isnt this on a database? -#### A : Because this usecase requires none of the features a database would offer. +Q : Why isnt this on a database? +A : Because this usecase requires none of the features a database would offer. - -#### Q : People are making too many accounts maliciously to fill up space on my server! -#### A : Consider disabling `ADD_USER_OPEN` in the [build proccess](https://github.com/EntireTwix/CCash/blob/main/docs/building.md). +Q : People are making too many accounts maliciously to fill up space on my server! +A : Consider disabling `ADD_USER_OPEN` in the [build proccess](https://github.com/EntireTwix/CCash/blob/main/docs/building.md). - -#### Q : My instance is taking up too much RAM -#### A : Reduce log size. +Q : My instance is taking up too much RAM +A : Reduce log size. - -#### Q : My instance is taking up too much disk spac -#### A : Use the prune users endpoint to dead accounts or you can reduce log size but should be a last resort. +Q : My instance is taking up too much disk spac +A : Use the prune users endpoint to dead accounts or you can reduce log size but should be a last resort. - -#### Q : My instance is slow -#### A : Toggling off logs will increase performance. On some devices multi threading increases performance, on others the overhead isn't worth the benefit. +Q : My instance is slow +A : Toggling off logs will increase performance. On some devices multi threading increases performance, on others the overhead isn't worth the benefit. From 35c50ac0f418731ad94d8588f494c13c6c73e6ae Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 18:20:21 -0800 Subject: [PATCH 16/73] :memo: --- docs/FAQ.md | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 85041cb..2931861 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -1,36 +1,22 @@ [PREVIOUS PAGE](building.md) -Q : How do I setup a CCash instance -A : You can with [build docs](https://github.com/EntireTwix/CCash/blob/main/docs/building.md) you can build from source or use the Docker package. - - -Q : Why is my username invalid -A : Usernames are restricted by minecraft's requirements +### How do I setup a CCash instance +You can with [build docs](https://github.com/EntireTwix/CCash/blob/main/docs/building.md) you can build from source or use the Docker package. +### Why is my username invalid +Usernames are restricted by minecraft's requirements * lowercase letters * numbers * _ * Length must be atleast 3 and at most 16 characters. - - -Q : Is this a crypto like krist? -A : CCash isn't a crypto, the economy you decide to implement is entirely up to you. - - -Q : Why isnt this on a database? -A : Because this usecase requires none of the features a database would offer. - - -Q : People are making too many accounts maliciously to fill up space on my server! -A : Consider disabling `ADD_USER_OPEN` in the [build proccess](https://github.com/EntireTwix/CCash/blob/main/docs/building.md). - - -Q : My instance is taking up too much RAM -A : Reduce log size. - - -Q : My instance is taking up too much disk spac -A : Use the prune users endpoint to dead accounts or you can reduce log size but should be a last resort. - - -Q : My instance is slow -A : Toggling off logs will increase performance. On some devices multi threading increases performance, on others the overhead isn't worth the benefit. +### Is this crypto like krist? +CCash isn't a crypto, simply a ledger keeping track of who owns what. +### Why isnt this on a database? +Because this usecase requires none of the features a database would offer. +### People are making too many accounts maliciously to fill up space on my server! +Consider disabling `ADD_USER_OPEN` in the [build proccess](https://github.com/EntireTwix/CCash/blob/main/docs/building.md). +### My instance is taking up too much RAM +Reduce log size. +### My instance is taking up too much disk spac +Use the prune users endpoint to dead accounts or you can reduce log size but should be a last resort. +### My instance is slow +Toggling off logs will increase performance. On some devices multi threading increases performance, on others the overhead isn't worth the benefit. From 73a80de08eb477d3cb5f3eb4256e9eed7118f46a Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 28 Nov 2022 18:37:38 -0800 Subject: [PATCH 17/73] :bug: broken cmake --- CMakeLists.txt | 6 ++---- ccash_config.hpp.in | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 188e7ef..bbff596 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,11 +82,9 @@ set(RETURN_ON_DEL_NAME_VAL "\"\"") endif() if(DEFINED API_VERSION) -set(RETURN_ON_DEL_VAL true) -set(RETURN_ON_DEL_NAME_VAL API_VERSION) +set(API_VERSION_VAL API_VERSION) else() -set(RETURN_ON_DEL_VAL false) -set(RETURN_ON_DEL_NAME_VAL 2) +set(API_VERSION_VAL 2) endif() configure_file(ccash_config.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/ccash_config.hpp) diff --git a/ccash_config.hpp.in b/ccash_config.hpp.in index 99a9967..0c4d2a6 100644 --- a/ccash_config.hpp.in +++ b/ccash_config.hpp.in @@ -35,7 +35,7 @@ version 2 will work version 3 will not work etc */ -#define API_VERSION @API_VERSION@ +#define API_VERSION @API_VERSION_VAL@ #define MULTI_THREADED @MULTI_THREADED_VAL@ From b874af86af2b6d0c23b950e13698a9d98d418fbb Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Wed, 30 Nov 2022 17:03:34 -0800 Subject: [PATCH 18/73] :bug: messed up `RETURN_ON_DEL_NAME` cmake var --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbff596..9c4e3a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,7 @@ endif() if(DEFINED RETURN_ON_DEL_NAME) set(RETURN_ON_DEL_VAL true) -set(RETURN_ON_DEL_NAME_VAL "\""${RETURN_ON_DEL_NAME}"\"") +set(RETURN_ON_DEL_NAME_VAL "\"${RETURN_ON_DEL_NAME}\"") else() set(RETURN_ON_DEL_VAL false) set(RETURN_ON_DEL_NAME_VAL "\"\"") From 7c31b4d680a6cb1ab55f2c7531bea1dec64fc746 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Wed, 30 Nov 2022 19:08:19 -0800 Subject: [PATCH 19/73] `GetLogsV2` and NumOfUsers output --- benchmarking.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/benchmarking.cpp b/benchmarking.cpp index 347ff69..d380cc7 100644 --- a/benchmarking.cpp +++ b/benchmarking.cpp @@ -65,6 +65,7 @@ int main(int argc, char **argv) { Bank::AddUser(std::to_string(i), 0, "root"); } + std::cout << "added " << Bank::NumOfUsers() << " users\n"; Bank::AddUser("twix", 0, "root"); Bank::AddUser("jolly", 0, "root"); Bank::admin_account = "twix"; @@ -91,6 +92,10 @@ int main(int argc, char **argv) #if MAX_LOG_SIZE > 0 Op(Bank::GetLogs("twix"), "get logs init: ", 1); Op(Bank::GetLogs("twix"), "get logs cached: ", 1000000); +#if API_VERSION >= 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); From 94c2cb1f65413c016f14bdc81b8f48ce057ee916 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Wed, 30 Nov 2022 19:14:22 -0800 Subject: [PATCH 20/73] :bug: used old log_snapshot --- src/log.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/log.cpp b/src/log.cpp index 35f4fb7..2f0f878 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -54,15 +54,15 @@ std::string Log::GetLogsV2() noexcept log_snapshot_v2 = '['; //1 for (size_t i = 0; i < data.size(); ++i) { - log_snapshot += "{\"counterparty\":\""; //17 - log_snapshot += data[i].counterparty; //max_name_size? - log_snapshot += "\",\"receiving\":\""; //15 - log_snapshot += std::to_string(data[i].receiving); //4 - log_snapshot += "\",\"amount\":"; //11 - log_snapshot += std::to_string(data[i].amount); //10? - log_snapshot += ",\"time\":"; //8 - log_snapshot += std::to_string(data[i].time); //10? - log_snapshot += "},"; //2 + log_snapshot_v2 += "{\"counterparty\":\""; //17 + log_snapshot_v2 += data[i].counterparty; //max_name_size? + log_snapshot_v2 += "\",\"receiving\":\""; //15 + log_snapshot_v2 += std::to_string(data[i].receiving); //4 + 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? + log_snapshot_v2 += "},"; //2 } log_snapshot_v2.back() = ']'; log_flag.SetChangesOff(); From f1b03ecb41a1821e20cdf852087c1b8c778b1275 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Wed, 30 Nov 2022 19:17:19 -0800 Subject: [PATCH 21/73] :bug: `GetLogsV2` also needs a log_flag --- src/log.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/log.cpp b/src/log.cpp index 2f0f878..995c11a 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -42,7 +42,7 @@ std::string Log::GetLogs(const std::string& name) noexcept } std::string Log::GetLogsV2() noexcept { - if (log_flag.GetChangeState() && data.size()) //if there are changes + if (log_flag_v2.GetChangeState() && data.size()) //if there are changes { log_snapshot_v2.resize(0); //re-generate snapshot @@ -65,7 +65,7 @@ std::string Log::GetLogsV2() noexcept log_snapshot_v2 += "},"; //2 } log_snapshot_v2.back() = ']'; - log_flag.SetChangesOff(); + log_flag_v2.SetChangesOff(); } return log_snapshot_v2; From 206698697bf758c89cb0c6120725d3cd4e31f516 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Wed, 30 Nov 2022 20:14:11 -0800 Subject: [PATCH 22/73] :bug: forgot usernames must be <3 characters --- benchmarking.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarking.cpp b/benchmarking.cpp index d380cc7..121318d 100644 --- a/benchmarking.cpp +++ b/benchmarking.cpp @@ -61,7 +61,7 @@ using namespace std::chrono; int main(int argc, char **argv) { - for (size_t i = 0; i < 10000; ++i) + for (size_t i = 100; i < 10100; ++i) { Bank::AddUser(std::to_string(i), 0, "root"); } From f6d8673045713bf40b21f67484f7d733297d584a Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Wed, 30 Nov 2022 20:14:25 -0800 Subject: [PATCH 23/73] :bug: `GetLogsV2` also needs a log_flag --- include/log.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/log.h b/include/log.h index 31a5936..c7522fc 100644 --- a/include/log.h +++ b/include/log.h @@ -13,6 +13,7 @@ private: ChangeFlag log_flag; std::string log_snapshot = "null"; #if API_VERSION >= 2 + ChangeFlag log_flag_v2; std::string log_snapshot_v2 = "null"; #endif From a9e3ca1665946586daf792e9bbd01ab37ad6fee1 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Wed, 30 Nov 2022 20:31:08 -0800 Subject: [PATCH 24/73] :memo: backwards compatibility noted --- docs/connected_services/how_to/APIs.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 80de04b..6c303ac 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -1,5 +1,6 @@ [PREVIOUS PAGE](explanation.md) | [NEXT PAGE](endpoints.md) +note: all CCash version's API are backwards compatible, so while an API may not support the newest CCash release it can still call the old endpoints. | author | language | | v1 | v2 | | :-------------------------------------------------------- | :------: | ------------------------------------------------------------------------- | :----------------------: | :----------------------: | | [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | :heavy_check_mark: | :heavy_multiplication_x: | From a68e86b216f87cf8f5e5d078975d9a3733578ade Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Wed, 30 Nov 2022 20:37:31 -0800 Subject: [PATCH 25/73] :memo: --- docs/connected_services/how_to/APIs.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 6c303ac..0377bcc 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -1,7 +1,7 @@ [PREVIOUS PAGE](explanation.md) | [NEXT PAGE](endpoints.md) -note: all CCash version's API are backwards compatible, so while an API may not support the newest CCash release it can still call the old endpoints. -| author | language | | v1 | v2 | +note: all CCash version's API are backwards compatible, so while a language's API may not support the newest CCash release 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: | :heavy_multiplication_x: | | [Luke](https://github.com/LukeeeeBennett/ccash-client-js) | JS | [ccash client js](https://github.com/LukeeeeBennett/ccash-client-js) | :heavy_multiplication_x: | :heavy_multiplication_x: | From 7d4a56451319bde19302708acc2c6001d4934ac9 Mon Sep 17 00:00:00 2001 From: Expand-sys <79956551+Expand-sys@users.noreply.github.com> Date: Sun, 4 Dec 2022 13:05:18 +1100 Subject: [PATCH 26/73] Update deploy.md added ansible docs and changed docker link to use auto built docker image --- docs/deploy.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/deploy.md b/docs/deploy.md index 5b35bbd..0be50bf 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -7,9 +7,22 @@ A pre-built docker image is supplied in the repos [GitHub Packages](https://gith It can be run with docker like so: ``` -docker run -itp 443:443 -v ccashconfig:/ccash/config -e ADMIN_A= -e SAVE_FREQ= expandsys/ccash +docker run -itp 443:443 -v ccashconfig:/ccash/config -e ADMIN_A= -e SAVE_FREQ= ghcr.io/entiretwix/ccash/ccash:latest ``` +## Ansible +Additionally CCash can be deployed to any infrastructure able to run Rocky/Alma Linux 8/9 x86_64 virtual or not, we will be eventually updating it to allow it to run on other OS's but for now RHEL is what works. + +As CCash is intended to be run as root, the playbook is run also as root. The playbook also builds CCash from the latest github push, so there may be bugs. + +In order to use the ansible playbook, clone the playbook to any pc with the ability to access the server through SSH and with Ansible installed, edit the inventory file to contain the IP address of the target server and run the following command: +```ansible-playbook -i inventory main.yml -k``` +When this is complete the server will have ccash installed to the user dir, this is customizable in the vars/default.yml file along with the admin username and save frequency. +To start CCash run: +```systemctl start ccash``` +To run ccash at start up run: +```systemctl enable ccash``` + ## Build Previously this used GitHub Workflows, I(Expand) dont know how to do those but its not that hard to deploy stuff manually. To run the pre configured docker image run the above command and you are off to the races it will deploy a self signed certificate and use that for deployment. As this is not a user facing deployment the certificate is self signed and thus will throw an error on chrome, though this will still work if you ignore it. For production you should deploy with a reverse proxy and a correct certificate for your domain. From 09422995e845e5ad39a7795c216aafdc01ea6330 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sat, 3 Dec 2022 23:45:19 -0800 Subject: [PATCH 27/73] :sparkles: MIN_API_SUPPORT --- CMakeLists.txt | 8 +++++++- benchmarking.cpp | 4 +++- ccash_config.hpp.in | 3 +++ include/bank.h | 8 +++++++- include/bank_api.h | 42 +++++++++++++++++++++++++++++++++++------- include/log.h | 11 +++++++++-- src/bank.cpp | 6 +++++- src/bank_api.cpp | 7 ++++++- src/log.cpp | 5 +++++ 9 files changed, 80 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c4e3a9..6f0aac1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3") find_package(Threads REQUIRED) -add_executable(${PROJECT_NAME} main.cpp ) +add_executable(${PROJECT_NAME} main.cpp) target_sources(${PROJECT_NAME} PRIVATE src/bank_api.cpp @@ -87,6 +87,12 @@ 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) +endif() + configure_file(ccash_config.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/ccash_config.hpp) target_include_directories(${PROJECT_NAME} PUBLIC include) diff --git a/benchmarking.cpp b/benchmarking.cpp index 121318d..bf25208 100644 --- a/benchmarking.cpp +++ b/benchmarking.cpp @@ -90,9 +90,11 @@ 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 Op(Bank::GetLogs("twix"), "get logs init: ", 1); Op(Bank::GetLogs("twix"), "get logs cached: ", 1000000); -#if API_VERSION >= 2 +#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 diff --git a/ccash_config.hpp.in b/ccash_config.hpp.in index 0c4d2a6..daae174 100644 --- a/ccash_config.hpp.in +++ b/ccash_config.hpp.in @@ -37,6 +37,9 @@ etc */ #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@ \ No newline at end of file diff --git a/include/bank.h b/include/bank.h index 85f23d0..f3c5637 100644 --- a/include/bank.h +++ b/include/bank.h @@ -43,12 +43,17 @@ public: static size_t SumBal() noexcept; static BankResponse GetBal(const std::string &name) noexcept; + #if MAX_LOG_SIZE > 0 +#if MIN_API_SUPPORT == 1 static BankResponse GetLogs(const std::string &name) noexcept; -#if API_VERSION >= 2 +#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; static bool VerifyPassword(const std::string &name, const std::string_view &attempt) noexcept; @@ -56,6 +61,7 @@ public: static BankResponse SetBal(const std::string &name, uint32_t amount) noexcept; static BankResponse ImpactBal(const std::string &name, int64_t amount) noexcept; static bool Contains(const std::string &name) noexcept; + #if MAX_LOG_SIZE > 0 static BankResponse PruneUsers(time_t threshold_time, uint32_t threshold_bal) noexcept; #else diff --git a/include/bank_api.h b/include/bank_api.h index cf631f5..cf5b976 100644 --- a/include/bank_api.h +++ b/include/bank_api.h @@ -13,7 +13,7 @@ class api : public HttpController public: static void GetBal(req_args, const std::string &name); static void GetLogs(req_args); -#if API_VERSION >= 2 +#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2) static void GetLogsV2(req_args); #endif static void SendFunds(req_args); @@ -38,18 +38,13 @@ public: METHOD_LIST_BEGIN +#if MIN_API_SUPPORT == 1 //Usage METHOD_ADD(api::GetBal, "/v1/user/balance?name={name}", Get, Options, "JsonFilter"); #if MAX_LOG_SIZE > 0 METHOD_ADD(api::GetLogs, "/v1/user/log", Get, Options, "JsonFilter", "UserFilter"); -#if API_VERSION >= 2 - METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter", "UserFilter"); -#endif #else METHOD_ADD(api::GetLogs, "/v1/user/log", Get, Options, "JsonFilter"); -#if API_VERSION >= 2 - METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter"); -#endif #endif METHOD_ADD(api::SendFunds, "/v1/user/transfer", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) METHOD_ADD(api::VerifyPassword, "/v1/user/verify_password", Post, Options, "UserFilter", "JsonFilter"); @@ -73,6 +68,39 @@ public: METHOD_ADD(api::AdminAddUser, "/v1/admin/user/register", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) ["amount"](uint32) ["pass"](string) METHOD_ADD(api::DelSelf, "/v1/user/delete", Delete, Options, "UserFilter", "JsonFilter"); METHOD_ADD(api::AdminDelUser, "/v1/admin/user/delete", Delete, Options, "JsonFilter", "UserFilter"); //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"); +#if MAX_LOG_SIZE > 0 + METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter", "UserFilter"); +#else + METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter"); +#endif + METHOD_ADD(api::SendFunds, "/v2/user/transfer", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) + METHOD_ADD(api::VerifyPassword, "/v2/user/verify_password", Post, Options, "UserFilter", "JsonFilter"); + + //Meta Usage + METHOD_ADD(api::ChangePassword, "/v2/user/change_password", Patch, Options, "JsonFilter", "UserFilter"); //expects ["pass"](string) + METHOD_ADD(api::AdminChangePassword, "/v2/admin/user/change_password", Patch, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["pass"](string) + METHOD_ADD(api::SetBal, "/v2/admin/set_balance", Patch, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) + METHOD_ADD(api::ImpactBal, "/v2/admin/impact_balance", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) + + //System Usage + METHOD_ADD(api::Help, "/v2/help", Get, Options); + METHOD_ADD(api::Close, "/v2/admin/shutdown", Post, Options, "UserFilter", "JsonFilter"); + METHOD_ADD(api::Contains, "/v2/user/exists?name={name}", Get, Options, "JsonFilter"); + METHOD_ADD(api::AdminVerifyAccount, "/v2/admin/verify_account", Post, Options, "UserFilter", "JsonFilter"); + METHOD_ADD(api::PruneUsers, "/v2/admin/prune_users", Post, "UserFilter", "JsonFilter"); //expects ["time"](int64) and ["amount"](uint32) + METHOD_ADD(api::ApiProperties, "/properties", Get, Options); + + //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", "UserFilter"); //expects ["name"](string) ["amount"](uint32) ["pass"](string) + METHOD_ADD(api::DelSelf, "/v2/user/delete", Delete, Options, "UserFilter", "JsonFilter"); + METHOD_ADD(api::AdminDelUser, "/v2/admin/user/delete", Delete, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) +#endif METHOD_LIST_END }; \ No newline at end of file diff --git a/include/log.h b/include/log.h index c7522fc..fc0ec92 100644 --- a/include/log.h +++ b/include/log.h @@ -10,9 +10,13 @@ using namespace simdjson; struct Log { private: + +#if MIN_API_SUPPORT == 1 ChangeFlag log_flag; std::string log_snapshot = "null"; -#if API_VERSION >= 2 +#endif + +#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2) ChangeFlag log_flag_v2; std::string log_snapshot_v2 = "null"; #endif @@ -20,8 +24,11 @@ private: public: std::deque data; +#if MIN_API_SUPPORT == 1 std::string GetLogs(const std::string& name) noexcept; -#if API_VERSION >= 2 +#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; diff --git a/src/bank.cpp b/src/bank.cpp index f4ee554..a6cbefe 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -86,6 +86,7 @@ BankResponse Bank::GetBal(const std::string &name) noexcept } } #if MAX_LOG_SIZE > 0 +#if MIN_API_SUPPORT == 1 BankResponse Bank::GetLogs(const std::string &name) noexcept { BankResponse res; @@ -98,7 +99,9 @@ BankResponse Bank::GetLogs(const std::string &name) noexcept return res; } } -#if API_VERSION >= 2 +#endif + +#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2) BankResponse Bank::GetLogsV2(const std::string &name) noexcept { BankResponse res; @@ -113,6 +116,7 @@ BankResponse Bank::GetLogsV2(const std::string &name) noexcept } #endif #endif + BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount) noexcept { if (!amount) diff --git a/src/bank_api.cpp b/src/bank_api.cpp index 1da47a3..eec698e 100644 --- a/src/bank_api.cpp +++ b/src/bank_api.cpp @@ -29,6 +29,8 @@ void api::GetBal(req_args, const std::string &name) { RESPONSE_PARSE(Bank::GetBal(name)); } + +#if MIN_API_SUPPORT == 1 void api::GetLogs(req_args) { #if MAX_LOG_SIZE > 0 @@ -40,7 +42,9 @@ void api::GetLogs(req_args) callback(resp); #endif } -#if API_VERSION >= 2 +#endif + +#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2) void api::GetLogsV2(req_args) { #if MAX_LOG_SIZE > 0 @@ -53,6 +57,7 @@ void api::GetLogsV2(req_args) #endif } #endif + void api::SendFunds(req_args) { SIMD_JSON_GEN; diff --git a/src/log.cpp b/src/log.cpp index 995c11a..5d34d0c 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -10,6 +10,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 std::string Log::GetLogs(const std::string& name) noexcept { if (log_flag.GetChangeState() && data.size()) //if there are changes @@ -40,6 +41,9 @@ std::string Log::GetLogs(const std::string& name) noexcept return log_snapshot; } +#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 @@ -70,3 +74,4 @@ std::string Log::GetLogsV2() noexcept return log_snapshot_v2; } +#endif From da65fb678a6b8dc654b2d0cf4906716409ae1f60 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sat, 3 Dec 2022 23:55:20 -0800 Subject: [PATCH 28/73] :memo: MIN_API_SUPPORT --- docs/building.md | 21 +++++++++++---------- docs/connected_services/how_to/endpoints.md | 16 ++++++++-------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/docs/building.md b/docs/building.md index aae4dfa..3628626 100644 --- a/docs/building.md +++ b/docs/building.md @@ -66,16 +66,17 @@ cd build ### CMake Flags 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 | api versions are backwards compatible, e.g if set to 2, v1 and v2 api endpoints will be compiled, but v3 would not. By default `API_VERSION` is set to the newest version | `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 | +| 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` | EXAMPLE: ``` diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index d3aabe9..8dadccf 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -68,14 +68,14 @@ | 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` | api/v1/help | `GET` | 301 | `N/A` | `N/A` | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | -| Close | saves & closes the CCash webserver | `N/A` | api/v1/admin/shutdown | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: | -| Contains | checks wether a user exists | `N/A` | api/v1/user/exists?name={name} | `GET` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | -| AdminVerifyAccount | checks wether a user is the admin | `N/A` | api/v1/admin/verify_account | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_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} | api/v1/admin/prune_users | `POST` | 200 | uint64 | number of users deleted | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: | -| ApiProperties | properties of the given instance | `N/A` | api/properties | `GET` | 200 | json object | {"version":uint64,"max_log":uint64} and "return_on_del":string if feature is enabled | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | +| 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` | api/v1/help | `GET` | 301 | `N/A` | `N/A` | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | +| Close | saves & closes the CCash webserver | `N/A` | api/v1/admin/shutdown | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: | +| Contains | checks wether a user exists | `N/A` | api/v1/user/exists?name={name} | `GET` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | +| AdminVerifyAccount | checks wether a user is the admin | `N/A` | api/v1/admin/verify_account | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_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} | api/v1/admin/prune_users | `POST` | 200 | uint64 | number of users deleted | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | ### System Usage endpoin errors | name | 401 | 404 | 406 | From f9aa33afaca978ad512f6a352b33c5f2beb82afc Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sat, 3 Dec 2022 23:56:07 -0800 Subject: [PATCH 29/73] :sparkles: updated `ApiProperties` --- src/bank_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bank_api.cpp b/src/bank_api.cpp index eec698e..8cdeee6 100644 --- a/src/bank_api.cpp +++ b/src/bank_api.cpp @@ -222,7 +222,7 @@ void api::AdminVerifyAccount(req_args) } void api::ApiProperties(req_args) { - std::string info = "{\"version\":" + std::to_string(API_VERSION) + ",\"max_log\":" + std::to_string(MAX_LOG_SIZE) + ",\"add_user_open\":" + std::to_string(ADD_USER_OPEN); + 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); if constexpr (RETURN_ON_DEL) { info += ",\"return_on_del\":\"" + std::string(return_account) + "\"}"; From 49b5b7d35d7a4e8aa4d0964c598c3c3cd947ae8e Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 4 Dec 2022 00:04:17 -0800 Subject: [PATCH 30/73] :memo: help and properties are version independent --- docs/connected_services/how_to/endpoints.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index 8dadccf..e2fb23d 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -88,12 +88,14 @@ | ApiProperties | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | ### System Usage endpoint support -| name | v1 | v2 | -| :----------------- | :----------------: | :----------------: | -| Help | :heavy_check_mark: | :heavy_check_mark: | -| Close | :heavy_check_mark: | :heavy_check_mark: | -| Contains | :heavy_check_mark: | :heavy_check_mark: | -| AdminVerifyAccount | :heavy_check_mark: | :heavy_check_mark: | +| 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_multiplication_x: | +| ApiProperties | `N/A` | `N/A` | ### Username Requirements Valid From b674a6ddedfcc6b0424b7151274d54b7c9795725 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 4 Dec 2022 00:04:31 -0800 Subject: [PATCH 31/73] :art: help and properties are version independent --- include/bank_api.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/bank_api.h b/include/bank_api.h index cf5b976..864cc28 100644 --- a/include/bank_api.h +++ b/include/bank_api.h @@ -38,6 +38,9 @@ public: METHOD_LIST_BEGIN + 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"); @@ -56,12 +59,10 @@ public: METHOD_ADD(api::ImpactBal, "/v1/admin/impact_balance", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) //System Usage - METHOD_ADD(api::Help, "/v1/help", Get, Options); METHOD_ADD(api::Close, "/v1/admin/shutdown", Post, Options, "UserFilter", "JsonFilter"); METHOD_ADD(api::Contains, "/v1/user/exists?name={name}", Get, Options, "JsonFilter"); METHOD_ADD(api::AdminVerifyAccount, "/v1/admin/verify_account", Post, Options, "UserFilter", "JsonFilter"); METHOD_ADD(api::PruneUsers, "/v1/admin/prune_users", Post, "UserFilter", "JsonFilter"); //expects ["time"](int64) and ["amount"](uint32) - METHOD_ADD(api::ApiProperties, "/properties", Get, Options); //User Managment METHOD_ADD(api::AddUser, "/v1/user/register", Post, Options); //expects ["name"](string) ["pass"](string) @@ -88,12 +89,10 @@ public: METHOD_ADD(api::ImpactBal, "/v2/admin/impact_balance", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) //System Usage - METHOD_ADD(api::Help, "/v2/help", Get, Options); METHOD_ADD(api::Close, "/v2/admin/shutdown", Post, Options, "UserFilter", "JsonFilter"); METHOD_ADD(api::Contains, "/v2/user/exists?name={name}", Get, Options, "JsonFilter"); METHOD_ADD(api::AdminVerifyAccount, "/v2/admin/verify_account", Post, Options, "UserFilter", "JsonFilter"); METHOD_ADD(api::PruneUsers, "/v2/admin/prune_users", Post, "UserFilter", "JsonFilter"); //expects ["time"](int64) and ["amount"](uint32) - METHOD_ADD(api::ApiProperties, "/properties", Get, Options); //User Managment METHOD_ADD(api::AddUser, "/v2/user/register", Post, Options); //expects ["name"](string) ["pass"](string) From 0b7de8b905a668e84c857a64afe609e441c26549 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 4 Dec 2022 00:07:04 -0800 Subject: [PATCH 32/73] :memo: doggo ->ArcNyxx --- docs/connected_services/how_to/APIs.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 0377bcc..3d08c6e 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -1,12 +1,12 @@ [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 release 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: | :heavy_multiplication_x: | -| [Luke](https://github.com/LukeeeeBennett/ccash-client-js) | JS | [ccash client js](https://github.com/LukeeeeBennett/ccash-client-js) | :heavy_multiplication_x: | :heavy_multiplication_x: | -| [Doggo](https://github.com/FearlessDoggo21) | Python | [CCashPythonClient](https://github.com/FearlessDoggo21/CCashPythonClient) | :heavy_check_mark: | :heavy_multiplication_x: | -| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | :heavy_check_mark: | :heavy_multiplication_x: | +| author | language | | v1 endpoints | v2 endpoints | +| :-------------------------------------------------------- | :------: | -------------------------------------------------------------------- | :----------------------: | :----------------------: | +| [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | :heavy_check_mark: | :heavy_multiplication_x: | +| [Luke](https://github.com/LukeeeeBennett/ccash-client-js) | JS | [ccash client js](https://github.com/LukeeeeBennett/ccash-client-js) | :heavy_multiplication_x: | :heavy_multiplication_x: | +| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | :heavy_check_mark: | :heavy_multiplication_x: | +| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | :heavy_check_mark: | :heavy_multiplication_x: | for example here is a demo program for the lua API by SpaceCat From a49a1730f79eff76551f0c30ea9f908c112463cc Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 4 Dec 2022 00:17:11 -0800 Subject: [PATCH 33/73] :bug: fixed MIN_API_SUPPORT commit --- src/log.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/log.cpp b/src/log.cpp index 5d34d0c..9fcfc00 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -2,7 +2,15 @@ void Log::AddTrans(const std::string &counterparty_str, bool receiving, uint32_t amount, time_t time) noexcept { + +#if MIN_API_SUPPORT == 1 log_flag.SetChangesOn(); +#endif + +#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2) + log_flag_v2.SetChangesOn(); +#endif + if (data.size() == MAX_LOG_SIZE) { data.pop_back(); From a308f830c0a4049b9cbab706842e01c0a4f67ee9 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 4 Dec 2022 00:40:04 -0800 Subject: [PATCH 34/73] :memo: --- docs/building.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/building.md b/docs/building.md index 3628626..2e9108c 100644 --- a/docs/building.md +++ b/docs/building.md @@ -5,10 +5,10 @@ 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, so 6678 logs per Mb of RAM. Setting to 0 will disable logs -* with no users memory usage is 8.47 Mb -* Saving frequency (a runtime argument) being set to 0 will disable frequency saving and only save on close -* make backups of your save files +* `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 +* 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! ## Docker & Ansible If you want to use the docker package, deploy information can be found [here](deploy.md) From c8791ec7ce9f046f99d07649e96903ed1dc1340a Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Fri, 9 Dec 2022 04:02:14 -0800 Subject: [PATCH 35/73] :memo: clarified path --- docs/connected_services/how_to/endpoints.md | 56 +++++++++++---------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index e2fb23d..8c0651b 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -15,14 +15,16 @@ ## 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 + ### 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` | api/v1/user/balance?name={name} | `GET` | 200 | uint32 | the user's balance | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | -| GetLog | 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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | -| GetLogV2 | 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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | -| SendFunds | 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: | :heavy_multiplication_x: | :heavy_check_mark: | -| VerifyPassword | 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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | +| 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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | +| GetLogV2 | 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: | :heavy_multiplication_x: | :heavy_multiplication_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: | :heavy_multiplication_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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | ### Usage enpoint errors | name | 400 | 401 | 404 | 406 | @@ -44,12 +46,12 @@ | 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} | api/v1/user/change_password | `PATCH` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | -| AdminChangePassword | 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: | :heavy_multiplication_x: | -| SetBal | 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: | :heavy_multiplication_x: | -| ImpactBal | 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: | :heavy_multiplication_x: | +| 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: | :heavy_multiplication_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: | :heavy_multiplication_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: | :heavy_multiplication_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: | :heavy_multiplication_x: | ### Meta Usage endpoint errors | name | 400 | 401 | 404 | 406 | @@ -68,14 +70,14 @@ | 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` | api/v1/help | `GET` | 301 | `N/A` | `N/A` | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | -| Close | saves & closes the CCash webserver | `N/A` | api/v1/admin/shutdown | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: | -| Contains | checks wether a user exists | `N/A` | api/v1/user/exists?name={name} | `GET` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | -| AdminVerifyAccount | checks wether a user is the admin | `N/A` | api/v1/admin/verify_account | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_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} | api/v1/admin/prune_users | `POST` | 200 | uint64 | number of users deleted | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | +| 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` | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | +| Close | saves & closes the CCash webserver | `N/A` | admin/shutdown | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: | +| Contains | checks wether a user exists | `N/A` | user/exists?name={name} | `GET` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | +| AdminVerifyAccount | checks wether a user is the admin | `N/A` | admin/verify_account | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_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: | :heavy_multiplication_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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | ### System Usage endpoin errors | name | 401 | 404 | 406 | @@ -105,12 +107,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} | api/v1/user/register | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | -| AdminAddUser | 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: | :heavy_multiplication_x: | -| DelSelf | deletes a user | `N/A` | api/v1/user/delete | `DELETE` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | -| AdminDelUser | 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: | :heavy_multiplication_x: | +| 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: | :heavy_multiplication_x: | :heavy_multiplication_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: | :heavy_multiplication_x: | +| DelSelf | deletes a user | `N/A` | user/delete | `DELETE` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_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: | :heavy_multiplication_x: | ### User Management endpoint errors | name | 400 | 401 | 404 | 406 | 409 | From 292b73001e89bd48a6a8939deabc851df81590be Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Fri, 9 Dec 2022 04:02:33 -0800 Subject: [PATCH 36/73] :memo: simplified --- ccash_config.hpp.in | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ccash_config.hpp.in b/ccash_config.hpp.in index daae174..46bdbfd 100644 --- a/ccash_config.hpp.in +++ b/ccash_config.hpp.in @@ -28,13 +28,7 @@ if false, when frequency is hit save */ #define CONSERVATIVE_DISK_SAVE @CONSERVATIVE_DISK_SAVE_VAL@ -/* -e.g when set to 2 -version 1 will work -version 2 will work -version 3 will not work -etc -*/ +// doesnt compile api endpoints above API_VERSION #define API_VERSION @API_VERSION_VAL@ // doesnt compile api endpoints below MIN_API_SUPPORT From 04fe7376ec08aedad8f88a2b1af18bed9cd29a96 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Fri, 9 Dec 2022 04:04:30 -0800 Subject: [PATCH 37/73] :memo: --- docs/connected_services/how_to/endpoints.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index 8c0651b..99c47eb 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -15,14 +15,14 @@ ## 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 +## 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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | -| GetLogV2 | 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: | :heavy_multiplication_x: | :heavy_multiplication_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: | :heavy_multiplication_x: | :heavy_multiplication_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: | :heavy_multiplication_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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | From 6d9c6d6c1c35eed2a1594106d29127e84e6a30f5 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Fri, 9 Dec 2022 04:06:04 -0800 Subject: [PATCH 38/73] :memo: corrected --- docs/connected_services/how_to/endpoints.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index 99c47eb..867d6a0 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -36,14 +36,13 @@ | VerifyPassword | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | ### Usage endpoint support -`v` denoting the API version -| name | v1 | v2 | -| :------------- | :----------------------: | :----------------: | -| GetBal | :heavy_check_mark: | :heavy_check_mark: | -| GetLog | :heavy_check_mark: | :heavy_check_mark: | -| GetLogV2 | :heavy_multiplication_x: | :heavy_check_mark: | -| SendFunds | :heavy_check_mark: | :heavy_check_mark: | -| VerifyPassword | :heavy_check_mark: | :heavy_check_mark: | +| name | v1 | v2 | +| :------------- | :----------------------: | :----------------------: | +| GetBal | :heavy_check_mark: | :heavy_check_mark: | +| GetLog | :heavy_check_mark: | :heavy_multiplication_x: | +| GetLogV2 | :heavy_multiplication_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 | From ed0d5c823114a8de8aea75f1e7a79eef6b73a2d4 Mon Sep 17 00:00:00 2001 From: Expand-sys Date: Sun, 11 Dec 2022 11:14:55 +1100 Subject: [PATCH 39/73] update ansible to allow for api version changes --- deployment/main.yml | 2 +- deployment/vars/default.yml | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/deployment/main.yml b/deployment/main.yml index 34dcaae..965da18 100644 --- a/deployment/main.yml +++ b/deployment/main.yml @@ -54,7 +54,7 @@ ansible.builtin.command: 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" .. + 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 }}" .. - name: make CCash community.general.make: diff --git a/deployment/vars/default.yml b/deployment/vars/default.yml index 95a253b..265567b 100644 --- a/deployment/vars/default.yml +++ b/deployment/vars/default.yml @@ -1,4 +1,6 @@ --- BUILD_DIR: '/root' ADMIN_A: "admin" -SAVE_FREQ: "2" \ No newline at end of file +SAVE_FREQ: "2" +API_VERSION: "2" +MIN_API_SUPPORT: "1" \ No newline at end of file From 8e44a3d44605e1aac27383e65badef59a81e7479 Mon Sep 17 00:00:00 2001 From: William Date: Sat, 17 Dec 2022 09:18:50 -0800 Subject: [PATCH 40/73] Update FAQ.md --- docs/FAQ.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 2931861..f16750a 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -14,9 +14,5 @@ CCash isn't a crypto, simply a ledger keeping track of who owns what. Because this usecase requires none of the features a database would offer. ### People are making too many accounts maliciously to fill up space on my server! Consider disabling `ADD_USER_OPEN` in the [build proccess](https://github.com/EntireTwix/CCash/blob/main/docs/building.md). -### My instance is taking up too much RAM -Reduce log size. -### My instance is taking up too much disk spac -Use the prune users endpoint to dead accounts or you can reduce log size but should be a last resort. -### My instance is slow -Toggling off logs will increase performance. On some devices multi threading increases performance, on others the overhead isn't worth the benefit. +### My instance is taking up too much storage or RAM +Reduce log size and/or use the prune users endpoint to remove dead accounts. From 37b110d36f3bc33fc78952020c7ed733aa871065 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sat, 17 Dec 2022 12:25:47 -0800 Subject: [PATCH 41/73] :bug: receiving field should not be in quotes --- src/log.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/log.cpp b/src/log.cpp index 9fcfc00..b32c2b0 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -68,9 +68,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? From 2c62c89b4784c8e596de61b140704875cfedb6c9 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 13:22:46 -0800 Subject: [PATCH 42/73] :bulb: clarifying comment --- include/str_intrusion.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/str_intrusion.h b/include/str_intrusion.h index 0d30fe4..2319071 100644 --- a/include/str_intrusion.h +++ b/include/str_intrusion.h @@ -1,6 +1,11 @@ #pragma once #include +/* +The intended use of this cursed class is in violating the encapsulation of std::string this class acts like std::string_view even though its stored in a std::string. +The reason this was needed is because sometimes we have a std::string_view instance and another library requires a const std::string& argument, forcing us to copy to a string before passing it, this copying is unnecessary. +*/ + struct StrFromSV_Wrapper { std::string str; From 54acbf8cc63b620fbb76e4809e013e9bd65c9144 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 15:48:28 -0800 Subject: [PATCH 43/73] :bug: "doc["time"].get(pass)" -> "doc["pass"].get(pass)" --- src/bank_api.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/bank_api.cpp b/src/bank_api.cpp index 8cdeee6..7b2a15e 100644 --- a/src/bank_api.cpp +++ b/src/bank_api.cpp @@ -1,7 +1,5 @@ #include "bank_api.h" -// TODO: parser iterate(input).get(doc) error handling might be superfulous - #define CACHE_FOREVER resp->setExpiredTime(0) #define CORS resp->addHeader("Access-Control-Allow-Origin", "*") @@ -96,7 +94,7 @@ void api::ChangePassword(req_args) else { std::string_view pass; - if (doc["time"].get(pass)) + if (doc["pass"].get(pass)) { res = BankResponse{k400BadRequest, "\"Missing/Invalid JSON arg(s)\""}; } @@ -120,7 +118,7 @@ void api::AdminChangePassword(req_args) else { std::string_view name, pass; - if (doc["name"].get(name) || doc["time"].get(pass)) + if (doc["name"].get(name) || doc["pass"].get(pass)) { res = BankResponse{k400BadRequest, "\"Missing/Invalid JSON arg(s)\""}; } @@ -319,7 +317,7 @@ void api::AdminAddUser(req_args) std::string_view name; uint64_t amount; std::string_view pass; - if (doc["name"].get(name) || doc["amount"].get(amount) || doc["time"].get(pass) || (amount > std::numeric_limits::max())) + if (doc["name"].get(name) || doc["amount"].get(amount) || doc["pass"].get(pass) || (amount > std::numeric_limits::max())) { res = BankResponse{k400BadRequest, "\"Missing/Invalid JSON arg(s)\""}; } From 4ca1bbe6eb19bc989735d734fc970a74f43cbe14 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 16:51:23 -0800 Subject: [PATCH 44/73] :memo: --- docs/FAQ.md | 2 +- docs/connected_services/how_to/APIs.md | 11 +++++------ docs/features/user_side.md | 13 ++++++------- docs/idea.md | 17 ++++++++--------- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index f16750a..f1a03a7 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -7,7 +7,7 @@ Usernames are restricted by minecraft's requirements * lowercase letters * numbers * _ -* Length must be atleast 3 and at most 16 characters. +* length must be atleast 3 and at most 16 characters. ### Is this crypto like krist? CCash isn't a crypto, simply a ledger keeping track of who owns what. ### Why isnt this on a database? diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 3d08c6e..bad29a5 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -1,12 +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 release 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: | :heavy_multiplication_x: | -| [Luke](https://github.com/LukeeeeBennett/ccash-client-js) | JS | [ccash client js](https://github.com/LukeeeeBennett/ccash-client-js) | :heavy_multiplication_x: | :heavy_multiplication_x: | -| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | :heavy_check_mark: | :heavy_multiplication_x: | -| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | :heavy_check_mark: | :heavy_multiplication_x: | +| author | language | | v1 endpoints | v2 endpoints | +| :------------------------------------------- | :------: | ------------------------------------------------------------------- | :----------------: | :----------------------: | +| [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | :heavy_check_mark: | :heavy_multiplication_x: | +| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | :heavy_check_mark: | :heavy_multiplication_x: | +| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | :heavy_check_mark: | :heavy_multiplication_x: | for example here is a demo program for the lua API by SpaceCat diff --git a/docs/features/user_side.md b/docs/features/user_side.md index 009fb81..6ce99f7 100644 --- a/docs/features/user_side.md +++ b/docs/features/user_side.md @@ -4,15 +4,12 @@ ## Performance #### Speed -Capable of processing thousands of requests per second, with no slow down as user size grows to the millions. - +Capable of processing hundreds of thousands of requests per second (depending on hardware), 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. - -Anecdotally I typically expierenced <1% CPU usage. - -Small save files at typically a couple kb, easily shareable. +* Low memory usage at 8 Mb baseline, and 157 bytes per new log. +* Extremely low CPU usage in the single digits of %. +* Small save files at typically a couple kb, easily shareable. ## Accessibility #### Connected Services as explained in earlier docs a ecosystem of connected services allows you many ways to utilize CCash. @@ -32,3 +29,5 @@ each transaction is logged and the last `n` logs are stored, if set to 0 logs wi by default this feature is off, but when enabled deleted account's funds will be redirected to a specified account rather then "burned" #### Configurable as you can read in [building.md](../building.md) CCash is highly configurable. +#### Game Independent +As CCash does not require an addition to the game in the form of a mod or plugin, it can be ran on any server. diff --git a/docs/idea.md b/docs/idea.md index ca5a02b..3f2c9de 100644 --- a/docs/idea.md +++ b/docs/idea.md @@ -6,26 +6,25 @@ While CCash can be used for anything that can interact with its API I think mine The currency model most Minecraft Servers adopt if any, is resource based, usually diamonds. This model is fraught with issues however: -* The primary issue is minecraft worlds are infinite leading to hyper inflation as everyone accrues more diamonds. -* There is no central authority minting the currency. Any consumer can introduce more diamonds to the system. -* Some resources are passively reapable, making the generation of currency a larger focus than that of creating products. +* The primary issue is minecraft worlds are infinite, leading to hyper inflation as everyone accrues more diamonds. +* Some resources are passively reapable (e.g iron or gold), making the generation of currency a larger focus than that of creating value. * Locality is required for transactions. -* Theft is possible; ownership is possession based. +* Theft is possible; ownership is physical possession based. -CCash solves these issues and adds a level of abstraction. The main philosophy of CCash is to have fast core operations which other services build on. +CCash solves these issues and adds a level of abstraction. The main philosophy of CCash is to have fast core operations which other services build on, CCash can proccess hundreds of thousands of requests per second (depending on hardware). -The CCash instance can be external to the game server. +The CCash instance can be external to the game server: ![image](external_diagram.png) -or on localhost: +Or on localhost: ![image](localhost_diagram.png) -Running it local to the game server reduces latency for connected services. Fortunately CCash is sufficiently lightweight as to not impact performance on most setups. +Running it local to the game server reduces latency for connected services and CCash is very lightweight and so will be a tiny proportion of the server's total computation. **DISCLAIMER: ComputerCraft requires you add `127.0.0.1` to its config section `allowed_domains` if you're interacting with CCash locally** As CCash is just a means of keeping track of who has what, the economic system you use is entirely up to whomever hosts the instance. -It's suggested an admin should manage the instance to lower incentive to manipulate. +I suggest an admin should manage the instance to lower incentive to manipulate balances. From d63be0ec732daed79fa01dfd3606a635f37b5128 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 17:18:47 -0800 Subject: [PATCH 45/73] :bug: logs being disabled wasnt building --- src/bank.cpp | 4 +++- src/bank_api.cpp | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bank.cpp b/src/bank.cpp index a6cbefe..08ba3a1 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -86,6 +86,7 @@ BankResponse Bank::GetBal(const std::string &name) noexcept } } #if MAX_LOG_SIZE > 0 + #if MIN_API_SUPPORT == 1 BankResponse Bank::GetLogs(const std::string &name) noexcept { @@ -115,6 +116,7 @@ BankResponse Bank::GetLogsV2(const std::string &name) noexcept } } #endif + #endif BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_name, uint32_t amount) noexcept @@ -231,7 +233,7 @@ BankResponse Bank::PruneUsers(uint32_t threshold_bal) noexcept for (const auto &u : users) { #if RETURN_ON_DEL - if (Bank::users.erase_if(u.first, [threshold_time, threshold_bal, &bal, &deleted_count](User &u) { + if (Bank::users.erase_if(u.first, [threshold_bal, &bal, &deleted_count](User &u) { bal += u.balance; #else if (Bank::users.erase_if(u.first, [threshold_time, threshold_bal, &deleted_count](User &u) { diff --git a/src/bank_api.cpp b/src/bank_api.cpp index 7b2a15e..aaef815 100644 --- a/src/bank_api.cpp +++ b/src/bank_api.cpp @@ -244,9 +244,9 @@ void api::PruneUsers(req_args) } else { + uint64_t amount; #if MAX_LOG_SIZE > 0 int64_t time; - uint64_t amount; if (doc["time"].get(time) || doc["amount"].get(amount) || (amount > std::numeric_limits::max())) { res = BankResponse{k400BadRequest, "\"Missing/Invalid JSON arg(s)\""}; @@ -256,7 +256,6 @@ void api::PruneUsers(req_args) res = Bank::PruneUsers(time, amount); } #else - uint64_t amount if (doc["amount"].get(amount) || (amount > std::numeric_limits::max())) { res = BankResponse{k400BadRequest, "\"Missing/Invalid JSON arg(s)\""}; From 5e253e42d937c8013104108a91fba31b1d330b88 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 17:22:12 -0800 Subject: [PATCH 46/73] :bug: fixing last commit --- src/bank.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/bank.cpp b/src/bank.cpp index 08ba3a1..ff0c9e9 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -232,16 +232,26 @@ BankResponse Bank::PruneUsers(uint32_t threshold_bal) noexcept #endif for (const auto &u : users) { + +#if MAX_LOG_SIZE > 0 + #if RETURN_ON_DEL - if (Bank::users.erase_if(u.first, [threshold_bal, &bal, &deleted_count](User &u) { + if (Bank::users.erase_if(u.first, [threshold_time, threshold_bal, &bal, &deleted_count](User &u) { bal += u.balance; #else if (Bank::users.erase_if(u.first, [threshold_time, threshold_bal, &deleted_count](User &u) { #endif -#if MAX_LOG_SIZE > 0 return ((!u.log.data.size() || u.log.data.back().time < threshold_time) && u.balance < threshold_bal); #else + +#if RETURN_ON_DEL + if (Bank::users.erase_if(u.first, [threshold_bal, &bal, &deleted_count](User &u) { + bal += u.balance; +#else + if (Bank::users.erase_if(u.first, [threshold_bal, &deleted_count](User &u) { +#endif return (u.balance < threshold_bal); + #endif })) { From ff0dfc8a939306a41e5ff99369bfbb64670544a7 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 17:28:02 -0800 Subject: [PATCH 47/73] :memo: --- docs/features/user_side.md | 2 +- docs/idea.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/features/user_side.md b/docs/features/user_side.md index 6ce99f7..eccc074 100644 --- a/docs/features/user_side.md +++ b/docs/features/user_side.md @@ -4,7 +4,7 @@ ## Performance #### Speed -Capable of processing hundreds of thousands of requests per second (depending on hardware), with little slow down as user size grows to the millions. +Capable of processing hundreds 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. diff --git a/docs/idea.md b/docs/idea.md index 3f2c9de..a665ddd 100644 --- a/docs/idea.md +++ b/docs/idea.md @@ -11,7 +11,7 @@ The currency model most Minecraft Servers adopt if any, is resource based, usual * Locality is required for transactions. * Theft is possible; ownership is physical possession based. -CCash solves these issues and adds a level of abstraction. The main philosophy of CCash is to have fast core operations which other services build on, CCash can proccess hundreds of thousands of requests per second (depending on hardware). +CCash solves these issues and adds a level of abstraction. The main philosophy of CCash is to have fast core operations which other services build on, CCash can proccess hundreds of requests per second. The CCash instance can be external to the game server: From 76388c6423d0be6e81610ffdea2a347f1d59337e Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 17:56:20 -0800 Subject: [PATCH 48/73] :memo: mistaken :heavy_multiplication_x: --- docs/connected_services/how_to/endpoints.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index 867d6a0..8305ac4 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -89,14 +89,14 @@ | ApiProperties | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_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_multiplication_x: | -| ApiProperties | `N/A` | `N/A` | +| 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 From aefdb4ce9b3b261d10bcdec2b2c4d519cdf8a6fc Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 18:34:35 -0800 Subject: [PATCH 49/73] more accurate thread readout --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 8f6c499..016cb06 100644 --- a/main.cpp +++ b/main.cpp @@ -61,7 +61,7 @@ int main(int argc, char **argv) << "\nSSE 4.1 : " << (__builtin_cpu_supports("sse4.1") ? "enabled" : "disabled") << "\nSSE 4.2 : " << (__builtin_cpu_supports("sse4.2") ? "enabled" : "disabled") #if MULTI_THREADED - << "\n\nThreads : " << get_nprocs() + 1 + << "\n\nThreads : " << get_nprocs() + saving_freq << "\nMulti threading : enabled"; #else << "\n\nThreads : " << 2 From 722f8d0f48d64f3ac0aab3bec9b5b1dff6dd61ce Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 18:35:26 -0800 Subject: [PATCH 50/73] :bug: correcting last commit --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 016cb06..a9206d8 100644 --- a/main.cpp +++ b/main.cpp @@ -52,6 +52,7 @@ int main(int argc, char **argv) std::cerr << "ERROR: CCash MUST be ran as root\n"; return 0; } + 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") @@ -88,7 +89,6 @@ int main(int argc, char **argv) Bank::admin_account = argv[1]; //Auto Saving - const unsigned long saving_freq = std::stoul(std::string(argv[2])); if (saving_freq) //if saving frequency is 0 then auto saving is turned off { std::thread([saving_freq]() From 411d1996c71ef2c6f873e3b5fd867428c9202c48 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 19:09:55 -0800 Subject: [PATCH 51/73] :bug: used CMake variables incorrectly --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f0aac1..21e2fee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,13 +82,13 @@ set(RETURN_ON_DEL_NAME_VAL "\"\"") endif() if(DEFINED API_VERSION) -set(API_VERSION_VAL API_VERSION) +set(API_VERSION_VAL ${API_VERSION}$) else() set(API_VERSION_VAL 2) endif() if(DEFINED MIN_API_SUPPORT) -set(MIN_API_SUPPORT_VAL MIN_API_SUPPORT) +set(MIN_API_SUPPORT_VAL ${MIN_API_SUPPORT}$) else() set(MIN_API_SUPPORT_VAL 1) endif() From 878a71f3106519c397814f3f8548e844dff4c023 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 19:11:26 -0800 Subject: [PATCH 52/73] :bug: fixing last commit --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21e2fee..8688794 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,13 +82,13 @@ set(RETURN_ON_DEL_NAME_VAL "\"\"") endif() if(DEFINED API_VERSION) -set(API_VERSION_VAL ${API_VERSION}$) +set(API_VERSION_VAL ${API_VERSION}) else() set(API_VERSION_VAL 2) endif() if(DEFINED MIN_API_SUPPORT) -set(MIN_API_SUPPORT_VAL ${MIN_API_SUPPORT}$) +set(MIN_API_SUPPORT_VAL ${MIN_API_SUPPORT}) else() set(MIN_API_SUPPORT_VAL 1) endif() From 472a9222fc6aed6add26c9f6100cf726f492d485 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 20:16:52 -0800 Subject: [PATCH 53/73] :sparkles: daemon flag --- main.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index a9206d8..21769ef 100644 --- a/main.cpp +++ b/main.cpp @@ -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 \n"; + std::cout << "User save file generated\nUsage: sudo ./bank [daemon flag]\n"; } else { @@ -42,9 +42,9 @@ int main(int argc, char **argv) } return 0; } - if (argc != 3) + if (argc < 3) { - std::cerr << "Usage: sudo ./bank \n"; + std::cerr << "Usage: sudo ./bank [daemon flag]\n"; return 0; } if (geteuid() != 0) @@ -65,16 +65,16 @@ int main(int argc, char **argv) << "\n\nThreads : " << get_nprocs() + saving_freq << "\nMulti threading : enabled"; #else - << "\n\nThreads : " << 2 + << "\n\nThreads : " << 1 + saving_freq << "\nMulti threading : disabled"; #endif - //Loading users from users.json + //Loading users from users.dat Bank::Load(); 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) + 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 " << Bank::SumBal() << " C$H" << std::endl; //flushing before EventLoop @@ -102,6 +102,8 @@ int main(int argc, char **argv) }) .detach(); } + + if (argc == 4 && !strcmp(argv[3], "true")) { app().enableRunAsDaemon(); } } //destroying setup variables app() From b69092d732b8a955ebb25b8ce943ada2d5685e5e Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 20:24:33 -0800 Subject: [PATCH 54/73] :memo: command line arguments example --- docs/building.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/building.md b/docs/building.md index 2e9108c..4278322 100644 --- a/docs/building.md +++ b/docs/building.md @@ -5,8 +5,8 @@ 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 -* with no users memory usage is ~8.47 Mb +* `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 +* 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! @@ -95,6 +95,7 @@ cmake .. make -j sudo ./bank ``` +the last command generates a blank save file in your defined location. ## Certs make sure to edit `config.json` adding the certificate location if you're using HTTPS, I personally use [certbot](https://certbot.eff.org/). @@ -144,4 +145,15 @@ leaving ] } ``` -**it is Highly recommened you secure your server** + +You can now run the program from the build location. For example +``` +sudo ./bank admin 5 +``` +in this example CCash will be launched with the admin account named `"admin"`, and a saving frequency of every `5` minutes; without daemon being given its default is `false`. + +Another example +``` +sudo ./bank Kevin 0 true +``` +in this example CCash will be launched with the admin account named `"Kevin"`, and a saving frequency of `0` meaning the server will only save when closed; daemon is set to `true` and so will be launched in the background. From 21fd1c94e49451a99ab5311f066e50bf1c6c9209 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 22:26:44 -0800 Subject: [PATCH 55/73] :memo: connect services versioning documented --- docs/connected_services/existing_services.md | 43 ++++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/docs/connected_services/existing_services.md b/docs/connected_services/existing_services.md index 51ae364..c0c0305 100644 --- a/docs/connected_services/existing_services.md +++ b/docs/connected_services/existing_services.md @@ -1,25 +1,32 @@ [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:. + ## General -| author | name | v1 | 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: | | -| [Sam](https://github.com/STBoyden) | [Market](https://github.com/STBoyden/market-api-2.0) | :heavy_multiplication_x: | | +| 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: | ⚠ | | ## Minecraft -| author | name | v1 | 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) | +| 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: | | ## Desired -| idea | description | -| :----------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| Market | a platform to buy and sell items. | -| Anonymous Payments | a service that allows for sending of funds annoymously, by first sending them to an intermediate account that is receiving and sending from many wallets as to obfuscate the fund's origin. | -| Gambling | physical or digital casino. | -| Shipping | the infastructure to quickly send items across long distances. | -| Mod | a server-side mod | \ No newline at end of file +| idea | description | +| :------: | :------------------------------------------------------------- | +| Gambling | physical or digital casino. | +| Shipping | the infastructure to quickly send items across long distances. | +| Mod | a server-side mod | \ No newline at end of file From 10c3c6a536551f7df931590c0ba58272234769f5 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 22:27:29 -0800 Subject: [PATCH 56/73] :heavy_multiplication_x: -> :x: --- docs/connected_services/how_to/APIs.md | 10 +- docs/connected_services/how_to/endpoints.md | 124 ++++++++++---------- 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index bad29a5..35a814f 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -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 release 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: | :heavy_multiplication_x: | -| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | :heavy_check_mark: | :heavy_multiplication_x: | -| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | :heavy_check_mark: | :heavy_multiplication_x: | +| 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: | for example here is a demo program for the lua API by SpaceCat diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index 8305ac4..abfadf7 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -11,54 +11,54 @@ `A` - Admin, same as `U` but in addition requires username supplied be equal to the admin account username :heavy_check_mark: -:heavy_multiplication_x: +:x: ## 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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_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: | :heavy_multiplication_x: | :heavy_multiplication_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: | :heavy_multiplication_x: | :heavy_multiplication_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: | :heavy_multiplication_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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | +| 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: | ### Usage enpoint errors -| name | 400 | 401 | 404 | 406 | -| :------------- | :----------------------: | :----------------------: | :----------------------: | :----------------: | -| GetBal | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_check_mark: | -| GetLog | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | -| GetLogV2 | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | -| SendFunds | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | -| VerifyPassword | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | +| name | 400 | 401 | 404 | 406 | +| :------------- | :----------------: | :----------------: | :----------------: | :----------------: | +| GetBal | :x: | :x: | :heavy_check_mark: | :heavy_check_mark: | +| GetLog | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | +| GetLogV2 | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | +| 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: | :heavy_multiplication_x: | -| GetLogV2 | :heavy_multiplication_x: | :heavy_check_mark: | -| SendFunds | :heavy_check_mark: | :heavy_check_mark: | -| VerifyPassword | :heavy_check_mark: | :heavy_check_mark: | +| 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: | :heavy_multiplication_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: | :heavy_multiplication_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: | :heavy_multiplication_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: | :heavy_multiplication_x: | +| 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: | ### Meta Usage endpoint errors -| name | 400 | 401 | 404 | 406 | -| :------------------ | :----------------: | :----------------: | :----------------------: | :----------------: | -| ChangePassword | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | -| AdminChangePassword | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | -| 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: | +| name | 400 | 401 | 404 | 406 | +| :------------------ | :----------------: | :----------------: | :----------------: | :----------------: | +| ChangePassword | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | +| AdminChangePassword | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | +| 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 | @@ -69,24 +69,24 @@ | 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` | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | -| Close | saves & closes the CCash webserver | `N/A` | admin/shutdown | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: | -| Contains | checks wether a user exists | `N/A` | user/exists?name={name} | `GET` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | -| AdminVerifyAccount | checks wether a user is the admin | `N/A` | admin/verify_account | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_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: | :heavy_multiplication_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: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | +| 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: | ### System Usage endpoin errors -| name | 401 | 404 | 406 | -| :----------------- | :----------------------: | :----------------------: | :----------------------: | -| Help | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | -| Close | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | -| Contains | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | -| AdminVerifyAccount | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | -| PruneUsers | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | -| ApiProperties | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | +| name | 401 | 404 | 406 | +| :----------------- | :----------------: | :----------------: | :----------------: | +| Help | :x: | :x: | :x: | +| Close | :heavy_check_mark: | :x: | :heavy_check_mark: | +| Contains | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | +| AdminVerifyAccount | :heavy_check_mark: | :x: | :heavy_check_mark: | +| PruneUsers | :heavy_check_mark: | :x: | :heavy_check_mark: | +| ApiProperties | :x: | :x: | :x: | ### System Usage endpoint support | name | v1 | v2 | @@ -106,20 +106,20 @@ 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: | :heavy_multiplication_x: | :heavy_multiplication_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: | :heavy_multiplication_x: | -| DelSelf | deletes a user | `N/A` | user/delete | `DELETE` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_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: | :heavy_multiplication_x: | +| 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: | ### User Management endpoint errors -| name | 400 | 401 | 404 | 406 | 409 | -| :----------- | :----------------------: | :----------------------: | :----------------------: | :----------------: | :----------------------: | -| AddUser | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | -| AdminAddUser | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_check_mark: | -| DelSelf | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: | -| AdminDelUser | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: | +| name | 400 | 401 | 404 | 406 | 409 | +| :----------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | +| AddUser | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | +| 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 | From cc103c72981c46439b0a781084c488c498d8d567 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 18 Dec 2022 23:23:53 -0800 Subject: [PATCH 57/73] :memo: --- docs/building.md | 1 + docs/connected_services/existing_services.md | 2 +- docs/connected_services/how_to/APIs.md | 2 +- docs/features/user_side.md | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/building.md b/docs/building.md index 4278322..4d94980 100644 --- a/docs/building.md +++ b/docs/building.md @@ -146,6 +146,7 @@ leaving } ``` +## Usage You can now run the program from the build location. For example ``` sudo ./bank admin 5 diff --git a/docs/connected_services/existing_services.md b/docs/connected_services/existing_services.md index c0c0305..f9414f9 100644 --- a/docs/connected_services/existing_services.md +++ b/docs/connected_services/existing_services.md @@ -7,7 +7,7 @@ | 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:. +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:**. ## General | author | name | v1 | v2 | image | diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 35a814f..2f453af 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -1,6 +1,6 @@ [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 release it can still use the old endpoints. +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: | diff --git a/docs/features/user_side.md b/docs/features/user_side.md index eccc074..77c6867 100644 --- a/docs/features/user_side.md +++ b/docs/features/user_side.md @@ -7,7 +7,7 @@ Capable of processing hundreds 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 157 bytes per new log. * Extremely low CPU usage in the single digits of %. * Small save files at typically a couple kb, easily shareable. ## Accessibility From 83455a0510f03ee4e792ef8cb9889586462a1871 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Dec 2022 15:45:05 -0800 Subject: [PATCH 58/73] :sparkles: changed to per-method versioning --- CMakeLists.txt | 12 +-- benchmarking.cpp | 4 +- ccash_config.hpp.in | 10 +- deployment/main.yml | 46 ++++++---- deployment/vars/default.yml | 5 +- docs/building.md | 23 +++-- docs/connected_services/existing_services.md | 34 +++---- docs/connected_services/how_to/APIs.md | 12 +-- docs/connected_services/how_to/endpoints.md | 96 ++++++-------------- include/bank.h | 5 +- include/bank_api.h | 42 ++------- include/log.h | 9 +- main.cpp | 5 +- src/bank.cpp | 8 +- src/bank_api.cpp | 6 +- src/log.cpp | 14 +-- 16 files changed, 121 insertions(+), 210 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8688794..f4c1e40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/benchmarking.cpp b/benchmarking.cpp index bf25208..243fe25 100644 --- a/benchmarking.cpp +++ b/benchmarking.cpp @@ -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); diff --git a/ccash_config.hpp.in b/ccash_config.hpp.in index 46bdbfd..baf91f9 100644 --- a/ccash_config.hpp.in +++ b/ccash_config.hpp.in @@ -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@ \ No newline at end of file +#define ADD_USER_OPEN @ADD_USER_OPEN_VAL@ + +#define USE_DEPRECATED_ENDPOINTS @USE_DEPRECATED_ENDPOINTS_VAL@ \ No newline at end of file diff --git a/deployment/main.yml b/deployment/main.yml index 965da18..5620fe1 100644 --- a/deployment/main.yml +++ b/deployment/main.yml @@ -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 \ No newline at end of file + dest: /etc/systemd/system/ccash.service diff --git a/deployment/vars/default.yml b/deployment/vars/default.yml index 265567b..308bc93 100644 --- a/deployment/vars/default.yml +++ b/deployment/vars/default.yml @@ -1,6 +1,5 @@ --- -BUILD_DIR: '/root' +BUILD_DIR: "/root" ADMIN_A: "admin" SAVE_FREQ: "2" -API_VERSION: "2" -MIN_API_SUPPORT: "1" \ No newline at end of file +USE_DEPRECATED_ENDPOINTS: "true" diff --git a/docs/building.md b/docs/building.md index 4d94980..5eb8579 100644 --- a/docs/building.md +++ b/docs/building.md @@ -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: ``` diff --git a/docs/connected_services/existing_services.md b/docs/connected_services/existing_services.md index f9414f9..269be20 100644 --- a/docs/connected_services/existing_services.md +++ b/docs/connected_services/existing_services.md @@ -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 | diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 2f453af..42a7eb3 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -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 diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index abfadf7..da0c05f 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -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: | diff --git a/include/bank.h b/include/bank.h index f3c5637..4cb8340 100644 --- a/include/bank.h +++ b/include/bank.h @@ -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; diff --git a/include/bank_api.h b/include/bank_api.h index 864cc28..610426e 100644 --- a/include/bank_api.h +++ b/include/bank_api.h @@ -12,10 +12,10 @@ class api : public HttpController { 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"); #if MAX_LOG_SIZE > 0 +#if USE_DEPRECATED_ENDPOINTS METHOD_ADD(api::GetLogs, "/v1/user/log", Get, Options, "JsonFilter", "UserFilter"); +#endif + METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter", "UserFilter"); #else +#if USE_DEPRECATED_ENDPOINTS METHOD_ADD(api::GetLogs, "/v1/user/log", Get, Options, "JsonFilter"); +#endif + METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter"); #endif METHOD_ADD(api::SendFunds, "/v1/user/transfer", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) METHOD_ADD(api::VerifyPassword, "/v1/user/verify_password", Post, Options, "UserFilter", "JsonFilter"); @@ -69,37 +74,6 @@ public: METHOD_ADD(api::AdminAddUser, "/v1/admin/user/register", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) ["amount"](uint32) ["pass"](string) METHOD_ADD(api::DelSelf, "/v1/user/delete", Delete, Options, "UserFilter", "JsonFilter"); METHOD_ADD(api::AdminDelUser, "/v1/admin/user/delete", Delete, Options, "JsonFilter", "UserFilter"); //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"); -#if MAX_LOG_SIZE > 0 - METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter", "UserFilter"); -#else - METHOD_ADD(api::GetLogsV2, "/v2/user/log", Get, Options, "JsonFilter"); -#endif - METHOD_ADD(api::SendFunds, "/v2/user/transfer", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) - METHOD_ADD(api::VerifyPassword, "/v2/user/verify_password", Post, Options, "UserFilter", "JsonFilter"); - - //Meta Usage - METHOD_ADD(api::ChangePassword, "/v2/user/change_password", Patch, Options, "JsonFilter", "UserFilter"); //expects ["pass"](string) - METHOD_ADD(api::AdminChangePassword, "/v2/admin/user/change_password", Patch, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["pass"](string) - METHOD_ADD(api::SetBal, "/v2/admin/set_balance", Patch, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) - METHOD_ADD(api::ImpactBal, "/v2/admin/impact_balance", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) - - //System Usage - METHOD_ADD(api::Close, "/v2/admin/shutdown", Post, Options, "UserFilter", "JsonFilter"); - METHOD_ADD(api::Contains, "/v2/user/exists?name={name}", Get, Options, "JsonFilter"); - METHOD_ADD(api::AdminVerifyAccount, "/v2/admin/verify_account", Post, Options, "UserFilter", "JsonFilter"); - METHOD_ADD(api::PruneUsers, "/v2/admin/prune_users", Post, "UserFilter", "JsonFilter"); //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", "UserFilter"); //expects ["name"](string) ["amount"](uint32) ["pass"](string) - METHOD_ADD(api::DelSelf, "/v2/user/delete", Delete, Options, "UserFilter", "JsonFilter"); - METHOD_ADD(api::AdminDelUser, "/v2/admin/user/delete", Delete, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) -#endif METHOD_LIST_END }; \ No newline at end of file diff --git a/include/log.h b/include/log.h index fc0ec92..e49c7a6 100644 --- a/include/log.h +++ b/include/log.h @@ -11,25 +11,20 @@ struct Log { private: -#if MIN_API_SUPPORT == 1 +#if USE_DEPRECATED_ENDPOINTS ChangeFlag log_flag; std::string log_snapshot = "null"; #endif -#if (API_VERSION >= 2) && (MIN_API_SUPPORT <= 2) ChangeFlag log_flag_v2; std::string log_snapshot_v2 = "null"; -#endif public: std::deque 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; }; diff --git a/main.cpp b/main.cpp index 21769ef..86f071b 100644 --- a/main.cpp +++ b/main.cpp @@ -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 [daemon flag]\n"; + std::cout << "User save file generated\nUsage: sudo ./bank [daemon flag {default: false}]\n"; } else { @@ -44,7 +44,7 @@ int main(int argc, char **argv) } if (argc < 3) { - std::cerr << "Usage: sudo ./bank [daemon flag]\n"; + std::cerr << "Usage: sudo ./bank [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") diff --git a/src/bank.cpp b/src/bank.cpp index ff0c9e9..ebbd40b 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -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 })) { diff --git a/src/bank_api.cpp b/src/bank_api.cpp index aaef815..0a86d43 100644 --- a/src/bank_api.cpp +++ b/src/bank_api.cpp @@ -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) + "\"}"; diff --git a/src/log.cpp b/src/log.cpp index b32c2b0..c99609f 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -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 From 07b9e20e3158531d4300531cf54ccf792b936d7d Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Dec 2022 15:48:08 -0800 Subject: [PATCH 59/73] expand's commit --- docs/deploy.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/deploy.md b/docs/deploy.md index 0be50bf..0314f3b 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -15,8 +15,9 @@ Additionally CCash can be deployed to any infrastructure able to run Rocky/Alma As CCash is intended to be run as root, the playbook is run also as root. The playbook also builds CCash from the latest github push, so there may be bugs. -In order to use the ansible playbook, clone the playbook to any pc with the ability to access the server through SSH and with Ansible installed, edit the inventory file to contain the IP address of the target server and run the following command: -```ansible-playbook -i inventory main.yml -k``` +In order to use the ansible playbook, clone the playbook to any pc with the ability to access the server through SSH and with Ansible installed, edit the inventory file to contain the IP address of the target server and run the following commands: +```ansible-galaxy install -r deployment/requirements.yml +```ansible-playbook -i deployment/inventory deployment/main.yml -k``` When this is complete the server will have ccash installed to the user dir, this is customizable in the vars/default.yml file along with the admin username and save frequency. To start CCash run: ```systemctl start ccash``` From 8ff1fddf7abbf534391de5f71a5d07def32f0847 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Dec 2022 16:07:34 -0800 Subject: [PATCH 60/73] :memo: --- docs/connected_services/how_to/APIs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 42a7eb3..38e6e88 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -1,6 +1,6 @@ [PREVIOUS PAGE](explanation.md) | [NEXT PAGE](endpoints.md) -CCash is backwards compatible, so even if a language API does not support the newester version it can still call the old endpoints. +CCash is backwards compatible, so even if a language API does not support the newester version it can still call the old endpoints. Only when the major version increments are deprecated features made defunct (e.g `v1.0.0 -> v2.0.0`), check [endpoints.md](endpoints.md) to avoid using deprecated endpoints. | author | language | | newest CCash supported version | | :------------------------------------------- | :------: | ------------------------------------------------------------------- | :----------------------------: | | [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | `v1.4.3` | From d8e88ec37593acf27fdd48a6c3d3f65a8206ce28 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Dec 2022 16:26:00 -0800 Subject: [PATCH 61/73] :memo: versioning documented --- docs/connected_services/how_to/APIs.md | 2 +- docs/versioning.md | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 docs/versioning.md diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 38e6e88..e1f35e2 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -1,6 +1,6 @@ [PREVIOUS PAGE](explanation.md) | [NEXT PAGE](endpoints.md) -CCash is backwards compatible, so even if a language API does not support the newester version it can still call the old endpoints. Only when the major version increments are deprecated features made defunct (e.g `v1.0.0 -> v2.0.0`), check [endpoints.md](endpoints.md) to avoid using deprecated endpoints. +CCash is backwards compatible, so even if a language API does not support the newester version it can still call the old endpoints. Only when the major version increments are deprecated features made defunct (e.g `v1.0.0 -> v2.0.0`), check the [endpoint docs](endpoints.md) to avoid using deprecated endpoints. For more information about versioning check out [versioning docs](../../versioning.md) | author | language | | newest CCash supported version | | :------------------------------------------- | :------: | ------------------------------------------------------------------- | :----------------------------: | | [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | `v1.4.3` | diff --git a/docs/versioning.md b/docs/versioning.md new file mode 100644 index 0000000..937b39a --- /dev/null +++ b/docs/versioning.md @@ -0,0 +1,12 @@ +# Versioning + +## Endpoint Version +When changing an existing endpoint in a breaking way the version will increment in the path e.g `api/v1/user/log` -> `api/v2/user/log`. If the change is non-breaking then extra parameters will simply be added to the endpoint. If the older version is marked deprecated it will be documented in [endpoints.md](connected_services/how_to/endpoints.md) + +## Release Version + +Major changes (e.g `v1.0.0` -> `v2.0.0`) denote a breaking change as all previously deprecated endpoints will now be made defunct and wont be built with that release. + +Minor changes (e.g `v1.0.0` -> `v1.1.0`) denote a non-breaking change that adds or changes something about CCash. + +Patches (e.g `v1.0.0` -> `v1.0.1`) denote bug fixes. From 99f47dc6edcfb208b2e79dbc0d44213211497984 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Dec 2022 17:31:38 -0800 Subject: [PATCH 62/73] :memo: versioning changes --- docs/connected_services/existing_services.md | 4 ++- docs/connected_services/how_to/APIs.md | 6 ++-- docs/connected_services/how_to/endpoints.md | 36 ++++++++++---------- docs/versioning.md | 2 +- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/docs/connected_services/existing_services.md b/docs/connected_services/existing_services.md index 269be20..80dea75 100644 --- a/docs/connected_services/existing_services.md +++ b/docs/connected_services/existing_services.md @@ -5,8 +5,10 @@ | :-----------------------: | :----------------- | | supported | :heavy_check_mark: | | uses deprecated endpoints | ⚠ | +| uses defunt endpoints | :no_entry: | + ## General -| author | name | v1 | image | +| 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) | [Discord Bot](https://github.com/Expand-sys/ccashbot) | :heavy_check_mark: | | diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index e1f35e2..37c1fe2 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -3,9 +3,9 @@ CCash is backwards compatible, so even if a language API does not support the newester version it can still call the old endpoints. Only when the major version increments are deprecated features made defunct (e.g `v1.0.0 -> v2.0.0`), check the [endpoint docs](endpoints.md) to avoid using deprecated endpoints. For more information about versioning check out [versioning docs](../../versioning.md) | 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` | +| [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | `v2.4.0` | +| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | `v2.4.0` | +| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | `v2.4.0` | for example here is a demo program for the lua API by SpaceCat diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index da0c05f..8d0a8e2 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -19,11 +19,11 @@ ### Usage endpoints | 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: | +| 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 | `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: | +| 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 | @@ -37,10 +37,10 @@ ### Meta Usage endpoints | 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: | +| ChangePassword | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | @@ -53,12 +53,12 @@ ### Sytem Usage endpoints | 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: | +| Help | `v2.3.0` | redirects to GitHub projects Docs | `N/A` | api/help | `GET` | 301 | `N/A` | `N/A` | :x: | :x: | :x: | :x: | +| Close | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | @@ -80,10 +80,10 @@ Valid ### User Management endpoints | 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: | +| AddUser | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | deletes a user | `N/A` | api/v1/user/delete | `DELETE` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | +| AdminDelUser | `v2.3.0` | 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 | diff --git a/docs/versioning.md b/docs/versioning.md index 937b39a..49921ae 100644 --- a/docs/versioning.md +++ b/docs/versioning.md @@ -9,4 +9,4 @@ Major changes (e.g `v1.0.0` -> `v2.0.0`) denote a breaking change as all previou Minor changes (e.g `v1.0.0` -> `v1.1.0`) denote a non-breaking change that adds or changes something about CCash. -Patches (e.g `v1.0.0` -> `v1.0.1`) denote bug fixes. +Patches (e.g `v1.0.0` -> `v1.0.1`) denote bug fixes or docs changes. From 026d2b84939bdb654911526197f1c47ef66e734b Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Dec 2022 17:43:13 -0800 Subject: [PATCH 63/73] :memo: versioning changes --- docs/connected_services/how_to/endpoints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index 8d0a8e2..34ab712 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -21,7 +21,7 @@ | :------------- | :------: | ------------------------------------------------------------------------------ | -------------------------------- | ------------------------------- | :---------: | :------------: | :--------------: | :------------------------------------------------------------------------: | :----------------: | :----------------: | :---: | :----------------: | | 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 | `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: | +| 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":bool, "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: | From 24665641b4db0a66380cba1b558f79fb2926bc76 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Dec 2022 17:44:49 -0800 Subject: [PATCH 64/73] :memo: versioning changes --- docs/connected_services/how_to/APIs.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 37c1fe2..50f6271 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -3,10 +3,10 @@ CCash is backwards compatible, so even if a language API does not support the newester version it can still call the old endpoints. Only when the major version increments are deprecated features made defunct (e.g `v1.0.0 -> v2.0.0`), check the [endpoint docs](endpoints.md) to avoid using deprecated endpoints. For more information about versioning check out [versioning docs](../../versioning.md) | author | language | | newest CCash supported version | | :------------------------------------------- | :------: | ------------------------------------------------------------------- | :----------------------------: | -| [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | `v2.4.0` | -| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | `v2.4.0` | -| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | `v2.4.0` | - +| [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | `v2.4.1` | +| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | `v2.4.1` | +| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | `v2.4.1` | + for example here is a demo program for the lua API by SpaceCat ```lua From dbe755da2bea450864bafd04a71c07eb4274052d Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Dec 2022 17:47:41 -0800 Subject: [PATCH 65/73] :memo: --- docs/connected_services/how_to/APIs.md | 2 +- main.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 50f6271..3780613 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -1,6 +1,6 @@ [PREVIOUS PAGE](explanation.md) | [NEXT PAGE](endpoints.md) -CCash is backwards compatible, so even if a language API does not support the newester version it can still call the old endpoints. Only when the major version increments are deprecated features made defunct (e.g `v1.0.0 -> v2.0.0`), check the [endpoint docs](endpoints.md) to avoid using deprecated endpoints. For more information about versioning check out [versioning docs](../../versioning.md) +CCash is backwards compatible, so even if a language API does not support the newester version it can still call the old endpoints. Only when the major version increments are deprecated features made defunct (e.g `v1.0.0` -> `v2.0.0`), check the [endpoint docs](endpoints.md) to avoid using deprecated endpoints. For more information about versioning check out [versioning docs](../../versioning.md) | author | language | | newest CCash supported version | | :------------------------------------------- | :------: | ------------------------------------------------------------------- | :----------------------------: | | [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | `v2.4.1` | diff --git a/main.cpp b/main.cpp index 86f071b..4e0fc31 100644 --- a/main.cpp +++ b/main.cpp @@ -54,6 +54,7 @@ int main(int argc, char **argv) } const unsigned long saving_freq = std::stoul(std::string(argv[2])); std::cout + << "\nAPI : v2.5.1" << "\n\nAVX : " << (__builtin_cpu_supports("avx") ? "enabled" : "disabled") << "\nAVX 2 : " << (__builtin_cpu_supports("avx2") ? "enabled" : "disabled") << "\nSSE 2 : " << (__builtin_cpu_supports("sse2") ? "enabled" : "disabled") From 8696c5d8703da5436bc026c0aacf661b2d75f2da Mon Sep 17 00:00:00 2001 From: Expand-sys Date: Tue, 20 Dec 2022 13:35:34 +1100 Subject: [PATCH 66/73] added pending changes to deployment script --- deployment/inventory | 2 +- deployment/main.yml | 184 +++++++++++++++++++++++++++--------- deployment/requirements.yml | 4 + deployment/vars/default.yml | 4 + 4 files changed, 150 insertions(+), 44 deletions(-) create mode 100644 deployment/requirements.yml diff --git a/deployment/inventory b/deployment/inventory index f8d136f..0ed1766 100644 --- a/deployment/inventory +++ b/deployment/inventory @@ -1,2 +1,2 @@ [all] -10.10.0.145 ansible_ssh_user=root ansible_ssh_common_args='-o StrictHostKeyChecking=no' \ No newline at end of file +127.0.0.1 ansible_ssh_user=root ansible_ssh_common_args='-o StrictHostKeyChecking=no' \ No newline at end of file diff --git a/deployment/main.yml b/deployment/main.yml index 5620fe1..df1f9cd 100644 --- a/deployment/main.yml +++ b/deployment/main.yml @@ -4,9 +4,10 @@ become: true pre_tasks: - name: load variables - ansible.builtin.include_vars: "{{ item }}" + ansible.builtin.include_vars: '{{ item }}' with_first_found: - - "default.yml" + - "vars/default.yml" + tasks: - name: refresh packages update @@ -23,30 +24,22 @@ - 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 + update: true + force: true + version: "{{ BRANCH }}" - 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 @@ -54,51 +47,156 @@ 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" -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" - - name: generate default ssl - ansible.builtin.command: - chdir: "{{BUILD_DIR}}/CCash/config/" - cmd: "./ssl.sh" - - - name: create service file + path: '{{BUILD_DIR}}/CCash/config/ssl.sh' + - name: create ssl gen file ansible.builtin.copy: content: | - [Unit] - Description=CCash API Server - After=network.target remote-fs.target nss-lookup.target + { + "listeners": [ + { + "address": "0.0.0.0", + "port": 80, + "https": false + }, + { + "address": "0.0.0.0", + "port": 443, + "https": true, + "cert": "{{ BUILD_DIR }}/CCash/config/cert.cert", + "key": "{{ BUILD_DIR }}/CCash/config/key.key" + } + ] + } + dest: "{{ BUILD_DIR }}/CCash/config/config.json" - [Service] - Type=simple - ExecStart={{BUILD_DIR}}/CCash/build/bank {{ADMIN_A}} {{SAVE_FREQ}} - ExecStop=/bin/kill -WINCH ${MAINPID} - KillSignal=SIGCONT - PrivateTmp=true - [Install] - WantedBy=multi-user.target - dest: /etc/systemd/system/ccash.service + - name: create ssl gen file + ansible.builtin.copy: + content: | + #!/bin/bash + + + openssl genrsa -out server.pass.key 2048 + openssl rsa -in server.pass.key -out {{ BUILD_DIR }}/CCash/config/key.key + rm server.pass.key + openssl req -new -key {{ BUILD_DIR }}/CCash/config/key.key -out server.csr \ + -subj "/C=US/ST=CCashland/L=NEW CCASH/O=CCash/OU=Devs/CN=localhost" + openssl x509 -req -days 365 -in server.csr -signkey {{ BUILD_DIR }}/CCash/config/key.key -out {{ BUILD_DIR }}/CCash/config/cert.cert + dest: "{{ BUILD_DIR }}/CCash/config/ssl.sh" + + - name: generate default ssl + ansible.builtin.command: + chdir: '{{BUILD_DIR}}/CCash/config/' + cmd: './ssl.sh' + + - name: Start CCash Api Server + ansible.builtin.command: + chdir: '{{ BUILD_DIR }}/CCash/build' + cmd: './bank {{ ADMIN_A }} {{ SAVE_FREQ }} true' + + - name: Clone Web + git: + repo: https://github.com/Expand-sys/ccashfrontend.git + dest: '{{BUILD_DIR}}/CCash/web' + recursive: true + update: true + force: true + + when: WEB_ENABLED == true + + - name: "Install Nodejs 18 module" + command: dnf module install -y nodejs:18/common + register: result + changed_when: + - '"Enabling module streams" in result.stdout' + when: ansible_os_family == "RedHat" and WEB_ENABLED == true + + + - name: install pm2 + community.general.npm: + path: '{{ BUILD_DIR }}/CCash/web' + name: pm2 + global: true + when: WEB_ENABLED == true + + - name: install web dependencies + community.general.npm: + path: '{{ BUILD_DIR }}/CCash/web' + when: WEB_ENABLED == true + + - name: create .env file + ansible.builtin.copy: + content: | + BANKAPIURL={{ ansible_facts["all_ipv4_addresses"][0] }} + SECURE=true + SETUP=true + PORT={{ WEB_PORT }} + dest: '{{ BUILD_DIR }}/CCash/web/.env' + when: WEB_ENABLED == true + + - name: create pm2 file + ansible.builtin.copy: + content: | + { + "name": "ccashfrontend", + "script": "{{ BUILD_DIR }}/ccash/web/index.js", + "watch": "{{ BUILD_DIR }}/ccash/web/tmp/restart.txt", + "instances": "1" + } + dest: "{{ BUILD_DIR }}/CCash/web/pm2.json" + when: WEB_ENABLED == true + + + - name: start webapp service + ansible.builtin.command: + chdir: "{{ BUILD_DIR }}/CCash/web" + cmd: | + pm2 start index.js --update-env --name 'CCashFrontend' -f + when: START_SERVICES == true and WEB_ENABLED == true + + - name: enable web app on boot + ansible.builtin.command: + chdir: "{{ BUILD_DIR }}/CCash/web" + cmd: | + pm2 startup + when: START_ON_BOOT == true and START_SERVICES == true and WEB_ENABLED == true + + - name: allow firewalld ports + ansible.posix.firewalld: + permanent: true + port: 443/tcp + state: enabled + + - name: allow firewalld ports + ansible.posix.firewalld: + permanent: true + port: 3000/tcp + state: enabled + when: WEB_ENABLED == true + diff --git a/deployment/requirements.yml b/deployment/requirements.yml new file mode 100644 index 0000000..24f5007 --- /dev/null +++ b/deployment/requirements.yml @@ -0,0 +1,4 @@ +--- +collections: +- ansible.posix +- community.general diff --git a/deployment/vars/default.yml b/deployment/vars/default.yml index 308bc93..d8ac2f9 100644 --- a/deployment/vars/default.yml +++ b/deployment/vars/default.yml @@ -3,3 +3,7 @@ BUILD_DIR: "/root" ADMIN_A: "admin" SAVE_FREQ: "2" USE_DEPRECATED_ENDPOINTS: "true" +WEB_ENABLED: true +WEB_PORT: "3000" +START_SERVICES: true +BRANCH: "v2" \ No newline at end of file From 95c2d47216f1fef7cddc3450089aae2f25d7417f Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Dec 2022 18:41:15 -0800 Subject: [PATCH 67/73] receiving output as "true" instead of "1" --- src/log.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/log.cpp b/src/log.cpp index c99609f..6b734a0 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -64,7 +64,7 @@ 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 += std::to_string(data[i].receiving); //4 + log_snapshot_v2 += (data[i].receiving)?"true":"false"; //4 log_snapshot_v2 += ",\"amount\":"; //11 log_snapshot_v2 += std::to_string(data[i].amount); //10? log_snapshot_v2 += ",\"time\":"; //8 From ce65a4387cb0c88f2f363ac30215264b737b9239 Mon Sep 17 00:00:00 2001 From: Expand-sys Date: Tue, 20 Dec 2022 14:01:55 +1100 Subject: [PATCH 68/73] made ccash use crontab to start it on boot --- deployment/main.yml | 7 +++++++ deployment/vars/default.yml | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/deployment/main.yml b/deployment/main.yml index df1f9cd..8c2fb7b 100644 --- a/deployment/main.yml +++ b/deployment/main.yml @@ -186,6 +186,13 @@ cmd: | pm2 startup when: START_ON_BOOT == true and START_SERVICES == true and WEB_ENABLED == true + - name: enable ccash on boot + ansible.builtin.cron: + name: CCash enable on boot + special_time: reboot + state: present + job: '{{ BUILD_DIR }}/CCash/build/bank {{ ADMIN_A }} {{ SAVE_FREQ }} true' + when: START_ON_BOOT == true - name: allow firewalld ports ansible.posix.firewalld: diff --git a/deployment/vars/default.yml b/deployment/vars/default.yml index d8ac2f9..ecfa980 100644 --- a/deployment/vars/default.yml +++ b/deployment/vars/default.yml @@ -6,4 +6,5 @@ USE_DEPRECATED_ENDPOINTS: "true" WEB_ENABLED: true WEB_PORT: "3000" START_SERVICES: true -BRANCH: "v2" \ No newline at end of file +START_ON_BOOT: true +BRANCH: "v2.5.1" \ No newline at end of file From 66b21332b31ce5d0503da37e29fc49c061f23dff Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Dec 2022 19:55:52 -0800 Subject: [PATCH 69/73] :bug: fixed `properties()` --- docs/connected_services/how_to/endpoints.md | 30 ++++++++++----------- src/bank_api.cpp | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index 34ab712..f51a5db 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":bool, "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, "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: | ### Usage enpoint errors | name | 400 | 401 | 404 | 406 | @@ -51,14 +51,14 @@ | ImpactBal | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | ### Sytem Usage endpoints -| name | added on | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U | -| :----------------- | :------: | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- | ------------------------------ | :---------: | :------------: | :---------: | :---------------------------------------------------------------------------------------------------------: | :----------------: | :----------------: | :----------------: | :---: | -| Help | `v2.3.0` | redirects to GitHub projects Docs | `N/A` | api/help | `GET` | 301 | `N/A` | `N/A` | :x: | :x: | :x: | :x: | -| Close | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | redirects to GitHub projects Docs | `N/A` | api/help | `GET` | 301 | `N/A` | `N/A` | :x: | :x: | :x: | :x: | +| Close | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | properties of the given instance | `N/A` | api/properties | `GET` | 200 | json object | {"max_log":uint64, "add_user_open":boolean} and "return_on_del":string if that feature is enabled | :heavy_check_mark: | :x: | :x: | :x: | ### System Usage endpoin errors | name | 401 | 404 | 406 | diff --git a/src/bank_api.cpp b/src/bank_api.cpp index 0a86d43..6f50984 100644 --- a/src/bank_api.cpp +++ b/src/bank_api.cpp @@ -218,7 +218,7 @@ void api::AdminVerifyAccount(req_args) } void api::ApiProperties(req_args) { - std::string info = "{\"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\":" + (ADD_USER_OPEN?"true":"false"); if constexpr (RETURN_ON_DEL) { info += ",\"return_on_del\":\"" + std::string(return_account) + "\"}"; From 82e3a6384ccbf930838296e3682829e10ea2d841 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 19 Dec 2022 20:07:49 -0800 Subject: [PATCH 70/73] :memo: --- docs/connected_services/how_to/APIs.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 3780613..0f88f5f 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -1,13 +1,14 @@ [PREVIOUS PAGE](explanation.md) | [NEXT PAGE](endpoints.md) -CCash is backwards compatible, so even if a language API does not support the newester version it can still call the old endpoints. Only when the major version increments are deprecated features made defunct (e.g `v1.0.0` -> `v2.0.0`), check the [endpoint docs](endpoints.md) to avoid using deprecated endpoints. For more information about versioning check out [versioning docs](../../versioning.md) -| author | language | | newest CCash supported version | -| :------------------------------------------- | :------: | ------------------------------------------------------------------- | :----------------------------: | -| [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | `v2.4.1` | -| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | `v2.4.1` | -| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | `v2.4.1` | +CCash is backwards compatible, so even if a language API does not support the newester version it can still call the old endpoints. Only when the major version increments are deprecated features made defunct (e.g `v1.0.0` -> `v2.0.0`), check the [endpoint docs](endpoints.md) to avoid using deprecated endpoints. For more information about versioning check out [versioning docs](../../versioning.md). +| author | language | | newest CCash supported version | +| :-------------------------------------------------------- | :--------: | -------------------------------------------------------------------- | :----------------------------: | +| [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | `v2.5.1` | +| [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | `v2.5.1` | +| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | `v2.4.1` | +| [Luke](https://github.com/LukeeeeBennett/ccash-client-js) | TypeScript | [ccash client js](https://github.com/LukeeeeBennett/ccash-client-js) | `v1.3.0` | -for example here is a demo program for the lua API by SpaceCat +here is a demo program for the lua API by SpaceCat ```lua local ccash = require("ccash.api") From 3e73d08227b85f4e0e7ab9e60855a5a7905a96da Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Tue, 20 Dec 2022 11:56:50 -0800 Subject: [PATCH 71/73] :fire: `return_on_del` is always a field now --- src/bank_api.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/bank_api.cpp b/src/bank_api.cpp index 6f50984..4c4ae9d 100644 --- a/src/bank_api.cpp +++ b/src/bank_api.cpp @@ -218,15 +218,7 @@ void api::AdminVerifyAccount(req_args) } void api::ApiProperties(req_args) { - std::string info = "{\"max_log\":" + std::to_string(MAX_LOG_SIZE) + ",\"add_user_open\":" + (ADD_USER_OPEN?"true":"false"); - if constexpr (RETURN_ON_DEL) - { - info += ",\"return_on_del\":\"" + std::string(return_account) + "\"}"; - } - else - { - info += "}"; - } + std::string info = "{\"max_log\":" + std::to_string(MAX_LOG_SIZE) + ",\"add_user_open\":" + (ADD_USER_OPEN?"true":"false") + ",\"return_on_del\":" + (RETURN_ON_DEL?'\"' + std::string(return_account) + "\"":"null") + '}'; auto resp = HttpResponse::newCustomHttpResponse(BankResponse{k200OK, std::move(info)}); CORS; CACHE_FOREVER; From 3b46c97d0a2bdcf44b082d1f0f0f3b58acc733e2 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Tue, 20 Dec 2022 12:06:40 -0800 Subject: [PATCH 72/73] :memo: `return_on_del` is always a field now --- docs/connected_services/how_to/endpoints.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index f51a5db..e0d5cd4 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -51,14 +51,14 @@ | ImpactBal | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | ### Sytem Usage endpoints -| name | added on | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U | -| :----------------- | :------: | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- | ------------------------------ | :---------: | :------------: | :---------: | :-----------------------------------------------------------------------------------------------: | :----------------: | :----------------: | :----------------: | :---: | -| Help | `v2.3.0` | redirects to GitHub projects Docs | `N/A` | api/help | `GET` | 301 | `N/A` | `N/A` | :x: | :x: | :x: | :x: | -| Close | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | properties of the given instance | `N/A` | api/properties | `GET` | 200 | json object | {"max_log":uint64, "add_user_open":boolean} and "return_on_del":string if that 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 | `v2.3.0` | redirects to GitHub projects Docs | `N/A` | api/help | `GET` | 301 | `N/A` | `N/A` | :x: | :x: | :x: | :x: | +| Close | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.3.0` | 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 | `v2.5.1` | properties of the given instance | `N/A` | api/properties | `GET` | 200 | json object | {"max_log":uint64, "add_user_open":boolean, "return_on_del":string} | :heavy_check_mark: | :x: | :x: | :x: | ### System Usage endpoin errors | name | 401 | 404 | 406 | From b656bb7e438c04f9aabfc951f8258a9722b8f4ed Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Tue, 20 Dec 2022 13:17:45 -0800 Subject: [PATCH 73/73] :memo: python lib up to date --- docs/connected_services/how_to/APIs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/connected_services/how_to/APIs.md b/docs/connected_services/how_to/APIs.md index 0f88f5f..52fc9a5 100644 --- a/docs/connected_services/how_to/APIs.md +++ b/docs/connected_services/how_to/APIs.md @@ -5,7 +5,7 @@ CCash is backwards compatible, so even if a language API does not support the ne | :-------------------------------------------------------- | :--------: | -------------------------------------------------------------------- | :----------------------------: | | [SpaceCat](https://github.com/SpaceCat-Chan) | CCLua | [CatsCCashLuaApi](https://github.com/SpaceCat-Chan/CatsCCashLuaApi) | `v2.5.1` | | [Sam](https://github.com/STBoyden) | Rust | [ccash rs](https://github.com/STBoyden/ccash-rs) | `v2.5.1` | -| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | `v2.4.1` | +| [Doggo](https://github.com/ArcNyxx) | Python | [CCashPythonClient](https://github.com/ArcNyxx/ccash_python_client) | `v2.5.1` | | [Luke](https://github.com/LukeeeeBennett/ccash-client-js) | TypeScript | [ccash client js](https://github.com/LukeeeeBennett/ccash-client-js) | `v1.3.0` | here is a demo program for the lua API by SpaceCat