CCF
Loading...
Searching...
No Matches
endpoint_context.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/claims_digest.h"
8#include "ccf/tx_status.h"
9
10#include <functional>
11#include <memory>
12
13namespace ccf
14{
15 class RpcContext;
16}
17
23namespace ccf::endpoints
24{
25 // Commands are endpoints which do not interact with the kv, even to read
27 {
28 virtual ~CommandEndpointContext() = default;
29
30 CommandEndpointContext(const std::shared_ptr<ccf::RpcContext>& r) :
31 rpc_ctx(r)
32 {}
33
34 std::shared_ptr<ccf::RpcContext> rpc_ctx;
35 std::unique_ptr<AuthnIdentity> caller;
36
37 template <typename T>
38 const T* try_get_caller()
39 {
40 return dynamic_cast<const T*>(caller.get());
41 }
42
43 template <typename T>
44 const T& get_caller()
45 {
46 const T* ident = try_get_caller<T>();
47 if (ident == nullptr)
48 {
49 throw std::logic_error("Asked for unprovided identity type");
50 }
51 return *ident;
52 }
53 };
55 std::function<void(CommandEndpointContext& args)>;
56
58 {
59 EndpointContext(const std::shared_ptr<ccf::RpcContext>& r, ccf::kv::Tx& t) :
61 tx(t)
62 {}
63
65 };
66 using EndpointFunction = std::function<void(EndpointContext& args)>;
67
69 std::function<void(CommandEndpointContext& ctx, const ccf::TxID& txid)>;
70
80
82 std::function<void(CommittedTxInfo& info)>;
83
84 // Read-only endpoints can only get values from the kv, they cannot write
86 {
88 const std::shared_ptr<ccf::RpcContext>& r, ccf::kv::ReadOnlyTx& t) :
90 tx(t)
91 {}
92
94 };
96 std::function<void(ReadOnlyEndpointContext& args)>;
97}
Definition claims_digest.h:10
Definition sha256_hash.h:16
Definition tx.h:159
Definition tx.h:200
Definition endpoint.h:17
std::function< void(CommandEndpointContext &args)> CommandEndpointFunction
Definition endpoint_context.h:55
std::function< void(ReadOnlyEndpointContext &args)> ReadOnlyEndpointFunction
Definition endpoint_context.h:96
std::function< void(CommittedTxInfo &info)> ConsensusCommittedEndpointFunction
Definition endpoint_context.h:82
std::function< void(CommandEndpointContext &ctx, const ccf::TxID &txid)> LocallyCommittedEndpointFunction
Definition endpoint_context.h:69
std::function< void(EndpointContext &args)> EndpointFunction
Definition endpoint_context.h:66
Definition app_interface.h:13
FinalTxStatus
Definition tx_status.h:36
Definition tx_id.h:44
Definition endpoint_context.h:27
const T & get_caller()
Definition endpoint_context.h:44
CommandEndpointContext(const std::shared_ptr< ccf::RpcContext > &r)
Definition endpoint_context.h:30
std::shared_ptr< ccf::RpcContext > rpc_ctx
Definition endpoint_context.h:34
const T * try_get_caller()
Definition endpoint_context.h:38
std::unique_ptr< AuthnIdentity > caller
Definition endpoint_context.h:35
Definition endpoint_context.h:72
std::shared_ptr< ccf::RpcContext > rpc_ctx
Definition endpoint_context.h:73
std::string commit_evidence
Definition endpoint_context.h:77
ccf::FinalTxStatus status
Definition endpoint_context.h:75
ccf::ClaimsDigest claims_digest
Definition endpoint_context.h:78
ccf::TxID tx_id
Definition endpoint_context.h:74
ccf::crypto::Sha256Hash write_set_digest
Definition endpoint_context.h:76
Definition endpoint_context.h:58
EndpointContext(const std::shared_ptr< ccf::RpcContext > &r, ccf::kv::Tx &t)
Definition endpoint_context.h:59
ccf::kv::Tx & tx
Definition endpoint_context.h:64
Definition endpoint_context.h:86
ReadOnlyEndpointContext(const std::shared_ptr< ccf::RpcContext > &r, ccf::kv::ReadOnlyTx &t)
Definition endpoint_context.h:87
ccf::kv::ReadOnlyTx & tx
Definition endpoint_context.h:93