Zecale - Reconciling Privacy and Scalability on Smart-Contract Chains  0.5
Reference implementation of the Zecale protocol by Clearmatics
nested_transaction.tcc
Go to the documentation of this file.
1 // Copyright (c) 2015-2022 Clearmatics Technologies Ltd
2 //
3 // SPDX-License-Identifier: LGPL-3.0+
4 
5 #ifndef __ZECALE_CORE_NESTED_TRANSACTION_TCC__
6 #define __ZECALE_CORE_NESTED_TRANSACTION_TCC__
7 
8 #include "libzecale/core/nested_transaction.hpp"
9 
10 #include <libzeth/core/utils.hpp>
11 
12 namespace libzecale
13 {
14 
15 template<typename nppT, typename nsnarkT>
16 nested_transaction<nppT, nsnarkT>::nested_transaction()
17 {
18 }
19 
20 template<typename nppT, typename nsnarkT>
21 nested_transaction<nppT, nsnarkT>::nested_transaction(
22  const std::string &application_name,
23  const libzeth::extended_proof<nppT, nsnarkT> &extended_proof,
24  const std::vector<uint8_t> &parameters,
25  uint32_t fee_wei)
26  : _application_name(application_name)
27  , _parameters(parameters)
28  , _fee_wei(fee_wei)
29 {
30  this->_extended_proof =
31  std::make_shared<libzeth::extended_proof<nppT, nsnarkT>>(
32  extended_proof);
33 }
34 
35 template<typename nppT, typename nsnarkT>
36 const std::string &nested_transaction<nppT, nsnarkT>::application_name() const
37 {
38  return _application_name;
39 };
40 
41 template<typename nppT, typename nsnarkT>
42 const libzeth::extended_proof<nppT, nsnarkT>
43  &nested_transaction<nppT, nsnarkT>::extended_proof() const
44 {
45  return *(_extended_proof);
46 };
47 
48 template<typename nppT, typename nsnarkT>
49 const std::vector<uint8_t> &nested_transaction<nppT, nsnarkT>::parameters()
50  const
51 {
52  return _parameters;
53 }
54 
55 template<typename nppT, typename nsnarkT>
56 uint32_t nested_transaction<nppT, nsnarkT>::fee_wei() const
57 {
58  return _fee_wei;
59 }
60 
61 template<typename nppT, typename nsnarkT>
62 std::ostream &nested_transaction<nppT, nsnarkT>::write_json(
63  std::ostream &os) const
64 {
65  os << "{\n"
66  "\t\"app_name\": "
67  << "\"" << _application_name << "\"";
68  os << ",\n"
69  "\t\"ext_proof\": ";
70  _extended_proof->write_json(os);
71  os << ",\n"
72  "\t\"parameters\": "
73  << "\"" << libzeth::bytes_to_hex(_parameters.data(), _parameters.size())
74  << ",\n\t\"fee_wei\": " << _fee_wei << "\"\n}\n";
75  return os;
76 }
77 
78 template<typename nppT, typename nsnarkT>
79 bool nested_transaction<nppT, nsnarkT>::operator<(
80  const nested_transaction<nppT, nsnarkT> &right) const
81 {
82  return fee_wei() < right.fee_wei();
83 }
84 
85 } // namespace libzecale
86 
87 #endif // __ZECALE_CORE_NESTED_TRANSACTION_TCC__