First ideas over transaction
This commit is contained in:
parent
4914a467e5
commit
973deaefd9
6 changed files with 133 additions and 0 deletions
|
@ -5,12 +5,14 @@ set(HEADERS
|
|||
session.h
|
||||
asset.h
|
||||
currency.h
|
||||
transaction.h
|
||||
)
|
||||
|
||||
set(SOURCES
|
||||
session.cpp
|
||||
asset.cpp
|
||||
currency.cpp
|
||||
transaction.cpp
|
||||
)
|
||||
|
||||
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
|
||||
|
|
50
database/schema/transaction.cpp
Normal file
50
database/schema/transaction.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
//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;
|
||||
}
|
35
database/schema/transaction.h
Normal file
35
database/schema/transaction.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
//SPDX-FileCopyrightText: 2024 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <any>
|
||||
#include <cstdint>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace DB {
|
||||
class Transaction {
|
||||
public:
|
||||
Transaction ();
|
||||
Transaction (const std::vector<std::any>& vec);
|
||||
|
||||
void parse (const std::vector<std::any>& vec);
|
||||
nlohmann::json toJSON () const;
|
||||
|
||||
public:
|
||||
uint32_t id;
|
||||
uint32_t initiator;
|
||||
// `type` INTEGER UNSIGNED NOT NULL,
|
||||
uint32_t asset;
|
||||
uint32_t parent;
|
||||
double value;
|
||||
// `state` INTEGER UNSIGNED DEFAULT 0,
|
||||
uint32_t modified;
|
||||
uint32_t performed;
|
||||
// `party` INTEGER UNSIGNED,
|
||||
std::string notes;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue