BitShares-Core  6.1.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  transaction_handle_type trx_handle = _builder_transactions.empty() ? 0
31  : (--_builder_transactions.end())->first + 1;
32  _builder_transactions[trx_handle] = {}; // Reset if exists already
33  return trx_handle;
34  }
35 
37  const operation& op)
38  {
39  FC_ASSERT(_builder_transactions.count(transaction_handle) > 0);
40  _builder_transactions[transaction_handle].operations.emplace_back(op);
41  }
42 
44  uint32_t operation_index, const operation& new_op)
45  {
46  FC_ASSERT(_builder_transactions.count(handle) > 0);
47  signed_transaction& trx = _builder_transactions[handle];
48  FC_ASSERT( operation_index < trx.operations.size());
49  trx.operations[operation_index] = new_op;
50  }
51 
53  {
54  FC_ASSERT(_builder_transactions.count(handle) > 0);
55 
56  auto fee_asset_obj = get_asset(fee_asset);
57  asset total_fee = fee_asset_obj.amount(0);
58 
59  auto gprops = _remote_db->get_global_properties().parameters;
60  if( fee_asset_obj.get_id() != asset_id_type() )
61  {
62  for( auto& op : _builder_transactions[handle].operations )
63  total_fee += gprops.get_current_fees().set_fee( op, fee_asset_obj.options.core_exchange_rate );
64 
65  FC_ASSERT((total_fee * fee_asset_obj.options.core_exchange_rate).amount <=
66  get_object(fee_asset_obj.dynamic_asset_data_id).fee_pool,
67  "Cannot pay fees in ${asset}, as this asset's fee pool is insufficiently funded.",
68  ("asset", fee_asset_obj.symbol));
69  } else {
70  for( auto& op : _builder_transactions[handle].operations )
71  total_fee += gprops.get_current_fees().set_fee( op );
72  }
73 
74  return total_fee;
75  }
76 
78  {
79  FC_ASSERT(_builder_transactions.count(handle) > 0);
80  return _builder_transactions[handle];
81  }
82 
84  transaction_handle, bool broadcast )
85  {
86  FC_ASSERT(_builder_transactions.count(transaction_handle) > 0);
87 
88  return _builder_transactions[transaction_handle] =
89  sign_transaction(_builder_transactions[transaction_handle], broadcast);
90  }
91 
93  transaction_handle, const vector<public_key_type>& signing_keys, bool broadcast)
94  {
95  FC_ASSERT(_builder_transactions.count(transaction_handle) > 0);
96 
97  return _builder_transactions[transaction_handle] =
98  sign_transaction2(_builder_transactions[transaction_handle], signing_keys, broadcast);
99  }
100 
102  time_point_sec expiration, uint32_t review_period_seconds, bool broadcast)
103  {
104  return propose_builder_transaction2( handle, "1.2.0", expiration, review_period_seconds, broadcast );
105  }
106 
108  string account_name_or_id, time_point_sec expiration, uint32_t review_period_seconds, bool broadcast )
109  {
110  FC_ASSERT(_builder_transactions.count(handle) > 0);
112  pcop.fee_paying_account = get_account(account_name_or_id).get_id();
113  pcop.expiration_time = expiration;
114  signed_transaction& trx = _builder_transactions[handle];
115  std::transform(trx.operations.begin(), trx.operations.end(), std::back_inserter(pcop.proposed_ops),
116  [](const operation& op) { return op_wrapper(op); });
117  if( review_period_seconds )
118  pcop.review_period_seconds = review_period_seconds;
119  trx.operations = {pcop};
120  _remote_db->get_global_properties().parameters.get_current_fees().set_fee( trx.operations.front() );
121 
122  return trx = sign_transaction(trx, broadcast);
123  }
124 
126  {
127  _builder_transactions.erase(handle);
128  }
129 
130 }}} // namespace graphene::wallet::detail1
extended_asset_object get_asset(asset_id_type id) const
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:152
vector< operation > operations
Definition: transaction.hpp:89
Definition: api.cpp:48
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, liquidity_pool_create_operation, liquidity_pool_delete_operation, liquidity_pool_deposit_operation, liquidity_pool_withdraw_operation, liquidity_pool_exchange_operation, samet_fund_create_operation, samet_fund_delete_operation, samet_fund_update_operation, samet_fund_borrow_operation, samet_fund_repay_operation, credit_offer_create_operation, credit_offer_delete_operation, credit_offer_update_operation, credit_offer_accept_operation, credit_deal_repay_operation, credit_deal_expired_operation >
transaction_handle_type begin_builder_transaction()
groups operations that should be applied atomically
Definition: transaction.hpp:69
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)
object_id< SpaceID, TypeID > get_id() const
Definition: object.hpp:113
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
graphene::db::object_downcast_t< const ID & > get_object(const ID &id) const
typename impl::transform< List, Transformer >::type transform
Transform elements of a typelist.
Definition: typelist.hpp:170
transaction preview_builder_transaction(transaction_handle_type handle)
uint32_t transaction_handle_type
account_object get_account(account_id_type id) const
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)