51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
|
//SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||
|
//SPDX-License-Identifier: GPL-3.0-or-later
|
||
|
|
||
|
#include "transaction.h"
|
||
|
|
||
|
DB::Transaction::Transaction():
|
||
|
id(0),
|
||
|
initiator(0),
|
||
|
asset(0),
|
||
|
parent(0),
|
||
|
value(0),
|
||
|
modified(0),
|
||
|
performed(0),
|
||
|
notes()
|
||
|
{}
|
||
|
|
||
|
DB::Transaction::Transaction(const std::vector<std::any>& vec):
|
||
|
id(std::any_cast<uint32_t>(vec[0])),
|
||
|
initiator(std::any_cast<uint32_t>(vec[1])),
|
||
|
asset(std::any_cast<uint32_t>(vec[2])),
|
||
|
parent(std::any_cast<uint32_t>(vec[3])),
|
||
|
value(std::any_cast<double>(vec[4])),
|
||
|
modified(std::any_cast<uint32_t>(vec[5])),
|
||
|
performed(std::any_cast<uint32_t>(vec[6])),
|
||
|
notes()
|
||
|
{}
|
||
|
|
||
|
void DB::Transaction::parse(const std::vector<std::any>& vec) {
|
||
|
id = std::any_cast<uint32_t>(vec[0]);
|
||
|
initiator = std::any_cast<uint32_t>(vec[1]);
|
||
|
asset = std::any_cast<uint32_t>(vec[2]);
|
||
|
parent = std::any_cast<uint32_t>(vec[3]);
|
||
|
value = std::any_cast<double>(vec[4]);
|
||
|
modified = std::any_cast<uint32_t>(vec[5]);
|
||
|
performed = std::any_cast<uint32_t>(vec[6]);
|
||
|
}
|
||
|
|
||
|
nlohmann::json DB::Transaction::toJSON() const {
|
||
|
nlohmann::json result = nlohmann::json::object();
|
||
|
|
||
|
result["id"] = id;
|
||
|
result["initiator"] = initiator;
|
||
|
result["asset"] = asset;
|
||
|
result["parent"] = parent;
|
||
|
result["value"] = value;
|
||
|
result["modified"] = modified;
|
||
|
result["performed"] = performed;
|
||
|
|
||
|
return result;
|
||
|
}
|