BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
htlc.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 
26 #include <fc/time.hpp>
30 #include <algorithm> // std::max
31 
32 namespace graphene { namespace protocol {
37 
38  typedef fc::static_variant<
44 
46  {
47  struct fee_params_t {
50  };
51 
52  // paid to network
54  // where the held monies are to come from
55  account_id_type from;
56  // where the held monies will go if the preimage is provided
57  account_id_type to;
58  // the amount to hold
60  // the (typed) hash of the preimage
62  // the size of the preimage
63  uint16_t preimage_size;
64  // The time the funds will be returned to the source if not claimed
66 
67  // additional extensions
69  {
71  };
73 
74  /***
75  * @brief Does simple validation of this object
76  */
77  void validate()const;
78 
82  account_id_type fee_payer()const { return from; }
83 
84  /****
85  * @brief calculates the fee to be paid for this operation
86  */
87  share_type calculate_fee(const fee_params_t& fee_params, uint32_t fee_per_kb)const;
88  };
89 
91  {
92  struct fee_params_t {
95  };
96 
97  // paid to network
99  // the object we are attempting to update
100  htlc_id_type htlc_id;
101  // who is attempting to update the transaction
102  account_id_type redeemer;
103  // the preimage (not used if after epoch timeout)
104  std::vector<char> preimage;
105  // for future expansion
107 
108  /***
109  * @brief Perform obvious checks to validate this object
110  */
111  void validate()const;
112 
116  account_id_type fee_payer()const { return redeemer; }
117 
118  /****
119  * @brief calculates the fee to be paid for this operation
120  */
121  share_type calculate_fee(const fee_params_t& fee_params)const;
122  };
123 
128  {
129  struct fee_params_t {};
130 
132  htlc_redeemed_operation( htlc_id_type htlc_id, account_id_type from, account_id_type to,
133  account_id_type redeemer, asset amount, const htlc_hash& preimage_hash, uint16_t preimage_size,
134  const std::vector<char>& preimage ) :
136  htlc_preimage_hash(preimage_hash), htlc_preimage_size(preimage_size), preimage(preimage) {}
137 
138  account_id_type fee_payer()const { return to; }
139  void validate()const { FC_ASSERT( !"virtual operation" ); }
140 
141  share_type calculate_fee(const fee_params_t& k)const { return 0; }
142 
143  htlc_id_type htlc_id;
144  account_id_type from, to, redeemer;
148 
150  std::vector<char> preimage;
151  };
152 
154  {
155  struct fee_params_t {
158  };
159 
160  // paid to network
162  // the object we are attempting to update
163  htlc_id_type htlc_id;
164  // who is attempting to update the transaction
165  account_id_type update_issuer;
166  // how much to add
167  uint32_t seconds_to_add;
168  // for future expansion
170 
171  /***
172  * @brief Perform obvious checks to validate this object
173  */
174  void validate()const;
175 
179  account_id_type fee_payer()const { return update_issuer; }
180 
181  /****
182  * @brief calculates the fee to be paid for this operation
183  */
184  share_type calculate_fee(const fee_params_t& fee_params)const;
185  };
186 
188  {
189  struct fee_params_t {};
190 
192  htlc_refund_operation( const htlc_id_type& htlc_id,
193  const account_id_type& htlc_from, const account_id_type& htlc_to, const asset& amount,
194  const htlc_hash& preimage_hash, uint16_t preimage_size ) :
196  htlc_preimage_hash(preimage_hash), htlc_preimage_size(preimage_size) {}
197 
198  account_id_type fee_payer()const { return to; }
199  void validate()const { FC_ASSERT( !"virtual operation" ); }
200 
202  share_type calculate_fee(const fee_params_t& k)const { return 0; }
203 
205 
206  htlc_id_type htlc_id; // of the associated htlc object; it is deleted during emittance of this operation
207  account_id_type to, original_htlc_recipient;
208  account_id_type htlc_from() const { return to; };
209  account_id_type htlc_to() const { return original_htlc_recipient; };
213  };
214  }
215 }
216 
218 
223 FC_REFLECT( graphene::protocol::htlc_extend_operation::fee_params_t, (fee) (fee_per_day))
224 FC_REFLECT( graphene::protocol::htlc_refund_operation::fee_params_t, ) // VIRTUAL
225 
226 FC_REFLECT( graphene::protocol::htlc_create_operation,
227  (fee)(from)(to)(amount)(preimage_hash)(preimage_size)(claim_period_seconds)(extensions))
228 FC_REFLECT( graphene::protocol::htlc_redeem_operation, (fee)(htlc_id)(redeemer)(preimage)(extensions))
229 FC_REFLECT( graphene::protocol::htlc_redeemed_operation,
230  (fee)(htlc_id)(from)(to)(redeemer)(amount)(htlc_preimage_hash)(htlc_preimage_size)(preimage))
231 FC_REFLECT( graphene::protocol::htlc_extend_operation, (fee)(htlc_id)(update_issuer)(seconds_to_add)(extensions))
232 FC_REFLECT( graphene::protocol::htlc_refund_operation,
233  (fee)(htlc_id)(to)(original_htlc_recipient)(htlc_amount)(htlc_preimage_hash)(htlc_preimage_size))
234 
235 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::htlc_create_operation::fee_params_t )
236 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::htlc_create_operation::additional_options_type )
237 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::htlc_redeem_operation::fee_params_t )
238 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::htlc_extend_operation::fee_params_t )
239 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::htlc_create_operation )
240 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::htlc_redeem_operation )
241 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::htlc_redeemed_operation )
242 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::htlc_extend_operation )
243 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::htlc_refund_operation )
graphene::protocol::htlc_algo_sha256
fc::sha256 htlc_algo_sha256
Definition: htlc.hpp:35
graphene::protocol::htlc_refund_operation::fee
asset fee
Definition: htlc.hpp:204
graphene::protocol::htlc_refund_operation::htlc_id
htlc_id_type htlc_id
Definition: htlc.hpp:206
graphene::protocol::htlc_redeem_operation::fee_params_t
Definition: htlc.hpp:92
graphene::protocol::extension
Definition: ext.hpp:36
graphene::protocol::htlc_refund_operation::fee_payer
account_id_type fee_payer() const
Definition: htlc.hpp:198
graphene::protocol::htlc_create_operation::fee_payer
account_id_type fee_payer() const
who will pay the fee
Definition: htlc.hpp:82
graphene::protocol::htlc_create_operation::fee
asset fee
Definition: htlc.hpp:53
graphene::protocol::htlc_refund_operation::htlc_preimage_size
uint16_t htlc_preimage_size
Definition: htlc.hpp:212
graphene::protocol::htlc_create_operation::fee_params_t::fee
uint64_t fee
Definition: htlc.hpp:48
graphene::protocol::htlc_refund_operation::htlc_refund_operation
htlc_refund_operation(const htlc_id_type &htlc_id, const account_id_type &htlc_from, const account_id_type &htlc_to, const asset &amount, const htlc_hash &preimage_hash, uint16_t preimage_size)
Definition: htlc.hpp:192
graphene::protocol::htlc_hash
fc::static_variant< htlc_algo_ripemd160, htlc_algo_sha1, htlc_algo_sha256, htlc_algo_hash160 > htlc_hash
Definition: htlc.hpp:43
fc::static_variant
Definition: raw_fwd.hpp:27
FC_REFLECT_TYPENAME
FC_REFLECT_TYPENAME(fc::log_message)
graphene::protocol::htlc_create_operation::preimage_size
uint16_t preimage_size
Definition: htlc.hpp:63
graphene::protocol::htlc_redeem_operation
Definition: htlc.hpp:90
graphene::protocol::htlc_extend_operation::fee_params_t::fee
uint64_t fee
Definition: htlc.hpp:156
graphene::protocol::htlc_refund_operation
Definition: htlc.hpp:187
graphene::protocol::htlc_redeem_operation::preimage
std::vector< char > preimage
Definition: htlc.hpp:104
graphene::protocol::htlc_create_operation::from
account_id_type from
Definition: htlc.hpp:55
graphene::protocol::htlc_refund_operation::fee_params_t
Definition: htlc.hpp:189
graphene::protocol::htlc_refund_operation::original_htlc_recipient
account_id_type original_htlc_recipient
Definition: htlc.hpp:207
graphene::protocol::htlc_redeem_operation::validate
void validate() const
Definition: htlc.cpp:49
fc::sha256
Definition: sha256.hpp:10
graphene::protocol::htlc_redeemed_operation::calculate_fee
share_type calculate_fee(const fee_params_t &k) const
Definition: htlc.hpp:141
graphene::protocol::htlc_extend_operation::htlc_id
htlc_id_type htlc_id
Definition: htlc.hpp:163
graphene::protocol::htlc_redeemed_operation::htlc_id
htlc_id_type htlc_id
Definition: htlc.hpp:143
graphene::protocol::htlc_extend_operation::fee_params_t
Definition: htlc.hpp:155
graphene::protocol::htlc_extend_operation::validate
void validate() const
Definition: htlc.cpp:61
graphene::protocol::htlc_redeemed_operation
Definition: htlc.hpp:127
graphene::protocol::htlc_refund_operation::htlc_to
account_id_type htlc_to() const
Definition: htlc.hpp:209
graphene::protocol::base_operation
Definition: base.hpp:124
graphene::protocol::htlc_redeemed_operation::to
account_id_type to
Definition: htlc.hpp:144
graphene::protocol::htlc_create_operation::to
account_id_type to
Definition: htlc.hpp:57
graphene::protocol::htlc_create_operation
Definition: htlc.hpp:45
graphene::protocol::htlc_create_operation::fee_params_t::fee_per_day
uint64_t fee_per_day
Definition: htlc.hpp:49
graphene::protocol::htlc_create_operation::calculate_fee
share_type calculate_fee(const fee_params_t &fee_params, uint32_t fee_per_kb) const
Definition: htlc.cpp:37
memo.hpp
GRAPHENE_BLOCKCHAIN_PRECISION
#define GRAPHENE_BLOCKCHAIN_PRECISION
Definition: config.hpp:29
graphene::protocol::htlc_redeem_operation::calculate_fee
share_type calculate_fee(const fee_params_t &fee_params) const
Definition: htlc.cpp:53
graphene::protocol::htlc_extend_operation::update_issuer
account_id_type update_issuer
Definition: htlc.hpp:165
graphene::protocol::htlc_redeemed_operation::htlc_preimage_hash
htlc_hash htlc_preimage_hash
Definition: htlc.hpp:146
graphene::protocol::htlc_refund_operation::htlc_amount
asset htlc_amount
Definition: htlc.hpp:209
graphene::protocol::htlc_create_operation::amount
asset amount
Definition: htlc.hpp:59
graphene::protocol::htlc_create_operation::additional_options_type::memo
fc::optional< memo_data > memo
Definition: htlc.hpp:70
fc::ripemd160
Definition: ripemd160.hpp:11
graphene::protocol::htlc_algo_sha1
fc::sha1 htlc_algo_sha1
Definition: htlc.hpp:34
graphene::protocol::htlc_redeem_operation::fee
asset fee
Definition: htlc.hpp:98
graphene::protocol::htlc_redeem_operation::htlc_id
htlc_id_type htlc_id
Definition: htlc.hpp:100
GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
graphene::protocol::htlc_redeemed_operation::from
account_id_type from
Definition: htlc.hpp:144
graphene::protocol::htlc_algo_hash160
fc::hash160 htlc_algo_hash160
Definition: htlc.hpp:36
graphene::protocol::htlc_redeemed_operation::fee
asset fee
Definition: htlc.hpp:149
graphene::protocol::htlc_refund_operation::htlc_from
account_id_type htlc_from() const
Definition: htlc.hpp:208
graphene::protocol::htlc_redeem_operation::fee_payer
account_id_type fee_payer() const
Who is to pay the fee.
Definition: htlc.hpp:116
graphene::protocol::htlc_redeemed_operation::redeemer
account_id_type redeemer
Definition: htlc.hpp:144
graphene::protocol::htlc_refund_operation::calculate_fee
share_type calculate_fee(const fee_params_t &k) const
This is a virtual operation; there is no fee.
Definition: htlc.hpp:202
graphene::protocol::htlc_redeem_operation::fee_params_t::fee
uint64_t fee
Definition: htlc.hpp:93
graphene::protocol::htlc_redeemed_operation::fee_params_t
Definition: htlc.hpp:129
graphene::protocol::htlc_redeemed_operation::htlc_redeemed_operation
htlc_redeemed_operation()
Definition: htlc.hpp:131
graphene::protocol::htlc_refund_operation::htlc_refund_operation
htlc_refund_operation()
Definition: htlc.hpp:191
graphene::protocol::htlc_create_operation::preimage_hash
htlc_hash preimage_hash
Definition: htlc.hpp:61
graphene::protocol::htlc_refund_operation::validate
void validate() const
Definition: htlc.hpp:199
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
fc::sha1
Definition: sha1.hpp:10
graphene::protocol::htlc_refund_operation::to
account_id_type to
Definition: htlc.hpp:207
base.hpp
graphene::protocol::htlc_redeem_operation::fee_params_t::fee_per_kb
uint64_t fee_per_kb
Definition: htlc.hpp:94
graphene::protocol::htlc_create_operation::fee_params_t
Definition: htlc.hpp:47
graphene::protocol::htlc_create_operation::validate
void validate() const
Definition: htlc.cpp:32
graphene::protocol::htlc_refund_operation::htlc_preimage_hash
htlc_hash htlc_preimage_hash
Definition: htlc.hpp:211
FC_REFLECT
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:388
graphene::protocol::htlc_extend_operation
Definition: htlc.hpp:153
graphene::protocol::htlc_extend_operation::calculate_fee
share_type calculate_fee(const fee_params_t &fee_params) const
Definition: htlc.cpp:65
fc::optional
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
graphene::protocol::htlc_redeemed_operation::htlc_preimage_size
uint16_t htlc_preimage_size
Definition: htlc.hpp:147
time.hpp
graphene::protocol::htlc_extend_operation::fee_payer
account_id_type fee_payer() const
Who is to pay the fee.
Definition: htlc.hpp:179
graphene::protocol::htlc_redeem_operation::redeemer
account_id_type redeemer
Definition: htlc.hpp:102
fc::hash160
Definition: hash160.hpp:32
graphene::protocol::asset
Definition: asset.hpp:31
asset.hpp
graphene::protocol::htlc_redeemed_operation::preimage
std::vector< char > preimage
Definition: htlc.hpp:150
graphene::protocol::htlc_extend_operation::fee
asset fee
Definition: htlc.hpp:161
graphene::protocol::htlc_extend_operation::seconds_to_add
uint32_t seconds_to_add
Definition: htlc.hpp:167
graphene::protocol::htlc_create_operation::extensions
extension< additional_options_type > extensions
Definition: htlc.hpp:72
graphene::protocol::htlc_extend_operation::extensions
extensions_type extensions
Definition: htlc.hpp:169
graphene::protocol::htlc_create_operation::additional_options_type
Definition: htlc.hpp:68
graphene::protocol::htlc_extend_operation::fee_params_t::fee_per_day
uint64_t fee_per_day
Definition: htlc.hpp:157
graphene::protocol::htlc_redeemed_operation::fee_payer
account_id_type fee_payer() const
Definition: htlc.hpp:138
graphene::protocol::htlc_algo_ripemd160
fc::ripemd160 htlc_algo_ripemd160
Definition: htlc.hpp:33
graphene
Definition: api.cpp:48
graphene::protocol::htlc_redeemed_operation::validate
void validate() const
Definition: htlc.hpp:139
graphene::protocol::htlc_create_operation::claim_period_seconds
uint32_t claim_period_seconds
Definition: htlc.hpp:65
graphene::protocol::htlc_redeemed_operation::htlc_redeemed_operation
htlc_redeemed_operation(htlc_id_type htlc_id, account_id_type from, account_id_type to, account_id_type redeemer, asset amount, const htlc_hash &preimage_hash, uint16_t preimage_size, const std::vector< char > &preimage)
Definition: htlc.hpp:132
graphene::protocol::htlc_redeemed_operation::amount
asset amount
Definition: htlc.hpp:145
graphene::protocol::extensions_type
future_extensions::flat_set_type extensions_type
Definition: base.hpp:156
graphene::protocol::htlc_redeem_operation::extensions
extensions_type extensions
Definition: htlc.hpp:106
fc::safe
Definition: safe.hpp:26