BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
wallet_builder.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cryptonomex, Inc., 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 #include "wallet_api_impl.hpp"
25 
26 namespace graphene { namespace wallet { namespace detail {
27 
29  {
30  int trx_handle = _builder_transactions.empty()? 0
31  : (--_builder_transactions.end())->first + 1;
32  _builder_transactions[trx_handle];
33  return trx_handle;
34  }
35 
37  {
38  FC_ASSERT(_builder_transactions.count(transaction_handle));
39  _builder_transactions[transaction_handle].operations.emplace_back(op);
40  }
41 
43  uint32_t operation_index, const operation& new_op)
44  {
45  FC_ASSERT(_builder_transactions.count(handle));
46  signed_transaction& trx = _builder_transactions[handle];
47  FC_ASSERT( operation_index < trx.operations.size());
48  trx.operations[operation_index] = new_op;
49  }
50 
52  {
53  FC_ASSERT(_builder_transactions.count(handle));
54 
55  auto fee_asset_obj = get_asset(fee_asset);
56  asset total_fee = fee_asset_obj.amount(0);
57 
58  auto gprops = _remote_db->get_global_properties().parameters;
59  if( fee_asset_obj.get_id() != asset_id_type() )
60  {
61  for( auto& op : _builder_transactions[handle].operations )
62  total_fee += gprops.get_current_fees().set_fee( op, fee_asset_obj.options.core_exchange_rate );
63 
64  FC_ASSERT((total_fee * fee_asset_obj.options.core_exchange_rate).amount <=
65  get_object(fee_asset_obj.dynamic_asset_data_id).fee_pool,
66  "Cannot pay fees in ${asset}, as this asset's fee pool is insufficiently funded.",
67  ("asset", fee_asset_obj.symbol));
68  } else {
69  for( auto& op : _builder_transactions[handle].operations )
70  total_fee += gprops.get_current_fees().set_fee( op );
71  }
72 
73  return total_fee;
74  }
75 
77  {
78  FC_ASSERT(_builder_transactions.count(handle));
79  return _builder_transactions[handle];
80  }
81 
83  transaction_handle, bool broadcast )
84  {
85  FC_ASSERT(_builder_transactions.count(transaction_handle));
86 
87  return _builder_transactions[transaction_handle] =
88  sign_transaction(_builder_transactions[transaction_handle], broadcast);
89  }
90 
92  transaction_handle, const vector<public_key_type>& signing_keys, bool broadcast)
93  {
94  FC_ASSERT(_builder_transactions.count(transaction_handle));
95 
96  return _builder_transactions[transaction_handle] =
97  sign_transaction2(_builder_transactions[transaction_handle], signing_keys, broadcast);
98  }
99 
101  time_point_sec expiration, uint32_t review_period_seconds, bool broadcast)
102  {
103  FC_ASSERT(_builder_transactions.count(handle));
105  op.expiration_time = expiration;
106  signed_transaction& trx = _builder_transactions[handle];
107  std::transform(trx.operations.begin(), trx.operations.end(), std::back_inserter(op.proposed_ops),
108  [](const operation& op) -> op_wrapper { return op; });
109  if( review_period_seconds )
110  op.review_period_seconds = review_period_seconds;
111  trx.operations = {op};
112  _remote_db->get_global_properties().parameters.get_current_fees().set_fee( trx.operations.front() );
113 
114  return trx = sign_transaction(trx, broadcast);
115  }
116 
118  string account_name_or_id, time_point_sec expiration, uint32_t review_period_seconds, bool broadcast )
119  {
120  FC_ASSERT(_builder_transactions.count(handle));
122  op.fee_paying_account = get_account(account_name_or_id).get_id();
123  op.expiration_time = expiration;
124  signed_transaction& trx = _builder_transactions[handle];
125  std::transform(trx.operations.begin(), trx.operations.end(), std::back_inserter(op.proposed_ops),
126  [](const operation& op) -> op_wrapper { return op; });
127  if( review_period_seconds )
128  op.review_period_seconds = review_period_seconds;
129  trx.operations = {op};
130  _remote_db->get_global_properties().parameters.get_current_fees().set_fee( trx.operations.front() );
131 
132  return trx = sign_transaction(trx, broadcast);
133  }
134 
136  {
137  _builder_transactions.erase(handle);
138  }
139 
140 }}} // namespace graphene::wallet::detail1
signed_transaction sign_transaction2(signed_transaction tx, const vector< public_key_type > &signing_keys=vector< public_key_type >(), bool broadcast=false)
necessary to support nested operations inside the proposal_create_operation
Definition: operations.hpp:133
vector< operation > operations
Definition: transaction.hpp:89
Definition: api.cpp:56
void remove_builder_transaction(transaction_handle_type handle)
fc::static_variant< transfer_operation, limit_order_create_operation, limit_order_cancel_operation, call_order_update_operation, fill_order_operation, account_create_operation, account_update_operation, account_whitelist_operation, account_upgrade_operation, account_transfer_operation, asset_create_operation, asset_update_operation, asset_update_bitasset_operation, asset_update_feed_producers_operation, asset_issue_operation, asset_reserve_operation, asset_fund_fee_pool_operation, asset_settle_operation, asset_global_settle_operation, asset_publish_feed_operation, witness_create_operation, witness_update_operation, proposal_create_operation, proposal_update_operation, proposal_delete_operation, withdraw_permission_create_operation, withdraw_permission_update_operation, withdraw_permission_claim_operation, withdraw_permission_delete_operation, committee_member_create_operation, committee_member_update_operation, committee_member_update_global_parameters_operation, vesting_balance_create_operation, vesting_balance_withdraw_operation, worker_create_operation, custom_operation, assert_operation, balance_claim_operation, override_transfer_operation, transfer_to_blind_operation, blind_transfer_operation, transfer_from_blind_operation, asset_settle_cancel_operation, asset_claim_fees_operation, fba_distribute_operation, bid_collateral_operation, execute_bid_operation, asset_claim_pool_operation, asset_update_issuer_operation, htlc_create_operation, htlc_redeem_operation, htlc_redeemed_operation, htlc_extend_operation, htlc_refund_operation, custom_authority_create_operation, custom_authority_update_operation, custom_authority_delete_operation, ticket_create_operation, ticket_update_operation >
transaction_handle_type begin_builder_transaction()
groups operations that should be applied atomically
Definition: transaction.hpp:68
account_object get_account(account_id_type id) const
The proposal_create_operation creates a transaction proposal, for use in multi-sig scenariosCreates a...
Definition: proposal.hpp:70
signed_transaction propose_builder_transaction(transaction_handle_type handle, time_point_sec expiration=time_point::now()+fc::minutes(1), uint32_t review_period_seconds=0, bool broadcast=true)
account_id_type get_id() const
signed_transaction sign_transaction(signed_transaction tx, bool broadcast=false)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
signed_transaction sign_builder_transaction(transaction_handle_type transaction_handle, bool broadcast=true)
adds a signature to a transaction
signed_transaction propose_builder_transaction2(transaction_handle_type handle, string account_name_or_id, time_point_sec expiration=time_point::now()+fc::minutes(1), uint32_t review_period_seconds=0, bool broadcast=true)
signed_transaction sign_builder_transaction2(transaction_handle_type transaction_handle, const vector< public_key_type > &signing_keys=vector< public_key_type >(), bool broadcast=true)
at< List, 0 > first
Get the type at the beginning of the list.
Definition: typelist.hpp:190
typename impl::transform< List, Transformer >::type transform
Transform elements of a typelist.
Definition: typelist.hpp:170
uint16_t transaction_handle_type
graphene::db::object_downcast_t< ID > get_object(ID id) const
extended_asset_object get_asset(asset_id_type id) const
transaction preview_builder_transaction(transaction_handle_type handle)
void add_operation_to_builder_transaction(transaction_handle_type transaction_handle, const operation &op)
void replace_operation_in_builder_transaction(transaction_handle_type handle, uint32_t operation_index, const operation &new_op)
asset set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset=GRAPHENE_SYMBOL)