An app could have nostrod pay an order: it called Pay of net.catcrafts.Nostro1.Checkout on the system bus, and nostrod paid from an account the user had chosen, after a dialog of its own. On 2026-11-22 the owner decided that a link takes its place. The app registers for payto links (RFC 8905), so that an app or a website can hand one to the desktop, and shows a link as its pay form filled in. The link: - The app's desktop entry takes the scheme (Exec=nostro-app %u, MimeType=x-scheme-handler/payto), and nostro-app takes an argument that is no option as a link: it overwrites it in argv and hands it to App::Open once the app has started. - ReadPaymentLink (Nostro.App:Forms) reads payto://iban/<IBAN> with the options amount, receiver-name and message, and refuses a link rather than guess at it, in a sentence of the app's own with nothing of the link in it. Among what it refuses: an IBAN whose check digits do not hold, one of the three options given twice, instruction, a comma in the amount, and a name or a message with a code point that is Unshown, or Blank and no plain space. - A link that is read waits until the accounts are read and DefaultCheckoutAccount has answered or failed, with a line on the accounts' page. Then App::TakeLink fills in the pay form, which says in a banner that a link filled it in, and with more than one account opens it under the choice of accounts that the form's From row has. A link pays nothing: the form's button sends, and polkit's dialog confirms as for any payment (design rule 12, and 14, which is new). - Unshown and Blank are the two tables the worker's Shown() works from. They move into Nostro:Utils, where the app's reader asks them too. The move is within the library. The reader holds a link's name to those two and to no more of Shown(): a name with an & is read, and the dialog shows it with a + as it does any name. The checkout: - nostrod serves one interface under one bus name. Gone are net.catcrafts.Nostro1.Checkout with its XML and its activation file, the polkit action Checkout, the module Nostro.Checkout with --product=checkout, and the worker's record of orders. That changes the published contract after a release, 0.0.0, and design rule 10 records it as the owner's decision. - DefaultCheckoutAccount and SetDefaultCheckoutAccount keep their names and signatures. The account they keep is where a link's pay form starts: nostrod's dialog for choosing it says "have pay links start from", the app's setting reads "Pay links start from", and `nostro checkout account` prints "pay links start from". - The D-Bus policy still lets nostrod own the old name: the nostrod of 0.0.0 asks for it when it starts, and the system files can be newer than the Flatpak it runs from. install.sh removes the old name's activation file. A user's checkouts.cdb is read by nothing any more, and is left where it is. - The Arch package stops installing the checkout's two files, and its pkgrel goes up to 2. Where makepkg -si finds a package of the version already built it installs that one again, which would bring the activation file back. The guide now says that pkgrel goes up with a change to what the package installs. - Bus::Interface goes too: the worker called it in two places, to tell a call to the checkout from one to the main interface. The review's own files follow. gate0 loses the build of --product=checkout, and the three lens sections that named the checkout no longer do, and ask about a link. The README has "Pay links" in place of "Checkout for apps", and AGENTS.consumer.md says what the app reads of a link. Its line on lib/json.hpp no longer gives a release: the file is of none, and the guide names its commit. The pay form and the accounts' page change only by a banner each, shown while a link is in play, which docs/screenshots/take.sh never has: the README's pictures stand. Tests: ShouldValidateForms reads and refuses links and fills the form from one. ShouldDriveTheApp opens links against a real nostrod on the fake bus: before the accounts are known, with no account, with one and with several, with the accounts known and the system bus gone, for a second user whose first connection pays their own accounts only, one that cannot be read, one whose name has an &, and through polkit's dialog to the payment. It now counts nostrod's answers to hold that the account pay links start from is read again once a connection is removed: the check it had there passed without that. ShouldHandleMoneyAndText holds the two tables at the ends of their ranges. ShouldServeEveryUser holds that nostrod serves no checkout, that the bus's policy lets an older nostrod own the old name, and the account pay links start from. ShouldRunCommands holds the CLI's wording. The review's gate0 passes at this commit: the version check, 17 tests, the builds of the CLI, the library, nostrod, the fake system, the app and its --debug-api build, and five lint runs that report nothing. tests/coverage.sh reports lines, functions and regions at 100.00%. Looked at on 2026-11-22 on the made-up system (run fake), on a desktop (KWin at a scale of 1.85). At 420x760, at --scale 3 --size 360x760 and at 1100x720 in the light look: a link's pay form under the choice of accounts, the form after a tap beside that choice, and the accounts' page while a link waits, its line above the rows that stand in for the accounts (--bank-delay 10000). At 420x760: that line above what the page says when the accounts cannot be read (--polkit deny) and above the accounts themselves (--polkit slow, the link opened in the running app), the settings' row and page for the account pay links start from, the sheet for a link that cannot be read, and with --empty the sheet for no account.
557 lines
20 KiB
C++
557 lines
20 KiB
C++
// SPDX-License-Identifier: LGPL-3.0-only
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
|
|
|
module;
|
|
|
|
#include <errno.h>
|
|
#include <systemd/sd-bus.h>
|
|
|
|
module Nostro:Bus_impl;
|
|
import std;
|
|
import :Bus;
|
|
import :Account;
|
|
import :Bunq;
|
|
import :Currency;
|
|
import :Transaction;
|
|
|
|
using namespace Nostro;
|
|
using namespace Nostro::Bus;
|
|
|
|
std::int32_t Bus::ThrowOnSdBus(std::int32_t result, std::string_view what) {
|
|
if(result < 0) {
|
|
throw std::system_error(-result, std::generic_category(), std::format("cannot {}", what));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
namespace {
|
|
// A C string sd-bus handed out, as a string; null is empty.
|
|
// lint-disable-next-line no-char-pointer
|
|
std::string Text(const char* text) {
|
|
return text ? std::string(text) : std::string();
|
|
}
|
|
}
|
|
|
|
std::string Bus::Sender(sd_bus_message* message) {
|
|
return Text(sd_bus_message_get_sender(message));
|
|
}
|
|
|
|
std::string Bus::Member(sd_bus_message* message) {
|
|
return Text(sd_bus_message_get_member(message));
|
|
}
|
|
|
|
std::string Bus::ErrorName(const sd_bus_error& error) {
|
|
return Text(error.name);
|
|
}
|
|
|
|
std::string Bus::ErrorMessage(const sd_bus_error& error) {
|
|
return Text(error.message);
|
|
}
|
|
|
|
bool Bus::IsSensitive(std::string_view member) {
|
|
return std::ranges::any_of(methods, [member](const Method& method) { return method.member == member && method.sensitive; });
|
|
}
|
|
|
|
std::string Bus::ReadText(sd_bus_message* message, char type) {
|
|
// sd-bus hands out strings as C strings into the message, valid while it lives.
|
|
// lint-disable-next-line no-char-pointer
|
|
const char* value = nullptr;
|
|
ThrowOnSdBus(sd_bus_message_read_basic(message, type, &value), "read a string");
|
|
return Text(value);
|
|
}
|
|
|
|
void Bus::BusUnref::operator()(sd_bus* bus) const {
|
|
sd_bus_flush_close_unref(bus);
|
|
}
|
|
|
|
void Bus::MessageUnref::operator()(sd_bus_message* message) const {
|
|
sd_bus_message_unref(message);
|
|
}
|
|
|
|
Bus::Error::~Error() {
|
|
sd_bus_error_free(&error);
|
|
}
|
|
|
|
std::vector<sd_bus_vtable> Bus::Vtable(std::span<const Method> table, const std::function<sd_bus_message_handler_t(std::string_view member)>& handler) {
|
|
std::vector<sd_bus_vtable> vtable = {SD_BUS_VTABLE_START(0)};
|
|
for(const Method& method : table) {
|
|
const std::uint64_t flags = SD_BUS_VTABLE_UNPRIVILEGED | (method.sensitive ? SD_BUS_VTABLE_SENSITIVE : 0);
|
|
sd_bus_vtable entry = SD_BUS_METHOD_WITH_NAMES_OFFSET(method.member.data(), method.in.data(), "", method.out.data(), "", handler(method.member), 0, flags);
|
|
// The names of the arguments and of the reply, which the macro would only take as literals to join.
|
|
entry.x.method.names = method.names.data();
|
|
vtable.push_back(entry);
|
|
}
|
|
vtable.push_back(SD_BUS_VTABLE_END);
|
|
return vtable;
|
|
}
|
|
|
|
void Bus::Enter(sd_bus_message* message, char type, std::string_view contents) {
|
|
// Every message was checked against its signature before it got here, so the container is there.
|
|
ThrowOnSdBus(sd_bus_message_enter_container(message, type, std::string(contents).c_str()), "read a container");
|
|
}
|
|
|
|
void Bus::Leave(sd_bus_message* message) {
|
|
ThrowOnSdBus(sd_bus_message_exit_container(message), "leave a container");
|
|
}
|
|
|
|
void Bus::Open(sd_bus_message* message, char type, std::string_view contents) {
|
|
ThrowOnSdBus(sd_bus_message_open_container(message, type, std::string(contents).c_str()), "open a container");
|
|
}
|
|
|
|
void Bus::Close(sd_bus_message* message) {
|
|
ThrowOnSdBus(sd_bus_message_close_container(message), "close a container");
|
|
}
|
|
|
|
namespace {
|
|
// A basic value, or an exception when the message holds something else or has ended.
|
|
template<typename T>
|
|
T ReadBasic(sd_bus_message* message, char type) {
|
|
T value{};
|
|
ThrowOnSdBus(sd_bus_message_read_basic(message, type, &value), "read a value");
|
|
return value;
|
|
}
|
|
|
|
std::chrono::system_clock::time_point FromMicroseconds(std::int64_t microseconds) {
|
|
return std::chrono::system_clock::time_point(std::chrono::microseconds(microseconds));
|
|
}
|
|
|
|
std::int64_t ToMicroseconds(std::chrono::system_clock::time_point time) {
|
|
return std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();
|
|
}
|
|
}
|
|
|
|
void Bus::Wire<std::string>::Append(sd_bus_message* message, const std::string& value) {
|
|
// D-Bus carries UTF-8 only: sd-bus refuses anything else.
|
|
const std::int32_t result = sd_bus_message_append_basic(message, 's', value.c_str());
|
|
if(result == -EINVAL) {
|
|
throw std::invalid_argument("text that is not UTF-8 cannot be sent to nostrod");
|
|
}
|
|
ThrowOnSdBus(result, "append a string");
|
|
}
|
|
|
|
std::string Bus::Wire<std::string>::Read(sd_bus_message* message) {
|
|
return ReadText(message, 's');
|
|
}
|
|
|
|
void Bus::Wire<bool>::Append(sd_bus_message* message, bool value) {
|
|
const std::int32_t b = value ? 1 : 0;
|
|
ThrowOnSdBus(sd_bus_message_append_basic(message, 'b', &b), "append a boolean");
|
|
}
|
|
|
|
bool Bus::Wire<bool>::Read(sd_bus_message* message) {
|
|
return ReadBasic<std::int32_t>(message, 'b') != 0;
|
|
}
|
|
|
|
void Bus::Wire<std::uint32_t>::Append(sd_bus_message* message, std::uint32_t value) {
|
|
ThrowOnSdBus(sd_bus_message_append_basic(message, 'u', &value), "append a number");
|
|
}
|
|
|
|
std::uint32_t Bus::Wire<std::uint32_t>::Read(sd_bus_message* message) {
|
|
return ReadBasic<std::uint32_t>(message, 'u');
|
|
}
|
|
|
|
void Bus::Wire<std::int64_t>::Append(sd_bus_message* message, std::int64_t value) {
|
|
ThrowOnSdBus(sd_bus_message_append_basic(message, 'x', &value), "append a number");
|
|
}
|
|
|
|
std::int64_t Bus::Wire<std::int64_t>::Read(sd_bus_message* message) {
|
|
return ReadBasic<std::int64_t>(message, 'x');
|
|
}
|
|
|
|
void Bus::Wire<std::uint64_t>::Append(sd_bus_message* message, std::uint64_t value) {
|
|
ThrowOnSdBus(sd_bus_message_append_basic(message, 't', &value), "append a number");
|
|
}
|
|
|
|
std::uint64_t Bus::Wire<std::uint64_t>::Read(sd_bus_message* message) {
|
|
return ReadBasic<std::uint64_t>(message, 't');
|
|
}
|
|
|
|
void Bus::Wire<std::chrono::system_clock::time_point>::Append(sd_bus_message* message, std::chrono::system_clock::time_point value) {
|
|
Wire<std::int64_t>::Append(message, ToMicroseconds(value));
|
|
}
|
|
|
|
std::chrono::system_clock::time_point Bus::Wire<std::chrono::system_clock::time_point>::Read(sd_bus_message* message) {
|
|
return FromMicroseconds(Wire<std::int64_t>::Read(message));
|
|
}
|
|
|
|
void Bus::Wire<Currency>::Append(sd_bus_message* message, Currency value) {
|
|
Wire<std::string>::Append(message, std::string(GetCurrencyCode(value)));
|
|
}
|
|
|
|
Currency Bus::Wire<Currency>::Read(sd_bus_message* message) {
|
|
return GetCurrency(Wire<std::string>::Read(message));
|
|
}
|
|
|
|
void Bus::Wire<Account>::Append(sd_bus_message* message, const Account& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.name);
|
|
Bus::Append(message, value.bic);
|
|
Bus::Append(message, value.iban);
|
|
Bus::Append(message, value.currency);
|
|
Bus::Append(message, value.balance);
|
|
Close(message);
|
|
}
|
|
|
|
Account Bus::Wire<Account>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
Account value{};
|
|
value.name = Bus::Read<std::string>(message);
|
|
value.bic = Bus::Read<std::string>(message);
|
|
value.iban = Bus::Read<std::string>(message);
|
|
value.currency = Bus::Read<Currency>(message);
|
|
value.balance = Bus::Read<std::int64_t>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::Wire<Transaction>::Append(sd_bus_message* message, const Transaction& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.name);
|
|
Bus::Append(message, value.bic);
|
|
Bus::Append(message, value.iban);
|
|
Bus::Append(message, value.description);
|
|
Bus::Append(message, value.currency);
|
|
Bus::Append(message, value.amount);
|
|
Bus::Append(message, value.timePoint);
|
|
Bus::Append(message, value.id);
|
|
Bus::Append(message, value.kind);
|
|
Close(message);
|
|
}
|
|
|
|
Transaction Bus::Wire<Transaction>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
Transaction value{};
|
|
value.name = Bus::Read<std::string>(message);
|
|
value.bic = Bus::Read<std::string>(message);
|
|
value.iban = Bus::Read<std::string>(message);
|
|
value.description = Bus::Read<std::string>(message);
|
|
value.currency = Bus::Read<Currency>(message);
|
|
value.amount = Bus::Read<std::int64_t>(message);
|
|
value.timePoint = Bus::Read<std::chrono::system_clock::time_point>(message);
|
|
value.id = Bus::Read<std::string>(message);
|
|
value.kind = Bus::Read<std::string>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::Wire<BunqLabel>::Append(sd_bus_message* message, const BunqLabel& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.name);
|
|
Bus::Append(message, value.iban);
|
|
Close(message);
|
|
}
|
|
|
|
BunqLabel Bus::Wire<BunqLabel>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
BunqLabel value;
|
|
value.name = Bus::Read<std::string>(message);
|
|
value.iban = Bus::Read<std::string>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::Wire<BunqPaymentRequest>::Append(sd_bus_message* message, const BunqPaymentRequest& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.id);
|
|
Bus::Append(message, value.status);
|
|
Bus::Append(message, value.counterparty);
|
|
Bus::Append(message, value.currency);
|
|
Bus::Append(message, value.amount);
|
|
Bus::Append(message, value.amountPaid);
|
|
Bus::Append(message, value.description);
|
|
Bus::Append(message, value.created);
|
|
Bus::Append(message, value.shareUrl);
|
|
Close(message);
|
|
}
|
|
|
|
BunqPaymentRequest Bus::Wire<BunqPaymentRequest>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
BunqPaymentRequest value{};
|
|
value.id = Bus::Read<std::uint64_t>(message);
|
|
value.status = Bus::Read<std::string>(message);
|
|
value.counterparty = Bus::Read<BunqLabel>(message);
|
|
value.currency = Bus::Read<Currency>(message);
|
|
value.amount = Bus::Read<std::int64_t>(message);
|
|
value.amountPaid = Bus::Read<std::optional<std::int64_t>>(message);
|
|
value.description = Bus::Read<std::string>(message);
|
|
value.created = Bus::Read<std::chrono::system_clock::time_point>(message);
|
|
value.shareUrl = Bus::Read<std::string>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::Wire<BunqIncomingRequest>::Append(sd_bus_message* message, const BunqIncomingRequest& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.id);
|
|
Bus::Append(message, value.status);
|
|
Bus::Append(message, value.type);
|
|
Bus::Append(message, value.counterparty);
|
|
Bus::Append(message, value.currency);
|
|
Bus::Append(message, value.amount);
|
|
Bus::Append(message, value.description);
|
|
Bus::Append(message, value.created);
|
|
Close(message);
|
|
}
|
|
|
|
BunqIncomingRequest Bus::Wire<BunqIncomingRequest>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
BunqIncomingRequest value{};
|
|
value.id = Bus::Read<std::uint64_t>(message);
|
|
value.status = Bus::Read<std::string>(message);
|
|
value.type = Bus::Read<std::string>(message);
|
|
value.counterparty = Bus::Read<BunqLabel>(message);
|
|
value.currency = Bus::Read<Currency>(message);
|
|
value.amount = Bus::Read<std::int64_t>(message);
|
|
value.description = Bus::Read<std::string>(message);
|
|
value.created = Bus::Read<std::chrono::system_clock::time_point>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::Wire<BunqSchedule>::Append(sd_bus_message* message, const BunqSchedule& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.start);
|
|
Bus::Append(message, value.end);
|
|
Bus::Append(message, value.unit);
|
|
Bus::Append(message, value.every);
|
|
Bus::Append(message, value.status);
|
|
Bus::Append(message, value.next);
|
|
Close(message);
|
|
}
|
|
|
|
BunqSchedule Bus::Wire<BunqSchedule>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
BunqSchedule value;
|
|
value.start = Bus::Read<std::chrono::system_clock::time_point>(message);
|
|
value.end = Bus::Read<std::optional<std::chrono::system_clock::time_point>>(message);
|
|
value.unit = Bus::Read<std::string>(message);
|
|
value.every = Bus::Read<std::uint32_t>(message);
|
|
value.status = Bus::Read<std::string>(message);
|
|
value.next = Bus::Read<std::optional<std::chrono::system_clock::time_point>>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::Wire<BunqScheduledPayment>::Append(sd_bus_message* message, const BunqScheduledPayment& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.id);
|
|
Bus::Append(message, value.counterparty);
|
|
Bus::Append(message, value.currency);
|
|
Bus::Append(message, value.amount);
|
|
Bus::Append(message, value.description);
|
|
Bus::Append(message, value.schedule);
|
|
Close(message);
|
|
}
|
|
|
|
BunqScheduledPayment Bus::Wire<BunqScheduledPayment>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
BunqScheduledPayment value{};
|
|
value.id = Bus::Read<std::uint64_t>(message);
|
|
value.counterparty = Bus::Read<BunqLabel>(message);
|
|
value.currency = Bus::Read<Currency>(message);
|
|
value.amount = Bus::Read<std::int64_t>(message);
|
|
value.description = Bus::Read<std::string>(message);
|
|
value.schedule = Bus::Read<BunqSchedule>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::Wire<BunqDraftPayment::Entry>::Append(sd_bus_message* message, const BunqDraftPayment::Entry& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.counterparty);
|
|
Bus::Append(message, value.currency);
|
|
Bus::Append(message, value.amount);
|
|
Bus::Append(message, value.description);
|
|
Close(message);
|
|
}
|
|
|
|
BunqDraftPayment::Entry Bus::Wire<BunqDraftPayment::Entry>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
BunqDraftPayment::Entry value{};
|
|
value.counterparty = Bus::Read<BunqLabel>(message);
|
|
value.currency = Bus::Read<Currency>(message);
|
|
value.amount = Bus::Read<std::int64_t>(message);
|
|
value.description = Bus::Read<std::string>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::Wire<BunqDraftPayment>::Append(sd_bus_message* message, const BunqDraftPayment& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.id);
|
|
Bus::Append(message, value.status);
|
|
Bus::Append(message, value.createdBy);
|
|
Bus::Append(message, value.entries);
|
|
Bus::Append(message, value.updated);
|
|
Close(message);
|
|
}
|
|
|
|
BunqDraftPayment Bus::Wire<BunqDraftPayment>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
BunqDraftPayment value{};
|
|
value.id = Bus::Read<std::uint64_t>(message);
|
|
value.status = Bus::Read<std::string>(message);
|
|
value.createdBy = Bus::Read<std::string>(message);
|
|
value.entries = Bus::Read<std::vector<BunqDraftPayment::Entry>>(message);
|
|
value.updated = Bus::Read<std::string>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::Wire<BunqCard>::Append(sd_bus_message* message, const BunqCard& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.id);
|
|
Bus::Append(message, value.kind);
|
|
Bus::Append(message, value.productType);
|
|
Bus::Append(message, value.status);
|
|
Bus::Append(message, value.orderStatus);
|
|
Bus::Append(message, value.nameOnCard);
|
|
Bus::Append(message, value.secondLine);
|
|
Bus::Append(message, value.lastFour);
|
|
Bus::Append(message, value.expiry);
|
|
Bus::Append(message, value.iban);
|
|
Close(message);
|
|
}
|
|
|
|
BunqCard Bus::Wire<BunqCard>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
BunqCard value{};
|
|
value.id = Bus::Read<std::uint64_t>(message);
|
|
value.kind = Bus::Read<std::string>(message);
|
|
value.productType = Bus::Read<std::string>(message);
|
|
value.status = Bus::Read<std::string>(message);
|
|
value.orderStatus = Bus::Read<std::string>(message);
|
|
value.nameOnCard = Bus::Read<std::string>(message);
|
|
value.secondLine = Bus::Read<std::string>(message);
|
|
value.lastFour = Bus::Read<std::string>(message);
|
|
value.expiry = Bus::Read<std::string>(message);
|
|
value.iban = Bus::Read<std::string>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::Wire<ConnectorSummary>::Append(sd_bus_message* message, const ConnectorSummary& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.name);
|
|
Bus::Append(message, value.bank);
|
|
Bus::Append(message, value.environment);
|
|
Bus::Append(message, value.auth);
|
|
Bus::Append(message, value.working);
|
|
Close(message);
|
|
}
|
|
|
|
ConnectorSummary Bus::Wire<ConnectorSummary>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
ConnectorSummary value;
|
|
value.name = Bus::Read<std::string>(message);
|
|
value.bank = Bus::Read<std::string>(message);
|
|
value.environment = Bus::Read<std::string>(message);
|
|
value.auth = Bus::Read<std::string>(message);
|
|
value.working = Bus::Read<bool>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::Wire<ConnectorAccounts>::Append(sd_bus_message* message, const ConnectorAccounts& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.name);
|
|
Bus::Append(message, value.bank);
|
|
Bus::Append(message, value.accounts);
|
|
Close(message);
|
|
}
|
|
|
|
ConnectorAccounts Bus::Wire<ConnectorAccounts>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
ConnectorAccounts value;
|
|
value.name = Bus::Read<std::string>(message);
|
|
value.bank = Bus::Read<std::string>(message);
|
|
value.accounts = Bus::Read<std::vector<Account>>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::Wire<ConnectorCards>::Append(sd_bus_message* message, const ConnectorCards& value) {
|
|
Open(message, 'r', contents);
|
|
Bus::Append(message, value.name);
|
|
Bus::Append(message, value.bank);
|
|
Bus::Append(message, value.cards);
|
|
Close(message);
|
|
}
|
|
|
|
ConnectorCards Bus::Wire<ConnectorCards>::Read(sd_bus_message* message) {
|
|
Enter(message, 'r', contents);
|
|
ConnectorCards value;
|
|
value.name = Bus::Read<std::string>(message);
|
|
value.bank = Bus::Read<std::string>(message);
|
|
value.cards = Bus::Read<std::vector<BunqCard>>(message);
|
|
Leave(message);
|
|
return value;
|
|
}
|
|
|
|
void Bus::AppendQuery(sd_bus_message* message, const TransactionQuery& query) {
|
|
Open(message, 'a', "{sv}");
|
|
const auto entry = [message](std::string_view key, std::string_view type, const auto& value) {
|
|
Open(message, 'e', "sv");
|
|
Bus::Append(message, std::string(key));
|
|
Open(message, 'v', type);
|
|
Bus::Append(message, value);
|
|
Close(message);
|
|
Close(message);
|
|
};
|
|
if(!query.search.empty()) {
|
|
entry("search", "s", query.search);
|
|
}
|
|
if(query.amount) {
|
|
entry("amount", "x", *query.amount);
|
|
}
|
|
if(query.from != std::chrono::system_clock::time_point::min()) {
|
|
entry("from", "x", query.from);
|
|
}
|
|
if(query.to != std::chrono::system_clock::time_point::max()) {
|
|
entry("to", "x", query.to);
|
|
}
|
|
entry("limit", "t", static_cast<std::uint64_t>(query.limit));
|
|
if(query.stored) {
|
|
entry("stored", "b", true);
|
|
}
|
|
Close(message);
|
|
}
|
|
|
|
TransactionQuery Bus::ReadQuery(sd_bus_message* message) {
|
|
TransactionQuery query;
|
|
Enter(message, 'a', "{sv}");
|
|
while(ThrowOnSdBus(sd_bus_message_at_end(message, 0), "read a query") == 0) {
|
|
Enter(message, 'e', "sv");
|
|
const std::string key = Bus::Read<std::string>(message);
|
|
if(key == "search") {
|
|
Enter(message, 'v', "s");
|
|
query.search = Bus::Read<std::string>(message);
|
|
Leave(message);
|
|
} else if(key == "amount") {
|
|
Enter(message, 'v', "x");
|
|
query.amount = Bus::Read<std::int64_t>(message);
|
|
Leave(message);
|
|
} else if(key == "from") {
|
|
Enter(message, 'v', "x");
|
|
query.from = Bus::Read<std::chrono::system_clock::time_point>(message);
|
|
Leave(message);
|
|
} else if(key == "to") {
|
|
Enter(message, 'v', "x");
|
|
query.to = Bus::Read<std::chrono::system_clock::time_point>(message);
|
|
Leave(message);
|
|
} else if(key == "limit") {
|
|
Enter(message, 'v', "t");
|
|
query.limit = Bus::Read<std::uint64_t>(message);
|
|
Leave(message);
|
|
} else if(key == "stored") {
|
|
Enter(message, 'v', "b");
|
|
query.stored = Bus::Read<bool>(message);
|
|
Leave(message);
|
|
} else {
|
|
ThrowOnSdBus(sd_bus_message_skip(message, "v"), "skip an unknown query key");
|
|
}
|
|
Leave(message);
|
|
}
|
|
Leave(message);
|
|
return query;
|
|
}
|