mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 08:32:13 +11:00
Merge branch 'EntireTwix:Refractor' into Refractor
This commit is contained in:
commit
cef439ef8b
6 changed files with 38 additions and 9 deletions
|
|
@ -8,7 +8,7 @@
|
||||||
* [existing services](docs/connected_services/existing_services.md)
|
* [existing services](docs/connected_services/existing_services.md)
|
||||||
* features
|
* features
|
||||||
* [user side](docs/features/user_side.md)
|
* [user side](docs/features/user_side.md)
|
||||||
* [implementation](docs/features/implementations.md)
|
* [implementation](docs/features/implementation.md)
|
||||||
* [building](docs/building.md)
|
* [building](docs/building.md)
|
||||||
* [FAQ](docs/FAQ.md)
|
* [FAQ](docs/FAQ.md)
|
||||||
* [Patreon](https://www.patreon.com/twoxx) if you wanna support this and/or future projects.
|
* [Patreon](https://www.patreon.com/twoxx) if you wanna support this and/or future projects.
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
| language |
|
||||||
|
| -------- |
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
# Contributors
|
# Contributors
|
||||||
| name | work |
|
| name | work |
|
||||||
| :------------------------------------------ | -------------------------- |
|
| :------------------------------------------ | ----------------------- |
|
||||||
| Caesay | Restful API suggestions |
|
| Caesay | Restful API suggestions |
|
||||||
| [Luke](https://github.com/LukeeeeBennett) | JS API, Docker package |
|
| [Luke](https://github.com/LukeeeeBennett) | Docker package |
|
||||||
| [React](https://github.com/Reactified) | Computer Craft API, logo |
|
| [React](https://github.com/Reactified) | logo |
|
||||||
| [Doggo](https://github.com/FearlessDoggo21) | Logs optimized, Python API |
|
| [Doggo](https://github.com/FearlessDoggo21) | Logs optimized |
|
||||||
| [Expand](https://github.com/Expand-sys) | fixed Docker package |
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <json/json.h> // to be removed later
|
#include <json/json.h> // to be removed later
|
||||||
#include <array>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "ccash_config.hpp"
|
#include "ccash_config.hpp"
|
||||||
#include "change_flag.h"
|
#include "change_flag.h"
|
||||||
|
|
@ -13,7 +13,11 @@ private:
|
||||||
Json::Value log_snapshot;
|
Json::Value log_snapshot;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
#if MAX_LOG_SIZE == 1
|
||||||
|
Transaction data;
|
||||||
|
#else
|
||||||
std::vector<Transaction> data;
|
std::vector<Transaction> data;
|
||||||
|
#endif
|
||||||
|
|
||||||
const Json::Value &GetLog() noexcept;
|
const Json::Value &GetLog() noexcept;
|
||||||
void AddTrans(Transaction &&t) noexcept;
|
void AddTrans(Transaction &&t) noexcept;
|
||||||
|
|
|
||||||
24
src/log.cpp
24
src/log.cpp
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
void Log::AddTrans(Transaction &&t) noexcept
|
void Log::AddTrans(Transaction &&t) noexcept
|
||||||
{
|
{
|
||||||
|
#if MAX_LOG_SIZE == 1
|
||||||
|
data = std::move(t);
|
||||||
|
#else
|
||||||
if (data.size() == MAX_LOG_SIZE) // If we hit the max size
|
if (data.size() == MAX_LOG_SIZE) // If we hit the max size
|
||||||
{
|
{
|
||||||
for (uint32_t i = 1; i < data.size(); i++) // Make room at the back
|
for (uint32_t i = 1; i < data.size(); i++) // Make room at the back
|
||||||
|
|
@ -16,6 +19,7 @@ void Log::AddTrans(Transaction &&t) noexcept
|
||||||
data.reserve(data.capacity() + PRE_LOG_SIZE); // Reserve more memory
|
data.reserve(data.capacity() + PRE_LOG_SIZE); // Reserve more memory
|
||||||
}
|
}
|
||||||
data.push_back(std::move(t)); // In either case we have space under max length, move to new spot
|
data.push_back(std::move(t)); // In either case we have space under max length, move to new spot
|
||||||
|
#endif
|
||||||
log_flag.SetChangesOn();
|
log_flag.SetChangesOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,6 +29,15 @@ const Json::Value &Log::GetLog() noexcept
|
||||||
{
|
{
|
||||||
//re-generate snapshot
|
//re-generate snapshot
|
||||||
Json::Value res;
|
Json::Value res;
|
||||||
|
#if MAX_LOG_SIZE == 1
|
||||||
|
res[0]["to"] = data.to;
|
||||||
|
res[0]["from"] = data.from;
|
||||||
|
#ifdef _USE_32BIT_TIME_T
|
||||||
|
res[0]["time"] = (Json::UInt)data.time;
|
||||||
|
#else
|
||||||
|
res[0]["time"] = (Json::UInt64)data.time;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
for (uint32_t i = data.size(); i > 0; --i)
|
for (uint32_t i = data.size(); i > 0; --i)
|
||||||
{
|
{
|
||||||
res[i - 1]["to"] = data[data.size() - i].to;
|
res[i - 1]["to"] = data[data.size() - i].to;
|
||||||
|
|
@ -36,6 +49,7 @@ const Json::Value &Log::GetLog() noexcept
|
||||||
res[i - 1]["time"] = (Json::UInt64)data[data.size() - i].time;
|
res[i - 1]["time"] = (Json::UInt64)data[data.size() - i].time;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
log_flag.SetChangesOff();
|
log_flag.SetChangesOff();
|
||||||
log_snapshot = res;
|
log_snapshot = res;
|
||||||
}
|
}
|
||||||
|
|
@ -45,6 +59,15 @@ const Json::Value &Log::GetLog() noexcept
|
||||||
Json::Value Log::Serialize() const
|
Json::Value Log::Serialize() const
|
||||||
{
|
{
|
||||||
Json::Value res;
|
Json::Value res;
|
||||||
|
#if MAX_LOG_SIZE == 1
|
||||||
|
res[0]["to"] = data.to;
|
||||||
|
res[0]["from"] = data.from;
|
||||||
|
#ifdef _USE_32BIT_TIME_T
|
||||||
|
res[0]["time"] = (Json::UInt)data.time;
|
||||||
|
#else
|
||||||
|
res[0]["time"] = (Json::UInt64)data.time;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
for (uint32_t i = 0; i < data.size(); ++i)
|
for (uint32_t i = 0; i < data.size(); ++i)
|
||||||
{
|
{
|
||||||
res[i]["to"] = data[i].to;
|
res[i]["to"] = data[i].to;
|
||||||
|
|
@ -56,5 +79,6 @@ Json::Value Log::Serialize() const
|
||||||
res[i]["time"] = (Json::UInt64)data[i].time;
|
res[i]["time"] = (Json::UInt64)data[i].time;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue