BitShares-Core  5.0.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> {
41  public:
42  // uniquely identify this object in the database
43  static constexpr uint8_t space_id = protocol_ids;
44  static constexpr uint8_t type_id = htlc_object_type;
45 
46  struct transfer_info {
47  account_id_type from;
48  account_id_type to;
50  asset_id_type asset_id;
51  } transfer;
52  struct condition_info {
53  struct hash_lock_info {
55  uint16_t preimage_size;
56  } hash_lock;
57  struct time_lock_info {
59  } time_lock;
60  } conditions;
61 
63 
64  /****
65  * Index helper for timelock
66  */
69  const result_type& operator()(const htlc_object& o)const { return o.conditions.time_lock.expiration; }
70  };
71 
72  /*****
73  * Index helper for from
74  */
75  struct from_extractor {
76  typedef account_id_type result_type;
77  const result_type& operator()(const htlc_object& o)const { return o.transfer.from; }
78  };
79 
80  /*****
81  * Index helper for to
82  */
83  struct to_extractor {
84  typedef account_id_type result_type;
85  const result_type& operator()(const htlc_object& o)const { return o.transfer.to; }
86  };
87  };
88 
89  struct by_from_id;
90  struct by_expiration;
91  struct by_to_id;
92  typedef multi_index_container<
94  indexed_by<
95  ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >,
96 
97  ordered_unique< tag< by_expiration >,
98  composite_key< htlc_object,
100  member< object, object_id_type, &object::id > > >,
101 
102  ordered_unique< tag< by_from_id >,
103  composite_key< htlc_object,
105  member< object, object_id_type, &object::id > > >,
106 
107  ordered_unique< tag< by_to_id >,
108  composite_key< htlc_object,
110  member< object, object_id_type, &object::id > > >
111  >
112 
114 
116 
117 } } // namespace graphene::chain
118 
120 
121 FC_REFLECT_TYPENAME( graphene::chain::htlc_object::condition_info::hash_lock_info )
122 FC_REFLECT_TYPENAME( graphene::chain::htlc_object::condition_info::time_lock_info )
123 FC_REFLECT_TYPENAME( graphene::chain::htlc_object::condition_info )
125 
struct graphene::chain::htlc_object::transfer_info transfer
const result_type & operator()(const htlc_object &o) const
Definition: htlc_object.hpp:69
struct graphene::chain::htlc_object::condition_info::time_lock_info time_lock
database object to store HTLCs
Definition: htlc_object.hpp:40
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_index_type
Definition: htlc_object.hpp:91
struct graphene::chain::htlc_object::condition_info conditions
Definition: api.cpp:56
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:98
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
FC_REFLECT_TYPENAME(fc::log_message)
fc::optional< memo_data > memo
Definition: htlc_object.hpp:62
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
const result_type & operator()(const htlc_object &o) const
Definition: htlc_object.hpp:85
Use the Curiously Recurring Template Pattern to automatically add the ability to clone, serialize, and move objects polymorphically.
Definition: object.hpp:86
generic_index< htlc_object, htlc_object_index_type > htlc_index
const result_type & operator()(const htlc_object &o) const
Definition: htlc_object.hpp:77