From f8b8f01a784e38dfefa8810594892425b030ed85 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Thu, 22 Oct 2015 11:03:15 -0400 Subject: [PATCH 1/5] genesis_util: Implement some more genesis utilities --- programs/genesis_util/CMakeLists.txt | 5 ++ programs/genesis_util/change_asset_symbol.py | 52 +++++++++++++++ programs/genesis_util/convert_address.cpp | 23 +++++++ .../genesis_util/generate_account_patch.py | 65 +++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 programs/genesis_util/change_asset_symbol.py create mode 100644 programs/genesis_util/convert_address.cpp create mode 100755 programs/genesis_util/generate_account_patch.py diff --git a/programs/genesis_util/CMakeLists.txt b/programs/genesis_util/CMakeLists.txt index 1125a108..9c3b278d 100644 --- a/programs/genesis_util/CMakeLists.txt +++ b/programs/genesis_util/CMakeLists.txt @@ -27,3 +27,8 @@ install( TARGETS LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ) + +add_executable( convert_address convert_address.cpp ) + +target_link_libraries( convert_address + PRIVATE graphene_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) diff --git a/programs/genesis_util/change_asset_symbol.py b/programs/genesis_util/change_asset_symbol.py new file mode 100644 index 00000000..98777f59 --- /dev/null +++ b/programs/genesis_util/change_asset_symbol.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 + +import argparse +import json +import sys + +def dump_json(obj, out, pretty): + if pretty: + json.dump(obj, out, indent=2, sort_keys=True) + else: + json.dump(obj, out, separators=(",", ":"), sort_keys=True) + return + +def main(): + parser = argparse.ArgumentParser(description="Change an asset's symbol with referential integrity") + parser.add_argument("-o", "--output", metavar="OUT", default="-", help="output filename (default: stdout)") + parser.add_argument("-i", "--input", metavar="IN", default="-", help="input filename (default: stdin)") + parser.add_argument("-f", "--from", metavar="PREFIX", default="", help="initial prefix") + parser.add_argument("-t", "--to", metavar="PREFIX", default="", help="new prefix") + parser.add_argument("-p", "--pretty", action="store_true", default=False, help="pretty print output") + opts = parser.parse_args() + + if opts.input == "-": + genesis = json.load(sys.stdin) + else: + with open(opts.input, "r") as f: + genesis = json.load(f) + + frum = opts.__dict__["from"] # from is a language keyword and cannot be an attribute name + + for asset in genesis["initial_assets"]: + if asset["symbol"] == frum: + asset["symbol"] = opts.to + + for balance in genesis["initial_balances"]: + if balance["asset_symbol"] == frum: + balance["asset_symbol"] = opts.to + + for vb in genesis["initial_vesting_balances"]: + if balance["asset_symbol"] == frum: + balance["asset_symbol"] = opts.to + + if opts.output == "-": + dump_json( genesis, sys.stdout, opts.pretty ) + sys.stdout.flush() + else: + with open(opts.output, "w") as f: + dump_json( genesis, f, opts.pretty ) + return + +if __name__ == "__main__": + main() diff --git a/programs/genesis_util/convert_address.cpp b/programs/genesis_util/convert_address.cpp new file mode 100644 index 00000000..828081c4 --- /dev/null +++ b/programs/genesis_util/convert_address.cpp @@ -0,0 +1,23 @@ + +/** + * Convert BTC / PTS addresses to a Graphene address. + */ + +#include +#include + +#include +#include + +using namespace graphene::chain; + +int main(int argc, char** argv) +{ + // grab 0 or more whitespace-delimited PTS addresses from stdin + std::string s; + while( std::cin >> s ) + { + std::cout << std::string( address( pts_address( s ) ) ) << std::endl; + } + return 0; +} diff --git a/programs/genesis_util/generate_account_patch.py b/programs/genesis_util/generate_account_patch.py new file mode 100755 index 00000000..df42e50c --- /dev/null +++ b/programs/genesis_util/generate_account_patch.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 + +import argparse +import json +import subprocess +import sys + +def dump_json(obj, out, pretty): + if pretty: + json.dump(obj, out, indent=2, sort_keys=True) + else: + json.dump(obj, out, separators=(",", ":"), sort_keys=True) + return + +def main(): + parser = argparse.ArgumentParser(description="Generate a patch file that adds init accounts") + parser.add_argument("-o", "--output", metavar="OUT", default="-", help="output filename (default: stdout)") + parser.add_argument("-a", "--accounts", metavar="ACCOUNTS", default="-", help="file containing name, balances to create") + parser.add_argument("-p", "--pretty", action="store_true", default=False, help="pretty print output") + parser.add_argument("-s", "--secret", metavar="SECRET", default=None, help="private key generation secret") + opts = parser.parse_args() + + if opts.secret is None: + sys.stderr.write("missing required parameter --secret\n") + sys.stderr.flush() + sys.exit(1) + + with open(opts.accounts, "r") as f: + accounts = json.load(f) + + initial_accounts = [] + initial_balances = [] + for e in accounts: + name = e["name"] + owner_str = subprocess.check_output(["programs/genesis_util/get_dev_key", opts.secret, "owner-"+name]).decode("utf-8") + active_str = subprocess.check_output(["programs/genesis_util/get_dev_key", opts.secret, "active-"+name]).decode("utf-8") + owner = json.loads(owner_str) + active = json.loads(active_str) + initial_accounts.append({ + "name" : name, + "owner_key" : owner[0]["public_key"], + "active_key" : active[0]["public_key"], + "is_lifetime_member" : True, + }) + for bal in e.get("balances", []): + bal = dict(bal) + bal["owner"] = active[0]["address"] + initial_balances.append(bal) + result = { + "append" : { + "initial_accounts" : initial_accounts }, + } + if len(initial_balances) > 0: + result["append"]["initial_balances"] = initial_balances + + if opts.output == "-": + dump_json( result, sys.stdout, opts.pretty ) + sys.stdout.flush() + else: + with open(opts.output, "w") as f: + dump_json( result, f, opts.pretty ) + return + +if __name__ == "__main__": + main() From 57969d50181b57e3cf0a351e8e6f831a2f7e0ecd Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 23 Oct 2015 14:27:56 -0400 Subject: [PATCH 2/5] cli_wallet: Show txid's for transactions in blocks --- libraries/wallet/include/graphene/wallet/wallet.hpp | 3 ++- libraries/wallet/wallet.cpp | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 25895a15..952b1b33 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -230,6 +230,7 @@ struct signed_block_with_info : public signed_block block_id_type block_id; public_key_type signing_key; + vector< transaction_id_type > transaction_ids; }; struct vesting_balance_object_with_info : public vesting_balance_object @@ -1449,7 +1450,7 @@ FC_REFLECT( graphene::wallet::worker_vote_delta, ) FC_REFLECT_DERIVED( graphene::wallet::signed_block_with_info, (graphene::chain::signed_block), - (block_id)(signing_key) ) + (block_id)(signing_key)(transaction_ids) ) FC_REFLECT_DERIVED( graphene::wallet::vesting_balance_object_with_info, (graphene::chain::vesting_balance_object), (allowed_withdraw)(allowed_withdraw_time) ) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 8880a6fc..a568aeaf 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3937,6 +3937,9 @@ signed_block_with_info::signed_block_with_info( const signed_block& block ) { block_id = id(); signing_key = signee(); + transaction_ids.reserve( transactions.size() ); + for( const processed_transaction& tx : transactions ) + transaction_ids.push_back( tx.id() ); } vesting_balance_object_with_info::vesting_balance_object_with_info( const vesting_balance_object& vbo, fc::time_point_sec now ) From 0d55541682ab2637eb4c4c2c04d492e95dc9d364 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 23 Oct 2015 14:49:13 -0400 Subject: [PATCH 3/5] object_id.hpp: Implement std::string() conversion for object_id_type --- libraries/db/include/graphene/db/object_id.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/db/include/graphene/db/object_id.hpp b/libraries/db/include/graphene/db/object_id.hpp index 6a3cf843..533534c8 100644 --- a/libraries/db/include/graphene/db/object_id.hpp +++ b/libraries/db/include/graphene/db/object_id.hpp @@ -83,6 +83,11 @@ namespace graphene { namespace db { return T( *this ); } + explicit operator std::string() const + { + return fc::to_string(space()) + "." + fc::to_string(type()) + "." + fc::to_string(instance()); + } + uint64_t number; }; @@ -173,8 +178,9 @@ struct reflector > inline void to_variant( const graphene::db::object_id_type& var, fc::variant& vo ) { - vo = fc::to_string(var.space()) + "." + fc::to_string(var.type()) + "." + fc::to_string(var.instance()); + vo = std::string( var ); } + inline void from_variant( const fc::variant& var, graphene::db::object_id_type& vo ) { try { vo.number = 0; From 4fa0f182ec7d77e66557a4f747a675f9c56c54ff Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 23 Oct 2015 14:42:59 -0400 Subject: [PATCH 4/5] cli_wallet: Print operation results --- libraries/wallet/wallet.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index a568aeaf..cccf510a 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -73,6 +73,19 @@ namespace graphene { namespace wallet { namespace detail { +struct operation_result_printer +{ +public: + operation_result_printer( const wallet_api_impl& w ) + : _wallet(w) {} + const wallet_api_impl& _wallet; + typedef std::string result_type; + + std::string operator()(const void_result& x) const; + std::string operator()(const object_id_type& oid); + std::string operator()(const asset& a); +}; + // BLOCK TRX OP VOP struct operation_printer { @@ -2396,7 +2409,13 @@ std::string operation_printer::operator()(const T& op)const op_name.erase(0, op_name.find_last_of(':')+1); out << op_name <<" "; // out << "balance delta: " << fc::json::to_string(acc.balance) <<" "; - out << payer.name << " fee: " << a.amount_to_pretty_string( op.fee ); + out << payer.name << " fee: " << a.amount_to_pretty_string( op.fee ); + operation_result_printer rprinter(wallet); + std::string str_result = result.visit(rprinter); + if( str_result != "" ) + { + out << " result: " << str_result; + } return ""; } std::string operation_printer::operator()(const transfer_from_blind_operation& op)const @@ -2470,6 +2489,21 @@ std::string operation_printer::operator()(const asset_create_operation& op) cons return fee(op.fee); } +std::string operation_result_printer::operator()(const void_result& x) const +{ + return ""; +} + +std::string operation_result_printer::operator()(const object_id_type& oid) +{ + return std::string(oid); +} + +std::string operation_result_printer::operator()(const asset& a) +{ + return _wallet.get_asset(a.asset_id).amount_to_pretty_string(a); +} + }}} From e564539f8844adbaffaeef7ee89e5ee6171a0ba5 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 23 Oct 2015 17:38:11 -0400 Subject: [PATCH 5/5] change_asset_symbol.py: Fix permissions --- programs/genesis_util/change_asset_symbol.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 programs/genesis_util/change_asset_symbol.py diff --git a/programs/genesis_util/change_asset_symbol.py b/programs/genesis_util/change_asset_symbol.py old mode 100644 new mode 100755