BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface 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);
49  std::string operator()(const graphene::protocol::asset& a);
51 };
52 
53 // BLOCK TRX OP VOP
55 {
56 private:
57  std::ostream& out;
58  const wallet_api_impl& wallet;
61 
62  std::string fee(const graphene::protocol::asset& a) const;
63 
64 public:
65  operation_printer( std::ostream& out, const wallet_api_impl& wallet,
67  : out(out),
68  wallet(wallet),
69  result(obj.result),
70  hist(obj)
71  {}
72  typedef std::string result_type;
73 
74  template<typename T>
75  std::string operator()(const T& op)const
76  {
77  auto a = wallet.get_asset( op.fee.asset_id );
78  auto payer = wallet.get_account( op.fee_payer() );
79 
80  std::string op_name = fc::get_typename<T>::name();
81  if( op_name.find_last_of(':') != std::string::npos )
82  op_name.erase(0, op_name.find_last_of(':')+1);
83  out << op_name <<" ";
84  out << payer.name << " fee: " << a.amount_to_pretty_string( op.fee );
85  operation_result_printer rprinter(wallet);
86  std::string str_result = result.visit(rprinter);
87  if( str_result != "" )
88  {
89  out << " result: " << str_result;
90  }
91  return "";
92  }
93 
94  std::string operator()(const graphene::protocol::transfer_operation& op)const;
97  std::string operator()(const graphene::protocol::account_create_operation& op)const;
98  std::string operator()(const graphene::protocol::account_update_operation& op)const;
99  std::string operator()(const graphene::protocol::asset_create_operation& op)const;
100  std::string operator()(const graphene::protocol::htlc_create_operation& op)const;
101  std::string operator()(const graphene::protocol::htlc_redeem_operation& op)const;
102  std::string operator()(const graphene::protocol::htlc_redeemed_operation& op)const;
103  protected:
104  std::string print_memo( const fc::optional<graphene::protocol::memo_data>& memo)const;
105  void print_preimage( const std::vector<char>& preimage)const;
106  std::string print_redeem(const graphene::protocol::htlc_id_type& id,
107  const std::string& redeemer, const std::vector<char>& preimage,
108  const graphene::protocol::asset& op_fee)const;
109 };
110 
111 }}} // namespace graphene::wallet::detail
operation_printer(std::ostream &out, const wallet_api_impl &wallet, const graphene::chain::operation_history_object &obj)
tracks the history of all logical operations on blockchain stateAll operations and virtual operations...
Definition: api.cpp:56
Update an existing account.
Definition: account.hpp:135
std::string operator()(const graphene::protocol::void_result &x) const
account_object get_account(account_id_type id) const
visitor::result_type visit(visitor &v)
Transfers an amount of one asset from one account to another.
Definition: transfer.hpp:45
Converts blinded/stealth balance to a public account balance.
std::string operator()(const T &op) const
extended_asset_object get_asset(asset_id_type id) const
Converts public account balance to a blinded or stealth balance.