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::jsgov
10{
11 using Ballots = std::unordered_map<ccf::MemberId, std::string>;
12 using Votes = std::unordered_map<ccf::MemberId, bool>;
13
14 struct Failure
15 {
16 std::string reason;
17 std::optional<std::string> trace;
18 bool operator==(const Failure& rhs) const
19 {
20 return reason == rhs.reason && trace == rhs.trace;
21 }
22 bool operator!=(const Failure& rhs) const
23 {
24 return !(*this == rhs);
25 }
26 };
30 using VoteFailures = std::unordered_map<ccf::MemberId, Failure>;
31
34 {
48 std::optional<Votes> final_votes = std::nullopt;
52 std::optional<VoteFailures> vote_failures = std::nullopt;
56 std::optional<Failure> failure = std::nullopt;
57 };
59 DECLARE_JSON_REQUIRED_FIELDS(ProposalInfo, proposer_id, state, ballots);
61 ProposalInfo, final_votes, vote_failures, failure);
62
65 {
70 std::optional<Votes> votes = std::nullopt;
71 std::optional<VoteFailures> vote_failures = std::nullopt;
72 std::optional<Failure> failure = std::nullopt;
73 };
76 ProposalInfoSummary, proposal_id, proposer_id, state, ballot_count);
78 ProposalInfoSummary, votes, vote_failures, failure);
79
83
84 namespace Tables
85 {
86 static constexpr auto PROPOSALS = "public:ccf.gov.proposals";
87 static constexpr auto PROPOSALS_INFO = "public:ccf.gov.proposals_info";
88 }
89
90 struct Action
91 {
92 std::string name;
93 nlohmann::json args;
94 };
97
98 struct Proposal
99 {
100 std::vector<Action> actions;
101 };
104
105 struct Ballot
106 {
107 std::string ballot;
108 };
111}
112
113FMT_BEGIN_NAMESPACE
114template <>
115struct formatter<std::optional<ccf::jsgov::Failure>>
116{
117 template <typename ParseContext>
118 constexpr auto parse(ParseContext& ctx)
119 {
120 return ctx.begin();
121 }
122
123 template <typename FormatContext>
124 auto format(
125 const std::optional<ccf::jsgov::Failure>& f, FormatContext& ctx) const
126 {
127 if (f.has_value())
128 {
129 return format_to(
130 ctx.out(), "{}\nTrace: {}", f->reason, f->trace.value_or("N/A"));
131 }
132 return format_to(ctx.out(), "N/A");
133 }
134};
135FMT_END_NAMESPACE
Definition map.h:30
#define DECLARE_JSON_REQUIRED_FIELDS(TYPE,...)
Definition json.h:718
#define DECLARE_JSON_TYPE(TYPE)
Definition json.h:667
#define DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(TYPE)
Definition json.h:694
#define DECLARE_JSON_OPTIONAL_FIELDS(TYPE,...)
Definition json.h:790
Definition gov.h:10
std::unordered_map< ccf::MemberId, bool > Votes
Definition gov.h:12
std::unordered_map< ccf::MemberId, Failure > VoteFailures
Definition gov.h:30
std::unordered_map< ccf::MemberId, std::string > Ballots
Definition gov.h:11
ProposalState
Definition proposals.h:19
std::string ProposalId
Definition proposals.h:40
STL namespace.
Definition gov.h:91
std::string name
Definition gov.h:92
nlohmann::json args
Definition gov.h:93
Definition gov.h:106
std::string ballot
Definition gov.h:107
Definition gov.h:15
std::optional< std::string > trace
Definition gov.h:17
std::string reason
Definition gov.h:16
bool operator==(const Failure &rhs) const
Definition gov.h:18
bool operator!=(const Failure &rhs) const
Definition gov.h:22
Proposal summary constructed while executing/resolving proposal ballots.
Definition gov.h:65
std::optional< VoteFailures > vote_failures
Definition gov.h:71
std::optional< Votes > votes
Definition gov.h:70
ccf::ProposalId proposal_id
Definition gov.h:66
size_t ballot_count
Definition gov.h:69
ccf::ProposalState state
Definition gov.h:68
ccf::MemberId proposer_id
Definition gov.h:67
std::optional< Failure > failure
Definition gov.h:72
Proposal metadata stored in the KV.
Definition gov.h:34
std::optional< Votes > final_votes
Definition gov.h:48
ccf::MemberId proposer_id
ID of the member who originally created/submitted this proposal.
Definition gov.h:36
std::optional< Failure > failure
Definition gov.h:56
std::optional< VoteFailures > vote_failures
Definition gov.h:52
Ballots ballots
Definition gov.h:43
ccf::ProposalState state
Current state of this proposal (eg - open, accepted, withdrawn)
Definition gov.h:38
Definition gov.h:99
std::vector< Action > actions
Definition gov.h:100
auto format(const std::optional< ccf::jsgov::Failure > &f, FormatContext &ctx) const
Definition gov.h:124
constexpr auto parse(ParseContext &ctx)
Definition gov.h:118