BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
htlc_object.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 jmjatlanta and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
25 
28 
29 #include <boost/multi_index/composite_key.hpp>
30 
31 namespace graphene { namespace chain {
32  using namespace protocol;
33 
40  class htlc_object : public graphene::db::abstract_object<htlc_object, protocol_ids, htlc_object_type>
41  {
42  public:
44  {
45  account_id_type from;
46  account_id_type to;
48  asset_id_type asset_id;
49  };
51  {
53  {
55  uint16_t preimage_size;
56  };
58  {
60  };
63  };
64 
68 
69  /****
70  * Index helper for timelock
71  */
74  const result_type& operator()(const htlc_object& o)const { return o.conditions.time_lock.expiration; }
75  };
76 
77  /*****
78  * Index helper for from
79  */
80  struct from_extractor {
81  using result_type = account_id_type;
82  const result_type& operator()(const htlc_object& o)const { return o.transfer.from; }
83  };
84 
85  /*****
86  * Index helper for to
87  */
88  struct to_extractor {
89  using result_type = account_id_type;
90  const result_type& operator()(const htlc_object& o)const { return o.transfer.to; }
91  };
92  };
93 
94  struct by_from_id;
95  struct by_expiration;
96  struct by_to_id;
97  using htlc_object_multi_index_type = multi_index_container<
99  indexed_by<
100  ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >,
101  ordered_unique< tag< by_expiration >,
102  composite_key< htlc_object,
104  member< object, object_id_type, &object::id > > >,
105  ordered_unique< tag< by_from_id >,
106  composite_key< htlc_object,
108  member< object, object_id_type, &object::id > > >,
109  ordered_unique< tag< by_to_id >,
110  composite_key< htlc_object,
112  member< object, object_id_type, &object::id > > >
113  >
114  >;
115 
117 
118 } } // namespace graphene::chain
119 
121 
126 
const result_type & operator()(const htlc_object &o) const
Definition: htlc_object.hpp:82
const result_type & operator()(const htlc_object &o) const
Definition: htlc_object.hpp:74
database object to store HTLCs
Definition: htlc_object.hpp:40
Definition: api.cpp:48
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:93
multi_index_container< htlc_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_expiration >, composite_key< htlc_object, htlc_object::timelock_extractor, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_from_id >, composite_key< htlc_object, htlc_object::from_extractor, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_to_id >, composite_key< htlc_object, htlc_object::to_extractor, member< object, object_id_type, &object::id > > > > > htlc_object_multi_index_type
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
FC_REFLECT_TYPENAME(fc::log_message)
const result_type & operator()(const htlc_object &o) const
Definition: htlc_object.hpp:90
fc::optional< memo_data > memo
Definition: htlc_object.hpp:67
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85