BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface 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<
42  htlc_algo_hash160
44 
46  {
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_parameters_type& fee_params, uint32_t fee_per_kb)const;
88  };
89 
91  {
94  uint64_t fee_per_kb = 1 * GRAPHENE_BLOCKCHAIN_PRECISION;
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_parameters_type& fee_params)const;
122  };
123 
128  {
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 ) :
135  htlc_id(htlc_id), from(from), to(to), redeemer(redeemer), amount(amount),
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_parameters_type& 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  {
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_parameters_type& fee_params)const;
185  };
186 
188  {
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 ) :
195  htlc_id(htlc_id), to(htlc_from), original_htlc_recipient(htlc_to), htlc_amount(amount),
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_parameters_type& 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; };
210  asset htlc_amount;
213  };
214  }
215 }
216 
218 
220 FC_REFLECT( graphene::protocol::htlc_create_operation::additional_options_type, (memo))
221 FC_REFLECT( graphene::protocol::htlc_redeem_operation::fee_parameters_type, (fee) (fee_per_kb) )
222 FC_REFLECT( graphene::protocol::htlc_redeemed_operation::fee_parameters_type, ) // VIRTUAL
223 FC_REFLECT( graphene::protocol::htlc_extend_operation::fee_parameters_type, (fee) (fee_per_day))
224 FC_REFLECT( graphene::protocol::htlc_refund_operation::fee_parameters_type, ) // VIRTUAL
225 
228 FC_REFLECT( graphene::protocol::htlc_redeem_operation, (fee)(htlc_id)(redeemer)(preimage)(extensions))
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))
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_parameters_type )
236 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::htlc_create_operation::additional_options_type )
237 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::htlc_redeem_operation::fee_parameters_type )
238 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::htlc_extend_operation::fee_parameters_type )
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 )
future_extensions::flat_set_type extensions_type
Definition: base.hpp:141
account_id_type fee_payer() const
who will pay the fee
Definition: htlc.hpp:82
account_id_type htlc_to() const
Definition: htlc.hpp:209
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:386
account_id_type htlc_from() const
Definition: htlc.hpp:208
Definition: api.cpp:56
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
fc::sha1 htlc_algo_sha1
Definition: htlc.hpp:34
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
extension< additional_options_type > extensions
Definition: htlc.hpp:72
FC_REFLECT_TYPENAME(fc::log_message)
account_id_type fee_payer() const
Definition: htlc.hpp:138
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
fc::hash160 htlc_algo_hash160
Definition: htlc.hpp:36
account_id_type fee_payer() const
Who is to pay the fee.
Definition: htlc.hpp:116
account_id_type fee_payer() const
Who is to pay the fee.
Definition: htlc.hpp:179
#define GRAPHENE_BLOCKCHAIN_PRECISION
Definition: config.hpp:29
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
account_id_type fee_payer() const
Definition: htlc.hpp:198
share_type calculate_fee(const fee_parameters_type &fee_params, uint32_t fee_per_kb) const
Definition: htlc.cpp:37
fc::ripemd160 htlc_algo_ripemd160
Definition: htlc.hpp:33
fc::static_variant< htlc_algo_ripemd160, htlc_algo_sha1, htlc_algo_sha256, htlc_algo_hash160 > htlc_hash
Definition: htlc.hpp:43
fc::sha256 htlc_algo_sha256
Definition: htlc.hpp:35
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
share_type calculate_fee(const fee_parameters_type &k) const
Definition: htlc.hpp:141
share_type calculate_fee(const fee_parameters_type &k) const
This is a virtual operation; there is no fee.
Definition: htlc.hpp:202