BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
operation_printer.hpp
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 #pragma once
25 
31 
32 #include <string>
33 #include <ostream>
34 
35 #include "wallet_api_impl.hpp"
36 
37 namespace graphene { namespace wallet { namespace detail {
38 
40 {
41 public:
43  : _wallet(w) {}
45  typedef std::string result_type;
46 
47  std::string operator()(const graphene::protocol::void_result& x) const;
48  std::string operator()(const graphene::protocol::object_id_type& oid) const;
49  std::string operator()(const graphene::protocol::asset& a) const;
50  std::string operator()(const graphene::protocol::generic_operation_result& r) const;
53 };
54 
55 // BLOCK TRX OP VOP
57 {
58 private:
59  std::ostream& out;
60  const wallet_api_impl& wallet;
63 
64  std::string format_asset(const graphene::protocol::asset& a) const;
65  void print_fee(const graphene::protocol::asset& a) const;
66 
67 public:
68  operation_printer( std::ostream& out, const wallet_api_impl& wallet,
70  : out(out),
71  wallet(wallet),
72  result(obj.result),
73  hist(obj)
74  {}
75 
77  typedef std::string result_type;
78 
79  template<typename T>
80  std::string operator()(const T& op)const
81  {
82  auto payer = wallet.get_account( op.fee_payer() );
83 
84  std::string op_name = fc::get_typename<T>::name();
85  if( op_name.find_last_of(':') != std::string::npos )
86  op_name.erase(0, op_name.find_last_of(':')+1);
87  out << op_name << " ";
88  out << payer.name;
89  print_fee( op.fee );
90  print_result();
91  return "";
92  }
93 
94  std::string operator()(const graphene::protocol::transfer_operation& op)const;
98  std::string operator()(const graphene::protocol::account_create_operation& op)const;
99  std::string operator()(const graphene::protocol::account_update_operation& op)const;
100  std::string operator()(const graphene::protocol::asset_create_operation& op)const;
101  std::string operator()(const graphene::protocol::asset_update_operation& op)const;
107  std::string operator()(const graphene::protocol::asset_issue_operation& op)const;
108  std::string operator()(const graphene::protocol::asset_reserve_operation& op)const;
109  std::string operator()(const graphene::protocol::asset_settle_operation& op)const;
113  std::string operator()(const graphene::protocol::fill_order_operation& op)const;
114  std::string operator()(const graphene::protocol::proposal_update_operation& op)const;
115  std::string operator()(const graphene::protocol::htlc_create_operation& op)const;
116  std::string operator()(const graphene::protocol::htlc_redeem_operation& op)const;
117  std::string operator()(const graphene::protocol::htlc_redeemed_operation& op)const;
118 
119 protected:
120  std::string print_memo( const fc::optional<graphene::protocol::memo_data>& memo)const;
121  void print_preimage( const std::vector<char>& preimage)const;
122  void print_redeem(const graphene::protocol::htlc_id_type& id,
123  const std::string& redeemer, const std::vector<char>& preimage,
124  const graphene::protocol::asset& op_fee)const;
125  void print_result()const;
126 };
127 
128 }}} // namespace graphene::wallet::detail
graphene::protocol::proposal_update_operation
The proposal_update_operation updates an existing transaction proposal.
Definition: proposal.hpp:119
graphene::protocol::transfer_to_blind_operation
Converts public account balance to a blinded or stealth balance.
Definition: confidential.hpp:150
graphene::protocol::extension
Definition: ext.hpp:36
graphene::protocol::fill_order_operation
Definition: market.hpp:206
fc::static_variant< void_result, object_id_type, asset, generic_operation_result, generic_exchange_operation_result, extendable_operation_result >
graphene::protocol::htlc_redeem_operation
Definition: htlc.hpp:90
graphene::wallet::detail::operation_result_printer::_wallet
const wallet_api_impl & _wallet
Definition: operation_printer.hpp:44
graphene::wallet::detail::operation_result_printer::result_type
std::string result_type
Definition: operation_printer.hpp:45
graphene::wallet::detail::operation_printer::print_redeem
void print_redeem(const graphene::protocol::htlc_id_type &id, const std::string &redeemer, const std::vector< char > &preimage, const graphene::protocol::asset &op_fee) const
Definition: operation_printer.cpp:124
graphene::wallet::detail::operation_printer::print_result
void print_result() const
Definition: operation_printer.cpp:66
wallet_api_impl.hpp
graphene::wallet::detail::wallet_api_impl
Definition: wallet_api_impl.hpp:94
graphene::protocol::htlc_redeemed_operation
Definition: htlc.hpp:127
graphene::wallet::detail::wallet_api_impl::get_account
account_object get_account(account_id_type id) const
Definition: wallet_account.cpp:193
graphene::wallet::detail::operation_result_printer::operator()
std::string operator()(const graphene::protocol::void_result &x) const
Definition: operation_printer.cpp:362
graphene::protocol::account_update_operation
Update an existing account.
Definition: account.hpp:136
graphene::protocol::htlc_create_operation
Definition: htlc.hpp:45
graphene::wallet::detail::operation_printer::result_type
std::string result_type
Return the decrypted memo if a memo exists, otherwise return an empty string.
Definition: operation_printer.hpp:77
graphene::wallet::detail::operation_printer::operator()
std::string operator()(const T &op) const
Definition: operation_printer.hpp:80
graphene::protocol::transfer_from_blind_operation
Converts blinded/stealth balance to a public account balance.
Definition: confidential.hpp:173
operations.hpp
graphene::wallet::detail::operation_printer::operation_printer
operation_printer(std::ostream &out, const wallet_api_impl &wallet, const graphene::chain::operation_history_object &obj)
Definition: operation_printer.hpp:68
graphene::protocol::asset_reserve_operation
used to take an asset out of circulation, returning to the issuer
Definition: asset_ops.hpp:513
graphene::protocol::call_order_update_operation
Definition: market.hpp:171
graphene::protocol::asset_update_operation
Update options common to all assets.
Definition: asset_ops.hpp:351
graphene::wallet::detail::operation_printer::print_preimage
void print_preimage(const std::vector< char > &preimage) const
Definition: operation_printer.cpp:108
graphene::wallet::detail::operation_printer::print_memo
std::string print_memo(const fc::optional< graphene::protocol::memo_data > &memo) const
Definition: operation_printer.cpp:76
graphene::protocol::account_create_operation
Definition: account.hpp:81
graphene::protocol::transfer_operation
Transfers an amount of one asset from one account to another.
Definition: transfer.hpp:45
fc::get_typename
Definition: typename.hpp:20
graphene::protocol::generic_exchange_operation_result
Definition: base.hpp:95
graphene::protocol::limit_order_cancel_operation
Definition: market.hpp:145
graphene::protocol::asset_update_bitasset_operation
Update options specific to BitAssets.
Definition: asset_ops.hpp:398
graphene::protocol::asset_publish_feed_operation
Publish price feeds for market-issued assets.
Definition: asset_ops.hpp:462
api_objects.hpp
graphene::protocol::asset_update_feed_producers_operation
Update the set of feed-producing accounts for a BitAsset.
Definition: asset_ops.hpp:430
base.hpp
graphene::protocol::asset_settle_operation
Schedules a market-issued asset for automatic settlement.
Definition: asset_ops.hpp:267
graphene::db::object_id_type
Definition: object_id.hpp:30
operation_history_object.hpp
graphene::protocol::limit_order_create_operation
instructs the blockchain to attempt to sell one asset for another
Definition: market.hpp:72
graphene::protocol::asset_fund_fee_pool_operation
Definition: asset_ops.hpp:322
graphene::protocol::override_transfer_operation
Allows the issuer of an asset to transfer an asset from any account to any account if they have overr...
Definition: transfer.hpp:77
fc::optional< graphene::protocol::memo_data >
graphene::protocol::asset
Definition: asset.hpp:31
graphene::protocol::void_result
Definition: base.hpp:86
asset.hpp
graphene::wallet::detail::operation_printer
Definition: operation_printer.hpp:56
graphene::protocol::asset_issue_operation
Definition: asset_ops.hpp:485
graphene::protocol::generic_operation_result
Definition: base.hpp:88
graphene
Definition: api.cpp:48
graphene::wallet::detail::operation_result_printer::operation_result_printer
operation_result_printer(const wallet_api_impl &w)
Definition: operation_printer.hpp:42
graphene::protocol::asset_create_operation
Definition: asset_ops.hpp:192
graphene::protocol::asset_claim_pool_operation
Transfers BTS from the fee pool of a specified asset back to the issuer's balance.
Definition: asset_ops.hpp:601
graphene::chain::operation_history_object
tracks the history of all logical operations on blockchain state
Definition: operation_history_object.hpp:48
graphene::wallet::detail::operation_result_printer
Definition: operation_printer.hpp:39