BitShares-Core  5.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);
52 };
53 
54 // BLOCK TRX OP VOP
56 {
57 private:
58  std::ostream& out;
59  const wallet_api_impl& wallet;
62 
63  std::string fee(const graphene::protocol::asset& a) const;
64 
65 public:
66  operation_printer( std::ostream& out, const wallet_api_impl& wallet,
68  : out(out),
69  wallet(wallet),
70  result(obj.result),
71  hist(obj)
72  {}
73  typedef std::string result_type;
74 
75  template<typename T>
76  std::string operator()(const T& op)const
77  {
78  auto a = wallet.get_asset( op.fee.asset_id );
79  auto payer = wallet.get_account( op.fee_payer() );
80 
81  std::string op_name = fc::get_typename<T>::name();
82  if( op_name.find_last_of(':') != std::string::npos )
83  op_name.erase(0, op_name.find_last_of(':')+1);
84  out << op_name <<" ";
85  out << payer.name << " fee: " << a.amount_to_pretty_string( op.fee );
86  operation_result_printer rprinter(wallet);
87  std::string str_result = result.visit(rprinter);
88  if( str_result != "" )
89  {
90  out << " result: " << str_result;
91  }
92  return "";
93  }
94 
95  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::htlc_create_operation& op)const;
102  std::string operator()(const graphene::protocol::htlc_redeem_operation& op)const;
103  std::string operator()(const graphene::protocol::htlc_redeemed_operation& op)const;
104  protected:
105  std::string print_memo( const fc::optional<graphene::protocol::memo_data>& memo)const;
106  void print_preimage( const std::vector<char>& preimage)const;
107  std::string print_redeem(const graphene::protocol::htlc_id_type& id,
108  const std::string& redeemer, const std::vector<char>& preimage,
109  const graphene::protocol::asset& op_fee)const;
110 };
111 
112 }}} // 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.