BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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 
graphene::chain::htlc_object::transfer_info::asset_id
asset_id_type asset_id
Definition: htlc_object.hpp:48
graphene::chain::htlc_object::from_extractor::result_type
account_id_type result_type
Definition: htlc_object.hpp:83
htlc.hpp
graphene::chain::htlc_object::from_extractor
Definition: htlc_object.hpp:80
graphene::chain::htlc_object::condition_info::hash_lock
hash_lock_info hash_lock
Definition: htlc_object.hpp:61
fc::static_variant< htlc_algo_ripemd160, htlc_algo_sha1, htlc_algo_sha256, htlc_algo_hash160 >
FC_REFLECT_TYPENAME
FC_REFLECT_TYPENAME(fc::log_message)
graphene::chain::htlc_object::condition_info
Definition: htlc_object.hpp:50
graphene::chain::htlc_object::condition_info::time_lock
time_lock_info time_lock
Definition: htlc_object.hpp:62
generic_index.hpp
graphene::chain::htlc_object::transfer_info::from
account_id_type from
Definition: htlc_object.hpp:45
MAP_OBJECT_ID_TO_TYPE
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:93
graphene::chain::htlc_object::condition_info::time_lock_info::expiration
fc::time_point_sec expiration
Definition: htlc_object.hpp:59
graphene::chain::htlc_object::condition_info::hash_lock_info
Definition: htlc_object.hpp:52
graphene::db::abstract_object
Definition: object.hpp:107
graphene::chain::htlc_object::transfer
transfer_info transfer
Definition: htlc_object.hpp:65
graphene::chain::htlc_object::transfer_info
Definition: htlc_object.hpp:43
graphene::chain::htlc_object_multi_index_type
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
Definition: htlc_object.hpp:114
graphene::chain::htlc_object::transfer_info::to
account_id_type to
Definition: htlc_object.hpp:46
graphene::chain::htlc_object::to_extractor::result_type
account_id_type result_type
Definition: htlc_object.hpp:91
graphene::chain::htlc_object::condition_info::hash_lock_info::preimage_hash
htlc_hash preimage_hash
Definition: htlc_object.hpp:54
fc::time_point_sec
Definition: time.hpp:74
graphene::chain::by_expiration
Definition: proposal_object.hpp:86
GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
graphene::chain::htlc_object::condition_info::hash_lock_info::preimage_size
uint16_t preimage_size
Definition: htlc_object.hpp:55
graphene::chain::htlc_object::transfer_info::amount
share_type amount
Definition: htlc_object.hpp:47
graphene::chain::htlc_object::timelock_extractor
Definition: htlc_object.hpp:72
graphene::chain::htlc_object::condition_info::time_lock_info
Definition: htlc_object.hpp:57
graphene::chain::htlc_object::conditions
condition_info conditions
Definition: htlc_object.hpp:66
graphene::db::generic_index
Definition: generic_index.hpp:43
graphene::chain::htlc_object::to_extractor
Definition: htlc_object.hpp:88
fc::optional
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
graphene::chain::htlc_object::memo
fc::optional< memo_data > memo
Definition: htlc_object.hpp:67
graphene
Definition: api.cpp:48
graphene::chain::htlc_object
database object to store HTLCs
Definition: htlc_object.hpp:40
fc::safe
Definition: safe.hpp:26