CCF
Loading...
Searching...
No Matches
common_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
12
13namespace ccf::js
14{
15 // This is intended to extend a js::core::Context with various CCF-specific
16 // extensions, expected to be accessible in every execution context (eg -
17 // ccf.bufToStr converters, ccf.crypto helpers). This is
18 // implemented as a CRTP mixin so that you could build your own hierarchy.
19 template <typename Base>
21 {
22 public:
24 {
25 // override Math.random
26 Base::add_extension(
27 std::make_shared<ccf::js::extensions::MathRandomExtension>());
28
29 // add console.[debug|log|...]
30 Base::add_extension(
31 std::make_shared<ccf::js::extensions::ConsoleExtension>());
32
33 // add ccf.[strToBuf|bufToStr|...]
34 Base::add_extension(
35 std::make_shared<ccf::js::extensions::ConvertersExtension>());
36
37 // add ccf.crypto.*
38 Base::add_extension(
39 std::make_shared<ccf::js::extensions::CryptoExtension>());
40
41 // add snp_attestation.*
42 Base::add_extension(
43 std::make_shared<ccf::js::extensions::SnpAttestationExtension>());
44 }
45 };
46
47 template <typename Base>
48 class WithKVExtension : public Base
49 {
50 public:
52 {
53 // add ccf.kv.*
54 Base::add_extension(
55 std::make_shared<ccf::js::extensions::KvExtension>(tx));
56 }
57 };
58
61}
Definition common_context.h:21
WithCommonExtensions(TxAccess acc)
Definition common_context.h:23
Definition common_context.h:49
WithKVExtension(TxAccess acc, ccf::kv::Tx *tx)
Definition common_context.h:51
Definition tx.h:202
Definition perf_client.h:198
Definition bundle.h:12
WithCommonExtensions< js::core::Context > CommonContext
Definition common_context.h:59
TxAccess
Definition tx_access.h:10
WithKVExtension< CommonContext > CommonContextWithLocalTx
Definition common_context.h:60