pre-ai
This commit is contained in:
parent
be13205ffd
commit
367c19386c
17 changed files with 561 additions and 166 deletions
|
|
@ -14,8 +14,20 @@ namespace Nostro {
|
|||
std::string iban;
|
||||
Currency currency;
|
||||
std::int64_t balance;
|
||||
|
||||
std::vector<Transaction> transactions;
|
||||
|
||||
std::chrono::system_clock::time_point GetLastTransactionTime(std::string_view connector) const;
|
||||
void SaveTransactions(std::string_view connector);
|
||||
void LoadTransactions(std::string_view connector);
|
||||
void LoadTransactions(std::string_view connector, std::chrono::system_clock::time_point from);
|
||||
void LoadTransactions(std::string_view connector, std::chrono::system_clock::time_point from, std::chrono::system_clock::time_point to);
|
||||
void LoadTransactionsByDescription(std::string_view connector, std::string_view description);
|
||||
void LoadTransactionsByIban(std::string_view connector, std::string_view iban);
|
||||
void LoadTransactions(std::string_view connector, std::int64_t amount);
|
||||
|
||||
private:
|
||||
std::ifstream LoadUntilFrom(std::string_view connector, std::chrono::system_clock::time_point from);
|
||||
Transaction& LoadTransaction(std::ifstream& file);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,10 +27,7 @@ namespace Nostro {
|
|||
BunqConnector* connector;
|
||||
|
||||
BunqAccount(std::string&& name, std::string&& bic, std::string&& iban, Currency currency, std::int64_t balance, std::uint32_t id, BunqConnector* connector);
|
||||
void Send(std::string_view iban, std::string_view name, std::int64_t amount, Currency currency) const;
|
||||
void Send(std::string_view iban, std::string_view name, std::int64_t amount, Currency currency, std::string_view description) const;
|
||||
private:
|
||||
void SendPayment(std::string iban) const;
|
||||
};
|
||||
|
||||
export struct BunqConnector {
|
||||
|
|
@ -44,6 +41,7 @@ namespace Nostro {
|
|||
|
||||
void RefreshSession();
|
||||
void RefreshAccounts();
|
||||
void GetNewTransactions();
|
||||
bool TestConnector();
|
||||
|
||||
static constexpr std::string connectorId = "bunq";
|
||||
|
|
|
|||
|
|
@ -9,9 +9,6 @@ namespace Nostro {
|
|||
export struct Connector {
|
||||
static void SaveConnectors();
|
||||
static void LoadConnectors();
|
||||
static std::filesystem::path GetConnectorPath();
|
||||
static std::string ListConnectors();
|
||||
static std::string ListBalance();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ export module Nostro:Currency;
|
|||
import std;
|
||||
|
||||
export namespace Nostro {
|
||||
enum class Currency {
|
||||
enum class Currency : std::uint16_t {
|
||||
Euro
|
||||
};
|
||||
|
||||
|
|
|
|||
19
interfaces/Nostro-File.cppm
Normal file
19
interfaces/Nostro-File.cppm
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
//SPDX-License-Identifier: LGPL-3.0-only
|
||||
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
export module Nostro:File;
|
||||
|
||||
import std;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
export namespace Nostro {
|
||||
fs::path GetConfigPath();
|
||||
fs::path GetCachePath();
|
||||
fs::path configPath = GetConfigPath();
|
||||
fs::path cachePath = GetCachePath();
|
||||
void CreatePrivateFile(const fs::path& path);
|
||||
void WriteString(std::ofstream& file, std::string_view str);
|
||||
void ReadString(std::ifstream& file, std::string& str);
|
||||
std::uint16_t SeekString(std::ifstream& file);
|
||||
}
|
||||
|
|
@ -8,10 +8,16 @@ import :Currency;
|
|||
|
||||
namespace Nostro {
|
||||
export struct Transaction {
|
||||
std::string_view bic;
|
||||
std::string_view iban;
|
||||
std::string name;
|
||||
std::string bic;
|
||||
std::string iban;
|
||||
std::string description;
|
||||
Currency currency;
|
||||
std::int64_t amount;
|
||||
std::chrono::system_clock::time_point timePoint;
|
||||
|
||||
Transaction();
|
||||
Transaction(std::string&& name, std::string&& bic, std::string&& iban, std::string&& description, Currency currency, std::int64_t amount, std::chrono::system_clock::time_point timePoint);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
69
interfaces/Nostro-Utils.cppm
Normal file
69
interfaces/Nostro-Utils.cppm
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
//SPDX-License-Identifier: LGPL-3.0-only
|
||||
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
export module Nostro:Utils;
|
||||
|
||||
import std;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
export namespace Nostro {
|
||||
constexpr std::string EscB(std::string_view s) {
|
||||
std::string out;
|
||||
out.reserve(s.size() + 8);
|
||||
for (const char c : s) {
|
||||
switch (c) {
|
||||
case '"': out += "\\\""; break;
|
||||
case '\\': out += "\\\\"; break;
|
||||
case '\n': out += "\\n"; break;
|
||||
case '\r': out += "\\r"; break;
|
||||
case '\t': out += "\\t"; break;
|
||||
default:
|
||||
if (static_cast<unsigned char>(c) < 0x20) {
|
||||
out += std::format("\\u{:04x}", static_cast<unsigned char>(c));
|
||||
} else {
|
||||
out += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr std::chrono::system_clock::time_point ParseTimestamp(std::string_view text) {
|
||||
const auto field = [text](std::size_t offset, std::size_t length) {
|
||||
std::uint32_t value = 0;
|
||||
const char* const first = text.data() + offset;
|
||||
if(offset + length > text.size()) {
|
||||
throw std::runtime_error(std::format("malformed timestamp '{}'", text));
|
||||
}
|
||||
const std::from_chars_result result = std::from_chars(first, first + length, value);
|
||||
if(result.ec != std::errc() || result.ptr != first + length) {
|
||||
throw std::runtime_error(std::format("malformed timestamp '{}'", text));
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
if(text.size() < 19 || text[4] != '-' || text[7] != '-' || text[10] != ' ' || text[13] != ':' || text[16] != ':') {
|
||||
throw std::runtime_error(std::format("malformed timestamp '{}'", text));
|
||||
}
|
||||
|
||||
std::uint32_t micros = 0;
|
||||
if(text.size() > 19) {
|
||||
const std::size_t digits = text.size() - 20;
|
||||
if(text[19] != '.' || digits == 0 || digits > 6) {
|
||||
throw std::runtime_error(std::format("malformed timestamp '{}'", text));
|
||||
}
|
||||
micros = field(20, digits);
|
||||
for(std::size_t i = digits; i < 6; i++) {
|
||||
micros *= 10;
|
||||
}
|
||||
}
|
||||
|
||||
const std::chrono::year_month_day date(std::chrono::year(static_cast<std::int32_t>(field(0, 4))), std::chrono::month(field(5, 2)), std::chrono::day(field(8, 2)));
|
||||
if(!date.ok()) {
|
||||
throw std::runtime_error(std::format("malformed timestamp '{}'", text));
|
||||
}
|
||||
|
||||
return std::chrono::sys_days(date) + std::chrono::hours(field(11, 2)) + std::chrono::minutes(field(14, 2)) + std::chrono::seconds(field(17, 2)) + std::chrono::microseconds(micros);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ export import :Transaction;
|
|||
export import :Connector;
|
||||
export import :Banks;
|
||||
export import :Currency;
|
||||
export import :File;
|
||||
export import :Utils;
|
||||
|
||||
#ifdef NOSTRO_BUNQ_ENABLED
|
||||
export import :Bunq;
|
||||
|
|
|
|||
Loading…
Reference in a new issue