CCF
Loading...
Searching...
No Matches
gov.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "ccf/ds/json.h"
6#include "ccf/kv/map.h"
8
9namespace ccf
10{
11 namespace jsgov
12 {
13 using Ballots = std::unordered_map<ccf::MemberId, std::string>;
14 using Votes = std::unordered_map<ccf::MemberId, bool>;
15
16 struct Failure
17 {
18 std::string reason;
19 std::optional<std::string> trace;
20 bool operator==(const Failure& rhs) const
21 {
22 return reason == rhs.reason && trace == rhs.trace;
23 }
24 bool operator!=(const Failure& rhs) const
25 {
26 return !(*this == rhs);
27 }
28 };
32 using VoteFailures = std::unordered_map<ccf::MemberId, Failure>;
33
36 {
50 std::optional<Votes> final_votes = std::nullopt;
54 std::optional<VoteFailures> vote_failures = std::nullopt;
58 std::optional<Failure> failure = std::nullopt;
59 };
61 DECLARE_JSON_REQUIRED_FIELDS(ProposalInfo, proposer_id, state, ballots);
63 ProposalInfo, final_votes, vote_failures, failure);
64
67 {
72 std::optional<Votes> votes = std::nullopt;
73 std::optional<VoteFailures> vote_failures = std::nullopt;
74 std::optional<Failure> failure = std::nullopt;
75 };
78 ProposalInfoSummary, proposal_id, proposer_id, state, ballot_count);
80 ProposalInfoSummary, votes, vote_failures, failure);
81
85
86 namespace Tables
87 {
88 static constexpr auto PROPOSALS = "public:ccf.gov.proposals";
89 static constexpr auto PROPOSALS_INFO = "public:ccf.gov.proposals_info";
90 }
91
92 struct Action
93 {
94 std::string name;
95 nlohmann::json args;
96 };
99
100 struct Proposal
101 {
102 std::vector<Action> actions;
103 };
106
107 struct Ballot
108 {
109 std::string ballot;
110 };
113 }
114}
115
116FMT_BEGIN_NAMESPACE
117template <>
118struct formatter<std::optional<ccf::jsgov::Failure>>
119{
120 template <typename ParseContext>
121 constexpr auto parse(ParseContext& ctx)
122 {
123 return ctx.begin();
124 }
125
126 template <typename FormatContext>
127 auto format(
128 const std::optional<ccf::jsgov::Failure>& f, FormatContext& ctx) const
129 {
130 if (f.has_value())
131 {
132 return format_to(
133 ctx.out(), "{}\nTrace: {}", f->reason, f->trace.value_or("N/A"));
134 }
135 else
136 {
137 return format_to(ctx.out(), "N/A");
138 }
139 }
140};
141FMT_END_NAMESPACE
Definition map.h:30
#define DECLARE_JSON_REQUIRED_FIELDS(TYPE,...)
Definition json.h:714
#define DECLARE_JSON_TYPE(TYPE)
Definition json.h:663
#define DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(TYPE)
Definition json.h:690
#define DECLARE_JSON_OPTIONAL_FIELDS(TYPE,...)
Definition json.h:786
std::unordered_map< ccf::MemberId, bool > Votes
Definition gov.h:14
std::unordered_map< ccf::MemberId, Failure > VoteFailures
Definition gov.h:32
std::unordered_map< ccf::MemberId, std::string > Ballots
Definition gov.h:13
Definition app_interface.h:14
ProposalState
Definition proposals.h:19
std::string ProposalId
Definition proposals.h:40
STL namespace.
Definition gov.h:93
std::string name
Definition gov.h:94
nlohmann::json args
Definition gov.h:95
Definition gov.h:108
std::string ballot
Definition gov.h:109
Definition gov.h:17
std::optional< std::string > trace
Definition gov.h:19
std::string reason
Definition gov.h:18
bool operator==(const Failure &rhs) const
Definition gov.h:20
bool operator!=(const Failure &rhs) const
Definition gov.h:24
Proposal summary constructed while executing/resolving proposal ballots.
Definition gov.h:67
std::optional< VoteFailures > vote_failures
Definition gov.h:73
std::optional< Votes > votes
Definition gov.h:72
ccf::ProposalId proposal_id
Definition gov.h:68
size_t ballot_count
Definition gov.h:71
ccf::ProposalState state
Definition gov.h:70
ccf::MemberId proposer_id
Definition gov.h:69
std::optional< Failure > failure
Definition gov.h:74
Proposal metadata stored in the KV.
Definition gov.h:36
std::optional< Votes > final_votes
Definition gov.h:50
ccf::MemberId proposer_id
ID of the member who originally created/submitted this proposal.
Definition gov.h:38
std::optional< Failure > failure
Definition gov.h:58
std::optional< VoteFailures > vote_failures
Definition gov.h:54
Ballots ballots
Definition gov.h:45
ccf::ProposalState state
Current state of this proposal (eg - open, accepted, withdrawn)
Definition gov.h:40
Definition gov.h:101
std::vector< Action > actions
Definition gov.h:102
auto format(const std::optional< ccf::jsgov::Failure > &f, FormatContext &ctx) const
Definition gov.h:127
constexpr auto parse(ParseContext &ctx)
Definition gov.h:121