fixed http request types

reformatted sources
This commit is contained in:
gulliver 2022-12-11 17:04:21 +01:00
parent ce784c38dd
commit 79094c8a6d
3 changed files with 371 additions and 334 deletions

View File

@ -1,94 +1,127 @@
#include "crow.h" #include "crow.h"
#include "crow/common.h"
#include "crow/http_parser_merged.h"
#include "crow/http_response.h"
#include "model.hpp" #include "model.hpp"
int main() int main() {
{
crow::SimpleApp app; crow::SimpleApp app;
std::shared_ptr<Model> model = Model::getModel("simple"); std::shared_ptr<Model> model = Model::getModel("simple");
CROW_ROUTE(app, "/cddc") CROW_ROUTE(app, "/cddc")
([&model](const crow::request& req){ .methods(crow::HTTPMethod::POST)([&model](const crow::request &req) {
auto req_cddc = RequestCDDC::from_string(req.body); auto req_cddc = RequestCDDC::from_string(req.body);
if (!req_cddc) { if (!req_cddc) {
return crow::response(crow::status::BAD_REQUEST); return crow::response(crow::status::BAD_REQUEST);
} else { } else {
ResponseCDDC res; ResponseCDDC res;
// TBD use serial from req
res.cddc = model->getCDDC();
res.message_reference = req_cddc->message_reference; res.message_reference = req_cddc->message_reference;
auto cddc = model->getCDDC(req_cddc->cdd_serial);
if (!cddc) {
res.status_code = crow::status::NOT_FOUND;
} else {
res.cddc = *cddc.value();
res.status_code = crow::status::OK; res.status_code = crow::status::OK;
}
return crow::response(res.to_json()); return crow::response(res.to_json());
} }
}); });
CROW_ROUTE(app, "/cddc/serial") CROW_ROUTE(app, "/cddc/serial")
([&model](const crow::request& request){ .methods(crow::HTTPMethod::POST)([&model](const crow::request &request) {
auto req = RequestCDDSerial::from_string(request.body); auto req = RequestCDDSerial::from_string(request.body);
if (!req) { if (!req) {
return crow::response(crow::status::BAD_REQUEST); return crow::response(crow::status::BAD_REQUEST);
} else { } else {
// \todo check serial input
ResponseCDDSerial res; ResponseCDDSerial res;
res.cdd_serial = model->getCurrentCDDC().cdd.cdd_serial;
res.message_reference = req->message_reference; res.message_reference = req->message_reference;
auto cddc = model->getCurrentCDDC();
if (!cddc) {
res.status_code = crow::status::NOT_FOUND;
} else {
res.cdd_serial = (*cddc)->cdd.cdd_serial;
res.status_code = crow::status::OK; res.status_code = crow::status::OK;
}
return crow::response(res.to_json()); return crow::response(res.to_json());
} }
}); });
CROW_ROUTE(app, "/mkcs") CROW_ROUTE(app, "/mkcs")
([&model](const crow::request& request){ .methods(crow::HTTPMethod::POST)([&model](const crow::request &request) {
auto req = RequestMKCs::from_string(request.body); auto req = RequestMKCs::from_string(request.body);
if (!req) { if (!req) {
return crow::response(crow::status::BAD_REQUEST); return crow::response(crow::status::BAD_REQUEST);
} else { } else {
// \todo implement request ResponseMKCs res;
return crow::response(crow::status::NOT_IMPLEMENTED); res.message_reference = req->message_reference;
res.keys = model->getMKCs(req->denominations, req->mint_key_ids);
res.status_code = crow::status::OK;
return crow::response(res.to_json());
} }
}); });
CROW_ROUTE(app, "/mint").methods(crow::HTTPMethod::GET) CROW_ROUTE(app, "/mint")
([&model](const crow::request& request){ .methods(crow::HTTPMethod::POST)([&model](const crow::request &request) {
auto req = RequestMint::from_string(request.body); auto req = RequestMint::from_string(request.body);
if (!req) { if (!req) {
return crow::response(crow::status::BAD_REQUEST); return crow::response(crow::status::BAD_REQUEST);
} else { } else {
// \todo implement request ResponseMint res;
return crow::response(crow::status::NOT_IMPLEMENTED); res.message_reference = req->message_reference;
auto minted = model->mint(req->transaction_reference, req->blinds);
res.blind_signatures = minted;
res.status_code = crow::status::OK;
return crow::response(res.to_json());
} }
}); });
CROW_ROUTE(app, "/renew")
CROW_ROUTE(app, "/renew").methods(crow::HTTPMethod::GET) .methods(crow::HTTPMethod::POST)([&model](const crow::request &request) {
([&model](const crow::request& request){ auto req = RequestRenew::from_string(request.body);
auto req = RequestMint::from_string(request.body);
if (!req) { if (!req) {
return crow::response(crow::status::BAD_REQUEST); return crow::response(crow::status::BAD_REQUEST);
} else { } else {
// \todo implement request // \todo implement ResponseDelay
return crow::response(crow::status::NOT_IMPLEMENTED); ResponseMint res;
res.message_reference = req->message_reference;
res.status_code = crow::status::OK;
res.blind_signatures =
model->mint(req->transaction_reference, req->blinds);
return crow::response(res.to_json());
} }
}); });
CROW_ROUTE(app, "/resume").methods(crow::HTTPMethod::GET) CROW_ROUTE(app, "/resume")
([&model](const crow::request& request){ .methods(crow::HTTPMethod::POST)([](const crow::request &request) {
auto req = RequestResume::from_string(request.body); auto req = RequestResume::from_string(request.body);
if (!req) { if (!req) {
return crow::response(crow::status::BAD_REQUEST); return crow::response(crow::status::BAD_REQUEST);
} else { } else {
// \todo implement request // \todo implement request
ResponseMint res;
res.message_reference = req->message_reference;
res.status_code = crow::status::NOT_IMPLEMENTED; // crow::status::OK;
return crow::response(crow::status::NOT_IMPLEMENTED); return crow::response(crow::status::NOT_IMPLEMENTED);
} }
}); });
CROW_ROUTE(app, "/redeem").methods(crow::HTTPMethod::GET) CROW_ROUTE(app, "/redeem")
([&model](const crow::request& request){ .methods(crow::HTTPMethod::POST)([&model](const crow::request &request) {
auto req = RequestRedeem::from_string(request.body); auto req = RequestRedeem::from_string(request.body);
if (!req) { if (!req) {
return crow::response(crow::status::BAD_REQUEST); return crow::response(crow::status::BAD_REQUEST);
} else { } else {
// \todo implement request ResponseRedeem res;
return crow::response(crow::status::NOT_IMPLEMENTED); res.message_reference = req->message_reference;
bool success = model->redeem(req->coins);
res.status_code =
success ? crow::status::OK : crow::status::NOT_FOUND;
return crow::response(res.to_json());
} }
}); });

View File

@ -20,7 +20,6 @@ crow::json::wvalue list_to_json(const std::vector<unsigned int>& array) {
return crow::json::wvalue(l); return crow::json::wvalue(l);
} }
crow::json::wvalue PublicKey::to_json() const { crow::json::wvalue PublicKey::to_json() const {
crow::json::wvalue r; crow::json::wvalue r;
TO_JSON(modulus); TO_JSON(modulus);
@ -29,8 +28,7 @@ crow::json::wvalue PublicKey::to_json() const {
return r; return r;
} }
crow::json::wvalue WeightedUrl::to_json() const crow::json::wvalue WeightedUrl::to_json() const {
{
crow::json::wvalue::list l; crow::json::wvalue::list l;
crow::json::wvalue w(weight); crow::json::wvalue w(weight);
@ -88,7 +86,6 @@ crow::json::wvalue MintKey::to_json() const {
return r; return r;
} }
crow::json::wvalue MintKeyCert::to_json() const { crow::json::wvalue MintKeyCert::to_json() const {
crow::json::wvalue r; crow::json::wvalue r;
TO_JSON_JSON(mint_key); TO_JSON_JSON(mint_key);
@ -97,8 +94,7 @@ crow::json::wvalue MintKeyCert::to_json() const {
return r; return r;
} }
crow::json::wvalue Response::to_json() const crow::json::wvalue Response::to_json() const {
{
crow::json::wvalue r; crow::json::wvalue r;
TO_JSON(message_reference); TO_JSON(message_reference);
TO_JSON(status_code); TO_JSON(status_code);
@ -106,9 +102,7 @@ crow::json::wvalue Response::to_json() const
return r; return r;
} }
crow::json::wvalue ResponseCDDSerial::to_json() const {
crow::json::wvalue ResponseCDDSerial::to_json() const
{
crow::json::wvalue r = Response::to_json(); crow::json::wvalue r = Response::to_json();
TO_JSON(cdd_serial); TO_JSON(cdd_serial);
@ -117,8 +111,7 @@ crow::json::wvalue ResponseCDDSerial::to_json() const
} }
tl::expected<RequestCDDSerial, eError> tl::expected<RequestCDDSerial, eError>
RequestCDDSerial::from_string(const std::string& str) RequestCDDSerial::from_string(const std::string &str) {
{
auto json = crow::json::load(str); auto json = crow::json::load(str);
if (!json) { if (!json) {
return tl::make_unexpected(eError::JSON_PARSE_ERROR); return tl::make_unexpected(eError::JSON_PARSE_ERROR);
@ -133,8 +126,7 @@ RequestCDDSerial::from_string(const std::string& str)
} }
} }
crow::json::wvalue ResponseCDDC::to_json() const crow::json::wvalue ResponseCDDC::to_json() const {
{
crow::json::wvalue r = Response::to_json(); crow::json::wvalue r = Response::to_json();
TO_JSON_JSON(cddc); TO_JSON_JSON(cddc);
r["type"] = "response cdd serial"; r["type"] = "response cdd serial";
@ -142,15 +134,12 @@ crow::json::wvalue ResponseCDDC::to_json() const
} }
tl::expected<RequestCDDC, eError> tl::expected<RequestCDDC, eError>
RequestCDDC::from_string(const std::string& str) RequestCDDC::from_string(const std::string &str) {
{
auto json = crow::json::load(str); auto json = crow::json::load(str);
if (!json) { if (!json) {
return tl::make_unexpected(eError::JSON_PARSE_ERROR); return tl::make_unexpected(eError::JSON_PARSE_ERROR);
} else if ( !( json.has("type") } else if (!(json.has("type") && json.has("message_reference") &&
&& json.has("message_reference") json.has("cdd_serial"))) {
&& json.has("cdd_serial")
) ) {
return tl::make_unexpected(eError::JSON_MISSING_KEY); return tl::make_unexpected(eError::JSON_MISSING_KEY);
} else if (json["type"] != "request cddc") { } else if (json["type"] != "request cddc") {
return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE); return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE);
@ -167,11 +156,8 @@ RequestMKCs::from_string(const std::string& str) {
auto json = crow::json::load(str); auto json = crow::json::load(str);
if (!json) { if (!json) {
return tl::make_unexpected(eError::JSON_PARSE_ERROR); return tl::make_unexpected(eError::JSON_PARSE_ERROR);
} else if ( !(json.has("denominations") } else if (!(json.has("denominations") && json.has("message_reference") &&
&& json.has("message_reference") json.has("mint_key_ids") && json.has("type"))) {
&& json.has("mint_key_ids")
&& json.has("type")
) ) {
return tl::make_unexpected(eError::JSON_MISSING_KEY); return tl::make_unexpected(eError::JSON_MISSING_KEY);
} else if (json["type"] != "request mint key certificates") { } else if (json["type"] != "request mint key certificates") {
return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE); return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE);
@ -199,7 +185,6 @@ RequestMKCs::from_string(const std::string& str) {
} }
} }
crow::json::wvalue ResponseMKCs::to_json() const { crow::json::wvalue ResponseMKCs::to_json() const {
crow::json::wvalue r = Response::to_json(); crow::json::wvalue r = Response::to_json();
TO_JSON_ARRAY(keys); TO_JSON_ARRAY(keys);
@ -216,13 +201,9 @@ crow::json::wvalue Blind::to_json() const {
return r; return r;
} }
tl::expected<Blind,eError> Blind::from_json(const crow::json::rvalue& json) tl::expected<Blind, eError> Blind::from_json(const crow::json::rvalue &json) {
{ if (!(json.has("type") && json.has("blinded_payload_hash") &&
if ( !( json.has("type") json.has("mint_key_id") && json.has("reference"))) {
&& json.has("blinded_payload_hash")
&& json.has("mint_key_id")
&& json.has("reference")
) ) {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
} else if (json["type"] != "blinded payload hash") { } else if (json["type"] != "blinded payload hash") {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
@ -241,7 +222,6 @@ crow::json::wvalue BlindSignature::to_json() const {
TO_JSON(reference); TO_JSON(reference);
r["type"] = "blind signature"; r["type"] = "blind signature";
return r; return r;
} }
tl::expected<RequestMint, eError> tl::expected<RequestMint, eError>
@ -251,11 +231,8 @@ RequestMint::from_string(const std::string& str){
auto json = crow::json::load(str); auto json = crow::json::load(str);
if (!json) { if (!json) {
return tl::make_unexpected(eError::JSON_PARSE_ERROR); return tl::make_unexpected(eError::JSON_PARSE_ERROR);
} else if ( !( json.has("type") } else if (!(json.has("type") && json.has("message_reference") &&
&& json.has("message_reference") json.has("transaction_reference") && json.has("blinds"))) {
&& json.has("transaction_reference")
&& json.has("blinds")
) ) {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
} else if (json["type"] != "request mint") { } else if (json["type"] != "request mint") {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
@ -299,8 +276,7 @@ crow::json::wvalue Coin::Payload::to_json() const {
return r; return r;
} }
crow::json::wvalue Coin::to_json() const crow::json::wvalue Coin::to_json() const {
{
crow::json::wvalue r; crow::json::wvalue r;
TO_JSON_JSON(payload); TO_JSON_JSON(payload);
TO_JSON(signature); TO_JSON(signature);
@ -308,14 +284,12 @@ crow::json::wvalue Coin::to_json() const
return r; return r;
} }
tl::expected<Coin::Payload,eError> Coin::Payload::from_json(const crow::json::rvalue& json) { tl::expected<Coin::Payload, eError>
if ( !( json.has("cdd_location") Coin::Payload::from_json(const crow::json::rvalue &json) {
&& json.has("denomination") if (!(json.has("cdd_location") && json.has("denomination") &&
&& json.has("issuer_id") json.has("issuer_id") && json.has("mint_key_id") &&
&& json.has("mint_key_id") json.has("protocol_version") && json.has("serial") &&
&& json.has("protocol_version") json.has("type"))) {
&& json.has("serial")
&& json.has("type"))) {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
} else if (json["type"] != "payload") { } else if (json["type"] != "payload") {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
@ -332,10 +306,7 @@ tl::expected<Coin::Payload,eError> Coin::Payload::from_json(const crow::json::rv
} }
tl::expected<Coin, eError> Coin::from_json(const crow::json::rvalue &json) { tl::expected<Coin, eError> Coin::from_json(const crow::json::rvalue &json) {
if ( !( json.has("type") if (!(json.has("type") && json.has("payload") && json.has("signature"))) {
&& json.has("payload")
&& json.has("signature")
) ) {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
} else if (json["type"] != "coin") { } else if (json["type"] != "coin") {
return tl::make_unexpected(eError::JSON_ERROR); return tl::make_unexpected(eError::JSON_ERROR);
@ -360,24 +331,20 @@ crow::json::wvalue CoinStack::to_json() const {
return r; return r;
} }
tl::expected<RequestRenew, eError> tl::expected<RequestRenew, eError>
RequestRenew::from_string(const std::string &str) { RequestRenew::from_string(const std::string &str) {
auto json = crow::json::load(str); auto json = crow::json::load(str);
if (!json) { if (!json) {
return tl::make_unexpected(eError::JSON_PARSE_ERROR); return tl::make_unexpected(eError::JSON_PARSE_ERROR);
} else if ( !( json.has("blinds") } else if (!(json.has("blinds") && json.has("coins") &&
&& json.has("coins") json.has("transaction_reference") &&
&& json.has("transaction_reference") json.has("message_reference") && json.has("type"))) {
&& json.has("message_reference")
&& json.has("type")
) ) {
return tl::make_unexpected(eError::JSON_MISSING_KEY); return tl::make_unexpected(eError::JSON_MISSING_KEY);
} else if (json["type"] != "request renew") { } else if (json["type"] != "request renew") {
return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE); return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE);
} else if ( (json["coins"].t()!=crow::json::type::List) } else if ((json["coins"].t() != crow::json::type::List) ||
|| (json["blinds"].t()!=crow::json::type::List) ) { (json["blinds"].t() != crow::json::type::List)) {
return tl::make_unexpected(eError::JSON_WRONG_VALUE_TYPE); return tl::make_unexpected(eError::JSON_WRONG_VALUE_TYPE);
} else { } else {
RequestRenew r; RequestRenew r;
@ -417,10 +384,8 @@ RequestResume::from_string(const std::string& str) {
auto json = crow::json::load(str); auto json = crow::json::load(str);
if (!json) { if (!json) {
return tl::make_unexpected(eError::JSON_PARSE_ERROR); return tl::make_unexpected(eError::JSON_PARSE_ERROR);
} else if ( !( json.has("transaction_reference") } else if (!(json.has("transaction_reference") &&
&& json.has("message_reference") json.has("message_reference") && json.has("type"))) {
&& json.has("type")
) ) {
return tl::make_unexpected(eError::JSON_MISSING_KEY); return tl::make_unexpected(eError::JSON_MISSING_KEY);
} else if (json["type"] != "request resume") { } else if (json["type"] != "request resume") {
return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE); return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE);
@ -438,10 +403,8 @@ RequestRedeem::from_string(const std::string& str) {
auto json = crow::json::load(str); auto json = crow::json::load(str);
if (!json) { if (!json) {
return tl::make_unexpected(eError::JSON_PARSE_ERROR); return tl::make_unexpected(eError::JSON_PARSE_ERROR);
} else if ( !( json.has("coins") } else if (!(json.has("coins") && json.has("message_reference") &&
&& json.has("message_reference") json.has("type"))) {
&& json.has("type")
) ) {
return tl::make_unexpected(eError::JSON_MISSING_KEY); return tl::make_unexpected(eError::JSON_MISSING_KEY);
} else if (json["type"] != "request redeem") { } else if (json["type"] != "request redeem") {
return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE); return tl::make_unexpected(eError::JSON_WRONG_REQUEST_TYPE);
@ -464,28 +427,57 @@ auto json = crow::json::load(str);
} }
} }
crow::json::wvalue ResponseReedem::to_json() const { crow::json::wvalue ResponseRedeem::to_json() const {
crow::json::wvalue r = Response::to_json(); crow::json::wvalue r = Response::to_json();
r["type"] = "response redeem"; r["type"] = "response redeem";
return r; return r;
} }
using std::cout;
using std::endl;
/** this is for now our sample model */ /** this is for now our sample model */
class DefaultModel : public Model { class DefaultModel : public Model {
public: public:
DefaultModel() {} DefaultModel() {}
const CDDC& getCDDC() override {return m_cddc; }; tl::expected<CDDC *, bool> getCDDC(unsigned int cdd_serial) override {
const CDDC& getCurrentCDDC() override {return m_cddc; }; cout << __FUNCTION__ << "(" << cdd_serial << ")" << endl;
void mint() override {}; return &m_cddc;
};
tl::expected<CDDC *, bool> getCurrentCDDC() override {
cout << __FUNCTION__ << "()" << endl;
return &m_cddc;
}
std::vector<BlindSignature> mint(const std::string &transaction_reference,
const std::vector<Blind> &blinds) override {
std::vector<BlindSignature> res;
cout << __FUNCTION__ << "("
<< ")" << endl;
return res;
}
const std::vector<MintKeyCert>
getMKCs(const std::vector<unsigned int> &denominations,
const std::vector<unsigned int> &mint_key_ids) override {
std::vector<MintKeyCert> res;
cout << __FUNCTION__ << endl;
return res;
}
bool redeem(const std::vector<Coin> &coins) override {
cout << __FUNCTION__ << endl;
return false;
}
private: private:
CDDC m_cddc; CDDC m_cddc;
}; };
std::unique_ptr<Model> Model::getModel(const std::string& /*backend_name*/) std::unique_ptr<Model> Model::getModel(const std::string & /*backend_name*/) {
{ cout << __FUNCTION__ << endl;
//:wq //:wq
// if (backend_name=="default") // if (backend_name=="default")
return std::make_unique<DefaultModel>(); return std::make_unique<DefaultModel>();

View File

@ -1,16 +1,15 @@
#ifndef MODEL_HPP #ifndef MODEL_HPP
#define MODEL_HPP #define MODEL_HPP
#include <memory>
#include <string>
#include <chrono> #include <chrono>
#include <memory>
#include <optional> #include <optional>
#include <string>
#include "crow/json.h" #include "crow/json.h"
#include "tl/expected.hpp" #include "tl/expected.hpp"
struct PublicKey { struct PublicKey {
std::string modulus; //: "daaa63ddda38c189b8c49020c8276adbe0a695685a...", std::string modulus; //: "daaa63ddda38c189b8c49020c8276adbe0a695685a...",
std::string public_exponent; //: 65537, std::string public_exponent; //: 65537,
@ -39,8 +38,10 @@ struct CDD {
std::string id; //: 23ed956e629ba35f0002eaf833ea436aea7db5c2, std::string id; //: 23ed956e629ba35f0002eaf833ea436aea7db5c2,
std::vector<WeightedUrl> info_service; std::vector<WeightedUrl> info_service;
/* eCipherSuite*/ std::string issuer_cipher_suite; //: RSA-SHA256-PSS-CHAUM82, /* eCipherSuite*/ std::string issuer_cipher_suite; //: RSA-SHA256-PSS-CHAUM82,
PublicKey issuer_public_master_key;//: { PublicKey
// modulus: daaa63ddda38c189b8c49020c8276adbe0a695685a..., issuer_public_master_key; //: {
// modulus:
// daaa63ddda38c189b8c49020c8276adbe0a695685a...,
// public_exponent: 65537, // public_exponent: 65537,
// type: rsa public key // type: rsa public key
//}, //},
@ -100,7 +101,8 @@ struct Response {
struct RequestCDDSerial { struct RequestCDDSerial {
unsigned int message_reference; /// Client internal message reference. unsigned int message_reference; /// Client internal message reference.
/// (Integer) /// (Integer)
static tl::expected<RequestCDDSerial,eError> from_string(const std::string& str); static tl::expected<RequestCDDSerial, eError>
from_string(const std::string &str);
}; };
struct ResponseCDDSerial : Response { struct ResponseCDDSerial : Response {
@ -166,7 +168,6 @@ struct ResponseMint : Response {
crow::json::wvalue to_json() const override; crow::json::wvalue to_json() const override;
}; };
struct Coin { struct Coin {
struct Payload { struct Payload {
std::string cdd_location; std::string cdd_location;
@ -177,7 +178,8 @@ struct Coin {
std::string serial; std::string serial;
crow::json::wvalue to_json() const; crow::json::wvalue to_json() const;
static tl::expected<Payload,eError> from_json(const crow::json::rvalue& json); static tl::expected<Payload, eError>
from_json(const crow::json::rvalue &json);
}; };
Payload payload; Payload payload;
@ -213,7 +215,8 @@ struct RequestResume {
/// (Integer) /// (Integer)
std::string transaction_reference; std::string transaction_reference;
// "type": "request resume" // "type": "request resume"
static tl::expected<RequestResume,eError> from_string(const std::string& str); static tl::expected<RequestResume, eError>
from_string(const std::string &str);
}; };
struct RequestRedeem { struct RequestRedeem {
@ -221,10 +224,11 @@ struct RequestRedeem {
unsigned int message_reference; /// Client internal message reference. unsigned int message_reference; /// Client internal message reference.
/// (Integer) /// (Integer)
// "type": "request redeem" // "type": "request redeem"
static tl::expected<RequestRedeem,eError> from_string(const std::string& str); static tl::expected<RequestRedeem, eError>
from_string(const std::string &str);
}; };
struct ResponseReedem : Response { struct ResponseRedeem : Response {
crow::json::wvalue to_json() const override; crow::json::wvalue to_json() const override;
}; };
@ -232,13 +236,21 @@ class Model {
public: public:
virtual ~Model(){}; virtual ~Model(){};
virtual const CDDC& getCDDC() = 0; virtual tl::expected<CDDC *, bool> getCDDC(unsigned int cdd_serial) = 0;
virtual const CDDC& getCurrentCDDC() = 0; virtual tl::expected<CDDC *, bool> getCurrentCDDC() = 0;
virtual void mint() = 0;
virtual const std::vector<MintKeyCert>
getMKCs(const std::vector<unsigned int> &denominations,
const std::vector<unsigned int> &mint_key_ids) = 0;
virtual std::vector<BlindSignature>
mint(const std::string &transaction_reference,
const std::vector<Blind> &blinds) = 0;
virtual bool redeem(const std::vector<Coin> &coins) = 0;
static std::unique_ptr<Model> getModel(const std::string &backend_name); static std::unique_ptr<Model> getModel(const std::string &backend_name);
private: private:
}; };
#endif // #ifndef MODEL_HPP #endif // #ifndef MODEL_HPP