Zecale - Reconciling Privacy and Scalability on Smart-Contract Chains  0.5
Reference implementation of the Zecale protocol by Clearmatics
application_pool.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_APPLICATION_POOL_TCC__
6 #define __ZECALE_CORE_APPLICATION_POOL_TCC__
7 
8 #include "libzecale/core/application_pool.hpp"
9 
10 namespace libzecale
11 {
12 
13 template<typename nppT, typename nsnarkT, size_t NumProofs>
14 application_pool<nppT, nsnarkT, NumProofs>::application_pool(
15  const std::string &name, const typename nsnarkT::verification_key &vk)
16  : _name(name), _verification_key(vk), _tx_pool()
17 {
18 }
19 
20 template<typename nppT, typename nsnarkT, size_t NumProofs>
21 const std::string &application_pool<nppT, nsnarkT, NumProofs>::name() const
22 {
23  return _name;
24 }
25 
26 template<typename nppT, typename nsnarkT, size_t NumProofs>
27 const typename nsnarkT::verification_key &application_pool<
28  nppT,
29  nsnarkT,
30  NumProofs>::verification_key() const
31 {
32  return _verification_key;
33 }
34 
35 template<typename nppT, typename nsnarkT, size_t NumProofs>
36 void application_pool<nppT, nsnarkT, NumProofs>::add_tx(
37  const nested_transaction<nppT, nsnarkT> &tx)
38 {
39  _tx_pool.push(tx);
40 }
41 
42 template<typename nppT, typename nsnarkT, size_t NumProofs>
43 size_t application_pool<nppT, nsnarkT, NumProofs>::tx_pool_size() const
44 {
45  return _tx_pool.size();
46 }
47 
48 template<typename nppT, typename nsnarkT, size_t NumProofs>
49 size_t application_pool<nppT, nsnarkT, NumProofs>::get_next_batch(
50  std::array<nested_transaction<nppT, nsnarkT>, NumProofs> &batch)
51 {
52  // TODO: For now, only return whole batches (to avoid nasty errors where
53  // elements in the array are not initialized properly). Later, clean up the
54  // data structures to support partial-batches in a safe way.
55  if (_tx_pool.size() < NumProofs) {
56  return 0;
57  }
58  for (size_t entry_idx = 0; entry_idx < NumProofs; ++entry_idx) {
59  batch[entry_idx] = _tx_pool.top();
60  _tx_pool.pop();
61  }
62  return NumProofs;
63 }
64 
65 } // namespace libzecale
66 
67 #endif // __ZECALE_CORE_APPLICATION_POOL_TCC__