From 9391ebcd9e6234b94aaa96269d5a51d08aaa2676 Mon Sep 17 00:00:00 2001 From: ejossev Date: Thu, 9 Nov 2017 10:08:48 +0100 Subject: [PATCH 001/136] bugfix with empty options --- libraries/chain/account_evaluator.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/chain/account_evaluator.cpp b/libraries/chain/account_evaluator.cpp index a42573ec..7b20cd18 100644 --- a/libraries/chain/account_evaluator.cpp +++ b/libraries/chain/account_evaluator.cpp @@ -150,11 +150,10 @@ void_result account_update_evaluator::do_evaluate( const account_update_operatio if( o.new_options.valid() ) { verify_account_votes(d, *o.new_options); + auto ao = d.get( o.new_options->price_per_subscribe.asset_id ); + FC_ASSERT( o.new_options->price_per_subscribe.asset_id == asset_id_type(0) || ao.is_monitored_asset() ); } - auto ao = d.get( o.new_options->price_per_subscribe.asset_id ); - FC_ASSERT( o.new_options->price_per_subscribe.asset_id == asset_id_type(0) || ao.is_monitored_asset() ); - return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } From b78c4868462d75b9982aef1e6bce3aafe12a195d Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 9 Nov 2017 15:15:31 +0100 Subject: [PATCH 002/136] initial unit-tests (not finished) --- CMakeLists.txt | 7 +- libraries/chain/asset_evaluator.cpp | 2 +- libraries/chain/protocol/asset_ops.cpp | 7 +- tests/CMakeLists.txt | 56 +- tests/common/database_fixture.cpp | 913 +++++++++++++------------ tests/common/database_fixture.hpp | 184 +++-- tests/common/tempdir.cpp | 39 ++ tests/common/tempdir.hpp | 34 + tests/tests/authority_tests.cpp | 124 ++-- tests/tests/basic_tests.cpp | 24 +- tests/tests/block_tests.cpp | 70 +- tests/tests/confidential_tests.cpp | 135 ---- tests/tests/operation_tests.cpp | 45 +- tests/tests/operation_tests2.cpp | 230 ++----- tests/tests/serialization_tests.cpp | 2 + tests/tests/uia_tests.cpp | 15 +- 16 files changed, 908 insertions(+), 979 deletions(-) create mode 100644 tests/common/tempdir.cpp create mode 100644 tests/common/tempdir.hpp delete mode 100644 tests/tests/confidential_tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f92c19f1..bd16b579 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -196,7 +196,12 @@ endif() add_subdirectory( libraries ) add_subdirectory( programs ) -#add_subdirectory( tests ) + +set(DECENT_NETWORK_TESTS true) + +if(DECENT_NETWORK_TESTS) + add_subdirectory( tests ) +endif() if( ENABLE_INSTALLER ) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 1323de83..c65d6c24 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -57,7 +57,7 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o if( op.monitored_asset_opts.valid() ) { FC_ASSERT( op.monitored_asset_opts->feed_lifetime_sec > d.get_global_properties().parameters.block_interval ); - FC_ASSERT( op.options.max_supply == 0, ); + FC_ASSERT( op.options.max_supply == 0 ); } return void_result(); diff --git a/libraries/chain/protocol/asset_ops.cpp b/libraries/chain/protocol/asset_ops.cpp index fcc2792e..1a5ac5f3 100644 --- a/libraries/chain/protocol/asset_ops.cpp +++ b/libraries/chain/protocol/asset_ops.cpp @@ -94,10 +94,13 @@ void asset_create_operation::validate()const FC_ASSERT(precision <= 12); FC_ASSERT( description.length() <= 1000 ); - if( monitored_asset_opts ) + if( monitored_asset_opts.valid() ) { monitored_asset_opts->validate(); - else + FC_ASSERT(options.max_supply == 0); + } + else { options.validate(); + } } share_type asset_issue_operation::calculate_fee(const fee_parameters_type& k)const diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 69e5ef58..5a66fcac 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,28 +6,44 @@ if( GPERFTOOLS_FOUND ) list( APPEND PLATFORM_SPECIFIC_LIBS tcmalloc ) endif() -file(GLOB UNIT_TESTS "tests/*.cpp") -add_executable( chain_test ${UNIT_TESTS} ${COMMON_SOURCES} ) +set(TEST_FILES_LIST + common/database_fixture.hpp + common/database_fixture.cpp + common/tempdir.hpp + common/tempdir.cpp + tests/basic_tests.cpp + tests/block_tests.cpp + tests/database_tests.cpp + tests/serialization_tests.cpp + tests/operation_tests.cpp + tests/operation_tests2.cpp + tests/authority_tests.cpp + + tests/uia_tests.cpp + tests/main.cpp +) + +add_executable( chain_test ${TEST_FILES_LIST} ) target_link_libraries( chain_test graphene_chain graphene_app graphene_account_history graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) if(MSVC) set_source_files_properties( tests/serialization_tests.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) endif(MSVC) - -file(GLOB PERFORMANCE_TESTS "performance/*.cpp") -add_executable( performance_test ${PERFORMANCE_TESTS} ${COMMON_SOURCES} ) -target_link_libraries( performance_test graphene_chain graphene_app graphene_account_history graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) - -file(GLOB BENCH_MARKS "benchmarks/*.cpp") -add_executable( chain_bench ${BENCH_MARKS} ${COMMON_SOURCES} ) -target_link_libraries( chain_bench graphene_chain graphene_app graphene_account_history graphene_time graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) - -file(GLOB APP_SOURCES "app/*.cpp") -add_executable( app_test ${APP_SOURCES} ) -target_link_libraries( app_test graphene_app graphene_account_history graphene_net graphene_chain graphene_time graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) - -file(GLOB INTENSE_SOURCES "intense/*.cpp") -add_executable( intense_test ${INTENSE_SOURCES} ${COMMON_SOURCES} ) -target_link_libraries( intense_test graphene_chain graphene_app graphene_account_history graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) - -add_subdirectory( generate_empty_blocks ) +# +#file(GLOB PERFORMANCE_TESTS "performance/*.cpp") +#add_executable( performance_test ${PERFORMANCE_TESTS} ${COMMON_SOURCES} ) +#target_link_libraries( performance_test graphene_chain graphene_app graphene_account_history graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +# +#file(GLOB BENCH_MARKS "benchmarks/*.cpp") +#add_executable( chain_bench ${BENCH_MARKS} ${COMMON_SOURCES} ) +#target_link_libraries( chain_bench graphene_chain graphene_app graphene_account_history graphene_time graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +# +#file(GLOB APP_SOURCES "app/*.cpp") +#add_executable( app_test ${APP_SOURCES} ) +#target_link_libraries( app_test graphene_app graphene_account_history graphene_net graphene_chain graphene_time graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +# +#file(GLOB INTENSE_SOURCES "intense/*.cpp") +#add_executable( intense_test ${INTENSE_SOURCES} ${COMMON_SOURCES} ) +#target_link_libraries( intense_test graphene_chain graphene_app graphene_account_history graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +# +#add_subdirectory( generate_empty_blocks ) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 8d7f98d6..efe2e319 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -26,17 +26,17 @@ #include #include -#include +//#include #include #include #include -#include +//#include #include #include -#include +#include "tempdir.hpp" #include #include @@ -57,351 +57,555 @@ using std::cout; using std::cerr; database_fixture::database_fixture() - : app(), db( *app.chain_database() ) -{ - try { - int argc = boost::unit_test::framework::master_test_suite().argc; - char** argv = boost::unit_test::framework::master_test_suite().argv; - for( int i=1; i(); - auto mhplugin = app.register_plugin(); - init_account_pub_key = init_account_priv_key.get_public_key(); - - boost::program_options::variables_map options; + : app(), db( *app.chain_database() ) +{ + try { + int argc = boost::unit_test::framework::master_test_suite().argc; + char** argv = boost::unit_test::framework::master_test_suite().argv; + for( int i=1; i(); + init_account_pub_key = init_account_priv_key.get_public_key(); + + boost::program_options::variables_map options; + + genesis_state.initial_timestamp = time_point_sec( GRAPHENE_TESTING_GENESIS_TIMESTAMP ); + + genesis_state.initial_active_miners = 10; + for( int i = 0; i < genesis_state.initial_active_miners; ++i ) + { + auto name = "init"+fc::to_string(i); + genesis_state.initial_accounts.emplace_back(name, + init_account_priv_key.get_public_key(), + init_account_priv_key.get_public_key()); + genesis_state.initial_miner_candidates.push_back({name, init_account_priv_key.get_public_key()}); + } + genesis_state.initial_parameters.current_fees->zero_all_fees(); + open_database(); + + // app.initialize(); + ahplugin->plugin_set_app(&app); + ahplugin->plugin_initialize(options); + + ahplugin->plugin_startup(); + + generate_block(); + + set_expiration( db, trx ); + } catch ( const fc::exception& e ) + { + edump( (e.to_detail_string()) ); + throw; + } - genesis_state.initial_timestamp = time_point_sec( GRAPHENE_TESTING_GENESIS_TIMESTAMP ); + return; +} - genesis_state.initial_active_miners = 10; - for( int i = 0; i < genesis_state.initial_active_miners; ++i ) - { - auto name = "init"+fc::to_string(i); - genesis_state.initial_accounts.emplace_back(name, - init_account_priv_key.get_public_key(), - init_account_priv_key.get_public_key()); - genesis_state.initial_miner_candidates.push_back({name, init_account_priv_key.get_public_key()}); - } - genesis_state.initial_parameters.current_fees->zero_all_fees(); - open_database(); +database_fixture::~database_fixture() +{ try { + // If we're unwinding due to an exception, don't do any more checks. + // This way, boost test's last checkpoint tells us approximately where the error was. + if( !std::uncaught_exception() ) + { +// verify_asset_supplies(db); +// verify_account_history_plugin_index(); + BOOST_CHECK( db.get_node_properties().skip_flags == database::skip_nothing ); + } - // app.initialize(); - ahplugin->plugin_set_app(&app); - ahplugin->plugin_initialize(options); - mhplugin->plugin_set_app(&app); - mhplugin->plugin_initialize(options); +// if( data_dir ) +// db.close(); - ahplugin->plugin_startup(); - mhplugin->plugin_startup(); + return; + } FC_CAPTURE_AND_RETHROW() } - generate_block(); - set_expiration( db, trx ); - } catch ( const fc::exception& e ) - { - edump( (e.to_detail_string()) ); - throw; - } - return; +fc::ecc::private_key database_fixture::generate_private_key(string seed) +{ + static const fc::ecc::private_key committee = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); + if( seed == "null_key" ) + return committee; + return fc::ecc::private_key::regenerate(fc::sha256::hash(seed)); } -database_fixture::~database_fixture() -{ try { - // If we're unwinding due to an exception, don't do any more checks. - // This way, boost test's last checkpoint tells us approximately where the error was. - if( !std::uncaught_exception() ) - { - verify_asset_supplies(db); - verify_account_history_plugin_index(); - BOOST_CHECK( db.get_node_properties().skip_flags == database::skip_nothing ); - } +void database_fixture::verify_asset_supplies( const database& db ) +{ + //wlog("*** Begin asset supply verification ***"); + const asset_dynamic_data_object& core_asset_data = db.get_core_asset().dynamic_asset_data_id(db); - if( data_dir ) - db.close(); - return; -} FC_CAPTURE_AND_RETHROW() } + const simple_index& statistics_index = db.get_index_type>(); + const auto& balance_index = db.get_index_type().indices(); + map total_balances; + map total_debts; + share_type core_in_orders; + share_type reported_core_in_orders; -fc::ecc::private_key database_fixture::generate_private_key(string seed) -{ - static const fc::ecc::private_key committee = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); - if( seed == "null_key" ) - return committee; - return fc::ecc::private_key::regenerate(fc::sha256::hash(seed)); + for( const account_balance_object& b : balance_index ) + total_balances[b.asset_type] += b.balance; + for( const account_statistics_object& a : statistics_index ) + { + reported_core_in_orders += a.total_core_in_orders; + total_balances[asset_id_type()] += a.pending_fees + a.pending_vested_fees; + } +// for( const limit_order_object& o : db.get_index_type().indices() ) +// { +// asset for_sale = o.amount_for_sale(); +// if( for_sale.asset_id == asset_id_type() ) core_in_orders += for_sale.amount; +// total_balances[for_sale.asset_id] += for_sale.amount; +// total_balances[asset_id_type()] += o.deferred_fee; +// } +// for( const asset_object& asset_obj : db.get_index_type().indices() ) +// { +// total_balances[asset_obj.id] += asset_obj.dynamic_asset_data_id(db).accumulated_fees; +// if( asset_obj.id != asset_id_type() ) +// BOOST_CHECK_EQUAL(total_balances[asset_obj.id].value, asset_obj.dynamic_asset_data_id(db).current_supply.value); +// } + for( const vesting_balance_object& vbo : db.get_index_type< vesting_balance_index >().indices() ) + total_balances[ vbo.balance.asset_id ] += vbo.balance.amount; + +// total_balances[asset_id_type()] += db.get_dynamic_global_properties().miner_budget; + + for( const auto& item : total_debts ) + { + BOOST_CHECK_EQUAL(item.first(db).dynamic_asset_data_id(db).current_supply.value, item.second.value); + } + + BOOST_CHECK_EQUAL( core_in_orders.value , reported_core_in_orders.value ); + BOOST_CHECK_EQUAL( total_balances[asset_id_type()].value , core_asset_data.current_supply.value); +// wlog("*** End asset supply verification ***"); } -string database_fixture::generate_anon_acct_name() +const account_object& database_fixture::create_account( + const string& name, + const public_key_type& key /* = public_key_type() */ +) { - // names of the form "anon-acct-x123" ; the "x" is necessary - // to workaround issue #46 - return "anon-acct-x" + std::to_string( anon_acct_count++ ); + trx.operations.push_back(make_account(name, key)); + trx.validate(); + processed_transaction ptx = db.push_transaction(trx, ~0); + auto& result = db.get(ptx.operation_results[0].get()); + trx.operations.clear(); + return result; } -void database_fixture::verify_asset_supplies( const database& db ) -{ - //wlog("*** Begin asset supply verification ***"); - const asset_dynamic_data_object& core_asset_data = db.get_core_asset().dynamic_asset_data_id(db); +const account_object& database_fixture::create_account( + const string& name, + const account_object& registrar, + const account_object& referrer, + uint8_t referrer_percent /* = 100 */, + const public_key_type& key /*= public_key_type()*/ +) +{ + try + { + trx.operations.resize(1); + trx.operations.back() = (make_account(name, registrar, referrer, referrer_percent, key)); + trx.validate(); + auto r = db.push_transaction(trx, ~0); + const auto& result = db.get(r.operation_results[0].get()); + trx.operations.clear(); + return result; + } + FC_CAPTURE_AND_RETHROW( (name)(registrar)(referrer) ) +} - const simple_index& statistics_index = db.get_index_type>(); - const auto& balance_index = db.get_index_type().indices(); - map total_balances; - map total_debts; - share_type core_in_orders; - share_type reported_core_in_orders; +const account_object& database_fixture::create_account( + const string& name, + const private_key_type& key, + const account_id_type& registrar_id /* = account_id_type() */, + const account_id_type& referrer_id /* = account_id_type() */, + uint8_t referrer_percent /* = 100 */ +) +{ + try + { + trx.operations.clear(); - for( const account_balance_object& b : balance_index ) - total_balances[b.asset_type] += b.balance; - for( const account_statistics_object& a : statistics_index ) - { - reported_core_in_orders += a.total_core_in_orders; - total_balances[asset_id_type()] += a.pending_fees + a.pending_vested_fees; - } - for( const limit_order_object& o : db.get_index_type().indices() ) - { - asset for_sale = o.amount_for_sale(); - if( for_sale.asset_id == asset_id_type() ) core_in_orders += for_sale.amount; - total_balances[for_sale.asset_id] += for_sale.amount; - total_balances[asset_id_type()] += o.deferred_fee; - } - for( const asset_object& asset_obj : db.get_index_type().indices() ) - { - total_balances[asset_obj.id] += asset_obj.dynamic_asset_data_id(db).accumulated_fees; - if( asset_obj.id != asset_id_type() ) - BOOST_CHECK_EQUAL(total_balances[asset_obj.id].value, asset_obj.dynamic_asset_data_id(db).current_supply.value); - } - for( const vesting_balance_object& vbo : db.get_index_type< vesting_balance_index >().indices() ) - total_balances[ vbo.balance.asset_id ] += vbo.balance.amount; + account_create_operation account_create_op; - total_balances[asset_id_type()] += db.get_dynamic_global_properties().miner_budget; + account_create_op.registrar = registrar_id; + account_create_op.name = name; + account_create_op.owner = authority(1234, public_key_type(key.get_public_key()), 1234); + account_create_op.active = authority(5678, public_key_type(key.get_public_key()), 5678); + account_create_op.options.memo_key = key.get_public_key(); + account_create_op.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT; + trx.operations.push_back( account_create_op ); - for( const auto& item : total_debts ) - { - BOOST_CHECK_EQUAL(item.first(db).dynamic_asset_data_id(db).current_supply.value, item.second.value); - } + trx.validate(); - BOOST_CHECK_EQUAL( core_in_orders.value , reported_core_in_orders.value ); - BOOST_CHECK_EQUAL( total_balances[asset_id_type()].value , core_asset_data.current_supply.value - core_asset_data.confidential_supply.value); -// wlog("*** End asset supply verification ***"); + processed_transaction ptx = db.push_transaction(trx, ~0); + //wdump( (ptx) ); + const account_object& result = db.get(ptx.operation_results[0].get()); + trx.operations.clear(); + return result; + } + FC_CAPTURE_AND_RETHROW( (name)(registrar_id)(referrer_id) ) } -void database_fixture::verify_account_history_plugin_index( )const -{ - return; - if( skip_key_index_test ) - return; - const std::shared_ptr pin = - app.get_plugin("account_history"); - return; +account_create_operation database_fixture::make_account( + const std::string& name /* = "nathan" */, + public_key_type key /* = key_id_type() */ +) +{ try { + account_create_operation create_account; + create_account.registrar = account_id_type(); + + create_account.name = name; + create_account.owner = authority(123, key, 123); + create_account.active = authority(321, key, 321); + create_account.options.memo_key = key; + create_account.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT; + + auto& active_miners = db.get_global_properties().active_miners; + if( active_miners.size() > 0 ) + { + set votes; + votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); + votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); + votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); + votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); + votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); + create_account.options.votes = flat_set(votes.begin(), votes.end()); + } + create_account.options.num_miner = create_account.options.votes.size(); + + create_account.fee = db.current_fee_schedule().calculate_fee( create_account ); + return create_account; + } FC_CAPTURE_AND_RETHROW() } + +account_create_operation database_fixture::make_account( + const std::string& name, + const account_object& registrar, + const account_object& referrer, + uint8_t referrer_percent /* = 100 */, + public_key_type key /* = public_key_type() */ +) +{ + try + { + account_create_operation create_account; + + create_account.registrar = registrar.id; + //create_account.referrer = referrer.id; + //create_account.referrer_percent = referrer_percent; + + create_account.name = name; + create_account.owner = authority(123, key, 123); + create_account.active = authority(321, key, 321); + create_account.options.memo_key = key; + create_account.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT; + + const vector& active_miners = db.get_global_properties().active_miners; + if( active_miners.size() > 0 ) + { + set votes; + votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); + votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); + votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); + votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); + votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); + create_account.options.votes = flat_set(votes.begin(), votes.end()); + } + create_account.options.num_miner = create_account.options.votes.size(); + + create_account.fee = db.current_fee_schedule().calculate_fee( create_account ); + return create_account; + } + FC_CAPTURE_AND_RETHROW((name)(referrer_percent)) +} + +digest_type database_fixture::digest( const transaction& tx ) +{ + return tx.digest(); } void database_fixture::open_database() { - if( !data_dir ) { - data_dir = fc::temp_directory( graphene::utilities::temp_directory_path() ); - db.open(data_dir->path(), [this]{return genesis_state;}); - } + if( !data_dir ) { + data_dir = fc::temp_directory( graphene::utilities::temp_directory_path() ); + db.open(data_dir->path(), [this]{return genesis_state;}); + } + + + //TODO: make it better +// fc::path data_dir = fc::temp_directory_path(); +// data_dir /= fc::path(".decent_test"); +// +// db.open(data_dir, [this]{return genesis_state;}); +// + +// if( !data_dir ) { +// data_dir = fc::temp_directory( graphene::utilities::temp_directory_path() ); +// db.open(data_dir->path(), [this]{return genesis_state;}); +// } } signed_block database_fixture::generate_block(uint32_t skip, const fc::ecc::private_key& key, int miss_blocks) { - skip |= database::skip_undo_history_check; - // skip == ~0 will skip checks specified in database::validation_steps - auto block = db.generate_block(db.get_slot_time(miss_blocks + 1), - db.get_scheduled_miner(miss_blocks + 1), - key, skip); - db.clear_pending(); - return block; + skip |= database::skip_undo_history_check; + // skip == ~0 will skip checks specified in database::validation_steps + auto block = db.generate_block(db.get_slot_time(miss_blocks + 1), + db.get_scheduled_miner(miss_blocks + 1), + key, skip); + db.clear_pending(); + return block; } void database_fixture::generate_blocks( uint32_t block_count ) { - for( uint32_t i = 0; i < block_count; ++i ) - generate_block(); + for( uint32_t i = 0; i < block_count; ++i ) + generate_block(); } void database_fixture::generate_blocks(fc::time_point_sec timestamp, bool miss_intermediate_blocks, uint32_t skip) { - if( miss_intermediate_blocks ) - { - generate_block(skip); - auto slots_to_miss = db.get_slot_at_time(timestamp); - if( slots_to_miss <= 1 ) - return; - --slots_to_miss; - generate_block(skip, init_account_priv_key, slots_to_miss); - return; - } - while( db.head_block_time() < timestamp ) - generate_block(skip); + if( miss_intermediate_blocks ) + { + generate_block(skip); + auto slots_to_miss = db.get_slot_at_time(timestamp); + if( slots_to_miss <= 1 ) + return; + --slots_to_miss; + generate_block(skip, init_account_priv_key, slots_to_miss); + return; + } + while( db.head_block_time() < timestamp ) + generate_block(skip); } -account_create_operation database_fixture::make_account( - const std::string& name /* = "nathan" */, - public_key_type key /* = key_id_type() */ - ) +const asset_object& database_fixture::create_monitored_asset( + const string& name, + account_id_type issuer /* = GRAPHENE_MINER_ACCOUNT */ ) { try { - account_create_operation create_account; - create_account.registrar = account_id_type(); + asset_create_operation creator; + creator.issuer = issuer; + creator.fee = asset(); + creator.symbol = name; + creator.options.max_supply = 0; //MIA allways with zero + creator.precision = 2; + creator.options.core_exchange_rate = price({asset(1,asset_id_type(1)),asset(1)}); + creator.monitored_asset_opts = monitored_asset_options(); + trx.operations.push_back(std::move(creator)); + trx.validate(); + processed_transaction ptx = db.push_transaction(trx, ~0); + trx.operations.clear(); + return db.get(ptx.operation_results[0].get()); +} FC_CAPTURE_AND_RETHROW( (name) ) } - create_account.name = name; - create_account.owner = authority(123, key, 123); - create_account.active = authority(321, key, 321); - create_account.options.memo_key = key; - create_account.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT; +const asset_object& database_fixture::create_user_issued_asset( const string& name ) +{ + asset_create_operation creator; + creator.issuer = account_id_type(); + creator.fee = asset(); + creator.symbol = name; + creator.options.max_supply = 0; + creator.precision = 2; + creator.options.core_exchange_rate = price({asset(1,asset_id_type(1)),asset(1)}); + creator.monitored_asset_opts = monitored_asset_options(); + trx.operations.push_back(std::move(creator)); + trx.validate(); + processed_transaction ptx = db.push_transaction(trx, ~0); + trx.operations.clear(); + return db.get(ptx.operation_results[0].get()); +} - auto& active_miners = db.get_global_properties().active_miners; - if( active_miners.size() > 0 ) - { - set votes; - votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); - votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); - votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); - votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); - votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); - create_account.options.votes = flat_set(votes.begin(), votes.end()); - } - create_account.options.num_miner = create_account.options.votes.size(); +const asset_object& database_fixture::create_user_issued_asset( const string& name, const account_object& issuer ) +{ + asset_create_operation creator; + creator.issuer = issuer.id; + creator.fee = asset(); + creator.symbol = name; + creator.options.max_supply = 0; + creator.precision = 2; + creator.options.core_exchange_rate = price({asset(1,asset_id_type(1)),asset(1)}); + creator.options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; + trx.operations.clear(); + trx.operations.push_back(std::move(creator)); + set_expiration( db, trx ); + trx.validate(); + processed_transaction ptx = db.push_transaction(trx, ~0); + trx.operations.clear(); + return db.get(ptx.operation_results[0].get()); +} - create_account.fee = db.current_fee_schedule().calculate_fee( create_account ); - return create_account; -} FC_CAPTURE_AND_RETHROW() } -account_create_operation database_fixture::make_account( - const std::string& name, - const account_object& registrar, - const account_object& referrer, - uint8_t referrer_percent /* = 100 */, - public_key_type key /* = public_key_type() */ - ) +const miner_object&database_fixture::create_miner(account_id_type owner, const fc::ecc::private_key& signing_private_key) { - try - { - account_create_operation create_account; - - create_account.registrar = registrar.id; - create_account.referrer = referrer.id; - create_account.referrer_percent = referrer_percent; - - create_account.name = name; - create_account.owner = authority(123, key, 123); - create_account.active = authority(321, key, 321); - create_account.options.memo_key = key; - create_account.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT; - - const vector& active_miners = db.get_global_properties().active_miners; - if( active_miners.size() > 0 ) - { - set votes; - votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); - votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); - votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); - votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); - votes.insert(active_miners[rand() % active_miners.size()](db).vote_id); - create_account.options.votes = flat_set(votes.begin(), votes.end()); - } - create_account.options.num_miner = create_account.options.votes.size(); - - create_account.fee = db.current_fee_schedule().calculate_fee( create_account ); - return create_account; - } - FC_CAPTURE_AND_RETHROW((name)(referrer_percent)) + return create_miner(owner(db), signing_private_key); +} + +const miner_object& database_fixture::create_miner( const account_object& owner, + const fc::ecc::private_key& signing_private_key ) +{ try { + miner_create_operation op; + op.miner_account = owner.id; + op.block_signing_key = signing_private_key.get_public_key(); + trx.operations.push_back(op); + trx.validate(); + processed_transaction ptx = db.push_transaction(trx, ~0); + trx.clear(); + return db.get(ptx.operation_results[0].get()); + } FC_CAPTURE_AND_RETHROW() +} + +int64_t database_fixture::get_balance( account_id_type account, asset_id_type a )const +{ + return db.get_balance(account, a).amount.value; +} + +int64_t database_fixture::get_balance( const account_object& account, const asset_object& a )const +{ + return db.get_balance(account.get_id(), a.get_id()).amount.value; } const asset_object& database_fixture::get_asset( const string& symbol )const { - const auto& idx = db.get_index_type().indices().get(); - const auto itr = idx.find(symbol); - assert( itr != idx.end() ); - return *itr; + const auto& idx = db.get_index_type().indices().get(); + const auto itr = idx.find(symbol); + assert( itr != idx.end() ); + return *itr; } const account_object& database_fixture::get_account( const string& name )const { - const auto& idx = db.get_index_type().indices().get(); - const auto itr = idx.find(name); - assert( itr != idx.end() ); - return *itr; + const auto& idx = db.get_index_type().indices().get(); + const auto itr = idx.find(name); + assert( itr != idx.end() ); + return *itr; } -const asset_object& database_fixture::create_monitored_asset( - const string& name, - account_id_type issuer /* = GRAPHENE_MINER_ACCOUNT */ ) -{ try { - asset_create_operation creator; - creator.issuer = issuer; - creator.fee = asset(); - creator.symbol = name; - creator.common_options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; - creator.precision = 2; - creator.common_options.core_exchange_rate = price({asset(1,asset_id_type(1)),asset(1)}); - creator.common_options.monitored_asset_opts = monitored_asset_options(); - trx.operations.push_back(std::move(creator)); - trx.validate(); - processed_transaction ptx = db.push_transaction(trx, ~0); - trx.operations.clear(); - return db.get(ptx.operation_results[0].get()); -} FC_CAPTURE_AND_RETHROW( (name) ) } +void database_fixture::sign(signed_transaction& trx, const fc::ecc::private_key& key) +{ + trx.sign( key, db.get_chain_id() ); +} -const asset_object& database_fixture::create_user_issued_asset( const string& name ) +void database_fixture::transfer( + account_id_type from, + account_id_type to, + const asset& amount, + const asset& fee /* = asset() */ +) { - asset_create_operation creator; - creator.issuer = account_id_type(); - creator.fee = asset(); - creator.symbol = name; - creator.common_options.max_supply = 0; - creator.precision = 2; - creator.common_options.core_exchange_rate = price({asset(1,asset_id_type(1)),asset(1)}); - creator.common_options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; - trx.operations.push_back(std::move(creator)); - trx.validate(); - processed_transaction ptx = db.push_transaction(trx, ~0); - trx.operations.clear(); - return db.get(ptx.operation_results[0].get()); + transfer(from(db), to(db), amount, fee); } -const asset_object& database_fixture::create_user_issued_asset( const string& name, const account_object& issuer ) +void database_fixture::transfer( + const account_object& from, + const account_object& to, + const asset& amount, + const asset& fee /* = asset() */ ) { - asset_create_operation creator; - creator.issuer = issuer.id; - creator.fee = asset(); - creator.symbol = name; - creator.common_options.max_supply = 0; - creator.precision = 2; - creator.common_options.core_exchange_rate = price({asset(1,asset_id_type(1)),asset(1)}); - creator.common_options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; - trx.operations.clear(); - trx.operations.push_back(std::move(creator)); - set_expiration( db, trx ); - trx.validate(); - processed_transaction ptx = db.push_transaction(trx, ~0); - trx.operations.clear(); - return db.get(ptx.operation_results[0].get()); + try + { + set_expiration( db, trx ); + transfer_operation trans; + trans.from = from.id; + trans.to = to.id; + trans.amount = amount; + trx.operations.push_back(trans); + + if( fee == asset() ) + { + for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op); + } + trx.validate(); + db.push_transaction(trx, ~0); + verify_asset_supplies(db); + trx.operations.clear(); + } FC_CAPTURE_AND_RETHROW( (from.id)(to.id)(amount)(fee) ) +} + +void database_fixture::enable_fees() +{ + db.modify(global_property_id_type()(db), [](global_property_object& gpo) + { + gpo.parameters.current_fees = fee_schedule::get_default(); + }); +} + +uint64_t database_fixture::fund( + const account_object& account, + const asset& amount /* = asset(500000) */ ) +{ + transfer(account_id_type()(db), account, amount); + return get_balance(account, amount.asset_id(db)); +} + +string database_fixture::generate_anon_acct_name() +{ + // names of the form "anon-acct-x123" ; the "x" is necessary + // to workaround issue #46 + return "anon-acct-x" + std::to_string( anon_acct_count++ ); } void database_fixture::issue_uia( const account_object& recipient, asset amount ) { - BOOST_TEST_MESSAGE( "Issuing UIA" ); - asset_issue_operation op; - op.issuer = amount.asset_id(db).issuer; - op.asset_to_issue = amount; - op.issue_to_account = recipient.id; - trx.operations.push_back(op); - db.push_transaction( trx, ~0 ); - trx.operations.clear(); + BOOST_TEST_MESSAGE( "Issuing UIA" ); + asset_issue_operation op; + op.issuer = amount.asset_id(db).issuer; + op.asset_to_issue = amount; + op.issue_to_account = recipient.id; + trx.operations.push_back(op); + db.push_transaction( trx, ~0 ); + trx.operations.clear(); } void database_fixture::issue_uia( account_id_type recipient_id, asset amount ) { - issue_uia( recipient_id(db), amount ); + issue_uia( recipient_id(db), amount ); +} + + + + + + +#if 0 /////////////////////////////////////////////////////////////////////////////////////// + + + + + + +fc::ecc::private_key database_fixture::generate_private_key(string seed) +{ + static const fc::ecc::private_key committee = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); + if( seed == "null_key" ) + return committee; + return fc::ecc::private_key::regenerate(fc::sha256::hash(seed)); +} + + + + +void database_fixture::verify_account_history_plugin_index( )const +{ + return; + if( skip_key_index_test ) + return; + + const std::shared_ptr pin = + app.get_plugin("account_history"); + + return; } + + + + + + + + void database_fixture::change_fees( const flat_set< fee_parameters >& new_params, uint32_t new_scale /* = 0 */ @@ -432,110 +636,6 @@ void database_fixture::change_fees( }); } -const account_object& database_fixture::create_account( - const string& name, - const public_key_type& key /* = public_key_type() */ - ) -{ - trx.operations.push_back(make_account(name, key)); - trx.validate(); - processed_transaction ptx = db.push_transaction(trx, ~0); - auto& result = db.get(ptx.operation_results[0].get()); - trx.operations.clear(); - return result; -} - -const account_object& database_fixture::create_account( - const string& name, - const account_object& registrar, - const account_object& referrer, - uint8_t referrer_percent /* = 100 */, - const public_key_type& key /*= public_key_type()*/ - ) -{ - try - { - trx.operations.resize(1); - trx.operations.back() = (make_account(name, registrar, referrer, referrer_percent, key)); - trx.validate(); - auto r = db.push_transaction(trx, ~0); - const auto& result = db.get(r.operation_results[0].get()); - trx.operations.clear(); - return result; - } - FC_CAPTURE_AND_RETHROW( (name)(registrar)(referrer) ) -} - -const account_object& database_fixture::create_account( - const string& name, - const private_key_type& key, - const account_id_type& registrar_id /* = account_id_type() */, - const account_id_type& referrer_id /* = account_id_type() */, - uint8_t referrer_percent /* = 100 */ - ) -{ - try - { - trx.operations.clear(); - - account_create_operation account_create_op; - - account_create_op.registrar = registrar_id; - account_create_op.name = name; - account_create_op.owner = authority(1234, public_key_type(key.get_public_key()), 1234); - account_create_op.active = authority(5678, public_key_type(key.get_public_key()), 5678); - account_create_op.options.memo_key = key.get_public_key(); - account_create_op.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT; - trx.operations.push_back( account_create_op ); - - trx.validate(); - - processed_transaction ptx = db.push_transaction(trx, ~0); - //wdump( (ptx) ); - const account_object& result = db.get(ptx.operation_results[0].get()); - trx.operations.clear(); - return result; - } - FC_CAPTURE_AND_RETHROW( (name)(registrar_id)(referrer_id) ) -} - -const miner_object&database_fixture::create_miner(account_id_type owner, const fc::ecc::private_key& signing_private_key) -{ - return create_miner(owner(db), signing_private_key); -} - -const miner_object& database_fixture::create_miner( const account_object& owner, - const fc::ecc::private_key& signing_private_key ) -{ try { - miner_create_operation op; - op.miner_account = owner.id; - op.block_signing_key = signing_private_key.get_public_key(); - trx.operations.push_back(op); - trx.validate(); - processed_transaction ptx = db.push_transaction(trx, ~0); - trx.clear(); - return db.get(ptx.operation_results[0].get()); -} FC_CAPTURE_AND_RETHROW() } - -uint64_t database_fixture::fund( - const account_object& account, - const asset& amount /* = asset(500000) */ - ) -{ - transfer(account_id_type()(db), account, amount); - return get_balance(account, amount.asset_id(db)); -} - -void database_fixture::sign(signed_transaction& trx, const fc::ecc::private_key& key) -{ - trx.sign( key, db.get_chain_id() ); -} - -digest_type database_fixture::digest( const transaction& tx ) -{ - return tx.digest(); -} - const limit_order_object*database_fixture::create_sell_order(account_id_type user, const asset& amount, const asset& recv) { auto r = create_sell_order(user(db), amount, recv); @@ -574,41 +674,7 @@ asset database_fixture::cancel_limit_order( const limit_order_object& order ) return processed.operation_results[0].get(); } -void database_fixture::transfer( - account_id_type from, - account_id_type to, - const asset& amount, - const asset& fee /* = asset() */ - ) -{ - transfer(from(db), to(db), amount, fee); -} -void database_fixture::transfer( - const account_object& from, - const account_object& to, - const asset& amount, - const asset& fee /* = asset() */ ) -{ - try - { - set_expiration( db, trx ); - transfer_operation trans; - trans.from = from.id; - trans.to = to.id; - trans.amount = amount; - trx.operations.push_back(trans); - - if( fee == asset() ) - { - for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op); - } - trx.validate(); - db.push_transaction(trx, ~0); - verify_asset_supplies(db); - trx.operations.clear(); - } FC_CAPTURE_AND_RETHROW( (from.id)(to.id)(amount)(fee) ) -} void database_fixture::publish_feed( const asset_object& mia, const account_object& by, const price_feed& f ) { @@ -630,15 +696,6 @@ void database_fixture::publish_feed( const asset_object& mia, const account_obje verify_asset_supplies(db); } - -void database_fixture::enable_fees() -{ - db.modify(global_property_id_type()(db), [](global_property_object& gpo) - { - gpo.parameters.current_fees = fee_schedule::get_default(); - }); -} - void database_fixture::print_market( const string& syma, const string& symb )const { const auto& limit_idx = db.get_index_type(); @@ -708,16 +765,6 @@ void database_fixture::print_joint_market( const string& syma, const string& sym } } -int64_t database_fixture::get_balance( account_id_type account, asset_id_type a )const -{ - return db.get_balance(account, a).amount.value; -} - -int64_t database_fixture::get_balance( const account_object& account, const asset_object& a )const -{ - return db.get_balance(account.get_id(), a.get_id()).amount.value; -} - vector< operation_history_object > database_fixture::get_operation_history( account_id_type account_id )const { vector< operation_history_object > result; @@ -736,6 +783,9 @@ vector< operation_history_object > database_fixture::get_operation_history( acco return result; } +#endif + + namespace test { void set_expiration( const database& db, transaction& tx ) @@ -758,6 +808,7 @@ processed_transaction _push_transaction( database& db, const signed_transaction& return pt; } FC_CAPTURE_AND_RETHROW((tx)) } + } // graphene::chain::test } } // graphene::chain diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 6c56e0f5..da146cf4 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -146,30 +146,51 @@ extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; namespace graphene { namespace chain { struct database_fixture { - // the reason we use an app is to exercise the indexes of built-in - // plugins - graphene::app::application app; - genesis_state_type genesis_state; - chain::database &db; - signed_transaction trx; - public_key_type miner_key; - account_id_type miner_account; - fc::ecc::private_key private_key = fc::ecc::private_key::generate(); - fc::ecc::private_key init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); - public_key_type init_account_pub_key; - - optional data_dir; - bool skip_key_index_test = false; - uint32_t anon_acct_count; database_fixture(); ~database_fixture(); static fc::ecc::private_key generate_private_key(string seed); - string generate_anon_acct_name(); static void verify_asset_supplies( const database& db ); - void verify_account_history_plugin_index( )const; + + digest_type digest( const transaction& tx ); + + const account_object& create_account( + const string& name, + const public_key_type& key = public_key_type() + ); + + const account_object& create_account( + const string& name, + const account_object& registrar, + const account_object& referrer, + uint8_t referrer_percent = 100, + const public_key_type& key = public_key_type() + ); + + const account_object& create_account( + const string& name, + const private_key_type& key, + const account_id_type& registrar_id = account_id_type(), + const account_id_type& referrer_id = account_id_type(), + uint8_t referrer_percent = 100 + ); + + account_create_operation make_account( + const std::string& name = "nathan", + public_key_type = public_key_type() + ); + + account_create_operation make_account( + const std::string& name, + const account_object& registrar, + const account_object& referrer, + uint8_t referrer_percent = 100, + public_key_type key = public_key_type() + ); + void open_database(); + signed_block generate_block(uint32_t skip = ~0, const fc::ecc::private_key& key = generate_private_key("null_key"), int miss_blocks = 0); @@ -186,78 +207,97 @@ struct database_fixture { */ void generate_blocks(fc::time_point_sec timestamp, bool miss_intermediate_blocks = true, uint32_t skip = ~0); - account_create_operation make_account( - const std::string& name = "nathan", - public_key_type = public_key_type() - ); - account_create_operation make_account( - const std::string& name, - const account_object& registrar, - const account_object& referrer, - uint8_t referrer_percent = 100, - public_key_type key = public_key_type() - ); + const asset_object& create_user_issued_asset( const string& name ); + const asset_object& create_user_issued_asset( const string& name, + const account_object& issuer ); + const asset_object& create_monitored_asset(const string& name, + account_id_type issuer = GRAPHENE_MINER_ACCOUNT ); - void publish_feed(asset_id_type mia, account_id_type by, const price_feed& f) - { publish_feed(mia(db), by(db), f); } - void publish_feed(const asset_object& mia, const account_object& by, const price_feed& f); + void transfer( account_id_type from, account_id_type to, const asset& amount, const asset& fee = asset() ); + void transfer( const account_object& from, const account_object& to, const asset& amount, const asset& fee = asset() ); + void sign( signed_transaction& trx, const fc::ecc::private_key& key ); + + const miner_object& create_miner(account_id_type owner, + const fc::ecc::private_key& signing_private_key = generate_private_key("null_key")); + const miner_object& create_miner(const account_object& owner, + const fc::ecc::private_key& signing_private_key = generate_private_key("null_key")); + + int64_t get_balance( account_id_type account, asset_id_type a )const; + int64_t get_balance( const account_object& account, const asset_object& a )const; const asset_object& get_asset( const string& symbol )const; const account_object& get_account( const string& name )const; - const asset_object& create_monitored_asset(const string& name, - account_id_type issuer = GRAPHENE_MINER_ACCOUNT ); - const asset_object& create_user_issued_asset( const string& name ); - const asset_object& create_user_issued_asset( const string& name, - const account_object& issuer ); + + void enable_fees(); + + uint64_t fund( const account_object& account, const asset& amount = asset(500000) ); + string generate_anon_acct_name(); + void issue_uia( const account_object& recipient, asset amount ); void issue_uia( account_id_type recipient_id, asset amount ); - const account_object& create_account( - const string& name, - const public_key_type& key = public_key_type() - ); - const account_object& create_account( - const string& name, - const account_object& registrar, - const account_object& referrer, - uint8_t referrer_percent = 100, - const public_key_type& key = public_key_type() - ); - const account_object& create_account( - const string& name, - const private_key_type& key, - const account_id_type& registrar_id = account_id_type(), - const account_id_type& referrer_id = account_id_type(), - uint8_t referrer_percent = 100 - ); - const miner_object& create_miner(account_id_type owner, - const fc::ecc::private_key& signing_private_key = generate_private_key("null_key")); - const miner_object& create_miner(const account_object& owner, - const fc::ecc::private_key& signing_private_key = generate_private_key("null_key")); - uint64_t fund( const account_object& account, const asset& amount = asset(500000) ); - digest_type digest( const transaction& tx ); - void sign( signed_transaction& trx, const fc::ecc::private_key& key ); - const limit_order_object* create_sell_order( account_id_type user, const asset& amount, const asset& recv ); - const limit_order_object* create_sell_order( const account_object& user, const asset& amount, const asset& recv ); - asset cancel_limit_order( const limit_order_object& order ); - void transfer( account_id_type from, account_id_type to, const asset& amount, const asset& fee = asset() ); - void transfer( const account_object& from, const account_object& to, const asset& amount, const asset& fee = asset() ); + // the reason we use an app is to exercise the indexes of built-in + // plugins + graphene::app::application app; + genesis_state_type genesis_state; + chain::database &db; + signed_transaction trx; + fc::ecc::private_key private_key = fc::ecc::private_key::generate(); + fc::ecc::private_key init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); + public_key_type init_account_pub_key; + + public_key_type miner_key; + account_id_type miner_account; + uint32_t anon_acct_count; + + optional data_dir; + + +#if 0 //OLD CODE.. + + + + + bool skip_key_index_test = false; + + + database_fixture(); + ~database_fixture(); + + static fc::ecc::private_key generate_private_key(string seed); + + static void verify_asset_supplies( const database& db ); + void verify_account_history_plugin_index( )const; + + + void publish_feed(asset_id_type mia, account_id_type by, const price_feed& f) + { publish_feed(mia(db), by(db), f); } + void publish_feed(const asset_object& mia, const account_object& by, const price_feed& f); + + + + + + //const limit_order_object* create_sell_order( account_id_type user, const asset& amount, const asset& recv ); + //const limit_order_object* create_sell_order( const account_object& user, const asset& amount, const asset& recv ); + //asset cancel_limit_order( const limit_order_object& order ); void fund_fee_pool( const account_object& from, const asset_object& asset_to_fund, const share_type amount ); - void enable_fees(); - void change_fees( const flat_set< fee_parameters >& new_params, uint32_t new_scale = 0 ); + //void change_fees( const flat_set< fee_parameters >& new_params, uint32_t new_scale = 0 ); void print_market( const string& syma, const string& symb )const; string pretty( const asset& a )const; - void print_limit_order( const limit_order_object& cur )const; + //void print_limit_order( const limit_order_object& cur )const; void print_joint_market( const string& syma, const string& symb )const; - int64_t get_balance( account_id_type account, asset_id_type a )const; - int64_t get_balance( const account_object& account, const asset_object& a )const; - vector< operation_history_object > get_operation_history( account_id_type account_id )const; + //vector< operation_history_object > get_operation_history( account_id_type account_id )const; +#endif + }; + + namespace test { /// set a reasonable expiration time for the transaction void set_expiration( const database& db, transaction& tx ); diff --git a/tests/common/tempdir.cpp b/tests/common/tempdir.cpp new file mode 100644 index 00000000..e42d84df --- /dev/null +++ b/tests/common/tempdir.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "tempdir.hpp" + +#include + +namespace graphene { namespace utilities { + +fc::path temp_directory_path() +{ + const char* graphene_tempdir = getenv("GRAPHENE_TEMPDIR"); + if( graphene_tempdir != nullptr ) + return fc::path( graphene_tempdir ); + return fc::temp_directory_path() / "graphene-tmp"; +} + +} } // graphene::utilities diff --git a/tests/common/tempdir.hpp b/tests/common/tempdir.hpp new file mode 100644 index 00000000..d2dfdfa8 --- /dev/null +++ b/tests/common/tempdir.hpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include + +#include + +namespace graphene { namespace utilities { + +fc::path temp_directory_path(); + +} } // graphene::utilities diff --git a/tests/tests/authority_tests.cpp b/tests/tests/authority_tests.cpp index c5edefc2..eaefe929 100644 --- a/tests/tests/authority_tests.cpp +++ b/tests/tests/authority_tests.cpp @@ -591,9 +591,9 @@ BOOST_FIXTURE_TEST_CASE( proposal_two_accounts, database_fixture ) generate_block(); auto nathan_key = generate_private_key("nathan"); - auto dan_key = generate_private_key("dan"); + auto dan_key = generate_private_key("danian"); const account_object& nathan = create_account("nathan", nathan_key.get_public_key() ); - const account_object& dan = create_account("dan", dan_key.get_public_key() ); + const account_object& dan = create_account("danian", dan_key.get_public_key() ); transfer(account_id_type()(db), nathan, asset(100000)); transfer(account_id_type()(db), dan, asset(100000)); @@ -652,9 +652,9 @@ BOOST_FIXTURE_TEST_CASE( proposal_delete, database_fixture ) generate_block(); auto nathan_key = generate_private_key("nathan"); - auto dan_key = generate_private_key("dan"); + auto dan_key = generate_private_key("danian"); const account_object& nathan = create_account("nathan", nathan_key.get_public_key() ); - const account_object& dan = create_account("dan", dan_key.get_public_key() ); + const account_object& dan = create_account("danian", dan_key.get_public_key() ); transfer(account_id_type()(db), nathan, asset(100000)); transfer(account_id_type()(db), dan, asset(100000)); @@ -723,16 +723,16 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_delete, database_fixture ) generate_block(); auto nathan_key = generate_private_key("nathan"); - auto dan_key = generate_private_key("dan"); + auto danian_key = generate_private_key("danian"); const account_object& nathan = create_account("nathan", nathan_key.get_public_key() ); - const account_object& dan = create_account("dan", dan_key.get_public_key() ); + const account_object& danian = create_account("danian", danian_key.get_public_key() ); transfer(account_id_type()(db), nathan, asset(100000)); - transfer(account_id_type()(db), dan, asset(100000)); + transfer(account_id_type()(db), danian, asset(100000)); { transfer_operation top; - top.from = dan.get_id(); + top.from = danian.get_id(); top.to = nathan.get_id(); top.amount = asset(500); @@ -800,16 +800,16 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture ) generate_block(); auto nathan_key = generate_private_key("nathan"); - auto dan_key = generate_private_key("dan"); + auto danian_key = generate_private_key("danian"); const account_object& nathan = create_account("nathan", nathan_key.get_public_key() ); - const account_object& dan = create_account("dan", dan_key.get_public_key() ); + const account_object& danian = create_account("danian", danian_key.get_public_key() ); transfer(account_id_type()(db), nathan, asset(100000)); - transfer(account_id_type()(db), dan, asset(100000)); + transfer(account_id_type()(db), danian, asset(100000)); { transfer_operation top; - top.from = dan.get_id(); + top.from = danian.get_id(); top.to = nathan.get_id(); top.amount = asset(500); @@ -842,11 +842,11 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture ) proposal_update_operation uop; uop.fee_paying_account = nathan.get_id(); uop.proposal = prop.id; - uop.key_approvals_to_add.insert(dan.active.key_auths.begin()->first); + uop.key_approvals_to_add.insert(danian.active.key_auths.begin()->first); trx.operations.push_back(uop); set_expiration( db, trx ); sign( trx, nathan_key ); - sign( trx, dan_key ); + sign( trx, danian_key ); PUSH_TX( db, trx ); trx.clear(); BOOST_CHECK(!prop.is_authorized_to_execute(db)); @@ -856,7 +856,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture ) trx.operations.push_back(uop); trx.expiration += fc::seconds(1); // Survive trx dupe check sign( trx, nathan_key ); - sign( trx, dan_key ); + sign( trx, danian_key ); PUSH_TX( db, trx ); trx.clear(); BOOST_CHECK(!prop.is_authorized_to_execute(db)); @@ -866,7 +866,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture ) trx.operations.push_back(uop); trx.expiration += fc::seconds(1); // Survive trx dupe check sign( trx, nathan_key ); - sign( trx, dan_key ); + sign( trx, danian_key ); PUSH_TX( db, trx ); trx.clear(); BOOST_CHECK(!prop.is_authorized_to_execute(db)); @@ -899,9 +899,9 @@ BOOST_FIXTURE_TEST_CASE( max_authority_membership, database_fixture ) private_key_type miner_key = init_account_priv_key; // Sam is the creator of accounts - private_key_type sam_key = generate_private_key("sam"); + private_key_type samian_key = generate_private_key("samian"); - account_object sam_account_object = create_account( "sam", sam_key ); + account_object sam_account_object = create_account( "samian", samian_key ); account_object miner_account_object = miner_account(db); const asset_object& core = asset_id_type()(db); @@ -985,12 +985,12 @@ BOOST_FIXTURE_TEST_CASE( bogus_signature, database_fixture ) private_key_type miner_key = init_account_priv_key; // Sam is the creator of accounts private_key_type alice_key = generate_private_key("alice"); - private_key_type bob_key = generate_private_key("bob"); + private_key_type bobian_key = generate_private_key("bobian"); private_key_type charlie_key = generate_private_key("charlie"); account_object miner_account_object = miner_account(db); account_object alice_account_object = create_account( "alice", alice_key ); - account_object bob_account_object = create_account( "bob", bob_key ); + account_object bobian_account_object = create_account( "bobian", bobian_key ); account_object charlie_account_object = create_account( "charlie", charlie_key ); // unneeded, comment it out to silence compiler warning @@ -1005,7 +1005,7 @@ BOOST_FIXTURE_TEST_CASE( bogus_signature, database_fixture ) transfer_operation xfer_op; xfer_op.from = alice_account_object.id; - xfer_op.to = bob_account_object.id; + xfer_op.to = bobian_account_object.id; xfer_op.amount = core.amount(5000); xfer_op.fee = db.current_fee_schedule().calculate_fee( xfer_op ); @@ -1114,9 +1114,9 @@ BOOST_FIXTURE_TEST_CASE( get_required_signatures_test, database_fixture ) try { ACTORS( - (alice)(bob)(cindy)(dan)(edy) - (mega)(nova)(odle)(poxx) - (well)(xylo)(yaya)(zyzz) + (alice)(bobian)(cindy)(danian)(edyian) + (megan)(novam)(odlem)(poxxx) + (wello)(xyloo)(yayat)(zyzzz) ); auto set_auth = [&]( @@ -1160,46 +1160,46 @@ BOOST_FIXTURE_TEST_CASE( get_required_signatures_test, database_fixture ) return result_set == ref_set; } ; - set_auth( well_id, authority( 60, alice_id, 50, bob_id, 50 ) ); - set_auth( xylo_id, authority( 40, alice_id, 30, cindy_id, 50 ) ); - set_auth( yaya_id, authority( 20, bob_id, 10, dan_id, 10, edy_id, 10 ) ); - set_auth( zyzz_id, authority( 40, dan_id, 50 ) ); + set_auth( wello_id, authority( 60, alice_id, 50, bobian_id, 50 ) ); + set_auth( xyloo_id, authority( 40, alice_id, 30, cindy_id, 50 ) ); + set_auth( yayat_id, authority( 20, bobian_id, 10, danian_id, 10, edyian_id, 10 ) ); + set_auth( zyzzz_id, authority( 40, danian_id, 50 ) ); - set_auth( mega_id, authority( 40, well_id, 30, yaya_id, 30 ) ); - set_auth( nova_id, authority( 20, alice_id, 10, well_id, 10 ) ); - set_auth( odle_id, authority( 20, dan_id, 10, yaya_id, 10, zyzz_id, 10 ) ); - set_auth( poxx_id, authority( 40, well_id, 10, xylo_id, 10, yaya_id, 20, zyzz_id, 20 ) ); + set_auth( megan_id, authority( 40, wello_id, 30, yayat_id, 30 ) ); + set_auth( novam_id, authority( 20, alice_id, 10, wello_id, 10 ) ); + set_auth( odlem_id, authority( 20, danian_id, 10, yayat_id, 10, zyzzz_id, 10 ) ); + set_auth( poxxx_id, authority( 40, wello_id, 10, xyloo_id, 10, yayat_id, 20, zyzzz_id, 20 ) ); signed_transaction tx; flat_set< public_key_type > all_keys - { alice_public_key, bob_public_key, cindy_public_key, dan_public_key, edy_public_key }; + { alice_public_key, bobian_public_key, cindy_public_key, danian_public_key, edyian_public_key }; tx.operations.push_back( transfer_operation() ); transfer_operation& op = tx.operations.back().get(); - op.to = edy_id; + op.to = edyian_id; op.amount = asset(1); op.from = alice_id; BOOST_CHECK( chk( tx, all_keys, { alice_public_key } ) ); - op.from = bob_id; - BOOST_CHECK( chk( tx, all_keys, { bob_public_key } ) ); - op.from = well_id; - BOOST_CHECK( chk( tx, all_keys, { alice_public_key, bob_public_key } ) ); - op.from = xylo_id; + op.from = bobian_id; + BOOST_CHECK( chk( tx, all_keys, { bobian_public_key } ) ); + op.from = wello_id; + BOOST_CHECK( chk( tx, all_keys, { alice_public_key, bobian_public_key } ) ); + op.from = xyloo_id; BOOST_CHECK( chk( tx, all_keys, { alice_public_key, cindy_public_key } ) ); - op.from = yaya_id; - BOOST_CHECK( chk( tx, all_keys, { bob_public_key, dan_public_key } ) ); - op.from = zyzz_id; - BOOST_CHECK( chk( tx, all_keys, { dan_public_key } ) ); - - op.from = mega_id; - BOOST_CHECK( chk( tx, all_keys, { alice_public_key, bob_public_key, dan_public_key } ) ); - op.from = nova_id; - BOOST_CHECK( chk( tx, all_keys, { alice_public_key, bob_public_key } ) ); - op.from = odle_id; - BOOST_CHECK( chk( tx, all_keys, { bob_public_key, dan_public_key } ) ); - op.from = poxx_id; - BOOST_CHECK( chk( tx, all_keys, { alice_public_key, bob_public_key, cindy_public_key, dan_public_key } ) ); + op.from = yayat_id; + BOOST_CHECK( chk( tx, all_keys, { bobian_public_key, danian_public_key } ) ); + op.from = zyzzz_id; + BOOST_CHECK( chk( tx, all_keys, { danian_public_key } ) ); + + op.from = megan_id; + BOOST_CHECK( chk( tx, all_keys, { alice_public_key, bobian_public_key, danian_public_key } ) ); + op.from = novam_id; + BOOST_CHECK( chk( tx, all_keys, { alice_public_key, bobian_public_key } ) ); + op.from = odlem_id; + BOOST_CHECK( chk( tx, all_keys, { bobian_public_key, danian_public_key } ) ); + op.from = poxxx_id; + BOOST_CHECK( chk( tx, all_keys, { alice_public_key, bobian_public_key, cindy_public_key, danian_public_key } ) ); // TODO: Add sigs to tx, then check // TODO: Check removing sigs @@ -1228,9 +1228,9 @@ BOOST_FIXTURE_TEST_CASE( nonminimal_sig_test, database_fixture ) try { ACTORS( - (alice)(bob) - (roco) - (styx)(thud) + (alice)(bobian) + (rocon) + (styxn)(thudn) ); auto set_auth = [&]( @@ -1286,19 +1286,19 @@ BOOST_FIXTURE_TEST_CASE( nonminimal_sig_test, database_fixture ) return result_set == ref_set; } ; - set_auth( roco_id, authority( 2, styx_id, 1, thud_id, 2 ) ); - set_auth( styx_id, authority( 2, alice_id, 1, bob_id, 1 ) ); - set_auth( thud_id, authority( 1, alice_id, 1 ) ); + set_auth( rocon_id, authority( 2, styxn_id, 1, thudn_id, 2 ) ); + set_auth( styxn_id, authority( 2, alice_id, 1, bobian_id, 1 ) ); + set_auth( thudn_id, authority( 1, alice_id, 1 ) ); signed_transaction tx; transfer_operation op; - op.from = roco_id; - op.to = bob_id; + op.from = rocon_id; + op.to = bobian_id; op.amount = asset(1); tx.operations.push_back( op ); - BOOST_CHECK( chk( tx, { alice_public_key, bob_public_key }, { alice_public_key, bob_public_key } ) ); - BOOST_CHECK( chk_min( tx, { alice_public_key, bob_public_key }, { alice_public_key } ) ); + BOOST_CHECK( chk( tx, { alice_public_key, bobian_public_key }, { alice_public_key, bobian_public_key } ) ); + BOOST_CHECK( chk_min( tx, { alice_public_key, bobian_public_key }, { alice_public_key } ) ); GRAPHENE_REQUIRE_THROW( tx.verify_authority( db.get_chain_id(), get_active, get_owner ), fc::exception ); sign( tx, alice_private_key ); diff --git a/tests/tests/basic_tests.cpp b/tests/tests/basic_tests.cpp index 71245242..78934d7f 100644 --- a/tests/tests/basic_tests.cpp +++ b/tests/tests/basic_tests.cpp @@ -44,6 +44,7 @@ using namespace graphene::chain; using namespace graphene::db; + BOOST_FIXTURE_TEST_SUITE( basic_tests, database_fixture ) /** @@ -64,17 +65,18 @@ BOOST_AUTO_TEST_CASE( valid_name_test ) BOOST_CHECK( !is_valid_name( "a." ) ); BOOST_CHECK( !is_valid_name( "a-" ) ); - BOOST_CHECK( is_valid_name( "aaa" ) ); - BOOST_CHECK( !is_valid_name( "aAa" ) ); - BOOST_CHECK( is_valid_name( "a0a" ) ); - BOOST_CHECK( !is_valid_name( "a.a" ) ); - BOOST_CHECK( is_valid_name( "a-a" ) ); - - BOOST_CHECK( is_valid_name( "aa0" ) ); - BOOST_CHECK( !is_valid_name( "aA0" ) ); - BOOST_CHECK( is_valid_name( "a00" ) ); - BOOST_CHECK( !is_valid_name( "a.0" ) ); - BOOST_CHECK( is_valid_name( "a-0" ) ); + //this is depend on GRAPHENE_MIN_ACCOUNT_NAME_LENGTH + BOOST_CHECK( is_valid_name( "aaaaa" ) ); + BOOST_CHECK( !is_valid_name( "aaaAa" ) ); + BOOST_CHECK( is_valid_name( "aaa0a" ) ); + BOOST_CHECK( !is_valid_name( "aaa.a" ) ); + BOOST_CHECK( is_valid_name( "aaa-a" ) ); + + BOOST_CHECK( is_valid_name( "aaaa0" ) ); + BOOST_CHECK( !is_valid_name( "aaaA0" ) ); + BOOST_CHECK( is_valid_name( "aaa00" ) ); + BOOST_CHECK( !is_valid_name( "aaa.0" ) ); + BOOST_CHECK( is_valid_name( "aaa-0" ) ); BOOST_CHECK( is_valid_name( "aaa-bbb-ccc" ) ); BOOST_CHECK( is_valid_name( "aaa-bbb.ccc" ) ); diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 9dd38a8c..5545af41 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -32,9 +32,9 @@ #include #include #include -#include +//#include -#include +#include "../common/tempdir.hpp" #include @@ -601,7 +601,7 @@ BOOST_FIXTURE_TEST_CASE( optional_tapos, database_fixture ) { try { - ACTORS( (alice)(bob) ); + ACTORS( (alice)(bobian) ); generate_block(); @@ -610,7 +610,7 @@ BOOST_FIXTURE_TEST_CASE( optional_tapos, database_fixture ) transfer( account_id_type(), alice_id, asset( 1000000 ) ); transfer_operation op; op.from = alice_id; - op.to = bob_id; + op.to = bobian_id; op.amount = asset( 1000 ); signed_transaction tx; tx.operations.push_back( op ); @@ -710,7 +710,7 @@ BOOST_FIXTURE_TEST_CASE( maintenance_interval, database_fixture ) } } - +#if 0 //NOT BOOST_FIXTURE_TEST_CASE( limit_order_expiration, database_fixture ) { try { //Get a sane head block time @@ -753,18 +753,19 @@ BOOST_FIXTURE_TEST_CASE( limit_order_expiration, database_fixture ) BOOST_CHECK(db.find_object(id) == nullptr); BOOST_CHECK_EQUAL( get_balance(*nathan, *core), 50000 ); } FC_LOG_AND_RETHROW() } +#endif BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture ) { try { generate_block(); const auto& alice = account_id_type()(db); - ACTOR(bob); + ACTOR(bobian); asset amount(1000); set_expiration( db, trx ); transfer_operation t; t.from = alice.id; - t.to = bob.id; + t.to = bobian.id; t.amount = amount; trx.operations.push_back(t); for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op); @@ -773,7 +774,7 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture ) db.push_transaction(trx, ~0); trx.operations.clear(); - t.from = bob.id; + t.from = bobian.id; t.to = alice.id; t.amount = amount; trx.operations.push_back(t); @@ -784,8 +785,8 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture ) GRAPHENE_REQUIRE_THROW( db.push_transaction(trx, 0), fc::exception ); BOOST_TEST_MESSAGE( "Verify that double-signing causes an exception" ); - sign( trx, bob_private_key ); - sign( trx, bob_private_key ); + sign( trx, bobian_private_key ); + sign( trx, bobian_private_key ); GRAPHENE_REQUIRE_THROW( db.push_transaction(trx, 0), tx_duplicate_sig ); BOOST_TEST_MESSAGE( "Verify that signing with an extra, unused key fails" ); @@ -796,7 +797,7 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture ) BOOST_TEST_MESSAGE( "Verify that signing once with the proper key passes" ); trx.signatures.pop_back(); db.push_transaction(trx, 0); - sign( trx, bob_private_key ); + sign( trx, bobian_private_key ); } FC_LOG_AND_RETHROW() } @@ -823,6 +824,7 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) { proposal_update_operation uop; uop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT; + uop.fee = asset(); uop.active_approvals_to_add = {get_account("init0").get_id(), get_account("init1").get_id(), get_account("init2").get_id(), get_account("init3").get_id(), get_account("init4").get_id(), get_account("init5").get_id(), @@ -882,8 +884,8 @@ BOOST_FIXTURE_TEST_CASE( pop_block_twice, database_fixture ) // Sam is the creator of accounts private_key_type miner_key = init_account_priv_key; - private_key_type sam_key = generate_private_key("sam"); - account_object sam_account_object = create_account("sam", sam_key); + private_key_type sam_key = generate_private_key("samian"); + account_object sam_account_object = create_account("samian", sam_key); //Get a sane head block time generate_block( skip_flags ); @@ -903,7 +905,7 @@ BOOST_FIXTURE_TEST_CASE( pop_block_twice, database_fixture ) create_account("alice"); generate_block(skip_flags); - create_account("bob"); + create_account("bobian"); generate_block(skip_flags); db.pop_block(); @@ -1042,7 +1044,7 @@ BOOST_FIXTURE_TEST_CASE( transaction_invalidated_in_cache, database_fixture ) { try { - ACTORS( (alice)(bob) ); + ACTORS( (alice)(bobian) ); auto generate_block = [&]( database& d, uint32_t skip ) -> signed_block { @@ -1065,18 +1067,18 @@ BOOST_FIXTURE_TEST_CASE( transaction_invalidated_in_cache, database_fixture ) db2.push_block(*b, database::skip_miner_signature); } BOOST_CHECK( db2.get( alice_id ).name == "alice" ); - BOOST_CHECK( db2.get( bob_id ).name == "bob" ); + BOOST_CHECK( db2.get( bobian_id ).name == "bobian" ); db2.push_block(generate_block(db, database::skip_nothing)); transfer( account_id_type(), alice_id, asset( 1000 ) ); - transfer( account_id_type(), bob_id, asset( 1000 ) ); + transfer( account_id_type(), bobian_id, asset( 1000 ) ); // need to skip authority check here as well for same reason as above db2.push_block(generate_block(db, database::skip_authority_check), database::skip_authority_check); BOOST_CHECK_EQUAL(db.get_balance(alice_id, asset_id_type()).amount.value, 1000); - BOOST_CHECK_EQUAL(db.get_balance( bob_id, asset_id_type()).amount.value, 1000); + BOOST_CHECK_EQUAL(db.get_balance(bobian_id, asset_id_type()).amount.value, 1000); BOOST_CHECK_EQUAL(db2.get_balance(alice_id, asset_id_type()).amount.value, 1000); - BOOST_CHECK_EQUAL(db2.get_balance( bob_id, asset_id_type()).amount.value, 1000); + BOOST_CHECK_EQUAL(db2.get_balance(bobian_id, asset_id_type()).amount.value, 1000); auto generate_and_send = [&]( int n ) { @@ -1100,11 +1102,11 @@ BOOST_FIXTURE_TEST_CASE( transaction_invalidated_in_cache, database_fixture ) if( from == alice_id ) sign( tx, alice_private_key ); else - sign( tx, bob_private_key ); + sign( tx, bobian_private_key ); return tx; }; - signed_transaction tx = generate_xfer_tx( alice_id, bob_id, 1000, 2 ); + signed_transaction tx = generate_xfer_tx( alice_id, bobian_id, 1000, 2 ); tx.set_expiration( db.head_block_time() + 2 * db.get_global_properties().parameters.block_interval ); tx.signatures.clear(); sign( tx, alice_private_key ); @@ -1112,18 +1114,18 @@ BOOST_FIXTURE_TEST_CASE( transaction_invalidated_in_cache, database_fixture ) PUSH_TX( db, tx ); BOOST_CHECK_EQUAL(db.get_balance(alice_id, asset_id_type()).amount.value, 0); - BOOST_CHECK_EQUAL(db.get_balance( bob_id, asset_id_type()).amount.value, 2000); + BOOST_CHECK_EQUAL(db.get_balance( bobian_id, asset_id_type()).amount.value, 2000); // generate some blocks with db2, make tx expire in db's cache generate_and_send(3); BOOST_CHECK_EQUAL(db.get_balance(alice_id, asset_id_type()).amount.value, 1000); - BOOST_CHECK_EQUAL(db.get_balance( bob_id, asset_id_type()).amount.value, 1000); + BOOST_CHECK_EQUAL(db.get_balance( bobian_id, asset_id_type()).amount.value, 1000); // generate a block with db and ensure we don't somehow apply it PUSH_BLOCK(db2, generate_block(db, database::skip_nothing)); BOOST_CHECK_EQUAL(db.get_balance(alice_id, asset_id_type()).amount.value, 1000); - BOOST_CHECK_EQUAL(db.get_balance( bob_id, asset_id_type()).amount.value, 1000); + BOOST_CHECK_EQUAL(db.get_balance( bobian_id, asset_id_type()).amount.value, 1000); // now the tricky part... // (A) Bob sends 1000 to Alice @@ -1138,24 +1140,24 @@ BOOST_FIXTURE_TEST_CASE( transaction_invalidated_in_cache, database_fixture ) // This needs to occur while switching to a fork. // - signed_transaction tx_a = generate_xfer_tx( bob_id, alice_id, 1000, 2 ); - signed_transaction tx_b = generate_xfer_tx( alice_id, bob_id, 2000, 10 ); - signed_transaction tx_c = generate_xfer_tx( alice_id, bob_id, 500, 10 ); + signed_transaction tx_a = generate_xfer_tx( bobian_id, alice_id, 1000, 2 ); + signed_transaction tx_b = generate_xfer_tx( alice_id, bobian_id, 2000, 10 ); + signed_transaction tx_c = generate_xfer_tx( alice_id, bobian_id, 500, 10 ); generate_block( db, database::skip_nothing ); PUSH_TX( db, tx_a ); BOOST_CHECK_EQUAL(db.get_balance(alice_id, asset_id_type()).amount.value, 2000); - BOOST_CHECK_EQUAL(db.get_balance( bob_id, asset_id_type()).amount.value, 0); + BOOST_CHECK_EQUAL(db.get_balance( bobian_id, asset_id_type()).amount.value, 0); PUSH_TX( db, tx_b ); PUSH_TX( db2, tx_c ); BOOST_CHECK_EQUAL(db.get_balance(alice_id, asset_id_type()).amount.value, 0); - BOOST_CHECK_EQUAL(db.get_balance( bob_id, asset_id_type()).amount.value, 2000); + BOOST_CHECK_EQUAL(db.get_balance(bobian_id, asset_id_type()).amount.value, 2000); BOOST_CHECK_EQUAL(db2.get_balance(alice_id, asset_id_type()).amount.value, 500); - BOOST_CHECK_EQUAL(db2.get_balance( bob_id, asset_id_type()).amount.value, 1500); + BOOST_CHECK_EQUAL(db2.get_balance(bobian_id, asset_id_type()).amount.value, 1500); // generate enough blocks on db2 to cause db to switch forks generate_and_send(2); @@ -1163,19 +1165,19 @@ BOOST_FIXTURE_TEST_CASE( transaction_invalidated_in_cache, database_fixture ) // db should invalidate B, but still be applying A, so the states don't agree BOOST_CHECK_EQUAL(db.get_balance(alice_id, asset_id_type()).amount.value, 1500); - BOOST_CHECK_EQUAL(db.get_balance( bob_id, asset_id_type()).amount.value, 500); + BOOST_CHECK_EQUAL(db.get_balance(bobian_id, asset_id_type()).amount.value, 500); BOOST_CHECK_EQUAL(db2.get_balance(alice_id, asset_id_type()).amount.value, 500); - BOOST_CHECK_EQUAL(db2.get_balance( bob_id, asset_id_type()).amount.value, 1500); + BOOST_CHECK_EQUAL(db2.get_balance(bobian_id, asset_id_type()).amount.value, 1500); // This will cause A to expire in db generate_and_send(1); BOOST_CHECK_EQUAL(db.get_balance(alice_id, asset_id_type()).amount.value, 500); - BOOST_CHECK_EQUAL(db.get_balance( bob_id, asset_id_type()).amount.value, 1500); + BOOST_CHECK_EQUAL(db.get_balance(bobian_id, asset_id_type()).amount.value, 1500); BOOST_CHECK_EQUAL(db2.get_balance(alice_id, asset_id_type()).amount.value, 500); - BOOST_CHECK_EQUAL(db2.get_balance( bob_id, asset_id_type()).amount.value, 1500); + BOOST_CHECK_EQUAL(db2.get_balance(bobian_id, asset_id_type()).amount.value, 1500); // Make sure we can generate and accept a plain old empty block on top of all this! generate_and_send(1); diff --git a/tests/tests/confidential_tests.cpp b/tests/tests/confidential_tests.cpp deleted file mode 100644 index ab7ff5c6..00000000 --- a/tests/tests/confidential_tests.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ -/* - * Copyright (c) 2015 Cryptonomex, Inc., and contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include "../common/database_fixture.hpp" - -using namespace graphene::chain; - -BOOST_FIXTURE_TEST_SUITE( confidential_tests, database_fixture ) -BOOST_AUTO_TEST_CASE( confidential_test ) -{ try { - ACTORS( (dan)(nathan) ) - const asset_object& core = asset_id_type()(db); - - transfer(account_id_type()(db), dan, core.amount(1000000)); - - transfer_to_blind_operation to_blind; - to_blind.amount = core.amount(1000); - to_blind.from = dan.id; - - auto owner1_key = fc::ecc::private_key::generate(); - auto owner1_pub = owner1_key.get_public_key(); - auto owner2_key = fc::ecc::private_key::generate(); - auto owner2_pub = owner2_key.get_public_key(); - - blind_output out1, out2; - out1.owner = authority( 1, public_key_type(owner1_pub), 1 ); - out2.owner = authority( 1, public_key_type(owner2_pub), 1 ); - - - auto InB1 = fc::sha256::hash("InB1"); - auto InB2 = fc::sha256::hash("InB2"); - auto OutB = fc::sha256::hash("InB2"); - auto nonce1 = fc::sha256::hash("nonce"); - auto nonce2 = fc::sha256::hash("nonce2"); - - out1.commitment = fc::ecc::blind(InB1,250); - out1.range_proof = fc::ecc::range_proof_sign( 0, out1.commitment, InB1, nonce1, 0, 0, 250 ); - - out2.commitment = fc::ecc::blind(InB2,750); - out2.range_proof = fc::ecc::range_proof_sign( 0, out2.commitment, InB1, nonce2, 0, 0, 750 ); - - to_blind.blinding_factor = fc::ecc::blind_sum( {InB1,InB2}, 2 ); - to_blind.outputs = {out2,out1}; - - trx.operations = {to_blind}; - sign( trx, dan_private_key ); - db.push_transaction(trx); - trx.signatures.clear(); - - BOOST_TEST_MESSAGE( "Transfering from blind to blind with change address" ); - auto Out3B = fc::sha256::hash("Out3B"); - auto Out4B = fc::ecc::blind_sum( {InB2,Out3B}, 1 ); // add InB2 - Out3b - blind_output out3, out4; - out3.commitment = fc::ecc::blind(Out3B,300); - out3.range_proof = fc::ecc::range_proof_sign( 0, out3.commitment, InB1, nonce1, 0, 0, 300 ); - out4.commitment = fc::ecc::blind(Out4B,750-300-10); - out4.range_proof = fc::ecc::range_proof_sign( 0, out3.commitment, InB1, nonce1, 0, 0, 750-300-10 ); - - - blind_transfer_operation blind_tr; - blind_tr.fee = core.amount(10); - blind_tr.inputs.push_back( {out2.commitment, out2.owner} ); - blind_tr.outputs = {out3,out4}; - blind_tr.validate(); - trx.operations = {blind_tr}; - sign( trx, owner2_key ); - db.push_transaction(trx); - - BOOST_TEST_MESSAGE( "Attempting to double spend the same commitments" ); - blind_tr.fee = core.amount(11); - - Out4B = fc::ecc::blind_sum( {InB2,Out3B}, 1 ); // add InB2 - Out3b - out4.commitment = fc::ecc::blind(Out4B,750-300-11); - auto out4_amount = 750-300-10; - out4.range_proof = fc::ecc::range_proof_sign( 0, out3.commitment, InB1, nonce1, 0, 0, 750-300-11 ); - blind_tr.outputs = {out4,out3}; - trx.operations = {blind_tr}; - BOOST_REQUIRE_THROW( db.push_transaction(trx, ~0), graphene::chain::blind_transfer_unknown_commitment ); - - - BOOST_TEST_MESSAGE( "Transfering from blind to nathan public" ); - out4.commitment = fc::ecc::blind(Out4B,750-300-10); - - transfer_from_blind_operation from_blind; - from_blind.fee = core.amount(10); - from_blind.to = nathan.id; - from_blind.amount = core.amount( out4_amount - 10 ); - from_blind.blinding_factor = Out4B; - from_blind.inputs.push_back( {out4.commitment, out4.owner} ); - trx.operations = {from_blind}; - trx.signatures.clear(); - db.push_transaction(trx); - - BOOST_REQUIRE_EQUAL( get_balance( nathan, core ), 750-300-10-10 ); - -} FC_LOG_AND_RETHROW() } - - - -BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 85709c0a..8efce721 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -31,7 +31,7 @@ #include #include -#include +//#include #include #include #include @@ -45,6 +45,7 @@ using namespace graphene::chain::test; BOOST_FIXTURE_TEST_SUITE( operation_tests, database_fixture ) +#if 0 //NOT BOOST_AUTO_TEST_CASE( feed_limit_logic_test ) { try { @@ -74,6 +75,7 @@ BOOST_AUTO_TEST_CASE( feed_limit_logic_test ) throw; } } +#endif BOOST_AUTO_TEST_CASE( create_account_test ) { @@ -237,22 +239,24 @@ BOOST_AUTO_TEST_CASE( update_mia ) generate_block(); const asset_object& bit_usd = get_asset("USDBIT"); - asset_update_operation op; + update_monitored_asset_operation op; + op.fee = asset(); op.issuer = bit_usd.issuer; op.asset_to_update = bit_usd.id; - op.new_options = bit_usd.options; + //op.new_options = bit_usd.options; trx.operations.emplace_back(op); trx.operations.back() = op; PUSH_TX( db, trx, ~0 ); - op.new_issuer = account_id_type(); + //op.new_issuer = account_id_type(); trx.operations.back() = op; PUSH_TX( db, trx, ~0 ); +#if 0 { asset_publish_feed_operation pop; pop.asset_id = bit_usd.get_id(); - pop.publisher = get_account("init0").get_id(); + pop.publisher = GRAPHENE_MINER_ACCOUNT; //get_account("init0").get_id(); price_feed feed; feed.core_exchange_rate = price(bit_usd.amount(5), bit_usd.amount(5)); REQUIRE_THROW_WITH_VALUE(pop, feed, feed); @@ -263,27 +267,15 @@ BOOST_AUTO_TEST_CASE( update_mia ) trx.operations.back() = pop; PUSH_TX( db, trx, ~0 ); } +#endif - trx.operations.clear(); - auto nathan = create_account("nathan"); - op.issuer = account_id_type(); - op.new_issuer = nathan.id; - trx.operations.emplace_back(op); - PUSH_TX( db, trx, ~0 ); - BOOST_CHECK(bit_usd.issuer == nathan.id); - - op.issuer = nathan.id; - op.new_issuer = account_id_type(); - trx.operations.back() = op; - PUSH_TX( db, trx, ~0 ); - BOOST_CHECK(bit_usd.issuer == account_id_type()); } catch ( const fc::exception& e ) { elog( "${e}", ("e", e.to_detail_string() ) ); throw; } } - +#if 0 BOOST_AUTO_TEST_CASE( create_uia ) { try { @@ -292,7 +284,6 @@ BOOST_AUTO_TEST_CASE( create_uia ) creator.issuer = account_id_type(); creator.fee = asset(); creator.symbol = "TEST"; - creator.common_options.max_supply = 100000000; creator.precision = 2; creator.common_options.core_exchange_rate = price({asset(2),asset(1,asset_id_type(1))}); trx.operations.push_back(std::move(creator)); @@ -328,7 +319,9 @@ BOOST_AUTO_TEST_CASE( create_uia ) throw; } } +#endif +#if 0 BOOST_AUTO_TEST_CASE( update_uia ) { using namespace graphene; @@ -439,8 +432,9 @@ BOOST_AUTO_TEST_CASE( transfer_uia ) throw; } } +#endif - +#if 0 BOOST_AUTO_TEST_CASE( create_buy_uia_multiple_match_new ) { try { INVOKE( issue_uia ); @@ -604,8 +598,9 @@ BOOST_AUTO_TEST_CASE( create_buy_uia_multiple_match_new_reverse_fract ) throw; } } +#endif - +#if 0 BOOST_AUTO_TEST_CASE( uia_fees ) { try { @@ -685,7 +680,9 @@ BOOST_AUTO_TEST_CASE( cancel_limit_order_test ) throw; } } +#endif +#if 0 BOOST_AUTO_TEST_CASE( miner_feeds ) { using namespace graphene::chain; @@ -734,6 +731,7 @@ BOOST_AUTO_TEST_CASE( miner_feeds ) throw; } } +#endif /** * Create an order such that when the trade executes at the @@ -742,6 +740,7 @@ BOOST_AUTO_TEST_CASE( miner_feeds ) * I am unable to actually create such an order; I'm not sure it's possible. What I have done is create an order which * broke an assert in the matching algorithm. */ +#if 0 BOOST_AUTO_TEST_CASE( trade_amount_equals_zero ) { try { @@ -1072,6 +1071,8 @@ BOOST_AUTO_TEST_CASE( vesting_balance_withdraw_test ) // TODO: Test with non-core asset and Bob account } FC_LOG_AND_RETHROW() } +#endif + // TODO: Write linear VBO tests BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 966851ae..9fe2a479 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -33,12 +33,12 @@ #include #include #include -#include +//#include #include #include #include -#include +#include "../common/tempdir.hpp" #include @@ -52,9 +52,9 @@ BOOST_FIXTURE_TEST_SUITE( operation_tests, database_fixture ) BOOST_AUTO_TEST_CASE( withdraw_permission_create ) { try { auto nathan_private_key = generate_private_key("nathan"); - auto dan_private_key = generate_private_key("dan"); + auto dan_private_key = generate_private_key("danian"); account_id_type nathan_id = create_account("nathan", nathan_private_key.get_public_key()).id; - account_id_type dan_id = create_account("dan", dan_private_key.get_public_key()).id; + account_id_type dan_id = create_account("danian", dan_private_key.get_public_key()).id; transfer(account_id_type(), nathan_id, asset(1000)); generate_block(); @@ -89,9 +89,9 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_test ) INVOKE(withdraw_permission_create); auto nathan_private_key = generate_private_key("nathan"); - auto dan_private_key = generate_private_key("dan"); + auto dan_private_key = generate_private_key("danian"); account_id_type nathan_id = get_account("nathan").id; - account_id_type dan_id = get_account("dan").id; + account_id_type dan_id = get_account("danian").id; withdraw_permission_id_type permit; set_expiration( db, trx ); @@ -224,9 +224,9 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_nominal_case ) INVOKE(withdraw_permission_create); auto nathan_private_key = generate_private_key("nathan"); - auto dan_private_key = generate_private_key("dan"); + auto dan_private_key = generate_private_key("danian"); account_id_type nathan_id = get_account("nathan").id; - account_id_type dan_id = get_account("dan").id; + account_id_type dan_id = get_account("danian").id; withdraw_permission_id_type permit; while(true) @@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_update ) auto nathan_private_key = generate_private_key("nathan"); account_id_type nathan_id = get_account("nathan").id; - account_id_type dan_id = get_account("dan").id; + account_id_type dan_id = get_account("danian").id; withdraw_permission_id_type permit; set_expiration( db, trx ); @@ -306,7 +306,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_delete ) INVOKE(withdraw_permission_update); withdraw_permission_delete_operation op; - op.authorized_account = get_account("dan").id; + op.authorized_account = get_account("danian").id; op.withdraw_from_account = get_account("nathan").id; set_expiration( db, trx ); trx.operations.push_back(op); @@ -314,9 +314,10 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_delete ) PUSH_TX( db, trx ); } FC_LOG_AND_RETHROW() } +#if 0 //not working now BOOST_AUTO_TEST_CASE( mia_feeds ) { try { - ACTORS((nathan)(dan)(ben)(vikram)); + ACTORS((nathan)(danian)(benian)(vikram)); asset_id_type bit_usd_id = create_monitored_asset("USDBIT").id; { @@ -324,7 +325,7 @@ BOOST_AUTO_TEST_CASE( mia_feeds ) const asset_object& obj = bit_usd_id(db); op.asset_to_update = bit_usd_id; op.issuer = obj.issuer; - op.new_issuer = nathan_id; + //op.new_issuer = nathan_id; op.new_options = obj.options; trx.operations.push_back(op); PUSH_TX( db, trx, ~0 ); @@ -386,6 +387,7 @@ BOOST_AUTO_TEST_CASE( feed_limit_test ) db.push_transaction(trx); } FC_LOG_AND_RETHROW() } +#endif BOOST_AUTO_TEST_CASE( miner_create ) { try { @@ -453,7 +455,7 @@ BOOST_AUTO_TEST_CASE( assert_op_test ) // nathan checks that his public key is not equal to the given value (fail) trx.clear(); - op.predicates.emplace_back(account_name_eq_lit_predicate{ nathan_id, "dan" }); + op.predicates.emplace_back(account_name_eq_lit_predicate{ nathan_id, "danian" }); trx.operations.push_back(op); sign( trx, nathan_private_key ); GRAPHENE_CHECK_THROW( PUSH_TX( db, trx ), fc::exception ); @@ -463,26 +465,26 @@ BOOST_AUTO_TEST_CASE( assert_op_test ) BOOST_AUTO_TEST_CASE(transfer_with_memo) { try { ACTOR(alice); - ACTOR(bob); + ACTOR(bobian); transfer(account_id_type(), alice_id, asset(1000)); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 1000); transfer_operation op; op.from = alice_id; - op.to = bob_id; + op.to = bobian_id; op.amount = asset(500); op.memo = memo_data(); - op.memo->set_message(alice_private_key, bob_public_key, "Dear Bob,\n\nMoney!\n\nLove, Alice"); + op.memo->set_message(alice_private_key, bobian_public_key, "Dear Bob,\n\nMoney!\n\nLove, Alice"); trx.operations = {op}; trx.sign(alice_private_key, db.get_chain_id()); db.push_transaction(trx); BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 500); - BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 500); + BOOST_CHECK_EQUAL(get_balance(bobian_id, asset_id_type()), 500); auto memo = db.get_recent_transaction(trx.id()).operations.front().get().memo; BOOST_CHECK(memo); - BOOST_CHECK_EQUAL(memo->get_message(bob_private_key, alice_public_key), "Dear Bob,\n\nMoney!\n\nLove, Alice"); + BOOST_CHECK_EQUAL(memo->get_message(bobian_private_key, alice_public_key), "Dear Bob,\n\nMoney!\n\nLove, Alice"); } FC_LOG_AND_RETHROW() } @@ -555,7 +557,7 @@ BOOST_AUTO_TEST_CASE(zero_second_vbo) BOOST_AUTO_TEST_CASE( top_n_special ) { - ACTORS( (alice)(bob)(chloe)(dan)(izzy)(stan) ); + ACTORS( (alice)(bobian)(chloe)(danian)(izzyt)(stann) ); try @@ -567,16 +569,16 @@ BOOST_AUTO_TEST_CASE( top_n_special ) // Alice, Bob, Chloe, Dan (ABCD) // - asset_id_type topn_id = create_user_issued_asset( "TOPN", izzy_id(db) ).id; - authority stan_owner_auth = stan_id(db).owner; - authority stan_active_auth = stan_id(db).active; + asset_id_type topn_id = create_user_issued_asset( "TOPN", izzyt_id(db) ).id; + authority stan_owner_auth = stann_id(db).owner; + authority stan_active_auth = stann_id(db).active; // wait for maint interval // make sure we don't have any authority as account hasn't gotten distributed yet generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - BOOST_CHECK( stan_id(db).owner == stan_owner_auth ); - BOOST_CHECK( stan_id(db).active == stan_active_auth ); + BOOST_CHECK( stann_id(db).owner == stan_owner_auth ); + BOOST_CHECK( stann_id(db).active == stan_active_auth ); // issue some to Alice, make sure she gets control of Stan @@ -584,8 +586,8 @@ BOOST_AUTO_TEST_CASE( top_n_special ) set_expiration( db, trx ); // #11 issue_uia( alice_id, asset( 1000, topn_id ) ); - BOOST_CHECK( stan_id(db).owner == stan_owner_auth ); - BOOST_CHECK( stan_id(db).active == stan_active_auth ); + BOOST_CHECK( stann_id(db).owner == stan_owner_auth ); + BOOST_CHECK( stann_id(db).active == stan_active_auth ); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); @@ -598,17 +600,17 @@ BOOST_AUTO_TEST_CASE( top_n_special ) generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); */ - BOOST_CHECK( stan_id(db).owner == authority( 501, alice_id, 1000 ) ); - BOOST_CHECK( stan_id(db).active == authority( 501, alice_id, 1000 ) ); + BOOST_CHECK( stann_id(db).owner == authority( 501, alice_id, 1000 ) ); + BOOST_CHECK( stann_id(db).active == authority( 501, alice_id, 1000 ) ); // give asset to Stan, make sure owner doesn't change at all set_expiration( db, trx ); // #11 - transfer( alice_id, stan_id, asset( 1000, topn_id ) ); + transfer( alice_id, stann_id, asset( 1000, topn_id ) ); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - BOOST_CHECK( stan_id(db).owner == authority( 501, alice_id, 1000 ) ); - BOOST_CHECK( stan_id(db).active == authority( 501, alice_id, 1000 ) ); + BOOST_CHECK( stann_id(db).owner == authority( 501, alice_id, 1000 ) ); + BOOST_CHECK( stann_id(db).active == authority( 501, alice_id, 1000 ) ); set_expiration( db, trx ); // #11 issue_uia( chloe_id, asset( 131000, topn_id ) ); @@ -620,50 +622,50 @@ BOOST_AUTO_TEST_CASE( top_n_special ) // we use Chloe so she can be displaced by Bob later (showing the tiebreaking logic). // Check Alice is still in control, because we're deferred to next maintenance interval - BOOST_CHECK( stan_id(db).owner == authority( 501, alice_id, 1000 ) ); - BOOST_CHECK( stan_id(db).active == authority( 501, alice_id, 1000 ) ); + BOOST_CHECK( stann_id(db).owner == authority( 501, alice_id, 1000 ) ); + BOOST_CHECK( stann_id(db).active == authority( 501, alice_id, 1000 ) ); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - BOOST_CHECK( stan_id(db).owner == authority( 32751, chloe_id, 65500 ) ); - BOOST_CHECK( stan_id(db).active == authority( 32751, chloe_id, 65500 ) ); + BOOST_CHECK( stann_id(db).owner == authority( 32751, chloe_id, 65500 ) ); + BOOST_CHECK( stann_id(db).active == authority( 32751, chloe_id, 65500 ) ); // put Alice's stake back in play set_expiration( db, trx ); // #11 - transfer( stan_id, alice_id, asset( 1000, topn_id ) ); + transfer( stann_id, alice_id, asset( 1000, topn_id ) ); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - BOOST_CHECK( stan_id(db).owner == authority( 33001, alice_id, 500, chloe_id, 65500 ) ); - BOOST_CHECK( stan_id(db).active == authority( 33001, alice_id, 500, chloe_id, 65500 ) ); + BOOST_CHECK( stann_id(db).owner == authority( 33001, alice_id, 500, chloe_id, 65500 ) ); + BOOST_CHECK( stann_id(db).active == authority( 33001, alice_id, 500, chloe_id, 65500 ) ); // issue 200,000 to Dan to cause another bitshift. set_expiration( db, trx ); // #11 - issue_uia( dan_id, asset( 200000, topn_id ) ); + issue_uia( danian_id, asset( 200000, topn_id ) ); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); // 200000 Dan // 131000 Chloe // 1000 Alice - BOOST_CHECK( stan_id(db).owner == authority( 41376, chloe_id, 32750, dan_id, 50000 ) ); - BOOST_CHECK( stan_id(db).active == authority( 41501, alice_id, 250, chloe_id, 32750, dan_id, 50000 ) ); + BOOST_CHECK( stann_id(db).owner == authority( 41376, chloe_id, 32750, danian_id, 50000 ) ); + BOOST_CHECK( stann_id(db).active == authority( 41501, alice_id, 250, chloe_id, 32750, danian_id, 50000 ) ); // have Alice send all but 1 back to Stan, verify that we clamp Alice at one vote set_expiration( db, trx ); // #11 - transfer( alice_id, stan_id, asset( 999, topn_id ) ); + transfer( alice_id, stann_id, asset( 999, topn_id ) ); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - BOOST_CHECK( stan_id(db).owner == authority( 41376, chloe_id, 32750, dan_id, 50000 ) ); - BOOST_CHECK( stan_id(db).active == authority( 41376, alice_id, 1, chloe_id, 32750, dan_id, 50000 ) ); + BOOST_CHECK( stann_id(db).owner == authority( 41376, chloe_id, 32750, danian_id, 50000 ) ); + BOOST_CHECK( stann_id(db).active == authority( 41376, alice_id, 1, chloe_id, 32750, danian_id, 50000 ) ); // send 131k to Bob so he's tied with Chloe, verify he displaces Chloe in top2 set_expiration( db, trx ); // #11 - issue_uia( bob_id, asset( 131000, topn_id ) ); + issue_uia( bobian_id, asset( 131000, topn_id ) ); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - BOOST_CHECK( stan_id(db).owner == authority( 41376, bob_id, 32750, dan_id, 50000 ) ); - BOOST_CHECK( stan_id(db).active == authority( 57751, bob_id, 32750, chloe_id, 32750, dan_id, 50000 ) ); + BOOST_CHECK( stann_id(db).owner == authority( 41376, bobian_id, 32750, danian_id, 50000 ) ); + BOOST_CHECK( stann_id(db).active == authority( 57751, bobian_id, 32750, chloe_id, 32750, danian_id, 50000 ) ); // TODO more rounding checks } @@ -671,138 +673,4 @@ BOOST_AUTO_TEST_CASE( top_n_special ) } FC_LOG_AND_RETHROW() } -BOOST_AUTO_TEST_CASE( buyback ) -{ - ACTORS( (alice)(bob)(chloe)(dan)(izzy)(philbin) ); - - - try - { - { - // - // Izzy (issuer) - // Alice, Bob, Chloe, Dan (ABCD) - // Rex (recycler -- buyback account) - // Philbin (registrar) - // - - asset_id_type nono_id = create_user_issued_asset( "NONO", izzy_id(db) ).id; - asset_id_type buyme_id = create_user_issued_asset( "BUYME", izzy_id(db) ).id; - - // Create a buyback account - account_id_type rex_id; - { - buyback_account_options bbo; - bbo.asset_to_buy = buyme_id; - bbo.asset_to_buy_issuer = izzy_id; - bbo.markets.emplace( asset_id_type() ); - account_create_operation create_op = make_account( "rex" ); - create_op.registrar = philbin_id; - create_op.extensions.value.buyback_options = bbo; - create_op.owner = authority::null_authority(); - create_op.active = authority::null_authority(); - - // Let's break it... - - signed_transaction tx; - tx.operations.push_back( create_op ); - set_expiration( db, tx ); - - tx.operations.back().get< account_create_operation >().extensions.value.buyback_options->asset_to_buy_issuer = alice_id; - sign( tx, alice_private_key ); - sign( tx, philbin_private_key ); - - // Alice and Philbin signed, but asset issuer is invalid - GRAPHENE_CHECK_THROW( db.push_transaction(tx), account_create_buyback_incorrect_issuer ); - - tx.signatures.clear(); - tx.operations.back().get< account_create_operation >().extensions.value.buyback_options->asset_to_buy_issuer = izzy_id; - sign( tx, philbin_private_key ); - - // Izzy didn't sign - GRAPHENE_CHECK_THROW( db.push_transaction(tx), tx_missing_active_auth ); - sign( tx, izzy_private_key ); - - // OK - processed_transaction ptx = db.push_transaction( tx ); - rex_id = ptx.operation_results.back().get< object_id_type >(); - - // Try to create another account rex2 which is bbo on same asset - tx.signatures.clear(); - tx.operations.back().get< account_create_operation >().name = "rex2"; - sign( tx, izzy_private_key ); - sign( tx, philbin_private_key ); - GRAPHENE_CHECK_THROW( db.push_transaction(tx), account_create_buyback_already_exists ); - } - - // issue some BUYME to Alice - // we need to set_expiration() before issue_uia() because the latter doens't call it #11 - set_expiration( db, trx ); // #11 - issue_uia( alice_id, asset( 1000, buyme_id ) ); - issue_uia( alice_id, asset( 1000, nono_id ) ); - - // Alice wants to sell 100 BUYME for 1000 BTS, a middle price. - limit_order_id_type order_id_mid = create_sell_order( alice_id, asset( 100, buyme_id ), asset( 1000, asset_id_type() ) )->id; - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - generate_block(); - - // no success because buyback has none for sale - BOOST_CHECK( order_id_mid(db).for_sale == 100 ); - - // but we can send some to buyback - fund( rex_id(db), asset( 100, asset_id_type() ) ); - // no action until next maint - BOOST_CHECK( order_id_mid(db).for_sale == 100 ); - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - generate_block(); - - // partial fill, Alice now sells 90 BUYME for 900 BTS. - BOOST_CHECK( order_id_mid(db).for_sale == 90 ); - - // TODO check burn amount - - // aagh more state in trx - set_expiration( db, trx ); // #11 - - // Selling 10 BUYME for 50 BTS, a low price. - limit_order_id_type order_id_low = create_sell_order( alice_id, asset( 10, buyme_id ), asset( 50, asset_id_type() ) )->id; - // Selling 10 BUYME for 150 BTS, a high price. - limit_order_id_type order_id_high = create_sell_order( alice_id, asset( 10, buyme_id ), asset( 150, asset_id_type() ) )->id; - - fund( rex_id(db), asset( 250, asset_id_type() ) ); - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - generate_block(); - - BOOST_CHECK( db.find( order_id_low ) == nullptr ); - BOOST_CHECK( db.find( order_id_mid ) != nullptr ); - BOOST_CHECK( db.find( order_id_high ) != nullptr ); - - // 250 CORE in rex 90 BUYME in mid order 10 BUYME in low order - // 50 CORE goes to low order, buy 10 for 50 CORE - // 200 CORE goes to mid order, buy 20 for 200 CORE - // 70 BUYME in mid order 0 BUYME in low order - - idump( (order_id_mid(db)) ); - BOOST_CHECK( order_id_mid(db).for_sale == 70 ); - BOOST_CHECK( order_id_high(db).for_sale == 10 ); - - BOOST_CHECK( get_balance( rex_id, asset_id_type() ) == 0 ); - - // clear out the books -- 700 left on mid order, 150 left on high order, so 2000 BTS should result in 1150 left over - - fund( rex_id(db), asset( 2000, asset_id_type() ) ); - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - idump( (get_balance( rex_id, asset_id_type() )) ); - - BOOST_CHECK( get_balance( rex_id, asset_id_type() ) == 1150 ); - - GRAPHENE_CHECK_THROW( transfer( alice_id, rex_id, asset( 1, nono_id ) ), fc::exception ); - // TODO: Check cancellation works for account which is BTS-restricted - } - - } FC_LOG_AND_RETHROW() -} - BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/tests/serialization_tests.cpp b/tests/tests/serialization_tests.cpp index fb87c4c4..7a583e81 100644 --- a/tests/tests/serialization_tests.cpp +++ b/tests/tests/serialization_tests.cpp @@ -122,6 +122,7 @@ BOOST_AUTO_TEST_CASE( extended_public_key_type_test ) } } +#if 0 BOOST_AUTO_TEST_CASE( extension_serialization_test ) { try @@ -147,5 +148,6 @@ BOOST_AUTO_TEST_CASE( extension_serialization_test ) throw; } } +#endif BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index af4856ea..03e23488 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -49,9 +49,9 @@ BOOST_AUTO_TEST_CASE( create_advanced_uia ) creator.issuer = account_id_type(); creator.fee = asset(); creator.symbol = "ADVANCED"; - creator.common_options.max_supply = 100000000; + creator.options.max_supply = 100000000; creator.precision = 2; - creator.common_options.core_exchange_rate = price({asset(2),asset(1,asset_id_type(1))}); + creator.options.core_exchange_rate = price({asset(2),asset(1, asset_id_type(1))}); trx.operations.push_back(std::move(creator)); PUSH_TX( db, trx, ~0 ); @@ -59,11 +59,11 @@ BOOST_AUTO_TEST_CASE( create_advanced_uia ) BOOST_CHECK(test_asset.symbol == "ADVANCED"); BOOST_CHECK(asset(1, test_asset_id) * test_asset.options.core_exchange_rate == asset(2)); BOOST_CHECK(test_asset.options.max_supply == 100000000); - BOOST_CHECK(!test_asset.options.monitored_asset_opts.valid()); + BOOST_CHECK(!test_asset.monitored_asset_opts.valid()); const asset_dynamic_data_object& test_asset_dynamic_data = test_asset.dynamic_asset_data_id(db); BOOST_CHECK(test_asset_dynamic_data.current_supply == 0); - BOOST_CHECK(test_asset_dynamic_data.accumulated_fees == 0); + } catch(fc::exception& e) { edump((e.to_detail_string())); throw; @@ -74,7 +74,8 @@ BOOST_AUTO_TEST_CASE( asset_name_test ) { try { - ACTORS( (alice)(bob) ); + //names must be at least 5 characters long... + ACTORS( (alice)(bobian) ); auto has_asset = [&]( std::string symbol ) -> bool { @@ -88,13 +89,13 @@ BOOST_AUTO_TEST_CASE( asset_name_test ) BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); // Nobody can create another asset named ALPHA - GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA", bob_id(db) ), fc::exception ); + GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA", bobian_id(db) ), fc::exception ); BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA", alice_id(db) ), fc::exception ); BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); // Bob can't create ALPHA.ONE - GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA.ONE", bob_id(db) ), fc::exception ); + GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA.ONE", bobian_id(db) ), fc::exception ); BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); // Alice can create it create_user_issued_asset( "ALPHA.ONE", alice_id(db) ); From 08ff64a60ad7b15f5cc8c1e56eb67233d79a6e55 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Fri, 10 Nov 2017 11:49:39 +0100 Subject: [PATCH 003/136] tests update --- tests/CMakeLists.txt | 1 + tests/common/database_fixture.cpp | 84 ++++++++++----------- tests/common/database_fixture.hpp | 12 +-- tests/tests/block_tests.cpp | 2 + tests/tests/fee_tests.cpp | 39 +++++----- tests/tests/operation_tests2.cpp | 117 ------------------------------ 6 files changed, 73 insertions(+), 182 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5a66fcac..82ad43cc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,6 +18,7 @@ set(TEST_FILES_LIST tests/operation_tests.cpp tests/operation_tests2.cpp tests/authority_tests.cpp + tests/fee_tests.cpp tests/uia_tests.cpp tests/main.cpp diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index efe2e319..aafd3aa8 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -563,16 +563,35 @@ void database_fixture::issue_uia( account_id_type recipient_id, asset amount ) issue_uia( recipient_id(db), amount ); } +void database_fixture::publish_feed( const asset_object& mia, const account_object& by, const price_feed& f ) +{ + set_expiration( db, trx ); + trx.operations.clear(); + asset_publish_feed_operation op; + op.publisher = by.id; + op.asset_id = mia.id; + op.feed = f; + if( op.feed.core_exchange_rate.is_null() ) + op.feed.core_exchange_rate = price(asset(1, op.feed.core_exchange_rate.base.asset_id), asset(1, op.feed.core_exchange_rate.quote.asset_id)); + trx.operations.emplace_back( std::move(op) ); + for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op); + trx.validate(); + db.push_transaction(trx, ~0); + trx.operations.clear(); + verify_asset_supplies(db); +} -#if 0 /////////////////////////////////////////////////////////////////////////////////////// +#if 0 /////////////////////////////////////////////////////////////////////////////////////// + + fc::ecc::private_key database_fixture::generate_private_key(string seed) @@ -598,7 +617,29 @@ void database_fixture::verify_account_history_plugin_index( )const return; } +const limit_order_object*database_fixture::create_sell_order(account_id_type user, const asset& amount, const asset& recv) +{ + auto r = create_sell_order(user(db), amount, recv); + verify_asset_supplies(db); + return r; +} +const limit_order_object* database_fixture::create_sell_order( const account_object& user, const asset& amount, const asset& recv ) +{ + //wdump((amount)(recv)); + limit_order_create_operation buy_order; + buy_order.seller = user.id; + buy_order.amount_to_sell = amount; + buy_order.min_to_receive = recv; + trx.operations.push_back(buy_order); + for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op); + trx.validate(); + auto processed = db.push_transaction(trx, ~0); + trx.operations.clear(); + verify_asset_supplies(db); + //wdump((processed)); + return db.find( processed.operation_results[0].get() ); +} @@ -636,29 +677,7 @@ void database_fixture::change_fees( }); } -const limit_order_object*database_fixture::create_sell_order(account_id_type user, const asset& amount, const asset& recv) -{ - auto r = create_sell_order(user(db), amount, recv); - verify_asset_supplies(db); - return r; -} -const limit_order_object* database_fixture::create_sell_order( const account_object& user, const asset& amount, const asset& recv ) -{ - //wdump((amount)(recv)); - limit_order_create_operation buy_order; - buy_order.seller = user.id; - buy_order.amount_to_sell = amount; - buy_order.min_to_receive = recv; - trx.operations.push_back(buy_order); - for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op); - trx.validate(); - auto processed = db.push_transaction(trx, ~0); - trx.operations.clear(); - verify_asset_supplies(db); - //wdump((processed)); - return db.find( processed.operation_results[0].get() ); -} asset database_fixture::cancel_limit_order( const limit_order_object& order ) { @@ -676,25 +695,6 @@ asset database_fixture::cancel_limit_order( const limit_order_object& order ) -void database_fixture::publish_feed( const asset_object& mia, const account_object& by, const price_feed& f ) -{ - set_expiration( db, trx ); - trx.operations.clear(); - - asset_publish_feed_operation op; - op.publisher = by.id; - op.asset_id = mia.id; - op.feed = f; - if( op.feed.core_exchange_rate.is_null() ) - op.feed.core_exchange_rate = price(asset(1, op.feed.core_exchange_rate.base.asset_id), asset(1, op.feed.core_exchange_rate.quote.asset_id)); - trx.operations.emplace_back( std::move(op) ); - - for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op); - trx.validate(); - db.push_transaction(trx, ~0); - trx.operations.clear(); - verify_asset_supplies(db); -} void database_fixture::print_market( const string& syma, const string& symb )const { diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index da146cf4..88feaaeb 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -237,6 +237,10 @@ struct database_fixture { void issue_uia( const account_object& recipient, asset amount ); void issue_uia( account_id_type recipient_id, asset amount ); + void publish_feed(asset_id_type mia, account_id_type by, const price_feed& f) + { publish_feed(mia(db), by(db), f); } + void publish_feed(const asset_object& mia, const account_object& by, const price_feed& f); + @@ -273,17 +277,13 @@ struct database_fixture { static void verify_asset_supplies( const database& db ); void verify_account_history_plugin_index( )const; - - void publish_feed(asset_id_type mia, account_id_type by, const price_feed& f) - { publish_feed(mia(db), by(db), f); } - void publish_feed(const asset_object& mia, const account_object& by, const price_feed& f); + const limit_order_object* create_sell_order( account_id_type user, const asset& amount, const asset& recv ); + const limit_order_object* create_sell_order( const account_object& user, const asset& amount, const asset& recv ); - //const limit_order_object* create_sell_order( account_id_type user, const asset& amount, const asset& recv ); - //const limit_order_object* create_sell_order( const account_object& user, const asset& amount, const asset& recv ); //asset cancel_limit_order( const limit_order_object& order ); void fund_fee_pool( const account_object& from, const asset_object& asset_to_fund, const share_type amount ); //void change_fees( const flat_set< fee_parameters >& new_params, uint32_t new_scale = 0 ); diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 5545af41..599b80d4 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -801,6 +801,7 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture ) } FC_LOG_AND_RETHROW() } +#if 0 //update_proposal need votes from miners.. BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) { try { generate_block(); @@ -869,6 +870,7 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) generate_block(); BOOST_CHECK_EQUAL(db.head_block_time().sec_since_epoch() - past_time, 2); } FC_LOG_AND_RETHROW() } +#endif BOOST_FIXTURE_TEST_CASE( pop_block_twice, database_fixture ) { diff --git a/tests/tests/fee_tests.cpp b/tests/tests/fee_tests.cpp index ec83ca90..731473cb 100644 --- a/tests/tests/fee_tests.cpp +++ b/tests/tests/fee_tests.cpp @@ -27,7 +27,7 @@ #include #include -#include +//#include #include #include @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE( nonzero_fee_test ) { try { - ACTORS((alice)(bob)); + ACTORS((alice)(bobian)); const share_type prec = asset::scaled_precision( asset_id_type()(db).precision ); @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE( nonzero_fee_test ) signed_transaction tx; transfer_operation xfer_op; xfer_op.from = alice_id; - xfer_op.to = bob_id; + xfer_op.to = bobian_id; xfer_op.amount = _core(1000); xfer_op.fee = _core(0); tx.operations.push_back( xfer_op ); @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(asset_claim_fees_test) { try { - ACTORS((alice)(bob)(izzy)(jill)); + ACTORS((alice)(bobian)(izzyt)(jilly)); // Izzy issues asset to Alice // Jill issues asset to Bob // Alice and Bob trade in the market and pay fees @@ -92,12 +92,12 @@ BOOST_AUTO_TEST_CASE(asset_claim_fees_test) { return asset( x*core_prec ); }; transfer( miner_account, alice_id, _core(1000000) ); - transfer( miner_account, bob_id, _core(1000000) ); - transfer( miner_account, izzy_id, _core(1000000) ); - transfer( miner_account, jill_id, _core(1000000) ); + transfer( miner_account, bobian_id, _core(1000000) ); + transfer( miner_account, izzyt_id, _core(1000000) ); + transfer( miner_account, jilly_id, _core(1000000) ); - asset_id_type izzycoin_id = create_monitored_asset( "IZZYCOIN", izzy_id ).id; - asset_id_type jillcoin_id = create_monitored_asset( "JILLCOIN", jill_id ).id; + asset_id_type izzycoin_id = create_monitored_asset( "IZZYCOIN", izzyt_id ).id; + asset_id_type jillcoin_id = create_monitored_asset( "JILLCOIN", jilly_id ).id; const share_type izzy_prec = asset::scaled_precision( asset_id_type(izzycoin_id)(db).precision ); const share_type jill_prec = asset::scaled_precision( asset_id_type(jillcoin_id)(db).precision ); @@ -112,20 +112,22 @@ BOOST_AUTO_TEST_CASE(asset_claim_fees_test) // Izzycoin is worth 100 BTS price_feed feed; - publish_feed( izzycoin_id(db), izzy, feed ); + publish_feed( izzycoin_id(db), izzyt, feed ); // Jillcoin is worth 30 BTS - publish_feed( jillcoin_id(db), jill, feed ); + publish_feed( jillcoin_id(db), jilly, feed ); enable_fees(); // Alice and Bob issue some coins issue_uia( alice_id, asset( 200*izzy_prec, izzycoin_id ) ); - issue_uia( bob_id, asset( 2000*jill_prec, jillcoin_id ) ); + issue_uia(bobian_id, asset( 2000*jill_prec, jillcoin_id ) ); + +#if 0 // Alice and Bob place orders which match create_sell_order( alice_id, _izzy(100), _jill(300) ); // Alice is willing to sell her Izzy's for 3 Jill - create_sell_order( bob_id, _jill(700), _izzy(200) ); // Bob is buying up to 200 Izzy's for up to 3.5 Jill + create_sell_order(bobian_id, _jill(700), _izzy(200) ); // Bob is buying up to 200 Izzy's for up to 3.5 Jill // 100 Izzys and 300 Jills are matched, so the fees should be // 1 Izzy (1%) and 6 Jill (2%). @@ -138,17 +140,18 @@ BOOST_AUTO_TEST_CASE(asset_claim_fees_test) //wdump( (jillcoin)(jillcoin.dynamic_asset_data_id(db))((*jillcoin.bitasset_data_id)(db)) ); // check the correct amount of fees has been awarded - BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees == _izzy(1).amount ); - BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees == _jill(6).amount ); +// BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees == _izzy(1).amount ); +// BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees == _jill(6).amount ); } +#endif } FC_LOG_AND_RETHROW() } - +#if 0 BOOST_AUTO_TEST_CASE( account_create_fee_scaling ) { try { auto accounts_per_scale = db.get_global_properties().parameters.accounts_per_fee_scale; @@ -178,7 +181,9 @@ BOOST_AUTO_TEST_CASE( account_create_fee_scaling ) generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); BOOST_CHECK_EQUAL(db.get_global_properties().parameters.current_fees->get().basic_fee, 1); } FC_LOG_AND_RETHROW() } +#endif +#if 0 BOOST_AUTO_TEST_CASE( fee_refund_test ) { try @@ -308,6 +313,6 @@ BOOST_AUTO_TEST_CASE( fee_refund_test ) } FC_LOG_AND_RETHROW() } - +#endif BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 9fe2a479..5ca92b90 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -555,122 +555,5 @@ BOOST_AUTO_TEST_CASE(zero_second_vbo) // TODO: Write linear VBO tests -BOOST_AUTO_TEST_CASE( top_n_special ) -{ - ACTORS( (alice)(bobian)(chloe)(danian)(izzyt)(stann) ); - - - try - { - { - // - // Izzy (issuer) - // Stan (special authority) - // Alice, Bob, Chloe, Dan (ABCD) - // - - asset_id_type topn_id = create_user_issued_asset( "TOPN", izzyt_id(db) ).id; - authority stan_owner_auth = stann_id(db).owner; - authority stan_active_auth = stann_id(db).active; - - // wait for maint interval - // make sure we don't have any authority as account hasn't gotten distributed yet - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - BOOST_CHECK( stann_id(db).owner == stan_owner_auth ); - BOOST_CHECK( stann_id(db).active == stan_active_auth ); - - // issue some to Alice, make sure she gets control of Stan - - // we need to set_expiration() before issue_uia() because the latter doens't call it #11 - set_expiration( db, trx ); // #11 - issue_uia( alice_id, asset( 1000, topn_id ) ); - - BOOST_CHECK( stann_id(db).owner == stan_owner_auth ); - BOOST_CHECK( stann_id(db).active == stan_active_auth ); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - /* NOTE - this was an old check from an earlier implementation that only allowed SA for LTM's - // no boost yet, we need to upgrade to LTM before mechanics apply to Stan - BOOST_CHECK( stan_id(db).owner == stan_owner_auth ); - BOOST_CHECK( stan_id(db).active == stan_active_auth ); - - set_expiration( db, trx ); // #11 - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - */ - - BOOST_CHECK( stann_id(db).owner == authority( 501, alice_id, 1000 ) ); - BOOST_CHECK( stann_id(db).active == authority( 501, alice_id, 1000 ) ); - - // give asset to Stan, make sure owner doesn't change at all - set_expiration( db, trx ); // #11 - transfer( alice_id, stann_id, asset( 1000, topn_id ) ); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - BOOST_CHECK( stann_id(db).owner == authority( 501, alice_id, 1000 ) ); - BOOST_CHECK( stann_id(db).active == authority( 501, alice_id, 1000 ) ); - - set_expiration( db, trx ); // #11 - issue_uia( chloe_id, asset( 131000, topn_id ) ); - - // now Chloe has 131,000 and Stan has 1k. Make sure change occurs at next maintenance interval. - // NB, 131072 is a power of 2; the number 131000 was chosen so that we need a bitshift, but - // if we put the 1000 from Stan's balance back into play, we need a different bitshift. - - // we use Chloe so she can be displaced by Bob later (showing the tiebreaking logic). - - // Check Alice is still in control, because we're deferred to next maintenance interval - BOOST_CHECK( stann_id(db).owner == authority( 501, alice_id, 1000 ) ); - BOOST_CHECK( stann_id(db).active == authority( 501, alice_id, 1000 ) ); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - BOOST_CHECK( stann_id(db).owner == authority( 32751, chloe_id, 65500 ) ); - BOOST_CHECK( stann_id(db).active == authority( 32751, chloe_id, 65500 ) ); - - // put Alice's stake back in play - set_expiration( db, trx ); // #11 - transfer( stann_id, alice_id, asset( 1000, topn_id ) ); - - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - BOOST_CHECK( stann_id(db).owner == authority( 33001, alice_id, 500, chloe_id, 65500 ) ); - BOOST_CHECK( stann_id(db).active == authority( 33001, alice_id, 500, chloe_id, 65500 ) ); - - // issue 200,000 to Dan to cause another bitshift. - set_expiration( db, trx ); // #11 - issue_uia( danian_id, asset( 200000, topn_id ) ); - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - // 200000 Dan - // 131000 Chloe - // 1000 Alice - - BOOST_CHECK( stann_id(db).owner == authority( 41376, chloe_id, 32750, danian_id, 50000 ) ); - BOOST_CHECK( stann_id(db).active == authority( 41501, alice_id, 250, chloe_id, 32750, danian_id, 50000 ) ); - - // have Alice send all but 1 back to Stan, verify that we clamp Alice at one vote - set_expiration( db, trx ); // #11 - transfer( alice_id, stann_id, asset( 999, topn_id ) ); - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - BOOST_CHECK( stann_id(db).owner == authority( 41376, chloe_id, 32750, danian_id, 50000 ) ); - BOOST_CHECK( stann_id(db).active == authority( 41376, alice_id, 1, chloe_id, 32750, danian_id, 50000 ) ); - - // send 131k to Bob so he's tied with Chloe, verify he displaces Chloe in top2 - set_expiration( db, trx ); // #11 - issue_uia( bobian_id, asset( 131000, topn_id ) ); - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - - BOOST_CHECK( stann_id(db).owner == authority( 41376, bobian_id, 32750, danian_id, 50000 ) ); - BOOST_CHECK( stann_id(db).active == authority( 57751, bobian_id, 32750, chloe_id, 32750, danian_id, 50000 ) ); - - // TODO more rounding checks - } - - } FC_LOG_AND_RETHROW() -} BOOST_AUTO_TEST_SUITE_END() From cdcdf368ac961999a22de156188e217bc8132578 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Sun, 12 Nov 2017 12:08:39 +0100 Subject: [PATCH 004/136] created basic package test (not finished yet) --- .../include/decent/package/package.hpp | 8 + tests/CMakeLists.txt | 29 ++- tests/app/main.cpp | 2 +- tests/package/main.cpp | 239 ++++++++++++++++++ 4 files changed, 272 insertions(+), 6 deletions(-) create mode 100644 tests/package/main.cpp diff --git a/libraries/package/include/decent/package/package.hpp b/libraries/package/include/decent/package/package.hpp index e34b7de7..e3871777 100644 --- a/libraries/package/include/decent/package/package.hpp +++ b/libraries/package/include/decent/package/package.hpp @@ -398,6 +398,7 @@ namespace package { * @param content_dir_path Files with content * @param samples_dir_path Files with samples * @param key Encryption key + * @param custody_sectors */ package_handle_t get_package(const boost::filesystem::path& content_dir_path, const boost::filesystem::path& samples_dir_path, @@ -406,6 +407,7 @@ namespace package { * Creates package info out of the URL and returns handle to it. The package is ready for download. * @param url URL of the package * @param hash + * @param is_virtual * @return */ package_handle_t get_package(const std::string& url, const fc::ripemd160& hash, bool is_virtual = false); @@ -416,9 +418,15 @@ namespace package { */ package_handle_t get_package(const fc::ripemd160& hash); + /** + * search for existing package and returns handle to it or nullptr. + * @param package_hash Hash of the package + * @return + */ package_handle_t find_package(const std::string& url); package_handle_t find_package(const fc::ripemd160& hash); + package_handle_set_t get_all_known_packages() const; void recover_all_packages(const event_listener_handle_t& event_listener = event_listener_handle_t()); bool release_all_packages(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 82ad43cc..b0624176 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,7 +19,6 @@ set(TEST_FILES_LIST tests/operation_tests2.cpp tests/authority_tests.cpp tests/fee_tests.cpp - tests/uia_tests.cpp tests/main.cpp ) @@ -30,6 +29,30 @@ if(MSVC) set_source_files_properties( tests/serialization_tests.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) endif(MSVC) +#///////////////////////////////////////////////////////////////////// + +set(APP_TEST_FILES + common/tempdir.hpp + common/tempdir.cpp + app/main.cpp +) + +add_executable( app_test ${APP_TEST_FILES} ) +target_link_libraries( app_test graphene_app graphene_account_history graphene_net graphene_chain graphene_time graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) + +#///////////////////////////////////////////////////////////////////// + +set(PACKAGE_TEST_FILES +# common/tempdir.hpp +# common/tempdir.cpp + package/main.cpp +) + +add_executable( package_test ${PACKAGE_TEST_FILES} ) +target_link_libraries( package_test package_manager graphene_app graphene_account_history graphene_net graphene_chain graphene_time graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) + + + # #file(GLOB PERFORMANCE_TESTS "performance/*.cpp") #add_executable( performance_test ${PERFORMANCE_TESTS} ${COMMON_SOURCES} ) @@ -39,10 +62,6 @@ endif(MSVC) #add_executable( chain_bench ${BENCH_MARKS} ${COMMON_SOURCES} ) #target_link_libraries( chain_bench graphene_chain graphene_app graphene_account_history graphene_time graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) # -#file(GLOB APP_SOURCES "app/*.cpp") -#add_executable( app_test ${APP_SOURCES} ) -#target_link_libraries( app_test graphene_app graphene_account_history graphene_net graphene_chain graphene_time graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) -# #file(GLOB INTENSE_SOURCES "intense/*.cpp") #add_executable( intense_test ${INTENSE_SOURCES} ${COMMON_SOURCES} ) #target_link_libraries( intense_test graphene_chain graphene_app graphene_account_history graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) diff --git a/tests/app/main.cpp b/tests/app/main.cpp index a2b4632f..f226ae72 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -28,7 +28,7 @@ #include -#include +#include "../common/tempdir.hpp" #include diff --git a/tests/package/main.cpp b/tests/package/main.cpp new file mode 100644 index 00000000..c4c6ff94 --- /dev/null +++ b/tests/package/main.cpp @@ -0,0 +1,239 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include +#include + + +#include + +using namespace decent::package; + +uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; + + +std::ostream& operator<< (std::ostream& os, const PackageInfo::DataState state) { + switch (state) { + case PackageInfo::DS_UNINITIALIZED: os << "UNINITIALIZED"; break; + case PackageInfo::INVALID: os << "INVALID"; break; + case PackageInfo::PARTIAL: os << "PARTIAL"; break; + case PackageInfo::UNCHECKED: os << "UNCHECKED"; break; + case PackageInfo::CHECKED: os << "CHECKED"; break; + default: os << "???"; break; + } + return os; +} + +std::ostream& operator<< (std::ostream& os, const PackageInfo::TransferState state) { + switch (state) { + case PackageInfo::TS_IDLE: os << "IDLE"; break; + case PackageInfo::DOWNLOADING: os << "DOWNLOADING"; break; + case PackageInfo::SEEDING: os << "SEEDING"; break; + default: os << "???"; break; + } + return os; +} + +std::ostream& operator<< (std::ostream& os, const PackageInfo::ManipulationState state) { + switch (state) { + case PackageInfo::MS_IDLE: os << "IDLE"; break; + case PackageInfo::PACKING: os << "PACKING"; break; + case PackageInfo::ENCRYPTING: os << "ENCRYPTING"; break; + case PackageInfo::STAGING: os << "STAGING"; break; + case PackageInfo::CHECKING: os << "CHECKING"; break; + case PackageInfo::DECRYPTING: os << "DECRYPTING"; break; + case PackageInfo::UNPACKING: os << "UNPACKING"; break; + case PackageInfo::DELETTING: os << "DELETTING"; break; + default: os << "???"; break; + } + return os; +} + + +class MyEventListener : public EventListenerInterface { +public: + + virtual void package_data_state_change(PackageInfo::DataState new_state) { std::clog << "Data state changed: " << new_state << std::endl; } + virtual void package_transfer_state_change(PackageInfo::TransferState new_state) { std::clog << "Transfer state changed: " << new_state << std::endl; } + virtual void package_manipulation_state_change(PackageInfo::ManipulationState new_state) { std::clog << "Manipulation state changed: " << new_state << std::endl; } + + virtual void package_creation_start() { std::clog << "Package creation started" << std::endl; } + virtual void package_creation_progress() { std::clog << "Package creation progress" << std::endl; } + virtual void package_creation_error(const std::string& error) { std::clog << "Package creation error: " << error << std::endl; } + virtual void package_creation_complete() { std::clog << "Package creation complete" << std::endl; } + + virtual void package_restoration_start() { std::clog << "Package restoration started" << std::endl; } + virtual void package_restoration_progress() { std::clog << "Package restoration progress" << std::endl; } + virtual void package_restoration_error(const std::string& error) { std::clog << "Package restoration error: " << error << std::endl; } + virtual void package_restoration_complete() { std::clog << "Package restoration complete" << std::endl; } + + virtual void package_extraction_start() { std::clog << "Package extraction started" << std::endl; } + virtual void package_extraction_progress() { std::clog << "Package extraction progress" << std::endl; } + virtual void package_extraction_error(const std::string& error) { std::clog << "Package extraction error: " << error << std::endl; } + virtual void package_extraction_complete() { std::clog << "Package extraction complete" << std::endl; } + + virtual void package_check_start() { std::clog << "Package check started" << std::endl; } + virtual void package_check_progress() { std::clog << "Package check progress" << std::endl; } + virtual void package_check_error(const std::string& error) { std::clog << "Package check error: " << error << std::endl; } + virtual void package_check_complete() { std::clog << "Package check complete" << std::endl; } + + virtual void package_seed_start() {} + virtual void package_seed_progress() {} + virtual void package_seed_error(const std::string& error) { std::clog << "Package seed error: " << error << std::endl; } + virtual void package_seed_complete() {} + + virtual void package_download_start() {} + virtual void package_download_progress() {} + virtual void package_download_error(const std::string&) {} + virtual void package_download_complete() {} +}; + +/////////////////////////////////////////////////////////////////////////////////////// + +void create_fake_content(boost::filesystem::path& content_path, boost::filesystem::path& samples_path) +{ + fc::path temp_dir = fc::temp_directory_path() / "decent_fake_content"; + + + + +} + +void delete_fake_content(const std::string& dir_folder) +{ + + + +} + +/////////////////////////////////////////////////////////////////////////////////////// + +boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { + + std::srand(time(NULL)); + std::cout << "Random number generator seeded to " << time(NULL) << std::endl; + const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); + if( genesis_timestamp_str != nullptr ) + { + GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); + } + std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; + return nullptr; +} + +BOOST_AUTO_TEST_CASE( package_create_test ) +{ + + auto& package_manager = decent::package::PackageManager::instance(); + + package_manager.recover_all_packages(); + + const fc::sha256 key = fc::sha256::hash(std::string("some_string_to_use_as_a_key")); + const bool block = false; + + boost::filesystem::path content_dir; // = "/tmp/test/test1_content"; + boost::filesystem::path samples_dir; // = "/tmp/test/test1_samples"; + + //create some fake content... + create_fake_content(content_dir, samples_dir); + + + try { + auto package_handle = package_manager.get_package(content_dir, samples_dir, key, DECENT_SECTORS); + BOOST_CHECK(package_handle.get() != nullptr); + + package_handle->add_event_listener(std::make_shared()); + + { + package_handle->create(block); + package_handle->wait_for_current_task(); + BOOST_CHECK(package_handle->get_task_last_error() == nullptr); + } + + std::cerr << "starting seeding" << std::endl; + package_handle->start_seeding("ipfs"); + package_handle->wait_for_current_task(); + BOOST_CHECK(package_handle->get_task_last_error() == nullptr); + +// std::cerr << "started seeding" << std::endl; +// std::cerr << "Package url:" << package_handle->get_url() << std::endl; + + // It is assumed that the package is now available for download from elsewhere. + std::this_thread::sleep_for(std::chrono::seconds(10)); + + { + package_handle->stop_seeding(); + package_handle->wait_for_current_task(); + BOOST_CHECK(package_handle->get_task_last_error() == nullptr); + + } + + const boost::filesystem::path package_dir = package_handle->get_package_dir(); + const std::string url = package_handle->get_url(); + + package_manager.release_package(package_handle); + + + } FC_LOG_AND_RETHROW() + + package_manager.release_all_packages(); + +} + +BOOST_AUTO_TEST_CASE( package_download_and_unpack_test ) +{ + const bool block = false; + const boost::filesystem::path dest_dir = "/tmp/test/test1_unpacked"; + const fc::sha256 key = fc::sha256::hash(std::string("some_string_to_use_as_a_key")); + + + auto& package_manager = decent::package::PackageManager::instance(); + + try { + auto package_handle = package_manager.get_package("/ipfs/QmWgZbg73wrgicmPradJcK51nY99o2fX8dt7pBJ8rUaurJ", fc::ripemd160()); + package_handle->add_event_listener(std::make_shared()); + + { + package_handle->download(); + package_handle->wait_for_current_task(); + BOOST_CHECK(package_handle->get_task_last_error() == nullptr); + } + + { + package_handle->check(block); + package_handle->wait_for_current_task(); + BOOST_CHECK(package_handle->get_task_last_error() == nullptr); + } + + { + package_handle->unpack(dest_dir, key, block); + package_handle->wait_for_current_task(); + BOOST_CHECK(package_handle->get_task_last_error() == nullptr); + } + + } FC_LOG_AND_RETHROW() + + package_manager.release_all_packages(); +} From 8b74606cff83409fe052624663ff1a2e5a11c49f Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Mon, 13 Nov 2017 13:41:19 +0100 Subject: [PATCH 005/136] updated package test --- tests/package/main.cpp | 56 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/tests/package/main.cpp b/tests/package/main.cpp index c4c6ff94..68d30b82 100644 --- a/tests/package/main.cpp +++ b/tests/package/main.cpp @@ -116,19 +116,44 @@ void create_fake_content(boost::filesystem::path& content_path, boost::filesyste { fc::path temp_dir = fc::temp_directory_path() / "decent_fake_content"; + boost::filesystem::create_directories(boost::filesystem::path(temp_dir.string()) ); + content_path = temp_dir / "content"; + samples_path = temp_dir / "samples"; + boost::filesystem::create_directories(content_path); + boost::filesystem::create_directories(samples_path); + boost::filesystem::ofstream content_file(content_path / "fake_content.txt" ); + content_file << "Heloo world of DECENT."; + content_file.close(); + + boost::filesystem::ofstream sample_file(samples_path / "fake_sample.txt" ); + sample_file << "Sample file..."; + sample_file.close(); } -void delete_fake_content(const std::string& dir_folder) +bool check_fake_content(const boost::filesystem::path& base_dir) { + boost::filesystem::path filename = base_dir / "fake_content.txt"; + return boost::filesystem::exists(filename); +} +void create_unpack_folder(boost::filesystem::path& content_path) +{ + fc::path temp_dir = fc::temp_directory_path() / "decent_fake_content"; + boost::filesystem::create_directories(boost::filesystem::path(temp_dir.string()) ); + content_path = temp_dir / "unpack"; + boost::filesystem::create_directories(content_path); } /////////////////////////////////////////////////////////////////////////////////////// +// run IPFS daemon before this test... + +std::string g_test_packagename; +std::string g_test_string_as_key = "some_string_to_use_as_a_key"; boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { @@ -150,7 +175,7 @@ BOOST_AUTO_TEST_CASE( package_create_test ) package_manager.recover_all_packages(); - const fc::sha256 key = fc::sha256::hash(std::string("some_string_to_use_as_a_key")); + const fc::sha256 key = fc::sha256::hash(g_test_string_as_key); const bool block = false; boost::filesystem::path content_dir; // = "/tmp/test/test1_content"; @@ -184,17 +209,21 @@ BOOST_AUTO_TEST_CASE( package_create_test ) std::this_thread::sleep_for(std::chrono::seconds(10)); { - package_handle->stop_seeding(); + package_handle->stop_seeding("ipfs"); package_handle->wait_for_current_task(); BOOST_CHECK(package_handle->get_task_last_error() == nullptr); } const boost::filesystem::path package_dir = package_handle->get_package_dir(); - const std::string url = package_handle->get_url(); + + g_test_packagename = package_handle->get_url(); package_manager.release_package(package_handle); + boost::filesystem::remove_all(content_dir); + boost::filesystem::remove_all(samples_dir); + } FC_LOG_AND_RETHROW() @@ -205,14 +234,22 @@ BOOST_AUTO_TEST_CASE( package_create_test ) BOOST_AUTO_TEST_CASE( package_download_and_unpack_test ) { const bool block = false; - const boost::filesystem::path dest_dir = "/tmp/test/test1_unpacked"; - const fc::sha256 key = fc::sha256::hash(std::string("some_string_to_use_as_a_key")); + if (g_test_packagename.empty()) { + return; + } + + boost::filesystem::path dest_dir; + create_unpack_folder(dest_dir); + + const fc::sha256 key = fc::sha256::hash(g_test_string_as_key); auto& package_manager = decent::package::PackageManager::instance(); try { - auto package_handle = package_manager.get_package("/ipfs/QmWgZbg73wrgicmPradJcK51nY99o2fX8dt7pBJ8rUaurJ", fc::ripemd160()); + // "/ipfs/QmWgZbg73wrgicmPradJcK51nY99o2fX8dt7pBJ8rUaurJ" + auto package_handle = package_manager.get_package(g_test_packagename, fc::ripemd160()); + BOOST_CHECK(package_handle.get() != nullptr); package_handle->add_event_listener(std::make_shared()); { @@ -233,6 +270,11 @@ BOOST_AUTO_TEST_CASE( package_download_and_unpack_test ) BOOST_CHECK(package_handle->get_task_last_error() == nullptr); } + //check if file exists... + BOOST_CHECK(check_fake_content(dest_dir)); + + boost::filesystem::remove_all(dest_dir); + } FC_LOG_AND_RETHROW() package_manager.release_all_packages(); From c9445dbdb7fe8c2068657986b0f40f07fbb1c6a3 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Mon, 13 Nov 2017 16:27:06 +0100 Subject: [PATCH 006/136] added package remove test --- tests/package/main.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/package/main.cpp b/tests/package/main.cpp index 68d30b82..50e11555 100644 --- a/tests/package/main.cpp +++ b/tests/package/main.cpp @@ -209,7 +209,7 @@ BOOST_AUTO_TEST_CASE( package_create_test ) std::this_thread::sleep_for(std::chrono::seconds(10)); { - package_handle->stop_seeding("ipfs"); + package_handle->stop_seeding(); package_handle->wait_for_current_task(); BOOST_CHECK(package_handle->get_task_last_error() == nullptr); @@ -279,3 +279,40 @@ BOOST_AUTO_TEST_CASE( package_download_and_unpack_test ) package_manager.release_all_packages(); } + +BOOST_AUTO_TEST_CASE( package_remove_test ) +{ + + if (g_test_packagename.empty()) { + return; + } + + auto& package_manager = decent::package::PackageManager::instance(); + + try { + + { + auto package_handle = package_manager.get_package(g_test_packagename, fc::ripemd160()); + BOOST_CHECK(package_handle.get() != nullptr); + package_handle->add_event_listener(std::make_shared()); + + package_handle->stop_seeding(); + package_handle->wait_for_current_task(); + BOOST_CHECK(package_handle->get_task_last_error() == nullptr); + + + package_handle->remove(true); + package_handle->wait_for_current_task(); + BOOST_CHECK(package_handle->get_task_last_error() == nullptr); + + BOOST_CHECK(package_manager.release_package(package_handle)); + + //now the package should be gone.. but IPFS. + } + + + + } FC_LOG_AND_RETHROW() + + package_manager.release_all_packages(); +} From a7d5a41f54c257dafe9d1650a2cdeca9f2fe5019 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 14 Nov 2017 10:32:25 +0100 Subject: [PATCH 007/136] package test update - cleanup --- tests/package/main.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/tests/package/main.cpp b/tests/package/main.cpp index 50e11555..1a3f2f14 100644 --- a/tests/package/main.cpp +++ b/tests/package/main.cpp @@ -178,13 +178,12 @@ BOOST_AUTO_TEST_CASE( package_create_test ) const fc::sha256 key = fc::sha256::hash(g_test_string_as_key); const bool block = false; - boost::filesystem::path content_dir; // = "/tmp/test/test1_content"; - boost::filesystem::path samples_dir; // = "/tmp/test/test1_samples"; + boost::filesystem::path content_dir; + boost::filesystem::path samples_dir; //create some fake content... create_fake_content(content_dir, samples_dir); - try { auto package_handle = package_manager.get_package(content_dir, samples_dir, key, DECENT_SECTORS); BOOST_CHECK(package_handle.get() != nullptr); @@ -202,19 +201,9 @@ BOOST_AUTO_TEST_CASE( package_create_test ) package_handle->wait_for_current_task(); BOOST_CHECK(package_handle->get_task_last_error() == nullptr); -// std::cerr << "started seeding" << std::endl; -// std::cerr << "Package url:" << package_handle->get_url() << std::endl; - // It is assumed that the package is now available for download from elsewhere. std::this_thread::sleep_for(std::chrono::seconds(10)); - { - package_handle->stop_seeding(); - package_handle->wait_for_current_task(); - BOOST_CHECK(package_handle->get_task_last_error() == nullptr); - - } - const boost::filesystem::path package_dir = package_handle->get_package_dir(); g_test_packagename = package_handle->get_url(); @@ -311,7 +300,6 @@ BOOST_AUTO_TEST_CASE( package_remove_test ) } - } FC_LOG_AND_RETHROW() package_manager.release_all_packages(); From 05f4ce05e804754ab8d2c0a9bff88fa0d00c59be Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 14 Nov 2017 11:11:54 +0100 Subject: [PATCH 008/136] updated gitmodule --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index feac185a..9224cc3d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,6 +14,6 @@ [submodule "libraries/contrib/pbc"] path = libraries/contrib/pbc url = https://github.com/DECENTfoundation/pbc -[submodule "update"] +[submodule "libraries/update"] path = libraries/update url = https://github.com/DECENTfoundation/updatemanager.git From 41dcf88f28a9d163b311d0e61c1268d6ee5d0e45 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 14 Nov 2017 11:53:26 +0100 Subject: [PATCH 009/136] removed update submodule --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 9224cc3d..ae47e5bf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,6 +14,3 @@ [submodule "libraries/contrib/pbc"] path = libraries/contrib/pbc url = https://github.com/DECENTfoundation/pbc -[submodule "libraries/update"] - path = libraries/update - url = https://github.com/DECENTfoundation/updatemanager.git From 58716e0d2d1b2ba1a3845f418b2f3f5981a16915 Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Mon, 20 Nov 2017 14:15:22 +0100 Subject: [PATCH 010/136] Fixed test change_block_interval --- programs/decentd/main.cpp | 2 +- tests/common/database_fixture.cpp | 17 +++++++- tests/common/database_fixture.hpp | 2 +- tests/tests/block_tests.cpp | 72 ++++++++++++++++++++++--------- 4 files changed, 70 insertions(+), 23 deletions(-) diff --git a/programs/decentd/main.cpp b/programs/decentd/main.cpp index edcfc814..28ca9292 100644 --- a/programs/decentd/main.cpp +++ b/programs/decentd/main.cpp @@ -309,7 +309,7 @@ void write_default_logging_config_to_stream(std::ostream& out) "# route any messages logged to the default logger to the \"stderr\" logger we\n" "# declared above, if they are info level are higher\n" "[logger.default]\n" - "level=info\n" + "level=error\n" "appenders=stderr\n\n" "# route messages sent to the \"p2p\" logger to the p2p appender declared above\n" "[logger.p2p]\n" diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index aafd3aa8..4af602bb 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -88,7 +88,6 @@ database_fixture::database_fixture() } genesis_state.initial_parameters.current_fees->zero_all_fees(); open_database(); - // app.initialize(); ahplugin->plugin_set_app(&app); ahplugin->plugin_initialize(options); @@ -482,6 +481,22 @@ const account_object& database_fixture::get_account( const string& name )const return *itr; } +const miner_object& database_fixture::get_miner(account_id_type id)const +{ + //const auto& idx = db.get_index_type().indices().get(); + //const auto itr = idx.find(name); + //assert(itr != idx.end()); + //return *itr; + const auto& all_miners = db.get_index_type().indices(); + for (const miner_object& wit : all_miners) + { + if (id == wit.miner_account) + return wit; + } + assert(0);// not found + return miner_object(); +} + void database_fixture::sign(signed_transaction& trx, const fc::ecc::private_key& key) { trx.sign( key, db.get_chain_id() ); diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 88feaaeb..84d9b2fe 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -228,6 +228,7 @@ struct database_fixture { const asset_object& get_asset( const string& symbol )const; const account_object& get_account( const string& name )const; + const miner_object& get_miner(account_id_type id)const; void enable_fees(); @@ -243,7 +244,6 @@ struct database_fixture { - // the reason we use an app is to exercise the indexes of built-in // plugins graphene::app::application app; diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 599b80d4..7628b27b 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -43,6 +43,8 @@ using namespace graphene::chain; using namespace graphene::chain::test; + + genesis_state_type make_genesis() { genesis_state_type genesis_state; @@ -53,6 +55,7 @@ genesis_state_type make_genesis() { for( int i = 0; i < genesis_state.initial_active_miners; ++i ) { auto name = "init"+fc::to_string(i); + genesis_state.initial_accounts.emplace_back(name, init_account_priv_key.get_public_key(), init_account_priv_key.get_public_key()); @@ -801,7 +804,7 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture ) } FC_LOG_AND_RETHROW() } -#if 0 //update_proposal need votes from miners.. + BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) { try { generate_block(); @@ -810,67 +813,96 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) p.parameters.miner_proposal_review_period = fc::hours(1).to_seconds(); }); + const uint8_t new_block_interval = 1; + fc::time_point_sec maintenence_time2; + BOOST_TEST_MESSAGE( "Creating a proposal to change the block_interval to 1 second" ); { + const account_object& nathan = create_account("nathan"); + time_point_sec now0 = db.head_block_time(); + + transfer(account_id_type()(db), nathan, asset(5000000)); + + account_update_operation op; + op.account = nathan.id; + op.new_options = nathan.options; + auto init0_miner_member = get_miner(get_account("init0").get_id()); + + op.new_options->votes.insert(init0_miner_member.vote_id); + trx.operations.push_back(op); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + proposal_create_operation cop = proposal_create_operation::miner_proposal(db.get_global_properties().parameters, db.head_block_time()); - cop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT; - cop.expiration_time = db.head_block_time() + *cop.review_period_seconds + 10; + cop.fee_paying_account = get_account("init0").get_id(); + cop.expiration_time = db.head_block_time() + *cop.review_period_seconds + 100; + fc::time_point_sec maintenence_time = db.get_dynamic_global_properties().next_maintenance_time; + miner_update_global_parameters_operation uop; - uop.new_parameters.block_interval = 1; + uop.new_parameters.block_interval = new_block_interval; cop.proposed_ops.emplace_back(uop); + trx.operations.push_back(cop); + + trx.expiration = db.head_block_time() + 100; + sign(trx, init_account_priv_key); + db.push_transaction(trx); } BOOST_TEST_MESSAGE( "Updating proposal by signing with the miner private key" ); { proposal_update_operation uop; - uop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT; + uop.fee_paying_account = get_account("init0").get_id(); uop.fee = asset(); uop.active_approvals_to_add = {get_account("init0").get_id(), get_account("init1").get_id(), get_account("init2").get_id(), get_account("init3").get_id(), get_account("init4").get_id(), get_account("init5").get_id(), get_account("init6").get_id(), get_account("init7").get_id()}; + trx.clear(); trx.operations.push_back(uop); - sign( trx, init_account_priv_key ); - /* - sign( trx, get_account("init1" ).active.get_keys().front(),init_account_priv_key); - sign( trx, get_account("init2" ).active.get_keys().front(),init_account_priv_key); - sign( trx, get_account("init3" ).active.get_keys().front(),init_account_priv_key); - sign( trx, get_account("init4" ).active.get_keys().front(),init_account_priv_key); - sign( trx, get_account("init5" ).active.get_keys().front(),init_account_priv_key); - sign( trx, get_account("init6" ).active.get_keys().front(),init_account_priv_key); - sign( trx, get_account("init7" ).active.get_keys().front(),init_account_priv_key); - */ + + auto& active_miners = db.get_global_properties().active_miners; + + fc::time_point_sec maintenence_time = db.get_dynamic_global_properties().next_maintenance_time; + trx.expiration = db.head_block_time() + 100; + sign(trx, init_account_priv_key); + db.push_transaction(trx); - BOOST_CHECK(proposal_id_type()(db).is_authorized_to_execute(db)); + + generate_blocks(maintenence_time + 5); + + maintenence_time2 = db.get_dynamic_global_properties().next_maintenance_time; } + generate_block(); BOOST_TEST_MESSAGE( "Verifying that the interval didn't change immediately" ); BOOST_CHECK_EQUAL(db.get_global_properties().parameters.block_interval, 5); auto past_time = db.head_block_time().sec_since_epoch(); generate_block(); + auto past_time2 = db.head_block_time().sec_since_epoch(); BOOST_CHECK_EQUAL(db.head_block_time().sec_since_epoch() - past_time, 5); generate_block(); BOOST_CHECK_EQUAL(db.head_block_time().sec_since_epoch() - past_time, 10); - BOOST_TEST_MESSAGE( "Generating blocks until proposal expires" ); - generate_blocks(proposal_id_type()(db).expiration_time + 5); BOOST_TEST_MESSAGE( "Verify that the block interval is still 5 seconds" ); BOOST_CHECK_EQUAL(db.get_global_properties().parameters.block_interval, 5); BOOST_TEST_MESSAGE( "Generating blocks until next maintenance interval" ); - generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + generate_blocks(maintenence_time2); generate_block(); // get the maintenance skip slots out of the way BOOST_TEST_MESSAGE( "Verify that the new block interval is 1 second" ); BOOST_CHECK_EQUAL(db.get_global_properties().parameters.block_interval, 1); past_time = db.head_block_time().sec_since_epoch(); generate_block(); + uint32_t head_time = db.head_block_time().sec_since_epoch(); BOOST_CHECK_EQUAL(db.head_block_time().sec_since_epoch() - past_time, 1); generate_block(); BOOST_CHECK_EQUAL(db.head_block_time().sec_since_epoch() - past_time, 2); } FC_LOG_AND_RETHROW() } -#endif + BOOST_FIXTURE_TEST_CASE( pop_block_twice, database_fixture ) { From 8c595f0c69c4f0bb1a63f745b39cafe59d844bfc Mon Sep 17 00:00:00 2001 From: ejossev Date: Thu, 23 Nov 2017 14:58:32 +0100 Subject: [PATCH 011/136] reworked UIA content buying --- libraries/chain/asset_object.cpp | 15 ++ libraries/chain/db_balance.cpp | 2 +- libraries/chain/decent_evaluator.cpp | 146 ++++++------------ .../include/graphene/chain/asset_object.hpp | 119 ++++++++++++++ .../graphene/chain/decent_evaluator.hpp | 10 +- .../graphene/chain/protocol/asset_ops.hpp | 7 + libraries/chain/protocol/decent.cpp | 9 +- 7 files changed, 201 insertions(+), 107 deletions(-) diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index 0a6fdaac..be1d8d98 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -214,3 +214,18 @@ void graphene::chain::monitored_asset_options::update_median_feeds(time_point_se current_feed = median_feed; } + +//template +//asset asset_object::convert_uia( asset from, const DB& db )const + + +//template +//asset asset_object::convert_mia( asset from, const DB& db ) const + + +//template +//asset asset_object::convert( asset from, const DB& db ) const + + +//template +//bool asset_object::can_convert( asset from, asset& to, const DB& db ) const diff --git a/libraries/chain/db_balance.cpp b/libraries/chain/db_balance.cpp index 4d3a40fa..b856a2ac 100644 --- a/libraries/chain/db_balance.cpp +++ b/libraries/chain/db_balance.cpp @@ -225,7 +225,7 @@ bool database::are_assets_exchangeable( const asset_object& payment, const asset return false; else if( payment.id == price.id ) return true; - else if( !payment.is_monitored_asset() && !price.is_monitored_asset() && + else if( !price.is_monitored_asset() && payment.id != asset_id_type() && price.id != asset_id_type() ) // exchange between two different UIAs is not allowed return false; else if( payment.options.is_exchangeable && price.options.is_exchangeable ) // DCT and MIA assets are always exchangeable diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index e401cba5..a73aff1e 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -145,15 +145,13 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri FC_ASSERT( RegionCodes::s_mapCodeToName.count( element.region ) , "Invalid region code" ); } - FC_ASSERT( o.seeders.size() > 0 ); - FC_ASSERT( o.seeders.size() == o.key_parts.size() ); FC_ASSERT( db().head_block_time() <= o.expiration); fc::microseconds duration = (o.expiration - db().head_block_time() ); uint64_t days = duration.to_seconds() / 3600 / 24; FC_ASSERT( days != 0, "time to expiration has to be at least one day" ); auto& idx = db().get_index_type().indices().get(); - asset total_price_per_day; + const auto& content_idx = db().get_index_type().indices().get(); auto content_itr = content_idx.find( o.URI ); if( content_itr != content_idx.end() ) // is resubmit? @@ -215,6 +213,7 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri FC_ASSERT( days * total_price_per_day <= o.publishing_fee + content_itr->publishing_fee_escrow );*/ } else { + asset total_price_per_day; for ( const auto &p : o.seeders ) //check if seeders exist and accumulate their prices { const auto& itr = idx.find( p ); @@ -400,16 +399,6 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri }FC_CAPTURE_AND_RETHROW((o)) } - bool request_to_buy_evaluator::is_price_sufficient( const asset& payment, const asset& price ) - { - database& d = db(); - - asset payment_in_dct = d.price_to_dct( payment ); - asset price_in_dct = d.price_to_dct( price ); - - return payment_in_dct >= price_in_dct; - } - void_result request_to_buy_evaluator::do_evaluate(const request_to_buy_operation& o ) {try{ database& d = db(); @@ -420,82 +409,47 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri FC_ASSERT( o.price <= d.get_balance( o.consumer, o.price.asset_id ) ); FC_ASSERT( content->expiration > db().head_block_time() ); - optional price = content->price.GetPrice(o.region_code_from); + optional content_price_got = content->price.GetPrice(o.region_code_from); - FC_ASSERT( price.valid(), "content is not available for this region" ); + FC_ASSERT( content_price_got.valid(), "content is not available for this region" ); + content_price = *content_price_got; FC_ASSERT( !content->is_blocked , "content has been canceled" ); - { - auto &range = d.get_index_type().indices().get(); - const auto &subscription = range.find(boost::make_tuple(o.consumer, content->author)); - /// Check whether subscription exists. If so, consumer doesn't need pay for content - if (subscription != range.end() && subscription->expiration > d.head_block_time() ) - is_subscriber = true; - } + auto &range = d.get_index_type().indices().get(); + const auto &subscription = range.find(boost::make_tuple(o.consumer, content->author)); - payment_o = d.get( o.price.asset_id ); - price_o = d.get( price->asset_id ); - FC_ASSERT( d.are_assets_exchangeable( payment_o, price_o ), "price for the content and price of the content are not exchangeable"); + /// Check whether subscription exists. If so, consumer doesn't need pay for content + if (subscription != range.end() && subscription->expiration > d.head_block_time() ) + is_subscriber = true; + return void_result(); - skip_exchange = (o.price.asset_id == price->asset_id) || ( o.price.asset_id == asset_id_type() && price_o.is_monitored_asset() ); + FC_ASSERT( d.are_assets_exchangeable( o.price.asset_id(d), content_price.asset_id(d) ), "price for the content and price of the content are not exchangeable"); - if( !is_subscriber ) - { - FC_ASSERT( is_price_sufficient( o.price, *price ) ); + /* + * Case 1: paid in some asset, price in the same asset + * Case 2: paid in DCT, price in MIA + * Case 3: paid in DCT, price in UIA + * Case 4: paid in UIA, price in DCT + * Case 5: paid in UIA, price in MIA + */ - if( !skip_exchange ) - { - if( o.price.asset_id == asset_id_type() ) // payment in DCT's, price in UIA's - { - asset payment_in_uia = o.price * price_o.options.core_exchange_rate; - const asset_dynamic_data_object& addo = price_o.dynamic_data(d); - FC_ASSERT( payment_in_uia.amount <= addo.asset_pool , "Asset ${uia} does not have enough balance in asset_pool",("uia",price_o.symbol)); - } - else // payment in UIA's, price in DCT's or in MIA's - { - asset payment_in_dct = o.price * payment_o.options.core_exchange_rate; - const asset_dynamic_data_object& addo = payment_o.dynamic_data(d); - FC_ASSERT( payment_in_dct.amount <= addo.core_pool , "Asset ${uia} does not have enough balance in core_pool",("uia",payment_o.symbol)); - } - } + paid_price = o.price; + + if( content_price.asset_id == o.price.asset_id ){ // no need to convert + paid_price_after_conversion = paid_price; + FC_ASSERT(paid_price_after_conversion >= content_price ); + return void_result(); } + asset paid_price_in_dct; + FC_ASSERT( paid_price.asset_id(d).can_convert(paid_price, paid_price_in_dct, d) && paid_price_in_dct.asset_id == asset_id_type() ); + FC_ASSERT( content_price.asset_id(d).can_convert(paid_price_in_dct, paid_price_after_conversion, d) && paid_price_after_conversion.asset_id == content_price.asset_id ); + FC_ASSERT( paid_price_after_conversion >= content_price ); + return void_result(); }FC_CAPTURE_AND_RETHROW( (o) ) } - void request_to_buy_evaluator::process_payment_and_exchange( const account_id_type& payer, const asset& payment, const asset& price ) - { - if( is_subscriber ) - return; - - database& d = db(); - - if( !skip_exchange ) - { - if( payment.asset_id == asset_id_type() ) //payment in DCT's, price in UIA's - { - asset_object ao_price = price.asset_id(d); - asset_dynamic_data_object addo = ao_price.dynamic_data(d); - d.modify( addo, [&payment, &ao_price]( asset_dynamic_data_object& _addo ){ - _addo.core_pool += payment.amount; - _addo.asset_pool -= (payment * ao_price.options.core_exchange_rate).amount; - }); - } - else // payment in UIA's, price in DCT's or in MIA's - { - asset_object ao_payment = payment.asset_id(d); - asset_dynamic_data_object addo = ao_payment.dynamic_data(d); - d.modify( addo, [&payment, &ao_payment]( asset_dynamic_data_object& _addo ){ - _addo.asset_pool += payment.amount; - _addo.core_pool -= (payment * ao_payment.options.core_exchange_rate).amount; - }); - } - } - - d.adjust_balance( payer, -payment ); - } - void_result request_to_buy_evaluator::do_apply(const request_to_buy_operation& o ) {try{ database& d = db(); @@ -503,23 +457,23 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri const auto& idx = d.get_index_type().indices().get(); const auto& content = idx.find( o.URI ); - asset payment_before_exchange = o.price; - asset payment_after_exchange = o.price; - - // calculates payment_after_exchange. If exchange is not needed ( payment and price are in the same asset ), - // payment_before_exchange == payment_after_exchange - if( !skip_exchange ) + if( is_subscriber ) //if it is subscription, price is ignored { - if( payment_before_exchange.asset_id == asset_id_type() ) // payment in DCT's, price in UIA's - payment_after_exchange = payment_after_exchange * price_o.options.core_exchange_rate; - else // payment in UIA's, price in DCT's or in MIA's - payment_after_exchange = payment_after_exchange * payment_o.options.core_exchange_rate; + paid_price = asset( 0 ); + paid_price_after_conversion = asset( 0 ); } - if( is_subscriber ) //if it is subscription, price is ignored - { - payment_before_exchange = asset( 0, payment_before_exchange.asset_id ); - payment_after_exchange = asset( 0, payment_after_exchange.asset_id ); + if( content->key_parts.size() == 0 ){ //simplified content buying - TODO + + + return void_result(); + } + + if( content_price.asset_id == o.price.asset_id ){ // no need to convert + paid_price_after_conversion = paid_price; + }else { + asset paid_price_in_dct = paid_price.asset_id(d).convert(paid_price, d); + paid_price_after_conversion = content_price.asset_id(d).convert(paid_price_in_dct, d); } const auto& object = db().create([&](buying_object& bo) @@ -529,9 +483,9 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri bo.expiration_time = d.head_block_time() + 24*3600; bo.pubKey = o.pubKey; - bo.price = payment_after_exchange; // escrow, will be reset to zero - bo.paid_price_before_exchange = payment_before_exchange; - bo.paid_price_after_exchange = payment_after_exchange; + bo.price = paid_price_after_conversion; // escrow, will be reset to zero + bo.paid_price_before_exchange = paid_price; + bo.paid_price_after_exchange = paid_price_after_conversion; bo.synopsis = content->synopsis; bo.size = content->size; @@ -539,8 +493,6 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri bo.region_code_from = o.region_code_from; }); - process_payment_and_exchange( o.consumer, payment_before_exchange, *(content->price.GetPrice(o.region_code_from)) ); - const auto& idx2 = d.get_index_type().indices().get(); for( auto& element : content->key_parts ) { @@ -550,7 +502,7 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri }); } - db().create([&o, &d, &payment_before_exchange](transaction_detail_object& obj) + db().create([&](transaction_detail_object& obj) { obj.m_operation_type = (uint8_t)transaction_detail_object::content_buy; @@ -564,7 +516,7 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri } obj.m_to_account = o.consumer; - obj.m_transaction_amount = payment_before_exchange; + obj.m_transaction_amount = paid_price; obj.m_transaction_fee = o.fee; obj.m_timestamp = d.head_block_time(); }); diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index b4b9370f..2fb217bc 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -118,6 +118,125 @@ namespace graphene { namespace chain { void validate()const {} + /* + * converts asset of ID type to core asset or vice versa. Pools are adjusted accordingly. + * + * + */ + template + asset convert( asset from, DB& db )const{ + const auto& ao = db.template get(id); + + if( id == asset_id_type() ) + { + FC_ASSERT(from.asset_id == asset_id_type(), "Convert can't be called on DCT"); + return from; + } + + if( ao.is_monitored_asset() ) + return convert_mia(from, db); + return convert_uia(from, db); + }; + + template + asset convert_uia( asset from, DB& db ) const{ + asset to; + const auto& add = db.template get(dynamic_asset_data_id); + const auto& ao = db.template get(id); + FC_ASSERT(ao.options.is_exchangeable && !ao.options.core_exchange_rate.is_null()); + + asset core_pool_diff; + asset asset_pool_diff; + price rate = ao.options.core_exchange_rate; + + + if( from.asset_id == id ){ + to.asset_id = asset_id_type(); + to = from * rate; + + core_pool_diff = -to; + asset_pool_diff = from; + + }else{ + FC_ASSERT(from.asset_id == asset_id_type(), "Unsupported conversion"); + + to.asset_id = id; + to = from * rate; + + core_pool_diff = -from; + asset_pool_diff = to; + } + + FC_ASSERT( add.asset_pool + asset_pool_diff.amount >= share_type(0), "Insufficient funds in asset pool to perform conversion" ); + FC_ASSERT( add.core_pool + core_pool_diff.amount >= share_type(0), "Insufficient funds in core pool to perform conversion" ); + + db.template modify(add,[&](asset_dynamic_data_object& ado){ + ado.asset_pool +=asset_pool_diff.amount; + ado.core_pool +=core_pool_diff.amount; + }); + return to; + }; + + template + asset convert_mia( asset from, DB& db ) const{ + const auto& ao = db.template get(id); + FC_ASSERT( ao.is_monitored_asset() && ao.monitored_asset_opts->feed_is_valid(db.head_block_time()) ); + FC_ASSERT( from.asset_id == asset_id_type() || from.asset_id == id ); + + return from * ao.monitored_asset_opts->current_feed.core_exchange_rate; + }; + + template + bool can_convert( asset from, asset& to, const DB& db ) const{ + const auto& add = db.template get(dynamic_asset_data_id); + const auto& ao = db.template get(id); + + if( id == asset_id_type() ) { + if( from.asset_id == asset_id_type()) { + to = from; + return true; + } + return false; + } + + if(!ao.options.is_exchangeable || ao.options.core_exchange_rate.is_null()) + return false; + + if( ao.is_monitored_asset() ){ + if( ao.monitored_asset_opts->feed_is_valid(db.head_block_time()) && ( from.asset_id == asset_id_type() || from.asset_id == id )){ + to = from * ao.monitored_asset_opts->current_feed.core_exchange_rate; + return true; + } + return false; + } + + asset core_pool_diff; + asset asset_pool_diff; + price rate = ao.options.core_exchange_rate; + if( from.asset_id == id ){ + to.asset_id = asset_id_type(); + to = from * rate; + + core_pool_diff = -to; + asset_pool_diff = from; + }else{ + if ( from.asset_id != asset_id_type() ) //unknown conversion + return false; + to.asset_id = id; + to = from * rate; + + core_pool_diff = -from; + asset_pool_diff = to; + } + + if ( add.asset_pool + asset_pool_diff.amount < share_type(0) || add.core_pool + core_pool_diff.amount < share_type(0) ) { + return false; + } + + return true; + + }; + template const asset_dynamic_data_object& dynamic_data(const DB& db)const { return db.get(dynamic_asset_data_id); } diff --git a/libraries/chain/include/graphene/chain/decent_evaluator.hpp b/libraries/chain/include/graphene/chain/decent_evaluator.hpp index e0435e79..c9448b18 100644 --- a/libraries/chain/include/graphene/chain/decent_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/decent_evaluator.hpp @@ -57,12 +57,10 @@ namespace graphene { namespace chain { private: bool is_subscriber = false; bool skip_exchange = false; - asset_object payment_o; - asset_object price_o; - // Checks whether payment is greater or equal to price of a content - bool is_price_sufficient( const asset& payment, const asset& price ); - // Takes care of payment and exchange between assets if needed - void process_payment_and_exchange( const account_id_type& payer, const asset& payment, const asset& price ); + asset paid_price; + asset paid_price_after_conversion; + asset content_price; + }; class leave_rating_evaluator : public evaluator diff --git a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp index ef78133f..e7751cce 100644 --- a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp +++ b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp @@ -78,6 +78,13 @@ namespace graphene { namespace chain { bool feed_is_expired(time_point_sec current_time)const { return feed_expiration_time() <= current_time; } void update_median_feeds(time_point_sec current_time); + bool feed_is_valid(time_point_sec current_time) const{ + if(feed_is_expired(current_time)) + return false; + if(current_feed.core_exchange_rate.is_null()) + return false; + return true; + } void validate()const; }; diff --git a/libraries/chain/protocol/decent.cpp b/libraries/chain/protocol/decent.cpp index 01356f48..d19242af 100644 --- a/libraries/chain/protocol/decent.cpp +++ b/libraries/chain/protocol/decent.cpp @@ -36,10 +36,13 @@ void content_submit_operation::validate()const } FC_ASSERT( size > 0 && size <= DECENT_MAX_FILE_SIZE, "max file size limit exceeded" ); - FC_ASSERT( seeders.size() > 0 ); FC_ASSERT( seeders.size() == key_parts.size() ); - FC_ASSERT( quorum >= 2 && quorum < UINT32_MAX, "At least two seeders are needed to reconstruct the key"); - FC_ASSERT( seeders.size() >= quorum ); + if(seeders.size() == 0){ //simplified content + FC_ASSERT(quorum == 0); + }else { + FC_ASSERT(quorum >= 2 && quorum < UINT32_MAX, "At least two seeders are needed to reconstruct the key"); + FC_ASSERT(seeders.size() >= quorum); + } FC_ASSERT( expiration <= fc::time_point_sec::maximum() ); FC_ASSERT( publishing_fee.amount >= 0); fc::url _url( URI ); From 6331fa5e270f2c3334c89586dfc8e9828a3ee768 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Fri, 24 Nov 2017 11:19:36 +0100 Subject: [PATCH 012/136] API documentation update --- libraries/app/include/graphene/app/api.hpp | 106 +- .../app/include/graphene/app/database_api.hpp | 586 +++---- .../graphene/chain/protocol/account.hpp | 2 +- .../wallet/include/graphene/wallet/wallet.hpp | 1383 ++++++++--------- 4 files changed, 1034 insertions(+), 1043 deletions(-) diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index d9751be3..9deae58c 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -86,12 +86,12 @@ namespace graphene { namespace app { history_api(application& app):_app(app){} /** - * @brief Get operations relevant to the specificed account - * @param account The account whose history should be queried + * @brief Get operations relevant to the specificed account. + * @param account the account whose history should be queried * @param stop ID of the earliest operation to retrieve - * @param limit Maximum number of operations to retrieve (must not exceed 100) + * @param limit maximum number of operations to retrieve (must not exceed 100) * @param start ID of the most recent operation to retrieve - * @return A list of operations performed by account, ordered from most recent to oldest. + * @return a list of operations performed by account, ordered from most recent to oldest * @ingroup HistoryAPI */ vector get_account_history(account_id_type account, @@ -99,16 +99,16 @@ namespace graphene { namespace app { unsigned limit = 100, operation_history_id_type start = operation_history_id_type())const; /** - * @breif Get operations relevant to the specified account referenced + * @brief Get operations relevant to the specified account referenced. * by an event numbering specific to the account. The current number of operations * for the account can be found in the account statistics (or use 0 for start). - * @param account The account whose history should be queried - * @param stop Sequence number of earliest operation. 0 is default and will - * query 'limit' number of operations. - * @param limit Maximum number of operations to retrieve (must not exceed 100) - * @param start Sequence number of the most recent operation to retrieve. - * 0 is default, which will start querying from the most recent operation. - * @return A list of operations performed by account, ordered from most recent to oldest. + * @param account the account whose history should be queried + * @param stop sequence number of earliest operation. 0 is default and will + * query 'limit' number of operations + * @param limit maximum number of operations to retrieve (must not exceed 100) + * @param start sequence number of the most recent operation to retrieve. + * 0 is default, which will start querying from the most recent operation + * @return a list of operations performed by account, ordered from most recent to oldest * @ingroup HistoryAPI */ vector get_relative_account_history( account_id_type account, @@ -139,11 +139,10 @@ namespace graphene { namespace app { typedef std::function confirmation_callback; /** - * @brief Broadcast a transaction to the network - * @param trx The transaction to broadcast - * - * The transaction will be checked for validity in the local database prior to broadcasting. If it fails to - * apply locally, an error will be thrown and the transaction will not be broadcast. + * @brief Broadcast a transaction to the network. + * @param trx the transaction to broadcast + * @note the transaction will be checked for validity in the local database prior to broadcasting. If it fails to + * apply locally, an error will be thrown and the transaction will not be broadcast * @ingroup Network_broadcastAPI */ void broadcast_transaction(const signed_transaction& trx); @@ -151,7 +150,7 @@ namespace graphene { namespace app { /** * * @brief This call will not return until the transaction is included in a block. - * @param trx The transaction to broadcast + * @param trx the transaction to broadcast * @ingroup Network_broadcastAPI */ fc::variant broadcast_transaction_synchronous( const signed_transaction& trx); @@ -160,22 +159,26 @@ namespace graphene { namespace app { * @brief This version of broadcast transaction registers a callback method that will be called when the transaction is * included into a block. The callback method includes the transaction id, block number, and transaction number in the * block. - * @param cb Callback function - * @param trx + * @param cb callback function + * @param trx the transaction to broadcast * @ingroup Network_broadcastAPI */ void broadcast_transaction_with_callback( confirmation_callback cb, const signed_transaction& trx); + /** + * @brief Broadcast a block to the network. + * @param block the signed block to broadcast + * @ingroup Network_broadcastAPI + */ void broadcast_block( const signed_block& block ); /** * @brief Not reflected, thus not accessible to API clients. - * * This function is registered to receive the applied_block * signal from the chain database when a block is received. * It then dispatches callbacks to clients who have requested * to be notified when a particular txid is included in a block. - * @param b The signed block + * @param b the signed block * @ingroup Network_broadcastAPI */ void on_applied_block( const signed_block& b ); @@ -194,54 +197,56 @@ namespace graphene { namespace app { network_node_api(application& a); /** - * @brief Return general network information, such as p2p port + * @brief Returns general network information, such as p2p port. + * @return general network information * @ingroup Network_NodeAPI */ fc::variant_object get_info() const; /** - * @brief add_node Connect to a new peer - * @param ep The IP/Port of the peer to connect to + * @brief Connects to a new peer. + * @param ep the IP/Port of the peer to connect to * @ingroup Network_NodeAPI */ void add_node(const fc::ip::endpoint& ep); /** - * @brief Get status of all current connections to peers + * @brief Get status of all current connections to peers. + * @return status of all connected peers * @ingroup Network_NodeAPI */ std::vector get_connected_peers() const; /** - * @brief Get advanced node parameters, such as desired and max - * number of connections + * @brief Get advanced node parameters, such as desired and max number of connections. + * @return advanced node parameters * @ingroup Network_NodeAPI */ fc::variant_object get_advanced_node_parameters() const; /** - * @brief Set advanced node parameters, such as desired and max - * number of connections + * @brief Set advanced node parameters, such as desired and max number of connections. * @param params a JSON object containing the name/value pairs for the parameters to set * @ingroup Network_NodeAPI */ void set_advanced_node_parameters(const fc::variant_object& params); /** - * @brief Return list of potential peers + * @brief Get a list of potential peers we can connect to. + * @return a list of potential peers * @ingroup Network_NodeAPI */ std::vector get_potential_peers() const; /** - * @brief This method allows user to start seeding plugin from running application - * @param account_id ID of account controlling this seeder + * @brief This method allows user to start seeding plugin from running application. + * @param account_id ID of the account controlling this seeder * @param content_private_key El Gamal content private key - * @param seeder_private_key Private key of the account controlling this seeder - * @param free_space Allocated disk space, in MegaBytes - * @param seeding_price Price per MegaBytes - * @param packages_path Packages storage path - * @param region_code Optional ISO 3166-1 alpha-2 two-letter region code + * @param seeder_private_key private key of the account controlling this seeder + * @param free_space allocated disk space, in MegaBytes + * @param seeding_price price per MegaBytes + * @param packages_path packages storage path + * @param region_code optional ISO 3166-1 alpha-2 two-letter region code * @ingroup Network_NodeAPI */ void seeding_startup(const account_id_type& account_id, @@ -320,49 +325,48 @@ namespace graphene { namespace app { ~login_api(); /** - * @brief Authenticate to the RPC server - * @param user Username to login with - * @param password Password to login with - * @return True if logged in successfully; false otherwise - * + * @brief Authenticate to the RPC server. * @note This must be called prior to requesting other APIs. Other APIs may not be accessible until the client * has sucessfully authenticated. + * @param user username to login with + * @param password password to login with + * @return \c true if logged in successfully, \c false otherwise * @ingroup LoginAPI */ bool login(const string& user, const string& password); /** - * @brief Retrieve the network broadcast API + * @brief Retrieve the network broadcast API. * @ingroup LoginAPI */ fc::api network_broadcast()const; /** - * @brief Retrieve the database API + * @brief Retrieve the database API. * @ingroup LoginAPI */ fc::api database()const; /** - * @brief Retrieve the history API + * @brief Retrieve the history API. * @ingroup LoginAPI */ fc::api history()const; /** - * @brief Retrieve the network node API + * @brief Retrieve the network node API. * @ingroup LoginAPI */ fc::api network_node()const; /** - * @brief Retrieve the cryptography API + * @brief Retrieve the cryptography API. * @ingroup LoginAPI */ fc::api crypto()const; /** - * @brief Retrieve the messaging API + * @brief Retrieve the messaging API. * @ingroup LoginAPI */ fc::api messaging()const; /** - * @brief Retrieve the debug API (if available) + * @brief Retrieve the debug API (if available). * @ingroup LoginAPI */ fc::api debug()const; @@ -370,7 +374,7 @@ namespace graphene { namespace app { private: /** * @brief Called to enable an API, not reflected. - * @param api_name + * @param api_name name of the API we are trying to enable * @ingroup LoginAPI */ void enable_api( const string& api_name ); diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 9d273926..e79d6f36 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -59,6 +59,19 @@ /** * @defgroup DatabaseAPI Database API + * @{ + * @defgroup DatabaseAPI_Subscription Subscription + * @defgroup DatabaseAPI_BlockTx Blocks and Transactions + * @defgroup DatabaseAPI_Globals Globals + * @defgroup DatabaseAPI_Key Key + * @defgroup DatabaseAPI_Account Account + * @defgroup DatabaseAPI_Balance Balance + * @defgroup DatabaseAPI_Asset Asset + * @defgroup DatabaseAPI_Mining Mining + * @defgroup DatabaseAPI_AuthValidation Authority and Validation + * @defgroup DatabaseAPI_Proposals Proposals + * @defgroup DatabaseAPI_Decent Decent + * @} */ namespace graphene { namespace app { @@ -115,7 +128,7 @@ namespace graphene { namespace app { * * This API exposes accessors on the database which query state tracked by a blockchain validating node. This API is * read-only; all modifications to the database must be performed via transactions. Transactions are broadcast via - * the @ref network_broadcast_api. + * the \c network_broadcast_api. */ class database_api { @@ -128,12 +141,11 @@ namespace graphene { namespace app { ///////////// /** - * @brief Get the objects corresponding to the provided IDs + * @brief Get the objects corresponding to the provided IDs. + * @note If any of the provided IDs does not map to an object, a null variant is returned in its position. * @param ids IDs of the objects to retrieve - * @return The objects retrieved, in the order they are mentioned in ids - * @ingroup DatabaseAPI - * - * If any of the provided IDs does not map to an object, a null variant is returned in its position. + * @return the objects retrieved, in the order they are mentioned in ids + * @ingroup DatabaseAPI_Globals */ fc::variants get_objects(const vector& ids)const; @@ -145,37 +157,36 @@ namespace graphene { namespace app { * * @param cb * @param clear_filter - * @ingroup DatabaseAPI + * @ingroup DatabaseAPI_Subscription */ void set_subscribe_callback( std::function cb, bool clear_filter ); /** * * @param cb - * @ingroup DatabaseAPI + * @ingroup DatabaseAPI_Subscription */ void set_pending_transaction_callback( std::function cb ); /** * * @param cb - * @ingroup DatabaseAPI + * @ingroup DatabaseAPI_Subscription */ void set_block_applied_callback( std::function cb ); /** * - * @param URI Content we are monitoring - * @param cb Callback - * @ingroup DatabaseAPI + * @param URI content we are monitoring + * @param cb callback + * @ingroup DatabaseAPI_Subscription */ void set_content_update_callback( std::functioncb, const string & URI ); /** - * @brief Stop receiving any notifications - * @ingroup DatabaseAPI - * - * This unsubscribes from all subscribed markets and objects. + * @brief Stop receiving any notifications. + * @note This unsubscribes from all subscribed objects. + * @ingroup DatabaseAPI_Subscription */ void cancel_all_subscriptions(); @@ -184,41 +195,43 @@ namespace graphene { namespace app { ///////////////////////////// /** - * @brief Retrieve a block header - * @param block_num Height of the block whose header should be returned - * @return header of the referenced block, or null if no matching block was found - * @ingroup DatabaseAPI + * @brief Retrieve a block header. + * @param block_num height of the block whose header should be returned + * @return header of the referenced block, or \c null if no matching block was found + * @ingroup DatabaseAPI_BlockTx */ optional get_block_header(uint32_t block_num)const; /** - * @brief Retrieve a full, signed block - * @param block_num Height of the block to be returned - * @return the referenced block, or null if no matching block was found - * @ingroup DatabaseAPI + * @brief Retrieve a full, signed block. + * @param block_num height of the block to be returned + * @return the referenced block, or \c null if no matching block was found + * @ingroup DatabaseAPI_BlockTx */ optional get_block(uint32_t block_num)const; /** - * @brief used to fetch an individual transaction. + * @brief Used to fetch an individual transaction. * @param block_num id of the block - * @param trx_in_block Specifies the position of the transaction within the block - * @ingroup DatabaseAPI + * @param trx_in_block specifies the position of the transaction within the block + * @return the transaction + * @ingroup DatabaseAPI_BlockTx */ processed_transaction get_transaction( uint32_t block_num, uint32_t trx_in_block )const; /** - * @brief Query the last local block + * @brief Query the last local block. * @return the block time + * @ingroup DatabaseAPI_BlockTx */ fc::time_point_sec head_block_time()const; /** * @brief If the transaction has not expired, this method will return the transaction for the given ID or - * it will return NULL if it is not known. Just because it is not known does not mean it wasn't + * it will return \c null if it is not known. Just because it is not known does not mean it wasn't * included in the blockchain. * @param id ID of the transaction to retrieve - * @ingroup DatabaseAPI + * @ingroup DatabaseAPI_BlockTx */ optional get_recent_transaction_by_id( const transaction_id_type& id )const; @@ -227,32 +240,40 @@ namespace graphene { namespace app { ///////////// /** - * @brief Retrieve the @ref chain_property_object associated with the chain - * @ingroup DatabaseAPI + * @brief Retrieve the \c chain_property_object associated with the chain. + * @return chain id and immutable chain parameters + * @ingroup DatabaseAPI_Globals */ chain_property_object get_chain_properties()const; /** - * @brief Retrieve the current @ref global_property_object - * @ingroup DatabaseAPI + * @brief Retrieve the current \c global_property_object. This object contains all of the properties + * of the blockchain that are fixed or that change only once per maintenance interval such as the current + * list of miners, block interval, etc. + * @return the global properties + * @ingroup DatabaseAPI_Globals */ global_property_object get_global_properties()const; /** - * @brief Retrieve compile-time constants - * @ingroup DatabaseAPI + * @brief Retrieve compile-time constants. + * @return configured constants + * @ingroup DatabaseAPI_Globals */ fc::variant_object get_config()const; /** * @brief Get the chain ID - * @ingroup DatabaseAPI + * @return the chain ID identifying blockchain network + * @ingroup DatabaseAPI_Globals */ chain_id_type get_chain_id()const; /** - * @brief Retrieve the current @ref dynamic_global_property_object - * @ingroup DatabaseAPI + * @brief Retrieve the current dynamic_global_property_object. The returned object contains information + * that changes every block interval such as the head block number, the next miner, etc. + * @return the dynamic properties + * @ingroup DatabaseAPI_Globals */ dynamic_global_property_object get_dynamic_global_properties()const; @@ -261,10 +282,10 @@ namespace graphene { namespace app { ////////// /** - * @brief Get all accounts that refer to the key in their owner or active authorities - * @param key List of public keys - * @return List of lists of account IDs. One list of account IDs per public key - * @ingroup DatabaseAPI + * @brief Get all accounts that refer to the key in their owner or active authorities. + * @param key list of public keys + * @return list of lists of account IDs. One list of account IDs per public key + * @ingroup DatabaseAPI_Key */ vector> get_key_references( vector key )const; @@ -273,83 +294,80 @@ namespace graphene { namespace app { ////////////// /** - * @brief Get a list of accounts by ID + * @brief Get a list of accounts by ID. + * @note This function has semantics identical to \c get_objects(). * @param account_ids IDs of the accounts to retrieve - * @return The accounts corresponding to the provided IDs - * @ingroup DatabaseAPI - * - * This function has semantics identical to @ref get_objects + * @return the accounts corresponding to the provided IDs + * @ingroup DatabaseAPI_Account */ vector> get_accounts(const vector& account_ids)const; /** - * @brief Fetch all objects relevant to the specified accounts and subscribe to updates - * @param subscribe true to subscribe to updates - * @param names_or_ids Each item must be the name or ID of an account to retrieve - * @return Map of string from @ref names_or_ids to the corresponding account - * @ingroup DatabaseAPI - * - * This function fetches all relevant objects for the given accounts, and subscribes to updates to the given - * accounts. If any of the strings in @ref names_or_ids cannot be tied to an account, that input will be + * @brief Fetch all objects relevant to the specified accounts and subscribe to updates. + * @note This function fetches all relevant objects for the given accounts, and subscribes to updates to the given + * accounts. If any of the \c strings in \c names_or_ids cannot be tied to an account, that input will be * ignored. All other accounts will be retrieved and subscribed. + * @param subscribe \c true to subscribe to updates + * @param names_or_ids each item must be the name or ID of an account to retrieve + * @return map of \c string from \c names_or_ids to the corresponding account + * @ingroup DatabaseAPI_Account */ std::map get_full_accounts( const vector& names_or_ids, bool subscribe ); /** - * @brief Get an account by name - * @param name Name of the account to retrieve - * @return The @ref account_object corresponding to the provided name, or null if no matching content was found - * @ingroup DatabaseAPI + * @brief Get an account by name. + * @param name name of the account to retrieve + * @return the \c account_object corresponding to the provided \c name, or \c null if no matching content was found + * @ingroup DatabaseAPI_Account */ optional get_account_by_name( string name )const; /** - * @brief Get all accounts that refer to the account id in their owner or active authorities - * @param account_id - * @return List of account IDs - * @ingroup DatabaseAPI + * @brief Get all accounts that refer to the account id in their owner or active authorities. + * @param account_id ID of the account + * @return a list of account IDs + * @ingroup DatabaseAPI_Account */ vector get_account_references( account_id_type account_id )const; /** - * @brief Get a list of accounts by name - * @param account_names Names of the accounts to retrieve - * @return The accounts holding the provided names - * @ingroup DatabaseAPI - * - * This function has semantics identical to @ref get_objects + * @brief Get a list of accounts by name. + * @note This function has semantics identical to \c get_objects(). + * @param account_names names of the accounts to retrieve + * @return the accounts holding the provided names + * @ingroup DatabaseAPI_Account */ vector> lookup_account_names(const vector& account_names)const; /** - * @brief Get names and IDs for registered accounts - * @param lower_bound_name Lower bound of the first name to return - * @param limit Maximum number of results to return -- must not exceed 1000 - * @return Map of account names to corresponding IDs - * @ingroup DatabaseAPI + * @brief Get names and IDs for registered accounts. + * @param lower_bound_name lower bound of the first name to return + * @param limit maximum number of results to return ( must not exceed 1000 ) + * @return map of account names to corresponding IDs + * @ingroup DatabaseAPI_Account */ map lookup_accounts(const string& lower_bound_name, uint32_t limit)const; /** - * @brief Get names and IDs for registered accounts that match search term + * @brief Get names and IDs for registered accounts that match search term. * @param search_term will try to partially match account name or id - * @param limit Maximum number of results to return -- must not exceed 1000 - * @return Map of account names to corresponding IDs - * @ingroup DatabaseAPI + * @param order sort data by field + * @param id \c object_id to start searching from + * @param limit maximum number of results to return ( must not exceed 1000 ) + * @return map of account names to corresponding IDs + * @ingroup DatabaseAPI_Account */ vector search_accounts(const string& search_term, const string order, const object_id_type& id, uint32_t limit) const; /** * @brief Returns the operations on the named account. - * - * This returns a list of transaction detail object, which describe activity on the account. - * + * @note This returns a list of transaction detail objects, which describe activity on the account. * @param account the account to search - * @param order Sort data by field - * @param id object_id to start searching from + * @param order sort data by field + * @param id \c object_id to start searching from * @param limit the number of entries to return (starting from the most recent) (max 100) - * @returns a list of \c transaction_detail_object - * @ingroup WalletCLI + * @return a list of transaction detail objects + * @ingroup DatabaseAPI_Account */ vector search_account_history(account_id_type const& account, string const& order, @@ -361,33 +379,35 @@ namespace graphene { namespace app { ////////////// /** - * @brief Get an account's balances in various assets + * @brief Get an account's balances in various assets. * @param id ID of the account to get balances for * @param assets IDs of the assets to get balances of; if empty, get all assets account has a balance in - * @return Balances of the account - * @ingroup DatabaseAPI + * @return a list of the given account's balances + * @ingroup DatabaseAPI_Balance */ vector get_account_balances(account_id_type id, const flat_set& assets)const; /** - * @brief Semantically equivalent to @ref get_account_balances, but takes a name instead of an ID. - * @param name of the account to get balances for - * @assets IDs of the assets to get balances of; if empty, get all assets account has a balance in - * @ingroup DatabaseAPI + * @brief Semantically equivalent to \c get_account_balances(), but takes a name instead of an ID. + * @param name the name of the account to get balances for + * @param assets IDs of the assets to get balances of; if empty, get all assets account has a balance in + * @return a list of the given account's balances + * @ingroup DatabaseAPI_Balance */ vector get_named_account_balances(const std::string& name, const flat_set& assets)const; /** * @brief Get information about a vesting balance object. - * - * @param account_id An account ID. - * @ingroup DatabaseAPI + * @param account_id an account ID + * @return a list of vesting balances with additional information + * @ingroup DatabaseAPI_Balance */ vector get_vesting_balances( account_id_type account_id )const; /** - * @brief Get the total number of accounts registered with the blockchain - * @ingroup DatabaseAPI + * @brief Get the total number of accounts registered on the blockchain. + * @return the total number of registered accounts + * @ingroup DatabaseAPI_Account */ uint64_t get_account_count()const; @@ -396,42 +416,53 @@ namespace graphene { namespace app { //////////// /** - * @brief Get a list of assets by ID + * @brief Get a list of assets by ID. + * @note This function has semantics identical to \c get_objects(). * @param asset_ids IDs of the assets to retrieve - * @return The assets corresponding to the provided IDs - * @ingroup DatabaseAPI - * - * This function has semantics identical to @ref get_objects + * @return the assets corresponding to the provided IDs + * @ingroup DatabaseAPI_Asset */ vector> get_assets(const vector& asset_ids)const; /** - * @brief Get assets alphabetically by symbol name - * @param lower_bound_symbol Lower bound of symbol names to retrieve - * @param limit Maximum number of assets to fetch (must not exceed 100) - * @return The assets found - * @ingroup DatabaseAPI + * @brief Get assets alphabetically by symbol name. + * @param lower_bound_symbol lower bound of symbol names to retrieve + * @param limit maximum number of assets to fetch (must not exceed 100) + * @return the assets found + * @ingroup DatabaseAPI_Asset */ vector list_assets(const string& lower_bound_symbol, uint32_t limit)const; /** - * @brief Get a list of assets by symbol - * @param symbols_or_ids Symbols or stringified IDs of the assets to retrieve - * @return The assets corresponding to the provided symbols or IDs - * @ingroup DatabaseAPI - * - * This function has semantics identical to @ref get_objects + * @brief Get a list of assets by symbol. + * @note This function has semantics identical to \c get_objects(). + * @param symbols_or_ids symbols or stringified IDs of the assets to retrieve + * @return the assets corresponding to the provided symbols or IDs + * @ingroup DatabaseAPI_Asset */ vector> lookup_asset_symbols(const vector& symbols_or_ids)const; + /** + * @brief Returns a reward for a miner from the most recent block. + * @return amount of newly generated DCT + * @ingroup DatabaseAPI_Mining + */ share_type get_new_asset_per_block() const; + + /** + * @brief Returns a reward for a miner from a specified block. + * @note A reward from transaction fees is not included. + * @param block_num the block number + * @return amount of newly generated DCT + * @ingroup DatabaseAPI_Mining + */ share_type get_asset_per_block_by_block_num(uint32_t block_num) const; /** * @brief Converts asset into DCT, using actual price feed. * @param price asset in DCT, monitored asset or user issued asset * @return price in DCT - * @ingroup DatabaseAPI + * @ingroup DatabaseAPI_Asset */ asset price_to_dct( asset price )const; @@ -440,45 +471,44 @@ namespace graphene { namespace app { /////////////// /** - * @brief Get a list of miners by ID + * @brief Get a list of miners by ID. + * @note This function has semantics identical to \c get_objects(). * @param miner_ids IDs of the miners to retrieve - * @return The miners corresponding to the provided IDs - * @ingroup DatabaseAPI - * - * This function has semantics identical to @ref get_objects + * @return the miners corresponding to the provided IDs + * @ingroup DatabaseAPI_Mining */ vector> get_miners(const vector& miner_ids)const; /** - * @brief Get the miner owned by a given account - * @param account The ID of the account whose miner should be retrieved - * @return The miner object, or null if the account does not have a miner - * @ingroup DatabaseAPI + * @brief Get the miner owned by a given account. + * @param account the ID of the account whose miner should be retrieved + * @return the miner object, or \c null if the account does not have a miner + * @ingroup DatabaseAPI_Mining */ fc::optional get_miner_by_account(account_id_type account)const; /** - * @brief Get names and IDs for registered miners - * @param lower_bound_name Lower bound of the first name to return - * @param limit Maximum number of results to return -- must not exceed 1000 - * @return Map of miner names to corresponding IDs - * @ingroup DatabaseAPI + * @brief Get names and IDs for registered miners. + * @param lower_bound_name lower bound of the first name to return + * @param limit maximum number of results to return ( must not exceed 1000 ) + * @return map of miner names to corresponding IDs + * @ingroup DatabaseAPI_Mining */ map lookup_miner_accounts(const string& lower_bound_name, uint32_t limit)const; /** - * @brief Get the total number of miners registered with the blockchain - * @ingroup DatabaseAPI + * @brief Get the total number of miners registered with the blockchain. + * @return the total number of registered miners + * @ingroup DatabaseAPI_Mining */ uint64_t get_miner_count()const; /** * @brief Get a list of published price feeds by a miner. - * * @param account_id id of the account - * @param count Maximum number of price feeds to fetch (must not exceed 100) - * @returns list of price feeds published by the miner - * @ingroup WalletCLI + * @param count maximum number of price feeds to fetch (must not exceed 100) + * @returns a list of price feeds published by the miner + * @ingroup DatabaseAPI_Mining */ multimap< time_point_sec, price_feed> get_feeds_by_miner(const account_id_type account_id, const uint32_t count)const; @@ -488,11 +518,11 @@ namespace graphene { namespace app { /////////// /** - * @brief Given a set of votes, return the objects they are voting for. - * @ingroup DatabaseAPI - * @param votes Set of votes - * The results will be in the same order as the votes. Null will be returned for - * any vote ids that are not found. + * @brief Given a set of votes, return the objects they are voting for. + * @note The results will be in the same order as the votes. \c null will be returned for + * any vote ids that are not found. + * @param votes set of votes + * @ingroup DatabaseAPI_Mining */ vector lookup_vote_ids( const vector& votes )const; @@ -501,59 +531,62 @@ namespace graphene { namespace app { //////////////////////////// /** - * @brief Get a hexdump of the serialized binary form of a transaction - * @param trx - * @return - * @ingroup DatabaseAPI + * @brief Get a hexdump of the serialized binary form of a transaction. + * @param trx the signed transaction + * @return hexadecimal string + * @ingroup DatabaseAPI_AuthValidation */ std::string get_transaction_hex(const signed_transaction& trx)const; /** * @brief This API will take a partially signed transaction and a set of public keys that the owner has the ability to sign for * and return the minimal subset of public keys that should add signatures to the transaction. - * @param trx - * @param available_keys Set of available public keys - * @ingroup DatabaseAPI + * @param trx the signed transaction + * @param available_keys set of available public keys + * @ingroup DatabaseAPI_AuthValidation */ set get_required_signatures( const signed_transaction& trx, const flat_set& available_keys )const; /** - * @brief This method will return the set of all public keys that could possibly sign for a given transaction. This call can - * be used by wallets to filter their set of public keys to just the relevant subset prior to calling @ref get_required_signatures + * @brief This method will return the set of all public keys that could possibly sign for a given transaction. This call can + * be used by wallets to filter their set of public keys to just the relevant subset prior to calling \c get_required_signatures() * to get the minimum subset. - * @param trx - * @ingroup DatabaseAPI + * @param trx the signed transaction + * @ingroup DatabaseAPI_AuthValidation */ set get_potential_signatures( const signed_transaction& trx )const; /** - * @return true if the @ref trx has all of the required signatures, otherwise throws an exception - * @ingroup DatabaseAPI - * @param trx + * @brief Verifies required signatures of a transaction. + * @param trx the signed transaction + * @return \c true if the \c trx has all of the required signatures, otherwise throws an exception + * @ingroup DatabaseAPI_AuthValidation */ bool verify_authority( const signed_transaction& trx )const; /** - * @return true if the signers have enough authority to authorize an account - * @ingroup DatabaseAPI - * @param name_or_id The name or id of the account - * @param signers Set of public keys + * @brief Verifies if the signers have enough authority to authorize an account. + * @param name_or_id the name or id of the account + * @param signers set of public keys + * @return \c true if the signers have enough authority + * @ingroup DatabaseAPI_AuthValidation */ bool verify_account_authority( const string& name_or_id, const flat_set& signers )const; /** * @brief Validates a transaction against the current state without broadcasting it on the network. - * @param trx - * @ingroup DatabaseAPI + * @param trx the signed transaction + * @ingroup DatabaseAPI_AuthValidation */ processed_transaction validate_transaction( const signed_transaction& trx )const; /** * @brief For each operation calculate the required fee in the specified asset type. If the asset type does - * not have a valid core_exchange_rate - * @param ops The set of operations - * @param id The asset ID - * @ingroup DatabaseAPI + * not have a valid core_exchange_rate. + * @param ops the set of operations + * @param id the asset ID + * @return the required fees + * @ingroup DatabaseAPI_AuthValidation */ vector< fc::variant > get_required_fees( const vector& ops, asset_id_type id )const; @@ -562,10 +595,10 @@ namespace graphene { namespace app { /////////////////////////// /** - * @brief Get the set of proposed transactions relevant to the specified account id - * @param id The account ID - * @return Set of proposed transactions - * @ingroup DatabaseAPI + * @brief Get the set of proposed transactions relevant to the specified account id. + * @param id the account ID + * @return a set of proposed transactions + * @ingroup DatabaseAPI_Proposals */ vector get_proposed_transactions( account_id_type id )const; @@ -575,62 +608,62 @@ namespace graphene { namespace app { /** - * @brief Return current core asset supply + * @brief Return current core asset supply. * @return current supply - * @ingroup DatabaseAPI + * @ingroup DatabaseAPI_Asset */ real_supply get_real_supply()const; /** * @brief Get a list of accounts holding publishing manager status. - * @param lower_bound_name The name of the first account to return. If the named account does not exist, + * @param lower_bound_name the name of the first account to return. If the named account does not exist, * the list will start at the account that comes after \c lowerbound - * @param limit The maximum number of accounts to return (max: 100) - * @return List of accounts - * @ingroup DatabaseAPI + * @param limit the maximum number of accounts to return (max: 100) + * @return a list of publishing managers + * @ingroup DatabaseAPI_Decent */ vector list_publishing_managers( const string& lower_bound_name, uint32_t limit )const; /** - * @brief Get a list of open buyings - * @return The buying_objects - * @ingroup DatabaseAPI + * @brief Get a list of open buyings. + * @return a list of buying objects + * @ingroup DatabaseAPI_Decent */ vector get_open_buyings()const; /** - * @brief Get a list of open buyings by URI + * @brief Get a list of open buyings by URI. * @param URI URI of the buyings to retrieve - * @return The buyings corresponding to the provided URI - * @ingroup DatabaseAPI + * @return a list of buyings corresponding to the provided URI + * @ingroup DatabaseAPI_Decent */ vector get_open_buyings_by_URI( const string& URI )const; /** - * @brief Get a list of open buyings by consumer - * @param consumer Consumer of the buyings to retrieve - * @return The buyings corresponding to the provided consumer - * @ingroup DatabaseAPI + * @brief Get a list of open buyings by consumer. + * @param consumer consumer of the buyings to retrieve + * @return a list of buyings corresponding to the provided consumer + * @ingroup DatabaseAPI_Decent */ vector get_open_buyings_by_consumer( const account_id_type& consumer )const; /** - * @brief Get history buying objects by consumer - * @param consumer Consumer of the history buyings to retrieve - * @return History buying objects corresponding to the provided consumer - * @ingroup DatabaseAPI + * @brief Get history buying objects by consumer. + * @param consumer consumer of the history buyings to retrieve + * @return history buying objects corresponding to the provided consumer + * @ingroup DatabaseAPI_Decent */ vector get_buying_history_objects_by_consumer( const account_id_type& consumer )const; /** - * @brief Get buying objects (open or history) by consumer - * @param consumer Consumer of the buyings to retrieve - * @param order Ordering field - * @param id The id of buying object to start searching from - * @param term Search term - * @param count Maximum number of contents to fetch (must not exceed 100) - * @return Buying objects corresponding to the provided consumer - * @ingroup DatabaseAPI + * @brief Get buying objects (open or history) by consumer. + * @param consumer consumer of the buyings to retrieve + * @param order ordering field + * @param id the id of buying object to start searching from + * @param term search term + * @param count maximum number of contents to fetch (must not exceed 100) + * @return buying objects corresponding to the provided consumer + * @ingroup DatabaseAPI_Decent */ vector get_buying_objects_by_consumer(const account_id_type& consumer, const string& order, @@ -639,22 +672,22 @@ namespace graphene { namespace app { uint32_t count)const; /** - * @brief Get buying (open or history) by consumer and URI - * @param consumer Consumer of the buying to retrieve + * @brief Get buying (open or history) by consumer and URI. + * @param consumer consumer of the buying to retrieve * @param URI URI of the buying to retrieve - * @return Buying object corresponding to the provided consumer and URI - * @ingroup DatabaseAPI + * @return buying object corresponding to the provided consumer and URI + * @ingroup DatabaseAPI_Decent */ optional get_buying_by_consumer_URI( const account_id_type& consumer, const string& URI )const; /** - * @brief Search for term in contents (author, title and description) - * @param user Feedback author + * @brief Search for term in contents (author, title and description). + * @param user feedback author * @param URI the content object uri - * @param id The id of feedback object to start searching from - * @param count Maximum number of feedbacks to fetch - * @return The feedback found - * @ingroup DatabaseAPI + * @param id the id of feedback object to start searching from + * @param count maximum number of feedbacks to fetch + * @return the feedback found + * @ingroup DatabaseAPI_Decent */ vector search_feedback(const string& user, const string& URI, @@ -662,34 +695,41 @@ namespace graphene { namespace app { uint32_t count) const; /** - * @brief Get a content by URI + * @brief Get a content by URI. * @param URI URI of the content to retrieve - * @return The content corresponding to the provided URI, or null if no matching content was found - * @ingroup DatabaseAPI + * @return the content corresponding to the provided URI, or \c null if no matching content was found + * @ingroup DatabaseAPI_Decent */ optional get_content( const string& URI )const; /** - * @brief Generate keys for new content submission + * @brief Generate keys for new content submission. * @param seeders list of seeder account IDs * @return generated key and key parts - * @ingroup DatabaseAPI + * @ingroup DatabaseAPI_Decent */ content_keys generate_content_keys(vector const& seeders)const; + /** + * @brief Restores encryption key from key parts stored in buying object. + * @param el_gamal_priv_key_string the private El Gamal key + * @param buying the buying object + * @return AES encryption key + * @ingroup DatabaseAPI_Decent + */ fc::sha256 restore_encryption_key(DIntegerString el_gamal_priv_key_string, buying_id_type buying ) const; /** - * @brief Search for term in contents (author, title and description) - * @param term Search term - * @param order Ordering field - * @param user Content owner - * @param region Two letter region code - * @param id The id of content object to start searching from + * @brief Search for term in contents (author, title and description). + * @param term search term + * @param order ordering field + * @param user content owner + * @param region_code two letter region code + * @param id the id of content object to start searching from * @param type the application and content type to be filtered - * @param count Maximum number of contents to fetch (must not exceed 100) - * @return The contents found - * @ingroup DatabaseAPI + * @param count maximum number of contents to fetch (must not exceed 100) + * @return the contents found + * @ingroup DatabaseAPI_Decent */ vector search_content(const string& term, const string& order, @@ -700,100 +740,112 @@ namespace graphene { namespace app { uint32_t count )const; /** - * @brief Get a list of seeders by price, in increasing order - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup DatabaseAPI + * @brief Get a list of seeders by price, in increasing order. + * @param count maximum number of seeders to retrieve + * @return the seeders found + * @ingroup DatabaseAPI_Decent */ vector list_seeders_by_price( uint32_t count )const; /** - * @brief Get a list of seeders by price, in increasing order. Same method as list_seeders_by_price, kept for compatibility - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup DatabaseAPI + * @brief Get a list of seeders by price, in increasing order. Same method as list_seeders_by_price, kept for compatibility. + * @param count maximum number of seeders to retrieve + * @return the seeders found + * @ingroup DatabaseAPI_Decent */ vector list_publishers_by_price( uint32_t count )const; /** - * @brief Get a seeder by ID - * @param ID ID of the seeder to retrieve - * @return The seeder corresponding to the provided ID, or null if no matching content was found - * @ingroup DatabaseAPI + * @brief Get a seeder by ID. + * @param aid ID of the seeder to retrieve + * @return the seeder corresponding to the provided ID, or \c null if no matching content was found + * @ingroup DatabaseAPI_Decent */ optional get_seeder(account_id_type aid) const; /** - * @brief Get a list of seeders by total upload, in decreasing order - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup DatabaseAPI + * @brief Get a list of seeders by total upload, in decreasing order. + * @param count maximum number of seeders to retrieve + * @return the seeders found + * @ingroup DatabaseAPI_Decent */ optional> list_seeders_by_upload( const uint32_t count )const; /** - * @brief Get a list of seeders by region code - * @param region_code Region code of seeders to retrieve - * @return The seeders found - * @ingroup DatabaseAPI + * @brief Get a list of seeders by region code. + * @param region_code region code of seeders to retrieve + * @return the seeders found + * @ingroup DatabaseAPI_Decent */ vector list_seeders_by_region( const string region_code )const; /** - * @brief Get a list of seeders by rating, in decreasing order - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup DatabaseAPI + * @brief Get a list of seeders by rating, in decreasing order. + * @param count maximum number of seeders to retrieve + * @return the seeders found + * @ingroup DatabaseAPI_Decent */ vector list_seeders_by_rating( const uint32_t count )const; /** - * @brief Get a subscription object by ID + * @brief Get a subscription object by ID. * @param sid ID of the subscription to retrieve - * @return The subscription object corresponding to the provided ID, or null if no matching subscription was found - * @ingroup DatabaseAPI + * @return the subscription object corresponding to the provided ID, or null if no matching subscription was found + * @ingroup DatabaseAPI_Decent */ optional get_subscription( const subscription_id_type& sid)const; /** - * @brief Get a list of active (not expired) subscriptions subscribed by account (consumer) - * @param URI_begin Lower bound of URI strings to retrieve - * @param count Maximum number of subscription objects to fetch (must not exceed 100) - * @return The list of subscription objects corresponding to the provided consumer - * @ingroup DatabaseAPI + * @brief Get a list of active (not expired) subscriptions subscribed by account (consumer). + * @param account ID of the account to get subscriptions for + * @param count maximum number of subscription objects to fetch (must not exceed 100) + * @return a list of subscription objects corresponding to the provided consumer + * @ingroup DatabaseAPI_Decent */ vector list_active_subscriptions_by_consumer( const account_id_type& account, const uint32_t count )const; /** - * @brief Get a list of subscriptions subscribed by account (consumer) - * @param URI_begin Lower bound of URI strings to retrieve - * @param count Maximum number of subscription objects to fetch (must not exceed 100) - * @return The contents found - * @ingroup DatabaseAPI + * @brief Get a list of subscriptions subscribed by account (consumer). + * @param account ID of the account to get subscriptions for + * @param count maximum number of subscription objects to fetch (must not exceed 100) + * @return the contents found + * @ingroup DatabaseAPI_Decent */ vector list_subscriptions_by_consumer( const account_id_type& account, const uint32_t count )const; /** - * @brief Get a list of active (not expired) subscriptions to account (author) - * @param URI_begin Lower bound of URI strings to retrieve - * @param count Maximum number of subscription objects to fetch (must not exceed 100) - * @return The contents found - * @ingroup DatabaseAPI + * @brief Get a list of active (not expired) subscriptions to account (author). + * @param account ID of the account to get subscriptions for + * @param count maximum number of subscription objects to fetch (must not exceed 100) + * @return the contents found + * @ingroup DatabaseAPI_Decent */ vector list_active_subscriptions_by_author( const account_id_type& account, const uint32_t count )const; /** - * @brief Get a list of subscriptions subscribed to account (author) - * @param URI_begin Lower bound of URI strings to retrieve - * @param count Maximum number of subscription objects to fetch (must not exceed 100) - * @return The contents found - * @ingroup DatabaseAPI + * @brief Get a list of subscriptions subscribed to account (author). + * @param account ID of the account to get subscriptions for + * @param count maximum number of subscription objects to fetch (must not exceed 100) + * @return the contents found + * @ingroup DatabaseAPI_Decent */ vector list_subscriptions_by_author( const account_id_type& account, const uint32_t count )const; + /** + * @brief Get remaining time to next maintenance interval from given time. + * @param block_time reference time + * @return remaining time to next maintenance interval along with some additional data + * @ingroup DatabaseAPI_Globals + */ miner_reward_input get_time_to_maint_by_block_time(fc::time_point_sec block_time) const; + /** + * @brief Get the number of votes each miner actually has. + * @return a list mapping account names to the number of votes + * @ingroup DatabaseAPI_Mining + */ vector get_actual_votes() const; + private: std::shared_ptr< database_api_impl > my; }; diff --git a/libraries/chain/include/graphene/chain/protocol/account.hpp b/libraries/chain/include/graphene/chain/protocol/account.hpp index 660acae7..02b4f8a7 100644 --- a/libraries/chain/include/graphene/chain/protocol/account.hpp +++ b/libraries/chain/include/graphene/chain/protocol/account.hpp @@ -88,7 +88,7 @@ namespace graphene { namespace chain { struct fee_parameters_type { - uint64_t basic_fee = 1*GRAPHENE_BLOCKCHAIN_PRECISION/1000; ///< the cost to register the cheapest non-free account + uint64_t basic_fee = 1*GRAPHENE_BLOCKCHAIN_PRECISION/1000; ///< the cost to register an account }; asset fee; diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 23b1496e..b8be7b8f 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -93,8 +93,8 @@ namespace graphene { namespace wallet { [](const account_object& ao) { return ao.id; }); return ids; } - /// Add acct to @ref my_accounts, or update it if it is already in @ref my_accounts - /// @return true if the account was newly inserted; false if it was only updated + /// @brief Add acct to @ref my_accounts, or update it if it is already in @ref my_accounts + /// @return \c true if the account was newly inserted; \c false if it was only updated bool update_account(const account_object& acct) { auto& idx = my_accounts.get(); @@ -238,8 +238,24 @@ namespace graphene { namespace wallet { * This wallet assumes it is connected to the database server with a high-bandwidth, low-latency connection and * performs minimal caching. This API could be provided locally to be used by a web interface. * - * @defgroup WalletCLI WalletCLI + * @defgroup WalletCLI CLI Wallet + * @{ + * @defgroup WalletAPI_Wallet Wallet + * @defgroup WalletAPI_General General + * @defgroup WalletAPI_Account Account + * @defgroup WalletAPI_Asset Asset + * @defgroup WalletAPI_Subscription Subscription + * @defgroup WalletAPI_Content Content + * @defgroup WalletAPI_Messaging Messaging + * @defgroup WalletAPI_Seeding Seeding + * @defgroup WalletAPI_Mining Mining + * @defgroup WalletAPI_Proposals Proposals + * @defgroup WalletAPI_TransactionBuilder Transaction Builder + * @defgroup WalletAPI_Network Network + * @defgroup WalletAPI_Debug Debug + * @} */ + class wallet_api { public: @@ -247,48 +263,48 @@ namespace graphene { namespace wallet { virtual ~wallet_api(); /** - * @brief Copy wallet file to a new file + * @brief Copy wallet file to a new file. * @param destination_filename - * @return true if the wallet is copied, false otherwise - * @ingroup WalletCLI + * @return \c true if the wallet is copied,\c false otherwise + * @ingroup WalletAPI_Wallet */ bool copy_wallet_file( string destination_filename ); /** - * @brief Derive private key from given prefix and sequence + * @brief Derive private key from given prefix and sequence. * @param prefix_string * @param sequence_number - * @return private_key Derived private key - * @ingroup WalletCLI + * @return derived private key + * @ingroup WalletAPI_Account */ fc::ecc::private_key derive_private_key(const std::string& prefix_string, int sequence_number) const; /** - * @brief Lists all available commands - * @return List of all available commands - * @ingroup WalletCLI + * @brief Lists all available commands. + * @return a list of all available commands + * @ingroup WalletAPI_General */ variant info(); /** * @brief Returns info such as client version, git version of graphene/fc, version of boost, openssl. - * @returns compile time info and client and dependencies versions - * @ingroup WalletCLI + * @return compile time info and client and dependencies versions + * @ingroup WalletAPI_General */ variant_object about() const; /** - * @brief Retrieve a full, signed block with info - * @param num ID of the block - * @return the referenced block with info, or null if no matching block was found - * @ingroup WalletCLI + * @brief Retrieve a full, signed block with info. + * @param num ID/height of the block + * @return the referenced block with info, or \c null if no matching block was found + * @ingroup WalletAPI_General */ optional get_block( uint32_t num ); /** - * @brief Returns the number of accounts registered on the blockchain - * @returns the number of registered accounts - * @ingroup WalletCLI + * @brief Returns the number of accounts registered on the blockchain. + * @return the number of registered accounts + * @ingroup WalletAPI_Account */ uint64_t get_account_count()const; @@ -296,73 +312,66 @@ namespace graphene { namespace wallet { * @brief Lists all accounts controlled by this wallet. * This returns a list of the full account objects for all accounts whose private keys * we possess. - * @returns a list of account objects - * @ingroup WalletCLI + * @return a list of accounts imported in the wallet + * @ingroup WalletAPI_Wallet */ vector list_my_accounts(); /** * @brief Lists all accounts registered in the blockchain. * This returns a list of all account names and their account ids, sorted by account name. - * - * Use the \c lowerbound and limit parameters to page through the list. To retrieve all accounts, + * Use the \c lowerbound and \c limit parameters to page through the list. To retrieve all accounts, * start by setting \c lowerbound to the empty string \c "", and then each iteration, pass * the last account name returned as the \c lowerbound for the next \c list_accounts() call. - * * @param lowerbound the name of the first account to return. If the named account does not exist, * the list will start at the account that comes after \c lowerbound * @param limit the maximum number of accounts to return (max: 1000) - * @returns a list of accounts mapping account names to account ids - * @ingroup WalletCLI + * @return a list of accounts mapping account names to account ids + * @ingroup WalletAPI_Account */ map list_accounts(const string& lowerbound, uint32_t limit); /** - * @brief Get names and IDs for registered accounts that match search term + * @brief Get registered accounts that match search term * @param term will try to partially match account name or id - * @param limit Maximum number of results to return -- must not exceed 1000 - * @param order Sort data by field + * @param limit maximum number of results to return ( must not exceed 1000 ) + * @param order sort data by field * @param id object_id to start searching from - * @return Map of account names to corresponding IDs - * @ingroup WalletCLI + * @return map of account names to corresponding IDs + * @ingroup WalletAPI_Account */ vector search_accounts(const string& term, const string& order, const string& id, uint32_t limit); /** * @brief List the balances of an account. * Each account can have multiple balances, one for each type of asset owned by that - * account. The returned list will only contain assets for which the account has a - * nonzero balance + * account. * @param id the name or id of the account whose balances you want - * @returns a list of the given account's balances - * @ingroup WalletCLI + * @return a list of the given account's balances + * @ingroup WalletAPI_Account */ vector list_account_balances(const string& id); /** * @brief Lists all assets registered on the blockchain. - * - * To list all assets, pass the empty string \c "" for the lowerbound to start + * To list all assets, pass the empty string \c "" for the \c lowerbound to start * at the beginning of the list, and iterate as necessary. - * - * @param lowerbound the symbol of the first asset to include in the list. + * @param lowerbound the symbol of the first asset to include in the list * @param limit the maximum number of assets to return (max: 100) - * @returns the list of asset objects, ordered by symbol - * @ingroup WalletCLI + * @return the list of asset objects, ordered by symbol + * @ingroup WalletAPI_Asset */ vector list_assets(const string& lowerbound, uint32_t limit)const; /** * @brief Returns the operations on the named account. - * - * This returns a list of transaction detail object, which describe activity on the account. - * + * This returns a list of transaction detail objects, which describe past the past activity on the account. * @param account_name the name or id of the account - * @param order Sort data by field + * @param order sort data by field * @param id object_id to start searching from * @param limit the number of entries to return (starting from the most recent) (max 100) - * @returns a list of \c transaction_detail_object - * @ingroup WalletCLI + * @return a list of transaction detail objects + * @ingroup WalletAPI_Account */ vector search_account_history(string const& account_name, string const& order, @@ -370,37 +379,36 @@ namespace graphene { namespace wallet { int limit) const; - /** Returns the most recent operations on the named account. - * + /** + * @brief Returns the most recent operations on the named account. * This returns a list of operation history objects, which describe activity on the account. - * - * @note this API doesn't give a way to retrieve more than the most recent 100 transactions, - * you can interface directly with the blockchain to get more history + * @note this API doesn't give a way to retrieve more than the most recent 100 transactions * @param name the name or id of the account - * @param limit the number of entries to return (starting from the most recent) (max 100) - * @returns a list of \c operation_history_objects + * @param limit the number of entries to return (starting from the most recent) + * @return a list of operation history objects + * @ingroup WalletAPI_Account */ vector get_account_history(string name, int limit)const; /** - * @brief Returns the block chain's slowly-changing settings. + * @brief Returns the blockchain's slowly-changing properties. * This object contains all of the properties of the blockchain that are fixed - * or that change only once per maintenance interval (daily) such as the + * or that change only once per maintenance interval such as the * current list of miners, block interval, etc. * @see \c get_dynamic_global_properties() for frequently changing properties - * @returns the global properties - * @ingroup WalletCLI + * @return the global properties + * @ingroup WalletAPI_General */ global_property_object get_global_properties() const; /** - * @brief Returns the block chain's rapidly-changing properties. + * @brief Returns the blockchain's rapidly-changing properties. * The returned object contains information that changes every block interval * such as the head block number, the next miner, etc. * @see \c get_global_properties() for less-frequently changing properties - * @returns the dynamic global properties - * @ingroup WalletCLI + * @return the dynamic global properties + * @ingroup WalletAPI_General */ dynamic_global_property_object get_dynamic_global_properties() const; @@ -408,140 +416,137 @@ namespace graphene { namespace wallet { * @brief Returns information about the given account. * * @param account_name_or_id the name or id of the account to provide information about - * @returns the public account data stored in the blockchain - * @ingroup WalletCLI + * @return the public account data stored in the blockchain + * @ingroup WalletAPI_Account */ account_object get_account(string account_name_or_id) const; /** * @brief Returns information about the given asset. * @param asset_name_or_id the symbol or id of the asset in question - * @returns the information about the asset stored in the block chain - * @ingroup WalletCLI + * @return the information about the asset stored in the block chain + * @ingroup WalletAPI_Asset */ asset_object get_asset(string asset_name_or_id) const; /** - * @brief Returns the BitAsset-specific data for a given asset. - * Market-issued assets's behavior are determined both by their "BitAsset Data" and - * their basic asset data, as returned by \c get_asset(). - * @param asset_name_or_id the symbol or id of the BitAsset in question - * @returns the BitAsset-specific data for this asset - * @ingroup WalletCLI + * @brief Returns the specific data for a given monitored asset. + * @see \c get_asset() + * @param asset_name_or_id the symbol or id of the monitored asset in question + * @return the specific data for this monitored asset + * @ingroup WalletAPI_Asset */ monitored_asset_options get_monitored_asset_data(string asset_name_or_id)const; /** * @brief Lookup the id of a named account. * @param account_name_or_id the name of the account to look up - * @returns the id of the named account - * @ingroup WalletCLI + * @return the id of the named account + * @ingroup WalletAPI_Account */ account_id_type get_account_id(string account_name_or_id) const; /** * @brief Lookup the id of a named asset. * @param asset_name_or_id the symbol of an asset to look up - * @returns the id of the given asset - * @ingroup WalletCLI + * @return the id of the given asset + * @ingroup WalletAPI_Asset */ asset_id_type get_asset_id(string asset_name_or_id) const; /** * @brief Returns the blockchain object corresponding to the given id. - * * This generic function can be used to retrieve any object from the blockchain * that is assigned an ID. Certain types of objects have specialized convenience * functions to return their objects -- e.g., assets have \c get_asset(), accounts * have \c get_account(), but this function will work for any object. - * * @param id the id of the object to return - * @returns the requested object - * @ingroup WalletCLI + * @return the requested object + * @ingroup WalletAPI_General */ variant get_object(object_id_type id) const; /** @brief Returns the current wallet filename. - * - * This is the filename that will be used when automatically saving the wallet. - * + * @note This is the filename that will be used when automatically saving the wallet. * @see set_wallet_filename() * @return the wallet filename - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ string get_wallet_filename() const; /** * @brief Get the WIF private key corresponding to a public key. The - * private key must already be in the wallet. - * @param pubkey Public key + * private key must already be imported in the wallet. + * @param pubkey public key * @return WIF private key corresponding to a public key - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ string get_private_key( public_key_type pubkey )const; /** - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Allows creation of customized transactions and fill them with operation/s. + * @return identifier allowing to construct several transactions in parallel and identify them + * @ingroup WalletAPI_TransactionBuilder */ transaction_handle_type begin_builder_transaction(); /** - * - * @param transaction_handle - * @param op - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Adds an operation to a transaction in transaction builder. + * @see \c begin_builder_transaction() + * @param transaction_handle the number indetifying transaction under construction process + * @param op the operation + * @ingroup WalletAPI_TransactionBuilder */ void add_operation_to_builder_transaction(transaction_handle_type transaction_handle, const operation& op); /** - * - * @param handle - * @param operation_index - * @param new_op - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Replace existing operation in specified transaction in transaction builder. + * @see \c add_operation_to_builder_transaction() + * @param handle the number identifying transaction under contruction process + * @param operation_index index of the operation to replace + * @param new_op the new operation replacing the existing one + * @ingroup WalletAPI_TransactionBuilder */ void replace_operation_in_builder_transaction(transaction_handle_type handle, unsigned operation_index, const operation& new_op); /** - * - * @param handle - * @param fee_asset - * @return - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Set fees on all operations in a transaction + * @see \c begin_builder_transaction() + * @param handle the number identifying transaction under contruction process + * @param fee_asset the asset in which fees are calculated + * @return total fee in specified asset + * @ingroup WalletAPI_TransactionBuilder */ asset set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset = GRAPHENE_SYMBOL); /** - * @param handle - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Previews a transaction from transaction builder. + * @see \c begin_builder_transaction() + * @param handle the number identifying transaction under contruction process + * @return the transaction to preview + * @ingroup WalletAPI_TransactionBuilder */ transaction preview_builder_transaction(transaction_handle_type handle); /** - * - * @param transaction_handle - * @param broadcast true to broadcast the transaction on the network - * @return - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Signs a transaction from transaction builder + * @see \c prewiev_builder_transaction() + * @param transaction_handle the number identifying transaction under contruction process + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction + * @ingroup WalletAPI_TransactionBuilder */ signed_transaction sign_builder_transaction(transaction_handle_type transaction_handle, bool broadcast = true); /** - * - * @param handle - * @param expiration - * @param review_period_seconds - * @param broadcast true to broadcast the transaction on the network - * @return - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Allows creation of a proposed transaction suitable for miner-account. Proposed transaction requires approval of multiple accounts in order to execute. + * @param handle the number identifying transaction under contruction process + * @param expiration the expiration time of the transaction + * @param review_period_seconds the time reserved for reviewing the proposal transaction. It's not allowed to vote for the proposal when the transaction is under review + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction + * @ingroup WalletAPI_TransactionBuilder */ signed_transaction propose_builder_transaction( transaction_handle_type handle, @@ -551,14 +556,15 @@ namespace graphene { namespace wallet { ); /** - * - * @param handle - * @param account_name_or_id - * @param expiration - * @param review_period_seconds - * @param broadcast true to broadcast the transaction on the network - * @return - * @ingroup WalletCLI + * @brief Allows creation of a proposed transaction. Proposed transaction requires approval of multiple accounts in order to execute. + * @see \c propose_builder_transaction() + * @param handle the number identifying transaction under contruction process + * @param account_name_or_id the account which will pay the fee to propose the transaction + * @param expiration the expiration time of the transaction + * @param review_period_seconds the time reserved for reviewing the proposal transaction. It's not allowed to vote for the proposal when the transaction is under review + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction + * @ingroup WalletAPI_TransactionBuilder */ signed_transaction propose_builder_transaction2( transaction_handle_type handle, @@ -569,116 +575,103 @@ namespace graphene { namespace wallet { ); /** - * - * @param handle - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Removes a transaction from transaction builder + * @param handle the number identifying transaction under contruction process + * @ingroup WalletAPI_TransactionBuilder */ void remove_builder_transaction(transaction_handle_type handle); /** - * Get list of proposed transactions + * @brief Lists proposed transactions relevant to a user + * @param account_or_id the name or id of the account + * @return a list of proposed transactions + * @ingroup WalletAPI_Proposals */ vector get_proposed_transactions( string account_or_id )const; /** * @brief Checks whether the wallet has just been created and has not yet had a password set. - * - * Calling \c set_password will transition the wallet to the locked state. - * @return true if the wallet is new - * @ingroup Wallet Management - * @ingroup WalletCLI + * Calling \c set_password() will transition the wallet to the locked state. + * @return \c true if the wallet is new + * @ingroup WalletAPI_Wallet */ bool is_new()const; /** * @brief Checks whether the wallet is locked (is unable to use its private keys). - * * This state can be changed by calling \c lock() or \c unlock(). - * @return true if the wallet is locked - * @ingroup Wallet Management - * @ingroup WalletCLI + * @see \c unlock() + * @return \c true if the wallet is locked + * @ingroup WalletAPI_Wallet */ bool is_locked()const; /** * @brief Locks the wallet immediately. - * @ingroup Wallet Management - * @ingroup WalletCLI + * @see \c unlock() + * @ingroup WalletAPI_Wallet */ void lock(); /** * @brief Unlocks the wallet. - * - * The wallet remain unlocked until the \c lock is called + * The wallet remain unlocked until the \c lock() is called * or the program exits. * @param password the password previously set with \c set_password() - * @ingroup Wallet Management - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ void unlock(string password); /** * @brief Sets a new password on the wallet. - * - * The wallet must be either 'new' or 'unlocked' to - * execute this command. + * The wallet must be either \c new or \c unlocked to execute this command. * @param password - * @ingroup Wallet Management - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ void set_password(string password); /** - * @brief Dumps all private keys owned by the wallet. - * - * The keys are printed in WIF format. You can import these keys into another wallet + * @brief Dumps all private keys successfully imported in the wallet. + * @note The keys are printed in WIF format. You can import these keys into another wallet * using \c import_key() - * @returns a map containing the private keys, indexed by their public key - * @ingroup WalletCLI + * @return a map containing the private keys and corresponding public keys + * @ingroup WalletAPI_Wallet */ map dump_private_keys(); /** * @brief Returns a list of all commands supported by the wallet API. - * * This lists each command, along with its arguments and return types. * For more detailed help on a single command, use \c get_help() - * - * @returns a multi-line string suitable for displaying on a terminal - * @ingroup WalletCLI + * @return a multi-line string suitable for displaying on a terminal + * @ingroup WalletAPI_General */ string help()const; /** * @brief Returns detailed help on a single API command. * @param method the name of the API command you want help with - * @returns a multi-line string suitable for displaying on a terminal - * @ingroup WalletCLI + * @return a multi-line string suitable for displaying on a terminal + * @ingroup WalletAPI_General */ - string gethelp(const string& method)const; + string get_help(const string& method)const; /** - * @brief Loads a specified Graphene wallet. - * + * @brief Loads a specified wallet file. * The current wallet is closed before the new wallet is loaded. - * * @warning This does not change the filename that will be used for future * wallet writes, so this may cause you to overwrite your original * wallet unless you also call \c set_wallet_filename() - * * @param wallet_filename the filename of the wallet JSON file to load. * If \c wallet_filename is empty, it reloads the * existing wallet file - * @returns true if the specified wallet is loaded - * @ingroup WalletCLI + * @return \c true if the specified wallet is loaded + * @ingroup WalletAPI_Wallet */ bool load_wallet_file(string wallet_filename = ""); /** * @brief Saves the current wallet to the given filename. - * * @warning This does not change the wallet filename that will be used for future * writes, so think of this function as 'Save a Copy As...' instead of * 'Save As...'. Use \c set_wallet_filename() to make the filename @@ -686,131 +679,122 @@ namespace graphene { namespace wallet { * @param wallet_filename the filename of the new wallet JSON file to create * or overwrite. If \c wallet_filename is empty, * save to the current filename. - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ void save_wallet_file(string wallet_filename = ""); /** * @brief Sets the wallet filename used for future writes. - * * This does not trigger a save, it only changes the default filename * that will be used the next time a save is triggered. - * * @param wallet_filename the new filename to use for future saves - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ void set_wallet_filename(string wallet_filename); /** * @brief Suggests a safe brain key to use for creating your account. - * \c create_account_with_brain_key() requires you to specify a 'brain key', + * \c create_account_with_brain_key() requires you to specify a brain key, * a long passphrase that provides enough entropy to generate cyrptographic * keys. This function will suggest a suitably random string that should * be easy to write down (and, with effort, memorize). - * @returns a suggested brain_key - * @ingroup WalletCLI + * @return a suggested brain key + * @ingroup WalletAPI_Account */ brain_key_info suggest_brain_key()const; /** - * @brief Suggests a safe brain key to use for creating your account also - * generates the el_gamal_key_pair corresponding to the brain key - * \c create_account_with_brain_key() requires you to specify a 'brain key', + * @brief Suggests a safe brain key to use for creating your account. This funcion also + * generates \c el_gamal_key_pair corresponding to the brain key. + * @note \c create_account_with_brain_key() requires you to specify a brain key, * a long passphrase that provides enough entropy to generate cyrptographic * keys. This function will suggest a suitably random string that should * be easy to write down (and, with effort, memorize). - * @returns a suggested brain_key - * @ingroup WalletCLI + * @return a suggested brain key and corresponding El Gamal key pair + * @ingroup WalletAPI_Account */ pair generate_brain_key_el_gamal_key() const; /** * @brief Calculates the private key and public key corresponding to any brain key * @param brain_key the brain key to be used for calculation - * @returns the corresponding brain_key_info - * @ingroup WalletCLI + * @return the corresponding \c brain_key_info + * @ingroup WalletAPI_Account */ brain_key_info get_brain_key_info(string const& brain_key) const; + // TODO: I don't see a broadcast_transaction() function, do we need one? /** * @brief Converts a signed_transaction in JSON form to its binary representation. - * - * TODO: I don't see a broadcast_transaction() function, do we need one? - * * @param tx the transaction to serialize - * @returns the binary form of the transaction. It will not be hex encoded, - * this returns a raw string that may have null characters embedded - * in it - * @ingroup WalletCLI + * @return the binary form of the transaction. It will not be hex encoded, + * this returns a raw string that may have null characters embedded in it + * @ingroup WalletAPI_TransactionBuilder */ string serialize_transaction(signed_transaction tx) const; /** * @brief Imports the private key for an existing account. - * - * The private key must match either an owner key or an active key for the + * The private key should match either an owner key or an active key for the * named account. - * * @see dump_private_keys() - * + * @see list_my_accounts() * @param account_name_or_id the account owning the key * @param wif_key the private key in WIF format - * @returns true if the key was imported - * @ingroup WalletCLI + * @return \c true if the key was imported + * @ingroup WalletAPI_Wallet */ bool import_key(string account_name_or_id, string wif_key); /** - * @brief Imports accounts from the other wallet file - * @param filename The filename of the wallet JSON file - * @param password User's password to the wallet + * @brief Imports accounts from the other wallet file. + * @param filename the filename of the wallet JSON file + * @param password user's password to the wallet * @return mapped account names to boolean values indicating whether the account was successfully imported - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ map import_accounts( string filename, string password ); /** - * @brief Imports account keys from particular account from another wallet file to desired account located in wallet file currently used - * @param filename The filename of the wallet JSON file - * @param password User's password to the wallet - * @param src_account_name Name of the source account - * @param dest_account_name Name of the destination account - * @return true if the keys were imported - * @ingroup WalletCLI + * @brief Imports account keys from particular account from another wallet file to desired account located in wallet file currently used. + * @param filename the filename of the wallet JSON file + * @param password user's password to the wallet + * @param src_account_name name of the source account + * @param dest_account_name name of the destination account + * @return \c true if the keys were imported + * @ingroup WalletAPI_Wallet */ bool import_account_keys( string filename, string password, string src_account_name, string dest_account_name ); /** * @brief Transforms a brain key to reduce the chance of errors when re-entering the key from memory. - * * This takes a user-supplied brain key and normalizes it into the form used * for generating private keys. In particular, this upper-cases all ASCII characters * and collapses multiple spaces into one. * @param s the brain key as supplied by the user - * @returns the brain key in its normalized form - * @ingroup WalletCLI + * @return the brain key in its normalized form + * @ingroup WalletAPI_Account */ string normalize_brain_key(string s) const; /** * @brief Registers a third party's account on the blockckain. - * * This function is used to register an account for which you do not own the private keys. * When acting as a registrar, an end user will generate their own private keys and send * you the public keys. The registrar will use this function to register the account * on behalf of the end user. - * - * @see create_account_with_brain_key() - * - * @param name the name of the account, must be unique on the blockchain. Shorter names - * are more expensive to register; the rules are still in flux, but in general - * names of more than 8 characters with at least one digit will be cheap. + * @note The owner key represents absolute control over the account. Generally, the only time the owner key is required + * is to update the active key. + * @note The active key represents the hot key of the account. This key has control over nearly all + * operations the account may perform. + * @see suggest_brain_key() + * @param name the name of the account, must be unique on the blockchain and contains at least 5 characters * @param owner the owner key for the new account * @param active the active key for the new account * @param registrar_account the account which will pay the fee to register the user - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction registering the account - * @ingroup WalletCLI + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction registering the account + * @ingroup WalletAPI_Account */ signed_transaction register_account(string name, public_key_type owner, @@ -820,57 +804,48 @@ namespace graphene { namespace wallet { /** * @brief Creates a new account and registers it on the blockchain. - * - * @todo why no referrer_percent here? - * * @see suggest_brain_key() * @see register_account() - * * @param brain_key the brain key used for generating the account's private keys - * @param account_name the name of the account, must be unique on the blockchain. Shorter names - * are more expensive to register; the rules are still in flux, but in general - * names of more than 8 characters with at least one digit will be cheap. + * @param account_name the name of the account, must be unique on the blockchain and contains at least 5 characters * @param registrar_account the account which will pay the fee to register the user - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction registering the account - * @ingroup WalletCLI + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction registering the account + * @ingroup WalletAPI_Account */ signed_transaction create_account_with_brain_key(string brain_key, string account_name, string registrar_account, bool broadcast = false); /** - * @brief Creates a new account and registers it on the blockchain, but does not import the key to wallet. - * + * @brief Creates a new account and registers it on the blockchain, but does not import the key to the wallet. * @see suggest_brain_key() * @see register_account() - * * @param brain_key the brain key used for generating the account's private keys - * @param account_name the name of the account, must be unique on the blockchain. Shorter names - * are more expensive to register; the rules are still in flux, but in general - * names of more than 8 characters with at least one digit will be cheap. + * @param account_name the name of the account, must be unique on the blockchain and contains at least 5 characters * @param registrar_account the account which will pay the fee to register the user - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction registering the account - * @ingroup WalletCLI + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction registering the account + * @ingroup WalletAPI_Account */ signed_transaction create_account_with_brain_key_noimport(string brain_key, string account_name, string registrar_account, bool broadcast = false); - /** @brief Transfer an amount from one account to another. + /** + * @brief Transfer an amount from one account to another. * @param from the name or id of the account sending the funds * @param to the name or id of the account receiving the funds - * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) + * @param amount the amount to send (in nominal units -- to send half of a DCT, specify 0.5) * @param asset_symbol the symbol or id of the asset to send * @param memo a memo to attach to the transaction. The memo will be encrypted in the - * transaction and readable for the receiver. There is no length limit - * other than the limit imposed by maximum transaction size, but transaction - * increase with transaction size - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction transferring funds - * @ingroup WalletCLI + * transaction and readable for the receiver. There is no length limit + * other than the limit imposed by maximum transaction size. + * @note transaction fee is fixed and does not depend on the length of the memo + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction transferring funds + * @ingroup WalletAPI_General */ signed_transaction transfer(string from, string to, @@ -880,17 +855,17 @@ namespace graphene { namespace wallet { bool broadcast = false); /** - * @brief This method works just like transfer, except it always broadcasts and - * returns the transaction ID along with the signed transaction. - * @param from the name or id of the account sending the funds - * @param to the name or id of the account receiving the funds - * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) - * @param asset_symbol the symbol or id of the asset to send - * @param memo a memo to attach to the transaction. The memo will be encrypted in the - * transaction and readable for the receiver. There is no length limit - * other than the limit imposed by maximum transaction size, but transaction - * increase with transaction size - * @ingroup WalletCLI + * @brief This method works just like transfer, except it always broadcasts the transaction. + * @param from the name or id of the account sending the funds + * @param to the name or id of the account receiving the funds + * @param amount the amount to send (in nominal units -- to send half of a DCT, specify 0.5) + * @param asset_symbol the symbol or id of the asset to send + * @param memo a memo to attach to the transaction. The memo will be encrypted in the + * transaction and readable for the receiver. There is no length limit + * other than the limit imposed by maximum transaction size. + * @note transaction fee is fixed and does not depend on the lenght of the memo + * @return the transaction ID along with the signed transaction. + * @ingroup WalletAPI_General */ pair transfer2(string from, string to, @@ -903,19 +878,17 @@ namespace graphene { namespace wallet { /** * @brief Encapsulates begin_builder_transaction(), add_operation_to_builder_transaction(), - * propose_builder_transaction2(), set_fees_on_builder_transaction() functions for transfer operation - * - * @param proposer Proposer + * propose_builder_transaction2(), set_fees_on_builder_transaction() functions for transfer operation. + * @param proposer proposer * @param from the name or id of the account sending the funds * @param to the name or id of the account receiving the funds - * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) + * @param amount the amount to send (in nominal units -- to send half of a DCT, specify 0.5) * @param asset_symbol the symbol or id of the asset to send * @param memo a memo to attach to the transaction. The memo will be encrypted in the - * transaction and readable for the receiver. There is no length limit - * other than the limit imposed by maximum transaction size, but transaction - * increase with transaction size + * transaction and readable for the receiver. There is no length limit + * other than the limit imposed by maximum transaction size. * @param expiration expiration time - * @ingroup WalletCLI + * @ingroup WalletAPI_Proposals */ void propose_transfer(string proposer, string from, @@ -928,9 +901,9 @@ namespace graphene { namespace wallet { /** * @brief This method is used to convert a JSON transaction to its transaction ID. - * @param trx Signed transaction - * @return - * @ingroup WalletCLI + * @param trx signed transaction + * @return transaction ID + * @ingroup WalletAPI_General */ transaction_id_type get_transaction_id( const signed_transaction& trx )const { return trx.id(); } @@ -938,20 +911,18 @@ namespace graphene { namespace wallet { /** * @brief Creates a new monitored asset. - * - * Options can be changed later using \c update_monitored_asset() - * + * @note some parameters can be changed later using \c update_monitored_asset() * @param issuer the name or id of the account who will pay the fee and become the * issuer of the new asset. This can be updated later * @param symbol the ticker symbol of the new asset * @param precision the number of digits of precision to the right of the decimal point, * must be less than or equal to 12 - * @param description asset description. Maximal length is 1000 chars. + * @param description asset description. Maximal length is 1000 chars * @param feed_lifetime_sec time before a price feed expires * @param minimum_feeds minimum number of unexpired feeds required to extract a median feed from - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction creating a new asset - * @ingroup WalletCLI + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction creating a new asset + * @ingroup WalletAPI_Asset */ signed_transaction create_monitored_asset(string issuer, string symbol, @@ -962,18 +933,14 @@ namespace graphene { namespace wallet { bool broadcast = false); /** - * @brief Update the options specific to a monitored asset. - * - * Monitored assets have some options which are not relevant to other asset types. This operation is used to update those - * options and an existing monitored asset. - * - * @param symbol the name or id of the asset to update, which must be a market-issued asset + * @brief Update the parameters specific to a monitored asset. + * @param symbol the name or id of the asset to update, which must be a monitored asset * @param description asset description * @param feed_lifetime_sec time before a price feed expires * @param minimum_feeds minimum number of unexpired feeds required to extract a median feed from - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction updating the bitasset - * @ingroup WalletCLI + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction updating the monitored asset + * @ingroup WalletAPI_Asset */ signed_transaction update_monitored_asset(string symbol, string description, @@ -983,24 +950,23 @@ namespace graphene { namespace wallet { /** * @brief Creates a new user-issued asset. - * - * Options can be changed later using \c update_asset() - * + * @note Some parameters can be changed later using \c update_user_issued_asset() + * @see \c issue_asset() * @param issuer the name or id of the account who will pay the fee and become the * issuer of the new asset. This can be updated later * @param symbol the ticker symbol of the new asset * @param precision the number of digits of precision to the right of the decimal point, - * must be less than or equal to 12 + * must be less than or equal to 12 * @param description asset description. Maximal length is 1000 chars * @param max_supply the maximum supply of this asset which may exist at any given time - * @param core_exchange_rate Core_exchange_rate technically needs to store the asset ID of + * @param core_exchange_rate core_exchange_rate technically needs to store the asset ID of * this new asset. Since this ID is not known at the time this operation is * created, create this price as though the new asset has instance ID 1, and * the chain will overwrite it with the new asset's ID - * @param is_exchangeable True to allow implicit conversion of this asset to/from core asset - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction creating a new asset - * @ingroup WalletCLI + * @param is_exchangeable \c true to allow implicit conversion of this asset to/from core asset + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction creating a new asset + * @ingroup WalletAPI_Asset */ signed_transaction create_user_issued_asset(string issuer, string symbol, @@ -1011,14 +977,15 @@ namespace graphene { namespace wallet { bool is_exchangeable, bool broadcast = false); - /** Issue new shares of an asset. - * + /** + * @brief Issue new shares of an asset. * @param to_account the name or id of the account to receive the new shares * @param amount the amount to issue, in nominal units * @param symbol the ticker symbol of the asset to issue * @param memo a memo to include in the transaction, readable by the recipient - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction issuing the new shares + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction issuing the new shares + * @ingroup WalletAPI_Asset */ signed_transaction issue_asset(string to_account, string amount, @@ -1027,21 +994,18 @@ namespace graphene { namespace wallet { bool broadcast = false); /** - * @brief Update the options specific to a user issued asset. - * + * @brief Update the parameters specific to a user issued asset. * User issued assets have some options which are not relevant to other asset types. This operation is used to update those * options an an existing user issues asset. - * - * - * @param symbol the name or id of the asset to update, which must be a market-issued asset + * @param symbol the name or id of the asset to update, which must be a user-issued asset * @param new_issuer if the asset is to be given a new issuer, specify his ID here * @param description asset description - * @param max_supply The maximum supply of this asset which may exist at any given time - * @param core_exchange_rate Price used to convert non-core asset to core asset - * @param is_exchangeable True to allow implicit conversion of this asset to/from core asset - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction updating the bitasset - * @ingroup WalletCLI + * @param max_supply the maximum supply of this asset which may exist at any given time + * @param core_exchange_rate price used to convert non-core asset to core asset + * @param is_exchangeable \c true to allow implicit conversion of this asset to/from core asset + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction updating the user-issued asset + * @ingroup WalletAPI_Asset */ signed_transaction update_user_issued_asset(string symbol, string new_issuer, @@ -1051,22 +1015,18 @@ namespace graphene { namespace wallet { bool is_exchangeable, bool broadcast = false); - /** Pay into the pools for the given asset. - * - * User-issued assets can optionally have a pool of the core asset which is - * automatically used to pay transaction fees for any transaction using that - * asset (using the asset's core exchange rate). - * - * Allows anyone to deposit core/asset into pools. - * This pool are used when conversion between assets is needed (paying fees, paying for a content in different asset). - * + /** + * @brief Pay into the pools for the given asset. Allows anyone to deposit core/asset into pools. + * @note User-issued assets can optionally have two asset pools. + * This pools are used when conversion between assets is needed (paying fees, paying for a content in different asset ). * @param from the name or id of the account sending the core asset * @param uia_amount the amount of "this" asset to deposit * @param uia_symbol the name or id of the asset whose pool you wish to fund * @param dct_amount the amount of the core asset to deposit * @param dct_symbol the name or id of the DCT asset - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction funding the fee pool + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction funding the asset pools + * @ingroup WalletAPI_Asset */ signed_transaction fund_asset_pools(string from, string uia_amount, @@ -1075,30 +1035,32 @@ namespace graphene { namespace wallet { string dct_symbol, bool broadcast = false); - /** Burns the given user-issued asset. - * + /** + * @brief Burns the given user-issued asset. * This command burns the user-issued asset to reduce the amount in circulation. - * @note you cannot burn market-issued assets. + * @note you cannot burn monitored asset. * @param from the account containing the asset you wish to burn * @param amount the amount to burn, in nominal units * @param symbol the name or id of the asset to burn - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction burning the asset + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction burning the asset + * @ingroup WalletAPI_Asset */ signed_transaction reserve_asset(string from, string amount, string symbol, bool broadcast = false); - /** Transfers accumulated assets from pools back to the issuer's balance. - * - * @note you cannot claim assets from pools of market-issued asset. + /** + * @brief Transfers accumulated assets from pools back to the issuer's balance. + * @note You cannot claim assets from pools of monitored asset. * @param uia_amount the amount of "this" asset to claim, in nominal units * @param uia_symbol the name or id of the asset to claim * @param dct_amount the amount of DCT asset to claim, in nominal units * @param dct_symbol the name or id of the DCT asset to claim - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction claiming the fees + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction claiming the fees + * @ingroup WalletAPI_Asset */ signed_transaction claim_fees(string uia_amount, string uia_symbol, @@ -1109,25 +1071,24 @@ namespace graphene { namespace wallet { /** * @brief Converts asset into DCT, using actual price feed. * @param amount the amount to convert in nominal units - * @param asset_symbol the symbol or id of the asset to convert + * @param asset_symbol_or_id the symbol or id of the asset to convert * @return price in DCT + * @ingroup WalletAPI_Asset */ string price_to_dct(const string& amount, const string& asset_symbol_or_id); /** * @brief Publishes a price feed for the named asset. - * - * Price feed providers use this command to publish their price feeds for market-issued assets. A price feed is - * used to tune the market for a particular market-issued asset. For each value in the feed, the median across all + * Price feed providers use this command to publish their price feeds for monitored assets. A price feed is + * used to tune the market for a particular monitored asset. For each value in the feed, the median across all * miner feeds for that asset is calculated and the market for the asset is configured with the median of that * value. - * * @param publishing_account the account publishing the price feed * @param symbol the name or id of the asset whose feed we're publishing - * @param feed the price_feed object for particular market-issued asset - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction updating the price feed for the given asset - * @ingroup WalletCLI + * @param feed the price feed object for particular monitored asset + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction updating the price feed for the given asset + * @ingroup WalletAPI_Asset */ signed_transaction publish_asset_feed(string publishing_account, string symbol, @@ -1136,11 +1097,10 @@ namespace graphene { namespace wallet { /** * @brief Get a list of published price feeds by a miner. - * * @param account_name_or_id the name or id of the account - * @param count Maximum number of price feeds to fetch (must not exceed 100) - * @returns list of price feeds published by the miner - * @ingroup WalletCLI + * @param count maximum number of price feeds to fetch (must not exceed 100) + * @return list of price feeds published by the miner + * @ingroup WalletAPI_Asset */ multimap get_feeds_by_miner(const string& account_name_or_id, const uint32_t count); @@ -1148,39 +1108,35 @@ namespace graphene { namespace wallet { /** * @brief Lists all miners registered in the blockchain. * This returns a list of all account names that own miners, and the associated miner id, - * sorted by name. This lists miners whether they are currently voted in or not. - * - * Use the \c lowerbound and limit parameters to page through the list. To retrieve all miners, + * sorted by name. This lists miners whether they are currently voted in or not. + * Use the \c lowerbound and \c limit parameters to page through the list. To retrieve all miners, * start by setting \c lowerbound to the empty string \c "", and then each iteration, pass * the last miner name returned as the \c lowerbound for the next \c list_miners() call. - * * @param lowerbound the name of the first miner to return. If the named miner does not exist, * the list will start at the miner that comes after \c lowerbound * @param limit the maximum number of miners to return (max: 1000) - * @returns a list of miners mapping miner names to miner ids - * @ingroup WalletCLI + * @return a list of miners mapping miner names to miner ids + * @ingroup WalletAPI_Mining */ map list_miners(const string& lowerbound, uint32_t limit); /** - * s@brief Returns information about the given miner. + * @brief Returns information about the given miner. * @param owner_account the name or id of the miner account owner, or the id of the miner - * @returns the information about the miner stored in the block chain - * @ingroup WalletCLI + * @return the information about the miner stored in the block chain + * @ingroup WalletAPI_Mining */ miner_object get_miner(string owner_account); /** * @brief Creates a miner object owned by the given account. - * - * An account can have at most one miner object. - * + * @note an account can have at most one miner object. * @param owner_account the name or id of the account which is creating the miner * @param url a URL to include in the miner record in the blockchain. Clients may * display this when showing a list of miners. May be blank. - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction registering a miner - * @ingroup WalletCLI + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction registering a miner + * @ingroup WalletAPI_Mining */ signed_transaction create_miner(string owner_account, string url, @@ -1188,12 +1144,11 @@ namespace graphene { namespace wallet { /** * @brief Update a miner object owned by the given account. - * - * @param miner_name The name of the miner's owner account. Also accepts the ID of the owner account or the ID of the miner. + * @param miner_name The name of the miner's owner account. Also accepts the ID of the owner account or the ID of the miner. * @param url Same as for create_miner. The empty string makes it remain the same. - * @param block_signing_key The new block signing public key. The empty string makes it remain the same. - * @param broadcast true if you wish to broadcast the transaction. - * @ingroup WalletCLI + * @param block_signing_key the new block signing public key. The empty string makes it remain the same + * @param broadcast \c true if you wish to broadcast the transaction. + * @ingroup WalletAPI_Mining */ signed_transaction update_miner(string miner_name, string url, @@ -1202,20 +1157,18 @@ namespace graphene { namespace wallet { /** * @brief Get information about a vesting balance object. - * - * @param account_name An account name, account ID, or vesting balance object ID. - * @ingroup WalletCLI + * @param account_name an account name, account ID, or vesting balance object ID. + * @ingroup WalletAPI_Mining */ vector< vesting_balance_object_with_info > get_vesting_balances( string account_name ); /** * @brief Withdraw a vesting balance. - * - * @param miner_name The account name of the miner, also accepts account ID or vesting balance ID type. - * @param amount The amount to withdraw. - * @param asset_symbol The symbol of the asset to withdraw. - * @param broadcast true if you wish to broadcast the transaction - * @ingroup WalletCLI + * @param miner_name the account name of the miner, also accepts account ID or vesting balance ID type. + * @param amount the amount to withdraw. + * @param asset_symbol the symbol of the asset to withdraw + * @param broadcast \c true if you wish to broadcast the transaction + * @ingroup WalletAPI_Mining */ signed_transaction withdraw_vesting( string miner_name, @@ -1225,22 +1178,20 @@ namespace graphene { namespace wallet { /** * @brief Vote for a given miner. - * - * An account can publish a list of all miners they approve of. This + * An account can publish a list of all miners they approve of. This * command allows you to add or remove miners from this list. * Each account's vote is weighted according to the number of shares of the * core asset owned by that account at the time the votes are tallied. - * - * @note you cannot vote against a miner, you can only vote for the miner + * @note You cannot vote against a miner, you can only vote for the miner * or not vote for the miner. - * + * @see \c list_miners() * @param voting_account the name or id of the account who is voting with their shares * @param miner the name or id of the miner' owner account - * @param approve true if you wish to vote in favor of that miner, false to + * @param approve \c true if you wish to vote in favor of that miner, \c false to * remove your vote in favor of that miner - * @param broadcast true if you wish to broadcast the transaction + * @param broadcast \c true if you wish to broadcast the transaction * @return the signed transaction changing your vote for the given miner - * @ingroup WalletCLI + * @ingroup WalletAPI_Mining */ signed_transaction vote_for_miner(string voting_account, string miner, @@ -1249,23 +1200,18 @@ namespace graphene { namespace wallet { /** * @brief Set the voting proxy for an account. - * * If a user does not wish to take an active part in voting, they can choose * to allow another account to vote their stake. - * * Setting a vote proxy does not remove your previous votes from the blockchain, - * they remain there but are ignored. If you later null out your vote proxy, + * they remain there but are ignored. If you later null out your vote proxy, * your previous votes will take effect again. - * * This setting can be changed at any time. - * * @param account_to_modify the name or id of the account to update * @param voting_account the name or id of an account authorized to vote account_to_modify's shares, * or null to vote your own shares - * - * @param broadcast true if you wish to broadcast the transaction + * @param broadcast \c true if you wish to broadcast the transaction * @return the signed transaction changing your vote proxy settings - * @ingroup WalletCLI + * @ingroup WalletAPI_Mining */ signed_transaction set_voting_proxy(string account_to_modify, optional voting_account, @@ -1273,24 +1219,20 @@ namespace graphene { namespace wallet { /** * @brief Set your vote for the number of miners in the system. - * * Each account can voice their opinion on how many - * miners there should be in the active miner list. These - * are independent of each other. You must vote your approval of at least as many + * miners there should be in the active miner list. These + * are independent of each other. You must vote your approval of at least as many * miners as you claim there should be (you can't say that there should * be 20 miners but only vote for 10). - * * There are maximum values for each set in the blockchain parameters (currently * defaulting to 1001). - * - * This setting can be changed at any time. If your account has a voting proxy + * This setting can be changed at any time. If your account has a voting proxy * set, your preferences will be ignored. - * * @param account_to_modify the name or id of the account to update * @param desired_number_of_miners - * @param broadcast true if you wish to broadcast the transaction + * @param broadcast \c true if you wish to broadcast the transaction * @return the signed transaction changing your vote proxy settings - * @ingroup WalletCLI + * @ingroup WalletAPI_Mining */ signed_transaction set_desired_miner_count(string account_to_modify, uint16_t desired_number_of_miners, @@ -1298,48 +1240,40 @@ namespace graphene { namespace wallet { /** * @brief Signs a transaction. - * * Given a fully-formed transaction that is only lacking signatures, this signs * the transaction with the necessary keys and optionally broadcasts the transaction * @param tx the unsigned transaction - * @param broadcast true if you wish to broadcast the transaction + * @param broadcast \c true if you wish to broadcast the transaction * @return the signed version of the transaction - * @ingroup WalletCLI + * @ingroup WalletAPI_TransactionBuilder */ signed_transaction sign_transaction(signed_transaction tx, bool broadcast = false); /** * @brief Returns an uninitialized object representing a given blockchain operation. - * - * This returns a default-initialized object of the given type; it can be used - * during early development of the wallet when we don't yet have custom commands for - * creating all of the operations the blockchain supports. - * + * This returns a default-initialized object of the given type. * Any operation the blockchain supports can be created using the transaction builder's * \c add_operation_to_builder_transaction() , but to do that from the CLI you need to - * know what the JSON form of the operation looks like. This will give you a template - * you can fill in. It's better than nothing. - * + * know what the JSON form of the operation looks like. This will give you a template + * you can fill in. * @param operation_type the type of operation to return, must be one of the * operations defined in `graphene/chain/operations.hpp` * (e.g., "global_parameters_update_operation") * @return a default-constructed operation of the given type - * @ingroup WalletCLI + * @ingroup WalletAPI_TransactionBuilder */ operation get_prototype_operation(string operation_type); /** * @brief Creates a transaction to propose a parameter change. - * * Multiple parameters can be specified if an atomic change is * desired. - * - * @param proposing_account The account paying the fee to propose the tx - * @param expiration_time Timestamp specifying when the proposal will either take effect or expire. - * @param changed_values The values to change; all other chain parameters are filled in with default values - * @param broadcast true if you wish to broadcast the transaction + * @param proposing_account the account paying the fee to propose the transaction + * @param expiration_time timestamp specifying when the proposal will either take effect or expire + * @param changed_values the values to change; all other chain parameters are filled in with default values + * @param broadcast \c true if you wish to broadcast the transaction * @return the signed version of the transaction - * @ingroup WalletCLI + * @ingroup WalletAPI_Proposals */ signed_transaction propose_parameter_change( const string& proposing_account, @@ -1349,14 +1283,13 @@ namespace graphene { namespace wallet { /** * @brief Propose a fee change. - * - * @param proposing_account The account paying the fee to propose the tx - * @param expiration_time Timestamp specifying when the proposal will either take effect or expire. - * @param changed_values Map of operation type to new fee. Operations may be specified by name or ID. - * The "scale" key changes the scale. All other operations will maintain current values. - * @param broadcast true if you wish to broadcast the transaction + * @param proposing_account the account paying the fee to propose the transaction + * @param expiration_time timestamp specifying when the proposal will either take effect or expire + * @param changed_values map of operation type to new fee. Operations may be specified by name or ID + * The "scale" key changes the scale. All other operations will maintain current values + * @param broadcast \c true if you wish to broadcast the transaction * @return the signed version of the transaction - * @ingroup WalletCLI + * @ingroup WalletAPI_Proposals */ signed_transaction propose_fee_change( const string& proposing_account, @@ -1365,17 +1298,13 @@ namespace graphene { namespace wallet { bool broadcast = false); /** - * - * - * * @brief Approve or disapprove a proposal. - * - * @param fee_paying_account The account paying the fee for the op. - * @param proposal_id The proposal to modify. - * @param delta Members contain approvals to create or remove. In JSON you can leave empty members undefined. - * @param broadcast true if you wish to broadcast the transaction + * @param fee_paying_account the account paying the fee for the operation + * @param proposal_id the proposal to modify + * @param delta members contain approvals to create or remove. In JSON you can leave empty members undefined + * @param broadcast \c true if you wish to broadcast the transaction * @return the signed version of the transaction - * @ingroup WalletCLI + * @ingroup WalletAPI_Proposals */ signed_transaction approve_proposal( const string& fee_paying_account, @@ -1385,61 +1314,56 @@ namespace graphene { namespace wallet { ); /** - * * @param creator * @param symbol - * @ingroup WalletCLI + * @ingroup WalletAPI_Debug */ void dbg_make_mia(string creator, string symbol); /** - * * @param src_filename * @param count - * @ingroup WalletCLI + * @ingroup WalletAPI_Debug */ void dbg_push_blocks( std::string src_filename, uint32_t count ); /** - * * @param debug_wif_key * @param count - * @ingroup WalletCLI + * @ingroup WalletAPI_Debug */ void dbg_generate_blocks( std::string debug_wif_key, uint32_t count ); /** - * * @param filename - * @ingroup WalletCLI + * @ingroup WalletAPI_Debug */ void dbg_stream_json_objects( const std::string& filename ); /** - * * @param update - * @ingroup WalletCLI + * @ingroup WalletAPI_Debug */ void dbg_update_object( fc::variant_object update ); /** - * + * @brief * @param prefix * @param number_of_transactions - * @ingroup WalletCLI + * @ingroup WalletAPI_Network */ void flood_network(string prefix, uint32_t number_of_transactions); /** - * + * @brief * @param nodes - * @ingroup WalletCLI + * @ingroup WalletAPI_Network */ void network_add_nodes( const vector& nodes ); /** - * - * @ingroup WalletCLI + * @brief + * @ingroup WalletAPI_Network */ vector< variant > network_get_connected_peers(); @@ -1451,8 +1375,9 @@ namespace graphene { namespace wallet { void encrypt_keys(); /** - * Get current supply of the core asset - * @ingroup WalletCLI + * @brief Get current supply of the core asset + * @return the number of shares currently in existence in account and vesting balances, escrows and pools + * @ingroup WalletAPI_Asset */ real_supply get_real_supply()const; @@ -1460,12 +1385,12 @@ namespace graphene { namespace wallet { * @brief This method is used to promote account to publishing manager. * Such an account can grant or remove right to publish a content. Only DECENT account has permission to use this method. * @see set_publishing_right() - * @param from Account ( DECENT account ) giving/removing status of the publishing manager. - * @param to List of accounts getting status of the publishing manager. - * @param is_allowed True to give the status, false to remove it - * @param broadcast True to broadcast the transaction on the network - * @return The signed transaction updating account status - * @ingroup WalletCLI + * @param from account ( DECENT account ) giving/removing status of the publishing manager. + * @param to list of accounts getting status of the publishing manager. + * @param is_allowed \c true to give the status, \c false to remove it + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction updating account status + * @ingroup WalletAPI_Content */ signed_transaction set_publishing_manager(const string from, const vector to, @@ -1475,12 +1400,12 @@ namespace graphene { namespace wallet { /** * @brief Allows account to publish a content. Only account with publishing manager status has permission to use this method. * @see set_publishing_manager() - * @param from Account giving/removing right to publish a content. - * @param to List of accounts getting right to publish a content. - * @param is_allowed True to give the right, false to remove it - * @param broadcast True to broadcast the transaction on the network - * @return The signed transaction updating account status - * @ingroup WalletCLI + * @param from account giving/removing right to publish a content. + * @param to list of accounts getting right to publish a content. + * @param is_allowed \c true to give the right, \c false to remove it + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction updating account status + * @ingroup WalletAPI_Content */ signed_transaction set_publishing_right(const string from, const vector to, @@ -1489,35 +1414,36 @@ namespace graphene { namespace wallet { /** * @brief Get a list of accounts holding publishing manager status. - * @param lower_bound_name The name of the first account to return. If the named account does not exist, + * @param lower_bound_name the name of the first account to return. If the named account does not exist, * the list will start at the account that comes after \c lowerbound - * @param limit The maximum number of accounts to return (max: 100) - * @return List of accounts - * @ingroup WalletCLI + * @param limit the maximum number of accounts to return (max: 100) + * @return a list of publishing managers + * @ingroup WalletAPI_Content */ vector list_publishing_managers( const string& lower_bound_name, uint32_t limit ); /** - * @brief Submits or resubmits content to the blockchain. In a case of resubmit, co-authors, price and synopsis fields + * @brief Submits or resubmits a content to the blockchain. In a case of resubmit, co-authors, price and synopsis fields * can be modified. - * @see submit_content_new() - * @param author The author of the content - * @param co_authors The co-authors' account name or ID mapped to corresponding payment split based on basis points - * @param URI The URI of the content - * @param price_amounts The price of the content per regions - * @param size The size of the content - * @param hash The Hash of the package - * @param seeders List of the seeders, which will publish the content - * @param quorum Defines number of seeders needed to restore the encryption key - * @param expiration The expiration time of the content. The content is available to buy till it's expiration time - * @param publishing_fee_asset Ticker symbol of the asset which will be used to publish content - * @param publishing_fee_amount Publishing price - * @param synopsis The description of the content - * @param secret The AES key used to encrypt and decrypt the content - * @param cd Custody data - * @param broadcast true to broadcast the transaction on the network - * @return The signed transaction submitting the content - * @ingroup WalletCLI + * @see \c generate_encryption_key() + * @see \c submit_content_async() + * @param author the author of the content + * @param co_authors the co-authors' account name or ID mapped to corresponding payment split based on basis points. The maximum number of co-authors is 10 + * @param URI the URI of the content + * @param price_amounts the price of the content per regions + * @param size the size of the content + * @param hash the Hash of the package + * @param seeders list of the seeders, which will publish the content + * @param quorum defines number of seeders needed to restore the encryption key + * @param expiration the expiration time of the content. The content is available to buy till it's expiration time + * @param publishing_fee_asset ticker symbol of the asset which will be used to publish content + * @param publishing_fee_amount publishing price + * @param synopsis the description of the content + * @param secret the AES key used to encrypt and decrypt the content + * @param cd custody data + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction submitting the content + * @ingroup WalletAPI_Content */ signed_transaction submit_content(string const& author, @@ -1537,23 +1463,21 @@ namespace graphene { namespace wallet { bool broadcast); /** - * @brief This function is used to create package, upload package and submit content in one step. + * @brief This function is used to create and upload a package and submit content in one step. * @see create_package() * @see upload_package() * @see submit_content() - * @param author The author of the content - * @param co_authors The co-authors' account name or ID mapped to corresponding payment split based on basis points - * @param content_dir Path to the directory containing all content that should be packed - * @param samples_dir Path to the directory containing samples of content - * @param protocol Protocol for uploading package( ipfs ) - * @param price_amounts The prices of the content per regions - * @param seeders List of the seeders, which will publish the content - * @param expiration The expiration time of the content. The content is available to buy till it's expiration time - * @param synopsis The description of the content - * @return The signed transaction submitting the content - * @ingroup WalletCLI + * @param author the author of the content + * @param co_authors the co-authors' account name or ID mapped to corresponding payment split based on basis points. The maximum number of co-authors is 10 + * @param content_dir path to the directory containing all content that should be packed + * @param samples_dir path to the directory containing samples of content + * @param protocol protocol for uploading package( ipfs ) + * @param price_amounts the prices of the content per regions + * @param seeders list of the seeders, which will publish the content + * @param expiration the expiration time of the content. The content is available to buy till it's expiration time + * @param synopsis the description of the content + * @ingroup WalletAPI_Content */ - void submit_content_async( string const &author, vector< pair< string, uint32_t>> co_authors, string const &content_dir, @@ -1567,12 +1491,12 @@ namespace graphene { namespace wallet { /** * @brief This function can be used to cancel submitted content. This content is immediately not available to purchase. - * Seeders keep seeding this content in next 24 hours. - * @param author The author of the content - * @param URI The URI of the content - * @param broadcast True to broadcast the transaction on the network - * @ingroup WalletCLI - * @return signed transaction + * Seeders keep seeding this content up to next 24 hours. + * @param author the author of the content + * @param URI the URI of the content + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction cancelling the content + * @ingroup WalletAPI_Content */ signed_transaction content_cancellation(string author, string URI, @@ -1580,33 +1504,33 @@ namespace graphene { namespace wallet { /** * @brief Downloads encrypted content specified by provided URI. - * @param consumer Consumer of the content - * @param URI The URI of the content - * @param region_code_from Two letter region code - * @param broadcast true to broadcast the transaction on the network - * @ingroup WalletCLI + * @param consumer consumer of the content + * @param URI the URI of the content + * @param region_code_from two letter region code + * @param broadcast \c true to broadcast the transaction on the network + * @ingroup WalletAPI_Content */ void download_content(string const& consumer, string const& URI, string const& region_code_from, bool broadcast = false); /** * @brief Get status about particular download process specified by provided URI. - * @param consumer Consumer of the content - * @param URI The URI of the content - * @return Download status, or null if no matching download process was found - * @ingroup WalletCLI + * @param consumer consumer of the content + * @param URI the URI of the content + * @return download status, or \c null if no matching download process was found + * @ingroup WalletAPI_Content */ optional get_download_status(string consumer, string URI) const; /** * @brief This function is used to send a request to buy a content. This request is caught by seeders. - * @param consumer Consumer of the content - * @param URI The URI of the content - * @param price_asset_name Ticker symbol of the asset which will be used to buy content - * @param price_amount The price of the content - * @param str_region_code_from Two letter region code - * @param broadcast true to broadcast the transaction on the network - * @return The signed transaction requesting buying of the content - * @ingroup WalletCLI + * @param consumer consumer of the content + * @param URI the URI of the content + * @param price_asset_name ticker symbol of the asset which will be used to buy content + * @param price_amount the price of the content + * @param str_region_code_from two letter region code + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction requesting buying of the content + * @ingroup WalletAPI_Content */ signed_transaction request_to_buy(string consumer, string URI, @@ -1617,14 +1541,14 @@ namespace graphene { namespace wallet { /** * @brief This method allows user to start seeding plugin from running application - * @param account_id_type_or_name Name or ID of account controlling this seeder + * @param account_id_type_or_name name or ID of account controlling this seeder * @param content_private_key El Gamal content private key - * @param seeder_private_key Private key of the account controlling this seeder - * @param free_space Allocated disk space, in MegaBytes + * @param seeder_private_key private key of the account controlling this seeder + * @param free_space allocated disk space, in MegaBytes * @param seeding_price price per MegaByte - * @param packages_path Packages storage path - * @param region_code Optional ISO 3166-1 alpha-2 two-letter region code - * @ingroup WalletCLI + * @param packages_path packages storage path + * @param region_code optional ISO 3166-1 alpha-2 two-letter region code + * @ingroup WalletAPI_Seeding */ void seeding_startup( string account_id_type_or_name, DInteger content_private_key, @@ -1636,12 +1560,12 @@ namespace graphene { namespace wallet { /** * @brief Rates and comments a content. - * @param consumer Consumer giving the rating - * @param URI The URI of the content - * @param rating Rating - * @param comment Comment - * @param broadcast true to broadcast the transaction on the network - * @ingroup WalletCLI + * @param consumer consumer giving the rating + * @param URI the URI of the content + * @param rating the rating. The available options are 1-5 + * @param comment the maximum length of a comment is 100 characters + * @param broadcast \c true to broadcast the transaction on the network + * @ingroup WalletAPI_Content */ void leave_rating_and_comment(string consumer, string URI, @@ -1651,13 +1575,13 @@ namespace graphene { namespace wallet { /** * @brief Creates a subscription to author. This function is used by consumers. - * @param from Account who wants subscription to author - * @param to The author you wish to subscribe to - * @param price_amount Price for the subscription - * @param price_asset_symbol Ticker symbol of the asset which will be used to buy subscription ( must be DCT token ) - * @param broadcast True if you wish to broadcast the transaction - * @return The signed transaction subscribing the consumer to the author - * @ingroup WalletCLI + * @param from account who wants subscription to author + * @param to the author you wish to subscribe to + * @param price_amount price for the subscription + * @param price_asset_symbol ticker symbol of the asset which will be used to buy subscription + * @param broadcast \c true if you wish to broadcast the transaction + * @return the signed transaction subscribing the consumer to the author + * @ingroup WalletAPI_Subscription */ signed_transaction subscribe_to_author( string from, string to, @@ -1667,11 +1591,11 @@ namespace graphene { namespace wallet { /** * @brief Creates a subscription to author. This function is used by author. - * @param from The account obtaining subscription from the author - * @param to The name or id of the author - * @param broadcast True if you wish to broadcast the transaction - * @return The signed transaction subscribing the consumer to the author - * @ingroup WalletCLI + * @param from the account obtaining subscription from the author + * @param to the name or id of the author + * @param broadcast \c true if you wish to broadcast the transaction + * @return the signed transaction subscribing the consumer to the author + * @ingroup WalletAPI_Subscription */ signed_transaction subscribe_by_author( string from, string to, @@ -1679,14 +1603,14 @@ namespace graphene { namespace wallet { /** * @brief This function can be used to allow/disallow subscription. - * @param account The name or id of the account to update - * @param allow_subscription True if account (author) wants to allow subscription, false otherwise - * @param subscription_period Duration of subscription in days - * @param price_amount Price for subscription per one subscription period - * @param price_asset_symbol Ticker symbol of the asset which will be used to buy subscription - * @param broadcast True if you wish to broadcast the transaction - * @return The signed transaction updating the account - * @ingroup WalletCLI + * @param account the name or id of the account to update + * @param allow_subscription \c true if account (author) wants to allow subscription, \c false otherwise + * @param subscription_period duration of subscription in days + * @param price_amount price for subscription per one subscription period + * @param price_asset_symbol ticker symbol of the asset which will be used to buy subscription + * @param broadcast \c true if you wish to broadcast the transaction + * @return the signed transaction updating the account + * @ingroup WalletAPI_Subscription */ signed_transaction set_subscription( string account, bool allow_subscription, @@ -1697,12 +1621,12 @@ namespace graphene { namespace wallet { /** * @brief This function can be used to allow/disallow automatic renewal of expired subscription. - * @param account_id_or_name The name or id of the account to update - * @param subscription_id The ID of the subscription. - * @param automatic_renewal True if account (consumer) wants to allow automatic renewal of subscription, false otherwise - * @param broadcast True if you wish to broadcast the transaction - * @return The signed transaction allowing/disallowing renewal of the subscription - * @ingroup WalletCLI + * @param account_id_or_name the name or id of the account to update + * @param subscription_id the ID of the subscription. + * @param automatic_renewal \c true if account (consumer) wants to allow automatic renewal of subscription, \c false otherwise + * @param broadcast \c true if you wish to broadcast the transaction + * @return the signed transaction allowing/disallowing renewal of the subscription + * @ingroup WalletAPI_Subscription */ signed_transaction set_automatic_renewal_of_subscription( string account_id_or_name, subscription_id_type subscription_id, @@ -1711,111 +1635,110 @@ namespace graphene { namespace wallet { /** * @brief Get a list of consumer's active (not expired) subscriptions. - * @param account_id_or_name The name or id of the consumer - * @param count Maximum number of subscriptions to fetch (must not exceed 100) - * @return List of active subscription objects corresponding to the provided consumer - * @ingroup WalletCLI + * @param account_id_or_name the name or id of the consumer + * @param count maximum number of subscriptions to fetch (must not exceed 100) + * @return list of active subscription objects corresponding to the provided consumer + * @ingroup WalletAPI_Subscription */ vector< subscription_object > list_active_subscriptions_by_consumer( const string& account_id_or_name, const uint32_t count)const; /** * @brief Get a list of consumer's subscriptions. - * @param account_id_or_name The name or id of the consumer - * @param count Maximum number of subscriptions to fetch (must not exceed 100) - * @return List of subscription objects corresponding to the provided consumer - * @ingroup WalletCLI + * @param account_id_or_name the name or id of the consumer + * @param count maximum number of subscriptions to fetch (must not exceed 100) + * @return list of subscription objects corresponding to the provided consumer + * @ingroup WalletAPI_Subscription */ vector< subscription_object > list_subscriptions_by_consumer( const string& account_id_or_name, const uint32_t count)const; /** * @brief Get a list of active (not expired) subscriptions to author. - * @param account_id_or_name The name or id of the author - * @param count Maximum number of subscriptions to fetch (must not exceed 100) - * @return List of active subscription objects corresponding to the provided author - * @ingroup WalletCLI + * @param account_id_or_name the name or id of the author + * @param count maximum number of subscriptions to fetch (must not exceed 100) + * @return list of active subscription objects corresponding to the provided author + * @ingroup WalletAPI_Subscription */ vector< subscription_object > list_active_subscriptions_by_author( const string& account_id_or_name, const uint32_t count)const; /** * @brief Get a list of subscriptions to author. - * @param account_id_or_name The name or id of the author - * @param count Maximum number of subscriptions to fetch (must not exceed 100) - * @return List of subscription objects corresponding to the provided author - * @ingroup WalletCLI + * @param account_id_or_name the name or id of the author + * @param count maximum number of subscriptions to fetch (must not exceed 100) + * @return list of subscription objects corresponding to the provided author + * @ingroup WalletAPI_Subscription */ vector< subscription_object > list_subscriptions_by_author( const string& account_id_or_name, const uint32_t count)const; /** - * @brief Restores AES key( used to encrypt and decrypt a content) from key particles stored in a buying object - * @param account Consumers account id or name - * @param buying The buying object containing key particles - * @return restored AES key from particles - * @ingroup WalletCLI + * @brief Restores AES key( used to encrypt and decrypt a content) from key particles stored in a buying object. + * @param account consumers account id or name + * @param buying the buying object containing key particles + * @return restored AES key from key particles + * @ingroup WalletAPI_Content */ DInteger restore_encryption_key(std::string account, buying_id_type buying); /** - * @brief Generates private ElGamal key and corresponding public key. - * @return Pair of ElGamal keys - * @ingroup WalletCLI + * @brief Generates private El Gamal key and corresponding public key. + * @return pair of El Gamal keys + * @ingroup WalletAPI_Account */ el_gamal_key_pair generate_el_gamal_keys() const; /** - * @brief Gets unique ElGamal key pair for consumer. - * @return Pair of ElGamal keys - * @ingroup WalletCLI + * @brief Gets unique El Gamal key pair for consumer. + * @return pair of El Gamal keys + * @ingroup WalletAPI_Account */ el_gamal_key_pair_str get_el_gammal_key(string const& consumer) const; - /** * @brief Generates AES encryption key. - * @return Random encryption key - * @ingroup WalletCLI + * @return random encryption key + * @ingroup WalletAPI_Content */ DInteger generate_encryption_key() const; /** - * @brief Get a list of open buyings - * @return Open buying objects - * @ingroup WalletCLI + * @brief Get a list of open buyings. + * @return a list of open buying objects + * @ingroup WalletAPI_Content */ vector get_open_buyings()const; /** - * @brief Get a list of open buyings by URI + * @brief Get a list of open buyings by URI. * @param URI URI of the buyings to retrieve - * @return Open buyings corresponding to the provided URI - * @ingroup WalletCLI + * @return a list of open buying objects corresponding to the provided URI + * @ingroup WalletAPI_Content */ vector get_open_buyings_by_URI( const string& URI )const; /** - * @brief Get a list of open buyings by consumer - * @param account_id_or_name Consumer of the buyings to retrieve - * @return Open buyings corresponding to the provided consumer - * @ingroup WalletCLI + * @brief Get a list of open buyings by consumer. + * @param account_id_or_name consumer of the buyings to retrieve + * @return a list of open buying objects corresponding to the provided consumer + * @ingroup WalletAPI_Content */ vector get_open_buyings_by_consumer( const string& account_id_or_name )const; /** - * @brief Get history buyings by consumer - * @param account_id_or_name Consumer of the buyings to retrieve - * @return History buying objects corresponding to the provided consumer - * @ingroup WalletCLI + * @brief Get history buyings by consumer. + * @param account_id_or_name consumer of the buyings to retrieve + * @return a list of history buying objects corresponding to the provided consumer + * @ingroup WalletAPI_Content */ vector get_buying_history_objects_by_consumer( const string& account_id_or_name )const; /** - * @brief Get history buying objects by consumer that match search term - * @param account_id_or_name Consumer of the buyings to retrieve - * @param term Search term to look up in Title and Description - * @param order Sort data by field - * @param id Object_id to start searching from - * @param count Maximum number of contents to fetch (must not exceed 100) - * @return History buying objects corresponding to the provided consumer and matching search term - * @ingroup WalletCLI + * @brief Get history buying objects by consumer that match search term. + * @param account_id_or_name consumer of the buyings to retrieve + * @param term search term to look up in \c title and \c description + * @param order sort data by field + * @param id object id to start searching from + * @param count maximum number of contents to fetch (must not exceed 100) + * @return a list of history buying objects corresponding to the provided consumer and matching search term + * @ingroup WalletAPI_Content */ vector search_my_purchases(const string& account_id_or_name, const string& term, @@ -1824,22 +1747,22 @@ namespace graphene { namespace wallet { uint32_t count) const; /** - * @brief Get buying (open or history) by consumer and URI - * @param account_id_or_name Consumer of the buying to retrieve - * @param URI URI of the buying to retrieve - * @return Buying_objects corresponding to the provided consumer, or null if no matching buying was found - * @ingroup WalletCLI + * @brief Get buying object (open or history) by consumer and URI. + * @param account_id_or_name consumer of the buying to retrieve + * @param URI the URI of the buying to retrieve + * @return buying objects corresponding to the provided consumer, or null if no matching buying was found + * @ingroup WalletAPI_Content */ optional get_buying_by_consumer_URI( const string& account_id_or_name, const string & URI )const; /** - * @brief Search for term in contents (author, title and description) - * @param user Feedback author - * @param URI The content object URI - * @param id The id of feedback object to start searching from - * @param count Maximum number of feedbacks to fetch - * @return The feedback found - * @ingroup WalletCLI + * @brief Search for term in users' feedbacks. + * @param user the author of the feedback + * @param URI the content object URI + * @param id the id of feedback object to start searching from + * @param count maximum number of feedbacks to fetch + * @return the feedback found + * @ingroup WalletAPI_Content */ vector search_feedback(const string& user, const string& URI, @@ -1847,24 +1770,24 @@ namespace graphene { namespace wallet { uint32_t count) const; /** - * @brief Get a content by URI - * @param URI URI of the content to retrieve - * @return The content corresponding to the provided URI, or null if no matching content was found - * @ingroup WalletCLI + * @brief Get a content by URI. + * @param URI the URI of the content to retrieve + * @return the content corresponding to the provided URI, or \c null if no matching content was found + * @ingroup WalletAPI_Content */ optional get_content( const string& URI )const; /** - * @brief Get a list of contents ordered alphabetically by search term - * @param term Search term - * @param order Order field - * @param user Content owner - * @param region_code Two letter region code - * @param id The id of content object to start searching from - * @param type The application and content type to be filtered - * @param count Maximum number of contents to fetch (must not exceed 100) - * @return The contents found - * @ingroup WalletCLI + * @brief Get a list of contents ordered alphabetically by search term. + * @param term search term + * @param order order field + * @param user content owner + * @param region_code two letter region code + * @param id the id of content object to start searching from + * @param type the application and content type to be filtered + * @param count maximum number of contents to fetch (must not exceed 100) + * @return the contents found + * @ingroup WalletAPI_Content */ vector search_content(const string& term, const string& order, @@ -1874,16 +1797,16 @@ namespace graphene { namespace wallet { const string& type, uint32_t count )const; /** - * @brief Get a list of contents ordered alphabetically by search term - * @param user Content owner - * @param term Search term - * @param order Order field - * @param region_code Two letter region code - * @param id The id of content object to start searching from - * @param type The application and content type to be filtered - * @param count Maximum number of contents to fetch (must not exceed 100) - * @return The contents found - * @ingroup WalletCLI + * @brief Get a list of contents ordered alphabetically by search term. + * @param user content owner + * @param term search term + * @param order order field + * @param region_code two letter region code + * @param id the id of content object to start searching from + * @param type the application and content type to be filtered + * @param count maximum number of contents to fetch (must not exceed 100) + * @return the contents found + * @ingroup WalletAPI_Content */ vector search_user_content(const string& user, const string& term, @@ -1894,149 +1817,161 @@ namespace graphene { namespace wallet { uint32_t count )const; /** - * @brief Get a list of seeders by price, in increasing order - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup WalletCLI + * @brief Get a list of seeders by price, in increasing order. + * @param count maximum number of seeders to retrieve + * @return a list of seeders + * @ingroup WalletAPI_Seeding */ vector list_seeders_by_price( uint32_t count )const; /** - * @brief Get a list of seeders ordered by total upload, in decreasing order - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup WalletCLI + * @brief Get a list of seeders ordered by total upload, in decreasing order. + * @param count maximum number of seeders to retrieve + * @return a list of seeders + * @ingroup WalletAPI_Seeding */ optional> list_seeders_by_upload( const uint32_t count )const; /** - * @brief Get a list of seeders by region code - * @param region_code Region code of seeders to retrieve - * @return The seeders found - * @ingroup WalletCLI + * @brief Get a list of seeders by region code. + * @param region_code region code of seeders to retrieve + * @return a list of seeders + * @ingroup WalletAPI_Seeding */ vector list_seeders_by_region( const string region_code )const; /** - * @brief Get a list of seeders ordered by rating, in decreasing order - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup WalletCLI + * @brief Get a list of seeders ordered by rating, in decreasing order. + * @param count the maximum number of seeders to retrieve + * @return a list of seeders + * @ingroup WalletAPI_Seeding */ vector list_seeders_by_rating( const uint32_t count )const; /** - * @brief Get author and list of co-authors of a content corresponding to the provided URI - * @param URI URI of the content - * @return The autor of the content and the list of co-authors, if provided + * @brief Get author and list of co-authors of a content corresponding to the provided URI. + * @param URI the URI of the content + * @return the autor of the content and the list of co-authors, if provided + * @ingroup WalletAPI_Content */ pair> get_author_and_co_authors_by_URI( const string& URI )const; /** - * @brief Create package from selected files - * @param content_dir Directory containing all content that should be packed - * @param samples_dir Directory containing samples of content - * @param aes_key AES key for encryption - * @return package hash (ripemd160 hash of package content) and content custody data - * @ingroup WalletCLI + * @brief Creates a package from selected files. + * @see \c upload_package() + * @param content_dir the directory containing all content that should be packed + * @param samples_dir the directory containing samples of the content + * @param aes_key the AES key for encryption + * @return the package hash and content custody data + * @ingroup WalletAPI_Content */ std::pair create_package(const std::string& content_dir, const std::string& samples_dir, const DInteger& aes_key) const; /** - * @brief Extract selected package - * @param package_hash Hash of package that needs to be extracted - * @param output_dir Directory where extracted files will be created - * @param aes_key AES key for decryption - * @ingroup WalletCLI + * @brief Extracts selected package. + * @see \c download_package() + * @param package_hash hash of the package that needs to be extracted + * @param output_dir directory where extracted files will be created + * @param aes_key the AES key for decryption + * @ingroup WalletAPI_Content */ void extract_package(const std::string& package_hash, const std::string& output_dir, const DInteger& aes_key) const; /** - * @brief Download package - * @param url Magnet or IPFS URL of package - * @ingroup WalletCLI + * @brief Downloads the package. + * @param url the URL of the package + * @ingroup WalletAPI_Content */ void download_package(const std::string& url) const; /** - * @brief Start uploading package - * @param package_hash Hash of package that needs to be extracted + * @brief Starts uploading of the package. + * @see \c create_package() + * @param package_hash hash of the package that needs to be extracted * @param protocol protocol for uploading package ( ipfs ) - * @ingroup WalletCLI + * @return URL of package + * @ingroup WalletAPI_Content */ std::string upload_package(const std::string& package_hash, const std::string& protocol) const; /** - * @brief Remove package - * @param package_hash Hash of package that needs to be removed - * @ingroup WalletCLI + * @brief Removes the package. + * @param package_hash hash of the package that needs to be removed + * @ingroup WalletAPI_Content */ void remove_package(const std::string& package_hash) const; /** - * @brief Print statuses of all active transfers - * @ingroup WalletCLI + * @brief Print statuses of all active transfers. + * @param enable \c true to enable transfer logging + * @ingroup WalletAPI_Debug */ - void set_transfer_logs(bool enable) const; /** - * @brief Sign a buffer - * @param str_buffer The buffer to be signed - * @param str_brainkey Derives the private key used for signature - * @return The signed buffer - * @ingroup WalletCLI + * @brief Sign a buffer. + * @param str_buffer the buffer to be signed + * @param str_brainkey derives the private key used for signature + * @return the signed buffer + * @ingroup WalletAPI_Debug */ std::string sign_buffer(std::string const& str_buffer, std::string const& str_brainkey) const; /** - * @brief Verify if the signature is valid - * @param str_buffer The original buffer - * @param str_publickey The public key used for verification - * @param str_signature The signed buffer - * @return true if valid, otherwise false - * @ingroup WalletCLI + * @brief Verify if the signature is valid. + * @param str_buffer the original buffer + * @param str_publickey the public key used for verification + * @param str_signature the signed buffer + * @return \c true if valid, otherwise \c false + * @ingroup WalletAPI_Debug */ bool verify_signature(std::string const& str_buffer, std::string const& str_publickey, std::string const& str_signature) const; /** - * @brief Query the last local block + * @brief Query the last local block. * @return the block time + * @ingroup WalletAPI_General */ fc::time_point_sec head_block_time() const; - /** - * @brief Send text message + /** + * @brief Sends a text message to one or many users. + * @param from account sending the message + * @param to account or multiple accounts receiving the message + * @param text the body of the message + * @ingroup WalletAPI_Messaging */ - void send_message(const std::string& from, std::vector to, string text); /** - * @brief Receives message objects by sender and/or receiver - * @param reveiver Name of message sender. If you dont want to filter by sender then let it empty. - * @param reveiver Name of message receiver. If you dont want to filter by receiver then let it empty. - * @param max_count Maximal number of last messages to be displayed - * @return vector of message objects + * @brief Receives message objects by sender and/or receiver. + * @param sender name of message sender. If you dont want to filter by sender then let it empty + * @param receiver name of message receiver. If you dont want to filter by receiver then let it empty + * @param max_count maximal number of last messages to be displayed + * @return a vector of message objects + * @ingroup WalletAPI_Messaging */ vector get_message_objects(const std::string& sender, const std::string& receiver, uint32_t max_count) const; /** - * @brief Receives messages by receiver - * @param reveiver Name of message receiver which must be imported to caller's wallet - * @param max_count Maximal number of last messages to be displayed - * @return vector of message objects + * @brief Receives messages by receiver. + * @param receiver name of message receiver which must be imported to caller's wallet + * @param max_count maximal number of last messages to be displayed + * @return a vector of message objects + * @ingroup WalletAPI_Messaging */ vector get_messages(const std::string& receiver, uint32_t max_count) const; /** - * @brief Receives sent messages by sender - * @param sender Name of message sender which must be imported to caller's wallet - * @param max_count Maximal number of last messages to be displayed - * @return vector of message objects + * @brief Receives sent messages by sender. + * @param sender name of message sender which must be imported to caller's wallet + * @param max_count maximal number of last messages to be displayed + * @return a vector of message objects + * @ingroup WalletAPI_Messaging */ vector get_sent_messages(const std::string& sender, uint32_t max_count) const; }; From 208d0da799cc676ba1d8a78a2cbc6edba050376a Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 27 Nov 2017 10:36:33 +0100 Subject: [PATCH 013/136] API documentation update --- .../app/include/graphene/app/database_api.hpp | 4 ++-- libraries/plugins/seeding/seeding.cpp | 4 ++-- .../wallet/include/graphene/wallet/wallet.hpp | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index e79d6f36..5545c371 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -658,7 +658,7 @@ namespace graphene { namespace app { /** * @brief Get buying objects (open or history) by consumer. * @param consumer consumer of the buyings to retrieve - * @param order ordering field + * @param order ordering field. Available options are defined in 'database_api.cpp' * @param id the id of buying object to start searching from * @param term search term * @param count maximum number of contents to fetch (must not exceed 100) @@ -722,7 +722,7 @@ namespace graphene { namespace app { /** * @brief Search for term in contents (author, title and description). * @param term search term - * @param order ordering field + * @param order ordering field. Available options are defined in 'database_api.cpp' * @param user content owner * @param region_code two letter region code * @param id the id of content object to start searching from diff --git a/libraries/plugins/seeding/seeding.cpp b/libraries/plugins/seeding/seeding.cpp index 8f6c5693..ad918a6a 100644 --- a/libraries/plugins/seeding/seeding.cpp +++ b/libraries/plugins/seeding/seeding.cpp @@ -376,7 +376,7 @@ void seeding_plugin_impl::send_ready_to_publish() ready_to_publish_operation op; op.seeder = sritr->seeder; op.space = sritr->free_space; - op.price_per_MByte = dct_price.amount.value;; + op.price_per_MByte = dct_price.amount.value; op.pubKey = get_public_el_gamal_key(sritr->content_privKey); op.ipfs_ID = json[ "ID" ]; @@ -387,7 +387,7 @@ void seeding_plugin_impl::send_ready_to_publish() ready_to_publish2_operation op; op.seeder = sritr->seeder; op.space = sritr->free_space; - op.price_per_MByte = dct_price.amount.value;; + op.price_per_MByte = dct_price.amount.value; op.pubKey = get_public_el_gamal_key(sritr->content_privKey); op.ipfs_ID = json[ "ID" ]; op.region_code = sritr->region_code; diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index b8be7b8f..0af24122 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1734,8 +1734,8 @@ namespace graphene { namespace wallet { * @brief Get history buying objects by consumer that match search term. * @param account_id_or_name consumer of the buyings to retrieve * @param term search term to look up in \c title and \c description - * @param order sort data by field - * @param id object id to start searching from + * @param order sort data by field. Available options are defined in 'database_api.cpp' + * @param id the id of buying object to start searching from * @param count maximum number of contents to fetch (must not exceed 100) * @return a list of history buying objects corresponding to the provided consumer and matching search term * @ingroup WalletAPI_Content @@ -1780,11 +1780,12 @@ namespace graphene { namespace wallet { /** * @brief Get a list of contents ordered alphabetically by search term. * @param term search term - * @param order order field + * @param order order field. Available options are defined in 'database_api.cpp' * @param user content owner * @param region_code two letter region code * @param id the id of content object to start searching from - * @param type the application and content type to be filtered + * @param type the application and content type to be filtered, separated by comma. + * Available options are defined in 'content_object.hpp' * @param count maximum number of contents to fetch (must not exceed 100) * @return the contents found * @ingroup WalletAPI_Content @@ -1799,11 +1800,12 @@ namespace graphene { namespace wallet { /** * @brief Get a list of contents ordered alphabetically by search term. * @param user content owner - * @param term search term + * @param term search term. Available options are defined in 'database_api.cpp' * @param order order field * @param region_code two letter region code * @param id the id of content object to start searching from - * @param type the application and content type to be filtered + * @param type the application and content type to be filtered, separated by comma. + * Available options are defined in 'content_object.hpp' * @param count maximum number of contents to fetch (must not exceed 100) * @return the contents found * @ingroup WalletAPI_Content From b077b1c8548841ae20f2cd079395ad52147ddb91 Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Mon, 27 Nov 2017 13:49:04 +0100 Subject: [PATCH 014/136] Fixed committee_authority test --- tests/common/database_fixture.cpp | 8 ++++ tests/common/database_fixture.hpp | 2 + tests/tests/authority_tests.cpp | 74 +++++++++++++++++++++---------- 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 4af602bb..dba8a666 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -481,6 +481,14 @@ const account_object& database_fixture::get_account( const string& name )const return *itr; } +const account_object& database_fixture::get_account_by_id(account_id_type id)const +{ + const auto& idx = db.get_index_type().indices().get(); + const auto itr = idx.find(id); + assert(itr != idx.end()); + return *itr; +} + const miner_object& database_fixture::get_miner(account_id_type id)const { //const auto& idx = db.get_index_type().indices().get(); diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 84d9b2fe..ccfdd605 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -228,6 +228,7 @@ struct database_fixture { const asset_object& get_asset( const string& symbol )const; const account_object& get_account( const string& name )const; + const account_object& get_account_by_id(account_id_type id)const; const miner_object& get_miner(account_id_type id)const; void enable_fees(); @@ -250,6 +251,7 @@ struct database_fixture { genesis_state_type genesis_state; chain::database &db; signed_transaction trx; + signed_transaction trx2; fc::ecc::private_key private_key = fc::ecc::private_key::generate(); fc::ecc::private_key init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); public_key_type init_account_pub_key; diff --git a/tests/tests/authority_tests.cpp b/tests/tests/authority_tests.cpp index eaefe929..fee2088f 100644 --- a/tests/tests/authority_tests.cpp +++ b/tests/tests/authority_tests.cpp @@ -391,24 +391,34 @@ BOOST_AUTO_TEST_CASE( proposed_single_account ) } } -/// Verify that miner authority cannot be invoked in a normal transaction +//// Verify that miner authority cannot be invoked in a normal transaction BOOST_AUTO_TEST_CASE( committee_authority ) { try { fc::ecc::private_key nathan_key = fc::ecc::private_key::generate(); + fc::ecc::private_key voter_key = fc::ecc::private_key::generate(); + voter_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); fc::ecc::private_key miner_key = init_account_priv_key; const account_object nathan = create_account("nathan", nathan_key.get_public_key()); + trx.clear(); + generate_block(); + const account_object voter = create_account("voter", voter_key.get_public_key()); const auto& global_params = db.get_global_properties().parameters; generate_block(); - // Signatures are for suckers. db.modify(db.get_global_properties(), [](global_property_object& p) { // Turn the review period WAY down, so it doesn't take long to produce blocks to that point in simulated time. p.parameters.miner_proposal_review_period = fc::days(1).to_seconds(); }); + const account_object init0_account = get_account("init0"); + const account_object graphene_miner_account = get_account_by_id(account_id_type()); + + transfer(account_id_type()(db), get_account("voter"), asset(5000000)); + BOOST_TEST_MESSAGE( "transfering 100000 CORE to nathan, signing with miner key should fail because this requires it to be part of a proposal" ); transfer_operation top; + top.to = nathan.id; top.amount = asset(100000); trx.operations.push_back(top); @@ -417,26 +427,47 @@ BOOST_AUTO_TEST_CASE( committee_authority ) auto _sign = [&] { trx.signatures.clear(); sign( trx, nathan_key ); }; + // We must vote + fc::time_point_sec now = db.head_block_time(); + account_update_operation op; + op.account = voter.id; + op.new_options = voter.options; + + auto init0_miner_member = get_miner(get_account("init0").get_id()); + op.new_options->votes.insert(init0_miner_member.vote_id); + trx2.operations.push_back(op); + trx2.expiration = now + global_params.maximum_time_until_expiration; + PUSH_TX(db, trx2, ~0); + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + + // Create proposal + now = db.head_block_time(); proposal_create_operation pop; pop.proposed_ops.push_back({trx.operations.front()}); pop.expiration_time = db.head_block_time() + global_params.miner_proposal_review_period*2; pop.fee_paying_account = nathan.id; trx.operations = {pop}; + + trx.expiration = now + global_params.maximum_time_until_expiration; _sign(); // The review period isn't set yet. Make sure it throws. GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx ), proposal_create_review_period_required ); + pop.review_period_seconds = global_params.miner_proposal_review_period / 2; trx.operations.back() = pop; _sign(); + // The review period is too short. Make sure it throws. GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx ), proposal_create_review_period_insufficient ); + pop.review_period_seconds = global_params.miner_proposal_review_period; trx.operations.back() = pop; _sign(); + proposal_object prop = db.get(PUSH_TX( db, trx ).operation_results.front().get()); BOOST_REQUIRE(db.find_object(prop.id)); - + BOOST_CHECK(prop.expiration_time == pop.expiration_time); BOOST_CHECK(prop.review_period_time && *prop.review_period_time == pop.expiration_time - *pop.review_period_seconds); BOOST_CHECK(prop.proposed_transaction.operations.size() == 1); @@ -451,35 +482,32 @@ BOOST_AUTO_TEST_CASE( committee_authority ) BOOST_REQUIRE(!db.get(prop.id).is_authorized_to_execute(db)); trx.operations.clear(); trx.signatures.clear(); + + // Update proposal proposal_update_operation uop; - uop.fee_paying_account = GRAPHENE_TEMP_ACCOUNT; + uop.fee_paying_account = get_account("init0").get_id(); + uop.fee == asset(); uop.proposal = prop.id; - - uop.key_approvals_to_add.emplace(miner_key.get_public_key()); - /* - uop.key_approvals_to_add.emplace(1); - uop.key_approvals_to_add.emplace(2); - uop.key_approvals_to_add.emplace(3); - uop.key_approvals_to_add.emplace(4); - uop.key_approvals_to_add.emplace(5); - uop.key_approvals_to_add.emplace(6); + uop.key_approvals_to_add.emplace(miner_key.get_public_key()); + /* we can use also active_approvals_to_add: + uop.active_approvals_to_add = { get_account("init0").get_id(), get_account("init1").get_id(), + get_account("init2").get_id(), get_account("init3").get_id(), + get_account("init4").get_id(), get_account("init5").get_id(), + get_account("init6").get_id(), get_account("init7").get_id() }; */ trx.operations.push_back(uop); sign( trx, miner_key ); db.push_transaction(trx); + BOOST_CHECK_EQUAL(get_balance(nathan, asset_id_type()(db)), 0); BOOST_CHECK(db.get(prop.id).is_authorized_to_execute(db)); - trx.signatures.clear(); - generate_blocks(*prop.review_period_time); - uop.key_approvals_to_add.clear(); - uop.key_approvals_to_add.insert(miner_key.get_public_key()); // was 7 - trx.operations.back() = uop; - sign( trx, miner_key ); - // Should throw because the transaction is now in review. - GRAPHENE_CHECK_THROW(PUSH_TX( db, trx ), fc::exception); - - generate_blocks(prop.expiration_time); + fc::time_point_sec maintenence_time = db.get_dynamic_global_properties().next_maintenance_time; + generate_blocks(maintenence_time); + maintenence_time = db.get_dynamic_global_properties().next_maintenance_time; + generate_blocks(maintenence_time); + + auto bn = get_balance(nathan, asset_id_type()(db)); BOOST_CHECK_EQUAL(get_balance(nathan, asset_id_type()(db)), 100000); } FC_LOG_AND_RETHROW() } From e7aa717a5e09512ed1278c8396e03687931ca5b2 Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Mon, 27 Nov 2017 13:55:53 +0100 Subject: [PATCH 015/136] Removed useless line from committee_authority test --- tests/tests/authority_tests.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tests/authority_tests.cpp b/tests/tests/authority_tests.cpp index fee2088f..f12ed96d 100644 --- a/tests/tests/authority_tests.cpp +++ b/tests/tests/authority_tests.cpp @@ -396,7 +396,6 @@ BOOST_AUTO_TEST_CASE( committee_authority ) { try { fc::ecc::private_key nathan_key = fc::ecc::private_key::generate(); fc::ecc::private_key voter_key = fc::ecc::private_key::generate(); - voter_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); fc::ecc::private_key miner_key = init_account_priv_key; const account_object nathan = create_account("nathan", nathan_key.get_public_key()); trx.clear(); From 57dd1807c711cfe5feea45b14ab5e5821d1fa95e Mon Sep 17 00:00:00 2001 From: ejossev Date: Mon, 27 Nov 2017 15:56:57 +0100 Subject: [PATCH 016/136] simplified content buying --- libraries/chain/decent_evaluator.cpp | 73 ++++++++++++++++++---------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index a73aff1e..f2f420e2 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -21,6 +21,34 @@ namespace graphene { namespace chain { +namespace { + +void content_payout(database& db, asset price, const content_object& content){ + if( content.co_authors.empty() ) + db.adjust_balance( content.author, price ); + else + { + boost::multiprecision::int128_t price_for_co_author; + for( auto const &element : content.co_authors ) + { + price_for_co_author = ( price.amount.value * element.second ) / 10000ll ; + db.adjust_balance( element.first, asset( static_cast(price_for_co_author), price.asset_id) ); + price.amount -= price_for_co_author; + } + + if( price.amount != 0 ) { + FC_ASSERT( price.amount > 0 ); + db.adjust_balance(content.author, price); + } + } +}; + + +} + + + + void_result set_publishing_manager_evaluator::do_evaluate( const set_publishing_manager_operation& o ) {try{ for( const auto id : o.to ) @@ -420,10 +448,10 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri const auto &subscription = range.find(boost::make_tuple(o.consumer, content->author)); /// Check whether subscription exists. If so, consumer doesn't need pay for content - if (subscription != range.end() && subscription->expiration > d.head_block_time() ) + if (subscription != range.end() && subscription->expiration > d.head_block_time() ) { is_subscriber = true; - return void_result(); - + return void_result(); + } FC_ASSERT( d.are_assets_exchangeable( o.price.asset_id(d), content_price.asset_id(d) ), "price for the content and price of the content are not exchangeable"); /* @@ -463,11 +491,7 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri paid_price_after_conversion = asset( 0 ); } - if( content->key_parts.size() == 0 ){ //simplified content buying - TODO - - return void_result(); - } if( content_price.asset_id == o.price.asset_id ){ // no need to convert paid_price_after_conversion = paid_price; @@ -476,6 +500,14 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri paid_price_after_conversion = content_price.asset_id(d).convert(paid_price_in_dct, d); } + bool delivered = false; + asset escrow = paid_price_after_conversion; + if( content->key_parts.size() == 0 ){ //simplified content buying - TODO + FC_ASSERT(d.head_block_time() >= HARDFORK_2_TIME); + delivered = true; + escrow = asset(0); + } + const auto& object = db().create([&](buying_object& bo) { //create new buying object bo.consumer = o.consumer; @@ -483,16 +515,23 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri bo.expiration_time = d.head_block_time() + 24*3600; bo.pubKey = o.pubKey; - bo.price = paid_price_after_conversion; // escrow, will be reset to zero + bo.price = escrow; // escrow, will be reset to zero bo.paid_price_before_exchange = paid_price; bo.paid_price_after_exchange = paid_price_after_conversion; bo.synopsis = content->synopsis; bo.size = content->size; bo.created = content->created; + bo.delivered = delivered; bo.region_code_from = o.region_code_from; + bo.expiration_or_delivery_time = db().head_block_time(); }); + d.adjust_balance( o.consumer, -paid_price ); + if(delivered) { + content_payout(d, paid_price_after_conversion, *content); + d.modify( *content, []( content_object& co ){ co.times_bought++; }); + } const auto& idx2 = d.get_index_type().indices().get(); for( auto& element : content->key_parts ) { @@ -579,23 +618,7 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri asset price = buying.price; db().modify( *content, []( content_object& co ){ co.times_bought++; }); - if( content->co_authors.empty() ) - db().adjust_balance( content->author, price ); - else - { - boost::multiprecision::int128_t price_for_co_author; - for( auto const &element : content->co_authors ) - { - price_for_co_author = ( price.amount.value * element.second ) / 10000ll ; - db().adjust_balance( element.first, asset( static_cast(price_for_co_author), price.asset_id) ); - price.amount -= price_for_co_author; - } - - if( price.amount != 0 ) { - FC_ASSERT( price.amount > 0 ); - db().adjust_balance(content->author, price); - } - } + content_payout(db(), price, *content); db().modify(buying, [&](buying_object& bo){ bo.price.amount = 0; From 7c9ed5c5944b570e3097e79e28ae6297f963bf0d Mon Sep 17 00:00:00 2001 From: ejossev Date: Tue, 28 Nov 2017 10:15:42 +0100 Subject: [PATCH 017/136] checking of tx size and optimization for checkpoints --- libraries/app/application.cpp | 2 ++ libraries/chain/db_block.cpp | 9 ++++++++- libraries/chain/decent_evaluator.cpp | 6 ++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 461cfe59..c815db06 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -345,8 +345,10 @@ namespace detail { { auto item = fc::json::from_string(cp).as >(); loaded_checkpoints[item.first] = item.second; + ilog ( "loaded checkpoint ${s} at ${n}", ("s",loaded_checkpoints[item.first])("n", item.first)); } } + _chain_db->add_checkpoints( loaded_checkpoints ); if( _options->count("replay-blockchain") ) diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index f8684f95..23bd62ea 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -243,6 +243,12 @@ bool database::_push_block(const signed_block &new_block, bool sync_mode) processed_transaction database::push_transaction( const signed_transaction& trx, uint32_t skip ) { try { processed_transaction result; + size_t tx_size = fc::raw::pack_size( trx ); + auto maximum_tx_size = get_global_properties().parameters.maximum_transaction_size; + + if(tx_size > maximum_tx_size) + elog("Tx too big"); + FC_ASSERT(tx_size <= maximum_tx_size, "Transaction size is too big"); detail::with_skip_flags( *this, skip, [&]() { result = _push_transaction( trx ); @@ -364,7 +370,8 @@ signed_block database::_generate_block( // pop pending state (reset to head block state) for( const processed_transaction& tx : _pending_tx ) { - size_t new_total_size = total_block_size + fc::raw::pack_size( tx ); + size_t tx_size = fc::raw::pack_size( tx ); + size_t new_total_size = total_block_size + tx_size; // postpone transaction if it would make block too big if( new_total_size >= maximum_block_size ) diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index e401cba5..4d9523c3 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -588,8 +588,10 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri const auto& firstK = content->key_parts.at( o.seeder ); const auto& secondK = o.key; const auto& proof = o.proof; - - FC_ASSERT( decent::encrypt::verify_delivery_proof( proof, firstK, secondK, seeder_pubKey, buyer_pubKey) ); + if(!(db().get_node_properties().skip_flags&db().skip_validate)) { + FC_ASSERT(decent::encrypt::verify_delivery_proof(proof, firstK, secondK, seeder_pubKey, buyer_pubKey)); + }else{ + } return void_result(); }FC_CAPTURE_AND_RETHROW( (o) ) } From 18ab565d86bab02008b2deb5518fa34cad7f5f13 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Tue, 28 Nov 2017 13:12:02 +0100 Subject: [PATCH 018/136] set hardfork variable for stage --- libraries/chain/hardfork.d/1.hf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/hardfork.d/1.hf b/libraries/chain/hardfork.d/1.hf index e83fa279..6fea6717 100644 --- a/libraries/chain/hardfork.d/1.hf +++ b/libraries/chain/hardfork.d/1.hf @@ -1,4 +1,4 @@ // #1 - UIA introduced; seeder regions; instant messaging. #ifndef HARDFORK_1_TIME -#define HARDFORK_1_TIME (fc::time_point_sec( 1510228800 )) +#define HARDFORK_1_TIME (fc::time_point_sec( 1500228800 )) #endif From d12db3538ac7a95c5f3b2ebeedb545c222455ef1 Mon Sep 17 00:00:00 2001 From: ejossev Date: Wed, 29 Nov 2017 10:09:39 +0100 Subject: [PATCH 019/136] unit test --- libraries/chain/decent_evaluator.cpp | 3 +- .../include/graphene/chain/asset_object.hpp | 13 +- tests/CMakeLists.txt | 16 +- tests/common/database_fixture.cpp | 54 ++++- tests/common/database_fixture.hpp | 4 + tests/tests/uia_tests.cpp | 189 +++++++++++++++++- 6 files changed, 257 insertions(+), 22 deletions(-) diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index 41edc302..56a9fa9b 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -472,7 +472,8 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri asset paid_price_in_dct; FC_ASSERT( paid_price.asset_id(d).can_convert(paid_price, paid_price_in_dct, d) && paid_price_in_dct.asset_id == asset_id_type() ); - FC_ASSERT( content_price.asset_id(d).can_convert(paid_price_in_dct, paid_price_after_conversion, d) && paid_price_after_conversion.asset_id == content_price.asset_id ); + FC_ASSERT( content_price.asset_id(d).can_convert(paid_price_in_dct, paid_price_after_conversion, d), "cannot convert ${f} to ${t}"); + FC_ASSERT( paid_price_after_conversion.asset_id == content_price.asset_id ); FC_ASSERT( paid_price_after_conversion >= content_price ); return void_result(); diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index 2fb217bc..2cb4e465 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -149,7 +149,6 @@ namespace graphene { namespace chain { asset asset_pool_diff; price rate = ao.options.core_exchange_rate; - if( from.asset_id == id ){ to.asset_id = asset_id_type(); to = from * rate; @@ -157,14 +156,18 @@ namespace graphene { namespace chain { core_pool_diff = -to; asset_pool_diff = from; + ilog("changes in core pool: ${c}",("c", -to)); + ilog("changes in asset pool: ${c}",("c", from)); }else{ FC_ASSERT(from.asset_id == asset_id_type(), "Unsupported conversion"); to.asset_id = id; to = from * rate; - core_pool_diff = -from; - asset_pool_diff = to; + core_pool_diff = from; + asset_pool_diff = -to; + ilog("changes in core pool: ${c}",("c", from)); + ilog("changes in asset pool: ${c}",("c", -to)); } FC_ASSERT( add.asset_pool + asset_pool_diff.amount >= share_type(0), "Insufficient funds in asset pool to perform conversion" ); @@ -225,8 +228,8 @@ namespace graphene { namespace chain { to.asset_id = id; to = from * rate; - core_pool_diff = -from; - asset_pool_diff = to; + core_pool_diff = from; + asset_pool_diff = -to; } if ( add.asset_pool + asset_pool_diff.amount < share_type(0) || add.core_pool + core_pool_diff.amount < share_type(0) ) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b0624176..feba8968 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,14 +11,14 @@ set(TEST_FILES_LIST common/database_fixture.cpp common/tempdir.hpp common/tempdir.cpp - tests/basic_tests.cpp - tests/block_tests.cpp - tests/database_tests.cpp - tests/serialization_tests.cpp - tests/operation_tests.cpp - tests/operation_tests2.cpp - tests/authority_tests.cpp - tests/fee_tests.cpp +# tests/basic_tests.cpp +# tests/block_tests.cpp +# tests/database_tests.cpp +# tests/serialization_tests.cpp +# tests/operation_tests.cpp +# tests/operation_tests2.cpp +# tests/authority_tests.cpp +# tests/fee_tests.cpp tests/uia_tests.cpp tests/main.cpp ) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index dba8a666..5e4c8bd2 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -140,11 +140,17 @@ void database_fixture::verify_asset_supplies( const database& db ) const simple_index& statistics_index = db.get_index_type>(); const auto& balance_index = db.get_index_type().indices(); + const auto& asset_idx = db.get_index_type().indices().get(); map total_balances; map total_debts; share_type core_in_orders; share_type reported_core_in_orders; + for( const asset_object& a: asset_idx) { + const auto& ad = a.dynamic_asset_data_id(db); + total_balances[asset_id_type()] += ad.core_pool; + total_balances[a.get_id()] += ad.asset_pool; + } for( const account_balance_object& b : balance_index ) total_balances[b.asset_type] += b.balance; for( const account_statistics_object& a : statistics_index ) @@ -422,7 +428,6 @@ const asset_object& database_fixture::create_user_issued_asset( const string& na creator.issuer = issuer.id; creator.fee = asset(); creator.symbol = name; - creator.options.max_supply = 0; creator.precision = 2; creator.options.core_exchange_rate = price({asset(1,asset_id_type(1)),asset(1)}); creator.options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; @@ -530,6 +535,7 @@ void database_fixture::transfer( { set_expiration( db, trx ); transfer_operation trans; + trans.fee = fee; trans.from = from.id; trans.to = to.id; trans.amount = amount; @@ -586,6 +592,19 @@ void database_fixture::issue_uia( account_id_type recipient_id, asset amount ) issue_uia( recipient_id(db), amount ); } +void database_fixture::fill_pools(asset_id_type uia, account_id_type by, asset to_core_pool, asset to_asset_pool) +{ + set_expiration( db, trx ); + trx.operations.clear(); + asset_fund_pools_operation filler; + filler.dct_asset = to_core_pool; + filler.from_account = by; + filler.uia_asset = to_asset_pool; + trx.operations.push_back(std::move(filler)); + db.push_transaction( trx, ~0 ); + trx.operations.clear(); +} + void database_fixture::publish_feed( const asset_object& mia, const account_object& by, const price_feed& f ) { set_expiration( db, trx ); @@ -606,10 +625,42 @@ void database_fixture::publish_feed( const asset_object& mia, const account_obje verify_asset_supplies(db); } +void database_fixture::create_content(account_id_type by, string url, asset price) +{ + set_expiration( db, trx ); + trx.operations.clear(); + + content_submit_operation op; + op.size = 100; + op.price.push_back({RegionCodes::OO_none, price}); + op.author = by; + op.URI = url; + op.hash = fc::ripemd160::hash(url); + op.expiration = fc::time_point::now()+fc::microseconds(10000000000); + op.publishing_fee = asset(0); + op.quorum = 0; + op.synopsis = "{\"title\":\"abcd\"}"; + trx.operations.emplace_back( std::move(op) ); + + db.push_transaction(trx, ~0); + trx.operations.clear(); +} +void database_fixture::buy_content(account_id_type by, string url, asset price) +{ + set_expiration( db, trx ); + trx.operations.clear(); + request_to_buy_operation op; + op.URI = url; + op.price = price; + op.consumer = by; + trx.operations.emplace_back( std::move(op) ); + db.push_transaction(trx, ~0); + trx.operations.clear(); +} #if 0 /////////////////////////////////////////////////////////////////////////////////////// @@ -832,6 +883,7 @@ processed_transaction _push_transaction( database& db, const signed_transaction& } FC_CAPTURE_AND_RETHROW((tx)) } + } // graphene::chain::test } } // graphene::chain diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index ccfdd605..05fe178c 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -243,6 +243,10 @@ struct database_fixture { { publish_feed(mia(db), by(db), f); } void publish_feed(const asset_object& mia, const account_object& by, const price_feed& f); + void fill_pools(asset_id_type uia, account_id_type by, asset to_core_pool, asset to_asset_pool); + + void create_content(account_id_type by, string url, asset price); + void buy_content(account_id_type by, string url, asset price); // the reason we use an app is to exercise the indexes of built-in diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index 03e23488..ca5627d1 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -44,15 +44,18 @@ BOOST_FIXTURE_TEST_SUITE( uia_tests, database_fixture ) BOOST_AUTO_TEST_CASE( create_advanced_uia ) { try { + ACTORS( (alice) ); asset_id_type test_asset_id = db.get_index().get_next_id(); asset_create_operation creator; - creator.issuer = account_id_type(); + creator.issuer = alice_id; creator.fee = asset(); creator.symbol = "ADVANCED"; creator.options.max_supply = 100000000; creator.precision = 2; - creator.options.core_exchange_rate = price({asset(2),asset(1, asset_id_type(1))}); + creator.options.core_exchange_rate = price({asset(2),asset(1, test_asset_id)}); + trx.operations.push_back(std::move(creator)); + ilog("Creating asset ADVANCED"); PUSH_TX( db, trx, ~0 ); const asset_object& test_asset = test_asset_id(db); @@ -83,6 +86,7 @@ BOOST_AUTO_TEST_CASE( asset_name_test ) return assets_by_symbol.find( symbol ) != assets_by_symbol.end(); }; + ilog("Creating asset ALPHA"); // Alice creates asset "ALPHA" BOOST_CHECK( !has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); create_user_issued_asset( "ALPHA", alice_id(db) ); @@ -94,12 +98,183 @@ BOOST_AUTO_TEST_CASE( asset_name_test ) GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA", alice_id(db) ), fc::exception ); BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); - // Bob can't create ALPHA.ONE - GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA.ONE", bobian_id(db) ), fc::exception ); + } + catch(fc::exception& e) + { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( asset_issue_transfer_test ) +{ + try + { + //names must be at least 5 characters long... + ACTORS( (alice)(bobian) ); + transfer( miner_account, alice_id, asset(300000000) ); + + auto has_asset = [&]( std::string symbol ) -> bool + { + const auto& assets_by_symbol = db.get_index_type().indices().get(); + return assets_by_symbol.find( symbol ) != assets_by_symbol.end(); + }; + + ilog("Creating asset ALPHA"); + // Alice creates asset "ALPHA" + BOOST_CHECK( !has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); + asset_id_type alpha_asset_id = db.get_index().get_next_id(); + create_user_issued_asset( "ALPHA", alice_id(db) ); BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); - // Alice can create it - create_user_issued_asset( "ALPHA.ONE", alice_id(db) ); - BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( has_asset("ALPHA.ONE") ); + + ilog("Issuing asset ALPHA"); + //Alice issues asset "ALPHA" + issue_uia( bobian_id(db), asset(100000000, alpha_asset_id)); + BOOST_CHECK(get_balance(bobian_id,alpha_asset_id) == 100000000 ); + issue_uia( alice_id(db), asset(250000000, alpha_asset_id)); + BOOST_CHECK(get_balance(bobian_id,alpha_asset_id) == 100000000 ); + BOOST_CHECK(get_balance(alice_id,alpha_asset_id) == 250000000 ); + + enable_fees(); + transfer(alice_id,bobian_id,asset(50000000,alpha_asset_id),asset(500000)); + BOOST_CHECK(get_balance(bobian_id,alpha_asset_id) == 150000000 ); + BOOST_CHECK(get_balance(alice_id,alpha_asset_id) == 200000000 ); + GRAPHENE_REQUIRE_THROW(transfer(alice_id,bobian_id,asset(5,alpha_asset_id),asset(500000, alpha_asset_id)), fc::exception); + trx.clear(); + idump((alpha_asset_id(db))); + ilog("Alice has ${s} DCTs, ",("s",get_balance(alice_id, asset_id_type()))); + //Fill the pools + asset_fund_pools_operation filler; + filler.dct_asset = asset(50000000); + filler.fee = asset(500000, asset_id_type()); + filler.from_account = alice_id; + filler.uia_asset = asset(50000000, alpha_asset_id); + + trx.operations.clear(); + trx.operations.push_back(std::move(filler)); + sign( trx, alice_private_key ); + ilog("Filling asset pools"); + PUSH_TX( db, trx); + trx.clear(); + idump((alpha_asset_id(db))); + transfer(alice_id,bobian_id,asset(50000000,alpha_asset_id),asset(500000, alpha_asset_id)); + BOOST_CHECK(get_balance(bobian_id,alpha_asset_id) == 200000000 ); + BOOST_CHECK(get_balance(alice_id,alpha_asset_id) == 99500000 ); + + for(int i=0; i<99; i++) + transfer(alice_id,bobian_id,asset(10000,alpha_asset_id),asset(500000, alpha_asset_id)); + + GRAPHENE_REQUIRE_THROW(transfer(alice_id,bobian_id,asset(10000,alpha_asset_id),asset(500000, alpha_asset_id)), fc::exception); + trx.clear(); + } + catch(fc::exception& e) + { + edump((e.to_detail_string())); + throw; + } +} + + +BOOST_AUTO_TEST_CASE( asset_content_in_uia_test ) +{ + try + { + //names must be at least 5 characters long... + ACTORS( (alice)(bobian)(cecil) ); + transfer( miner_account, alice_id, asset(400000000) ); + transfer( miner_account, cecil_id, asset(400000000) ); + + + auto has_asset = [&]( std::string symbol ) -> bool + { + const auto& assets_by_symbol = db.get_index_type().indices().get(); + return assets_by_symbol.find( symbol ) != assets_by_symbol.end(); + }; + + ilog("Creating asset ALPHA"); + // Alice creates asset "ALPHA" + BOOST_CHECK( !has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); + asset_id_type alpha_asset_id = db.get_index().get_next_id(); + create_user_issued_asset( "ALPHA", alice_id(db) ); + BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); + + //create content + create_content(alice_id, "http://abcd", asset(100, alpha_asset_id)); + GRAPHENE_REQUIRE_THROW(buy_content(cecil_id, "http://abcd", asset(100)), fc::exception); + trx.clear(); + ilog("Issuing asset ALPHA"); + //Alice issues asset "ALPHA" + issue_uia( bobian_id(db), asset(100000000, alpha_asset_id)); + issue_uia( alice_id(db), asset(250000000, alpha_asset_id)); + + //Fill the pools + fill_pools(alpha_asset_id, alice_id, asset(50000000), asset(50000000, alpha_asset_id)); + + + ilog("Alice has ${s} DCTs, ",("s",get_balance(alice_id, asset_id_type()))); + ilog("Alice has ${s} ALPHAs, ",("s",get_balance(alice_id, alpha_asset_id))); + idump((alpha_asset_id(db).dynamic_asset_data_id(db))); + + buy_content(bobian_id, "http://abcd", asset(100, alpha_asset_id)); + buy_content(cecil_id, "http://abcd", asset(100)); + ilog("Alice has ${s} DCTs, ",("s",get_balance(alice_id, asset_id_type()))); + ilog("Alice has ${s} ALPHAs, ",("s",get_balance(alice_id, alpha_asset_id))); + idump((alpha_asset_id(db).dynamic_asset_data_id(db))); + } + catch(fc::exception& e) + { + edump((e.to_detail_string())); + throw; + } +} + + +BOOST_AUTO_TEST_CASE( asset_content_in_dct_test ) +{ + try + { + //names must be at least 5 characters long... + ACTORS( (alice)(bobian)(cecil) ); + transfer( miner_account, alice_id, asset(400000000) ); + transfer( miner_account, cecil_id, asset(400000000) ); + + + auto has_asset = [&]( std::string symbol ) -> bool + { + const auto& assets_by_symbol = db.get_index_type().indices().get(); + return assets_by_symbol.find( symbol ) != assets_by_symbol.end(); + }; + + ilog("Creating asset ALPHA"); + // Alice creates asset "ALPHA" + BOOST_CHECK( !has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); + asset_id_type alpha_asset_id = db.get_index().get_next_id(); + create_user_issued_asset( "ALPHA", alice_id(db) ); + BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); + + //create content + create_content(alice_id, "http://abcd", asset(100)); + GRAPHENE_REQUIRE_THROW(buy_content(bobian_id, "http://abcd", asset(100, alpha_asset_id)), fc::exception); + trx.clear(); + //try to buy + ilog("Issuing asset ALPHA"); + //Alice issues asset "ALPHA" + issue_uia( bobian_id(db), asset(100000000, alpha_asset_id)); + issue_uia( alice_id(db), asset(250000000, alpha_asset_id)); + + //Fill the pools + fill_pools(alpha_asset_id, alice_id, asset(50000000), asset(50000000, alpha_asset_id)); + + + ilog("Alice has ${s} DCTs, ",("s",get_balance(alice_id, asset_id_type()))); + ilog("Alice has ${s} ALPHAs, ",("s",get_balance(alice_id, alpha_asset_id))); + idump((alpha_asset_id(db).dynamic_asset_data_id(db))); + + buy_content(bobian_id, "http://abcd", asset(100, alpha_asset_id)); + buy_content(cecil_id, "http://abcd", asset(100)); + ilog("Alice has ${s} DCTs, ",("s",get_balance(alice_id, asset_id_type()))); + ilog("Alice has ${s} ALPHAs, ",("s",get_balance(alice_id, alpha_asset_id))); + idump((alpha_asset_id(db).dynamic_asset_data_id(db))); } catch(fc::exception& e) { From fec34da1477672439c628f5586517c2dcba2e3f2 Mon Sep 17 00:00:00 2001 From: ejossev Date: Wed, 29 Nov 2017 10:31:30 +0100 Subject: [PATCH 020/136] unit test --- tests/tests/uia_tests.cpp | 49 ++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index ca5627d1..84a45a1b 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE( asset_content_in_uia_test ) try { //names must be at least 5 characters long... - ACTORS( (alice)(bobian)(cecil) ); + ACTORS( (alice)(bobian)(cecil)(david) ); transfer( miner_account, alice_id, asset(400000000) ); transfer( miner_account, cecil_id, asset(400000000) ); @@ -211,15 +211,25 @@ BOOST_AUTO_TEST_CASE( asset_content_in_uia_test ) fill_pools(alpha_asset_id, alice_id, asset(50000000), asset(50000000, alpha_asset_id)); - ilog("Alice has ${s} DCTs, ",("s",get_balance(alice_id, asset_id_type()))); - ilog("Alice has ${s} ALPHAs, ",("s",get_balance(alice_id, alpha_asset_id))); - idump((alpha_asset_id(db).dynamic_asset_data_id(db))); + BOOST_CHECK(get_balance(alice_id, asset_id_type()) == 350000000); + BOOST_CHECK(get_balance(alice_id, alpha_asset_id ) == 200000000); + BOOST_CHECK(get_balance(cecil_id, asset_id_type()) == 400000000); + BOOST_CHECK(get_balance(bobian_id, alpha_asset_id ) == 100000000); + BOOST_CHECK(alpha_asset_id(db).dynamic_asset_data_id(db).asset_pool == 50000000); + BOOST_CHECK(alpha_asset_id(db).dynamic_asset_data_id(db).core_pool == 50000000); buy_content(bobian_id, "http://abcd", asset(100, alpha_asset_id)); buy_content(cecil_id, "http://abcd", asset(100)); - ilog("Alice has ${s} DCTs, ",("s",get_balance(alice_id, asset_id_type()))); - ilog("Alice has ${s} ALPHAs, ",("s",get_balance(alice_id, alpha_asset_id))); - idump((alpha_asset_id(db).dynamic_asset_data_id(db))); + GRAPHENE_REQUIRE_THROW(buy_content(david_id, "http://abcd", asset(100, alpha_asset_id)), fc::exception); + GRAPHENE_REQUIRE_THROW(buy_content(david_id, "http://abcd", asset(100)), fc::exception); + + BOOST_CHECK(get_balance(alice_id, asset_id_type()) == 350000000); + BOOST_CHECK(get_balance(alice_id, alpha_asset_id ) == 200000200); + BOOST_CHECK(get_balance(cecil_id, asset_id_type()) == 399999900); + BOOST_CHECK(get_balance(bobian_id, alpha_asset_id ) == 99999900); + BOOST_CHECK(alpha_asset_id(db).dynamic_asset_data_id(db).asset_pool == 49999900); + BOOST_CHECK(alpha_asset_id(db).dynamic_asset_data_id(db).core_pool == 50000100); + } catch(fc::exception& e) { @@ -234,11 +244,10 @@ BOOST_AUTO_TEST_CASE( asset_content_in_dct_test ) try { //names must be at least 5 characters long... - ACTORS( (alice)(bobian)(cecil) ); + ACTORS( (alice)(bobian)(cecil)(david) ); transfer( miner_account, alice_id, asset(400000000) ); transfer( miner_account, cecil_id, asset(400000000) ); - auto has_asset = [&]( std::string symbol ) -> bool { const auto& assets_by_symbol = db.get_index_type().indices().get(); @@ -265,16 +274,24 @@ BOOST_AUTO_TEST_CASE( asset_content_in_dct_test ) //Fill the pools fill_pools(alpha_asset_id, alice_id, asset(50000000), asset(50000000, alpha_asset_id)); - - ilog("Alice has ${s} DCTs, ",("s",get_balance(alice_id, asset_id_type()))); - ilog("Alice has ${s} ALPHAs, ",("s",get_balance(alice_id, alpha_asset_id))); - idump((alpha_asset_id(db).dynamic_asset_data_id(db))); + BOOST_CHECK(get_balance(alice_id, asset_id_type()) == 350000000); + BOOST_CHECK(get_balance(alice_id, alpha_asset_id ) == 200000000); + BOOST_CHECK(get_balance(cecil_id, asset_id_type()) == 400000000); + BOOST_CHECK(get_balance(bobian_id, alpha_asset_id ) == 100000000); + BOOST_CHECK(alpha_asset_id(db).dynamic_asset_data_id(db).asset_pool == 50000000); + BOOST_CHECK(alpha_asset_id(db).dynamic_asset_data_id(db).core_pool == 50000000); buy_content(bobian_id, "http://abcd", asset(100, alpha_asset_id)); buy_content(cecil_id, "http://abcd", asset(100)); - ilog("Alice has ${s} DCTs, ",("s",get_balance(alice_id, asset_id_type()))); - ilog("Alice has ${s} ALPHAs, ",("s",get_balance(alice_id, alpha_asset_id))); - idump((alpha_asset_id(db).dynamic_asset_data_id(db))); + GRAPHENE_REQUIRE_THROW(buy_content(david_id, "http://abcd", asset(100, alpha_asset_id)), fc::exception); + GRAPHENE_REQUIRE_THROW(buy_content(david_id, "http://abcd", asset(100)), fc::exception); + + BOOST_CHECK(get_balance(alice_id, asset_id_type()) == 350000200); + BOOST_CHECK(get_balance(alice_id, alpha_asset_id ) == 200000000); + BOOST_CHECK(get_balance(cecil_id, asset_id_type()) == 399999900); + BOOST_CHECK(get_balance(bobian_id, alpha_asset_id ) == 99999900); + BOOST_CHECK(alpha_asset_id(db).dynamic_asset_data_id(db).asset_pool == 50000100); + BOOST_CHECK(alpha_asset_id(db).dynamic_asset_data_id(db).core_pool == 49999900); } catch(fc::exception& e) { From f318af8cdd6f9c5684d92bcec642aacf27c5bbf3 Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Wed, 29 Nov 2017 15:21:37 +0100 Subject: [PATCH 021/136] Added messaging test --- tests/CMakeLists.txt | 3 +- tests/common/database_fixture.cpp | 8 ++ tests/tests/messaging_tests.cpp | 146 ++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 tests/tests/messaging_tests.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b0624176..9d3c2826 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,11 +20,12 @@ set(TEST_FILES_LIST tests/authority_tests.cpp tests/fee_tests.cpp tests/uia_tests.cpp + tests/messaging_tests.cpp tests/main.cpp ) add_executable( chain_test ${TEST_FILES_LIST} ) -target_link_libraries( chain_test graphene_chain graphene_app graphene_account_history graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} ) +target_link_libraries( chain_test graphene_chain graphene_app graphene_account_history graphene_egenesis_none decent_messaging fc ${PLATFORM_SPECIFIC_LIBS} ) if(MSVC) set_source_files_properties( tests/serialization_tests.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) endif(MSVC) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index dba8a666..f5011895 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -140,11 +140,18 @@ void database_fixture::verify_asset_supplies( const database& db ) const simple_index& statistics_index = db.get_index_type>(); const auto& balance_index = db.get_index_type().indices(); + const auto& asset_idx = db.get_index_type().indices().get(); map total_balances; map total_debts; share_type core_in_orders; share_type reported_core_in_orders; + for (const asset_object& a : asset_idx) { + const auto& ad = a.dynamic_asset_data_id(db); + total_balances[asset_id_type()] += ad.core_pool; + total_balances[a.get_id()] += ad.asset_pool; + } + for( const account_balance_object& b : balance_index ) total_balances[b.asset_type] += b.balance; for( const account_statistics_object& a : statistics_index ) @@ -176,6 +183,7 @@ void database_fixture::verify_asset_supplies( const database& db ) } BOOST_CHECK_EQUAL( core_in_orders.value , reported_core_in_orders.value ); + int64_t v = total_balances[asset_id_type()].value; BOOST_CHECK_EQUAL( total_balances[asset_id_type()].value , core_asset_data.current_supply.value); // wlog("*** End asset supply verification ***"); } diff --git a/tests/tests/messaging_tests.cpp b/tests/tests/messaging_tests.cpp new file mode 100644 index 00000000..2b41ce8d --- /dev/null +++ b/tests/tests/messaging_tests.cpp @@ -0,0 +1,146 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include +#include +#include + +#include +#include +#include + +#include + +#include //added +#include //added +#include //added +#include + +#include + +#include +#include "../common/database_fixture.hpp" + +using namespace graphene::chain; +using namespace graphene::chain::test; + +BOOST_FIXTURE_TEST_SUITE( messaging_tests, database_fixture ) + + +BOOST_AUTO_TEST_CASE( messaging ) +{ try { + + + auto messaging_plug = app.register_plugin(); + messaging_plug->plugin_set_app(&app); + boost::program_options::variables_map omap; + messaging_plug->plugin_initialize(omap); + messaging_plug->plugin_startup(); + + ACTOR(nathan); + ACTOR(bobian); + ACTOR(alice); + + transfer(account_id_type()(db), nathan, asset(200000)); + enable_fees(); + + std::vector to = { "alice", "bobian" }; + std::string text_sent = "Hello from nathan to alice and bobian"; + + std::vector to_accounts; + account_id_type from_id = nathan_id; + + message_payload pl; + + message_payload_receivers_data receivers_data_item; + + // message for bobian + receivers_data_item.to = bobian_id; + pl.set_message(nathan_private_key, bobian.options.memo_key, text_sent, receivers_data_item); + pl.receivers_data.push_back(receivers_data_item); + + // message for alice + receivers_data_item.to = alice_id; + pl.set_message(nathan_private_key, alice.options.memo_key, text_sent, receivers_data_item); + pl.receivers_data.push_back(receivers_data_item); + + custom_operation cust_op; + + cust_op.id = graphene::chain::custom_operation_subtype_messaging; + cust_op.payer = from_id; + + pl.from = from_id; + pl.pub_from = nathan.options.memo_key; + cust_op.set_messaging_payload(pl); + + trx.operations.push_back(cust_op); + + fee_schedule s = db.get_global_properties().parameters.current_fees; + s.set_fee(trx.operations.back()); + + const auto& global_params = db.get_global_properties().parameters; + trx.expiration = db.head_block_time() + global_params.maximum_time_until_expiration; + custom_operation& result_op = (trx.operations.back()).get(); + trx.validate(); + + sign(trx, nathan_private_key); + + PUSH_TX(db, trx); + + auto msg_itr_found = db.get_index_type().indices().get().end(); + const auto& idx = db.get_index_type(); + const auto& aidx = dynamic_cast&>(idx); + const auto& refs = aidx.get_secondary_index(); + auto itr = refs.message_to_receiver_memberships.find(bobian_id); + + if (itr != refs.message_to_receiver_memberships.end()) + { + for (const object_id_type& item : itr->second) { + + auto msg_itr = db.get_index_type().indices().get().find(item); + if (msg_itr != db.get_index_type().indices().get().end()) { + message_object o = *msg_itr; + if ((*msg_itr).sender == nathan_id) { + msg_itr_found = msg_itr; + break; + } + } + } + } + BOOST_REQUIRE(msg_itr_found != db.get_index_type().indices().get().end()); + std::string received_text_bobian; + std::string received_text_alice; + message_payload::get_message(bobian_private_key, nathan_public_key, (*msg_itr_found).receivers_data[0].data, received_text_bobian, (*msg_itr_found).receivers_data[0].nonce); + message_payload::get_message(alice_private_key, nathan_public_key, (*msg_itr_found).receivers_data[1].data, received_text_alice, (*msg_itr_found).receivers_data[1].nonce); + BOOST_REQUIRE(received_text_bobian == received_text_alice); + BOOST_REQUIRE(received_text_bobian == received_text_alice); + BOOST_REQUIRE(received_text_bobian == text_sent); + +} FC_LOG_AND_RETHROW() } + + +BOOST_AUTO_TEST_SUITE_END() From 4ae4ea1db656e05aada733e6c804e1bc75d256ad Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Wed, 29 Nov 2017 18:02:51 +0100 Subject: [PATCH 022/136] add get_relative_account_history to wallet_api --- .../wallet/include/graphene/wallet/wallet.hpp | 18 +++++++++++++++++ libraries/wallet/wallet.cpp | 20 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 23b1496e..ee71a1af 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -382,6 +382,23 @@ namespace graphene { namespace wallet { */ vector get_account_history(string name, int limit)const; + /** + * @breif Get operations relevant to the specified account referenced + * by an event numbering specific to the account. The current number of operations + * for the account can be found in the account statistics (or use 0 for start). + * @param account The account whose history should be queried + * @param stop Sequence number of earliest operation. 0 is default and will + * query 'limit' number of operations. + * @param limit Maximum number of operations to retrieve (must not exceed 100) + * @param start Sequence number of the most recent operation to retrieve. + * 0 is default, which will start querying from the most recent operation. + * @return A list of operations performed by account, ordered from most recent to oldest. + * @ingroup WalletCLI + */ + vector get_relative_account_history(string name, + uint32_t stop, + int limit, + uint32_t start)const; /** * @brief Returns the block chain's slowly-changing settings. @@ -2178,6 +2195,7 @@ FC_API( graphene::wallet::wallet_api, (get_block) (get_account_count) (get_account_history) + (get_relative_account_history) (search_account_history) (get_global_properties) (get_dynamic_global_properties) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index c0e4e9e2..c8445d16 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2185,7 +2185,7 @@ class wallet_api_impl } - void submit_content_utility(content_submit_operation& submit_op, + void submit_content_utility(content_submit_operation& submit_op, vector const& price_amounts) { vector arr_prices; @@ -3500,6 +3500,24 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return result; } + vector wallet_api::get_relative_account_history(string name, + uint32_t stop, + int limit, + uint32_t start)const + { + vector result; + auto account_id = get_account_id(name); + + vector current = my->_remote_hist->get_relative_account_history(account_id, stop, limit, start); + for( auto& o : current ) { + std::stringstream ss; + auto memo = o.op.visit(detail::operation_printer(ss, *my, o.result)); + result.push_back( operation_detail{ memo, ss.str(), o } ); + } + + return result; + } + vector wallet_api::search_account_history(string const& account_name, string const& order, string const& id, From 61ab94e3da57b198837e98c1062b4dd24a54b357 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Fri, 1 Dec 2017 16:00:28 +0100 Subject: [PATCH 023/136] set hardfork variable for mainnet --- libraries/chain/hardfork.d/1.hf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/hardfork.d/1.hf b/libraries/chain/hardfork.d/1.hf index 6fea6717..e83fa279 100644 --- a/libraries/chain/hardfork.d/1.hf +++ b/libraries/chain/hardfork.d/1.hf @@ -1,4 +1,4 @@ // #1 - UIA introduced; seeder regions; instant messaging. #ifndef HARDFORK_1_TIME -#define HARDFORK_1_TIME (fc::time_point_sec( 1500228800 )) +#define HARDFORK_1_TIME (fc::time_point_sec( 1510228800 )) #endif From 94984e882bc5071eedacc017f35735f040705939 Mon Sep 17 00:00:00 2001 From: ejossev Date: Sat, 2 Dec 2017 21:09:32 +0100 Subject: [PATCH 024/136] change in publishing fee --- libraries/chain/decent_evaluator.cpp | 3 --- libraries/chain/include/graphene/chain/protocol/decent.hpp | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index 56a9fa9b..40cd2aae 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -46,9 +46,6 @@ void content_payout(database& db, asset price, const content_object& content){ } - - - void_result set_publishing_manager_evaluator::do_evaluate( const set_publishing_manager_operation& o ) {try{ for( const auto id : o.to ) diff --git a/libraries/chain/include/graphene/chain/protocol/decent.hpp b/libraries/chain/include/graphene/chain/protocol/decent.hpp index 33f00f87..2a5b92cf 100644 --- a/libraries/chain/include/graphene/chain/protocol/decent.hpp +++ b/libraries/chain/include/graphene/chain/protocol/decent.hpp @@ -66,7 +66,7 @@ namespace graphene { namespace chain { */ struct content_submit_operation : public base_operation { - struct fee_parameters_type { uint64_t fee = 0; }; + struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION / 1000; }; asset fee; account_id_type author; /// Date: Tue, 5 Dec 2017 10:35:20 +0100 Subject: [PATCH 025/136] memo decryption fix in operation_printer --- libraries/wallet/wallet.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index c0e4e9e2..42f4b4a1 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3096,12 +3096,18 @@ signed_transaction content_cancellation(string author, FC_ASSERT(my_memo_key, "Unable to recover private key to decrypt memo. Wallet may be corrupted."); keys_to_try_to.push_back(*my_memo_key); for( auto k: to_account.active.key_auths ) { - auto my_key = wif_to_key(wallet._keys.at(k.first)); + auto key_itr = wallet._keys.find(k.first); + if( key_itr == wallet._keys.end() ) + continue; + auto my_key = wif_to_key(key_itr->second); if(my_key) keys_to_try_to.push_back(*my_key); } for( auto k: to_account.owner.key_auths ) { - auto my_key = wif_to_key(wallet._keys.at(k.first)); + auto key_itr = wallet._keys.find(k.first); + if( key_itr == wallet._keys.end() ) + continue; + auto my_key = wif_to_key(key_itr->second); if(my_key) keys_to_try_to.push_back(*my_key); } @@ -3142,12 +3148,18 @@ signed_transaction content_cancellation(string author, FC_ASSERT(my_memo_key, "Unable to recover private key to decrypt memo. Wallet may be corrupted."); keys_to_try_from.push_back(*my_memo_key); for( auto k: from_account.active.key_auths ) { - auto my_key = wif_to_key(wallet._keys.at(k.first)); + auto key_itr = wallet._keys.find(k.first); + if( key_itr == wallet._keys.end() ) + continue; + auto my_key = wif_to_key(key_itr->second); if(my_key) keys_to_try_from.push_back(*my_key); } for( auto k: from_account.owner.key_auths ) { - auto my_key = wif_to_key(wallet._keys.at(k.first)); + auto key_itr = wallet._keys.find(k.first); + if( key_itr == wallet._keys.end() ) + continue; + auto my_key = wif_to_key(key_itr->second); if(my_key) keys_to_try_from.push_back(*my_key); } From 10aa71cfe9ec20083cd295d5d07517df068ddc1d Mon Sep 17 00:00:00 2001 From: ejossev Date: Wed, 6 Dec 2017 12:44:33 +0100 Subject: [PATCH 026/136] generate_content_keys in wallet and HF2 defined --- libraries/chain/hardfork.d/2.hf | 6 ++++++ libraries/wallet/include/graphene/wallet/wallet.hpp | 9 +++++++++ libraries/wallet/wallet.cpp | 4 ++++ 3 files changed, 19 insertions(+) create mode 100644 libraries/chain/hardfork.d/2.hf diff --git a/libraries/chain/hardfork.d/2.hf b/libraries/chain/hardfork.d/2.hf new file mode 100644 index 00000000..7da28e07 --- /dev/null +++ b/libraries/chain/hardfork.d/2.hf @@ -0,0 +1,6 @@ +// #2 - simple buying + +#ifndef HARDFORK_2_TIME +#define HARDFORK_2_TIME (fc::time_point_sec( 1410238800 )) +#endif + diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 23b1496e..8f0ea2ef 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1776,6 +1776,14 @@ namespace graphene { namespace wallet { */ DInteger generate_encryption_key() const; + /** + * @brief Generate keys for new content submission + * @param seeders list of seeder account IDs + * @return generated key and key parts + * @ingroup WalletCLI + */ + content_keys generate_content_keys(vector const& seeders)const; + /** * @brief Get a list of open buyings * @return Open buying objects @@ -2253,4 +2261,5 @@ FC_API( graphene::wallet::wallet_api, (get_message_objects) (get_messages) (get_sent_messages) + (generate_content_keys) ) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index c0e4e9e2..3d652812 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -4881,6 +4881,10 @@ void graphene::wallet::detail::submit_transfer_listener::package_seed_complete() return my->get_sent_messages(sender, max_count); } + content_keys wallet_api::generate_content_keys(vector const& seeders)const + { + return my->_remote_db->generate_content_keys(seeders); + } } } // graphene::wallet From 51b7d1fe268b85f58c84c13454ace507bef7ea1a Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 7 Dec 2017 14:27:30 +0100 Subject: [PATCH 027/136] fix/buying_expiration_in_deliver_keys_eval --- libraries/chain/db_decent.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/libraries/chain/db_decent.cpp b/libraries/chain/db_decent.cpp index 67de1d62..f5fcb6ea 100644 --- a/libraries/chain/db_decent.cpp +++ b/libraries/chain/db_decent.cpp @@ -41,15 +41,27 @@ namespace graphene { namespace chain { void database::buying_expire(const buying_object& buying){ + return_escrow_buying_operation rebop; + rebop.escrow = buying.price; + rebop.consumer = buying.consumer; + rebop.buying = buying.id; + adjust_balance( buying.consumer, buying.price ); modify(buying, [&](buying_object& bo){ bo.price.amount = 0; bo.expired = true; bo.expiration_or_delivery_time = head_block_time(); }); + + push_applied_operation(rebop); } void database::content_expire(const content_object& content){ + return_escrow_submission_operation resop; + resop.escrow = content.publishing_fee_escrow; + resop.author = content.author; + resop.content = content.id; + if( content.publishing_fee_escrow.amount >= 0 ) adjust_balance( content.author, content.publishing_fee_escrow ); else //workaround due to block halt at #404726- this should never happen but if it does again, the remaining amount shall be paid by someone else, in this case by decent6 @@ -80,6 +92,8 @@ void database::content_expire(const content_object& content){ }); } } + + push_applied_operation( resop ); } void database::renew_subscription(const subscription_object& subscription, const uint32_t subscription_period, const asset price){ @@ -210,15 +224,7 @@ void database::decent_housekeeping() auto citr = cidx.lower_bound( get_dynamic_global_properties().last_budget_time + get_global_properties().parameters.block_interval ); while( citr != cidx.end() && citr->expiration <= head_block_time() ) { - return_escrow_submission_operation resop; - resop.escrow = citr->publishing_fee_escrow; - content_expire(*citr); - - resop.author = citr->author; - resop.content = citr->id; - push_applied_operation( resop ); - ++citr; } @@ -226,17 +232,9 @@ void database::decent_housekeeping() auto bitr = bidx.lower_bound( get_dynamic_global_properties().last_budget_time + get_global_properties().parameters.block_interval ); while( bitr != bidx.end() && bitr->expiration_time <= head_block_time() ) { - if(!bitr->delivered) { - return_escrow_buying_operation rebop; - rebop.escrow = bitr->price; - + if(!bitr->delivered) buying_expire(*bitr); - rebop.consumer = bitr->consumer; - rebop.buying = bitr->id; - push_applied_operation(rebop); - - } ++bitr; } From fee762794857de6800f39107237d18288a39517c Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 7 Dec 2017 14:32:13 +0100 Subject: [PATCH 028/136] fix/payment_splitting --- libraries/chain/decent_evaluator.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index e401cba5..1ba581fe 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -624,17 +624,17 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri //The content just has been successfuly delivered, take care of the payment if( delivered ) { - asset price = buying.price; db().modify( *content, []( content_object& co ){ co.times_bought++; }); if( content->co_authors.empty() ) - db().adjust_balance( content->author, price ); + db().adjust_balance( content->author, buying.paid_price_after_exchange ); else { + asset price = buying.paid_price_after_exchange; boost::multiprecision::int128_t price_for_co_author; for( auto const &element : content->co_authors ) { - price_for_co_author = ( price.amount.value * element.second ) / 10000ll ; + price_for_co_author = ( buying.paid_price_after_exchange.amount.value * element.second ) / 10000ll ; db().adjust_balance( element.first, asset( static_cast(price_for_co_author), price.asset_id) ); price.amount -= price_for_co_author; } @@ -654,7 +654,7 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri finish_buying_operation op; op.author = content->author; op.co_authors = content->co_authors; - op.payout = price; + op.payout = buying.paid_price_after_exchange; op.consumer = buying.consumer; op.buying = buying.id; From 78ac420cd6f4b291faa11558e841391e3e415931 Mon Sep 17 00:00:00 2001 From: ejossev Date: Fri, 8 Dec 2017 15:43:20 +0100 Subject: [PATCH 029/136] speeding up sync with checkpoints --- libraries/chain/db_update.cpp | 9 +++++++++ libraries/chain/decent_evaluator.cpp | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index 0a5a0e0e..1340fd0e 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -143,6 +143,15 @@ void database::update_last_irreversible_block() const global_property_object& gpo = get_global_properties(); const dynamic_global_property_object& dpo = get_dynamic_global_properties(); + if(get_node_properties().skip_flags&skip_undo_history_check) + { + modify( dpo, [&]( dynamic_global_property_object& _dpo ) + { + _dpo.last_irreversible_block_num = head_block_num(); + } ); + return; + } + vector< const miner_object* > wit_objs; wit_objs.reserve( gpo.active_miners.size() ); for( const miner_id_type& wid : gpo.active_miners ) diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index 40cd2aae..81da26b3 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -577,9 +577,8 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri const auto& firstK = content->key_parts.at( o.seeder ); const auto& secondK = o.key; const auto& proof = o.proof; - if(!(db().get_node_properties().skip_flags&db().skip_validate)) { + if(!(db().get_node_properties().skip_flags&db().skip_undo_history_check)) { FC_ASSERT(decent::encrypt::verify_delivery_proof(proof, firstK, secondK, seeder_pubKey, buyer_pubKey)); - }else{ } return void_result(); @@ -808,8 +807,10 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri } // FC_ASSERT( content->cd.valid() == o.proof.valid() ); - FC_ASSERT( !(content->cd.valid() ) || _custody_utils.verify_by_miner( *(content->cd), *(o.proof) ) == 0, "Invalid proof of custody" ); + if(!(db().get_node_properties().skip_flags&db().skip_validate)) { + FC_ASSERT( !(content->cd.valid() ) || _custody_utils.verify_by_miner( *(content->cd), *(o.proof) ) == 0, "Invalid proof of custody" ); + } //ilog("proof_of_custody OK"); return void_result(); From c2e9bed1b1b79e964ac6ef42a2052f8d5efbdceb Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Fri, 15 Dec 2017 13:16:07 +0100 Subject: [PATCH 030/136] fix/payment_splitting --- libraries/chain/decent_evaluator.cpp | 12 ++--- tests/common/database_fixture.cpp | 3 +- tests/common/database_fixture.hpp | 2 +- tests/tests/uia_tests.cpp | 81 ++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 8 deletions(-) diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index 40cd2aae..19a7e272 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -23,15 +23,16 @@ namespace graphene { namespace chain { namespace { -void content_payout(database& db, asset price, const content_object& content){ +void content_payout(database& db, asset paid_price_after_exchange, const content_object& content){ if( content.co_authors.empty() ) - db.adjust_balance( content.author, price ); + db.adjust_balance( content.author, paid_price_after_exchange ); else { + asset price = paid_price_after_exchange; boost::multiprecision::int128_t price_for_co_author; for( auto const &element : content.co_authors ) { - price_for_co_author = ( price.amount.value * element.second ) / 10000ll ; + price_for_co_author = ( paid_price_after_exchange.amount.value * element.second ) / 10000ll ; db.adjust_balance( element.first, asset( static_cast(price_for_co_author), price.asset_id) ); price.amount -= price_for_co_author; } @@ -615,10 +616,9 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri //The content just has been successfuly delivered, take care of the payment if( delivered ) { - asset price = buying.price; db().modify( *content, []( content_object& co ){ co.times_bought++; }); - content_payout(db(), price, *content); + content_payout(db(), buying.paid_price_after_exchange, *content); db().modify(buying, [&](buying_object& bo){ bo.price.amount = 0; @@ -629,7 +629,7 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri finish_buying_operation op; op.author = content->author; op.co_authors = content->co_authors; - op.payout = price; + op.payout = buying.paid_price_after_exchange; op.consumer = buying.consumer; op.buying = buying.id; diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 5e4c8bd2..d5d5b318 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -625,7 +625,7 @@ void database_fixture::publish_feed( const asset_object& mia, const account_obje verify_asset_supplies(db); } -void database_fixture::create_content(account_id_type by, string url, asset price) +void database_fixture::create_content(account_id_type by, string url, asset price, map co_authors) { set_expiration( db, trx ); trx.operations.clear(); @@ -634,6 +634,7 @@ void database_fixture::create_content(account_id_type by, string url, asset pric op.size = 100; op.price.push_back({RegionCodes::OO_none, price}); op.author = by; + op.co_authors = co_authors; op.URI = url; op.hash = fc::ripemd160::hash(url); op.expiration = fc::time_point::now()+fc::microseconds(10000000000); diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 05fe178c..61cf0bc8 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -245,7 +245,7 @@ struct database_fixture { void fill_pools(asset_id_type uia, account_id_type by, asset to_core_pool, asset to_asset_pool); - void create_content(account_id_type by, string url, asset price); + void create_content(account_id_type by, string url, asset price, map co_authors={}); void buy_content(account_id_type by, string url, asset price); diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index 84a45a1b..a6ca5e1a 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -300,4 +300,85 @@ BOOST_AUTO_TEST_CASE( asset_content_in_dct_test ) } } +BOOST_AUTO_TEST_CASE( payment_splitting_test ) +{ + try + { + ilog("payment_splitting_test start"); + //names must be at least 5 characters long... + ACTORS( (alice)(bobian)(cecil)(david) ); + fund( alice_id(db), asset(107) ); + + auto has_asset = [&]( std::string symbol ) -> bool + { + const auto& assets_by_symbol = db.get_index_type().indices().get(); + return assets_by_symbol.find( symbol ) != assets_by_symbol.end(); + }; + + //create content + map co_authors; + // bobian 70% + co_authors[cecil_id]=2000; // 20% + co_authors[david_id]=1000; // 10% + create_content(bobian_id, "http://abcd1", asset(100), co_authors); + + BOOST_CHECK(get_balance( alice_id, asset_id_type()) == 107); + BOOST_CHECK(get_balance(bobian_id, asset_id_type()) == 0); + BOOST_CHECK(get_balance( cecil_id, asset_id_type()) == 0); + BOOST_CHECK(get_balance( david_id, asset_id_type()) == 0); + + buy_content(alice_id, "http://abcd1", asset(100)); + + BOOST_CHECK(get_balance( alice_id, asset_id_type()) == 7); + BOOST_CHECK(get_balance(bobian_id, asset_id_type()) == 70); + BOOST_CHECK(get_balance( cecil_id, asset_id_type()) == 20); + BOOST_CHECK(get_balance( david_id, asset_id_type()) == 10); + + //create content, shares are indivisible + co_authors[cecil_id] =3000; // 30% + co_authors[bobian_id]=5000; // 50% + co_authors[david_id] =2000; // 20% + create_content(bobian_id, "http://abcd2", asset(7), co_authors); + + buy_content(alice_id, "http://abcd2", asset(7)); + + BOOST_CHECK(get_balance( alice_id, asset_id_type()) == 0); + BOOST_CHECK(get_balance(bobian_id, asset_id_type()) == 70+4); + BOOST_CHECK(get_balance( cecil_id, asset_id_type()) == 20+2); + BOOST_CHECK(get_balance( david_id, asset_id_type()) == 10+1); + + + BOOST_CHECK( !has_asset("UIA") ); + asset_id_type uia_asset_id = db.get_index().get_next_id(); + create_user_issued_asset( "UIA", alice_id(db) ); + BOOST_CHECK( has_asset("UIA") ); + issue_uia( alice_id(db), asset(100, uia_asset_id)); + + //create content, price in UIA + co_authors[bobian_id]=7000; // 50% + 20% + co_authors[cecil_id] =2000; // 20% + co_authors[david_id] =1000; // 10% + create_content(bobian_id, "http://abcd3", asset(100,uia_asset_id), co_authors); + + BOOST_CHECK(get_balance( alice_id, uia_asset_id) == 100); + BOOST_CHECK(get_balance(bobian_id, uia_asset_id) == 0); + BOOST_CHECK(get_balance( cecil_id, uia_asset_id) == 0); + BOOST_CHECK(get_balance( david_id, uia_asset_id) == 0); + + buy_content(alice_id, "http://abcd3", asset(100,uia_asset_id)); + + BOOST_CHECK(get_balance( alice_id, uia_asset_id) == 0); + BOOST_CHECK(get_balance(bobian_id, uia_asset_id) == 70); + BOOST_CHECK(get_balance( cecil_id, uia_asset_id) == 20); + BOOST_CHECK(get_balance( david_id, uia_asset_id) == 10); + + ilog("payment_splitting_test end"); + } + catch(fc::exception& e) + { + edump((e.to_detail_string())); + throw; + } +} + BOOST_AUTO_TEST_SUITE_END() From 56539cbdddf0f45bc57e7a1d4a2bf2bc558af298 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Fri, 15 Dec 2017 14:24:53 +0100 Subject: [PATCH 031/136] fix/buying expiration in deliver_keys_eval --- libraries/chain/db_decent.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/libraries/chain/db_decent.cpp b/libraries/chain/db_decent.cpp index 67de1d62..a95d8029 100644 --- a/libraries/chain/db_decent.cpp +++ b/libraries/chain/db_decent.cpp @@ -41,15 +41,28 @@ namespace graphene { namespace chain { void database::buying_expire(const buying_object& buying){ + + return_escrow_buying_operation rebop; + rebop.escrow = buying.price; + rebop.consumer = buying.consumer; + rebop.buying = buying.id; + adjust_balance( buying.consumer, buying.price ); modify(buying, [&](buying_object& bo){ bo.price.amount = 0; bo.expired = true; bo.expiration_or_delivery_time = head_block_time(); }); + + push_applied_operation(rebop); } void database::content_expire(const content_object& content){ + return_escrow_submission_operation resop; + resop.escrow = content.publishing_fee_escrow; + resop.author = content.author; + resop.content = content.id; + if( content.publishing_fee_escrow.amount >= 0 ) adjust_balance( content.author, content.publishing_fee_escrow ); else //workaround due to block halt at #404726- this should never happen but if it does again, the remaining amount shall be paid by someone else, in this case by decent6 @@ -80,6 +93,8 @@ void database::content_expire(const content_object& content){ }); } } + + push_applied_operation( resop ); } void database::renew_subscription(const subscription_object& subscription, const uint32_t subscription_period, const asset price){ @@ -210,15 +225,7 @@ void database::decent_housekeeping() auto citr = cidx.lower_bound( get_dynamic_global_properties().last_budget_time + get_global_properties().parameters.block_interval ); while( citr != cidx.end() && citr->expiration <= head_block_time() ) { - return_escrow_submission_operation resop; - resop.escrow = citr->publishing_fee_escrow; - content_expire(*citr); - - resop.author = citr->author; - resop.content = citr->id; - push_applied_operation( resop ); - ++citr; } @@ -226,17 +233,9 @@ void database::decent_housekeeping() auto bitr = bidx.lower_bound( get_dynamic_global_properties().last_budget_time + get_global_properties().parameters.block_interval ); while( bitr != bidx.end() && bitr->expiration_time <= head_block_time() ) { - if(!bitr->delivered) { - return_escrow_buying_operation rebop; - rebop.escrow = bitr->price; - + if(!bitr->delivered) buying_expire(*bitr); - rebop.consumer = bitr->consumer; - rebop.buying = bitr->id; - push_applied_operation(rebop); - - } ++bitr; } From 881d1a4f3035e573b9c707af3bdd4bb59b3f3f5a Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 18 Dec 2017 15:54:59 +0100 Subject: [PATCH 032/136] fix in public key generation --- libraries/wallet/wallet.cpp | 53 ++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index bf6d64c3..61306bae 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3574,29 +3574,40 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati { brain_key_info result; // create a private key for secure entropy - fc::sha256 sha_entropy1 = fc::ecc::private_key::generate().get_secret(); - fc::sha256 sha_entropy2 = fc::ecc::private_key::generate().get_secret(); - fc::bigint entropy1( sha_entropy1.data(), sha_entropy1.data_size() ); - fc::bigint entropy2( sha_entropy2.data(), sha_entropy2.data_size() ); - fc::bigint entropy(entropy1); - entropy <<= 8*sha_entropy1.data_size(); - entropy += entropy2; - string brain_key = ""; - - for( int i=0; i 0 ) - brain_key += " "; - brain_key += graphene::words::word_list[ choice.to_int64() ]; + string brain_key; + bool cont; + fc::ecc::private_key priv_key; + + do { + cont = false; + fc::sha256 sha_entropy1 = fc::ecc::private_key::generate().get_secret(); + fc::sha256 sha_entropy2 = fc::ecc::private_key::generate().get_secret(); + fc::bigint entropy1(sha_entropy1.data(), sha_entropy1.data_size()); + fc::bigint entropy2(sha_entropy2.data(), sha_entropy2.data_size()); + fc::bigint entropy(entropy1); + entropy <<= 8 * sha_entropy1.data_size(); + entropy += entropy2; + brain_key = "" ; + for (int i = 0; i < BRAIN_KEY_WORD_COUNT; i++) { + fc::bigint choice = entropy % graphene::words::word_list_size; + entropy /= graphene::words::word_list_size; + if (i > 0) + brain_key += " "; + brain_key += graphene::words::word_list[choice.to_int64()]; + } + + brain_key = normalize_brain_key(brain_key); + priv_key = derive_private_key(brain_key, 0); + result.brain_priv_key = brain_key; + result.wif_priv_key = key_to_wif( priv_key ); + try { + result.pub_key = priv_key.get_public_key(); + }catch(fc::assert_exception ae) { + cont = true; + } } + while (cont); - brain_key = normalize_brain_key(brain_key); - fc::ecc::private_key priv_key = derive_private_key( brain_key, 0 ); - result.brain_priv_key = brain_key; - result.wif_priv_key = key_to_wif( priv_key ); - result.pub_key = priv_key.get_public_key(); return result; } From 596ceda53a0903350e945294f43cc883eed32f91 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 18 Dec 2017 16:29:32 +0100 Subject: [PATCH 033/136] corrected description of info command --- libraries/wallet/include/graphene/wallet/wallet.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 0af24122..2951fa80 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -280,8 +280,9 @@ namespace graphene { namespace wallet { fc::ecc::private_key derive_private_key(const std::string& prefix_string, int sequence_number) const; /** - * @brief Lists all available commands. - * @return a list of all available commands + * @brief Get information about current state of the blockchain, + * such as head block number, chain_id, list of active miners,... + * @return information about current state of the blockchain * @ingroup WalletAPI_General */ variant info(); From e1a7a9f576c04fb1d763155eb89ac496b54c7998 Mon Sep 17 00:00:00 2001 From: ejossev Date: Wed, 20 Dec 2017 14:47:39 +0100 Subject: [PATCH 034/136] minor bugfixes --- libraries/app/api.cpp | 1 - .../include/graphene/chain/protocol/types.hpp | 2 -- .../include/graphene/seeding/seeding.hpp | 1 + libraries/plugins/seeding/seeding.cpp | 17 ++++++++++++++--- .../wallet/include/graphene/wallet/wallet.hpp | 1 + 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 5137ab94..b9a2f651 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -282,7 +282,6 @@ namespace graphene { namespace app { switch( (object_type)obj->id.type() ) { case null_object_type: - case base_object_type: case OBJECT_TYPE_COUNT: return result; case account_object_type:{ diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index 257e3395..6cd56407 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -111,7 +111,6 @@ namespace graphene { namespace chain { enum object_type { null_object_type, - base_object_type, account_object_type, asset_object_type, miner_object_type, @@ -317,7 +316,6 @@ FC_REFLECT( graphene::chain::extended_private_key_type::binary_key, (check)(data FC_REFLECT_ENUM( graphene::chain::object_type, (null_object_type) - (base_object_type) (account_object_type) (asset_object_type) (miner_object_type) diff --git a/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp b/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp index 8271de02..78b19f50 100644 --- a/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp +++ b/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp @@ -208,6 +208,7 @@ class SeedingListener : public decent::package::EventListenerInterface, public s string _url; decent::package::package_handle_t _pi; seeding_plugin_impl *_my; + int failed=0; public: SeedingListener(seeding_plugin_impl &impl, const my_seeding_object &mso, const decent::package::package_handle_t pi) { diff --git a/libraries/plugins/seeding/seeding.cpp b/libraries/plugins/seeding/seeding.cpp index 8f6c5693..1f49afac 100644 --- a/libraries/plugins/seeding/seeding.cpp +++ b/libraries/plugins/seeding/seeding.cpp @@ -733,13 +733,24 @@ void seeding_plugin::plugin_set_program_options( void detail::SeedingListener::package_download_error(const std::string & error) { elog("seeding plugin: package_download_error(): Failed downloading package ${s}, ${e}", ("s", _url)("e", error)); + failed++; decent::package::package_handle_t pi; auto& pm = decent::package::PackageManager::instance(); pi = _pi; - //we want to restart the download; however, this method is being called from pi->_download_task::Task method, so we can't restart directly. - // We will start asynchronously - fc::thread::current().schedule([pi](){ pi->download(true);}, fc::time_point::now() + fc::seconds(60) ); + + if(failed < 5) { + //we want to restart the download; however, this method is being called from pi->_download_task::Task method, so we can't restart directly. + // We will start asynchronously + fc::thread::current().schedule([ pi ]() { pi->download(true); }, fc::time_point::now() + fc::seconds(60)); + } + else{ + const auto& db = _my->database(); + const auto &mso_idx = db.get_index_type().indices().get(); + const auto &mso_itr = mso_idx.find(_url); + const auto& mso = *mso_itr; + _my->release_package(mso, pi); + } }; void detail::SeedingListener::package_download_complete() { diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index f6a9b09a..ed59a84e 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -112,6 +112,7 @@ namespace graphene { namespace wallet { /** encrypted keys */ vector cipher_keys; + /** map an account to a set of extra keys that have been imported for that account */ map > extra_keys; From 332df7b61b18ec4dd19738fc4737102aca666eef Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Fri, 22 Dec 2017 10:58:27 +0100 Subject: [PATCH 035/136] limiting the seeding price --- libraries/app/api.cpp | 2 ++ libraries/app/include/graphene/app/api.hpp | 2 ++ .../chain/include/graphene/chain/config.hpp | 1 + .../graphene/seeding/seeding_utility.hpp | 3 +-- libraries/plugins/seeding/seeding.cpp | 19 ++++++++++++------- .../wallet/include/graphene/wallet/wallet.hpp | 2 ++ libraries/wallet/wallet.cpp | 6 ++++-- 7 files changed, 24 insertions(+), 11 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 5137ab94..de4513f0 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -215,6 +215,7 @@ namespace graphene { namespace app { const fc::ecc::private_key& seeder_private_key, const uint64_t free_space, const uint32_t seeding_price, + const string seeding_symbol, const string packages_path, const string region_code) { @@ -227,6 +228,7 @@ namespace graphene { namespace app { seeding_options.seeder_private_key = seeder_private_key; seeding_options.free_space = free_space; seeding_options.seeding_price = seeding_price; + seeding_options.seeding_symbol = seeding_symbol; seeding_options.packages_path = packages_path; seeding_options.region_code = region_code; decent::seeding::seeding_promise->set_value( seeding_options ); diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index d9751be3..8cd88557 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -240,6 +240,7 @@ namespace graphene { namespace app { * @param seeder_private_key Private key of the account controlling this seeder * @param free_space Allocated disk space, in MegaBytes * @param seeding_price Price per MegaBytes + * @param seeding_symbol seeding price asset, e.g. DCT * @param packages_path Packages storage path * @param region_code Optional ISO 3166-1 alpha-2 two-letter region code * @ingroup Network_NodeAPI @@ -249,6 +250,7 @@ namespace graphene { namespace app { const fc::ecc::private_key& seeder_private_key, const uint64_t free_space, const uint32_t seeding_price, + const string seeding_symbol, const string packages_path, const string region_code = "" ); diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index 3fc3c6cd..dc3f0a2a 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -65,6 +65,7 @@ #define DECENT_MAX_FILE_SIZE 10000 /// MBs, aka: 10 GBs #define DECENT_MAX_COMMENT_SIZE 100 /// chars #define DECENT_MAX_SUBSCRIPTION_PERIOD 365 /// days, aka: 1 year +#define DECENT_MAX_SEEDING_PRICE 100000000 /// 1 DCT per MB /** * Don't allow the committee_members to publish a limit that would * make the network unable to operate. diff --git a/libraries/plugins/seeding/include/graphene/seeding/seeding_utility.hpp b/libraries/plugins/seeding/include/graphene/seeding/seeding_utility.hpp index fc94ce93..038a8da2 100644 --- a/libraries/plugins/seeding/include/graphene/seeding/seeding_utility.hpp +++ b/libraries/plugins/seeding/include/graphene/seeding/seeding_utility.hpp @@ -15,10 +15,9 @@ namespace decent { namespace seeding { fc::ecc::private_key seeder_private_key; uint64_t free_space; std::string seeding_price; + std::string seeding_symbol; fc::path packages_path; std::string region_code; - std::string seeding_symbol; - }; extern fc::promise::ptr seeding_promise; diff --git a/libraries/plugins/seeding/seeding.cpp b/libraries/plugins/seeding/seeding.cpp index 8f6c5693..c67467b4 100644 --- a/libraries/plugins/seeding/seeding.cpp +++ b/libraries/plugins/seeding/seeding.cpp @@ -366,17 +366,23 @@ void seeding_plugin_impl::send_ready_to_publish() } const asset_object &ao = *itr; - asset dct_price = ao.amount_from_string(sritr->price); if( ao.id != asset_id_type()) //core asset - dct_price = dct_price * ao.monitored_asset_opts->current_feed.core_exchange_rate; + dct_price = database().price_to_dct( dct_price ); + + if( dct_price.amount.value > DECENT_MAX_SEEDING_PRICE) + { + const auto& dct_ao = database().get(asset_id_type()); + ilog("Seeding price limit ${limit} DCT exceeded.",("limit",dct_ao.amount_to_string(DECENT_MAX_SEEDING_PRICE))); + FC_THROW(""); + } signed_transaction tx; if( database().head_block_time() < HARDFORK_1_TIME) { ready_to_publish_operation op; op.seeder = sritr->seeder; op.space = sritr->free_space; - op.price_per_MByte = dct_price.amount.value;; + op.price_per_MByte = dct_price.amount.value; op.pubKey = get_public_el_gamal_key(sritr->content_privKey); op.ipfs_ID = json[ "ID" ]; @@ -387,7 +393,7 @@ void seeding_plugin_impl::send_ready_to_publish() ready_to_publish2_operation op; op.seeder = sritr->seeder; op.space = sritr->free_space; - op.price_per_MByte = dct_price.amount.value;; + op.price_per_MByte = dct_price.amount.value; op.pubKey = get_public_el_gamal_key(sritr->content_privKey); op.ipfs_ID = json[ "ID" ]; op.region_code = sritr->region_code; @@ -415,7 +421,7 @@ void seeding_plugin_impl::send_ready_to_publish() //fc::usleep(fc::microseconds(1000000)); sritr++; } - }catch(...){}; + }catch(...){elog("Didn't send out RtP.");}; fc::time_point next_wakeup(fc::time_point::now() + fc::microseconds( (uint64_t) 1000000 * (DECENT_RTP_VALIDITY / 2 ))); //let's send PoR every hour ilog("seeding plugin_impl: planning next send_ready_to_publish at ${t}",("t",next_wakeup )); service_thread->schedule([=](){ send_ready_to_publish();}, next_wakeup, "Seeding plugin RtP generate" ); @@ -676,7 +682,7 @@ void seeding_plugin::plugin_pre_startup( const seeding_plugin_startup_options& s dir_helper.set_packages_path( seeding_options.packages_path ); else dir_helper.set_packages_path( dir_helper.get_decent_packages() / "seeding" ); - + ilog("starting service thread"); my = unique_ptr( new detail::seeding_plugin_impl( *this) ); my->service_thread = std::make_shared("seeding"); @@ -702,7 +708,6 @@ void seeding_plugin::plugin_pre_startup( const seeding_plugin_startup_options& s mso.privKey = seeding_options.seeder_private_key; mso.price = seeding_options.seeding_price; mso.region_code = seeding_options.region_code; - mso.symbol = seeding_options.seeding_symbol; }); }catch(...){} diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index ee71a1af..24437a87 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1639,6 +1639,7 @@ namespace graphene { namespace wallet { * @param seeder_private_key Private key of the account controlling this seeder * @param free_space Allocated disk space, in MegaBytes * @param seeding_price price per MegaByte + * @param seeding_symbol seeding price asset, e.g. DCT * @param packages_path Packages storage path * @param region_code Optional ISO 3166-1 alpha-2 two-letter region code * @ingroup WalletCLI @@ -1648,6 +1649,7 @@ namespace graphene { namespace wallet { string seeder_private_key, uint64_t free_space, uint32_t seeding_price, + string seeding_symbol, string packages_path, string region_code = "" ); diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index bf6d64c3..104073dd 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2573,13 +2573,14 @@ signed_transaction content_cancellation(string author, string seeder_private_key, uint64_t free_space, uint32_t seeding_price, + string seeding_symbol, string packages_path, string region_code) { account_id_type seeder = get_account_id( account_id_type_or_name ); use_network_node_api(); fc::ecc::private_key seeder_priv_key = *(wif_to_key(seeder_private_key)); - (*_remote_net_node)->seeding_startup( seeder, content_private_key, seeder_priv_key, free_space, seeding_price, packages_path, region_code); + (*_remote_net_node)->seeding_startup( seeder, content_private_key, seeder_priv_key, free_space, seeding_price, seeding_symbol, packages_path, region_code); } signed_transaction subscribe_to_author( string from, @@ -4472,10 +4473,11 @@ void wallet_api::leave_rating_and_comment(string consumer, string seeder_private_key, uint64_t free_space, uint32_t seeding_price, + string seeding_symbol, string packages_path, string region_code) { - return my->seeding_startup(account_id_type_or_name, content_private_key, seeder_private_key, free_space, seeding_price, packages_path, region_code); + return my->seeding_startup(account_id_type_or_name, content_private_key, seeder_private_key, free_space, seeding_price, seeding_symbol, packages_path, region_code); } DInteger wallet_api::restore_encryption_key(string consumer, buying_id_type buying) From 264f49a2d9c049d9d02d3064ae07d9d79d7b0d50 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 25 Jan 2018 13:51:54 +0100 Subject: [PATCH 036/136] removing obsollete and not used functions --- .../wallet/include/graphene/wallet/wallet.hpp | 144 ---------- libraries/wallet/wallet.cpp | 272 ++---------------- 2 files changed, 28 insertions(+), 388 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 24437a87..75c89362 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -246,14 +246,6 @@ namespace graphene { namespace wallet { wallet_api( const wallet_data& initial_data, fc::api rapi ); virtual ~wallet_api(); - /** - * @brief Copy wallet file to a new file - * @param destination_filename - * @return true if the wallet is copied, false otherwise - * @ingroup WalletCLI - */ - bool copy_wallet_file( string destination_filename ); - /** * @brief Derive private key from given prefix and sequence * @param prefix_string @@ -448,22 +440,6 @@ namespace graphene { namespace wallet { */ monitored_asset_options get_monitored_asset_data(string asset_name_or_id)const; - /** - * @brief Lookup the id of a named account. - * @param account_name_or_id the name of the account to look up - * @returns the id of the named account - * @ingroup WalletCLI - */ - account_id_type get_account_id(string account_name_or_id) const; - - /** - * @brief Lookup the id of a named asset. - * @param asset_name_or_id the symbol of an asset to look up - * @returns the id of the given asset - * @ingroup WalletCLI - */ - asset_id_type get_asset_id(string asset_name_or_id) const; - /** * @brief Returns the blockchain object corresponding to the given id. * @@ -777,26 +753,6 @@ namespace graphene { namespace wallet { */ bool import_key(string account_name_or_id, string wif_key); - /** - * @brief Imports accounts from the other wallet file - * @param filename The filename of the wallet JSON file - * @param password User's password to the wallet - * @return mapped account names to boolean values indicating whether the account was successfully imported - * @ingroup WalletCLI - */ - map import_accounts( string filename, string password ); - - /** - * @brief Imports account keys from particular account from another wallet file to desired account located in wallet file currently used - * @param filename The filename of the wallet JSON file - * @param password User's password to the wallet - * @param src_account_name Name of the source account - * @param dest_account_name Name of the destination account - * @return true if the keys were imported - * @ingroup WalletCLI - */ - bool import_account_keys( string filename, string password, string src_account_name, string dest_account_name ); - /** * @brief Transforms a brain key to reduce the chance of errors when re-entering the key from memory. * @@ -856,25 +812,6 @@ namespace graphene { namespace wallet { string account_name, string registrar_account, bool broadcast = false); - /** - * @brief Creates a new account and registers it on the blockchain, but does not import the key to wallet. - * - * @see suggest_brain_key() - * @see register_account() - * - * @param brain_key the brain key used for generating the account's private keys - * @param account_name the name of the account, must be unique on the blockchain. Shorter names - * are more expensive to register; the rules are still in flux, but in general - * names of more than 8 characters with at least one digit will be cheap. - * @param registrar_account the account which will pay the fee to register the user - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction registering the account - * @ingroup WalletCLI - */ - signed_transaction create_account_with_brain_key_noimport(string brain_key, - string account_name, - string registrar_account, - bool broadcast = false); /** @brief Transfer an amount from one account to another. * @param from the name or id of the account sending the funds @@ -896,28 +833,6 @@ namespace graphene { namespace wallet { string memo, bool broadcast = false); - /** - * @brief This method works just like transfer, except it always broadcasts and - * returns the transaction ID along with the signed transaction. - * @param from the name or id of the account sending the funds - * @param to the name or id of the account receiving the funds - * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) - * @param asset_symbol the symbol or id of the asset to send - * @param memo a memo to attach to the transaction. The memo will be encrypted in the - * transaction and readable for the receiver. There is no length limit - * other than the limit imposed by maximum transaction size, but transaction - * increase with transaction size - * @ingroup WalletCLI - */ - pair transfer2(string from, - string to, - string amount, - string asset_symbol, - string memo ) { - auto trx = transfer( from, to, amount, asset_symbol, memo, true ); - return std::make_pair(trx.id(),trx); - } - /** * @brief Encapsulates begin_builder_transaction(), add_operation_to_builder_transaction(), * propose_builder_transaction2(), set_fees_on_builder_transaction() functions for transfer operation @@ -943,15 +858,6 @@ namespace graphene { namespace wallet { time_point_sec expiration ); - /** - * @brief This method is used to convert a JSON transaction to its transaction ID. - * @param trx Signed transaction - * @return - * @ingroup WalletCLI - */ - transaction_id_type get_transaction_id( const signed_transaction& trx )const { return trx.id(); } - - /** * @brief Creates a new monitored asset. @@ -1473,47 +1379,6 @@ namespace graphene { namespace wallet { */ real_supply get_real_supply()const; - /** - * @brief This method is used to promote account to publishing manager. - * Such an account can grant or remove right to publish a content. Only DECENT account has permission to use this method. - * @see set_publishing_right() - * @param from Account ( DECENT account ) giving/removing status of the publishing manager. - * @param to List of accounts getting status of the publishing manager. - * @param is_allowed True to give the status, false to remove it - * @param broadcast True to broadcast the transaction on the network - * @return The signed transaction updating account status - * @ingroup WalletCLI - */ - signed_transaction set_publishing_manager(const string from, - const vector to, - bool is_allowed, - bool broadcast); - - /** - * @brief Allows account to publish a content. Only account with publishing manager status has permission to use this method. - * @see set_publishing_manager() - * @param from Account giving/removing right to publish a content. - * @param to List of accounts getting right to publish a content. - * @param is_allowed True to give the right, false to remove it - * @param broadcast True to broadcast the transaction on the network - * @return The signed transaction updating account status - * @ingroup WalletCLI - */ - signed_transaction set_publishing_right(const string from, - const vector to, - bool is_allowed, - bool broadcast); - - /** - * @brief Get a list of accounts holding publishing manager status. - * @param lower_bound_name The name of the first account to return. If the named account does not exist, - * the list will start at the account that comes after \c lowerbound - * @param limit The maximum number of accounts to return (max: 100) - * @return List of accounts - * @ingroup WalletCLI - */ - vector list_publishing_managers( const string& lower_bound_name, uint32_t limit ); - /** * @brief Submits or resubmits content to the blockchain. In a case of resubmit, co-authors, price and synopsis fields * can be modified. @@ -2158,18 +2023,13 @@ FC_API( graphene::wallet::wallet_api, (list_account_balances) (list_assets) (import_key) - (import_accounts) - (import_account_keys) (suggest_brain_key) (generate_brain_key_el_gamal_key) (get_brain_key_info) (register_account) (create_account_with_brain_key) - (create_account_with_brain_key_noimport) (transfer) - (transfer2) (propose_transfer) - (get_transaction_id) (create_monitored_asset) (update_monitored_asset) (publish_asset_feed) @@ -2193,7 +2053,6 @@ FC_API( graphene::wallet::wallet_api, (set_voting_proxy) (set_desired_miner_count) (get_account) - (get_account_id) (get_block) (get_account_count) (get_account_history) @@ -2222,9 +2081,6 @@ FC_API( graphene::wallet::wallet_api, (network_get_connected_peers) (download_content) (get_download_status) - (set_publishing_manager) - (set_publishing_right) - (list_publishing_managers) (submit_content) (submit_content_async) (content_cancellation) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 104073dd..21bbbbb8 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -658,10 +658,7 @@ class wallet_api_impl return *rec; } } - account_id_type get_account_id(string account_name_or_id) const - { - return get_account(account_name_or_id).get_id(); - } + optional find_asset(asset_id_type id)const { auto rec = _remote_db->get_assets({id}).front(); @@ -669,6 +666,7 @@ class wallet_api_impl _asset_cache[id] = *rec; return rec; } + optional find_asset(string asset_symbol_or_id)const { FC_ASSERT( asset_symbol_or_id.size() > 0 ); @@ -704,6 +702,7 @@ class wallet_api_impl return *opt; } +#if 0 asset_id_type get_asset_id(string asset_symbol_or_id) const { FC_ASSERT( asset_symbol_or_id.size() > 0 ); @@ -714,6 +713,7 @@ class wallet_api_impl FC_ASSERT( (opt_asset.size() > 0) && (opt_asset[0].valid()) ); return opt_asset[0]->id; } +#endif string get_wallet_filename() const { @@ -1414,7 +1414,7 @@ class wallet_api_impl FC_THROW("No asset with that symbol exists!"); asset_publish_feed_operation publish_op; - publish_op.publisher = get_account_id(publishing_account); + publish_op.publisher = get_account(publishing_account).get_id(); publish_op.asset_id = asset_to_update->id; publish_op.feed = feed; @@ -1446,7 +1446,7 @@ class wallet_api_impl // then maybe it's the owner account try { - account_id_type owner_account_id = get_account_id(owner_account); + account_id_type owner_account_id = get_account(owner_account).get_id(); fc::optional miner = _remote_db->get_miner_by_account(owner_account_id); if (miner) return *miner; @@ -1580,7 +1580,7 @@ class wallet_api_impl bool broadcast /* = false */) { try { account_object voting_account_object = get_account(voting_account); - account_id_type miner_owner_account_id = get_account_id(miner); + account_id_type miner_owner_account_id = get_account(miner).get_id(); fc::optional miner_obj = _remote_db->get_miner_by_account(miner_owner_account_id); if (!miner_obj) FC_THROW("Account ${miner} is not registered as a miner", ("miner", miner)); @@ -1615,7 +1615,7 @@ class wallet_api_impl account_object account_object_to_modify = get_account(account_to_modify); if (voting_account) { - account_id_type new_voting_account_id = get_account_id(*voting_account); + account_id_type new_voting_account_id = get_account(*voting_account).get_id(); if (account_object_to_modify.options.voting_account == new_voting_account_id) FC_THROW("Voting proxy for ${account} is already set to ${voter}", ("account", account_to_modify)("voter", *voting_account)); account_object_to_modify.options.voting_account = new_voting_account_id; @@ -1810,7 +1810,7 @@ class wallet_api_impl account_object from_account = get_account(from); account_object to_account = get_account(to); account_id_type from_id = from_account.id; - account_id_type to_id = get_account_id(to); + account_id_type to_id = get_account(to).get_id(); transfer_operation xfer_op; @@ -2132,58 +2132,6 @@ class wallet_api_impl return sign_transaction(tx, broadcast); } - signed_transaction set_publishing_manager(const string from, - const vector to, - bool is_allowed, - bool broadcast) - { - try - { - FC_ASSERT( !to.empty() ); - set_publishing_manager_operation spm_op; - spm_op.from = get_account_id( from ); - spm_op.can_create_publishers = is_allowed; - - for( const auto& element : to ) - { - spm_op.to.push_back( get_account_id( element ) ); - } - - signed_transaction tx; - tx.operations.push_back( spm_op ); - set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees); - tx.validate(); - - return sign_transaction( tx, broadcast ); - } FC_CAPTURE_AND_RETHROW( (from)(to)(is_allowed)(broadcast) ) - } - signed_transaction set_publishing_right(const string from, - const vector to, - bool is_allowed, - bool broadcast) - { - try - { - FC_ASSERT( !to.empty() ); - - set_publishing_right_operation spr_op; - spr_op.from = get_account_id( from ); - spr_op.is_publisher = is_allowed; - - for( const auto& element : to ) - { - spr_op.to.push_back( get_account_id( element ) ); - } - - signed_transaction tx; - tx.operations.push_back( spr_op ); - set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees); - tx.validate(); - - return sign_transaction( tx, broadcast ); - } FC_CAPTURE_AND_RETHROW( (from)(to)(is_allowed)(broadcast) ) - } - void submit_content_utility(content_submit_operation& submit_op, vector const& price_amounts) @@ -2229,14 +2177,14 @@ class wallet_api_impl try { FC_ASSERT(!is_locked()); - account_id_type author_account = get_account_id( author ); + account_id_type author_account = get_account( author ).get_id(); map co_authors_id_to_split; if( !co_authors.empty() ) { for( auto const& element : co_authors ) { - account_id_type co_author = get_account_id( element.first ); + account_id_type co_author = get_account( element.first ).get_id(); co_authors_id_to_split[ co_author ] = element.second; } } @@ -2303,7 +2251,7 @@ class wallet_api_impl { for( auto const &element : co_authors ) { - account_id_type co_author = get_account_id( element.first ); + account_id_type co_author = get_account( element.first ).get_id(); co_authors_id_to_split[ co_author ] = element.second; } } @@ -2382,7 +2330,7 @@ signed_transaction content_cancellation(string author, FC_ASSERT(!is_locked()); content_cancellation_operation cc_op; - cc_op.author = get_account_id( author ); + cc_op.author = get_account( author ).get_id(); cc_op.URI = URI; signed_transaction tx; @@ -2577,7 +2525,7 @@ signed_transaction content_cancellation(string author, string packages_path, string region_code) { - account_id_type seeder = get_account_id( account_id_type_or_name ); + account_id_type seeder = get_account( account_id_type_or_name ).get_id(); use_network_node_api(); fc::ecc::private_key seeder_priv_key = *(wif_to_key(seeder_private_key)); (*_remote_net_node)->seeding_startup( seeder, content_private_key, seeder_priv_key, free_space, seeding_price, seeding_symbol, packages_path, region_code); @@ -2593,8 +2541,8 @@ signed_transaction content_cancellation(string author, FC_ASSERT( asset_obj->id == asset_id_type() ); subscribe_operation subscribe_op; - subscribe_op.from = get_account_id( from ); - subscribe_op.to = get_account_id( to ); + subscribe_op.from = get_account( from ).get_id(); + subscribe_op.to = get_account( to ).get_id(); subscribe_op.price = asset_obj->amount_from_string(price_amount); signed_transaction tx; @@ -2610,8 +2558,8 @@ signed_transaction content_cancellation(string author, bool broadcast/* = false */) { try { subscribe_by_author_operation subscribe_op; - subscribe_op.from = get_account_id( from ); - subscribe_op.to = get_account_id( to ); + subscribe_op.from = get_account( from ).get_id(); + subscribe_op.to = get_account( to ).get_id(); signed_transaction tx; tx.operations.push_back( subscribe_op ); @@ -2655,7 +2603,7 @@ signed_transaction content_cancellation(string author, { try { - account_id_type account = get_account_id( account_id_or_name ); + account_id_type account = get_account( account_id_or_name ).get_id(); fc::optional subscription_obj = _remote_db->get_subscription(subscription_id); FC_ASSERT(subscription_obj, "Could not find subscription matching ${subscription}", ("subscription", subscription_id)); @@ -2767,7 +2715,7 @@ signed_transaction content_cancellation(string author, { FC_ASSERT(!is_locked()); const auto& mapi = _remote_api->messaging(); - const auto& receiver_id = get_account_id(receiver); + const auto& receiver_id = get_account(receiver).get_id(); auto itr = _wallet.my_accounts.get().find(receiver_id); if (itr == _wallet.my_accounts.get().end()) return vector(); @@ -2797,7 +2745,7 @@ signed_transaction content_cancellation(string author, { FC_ASSERT(!is_locked()); const auto& mapi = _remote_api->messaging(); - const auto& sender_id = get_account_id(sender); + const auto& sender_id = get_account(sender).get_id(); auto itr = _wallet.my_accounts.get().find(sender_id); if (itr == _wallet.my_accounts.get().end()) return vector(); @@ -2838,7 +2786,7 @@ signed_transaction content_cancellation(string author, for (auto& receiver : to) { account_object to_account = get_account(receiver); message_payload_receivers_data receivers_data_item; - receivers_data_item.to = get_account_id(receiver); + receivers_data_item.to = get_account(receiver).get_id(); if (text.size()) { pl.set_message(get_private_key(from_account.options.memo_key), @@ -3421,11 +3369,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati { } - bool wallet_api::copy_wallet_file(string destination_filename) - { - return my->copy_wallet_file(destination_filename); - } - optional wallet_api::get_block(uint32_t num) { optional result = my->_remote_db->get_block(num); @@ -3519,7 +3462,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati uint32_t start)const { vector result; - auto account_id = get_account_id(name); + auto account_id = get_account(name).get_id(); vector current = my->_remote_hist->get_relative_account_history(account_id, stop, limit, start); for( auto& o : current ) { @@ -3679,7 +3622,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati vector wallet_api::get_proposed_transactions( string account_or_id )const { - account_id_type id = get_account_id(account_or_id); + account_id_type id = get_account(account_or_id).get_id(); return my->_remote_db->get_proposed_transactions( id ); } @@ -3736,16 +3679,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return *asset.monitored_asset_opts; } - account_id_type wallet_api::get_account_id(string account_name_or_id) const - { - return my->get_account_id(account_name_or_id); - } - - asset_id_type wallet_api::get_asset_id(string asset_symbol_or_id) const - { - return my->get_asset_id(asset_symbol_or_id); - } - bool wallet_api::import_key(string account_name_or_id, string wif_key) { FC_ASSERT(!is_locked()); @@ -3754,134 +3687,17 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati if (!optional_private_key) FC_THROW("Invalid private key"); string base58_public_key = optional_private_key->get_public_key().to_base58(); - // copy_wallet_file( "before-import-key-" + base58_public_key ); + // copy_wallet_file( "before-import-key-" + base58_public_key ); if( my->import_key(account_name_or_id, wif_key) ) { save_wallet_file(); - // copy_wallet_file( "after-import-key-" + base58_public_key ); + // copy_wallet_file( "after-import-key-" + base58_public_key ); return true; } return false; } - map wallet_api::import_accounts( string filename, string password ) - { - FC_ASSERT( !is_locked() ); - FC_ASSERT( fc::exists( filename ) ); - - const auto imported_keys = fc::json::from_file( filename ); - - const auto password_hash = fc::sha512::hash( password ); - FC_ASSERT( fc::sha512::hash( password_hash ) == imported_keys.password_checksum ); - - map result; - for( const auto& item : imported_keys.account_keys ) - { - const auto import_this_account = [ & ]() -> bool - { - try - { - const account_object account = get_account( item.account_name ); - const auto& owner_keys = account.owner.get_keys(); - const auto& active_keys = account.active.get_keys(); - - for( const auto& public_key : item.public_keys ) - { - if( std::find( owner_keys.begin(), owner_keys.end(), public_key ) != owner_keys.end() ) - return true; - - if( std::find( active_keys.begin(), active_keys.end(), public_key ) != active_keys.end() ) - return true; - } - } - catch( ... ) - { - } - - return false; - }; - - const auto should_proceed = import_this_account(); - result[ item.account_name ] = should_proceed; - - if( should_proceed ) - { - uint32_t import_successes = 0; - uint32_t import_failures = 0; - // TODO: First check that all private keys match public keys - for( const auto& encrypted_key : item.encrypted_private_keys ) - { - try - { - const auto plain_text = fc::aes_decrypt( password_hash, encrypted_key ); - const auto private_key = fc::raw::unpack( plain_text ); - - import_key( item.account_name, string( graphene::utilities::key_to_wif( private_key ) ) ); - ++import_successes; - } - catch( const fc::exception& e ) - { - elog( "Couldn't import key due to exception ${e}", ("e", e.to_detail_string()) ); - ++import_failures; - } - } - ilog( "successfully imported ${n} keys for account ${name}", ("n", import_successes)("name", item.account_name) ); - if( import_failures > 0 ) - elog( "failed to import ${n} keys for account ${name}", ("n", import_failures)("name", item.account_name) ); - } - } - - return result; - } - - bool wallet_api::import_account_keys( string filename, string password, string src_account_name, string dest_account_name ) - { - FC_ASSERT( !is_locked() ); - FC_ASSERT( fc::exists( filename ) ); - - bool is_my_account = false; - const auto accounts = list_my_accounts(); - for( const auto& account : accounts ) - { - if( account.name == dest_account_name ) - { - is_my_account = true; - break; - } - } - FC_ASSERT( is_my_account ); - - const auto imported_keys = fc::json::from_file( filename ); - - const auto password_hash = fc::sha512::hash( password ); - FC_ASSERT( fc::sha512::hash( password_hash ) == imported_keys.password_checksum ); - - bool found_account = false; - for( const auto& item : imported_keys.account_keys ) - { - if( item.account_name != src_account_name ) - continue; - - found_account = true; - - for( const auto& encrypted_key : item.encrypted_private_keys ) - { - const auto plain_text = fc::aes_decrypt( password_hash, encrypted_key ); - const auto private_key = fc::raw::unpack( plain_text ); - - my->import_key( dest_account_name, string( graphene::utilities::key_to_wif( private_key ) ) ); - } - - return true; - } - save_wallet_file(); - - FC_ASSERT( found_account ); - - return false; - } - string wallet_api::normalize_brain_key(string s) const { return detail::normalize_brain_key( s ); @@ -3922,17 +3738,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati ); } - signed_transaction wallet_api::create_account_with_brain_key_noimport(string brain_key, - string account_name, - string registrar_account, - bool broadcast /* = false */) - { - return my->create_account_with_brain_key( - brain_key, account_name, registrar_account, false, - broadcast - ); - } - signed_transaction wallet_api::transfer(string from, string to, string amount, string asset_symbol, string memo, bool broadcast /* = false */) @@ -4371,27 +4176,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return my->_remote_db->get_real_supply(); } - signed_transaction wallet_api::set_publishing_manager(const string from, - const vector to, - bool is_allowed, - bool broadcast ) - { - return my->set_publishing_manager( from, to, is_allowed, broadcast ); - } - - signed_transaction wallet_api::set_publishing_right(const string from, - const vector to, - bool is_allowed, - bool broadcast ) - { - return my->set_publishing_right( from, to, is_allowed, broadcast ); - } - - vector wallet_api::list_publishing_managers( const string& lower_bound_name, uint32_t limit ) - { - return my->_remote_db->list_publishing_managers( lower_bound_name, limit ); - } - signed_transaction wallet_api::submit_content(string const& author, vector< pair< string, uint32_t>> co_authors, @@ -4896,10 +4680,10 @@ void graphene::wallet::detail::submit_transfer_listener::package_seed_complete() { optional receiver_id; if(receiver.size()) - receiver_id = get_account_id(receiver); + receiver_id = get_account(receiver).get_id(); optional sender_id; if(sender.size()) - sender_id = get_account_id(sender); + sender_id = get_account(sender).get_id(); return my->get_message_objects(sender_id, receiver_id, max_count); } From 54e4b29139f44bf98d380e554a49e24b5ca30a48 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Fri, 26 Jan 2018 15:16:14 +0100 Subject: [PATCH 037/136] generating description of cryptoAPI and messagingAPI --- libraries/app/include/graphene/app/api.hpp | 87 ++++++++++++++++--- .../wallet/include/graphene/wallet/wallet.hpp | 2 +- libraries/wallet/wallet.cpp | 2 +- 3 files changed, 77 insertions(+), 14 deletions(-) diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 9deae58c..49795f94 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -49,6 +49,8 @@ * @defgroup HistoryAPI History API * @defgroup Network_broadcastAPI Network broadcastAPI * @defgroup Network_NodeAPI Network NodeAPI + * @defgroup CryptoAPI Crypto API + * @defgroup MessagingAPI Messaging API * @defgroup LoginAPI LoginAPI */ namespace graphene { namespace app { @@ -260,28 +262,76 @@ namespace graphene { namespace app { private: application& _app; }; - + + /** + * + */ class crypto_api { public: crypto_api(); - + + /** + * @param key + * @param hash + * @param i + * @ingroup CryptoAPI + */ fc::ecc::blind_signature blind_sign( const extended_private_key_type& key, const fc::ecc::blinded_hash& hash, int i ); - + + /** + * @param key + * @param bob + * @param sig + * @param hash + * @param i + * @ingroup CryptoAPI + */ signature_type unblind_signature( const extended_private_key_type& key, const extended_public_key_type& bob, const fc::ecc::blind_signature& sig, const fc::sha256& hash, int i ); - + + /** + * @param blind + * @param value + * @ingroup CryptoAPI + */ fc::ecc::commitment_type blind( const fc::ecc::blind_factor_type& blind, uint64_t value ); - + + /** + * @param blinds_in + * @param non_neg + * @param CryptoAPI + */ fc::ecc::blind_factor_type blind_sum( const std::vector& blinds_in, uint32_t non_neg ); - + + /** + * @param commits_in + * @param neg_commits_in + * @param excess + * @ingroup CryptoAPI + */ bool verify_sum( const std::vector& commits_in, const std::vector& neg_commits_in, int64_t excess ); - + + /** + * @param commit + * @param proof + * @ingroup CryptoAPI + */ verify_range_result verify_range( const fc::ecc::commitment_type& commit, const std::vector& proof ); - + + /** + * @param min_value + * @param commit + * @param commit_blind + * @param nonce + * @param base10_exp + * @param min_bits + * @param actual_value + * @ingroup CryptoAPI + */ std::vector range_proof_sign( uint64_t min_value, const commitment_type& commit, const blind_factor_type& commit_blind, @@ -290,24 +340,37 @@ namespace graphene { namespace app { uint8_t min_bits, uint64_t actual_value ); - + /** + * @param nonce + * @param commit + * @param proof + * @ingroup CryptoAPI + */ verify_range_proof_rewind_result verify_range_proof_rewind( const blind_factor_type& nonce, const fc::ecc::commitment_type& commit, const std::vector& proof ); - + /** + * @param proof + * @ingroup CryptoAPI + */ range_proof_info range_get_info( const std::vector& proof ); }; /** * @brief The messaging_api class implements instant messaging */ - - class messaging_api { public: messaging_api(application& a); + + /** + * @param sender + * @param receiver + * @param max_count + * @ingroup MessagingAPI + */ vector get_message_objects(optional sender, optional receiver, uint32_t max_count) const; private: application& _app; diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 2951fa80..62d4cbaf 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -2055,7 +2055,7 @@ FC_REFLECT( graphene::wallet::operation_detail, FC_API( graphene::wallet::wallet_api, (help) - (gethelp) + (get_help) (info) (about) (begin_builder_transaction) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index c0e4e9e2..f6a23b42 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -4189,7 +4189,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return ss.str(); } - string wallet_api::gethelp(const string& method)const + string wallet_api::get_help(const string& method)const { fc::api tmp; std::stringstream ss; From b748318dc95da21a1523e072803358daedffe194 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 29 Jan 2018 09:39:57 +0100 Subject: [PATCH 038/136] added description to Messaging API --- libraries/app/include/graphene/app/api.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 49795f94..23ee6577 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -366,9 +366,11 @@ namespace graphene { namespace app { messaging_api(application& a); /** - * @param sender - * @param receiver - * @param max_count + * @brief Receives message objects by sender and/or receiver. + * @param sender name of message sender. If you dont want to filter by sender then let it empty + * @param receiver name of message receiver. If you dont want to filter by receiver then let it empty + * @param max_count maximal number of last messages to be displayed + * @return a vector of message objects * @ingroup MessagingAPI */ vector get_message_objects(optional sender, optional receiver, uint32_t max_count) const; From 81a00823f655dc5dffbbdf23d75b8816df2119e3 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Mon, 29 Jan 2018 12:13:51 +0100 Subject: [PATCH 039/136] moved functions from API to internal or detail section --- .../wallet/include/graphene/wallet/wallet.hpp | 89 +--------- libraries/wallet/wallet.cpp | 158 +++++++++--------- 2 files changed, 81 insertions(+), 166 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 75c89362..cca208da 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -753,19 +753,7 @@ namespace graphene { namespace wallet { */ bool import_key(string account_name_or_id, string wif_key); - /** - * @brief Transforms a brain key to reduce the chance of errors when re-entering the key from memory. - * - * This takes a user-supplied brain key and normalizes it into the form used - * for generating private keys. In particular, this upper-cases all ASCII characters - * and collapses multiple spaces into one. - * @param s the brain key as supplied by the user - * @returns the brain key in its normalized form - * @ingroup WalletCLI - */ - string normalize_brain_key(string s) const; - - /** + /** * @brief Registers a third party's account on the blockckain. * * This function is used to register an account for which you do not own the private keys. @@ -1307,43 +1295,6 @@ namespace graphene { namespace wallet { bool broadcast /* = false */ ); - /** - * - * @param creator - * @param symbol - * @ingroup WalletCLI - */ - void dbg_make_mia(string creator, string symbol); - - /** - * - * @param src_filename - * @param count - * @ingroup WalletCLI - */ - void dbg_push_blocks( std::string src_filename, uint32_t count ); - - /** - * - * @param debug_wif_key - * @param count - * @ingroup WalletCLI - */ - void dbg_generate_blocks( std::string debug_wif_key, uint32_t count ); - - /** - * - * @param filename - * @ingroup WalletCLI - */ - void dbg_stream_json_objects( const std::string& filename ); - - /** - * - * @param update - * @ingroup WalletCLI - */ - void dbg_update_object( fc::variant_object update ); /** * @@ -1858,35 +1809,6 @@ namespace graphene { namespace wallet { */ void remove_package(const std::string& package_hash) const; - /** - * @brief Print statuses of all active transfers - * @ingroup WalletCLI - */ - - void set_transfer_logs(bool enable) const; - - /** - * @brief Sign a buffer - * @param str_buffer The buffer to be signed - * @param str_brainkey Derives the private key used for signature - * @return The signed buffer - * @ingroup WalletCLI - */ - std::string sign_buffer(std::string const& str_buffer, - std::string const& str_brainkey) const; - - /** - * @brief Verify if the signature is valid - * @param str_buffer The original buffer - * @param str_publickey The public key used for verification - * @param str_signature The signed buffer - * @return true if valid, otherwise false - * @ingroup WalletCLI - */ - bool verify_signature(std::string const& str_buffer, - std::string const& str_publickey, - std::string const& str_signature) const; - /** * @brief Query the last local block * @return the block time @@ -2063,7 +1985,6 @@ FC_API( graphene::wallet::wallet_api, (get_object) (get_private_key) (load_wallet_file) - (normalize_brain_key) (save_wallet_file) (serialize_transaction) (sign_transaction) @@ -2071,11 +1992,6 @@ FC_API( graphene::wallet::wallet_api, (propose_parameter_change) (propose_fee_change) (approve_proposal) - (dbg_make_mia) - (dbg_push_blocks) - (dbg_generate_blocks) - (dbg_stream_json_objects) - (dbg_update_object) (flood_network) (network_add_nodes) (network_get_connected_peers) @@ -2120,9 +2036,6 @@ FC_API( graphene::wallet::wallet_api, (download_package) (upload_package) (remove_package) - (set_transfer_logs) - (sign_buffer) - (verify_signature) (head_block_time) (get_proposed_transactions) (send_message) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 21bbbbb8..0823dd52 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -85,6 +85,7 @@ #include "ipfs/client.h" #include #include +#include #ifndef WIN32 # include @@ -1164,7 +1165,7 @@ class wallet_api_impl { try { FC_ASSERT( !self.is_locked() ); - string normalized_brain_key = normalize_brain_key( brain_key ); + string normalized_brain_key = detail::normalize_brain_key( brain_key ); // TODO: scan blockchain for accounts that exist with same brain key fc::ecc::private_key owner_privkey = derive_private_key( normalized_brain_key, 0 ); return create_account_with_private_key(owner_privkey, account_name, registrar_account, import, broadcast, save_wallet); @@ -3536,7 +3537,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati brain_key += graphene::words::word_list[ choice.to_int64() ]; } - brain_key = normalize_brain_key(brain_key); + brain_key = detail::normalize_brain_key(brain_key); fc::ecc::private_key priv_key = derive_private_key( brain_key, 0 ); result.brain_priv_key = brain_key; result.wif_priv_key = key_to_wif( priv_key ); @@ -3561,7 +3562,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati { brain_key_info result; - string str_brain_key = normalize_brain_key(brain_key); + string str_brain_key = detail::normalize_brain_key(brain_key); fc::ecc::private_key priv_key = derive_private_key( str_brain_key, 0 ); result.brain_priv_key = str_brain_key; result.wif_priv_key = key_to_wif( priv_key ); @@ -3698,11 +3699,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return false; } - string wallet_api::normalize_brain_key(string s) const - { - return detail::normalize_brain_key( s ); - } - variant wallet_api::info() { return my->info(); @@ -3925,32 +3921,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return my->get_prototype_operation( operation_name ); } - void wallet_api::dbg_make_mia(string creator, string symbol) - { - FC_ASSERT(!is_locked()); - my->dbg_make_mia(creator, symbol); - } - - void wallet_api::dbg_push_blocks( std::string src_filename, uint32_t count ) - { - my->dbg_push_blocks( src_filename, count ); - } - - void wallet_api::dbg_generate_blocks( std::string debug_wif_key, uint32_t count ) - { - my->dbg_generate_blocks( debug_wif_key, count ); - } - - void wallet_api::dbg_stream_json_objects( const std::string& filename ) - { - my->dbg_stream_json_objects( filename ); - } - - void wallet_api::dbg_update_object( fc::variant_object update ) - { - my->dbg_update_object( update ); - } - void wallet_api::network_add_nodes( const vector& nodes ) { my->network_add_nodes( nodes ); @@ -4516,23 +4486,6 @@ pair> wallet_api::get_author_and_co_aut return my->_remote_db->list_active_subscriptions_by_author( account, count); } - std::string wallet_api::sign_buffer(std::string const& str_buffer, - std::string const& str_brainkey) const - { - if (str_buffer.empty() || - str_brainkey.empty()) - throw std::runtime_error("You need buffer and brainkey to sign"); - - string normalized_brain_key = normalize_brain_key( str_brainkey ); - fc::ecc::private_key privkey = derive_private_key( normalized_brain_key, 0 ); - - fc::sha256 digest(str_buffer); - - auto sign = privkey.sign_compact(digest); - - return fc::to_hex((const char*)sign.begin(), sign.size()); - } - el_gamal_key_pair_str wallet_api::get_el_gammal_key(string const& consumer) const { try { @@ -4547,27 +4500,6 @@ pair> wallet_api::get_author_and_co_aut } FC_CAPTURE_AND_RETHROW( (consumer) ) } - bool wallet_api::verify_signature(std::string const& str_buffer, - std::string const& str_publickey, - std::string const& str_signature) const - { - if (str_buffer.empty() || - str_publickey.empty() || - str_signature.empty()) - throw std::runtime_error("You need buffer, public key and signature to verify"); - - fc::ecc::compact_signature signature; - fc::from_hex(str_signature, (char*)signature.begin(), signature.size()); - fc::sha256 digest(str_buffer); - - fc::ecc::public_key pub_key(signature, digest); - public_key_type provided_key(str_publickey); - - if (provided_key == pub_key) - return true; - else - return false; - } fc::time_point_sec wallet_api::head_block_time() const { @@ -4666,11 +4598,6 @@ void graphene::wallet::detail::submit_transfer_listener::package_seed_complete() return package->get_url(); } - - void wallet_api::set_transfer_logs(bool enable) const { - // FC_ASSERT(!is_locked()); - } - void wallet_api::send_message(const std::string& from, std::vector to, string text) { return my->send_message(from, to, text); @@ -4698,8 +4625,82 @@ void graphene::wallet::detail::submit_transfer_listener::package_seed_complete() } -} } // graphene::wallet + namespace internal { + + std::string sign_buffer(std::string const& str_buffer, + std::string const& str_brainkey) + { + if (str_buffer.empty() || + str_brainkey.empty()) + throw std::runtime_error("You need buffer and brainkey to sign"); + + string normalized_brain_key = detail::normalize_brain_key( str_brainkey ); + fc::ecc::private_key privkey = detail::derive_private_key( normalized_brain_key, 0 ); + + fc::sha256 digest(str_buffer); + + auto sign = privkey.sign_compact(digest); + + return fc::to_hex((const char*)sign.begin(), sign.size()); + } + + bool verify_signature(std::string const& str_buffer, + std::string const& str_publickey, + std::string const& str_signature) + { + if (str_buffer.empty() || + str_publickey.empty() || + str_signature.empty()) + throw std::runtime_error("You need buffer, public key and signature to verify"); + + fc::ecc::compact_signature signature; + fc::from_hex(str_signature, (char*)signature.begin(), signature.size()); + fc::sha256 digest(str_buffer); + + fc::ecc::public_key pub_key(signature, digest); + public_key_type provided_key(str_publickey); + + if (provided_key == pub_key) + return true; + else + return false; + } + + +#if 0 + void wallet_api::dbg_make_mia(string creator, string symbol) + { + FC_ASSERT(!is_locked()); + my->dbg_make_mia(creator, symbol); + } + + void wallet_api::dbg_push_blocks( std::string src_filename, uint32_t count ) + { + my->dbg_push_blocks( src_filename, count ); + } + void wallet_api::dbg_generate_blocks( std::string debug_wif_key, uint32_t count ) + { + my->dbg_generate_blocks( debug_wif_key, count ); + } + + void wallet_api::dbg_stream_json_objects( const std::string& filename ) + { + my->dbg_stream_json_objects( filename ); + } + + void wallet_api::dbg_update_object( fc::variant_object update ) + { + my->dbg_update_object( update ); + } +#endif + + + } + + + +} } // graphene::wallet void fc::to_variant(const account_multi_index_type& accts, fc::variant& vo) @@ -4714,3 +4715,4 @@ void fc::from_variant(const fc::variant& var, account_multi_index_type& vo) } + From f1a5ca12f249a59e171fcb240a5066c6f270487c Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Mon, 29 Jan 2018 13:31:42 +0100 Subject: [PATCH 040/136] added missing file --- .../include/graphene/wallet/internal.hpp | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 libraries/wallet/include/graphene/wallet/internal.hpp diff --git a/libraries/wallet/include/graphene/wallet/internal.hpp b/libraries/wallet/include/graphene/wallet/internal.hpp new file mode 100644 index 00000000..723020c0 --- /dev/null +++ b/libraries/wallet/include/graphene/wallet/internal.hpp @@ -0,0 +1,92 @@ +// +// Created by Milan Franc on 26/01/2018. +// + +#ifndef DECENT_INTERNAL_H +#define DECENT_INTERNAL_H + +#include + +using namespace std; + +namespace graphene { namespace wallet { namespace internal { + + + /** + * @brief Transforms a brain key to reduce the chance of errors when re-entering the key from memory. + * + * This takes a user-supplied brain key and normalizes it into the form used + * for generating private keys. In particular, this upper-cases all ASCII characters + * and collapses multiple spaces into one. + * @param s the brain key as supplied by the user + * @returns the brain key in its normalized form + * @ingroup WalletCLI + */ +// std::string normalize_brain_key(std::string s) const; + + /** + * @brief Sign a buffer + * @param str_buffer The buffer to be signed + * @param str_brainkey Derives the private key used for signature + * @return The signed buffer + * @ingroup WalletCLI + */ + std::string sign_buffer(std::string const& str_buffer, + std::string const& str_brainkey); + + /** + * @brief Verify if the signature is valid + * @param str_buffer The original buffer + * @param str_publickey The public key used for verification + * @param str_signature The signed buffer + * @return true if valid, otherwise false + * @ingroup WalletCLI + */ + bool verify_signature(std::string const& str_buffer, + std::string const& str_publickey, + std::string const& str_signature); + + + + /** + * + * @param creator + * @param symbol + * @ingroup WalletCLI + */ + void dbg_make_mia(string creator, string symbol); + + /** + * + * @param src_filename + * @param count + * @ingroup WalletCLI + */ + void dbg_push_blocks( std::string src_filename, uint32_t count ); + + /** + * + * @param debug_wif_key + * @param count + * @ingroup WalletCLI + */ + void dbg_generate_blocks( std::string debug_wif_key, uint32_t count ); + + /** + * + * @param filename + * @ingroup WalletCLI + */ + void dbg_stream_json_objects( const std::string& filename ); + + /** + * + * @param update + * @ingroup WalletCLI + */ + void dbg_update_object( fc::variant_object update ); + + +} } } + +#endif //DECENT_INTERNAL_H From 2a785257a349abc19fbf28e875442d938c786335 Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Mon, 29 Jan 2018 14:14:31 +0100 Subject: [PATCH 041/136] Removed need of custom changes in pbc library header pbc_utils.h for Windows build --- libraries/encrypt/include/decent/encrypt/custodyutils.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/encrypt/include/decent/encrypt/custodyutils.hpp b/libraries/encrypt/include/decent/encrypt/custodyutils.hpp index c2029bcf..c4f3e8e5 100644 --- a/libraries/encrypt/include/decent/encrypt/custodyutils.hpp +++ b/libraries/encrypt/include/decent/encrypt/custodyutils.hpp @@ -6,6 +6,7 @@ #pragma once #if defined( _MSC_VER ) +#include #include #else #include From 44edd8463de746c4ce7120da1d37e942db6c63fc Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Mon, 29 Jan 2018 19:54:42 +0100 Subject: [PATCH 042/136] Fix for Windows build --- libraries/encrypt/include/decent/encrypt/custodyutils.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/encrypt/include/decent/encrypt/custodyutils.hpp b/libraries/encrypt/include/decent/encrypt/custodyutils.hpp index c4f3e8e5..40f6ef72 100644 --- a/libraries/encrypt/include/decent/encrypt/custodyutils.hpp +++ b/libraries/encrypt/include/decent/encrypt/custodyutils.hpp @@ -6,8 +6,9 @@ #pragma once #if defined( _MSC_VER ) -#include +#define __attribute__(X) #include +#undef __attribute__ #else #include #endif From 04042f340e2190bd4ba84588cc9c3fd39ff9ca0d Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Tue, 30 Jan 2018 11:18:46 +0100 Subject: [PATCH 043/136] Fixed Windows build, link errors with update.lib --- programs/gui_wallet/CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/programs/gui_wallet/CMakeLists.txt b/programs/gui_wallet/CMakeLists.txt index 0b0e78b8..d8d47894 100644 --- a/programs/gui_wallet/CMakeLists.txt +++ b/programs/gui_wallet/CMakeLists.txt @@ -65,10 +65,15 @@ add_definitions(-DUPDATE_MANAGER=1) endif() if( WIN32 ) - target_link_libraries( DECENT PUBLIC + if( UPDATE_MANAGER ) + target_link_libraries( DECENT PUBLIC Qt5::Core Qt5::Widgets Qt5::Svg graphene_app graphene_net graphene_chain graphene_utilities graphene_wallet wallet_utility decent_messaging package_manager decent_encrypt pbc ${GMP_LIBRARIES} graphene_account_history decent_seeding graphene_miner graphene_debug_miner graphene_egenesis_decent fc msi update ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) - + else() + target_link_libraries( DECENT PUBLIC + Qt5::Core Qt5::Widgets Qt5::Svg graphene_app graphene_net graphene_chain graphene_utilities graphene_wallet wallet_utility decent_messaging package_manager decent_encrypt pbc ${GMP_LIBRARIES} graphene_account_history decent_seeding graphene_miner graphene_debug_miner graphene_egenesis_decent fc msi ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} + ) + endif() target_sources(DECENT PUBLIC src/rev_history_dlg.cpp src/rev_history_dlg.hpp From 0d85346b4207e23f92952e06b2a68a118c09103c Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Mon, 5 Feb 2018 13:35:16 +0100 Subject: [PATCH 044/136] removed 'copy_wallet_file' function --- libraries/wallet/wallet.cpp | 46 ------------------------------------- 1 file changed, 46 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 0823dd52..770ef4f4 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -508,39 +508,6 @@ class wallet_api_impl fc::async([this]{resync();}, "Resync after block"); } - bool copy_wallet_file( string destination_filename ) - { - fc::path src_path = get_wallet_filename(); - if( !fc::exists( src_path ) ) - return false; - fc::path dest_path = destination_filename + _wallet_filename_extension; - int suffix = 0; - while( fc::exists(dest_path) ) - { - ++suffix; - dest_path = destination_filename + "-" + to_string( suffix ) + _wallet_filename_extension; - } - wlog( "backing up wallet ${src} to ${dest}", - ("src", src_path) - ("dest", dest_path) ); - - fc::path dest_parent = fc::absolute(dest_path).parent_path(); - try - { - enable_umask_protection(); - if( !fc::exists( dest_parent ) ) - fc::create_directories( dest_parent ); - fc::copy( src_path, dest_path ); - disable_umask_protection(); - } - catch(...) - { - disable_umask_protection(); - throw; - } - return true; - } - bool is_locked()const { return _checksum == fc::sha512(); @@ -703,19 +670,6 @@ class wallet_api_impl return *opt; } -#if 0 - asset_id_type get_asset_id(string asset_symbol_or_id) const - { - FC_ASSERT( asset_symbol_or_id.size() > 0 ); - vector> opt_asset; - if( std::isdigit( asset_symbol_or_id.front() ) ) - return fc::variant(asset_symbol_or_id).as(); - opt_asset = _remote_db->lookup_asset_symbols( {asset_symbol_or_id} ); - FC_ASSERT( (opt_asset.size() > 0) && (opt_asset[0].valid()) ); - return opt_asset[0]->id; - } -#endif - string get_wallet_filename() const { return _wallet_filename; From e7f7858074a0d5a21b3c5426ac08c92e8415b45e Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 14 Feb 2018 11:04:02 +0100 Subject: [PATCH 045/136] divided wallet API into separate header files, removed some obsolete functions --- .../include/graphene/wallet/account.hpp | 231 ++ .../wallet/include/graphene/wallet/assets.hpp | 262 +++ .../include/graphene/wallet/content.hpp | 342 +++ .../include/graphene/wallet/general.hpp | 124 + .../include/graphene/wallet/messaging.hpp | 37 + .../wallet/include/graphene/wallet/mining.hpp | 158 ++ .../include/graphene/wallet/proposals.hpp | 89 + .../include/graphene/wallet/seeding.hpp | 38 + .../include/graphene/wallet/subscription.hpp | 101 + .../graphene/wallet/transaction_builder.hpp | 146 ++ .../wallet/include/graphene/wallet/wallet.hpp | 2073 ++--------------- .../include/graphene/wallet/wallet_file.hpp | 180 ++ libraries/wallet/wallet.cpp | 159 +- 13 files changed, 1914 insertions(+), 2026 deletions(-) create mode 100644 libraries/wallet/include/graphene/wallet/account.hpp create mode 100644 libraries/wallet/include/graphene/wallet/assets.hpp create mode 100644 libraries/wallet/include/graphene/wallet/content.hpp create mode 100644 libraries/wallet/include/graphene/wallet/general.hpp create mode 100644 libraries/wallet/include/graphene/wallet/messaging.hpp create mode 100644 libraries/wallet/include/graphene/wallet/mining.hpp create mode 100644 libraries/wallet/include/graphene/wallet/proposals.hpp create mode 100644 libraries/wallet/include/graphene/wallet/seeding.hpp create mode 100644 libraries/wallet/include/graphene/wallet/subscription.hpp create mode 100644 libraries/wallet/include/graphene/wallet/transaction_builder.hpp create mode 100644 libraries/wallet/include/graphene/wallet/wallet_file.hpp diff --git a/libraries/wallet/include/graphene/wallet/account.hpp b/libraries/wallet/include/graphene/wallet/account.hpp new file mode 100644 index 00000000..62f778d6 --- /dev/null +++ b/libraries/wallet/include/graphene/wallet/account.hpp @@ -0,0 +1,231 @@ +#ifndef DECENT_WALLET_ACCOUNT_H +#define DECENT_WALLET_ACCOUNT_H + +/** + * @brief Returns the number of accounts registered on the blockchain + * @returns the number of registered accounts + * @ingroup WalletCLI + */ +uint64_t get_account_count()const; + +/** + * @brief Lists all accounts registered in the blockchain. + * This returns a list of all account names and their account ids, sorted by account name. + * + * Use the \c lowerbound and limit parameters to page through the list. To retrieve all accounts, + * start by setting \c lowerbound to the empty string \c "", and then each iteration, pass + * the last account name returned as the \c lowerbound for the next \c list_accounts() call. + * + * @param lowerbound the name of the first account to return. If the named account does not exist, + * the list will start at the account that comes after \c lowerbound + * @param limit the maximum number of accounts to return (max: 1000) + * @returns a list of accounts mapping account names to account ids + * @ingroup WalletCLI + */ +map list_accounts(const string& lowerbound, uint32_t limit); + +/** + * @brief Get names and IDs for registered accounts that match search term + * @param term will try to partially match account name or id + * @param limit Maximum number of results to return -- must not exceed 1000 + * @param order Sort data by field + * @param id object_id to start searching from + * @return Map of account names to corresponding IDs + * @ingroup WalletCLI + */ +vector search_accounts(const string& term, const string& order, const string& id, uint32_t limit); + +/** + * @brief List the balances of an account. + * Each account can have multiple balances, one for each type of asset owned by that + * account. The returned list will only contain assets for which the account has a + * nonzero balance + * @param id the name or id of the account whose balances you want + * @returns a list of the given account's balances + * @ingroup WalletCLI + */ +vector list_account_balances(const string& id); + +/** + * @brief Returns the operations on the named account. + * + * This returns a list of transaction detail object, which describe activity on the account. + * + * @param account_name the name or id of the account + * @param order Sort data by field + * @param id object_id to start searching from + * @param limit the number of entries to return (starting from the most recent) (max 100) + * @returns a list of \c transaction_detail_object + * @ingroup WalletCLI + */ +vector search_account_history(string const& account_name, + string const& order, + string const& id, + int limit) const; + + +/** Returns the most recent operations on the named account. + * + * This returns a list of operation history objects, which describe activity on the account. + * + * @note this API doesn't give a way to retrieve more than the most recent 100 transactions, + * you can interface directly with the blockchain to get more history + * @param name the name or id of the account + * @param limit the number of entries to return (starting from the most recent) (max 100) + * @returns a list of \c operation_history_objects + */ +vector get_account_history(string name, int limit)const; + +/** + * @brief Get operations relevant to the specified account referenced + * by an event numbering specific to the account. The current number of operations + * for the account can be found in the account statistics (or use 0 for start). + * @param name The account whose history should be queried + * @param stop Sequence number of earliest operation. 0 is default and will + * query 'limit' number of operations. + * @param limit Maximum number of operations to retrieve (must not exceed 100) + * @param start Sequence number of the most recent operation to retrieve. + * 0 is default, which will start querying from the most recent operation. + * @return A list of operations performed by account, ordered from most recent to oldest. + * @ingroup WalletCLI + */ +vector get_relative_account_history(string name, + uint32_t stop, + int limit, + uint32_t start)const; + + +/** + * @brief Returns information about the given account. + * + * @param account_name_or_id the name or id of the account to provide information about + * @returns the public account data stored in the blockchain + * @ingroup WalletCLI + */ +account_object get_account(string account_name_or_id) const; + +/** + * @brief Derive private key from given prefix and sequence + * @param prefix_string + * @param sequence_number + * @return private_key Derived private key + * @ingroup WalletCLI + */ +fc::ecc::private_key derive_private_key(const std::string& prefix_string, int sequence_number) const; + +/** + * @brief Suggests a safe brain key to use for creating your account. + * \c create_account_with_brain_key() requires you to specify a 'brain key', + * a long passphrase that provides enough entropy to generate cyrptographic + * keys. This function will suggest a suitably random string that should + * be easy to write down (and, with effort, memorize). + * @returns a suggested brain_key + * @ingroup WalletCLI + */ +brain_key_info suggest_brain_key()const; + +/** + * @brief Calculates the private key and public key corresponding to any brain key + * @param brain_key the brain key to be used for calculation + * @returns the corresponding brain_key_info + * @ingroup WalletCLI + */ +brain_key_info get_brain_key_info(string const& brain_key) const; + +/** + * @brief Suggests a safe brain key to use for creating your account also + * generates the el_gamal_key_pair corresponding to the brain key + * \c create_account_with_brain_key() requires you to specify a 'brain key', + * a long passphrase that provides enough entropy to generate cyrptographic + * keys. This function will suggest a suitably random string that should + * be easy to write down (and, with effort, memorize). + * @returns a suggested brain_key + * @ingroup WalletCLI + */ +pair generate_brain_key_el_gamal_key() const; + +/** + * @brief Registers a third party's account on the blockckain. + * + * This function is used to register an account for which you do not own the private keys. + * When acting as a registrar, an end user will generate their own private keys and send + * you the public keys. The registrar will use this function to register the account + * on behalf of the end user. + * + * @see create_account_with_brain_key() + * + * @param name the name of the account, must be unique on the blockchain. Shorter names + * are more expensive to register; the rules are still in flux, but in general + * names of more than 8 characters with at least one digit will be cheap. + * @param owner the owner key for the new account + * @param active the active key for the new account + * @param registrar_account the account which will pay the fee to register the user + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction registering the account + * @ingroup WalletCLI + */ +signed_transaction register_account(string name, + public_key_type owner, + public_key_type active, + string registrar_account, + bool broadcast = false); + +/** + * @brief Creates a new account and registers it on the blockchain. + * + * @todo why no referrer_percent here? + * + * @see suggest_brain_key() + * @see register_account() + * + * @param brain_key the brain key used for generating the account's private keys + * @param account_name the name of the account, must be unique on the blockchain. Shorter names + * are more expensive to register; the rules are still in flux, but in general + * names of more than 8 characters with at least one digit will be cheap. + * @param registrar_account the account which will pay the fee to register the user + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction registering the account + * @ingroup WalletCLI + */ +signed_transaction create_account_with_brain_key(string brain_key, + string account_name, + string registrar_account, + bool broadcast = false); + +/** + * @brief Transfer an amount from one account to another. + * @param from the name or id of the account sending the funds + * @param to the name or id of the account receiving the funds + * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) + * @param asset_symbol the symbol or id of the asset to send + * @param memo a memo to attach to the transaction. The memo will be encrypted in the + * transaction and readable for the receiver. There is no length limit + * other than the limit imposed by maximum transaction size, but transaction + * increase with transaction size + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction transferring funds + * @ingroup WalletCLI + */ +signed_transaction transfer(string from, + string to, + string amount, + string asset_symbol, + string memo, + bool broadcast = false); + +/** + * @brief Generates private ElGamal key and corresponding public key. + * @return Pair of ElGamal keys + * @ingroup WalletCLI + */ +el_gamal_key_pair generate_el_gamal_keys() const; + +/** + * @brief Gets unique ElGamal key pair for consumer. + * @return Pair of ElGamal keys + * @ingroup WalletCLI + */ +el_gamal_key_pair_str get_el_gammal_key(string const& consumer) const; + + +#endif //DECENT_WALLET_ACCOUNT_H diff --git a/libraries/wallet/include/graphene/wallet/assets.hpp b/libraries/wallet/include/graphene/wallet/assets.hpp new file mode 100644 index 00000000..181bff09 --- /dev/null +++ b/libraries/wallet/include/graphene/wallet/assets.hpp @@ -0,0 +1,262 @@ +#ifndef DECENT_WALLET_ASSETS_H +#define DECENT_WALLET_ASSETS_H + +/** + * @brief Lists all assets registered on the blockchain. + * + * To list all assets, pass the empty string \c "" for the lowerbound to start + * at the beginning of the list, and iterate as necessary. + * + * @param lowerbound the symbol of the first asset to include in the list. + * @param limit the maximum number of assets to return (max: 100) + * @returns the list of asset objects, ordered by symbol + * @ingroup WalletCLI + */ +vector list_assets(const string& lowerbound, uint32_t limit)const; + +/** + * @brief Returns information about the given asset. + * @param asset_name_or_id the symbol or id of the asset in question + * @returns the information about the asset stored in the block chain + * @ingroup WalletCLI + */ +asset_object get_asset(string asset_name_or_id) const; + +/** + * @brief Returns the BitAsset-specific data for a given asset. + * Market-issued assets's behavior are determined both by their "BitAsset Data" and + * their basic asset data, as returned by \c get_asset(). + * @param asset_name_or_id the symbol or id of the BitAsset in question + * @returns the BitAsset-specific data for this asset + * @ingroup WalletCLI + */ +monitored_asset_options get_monitored_asset_data(string asset_name_or_id)const; + +/** + * @brief Lookup the id of a named asset. + * @param asset_name_or_id the symbol of an asset to look up + * @returns the id of the given asset + * @ingroup WalletCLI + */ +asset_id_type get_asset_id(string asset_name_or_id) const; + +/** + * @brief Creates a new monitored asset. + * + * Options can be changed later using \c update_monitored_asset() + * + * @param issuer the name or id of the account who will pay the fee and become the + * issuer of the new asset. This can be updated later + * @param symbol the ticker symbol of the new asset + * @param precision the number of digits of precision to the right of the decimal point, + * must be less than or equal to 12 + * @param description asset description. Maximal length is 1000 chars. + * @param feed_lifetime_sec time before a price feed expires + * @param minimum_feeds minimum number of unexpired feeds required to extract a median feed from + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction creating a new asset + * @ingroup WalletCLI + */ +signed_transaction create_monitored_asset(string issuer, + string symbol, + uint8_t precision, + string description, + uint32_t feed_lifetime_sec, + uint8_t minimum_feeds, + bool broadcast = false); + +/** + * @brief Update the options specific to a monitored asset. + * + * Monitored assets have some options which are not relevant to other asset types. This operation is used to update those + * options and an existing monitored asset. + * + * @param symbol the name or id of the asset to update, which must be a market-issued asset + * @param description asset description + * @param feed_lifetime_sec time before a price feed expires + * @param minimum_feeds minimum number of unexpired feeds required to extract a median feed from + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction updating the bitasset + * @ingroup WalletCLI + */ +signed_transaction update_monitored_asset(string symbol, + string description, + uint32_t feed_lifetime_sec, + uint8_t minimum_feeds, + bool broadcast = false); + +/** + * @brief Creates a new user-issued asset. + * + * Options can be changed later using \c update_asset() + * + * @param issuer the name or id of the account who will pay the fee and become the + * issuer of the new asset. This can be updated later + * @param symbol the ticker symbol of the new asset + * @param precision the number of digits of precision to the right of the decimal point, + * must be less than or equal to 12 + * @param description asset description. Maximal length is 1000 chars + * @param max_supply the maximum supply of this asset which may exist at any given time + * @param core_exchange_rate Core_exchange_rate technically needs to store the asset ID of + * this new asset. Since this ID is not known at the time this operation is + * created, create this price as though the new asset has instance ID 1, and + * the chain will overwrite it with the new asset's ID + * @param is_exchangeable True to allow implicit conversion of this asset to/from core asset + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction creating a new asset + * @ingroup WalletCLI + */ +signed_transaction create_user_issued_asset(string issuer, + string symbol, + uint8_t precision, + string description, + uint64_t max_supply, + price core_exchange_rate, + bool is_exchangeable, + bool broadcast = false); + +/** Issue new shares of an asset. + * + * @param to_account the name or id of the account to receive the new shares + * @param amount the amount to issue, in nominal units + * @param symbol the ticker symbol of the asset to issue + * @param memo a memo to include in the transaction, readable by the recipient + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction issuing the new shares + */ + signed_transaction issue_asset(string to_account, + string amount, + string symbol, + string memo, + bool broadcast = false); + +/** + * @brief Update the options specific to a user issued asset. + * + * User issued assets have some options which are not relevant to other asset types. This operation is used to update those + * options an an existing user issues asset. + * + * + * @param symbol the name or id of the asset to update, which must be a market-issued asset + * @param new_issuer if the asset is to be given a new issuer, specify his ID here + * @param description asset description + * @param max_supply The maximum supply of this asset which may exist at any given time + * @param core_exchange_rate Price used to convert non-core asset to core asset + * @param is_exchangeable True to allow implicit conversion of this asset to/from core asset + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction updating the bitasset + * @ingroup WalletCLI + */ +signed_transaction update_user_issued_asset(string symbol, + string new_issuer, + string description, + uint64_t max_supply, + price core_exchange_rate, + bool is_exchangeable, + bool broadcast = false); + +/** + * Pay into the pools for the given asset. + * + * User-issued assets can optionally have a pool of the core asset which is + * automatically used to pay transaction fees for any transaction using that + * asset (using the asset's core exchange rate). + * + * Allows anyone to deposit core/asset into pools. + * This pool are used when conversion between assets is needed (paying fees, paying for a content in different asset). + * + * @param from the name or id of the account sending the core asset + * @param uia_amount the amount of "this" asset to deposit + * @param uia_symbol the name or id of the asset whose pool you wish to fund + * @param dct_amount the amount of the core asset to deposit + * @param dct_symbol the name or id of the DCT asset + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction funding the fee pool + */ +signed_transaction fund_asset_pools(string from, + string uia_amount, + string uia_symbol, + string dct_amount, + string dct_symbol, + bool broadcast = false); + +/** + * Burns the given user-issued asset. + * + * This command burns the user-issued asset to reduce the amount in circulation. + * @note you cannot burn market-issued assets. + * @param from the account containing the asset you wish to burn + * @param amount the amount to burn, in nominal units + * @param symbol the name or id of the asset to burn + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction burning the asset + */ +signed_transaction reserve_asset(string from, + string amount, + string symbol, + bool broadcast = false); + +/** + * Transfers accumulated assets from pools back to the issuer's balance. + * + * @note you cannot claim assets from pools of market-issued asset. + * @param uia_amount the amount of "this" asset to claim, in nominal units + * @param uia_symbol the name or id of the asset to claim + * @param dct_amount the amount of DCT asset to claim, in nominal units + * @param dct_symbol the name or id of the DCT asset to claim + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction claiming the fees + */ +signed_transaction claim_fees(string uia_amount, + string uia_symbol, + string dct_amount, + string dct_symbol, + bool broadcast = false); + +/** + * @brief Converts asset into DCT, using actual price feed. + * @param amount the amount to convert in nominal units + * @param asset_symbol_or_id the symbol or id of the asset to convert + * @return price in DCT + */ +string price_to_dct(const string& amount, const string& asset_symbol_or_id); + +/** + * @brief Publishes a price feed for the named asset. + * + * Price feed providers use this command to publish their price feeds for market-issued assets. A price feed is + * used to tune the market for a particular market-issued asset. For each value in the feed, the median across all + * miner feeds for that asset is calculated and the market for the asset is configured with the median of that + * value. + * + * @param publishing_account the account publishing the price feed + * @param symbol the name or id of the asset whose feed we're publishing + * @param feed the price_feed object for particular market-issued asset + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction updating the price feed for the given asset + * @ingroup WalletCLI + */ +signed_transaction publish_asset_feed(string publishing_account, + string symbol, + price_feed feed, + bool broadcast = false); + +/** + * @brief Get a list of published price feeds by a miner. + * + * @param account_name_or_id the name or id of the account + * @param count Maximum number of price feeds to fetch (must not exceed 100) + * @returns list of price feeds published by the miner + * @ingroup WalletCLI + */ +multimap get_feeds_by_miner(const string& account_name_or_id, + const uint32_t count); + +/** + * Get current supply of the core asset + * @ingroup WalletCLI + */ +real_supply get_real_supply()const; + + +#endif //DECENT_WALLET_ASSETS_H diff --git a/libraries/wallet/include/graphene/wallet/content.hpp b/libraries/wallet/include/graphene/wallet/content.hpp new file mode 100644 index 00000000..25347fe6 --- /dev/null +++ b/libraries/wallet/include/graphene/wallet/content.hpp @@ -0,0 +1,342 @@ +#ifndef DECENT_WALLET_CONTENT_H +#define DECENT_WALLET_CONTENT_H + +/** + * @brief Submits or resubmits content to the blockchain. In a case of resubmit, co-authors, price and synopsis fields + * can be modified. + * @see submit_content_new() + * @param author The author of the content + * @param co_authors The co-authors' account name or ID mapped to corresponding payment split based on basis points + * @param URI The URI of the content + * @param price_amounts The price of the content per regions + * @param size The size of the content + * @param hash The Hash of the package + * @param seeders List of the seeders, which will publish the content + * @param quorum Defines number of seeders needed to restore the encryption key + * @param expiration The expiration time of the content. The content is available to buy till it's expiration time + * @param publishing_fee_asset Ticker symbol of the asset which will be used to publish content + * @param publishing_fee_amount Publishing price + * @param synopsis The description of the content + * @param secret The AES key used to encrypt and decrypt the content + * @param cd Custody data + * @param broadcast true to broadcast the transaction on the network + * @return The signed transaction submitting the content + * @ingroup WalletCLI + */ +signed_transaction +submit_content(string const& author, + vector< pair< string, uint32_t>> co_authors, + string const& URI, + vector const& price_amounts, + uint64_t size, + fc::ripemd160 const& hash, + vector const& seeders, + uint32_t quorum, + fc::time_point_sec const& expiration, + string const& publishing_fee_asset, + string const& publishing_fee_amount, + string const& synopsis, + DInteger const& secret, + decent::encrypt::CustodyData const& cd, + bool broadcast); + +/** + * @brief This function is used to create package, upload package and submit content in one step. + * @see create_package() + * @see upload_package() + * @see submit_content() + * @param author The author of the content + * @param co_authors The co-authors' account name or ID mapped to corresponding payment split based on basis points + * @param content_dir Path to the directory containing all content that should be packed + * @param samples_dir Path to the directory containing samples of content + * @param protocol Protocol for uploading package( ipfs ) + * @param price_amounts The prices of the content per regions + * @param seeders List of the seeders, which will publish the content + * @param expiration The expiration time of the content. The content is available to buy till it's expiration time + * @param synopsis The description of the content + * @return The signed transaction submitting the content + * @ingroup WalletCLI + */ + +void submit_content_async( string const &author, + vector< pair< string, uint32_t>> co_authors, + string const &content_dir, + string const &samples_dir, + string const &protocol, + vector const &price_amounts, + vector const &seeders, + fc::time_point_sec const &expiration, + string const &synopsis); + + +/** + * @brief This function can be used to cancel submitted content. This content is immediately not available to purchase. + * Seeders keep seeding this content in next 24 hours. + * @param author The author of the content + * @param URI The URI of the content + * @param broadcast True to broadcast the transaction on the network + * @ingroup WalletCLI + * @return signed transaction + */ +signed_transaction content_cancellation(string author, + string URI, + bool broadcast); + +/** + * @brief Downloads encrypted content specified by provided URI. + * @param consumer Consumer of the content + * @param URI The URI of the content + * @param region_code_from Two letter region code + * @param broadcast true to broadcast the transaction on the network + * @ingroup WalletCLI + */ +void download_content(string const& consumer, string const& URI, string const& region_code_from, bool broadcast = false); + +/** + * @brief Get status about particular download process specified by provided URI. + * @param consumer Consumer of the content + * @param URI The URI of the content + * @return Download status, or null if no matching download process was found + * @ingroup WalletCLI + */ +optional get_download_status(string consumer, string URI) const; + +/** + * @brief This function is used to send a request to buy a content. This request is caught by seeders. + * @param consumer Consumer of the content + * @param URI The URI of the content + * @param price_asset_name Ticker symbol of the asset which will be used to buy content + * @param price_amount The price of the content + * @param str_region_code_from Two letter region code + * @param broadcast true to broadcast the transaction on the network + * @return The signed transaction requesting buying of the content + * @ingroup WalletCLI + */ +signed_transaction request_to_buy(string consumer, + string URI, + string price_asset_name, + string price_amount, + string str_region_code_from, + bool broadcast); + +/** + * @brief This method allows user to start seeding plugin from running application + * @param account_id_type_or_name Name or ID of account controlling this seeder + * @param content_private_key El Gamal content private key + * @param seeder_private_key Private key of the account controlling this seeder + * @param free_space Allocated disk space, in MegaBytes + * @param seeding_price price per MegaByte + * @param seeding_symbol seeding price asset, e.g. DCT + * @param packages_path Packages storage path + * @param region_code Optional ISO 3166-1 alpha-2 two-letter region code + * @ingroup WalletCLI + */ +void seeding_startup( string account_id_type_or_name, + DInteger content_private_key, + string seeder_private_key, + uint64_t free_space, + uint32_t seeding_price, + string seeding_symbol, + string packages_path, + string region_code = "" ); + +/** + * @brief Rates and comments a content. + * @param consumer Consumer giving the rating + * @param URI The URI of the content + * @param rating Rating + * @param comment Comment + * @param broadcast true to broadcast the transaction on the network + * @ingroup WalletCLI + */ +void leave_rating_and_comment(string consumer, + string URI, + uint64_t rating, + string comment, + bool broadcast = false); + +/** + * @brief Get a list of open buyings + * @return Open buying objects + * @ingroup WalletCLI + */ +vector get_open_buyings()const; + +/** + * @brief Get a list of open buyings by URI + * @param URI URI of the buyings to retrieve + * @return Open buyings corresponding to the provided URI + * @ingroup WalletCLI + */ +vector get_open_buyings_by_URI( const string& URI )const; + +/** + * @brief Get a list of open buyings by consumer + * @param account_id_or_name Consumer of the buyings to retrieve + * @return Open buyings corresponding to the provided consumer + * @ingroup WalletCLI + */ +vector get_open_buyings_by_consumer( const string& account_id_or_name )const; + +/** + * @brief Get history buyings by consumer + * @param account_id_or_name Consumer of the buyings to retrieve + * @return History buying objects corresponding to the provided consumer + * @ingroup WalletCLI + */ +vector get_buying_history_objects_by_consumer( const string& account_id_or_name )const; + + +/** + * @brief Get history buying objects by consumer that match search term + * @param account_id_or_name Consumer of the buyings to retrieve + * @param term Search term to look up in Title and Description + * @param order Sort data by field + * @param id Object_id to start searching from + * @param count Maximum number of contents to fetch (must not exceed 100) + * @return History buying objects corresponding to the provided consumer and matching search term + * @ingroup WalletCLI + */ +vector search_my_purchases(const string& account_id_or_name, + const string& term, + const string& order, + const string& id, + uint32_t count) const; + +/** +* @brief Get buying (open or history) by consumer and URI +* @param account_id_or_name Consumer of the buying to retrieve +* @param URI URI of the buying to retrieve +* @return Buying_objects corresponding to the provided consumer, or null if no matching buying was found +* @ingroup WalletCLI +*/ +optional get_buying_by_consumer_URI( const string& account_id_or_name, const string & URI )const; + +/** + * @brief Search for term in contents (author, title and description) + * @param user Feedback author + * @param URI The content object URI + * @param id The id of feedback object to start searching from + * @param count Maximum number of feedbacks to fetch + * @return The feedback found + * @ingroup WalletCLI + */ +vector search_feedback(const string& user, + const string& URI, + const string& id, + uint32_t count) const; + +/** + * @brief Get a content by URI + * @param URI URI of the content to retrieve + * @return The content corresponding to the provided URI, or null if no matching content was found + * @ingroup WalletCLI + */ +optional get_content( const string& URI )const; + +/** + * @brief Get a list of contents ordered alphabetically by search term + * @param term Search term + * @param order Order field + * @param user Content owner + * @param region_code Two letter region code + * @param id The id of content object to start searching from + * @param type The application and content type to be filtered + * @param count Maximum number of contents to fetch (must not exceed 100) + * @return The contents found + * @ingroup WalletCLI + */ +vector search_content(const string& term, + const string& order, + const string& user, + const string& region_code, + const string& id, + const string& type, + uint32_t count )const; +/** + * @brief Get a list of contents ordered alphabetically by search term + * @param user Content owner + * @param term Search term + * @param order Order field + * @param region_code Two letter region code + * @param id The id of content object to start searching from + * @param type The application and content type to be filtered + * @param count Maximum number of contents to fetch (must not exceed 100) + * @return The contents found + * @ingroup WalletCLI + */ +vector search_user_content(const string& user, + const string& term, + const string& order, + const string& region_code, + const string& id, + const string& type, + uint32_t count )const; + +/** + * @brief Get author and list of co-authors of a content corresponding to the provided URI + * @param URI URI of the content + * @return The autor of the content and the list of co-authors, if provided + */ +pair> get_author_and_co_authors_by_URI( const string& URI )const; + +/** + * @brief Create package from selected files + * @param content_dir Directory containing all content that should be packed + * @param samples_dir Directory containing samples of content + * @param aes_key AES key for encryption + * @return package hash (ripemd160 hash of package content) and content custody data + * @ingroup WalletCLI + */ +std::pair create_package(const std::string& content_dir, const std::string& samples_dir, const DInteger& aes_key) const; + + +/** + * @brief Extract selected package + * @param package_hash Hash of package that needs to be extracted + * @param output_dir Directory where extracted files will be created + * @param aes_key AES key for decryption + * @ingroup WalletCLI + */ +void extract_package(const std::string& package_hash, const std::string& output_dir, const DInteger& aes_key) const; + +/** + * @brief Download package + * @param url Magnet or IPFS URL of package + * @ingroup WalletCLI + */ +void download_package(const std::string& url) const; + +/** + * @brief Start uploading package + * @param package_hash Hash of package that needs to be extracted + * @param protocol protocol for uploading package ( ipfs ) + * @ingroup WalletCLI + */ +std::string upload_package(const std::string& package_hash, const std::string& protocol) const; + +/** + * @brief Remove package + * @param package_hash Hash of package that needs to be removed + * @ingroup WalletCLI + */ +void remove_package(const std::string& package_hash) const; + +/** + * @brief Restores AES key( used to encrypt and decrypt a content) from key particles stored in a buying object + * @param account Consumers account id or name + * @param buying The buying object containing key particles + * @return restored AES key from particles + * @ingroup WalletCLI + */ +DInteger restore_encryption_key(std::string account, buying_id_type buying); + +/** + * @brief Generates AES encryption key. + * @return Random encryption key + * @ingroup WalletCLI + */ +DInteger generate_encryption_key() const; + + +#endif //DECENT_WALLET_CONTENT_H diff --git a/libraries/wallet/include/graphene/wallet/general.hpp b/libraries/wallet/include/graphene/wallet/general.hpp new file mode 100644 index 00000000..19433267 --- /dev/null +++ b/libraries/wallet/include/graphene/wallet/general.hpp @@ -0,0 +1,124 @@ +#ifndef DECENT_WALLET_GENERAL_H +#define DECENT_WALLET_GENERAL_H + +/** + * @brief Returns info such as client version, git version of graphene/fc, version of boost, openssl. + * @returns compile time info and client and dependencies versions + * @ingroup WalletCLI + */ +variant_object about() const; + +/** + * @brief Retrieve a full, signed block with info + * @param num ID of the block + * @return the referenced block with info, or null if no matching block was found + * @ingroup WalletCLI + */ +optional get_block( uint32_t num ); + +/** + * @brief Returns the block chain's slowly-changing settings. + * This object contains all of the properties of the blockchain that are fixed + * or that change only once per maintenance interval (daily) such as the + * current list of miners, block interval, etc. + * @see \c get_dynamic_global_properties() for frequently changing properties + * @returns the global properties + * @ingroup WalletCLI + */ +global_property_object get_global_properties() const; + +/** + * @brief Returns the block chain's rapidly-changing properties. + * The returned object contains information that changes every block interval + * such as the head block number, the next miner, etc. + * @see \c get_global_properties() for less-frequently changing properties + * @returns the dynamic global properties + * @ingroup WalletCLI + */ +dynamic_global_property_object get_dynamic_global_properties() const; + +/** + * @brief Returns the blockchain object corresponding to the given id. + * + * This generic function can be used to retrieve any object from the blockchain + * that is assigned an ID. Certain types of objects have specialized convenience + * functions to return their objects -- e.g., assets have \c get_asset(), accounts + * have \c get_account(), but this function will work for any object. + * + * @param id the id of the object to return + * @returns the requested object + * @ingroup WalletCLI + */ +variant get_object(object_id_type id) const; + +/** + * @brief Query the last local block + * @return the block time + */ +fc::time_point_sec head_block_time() const; + +/** + * @brief Lists all available commands + * @return List of all available commands + * @ingroup WalletCLI + */ +variant info(); + +/** + * @brief Returns a list of all commands supported by the wallet API. + * + * This lists each command, along with its arguments and return types. + * For more detailed help on a single command, use \c get_help() + * + * @returns a multi-line string suitable for displaying on a terminal + * @ingroup WalletCLI + */ +string help()const; + +/** + * @brief Returns detailed help on a single API command. + * @param method the name of the API command you want help with + * @returns a multi-line string suitable for displaying on a terminal + * @ingroup WalletCLI + */ +string gethelp(const string& method)const; + +/** + * @brief Sign a buffer + * @param str_buffer The buffer to be signed + * @param str_brainkey Derives the private key used for signature + * @return The signed buffer + * @ingroup WalletCLI + */ +std::string sign_buffer(std::string const& str_buffer, + std::string const& str_brainkey) const; + +/** + * @brief Verify if the signature is valid + * @param str_buffer The original buffer + * @param str_publickey The public key used for verification + * @param str_signature The signed buffer + * @return true if valid, otherwise false + * @ingroup WalletCLI + */ +bool verify_signature(std::string const& str_buffer, + std::string const& str_publickey, + std::string const& str_signature) const; + +/** + * + * @param nodes + * @ingroup WalletCLI + */ +void network_add_nodes( const vector& nodes ); + +/** + * + * @ingroup WalletCLI + */ +vector< variant > network_get_connected_peers(); + + + + +#endif //DECENT_WALLET_GENERAL_H diff --git a/libraries/wallet/include/graphene/wallet/messaging.hpp b/libraries/wallet/include/graphene/wallet/messaging.hpp new file mode 100644 index 00000000..2d038818 --- /dev/null +++ b/libraries/wallet/include/graphene/wallet/messaging.hpp @@ -0,0 +1,37 @@ +#ifndef DECENT_WALLET_MESSAGING_H +#define DECENT_WALLET_MESSAGING_H + +/** + * @brief Send text message + * @param from + * @param to + * @param text + */ +void send_message(const std::string& from, std::vector to, string text); + +/** +* @brief Receives message objects by sender and/or receiver +* @param sender Name of message sender. If you dont want to filter by sender then let it empty. +* @param receiver Name of message receiver. If you dont want to filter by receiver then let it empty. +* @param max_count Maximal number of last messages to be displayed +* @return vector of message objects +*/ +vector get_message_objects(const std::string& sender, const std::string& receiver, uint32_t max_count) const; + +/** +* @brief Receives messages by receiver +* @param receiver Name of message receiver which must be imported to caller's wallet +* @param max_count Maximal number of last messages to be displayed +* @return vector of message objects +*/ +vector get_messages(const std::string& receiver, uint32_t max_count) const; + +/** +* @brief Receives sent messages by sender +* @param sender Name of message sender which must be imported to caller's wallet +* @param max_count Maximal number of last messages to be displayed +* @return vector of message objects +*/ +vector get_sent_messages(const std::string& sender, uint32_t max_count) const; + +#endif //DECENT_WALLET_MESSAGING_H diff --git a/libraries/wallet/include/graphene/wallet/mining.hpp b/libraries/wallet/include/graphene/wallet/mining.hpp new file mode 100644 index 00000000..fb1e036a --- /dev/null +++ b/libraries/wallet/include/graphene/wallet/mining.hpp @@ -0,0 +1,158 @@ +#ifndef DECENT_WALLET_MINING_H +#define DECENT_WALLET_MINING_H + +/** + * @brief Lists all miners registered in the blockchain. + * This returns a list of all account names that own miners, and the associated miner id, + * sorted by name. This lists miners whether they are currently voted in or not. + * + * Use the \c lowerbound and limit parameters to page through the list. To retrieve all miners, + * start by setting \c lowerbound to the empty string \c "", and then each iteration, pass + * the last miner name returned as the \c lowerbound for the next \c list_miners() call. + * + * @param lowerbound the name of the first miner to return. If the named miner does not exist, + * the list will start at the miner that comes after \c lowerbound + * @param limit the maximum number of miners to return (max: 1000) + * @returns a list of miners mapping miner names to miner ids + * @ingroup WalletCLI + */ +map list_miners(const string& lowerbound, uint32_t limit); + +/** + * s@brief Returns information about the given miner. + * @param owner_account the name or id of the miner account owner, or the id of the miner + * @returns the information about the miner stored in the block chain + * @ingroup WalletCLI + */ +miner_object get_miner(string owner_account); + +/** + * @brief Creates a miner object owned by the given account. + * + * An account can have at most one miner object. + * + * @param owner_account the name or id of the account which is creating the miner + * @param url a URL to include in the miner record in the blockchain. Clients may + * display this when showing a list of miners. May be blank. + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction registering a miner + * @ingroup WalletCLI + */ +signed_transaction create_miner(string owner_account, + string url, + bool broadcast = false); + +/** + * @brief Update a miner object owned by the given account. + * + * @param miner_name The name of the miner's owner account. Also accepts the ID of the owner account or the ID of the miner. + * @param url Same as for create_miner. The empty string makes it remain the same. + * @param block_signing_key The new block signing public key. The empty string makes it remain the same. + * @param broadcast true if you wish to broadcast the transaction. + * @ingroup WalletCLI + */ +signed_transaction update_miner(string miner_name, + string url, + string block_signing_key, + bool broadcast = false); + +/** + * @brief Get information about a vesting balance object. + * + * @param account_name An account name, account ID, or vesting balance object ID. + * @ingroup WalletCLI + */ +vector< vesting_balance_object_with_info > get_vesting_balances( string account_name ); + +/** + * @brief Withdraw a vesting balance. + * + * @param miner_name The account name of the miner, also accepts account ID or vesting balance ID type. + * @param amount The amount to withdraw. + * @param asset_symbol The symbol of the asset to withdraw. + * @param broadcast true if you wish to broadcast the transaction + * @ingroup WalletCLI + */ +signed_transaction withdraw_vesting( + string miner_name, + string amount, + string asset_symbol, + bool broadcast = false); + +/** + * @brief Vote for a given miner. + * + * An account can publish a list of all miners they approve of. This + * command allows you to add or remove miners from this list. + * Each account's vote is weighted according to the number of shares of the + * core asset owned by that account at the time the votes are tallied. + * + * @note you cannot vote against a miner, you can only vote for the miner + * or not vote for the miner. + * + * @param voting_account the name or id of the account who is voting with their shares + * @param miner the name or id of the miner' owner account + * @param approve true if you wish to vote in favor of that miner, false to + * remove your vote in favor of that miner + * @param broadcast true if you wish to broadcast the transaction + * @return the signed transaction changing your vote for the given miner + * @ingroup WalletCLI + */ +signed_transaction vote_for_miner(string voting_account, + string miner, + bool approve, + bool broadcast = false); + +/** + * @brief Set the voting proxy for an account. + * + * If a user does not wish to take an active part in voting, they can choose + * to allow another account to vote their stake. + * + * Setting a vote proxy does not remove your previous votes from the blockchain, + * they remain there but are ignored. If you later null out your vote proxy, + * your previous votes will take effect again. + * + * This setting can be changed at any time. + * + * @param account_to_modify the name or id of the account to update + * @param voting_account the name or id of an account authorized to vote account_to_modify's shares, + * or null to vote your own shares + * + * @param broadcast true if you wish to broadcast the transaction + * @return the signed transaction changing your vote proxy settings + * @ingroup WalletCLI + */ +signed_transaction set_voting_proxy(string account_to_modify, + optional voting_account, + bool broadcast = false); + +/** + * @brief Set your vote for the number of miners in the system. + * + * Each account can voice their opinion on how many + * miners there should be in the active miner list. These + * are independent of each other. You must vote your approval of at least as many + * miners as you claim there should be (you can't say that there should + * be 20 miners but only vote for 10). + * + * There are maximum values for each set in the blockchain parameters (currently + * defaulting to 1001). + * + * This setting can be changed at any time. If your account has a voting proxy + * set, your preferences will be ignored. + * + * @param account_to_modify the name or id of the account to update + * @param desired_number_of_miners + * @param broadcast true if you wish to broadcast the transaction + * @return the signed transaction changing your vote proxy settings + * @ingroup WalletCLI + */ +signed_transaction set_desired_miner_count(string account_to_modify, + uint16_t desired_number_of_miners, + bool broadcast = false); + + + + +#endif //DECENT_WALLET_MINING_H diff --git a/libraries/wallet/include/graphene/wallet/proposals.hpp b/libraries/wallet/include/graphene/wallet/proposals.hpp new file mode 100644 index 00000000..6285c8b2 --- /dev/null +++ b/libraries/wallet/include/graphene/wallet/proposals.hpp @@ -0,0 +1,89 @@ +#ifndef DECENT_WALLET_PROPOSALS_H +#define DECENT_WALLET_PROPOSALS_H + +/** + * Get list of proposed transactions + */ +vector get_proposed_transactions( string account_or_id )const; + +/** + * @brief Encapsulates begin_builder_transaction(), add_operation_to_builder_transaction(), + * propose_builder_transaction2(), set_fees_on_builder_transaction() functions for transfer operation + * + * @param proposer Proposer + * @param from the name or id of the account sending the funds + * @param to the name or id of the account receiving the funds + * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) + * @param asset_symbol the symbol or id of the asset to send + * @param memo a memo to attach to the transaction. The memo will be encrypted in the + * transaction and readable for the receiver. There is no length limit + * other than the limit imposed by maximum transaction size, but transaction + * increase with transaction size + * @param expiration expiration time + * @ingroup WalletCLI + */ + void propose_transfer(string proposer, + string from, + string to, + string amount, + string asset_symbol, + string memo, + time_point_sec expiration + ); + + + /** + * @brief Creates a transaction to propose a parameter change. + * + * Multiple parameters can be specified if an atomic change is + * desired. + * + * @param proposing_account The account paying the fee to propose the tx + * @param expiration_time Timestamp specifying when the proposal will either take effect or expire. + * @param changed_values The values to change; all other chain parameters are filled in with default values + * @param broadcast true if you wish to broadcast the transaction + * @return the signed version of the transaction + * @ingroup WalletCLI + */ + signed_transaction propose_parameter_change( + const string& proposing_account, + fc::time_point_sec expiration_time, + const variant_object& changed_values, + bool broadcast = false); + + /** + * @brief Propose a fee change. + * + * @param proposing_account The account paying the fee to propose the tx + * @param expiration_time Timestamp specifying when the proposal will either take effect or expire. + * @param changed_values Map of operation type to new fee. Operations may be specified by name or ID. + * The "scale" key changes the scale. All other operations will maintain current values. + * @param broadcast true if you wish to broadcast the transaction + * @return the signed version of the transaction + * @ingroup WalletCLI + */ + signed_transaction propose_fee_change( + const string& proposing_account, + fc::time_point_sec expiration_time, + const variant_object& changed_values, + bool broadcast = false); + + /** + * + * @brief Approve or disapprove a proposal. + * + * @param fee_paying_account The account paying the fee for the op. + * @param proposal_id The proposal to modify. + * @param delta Members contain approvals to create or remove. In JSON you can leave empty members undefined. + * @param broadcast true if you wish to broadcast the transaction + * @return the signed version of the transaction + * @ingroup WalletCLI + */ + signed_transaction approve_proposal( + const string& fee_paying_account, + const string& proposal_id, + const approval_delta& delta, + bool broadcast /* = false */); + + +#endif //DECENT_WALLET_PROPOSALS_H diff --git a/libraries/wallet/include/graphene/wallet/seeding.hpp b/libraries/wallet/include/graphene/wallet/seeding.hpp new file mode 100644 index 00000000..2e5e97c9 --- /dev/null +++ b/libraries/wallet/include/graphene/wallet/seeding.hpp @@ -0,0 +1,38 @@ +#ifndef DECENT_WALLET_SEEDING_H +#define DECENT_WALLET_SEEDING_H + + +/** + * @brief Get a list of seeders by price, in increasing order + * @param count Maximum number of seeders to retrieve + * @return The seeders found + * @ingroup WalletCLI + */ +vector list_seeders_by_price( uint32_t count )const; + +/** + * @brief Get a list of seeders ordered by total upload, in decreasing order + * @param count Maximum number of seeders to retrieve + * @return The seeders found + * @ingroup WalletCLI + */ +optional> list_seeders_by_upload( const uint32_t count )const; + +/** + * @brief Get a list of seeders by region code + * @param region_code Region code of seeders to retrieve + * @return The seeders found + * @ingroup WalletCLI + */ +vector list_seeders_by_region( const string region_code )const; + +/** + * @brief Get a list of seeders ordered by rating, in decreasing order + * @param count Maximum number of seeders to retrieve + * @return The seeders found + * @ingroup WalletCLI + */ +vector list_seeders_by_rating( const uint32_t count )const; + + +#endif //DECENT_WALLET_SEEDING_H diff --git a/libraries/wallet/include/graphene/wallet/subscription.hpp b/libraries/wallet/include/graphene/wallet/subscription.hpp new file mode 100644 index 00000000..3a5225ae --- /dev/null +++ b/libraries/wallet/include/graphene/wallet/subscription.hpp @@ -0,0 +1,101 @@ +#ifndef DECENT_WALLET_SUBSCRIPTION_H +#define DECENT_WALLET_SUBSCRIPTION_H + +/** + * @brief Creates a subscription to author. This function is used by consumers. + * @param from Account who wants subscription to author + * @param to The author you wish to subscribe to + * @param price_amount Price for the subscription + * @param price_asset_symbol Ticker symbol of the asset which will be used to buy subscription ( must be DCT token ) + * @param broadcast True if you wish to broadcast the transaction + * @return The signed transaction subscribing the consumer to the author + * @ingroup WalletCLI + */ +signed_transaction subscribe_to_author( string from, + string to, + string price_amount, + string price_asset_symbol, + bool broadcast/* = false */); + +/** + * @brief Creates a subscription to author. This function is used by author. + * @param from The account obtaining subscription from the author + * @param to The name or id of the author + * @param broadcast True if you wish to broadcast the transaction + * @return The signed transaction subscribing the consumer to the author + * @ingroup WalletCLI + */ +signed_transaction subscribe_by_author( string from, + string to, + bool broadcast/* = false */); + +/** + * @brief This function can be used to allow/disallow subscription. + * @param account The name or id of the account to update + * @param allow_subscription True if account (author) wants to allow subscription, false otherwise + * @param subscription_period Duration of subscription in days + * @param price_amount Price for subscription per one subscription period + * @param price_asset_symbol Ticker symbol of the asset which will be used to buy subscription + * @param broadcast True if you wish to broadcast the transaction + * @return The signed transaction updating the account + * @ingroup WalletCLI + */ +signed_transaction set_subscription( string account, + bool allow_subscription, + uint32_t subscription_period, + string price_amount, + string price_asset_symbol, + bool broadcast/* = false */); + +/** + * @brief This function can be used to allow/disallow automatic renewal of expired subscription. + * @param account_id_or_name The name or id of the account to update + * @param subscription_id The ID of the subscription. + * @param automatic_renewal True if account (consumer) wants to allow automatic renewal of subscription, false otherwise + * @param broadcast True if you wish to broadcast the transaction + * @return The signed transaction allowing/disallowing renewal of the subscription + * @ingroup WalletCLI + */ +signed_transaction set_automatic_renewal_of_subscription( string account_id_or_name, + subscription_id_type subscription_id, + bool automatic_renewal, + bool broadcast/* = false */); + +/** + * @brief Get a list of consumer's active (not expired) subscriptions. + * @param account_id_or_name The name or id of the consumer + * @param count Maximum number of subscriptions to fetch (must not exceed 100) + * @return List of active subscription objects corresponding to the provided consumer + * @ingroup WalletCLI + */ +vector< subscription_object > list_active_subscriptions_by_consumer( const string& account_id_or_name, const uint32_t count)const; + +/** + * @brief Get a list of consumer's subscriptions. + * @param account_id_or_name The name or id of the consumer + * @param count Maximum number of subscriptions to fetch (must not exceed 100) + * @return List of subscription objects corresponding to the provided consumer + * @ingroup WalletCLI + */ +vector< subscription_object > list_subscriptions_by_consumer( const string& account_id_or_name, const uint32_t count)const; + +/** + * @brief Get a list of active (not expired) subscriptions to author. + * @param account_id_or_name The name or id of the author + * @param count Maximum number of subscriptions to fetch (must not exceed 100) + * @return List of active subscription objects corresponding to the provided author + * @ingroup WalletCLI + */ +vector< subscription_object > list_active_subscriptions_by_author( const string& account_id_or_name, const uint32_t count)const; + +/** + * @brief Get a list of subscriptions to author. + * @param account_id_or_name The name or id of the author + * @param count Maximum number of subscriptions to fetch (must not exceed 100) + * @return List of subscription objects corresponding to the provided author + * @ingroup WalletCLI + */ +vector< subscription_object > list_subscriptions_by_author( const string& account_id_or_name, const uint32_t count)const; + + +#endif //DECENT_WALLET_SUBSCRIPTION_H diff --git a/libraries/wallet/include/graphene/wallet/transaction_builder.hpp b/libraries/wallet/include/graphene/wallet/transaction_builder.hpp new file mode 100644 index 00000000..62139aca --- /dev/null +++ b/libraries/wallet/include/graphene/wallet/transaction_builder.hpp @@ -0,0 +1,146 @@ +#ifndef DECENT_WALLET_TRANSACTION_BUILDER_H +#define DECENT_WALLET_TRANSACTION_BUILDER_H + +/** + * @ingroup Transaction Builder API + * @ingroup WalletCLI + */ +transaction_handle_type begin_builder_transaction(); + +/** + * + * @param transaction_handle + * @param op + * @ingroup Transaction Builder API + * @ingroup WalletCLI + */ +void add_operation_to_builder_transaction(transaction_handle_type transaction_handle, const operation& op); + +/** + * + * @param handle + * @param operation_index + * @param new_op + * @ingroup Transaction Builder API + * @ingroup WalletCLI + */ +void replace_operation_in_builder_transaction(transaction_handle_type handle, + unsigned operation_index, + const operation& new_op); +/** + * + * @param handle + * @param fee_asset + * @return + * @ingroup Transaction Builder API + * @ingroup WalletCLI + */ +asset set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset = GRAPHENE_SYMBOL); + +/** + * @param handle + * @ingroup Transaction Builder API + * @ingroup WalletCLI + */ +transaction preview_builder_transaction(transaction_handle_type handle); + +/** + * + * @param transaction_handle + * @param broadcast true to broadcast the transaction on the network + * @return + * @ingroup Transaction Builder API + * @ingroup WalletCLI + */ +signed_transaction sign_builder_transaction(transaction_handle_type transaction_handle, bool broadcast = true); + +/** + * + * @param handle + * @param expiration + * @param review_period_seconds + * @param broadcast true to broadcast the transaction on the network + * @return + * @ingroup Transaction Builder API + * @ingroup WalletCLI + */ +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 +); + +/** + * + * @param handle + * @param account_name_or_id + * @param expiration + * @param review_period_seconds + * @param broadcast true to broadcast the transaction on the network + * @return + * @ingroup WalletCLI + */ +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 +); + +/** + * + * @param handle + * @ingroup Transaction Builder API + * @ingroup WalletCLI + */ +void remove_builder_transaction(transaction_handle_type handle); + +/** + * @brief Converts a signed_transaction in JSON form to its binary representation. + * + * TODO: I don't see a broadcast_transaction() function, do we need one? + * + * @param tx the transaction to serialize + * @returns the binary form of the transaction. It will not be hex encoded, + * this returns a raw string that may have null characters embedded + * in it + * @ingroup WalletCLI + */ +string serialize_transaction(signed_transaction tx) const; + +/** + * @brief Signs a transaction. + * + * Given a fully-formed transaction that is only lacking signatures, this signs + * the transaction with the necessary keys and optionally broadcasts the transaction + * @param tx the unsigned transaction + * @param broadcast true if you wish to broadcast the transaction + * @return the signed version of the transaction + * @ingroup WalletCLI + */ +signed_transaction sign_transaction(signed_transaction tx, bool broadcast = false); + +/** + * @brief Returns an uninitialized object representing a given blockchain operation. + * + * This returns a default-initialized object of the given type; it can be used + * during early development of the wallet when we don't yet have custom commands for + * creating all of the operations the blockchain supports. + * + * Any operation the blockchain supports can be created using the transaction builder's + * \c add_operation_to_builder_transaction() , but to do that from the CLI you need to + * know what the JSON form of the operation looks like. This will give you a template + * you can fill in. It's better than nothing. + * + * @param operation_type the type of operation to return, must be one of the + * operations defined in `graphene/chain/operations.hpp` + * (e.g., "global_parameters_update_operation") + * @return a default-constructed operation of the given type + * @ingroup WalletCLI + */ +operation get_prototype_operation(string operation_type); + + +#endif //DECENT_TRANSACTION_BUILDER_H diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 24437a87..bad223dd 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -246,1161 +246,21 @@ namespace graphene { namespace wallet { wallet_api( const wallet_data& initial_data, fc::api rapi ); virtual ~wallet_api(); - /** - * @brief Copy wallet file to a new file - * @param destination_filename - * @return true if the wallet is copied, false otherwise - * @ingroup WalletCLI - */ - bool copy_wallet_file( string destination_filename ); - - /** - * @brief Derive private key from given prefix and sequence - * @param prefix_string - * @param sequence_number - * @return private_key Derived private key - * @ingroup WalletCLI - */ - fc::ecc::private_key derive_private_key(const std::string& prefix_string, int sequence_number) const; - - /** - * @brief Lists all available commands - * @return List of all available commands - * @ingroup WalletCLI - */ - variant info(); - - /** - * @brief Returns info such as client version, git version of graphene/fc, version of boost, openssl. - * @returns compile time info and client and dependencies versions - * @ingroup WalletCLI - */ - variant_object about() const; - - /** - * @brief Retrieve a full, signed block with info - * @param num ID of the block - * @return the referenced block with info, or null if no matching block was found - * @ingroup WalletCLI - */ - optional get_block( uint32_t num ); - - /** - * @brief Returns the number of accounts registered on the blockchain - * @returns the number of registered accounts - * @ingroup WalletCLI - */ - uint64_t get_account_count()const; - - /** - * @brief Lists all accounts controlled by this wallet. - * This returns a list of the full account objects for all accounts whose private keys - * we possess. - * @returns a list of account objects - * @ingroup WalletCLI - */ - vector list_my_accounts(); - - /** - * @brief Lists all accounts registered in the blockchain. - * This returns a list of all account names and their account ids, sorted by account name. - * - * Use the \c lowerbound and limit parameters to page through the list. To retrieve all accounts, - * start by setting \c lowerbound to the empty string \c "", and then each iteration, pass - * the last account name returned as the \c lowerbound for the next \c list_accounts() call. - * - * @param lowerbound the name of the first account to return. If the named account does not exist, - * the list will start at the account that comes after \c lowerbound - * @param limit the maximum number of accounts to return (max: 1000) - * @returns a list of accounts mapping account names to account ids - * @ingroup WalletCLI - */ - map list_accounts(const string& lowerbound, uint32_t limit); - - /** - * @brief Get names and IDs for registered accounts that match search term - * @param term will try to partially match account name or id - * @param limit Maximum number of results to return -- must not exceed 1000 - * @param order Sort data by field - * @param id object_id to start searching from - * @return Map of account names to corresponding IDs - * @ingroup WalletCLI - */ - vector search_accounts(const string& term, const string& order, const string& id, uint32_t limit); - - /** - * @brief List the balances of an account. - * Each account can have multiple balances, one for each type of asset owned by that - * account. The returned list will only contain assets for which the account has a - * nonzero balance - * @param id the name or id of the account whose balances you want - * @returns a list of the given account's balances - * @ingroup WalletCLI - */ - vector list_account_balances(const string& id); - - /** - * @brief Lists all assets registered on the blockchain. - * - * To list all assets, pass the empty string \c "" for the lowerbound to start - * at the beginning of the list, and iterate as necessary. - * - * @param lowerbound the symbol of the first asset to include in the list. - * @param limit the maximum number of assets to return (max: 100) - * @returns the list of asset objects, ordered by symbol - * @ingroup WalletCLI - */ - vector list_assets(const string& lowerbound, uint32_t limit)const; - - /** - * @brief Returns the operations on the named account. - * - * This returns a list of transaction detail object, which describe activity on the account. - * - * @param account_name the name or id of the account - * @param order Sort data by field - * @param id object_id to start searching from - * @param limit the number of entries to return (starting from the most recent) (max 100) - * @returns a list of \c transaction_detail_object - * @ingroup WalletCLI - */ - vector search_account_history(string const& account_name, - string const& order, - string const& id, - int limit) const; - - - /** Returns the most recent operations on the named account. - * - * This returns a list of operation history objects, which describe activity on the account. - * - * @note this API doesn't give a way to retrieve more than the most recent 100 transactions, - * you can interface directly with the blockchain to get more history - * @param name the name or id of the account - * @param limit the number of entries to return (starting from the most recent) (max 100) - * @returns a list of \c operation_history_objects - */ - vector get_account_history(string name, int limit)const; - - /** - * @breif Get operations relevant to the specified account referenced - * by an event numbering specific to the account. The current number of operations - * for the account can be found in the account statistics (or use 0 for start). - * @param account The account whose history should be queried - * @param stop Sequence number of earliest operation. 0 is default and will - * query 'limit' number of operations. - * @param limit Maximum number of operations to retrieve (must not exceed 100) - * @param start Sequence number of the most recent operation to retrieve. - * 0 is default, which will start querying from the most recent operation. - * @return A list of operations performed by account, ordered from most recent to oldest. - * @ingroup WalletCLI - */ - vector get_relative_account_history(string name, - uint32_t stop, - int limit, - uint32_t start)const; - - /** - * @brief Returns the block chain's slowly-changing settings. - * This object contains all of the properties of the blockchain that are fixed - * or that change only once per maintenance interval (daily) such as the - * current list of miners, block interval, etc. - * @see \c get_dynamic_global_properties() for frequently changing properties - * @returns the global properties - * @ingroup WalletCLI - */ - global_property_object get_global_properties() const; - - /** - * @brief Returns the block chain's rapidly-changing properties. - * The returned object contains information that changes every block interval - * such as the head block number, the next miner, etc. - * @see \c get_global_properties() for less-frequently changing properties - * @returns the dynamic global properties - * @ingroup WalletCLI - */ - dynamic_global_property_object get_dynamic_global_properties() const; - - /** - * @brief Returns information about the given account. - * - * @param account_name_or_id the name or id of the account to provide information about - * @returns the public account data stored in the blockchain - * @ingroup WalletCLI - */ - account_object get_account(string account_name_or_id) const; - - /** - * @brief Returns information about the given asset. - * @param asset_name_or_id the symbol or id of the asset in question - * @returns the information about the asset stored in the block chain - * @ingroup WalletCLI - */ - asset_object get_asset(string asset_name_or_id) const; - - /** - * @brief Returns the BitAsset-specific data for a given asset. - * Market-issued assets's behavior are determined both by their "BitAsset Data" and - * their basic asset data, as returned by \c get_asset(). - * @param asset_name_or_id the symbol or id of the BitAsset in question - * @returns the BitAsset-specific data for this asset - * @ingroup WalletCLI - */ - monitored_asset_options get_monitored_asset_data(string asset_name_or_id)const; - - /** - * @brief Lookup the id of a named account. - * @param account_name_or_id the name of the account to look up - * @returns the id of the named account - * @ingroup WalletCLI - */ - account_id_type get_account_id(string account_name_or_id) const; - - /** - * @brief Lookup the id of a named asset. - * @param asset_name_or_id the symbol of an asset to look up - * @returns the id of the given asset - * @ingroup WalletCLI - */ - asset_id_type get_asset_id(string asset_name_or_id) const; - - /** - * @brief Returns the blockchain object corresponding to the given id. - * - * This generic function can be used to retrieve any object from the blockchain - * that is assigned an ID. Certain types of objects have specialized convenience - * functions to return their objects -- e.g., assets have \c get_asset(), accounts - * have \c get_account(), but this function will work for any object. - * - * @param id the id of the object to return - * @returns the requested object - * @ingroup WalletCLI - */ - variant get_object(object_id_type id) const; - - /** @brief Returns the current wallet filename. - * - * This is the filename that will be used when automatically saving the wallet. - * - * @see set_wallet_filename() - * @return the wallet filename - * @ingroup WalletCLI - */ - string get_wallet_filename() const; - - /** - * @brief Get the WIF private key corresponding to a public key. The - * private key must already be in the wallet. - * @param pubkey Public key - * @return WIF private key corresponding to a public key - * @ingroup WalletCLI - */ - string get_private_key( public_key_type pubkey )const; - - /** - * @ingroup Transaction Builder API - * @ingroup WalletCLI - */ - transaction_handle_type begin_builder_transaction(); - - /** - * - * @param transaction_handle - * @param op - * @ingroup Transaction Builder API - * @ingroup WalletCLI - */ - void add_operation_to_builder_transaction(transaction_handle_type transaction_handle, const operation& op); - - /** - * - * @param handle - * @param operation_index - * @param new_op - * @ingroup Transaction Builder API - * @ingroup WalletCLI - */ - void replace_operation_in_builder_transaction(transaction_handle_type handle, - unsigned operation_index, - const operation& new_op); - /** - * - * @param handle - * @param fee_asset - * @return - * @ingroup Transaction Builder API - * @ingroup WalletCLI - */ - asset set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset = GRAPHENE_SYMBOL); - - /** - * @param handle - * @ingroup Transaction Builder API - * @ingroup WalletCLI - */ - transaction preview_builder_transaction(transaction_handle_type handle); - - /** - * - * @param transaction_handle - * @param broadcast true to broadcast the transaction on the network - * @return - * @ingroup Transaction Builder API - * @ingroup WalletCLI - */ - signed_transaction sign_builder_transaction(transaction_handle_type transaction_handle, bool broadcast = true); - - /** - * - * @param handle - * @param expiration - * @param review_period_seconds - * @param broadcast true to broadcast the transaction on the network - * @return - * @ingroup Transaction Builder API - * @ingroup WalletCLI - */ - 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 - ); - - /** - * - * @param handle - * @param account_name_or_id - * @param expiration - * @param review_period_seconds - * @param broadcast true to broadcast the transaction on the network - * @return - * @ingroup WalletCLI - */ - 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 - ); - - /** - * - * @param handle - * @ingroup Transaction Builder API - * @ingroup WalletCLI - */ - void remove_builder_transaction(transaction_handle_type handle); - - /** - * Get list of proposed transactions - */ - vector get_proposed_transactions( string account_or_id )const; - - /** - * @brief Checks whether the wallet has just been created and has not yet had a password set. - * - * Calling \c set_password will transition the wallet to the locked state. - * @return true if the wallet is new - * @ingroup Wallet Management - * @ingroup WalletCLI - */ - bool is_new()const; - - /** - * @brief Checks whether the wallet is locked (is unable to use its private keys). - * - * This state can be changed by calling \c lock() or \c unlock(). - * @return true if the wallet is locked - * @ingroup Wallet Management - * @ingroup WalletCLI - */ - bool is_locked()const; - - /** - * @brief Locks the wallet immediately. - * @ingroup Wallet Management - * @ingroup WalletCLI - */ - void lock(); - - /** - * @brief Unlocks the wallet. - * - * The wallet remain unlocked until the \c lock is called - * or the program exits. - * @param password the password previously set with \c set_password() - * @ingroup Wallet Management - * @ingroup WalletCLI - */ - void unlock(string password); - - /** - * @brief Sets a new password on the wallet. - * - * The wallet must be either 'new' or 'unlocked' to - * execute this command. - * @param password - * @ingroup Wallet Management - * @ingroup WalletCLI - */ - void set_password(string password); - - /** - * @brief Dumps all private keys owned by the wallet. - * - * The keys are printed in WIF format. You can import these keys into another wallet - * using \c import_key() - * @returns a map containing the private keys, indexed by their public key - * @ingroup WalletCLI - */ - map dump_private_keys(); - - /** - * @brief Returns a list of all commands supported by the wallet API. - * - * This lists each command, along with its arguments and return types. - * For more detailed help on a single command, use \c get_help() - * - * @returns a multi-line string suitable for displaying on a terminal - * @ingroup WalletCLI - */ - string help()const; - - /** - * @brief Returns detailed help on a single API command. - * @param method the name of the API command you want help with - * @returns a multi-line string suitable for displaying on a terminal - * @ingroup WalletCLI - */ - string gethelp(const string& method)const; - - /** - * @brief Loads a specified Graphene wallet. - * - * The current wallet is closed before the new wallet is loaded. - * - * @warning This does not change the filename that will be used for future - * wallet writes, so this may cause you to overwrite your original - * wallet unless you also call \c set_wallet_filename() - * - * @param wallet_filename the filename of the wallet JSON file to load. - * If \c wallet_filename is empty, it reloads the - * existing wallet file - * @returns true if the specified wallet is loaded - * @ingroup WalletCLI - */ - bool load_wallet_file(string wallet_filename = ""); - - /** - * @brief Saves the current wallet to the given filename. - * - * @warning This does not change the wallet filename that will be used for future - * writes, so think of this function as 'Save a Copy As...' instead of - * 'Save As...'. Use \c set_wallet_filename() to make the filename - * persist. - * @param wallet_filename the filename of the new wallet JSON file to create - * or overwrite. If \c wallet_filename is empty, - * save to the current filename. - * @ingroup WalletCLI - */ - void save_wallet_file(string wallet_filename = ""); - - /** - * @brief Sets the wallet filename used for future writes. - * - * This does not trigger a save, it only changes the default filename - * that will be used the next time a save is triggered. - * - * @param wallet_filename the new filename to use for future saves - * @ingroup WalletCLI - */ - void set_wallet_filename(string wallet_filename); - - /** - * @brief Suggests a safe brain key to use for creating your account. - * \c create_account_with_brain_key() requires you to specify a 'brain key', - * a long passphrase that provides enough entropy to generate cyrptographic - * keys. This function will suggest a suitably random string that should - * be easy to write down (and, with effort, memorize). - * @returns a suggested brain_key - * @ingroup WalletCLI - */ - brain_key_info suggest_brain_key()const; - - /** - * @brief Suggests a safe brain key to use for creating your account also - * generates the el_gamal_key_pair corresponding to the brain key - * \c create_account_with_brain_key() requires you to specify a 'brain key', - * a long passphrase that provides enough entropy to generate cyrptographic - * keys. This function will suggest a suitably random string that should - * be easy to write down (and, with effort, memorize). - * @returns a suggested brain_key - * @ingroup WalletCLI - */ - pair generate_brain_key_el_gamal_key() const; - - /** - * @brief Calculates the private key and public key corresponding to any brain key - * @param brain_key the brain key to be used for calculation - * @returns the corresponding brain_key_info - * @ingroup WalletCLI - */ - brain_key_info get_brain_key_info(string const& brain_key) const; - - /** - * @brief Converts a signed_transaction in JSON form to its binary representation. - * - * TODO: I don't see a broadcast_transaction() function, do we need one? - * - * @param tx the transaction to serialize - * @returns the binary form of the transaction. It will not be hex encoded, - * this returns a raw string that may have null characters embedded - * in it - * @ingroup WalletCLI - */ - string serialize_transaction(signed_transaction tx) const; - - /** - * @brief Imports the private key for an existing account. - * - * The private key must match either an owner key or an active key for the - * named account. - * - * @see dump_private_keys() - * - * @param account_name_or_id the account owning the key - * @param wif_key the private key in WIF format - * @returns true if the key was imported - * @ingroup WalletCLI - */ - bool import_key(string account_name_or_id, string wif_key); - - /** - * @brief Imports accounts from the other wallet file - * @param filename The filename of the wallet JSON file - * @param password User's password to the wallet - * @return mapped account names to boolean values indicating whether the account was successfully imported - * @ingroup WalletCLI - */ - map import_accounts( string filename, string password ); - - /** - * @brief Imports account keys from particular account from another wallet file to desired account located in wallet file currently used - * @param filename The filename of the wallet JSON file - * @param password User's password to the wallet - * @param src_account_name Name of the source account - * @param dest_account_name Name of the destination account - * @return true if the keys were imported - * @ingroup WalletCLI - */ - bool import_account_keys( string filename, string password, string src_account_name, string dest_account_name ); - - /** - * @brief Transforms a brain key to reduce the chance of errors when re-entering the key from memory. - * - * This takes a user-supplied brain key and normalizes it into the form used - * for generating private keys. In particular, this upper-cases all ASCII characters - * and collapses multiple spaces into one. - * @param s the brain key as supplied by the user - * @returns the brain key in its normalized form - * @ingroup WalletCLI - */ - string normalize_brain_key(string s) const; - - /** - * @brief Registers a third party's account on the blockckain. - * - * This function is used to register an account for which you do not own the private keys. - * When acting as a registrar, an end user will generate their own private keys and send - * you the public keys. The registrar will use this function to register the account - * on behalf of the end user. - * - * @see create_account_with_brain_key() - * - * @param name the name of the account, must be unique on the blockchain. Shorter names - * are more expensive to register; the rules are still in flux, but in general - * names of more than 8 characters with at least one digit will be cheap. - * @param owner the owner key for the new account - * @param active the active key for the new account - * @param registrar_account the account which will pay the fee to register the user - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction registering the account - * @ingroup WalletCLI - */ - signed_transaction register_account(string name, - public_key_type owner, - public_key_type active, - string registrar_account, - bool broadcast = false); - - /** - * @brief Creates a new account and registers it on the blockchain. - * - * @todo why no referrer_percent here? - * - * @see suggest_brain_key() - * @see register_account() - * - * @param brain_key the brain key used for generating the account's private keys - * @param account_name the name of the account, must be unique on the blockchain. Shorter names - * are more expensive to register; the rules are still in flux, but in general - * names of more than 8 characters with at least one digit will be cheap. - * @param registrar_account the account which will pay the fee to register the user - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction registering the account - * @ingroup WalletCLI - */ - signed_transaction create_account_with_brain_key(string brain_key, - string account_name, - string registrar_account, - bool broadcast = false); - /** - * @brief Creates a new account and registers it on the blockchain, but does not import the key to wallet. - * - * @see suggest_brain_key() - * @see register_account() - * - * @param brain_key the brain key used for generating the account's private keys - * @param account_name the name of the account, must be unique on the blockchain. Shorter names - * are more expensive to register; the rules are still in flux, but in general - * names of more than 8 characters with at least one digit will be cheap. - * @param registrar_account the account which will pay the fee to register the user - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction registering the account - * @ingroup WalletCLI - */ - signed_transaction create_account_with_brain_key_noimport(string brain_key, - string account_name, - string registrar_account, - bool broadcast = false); - - /** @brief Transfer an amount from one account to another. - * @param from the name or id of the account sending the funds - * @param to the name or id of the account receiving the funds - * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) - * @param asset_symbol the symbol or id of the asset to send - * @param memo a memo to attach to the transaction. The memo will be encrypted in the - * transaction and readable for the receiver. There is no length limit - * other than the limit imposed by maximum transaction size, but transaction - * increase with transaction size - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction transferring funds - * @ingroup WalletCLI - */ - signed_transaction transfer(string from, - string to, - string amount, - string asset_symbol, - string memo, - bool broadcast = false); - - /** - * @brief This method works just like transfer, except it always broadcasts and - * returns the transaction ID along with the signed transaction. - * @param from the name or id of the account sending the funds - * @param to the name or id of the account receiving the funds - * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) - * @param asset_symbol the symbol or id of the asset to send - * @param memo a memo to attach to the transaction. The memo will be encrypted in the - * transaction and readable for the receiver. There is no length limit - * other than the limit imposed by maximum transaction size, but transaction - * increase with transaction size - * @ingroup WalletCLI - */ - pair transfer2(string from, - string to, - string amount, - string asset_symbol, - string memo ) { - auto trx = transfer( from, to, amount, asset_symbol, memo, true ); - return std::make_pair(trx.id(),trx); - } - - /** - * @brief Encapsulates begin_builder_transaction(), add_operation_to_builder_transaction(), - * propose_builder_transaction2(), set_fees_on_builder_transaction() functions for transfer operation - * - * @param proposer Proposer - * @param from the name or id of the account sending the funds - * @param to the name or id of the account receiving the funds - * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) - * @param asset_symbol the symbol or id of the asset to send - * @param memo a memo to attach to the transaction. The memo will be encrypted in the - * transaction and readable for the receiver. There is no length limit - * other than the limit imposed by maximum transaction size, but transaction - * increase with transaction size - * @param expiration expiration time - * @ingroup WalletCLI - */ - void propose_transfer(string proposer, - string from, - string to, - string amount, - string asset_symbol, - string memo, - time_point_sec expiration - ); - - /** - * @brief This method is used to convert a JSON transaction to its transaction ID. - * @param trx Signed transaction - * @return - * @ingroup WalletCLI - */ - transaction_id_type get_transaction_id( const signed_transaction& trx )const { return trx.id(); } - - - - /** - * @brief Creates a new monitored asset. - * - * Options can be changed later using \c update_monitored_asset() - * - * @param issuer the name or id of the account who will pay the fee and become the - * issuer of the new asset. This can be updated later - * @param symbol the ticker symbol of the new asset - * @param precision the number of digits of precision to the right of the decimal point, - * must be less than or equal to 12 - * @param description asset description. Maximal length is 1000 chars. - * @param feed_lifetime_sec time before a price feed expires - * @param minimum_feeds minimum number of unexpired feeds required to extract a median feed from - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction creating a new asset - * @ingroup WalletCLI - */ - signed_transaction create_monitored_asset(string issuer, - string symbol, - uint8_t precision, - string description, - uint32_t feed_lifetime_sec, - uint8_t minimum_feeds, - bool broadcast = false); - - /** - * @brief Update the options specific to a monitored asset. - * - * Monitored assets have some options which are not relevant to other asset types. This operation is used to update those - * options and an existing monitored asset. - * - * @param symbol the name or id of the asset to update, which must be a market-issued asset - * @param description asset description - * @param feed_lifetime_sec time before a price feed expires - * @param minimum_feeds minimum number of unexpired feeds required to extract a median feed from - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction updating the bitasset - * @ingroup WalletCLI - */ - signed_transaction update_monitored_asset(string symbol, - string description, - uint32_t feed_lifetime_sec, - uint8_t minimum_feeds, - bool broadcast = false); - - /** - * @brief Creates a new user-issued asset. - * - * Options can be changed later using \c update_asset() - * - * @param issuer the name or id of the account who will pay the fee and become the - * issuer of the new asset. This can be updated later - * @param symbol the ticker symbol of the new asset - * @param precision the number of digits of precision to the right of the decimal point, - * must be less than or equal to 12 - * @param description asset description. Maximal length is 1000 chars - * @param max_supply the maximum supply of this asset which may exist at any given time - * @param core_exchange_rate Core_exchange_rate technically needs to store the asset ID of - * this new asset. Since this ID is not known at the time this operation is - * created, create this price as though the new asset has instance ID 1, and - * the chain will overwrite it with the new asset's ID - * @param is_exchangeable True to allow implicit conversion of this asset to/from core asset - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction creating a new asset - * @ingroup WalletCLI - */ - signed_transaction create_user_issued_asset(string issuer, - string symbol, - uint8_t precision, - string description, - uint64_t max_supply, - price core_exchange_rate, - bool is_exchangeable, - bool broadcast = false); - - /** Issue new shares of an asset. - * - * @param to_account the name or id of the account to receive the new shares - * @param amount the amount to issue, in nominal units - * @param symbol the ticker symbol of the asset to issue - * @param memo a memo to include in the transaction, readable by the recipient - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction issuing the new shares - */ - signed_transaction issue_asset(string to_account, - string amount, - string symbol, - string memo, - bool broadcast = false); - - /** - * @brief Update the options specific to a user issued asset. - * - * User issued assets have some options which are not relevant to other asset types. This operation is used to update those - * options an an existing user issues asset. - * - * - * @param symbol the name or id of the asset to update, which must be a market-issued asset - * @param new_issuer if the asset is to be given a new issuer, specify his ID here - * @param description asset description - * @param max_supply The maximum supply of this asset which may exist at any given time - * @param core_exchange_rate Price used to convert non-core asset to core asset - * @param is_exchangeable True to allow implicit conversion of this asset to/from core asset - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction updating the bitasset - * @ingroup WalletCLI - */ - signed_transaction update_user_issued_asset(string symbol, - string new_issuer, - string description, - uint64_t max_supply, - price core_exchange_rate, - bool is_exchangeable, - bool broadcast = false); - - /** Pay into the pools for the given asset. - * - * User-issued assets can optionally have a pool of the core asset which is - * automatically used to pay transaction fees for any transaction using that - * asset (using the asset's core exchange rate). - * - * Allows anyone to deposit core/asset into pools. - * This pool are used when conversion between assets is needed (paying fees, paying for a content in different asset). - * - * @param from the name or id of the account sending the core asset - * @param uia_amount the amount of "this" asset to deposit - * @param uia_symbol the name or id of the asset whose pool you wish to fund - * @param dct_amount the amount of the core asset to deposit - * @param dct_symbol the name or id of the DCT asset - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction funding the fee pool - */ - signed_transaction fund_asset_pools(string from, - string uia_amount, - string uia_symbol, - string dct_amount, - string dct_symbol, - bool broadcast = false); - - /** Burns the given user-issued asset. - * - * This command burns the user-issued asset to reduce the amount in circulation. - * @note you cannot burn market-issued assets. - * @param from the account containing the asset you wish to burn - * @param amount the amount to burn, in nominal units - * @param symbol the name or id of the asset to burn - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction burning the asset - */ - signed_transaction reserve_asset(string from, - string amount, - string symbol, - bool broadcast = false); - - /** Transfers accumulated assets from pools back to the issuer's balance. - * - * @note you cannot claim assets from pools of market-issued asset. - * @param uia_amount the amount of "this" asset to claim, in nominal units - * @param uia_symbol the name or id of the asset to claim - * @param dct_amount the amount of DCT asset to claim, in nominal units - * @param dct_symbol the name or id of the DCT asset to claim - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction claiming the fees - */ - signed_transaction claim_fees(string uia_amount, - string uia_symbol, - string dct_amount, - string dct_symbol, - bool broadcast = false); - - /** - * @brief Converts asset into DCT, using actual price feed. - * @param amount the amount to convert in nominal units - * @param asset_symbol the symbol or id of the asset to convert - * @return price in DCT - */ - string price_to_dct(const string& amount, const string& asset_symbol_or_id); - - /** - * @brief Publishes a price feed for the named asset. - * - * Price feed providers use this command to publish their price feeds for market-issued assets. A price feed is - * used to tune the market for a particular market-issued asset. For each value in the feed, the median across all - * miner feeds for that asset is calculated and the market for the asset is configured with the median of that - * value. - * - * @param publishing_account the account publishing the price feed - * @param symbol the name or id of the asset whose feed we're publishing - * @param feed the price_feed object for particular market-issued asset - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction updating the price feed for the given asset - * @ingroup WalletCLI - */ - signed_transaction publish_asset_feed(string publishing_account, - string symbol, - price_feed feed, - bool broadcast = false); - - /** - * @brief Get a list of published price feeds by a miner. - * - * @param account_name_or_id the name or id of the account - * @param count Maximum number of price feeds to fetch (must not exceed 100) - * @returns list of price feeds published by the miner - * @ingroup WalletCLI - */ - multimap get_feeds_by_miner(const string& account_name_or_id, - const uint32_t count); - - /** - * @brief Lists all miners registered in the blockchain. - * This returns a list of all account names that own miners, and the associated miner id, - * sorted by name. This lists miners whether they are currently voted in or not. - * - * Use the \c lowerbound and limit parameters to page through the list. To retrieve all miners, - * start by setting \c lowerbound to the empty string \c "", and then each iteration, pass - * the last miner name returned as the \c lowerbound for the next \c list_miners() call. - * - * @param lowerbound the name of the first miner to return. If the named miner does not exist, - * the list will start at the miner that comes after \c lowerbound - * @param limit the maximum number of miners to return (max: 1000) - * @returns a list of miners mapping miner names to miner ids - * @ingroup WalletCLI - */ - map list_miners(const string& lowerbound, uint32_t limit); - - /** - * s@brief Returns information about the given miner. - * @param owner_account the name or id of the miner account owner, or the id of the miner - * @returns the information about the miner stored in the block chain - * @ingroup WalletCLI - */ - miner_object get_miner(string owner_account); - - /** - * @brief Creates a miner object owned by the given account. - * - * An account can have at most one miner object. - * - * @param owner_account the name or id of the account which is creating the miner - * @param url a URL to include in the miner record in the blockchain. Clients may - * display this when showing a list of miners. May be blank. - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction registering a miner - * @ingroup WalletCLI - */ - signed_transaction create_miner(string owner_account, - string url, - bool broadcast = false); - - /** - * @brief Update a miner object owned by the given account. - * - * @param miner_name The name of the miner's owner account. Also accepts the ID of the owner account or the ID of the miner. - * @param url Same as for create_miner. The empty string makes it remain the same. - * @param block_signing_key The new block signing public key. The empty string makes it remain the same. - * @param broadcast true if you wish to broadcast the transaction. - * @ingroup WalletCLI - */ - signed_transaction update_miner(string miner_name, - string url, - string block_signing_key, - bool broadcast = false); - - /** - * @brief Get information about a vesting balance object. - * - * @param account_name An account name, account ID, or vesting balance object ID. - * @ingroup WalletCLI - */ - vector< vesting_balance_object_with_info > get_vesting_balances( string account_name ); - - /** - * @brief Withdraw a vesting balance. - * - * @param miner_name The account name of the miner, also accepts account ID or vesting balance ID type. - * @param amount The amount to withdraw. - * @param asset_symbol The symbol of the asset to withdraw. - * @param broadcast true if you wish to broadcast the transaction - * @ingroup WalletCLI - */ - signed_transaction withdraw_vesting( - string miner_name, - string amount, - string asset_symbol, - bool broadcast = false); - - /** - * @brief Vote for a given miner. - * - * An account can publish a list of all miners they approve of. This - * command allows you to add or remove miners from this list. - * Each account's vote is weighted according to the number of shares of the - * core asset owned by that account at the time the votes are tallied. - * - * @note you cannot vote against a miner, you can only vote for the miner - * or not vote for the miner. - * - * @param voting_account the name or id of the account who is voting with their shares - * @param miner the name or id of the miner' owner account - * @param approve true if you wish to vote in favor of that miner, false to - * remove your vote in favor of that miner - * @param broadcast true if you wish to broadcast the transaction - * @return the signed transaction changing your vote for the given miner - * @ingroup WalletCLI - */ - signed_transaction vote_for_miner(string voting_account, - string miner, - bool approve, - bool broadcast = false); - - /** - * @brief Set the voting proxy for an account. - * - * If a user does not wish to take an active part in voting, they can choose - * to allow another account to vote their stake. - * - * Setting a vote proxy does not remove your previous votes from the blockchain, - * they remain there but are ignored. If you later null out your vote proxy, - * your previous votes will take effect again. - * - * This setting can be changed at any time. - * - * @param account_to_modify the name or id of the account to update - * @param voting_account the name or id of an account authorized to vote account_to_modify's shares, - * or null to vote your own shares - * - * @param broadcast true if you wish to broadcast the transaction - * @return the signed transaction changing your vote proxy settings - * @ingroup WalletCLI - */ - signed_transaction set_voting_proxy(string account_to_modify, - optional voting_account, - bool broadcast = false); - - /** - * @brief Set your vote for the number of miners in the system. - * - * Each account can voice their opinion on how many - * miners there should be in the active miner list. These - * are independent of each other. You must vote your approval of at least as many - * miners as you claim there should be (you can't say that there should - * be 20 miners but only vote for 10). - * - * There are maximum values for each set in the blockchain parameters (currently - * defaulting to 1001). - * - * This setting can be changed at any time. If your account has a voting proxy - * set, your preferences will be ignored. - * - * @param account_to_modify the name or id of the account to update - * @param desired_number_of_miners - * @param broadcast true if you wish to broadcast the transaction - * @return the signed transaction changing your vote proxy settings - * @ingroup WalletCLI - */ - signed_transaction set_desired_miner_count(string account_to_modify, - uint16_t desired_number_of_miners, - bool broadcast = false); - - /** - * @brief Signs a transaction. - * - * Given a fully-formed transaction that is only lacking signatures, this signs - * the transaction with the necessary keys and optionally broadcasts the transaction - * @param tx the unsigned transaction - * @param broadcast true if you wish to broadcast the transaction - * @return the signed version of the transaction - * @ingroup WalletCLI - */ - signed_transaction sign_transaction(signed_transaction tx, bool broadcast = false); - - /** - * @brief Returns an uninitialized object representing a given blockchain operation. - * - * This returns a default-initialized object of the given type; it can be used - * during early development of the wallet when we don't yet have custom commands for - * creating all of the operations the blockchain supports. - * - * Any operation the blockchain supports can be created using the transaction builder's - * \c add_operation_to_builder_transaction() , but to do that from the CLI you need to - * know what the JSON form of the operation looks like. This will give you a template - * you can fill in. It's better than nothing. - * - * @param operation_type the type of operation to return, must be one of the - * operations defined in `graphene/chain/operations.hpp` - * (e.g., "global_parameters_update_operation") - * @return a default-constructed operation of the given type - * @ingroup WalletCLI - */ - operation get_prototype_operation(string operation_type); - /** - * @brief Creates a transaction to propose a parameter change. - * - * Multiple parameters can be specified if an atomic change is - * desired. - * - * @param proposing_account The account paying the fee to propose the tx - * @param expiration_time Timestamp specifying when the proposal will either take effect or expire. - * @param changed_values The values to change; all other chain parameters are filled in with default values - * @param broadcast true if you wish to broadcast the transaction - * @return the signed version of the transaction - * @ingroup WalletCLI - */ - signed_transaction propose_parameter_change( - const string& proposing_account, - fc::time_point_sec expiration_time, - const variant_object& changed_values, - bool broadcast = false); - - /** - * @brief Propose a fee change. - * - * @param proposing_account The account paying the fee to propose the tx - * @param expiration_time Timestamp specifying when the proposal will either take effect or expire. - * @param changed_values Map of operation type to new fee. Operations may be specified by name or ID. - * The "scale" key changes the scale. All other operations will maintain current values. - * @param broadcast true if you wish to broadcast the transaction - * @return the signed version of the transaction - * @ingroup WalletCLI - */ - signed_transaction propose_fee_change( - const string& proposing_account, - fc::time_point_sec expiration_time, - const variant_object& changed_values, - bool broadcast = false); +#include "general.hpp" +#include "wallet_file.hpp" +#include "account.hpp" +#include "assets.hpp" +#include "transaction_builder.hpp" +#include "mining.hpp" +#include "seeding.hpp" +#include "proposals.hpp" +#include "content.hpp" +#include "subscription.hpp" +#include "messaging.hpp" - /** - * - * - * - * @brief Approve or disapprove a proposal. - * - * @param fee_paying_account The account paying the fee for the op. - * @param proposal_id The proposal to modify. - * @param delta Members contain approvals to create or remove. In JSON you can leave empty members undefined. - * @param broadcast true if you wish to broadcast the transaction - * @return the signed version of the transaction - * @ingroup WalletCLI - */ - signed_transaction approve_proposal( - const string& fee_paying_account, - const string& proposal_id, - const approval_delta& delta, - bool broadcast /* = false */ - ); +#if 0 /** * * @param creator @@ -1438,28 +298,7 @@ namespace graphene { namespace wallet { * @ingroup WalletCLI */ void dbg_update_object( fc::variant_object update ); - - /** - * - * @param prefix - * @param number_of_transactions - * @ingroup WalletCLI - */ - void flood_network(string prefix, uint32_t number_of_transactions); - - /** - * - * @param nodes - * @ingroup WalletCLI - */ - void network_add_nodes( const vector& nodes ); - - /** - * - * @ingroup WalletCLI - */ - vector< variant > network_get_connected_peers(); - +#endif std::map> get_result_formatters() const; @@ -1467,597 +306,9 @@ namespace graphene { namespace wallet { std::shared_ptr my; void encrypt_keys(); - /** - * Get current supply of the core asset - * @ingroup WalletCLI - */ - real_supply get_real_supply()const; - - /** - * @brief This method is used to promote account to publishing manager. - * Such an account can grant or remove right to publish a content. Only DECENT account has permission to use this method. - * @see set_publishing_right() - * @param from Account ( DECENT account ) giving/removing status of the publishing manager. - * @param to List of accounts getting status of the publishing manager. - * @param is_allowed True to give the status, false to remove it - * @param broadcast True to broadcast the transaction on the network - * @return The signed transaction updating account status - * @ingroup WalletCLI - */ - signed_transaction set_publishing_manager(const string from, - const vector to, - bool is_allowed, - bool broadcast); - - /** - * @brief Allows account to publish a content. Only account with publishing manager status has permission to use this method. - * @see set_publishing_manager() - * @param from Account giving/removing right to publish a content. - * @param to List of accounts getting right to publish a content. - * @param is_allowed True to give the right, false to remove it - * @param broadcast True to broadcast the transaction on the network - * @return The signed transaction updating account status - * @ingroup WalletCLI - */ - signed_transaction set_publishing_right(const string from, - const vector to, - bool is_allowed, - bool broadcast); - - /** - * @brief Get a list of accounts holding publishing manager status. - * @param lower_bound_name The name of the first account to return. If the named account does not exist, - * the list will start at the account that comes after \c lowerbound - * @param limit The maximum number of accounts to return (max: 100) - * @return List of accounts - * @ingroup WalletCLI - */ - vector list_publishing_managers( const string& lower_bound_name, uint32_t limit ); - - /** - * @brief Submits or resubmits content to the blockchain. In a case of resubmit, co-authors, price and synopsis fields - * can be modified. - * @see submit_content_new() - * @param author The author of the content - * @param co_authors The co-authors' account name or ID mapped to corresponding payment split based on basis points - * @param URI The URI of the content - * @param price_amounts The price of the content per regions - * @param size The size of the content - * @param hash The Hash of the package - * @param seeders List of the seeders, which will publish the content - * @param quorum Defines number of seeders needed to restore the encryption key - * @param expiration The expiration time of the content. The content is available to buy till it's expiration time - * @param publishing_fee_asset Ticker symbol of the asset which will be used to publish content - * @param publishing_fee_amount Publishing price - * @param synopsis The description of the content - * @param secret The AES key used to encrypt and decrypt the content - * @param cd Custody data - * @param broadcast true to broadcast the transaction on the network - * @return The signed transaction submitting the content - * @ingroup WalletCLI - */ - signed_transaction - submit_content(string const& author, - vector< pair< string, uint32_t>> co_authors, - string const& URI, - vector const& price_amounts, - uint64_t size, - fc::ripemd160 const& hash, - vector const& seeders, - uint32_t quorum, - fc::time_point_sec const& expiration, - string const& publishing_fee_asset, - string const& publishing_fee_amount, - string const& synopsis, - DInteger const& secret, - decent::encrypt::CustodyData const& cd, - bool broadcast); - - /** - * @brief This function is used to create package, upload package and submit content in one step. - * @see create_package() - * @see upload_package() - * @see submit_content() - * @param author The author of the content - * @param co_authors The co-authors' account name or ID mapped to corresponding payment split based on basis points - * @param content_dir Path to the directory containing all content that should be packed - * @param samples_dir Path to the directory containing samples of content - * @param protocol Protocol for uploading package( ipfs ) - * @param price_amounts The prices of the content per regions - * @param seeders List of the seeders, which will publish the content - * @param expiration The expiration time of the content. The content is available to buy till it's expiration time - * @param synopsis The description of the content - * @return The signed transaction submitting the content - * @ingroup WalletCLI - */ - - void submit_content_async( string const &author, - vector< pair< string, uint32_t>> co_authors, - string const &content_dir, - string const &samples_dir, - string const &protocol, - vector const &price_amounts, - vector const &seeders, - fc::time_point_sec const &expiration, - string const &synopsis); - - - /** - * @brief This function can be used to cancel submitted content. This content is immediately not available to purchase. - * Seeders keep seeding this content in next 24 hours. - * @param author The author of the content - * @param URI The URI of the content - * @param broadcast True to broadcast the transaction on the network - * @ingroup WalletCLI - * @return signed transaction - */ - signed_transaction content_cancellation(string author, - string URI, - bool broadcast); - - /** - * @brief Downloads encrypted content specified by provided URI. - * @param consumer Consumer of the content - * @param URI The URI of the content - * @param region_code_from Two letter region code - * @param broadcast true to broadcast the transaction on the network - * @ingroup WalletCLI - */ - void download_content(string const& consumer, string const& URI, string const& region_code_from, bool broadcast = false); - - /** - * @brief Get status about particular download process specified by provided URI. - * @param consumer Consumer of the content - * @param URI The URI of the content - * @return Download status, or null if no matching download process was found - * @ingroup WalletCLI - */ - optional get_download_status(string consumer, string URI) const; - - /** - * @brief This function is used to send a request to buy a content. This request is caught by seeders. - * @param consumer Consumer of the content - * @param URI The URI of the content - * @param price_asset_name Ticker symbol of the asset which will be used to buy content - * @param price_amount The price of the content - * @param str_region_code_from Two letter region code - * @param broadcast true to broadcast the transaction on the network - * @return The signed transaction requesting buying of the content - * @ingroup WalletCLI - */ - signed_transaction request_to_buy(string consumer, - string URI, - string price_asset_name, - string price_amount, - string str_region_code_from, - bool broadcast); - - /** - * @brief This method allows user to start seeding plugin from running application - * @param account_id_type_or_name Name or ID of account controlling this seeder - * @param content_private_key El Gamal content private key - * @param seeder_private_key Private key of the account controlling this seeder - * @param free_space Allocated disk space, in MegaBytes - * @param seeding_price price per MegaByte - * @param seeding_symbol seeding price asset, e.g. DCT - * @param packages_path Packages storage path - * @param region_code Optional ISO 3166-1 alpha-2 two-letter region code - * @ingroup WalletCLI - */ - void seeding_startup( string account_id_type_or_name, - DInteger content_private_key, - string seeder_private_key, - uint64_t free_space, - uint32_t seeding_price, - string seeding_symbol, - string packages_path, - string region_code = "" ); - - /** - * @brief Rates and comments a content. - * @param consumer Consumer giving the rating - * @param URI The URI of the content - * @param rating Rating - * @param comment Comment - * @param broadcast true to broadcast the transaction on the network - * @ingroup WalletCLI - */ - void leave_rating_and_comment(string consumer, - string URI, - uint64_t rating, - string comment, - bool broadcast = false); - - /** - * @brief Creates a subscription to author. This function is used by consumers. - * @param from Account who wants subscription to author - * @param to The author you wish to subscribe to - * @param price_amount Price for the subscription - * @param price_asset_symbol Ticker symbol of the asset which will be used to buy subscription ( must be DCT token ) - * @param broadcast True if you wish to broadcast the transaction - * @return The signed transaction subscribing the consumer to the author - * @ingroup WalletCLI - */ - signed_transaction subscribe_to_author( string from, - string to, - string price_amount, - string price_asset_symbol, - bool broadcast/* = false */); - - /** - * @brief Creates a subscription to author. This function is used by author. - * @param from The account obtaining subscription from the author - * @param to The name or id of the author - * @param broadcast True if you wish to broadcast the transaction - * @return The signed transaction subscribing the consumer to the author - * @ingroup WalletCLI - */ - signed_transaction subscribe_by_author( string from, - string to, - bool broadcast/* = false */); - - /** - * @brief This function can be used to allow/disallow subscription. - * @param account The name or id of the account to update - * @param allow_subscription True if account (author) wants to allow subscription, false otherwise - * @param subscription_period Duration of subscription in days - * @param price_amount Price for subscription per one subscription period - * @param price_asset_symbol Ticker symbol of the asset which will be used to buy subscription - * @param broadcast True if you wish to broadcast the transaction - * @return The signed transaction updating the account - * @ingroup WalletCLI - */ - signed_transaction set_subscription( string account, - bool allow_subscription, - uint32_t subscription_period, - string price_amount, - string price_asset_symbol, - bool broadcast/* = false */); - - /** - * @brief This function can be used to allow/disallow automatic renewal of expired subscription. - * @param account_id_or_name The name or id of the account to update - * @param subscription_id The ID of the subscription. - * @param automatic_renewal True if account (consumer) wants to allow automatic renewal of subscription, false otherwise - * @param broadcast True if you wish to broadcast the transaction - * @return The signed transaction allowing/disallowing renewal of the subscription - * @ingroup WalletCLI - */ - signed_transaction set_automatic_renewal_of_subscription( string account_id_or_name, - subscription_id_type subscription_id, - bool automatic_renewal, - bool broadcast/* = false */); - - /** - * @brief Get a list of consumer's active (not expired) subscriptions. - * @param account_id_or_name The name or id of the consumer - * @param count Maximum number of subscriptions to fetch (must not exceed 100) - * @return List of active subscription objects corresponding to the provided consumer - * @ingroup WalletCLI - */ - vector< subscription_object > list_active_subscriptions_by_consumer( const string& account_id_or_name, const uint32_t count)const; - - /** - * @brief Get a list of consumer's subscriptions. - * @param account_id_or_name The name or id of the consumer - * @param count Maximum number of subscriptions to fetch (must not exceed 100) - * @return List of subscription objects corresponding to the provided consumer - * @ingroup WalletCLI - */ - vector< subscription_object > list_subscriptions_by_consumer( const string& account_id_or_name, const uint32_t count)const; - - /** - * @brief Get a list of active (not expired) subscriptions to author. - * @param account_id_or_name The name or id of the author - * @param count Maximum number of subscriptions to fetch (must not exceed 100) - * @return List of active subscription objects corresponding to the provided author - * @ingroup WalletCLI - */ - vector< subscription_object > list_active_subscriptions_by_author( const string& account_id_or_name, const uint32_t count)const; - - /** - * @brief Get a list of subscriptions to author. - * @param account_id_or_name The name or id of the author - * @param count Maximum number of subscriptions to fetch (must not exceed 100) - * @return List of subscription objects corresponding to the provided author - * @ingroup WalletCLI - */ - vector< subscription_object > list_subscriptions_by_author( const string& account_id_or_name, const uint32_t count)const; - - /** - * @brief Restores AES key( used to encrypt and decrypt a content) from key particles stored in a buying object - * @param account Consumers account id or name - * @param buying The buying object containing key particles - * @return restored AES key from particles - * @ingroup WalletCLI - */ - DInteger restore_encryption_key(std::string account, buying_id_type buying); - - /** - * @brief Generates private ElGamal key and corresponding public key. - * @return Pair of ElGamal keys - * @ingroup WalletCLI - */ - el_gamal_key_pair generate_el_gamal_keys() const; - - /** - * @brief Gets unique ElGamal key pair for consumer. - * @return Pair of ElGamal keys - * @ingroup WalletCLI - */ - el_gamal_key_pair_str get_el_gammal_key(string const& consumer) const; - - - /** - * @brief Generates AES encryption key. - * @return Random encryption key - * @ingroup WalletCLI - */ - DInteger generate_encryption_key() const; - - /** - * @brief Get a list of open buyings - * @return Open buying objects - * @ingroup WalletCLI - */ - vector get_open_buyings()const; - - /** - * @brief Get a list of open buyings by URI - * @param URI URI of the buyings to retrieve - * @return Open buyings corresponding to the provided URI - * @ingroup WalletCLI - */ - vector get_open_buyings_by_URI( const string& URI )const; - - /** - * @brief Get a list of open buyings by consumer - * @param account_id_or_name Consumer of the buyings to retrieve - * @return Open buyings corresponding to the provided consumer - * @ingroup WalletCLI - */ - vector get_open_buyings_by_consumer( const string& account_id_or_name )const; - - /** - * @brief Get history buyings by consumer - * @param account_id_or_name Consumer of the buyings to retrieve - * @return History buying objects corresponding to the provided consumer - * @ingroup WalletCLI - */ - vector get_buying_history_objects_by_consumer( const string& account_id_or_name )const; - - /** - * @brief Get history buying objects by consumer that match search term - * @param account_id_or_name Consumer of the buyings to retrieve - * @param term Search term to look up in Title and Description - * @param order Sort data by field - * @param id Object_id to start searching from - * @param count Maximum number of contents to fetch (must not exceed 100) - * @return History buying objects corresponding to the provided consumer and matching search term - * @ingroup WalletCLI - */ - vector search_my_purchases(const string& account_id_or_name, - const string& term, - const string& order, - const string& id, - uint32_t count) const; - - /** - * @brief Get buying (open or history) by consumer and URI - * @param account_id_or_name Consumer of the buying to retrieve - * @param URI URI of the buying to retrieve - * @return Buying_objects corresponding to the provided consumer, or null if no matching buying was found - * @ingroup WalletCLI - */ - optional get_buying_by_consumer_URI( const string& account_id_or_name, const string & URI )const; - - /** - * @brief Search for term in contents (author, title and description) - * @param user Feedback author - * @param URI The content object URI - * @param id The id of feedback object to start searching from - * @param count Maximum number of feedbacks to fetch - * @return The feedback found - * @ingroup WalletCLI - */ - vector search_feedback(const string& user, - const string& URI, - const string& id, - uint32_t count) const; - - /** - * @brief Get a content by URI - * @param URI URI of the content to retrieve - * @return The content corresponding to the provided URI, or null if no matching content was found - * @ingroup WalletCLI - */ - optional get_content( const string& URI )const; - - /** - * @brief Get a list of contents ordered alphabetically by search term - * @param term Search term - * @param order Order field - * @param user Content owner - * @param region_code Two letter region code - * @param id The id of content object to start searching from - * @param type The application and content type to be filtered - * @param count Maximum number of contents to fetch (must not exceed 100) - * @return The contents found - * @ingroup WalletCLI - */ - vector search_content(const string& term, - const string& order, - const string& user, - const string& region_code, - const string& id, - const string& type, - uint32_t count )const; - /** - * @brief Get a list of contents ordered alphabetically by search term - * @param user Content owner - * @param term Search term - * @param order Order field - * @param region_code Two letter region code - * @param id The id of content object to start searching from - * @param type The application and content type to be filtered - * @param count Maximum number of contents to fetch (must not exceed 100) - * @return The contents found - * @ingroup WalletCLI - */ - vector search_user_content(const string& user, - const string& term, - const string& order, - const string& region_code, - const string& id, - const string& type, - uint32_t count )const; - - /** - * @brief Get a list of seeders by price, in increasing order - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup WalletCLI - */ - vector list_seeders_by_price( uint32_t count )const; - - /** - * @brief Get a list of seeders ordered by total upload, in decreasing order - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup WalletCLI - */ - optional> list_seeders_by_upload( const uint32_t count )const; - - /** - * @brief Get a list of seeders by region code - * @param region_code Region code of seeders to retrieve - * @return The seeders found - * @ingroup WalletCLI - */ - vector list_seeders_by_region( const string region_code )const; - - /** - * @brief Get a list of seeders ordered by rating, in decreasing order - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup WalletCLI - */ - vector list_seeders_by_rating( const uint32_t count )const; - - /** - * @brief Get author and list of co-authors of a content corresponding to the provided URI - * @param URI URI of the content - * @return The autor of the content and the list of co-authors, if provided - */ - pair> get_author_and_co_authors_by_URI( const string& URI )const; - - /** - * @brief Create package from selected files - * @param content_dir Directory containing all content that should be packed - * @param samples_dir Directory containing samples of content - * @param aes_key AES key for encryption - * @return package hash (ripemd160 hash of package content) and content custody data - * @ingroup WalletCLI - */ - std::pair create_package(const std::string& content_dir, const std::string& samples_dir, const DInteger& aes_key) const; - - - /** - * @brief Extract selected package - * @param package_hash Hash of package that needs to be extracted - * @param output_dir Directory where extracted files will be created - * @param aes_key AES key for decryption - * @ingroup WalletCLI - */ - void extract_package(const std::string& package_hash, const std::string& output_dir, const DInteger& aes_key) const; - - /** - * @brief Download package - * @param url Magnet or IPFS URL of package - * @ingroup WalletCLI - */ - void download_package(const std::string& url) const; - - /** - * @brief Start uploading package - * @param package_hash Hash of package that needs to be extracted - * @param protocol protocol for uploading package ( ipfs ) - * @ingroup WalletCLI - */ - std::string upload_package(const std::string& package_hash, const std::string& protocol) const; - - /** - * @brief Remove package - * @param package_hash Hash of package that needs to be removed - * @ingroup WalletCLI - */ - void remove_package(const std::string& package_hash) const; - - /** - * @brief Print statuses of all active transfers - * @ingroup WalletCLI - */ - - void set_transfer_logs(bool enable) const; - - /** - * @brief Sign a buffer - * @param str_buffer The buffer to be signed - * @param str_brainkey Derives the private key used for signature - * @return The signed buffer - * @ingroup WalletCLI - */ - std::string sign_buffer(std::string const& str_buffer, - std::string const& str_brainkey) const; - - /** - * @brief Verify if the signature is valid - * @param str_buffer The original buffer - * @param str_publickey The public key used for verification - * @param str_signature The signed buffer - * @return true if valid, otherwise false - * @ingroup WalletCLI - */ - bool verify_signature(std::string const& str_buffer, - std::string const& str_publickey, - std::string const& str_signature) const; - - /** - * @brief Query the last local block - * @return the block time - */ - fc::time_point_sec head_block_time() const; - - /** - * @brief Send text message - */ - - void send_message(const std::string& from, std::vector to, string text); - /** - * @brief Receives message objects by sender and/or receiver - * @param reveiver Name of message sender. If you dont want to filter by sender then let it empty. - * @param reveiver Name of message receiver. If you dont want to filter by receiver then let it empty. - * @param max_count Maximal number of last messages to be displayed - * @return vector of message objects - */ - vector get_message_objects(const std::string& sender, const std::string& receiver, uint32_t max_count) const; - /** - * @brief Receives messages by receiver - * @param reveiver Name of message receiver which must be imported to caller's wallet - * @param max_count Maximal number of last messages to be displayed - * @return vector of message objects - */ - vector get_messages(const std::string& receiver, uint32_t max_count) const; - /** - * @brief Receives sent messages by sender - * @param sender Name of message sender which must be imported to caller's wallet - * @param max_count Maximal number of last messages to be displayed - * @return vector of message objects - */ - vector get_sent_messages(const std::string& sender, uint32_t max_count) const; }; } } @@ -2135,142 +386,164 @@ FC_REFLECT( graphene::wallet::operation_detail, (memo)(description)(op) ) FC_API( graphene::wallet::wallet_api, - (help) - (gethelp) - (info) - (about) - (begin_builder_transaction) - (add_operation_to_builder_transaction) - (replace_operation_in_builder_transaction) - (set_fees_on_builder_transaction) - (preview_builder_transaction) - (sign_builder_transaction) - (propose_builder_transaction) - (propose_builder_transaction2) - (remove_builder_transaction) - (is_new) - (is_locked) - (lock)(unlock)(set_password) - (dump_private_keys) - (list_my_accounts) - (list_accounts) - (search_accounts) - (list_account_balances) - (list_assets) - (import_key) - (import_accounts) - (import_account_keys) - (suggest_brain_key) - (generate_brain_key_el_gamal_key) - (get_brain_key_info) - (register_account) - (create_account_with_brain_key) - (create_account_with_brain_key_noimport) - (transfer) - (transfer2) - (propose_transfer) - (get_transaction_id) - (create_monitored_asset) - (update_monitored_asset) - (publish_asset_feed) - (get_feeds_by_miner) - (create_user_issued_asset) - (update_user_issued_asset) - (issue_asset) - (fund_asset_pools) - (reserve_asset) - (claim_fees) - (price_to_dct) - (get_asset) - (get_monitored_asset_data) - (get_miner) - (list_miners) - (create_miner) - (update_miner) - (get_vesting_balances) - (withdraw_vesting) - (vote_for_miner) - (set_voting_proxy) - (set_desired_miner_count) - (get_account) - (get_account_id) - (get_block) - (get_account_count) - (get_account_history) - (get_relative_account_history) - (search_account_history) - (get_global_properties) - (get_dynamic_global_properties) - (get_object) - (get_private_key) - (load_wallet_file) - (normalize_brain_key) - (save_wallet_file) - (serialize_transaction) - (sign_transaction) - (get_prototype_operation) - (propose_parameter_change) - (propose_fee_change) - (approve_proposal) - (dbg_make_mia) - (dbg_push_blocks) - (dbg_generate_blocks) - (dbg_stream_json_objects) - (dbg_update_object) - (flood_network) - (network_add_nodes) - (network_get_connected_peers) - (download_content) - (get_download_status) - (set_publishing_manager) - (set_publishing_right) - (list_publishing_managers) - (submit_content) - (submit_content_async) - (content_cancellation) - (request_to_buy) - (leave_rating_and_comment) - (seeding_startup) - (restore_encryption_key) - (generate_encryption_key) - (generate_el_gamal_keys) - (get_el_gammal_key) - (subscribe_to_author) - (subscribe_by_author) - (set_subscription) - (set_automatic_renewal_of_subscription) - (list_active_subscriptions_by_consumer) - (list_subscriptions_by_consumer) - (list_active_subscriptions_by_author) - (list_subscriptions_by_author) - (get_open_buyings) - (get_open_buyings_by_URI) - (get_open_buyings_by_consumer) - (get_buying_history_objects_by_consumer) - (search_my_purchases) - (get_buying_by_consumer_URI) - (search_feedback) - (get_content) - (get_real_supply) - (search_content) - (search_user_content) - (list_seeders_by_price) - (list_seeders_by_upload) - (list_seeders_by_region) - (list_seeders_by_rating) - (get_author_and_co_authors_by_URI) - (create_package) - (extract_package) - (download_package) - (upload_package) - (remove_package) - (set_transfer_logs) - (sign_buffer) - (verify_signature) - (head_block_time) - (get_proposed_transactions) - (send_message) - (get_message_objects) - (get_messages) - (get_sent_messages) + //General + (about) + (get_block) + (get_global_properties) + (get_dynamic_global_properties) + (get_object) + (info) + (help) + (gethelp) + (head_block_time) + (network_add_nodes) + (network_get_connected_peers) + + //Wallet file + (list_my_accounts) + (get_private_key) + (is_new) + (is_locked) + (lock)(unlock)(set_password) + (load_wallet_file) + (save_wallet_file) + (import_key) + (import_accounts) //obsolete + (import_account_keys) //obsolete + (dump_private_keys) + + //Account + (get_account_count) + (list_accounts) + (search_accounts) + (list_account_balances) + (search_account_history) + (get_account_history) + (get_relative_account_history) + (get_account) +// (get_account_id) //obsolete + (suggest_brain_key) + (register_account) + (create_account_with_brain_key) +// (create_account_with_brain_key_noimport) + (transfer) + (generate_el_gamal_keys) + (get_el_gammal_key) + (generate_brain_key_el_gamal_key) + (get_brain_key_info) + + //Assets + (list_assets) + (get_asset) + (get_monitored_asset_data) + (create_monitored_asset) + (update_monitored_asset) + (create_user_issued_asset) + (update_user_issued_asset) + (issue_asset) + (fund_asset_pools) + (reserve_asset) + (claim_fees) + (price_to_dct) + (publish_asset_feed) + (get_feeds_by_miner) + (get_real_supply) + + //Transaction builder + (begin_builder_transaction) + (add_operation_to_builder_transaction) + (replace_operation_in_builder_transaction) + (set_fees_on_builder_transaction) + (preview_builder_transaction) + (sign_builder_transaction) + (propose_builder_transaction) + (propose_builder_transaction2) + (remove_builder_transaction) + (serialize_transaction) + (sign_transaction) + (get_prototype_operation) + + //Mining + (list_miners) + (get_miner) + (create_miner) + (update_miner) + (get_vesting_balances) + (withdraw_vesting) + (vote_for_miner) + (set_voting_proxy) + (set_desired_miner_count) + + //Seeding + (list_seeders_by_price) + (list_seeders_by_upload) + (list_seeders_by_region) + (list_seeders_by_rating) + + //Proposals + (get_proposed_transactions) + (propose_transfer) + (propose_parameter_change) + (propose_fee_change) + (approve_proposal) + + //Content + (submit_content) + (submit_content_async) + (content_cancellation) + (download_content) + (get_download_status) + (request_to_buy) + (leave_rating_and_comment) + (seeding_startup) + (restore_encryption_key) + (generate_encryption_key) + (get_open_buyings) + (get_open_buyings_by_URI) + (get_open_buyings_by_consumer) + (get_buying_history_objects_by_consumer) + (search_my_purchases) + (get_buying_by_consumer_URI) + (search_feedback) + (get_content) + (search_content) + (search_user_content) + (get_author_and_co_authors_by_URI) + (create_package) + (extract_package) + (download_package) + (upload_package) + (remove_package) + + //Subsctiption + (subscribe_to_author) + (subscribe_by_author) + (set_subscription) + (set_automatic_renewal_of_subscription) + (list_active_subscriptions_by_consumer) + (list_subscriptions_by_consumer) + (list_active_subscriptions_by_author) + (list_subscriptions_by_author) + + //Messaging + (send_message) + (get_message_objects) + (get_messages) + (get_sent_messages) +#if 0 + //Debug + (dbg_make_mia) + (dbg_push_blocks) + (dbg_generate_blocks) + (dbg_stream_json_objects) + (dbg_update_object) + (set_transfer_logs) + (sign_buffer) + (verify_signature) + + //Network + (flood_network) +#endif + + ) diff --git a/libraries/wallet/include/graphene/wallet/wallet_file.hpp b/libraries/wallet/include/graphene/wallet/wallet_file.hpp new file mode 100644 index 00000000..731dc96c --- /dev/null +++ b/libraries/wallet/include/graphene/wallet/wallet_file.hpp @@ -0,0 +1,180 @@ +#ifndef DECENT_WALLET_WALLET_FILE_H +#define DECENT_WALLET_WALLET_FILE_H + +/** + * @brief Copy wallet file to a new file + * @param destination_filename + * @return true if the wallet is copied, false otherwise + * @ingroup WalletCLI + */ +bool copy_wallet_file( string destination_filename ); //obsolete + +/** + * @brief Lists all accounts controlled by this wallet. + * This returns a list of the full account objects for all accounts whose private keys + * we possess. + * @returns a list of account objects + * @ingroup WalletCLI + */ +vector list_my_accounts(); + +/** + * @brief Returns the current wallet filename. + * + * This is the filename that will be used when automatically saving the wallet. + * + * @see set_wallet_filename() + * @return the wallet filename + * @ingroup WalletCLI + */ +string get_wallet_filename() const; + +/** + * @brief Get the WIF private key corresponding to a public key. The + * private key must already be in the wallet. + * @param pubkey Public key + * @return WIF private key corresponding to a public key + * @ingroup WalletCLI + */ +string get_private_key( public_key_type pubkey )const; + +/** + * @brief Checks whether the wallet has just been created and has not yet had a password set. + * + * Calling \c set_password will transition the wallet to the locked state. + * @return true if the wallet is new + * @ingroup Wallet Management + * @ingroup WalletCLI + */ +bool is_new()const; + +/** + * @brief Checks whether the wallet is locked (is unable to use its private keys). + * + * This state can be changed by calling \c lock() or \c unlock(). + * @return true if the wallet is locked + * @ingroup Wallet Management + * @ingroup WalletCLI + */ +bool is_locked()const; + +/** + * @brief Locks the wallet immediately. + * @ingroup Wallet Management + * @ingroup WalletCLI + */ +void lock(); + +/** + * @brief Unlocks the wallet. + * + * The wallet remain unlocked until the \c lock is called + * or the program exits. + * @param password the password previously set with \c set_password() + * @ingroup Wallet Management + * @ingroup WalletCLI + */ +void unlock(string password); + +/** + * @brief Sets a new password on the wallet. + * + * The wallet must be either 'new' or 'unlocked' to + * execute this command. + * @param password + * @ingroup Wallet Management + * @ingroup WalletCLI + */ +void set_password(string password); + +/** + * @brief Loads a specified Graphene wallet. + * + * The current wallet is closed before the new wallet is loaded. + * + * @warning This does not change the filename that will be used for future + * wallet writes, so this may cause you to overwrite your original + * wallet unless you also call \c set_wallet_filename() + * + * @param wallet_filename the filename of the wallet JSON file to load. + * If \c wallet_filename is empty, it reloads the + * existing wallet file + * @returns true if the specified wallet is loaded + * @ingroup WalletCLI + */ +bool load_wallet_file(string wallet_filename = ""); + +/** + * @brief Saves the current wallet to the given filename. + * + * @warning This does not change the wallet filename that will be used for future + * writes, so think of this function as 'Save a Copy As...' instead of + * 'Save As...'. Use \c set_wallet_filename() to make the filename + * persist. + * @param wallet_filename the filename of the new wallet JSON file to create + * or overwrite. If \c wallet_filename is empty, + * save to the current filename. + * @ingroup WalletCLI + */ +void save_wallet_file(string wallet_filename = ""); + +/** + * @brief Sets the wallet filename used for future writes. + * + * This does not trigger a save, it only changes the default filename + * that will be used the next time a save is triggered. + * + * @param wallet_filename the new filename to use for future saves + * @ingroup WalletCLI + */ +void set_wallet_filename(string wallet_filename); + + + +/** + * @brief Imports the private key for an existing account. + * + * The private key must match either an owner key or an active key for the + * named account. + * + * @see dump_private_keys() + * + * @param account_name_or_id the account owning the key + * @param wif_key the private key in WIF format + * @returns true if the key was imported + * @ingroup WalletCLI + */ +bool import_key(string account_name_or_id, string wif_key); + +/** + * @brief Imports accounts from the other wallet file + * @param filename The filename of the wallet JSON file + * @param password User's password to the wallet + * @return mapped account names to boolean values indicating whether the account was successfully imported + * @ingroup WalletCLI + */ +map import_accounts( string filename, string password ); //obsolete + +/** + * @brief Imports account keys from particular account from another wallet file to desired account located in wallet file currently used + * @param filename The filename of the wallet JSON file + * @param password User's password to the wallet + * @param src_account_name Name of the source account + * @param dest_account_name Name of the destination account + * @return true if the keys were imported + * @ingroup WalletCLI + */ +bool import_account_keys( string filename, string password, string src_account_name, string dest_account_name ); //obsolete + +/** + * @brief Dumps all private keys owned by the wallet. + * + * The keys are printed in WIF format. You can import these keys into another wallet + * using \c import_key() + * @returns a map containing the private keys, indexed by their public key + * @ingroup WalletCLI + */ +map dump_private_keys(); + + +#endif //DECENT_WALLET_FILE_H diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 104073dd..b86a8505 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -507,39 +507,6 @@ class wallet_api_impl fc::async([this]{resync();}, "Resync after block"); } - bool copy_wallet_file( string destination_filename ) - { - fc::path src_path = get_wallet_filename(); - if( !fc::exists( src_path ) ) - return false; - fc::path dest_path = destination_filename + _wallet_filename_extension; - int suffix = 0; - while( fc::exists(dest_path) ) - { - ++suffix; - dest_path = destination_filename + "-" + to_string( suffix ) + _wallet_filename_extension; - } - wlog( "backing up wallet ${src} to ${dest}", - ("src", src_path) - ("dest", dest_path) ); - - fc::path dest_parent = fc::absolute(dest_path).parent_path(); - try - { - enable_umask_protection(); - if( !fc::exists( dest_parent ) ) - fc::create_directories( dest_parent ); - fc::copy( src_path, dest_path ); - disable_umask_protection(); - } - catch(...) - { - disable_umask_protection(); - throw; - } - return true; - } - bool is_locked()const { return _checksum == fc::sha512(); @@ -658,10 +625,6 @@ class wallet_api_impl return *rec; } } - account_id_type get_account_id(string account_name_or_id) const - { - return get_account(account_name_or_id).get_id(); - } optional find_asset(asset_id_type id)const { auto rec = _remote_db->get_assets({id}).front(); @@ -1414,7 +1377,7 @@ class wallet_api_impl FC_THROW("No asset with that symbol exists!"); asset_publish_feed_operation publish_op; - publish_op.publisher = get_account_id(publishing_account); + publish_op.publisher = get_account(publishing_account).get_id(); publish_op.asset_id = asset_to_update->id; publish_op.feed = feed; @@ -1446,7 +1409,7 @@ class wallet_api_impl // then maybe it's the owner account try { - account_id_type owner_account_id = get_account_id(owner_account); + account_id_type owner_account_id = get_account(owner_account).get_id(); fc::optional miner = _remote_db->get_miner_by_account(owner_account_id); if (miner) return *miner; @@ -1580,7 +1543,7 @@ class wallet_api_impl bool broadcast /* = false */) { try { account_object voting_account_object = get_account(voting_account); - account_id_type miner_owner_account_id = get_account_id(miner); + account_id_type miner_owner_account_id = get_account(miner).get_id(); fc::optional miner_obj = _remote_db->get_miner_by_account(miner_owner_account_id); if (!miner_obj) FC_THROW("Account ${miner} is not registered as a miner", ("miner", miner)); @@ -1615,7 +1578,7 @@ class wallet_api_impl account_object account_object_to_modify = get_account(account_to_modify); if (voting_account) { - account_id_type new_voting_account_id = get_account_id(*voting_account); + account_id_type new_voting_account_id = get_account(*voting_account).get_id(); if (account_object_to_modify.options.voting_account == new_voting_account_id) FC_THROW("Voting proxy for ${account} is already set to ${voter}", ("account", account_to_modify)("voter", *voting_account)); account_object_to_modify.options.voting_account = new_voting_account_id; @@ -1810,7 +1773,7 @@ class wallet_api_impl account_object from_account = get_account(from); account_object to_account = get_account(to); account_id_type from_id = from_account.id; - account_id_type to_id = get_account_id(to); + account_id_type to_id = get_account(to).get_id(); transfer_operation xfer_op; @@ -2141,12 +2104,12 @@ class wallet_api_impl { FC_ASSERT( !to.empty() ); set_publishing_manager_operation spm_op; - spm_op.from = get_account_id( from ); + spm_op.from = get_account( from ).get_id(); spm_op.can_create_publishers = is_allowed; for( const auto& element : to ) { - spm_op.to.push_back( get_account_id( element ) ); + spm_op.to.push_back( get_account( element ).get_id() ); } signed_transaction tx; @@ -2167,12 +2130,12 @@ class wallet_api_impl FC_ASSERT( !to.empty() ); set_publishing_right_operation spr_op; - spr_op.from = get_account_id( from ); + spr_op.from = get_account( from ).get_id(); spr_op.is_publisher = is_allowed; for( const auto& element : to ) { - spr_op.to.push_back( get_account_id( element ) ); + spr_op.to.push_back( get_account( element ).get_id() ); } signed_transaction tx; @@ -2229,14 +2192,14 @@ class wallet_api_impl try { FC_ASSERT(!is_locked()); - account_id_type author_account = get_account_id( author ); + account_id_type author_account = get_account( author ).get_id(); map co_authors_id_to_split; if( !co_authors.empty() ) { for( auto const& element : co_authors ) { - account_id_type co_author = get_account_id( element.first ); + account_id_type co_author = get_account( element.first ).get_id(); co_authors_id_to_split[ co_author ] = element.second; } } @@ -2303,7 +2266,7 @@ class wallet_api_impl { for( auto const &element : co_authors ) { - account_id_type co_author = get_account_id( element.first ); + account_id_type co_author = get_account( element.first ).get_id(); co_authors_id_to_split[ co_author ] = element.second; } } @@ -2382,7 +2345,7 @@ signed_transaction content_cancellation(string author, FC_ASSERT(!is_locked()); content_cancellation_operation cc_op; - cc_op.author = get_account_id( author ); + cc_op.author = get_account( author ).get_id(); cc_op.URI = URI; signed_transaction tx; @@ -2577,7 +2540,7 @@ signed_transaction content_cancellation(string author, string packages_path, string region_code) { - account_id_type seeder = get_account_id( account_id_type_or_name ); + account_id_type seeder = get_account( account_id_type_or_name ).get_id(); use_network_node_api(); fc::ecc::private_key seeder_priv_key = *(wif_to_key(seeder_private_key)); (*_remote_net_node)->seeding_startup( seeder, content_private_key, seeder_priv_key, free_space, seeding_price, seeding_symbol, packages_path, region_code); @@ -2593,8 +2556,8 @@ signed_transaction content_cancellation(string author, FC_ASSERT( asset_obj->id == asset_id_type() ); subscribe_operation subscribe_op; - subscribe_op.from = get_account_id( from ); - subscribe_op.to = get_account_id( to ); + subscribe_op.from = get_account( from ).get_id(); + subscribe_op.to = get_account( to ).get_id(); subscribe_op.price = asset_obj->amount_from_string(price_amount); signed_transaction tx; @@ -2610,8 +2573,8 @@ signed_transaction content_cancellation(string author, bool broadcast/* = false */) { try { subscribe_by_author_operation subscribe_op; - subscribe_op.from = get_account_id( from ); - subscribe_op.to = get_account_id( to ); + subscribe_op.from = get_account( from ).get_id(); + subscribe_op.to = get_account( to ).get_id(); signed_transaction tx; tx.operations.push_back( subscribe_op ); @@ -2655,7 +2618,7 @@ signed_transaction content_cancellation(string author, { try { - account_id_type account = get_account_id( account_id_or_name ); + account_id_type account = get_account( account_id_or_name ).get_id(); fc::optional subscription_obj = _remote_db->get_subscription(subscription_id); FC_ASSERT(subscription_obj, "Could not find subscription matching ${subscription}", ("subscription", subscription_id)); @@ -2767,7 +2730,7 @@ signed_transaction content_cancellation(string author, { FC_ASSERT(!is_locked()); const auto& mapi = _remote_api->messaging(); - const auto& receiver_id = get_account_id(receiver); + const auto& receiver_id = get_account(receiver).get_id(); auto itr = _wallet.my_accounts.get().find(receiver_id); if (itr == _wallet.my_accounts.get().end()) return vector(); @@ -2797,7 +2760,7 @@ signed_transaction content_cancellation(string author, { FC_ASSERT(!is_locked()); const auto& mapi = _remote_api->messaging(); - const auto& sender_id = get_account_id(sender); + const auto& sender_id = get_account(sender).get_id(); auto itr = _wallet.my_accounts.get().find(sender_id); if (itr == _wallet.my_accounts.get().end()) return vector(); @@ -2838,7 +2801,7 @@ signed_transaction content_cancellation(string author, for (auto& receiver : to) { account_object to_account = get_account(receiver); message_payload_receivers_data receivers_data_item; - receivers_data_item.to = get_account_id(receiver); + receivers_data_item.to = get_account(receiver).get_id(); if (text.size()) { pl.set_message(get_private_key(from_account.options.memo_key), @@ -3421,11 +3384,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati { } - bool wallet_api::copy_wallet_file(string destination_filename) - { - return my->copy_wallet_file(destination_filename); - } - optional wallet_api::get_block(uint32_t num) { optional result = my->_remote_db->get_block(num); @@ -3519,7 +3477,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati uint32_t start)const { vector result; - auto account_id = get_account_id(name); + auto account_id = get_account(name).get_id(); vector current = my->_remote_hist->get_relative_account_history(account_id, stop, limit, start); for( auto& o : current ) { @@ -3593,7 +3551,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati brain_key += graphene::words::word_list[ choice.to_int64() ]; } - brain_key = normalize_brain_key(brain_key); + brain_key = detail::normalize_brain_key(brain_key); fc::ecc::private_key priv_key = derive_private_key( brain_key, 0 ); result.brain_priv_key = brain_key; result.wif_priv_key = key_to_wif( priv_key ); @@ -3618,7 +3576,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati { brain_key_info result; - string str_brain_key = normalize_brain_key(brain_key); + string str_brain_key = detail::normalize_brain_key(brain_key); fc::ecc::private_key priv_key = derive_private_key( str_brain_key, 0 ); result.brain_priv_key = str_brain_key; result.wif_priv_key = key_to_wif( priv_key ); @@ -3679,7 +3637,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati vector wallet_api::get_proposed_transactions( string account_or_id )const { - account_id_type id = get_account_id(account_or_id); + account_id_type id = get_account(account_or_id).get_id(); return my->_remote_db->get_proposed_transactions( id ); } @@ -3736,11 +3694,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return *asset.monitored_asset_opts; } - account_id_type wallet_api::get_account_id(string account_name_or_id) const - { - return my->get_account_id(account_name_or_id); - } - asset_id_type wallet_api::get_asset_id(string asset_symbol_or_id) const { return my->get_asset_id(asset_symbol_or_id); @@ -3882,11 +3835,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return false; } - string wallet_api::normalize_brain_key(string s) const - { - return detail::normalize_brain_key( s ); - } - variant wallet_api::info() { return my->info(); @@ -3922,18 +3870,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati ); } - signed_transaction wallet_api::create_account_with_brain_key_noimport(string brain_key, - string account_name, - string registrar_account, - bool broadcast /* = false */) - { - return my->create_account_with_brain_key( - brain_key, account_name, registrar_account, false, - broadcast - ); - } - - signed_transaction wallet_api::transfer(string from, string to, string amount, string asset_symbol, string memo, bool broadcast /* = false */) { @@ -4120,6 +4056,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return my->get_prototype_operation( operation_name ); } +#if 0 void wallet_api::dbg_make_mia(string creator, string symbol) { FC_ASSERT(!is_locked()); @@ -4145,6 +4082,8 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati { my->dbg_update_object( update ); } +#endif + void wallet_api::network_add_nodes( const vector& nodes ) { @@ -4156,12 +4095,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return my->network_get_connected_peers(); } - void wallet_api::flood_network(string prefix, uint32_t number_of_transactions) - { - FC_ASSERT(!is_locked()); - my->flood_network(prefix, number_of_transactions); - } - signed_transaction wallet_api::propose_parameter_change( const string& proposing_account, fc::time_point_sec expiration_time, @@ -4371,27 +4304,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return my->_remote_db->get_real_supply(); } - signed_transaction wallet_api::set_publishing_manager(const string from, - const vector to, - bool is_allowed, - bool broadcast ) - { - return my->set_publishing_manager( from, to, is_allowed, broadcast ); - } - - signed_transaction wallet_api::set_publishing_right(const string from, - const vector to, - bool is_allowed, - bool broadcast ) - { - return my->set_publishing_right( from, to, is_allowed, broadcast ); - } - - vector wallet_api::list_publishing_managers( const string& lower_bound_name, uint32_t limit ) - { - return my->_remote_db->list_publishing_managers( lower_bound_name, limit ); - } - signed_transaction wallet_api::submit_content(string const& author, vector< pair< string, uint32_t>> co_authors, @@ -4739,7 +4651,7 @@ pair> wallet_api::get_author_and_co_aut str_brainkey.empty()) throw std::runtime_error("You need buffer and brainkey to sign"); - string normalized_brain_key = normalize_brain_key( str_brainkey ); + string normalized_brain_key = detail::normalize_brain_key( str_brainkey ); fc::ecc::private_key privkey = derive_private_key( normalized_brain_key, 0 ); fc::sha256 digest(str_buffer); @@ -4762,7 +4674,7 @@ pair> wallet_api::get_author_and_co_aut return res; } FC_CAPTURE_AND_RETHROW( (consumer) ) } - + bool wallet_api::verify_signature(std::string const& str_buffer, std::string const& str_publickey, std::string const& str_signature) const @@ -4882,11 +4794,6 @@ void graphene::wallet::detail::submit_transfer_listener::package_seed_complete() return package->get_url(); } - - void wallet_api::set_transfer_logs(bool enable) const { - // FC_ASSERT(!is_locked()); - } - void wallet_api::send_message(const std::string& from, std::vector to, string text) { return my->send_message(from, to, text); @@ -4896,10 +4803,10 @@ void graphene::wallet::detail::submit_transfer_listener::package_seed_complete() { optional receiver_id; if(receiver.size()) - receiver_id = get_account_id(receiver); + receiver_id = get_account(receiver).get_id(); optional sender_id; if(sender.size()) - sender_id = get_account_id(sender); + sender_id = get_account(sender).get_id(); return my->get_message_objects(sender_id, receiver_id, max_count); } From f62615826acabbb21588e4dd5866fa68e05ef2fb Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Tue, 13 Feb 2018 16:23:37 +0100 Subject: [PATCH 046/136] DCT-565 and added get_running_plugins() --- libraries/app/api.cpp | 35 ++++ libraries/app/application.cpp | 11 ++ libraries/app/include/graphene/app/api.hpp | 8 + .../app/include/graphene/app/application.hpp | 1 + libraries/app/include/graphene/app/plugin.hpp | 11 ++ libraries/app/plugin.cpp | 1 + libraries/chain/db_block.cpp | 5 +- .../account_history_plugin.cpp | 1 + libraries/plugins/debug_miner/debug_miner.cpp | 2 + .../delayed_node/delayed_node_plugin.cpp | 1 + libraries/plugins/messaging/messaging.cpp | 3 +- libraries/plugins/miner/miner.cpp | 2 + .../include/graphene/seeding/seeding.hpp | 14 ++ libraries/plugins/seeding/seeding.cpp | 173 +++++++++++++++++- .../wallet/include/graphene/wallet/wallet.hpp | 23 +++ libraries/wallet/wallet.cpp | 47 +++++ 16 files changed, 332 insertions(+), 6 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index de4513f0..3e1c3aab 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include @@ -234,6 +235,40 @@ namespace graphene { namespace app { decent::seeding::seeding_promise->set_value( seeding_options ); } + std::vector network_node_api::get_running_plugins() const + { + std::vector roles; + int index = 0; + std::shared_ptr p = _app.get_plugin_by_index(index); + + while(p != nullptr) { + if(p->plugin_is_running()) + roles.push_back(p->plugin_name()); + index++; + p = _app.get_plugin_by_index(index); + } + + return roles; + } + + void network_node_api::start_content_seeding(const std::string& url) const + { + shared_ptr p = _app.get_plugin("seeding"); + FC_ASSERT(p); + bool running = p->plugin_is_running(); + FC_ASSERT(running, "Seeding plugin is not running"); + p->start_content_seeding(url); + } + + void network_node_api::stop_content_seeding(const std::string& url) const + { + shared_ptr p = _app.get_plugin("seeding"); + FC_ASSERT(p); + bool running = p->plugin_is_running(); + FC_ASSERT(running, "Seeding plugin is not running"); + p->stop_content_seeding(url); + } + fc::api login_api::network_broadcast()const { FC_ASSERT(_network_broadcast_api); diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index c815db06..767f7e3b 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -1026,6 +1026,17 @@ std::shared_ptr application::get_plugin(const string& name) con return my->_plugins[name]; } +std::shared_ptr application::get_plugin_by_index(int index) const +{ + std::map>::iterator iter; + int cur_index = 0; + for (iter = my->_plugins.begin(); iter != my->_plugins.end(); ++iter, cur_index++) { + if (cur_index == index) + return (*iter).second; + } + return nullptr; +} + net::node_ptr application::p2p_node() { return my->_p2p_network; diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 8cd88557..e4008aa1 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -254,6 +254,11 @@ namespace graphene { namespace app { const string packages_path, const string region_code = "" ); + std::vector get_running_plugins() const; + + void start_content_seeding(const std::string& url) const; + void stop_content_seeding(const std::string& url) const; + private: application& _app; }; @@ -415,6 +420,9 @@ FC_API(graphene::app::network_node_api, (get_advanced_node_parameters) (set_advanced_node_parameters) (seeding_startup) + (get_running_plugins) + (start_content_seeding) + (stop_content_seeding) ) FC_API(graphene::app::crypto_api, (blind_sign) diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index 26ae78ef..c30b52e7 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -67,6 +67,7 @@ namespace graphene { namespace app { return plug; } std::shared_ptr get_plugin( const string& name )const; + std::shared_ptr get_plugin_by_index(int index)const; template std::shared_ptr get_plugin( const string& name ) const diff --git a/libraries/app/include/graphene/app/plugin.hpp b/libraries/app/include/graphene/app/plugin.hpp index 87220744..87461d46 100644 --- a/libraries/app/include/graphene/app/plugin.hpp +++ b/libraries/app/include/graphene/app/plugin.hpp @@ -87,6 +87,15 @@ class abstract_plugin boost::program_options::options_description& command_line_options, boost::program_options::options_description& config_file_options ) = 0; + + /** + * @brief Returns plugin state. + * + * This method retruns plugin state + * @return true if plugin_startup() was finished without exceptions. It returns + * false if plugin_shutdown() was called or if plugin_startup() throws some exception. + */ + virtual bool plugin_is_running() const = 0; }; /** @@ -111,8 +120,10 @@ class plugin : public abstract_plugin chain::database& database() { return *app().chain_database(); } application& app()const { assert(_app); return *_app; } + bool plugin_is_running()const override { return _running; } protected: net::node& p2p_node() { return *app().p2p_node(); } + bool _running = false; private: application* _app = nullptr; diff --git a/libraries/app/plugin.cpp b/libraries/app/plugin.cpp index 8568d371..0c0cf3d3 100644 --- a/libraries/app/plugin.cpp +++ b/libraries/app/plugin.cpp @@ -55,6 +55,7 @@ void plugin::plugin_startup() void plugin::plugin_shutdown() { + _running = false; return; } diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 23bd62ea..54377139 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -596,7 +596,7 @@ processed_transaction database::apply_transaction(const signed_transaction& trx, }); return result; } - +#pragma optimize("",off) processed_transaction database::_apply_transaction(const signed_transaction& trx) { try { uint32_t skip = get_node_properties().skip_flags; @@ -652,6 +652,7 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx //Finally process the operations processed_transaction ptrx(trx); + int rbn = trx.ref_block_num; _current_op_in_trx = 0; for( const auto& op : ptrx.operations ) { @@ -667,7 +668,7 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx return ptrx; } FC_CAPTURE_AND_RETHROW( (trx) ) } - +#pragma optimize("",on) operation_result database::apply_operation(transaction_evaluation_state& eval_state, const operation& op) { try { int i_which = op.which(); diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index bdd1fb23..7ca942f1 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -192,6 +192,7 @@ void account_history_plugin::plugin_initialize(const boost::program_options::var void account_history_plugin::plugin_startup() { + _running = true; } flat_set account_history_plugin::tracked_accounts() const diff --git a/libraries/plugins/debug_miner/debug_miner.cpp b/libraries/plugins/debug_miner/debug_miner.cpp index f8882889..80374f2c 100644 --- a/libraries/plugins/debug_miner/debug_miner.cpp +++ b/libraries/plugins/debug_miner/debug_miner.cpp @@ -101,6 +101,7 @@ void debug_miner_plugin::plugin_startup() _applied_block_conn = db.applied_block.connect([this](const graphene::chain::signed_block& b){ on_applied_block(b); }); _changed_objects_conn = db.changed_objects.connect([this](const std::vector& ids){ on_changed_objects(ids); }); _removed_objects_conn = db.removed_objects.connect([this](const std::vector& objs){ on_removed_objects(objs); }); + _running = true; return; } @@ -169,5 +170,6 @@ void debug_miner_plugin::plugin_shutdown() _json_object_stream->close(); _json_object_stream.reset(); } + _running = false; return; } diff --git a/libraries/plugins/delayed_node/delayed_node_plugin.cpp b/libraries/plugins/delayed_node/delayed_node_plugin.cpp index 91edbbb8..7bb43edb 100644 --- a/libraries/plugins/delayed_node/delayed_node_plugin.cpp +++ b/libraries/plugins/delayed_node/delayed_node_plugin.cpp @@ -145,6 +145,7 @@ void delayed_node_plugin::plugin_startup() { fc::from_variant( block_id, my->last_received_remote_head ); } ); + _running = true; return; } catch (const fc::exception& e) diff --git a/libraries/plugins/messaging/messaging.cpp b/libraries/plugins/messaging/messaging.cpp index eefb31bc..f1bcdba2 100644 --- a/libraries/plugins/messaging/messaging.cpp +++ b/libraries/plugins/messaging/messaging.cpp @@ -44,7 +44,7 @@ void messaging_plugin::plugin_startup() graphene::chain::custom_evaluator_register::instance().register_callback(graphene::chain::custom_operation_subtype_messaging, static_cast(this)); - + _running = true; ilog("messaging plugin: plugin_startup() end"); } FC_CAPTURE_AND_RETHROW() } @@ -52,6 +52,7 @@ void messaging_plugin::plugin_startup() void messaging_plugin::plugin_shutdown() { graphene::chain::custom_evaluator_register::instance().unregister_callback(graphene::chain::custom_operation_subtype_messaging); + _running = false; } void_result messaging_plugin::do_evaluate(const custom_operation& o) diff --git a/libraries/plugins/miner/miner.cpp b/libraries/plugins/miner/miner.cpp index 050074aa..5238317e 100644 --- a/libraries/plugins/miner/miner.cpp +++ b/libraries/plugins/miner/miner.cpp @@ -136,6 +136,7 @@ void miner_plugin::plugin_startup() _production_skip_flags |= graphene::chain::database::skip_undo_history_check; } schedule_production_loop(); + _running = true; } else elog("No miners configured! Please add miner IDs and private keys to configuration."); ilog("miner plugin: plugin_startup() end"); @@ -144,6 +145,7 @@ void miner_plugin::plugin_startup() void miner_plugin::plugin_shutdown() { graphene::time::shutdown_ntp_time(); + _running = false; return; } diff --git a/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp b/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp index 8271de02..587896c6 100644 --- a/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp +++ b/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp @@ -195,6 +195,16 @@ class seeding_plugin_impl /*: public package_transfer_interface::transfer_listen */ void send_ready_to_publish(); + /** + * Starts seeding of specified content + */ + void start_content_seeding(const std::string& url); + + /** + * Stops seeding of specified content + */ + void stop_content_seeding(const std::string& url); + std::vector listeners; seeding_plugin& _self; // std::map active_downloads; // my; diff --git a/libraries/plugins/seeding/seeding.cpp b/libraries/plugins/seeding/seeding.cpp index c67467b4..aa9d90db 100644 --- a/libraries/plugins/seeding/seeding.cpp +++ b/libraries/plugins/seeding/seeding.cpp @@ -567,6 +567,158 @@ void seeding_plugin_impl::restore_state(){ generate_pors(); }); } + +void seeding_plugin_impl::start_content_seeding(const std::string& url) +{ + try { + graphene::chain::database &db = database(); + + elog("start_content_seeding, main thread"); + service_thread->async([this, url]() { + if (std::abs((fc::time_point::now() - database().head_block_time()).count()) > int64_t(10000000)) + { + ilog("seeding plugin: start_content_seeding, waiting for sync"); + fc::usleep(fc::microseconds(1000000)); + } + elog("starting download of stopped content seeding, service thread"); + //start with rebuilding my_seeding_object database + const auto& sidx = database().get_index_type().indices().get(); + const auto& cidx = database().get_index_type().indices().get(); + + + const auto& c_idx = database().get_index_type().indices().get(); + auto sitr = sidx.begin(); + while (sitr != sidx.end()) + { + auto content_itr = c_idx.end(); + while (content_itr != c_idx.begin()) + // iterating backwards. + // Content objects are ordered increasingly by expiration time. + // This way we do not need to iterate over all ( expired ) objects + { + content_itr--; + if (content_itr->URI != url) + continue; + if (content_itr->expiration < database().head_block_time()) + break; + auto search_itr = content_itr->key_parts.find(sitr->seeder); + if (search_itr != content_itr->key_parts.end()) + { + + auto citr = cidx.find(content_itr->URI); + if (citr == cidx.end()) + { + const my_seeding_object& mso = database().create([&](my_seeding_object &so) { + so.URI = content_itr->URI; + so.seeder = sitr->seeder; + so._hash = content_itr->_hash; + so.space = content_itr->size; //we allocate the whole megabytes per content + so.key = search_itr->second; + so.expiration = content_itr->expiration; + so.cd = content_itr->cd; + }); + ilog("seeding_plugin: restore_state() creating seeding object for ${s}", ("s", mso)); + database().modify(*sitr, [&](my_seeder_object &mso) { + mso.free_space -= content_itr->size; //we allocate the whole megabytes per content + }); + sitr = sidx.end(); + break; + } + else { + ilog("seeding_plugin: content is already seeded"); + } + } + } + sitr++; + } + + //We need to rebuild the list of downloaded packages and compare it to the list of my_seeding_objects. + //For the downloaded packages we can issue PoR right away, the others needs to be downloaded + auto& pm = decent::package::PackageManager::instance(); + pm.recover_all_packages(); + auto packages = pm.get_all_known_packages(); + for (decent::package::package_handle_t package : packages) { + package->check(true); + if (package->get_data_state() != decent::package::PackageInfo::CHECKED) + pm.release_package(package); + } + + packages = pm.get_all_known_packages(); + + auto citr = cidx.begin(); + while (citr != cidx.end()) { + elog("restarting downloads, dealing with package ${u}", ("u", citr->URI)); + bool already_have = false; + decent::package::package_handle_t package_handle(0); + for (auto package : packages) + if (package->get_hash() == citr->_hash) { + already_have = true; + package_handle = package; + } + + if (already_have) { + database().modify(*citr, [](my_seeding_object& so) {so.downloaded = true; }); + + } + else { + elog("restarting downloads, re-downloading package ${u}", ("u", citr->URI)); + package_handle = pm.get_package(citr->URI, citr->_hash); + decent::package::event_listener_handle_t sl = std::make_shared(*this, *citr, package_handle); + package_handle->remove_all_event_listeners(); + package_handle->add_event_listener(sl); + package_handle->download(false); + } + ++citr; + } + elog("restarting downloads, service thread end"); + generate_pors(); + }); + } FC_CAPTURE_AND_RETHROW() +} + +void seeding_plugin_impl::stop_content_seeding(const std::string& url) +{ + try { + graphene::chain::database &db = database(); + const auto &sidx = db.get_index_type().indices().get(); + const auto &seeding_idx = db.get_index_type().indices().get(); + ilog("seeding plugin_impl: stop_content_seeding() start"); + auto& pm = decent::package::PackageManager::instance(); + + for (const auto& mso : seeding_idx) { + + if (!mso.downloaded || mso.deleted) + continue; + + if (mso.URI != url) + continue; + + auto package_handle = pm.get_package(mso.URI, mso._hash); + package_handle->remove_all_event_listeners(); + + const auto &sritr = sidx.find(mso.seeder); + FC_ASSERT(sritr != sidx.end()); + const auto &content = mso.get_content(db); + + ilog("seeding plugin_impl: stop_content_seeding() content ${c} expired, clenaing up", ("c", mso.URI)); + + + const auto &idx = db.get_index_type().indices().get(); + auto seeder_itr = idx.begin(); + FC_ASSERT(seeder_itr != idx.end()); + db.modify(*seeder_itr, [&](my_seeder_object &seeder_object) { + seeder_object.free_space += mso.space; + }); + + release_package(mso, package_handle); + db.remove(mso); + ilog("seeding plugin_impl: stop_content_seeding() content cleaned, continue"); + break; + } + ilog("seeding plugin_impl: stop_content_seeding() end"); + }FC_CAPTURE_AND_RETHROW() +} + }// end namespace detail @@ -584,6 +736,7 @@ void seeding_plugin::plugin_startup() fc::time_point next_call = fc::time_point::now() + fc::microseconds(30000000); elog("RtP planned at ${t}", ("t",next_call) ); my->service_thread->schedule([this](){elog("generating first ready to publish");my->send_ready_to_publish(); }, next_call, "Seeding plugin RtP generate"); + _running = true; ilog("seeding plugin: plugin_startup() end"); } @@ -719,6 +872,16 @@ std::string seeding_plugin::plugin_name()const return "seeding"; } +void seeding_plugin::start_content_seeding(const std::string& url) +{ + my->start_content_seeding(url); +} + +void seeding_plugin::stop_content_seeding(const std::string& url) +{ + my->stop_content_seeding(url); +} + void seeding_plugin::plugin_set_program_options( boost::program_options::options_description& cli, boost::program_options::options_description& cfg) @@ -756,12 +919,15 @@ void detail::SeedingListener::package_download_complete() { const auto& mso = *mso_itr; decent::package::package_handle_t pi = _pi; - + if (pi == nullptr) { + int a = 0; + } size_t size = (_pi->get_size() + 1024 * 1024 - 1) / (1024 * 1024); if( size > mso_itr->space ) { ilog("seeding plugin: package_download_complete(): Fraud detected: real content size is greater than propagated in blockchain; deleting..."); //changing DB outside the main thread does not work properly, let's delete it from there - _my->main_thread->async([ & ]() { _my->release_package(mso, pi); }); + _my->main_thread->async([ this, &mso, pi ]() { _my->release_package(mso, pi); }); + //_my->main_thread->async([ & ]() { _my->release_package(mso, pi); }); _pi.reset(); return; } @@ -769,7 +935,8 @@ void detail::SeedingListener::package_download_complete() { //Don't block package manager thread for too long. seeding_plugin_impl *my = _my; _my->database().modify(mso, [](my_seeding_object& so){so.downloaded = true;}); - _my->service_thread->async([ & ]() { _my->generate_por_int(mso, pi); }); + //_my->service_thread->async([ & ]() { _my->generate_por_int(mso, pi); }); + _my->service_thread->async([ this, &mso, pi ]() { _my->generate_por_int(mso, pi); }); }; diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 24437a87..635354aa 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -2058,6 +2058,26 @@ namespace graphene { namespace wallet { * @return vector of message objects */ vector get_sent_messages(const std::string& sender, uint32_t max_count) const; + + /** + * @brief Starts locally seeding of content by URL previously stopped by stop_content_seeding + * @param url of content + * @return vector of message objects + */ + void start_content_seeding(const std::string& url) const; + + /** + * @brief Stops locally seeding of content by URL + * @param url of content + * @return vector of message objects + */ + void stop_content_seeding(const std::string& url) const; + + /** + * @brief Returns list of running plugins + * @return vector of running plugins + */ + std::vector get_running_plugins() const; }; } } @@ -2273,4 +2293,7 @@ FC_API( graphene::wallet::wallet_api, (get_message_objects) (get_messages) (get_sent_messages) + (start_content_seeding) + (stop_content_seeding) + (get_running_plugins) ) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 104073dd..8503abdb 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2868,6 +2868,39 @@ signed_transaction content_cancellation(string author, } FC_CAPTURE_AND_RETHROW((from)(to)(text)) } + std::vector get_running_plugins() + { + try { + FC_ASSERT(!is_locked()); + + use_network_node_api(); + return (*_remote_net_node)->get_running_plugins(); + + } FC_CAPTURE_AND_RETHROW() + } + + void start_content_seeding(const std::string& url) + { + try { + FC_ASSERT(!is_locked()); + + use_network_node_api(); + (*_remote_net_node)->start_content_seeding(url); + + } FC_CAPTURE_AND_RETHROW((url)) + } + + void stop_content_seeding(const std::string& url) + { + try { + FC_ASSERT(!is_locked()); + + use_network_node_api(); + (*_remote_net_node)->stop_content_seeding(url); + + } FC_CAPTURE_AND_RETHROW((url)) + } + void dbg_make_mia(string creator, string symbol) { create_monitored_asset(get_account(creator).name, symbol, 2, "abcd", 3600, 1, true); @@ -4913,6 +4946,20 @@ void graphene::wallet::detail::submit_transfer_listener::package_seed_complete() return my->get_sent_messages(sender, max_count); } + std::vector wallet_api::get_running_plugins() const + { + return my->get_running_plugins(); + } + + void wallet_api::stop_content_seeding(const std::string& url) const + { + my->stop_content_seeding(url); + } + + void wallet_api::start_content_seeding(const std::string& url) const + { + my->start_content_seeding(url); + } } } // graphene::wallet From d87c13228f4b8cca4f0977cc3bab4dedad0e190e Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 15 Feb 2018 15:31:09 +0100 Subject: [PATCH 047/136] divided wallet API into separate header files, removed some obsolete functions --- libraries/wallet/wallet.cpp | 1373 +---------------- libraries/wallet/wallet_account.inl | 225 +++ libraries/wallet/wallet_assets.inl | 121 ++ libraries/wallet/wallet_content.inl | 324 ++++ libraries/wallet/wallet_general.inl | 187 +++ libraries/wallet/wallet_messaging.inl | 27 + libraries/wallet/wallet_mining.inl | 63 + libraries/wallet/wallet_proposals.inl | 44 + libraries/wallet/wallet_subscription.inl | 59 + .../wallet/wallet_transaction_builder.inl | 72 + libraries/wallet/wallet_wallet_file.inl | 223 +++ 11 files changed, 1377 insertions(+), 1341 deletions(-) create mode 100644 libraries/wallet/wallet_account.inl create mode 100644 libraries/wallet/wallet_assets.inl create mode 100644 libraries/wallet/wallet_content.inl create mode 100644 libraries/wallet/wallet_general.inl create mode 100644 libraries/wallet/wallet_messaging.inl create mode 100644 libraries/wallet/wallet_mining.inl create mode 100644 libraries/wallet/wallet_proposals.inl create mode 100644 libraries/wallet/wallet_subscription.inl create mode 100644 libraries/wallet/wallet_transaction_builder.inl create mode 100644 libraries/wallet/wallet_wallet_file.inl diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index b86a8505..6420d7f0 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3370,918 +3370,71 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati }}} + namespace graphene { namespace wallet { - - - namespace graphene { namespace wallet { - - wallet_api::wallet_api(const wallet_data& initial_data, fc::api rapi) - : my(new detail::wallet_api_impl(*this, initial_data, rapi)) - { - } - - wallet_api::~wallet_api() - { - } - - optional wallet_api::get_block(uint32_t num) - { - optional result = my->_remote_db->get_block(num); - - share_type miner_pay_from_reward = 0; - share_type miner_pay_from_fees = 0; - - //int64_t time_to_maint = my->_remote_db->get_time_to_maint_by_block_time(result->timestamp);//(dpo.next_maintenance_time - dpo.last_budget_time).to_seconds(); - miner_reward_input mri = my->_remote_db->get_time_to_maint_by_block_time(result->timestamp); - int64_t time_to_maint = mri.time_to_maint; - uint32_t blocks_in_interval = (uint64_t(time_to_maint) + mri.block_interval - 1) / mri.block_interval; - - if (blocks_in_interval > 0) { - miner_pay_from_fees = mri.from_accumulated_fees / blocks_in_interval; - } - miner_pay_from_reward = my->_remote_db->get_asset_per_block_by_block_num(num); - - //this should never happen, but better check. - if (miner_pay_from_fees < share_type(0)) - miner_pay_from_fees = share_type(0); - - result->miner_reward = miner_pay_from_fees + miner_pay_from_reward; - - return result; - } - - uint64_t wallet_api::get_account_count() const - { - return my->_remote_db->get_account_count(); - } - - vector wallet_api::list_my_accounts() - { - return vector(my->_wallet.my_accounts.begin(), my->_wallet.my_accounts.end()); - } - - map wallet_api::list_accounts(const string& lowerbound, uint32_t limit) - { - return my->_remote_db->lookup_accounts(lowerbound, limit); - } - - vector wallet_api::search_accounts(const string& term, const string& order, const string& id, uint32_t limit) - { - return my->_remote_db->search_accounts(term, order, object_id_type(id), limit); - } - - vector wallet_api::list_account_balances(const string& id) - { - if( auto real_id = detail::maybe_id(id) ) - return my->_remote_db->get_account_balances(*real_id, flat_set()); - return my->_remote_db->get_account_balances(get_account(id).id, flat_set()); - } - - vector wallet_api::list_assets(const string& lowerbound, uint32_t limit)const - { - return my->_remote_db->list_assets( lowerbound, limit ); - } - - vector wallet_api::get_account_history(string name, int limit)const - { - vector result; - auto account_id = get_account(name).get_id(); - - while( limit > 0 ) - { - operation_history_id_type start; - if( result.size() ) - { - start = result.back().op.id; - start = start + 1; - } - - - vector current = my->_remote_hist->get_account_history(account_id, operation_history_id_type(), std::min(100,limit), start); - for( auto& o : current ) { - std::stringstream ss; - auto memo = o.op.visit(detail::operation_printer(ss, *my, o.result)); - result.push_back( operation_detail{ memo, ss.str(), o } ); - } - if( current.size() < std::min(100,limit) ) - break; - limit -= current.size(); - } - - return result; - } - - vector wallet_api::get_relative_account_history(string name, - uint32_t stop, - int limit, - uint32_t start)const - { - vector result; - auto account_id = get_account(name).get_id(); - - vector current = my->_remote_hist->get_relative_account_history(account_id, stop, limit, start); - for( auto& o : current ) { - std::stringstream ss; - auto memo = o.op.visit(detail::operation_printer(ss, *my, o.result)); - result.push_back( operation_detail{ memo, ss.str(), o } ); - } - - return result; - } - - vector wallet_api::search_account_history(string const& account_name, - string const& order, - string const& id, - int limit) const - { - vector result; - try - { - account_object account = get_account(account_name); - result = my->_remote_db->search_account_history(account.id, order, object_id_type(id), limit); - - for (auto& item : result) - { - auto const& memo = item.m_transaction_encrypted_memo; - if (memo) - { - item.m_str_description += " - "; - auto it = my->_keys.find(memo->to); - if (it == my->_keys.end()) - // memo is encrypted for someone else - item.m_str_description += "{encrypted}"; - else - { - // here the memo is encrypted for me - // so I can decrypt it - string mykey = it->second; - auto wtok = *wif_to_key(mykey); - string str_memo = - memo->get_message(wtok, memo->from); - - item.m_str_description += str_memo; - } - } - } - } - catch(...){} - - return result; - } - - brain_key_info wallet_api::suggest_brain_key()const - { - brain_key_info result; - // create a private key for secure entropy - fc::sha256 sha_entropy1 = fc::ecc::private_key::generate().get_secret(); - fc::sha256 sha_entropy2 = fc::ecc::private_key::generate().get_secret(); - fc::bigint entropy1( sha_entropy1.data(), sha_entropy1.data_size() ); - fc::bigint entropy2( sha_entropy2.data(), sha_entropy2.data_size() ); - fc::bigint entropy(entropy1); - entropy <<= 8*sha_entropy1.data_size(); - entropy += entropy2; - string brain_key = ""; - - for( int i=0; i 0 ) - brain_key += " "; - brain_key += graphene::words::word_list[ choice.to_int64() ]; - } - - brain_key = detail::normalize_brain_key(brain_key); - fc::ecc::private_key priv_key = derive_private_key( brain_key, 0 ); - result.brain_priv_key = brain_key; - result.wif_priv_key = key_to_wif( priv_key ); - result.pub_key = priv_key.get_public_key(); - return result; - } - - pair wallet_api::generate_brain_key_el_gamal_key() const - { - pair ret; - ret.first = suggest_brain_key(); - - fc::optional op_private_key = wif_to_key(ret.first.wif_priv_key); - FC_ASSERT(op_private_key); - ret.second.private_key = generate_private_el_gamal_key_from_secret ( op_private_key->get_secret() ); - ret.second.public_key = decent::encrypt::get_public_el_gamal_key( ret.second.private_key ); - - return ret; - } - - brain_key_info wallet_api::get_brain_key_info(string const& brain_key) const - { - brain_key_info result; - - string str_brain_key = detail::normalize_brain_key(brain_key); - fc::ecc::private_key priv_key = derive_private_key( str_brain_key, 0 ); - result.brain_priv_key = str_brain_key; - result.wif_priv_key = key_to_wif( priv_key ); - result.pub_key = priv_key.get_public_key(); - return result; - } - - el_gamal_key_pair wallet_api::generate_el_gamal_keys() const - { - el_gamal_key_pair ret; - ret.private_key = decent::encrypt::generate_private_el_gamal_key(); - ret.public_key = decent::encrypt::get_public_el_gamal_key( ret.private_key ); - return ret; - } - - - - DInteger wallet_api::generate_encryption_key() const - { - CryptoPP::Integer secret(randomGenerator, 256); - return secret; - } - - string wallet_api::serialize_transaction( signed_transaction tx )const - { - return fc::to_hex(fc::raw::pack(tx)); - } - - variant wallet_api::get_object( object_id_type id ) const - { - return my->_remote_db->get_objects({id}); - } - - string wallet_api::get_wallet_filename() const - { - return my->get_wallet_filename(); - } - - transaction_handle_type wallet_api::begin_builder_transaction() - { - return my->begin_builder_transaction(); - } - - void wallet_api::add_operation_to_builder_transaction(transaction_handle_type transaction_handle, const operation& op) - { - my->add_operation_to_builder_transaction(transaction_handle, op); - } - - void wallet_api::replace_operation_in_builder_transaction(transaction_handle_type handle, unsigned operation_index, const operation& new_op) - { - my->replace_operation_in_builder_transaction(handle, operation_index, new_op); - } - - asset wallet_api::set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset) - { - return my->set_fees_on_builder_transaction(handle, fee_asset); - } - - vector wallet_api::get_proposed_transactions( string account_or_id )const - { - account_id_type id = get_account(account_or_id).get_id(); - return my->_remote_db->get_proposed_transactions( id ); - } - - transaction wallet_api::preview_builder_transaction(transaction_handle_type handle) - { - return my->preview_builder_transaction(handle); - } - - signed_transaction wallet_api::sign_builder_transaction(transaction_handle_type transaction_handle, bool broadcast) - { - return my->sign_builder_transaction(transaction_handle, broadcast); - } - - signed_transaction wallet_api::propose_builder_transaction( - transaction_handle_type handle, - time_point_sec expiration, - uint32_t review_period_seconds, - bool broadcast) - { - return my->propose_builder_transaction(handle, expiration, review_period_seconds, broadcast); - } - - signed_transaction wallet_api::propose_builder_transaction2( - transaction_handle_type handle, - string account_name_or_id, - time_point_sec expiration, - uint32_t review_period_seconds, - bool broadcast) - { - return my->propose_builder_transaction2(handle, account_name_or_id, expiration, review_period_seconds, broadcast); - } - - void wallet_api::remove_builder_transaction(transaction_handle_type handle) - { - return my->remove_builder_transaction(handle); - } - - account_object wallet_api::get_account(string account_name_or_id) const - { - return my->get_account(account_name_or_id); - } - - asset_object wallet_api::get_asset(string asset_name_or_id) const - { - auto a = my->find_asset(asset_name_or_id); - FC_ASSERT(a); - return *a; - } - - monitored_asset_options wallet_api::get_monitored_asset_data(string asset_name_or_id) const - { - auto asset = get_asset(asset_name_or_id); - FC_ASSERT(asset.is_monitored_asset() ); - return *asset.monitored_asset_opts; - } - - asset_id_type wallet_api::get_asset_id(string asset_symbol_or_id) const - { - return my->get_asset_id(asset_symbol_or_id); - } - - bool wallet_api::import_key(string account_name_or_id, string wif_key) - { - FC_ASSERT(!is_locked()); - // backup wallet - fc::optional optional_private_key = wif_to_key(wif_key); - if (!optional_private_key) - FC_THROW("Invalid private key"); - string base58_public_key = optional_private_key->get_public_key().to_base58(); - // copy_wallet_file( "before-import-key-" + base58_public_key ); - - if( my->import_key(account_name_or_id, wif_key) ) - { - save_wallet_file(); - // copy_wallet_file( "after-import-key-" + base58_public_key ); - return true; - } - return false; - } - - map wallet_api::import_accounts( string filename, string password ) - { - FC_ASSERT( !is_locked() ); - FC_ASSERT( fc::exists( filename ) ); - - const auto imported_keys = fc::json::from_file( filename ); - - const auto password_hash = fc::sha512::hash( password ); - FC_ASSERT( fc::sha512::hash( password_hash ) == imported_keys.password_checksum ); - - map result; - for( const auto& item : imported_keys.account_keys ) - { - const auto import_this_account = [ & ]() -> bool - { - try - { - const account_object account = get_account( item.account_name ); - const auto& owner_keys = account.owner.get_keys(); - const auto& active_keys = account.active.get_keys(); - - for( const auto& public_key : item.public_keys ) - { - if( std::find( owner_keys.begin(), owner_keys.end(), public_key ) != owner_keys.end() ) - return true; - - if( std::find( active_keys.begin(), active_keys.end(), public_key ) != active_keys.end() ) - return true; - } - } - catch( ... ) - { - } - - return false; - }; - - const auto should_proceed = import_this_account(); - result[ item.account_name ] = should_proceed; - - if( should_proceed ) - { - uint32_t import_successes = 0; - uint32_t import_failures = 0; - // TODO: First check that all private keys match public keys - for( const auto& encrypted_key : item.encrypted_private_keys ) - { - try - { - const auto plain_text = fc::aes_decrypt( password_hash, encrypted_key ); - const auto private_key = fc::raw::unpack( plain_text ); - - import_key( item.account_name, string( graphene::utilities::key_to_wif( private_key ) ) ); - ++import_successes; - } - catch( const fc::exception& e ) - { - elog( "Couldn't import key due to exception ${e}", ("e", e.to_detail_string()) ); - ++import_failures; - } - } - ilog( "successfully imported ${n} keys for account ${name}", ("n", import_successes)("name", item.account_name) ); - if( import_failures > 0 ) - elog( "failed to import ${n} keys for account ${name}", ("n", import_failures)("name", item.account_name) ); - } - } - - return result; - } - - bool wallet_api::import_account_keys( string filename, string password, string src_account_name, string dest_account_name ) - { - FC_ASSERT( !is_locked() ); - FC_ASSERT( fc::exists( filename ) ); - - bool is_my_account = false; - const auto accounts = list_my_accounts(); - for( const auto& account : accounts ) - { - if( account.name == dest_account_name ) - { - is_my_account = true; - break; - } - } - FC_ASSERT( is_my_account ); - - const auto imported_keys = fc::json::from_file( filename ); - - const auto password_hash = fc::sha512::hash( password ); - FC_ASSERT( fc::sha512::hash( password_hash ) == imported_keys.password_checksum ); - - bool found_account = false; - for( const auto& item : imported_keys.account_keys ) - { - if( item.account_name != src_account_name ) - continue; - - found_account = true; - - for( const auto& encrypted_key : item.encrypted_private_keys ) - { - const auto plain_text = fc::aes_decrypt( password_hash, encrypted_key ); - const auto private_key = fc::raw::unpack( plain_text ); - - my->import_key( dest_account_name, string( graphene::utilities::key_to_wif( private_key ) ) ); - } - - return true; - } - save_wallet_file(); - - FC_ASSERT( found_account ); - - return false; - } - - variant wallet_api::info() - { - return my->info(); - } - - variant_object wallet_api::about() const - { - return my->about(); - } - - fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_string, int sequence_number) const - { - return detail::derive_private_key( prefix_string, sequence_number ); - } - - signed_transaction wallet_api::register_account(string name, - public_key_type owner_pubkey, - public_key_type active_pubkey, - string registrar_account, - bool broadcast) - { - return my->register_account( name, owner_pubkey, active_pubkey, registrar_account, broadcast ); - } - - signed_transaction wallet_api::create_account_with_brain_key(string brain_key, - string account_name, - string registrar_account, - bool broadcast /* = false */) - { - return my->create_account_with_brain_key( - brain_key, account_name, registrar_account, true, - broadcast - ); - } - - signed_transaction wallet_api::transfer(string from, string to, string amount, - string asset_symbol, string memo, bool broadcast /* = false */) - { - return my->transfer(from, to, amount, asset_symbol, memo, broadcast); - } - - signed_transaction wallet_api::create_monitored_asset(string issuer, - string symbol, - uint8_t precision, - string description, - uint32_t feed_lifetime_sec, - uint8_t minimum_feeds, - bool broadcast) - - { - return my->create_monitored_asset(issuer, symbol, precision, description, feed_lifetime_sec, minimum_feeds, broadcast); - } - - void wallet_api::propose_transfer(string proposer, - string from, - string to, - string amount, - string asset_symbol, - string memo, - time_point_sec expiration) - { - return my->propose_transfer(proposer, from, to, amount, asset_symbol, memo, expiration); - } - - signed_transaction wallet_api::update_monitored_asset(string symbol, - string description, - uint32_t feed_lifetime_sec, - uint8_t minimum_feeds, - bool broadcast /* = false */) - { - return my->update_monitored_asset(symbol, description, feed_lifetime_sec, minimum_feeds, broadcast); - } - - signed_transaction wallet_api::publish_asset_feed(string publishing_account, - string symbol, - price_feed feed, - bool broadcast /* = false */) - { - return my->publish_asset_feed(publishing_account, symbol, feed, broadcast); - } - - multimap wallet_api::get_feeds_by_miner(const string& account_name_or_id, - const uint32_t count) - { - account_id_type account_id = get_account( account_name_or_id ).id; - return my->_remote_db->get_feeds_by_miner( account_id, count ); - } - - signed_transaction wallet_api::create_user_issued_asset(string issuer, - string symbol, - uint8_t precision, - string description, - uint64_t max_supply, - price core_exchange_rate, - bool is_exchangeable, - bool broadcast /* = false */) - { - return my->create_user_issued_asset(issuer, symbol, precision, description, max_supply, core_exchange_rate, is_exchangeable, broadcast); - } - - signed_transaction wallet_api::issue_asset(string to_account, string amount, string symbol, - string memo, bool broadcast) - { - return my->issue_asset(to_account, amount, symbol, memo, broadcast); - } - - signed_transaction wallet_api::update_user_issued_asset(string symbol, - string new_issuer, - string description, - uint64_t max_supply, - price core_exchange_rate, - bool is_exchangeable, - bool broadcast /* = false */) - { - return my->update_user_issued_asset(symbol, new_issuer, description, max_supply, core_exchange_rate, is_exchangeable, broadcast); - } - - signed_transaction wallet_api::fund_asset_pools(string from, - string uia_amount, - string uia_symbol, - string DCT_amount, - string DCT_symbol, - bool broadcast /* = false */) - { - return my->fund_asset_pools(from, uia_amount, uia_symbol, DCT_amount, DCT_symbol, broadcast); - } - - signed_transaction wallet_api::reserve_asset(string from, - string amount, - string symbol, - bool broadcast /* = false */) - { - return my->reserve_asset(from, amount, symbol, broadcast); - } - - signed_transaction wallet_api::claim_fees(string uia_amount, - string uia_symbol, - string dct_amount, - string dct_symbol, - bool broadcast /* = false */) - { - return my->claim_fees( uia_amount, uia_symbol, dct_amount, dct_symbol, broadcast); - } - - map wallet_api::list_miners(const string& lowerbound, uint32_t limit) - { - return my->_remote_db->lookup_miner_accounts(lowerbound, limit); - } - - miner_object wallet_api::get_miner(string owner_account) - { - return my->get_miner(owner_account); - } - - signed_transaction wallet_api::create_miner(string owner_account, - string url, - bool broadcast /* = false */) - { - return my->create_miner(owner_account, url, broadcast); - } - - signed_transaction wallet_api::update_miner( - string miner_name, - string url, - string block_signing_key, - bool broadcast /* = false */) - { - return my->update_miner(miner_name, url, block_signing_key, broadcast); - } - - vector< vesting_balance_object_with_info > wallet_api::get_vesting_balances( string account_name ) - { - return my->get_vesting_balances( account_name ); - } - - signed_transaction wallet_api::withdraw_vesting( - string miner_name, - string amount, - string asset_symbol, - bool broadcast /* = false */) - { - return my->withdraw_vesting( miner_name, amount, asset_symbol, broadcast ); - } - - signed_transaction wallet_api::vote_for_miner(string voting_account, - string miner, - bool approve, - bool broadcast /* = false */) - { - return my->vote_for_miner(voting_account, miner, approve, broadcast); - } - - signed_transaction wallet_api::set_voting_proxy(string account_to_modify, - optional voting_account, - bool broadcast /* = false */) - { - return my->set_voting_proxy(account_to_modify, voting_account, broadcast); - } - - signed_transaction wallet_api::set_desired_miner_count(string account_to_modify, - uint16_t desired_number_of_miners, - bool broadcast /* = false */) - { - return my->set_desired_miner_count(account_to_modify, desired_number_of_miners, broadcast); - } - - void wallet_api::set_wallet_filename(string wallet_filename) - { - my->_wallet_filename = wallet_filename; - } - - signed_transaction wallet_api::sign_transaction(signed_transaction tx, bool broadcast /* = false */) - { try { - return my->sign_transaction( tx, broadcast); - } FC_CAPTURE_AND_RETHROW( (tx) ) } - - operation wallet_api::get_prototype_operation(string operation_name) - { - return my->get_prototype_operation( operation_name ); - } - -#if 0 - void wallet_api::dbg_make_mia(string creator, string symbol) - { - FC_ASSERT(!is_locked()); - my->dbg_make_mia(creator, symbol); - } - - void wallet_api::dbg_push_blocks( std::string src_filename, uint32_t count ) - { - my->dbg_push_blocks( src_filename, count ); - } - - void wallet_api::dbg_generate_blocks( std::string debug_wif_key, uint32_t count ) - { - my->dbg_generate_blocks( debug_wif_key, count ); - } - - void wallet_api::dbg_stream_json_objects( const std::string& filename ) - { - my->dbg_stream_json_objects( filename ); - } - - void wallet_api::dbg_update_object( fc::variant_object update ) - { - my->dbg_update_object( update ); - } -#endif - - - void wallet_api::network_add_nodes( const vector& nodes ) - { - my->network_add_nodes( nodes ); - } - - vector< variant > wallet_api::network_get_connected_peers() - { - return my->network_get_connected_peers(); - } - - signed_transaction wallet_api::propose_parameter_change( - const string& proposing_account, - fc::time_point_sec expiration_time, - const variant_object& changed_values, - bool broadcast /* = false */ - ) - { - return my->propose_parameter_change( proposing_account, expiration_time, changed_values, broadcast ); - } - - signed_transaction wallet_api::propose_fee_change( - const string& proposing_account, - fc::time_point_sec expiration_time, - const variant_object& changed_fees, - bool broadcast /* = false */ - ) - { - return my->propose_fee_change( proposing_account, expiration_time, changed_fees, broadcast ); - } - - signed_transaction wallet_api::approve_proposal( - const string& fee_paying_account, - const string& proposal_id, - const approval_delta& delta, - bool broadcast /* = false */ - ) - { - return my->approve_proposal( fee_paying_account, proposal_id, delta, broadcast ); - } - - global_property_object wallet_api::get_global_properties() const - { - return my->get_global_properties(); - } - - dynamic_global_property_object wallet_api::get_dynamic_global_properties() const + wallet_api::wallet_api(const wallet_data& initial_data, fc::api rapi) + : my(new detail::wallet_api_impl(*this, initial_data, rapi)) { - return my->get_dynamic_global_properties(); } - string wallet_api::help()const + wallet_api::~wallet_api() { - std::vector method_names = my->method_documentation.get_method_names(); - std::stringstream ss; - for (const std::string method_name : method_names) - { - try - { - ss << my->method_documentation.get_brief_description(method_name); - } - catch (const fc::key_not_found_exception&) - { - ss << method_name << " (no help available)\n"; - } - } - return ss.str(); } - string wallet_api::gethelp(const string& method)const - { - fc::api tmp; - std::stringstream ss; - ss << "\n"; - - if( method == "import_key" ) - { - ss << "usage: import_key ACCOUNT_NAME_OR_ID WIF_PRIVATE_KEY\n\n"; - ss << "example: import_key \"1.2.11\" 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3\n"; - ss << "example: import_key \"usera\" 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3\n"; - } - else if( method == "transfer" ) - { - ss << "usage: transfer FROM TO AMOUNT SYMBOL \"memo\" BROADCAST\n\n"; - ss << "example: transfer \"1.2.11\" \"1.2.4\" 1000.03 DCT \"memo\" true\n"; - ss << "example: transfer \"usera\" \"userb\" 1000.123 DCT \"memo\" true\n"; - } - else if( method == "create_account_with_brain_key" ) - { - ss << "usage: create_account_with_brain_key BRAIN_KEY ACCOUNT_NAME REGISTRAR BROADCAST\n\n"; - ss << "example: create_account_with_brain_key \"my really long brain key\" \"newaccount\" \"1.2.11\" true\n"; - ss << "example: create_account_with_brain_key \"my really long brain key\" \"newaccount\" \"someaccount\" true\n"; - ss << "\n"; - ss << "This method should be used if you would like the wallet to generate new keys derived from the brain key.\n"; - ss << "The BRAIN_KEY will be used as the owner key, and the active key will be derived from the BRAIN_KEY. Use\n"; - ss << "register_account if you already know the keys you know the public keys that you would like to register.\n"; +#include "wallet_general.inl" +#include "wallet_wallet_file.inl" +#include "wallet_account.inl" +#include "wallet_assets.inl" +#include "wallet_transaction_builder.inl" +#include "wallet_mining.inl" +#include "wallet_proposals.inl" +#include "wallet_content.inl" +#include "wallet_subscription.inl" +#include "wallet_messaging.inl" - } - else if( method == "register_account" ) - { - ss << "usage: register_account ACCOUNT_NAME OWNER_PUBLIC_KEY ACTIVE_PUBLIC_KEY REGISTRAR BROADCAST\n\n"; - ss << "example: register_account \"newaccount\" \"CORE6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV\" \"CORE6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV\" \"1.3.11\" true\n"; - ss << "\n"; - ss << "Use this method to register an account for which you do not know the private keys."; - } - else if( method == "create_monitored_asset" ) - { - ss << "usage: ISSUER SYMBOL PRECISION DESCRIPTION FEED_LIFETIME_SEC MINIMUM_FEEDS BROADCAST\n\n"; - ss << "PRECISION: the number of digits after the decimal point\n\n"; - ss << "\nExample value of MONITORED ASSET_OPTIONS: \n"; - ss << fc::json::to_pretty_string( graphene::chain::monitored_asset_options() ); - } - else - { - std::string doxygenHelpString = my->method_documentation.get_detailed_description(method); - if (!doxygenHelpString.empty()) - ss << doxygenHelpString; - else - ss << "No help defined for method " << method << "\n"; - } - return ss.str(); - } - bool wallet_api::load_wallet_file( string wallet_filename ) +#if 0 + void wallet_api::dbg_make_mia(string creator, string symbol) { - return my->load_wallet_file( wallet_filename ); + FC_ASSERT(!is_locked()); + my->dbg_make_mia(creator, symbol); } - void wallet_api::save_wallet_file( string wallet_filename ) + void wallet_api::dbg_push_blocks( std::string src_filename, uint32_t count ) { - my->save_wallet_file( wallet_filename ); + my->dbg_push_blocks( src_filename, count ); } - std::map > - wallet_api::get_result_formatters() const + void wallet_api::dbg_generate_blocks( std::string debug_wif_key, uint32_t count ) { - return my->get_result_formatters(); + my->dbg_generate_blocks( debug_wif_key, count ); } - bool wallet_api::is_locked()const - { - return my->is_locked(); - } - bool wallet_api::is_new()const + void wallet_api::dbg_stream_json_objects( const std::string& filename ) { - return my->_wallet.cipher_keys.size() == 0; + my->dbg_stream_json_objects( filename ); } - void wallet_api::encrypt_keys() + void wallet_api::dbg_update_object( fc::variant_object update ) { - my->encrypt_keys(); + my->dbg_update_object( update ); } +#endif - void wallet_api::lock() - { try { - FC_ASSERT( !is_locked() ); - encrypt_keys(); - for( auto & key : my->_keys ) - key.second = key_to_wif(fc::ecc::private_key()); - my->_keys.clear(); - my->_checksum = fc::sha512(); - my->self.lock_changed(true); - } FC_CAPTURE_AND_RETHROW() } - - void wallet_api::unlock(string password) - { try { - FC_ASSERT(password.size() > 0); - auto pw = fc::sha512::hash(password.c_str(), password.size()); - vector decrypted = fc::aes_decrypt(pw, my->_wallet.cipher_keys); - auto pk = fc::raw::unpack(decrypted); - FC_ASSERT(pk.checksum == pw); - my->_keys = std::move(pk.keys); - my->_checksum = pk.checksum; - my->self.lock_changed(false); - } FC_CAPTURE_AND_RETHROW() } - - void wallet_api::set_password( string password ) + std::map > + wallet_api::get_result_formatters() const { - if( !is_new() ) - FC_ASSERT( !is_locked(), "The wallet must be unlocked before the password can be set" ); - my->_checksum = fc::sha512::hash( password.c_str(), password.size() ); - lock(); + return my->get_result_formatters(); } - map wallet_api::dump_private_keys() + void wallet_api::encrypt_keys() { - FC_ASSERT(!is_locked()); - return my->_keys; + my->encrypt_keys(); } - string wallet_api::get_private_key( public_key_type pubkey )const - { - return key_to_wif( my->get_private_key( pubkey ) ); - } - signed_block_with_info::signed_block_with_info( const signed_block& block ) : signed_block( block ) { @@ -4299,278 +3452,8 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati allowed_withdraw_time = now; } - real_supply wallet_api::get_real_supply()const - { - return my->_remote_db->get_real_supply(); - } - - signed_transaction - wallet_api::submit_content(string const& author, - vector< pair< string, uint32_t>> co_authors, - string const& URI, - vector const& price_amounts, - uint64_t size, - fc::ripemd160 const& hash, - vector const& seeders, - uint32_t quorum, - fc::time_point_sec const& expiration, - string const& publishing_fee_asset, - string const& publishing_fee_amount, - string const& synopsis, - DInteger const& secret, - decent::encrypt::CustodyData const& cd, - bool broadcast) - { - return my->submit_content(author, co_authors, URI, price_amounts, hash, size, seeders, quorum, expiration, publishing_fee_asset, publishing_fee_amount, synopsis, secret, cd, broadcast); - } - - void - wallet_api::submit_content_async(string const &author, vector< pair< string, uint32_t>> co_authors, - string const &content_dir, string const &samples_dir, - string const &protocol, - vector const &price_amounts, - vector const &seeders, - fc::time_point_sec const &expiration, string const &synopsis) - { - return my->submit_content_async(author, co_authors, content_dir, samples_dir, protocol, price_amounts, seeders, expiration, synopsis); - - } - - signed_transaction wallet_api::content_cancellation(string author, - string URI, - bool broadcast) - { - return my->content_cancellation(author, URI, broadcast); - } - - void - wallet_api::download_content(string const& consumer, string const& URI, string const& region_code_from, bool broadcast) - { - return my->download_content(consumer, URI, region_code_from, broadcast); - } - - string wallet_api::price_to_dct(const string& amount, const string& asset_symbol_or_id) - { - return my->price_to_dct(amount, asset_symbol_or_id ); - } - -// HEAD -optional wallet_api::get_download_status(string consumer, - string URI) const -{ - return my->get_download_status(consumer, URI); -} - -signed_transaction wallet_api::request_to_buy(string consumer, - string URI, - string price_asset_name, - string price_amount, - string str_region_code_from, - bool broadcast) -{ - return my->request_to_buy(consumer, URI, price_asset_name, price_amount, str_region_code_from, broadcast); -} - -void wallet_api::leave_rating_and_comment(string consumer, - string URI, - uint64_t rating, - string comment, - bool broadcast) -{ - return my->leave_rating_and_comment(consumer, URI, rating, comment, broadcast); -} - - void wallet_api::seeding_startup(string account_id_type_or_name, - DInteger content_private_key, - string seeder_private_key, - uint64_t free_space, - uint32_t seeding_price, - string seeding_symbol, - string packages_path, - string region_code) - { - return my->seeding_startup(account_id_type_or_name, content_private_key, seeder_private_key, free_space, seeding_price, seeding_symbol, packages_path, region_code); - } - - DInteger wallet_api::restore_encryption_key(string consumer, buying_id_type buying) - { - return my->restore_encryption_key(consumer, buying); - } - - vector wallet_api::get_open_buyings()const - { - return my->_remote_db->get_open_buyings(); - } - - vector wallet_api::get_open_buyings_by_URI( const string& URI )const - { - return my->_remote_db->get_open_buyings_by_URI( URI ); - } - - vector wallet_api::get_open_buyings_by_consumer( const string& account_id_or_name )const - { - account_id_type consumer = get_account( account_id_or_name ).id; - return my->_remote_db->get_open_buyings_by_consumer( consumer ); - } - - vector wallet_api::get_buying_history_objects_by_consumer( const string& account_id_or_name )const - { - account_id_type consumer = get_account( account_id_or_name ).id; - vector result = my->_remote_db->get_buying_history_objects_by_consumer( consumer ); - - for (int i = 0; i < result.size(); ++i) - { - buying_object& bobj = result[i]; - - optional content = my->_remote_db->get_content( bobj.URI ); - if (!content) - continue; - optional op_price = content->price.GetPrice(bobj.region_code_from); - if (!op_price) - continue; - - bobj.price = *op_price; - - bobj.size = content->size; - bobj.rating = content->AVG_rating; - bobj.synopsis = content->synopsis; - - } - return result; - } - - - vector wallet_api::search_my_purchases(const string& account_id_or_name, - const string& term, - const string& order, - const string& id, - uint32_t count)const - { - account_id_type consumer = get_account( account_id_or_name ).id; - vector bobjects = my->_remote_db->get_buying_objects_by_consumer(consumer, order, object_id_type(id), term, count ); - vector result; - - for (size_t i = 0; i < bobjects.size(); ++i) - { - buying_object const& buyobj = bobjects[i]; - - optional status = get_download_status(account_id_or_name, buyobj.URI); - if (!status) - continue; - - optional content = my->_remote_db->get_content( buyobj.URI ); - if (!content) - continue; - - result.emplace_back(buying_object_ex(bobjects[i], *status)); - buying_object_ex& bobj = result.back(); - - bobj.author_account = my->get_account(content->author).name; - bobj.times_bought = content->times_bought; - bobj.hash = content->_hash; - bobj.AVG_rating = content->AVG_rating; - bobj.rating = content->AVG_rating; - } - - return result; - } - -vector wallet_api::search_feedback(const string& user, - const string& URI, - const string& id, - uint32_t count) const -{ - vector result; - vector temp = my->_remote_db->search_feedback(user, URI, object_id_type(id), count); - - for (auto const& item : temp) - result.push_back(rating_object_ex( item, get_account(string(object_id_type(item.consumer))).name )); - - return result; -} - -optional wallet_api::get_content( const string& URI )const -{ - return my->_remote_db->get_content( URI ); -} - -optional wallet_api::get_buying_by_consumer_URI( const string& account_id_or_name, const string & URI )const -{ - account_id_type account = get_account( account_id_or_name ).id; - return my->_remote_db->get_buying_by_consumer_URI( account, URI ); -} - -vector wallet_api::search_content(const string& term, - const string& order, - const string& user, - const string& region_code, - const string& id, - const string& type, - uint32_t count)const -{ - return my->_remote_db->search_content(term, order, user, region_code, object_id_type(id), type, count); -} - - vector wallet_api::search_user_content(const string& user, - const string& term, - const string& order, - const string& region_code, - const string& id, - const string& type, - uint32_t count)const - { - vector result = my->_remote_db->search_content(term, order, user, region_code, object_id_type(id), type, count); - - auto packages = PackageManager::instance().get_all_known_packages(); - for (auto package: packages) - { - auto state = package->get_manipulation_state(); - - if (package->get_data_state() == PackageInfo::CHECKED){ - bool cont = false; - auto hash = package->get_hash(); - for( const auto& item : result ) - if( item._hash == hash ) - cont = true; - if(cont) - continue; - } - - bool cont = false; - for (auto listener: my->_package_manager_listeners) - { - - if (listener->get_hash() == package->get_hash()) - { - cont = true; - content_summary newObject; - newObject.synopsis = listener->op().synopsis; - newObject.expiration = listener->op().expiration; - newObject.author = my->get_account( listener->op().author ).name; - - if (state == PackageInfo::PACKING) { - newObject.status = "Packing"; - } else if (state == PackageInfo::ENCRYPTING) { - newObject.status = "Encrypting"; - } else if (state == PackageInfo::STAGING) { - newObject.status = "Staging"; - } else if (state == PackageInfo:: MS_IDLE ) - newObject.status = "Submission failed"; - - result.insert(result.begin(), newObject); - } - } - if(cont) - continue; - } - return result; - } -pair> wallet_api::get_author_and_co_authors_by_URI( const string& URI )const -{ - return my->get_author_and_co_authors_by_URI( URI ); -} vector wallet_api::list_seeders_by_price( uint32_t count )const { @@ -4592,153 +3475,9 @@ pair> wallet_api::get_author_and_co_aut return my->_remote_db->list_seeders_by_rating( count ); } - signed_transaction wallet_api::subscribe_to_author( string from, - string to, - string price_amount, - string price_asset_symbol, - bool broadcast/* = false */) - { - return my->subscribe_to_author(from, to, price_amount, price_asset_symbol, broadcast); - } - - signed_transaction wallet_api::subscribe_by_author( string from, - string to, - bool broadcast/* = false */) - { - return my->subscribe_by_author(from, to, broadcast); - } - - signed_transaction wallet_api::set_subscription( string account, - bool allow_subscription, - uint32_t subscription_period, - string price_amount, - string price_asset_symbol, - bool broadcast/* = false */) - { - return my->set_subscription(account, allow_subscription, subscription_period, price_amount, price_asset_symbol, broadcast); - } - - signed_transaction wallet_api::set_automatic_renewal_of_subscription( string account_id_or_name, - subscription_id_type subscription_id, - bool automatic_renewal, - bool broadcast/* = false */) - { - return my->set_automatic_renewal_of_subscription(account_id_or_name, subscription_id, automatic_renewal, broadcast); - } - - vector< subscription_object > wallet_api::list_active_subscriptions_by_consumer( const string& account_id_or_name, const uint32_t count) const - { - account_id_type account = get_account( account_id_or_name ).id; - return my->_remote_db->list_active_subscriptions_by_consumer( account, count); - } - - vector< subscription_object > wallet_api::list_subscriptions_by_consumer( const string& account_id_or_name, const uint32_t count) const - { - account_id_type account = get_account( account_id_or_name ).id; - return my->_remote_db->list_subscriptions_by_consumer( account, count); - } - - vector< subscription_object > wallet_api::list_active_subscriptions_by_author( const string& account_id_or_name, const uint32_t count) const - { - account_id_type account = get_account( account_id_or_name ).id; - return my->_remote_db->list_active_subscriptions_by_author( account, count); - } - - std::string wallet_api::sign_buffer(std::string const& str_buffer, - std::string const& str_brainkey) const - { - if (str_buffer.empty() || - str_brainkey.empty()) - throw std::runtime_error("You need buffer and brainkey to sign"); - - string normalized_brain_key = detail::normalize_brain_key( str_brainkey ); - fc::ecc::private_key privkey = derive_private_key( normalized_brain_key, 0 ); - - fc::sha256 digest(str_buffer); - - auto sign = privkey.sign_compact(digest); - - return fc::to_hex((const char*)sign.begin(), sign.size()); - } - - el_gamal_key_pair_str wallet_api::get_el_gammal_key(string const& consumer) const { - try - { - FC_ASSERT( !is_locked() ); - - account_object consumer_account = get_account( consumer ); - el_gamal_key_pair_str res; - - res.private_key = generate_private_el_gamal_key_from_secret ( my->get_private_key_for_account(consumer_account).get_secret() ); - res.public_key = decent::encrypt::get_public_el_gamal_key( res.private_key ); - return res; - } FC_CAPTURE_AND_RETHROW( (consumer) ) - } - - bool wallet_api::verify_signature(std::string const& str_buffer, - std::string const& str_publickey, - std::string const& str_signature) const - { - if (str_buffer.empty() || - str_publickey.empty() || - str_signature.empty()) - throw std::runtime_error("You need buffer, public key and signature to verify"); - - fc::ecc::compact_signature signature; - fc::from_hex(str_signature, (char*)signature.begin(), signature.size()); - fc::sha256 digest(str_buffer); - - fc::ecc::public_key pub_key(signature, digest); - public_key_type provided_key(str_publickey); - - if (provided_key == pub_key) - return true; - else - return false; - } - - fc::time_point_sec wallet_api::head_block_time() const - { - return my->head_block_time(); - } - - vector< subscription_object > wallet_api::list_subscriptions_by_author( const string& account_id_or_name, const uint32_t count) const - { - account_id_type account = get_account( account_id_or_name ).id; - return my->_remote_db->list_subscriptions_by_author( account, count); - } - - std::pair wallet_api::create_package(const std::string& content_dir, const std::string& samples_dir, const DInteger& aes_key) const { - FC_ASSERT(!is_locked()); - fc::sha256 key1; - aes_key.Encode((byte*)key1._hash, 32); - - uint32_t sectors; - if(my->head_block_time()>HARDFORK_1_TIME) - sectors = DECENT_SECTORS; - else - sectors = DECENT_SECTORS_BIG; - auto pack = PackageManager::instance().get_package(content_dir, samples_dir, key1, sectors); - decent::encrypt::CustodyData cd = pack->get_custody_data(); - return std::pair(pack->get_hash().str(), cd); - } - - void wallet_api::extract_package(const std::string& package_hash, const std::string& output_dir, const DInteger& aes_key) const { - FC_ASSERT(!is_locked()); - fc::sha256 key1; - aes_key.Encode((byte*)key1._hash, 32); - auto pack = PackageManager::instance().find_package(fc::ripemd160(package_hash)); - if (pack == nullptr) { - FC_THROW("Can not find package"); - } - if (pack->get_manipulation_state() != PackageInfo::ManipulationState::MS_IDLE) { - FC_THROW("Package is not in valid state"); - } - pack->unpack(output_dir, key1); - } void graphene::wallet::detail::submit_transfer_listener::package_creation_complete() { uint64_t size = std::max((uint64_t)1, ( _info->get_size() + (1024 * 1024) -1 ) / (1024 * 1024)); @@ -4773,54 +3512,6 @@ void graphene::wallet::detail::submit_transfer_listener::package_seed_complete() } - - void wallet_api::remove_package(const std::string& package_hash) const { - FC_ASSERT(!is_locked()); - PackageManager::instance().release_package(fc::ripemd160(package_hash)); - } - - void wallet_api::download_package(const std::string& url) const { - FC_ASSERT(!is_locked()); - auto content = get_content(url); - FC_ASSERT(content, "no such package in the system"); - auto pack = PackageManager::instance().get_package(url, content->_hash ); - pack->download(false); - } - - std::string wallet_api::upload_package(const std::string& package_hash, const std::string& protocol) const { - FC_ASSERT(!is_locked()); - auto package = PackageManager::instance().get_package(fc::ripemd160(package_hash)); - package->start_seeding(protocol, true); - return package->get_url(); - } - - void wallet_api::send_message(const std::string& from, std::vector to, string text) - { - return my->send_message(from, to, text); - } - - vector wallet_api::get_message_objects(const std::string& sender, const std::string& receiver, uint32_t max_count) const - { - optional receiver_id; - if(receiver.size()) - receiver_id = get_account(receiver).get_id(); - optional sender_id; - if(sender.size()) - sender_id = get_account(sender).get_id(); - return my->get_message_objects(sender_id, receiver_id, max_count); - } - - vector wallet_api::get_messages(const std::string& receiver, uint32_t max_count) const - { - return my->get_messages(receiver, max_count); - } - - vector wallet_api::get_sent_messages(const std::string& sender, uint32_t max_count) const - { - return my->get_sent_messages(sender, max_count); - } - - } } // graphene::wallet diff --git a/libraries/wallet/wallet_account.inl b/libraries/wallet/wallet_account.inl new file mode 100644 index 00000000..f1a026c3 --- /dev/null +++ b/libraries/wallet/wallet_account.inl @@ -0,0 +1,225 @@ + +fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_string, int sequence_number) const +{ + return detail::derive_private_key( prefix_string, sequence_number ); +} + +uint64_t wallet_api::get_account_count() const +{ + return my->_remote_db->get_account_count(); +} + +map wallet_api::list_accounts(const string& lowerbound, uint32_t limit) +{ + return my->_remote_db->lookup_accounts(lowerbound, limit); +} + +vector wallet_api::search_accounts(const string& term, const string& order, const string& id, uint32_t limit) +{ + return my->_remote_db->search_accounts(term, order, object_id_type(id), limit); +} + +vector wallet_api::list_account_balances(const string& id) +{ + if( auto real_id = detail::maybe_id(id) ) + return my->_remote_db->get_account_balances(*real_id, flat_set()); + return my->_remote_db->get_account_balances(get_account(id).id, flat_set()); +} + +vector wallet_api::get_account_history(string name, int limit)const +{ + vector result; + auto account_id = get_account(name).get_id(); + + while( limit > 0 ) + { + operation_history_id_type start; + if( result.size() ) + { + start = result.back().op.id; + start = start + 1; + } + + + vector current = my->_remote_hist->get_account_history(account_id, operation_history_id_type(), std::min(100,limit), start); + for( auto& o : current ) { + std::stringstream ss; + auto memo = o.op.visit(detail::operation_printer(ss, *my, o.result)); + result.push_back( operation_detail{ memo, ss.str(), o } ); + } + if( current.size() < std::min(100,limit) ) + break; + limit -= current.size(); + } + + return result; +} + +vector wallet_api::get_relative_account_history(string name, + uint32_t stop, + int limit, + uint32_t start)const +{ + vector result; + auto account_id = get_account(name).get_id(); + + vector current = my->_remote_hist->get_relative_account_history(account_id, stop, limit, start); + for( auto& o : current ) { + std::stringstream ss; + auto memo = o.op.visit(detail::operation_printer(ss, *my, o.result)); + result.push_back( operation_detail{ memo, ss.str(), o } ); + } + + return result; +} + +vector wallet_api::search_account_history(string const& account_name, + string const& order, + string const& id, + int limit) const +{ + vector result; + try + { + account_object account = get_account(account_name); + result = my->_remote_db->search_account_history(account.id, order, object_id_type(id), limit); + + for (auto& item : result) + { + auto const& memo = item.m_transaction_encrypted_memo; + if (memo) + { + item.m_str_description += " - "; + auto it = my->_keys.find(memo->to); + if (it == my->_keys.end()) + // memo is encrypted for someone else + item.m_str_description += "{encrypted}"; + else + { + // here the memo is encrypted for me + // so I can decrypt it + string mykey = it->second; + auto wtok = *wif_to_key(mykey); + string str_memo = + memo->get_message(wtok, memo->from); + + item.m_str_description += str_memo; + } + } + } + } + catch(...){} + + return result; +} + +account_object wallet_api::get_account(string account_name_or_id) const +{ + return my->get_account(account_name_or_id); +} + +brain_key_info wallet_api::suggest_brain_key()const +{ + brain_key_info result; + // create a private key for secure entropy + fc::sha256 sha_entropy1 = fc::ecc::private_key::generate().get_secret(); + fc::sha256 sha_entropy2 = fc::ecc::private_key::generate().get_secret(); + fc::bigint entropy1( sha_entropy1.data(), sha_entropy1.data_size() ); + fc::bigint entropy2( sha_entropy2.data(), sha_entropy2.data_size() ); + fc::bigint entropy(entropy1); + entropy <<= 8*sha_entropy1.data_size(); + entropy += entropy2; + string brain_key; + + for( int i=0; i 0 ) + brain_key += " "; + brain_key += graphene::words::word_list[ choice.to_int64() ]; + } + + brain_key = detail::normalize_brain_key(brain_key); + fc::ecc::private_key priv_key = derive_private_key( brain_key, 0 ); + result.brain_priv_key = brain_key; + result.wif_priv_key = key_to_wif( priv_key ); + result.pub_key = priv_key.get_public_key(); + return result; +} + + +signed_transaction wallet_api::register_account(string name, + public_key_type owner_pubkey, + public_key_type active_pubkey, + string registrar_account, + bool broadcast) +{ + return my->register_account( name, owner_pubkey, active_pubkey, registrar_account, broadcast ); +} + +signed_transaction wallet_api::create_account_with_brain_key(string brain_key, + string account_name, + string registrar_account, + bool broadcast /* = false */) +{ + return my->create_account_with_brain_key( + brain_key, account_name, registrar_account, true, + broadcast); +} + +el_gamal_key_pair wallet_api::generate_el_gamal_keys() const +{ + el_gamal_key_pair ret; + ret.private_key = decent::encrypt::generate_private_el_gamal_key(); + ret.public_key = decent::encrypt::get_public_el_gamal_key( ret.private_key ); + return ret; +} + +el_gamal_key_pair_str wallet_api::get_el_gammal_key(string const& consumer) const +{ + try + { + FC_ASSERT( !is_locked() ); + + account_object consumer_account = get_account( consumer ); + el_gamal_key_pair_str res; + + res.private_key = generate_private_el_gamal_key_from_secret ( my->get_private_key_for_account(consumer_account).get_secret() ); + res.public_key = decent::encrypt::get_public_el_gamal_key( res.private_key ); + return res; + } FC_CAPTURE_AND_RETHROW( (consumer) ) +} + +pair wallet_api::generate_brain_key_el_gamal_key() const +{ + pair ret; + ret.first = suggest_brain_key(); + + fc::optional op_private_key = wif_to_key(ret.first.wif_priv_key); + FC_ASSERT(op_private_key); + ret.second.private_key = generate_private_el_gamal_key_from_secret ( op_private_key->get_secret() ); + ret.second.public_key = decent::encrypt::get_public_el_gamal_key( ret.second.private_key ); + + return ret; +} + +brain_key_info wallet_api::get_brain_key_info(string const& brain_key) const +{ + brain_key_info result; + + string str_brain_key = detail::normalize_brain_key(brain_key); + fc::ecc::private_key priv_key = derive_private_key( str_brain_key, 0 ); + result.brain_priv_key = str_brain_key; + result.wif_priv_key = key_to_wif( priv_key ); + result.pub_key = priv_key.get_public_key(); + return result; +} + +signed_transaction wallet_api::transfer(string from, string to, string amount, + string asset_symbol, string memo, bool broadcast /* = false */) +{ + return my->transfer(from, to, amount, asset_symbol, memo, broadcast); +} + + diff --git a/libraries/wallet/wallet_assets.inl b/libraries/wallet/wallet_assets.inl new file mode 100644 index 00000000..b71581c8 --- /dev/null +++ b/libraries/wallet/wallet_assets.inl @@ -0,0 +1,121 @@ + +vector wallet_api::list_assets(const string& lowerbound, uint32_t limit)const +{ + return my->_remote_db->list_assets( lowerbound, limit ); +} + +asset_object wallet_api::get_asset(string asset_name_or_id) const +{ + auto a = my->find_asset(asset_name_or_id); + FC_ASSERT(a); + return *a; +} + +monitored_asset_options wallet_api::get_monitored_asset_data(string asset_name_or_id) const +{ + auto asset = get_asset(asset_name_or_id); + FC_ASSERT(asset.is_monitored_asset() ); + return *asset.monitored_asset_opts; +} + +signed_transaction wallet_api::create_monitored_asset(string issuer, + string symbol, + uint8_t precision, + string description, + uint32_t feed_lifetime_sec, + uint8_t minimum_feeds, + bool broadcast) + +{ + return my->create_monitored_asset(issuer, symbol, precision, description, feed_lifetime_sec, minimum_feeds, broadcast); +} + +signed_transaction wallet_api::update_monitored_asset(string symbol, + string description, + uint32_t feed_lifetime_sec, + uint8_t minimum_feeds, + bool broadcast /* = false */) +{ + return my->update_monitored_asset(symbol, description, feed_lifetime_sec, minimum_feeds, broadcast); +} + +signed_transaction wallet_api::create_user_issued_asset(string issuer, + string symbol, + uint8_t precision, + string description, + uint64_t max_supply, + price core_exchange_rate, + bool is_exchangeable, + bool broadcast /* = false */) +{ + return my->create_user_issued_asset(issuer, symbol, precision, description, max_supply, core_exchange_rate, is_exchangeable, broadcast); +} + +signed_transaction wallet_api::issue_asset(string to_account, string amount, string symbol, + string memo, bool broadcast) +{ + return my->issue_asset(to_account, amount, symbol, memo, broadcast); +} + +signed_transaction wallet_api::update_user_issued_asset(string symbol, + string new_issuer, + string description, + uint64_t max_supply, + price core_exchange_rate, + bool is_exchangeable, + bool broadcast /* = false */) +{ + return my->update_user_issued_asset(symbol, new_issuer, description, max_supply, core_exchange_rate, is_exchangeable, broadcast); +} + +signed_transaction wallet_api::fund_asset_pools(string from, + string uia_amount, + string uia_symbol, + string DCT_amount, + string DCT_symbol, + bool broadcast /* = false */) +{ + return my->fund_asset_pools(from, uia_amount, uia_symbol, DCT_amount, DCT_symbol, broadcast); +} + +signed_transaction wallet_api::reserve_asset(string from, + string amount, + string symbol, + bool broadcast /* = false */) +{ + return my->reserve_asset(from, amount, symbol, broadcast); +} + +string wallet_api::price_to_dct(const string& amount, const string& asset_symbol_or_id) +{ + return my->price_to_dct(amount, asset_symbol_or_id ); +} + +signed_transaction wallet_api::claim_fees(string uia_amount, + string uia_symbol, + string dct_amount, + string dct_symbol, + bool broadcast /* = false */) +{ + return my->claim_fees( uia_amount, uia_symbol, dct_amount, dct_symbol, broadcast); +} + +signed_transaction wallet_api::publish_asset_feed(string publishing_account, + string symbol, + price_feed feed, + bool broadcast /* = false */) +{ + return my->publish_asset_feed(publishing_account, symbol, feed, broadcast); +} + +multimap wallet_api::get_feeds_by_miner(const string& account_name_or_id, + const uint32_t count) +{ + account_id_type account_id = get_account( account_name_or_id ).id; + return my->_remote_db->get_feeds_by_miner( account_id, count ); +} + +real_supply wallet_api::get_real_supply()const +{ + return my->_remote_db->get_real_supply(); +} diff --git a/libraries/wallet/wallet_content.inl b/libraries/wallet/wallet_content.inl new file mode 100644 index 00000000..7065a03e --- /dev/null +++ b/libraries/wallet/wallet_content.inl @@ -0,0 +1,324 @@ + +signed_transaction wallet_api::submit_content(string const& author, + vector< pair< string, uint32_t>> co_authors, + string const& URI, + vector const& price_amounts, + uint64_t size, + fc::ripemd160 const& hash, + vector const& seeders, + uint32_t quorum, + fc::time_point_sec const& expiration, + string const& publishing_fee_asset, + string const& publishing_fee_amount, + string const& synopsis, + DInteger const& secret, + decent::encrypt::CustodyData const& cd, + bool broadcast) +{ + return my->submit_content(author, co_authors, URI, price_amounts, hash, size, seeders, quorum, expiration, publishing_fee_asset, publishing_fee_amount, synopsis, secret, cd, broadcast); +} + +void wallet_api::submit_content_async(string const &author, vector< pair< string, uint32_t>> co_authors, + string const &content_dir, string const &samples_dir, + string const &protocol, + vector const &price_amounts, + vector const &seeders, + fc::time_point_sec const &expiration, string const &synopsis) +{ + return my->submit_content_async(author, co_authors, content_dir, samples_dir, protocol, price_amounts, seeders, expiration, synopsis); + +} + +signed_transaction wallet_api::content_cancellation(string author, + string URI, + bool broadcast) +{ + return my->content_cancellation(author, URI, broadcast); +} + +void wallet_api::download_content(string const& consumer, string const& URI, string const& region_code_from, bool broadcast) +{ + return my->download_content(consumer, URI, region_code_from, broadcast); +} + +optional wallet_api::get_download_status(string consumer, + string URI) const +{ + return my->get_download_status(consumer, URI); +} + +signed_transaction wallet_api::request_to_buy(string consumer, + string URI, + string price_asset_name, + string price_amount, + string str_region_code_from, + bool broadcast) +{ + return my->request_to_buy(consumer, URI, price_asset_name, price_amount, str_region_code_from, broadcast); +} + +void wallet_api::seeding_startup(string account_id_type_or_name, + DInteger content_private_key, + string seeder_private_key, + uint64_t free_space, + uint32_t seeding_price, + string seeding_symbol, + string packages_path, + string region_code) +{ + return my->seeding_startup(account_id_type_or_name, content_private_key, seeder_private_key, free_space, seeding_price, seeding_symbol, packages_path, region_code); +} + +void wallet_api::leave_rating_and_comment(string consumer, + string URI, + uint64_t rating, + string comment, + bool broadcast) +{ + return my->leave_rating_and_comment(consumer, URI, rating, comment, broadcast); +} + +DInteger wallet_api::restore_encryption_key(string consumer, buying_id_type buying) +{ + return my->restore_encryption_key(consumer, buying); +} + +DInteger wallet_api::generate_encryption_key() const +{ + CryptoPP::Integer secret(randomGenerator, 256); + return secret; +} + + +vector wallet_api::get_open_buyings()const +{ + return my->_remote_db->get_open_buyings(); +} + +vector wallet_api::get_open_buyings_by_URI( const string& URI )const +{ + return my->_remote_db->get_open_buyings_by_URI( URI ); +} + +vector wallet_api::get_open_buyings_by_consumer( const string& account_id_or_name )const +{ + account_id_type consumer = get_account( account_id_or_name ).id; + return my->_remote_db->get_open_buyings_by_consumer( consumer ); +} + +vector wallet_api::get_buying_history_objects_by_consumer( const string& account_id_or_name )const +{ + account_id_type consumer = get_account( account_id_or_name ).id; + vector result = my->_remote_db->get_buying_history_objects_by_consumer( consumer ); + + for (int i = 0; i < result.size(); ++i) + { + buying_object& bobj = result[i]; + + optional content = my->_remote_db->get_content( bobj.URI ); + if (!content) + continue; + optional op_price = content->price.GetPrice(bobj.region_code_from); + if (!op_price) + continue; + + bobj.price = *op_price; + + bobj.size = content->size; + bobj.rating = content->AVG_rating; + bobj.synopsis = content->synopsis; + + } + return result; +} + + +vector wallet_api::search_my_purchases(const string& account_id_or_name, + const string& term, + const string& order, + const string& id, + uint32_t count)const +{ + account_id_type consumer = get_account( account_id_or_name ).id; + vector bobjects = my->_remote_db->get_buying_objects_by_consumer(consumer, order, object_id_type(id), term, count ); + vector result; + + for (size_t i = 0; i < bobjects.size(); ++i) + { + buying_object const& buyobj = bobjects[i]; + + optional status = get_download_status(account_id_or_name, buyobj.URI); + if (!status) + continue; + + optional content = my->_remote_db->get_content( buyobj.URI ); + if (!content) + continue; + + result.emplace_back(buying_object_ex(bobjects[i], *status)); + buying_object_ex& bobj = result.back(); + + bobj.author_account = my->get_account(content->author).name; + bobj.times_bought = content->times_bought; + bobj.hash = content->_hash; + bobj.AVG_rating = content->AVG_rating; + bobj.rating = content->AVG_rating; + } + + return result; +} + +optional wallet_api::get_buying_by_consumer_URI( const string& account_id_or_name, const string & URI )const +{ + account_id_type account = get_account( account_id_or_name ).id; + return my->_remote_db->get_buying_by_consumer_URI( account, URI ); +} + +vector wallet_api::search_feedback(const string& user, + const string& URI, + const string& id, + uint32_t count) const +{ + vector result; + vector temp = my->_remote_db->search_feedback(user, URI, object_id_type(id), count); + + for (auto const& item : temp) + result.push_back(rating_object_ex( item, get_account(string(object_id_type(item.consumer))).name )); + + return result; +} + +optional wallet_api::get_content( const string& URI )const +{ + return my->_remote_db->get_content( URI ); +} + + +vector wallet_api::search_content(const string& term, + const string& order, + const string& user, + const string& region_code, + const string& id, + const string& type, + uint32_t count)const +{ + return my->_remote_db->search_content(term, order, user, region_code, object_id_type(id), type, count); +} + +vector wallet_api::search_user_content(const string& user, + const string& term, + const string& order, + const string& region_code, + const string& id, + const string& type, + uint32_t count)const +{ + vector result = my->_remote_db->search_content(term, order, user, region_code, object_id_type(id), type, count); + + auto packages = PackageManager::instance().get_all_known_packages(); + for (auto package: packages) + { + auto state = package->get_manipulation_state(); + + if (package->get_data_state() == PackageInfo::CHECKED){ + bool cont = false; + auto hash = package->get_hash(); + for( const auto& item : result ) + if( item._hash == hash ) + cont = true; + if(cont) + continue; + } + + bool cont = false; + for (auto listener: my->_package_manager_listeners) + { + + if (listener->get_hash() == package->get_hash()) + { + cont = true; + content_summary newObject; + newObject.synopsis = listener->op().synopsis; + newObject.expiration = listener->op().expiration; + newObject.author = my->get_account( listener->op().author ).name; + + if (state == PackageInfo::PACKING) { + newObject.status = "Packing"; + } else if (state == PackageInfo::ENCRYPTING) { + newObject.status = "Encrypting"; + } else if (state == PackageInfo::STAGING) { + newObject.status = "Staging"; + } else if (state == PackageInfo:: MS_IDLE ) + newObject.status = "Submission failed"; + + result.insert(result.begin(), newObject); + } + } + if (cont) + continue; + } + + return result; +} + +pair> wallet_api::get_author_and_co_authors_by_URI( const string& URI )const +{ + return my->get_author_and_co_authors_by_URI( URI ); +} + +std::pair wallet_api::create_package(const std::string& content_dir, const std::string& samples_dir, const DInteger& aes_key) const +{ + FC_ASSERT(!is_locked()); + fc::sha256 key1; + aes_key.Encode((byte*)key1._hash, 32); + + uint32_t sectors; + if(my->head_block_time()>HARDFORK_1_TIME) + sectors = DECENT_SECTORS; + else + sectors = DECENT_SECTORS_BIG; + auto pack = PackageManager::instance().get_package(content_dir, samples_dir, key1, sectors); + decent::encrypt::CustodyData cd = pack->get_custody_data(); + return std::pair(pack->get_hash().str(), cd); +} + +void wallet_api::extract_package(const std::string& package_hash, const std::string& output_dir, const DInteger& aes_key) const +{ + FC_ASSERT(!is_locked()); + fc::sha256 key1; + aes_key.Encode((byte*)key1._hash, 32); + + auto pack = PackageManager::instance().find_package(fc::ripemd160(package_hash)); + if (pack == nullptr) { + FC_THROW("Can not find package"); + } + + if (pack->get_manipulation_state() != PackageInfo::ManipulationState::MS_IDLE) { + FC_THROW("Package is not in valid state"); + } + pack->unpack(output_dir, key1); +} + +void wallet_api::download_package(const std::string& url) const +{ + FC_ASSERT(!is_locked()); + auto content = get_content(url); + FC_ASSERT(content, "no such package in the system"); + auto pack = PackageManager::instance().get_package(url, content->_hash ); + pack->download(false); +} + +std::string wallet_api::upload_package(const std::string& package_hash, const std::string& protocol) const +{ + FC_ASSERT(!is_locked()); + auto package = PackageManager::instance().get_package(fc::ripemd160(package_hash)); + package->start_seeding(protocol, true); + return package->get_url(); +} + +void wallet_api::remove_package(const std::string& package_hash) const +{ + FC_ASSERT(!is_locked()); + PackageManager::instance().release_package(fc::ripemd160(package_hash)); +} + diff --git a/libraries/wallet/wallet_general.inl b/libraries/wallet/wallet_general.inl new file mode 100644 index 00000000..f53dc96d --- /dev/null +++ b/libraries/wallet/wallet_general.inl @@ -0,0 +1,187 @@ + + +variant_object wallet_api::about() const +{ + return my->about(); +} + +optional wallet_api::get_block(uint32_t num) +{ + optional result = my->_remote_db->get_block(num); + + share_type miner_pay_from_reward = 0; + share_type miner_pay_from_fees = 0; + + //int64_t time_to_maint = my->_remote_db->get_time_to_maint_by_block_time(result->timestamp);//(dpo.next_maintenance_time - dpo.last_budget_time).to_seconds(); + miner_reward_input mri = my->_remote_db->get_time_to_maint_by_block_time(result->timestamp); + int64_t time_to_maint = mri.time_to_maint; + uint32_t blocks_in_interval = (uint64_t(time_to_maint) + mri.block_interval - 1) / mri.block_interval; + + if (blocks_in_interval > 0) { + miner_pay_from_fees = mri.from_accumulated_fees / blocks_in_interval; + } + miner_pay_from_reward = my->_remote_db->get_asset_per_block_by_block_num(num); + + //this should never happen, but better check. + if (miner_pay_from_fees < share_type(0)) + miner_pay_from_fees = share_type(0); + + result->miner_reward = miner_pay_from_fees + miner_pay_from_reward; + + return result; +} + +global_property_object wallet_api::get_global_properties() const +{ + return my->get_global_properties(); +} + +dynamic_global_property_object wallet_api::get_dynamic_global_properties() const +{ + return my->get_dynamic_global_properties(); +} + +variant wallet_api::get_object( object_id_type id ) const +{ + return my->_remote_db->get_objects({id}); +} + +variant wallet_api::info() +{ + return my->info(); +} + + +string wallet_api::help()const +{ + std::vector method_names = my->method_documentation.get_method_names(); + std::stringstream ss; + for (const std::string method_name : method_names) + { + try + { + ss << my->method_documentation.get_brief_description(method_name); + } + catch (const fc::key_not_found_exception&) + { + ss << method_name << " (no help available)\n"; + } + } + return ss.str(); +} + +string wallet_api::gethelp(const string& method)const +{ + fc::api tmp; + std::stringstream ss; + ss << "\n"; + + if( method == "import_key" ) + { + ss << "usage: import_key ACCOUNT_NAME_OR_ID WIF_PRIVATE_KEY\n\n"; + ss << "example: import_key \"1.2.11\" 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3\n"; + ss << "example: import_key \"usera\" 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3\n"; + } + else if( method == "transfer" ) + { + ss << "usage: transfer FROM TO AMOUNT SYMBOL \"memo\" BROADCAST\n\n"; + ss << "example: transfer \"1.2.11\" \"1.2.4\" 1000.03 DCT \"memo\" true\n"; + ss << "example: transfer \"usera\" \"userb\" 1000.123 DCT \"memo\" true\n"; + } + else if( method == "create_account_with_brain_key" ) + { + ss << "usage: create_account_with_brain_key BRAIN_KEY ACCOUNT_NAME REGISTRAR BROADCAST\n\n"; + ss << "example: create_account_with_brain_key \"my really long brain key\" \"newaccount\" \"1.2.11\" true\n"; + ss << "example: create_account_with_brain_key \"my really long brain key\" \"newaccount\" \"someaccount\" true\n"; + ss << "\n"; + ss << "This method should be used if you would like the wallet to generate new keys derived from the brain key.\n"; + ss << "The BRAIN_KEY will be used as the owner key, and the active key will be derived from the BRAIN_KEY. Use\n"; + ss << "register_account if you already know the keys you know the public keys that you would like to register.\n"; + + } + else if( method == "register_account" ) + { + ss << "usage: register_account ACCOUNT_NAME OWNER_PUBLIC_KEY ACTIVE_PUBLIC_KEY REGISTRAR BROADCAST\n\n"; + ss << "example: register_account \"newaccount\" \"CORE6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV\" \"CORE6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV\" \"1.3.11\" true\n"; + ss << "\n"; + ss << "Use this method to register an account for which you do not know the private keys."; + } + else if( method == "create_monitored_asset" ) + { + ss << "usage: ISSUER SYMBOL PRECISION DESCRIPTION FEED_LIFETIME_SEC MINIMUM_FEEDS BROADCAST\n\n"; + ss << "PRECISION: the number of digits after the decimal point\n\n"; + + ss << "\nExample value of MONITORED ASSET_OPTIONS: \n"; + ss << fc::json::to_pretty_string( graphene::chain::monitored_asset_options() ); + } + else + { + std::string doxygenHelpString = my->method_documentation.get_detailed_description(method); + if (!doxygenHelpString.empty()) + ss << doxygenHelpString; + else + ss << "No help defined for method " << method << "\n"; + } + + return ss.str(); +} + +fc::time_point_sec wallet_api::head_block_time() const +{ + return my->head_block_time(); +} + + +void wallet_api::network_add_nodes( const vector& nodes ) +{ + my->network_add_nodes( nodes ); +} + +vector< variant > wallet_api::network_get_connected_peers() +{ + return my->network_get_connected_peers(); +} + + +std::string wallet_api::sign_buffer(std::string const& str_buffer, + std::string const& str_brainkey) const +{ + if (str_buffer.empty() || + str_brainkey.empty()) + throw std::runtime_error("You need buffer and brainkey to sign"); + + string normalized_brain_key = detail::normalize_brain_key( str_brainkey ); + fc::ecc::private_key privkey = derive_private_key( normalized_brain_key, 0 ); + + fc::sha256 digest(str_buffer); + + auto sign = privkey.sign_compact(digest); + + return fc::to_hex((const char*)sign.begin(), sign.size()); +} + + +bool wallet_api::verify_signature(std::string const& str_buffer, + std::string const& str_publickey, + std::string const& str_signature) const +{ + if (str_buffer.empty() || + str_publickey.empty() || + str_signature.empty()) + throw std::runtime_error("You need buffer, public key and signature to verify"); + + fc::ecc::compact_signature signature; + fc::from_hex(str_signature, (char*)signature.begin(), signature.size()); + fc::sha256 digest(str_buffer); + + fc::ecc::public_key pub_key(signature, digest); + public_key_type provided_key(str_publickey); + + if (provided_key == pub_key) + return true; + else + return false; +} + + + diff --git a/libraries/wallet/wallet_messaging.inl b/libraries/wallet/wallet_messaging.inl new file mode 100644 index 00000000..451db417 --- /dev/null +++ b/libraries/wallet/wallet_messaging.inl @@ -0,0 +1,27 @@ + +void wallet_api::send_message(const std::string& from, std::vector to, string text) +{ + return my->send_message(from, to, text); +} + +vector wallet_api::get_message_objects(const std::string& sender, const std::string& receiver, uint32_t max_count) const +{ + optional receiver_id; + if(receiver.size()) + receiver_id = get_account(receiver).get_id(); + optional sender_id; + if(sender.size()) + sender_id = get_account(sender).get_id(); + return my->get_message_objects(sender_id, receiver_id, max_count); +} + +vector wallet_api::get_messages(const std::string& receiver, uint32_t max_count) const +{ + return my->get_messages(receiver, max_count); +} + +vector wallet_api::get_sent_messages(const std::string& sender, uint32_t max_count) const +{ + return my->get_sent_messages(sender, max_count); +} + diff --git a/libraries/wallet/wallet_mining.inl b/libraries/wallet/wallet_mining.inl new file mode 100644 index 00000000..2b4768f6 --- /dev/null +++ b/libraries/wallet/wallet_mining.inl @@ -0,0 +1,63 @@ + +map wallet_api::list_miners(const string& lowerbound, uint32_t limit) +{ + return my->_remote_db->lookup_miner_accounts(lowerbound, limit); +} + +miner_object wallet_api::get_miner(string owner_account) +{ + return my->get_miner(owner_account); +} + +signed_transaction wallet_api::create_miner(string owner_account, + string url, + bool broadcast /* = false */) +{ + return my->create_miner(owner_account, url, broadcast); +} + +signed_transaction wallet_api::update_miner( + string miner_name, + string url, + string block_signing_key, + bool broadcast /* = false */) +{ + return my->update_miner(miner_name, url, block_signing_key, broadcast); +} + +vector< vesting_balance_object_with_info > wallet_api::get_vesting_balances( string account_name ) +{ + return my->get_vesting_balances( account_name ); +} + +signed_transaction wallet_api::withdraw_vesting( + string miner_name, + string amount, + string asset_symbol, + bool broadcast /* = false */) +{ + return my->withdraw_vesting( miner_name, amount, asset_symbol, broadcast ); +} + +signed_transaction wallet_api::vote_for_miner(string voting_account, + string miner, + bool approve, + bool broadcast /* = false */) +{ + return my->vote_for_miner(voting_account, miner, approve, broadcast); +} + +signed_transaction wallet_api::set_voting_proxy(string account_to_modify, + optional voting_account, + bool broadcast /* = false */) +{ + return my->set_voting_proxy(account_to_modify, voting_account, broadcast); +} + +signed_transaction wallet_api::set_desired_miner_count(string account_to_modify, + uint16_t desired_number_of_miners, + bool broadcast /* = false */) +{ + return my->set_desired_miner_count(account_to_modify, desired_number_of_miners, broadcast); +} + diff --git a/libraries/wallet/wallet_proposals.inl b/libraries/wallet/wallet_proposals.inl new file mode 100644 index 00000000..92e1dcf3 --- /dev/null +++ b/libraries/wallet/wallet_proposals.inl @@ -0,0 +1,44 @@ + +vector wallet_api::get_proposed_transactions( string account_or_id )const +{ + account_id_type id = get_account(account_or_id).get_id(); + return my->_remote_db->get_proposed_transactions( id ); +} + +void wallet_api::propose_transfer(string proposer, + string from, + string to, + string amount, + string asset_symbol, + string memo, + time_point_sec expiration) +{ + return my->propose_transfer(proposer, from, to, amount, asset_symbol, memo, expiration); +} + +signed_transaction wallet_api::propose_parameter_change( + const string& proposing_account, + fc::time_point_sec expiration_time, + const variant_object& changed_values, + bool broadcast /* = false */) +{ + return my->propose_parameter_change( proposing_account, expiration_time, changed_values, broadcast ); +} + +signed_transaction wallet_api::propose_fee_change( + const string& proposing_account, + fc::time_point_sec expiration_time, + const variant_object& changed_fees, + bool broadcast /* = false */) +{ + return my->propose_fee_change( proposing_account, expiration_time, changed_fees, broadcast ); +} + +signed_transaction wallet_api::approve_proposal( + const string& fee_paying_account, + const string& proposal_id, + const approval_delta& delta, + bool broadcast /* = false */) +{ + return my->approve_proposal( fee_paying_account, proposal_id, delta, broadcast ); +} diff --git a/libraries/wallet/wallet_subscription.inl b/libraries/wallet/wallet_subscription.inl new file mode 100644 index 00000000..0fc136ca --- /dev/null +++ b/libraries/wallet/wallet_subscription.inl @@ -0,0 +1,59 @@ + +signed_transaction wallet_api::subscribe_to_author( string from, + string to, + string price_amount, + string price_asset_symbol, + bool broadcast/* = false */) +{ + return my->subscribe_to_author(from, to, price_amount, price_asset_symbol, broadcast); +} + +signed_transaction wallet_api::subscribe_by_author( string from, + string to, + bool broadcast/* = false */) +{ + return my->subscribe_by_author(from, to, broadcast); +} + +signed_transaction wallet_api::set_subscription( string account, + bool allow_subscription, + uint32_t subscription_period, + string price_amount, + string price_asset_symbol, + bool broadcast/* = false */) +{ + return my->set_subscription(account, allow_subscription, subscription_period, price_amount, price_asset_symbol, broadcast); +} + +signed_transaction wallet_api::set_automatic_renewal_of_subscription( string account_id_or_name, + subscription_id_type subscription_id, + bool automatic_renewal, + bool broadcast/* = false */) +{ + return my->set_automatic_renewal_of_subscription(account_id_or_name, subscription_id, automatic_renewal, broadcast); +} + +vector< subscription_object > wallet_api::list_active_subscriptions_by_consumer( const string& account_id_or_name, const uint32_t count) const +{ + account_id_type account = get_account( account_id_or_name ).id; + return my->_remote_db->list_active_subscriptions_by_consumer( account, count); +} + +vector< subscription_object > wallet_api::list_subscriptions_by_consumer( const string& account_id_or_name, const uint32_t count) const +{ + account_id_type account = get_account( account_id_or_name ).id; + return my->_remote_db->list_subscriptions_by_consumer( account, count); +} + +vector< subscription_object > wallet_api::list_active_subscriptions_by_author( const string& account_id_or_name, const uint32_t count) const +{ + account_id_type account = get_account( account_id_or_name ).id; + return my->_remote_db->list_active_subscriptions_by_author( account, count); +} + +vector< subscription_object > wallet_api::list_subscriptions_by_author( const string& account_id_or_name, const uint32_t count) const +{ + account_id_type account = get_account( account_id_or_name ).id; + return my->_remote_db->list_subscriptions_by_author( account, count); +} + diff --git a/libraries/wallet/wallet_transaction_builder.inl b/libraries/wallet/wallet_transaction_builder.inl new file mode 100644 index 00000000..5e719508 --- /dev/null +++ b/libraries/wallet/wallet_transaction_builder.inl @@ -0,0 +1,72 @@ + +transaction_handle_type wallet_api::begin_builder_transaction() +{ + return my->begin_builder_transaction(); +} + +void wallet_api::add_operation_to_builder_transaction(transaction_handle_type transaction_handle, const operation& op) +{ + my->add_operation_to_builder_transaction(transaction_handle, op); +} + +void wallet_api::replace_operation_in_builder_transaction(transaction_handle_type handle, unsigned operation_index, const operation& new_op) +{ + my->replace_operation_in_builder_transaction(handle, operation_index, new_op); +} + +asset wallet_api::set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset) +{ + return my->set_fees_on_builder_transaction(handle, fee_asset); +} + +transaction wallet_api::preview_builder_transaction(transaction_handle_type handle) +{ + return my->preview_builder_transaction(handle); +} + +signed_transaction wallet_api::sign_builder_transaction(transaction_handle_type transaction_handle, bool broadcast) +{ + return my->sign_builder_transaction(transaction_handle, broadcast); +} + +signed_transaction wallet_api::propose_builder_transaction( + transaction_handle_type handle, + time_point_sec expiration, + uint32_t review_period_seconds, + bool broadcast) +{ + return my->propose_builder_transaction(handle, expiration, review_period_seconds, broadcast); +} + +signed_transaction wallet_api::propose_builder_transaction2( + transaction_handle_type handle, + string account_name_or_id, + time_point_sec expiration, + uint32_t review_period_seconds, + bool broadcast) +{ + return my->propose_builder_transaction2(handle, account_name_or_id, expiration, review_period_seconds, broadcast); +} + +void wallet_api::remove_builder_transaction(transaction_handle_type handle) +{ + return my->remove_builder_transaction(handle); +} + +string wallet_api::serialize_transaction( signed_transaction tx )const +{ + return fc::to_hex(fc::raw::pack(tx)); +} + +signed_transaction wallet_api::sign_transaction(signed_transaction tx, bool broadcast /* = false */) +{ + try { + return my->sign_transaction( tx, broadcast); + } FC_CAPTURE_AND_RETHROW( (tx) ) +} + +operation wallet_api::get_prototype_operation(string operation_name) +{ + return my->get_prototype_operation( operation_name ); +} + diff --git a/libraries/wallet/wallet_wallet_file.inl b/libraries/wallet/wallet_wallet_file.inl new file mode 100644 index 00000000..bdd8cc8c --- /dev/null +++ b/libraries/wallet/wallet_wallet_file.inl @@ -0,0 +1,223 @@ + +vector wallet_api::list_my_accounts() +{ + return vector(my->_wallet.my_accounts.begin(), my->_wallet.my_accounts.end()); +} + +string wallet_api::get_wallet_filename() const +{ + return my->get_wallet_filename(); +} + +string wallet_api::get_private_key( public_key_type pubkey )const +{ + return key_to_wif( my->get_private_key( pubkey ) ); +} + +bool wallet_api::is_new()const +{ + return my->_wallet.cipher_keys.size() == 0; +} + +bool wallet_api::is_locked()const +{ + return my->is_locked(); +} + +void wallet_api::lock() +{ try { + FC_ASSERT( !is_locked() ); + encrypt_keys(); + for( auto & key : my->_keys ) + key.second = key_to_wif(fc::ecc::private_key()); + my->_keys.clear(); + my->_checksum = fc::sha512(); + my->self.lock_changed(true); +} FC_CAPTURE_AND_RETHROW() } + +void wallet_api::unlock(string password) +{ try { + FC_ASSERT(password.size() > 0); + auto pw = fc::sha512::hash(password.c_str(), password.size()); + vector decrypted = fc::aes_decrypt(pw, my->_wallet.cipher_keys); + auto pk = fc::raw::unpack(decrypted); + FC_ASSERT(pk.checksum == pw); + my->_keys = std::move(pk.keys); + my->_checksum = pk.checksum; + my->self.lock_changed(false); +} FC_CAPTURE_AND_RETHROW() } + +void wallet_api::set_password( string password ) +{ + if( !is_new() ) + FC_ASSERT( !is_locked(), "The wallet must be unlocked before the password can be set" ); + my->_checksum = fc::sha512::hash( password.c_str(), password.size() ); + lock(); +} + +bool wallet_api::load_wallet_file( string wallet_filename ) +{ + return my->load_wallet_file( wallet_filename ); +} + +void wallet_api::save_wallet_file( string wallet_filename ) +{ + my->save_wallet_file( wallet_filename ); +} + +void wallet_api::set_wallet_filename(string wallet_filename) +{ + my->_wallet_filename = wallet_filename; +} + +bool wallet_api::import_key(string account_name_or_id, string wif_key) +{ + FC_ASSERT(!is_locked()); + // backup wallet + fc::optional optional_private_key = wif_to_key(wif_key); + if (!optional_private_key) + FC_THROW("Invalid private key"); + string base58_public_key = optional_private_key->get_public_key().to_base58(); +// copy_wallet_file( "before-import-key-" + base58_public_key ); + + if( my->import_key(account_name_or_id, wif_key) ) + { + save_wallet_file(); +// copy_wallet_file( "after-import-key-" + base58_public_key ); + return true; + } + return false; +} + +//obsolete +map wallet_api::import_accounts( string filename, string password ) +{ + FC_ASSERT( !is_locked() ); + FC_ASSERT( fc::exists( filename ) ); + + const auto imported_keys = fc::json::from_file( filename ); + + const auto password_hash = fc::sha512::hash( password ); + FC_ASSERT( fc::sha512::hash( password_hash ) == imported_keys.password_checksum ); + + map result; + for( const auto& item : imported_keys.account_keys ) + { + const auto import_this_account = [ & ]() -> bool + { + try + { + const account_object account = get_account( item.account_name ); + const auto& owner_keys = account.owner.get_keys(); + const auto& active_keys = account.active.get_keys(); + + for( const auto& public_key : item.public_keys ) + { + if( std::find( owner_keys.begin(), owner_keys.end(), public_key ) != owner_keys.end() ) + return true; + + if( std::find( active_keys.begin(), active_keys.end(), public_key ) != active_keys.end() ) + return true; + } + } + catch( ... ) + { + } + + return false; + }; + + const auto should_proceed = import_this_account(); + result[ item.account_name ] = should_proceed; + + if( should_proceed ) + { + uint32_t import_successes = 0; + uint32_t import_failures = 0; + // TODO: First check that all private keys match public keys + for( const auto& encrypted_key : item.encrypted_private_keys ) + { + try + { + const auto plain_text = fc::aes_decrypt( password_hash, encrypted_key ); + const auto private_key = fc::raw::unpack( plain_text ); + + import_key( item.account_name, string( graphene::utilities::key_to_wif( private_key ) ) ); + ++import_successes; + } + catch( const fc::exception& e ) + { + elog( "Couldn't import key due to exception ${e}", ("e", e.to_detail_string()) ); + ++import_failures; + } + } + ilog( "successfully imported ${n} keys for account ${name}", ("n", import_successes)("name", item.account_name) ); + if( import_failures > 0 ) + elog( "failed to import ${n} keys for account ${name}", ("n", import_failures)("name", item.account_name) ); + } + } + + return result; +} + +//obsolete +bool wallet_api::import_account_keys( string filename, string password, string src_account_name, string dest_account_name ) +{ + FC_ASSERT( !is_locked() ); + FC_ASSERT( fc::exists( filename ) ); + + bool is_my_account = false; + const auto accounts = list_my_accounts(); + for( const auto& account : accounts ) + { + if( account.name == dest_account_name ) + { + is_my_account = true; + break; + } + } + FC_ASSERT( is_my_account ); + + const auto imported_keys = fc::json::from_file( filename ); + + const auto password_hash = fc::sha512::hash( password ); + FC_ASSERT( fc::sha512::hash( password_hash ) == imported_keys.password_checksum ); + + bool found_account = false; + for( const auto& item : imported_keys.account_keys ) + { + if( item.account_name != src_account_name ) + continue; + + found_account = true; + + for( const auto& encrypted_key : item.encrypted_private_keys ) + { + const auto plain_text = fc::aes_decrypt( password_hash, encrypted_key ); + const auto private_key = fc::raw::unpack( plain_text ); + + my->import_key( dest_account_name, string( graphene::utilities::key_to_wif( private_key ) ) ); + } + + return true; + } + save_wallet_file(); + + FC_ASSERT( found_account ); + + return false; +} + +map wallet_api::dump_private_keys() +{ + FC_ASSERT(!is_locked()); + return my->_keys; +} + + + + + + + + From 5d5b9c4824ff039559b67006afc1c33ce2503406 Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Thu, 15 Feb 2018 16:57:33 +0100 Subject: [PATCH 048/136] Loading of blacklist on seeder plugin startup --- .../include/graphene/seeding/seeding.hpp | 8 ++++++++ libraries/plugins/seeding/seeding.cpp | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp b/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp index 8271de02..c29c15e3 100644 --- a/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp +++ b/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp @@ -76,6 +76,12 @@ class my_seeding_object : public graphene::db::abstract_object< my_seeding_objec }; }; +struct seeder_blacklist_cfg +{ + std::vector content_blacklist; +}; + + typedef graphene::chain::object_id< SEEDING_PLUGIN_SPACE_ID, seeding_object_type, my_seeding_object> my_seeding_id_type; typedef graphene::chain::object_id< SEEDING_PLUGIN_SPACE_ID, seeder_object_type, my_seeder_object> my_seeder_id_type; @@ -200,6 +206,7 @@ class seeding_plugin_impl /*: public package_transfer_interface::transfer_listen // std::map active_downloads; // service_thread; //The thread where the computation shall happen fc::thread* main_thread; //The main thread, used mainly for DB modifications + seeder_blacklist_cfg seeder_cfg; }; @@ -268,5 +275,6 @@ class seeding_plugin : public graphene::app::plugin FC_REFLECT_DERIVED( decent::seeding::my_seeder_object, (graphene::db::object), (seeder)(content_privKey)(privKey)(free_space)(region_code)(price)(symbol) ); FC_REFLECT_DERIVED( decent::seeding::my_seeding_object, (graphene::db::object), (URI)(expiration)(cd)(seeder)(key)(space)(downloaded)(deleted)(_hash) ); +FC_REFLECT(decent::seeding::seeder_blacklist_cfg, (content_blacklist)); diff --git a/libraries/plugins/seeding/seeding.cpp b/libraries/plugins/seeding/seeding.cpp index c67467b4..cd8229ed 100644 --- a/libraries/plugins/seeding/seeding.cpp +++ b/libraries/plugins/seeding/seeding.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -578,8 +577,6 @@ void seeding_plugin::plugin_startup() return; ilog("seeding plugin: plugin_startup() start"); - - my->restore_state(); fc::time_point next_call = fc::time_point::now() + fc::microseconds(30000000); elog("RtP planned at ${t}", ("t",next_call) ); @@ -685,6 +682,22 @@ void seeding_plugin::plugin_pre_startup( const seeding_plugin_startup_options& s ilog("starting service thread"); my = unique_ptr( new detail::seeding_plugin_impl( *this) ); + + // load blacklist + fc::path seeder_blacklist_path = graphene::utilities::decent_path_finder::instance().get_decent_home(); + seeder_blacklist_path = seeder_blacklist_path / "seeder"; + if (!fc::exists(seeder_blacklist_path)) + fc::create_directories(seeder_blacklist_path); + + seeder_blacklist_path = seeder_blacklist_path / "blacklist.json"; + std::string string_path = seeder_blacklist_path.string(); + try { + if (fc::exists(seeder_blacklist_path)) { + variant tmp = fc::json::from_file(seeder_blacklist_path); + my->seeder_cfg = tmp.as(); + } + } FC_CAPTURE_AND_LOG((string_path)); + my->service_thread = std::make_shared("seeding"); my->main_thread = &fc::thread::current(); From a4f40b3466d77b139d385f80b3cd2abb9910e4d6 Mon Sep 17 00:00:00 2001 From: Josef Sevcik Date: Fri, 5 Jan 2018 15:45:54 +0100 Subject: [PATCH 049/136] Update application.cpp --- libraries/app/application.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index c815db06..a0ea03a1 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -138,12 +138,8 @@ namespace detail { "seed1.decentgo.com:40000", "seed2.decentgo.com:40000", "seed3.decentgo.com:40000", - "decent.roelandp.nl:40000", // # roelandp (DE) - "5.9.18.213:40000", // # pfunk (DE) - "decent.rondonson.com:40000", // # rondonson (DE) "52.10.121.79:40000", // # liberosist (US) "decent.agoric.systems:46023", // # agoric.systems / robrigo (BR) - "45.124.64.161:40000", // # nuevax (HK) "66.70.188.105:40000" // # decentspace (CA) }; From a24046eb56585a7a2d5df0c5888163984c70d29d Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Mon, 19 Feb 2018 11:04:43 +0100 Subject: [PATCH 050/136] divided wallet API into separate header files, removed some obsolete functions --- .../include/graphene/wallet/account.hpp | 25 +++++++++++++++++++ .../wallet/include/graphene/wallet/assets.hpp | 25 +++++++++++++++++++ .../include/graphene/wallet/content.hpp | 25 +++++++++++++++++++ .../include/graphene/wallet/general.hpp | 25 +++++++++++++++++++ .../include/graphene/wallet/messaging.hpp | 25 +++++++++++++++++++ .../wallet/include/graphene/wallet/mining.hpp | 25 +++++++++++++++++++ .../include/graphene/wallet/proposals.hpp | 25 +++++++++++++++++++ .../include/graphene/wallet/seeding.hpp | 25 +++++++++++++++++++ .../include/graphene/wallet/subscription.hpp | 25 +++++++++++++++++++ .../graphene/wallet/transaction_builder.hpp | 25 +++++++++++++++++++ .../include/graphene/wallet/wallet_file.hpp | 25 +++++++++++++++++++ libraries/wallet/wallet.cpp | 25 +------------------ libraries/wallet/wallet_seeding.inl | 21 ++++++++++++++++ 13 files changed, 297 insertions(+), 24 deletions(-) create mode 100644 libraries/wallet/wallet_seeding.inl diff --git a/libraries/wallet/include/graphene/wallet/account.hpp b/libraries/wallet/include/graphene/wallet/account.hpp index 62f778d6..b233f712 100644 --- a/libraries/wallet/include/graphene/wallet/account.hpp +++ b/libraries/wallet/include/graphene/wallet/account.hpp @@ -1,3 +1,28 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + #ifndef DECENT_WALLET_ACCOUNT_H #define DECENT_WALLET_ACCOUNT_H diff --git a/libraries/wallet/include/graphene/wallet/assets.hpp b/libraries/wallet/include/graphene/wallet/assets.hpp index 181bff09..8263b639 100644 --- a/libraries/wallet/include/graphene/wallet/assets.hpp +++ b/libraries/wallet/include/graphene/wallet/assets.hpp @@ -1,3 +1,28 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + #ifndef DECENT_WALLET_ASSETS_H #define DECENT_WALLET_ASSETS_H diff --git a/libraries/wallet/include/graphene/wallet/content.hpp b/libraries/wallet/include/graphene/wallet/content.hpp index 25347fe6..bd969688 100644 --- a/libraries/wallet/include/graphene/wallet/content.hpp +++ b/libraries/wallet/include/graphene/wallet/content.hpp @@ -1,3 +1,28 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + #ifndef DECENT_WALLET_CONTENT_H #define DECENT_WALLET_CONTENT_H diff --git a/libraries/wallet/include/graphene/wallet/general.hpp b/libraries/wallet/include/graphene/wallet/general.hpp index 19433267..e94283d3 100644 --- a/libraries/wallet/include/graphene/wallet/general.hpp +++ b/libraries/wallet/include/graphene/wallet/general.hpp @@ -1,3 +1,28 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + #ifndef DECENT_WALLET_GENERAL_H #define DECENT_WALLET_GENERAL_H diff --git a/libraries/wallet/include/graphene/wallet/messaging.hpp b/libraries/wallet/include/graphene/wallet/messaging.hpp index 2d038818..4d688765 100644 --- a/libraries/wallet/include/graphene/wallet/messaging.hpp +++ b/libraries/wallet/include/graphene/wallet/messaging.hpp @@ -1,3 +1,28 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + #ifndef DECENT_WALLET_MESSAGING_H #define DECENT_WALLET_MESSAGING_H diff --git a/libraries/wallet/include/graphene/wallet/mining.hpp b/libraries/wallet/include/graphene/wallet/mining.hpp index fb1e036a..4ce09b72 100644 --- a/libraries/wallet/include/graphene/wallet/mining.hpp +++ b/libraries/wallet/include/graphene/wallet/mining.hpp @@ -1,3 +1,28 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + #ifndef DECENT_WALLET_MINING_H #define DECENT_WALLET_MINING_H diff --git a/libraries/wallet/include/graphene/wallet/proposals.hpp b/libraries/wallet/include/graphene/wallet/proposals.hpp index 6285c8b2..eabd93d2 100644 --- a/libraries/wallet/include/graphene/wallet/proposals.hpp +++ b/libraries/wallet/include/graphene/wallet/proposals.hpp @@ -1,3 +1,28 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + #ifndef DECENT_WALLET_PROPOSALS_H #define DECENT_WALLET_PROPOSALS_H diff --git a/libraries/wallet/include/graphene/wallet/seeding.hpp b/libraries/wallet/include/graphene/wallet/seeding.hpp index 2e5e97c9..c61147da 100644 --- a/libraries/wallet/include/graphene/wallet/seeding.hpp +++ b/libraries/wallet/include/graphene/wallet/seeding.hpp @@ -1,3 +1,28 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + #ifndef DECENT_WALLET_SEEDING_H #define DECENT_WALLET_SEEDING_H diff --git a/libraries/wallet/include/graphene/wallet/subscription.hpp b/libraries/wallet/include/graphene/wallet/subscription.hpp index 3a5225ae..260c4ef8 100644 --- a/libraries/wallet/include/graphene/wallet/subscription.hpp +++ b/libraries/wallet/include/graphene/wallet/subscription.hpp @@ -1,3 +1,28 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + #ifndef DECENT_WALLET_SUBSCRIPTION_H #define DECENT_WALLET_SUBSCRIPTION_H diff --git a/libraries/wallet/include/graphene/wallet/transaction_builder.hpp b/libraries/wallet/include/graphene/wallet/transaction_builder.hpp index 62139aca..8adcd6b5 100644 --- a/libraries/wallet/include/graphene/wallet/transaction_builder.hpp +++ b/libraries/wallet/include/graphene/wallet/transaction_builder.hpp @@ -1,3 +1,28 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + #ifndef DECENT_WALLET_TRANSACTION_BUILDER_H #define DECENT_WALLET_TRANSACTION_BUILDER_H diff --git a/libraries/wallet/include/graphene/wallet/wallet_file.hpp b/libraries/wallet/include/graphene/wallet/wallet_file.hpp index 731dc96c..593219bc 100644 --- a/libraries/wallet/include/graphene/wallet/wallet_file.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet_file.hpp @@ -1,3 +1,28 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + #ifndef DECENT_WALLET_WALLET_FILE_H #define DECENT_WALLET_WALLET_FILE_H diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 6420d7f0..739dd803 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3387,6 +3387,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati #include "wallet_assets.inl" #include "wallet_transaction_builder.inl" #include "wallet_mining.inl" +#include "wallet_seeding.inl" #include "wallet_proposals.inl" #include "wallet_content.inl" #include "wallet_subscription.inl" @@ -3455,30 +3456,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati - vector wallet_api::list_seeders_by_price( uint32_t count )const - { - return my->_remote_db->list_seeders_by_price( count ); - } - - optional> wallet_api::list_seeders_by_upload( const uint32_t count )const - { - return my->_remote_db->list_seeders_by_upload( count ); - } - - vector wallet_api::list_seeders_by_region( const string region_code )const - { - return my->_remote_db->list_seeders_by_region( region_code ); - } - - vector wallet_api::list_seeders_by_rating( const uint32_t count )const - { - return my->_remote_db->list_seeders_by_rating( count ); - } - - - - - void graphene::wallet::detail::submit_transfer_listener::package_creation_complete() { uint64_t size = std::max((uint64_t)1, ( _info->get_size() + (1024 * 1024) -1 ) / (1024 * 1024)); diff --git a/libraries/wallet/wallet_seeding.inl b/libraries/wallet/wallet_seeding.inl new file mode 100644 index 00000000..59ef30c7 --- /dev/null +++ b/libraries/wallet/wallet_seeding.inl @@ -0,0 +1,21 @@ + +vector wallet_api::list_seeders_by_price( uint32_t count )const +{ + return my->_remote_db->list_seeders_by_price( count ); +} + +optional> wallet_api::list_seeders_by_upload( const uint32_t count )const +{ + return my->_remote_db->list_seeders_by_upload( count ); +} + +vector wallet_api::list_seeders_by_region( const string region_code )const +{ + return my->_remote_db->list_seeders_by_region( region_code ); +} + +vector wallet_api::list_seeders_by_rating( const uint32_t count )const +{ + return my->_remote_db->list_seeders_by_rating( count ); +} + From f4d78a80d1ab598c3d3c09fe1f9e2ed95541a7f3 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Mon, 19 Feb 2018 14:46:22 +0100 Subject: [PATCH 051/136] merge commit with develop branch --- libraries/wallet/wallet.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index a6d29a1f..bfcdfabd 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3486,7 +3486,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati fc::bigint entropy(entropy1); entropy <<= 8 * sha_entropy1.data_size(); entropy += entropy2; - brain_key = "" ; + brain_key.clear(); for (int i = 0; i < BRAIN_KEY_WORD_COUNT; i++) { fc::bigint choice = entropy % graphene::words::word_list_size; entropy /= graphene::words::word_list_size; @@ -3501,11 +3501,10 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati result.wif_priv_key = key_to_wif( priv_key ); try { result.pub_key = priv_key.get_public_key(); - }catch(fc::assert_exception ae) { + } catch(const fc::assert_exception& ae) { cont = true; } - } - while (cont); + } while (cont); return result; } From 11eb605d44bbda7af8432260f9d139886f9e1c40 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Mon, 19 Feb 2018 16:05:17 +0100 Subject: [PATCH 052/136] fixed comments for wallet.hpp, general.hpp and wallet_file.hpp --- .../include/graphene/wallet/general.hpp | 88 ++++++------- .../wallet/include/graphene/wallet/wallet.hpp | 63 +++------ .../include/graphene/wallet/wallet_file.hpp | 120 +++++++----------- 3 files changed, 110 insertions(+), 161 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/general.hpp b/libraries/wallet/include/graphene/wallet/general.hpp index e94283d3..c7eb9d3d 100644 --- a/libraries/wallet/include/graphene/wallet/general.hpp +++ b/libraries/wallet/include/graphene/wallet/general.hpp @@ -28,122 +28,118 @@ /** * @brief Returns info such as client version, git version of graphene/fc, version of boost, openssl. - * @returns compile time info and client and dependencies versions - * @ingroup WalletCLI + * @return compile time info and client and dependencies versions + * @ingroup WalletAPI_General */ variant_object about() const; /** - * @brief Retrieve a full, signed block with info - * @param num ID of the block - * @return the referenced block with info, or null if no matching block was found - * @ingroup WalletCLI + * @brief Retrieve a full, signed block with info. + * @param num ID/height of the block + * @return the referenced block with info, or \c null if no matching block was found + * @ingroup WalletAPI_General */ optional get_block( uint32_t num ); /** - * @brief Returns the block chain's slowly-changing settings. + * @brief Returns the blockchain's slowly-changing properties. * This object contains all of the properties of the blockchain that are fixed - * or that change only once per maintenance interval (daily) such as the + * or that change only once per maintenance interval such as the * current list of miners, block interval, etc. * @see \c get_dynamic_global_properties() for frequently changing properties - * @returns the global properties - * @ingroup WalletCLI + * @return the global properties + * @ingroup WalletAPI_General */ global_property_object get_global_properties() const; /** - * @brief Returns the block chain's rapidly-changing properties. + * @brief Returns the blockchain's rapidly-changing properties. * The returned object contains information that changes every block interval * such as the head block number, the next miner, etc. * @see \c get_global_properties() for less-frequently changing properties - * @returns the dynamic global properties - * @ingroup WalletCLI + * @return the dynamic global properties + * @ingroup WalletAPI_General */ dynamic_global_property_object get_dynamic_global_properties() const; /** * @brief Returns the blockchain object corresponding to the given id. - * * This generic function can be used to retrieve any object from the blockchain * that is assigned an ID. Certain types of objects have specialized convenience * functions to return their objects -- e.g., assets have \c get_asset(), accounts * have \c get_account(), but this function will work for any object. - * * @param id the id of the object to return - * @returns the requested object - * @ingroup WalletCLI + * @return the requested object + * @ingroup WalletAPI_General */ variant get_object(object_id_type id) const; /** - * @brief Query the last local block + * @brief Query the last local block. * @return the block time + * @ingroup WalletAPI_General */ fc::time_point_sec head_block_time() const; /** - * @brief Lists all available commands - * @return List of all available commands - * @ingroup WalletCLI + * @brief Get information about current state of the blockchain, + * such as head block number, chain_id, list of active miners,... + * @return information about current state of the blockchain + * @ingroup WalletAPI_General */ variant info(); /** * @brief Returns a list of all commands supported by the wallet API. - * * This lists each command, along with its arguments and return types. * For more detailed help on a single command, use \c get_help() - * - * @returns a multi-line string suitable for displaying on a terminal - * @ingroup WalletCLI + * @return a multi-line string suitable for displaying on a terminal + * @ingroup WalletAPI_General */ -string help()const; +string help() const; /** * @brief Returns detailed help on a single API command. * @param method the name of the API command you want help with - * @returns a multi-line string suitable for displaying on a terminal - * @ingroup WalletCLI + * @return a multi-line string suitable for displaying on a terminal + * @ingroup WalletAPI_General */ -string gethelp(const string& method)const; +string get_help(const string& method) const; /** - * @brief Sign a buffer - * @param str_buffer The buffer to be signed - * @param str_brainkey Derives the private key used for signature - * @return The signed buffer - * @ingroup WalletCLI + * @brief Sign a buffer. + * @param str_buffer the buffer to be signed + * @param str_brainkey derives the private key used for signature + * @return the signed buffer + * @ingroup WalletAPI_General */ std::string sign_buffer(std::string const& str_buffer, std::string const& str_brainkey) const; /** - * @brief Verify if the signature is valid - * @param str_buffer The original buffer - * @param str_publickey The public key used for verification - * @param str_signature The signed buffer - * @return true if valid, otherwise false - * @ingroup WalletCLI + * @brief Verify if the signature is valid. + * @param str_buffer the original buffer + * @param str_publickey the public key used for verification + * @param str_signature the signed buffer + * @return \c true if valid, otherwise \c false + * @ingroup WalletAPI_General */ bool verify_signature(std::string const& str_buffer, std::string const& str_publickey, std::string const& str_signature) const; /** - * + * @brief * @param nodes - * @ingroup WalletCLI + * @ingroup WalletAPI_General */ void network_add_nodes( const vector& nodes ); /** - * - * @ingroup WalletCLI + * @brief + * @ingroup WalletAPI_General */ vector< variant > network_get_connected_peers(); - - #endif //DECENT_WALLET_GENERAL_H diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index bad223dd..a9a26ca9 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -231,14 +231,29 @@ namespace graphene { namespace wallet { namespace detail { class wallet_api_impl; } - - - + + + /** * This wallet assumes it is connected to the database server with a high-bandwidth, low-latency connection and * performs minimal caching. This API could be provided locally to be used by a web interface. * - * @defgroup WalletCLI WalletCLI + * @defgroup WalletCLI CLI Wallet + * @{ + * @defgroup WalletAPI_Wallet Wallet + * @defgroup WalletAPI_General General + * @defgroup WalletAPI_Account Account + * @defgroup WalletAPI_Asset Asset + * @defgroup WalletAPI_Subscription Subscription + * @defgroup WalletAPI_Content Content + * @defgroup WalletAPI_Messaging Messaging + * @defgroup WalletAPI_Seeding Seeding + * @defgroup WalletAPI_Mining Mining + * @defgroup WalletAPI_Proposals Proposals + * @defgroup WalletAPI_TransactionBuilder Transaction Builder + * @defgroup WalletAPI_Network Network + * @defgroup WalletAPI_Debug Debug + * @} */ class wallet_api { @@ -260,46 +275,6 @@ namespace graphene { namespace wallet { #include "messaging.hpp" -#if 0 - /** - * - * @param creator - * @param symbol - * @ingroup WalletCLI - */ - void dbg_make_mia(string creator, string symbol); - - /** - * - * @param src_filename - * @param count - * @ingroup WalletCLI - */ - void dbg_push_blocks( std::string src_filename, uint32_t count ); - - /** - * - * @param debug_wif_key - * @param count - * @ingroup WalletCLI - */ - void dbg_generate_blocks( std::string debug_wif_key, uint32_t count ); - - /** - * - * @param filename - * @ingroup WalletCLI - */ - void dbg_stream_json_objects( const std::string& filename ); - - /** - * - * @param update - * @ingroup WalletCLI - */ - void dbg_update_object( fc::variant_object update ); -#endif - std::map> get_result_formatters() const; fc::signal lock_changed; diff --git a/libraries/wallet/include/graphene/wallet/wallet_file.hpp b/libraries/wallet/include/graphene/wallet/wallet_file.hpp index 593219bc..bbc7d594 100644 --- a/libraries/wallet/include/graphene/wallet/wallet_file.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet_file.hpp @@ -27,10 +27,10 @@ #define DECENT_WALLET_WALLET_FILE_H /** - * @brief Copy wallet file to a new file + * @brief Copy wallet file to a new file. * @param destination_filename - * @return true if the wallet is copied, false otherwise - * @ingroup WalletCLI + * @return \c true if the wallet is copied,\c false otherwise + * @ingroup WalletAPI_Wallet */ bool copy_wallet_file( string destination_filename ); //obsolete @@ -38,100 +38,85 @@ bool copy_wallet_file( string destination_filename ); //obsolete * @brief Lists all accounts controlled by this wallet. * This returns a list of the full account objects for all accounts whose private keys * we possess. - * @returns a list of account objects - * @ingroup WalletCLI + * @return a list of accounts imported in the wallet + * @ingroup WalletAPI_Wallet */ vector list_my_accounts(); -/** - * @brief Returns the current wallet filename. - * - * This is the filename that will be used when automatically saving the wallet. - * +/** @brief Returns the current wallet filename. + * @note This is the filename that will be used when automatically saving the wallet. * @see set_wallet_filename() * @return the wallet filename - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ string get_wallet_filename() const; /** * @brief Get the WIF private key corresponding to a public key. The - * private key must already be in the wallet. - * @param pubkey Public key + * private key must already be imported in the wallet. + * @param pubkey public key * @return WIF private key corresponding to a public key - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ -string get_private_key( public_key_type pubkey )const; +string get_private_key( public_key_type pubkey) const; /** * @brief Checks whether the wallet has just been created and has not yet had a password set. - * - * Calling \c set_password will transition the wallet to the locked state. - * @return true if the wallet is new - * @ingroup Wallet Management - * @ingroup WalletCLI + * Calling \c set_password() will transition the wallet to the locked state. + * @return \c true if the wallet is new + * @ingroup WalletAPI_Wallet */ bool is_new()const; /** * @brief Checks whether the wallet is locked (is unable to use its private keys). - * * This state can be changed by calling \c lock() or \c unlock(). - * @return true if the wallet is locked - * @ingroup Wallet Management - * @ingroup WalletCLI + * @see \c unlock() + * @return \c true if the wallet is locked + * @ingroup WalletAPI_Wallet */ bool is_locked()const; /** * @brief Locks the wallet immediately. - * @ingroup Wallet Management - * @ingroup WalletCLI + * @see \c unlock() + * @ingroup WalletAPI_Wallet */ void lock(); /** * @brief Unlocks the wallet. - * - * The wallet remain unlocked until the \c lock is called + * The wallet remain unlocked until the \c lock() is called * or the program exits. * @param password the password previously set with \c set_password() - * @ingroup Wallet Management - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ void unlock(string password); /** * @brief Sets a new password on the wallet. - * - * The wallet must be either 'new' or 'unlocked' to - * execute this command. + * The wallet must be either \c new or \c unlocked to execute this command. * @param password - * @ingroup Wallet Management - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ void set_password(string password); /** - * @brief Loads a specified Graphene wallet. - * + * @brief Loads a specified wallet file. * The current wallet is closed before the new wallet is loaded. - * * @warning This does not change the filename that will be used for future * wallet writes, so this may cause you to overwrite your original * wallet unless you also call \c set_wallet_filename() - * * @param wallet_filename the filename of the wallet JSON file to load. * If \c wallet_filename is empty, it reloads the * existing wallet file - * @returns true if the specified wallet is loaded - * @ingroup WalletCLI + * @return \c true if the specified wallet is loaded + * @ingroup WalletAPI_Wallet */ bool load_wallet_file(string wallet_filename = ""); /** * @brief Saves the current wallet to the given filename. - * * @warning This does not change the wallet filename that will be used for future * writes, so think of this function as 'Save a Copy As...' instead of * 'Save As...'. Use \c set_wallet_filename() to make the filename @@ -139,67 +124,60 @@ bool load_wallet_file(string wallet_filename = ""); * @param wallet_filename the filename of the new wallet JSON file to create * or overwrite. If \c wallet_filename is empty, * save to the current filename. - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ void save_wallet_file(string wallet_filename = ""); /** * @brief Sets the wallet filename used for future writes. - * * This does not trigger a save, it only changes the default filename * that will be used the next time a save is triggered. - * * @param wallet_filename the new filename to use for future saves - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ void set_wallet_filename(string wallet_filename); - - /** * @brief Imports the private key for an existing account. - * - * The private key must match either an owner key or an active key for the + * The private key should match either an owner key or an active key for the * named account. - * * @see dump_private_keys() - * + * @see list_my_accounts() * @param account_name_or_id the account owning the key * @param wif_key the private key in WIF format - * @returns true if the key was imported - * @ingroup WalletCLI + * @return \c true if the key was imported + * @ingroup WalletAPI_Wallet */ bool import_key(string account_name_or_id, string wif_key); /** - * @brief Imports accounts from the other wallet file - * @param filename The filename of the wallet JSON file - * @param password User's password to the wallet + * @brief Imports accounts from the other wallet file. + * @param filename the filename of the wallet JSON file + * @param password user's password to the wallet * @return mapped account names to boolean values indicating whether the account was successfully imported - * @ingroup WalletCLI + * @ingroup WalletAPI_Wallet */ map import_accounts( string filename, string password ); //obsolete /** - * @brief Imports account keys from particular account from another wallet file to desired account located in wallet file currently used - * @param filename The filename of the wallet JSON file - * @param password User's password to the wallet - * @param src_account_name Name of the source account - * @param dest_account_name Name of the destination account - * @return true if the keys were imported - * @ingroup WalletCLI + * @brief Imports account keys from particular account from another wallet file to desired account located in wallet file currently used. + * @param filename the filename of the wallet JSON file + * @param password user's password to the wallet + * @param src_account_name name of the source account + * @param dest_account_name name of the destination account + * @return \c true if the keys were imported + * @ingroup WalletAPI_Wallet */ bool import_account_keys( string filename, string password, string src_account_name, string dest_account_name ); //obsolete /** - * @brief Dumps all private keys owned by the wallet. - * - * The keys are printed in WIF format. You can import these keys into another wallet + * @brief Dumps all private keys successfully imported in the wallet. + * @note The keys are printed in WIF format. You can import these keys into another wallet * using \c import_key() - * @returns a map containing the private keys, indexed by their public key - * @ingroup WalletCLI + * @return a map containing the private keys and corresponding public keys + * @ingroup WalletAPI_Wallet */ map dump_private_keys(); -#endif //DECENT_WALLET_FILE_H +#endif //DECENT_WALLET_WALLET_FILE_H From ef255a5cdd5d0f0f3fc96969795b3203cc698ab4 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 20 Feb 2018 13:46:48 +0100 Subject: [PATCH 053/136] fixed comments --- .../include/graphene/wallet/account.hpp | 149 +++---- .../wallet/include/graphene/wallet/assets.hpp | 170 ++++---- .../include/graphene/wallet/content.hpp | 389 +++++++++--------- .../include/graphene/wallet/messaging.hpp | 44 +- .../wallet/include/graphene/wallet/mining.hpp | 133 +++--- .../include/graphene/wallet/proposals.hpp | 130 +++--- .../include/graphene/wallet/seeding.hpp | 34 +- .../include/graphene/wallet/subscription.hpp | 84 ++-- .../graphene/wallet/transaction_builder.hpp | 150 ++++--- .../wallet/include/graphene/wallet/wallet.hpp | 2 +- libraries/wallet/wallet_general.inl | 2 +- 11 files changed, 610 insertions(+), 677 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/account.hpp b/libraries/wallet/include/graphene/wallet/account.hpp index b233f712..e16656b6 100644 --- a/libraries/wallet/include/graphene/wallet/account.hpp +++ b/libraries/wallet/include/graphene/wallet/account.hpp @@ -27,61 +27,56 @@ #define DECENT_WALLET_ACCOUNT_H /** - * @brief Returns the number of accounts registered on the blockchain - * @returns the number of registered accounts - * @ingroup WalletCLI + * @brief Returns the number of accounts registered on the blockchain. + * @return the number of registered accounts + * @ingroup WalletAPI_Account */ -uint64_t get_account_count()const; +uint64_t get_account_count() const; /** * @brief Lists all accounts registered in the blockchain. * This returns a list of all account names and their account ids, sorted by account name. - * - * Use the \c lowerbound and limit parameters to page through the list. To retrieve all accounts, + * Use the \c lowerbound and \c limit parameters to page through the list. To retrieve all accounts, * start by setting \c lowerbound to the empty string \c "", and then each iteration, pass * the last account name returned as the \c lowerbound for the next \c list_accounts() call. - * * @param lowerbound the name of the first account to return. If the named account does not exist, * the list will start at the account that comes after \c lowerbound * @param limit the maximum number of accounts to return (max: 1000) - * @returns a list of accounts mapping account names to account ids - * @ingroup WalletCLI + * @return a list of accounts mapping account names to account ids + * @ingroup WalletAPI_Account */ map list_accounts(const string& lowerbound, uint32_t limit); /** - * @brief Get names and IDs for registered accounts that match search term + * @brief Get registered accounts that match search term * @param term will try to partially match account name or id - * @param limit Maximum number of results to return -- must not exceed 1000 - * @param order Sort data by field + * @param limit maximum number of results to return ( must not exceed 1000 ) + * @param order sort data by field * @param id object_id to start searching from - * @return Map of account names to corresponding IDs - * @ingroup WalletCLI + * @return map of account names to corresponding IDs + * @ingroup WalletAPI_Account */ vector search_accounts(const string& term, const string& order, const string& id, uint32_t limit); /** * @brief List the balances of an account. * Each account can have multiple balances, one for each type of asset owned by that - * account. The returned list will only contain assets for which the account has a - * nonzero balance + * account. * @param id the name or id of the account whose balances you want - * @returns a list of the given account's balances - * @ingroup WalletCLI + * @return a list of the given account's balances + * @ingroup WalletAPI_Account */ vector list_account_balances(const string& id); /** * @brief Returns the operations on the named account. - * - * This returns a list of transaction detail object, which describe activity on the account. - * + * This returns a list of transaction detail objects, which describe past the past activity on the account. * @param account_name the name or id of the account - * @param order Sort data by field + * @param order sort data by field * @param id object_id to start searching from * @param limit the number of entries to return (starting from the most recent) (max 100) - * @returns a list of \c transaction_detail_object - * @ingroup WalletCLI + * @return a list of transaction detail objects + * @ingroup WalletAPI_Account */ vector search_account_history(string const& account_name, string const& order, @@ -89,23 +84,22 @@ vector search_account_history(string const& acc int limit) const; -/** Returns the most recent operations on the named account. - * +/** + * @brief Returns the most recent operations on the named account. * This returns a list of operation history objects, which describe activity on the account. - * - * @note this API doesn't give a way to retrieve more than the most recent 100 transactions, - * you can interface directly with the blockchain to get more history + * @note this API doesn't give a way to retrieve more than the most recent 100 transactions * @param name the name or id of the account - * @param limit the number of entries to return (starting from the most recent) (max 100) - * @returns a list of \c operation_history_objects + * @param limit the number of entries to return (starting from the most recent) + * @return a list of operation history objects + * @ingroup WalletAPI_Account */ vector get_account_history(string name, int limit)const; /** - * @brief Get operations relevant to the specified account referenced + * @breif Get operations relevant to the specified account referenced * by an event numbering specific to the account. The current number of operations * for the account can be found in the account statistics (or use 0 for start). - * @param name The account whose history should be queried + * @param account The account whose history should be queried * @param stop Sequence number of earliest operation. 0 is default and will * query 'limit' number of operations. * @param limit Maximum number of operations to retrieve (must not exceed 100) @@ -124,70 +118,69 @@ vector get_relative_account_history(string name, * @brief Returns information about the given account. * * @param account_name_or_id the name or id of the account to provide information about - * @returns the public account data stored in the blockchain - * @ingroup WalletCLI + * @return the public account data stored in the blockchain + * @ingroup WalletAPI_Account */ account_object get_account(string account_name_or_id) const; /** - * @brief Derive private key from given prefix and sequence + * @brief Derive private key from given prefix and sequence. * @param prefix_string * @param sequence_number - * @return private_key Derived private key - * @ingroup WalletCLI + * @return derived private key + * @ingroup WalletAPI_Account */ fc::ecc::private_key derive_private_key(const std::string& prefix_string, int sequence_number) const; /** * @brief Suggests a safe brain key to use for creating your account. - * \c create_account_with_brain_key() requires you to specify a 'brain key', + * \c create_account_with_brain_key() requires you to specify a brain key, * a long passphrase that provides enough entropy to generate cyrptographic * keys. This function will suggest a suitably random string that should * be easy to write down (and, with effort, memorize). - * @returns a suggested brain_key - * @ingroup WalletCLI + * @return a suggested brain key + * @ingroup WalletAPI_Account */ brain_key_info suggest_brain_key()const; /** * @brief Calculates the private key and public key corresponding to any brain key * @param brain_key the brain key to be used for calculation - * @returns the corresponding brain_key_info - * @ingroup WalletCLI + * @return the corresponding \c brain_key_info + * @ingroup WalletAPI_Account */ brain_key_info get_brain_key_info(string const& brain_key) const; /** - * @brief Suggests a safe brain key to use for creating your account also - * generates the el_gamal_key_pair corresponding to the brain key - * \c create_account_with_brain_key() requires you to specify a 'brain key', + * @brief Suggests a safe brain key to use for creating your account. This funcion also + * generates \c el_gamal_key_pair corresponding to the brain key. + * @note \c create_account_with_brain_key() requires you to specify a brain key, * a long passphrase that provides enough entropy to generate cyrptographic * keys. This function will suggest a suitably random string that should * be easy to write down (and, with effort, memorize). - * @returns a suggested brain_key - * @ingroup WalletCLI + * @return a suggested brain key and corresponding El Gamal key pair + * @ingroup WalletAPI_Account */ pair generate_brain_key_el_gamal_key() const; /** * @brief Registers a third party's account on the blockckain. - * * This function is used to register an account for which you do not own the private keys. * When acting as a registrar, an end user will generate their own private keys and send * you the public keys. The registrar will use this function to register the account * on behalf of the end user. - * - * @see create_account_with_brain_key() - * - * @param name the name of the account, must be unique on the blockchain. Shorter names - * are more expensive to register; the rules are still in flux, but in general - * names of more than 8 characters with at least one digit will be cheap. + * @note The owner key represents absolute control over the account. Generally, the only time the owner key is required + * is to update the active key. + * @note The active key represents the hot key of the account. This key has control over nearly all + * operations the account may perform. + * @see suggest_brain_key() + * @param name the name of the account, must be unique on the blockchain and contains at least 5 characters * @param owner the owner key for the new account * @param active the active key for the new account * @param registrar_account the account which will pay the fee to register the user - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction registering the account - * @ingroup WalletCLI + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction registering the account + * @ingroup WalletAPI_Account */ signed_transaction register_account(string name, public_key_type owner, @@ -197,20 +190,14 @@ signed_transaction register_account(string name, /** * @brief Creates a new account and registers it on the blockchain. - * - * @todo why no referrer_percent here? - * * @see suggest_brain_key() * @see register_account() - * * @param brain_key the brain key used for generating the account's private keys - * @param account_name the name of the account, must be unique on the blockchain. Shorter names - * are more expensive to register; the rules are still in flux, but in general - * names of more than 8 characters with at least one digit will be cheap. + * @param account_name the name of the account, must be unique on the blockchain and contains at least 5 characters * @param registrar_account the account which will pay the fee to register the user - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction registering the account - * @ingroup WalletCLI + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction registering the account + * @ingroup WalletAPI_Account */ signed_transaction create_account_with_brain_key(string brain_key, string account_name, @@ -221,15 +208,15 @@ signed_transaction create_account_with_brain_key(string brain_key, * @brief Transfer an amount from one account to another. * @param from the name or id of the account sending the funds * @param to the name or id of the account receiving the funds - * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) + * @param amount the amount to send (in nominal units -- to send half of a DCT, specify 0.5) * @param asset_symbol the symbol or id of the asset to send * @param memo a memo to attach to the transaction. The memo will be encrypted in the - * transaction and readable for the receiver. There is no length limit - * other than the limit imposed by maximum transaction size, but transaction - * increase with transaction size - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction transferring funds - * @ingroup WalletCLI + * transaction and readable for the receiver. There is no length limit + * other than the limit imposed by maximum transaction size. + * @note transaction fee is fixed and does not depend on the length of the memo + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction transferring funds + * @ingroup WalletAPI_General */ signed_transaction transfer(string from, string to, @@ -239,16 +226,16 @@ signed_transaction transfer(string from, bool broadcast = false); /** - * @brief Generates private ElGamal key and corresponding public key. - * @return Pair of ElGamal keys - * @ingroup WalletCLI + * @brief Generates private El Gamal key and corresponding public key. + * @return pair of El Gamal keys + * @ingroup WalletAPI_Account */ el_gamal_key_pair generate_el_gamal_keys() const; /** - * @brief Gets unique ElGamal key pair for consumer. - * @return Pair of ElGamal keys - * @ingroup WalletCLI + * @brief Gets unique El Gamal key pair for consumer. + * @return pair of El Gamal keys + * @ingroup WalletAPI_Account */ el_gamal_key_pair_str get_el_gammal_key(string const& consumer) const; diff --git a/libraries/wallet/include/graphene/wallet/assets.hpp b/libraries/wallet/include/graphene/wallet/assets.hpp index 8263b639..07a72ac3 100644 --- a/libraries/wallet/include/graphene/wallet/assets.hpp +++ b/libraries/wallet/include/graphene/wallet/assets.hpp @@ -28,59 +28,54 @@ /** * @brief Lists all assets registered on the blockchain. - * - * To list all assets, pass the empty string \c "" for the lowerbound to start + * To list all assets, pass the empty string \c "" for the \c lowerbound to start * at the beginning of the list, and iterate as necessary. - * - * @param lowerbound the symbol of the first asset to include in the list. + * @param lowerbound the symbol of the first asset to include in the list * @param limit the maximum number of assets to return (max: 100) - * @returns the list of asset objects, ordered by symbol - * @ingroup WalletCLI + * @return the list of asset objects, ordered by symbol + * @ingroup WalletAPI_Asset */ vector list_assets(const string& lowerbound, uint32_t limit)const; /** * @brief Returns information about the given asset. * @param asset_name_or_id the symbol or id of the asset in question - * @returns the information about the asset stored in the block chain - * @ingroup WalletCLI + * @return the information about the asset stored in the block chain + * @ingroup WalletAPI_Asset */ asset_object get_asset(string asset_name_or_id) const; /** - * @brief Returns the BitAsset-specific data for a given asset. - * Market-issued assets's behavior are determined both by their "BitAsset Data" and - * their basic asset data, as returned by \c get_asset(). - * @param asset_name_or_id the symbol or id of the BitAsset in question - * @returns the BitAsset-specific data for this asset - * @ingroup WalletCLI + * @brief Returns the specific data for a given monitored asset. + * @see \c get_asset() + * @param asset_name_or_id the symbol or id of the monitored asset in question + * @return the specific data for this monitored asset + * @ingroup WalletAPI_Asset */ monitored_asset_options get_monitored_asset_data(string asset_name_or_id)const; /** * @brief Lookup the id of a named asset. * @param asset_name_or_id the symbol of an asset to look up - * @returns the id of the given asset - * @ingroup WalletCLI + * @return the id of the given asset + * @ingroup WalletAPI_Asset */ -asset_id_type get_asset_id(string asset_name_or_id) const; +asset_id_type get_asset_id(string asset_name_or_id) const; //obsolete /** * @brief Creates a new monitored asset. - * - * Options can be changed later using \c update_monitored_asset() - * + * @note some parameters can be changed later using \c update_monitored_asset() * @param issuer the name or id of the account who will pay the fee and become the * issuer of the new asset. This can be updated later * @param symbol the ticker symbol of the new asset * @param precision the number of digits of precision to the right of the decimal point, * must be less than or equal to 12 - * @param description asset description. Maximal length is 1000 chars. + * @param description asset description. Maximal length is 1000 chars * @param feed_lifetime_sec time before a price feed expires * @param minimum_feeds minimum number of unexpired feeds required to extract a median feed from - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction creating a new asset - * @ingroup WalletCLI + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction creating a new asset + * @ingroup WalletAPI_Asset */ signed_transaction create_monitored_asset(string issuer, string symbol, @@ -91,18 +86,14 @@ signed_transaction create_monitored_asset(string issuer, bool broadcast = false); /** - * @brief Update the options specific to a monitored asset. - * - * Monitored assets have some options which are not relevant to other asset types. This operation is used to update those - * options and an existing monitored asset. - * - * @param symbol the name or id of the asset to update, which must be a market-issued asset + * @brief Update the parameters specific to a monitored asset. + * @param symbol the name or id of the asset to update, which must be a monitored asset * @param description asset description * @param feed_lifetime_sec time before a price feed expires * @param minimum_feeds minimum number of unexpired feeds required to extract a median feed from - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction updating the bitasset - * @ingroup WalletCLI + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction updating the monitored asset + * @ingroup WalletAPI_Asset */ signed_transaction update_monitored_asset(string symbol, string description, @@ -112,24 +103,23 @@ signed_transaction update_monitored_asset(string symbol, /** * @brief Creates a new user-issued asset. - * - * Options can be changed later using \c update_asset() - * + * @note Some parameters can be changed later using \c update_user_issued_asset() + * @see \c issue_asset() * @param issuer the name or id of the account who will pay the fee and become the * issuer of the new asset. This can be updated later * @param symbol the ticker symbol of the new asset * @param precision the number of digits of precision to the right of the decimal point, - * must be less than or equal to 12 + * must be less than or equal to 12 * @param description asset description. Maximal length is 1000 chars * @param max_supply the maximum supply of this asset which may exist at any given time - * @param core_exchange_rate Core_exchange_rate technically needs to store the asset ID of + * @param core_exchange_rate core_exchange_rate technically needs to store the asset ID of * this new asset. Since this ID is not known at the time this operation is * created, create this price as though the new asset has instance ID 1, and * the chain will overwrite it with the new asset's ID - * @param is_exchangeable True to allow implicit conversion of this asset to/from core asset - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction creating a new asset - * @ingroup WalletCLI + * @param is_exchangeable \c true to allow implicit conversion of this asset to/from core asset + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction creating a new asset + * @ingroup WalletAPI_Asset */ signed_transaction create_user_issued_asset(string issuer, string symbol, @@ -140,37 +130,35 @@ signed_transaction create_user_issued_asset(string issuer, bool is_exchangeable, bool broadcast = false); -/** Issue new shares of an asset. - * +/** + * @brief Issue new shares of an asset. * @param to_account the name or id of the account to receive the new shares * @param amount the amount to issue, in nominal units * @param symbol the ticker symbol of the asset to issue * @param memo a memo to include in the transaction, readable by the recipient - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction issuing the new shares + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction issuing the new shares + * @ingroup WalletAPI_Asset */ - signed_transaction issue_asset(string to_account, +signed_transaction issue_asset(string to_account, string amount, string symbol, string memo, bool broadcast = false); /** - * @brief Update the options specific to a user issued asset. - * + * @brief Update the parameters specific to a user issued asset. * User issued assets have some options which are not relevant to other asset types. This operation is used to update those * options an an existing user issues asset. - * - * - * @param symbol the name or id of the asset to update, which must be a market-issued asset + * @param symbol the name or id of the asset to update, which must be a user-issued asset * @param new_issuer if the asset is to be given a new issuer, specify his ID here * @param description asset description - * @param max_supply The maximum supply of this asset which may exist at any given time - * @param core_exchange_rate Price used to convert non-core asset to core asset - * @param is_exchangeable True to allow implicit conversion of this asset to/from core asset - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction updating the bitasset - * @ingroup WalletCLI + * @param max_supply the maximum supply of this asset which may exist at any given time + * @param core_exchange_rate price used to convert non-core asset to core asset + * @param is_exchangeable \c true to allow implicit conversion of this asset to/from core asset + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction updating the user-issued asset + * @ingroup WalletAPI_Asset */ signed_transaction update_user_issued_asset(string symbol, string new_issuer, @@ -181,22 +169,17 @@ signed_transaction update_user_issued_asset(string symbol, bool broadcast = false); /** - * Pay into the pools for the given asset. - * - * User-issued assets can optionally have a pool of the core asset which is - * automatically used to pay transaction fees for any transaction using that - * asset (using the asset's core exchange rate). - * - * Allows anyone to deposit core/asset into pools. - * This pool are used when conversion between assets is needed (paying fees, paying for a content in different asset). - * + * @brief Pay into the pools for the given asset. Allows anyone to deposit core/asset into pools. + * @note User-issued assets can optionally have two asset pools. + * This pools are used when conversion between assets is needed (paying fees, paying for a content in different asset ). * @param from the name or id of the account sending the core asset * @param uia_amount the amount of "this" asset to deposit * @param uia_symbol the name or id of the asset whose pool you wish to fund * @param dct_amount the amount of the core asset to deposit * @param dct_symbol the name or id of the DCT asset - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction funding the fee pool + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction funding the asset pools + * @ingroup WalletAPI_Asset */ signed_transaction fund_asset_pools(string from, string uia_amount, @@ -206,15 +189,15 @@ signed_transaction fund_asset_pools(string from, bool broadcast = false); /** - * Burns the given user-issued asset. - * + * @brief Burns the given user-issued asset. * This command burns the user-issued asset to reduce the amount in circulation. - * @note you cannot burn market-issued assets. + * @note you cannot burn monitored asset. * @param from the account containing the asset you wish to burn * @param amount the amount to burn, in nominal units * @param symbol the name or id of the asset to burn - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction burning the asset + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction burning the asset + * @ingroup WalletAPI_Asset */ signed_transaction reserve_asset(string from, string amount, @@ -222,15 +205,15 @@ signed_transaction reserve_asset(string from, bool broadcast = false); /** - * Transfers accumulated assets from pools back to the issuer's balance. - * - * @note you cannot claim assets from pools of market-issued asset. + * @brief Transfers accumulated assets from pools back to the issuer's balance. + * @note You cannot claim assets from pools of monitored asset. * @param uia_amount the amount of "this" asset to claim, in nominal units * @param uia_symbol the name or id of the asset to claim * @param dct_amount the amount of DCT asset to claim, in nominal units * @param dct_symbol the name or id of the DCT asset to claim - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction claiming the fees + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction claiming the fees + * @ingroup WalletAPI_Asset */ signed_transaction claim_fees(string uia_amount, string uia_symbol, @@ -243,23 +226,22 @@ signed_transaction claim_fees(string uia_amount, * @param amount the amount to convert in nominal units * @param asset_symbol_or_id the symbol or id of the asset to convert * @return price in DCT + * @ingroup WalletAPI_Asset */ string price_to_dct(const string& amount, const string& asset_symbol_or_id); /** * @brief Publishes a price feed for the named asset. - * - * Price feed providers use this command to publish their price feeds for market-issued assets. A price feed is - * used to tune the market for a particular market-issued asset. For each value in the feed, the median across all + * Price feed providers use this command to publish their price feeds for monitored assets. A price feed is + * used to tune the market for a particular monitored asset. For each value in the feed, the median across all * miner feeds for that asset is calculated and the market for the asset is configured with the median of that * value. - * * @param publishing_account the account publishing the price feed * @param symbol the name or id of the asset whose feed we're publishing - * @param feed the price_feed object for particular market-issued asset - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction updating the price feed for the given asset - * @ingroup WalletCLI + * @param feed the price feed object for particular monitored asset + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction updating the price feed for the given asset + * @ingroup WalletAPI_Asset */ signed_transaction publish_asset_feed(string publishing_account, string symbol, @@ -268,20 +250,20 @@ signed_transaction publish_asset_feed(string publishing_account, /** * @brief Get a list of published price feeds by a miner. - * * @param account_name_or_id the name or id of the account - * @param count Maximum number of price feeds to fetch (must not exceed 100) - * @returns list of price feeds published by the miner - * @ingroup WalletCLI + * @param count maximum number of price feeds to fetch (must not exceed 100) + * @return list of price feeds published by the miner + * @ingroup WalletAPI_Asset */ multimap get_feeds_by_miner(const string& account_name_or_id, const uint32_t count); /** - * Get current supply of the core asset - * @ingroup WalletCLI + * @brief Get current supply of the core asset + * @return the number of shares currently in existence in account and vesting balances, escrows and pools + * @ingroup WalletAPI_Asset */ -real_supply get_real_supply()const; +real_supply get_real_supply() const; #endif //DECENT_WALLET_ASSETS_H diff --git a/libraries/wallet/include/graphene/wallet/content.hpp b/libraries/wallet/include/graphene/wallet/content.hpp index bd969688..43305051 100644 --- a/libraries/wallet/include/graphene/wallet/content.hpp +++ b/libraries/wallet/include/graphene/wallet/content.hpp @@ -27,81 +27,78 @@ #define DECENT_WALLET_CONTENT_H /** - * @brief Submits or resubmits content to the blockchain. In a case of resubmit, co-authors, price and synopsis fields + * @brief Submits or resubmits a content to the blockchain. In a case of resubmit, co-authors, price and synopsis fields * can be modified. - * @see submit_content_new() - * @param author The author of the content - * @param co_authors The co-authors' account name or ID mapped to corresponding payment split based on basis points - * @param URI The URI of the content - * @param price_amounts The price of the content per regions - * @param size The size of the content - * @param hash The Hash of the package - * @param seeders List of the seeders, which will publish the content - * @param quorum Defines number of seeders needed to restore the encryption key - * @param expiration The expiration time of the content. The content is available to buy till it's expiration time - * @param publishing_fee_asset Ticker symbol of the asset which will be used to publish content - * @param publishing_fee_amount Publishing price - * @param synopsis The description of the content - * @param secret The AES key used to encrypt and decrypt the content - * @param cd Custody data - * @param broadcast true to broadcast the transaction on the network - * @return The signed transaction submitting the content - * @ingroup WalletCLI + * @see \c generate_encryption_key() + * @see \c submit_content_async() + * @param author the author of the content + * @param co_authors the co-authors' account name or ID mapped to corresponding payment split based on basis points. The maximum number of co-authors is 10 + * @param URI the URI of the content + * @param price_amounts the price of the content per regions + * @param size the size of the content + * @param hash the Hash of the package + * @param seeders list of the seeders, which will publish the content + * @param quorum defines number of seeders needed to restore the encryption key + * @param expiration the expiration time of the content. The content is available to buy till it's expiration time + * @param publishing_fee_asset ticker symbol of the asset which will be used to publish content + * @param publishing_fee_amount publishing price + * @param synopsis the description of the content + * @param secret the AES key used to encrypt and decrypt the content + * @param cd custody data + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction submitting the content + * @ingroup WalletAPI_Content */ -signed_transaction -submit_content(string const& author, - vector< pair< string, uint32_t>> co_authors, - string const& URI, - vector const& price_amounts, - uint64_t size, - fc::ripemd160 const& hash, - vector const& seeders, - uint32_t quorum, - fc::time_point_sec const& expiration, - string const& publishing_fee_asset, - string const& publishing_fee_amount, - string const& synopsis, - DInteger const& secret, - decent::encrypt::CustodyData const& cd, - bool broadcast); +signed_transaction submit_content(const string& author, + vector< pair< string, uint32_t>> co_authors, + const string& URI, + const vector & price_amounts, + uint64_t size, + const fc::ripemd160& hash, + const vector& seeders, + uint32_t quorum, + const fc::time_point_sec& expiration, + const string& publishing_fee_asset, + const string& publishing_fee_amount, + const string& synopsis, + const DInteger& secret, + const decent::encrypt::CustodyData& cd, + bool broadcast); /** - * @brief This function is used to create package, upload package and submit content in one step. + * @brief This function is used to create and upload a package and submit content in one step. * @see create_package() * @see upload_package() * @see submit_content() - * @param author The author of the content - * @param co_authors The co-authors' account name or ID mapped to corresponding payment split based on basis points - * @param content_dir Path to the directory containing all content that should be packed - * @param samples_dir Path to the directory containing samples of content - * @param protocol Protocol for uploading package( ipfs ) - * @param price_amounts The prices of the content per regions - * @param seeders List of the seeders, which will publish the content - * @param expiration The expiration time of the content. The content is available to buy till it's expiration time - * @param synopsis The description of the content - * @return The signed transaction submitting the content - * @ingroup WalletCLI + * @param author the author of the content + * @param co_authors the co-authors' account name or ID mapped to corresponding payment split based on basis points. The maximum number of co-authors is 10 + * @param content_dir path to the directory containing all content that should be packed + * @param samples_dir path to the directory containing samples of content + * @param protocol protocol for uploading package( ipfs ) + * @param price_amounts the prices of the content per regions + * @param seeders list of the seeders, which will publish the content + * @param expiration the expiration time of the content. The content is available to buy till it's expiration time + * @param synopsis the description of the content + * @ingroup WalletAPI_Content */ - void submit_content_async( string const &author, - vector< pair< string, uint32_t>> co_authors, - string const &content_dir, - string const &samples_dir, - string const &protocol, - vector const &price_amounts, - vector const &seeders, - fc::time_point_sec const &expiration, - string const &synopsis); - + vector< pair< string, uint32_t>> co_authors, + string const &content_dir, + string const &samples_dir, + string const &protocol, + vector const &price_amounts, + vector const &seeders, + fc::time_point_sec const &expiration, + string const &synopsis); /** * @brief This function can be used to cancel submitted content. This content is immediately not available to purchase. - * Seeders keep seeding this content in next 24 hours. - * @param author The author of the content - * @param URI The URI of the content - * @param broadcast True to broadcast the transaction on the network - * @ingroup WalletCLI - * @return signed transaction + * Seeders keep seeding this content up to next 24 hours. + * @param author the author of the content + * @param URI the URI of the content + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction cancelling the content + * @ingroup WalletAPI_Content */ signed_transaction content_cancellation(string author, string URI, @@ -109,33 +106,33 @@ signed_transaction content_cancellation(string author, /** * @brief Downloads encrypted content specified by provided URI. - * @param consumer Consumer of the content - * @param URI The URI of the content - * @param region_code_from Two letter region code - * @param broadcast true to broadcast the transaction on the network - * @ingroup WalletCLI + * @param consumer consumer of the content + * @param URI the URI of the content + * @param region_code_from two letter region code + * @param broadcast \c true to broadcast the transaction on the network + * @ingroup WalletAPI_Content */ void download_content(string const& consumer, string const& URI, string const& region_code_from, bool broadcast = false); /** * @brief Get status about particular download process specified by provided URI. - * @param consumer Consumer of the content - * @param URI The URI of the content - * @return Download status, or null if no matching download process was found - * @ingroup WalletCLI + * @param consumer consumer of the content + * @param URI the URI of the content + * @return download status, or \c null if no matching download process was found + * @ingroup WalletAPI_Content */ optional get_download_status(string consumer, string URI) const; /** * @brief This function is used to send a request to buy a content. This request is caught by seeders. - * @param consumer Consumer of the content - * @param URI The URI of the content - * @param price_asset_name Ticker symbol of the asset which will be used to buy content - * @param price_amount The price of the content - * @param str_region_code_from Two letter region code - * @param broadcast true to broadcast the transaction on the network - * @return The signed transaction requesting buying of the content - * @ingroup WalletCLI + * @param consumer consumer of the content + * @param URI the URI of the content + * @param price_asset_name ticker symbol of the asset which will be used to buy content + * @param price_amount the price of the content + * @param str_region_code_from two letter region code + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction requesting buying of the content + * @ingroup WalletAPI_Content */ signed_transaction request_to_buy(string consumer, string URI, @@ -146,15 +143,15 @@ signed_transaction request_to_buy(string consumer, /** * @brief This method allows user to start seeding plugin from running application - * @param account_id_type_or_name Name or ID of account controlling this seeder + * @param account_id_type_or_name name or ID of account controlling this seeder * @param content_private_key El Gamal content private key - * @param seeder_private_key Private key of the account controlling this seeder - * @param free_space Allocated disk space, in MegaBytes + * @param seeder_private_key private key of the account controlling this seeder + * @param free_space allocated disk space, in MegaBytes * @param seeding_price price per MegaByte * @param seeding_symbol seeding price asset, e.g. DCT - * @param packages_path Packages storage path - * @param region_code Optional ISO 3166-1 alpha-2 two-letter region code - * @ingroup WalletCLI + * @param packages_path packages storage path + * @param region_code optional ISO 3166-1 alpha-2 two-letter region code + * @ingroup WalletAPI_Seeding */ void seeding_startup( string account_id_type_or_name, DInteger content_private_key, @@ -163,16 +160,16 @@ void seeding_startup( string account_id_type_or_name, uint32_t seeding_price, string seeding_symbol, string packages_path, - string region_code = "" ); + string region_code = string() ); /** * @brief Rates and comments a content. - * @param consumer Consumer giving the rating - * @param URI The URI of the content - * @param rating Rating - * @param comment Comment - * @param broadcast true to broadcast the transaction on the network - * @ingroup WalletCLI + * @param consumer consumer giving the rating + * @param URI the URI of the content + * @param rating the rating. The available options are 1-5 + * @param comment the maximum length of a comment is 100 characters + * @param broadcast \c true to broadcast the transaction on the network + * @ingroup WalletAPI_Content */ void leave_rating_and_comment(string consumer, string URI, @@ -181,46 +178,45 @@ void leave_rating_and_comment(string consumer, bool broadcast = false); /** - * @brief Get a list of open buyings - * @return Open buying objects - * @ingroup WalletCLI + * @brief Get a list of open buyings. + * @return a list of open buying objects + * @ingroup WalletAPI_Content */ -vector get_open_buyings()const; +vector get_open_buyings() const; /** - * @brief Get a list of open buyings by URI + * @brief Get a list of open buyings by URI. * @param URI URI of the buyings to retrieve - * @return Open buyings corresponding to the provided URI - * @ingroup WalletCLI + * @return a list of open buying objects corresponding to the provided URI + * @ingroup WalletAPI_Content */ -vector get_open_buyings_by_URI( const string& URI )const; +vector get_open_buyings_by_URI( const string& URI ) const; /** - * @brief Get a list of open buyings by consumer - * @param account_id_or_name Consumer of the buyings to retrieve - * @return Open buyings corresponding to the provided consumer - * @ingroup WalletCLI + * @brief Get a list of open buyings by consumer. + * @param account_id_or_name consumer of the buyings to retrieve + * @return a list of open buying objects corresponding to the provided consumer + * @ingroup WalletAPI_Content */ -vector get_open_buyings_by_consumer( const string& account_id_or_name )const; +vector get_open_buyings_by_consumer( const string& account_id_or_name ) const; /** - * @brief Get history buyings by consumer - * @param account_id_or_name Consumer of the buyings to retrieve - * @return History buying objects corresponding to the provided consumer - * @ingroup WalletCLI + * @brief Get history buyings by consumer. + * @param account_id_or_name consumer of the buyings to retrieve + * @return a list of history buying objects corresponding to the provided consumer + * @ingroup WalletAPI_Content */ -vector get_buying_history_objects_by_consumer( const string& account_id_or_name )const; - +vector get_buying_history_objects_by_consumer( const string& account_id_or_name ) const; /** - * @brief Get history buying objects by consumer that match search term - * @param account_id_or_name Consumer of the buyings to retrieve - * @param term Search term to look up in Title and Description - * @param order Sort data by field - * @param id Object_id to start searching from - * @param count Maximum number of contents to fetch (must not exceed 100) - * @return History buying objects corresponding to the provided consumer and matching search term - * @ingroup WalletCLI + * @brief Get history buying objects by consumer that match search term. + * @param account_id_or_name consumer of the buyings to retrieve + * @param term search term to look up in \c title and \c description + * @param order sort data by field. Available options are defined in 'database_api.cpp' + * @param id the id of buying object to start searching from + * @param count maximum number of contents to fetch (must not exceed 100) + * @return a list of history buying objects corresponding to the provided consumer and matching search term + * @ingroup WalletAPI_Content */ vector search_my_purchases(const string& account_id_or_name, const string& term, @@ -229,22 +225,22 @@ vector search_my_purchases(const string& account_id_or_name, uint32_t count) const; /** -* @brief Get buying (open or history) by consumer and URI -* @param account_id_or_name Consumer of the buying to retrieve -* @param URI URI of the buying to retrieve -* @return Buying_objects corresponding to the provided consumer, or null if no matching buying was found -* @ingroup WalletCLI -*/ -optional get_buying_by_consumer_URI( const string& account_id_or_name, const string & URI )const; + * @brief Get buying object (open or history) by consumer and URI. + * @param account_id_or_name consumer of the buying to retrieve + * @param URI the URI of the buying to retrieve + * @return buying objects corresponding to the provided consumer, or null if no matching buying was found + * @ingroup WalletAPI_Content + */ +optional get_buying_by_consumer_URI( const string& account_id_or_name, const string & URI ) const; /** - * @brief Search for term in contents (author, title and description) - * @param user Feedback author - * @param URI The content object URI - * @param id The id of feedback object to start searching from - * @param count Maximum number of feedbacks to fetch - * @return The feedback found - * @ingroup WalletCLI + * @brief Search for term in users' feedbacks. + * @param user the author of the feedback + * @param URI the content object URI + * @param id the id of feedback object to start searching from + * @param count maximum number of feedbacks to fetch + * @return the feedback found + * @ingroup WalletAPI_Content */ vector search_feedback(const string& user, const string& URI, @@ -252,24 +248,25 @@ vector search_feedback(const string& user, uint32_t count) const; /** - * @brief Get a content by URI - * @param URI URI of the content to retrieve - * @return The content corresponding to the provided URI, or null if no matching content was found - * @ingroup WalletCLI + * @brief Get a content by URI. + * @param URI the URI of the content to retrieve + * @return the content corresponding to the provided URI, or \c null if no matching content was found + * @ingroup WalletAPI_Content */ -optional get_content( const string& URI )const; +optional get_content( const string& URI ) const; /** - * @brief Get a list of contents ordered alphabetically by search term - * @param term Search term - * @param order Order field - * @param user Content owner - * @param region_code Two letter region code - * @param id The id of content object to start searching from - * @param type The application and content type to be filtered - * @param count Maximum number of contents to fetch (must not exceed 100) - * @return The contents found - * @ingroup WalletCLI + * @brief Get a list of contents ordered alphabetically by search term. + * @param term search term + * @param order order field. Available options are defined in 'database_api.cpp' + * @param user content owner + * @param region_code two letter region code + * @param id the id of content object to start searching from + * @param type the application and content type to be filtered, separated by comma. + * Available options are defined in 'content_object.hpp' + * @param count maximum number of contents to fetch (must not exceed 100) + * @return the contents found + * @ingroup WalletAPI_Content */ vector search_content(const string& term, const string& order, @@ -277,18 +274,20 @@ vector search_content(const string& term, const string& region_code, const string& id, const string& type, - uint32_t count )const; + uint32_t count ) const; + /** - * @brief Get a list of contents ordered alphabetically by search term - * @param user Content owner - * @param term Search term - * @param order Order field - * @param region_code Two letter region code - * @param id The id of content object to start searching from - * @param type The application and content type to be filtered - * @param count Maximum number of contents to fetch (must not exceed 100) - * @return The contents found - * @ingroup WalletCLI + * @brief Get a list of contents ordered alphabetically by search term. + * @param user content owner + * @param term search term. Available options are defined in 'database_api.cpp' + * @param order order field + * @param region_code two letter region code + * @param id the id of content object to start searching from + * @param type the application and content type to be filtered, separated by comma. + * Available options are defined in 'content_object.hpp' + * @param count maximum number of contents to fetch (must not exceed 100) + * @return the contents found + * @ingroup WalletAPI_Content */ vector search_user_content(const string& user, const string& term, @@ -296,70 +295,74 @@ vector search_user_content(const string& user, const string& region_code, const string& id, const string& type, - uint32_t count )const; + uint32_t count ) const; /** - * @brief Get author and list of co-authors of a content corresponding to the provided URI - * @param URI URI of the content - * @return The autor of the content and the list of co-authors, if provided + * @brief Get author and list of co-authors of a content corresponding to the provided URI. + * @param URI the URI of the content + * @return the autor of the content and the list of co-authors, if provided + * @ingroup WalletAPI_Content */ -pair> get_author_and_co_authors_by_URI( const string& URI )const; +pair> get_author_and_co_authors_by_URI( const string& URI ) const; /** - * @brief Create package from selected files - * @param content_dir Directory containing all content that should be packed - * @param samples_dir Directory containing samples of content - * @param aes_key AES key for encryption - * @return package hash (ripemd160 hash of package content) and content custody data - * @ingroup WalletCLI + * @brief Creates a package from selected files. + * @see \c upload_package() + * @param content_dir the directory containing all content that should be packed + * @param samples_dir the directory containing samples of the content + * @param aes_key the AES key for encryption + * @return the package hash and content custody data + * @ingroup WalletAPI_Content */ std::pair create_package(const std::string& content_dir, const std::string& samples_dir, const DInteger& aes_key) const; - /** - * @brief Extract selected package - * @param package_hash Hash of package that needs to be extracted - * @param output_dir Directory where extracted files will be created - * @param aes_key AES key for decryption - * @ingroup WalletCLI + * @brief Extracts selected package. + * @see \c download_package() + * @param package_hash hash of the package that needs to be extracted + * @param output_dir directory where extracted files will be created + * @param aes_key the AES key for decryption + * @ingroup WalletAPI_Content */ void extract_package(const std::string& package_hash, const std::string& output_dir, const DInteger& aes_key) const; /** - * @brief Download package - * @param url Magnet or IPFS URL of package - * @ingroup WalletCLI + * @brief Downloads the package. + * @param url the URL of the package + * @ingroup WalletAPI_Content */ void download_package(const std::string& url) const; /** - * @brief Start uploading package - * @param package_hash Hash of package that needs to be extracted + * @brief Starts uploading of the package. + * @see \c create_package() + * @param package_hash hash of the package that needs to be extracted * @param protocol protocol for uploading package ( ipfs ) - * @ingroup WalletCLI + * @return URL of package + * @ingroup WalletAPI_Content */ std::string upload_package(const std::string& package_hash, const std::string& protocol) const; /** - * @brief Remove package - * @param package_hash Hash of package that needs to be removed - * @ingroup WalletCLI + * @brief Removes the package. + * @param package_hash hash of the package that needs to be removed + * @ingroup WalletAPI_Content */ void remove_package(const std::string& package_hash) const; /** - * @brief Restores AES key( used to encrypt and decrypt a content) from key particles stored in a buying object - * @param account Consumers account id or name - * @param buying The buying object containing key particles - * @return restored AES key from particles - * @ingroup WalletCLI + * @brief Restores AES key( used to encrypt and decrypt a content) from key particles stored in a buying object. + * @param account consumers account id or name + * @param buying the buying object containing key particles + * @return restored AES key from key particles + * @ingroup WalletAPI_Content */ DInteger restore_encryption_key(std::string account, buying_id_type buying); /** * @brief Generates AES encryption key. - * @return Random encryption key - * @ingroup WalletCLI + * @return random encryption key + * @ingroup WalletAPI_Content */ DInteger generate_encryption_key() const; diff --git a/libraries/wallet/include/graphene/wallet/messaging.hpp b/libraries/wallet/include/graphene/wallet/messaging.hpp index 4d688765..8bf799e3 100644 --- a/libraries/wallet/include/graphene/wallet/messaging.hpp +++ b/libraries/wallet/include/graphene/wallet/messaging.hpp @@ -27,36 +27,40 @@ #define DECENT_WALLET_MESSAGING_H /** - * @brief Send text message - * @param from - * @param to - * @param text + * @brief Sends a text message to one or many users. + * @param from account sending the message + * @param to account or multiple accounts receiving the message + * @param text the body of the message + * @ingroup WalletAPI_Messaging */ void send_message(const std::string& from, std::vector to, string text); /** -* @brief Receives message objects by sender and/or receiver -* @param sender Name of message sender. If you dont want to filter by sender then let it empty. -* @param receiver Name of message receiver. If you dont want to filter by receiver then let it empty. -* @param max_count Maximal number of last messages to be displayed -* @return vector of message objects -*/ + * @brief Receives message objects by sender and/or receiver. + * @param sender name of message sender. If you dont want to filter by sender then let it empty + * @param receiver name of message receiver. If you dont want to filter by receiver then let it empty + * @param max_count maximal number of last messages to be displayed + * @return a vector of message objects + * @ingroup WalletAPI_Messaging + */ vector get_message_objects(const std::string& sender, const std::string& receiver, uint32_t max_count) const; /** -* @brief Receives messages by receiver -* @param receiver Name of message receiver which must be imported to caller's wallet -* @param max_count Maximal number of last messages to be displayed -* @return vector of message objects -*/ + * @brief Receives messages by receiver. + * @param receiver name of message receiver which must be imported to caller's wallet + * @param max_count maximal number of last messages to be displayed + * @return a vector of message objects + * @ingroup WalletAPI_Messaging + */ vector get_messages(const std::string& receiver, uint32_t max_count) const; /** -* @brief Receives sent messages by sender -* @param sender Name of message sender which must be imported to caller's wallet -* @param max_count Maximal number of last messages to be displayed -* @return vector of message objects -*/ + * @brief Receives sent messages by sender. + * @param sender name of message sender which must be imported to caller's wallet + * @param max_count maximal number of last messages to be displayed + * @return a vector of message objects + * @ingroup WalletAPI_Messaging + */ vector get_sent_messages(const std::string& sender, uint32_t max_count) const; #endif //DECENT_WALLET_MESSAGING_H diff --git a/libraries/wallet/include/graphene/wallet/mining.hpp b/libraries/wallet/include/graphene/wallet/mining.hpp index 4ce09b72..d2a3488e 100644 --- a/libraries/wallet/include/graphene/wallet/mining.hpp +++ b/libraries/wallet/include/graphene/wallet/mining.hpp @@ -29,124 +29,109 @@ /** * @brief Lists all miners registered in the blockchain. * This returns a list of all account names that own miners, and the associated miner id, - * sorted by name. This lists miners whether they are currently voted in or not. - * - * Use the \c lowerbound and limit parameters to page through the list. To retrieve all miners, + * sorted by name. This lists miners whether they are currently voted in or not. + * Use the \c lowerbound and \c limit parameters to page through the list. To retrieve all miners, * start by setting \c lowerbound to the empty string \c "", and then each iteration, pass * the last miner name returned as the \c lowerbound for the next \c list_miners() call. - * * @param lowerbound the name of the first miner to return. If the named miner does not exist, * the list will start at the miner that comes after \c lowerbound * @param limit the maximum number of miners to return (max: 1000) - * @returns a list of miners mapping miner names to miner ids - * @ingroup WalletCLI + * @return a list of miners mapping miner names to miner ids + * @ingroup WalletAPI_Mining */ -map list_miners(const string& lowerbound, uint32_t limit); +map list_miners(const string& lowerbound, uint32_t limit); /** - * s@brief Returns information about the given miner. + * @brief Returns information about the given miner. * @param owner_account the name or id of the miner account owner, or the id of the miner - * @returns the information about the miner stored in the block chain - * @ingroup WalletCLI + * @return the information about the miner stored in the block chain + * @ingroup WalletAPI_Mining */ miner_object get_miner(string owner_account); /** - * @brief Creates a miner object owned by the given account. - * - * An account can have at most one miner object. - * - * @param owner_account the name or id of the account which is creating the miner - * @param url a URL to include in the miner record in the blockchain. Clients may - * display this when showing a list of miners. May be blank. - * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction registering a miner - * @ingroup WalletCLI - */ + * @brief Creates a miner object owned by the given account. + * @note an account can have at most one miner object. + * @param owner_account the name or id of the account which is creating the miner + * @param url a URL to include in the miner record in the blockchain. Clients may + * display this when showing a list of miners. May be blank. + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction registering a miner + * @ingroup WalletAPI_Mining + */ signed_transaction create_miner(string owner_account, - string url, - bool broadcast = false); + string url, + bool broadcast = false); /** * @brief Update a miner object owned by the given account. - * - * @param miner_name The name of the miner's owner account. Also accepts the ID of the owner account or the ID of the miner. + * @param miner_name The name of the miner's owner account. Also accepts the ID of the owner account or the ID of the miner. * @param url Same as for create_miner. The empty string makes it remain the same. - * @param block_signing_key The new block signing public key. The empty string makes it remain the same. - * @param broadcast true if you wish to broadcast the transaction. - * @ingroup WalletCLI + * @param block_signing_key the new block signing public key. The empty string makes it remain the same + * @param broadcast \c true if you wish to broadcast the transaction. + * @ingroup WalletAPI_Mining */ signed_transaction update_miner(string miner_name, - string url, - string block_signing_key, - bool broadcast = false); + string url, + string block_signing_key, + bool broadcast = false); /** * @brief Get information about a vesting balance object. - * - * @param account_name An account name, account ID, or vesting balance object ID. - * @ingroup WalletCLI + * @param account_name an account name, account ID, or vesting balance object ID. + * @ingroup WalletAPI_Mining */ vector< vesting_balance_object_with_info > get_vesting_balances( string account_name ); /** * @brief Withdraw a vesting balance. - * - * @param miner_name The account name of the miner, also accepts account ID or vesting balance ID type. - * @param amount The amount to withdraw. - * @param asset_symbol The symbol of the asset to withdraw. - * @param broadcast true if you wish to broadcast the transaction - * @ingroup WalletCLI + * @param miner_name the account name of the miner, also accepts account ID or vesting balance ID type. + * @param amount the amount to withdraw. + * @param asset_symbol the symbol of the asset to withdraw + * @param broadcast \c true if you wish to broadcast the transaction + * @ingroup WalletAPI_Mining */ -signed_transaction withdraw_vesting( - string miner_name, - string amount, - string asset_symbol, - bool broadcast = false); +signed_transaction withdraw_vesting(string miner_name, + string amount, + string asset_symbol, + bool broadcast = false); /** * @brief Vote for a given miner. - * - * An account can publish a list of all miners they approve of. This + * An account can publish a list of all miners they approve of. This * command allows you to add or remove miners from this list. * Each account's vote is weighted according to the number of shares of the * core asset owned by that account at the time the votes are tallied. - * - * @note you cannot vote against a miner, you can only vote for the miner + * @note You cannot vote against a miner, you can only vote for the miner * or not vote for the miner. - * + * @see \c list_miners() * @param voting_account the name or id of the account who is voting with their shares * @param miner the name or id of the miner' owner account - * @param approve true if you wish to vote in favor of that miner, false to + * @param approve \c true if you wish to vote in favor of that miner, \c false to * remove your vote in favor of that miner - * @param broadcast true if you wish to broadcast the transaction + * @param broadcast \c true if you wish to broadcast the transaction * @return the signed transaction changing your vote for the given miner - * @ingroup WalletCLI + * @ingroup WalletAPI_Mining */ signed_transaction vote_for_miner(string voting_account, - string miner, - bool approve, - bool broadcast = false); + string miner, + bool approve, + bool broadcast = false); /** * @brief Set the voting proxy for an account. - * * If a user does not wish to take an active part in voting, they can choose * to allow another account to vote their stake. - * * Setting a vote proxy does not remove your previous votes from the blockchain, - * they remain there but are ignored. If you later null out your vote proxy, + * they remain there but are ignored. If you later null out your vote proxy, * your previous votes will take effect again. - * * This setting can be changed at any time. - * * @param account_to_modify the name or id of the account to update * @param voting_account the name or id of an account authorized to vote account_to_modify's shares, * or null to vote your own shares - * - * @param broadcast true if you wish to broadcast the transaction + * @param broadcast \c true if you wish to broadcast the transaction * @return the signed transaction changing your vote proxy settings - * @ingroup WalletCLI + * @ingroup WalletAPI_Mining */ signed_transaction set_voting_proxy(string account_to_modify, optional voting_account, @@ -154,30 +139,24 @@ signed_transaction set_voting_proxy(string account_to_modify, /** * @brief Set your vote for the number of miners in the system. - * * Each account can voice their opinion on how many - * miners there should be in the active miner list. These - * are independent of each other. You must vote your approval of at least as many + * miners there should be in the active miner list. These + * are independent of each other. You must vote your approval of at least as many * miners as you claim there should be (you can't say that there should * be 20 miners but only vote for 10). - * * There are maximum values for each set in the blockchain parameters (currently * defaulting to 1001). - * - * This setting can be changed at any time. If your account has a voting proxy + * This setting can be changed at any time. If your account has a voting proxy * set, your preferences will be ignored. - * * @param account_to_modify the name or id of the account to update * @param desired_number_of_miners - * @param broadcast true if you wish to broadcast the transaction + * @param broadcast \c true if you wish to broadcast the transaction * @return the signed transaction changing your vote proxy settings - * @ingroup WalletCLI + * @ingroup WalletAPI_Mining */ signed_transaction set_desired_miner_count(string account_to_modify, - uint16_t desired_number_of_miners, - bool broadcast = false); - - + uint16_t desired_number_of_miners, + bool broadcast = false); #endif //DECENT_WALLET_MINING_H diff --git a/libraries/wallet/include/graphene/wallet/proposals.hpp b/libraries/wallet/include/graphene/wallet/proposals.hpp index eabd93d2..165efd83 100644 --- a/libraries/wallet/include/graphene/wallet/proposals.hpp +++ b/libraries/wallet/include/graphene/wallet/proposals.hpp @@ -27,88 +27,78 @@ #define DECENT_WALLET_PROPOSALS_H /** - * Get list of proposed transactions + * @brief Lists proposed transactions relevant to a user + * @param account_or_id the name or id of the account + * @return a list of proposed transactions + * @ingroup WalletAPI_Proposals */ -vector get_proposed_transactions( string account_or_id )const; +vector get_proposed_transactions( string account_or_id ) const; /** * @brief Encapsulates begin_builder_transaction(), add_operation_to_builder_transaction(), - * propose_builder_transaction2(), set_fees_on_builder_transaction() functions for transfer operation - * - * @param proposer Proposer + * propose_builder_transaction2(), set_fees_on_builder_transaction() functions for transfer operation. + * @param proposer proposer * @param from the name or id of the account sending the funds * @param to the name or id of the account receiving the funds - * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) + * @param amount the amount to send (in nominal units -- to send half of a DCT, specify 0.5) * @param asset_symbol the symbol or id of the asset to send * @param memo a memo to attach to the transaction. The memo will be encrypted in the - * transaction and readable for the receiver. There is no length limit - * other than the limit imposed by maximum transaction size, but transaction - * increase with transaction size + * transaction and readable for the receiver. There is no length limit + * other than the limit imposed by maximum transaction size. * @param expiration expiration time - * @ingroup WalletCLI + * @ingroup WalletAPI_Proposals */ - void propose_transfer(string proposer, - string from, - string to, - string amount, - string asset_symbol, - string memo, - time_point_sec expiration - ); - - - /** - * @brief Creates a transaction to propose a parameter change. - * - * Multiple parameters can be specified if an atomic change is - * desired. - * - * @param proposing_account The account paying the fee to propose the tx - * @param expiration_time Timestamp specifying when the proposal will either take effect or expire. - * @param changed_values The values to change; all other chain parameters are filled in with default values - * @param broadcast true if you wish to broadcast the transaction - * @return the signed version of the transaction - * @ingroup WalletCLI - */ - signed_transaction propose_parameter_change( - const string& proposing_account, - fc::time_point_sec expiration_time, - const variant_object& changed_values, - bool broadcast = false); +void propose_transfer(string proposer, + string from, + string to, + string amount, + string asset_symbol, + string memo, + time_point_sec expiration); - /** - * @brief Propose a fee change. - * - * @param proposing_account The account paying the fee to propose the tx - * @param expiration_time Timestamp specifying when the proposal will either take effect or expire. - * @param changed_values Map of operation type to new fee. Operations may be specified by name or ID. - * The "scale" key changes the scale. All other operations will maintain current values. - * @param broadcast true if you wish to broadcast the transaction - * @return the signed version of the transaction - * @ingroup WalletCLI - */ - signed_transaction propose_fee_change( - const string& proposing_account, - fc::time_point_sec expiration_time, - const variant_object& changed_values, - bool broadcast = false); +/** + * @brief Creates a transaction to propose a parameter change. + * Multiple parameters can be specified if an atomic change is + * desired. + * @param proposing_account the account paying the fee to propose the transaction + * @param expiration_time timestamp specifying when the proposal will either take effect or expire + * @param changed_values the values to change; all other chain parameters are filled in with default values + * @param broadcast \c true if you wish to broadcast the transaction + * @return the signed version of the transaction + * @ingroup WalletAPI_Proposals + */ +signed_transaction propose_parameter_change(const string& proposing_account, + fc::time_point_sec expiration_time, + const variant_object& changed_values, + bool broadcast = false); - /** - * - * @brief Approve or disapprove a proposal. - * - * @param fee_paying_account The account paying the fee for the op. - * @param proposal_id The proposal to modify. - * @param delta Members contain approvals to create or remove. In JSON you can leave empty members undefined. - * @param broadcast true if you wish to broadcast the transaction - * @return the signed version of the transaction - * @ingroup WalletCLI - */ - signed_transaction approve_proposal( - const string& fee_paying_account, - const string& proposal_id, - const approval_delta& delta, - bool broadcast /* = false */); +/** + * @brief Propose a fee change. + * @param proposing_account the account paying the fee to propose the transaction + * @param expiration_time timestamp specifying when the proposal will either take effect or expire + * @param changed_values map of operation type to new fee. Operations may be specified by name or ID + * The "scale" key changes the scale. All other operations will maintain current values + * @param broadcast \c true if you wish to broadcast the transaction + * @return the signed version of the transaction + * @ingroup WalletAPI_Proposals + */ +signed_transaction propose_fee_change(const string& proposing_account, + fc::time_point_sec expiration_time, + const variant_object& changed_values, + bool broadcast = false); +/** + * @brief Approve or disapprove a proposal. + * @param fee_paying_account the account paying the fee for the operation + * @param proposal_id the proposal to modify + * @param delta members contain approvals to create or remove. In JSON you can leave empty members undefined + * @param broadcast \c true if you wish to broadcast the transaction + * @return the signed version of the transaction + * @ingroup WalletAPI_Proposals + */ +signed_transaction approve_proposal(const string& fee_paying_account, + const string& proposal_id, + const approval_delta& delta, + bool broadcast /* = false */); #endif //DECENT_WALLET_PROPOSALS_H diff --git a/libraries/wallet/include/graphene/wallet/seeding.hpp b/libraries/wallet/include/graphene/wallet/seeding.hpp index c61147da..f5a8fb3d 100644 --- a/libraries/wallet/include/graphene/wallet/seeding.hpp +++ b/libraries/wallet/include/graphene/wallet/seeding.hpp @@ -26,38 +26,36 @@ #ifndef DECENT_WALLET_SEEDING_H #define DECENT_WALLET_SEEDING_H - /** - * @brief Get a list of seeders by price, in increasing order - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup WalletCLI + * @brief Get a list of seeders by price, in increasing order. + * @param count maximum number of seeders to retrieve + * @return a list of seeders + * @ingroup WalletAPI_Seeding */ vector list_seeders_by_price( uint32_t count )const; /** - * @brief Get a list of seeders ordered by total upload, in decreasing order - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup WalletCLI + * @brief Get a list of seeders ordered by total upload, in decreasing order. + * @param count maximum number of seeders to retrieve + * @return a list of seeders + * @ingroup WalletAPI_Seeding */ optional> list_seeders_by_upload( const uint32_t count )const; /** - * @brief Get a list of seeders by region code - * @param region_code Region code of seeders to retrieve - * @return The seeders found - * @ingroup WalletCLI + * @brief Get a list of seeders by region code. + * @param region_code region code of seeders to retrieve + * @return a list of seeders + * @ingroup WalletAPI_Seeding */ vector list_seeders_by_region( const string region_code )const; /** - * @brief Get a list of seeders ordered by rating, in decreasing order - * @param count Maximum number of seeders to retrieve - * @return The seeders found - * @ingroup WalletCLI + * @brief Get a list of seeders ordered by rating, in decreasing order. + * @param count the maximum number of seeders to retrieve + * @return a list of seeders + * @ingroup WalletAPI_Seeding */ vector list_seeders_by_rating( const uint32_t count )const; - #endif //DECENT_WALLET_SEEDING_H diff --git a/libraries/wallet/include/graphene/wallet/subscription.hpp b/libraries/wallet/include/graphene/wallet/subscription.hpp index 260c4ef8..7b92d1a4 100644 --- a/libraries/wallet/include/graphene/wallet/subscription.hpp +++ b/libraries/wallet/include/graphene/wallet/subscription.hpp @@ -28,13 +28,13 @@ /** * @brief Creates a subscription to author. This function is used by consumers. - * @param from Account who wants subscription to author - * @param to The author you wish to subscribe to - * @param price_amount Price for the subscription - * @param price_asset_symbol Ticker symbol of the asset which will be used to buy subscription ( must be DCT token ) - * @param broadcast True if you wish to broadcast the transaction - * @return The signed transaction subscribing the consumer to the author - * @ingroup WalletCLI + * @param from account who wants subscription to author + * @param to the author you wish to subscribe to + * @param price_amount price for the subscription + * @param price_asset_symbol ticker symbol of the asset which will be used to buy subscription + * @param broadcast \c true if you wish to broadcast the transaction + * @return the signed transaction subscribing the consumer to the author + * @ingroup WalletAPI_Subscription */ signed_transaction subscribe_to_author( string from, string to, @@ -44,11 +44,11 @@ signed_transaction subscribe_to_author( string from, /** * @brief Creates a subscription to author. This function is used by author. - * @param from The account obtaining subscription from the author - * @param to The name or id of the author - * @param broadcast True if you wish to broadcast the transaction - * @return The signed transaction subscribing the consumer to the author - * @ingroup WalletCLI + * @param from the account obtaining subscription from the author + * @param to the name or id of the author + * @param broadcast \c true if you wish to broadcast the transaction + * @return the signed transaction subscribing the consumer to the author + * @ingroup WalletAPI_Subscription */ signed_transaction subscribe_by_author( string from, string to, @@ -56,14 +56,14 @@ signed_transaction subscribe_by_author( string from, /** * @brief This function can be used to allow/disallow subscription. - * @param account The name or id of the account to update - * @param allow_subscription True if account (author) wants to allow subscription, false otherwise - * @param subscription_period Duration of subscription in days - * @param price_amount Price for subscription per one subscription period - * @param price_asset_symbol Ticker symbol of the asset which will be used to buy subscription - * @param broadcast True if you wish to broadcast the transaction - * @return The signed transaction updating the account - * @ingroup WalletCLI + * @param account the name or id of the account to update + * @param allow_subscription \c true if account (author) wants to allow subscription, \c false otherwise + * @param subscription_period duration of subscription in days + * @param price_amount price for subscription per one subscription period + * @param price_asset_symbol ticker symbol of the asset which will be used to buy subscription + * @param broadcast \c true if you wish to broadcast the transaction + * @return the signed transaction updating the account + * @ingroup WalletAPI_Subscription */ signed_transaction set_subscription( string account, bool allow_subscription, @@ -74,12 +74,12 @@ signed_transaction set_subscription( string account, /** * @brief This function can be used to allow/disallow automatic renewal of expired subscription. - * @param account_id_or_name The name or id of the account to update - * @param subscription_id The ID of the subscription. - * @param automatic_renewal True if account (consumer) wants to allow automatic renewal of subscription, false otherwise - * @param broadcast True if you wish to broadcast the transaction - * @return The signed transaction allowing/disallowing renewal of the subscription - * @ingroup WalletCLI + * @param account_id_or_name the name or id of the account to update + * @param subscription_id the ID of the subscription. + * @param automatic_renewal \c true if account (consumer) wants to allow automatic renewal of subscription, \c false otherwise + * @param broadcast \c true if you wish to broadcast the transaction + * @return the signed transaction allowing/disallowing renewal of the subscription + * @ingroup WalletAPI_Subscription */ signed_transaction set_automatic_renewal_of_subscription( string account_id_or_name, subscription_id_type subscription_id, @@ -88,37 +88,37 @@ signed_transaction set_automatic_renewal_of_subscription( string account_id_or_n /** * @brief Get a list of consumer's active (not expired) subscriptions. - * @param account_id_or_name The name or id of the consumer - * @param count Maximum number of subscriptions to fetch (must not exceed 100) - * @return List of active subscription objects corresponding to the provided consumer - * @ingroup WalletCLI + * @param account_id_or_name the name or id of the consumer + * @param count maximum number of subscriptions to fetch (must not exceed 100) + * @return list of active subscription objects corresponding to the provided consumer + * @ingroup WalletAPI_Subscription */ vector< subscription_object > list_active_subscriptions_by_consumer( const string& account_id_or_name, const uint32_t count)const; /** * @brief Get a list of consumer's subscriptions. - * @param account_id_or_name The name or id of the consumer - * @param count Maximum number of subscriptions to fetch (must not exceed 100) - * @return List of subscription objects corresponding to the provided consumer - * @ingroup WalletCLI + * @param account_id_or_name the name or id of the consumer + * @param count maximum number of subscriptions to fetch (must not exceed 100) + * @return list of subscription objects corresponding to the provided consumer + * @ingroup WalletAPI_Subscription */ vector< subscription_object > list_subscriptions_by_consumer( const string& account_id_or_name, const uint32_t count)const; /** * @brief Get a list of active (not expired) subscriptions to author. - * @param account_id_or_name The name or id of the author - * @param count Maximum number of subscriptions to fetch (must not exceed 100) - * @return List of active subscription objects corresponding to the provided author - * @ingroup WalletCLI + * @param account_id_or_name the name or id of the author + * @param count maximum number of subscriptions to fetch (must not exceed 100) + * @return list of active subscription objects corresponding to the provided author + * @ingroup WalletAPI_Subscription */ vector< subscription_object > list_active_subscriptions_by_author( const string& account_id_or_name, const uint32_t count)const; /** * @brief Get a list of subscriptions to author. - * @param account_id_or_name The name or id of the author - * @param count Maximum number of subscriptions to fetch (must not exceed 100) - * @return List of subscription objects corresponding to the provided author - * @ingroup WalletCLI + * @param account_id_or_name the name or id of the author + * @param count maximum number of subscriptions to fetch (must not exceed 100) + * @return list of subscription objects corresponding to the provided author + * @ingroup WalletAPI_Subscription */ vector< subscription_object > list_subscriptions_by_author( const string& account_id_or_name, const uint32_t count)const; diff --git a/libraries/wallet/include/graphene/wallet/transaction_builder.hpp b/libraries/wallet/include/graphene/wallet/transaction_builder.hpp index 8adcd6b5..eeb25566 100644 --- a/libraries/wallet/include/graphene/wallet/transaction_builder.hpp +++ b/libraries/wallet/include/graphene/wallet/transaction_builder.hpp @@ -27,143 +27,133 @@ #define DECENT_WALLET_TRANSACTION_BUILDER_H /** - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Allows creation of customized transactions and fill them with operation/s. + * @return identifier allowing to construct several transactions in parallel and identify them + * @ingroup WalletAPI_TransactionBuilder */ transaction_handle_type begin_builder_transaction(); /** - * - * @param transaction_handle - * @param op - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Adds an operation to a transaction in transaction builder. + * @see \c begin_builder_transaction() + * @param transaction_handle the number indetifying transaction under construction process + * @param op the operation + * @ingroup WalletAPI_TransactionBuilder */ void add_operation_to_builder_transaction(transaction_handle_type transaction_handle, const operation& op); /** - * - * @param handle - * @param operation_index - * @param new_op - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Replace existing operation in specified transaction in transaction builder. + * @see \c add_operation_to_builder_transaction() + * @param handle the number identifying transaction under contruction process + * @param operation_index index of the operation to replace + * @param new_op the new operation replacing the existing one + * @ingroup WalletAPI_TransactionBuilder */ void replace_operation_in_builder_transaction(transaction_handle_type handle, unsigned operation_index, const operation& new_op); + /** - * - * @param handle - * @param fee_asset - * @return - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Set fees on all operations in a transaction + * @see \c begin_builder_transaction() + * @param handle the number identifying transaction under contruction process + * @param fee_asset the asset in which fees are calculated + * @return total fee in specified asset + * @ingroup WalletAPI_TransactionBuilder */ asset set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset = GRAPHENE_SYMBOL); /** - * @param handle - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Previews a transaction from transaction builder. + * @see \c begin_builder_transaction() + * @param handle the number identifying transaction under contruction process + * @return the transaction to preview + * @ingroup WalletAPI_TransactionBuilder */ transaction preview_builder_transaction(transaction_handle_type handle); /** - * - * @param transaction_handle - * @param broadcast true to broadcast the transaction on the network - * @return - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Signs a transaction from transaction builder + * @see \c prewiev_builder_transaction() + * @param transaction_handle the number identifying transaction under contruction process + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction + * @ingroup WalletAPI_TransactionBuilder */ signed_transaction sign_builder_transaction(transaction_handle_type transaction_handle, bool broadcast = true); /** - * - * @param handle - * @param expiration - * @param review_period_seconds - * @param broadcast true to broadcast the transaction on the network - * @return - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Allows creation of a proposed transaction suitable for miner-account. Proposed transaction requires approval of multiple accounts in order to execute. + * @param handle the number identifying transaction under contruction process + * @param expiration the expiration time of the transaction + * @param review_period_seconds the time reserved for reviewing the proposal transaction. It's not allowed to vote for the proposal when the transaction is under review + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction + * @ingroup WalletAPI_TransactionBuilder */ -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 -); +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); /** - * - * @param handle - * @param account_name_or_id - * @param expiration - * @param review_period_seconds - * @param broadcast true to broadcast the transaction on the network - * @return - * @ingroup WalletCLI + * @brief Allows creation of a proposed transaction. Proposed transaction requires approval of multiple accounts in order to execute. + * @see \c propose_builder_transaction() + * @param handle the number identifying transaction under contruction process + * @param account_name_or_id the account which will pay the fee to propose the transaction + * @param expiration the expiration time of the transaction + * @param review_period_seconds the time reserved for reviewing the proposal transaction. It's not allowed to vote for the proposal when the transaction is under review + * @param broadcast \c true to broadcast the transaction on the network + * @return the signed transaction + * @ingroup WalletAPI_TransactionBuilder */ -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 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); /** - * - * @param handle - * @ingroup Transaction Builder API - * @ingroup WalletCLI + * @brief Removes a transaction from transaction builder + * @param handle the number identifying transaction under contruction process + * @ingroup WalletAPI_TransactionBuilder */ void remove_builder_transaction(transaction_handle_type handle); +// TODO: I don't see a broadcast_transaction() function, do we need one? /** * @brief Converts a signed_transaction in JSON form to its binary representation. - * - * TODO: I don't see a broadcast_transaction() function, do we need one? - * * @param tx the transaction to serialize - * @returns the binary form of the transaction. It will not be hex encoded, - * this returns a raw string that may have null characters embedded - * in it - * @ingroup WalletCLI + * @return the binary form of the transaction. It will not be hex encoded, + * this returns a raw string that may have null characters embedded in it + * @ingroup WalletAPI_TransactionBuilder */ string serialize_transaction(signed_transaction tx) const; /** * @brief Signs a transaction. - * * Given a fully-formed transaction that is only lacking signatures, this signs * the transaction with the necessary keys and optionally broadcasts the transaction * @param tx the unsigned transaction - * @param broadcast true if you wish to broadcast the transaction + * @param broadcast \c true if you wish to broadcast the transaction * @return the signed version of the transaction - * @ingroup WalletCLI + * @ingroup WalletAPI_TransactionBuilder */ signed_transaction sign_transaction(signed_transaction tx, bool broadcast = false); /** * @brief Returns an uninitialized object representing a given blockchain operation. - * - * This returns a default-initialized object of the given type; it can be used - * during early development of the wallet when we don't yet have custom commands for - * creating all of the operations the blockchain supports. - * + * This returns a default-initialized object of the given type. * Any operation the blockchain supports can be created using the transaction builder's * \c add_operation_to_builder_transaction() , but to do that from the CLI you need to - * know what the JSON form of the operation looks like. This will give you a template - * you can fill in. It's better than nothing. - * + * know what the JSON form of the operation looks like. This will give you a template + * you can fill in. * @param operation_type the type of operation to return, must be one of the * operations defined in `graphene/chain/operations.hpp` * (e.g., "global_parameters_update_operation") * @return a default-constructed operation of the given type - * @ingroup WalletCLI + * @ingroup WalletAPI_TransactionBuilder */ operation get_prototype_operation(string operation_type); diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index a9a26ca9..fb7ac084 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -369,7 +369,7 @@ FC_API( graphene::wallet::wallet_api, (get_object) (info) (help) - (gethelp) + (get_help) (head_block_time) (network_add_nodes) (network_get_connected_peers) diff --git a/libraries/wallet/wallet_general.inl b/libraries/wallet/wallet_general.inl index f53dc96d..06d329d3 100644 --- a/libraries/wallet/wallet_general.inl +++ b/libraries/wallet/wallet_general.inl @@ -70,7 +70,7 @@ string wallet_api::help()const return ss.str(); } -string wallet_api::gethelp(const string& method)const +string wallet_api::get_help(const string& method)const { fc::api tmp; std::stringstream ss; From 97166b92dd89da3c422b173a233e475342a30629 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 21 Feb 2018 11:28:25 +0100 Subject: [PATCH 054/136] fixed comments --- libraries/app/include/graphene/app/database_api.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 9d273926..b5664d9f 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -349,7 +349,7 @@ namespace graphene { namespace app { * @param id object_id to start searching from * @param limit the number of entries to return (starting from the most recent) (max 100) * @returns a list of \c transaction_detail_object - * @ingroup WalletCLI + * @ingroup DatabaseAPI */ vector search_account_history(account_id_type const& account, string const& order, @@ -478,7 +478,7 @@ namespace graphene { namespace app { * @param account_id id of the account * @param count Maximum number of price feeds to fetch (must not exceed 100) * @returns list of price feeds published by the miner - * @ingroup WalletCLI + * @ingroup DatabaseAPI */ multimap< time_point_sec, price_feed> get_feeds_by_miner(const account_id_type account_id, const uint32_t count)const; From afaa50666c894a38e2c00f40d85ae3ca3f88c835 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 21 Feb 2018 11:38:19 +0100 Subject: [PATCH 055/136] fixed comments and changed string to const string& --- .../include/graphene/wallet/account.hpp | 46 +++--- .../wallet/include/graphene/wallet/assets.hpp | 72 +++++----- .../include/graphene/wallet/content.hpp | 60 ++++---- .../include/graphene/wallet/general.hpp | 10 +- .../include/graphene/wallet/messaging.hpp | 2 +- .../wallet/include/graphene/wallet/mining.hpp | 28 ++-- .../include/graphene/wallet/proposals.hpp | 14 +- .../include/graphene/wallet/seeding.hpp | 2 +- .../include/graphene/wallet/subscription.hpp | 20 +-- .../graphene/wallet/transaction_builder.hpp | 2 +- .../wallet/include/graphene/wallet/wallet.hpp | 4 - .../include/graphene/wallet/wallet_file.hpp | 52 ++----- libraries/wallet/wallet.cpp | 4 +- libraries/wallet/wallet_account.inl | 25 ++-- libraries/wallet/wallet_assets.inl | 67 ++++----- libraries/wallet/wallet_content.inl | 114 ++++++++------- libraries/wallet/wallet_general.inl | 17 +-- libraries/wallet/wallet_messaging.inl | 2 +- libraries/wallet/wallet_mining.inl | 44 +++--- libraries/wallet/wallet_proposals.inl | 41 +++--- libraries/wallet/wallet_seeding.inl | 2 +- libraries/wallet/wallet_subscription.inl | 20 +-- .../wallet/wallet_transaction_builder.inl | 2 +- libraries/wallet/wallet_wallet_file.inl | 131 +----------------- 24 files changed, 315 insertions(+), 466 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/account.hpp b/libraries/wallet/include/graphene/wallet/account.hpp index e16656b6..a3626831 100644 --- a/libraries/wallet/include/graphene/wallet/account.hpp +++ b/libraries/wallet/include/graphene/wallet/account.hpp @@ -78,9 +78,9 @@ vector list_account_balances(const string& id); * @return a list of transaction detail objects * @ingroup WalletAPI_Account */ -vector search_account_history(string const& account_name, - string const& order, - string const& id, +vector search_account_history(const string& account_name, + const string& order, + const string& id, int limit) const; @@ -93,25 +93,25 @@ vector search_account_history(string const& acc * @return a list of operation history objects * @ingroup WalletAPI_Account */ -vector get_account_history(string name, int limit)const; +vector get_account_history(const string& name, int limit) const; /** * @breif Get operations relevant to the specified account referenced * by an event numbering specific to the account. The current number of operations * for the account can be found in the account statistics (or use 0 for start). - * @param account The account whose history should be queried + * @param name The account whose history should be queried * @param stop Sequence number of earliest operation. 0 is default and will * query 'limit' number of operations. * @param limit Maximum number of operations to retrieve (must not exceed 100) * @param start Sequence number of the most recent operation to retrieve. * 0 is default, which will start querying from the most recent operation. * @return A list of operations performed by account, ordered from most recent to oldest. - * @ingroup WalletCLI + * @ingroup WalletAPI_Account */ -vector get_relative_account_history(string name, +vector get_relative_account_history(const string& name, uint32_t stop, int limit, - uint32_t start)const; + uint32_t start) const; /** @@ -121,7 +121,7 @@ vector get_relative_account_history(string name, * @return the public account data stored in the blockchain * @ingroup WalletAPI_Account */ -account_object get_account(string account_name_or_id) const; +account_object get_account(const string& account_name_or_id) const; /** * @brief Derive private key from given prefix and sequence. @@ -141,7 +141,7 @@ fc::ecc::private_key derive_private_key(const std::string& prefix_string, int se * @return a suggested brain key * @ingroup WalletAPI_Account */ -brain_key_info suggest_brain_key()const; +brain_key_info suggest_brain_key() const; /** * @brief Calculates the private key and public key corresponding to any brain key @@ -149,7 +149,7 @@ brain_key_info suggest_brain_key()const; * @return the corresponding \c brain_key_info * @ingroup WalletAPI_Account */ -brain_key_info get_brain_key_info(string const& brain_key) const; +brain_key_info get_brain_key_info(const string& brain_key) const; /** * @brief Suggests a safe brain key to use for creating your account. This funcion also @@ -182,10 +182,10 @@ pair generate_brain_key_el_gamal_key() const; * @return the signed transaction registering the account * @ingroup WalletAPI_Account */ -signed_transaction register_account(string name, +signed_transaction register_account(const string& name, public_key_type owner, public_key_type active, - string registrar_account, + const string& registrar_account, bool broadcast = false); /** @@ -199,9 +199,9 @@ signed_transaction register_account(string name, * @return the signed transaction registering the account * @ingroup WalletAPI_Account */ -signed_transaction create_account_with_brain_key(string brain_key, - string account_name, - string registrar_account, +signed_transaction create_account_with_brain_key(const string& brain_key, + const string& account_name, + const string& registrar_account, bool broadcast = false); /** @@ -216,13 +216,13 @@ signed_transaction create_account_with_brain_key(string brain_key, * @note transaction fee is fixed and does not depend on the length of the memo * @param broadcast \c true to broadcast the transaction on the network * @return the signed transaction transferring funds - * @ingroup WalletAPI_General + * @ingroup WalletAPI_Account */ -signed_transaction transfer(string from, - string to, - string amount, - string asset_symbol, - string memo, +signed_transaction transfer(const string& from, + const string& to, + const string& amount, + const string& asset_symbol, + const string& memo, bool broadcast = false); /** @@ -237,7 +237,7 @@ el_gamal_key_pair generate_el_gamal_keys() const; * @return pair of El Gamal keys * @ingroup WalletAPI_Account */ -el_gamal_key_pair_str get_el_gammal_key(string const& consumer) const; +el_gamal_key_pair_str get_el_gammal_key(const string& consumer) const; #endif //DECENT_WALLET_ACCOUNT_H diff --git a/libraries/wallet/include/graphene/wallet/assets.hpp b/libraries/wallet/include/graphene/wallet/assets.hpp index 07a72ac3..8275edbb 100644 --- a/libraries/wallet/include/graphene/wallet/assets.hpp +++ b/libraries/wallet/include/graphene/wallet/assets.hpp @@ -43,7 +43,7 @@ vector list_assets(const string& lowerbound, uint32_t * @return the information about the asset stored in the block chain * @ingroup WalletAPI_Asset */ -asset_object get_asset(string asset_name_or_id) const; +asset_object get_asset(const string& asset_name_or_id) const; /** * @brief Returns the specific data for a given monitored asset. @@ -52,15 +52,7 @@ asset_object get_asset(string asset_name_or_id) const; * @return the specific data for this monitored asset * @ingroup WalletAPI_Asset */ -monitored_asset_options get_monitored_asset_data(string asset_name_or_id)const; - -/** - * @brief Lookup the id of a named asset. - * @param asset_name_or_id the symbol of an asset to look up - * @return the id of the given asset - * @ingroup WalletAPI_Asset - */ -asset_id_type get_asset_id(string asset_name_or_id) const; //obsolete +monitored_asset_options get_monitored_asset_data(const string& asset_name_or_id)const; /** * @brief Creates a new monitored asset. @@ -77,10 +69,10 @@ asset_id_type get_asset_id(string asset_name_or_id) const; * @return the signed transaction creating a new asset * @ingroup WalletAPI_Asset */ -signed_transaction create_monitored_asset(string issuer, - string symbol, +signed_transaction create_monitored_asset(const string& issuer, + const string& symbol, uint8_t precision, - string description, + const string& description, uint32_t feed_lifetime_sec, uint8_t minimum_feeds, bool broadcast = false); @@ -95,8 +87,8 @@ signed_transaction create_monitored_asset(string issuer, * @return the signed transaction updating the monitored asset * @ingroup WalletAPI_Asset */ -signed_transaction update_monitored_asset(string symbol, - string description, +signed_transaction update_monitored_asset(const string& symbol, + const string& description, uint32_t feed_lifetime_sec, uint8_t minimum_feeds, bool broadcast = false); @@ -121,10 +113,10 @@ signed_transaction update_monitored_asset(string symbol, * @return the signed transaction creating a new asset * @ingroup WalletAPI_Asset */ -signed_transaction create_user_issued_asset(string issuer, - string symbol, +signed_transaction create_user_issued_asset(const string& issuer, + const string& symbol, uint8_t precision, - string description, + const string& description, uint64_t max_supply, price core_exchange_rate, bool is_exchangeable, @@ -140,11 +132,11 @@ signed_transaction create_user_issued_asset(string issuer, * @return the signed transaction issuing the new shares * @ingroup WalletAPI_Asset */ -signed_transaction issue_asset(string to_account, - string amount, - string symbol, - string memo, - bool broadcast = false); +signed_transaction issue_asset(const string& to_account, + const string& amount, + const string& symbol, + const string& memo, + bool broadcast = false); /** * @brief Update the parameters specific to a user issued asset. @@ -160,9 +152,9 @@ signed_transaction issue_asset(string to_account, * @return the signed transaction updating the user-issued asset * @ingroup WalletAPI_Asset */ -signed_transaction update_user_issued_asset(string symbol, - string new_issuer, - string description, +signed_transaction update_user_issued_asset(const string& symbol, + const string& new_issuer, + const string& description, uint64_t max_supply, price core_exchange_rate, bool is_exchangeable, @@ -181,11 +173,11 @@ signed_transaction update_user_issued_asset(string symbol, * @return the signed transaction funding the asset pools * @ingroup WalletAPI_Asset */ -signed_transaction fund_asset_pools(string from, - string uia_amount, - string uia_symbol, - string dct_amount, - string dct_symbol, +signed_transaction fund_asset_pools(const string& from, + const string& uia_amount, + const string& uia_symbol, + const string& dct_amount, + const string& dct_symbol, bool broadcast = false); /** @@ -199,9 +191,9 @@ signed_transaction fund_asset_pools(string from, * @return the signed transaction burning the asset * @ingroup WalletAPI_Asset */ -signed_transaction reserve_asset(string from, - string amount, - string symbol, +signed_transaction reserve_asset(const string& from, + const string& amount, + const string& symbol, bool broadcast = false); /** @@ -215,10 +207,10 @@ signed_transaction reserve_asset(string from, * @return the signed transaction claiming the fees * @ingroup WalletAPI_Asset */ -signed_transaction claim_fees(string uia_amount, - string uia_symbol, - string dct_amount, - string dct_symbol, +signed_transaction claim_fees(const string& uia_amount, + const string& uia_symbol, + const string& dct_amount, + const string& dct_symbol, bool broadcast = false); /** @@ -243,8 +235,8 @@ string price_to_dct(const string& amount, const string& asset_symbol_or_id); * @return the signed transaction updating the price feed for the given asset * @ingroup WalletAPI_Asset */ -signed_transaction publish_asset_feed(string publishing_account, - string symbol, +signed_transaction publish_asset_feed(const string& publishing_account, + const string& symbol, price_feed feed, bool broadcast = false); diff --git a/libraries/wallet/include/graphene/wallet/content.hpp b/libraries/wallet/include/graphene/wallet/content.hpp index 43305051..9a1b59e2 100644 --- a/libraries/wallet/include/graphene/wallet/content.hpp +++ b/libraries/wallet/include/graphene/wallet/content.hpp @@ -50,7 +50,7 @@ * @ingroup WalletAPI_Content */ signed_transaction submit_content(const string& author, - vector< pair< string, uint32_t>> co_authors, + const vector< pair< string, uint32_t>>& co_authors, const string& URI, const vector & price_amounts, uint64_t size, @@ -81,15 +81,15 @@ signed_transaction submit_content(const string& author, * @param synopsis the description of the content * @ingroup WalletAPI_Content */ -void submit_content_async( string const &author, - vector< pair< string, uint32_t>> co_authors, - string const &content_dir, - string const &samples_dir, - string const &protocol, - vector const &price_amounts, - vector const &seeders, - fc::time_point_sec const &expiration, - string const &synopsis); +void submit_content_async( const string& author, + const vector< pair< string, uint32_t>>& co_authors, + const string& content_dir, + const string& samples_dir, + const string& protocol, + const vector& price_amounts, + const vector& seeders, + const fc::time_point_sec& expiration, + const string& synopsis); /** * @brief This function can be used to cancel submitted content. This content is immediately not available to purchase. @@ -100,8 +100,8 @@ void submit_content_async( string const &author, * @return the signed transaction cancelling the content * @ingroup WalletAPI_Content */ -signed_transaction content_cancellation(string author, - string URI, +signed_transaction content_cancellation(const string& author, + const string& URI, bool broadcast); /** @@ -112,7 +112,7 @@ signed_transaction content_cancellation(string author, * @param broadcast \c true to broadcast the transaction on the network * @ingroup WalletAPI_Content */ -void download_content(string const& consumer, string const& URI, string const& region_code_from, bool broadcast = false); +void download_content(const string& consumer, const string& URI, const string& region_code_from, bool broadcast = false); /** * @brief Get status about particular download process specified by provided URI. @@ -121,7 +121,7 @@ void download_content(string const& consumer, string const& URI, string const& r * @return download status, or \c null if no matching download process was found * @ingroup WalletAPI_Content */ -optional get_download_status(string consumer, string URI) const; +optional get_download_status(const string& consumer, const string& URI) const; /** * @brief This function is used to send a request to buy a content. This request is caught by seeders. @@ -134,11 +134,11 @@ optional get_download_status(string consumer, string UR * @return the signed transaction requesting buying of the content * @ingroup WalletAPI_Content */ -signed_transaction request_to_buy(string consumer, - string URI, - string price_asset_name, - string price_amount, - string str_region_code_from, +signed_transaction request_to_buy(const string& consumer, + const string& URI, + const string& price_asset_name, + const string& price_amount, + const string& str_region_code_from, bool broadcast); /** @@ -153,14 +153,14 @@ signed_transaction request_to_buy(string consumer, * @param region_code optional ISO 3166-1 alpha-2 two-letter region code * @ingroup WalletAPI_Seeding */ -void seeding_startup( string account_id_type_or_name, +void seeding_startup( const string& account_id_type_or_name, DInteger content_private_key, - string seeder_private_key, + const string& seeder_private_key, uint64_t free_space, uint32_t seeding_price, - string seeding_symbol, - string packages_path, - string region_code = string() ); + const string& seeding_symbol, + const string& packages_path, + const string& region_code = string() ); /** * @brief Rates and comments a content. @@ -171,10 +171,10 @@ void seeding_startup( string account_id_type_or_name, * @param broadcast \c true to broadcast the transaction on the network * @ingroup WalletAPI_Content */ -void leave_rating_and_comment(string consumer, - string URI, +void leave_rating_and_comment(const string& consumer, + const string& URI, uint64_t rating, - string comment, + const string& comment, bool broadcast = false); /** @@ -314,7 +314,9 @@ pair> get_author_and_co_authors_by_URI( * @return the package hash and content custody data * @ingroup WalletAPI_Content */ -std::pair create_package(const std::string& content_dir, const std::string& samples_dir, const DInteger& aes_key) const; +std::pair create_package(const std::string& content_dir, + const std::string& samples_dir, + const DInteger& aes_key) const; /** * @brief Extracts selected package. @@ -357,7 +359,7 @@ void remove_package(const std::string& package_hash) const; * @return restored AES key from key particles * @ingroup WalletAPI_Content */ -DInteger restore_encryption_key(std::string account, buying_id_type buying); +DInteger restore_encryption_key(const string& account, buying_id_type buying); /** * @brief Generates AES encryption key. diff --git a/libraries/wallet/include/graphene/wallet/general.hpp b/libraries/wallet/include/graphene/wallet/general.hpp index c7eb9d3d..5e354424 100644 --- a/libraries/wallet/include/graphene/wallet/general.hpp +++ b/libraries/wallet/include/graphene/wallet/general.hpp @@ -113,8 +113,8 @@ string get_help(const string& method) const; * @return the signed buffer * @ingroup WalletAPI_General */ -std::string sign_buffer(std::string const& str_buffer, - std::string const& str_brainkey) const; +std::string sign_buffer(const std::string& str_buffer, + const std::string& str_brainkey) const; /** * @brief Verify if the signature is valid. @@ -124,9 +124,9 @@ std::string sign_buffer(std::string const& str_buffer, * @return \c true if valid, otherwise \c false * @ingroup WalletAPI_General */ -bool verify_signature(std::string const& str_buffer, - std::string const& str_publickey, - std::string const& str_signature) const; +bool verify_signature(const std::string& str_buffer, + const std::string& str_publickey, + const std::string& str_signature) const; /** * @brief diff --git a/libraries/wallet/include/graphene/wallet/messaging.hpp b/libraries/wallet/include/graphene/wallet/messaging.hpp index 8bf799e3..6784dfbb 100644 --- a/libraries/wallet/include/graphene/wallet/messaging.hpp +++ b/libraries/wallet/include/graphene/wallet/messaging.hpp @@ -33,7 +33,7 @@ * @param text the body of the message * @ingroup WalletAPI_Messaging */ -void send_message(const std::string& from, std::vector to, string text); +void send_message(const std::string& from, const std::vector& to, const string& text); /** * @brief Receives message objects by sender and/or receiver. diff --git a/libraries/wallet/include/graphene/wallet/mining.hpp b/libraries/wallet/include/graphene/wallet/mining.hpp index d2a3488e..11d1fa6d 100644 --- a/libraries/wallet/include/graphene/wallet/mining.hpp +++ b/libraries/wallet/include/graphene/wallet/mining.hpp @@ -47,7 +47,7 @@ map list_miners(const string& lowerbound, uint32_t limit) * @return the information about the miner stored in the block chain * @ingroup WalletAPI_Mining */ -miner_object get_miner(string owner_account); +miner_object get_miner(const string& owner_account); /** * @brief Creates a miner object owned by the given account. @@ -59,8 +59,8 @@ miner_object get_miner(string owner_account); * @return the signed transaction registering a miner * @ingroup WalletAPI_Mining */ -signed_transaction create_miner(string owner_account, - string url, +signed_transaction create_miner(const string& owner_account, + const string& url, bool broadcast = false); /** @@ -71,9 +71,9 @@ signed_transaction create_miner(string owner_account, * @param broadcast \c true if you wish to broadcast the transaction. * @ingroup WalletAPI_Mining */ -signed_transaction update_miner(string miner_name, - string url, - string block_signing_key, +signed_transaction update_miner(const string& miner_name, + const string& url, + const string& block_signing_key, bool broadcast = false); /** @@ -81,7 +81,7 @@ signed_transaction update_miner(string miner_name, * @param account_name an account name, account ID, or vesting balance object ID. * @ingroup WalletAPI_Mining */ -vector< vesting_balance_object_with_info > get_vesting_balances( string account_name ); +vector< vesting_balance_object_with_info > get_vesting_balances( const string& account_name ); /** * @brief Withdraw a vesting balance. @@ -91,9 +91,9 @@ vector< vesting_balance_object_with_info > get_vesting_balances( string account_ * @param broadcast \c true if you wish to broadcast the transaction * @ingroup WalletAPI_Mining */ -signed_transaction withdraw_vesting(string miner_name, - string amount, - string asset_symbol, +signed_transaction withdraw_vesting(const string& miner_name, + const string& amount, + const string& asset_symbol, bool broadcast = false); /** @@ -113,8 +113,8 @@ signed_transaction withdraw_vesting(string miner_name, * @return the signed transaction changing your vote for the given miner * @ingroup WalletAPI_Mining */ -signed_transaction vote_for_miner(string voting_account, - string miner, +signed_transaction vote_for_miner(const string& voting_account, + const string& miner, bool approve, bool broadcast = false); @@ -133,7 +133,7 @@ signed_transaction vote_for_miner(string voting_account, * @return the signed transaction changing your vote proxy settings * @ingroup WalletAPI_Mining */ -signed_transaction set_voting_proxy(string account_to_modify, +signed_transaction set_voting_proxy(const string& account_to_modify, optional voting_account, bool broadcast = false); @@ -154,7 +154,7 @@ signed_transaction set_voting_proxy(string account_to_modify, * @return the signed transaction changing your vote proxy settings * @ingroup WalletAPI_Mining */ -signed_transaction set_desired_miner_count(string account_to_modify, +signed_transaction set_desired_miner_count(const string& account_to_modify, uint16_t desired_number_of_miners, bool broadcast = false); diff --git a/libraries/wallet/include/graphene/wallet/proposals.hpp b/libraries/wallet/include/graphene/wallet/proposals.hpp index 165efd83..94404de2 100644 --- a/libraries/wallet/include/graphene/wallet/proposals.hpp +++ b/libraries/wallet/include/graphene/wallet/proposals.hpp @@ -32,7 +32,7 @@ * @return a list of proposed transactions * @ingroup WalletAPI_Proposals */ -vector get_proposed_transactions( string account_or_id ) const; +vector get_proposed_transactions( const string& account_or_id ) const; /** * @brief Encapsulates begin_builder_transaction(), add_operation_to_builder_transaction(), @@ -48,12 +48,12 @@ vector get_proposed_transactions( string account_or_id ) const; * @param expiration expiration time * @ingroup WalletAPI_Proposals */ -void propose_transfer(string proposer, - string from, - string to, - string amount, - string asset_symbol, - string memo, +void propose_transfer(const string& proposer, + const string& from, + const string& to, + const string& amount, + const string& asset_symbol, + const string& memo, time_point_sec expiration); /** diff --git a/libraries/wallet/include/graphene/wallet/seeding.hpp b/libraries/wallet/include/graphene/wallet/seeding.hpp index f5a8fb3d..66063b9a 100644 --- a/libraries/wallet/include/graphene/wallet/seeding.hpp +++ b/libraries/wallet/include/graphene/wallet/seeding.hpp @@ -48,7 +48,7 @@ optional> list_seeders_by_upload( const uint32_t count )co * @return a list of seeders * @ingroup WalletAPI_Seeding */ -vector list_seeders_by_region( const string region_code )const; +vector list_seeders_by_region( const string& region_code )const; /** * @brief Get a list of seeders ordered by rating, in decreasing order. diff --git a/libraries/wallet/include/graphene/wallet/subscription.hpp b/libraries/wallet/include/graphene/wallet/subscription.hpp index 7b92d1a4..de3beaf1 100644 --- a/libraries/wallet/include/graphene/wallet/subscription.hpp +++ b/libraries/wallet/include/graphene/wallet/subscription.hpp @@ -36,10 +36,10 @@ * @return the signed transaction subscribing the consumer to the author * @ingroup WalletAPI_Subscription */ -signed_transaction subscribe_to_author( string from, - string to, - string price_amount, - string price_asset_symbol, +signed_transaction subscribe_to_author( const string& from, + const string& to, + const string& price_amount, + const string& price_asset_symbol, bool broadcast/* = false */); /** @@ -50,8 +50,8 @@ signed_transaction subscribe_to_author( string from, * @return the signed transaction subscribing the consumer to the author * @ingroup WalletAPI_Subscription */ -signed_transaction subscribe_by_author( string from, - string to, +signed_transaction subscribe_by_author( const string& from, + const string& to, bool broadcast/* = false */); /** @@ -65,11 +65,11 @@ signed_transaction subscribe_by_author( string from, * @return the signed transaction updating the account * @ingroup WalletAPI_Subscription */ -signed_transaction set_subscription( string account, +signed_transaction set_subscription( const string& account, bool allow_subscription, uint32_t subscription_period, - string price_amount, - string price_asset_symbol, + const string& price_amount, + const string& price_asset_symbol, bool broadcast/* = false */); /** @@ -81,7 +81,7 @@ signed_transaction set_subscription( string account, * @return the signed transaction allowing/disallowing renewal of the subscription * @ingroup WalletAPI_Subscription */ -signed_transaction set_automatic_renewal_of_subscription( string account_id_or_name, +signed_transaction set_automatic_renewal_of_subscription( const string& account_id_or_name, subscription_id_type subscription_id, bool automatic_renewal, bool broadcast/* = false */); diff --git a/libraries/wallet/include/graphene/wallet/transaction_builder.hpp b/libraries/wallet/include/graphene/wallet/transaction_builder.hpp index eeb25566..347fef57 100644 --- a/libraries/wallet/include/graphene/wallet/transaction_builder.hpp +++ b/libraries/wallet/include/graphene/wallet/transaction_builder.hpp @@ -155,7 +155,7 @@ signed_transaction sign_transaction(signed_transaction tx, bool broadcast = fals * @return a default-constructed operation of the given type * @ingroup WalletAPI_TransactionBuilder */ -operation get_prototype_operation(string operation_type); +operation get_prototype_operation(const string& operation_type); #endif //DECENT_TRANSACTION_BUILDER_H diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index fb7ac084..7982934f 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -383,8 +383,6 @@ FC_API( graphene::wallet::wallet_api, (load_wallet_file) (save_wallet_file) (import_key) - (import_accounts) //obsolete - (import_account_keys) //obsolete (dump_private_keys) //Account @@ -396,11 +394,9 @@ FC_API( graphene::wallet::wallet_api, (get_account_history) (get_relative_account_history) (get_account) -// (get_account_id) //obsolete (suggest_brain_key) (register_account) (create_account_with_brain_key) -// (create_account_with_brain_key_noimport) (transfer) (generate_el_gamal_keys) (get_el_gammal_key) diff --git a/libraries/wallet/include/graphene/wallet/wallet_file.hpp b/libraries/wallet/include/graphene/wallet/wallet_file.hpp index bbc7d594..73296a06 100644 --- a/libraries/wallet/include/graphene/wallet/wallet_file.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet_file.hpp @@ -26,14 +26,6 @@ #ifndef DECENT_WALLET_WALLET_FILE_H #define DECENT_WALLET_WALLET_FILE_H -/** - * @brief Copy wallet file to a new file. - * @param destination_filename - * @return \c true if the wallet is copied,\c false otherwise - * @ingroup WalletAPI_Wallet - */ -bool copy_wallet_file( string destination_filename ); //obsolete - /** * @brief Lists all accounts controlled by this wallet. * This returns a list of the full account objects for all accounts whose private keys @@ -41,7 +33,7 @@ bool copy_wallet_file( string destination_filename ); //obsolete * @return a list of accounts imported in the wallet * @ingroup WalletAPI_Wallet */ -vector list_my_accounts(); +vector list_my_accounts(); /** @brief Returns the current wallet filename. * @note This is the filename that will be used when automatically saving the wallet. @@ -49,7 +41,7 @@ vector list_my_accounts(); * @return the wallet filename * @ingroup WalletAPI_Wallet */ -string get_wallet_filename() const; +string get_wallet_filename() const; /** * @brief Get the WIF private key corresponding to a public key. The @@ -58,7 +50,7 @@ string get_wallet_filename() const; * @return WIF private key corresponding to a public key * @ingroup WalletAPI_Wallet */ -string get_private_key( public_key_type pubkey) const; +string get_private_key( public_key_type pubkey) const; /** * @brief Checks whether the wallet has just been created and has not yet had a password set. @@ -66,7 +58,7 @@ string get_private_key( public_key_type pubkey) const * @return \c true if the wallet is new * @ingroup WalletAPI_Wallet */ -bool is_new()const; +bool is_new() const; /** * @brief Checks whether the wallet is locked (is unable to use its private keys). @@ -75,14 +67,14 @@ bool is_new()const; * @return \c true if the wallet is locked * @ingroup WalletAPI_Wallet */ -bool is_locked()const; +bool is_locked() const; /** * @brief Locks the wallet immediately. * @see \c unlock() * @ingroup WalletAPI_Wallet */ -void lock(); +void lock(); /** * @brief Unlocks the wallet. @@ -91,7 +83,7 @@ void lock(); * @param password the password previously set with \c set_password() * @ingroup WalletAPI_Wallet */ -void unlock(string password); +void unlock(const string& password); /** * @brief Sets a new password on the wallet. @@ -99,7 +91,7 @@ void unlock(string password); * @param password * @ingroup WalletAPI_Wallet */ -void set_password(string password); +void set_password(const string& password); /** * @brief Loads a specified wallet file. @@ -113,7 +105,7 @@ void set_password(string password); * @return \c true if the specified wallet is loaded * @ingroup WalletAPI_Wallet */ -bool load_wallet_file(string wallet_filename = ""); +bool load_wallet_file(const string& wallet_filename = string()); /** * @brief Saves the current wallet to the given filename. @@ -126,7 +118,7 @@ bool load_wallet_file(string wallet_filename = ""); * save to the current filename. * @ingroup WalletAPI_Wallet */ -void save_wallet_file(string wallet_filename = ""); +void save_wallet_file(const string& wallet_filename = string()); /** * @brief Sets the wallet filename used for future writes. @@ -135,7 +127,7 @@ void save_wallet_file(string wallet_filename = ""); * @param wallet_filename the new filename to use for future saves * @ingroup WalletAPI_Wallet */ -void set_wallet_filename(string wallet_filename); +void set_wallet_filename(const string& wallet_filename); /** * @brief Imports the private key for an existing account. @@ -148,27 +140,7 @@ void set_wallet_filename(string wallet_filename); * @return \c true if the key was imported * @ingroup WalletAPI_Wallet */ -bool import_key(string account_name_or_id, string wif_key); - -/** - * @brief Imports accounts from the other wallet file. - * @param filename the filename of the wallet JSON file - * @param password user's password to the wallet - * @return mapped account names to boolean values indicating whether the account was successfully imported - * @ingroup WalletAPI_Wallet - */ -map import_accounts( string filename, string password ); //obsolete - -/** - * @brief Imports account keys from particular account from another wallet file to desired account located in wallet file currently used. - * @param filename the filename of the wallet JSON file - * @param password user's password to the wallet - * @param src_account_name name of the source account - * @param dest_account_name name of the destination account - * @return \c true if the keys were imported - * @ingroup WalletAPI_Wallet - */ -bool import_account_keys( string filename, string password, string src_account_name, string dest_account_name ); //obsolete +bool import_key(const string& account_name_or_id, const string& wif_key); /** * @brief Dumps all private keys successfully imported in the wallet. diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 739dd803..85972fb1 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2665,7 +2665,7 @@ signed_transaction content_cancellation(string author, return ss.secret; } - pair> get_author_and_co_authors_by_URI( const string& URI )const + pair> get_author_and_co_authors_by_URI( const string& URI ) const { fc::optional co = _remote_db->get_content( URI ); FC_ASSERT( co.valid(), "Content does not exist."); @@ -2677,7 +2677,7 @@ signed_transaction content_cancellation(string author, return result; }; - vector get_message_objects(optional sender, optional receiver, uint32_t max_count)const + vector get_message_objects(optional sender, optional receiver, uint32_t max_count) const { try { FC_ASSERT(!is_locked()); diff --git a/libraries/wallet/wallet_account.inl b/libraries/wallet/wallet_account.inl index f1a026c3..aaa28788 100644 --- a/libraries/wallet/wallet_account.inl +++ b/libraries/wallet/wallet_account.inl @@ -26,7 +26,7 @@ vector wallet_api::list_account_balances(const string& id) return my->_remote_db->get_account_balances(get_account(id).id, flat_set()); } -vector wallet_api::get_account_history(string name, int limit)const +vector wallet_api::get_account_history(const string& name, int limit)const { vector result; auto account_id = get_account(name).get_id(); @@ -55,7 +55,7 @@ vector wallet_api::get_account_history(string name, int limit) return result; } -vector wallet_api::get_relative_account_history(string name, +vector wallet_api::get_relative_account_history(const string& name, uint32_t stop, int limit, uint32_t start)const @@ -113,12 +113,12 @@ vector wallet_api::search_account_history(string cons return result; } -account_object wallet_api::get_account(string account_name_or_id) const +account_object wallet_api::get_account(const string& account_name_or_id) const { return my->get_account(account_name_or_id); } -brain_key_info wallet_api::suggest_brain_key()const +brain_key_info wallet_api::suggest_brain_key() const { brain_key_info result; // create a private key for secure entropy @@ -149,18 +149,18 @@ brain_key_info wallet_api::suggest_brain_key()const } -signed_transaction wallet_api::register_account(string name, +signed_transaction wallet_api::register_account(const string& name, public_key_type owner_pubkey, public_key_type active_pubkey, - string registrar_account, + const string& registrar_account, bool broadcast) { return my->register_account( name, owner_pubkey, active_pubkey, registrar_account, broadcast ); } -signed_transaction wallet_api::create_account_with_brain_key(string brain_key, - string account_name, - string registrar_account, +signed_transaction wallet_api::create_account_with_brain_key(const string& brain_key, + const string& account_name, + const string& registrar_account, bool broadcast /* = false */) { return my->create_account_with_brain_key( @@ -216,8 +216,11 @@ brain_key_info wallet_api::get_brain_key_info(string const& brain_key) const return result; } -signed_transaction wallet_api::transfer(string from, string to, string amount, - string asset_symbol, string memo, bool broadcast /* = false */) +signed_transaction wallet_api::transfer(const string& from, const string& to, + const string& amount, + const string& asset_symbol, + const string& memo, + bool broadcast /* = false */) { return my->transfer(from, to, amount, asset_symbol, memo, broadcast); } diff --git a/libraries/wallet/wallet_assets.inl b/libraries/wallet/wallet_assets.inl index b71581c8..4ac9154c 100644 --- a/libraries/wallet/wallet_assets.inl +++ b/libraries/wallet/wallet_assets.inl @@ -1,27 +1,27 @@ -vector wallet_api::list_assets(const string& lowerbound, uint32_t limit)const +vector wallet_api::list_assets(const string& lowerbound, uint32_t limit) const { return my->_remote_db->list_assets( lowerbound, limit ); } -asset_object wallet_api::get_asset(string asset_name_or_id) const +asset_object wallet_api::get_asset(const string& asset_name_or_id) const { auto a = my->find_asset(asset_name_or_id); FC_ASSERT(a); return *a; } -monitored_asset_options wallet_api::get_monitored_asset_data(string asset_name_or_id) const +monitored_asset_options wallet_api::get_monitored_asset_data(const string& asset_name_or_id) const { auto asset = get_asset(asset_name_or_id); FC_ASSERT(asset.is_monitored_asset() ); return *asset.monitored_asset_opts; } -signed_transaction wallet_api::create_monitored_asset(string issuer, - string symbol, +signed_transaction wallet_api::create_monitored_asset(const string& issuer, + const string& symbol, uint8_t precision, - string description, + const string& description, uint32_t feed_lifetime_sec, uint8_t minimum_feeds, bool broadcast) @@ -30,8 +30,8 @@ signed_transaction wallet_api::create_monitored_asset(string issuer, return my->create_monitored_asset(issuer, symbol, precision, description, feed_lifetime_sec, minimum_feeds, broadcast); } -signed_transaction wallet_api::update_monitored_asset(string symbol, - string description, +signed_transaction wallet_api::update_monitored_asset(const string& symbol, + const string& description, uint32_t feed_lifetime_sec, uint8_t minimum_feeds, bool broadcast /* = false */) @@ -39,10 +39,10 @@ signed_transaction wallet_api::update_monitored_asset(string symbol, return my->update_monitored_asset(symbol, description, feed_lifetime_sec, minimum_feeds, broadcast); } -signed_transaction wallet_api::create_user_issued_asset(string issuer, - string symbol, +signed_transaction wallet_api::create_user_issued_asset(const string& issuer, + const string& symbol, uint8_t precision, - string description, + const string& description, uint64_t max_supply, price core_exchange_rate, bool is_exchangeable, @@ -51,15 +51,18 @@ signed_transaction wallet_api::create_user_issued_asset(string issuer, return my->create_user_issued_asset(issuer, symbol, precision, description, max_supply, core_exchange_rate, is_exchangeable, broadcast); } -signed_transaction wallet_api::issue_asset(string to_account, string amount, string symbol, - string memo, bool broadcast) +signed_transaction wallet_api::issue_asset(const string& to_account, + const string& amount, + const string& symbol, + const string& memo, + bool broadcast) { return my->issue_asset(to_account, amount, symbol, memo, broadcast); } -signed_transaction wallet_api::update_user_issued_asset(string symbol, - string new_issuer, - string description, +signed_transaction wallet_api::update_user_issued_asset(const string& symbol, + const string& new_issuer, + const string& description, uint64_t max_supply, price core_exchange_rate, bool is_exchangeable, @@ -68,19 +71,19 @@ signed_transaction wallet_api::update_user_issued_asset(string symbol, return my->update_user_issued_asset(symbol, new_issuer, description, max_supply, core_exchange_rate, is_exchangeable, broadcast); } -signed_transaction wallet_api::fund_asset_pools(string from, - string uia_amount, - string uia_symbol, - string DCT_amount, - string DCT_symbol, +signed_transaction wallet_api::fund_asset_pools(const string& from, + const string& uia_amount, + const string& uia_symbol, + const string& DCT_amount, + const string& DCT_symbol, bool broadcast /* = false */) { return my->fund_asset_pools(from, uia_amount, uia_symbol, DCT_amount, DCT_symbol, broadcast); } -signed_transaction wallet_api::reserve_asset(string from, - string amount, - string symbol, +signed_transaction wallet_api::reserve_asset(const string& from, + const string& amount, + const string& symbol, bool broadcast /* = false */) { return my->reserve_asset(from, amount, symbol, broadcast); @@ -91,17 +94,17 @@ string wallet_api::price_to_dct(const string& amount, const string& asset_symbol return my->price_to_dct(amount, asset_symbol_or_id ); } -signed_transaction wallet_api::claim_fees(string uia_amount, - string uia_symbol, - string dct_amount, - string dct_symbol, +signed_transaction wallet_api::claim_fees(const string& uia_amount, + const string& uia_symbol, + const string& dct_amount, + const string& dct_symbol, bool broadcast /* = false */) { return my->claim_fees( uia_amount, uia_symbol, dct_amount, dct_symbol, broadcast); } -signed_transaction wallet_api::publish_asset_feed(string publishing_account, - string symbol, +signed_transaction wallet_api::publish_asset_feed(const string& publishing_account, + const string& symbol, price_feed feed, bool broadcast /* = false */) { @@ -109,13 +112,13 @@ signed_transaction wallet_api::publish_asset_feed(string publishing_account, } multimap wallet_api::get_feeds_by_miner(const string& account_name_or_id, - const uint32_t count) + const uint32_t count) { account_id_type account_id = get_account( account_name_or_id ).id; return my->_remote_db->get_feeds_by_miner( account_id, count ); } -real_supply wallet_api::get_real_supply()const +real_supply wallet_api::get_real_supply() const { return my->_remote_db->get_real_supply(); } diff --git a/libraries/wallet/wallet_content.inl b/libraries/wallet/wallet_content.inl index 7065a03e..85aeeae8 100644 --- a/libraries/wallet/wallet_content.inl +++ b/libraries/wallet/wallet_content.inl @@ -1,84 +1,90 @@ -signed_transaction wallet_api::submit_content(string const& author, - vector< pair< string, uint32_t>> co_authors, - string const& URI, - vector const& price_amounts, - uint64_t size, - fc::ripemd160 const& hash, - vector const& seeders, - uint32_t quorum, - fc::time_point_sec const& expiration, - string const& publishing_fee_asset, - string const& publishing_fee_amount, - string const& synopsis, - DInteger const& secret, - decent::encrypt::CustodyData const& cd, - bool broadcast) +signed_transaction wallet_api::submit_content(const string& author, + const vector< pair< string, uint32_t>>& co_authors, + const string& URI, + const vector & price_amounts, + uint64_t size, + const fc::ripemd160& hash, + const vector& seeders, + uint32_t quorum, + const fc::time_point_sec& expiration, + const string& publishing_fee_asset, + const string& publishing_fee_amount, + const string& synopsis, + const DInteger& secret, + const decent::encrypt::CustodyData& cd, + bool broadcast) { - return my->submit_content(author, co_authors, URI, price_amounts, hash, size, seeders, quorum, expiration, publishing_fee_asset, publishing_fee_amount, synopsis, secret, cd, broadcast); + return my->submit_content(author, co_authors, URI, price_amounts, hash, size, + seeders, quorum, expiration, publishing_fee_asset, publishing_fee_amount, + synopsis, secret, cd, broadcast); } -void wallet_api::submit_content_async(string const &author, vector< pair< string, uint32_t>> co_authors, - string const &content_dir, string const &samples_dir, - string const &protocol, - vector const &price_amounts, - vector const &seeders, - fc::time_point_sec const &expiration, string const &synopsis) +void wallet_api::submit_content_async(const string& author, + const vector< pair< string, uint32_t>>& co_authors, + const string& content_dir, + const string& samples_dir, + const string& protocol, + const vector& price_amounts, + const vector& seeders, + const fc::time_point_sec& expiration, + const string& synopsis) { return my->submit_content_async(author, co_authors, content_dir, samples_dir, protocol, price_amounts, seeders, expiration, synopsis); } -signed_transaction wallet_api::content_cancellation(string author, - string URI, +signed_transaction wallet_api::content_cancellation(const string& author, + const string& URI, bool broadcast) { return my->content_cancellation(author, URI, broadcast); } -void wallet_api::download_content(string const& consumer, string const& URI, string const& region_code_from, bool broadcast) +void wallet_api::download_content(const string& consumer, const string& URI, const string& region_code_from, bool broadcast) { return my->download_content(consumer, URI, region_code_from, broadcast); } -optional wallet_api::get_download_status(string consumer, - string URI) const +optional wallet_api::get_download_status(const string& consumer, + const string& URI) const { return my->get_download_status(consumer, URI); } -signed_transaction wallet_api::request_to_buy(string consumer, - string URI, - string price_asset_name, - string price_amount, - string str_region_code_from, +signed_transaction wallet_api::request_to_buy(const string& consumer, + const string& URI, + const string& price_asset_name, + const string& price_amount, + const string& str_region_code_from, bool broadcast) { return my->request_to_buy(consumer, URI, price_asset_name, price_amount, str_region_code_from, broadcast); } -void wallet_api::seeding_startup(string account_id_type_or_name, - DInteger content_private_key, - string seeder_private_key, - uint64_t free_space, - uint32_t seeding_price, - string seeding_symbol, - string packages_path, - string region_code) +void wallet_api::seeding_startup(const string& account_id_type_or_name, + DInteger content_private_key, + const string& seeder_private_key, + uint64_t free_space, + uint32_t seeding_price, + const string& seeding_symbol, + const string& packages_path, + const string& region_code) { - return my->seeding_startup(account_id_type_or_name, content_private_key, seeder_private_key, free_space, seeding_price, seeding_symbol, packages_path, region_code); + return my->seeding_startup(account_id_type_or_name, content_private_key, seeder_private_key, + free_space, seeding_price, seeding_symbol, packages_path, region_code); } -void wallet_api::leave_rating_and_comment(string consumer, - string URI, +void wallet_api::leave_rating_and_comment(const string& consumer, + const string& URI, uint64_t rating, - string comment, + const string& comment, bool broadcast) { return my->leave_rating_and_comment(consumer, URI, rating, comment, broadcast); } -DInteger wallet_api::restore_encryption_key(string consumer, buying_id_type buying) +DInteger wallet_api::restore_encryption_key(const string& consumer, buying_id_type buying) { return my->restore_encryption_key(consumer, buying); } @@ -90,23 +96,23 @@ DInteger wallet_api::generate_encryption_key() const } -vector wallet_api::get_open_buyings()const +vector wallet_api::get_open_buyings() const { return my->_remote_db->get_open_buyings(); } -vector wallet_api::get_open_buyings_by_URI( const string& URI )const +vector wallet_api::get_open_buyings_by_URI( const string& URI ) const { return my->_remote_db->get_open_buyings_by_URI( URI ); } -vector wallet_api::get_open_buyings_by_consumer( const string& account_id_or_name )const +vector wallet_api::get_open_buyings_by_consumer( const string& account_id_or_name ) const { account_id_type consumer = get_account( account_id_or_name ).id; return my->_remote_db->get_open_buyings_by_consumer( consumer ); } -vector wallet_api::get_buying_history_objects_by_consumer( const string& account_id_or_name )const +vector wallet_api::get_buying_history_objects_by_consumer( const string& account_id_or_name ) const { account_id_type consumer = get_account( account_id_or_name ).id; vector result = my->_remote_db->get_buying_history_objects_by_consumer( consumer ); @@ -137,7 +143,7 @@ vector wallet_api::search_my_purchases(const string& account_i const string& term, const string& order, const string& id, - uint32_t count)const + uint32_t count) const { account_id_type consumer = get_account( account_id_or_name ).id; vector bobjects = my->_remote_db->get_buying_objects_by_consumer(consumer, order, object_id_type(id), term, count ); @@ -168,7 +174,7 @@ vector wallet_api::search_my_purchases(const string& account_i return result; } -optional wallet_api::get_buying_by_consumer_URI( const string& account_id_or_name, const string & URI )const +optional wallet_api::get_buying_by_consumer_URI( const string& account_id_or_name, const string& URI ) const { account_id_type account = get_account( account_id_or_name ).id; return my->_remote_db->get_buying_by_consumer_URI( account, URI ); @@ -188,7 +194,7 @@ vector wallet_api::search_feedback(const string& user, return result; } -optional wallet_api::get_content( const string& URI )const +optional wallet_api::get_content( const string& URI ) const { return my->_remote_db->get_content( URI ); } @@ -266,7 +272,9 @@ pair> wallet_api::get_author_and_co_aut return my->get_author_and_co_authors_by_URI( URI ); } -std::pair wallet_api::create_package(const std::string& content_dir, const std::string& samples_dir, const DInteger& aes_key) const +std::pair wallet_api::create_package(const std::string& content_dir, + const std::string& samples_dir, + const DInteger& aes_key) const { FC_ASSERT(!is_locked()); fc::sha256 key1; diff --git a/libraries/wallet/wallet_general.inl b/libraries/wallet/wallet_general.inl index 06d329d3..11e1857a 100644 --- a/libraries/wallet/wallet_general.inl +++ b/libraries/wallet/wallet_general.inl @@ -52,7 +52,7 @@ variant wallet_api::info() } -string wallet_api::help()const +string wallet_api::help() const { std::vector method_names = my->method_documentation.get_method_names(); std::stringstream ss; @@ -143,8 +143,8 @@ vector< variant > wallet_api::network_get_connected_peers() } -std::string wallet_api::sign_buffer(std::string const& str_buffer, - std::string const& str_brainkey) const +std::string wallet_api::sign_buffer(const std::string& str_buffer, + const std::string& str_brainkey) const { if (str_buffer.empty() || str_brainkey.empty()) @@ -161,9 +161,9 @@ std::string wallet_api::sign_buffer(std::string const& str_buffer, } -bool wallet_api::verify_signature(std::string const& str_buffer, - std::string const& str_publickey, - std::string const& str_signature) const +bool wallet_api::verify_signature(const std::string& str_buffer, + const std::string& str_publickey, + const std::string& str_signature) const { if (str_buffer.empty() || str_publickey.empty() || @@ -177,10 +177,7 @@ bool wallet_api::verify_signature(std::string const& str_buffer, fc::ecc::public_key pub_key(signature, digest); public_key_type provided_key(str_publickey); - if (provided_key == pub_key) - return true; - else - return false; + return (provided_key == pub_key); } diff --git a/libraries/wallet/wallet_messaging.inl b/libraries/wallet/wallet_messaging.inl index 451db417..46189026 100644 --- a/libraries/wallet/wallet_messaging.inl +++ b/libraries/wallet/wallet_messaging.inl @@ -1,5 +1,5 @@ -void wallet_api::send_message(const std::string& from, std::vector to, string text) +void wallet_api::send_message(const std::string& from, const std::vector& to, const string& text) { return my->send_message(from, to, text); } diff --git a/libraries/wallet/wallet_mining.inl b/libraries/wallet/wallet_mining.inl index 2b4768f6..44e69e42 100644 --- a/libraries/wallet/wallet_mining.inl +++ b/libraries/wallet/wallet_mining.inl @@ -4,59 +4,57 @@ map wallet_api::list_miners(const string& lowerbound, uint return my->_remote_db->lookup_miner_accounts(lowerbound, limit); } -miner_object wallet_api::get_miner(string owner_account) +miner_object wallet_api::get_miner(const string& owner_account) { return my->get_miner(owner_account); } -signed_transaction wallet_api::create_miner(string owner_account, - string url, - bool broadcast /* = false */) +signed_transaction wallet_api::create_miner(const string& owner_account, + const string& url, + bool broadcast /* = false */) { return my->create_miner(owner_account, url, broadcast); } -signed_transaction wallet_api::update_miner( - string miner_name, - string url, - string block_signing_key, - bool broadcast /* = false */) +signed_transaction wallet_api::update_miner(const string& miner_name, + const string& url, + const string& block_signing_key, + bool broadcast /* = false */) { return my->update_miner(miner_name, url, block_signing_key, broadcast); } -vector< vesting_balance_object_with_info > wallet_api::get_vesting_balances( string account_name ) +vector< vesting_balance_object_with_info > wallet_api::get_vesting_balances( const string& account_name ) { return my->get_vesting_balances( account_name ); } -signed_transaction wallet_api::withdraw_vesting( - string miner_name, - string amount, - string asset_symbol, - bool broadcast /* = false */) +signed_transaction wallet_api::withdraw_vesting(const string& miner_name, + const string& amount, + const string& asset_symbol, + bool broadcast /* = false */) { return my->withdraw_vesting( miner_name, amount, asset_symbol, broadcast ); } -signed_transaction wallet_api::vote_for_miner(string voting_account, - string miner, - bool approve, - bool broadcast /* = false */) +signed_transaction wallet_api::vote_for_miner(const string& voting_account, + const string& miner, + bool approve, + bool broadcast /* = false */) { return my->vote_for_miner(voting_account, miner, approve, broadcast); } -signed_transaction wallet_api::set_voting_proxy(string account_to_modify, +signed_transaction wallet_api::set_voting_proxy(const string& account_to_modify, optional voting_account, bool broadcast /* = false */) { return my->set_voting_proxy(account_to_modify, voting_account, broadcast); } -signed_transaction wallet_api::set_desired_miner_count(string account_to_modify, - uint16_t desired_number_of_miners, - bool broadcast /* = false */) +signed_transaction wallet_api::set_desired_miner_count(const string& account_to_modify, + uint16_t desired_number_of_miners, + bool broadcast /* = false */) { return my->set_desired_miner_count(account_to_modify, desired_number_of_miners, broadcast); } diff --git a/libraries/wallet/wallet_proposals.inl b/libraries/wallet/wallet_proposals.inl index 92e1dcf3..e6864ccc 100644 --- a/libraries/wallet/wallet_proposals.inl +++ b/libraries/wallet/wallet_proposals.inl @@ -1,44 +1,41 @@ -vector wallet_api::get_proposed_transactions( string account_or_id )const +vector wallet_api::get_proposed_transactions(const string& account_or_id ) const { account_id_type id = get_account(account_or_id).get_id(); return my->_remote_db->get_proposed_transactions( id ); } -void wallet_api::propose_transfer(string proposer, - string from, - string to, - string amount, - string asset_symbol, - string memo, +void wallet_api::propose_transfer(const string& proposer, + const string& from, + const string& to, + const string& amount, + const string& asset_symbol, + const string& memo, time_point_sec expiration) { return my->propose_transfer(proposer, from, to, amount, asset_symbol, memo, expiration); } -signed_transaction wallet_api::propose_parameter_change( - const string& proposing_account, - fc::time_point_sec expiration_time, - const variant_object& changed_values, - bool broadcast /* = false */) +signed_transaction wallet_api::propose_parameter_change( const string& proposing_account, + fc::time_point_sec expiration_time, + const variant_object& changed_values, + bool broadcast /* = false */) { return my->propose_parameter_change( proposing_account, expiration_time, changed_values, broadcast ); } -signed_transaction wallet_api::propose_fee_change( - const string& proposing_account, - fc::time_point_sec expiration_time, - const variant_object& changed_fees, - bool broadcast /* = false */) +signed_transaction wallet_api::propose_fee_change( const string& proposing_account, + fc::time_point_sec expiration_time, + const variant_object& changed_fees, + bool broadcast /* = false */) { return my->propose_fee_change( proposing_account, expiration_time, changed_fees, broadcast ); } -signed_transaction wallet_api::approve_proposal( - const string& fee_paying_account, - const string& proposal_id, - const approval_delta& delta, - bool broadcast /* = false */) +signed_transaction wallet_api::approve_proposal(const string& fee_paying_account, + const string& proposal_id, + const approval_delta& delta, + bool broadcast /* = false */) { return my->approve_proposal( fee_paying_account, proposal_id, delta, broadcast ); } diff --git a/libraries/wallet/wallet_seeding.inl b/libraries/wallet/wallet_seeding.inl index 59ef30c7..1a390118 100644 --- a/libraries/wallet/wallet_seeding.inl +++ b/libraries/wallet/wallet_seeding.inl @@ -9,7 +9,7 @@ optional> wallet_api::list_seeders_by_upload( const uint32 return my->_remote_db->list_seeders_by_upload( count ); } -vector wallet_api::list_seeders_by_region( const string region_code )const +vector wallet_api::list_seeders_by_region( const string& region_code )const { return my->_remote_db->list_seeders_by_region( region_code ); } diff --git a/libraries/wallet/wallet_subscription.inl b/libraries/wallet/wallet_subscription.inl index 0fc136ca..7131064c 100644 --- a/libraries/wallet/wallet_subscription.inl +++ b/libraries/wallet/wallet_subscription.inl @@ -1,31 +1,31 @@ -signed_transaction wallet_api::subscribe_to_author( string from, - string to, - string price_amount, - string price_asset_symbol, +signed_transaction wallet_api::subscribe_to_author( const string& from, + const string& to, + const string& price_amount, + const string& price_asset_symbol, bool broadcast/* = false */) { return my->subscribe_to_author(from, to, price_amount, price_asset_symbol, broadcast); } -signed_transaction wallet_api::subscribe_by_author( string from, - string to, +signed_transaction wallet_api::subscribe_by_author( const string& from, + const string& to, bool broadcast/* = false */) { return my->subscribe_by_author(from, to, broadcast); } -signed_transaction wallet_api::set_subscription( string account, +signed_transaction wallet_api::set_subscription( const string& account, bool allow_subscription, uint32_t subscription_period, - string price_amount, - string price_asset_symbol, + const string& price_amount, + const string& price_asset_symbol, bool broadcast/* = false */) { return my->set_subscription(account, allow_subscription, subscription_period, price_amount, price_asset_symbol, broadcast); } -signed_transaction wallet_api::set_automatic_renewal_of_subscription( string account_id_or_name, +signed_transaction wallet_api::set_automatic_renewal_of_subscription( const string& account_id_or_name, subscription_id_type subscription_id, bool automatic_renewal, bool broadcast/* = false */) diff --git a/libraries/wallet/wallet_transaction_builder.inl b/libraries/wallet/wallet_transaction_builder.inl index 5e719508..5dc2de8a 100644 --- a/libraries/wallet/wallet_transaction_builder.inl +++ b/libraries/wallet/wallet_transaction_builder.inl @@ -65,7 +65,7 @@ signed_transaction wallet_api::sign_transaction(signed_transaction tx, bool broa } FC_CAPTURE_AND_RETHROW( (tx) ) } -operation wallet_api::get_prototype_operation(string operation_name) +operation wallet_api::get_prototype_operation(const string& operation_name) { return my->get_prototype_operation( operation_name ); } diff --git a/libraries/wallet/wallet_wallet_file.inl b/libraries/wallet/wallet_wallet_file.inl index bdd8cc8c..876d70ed 100644 --- a/libraries/wallet/wallet_wallet_file.inl +++ b/libraries/wallet/wallet_wallet_file.inl @@ -35,7 +35,7 @@ void wallet_api::lock() my->self.lock_changed(true); } FC_CAPTURE_AND_RETHROW() } -void wallet_api::unlock(string password) +void wallet_api::unlock(const string& password) { try { FC_ASSERT(password.size() > 0); auto pw = fc::sha512::hash(password.c_str(), password.size()); @@ -47,7 +47,7 @@ void wallet_api::unlock(string password) my->self.lock_changed(false); } FC_CAPTURE_AND_RETHROW() } -void wallet_api::set_password( string password ) +void wallet_api::set_password(const string& password ) { if( !is_new() ) FC_ASSERT( !is_locked(), "The wallet must be unlocked before the password can be set" ); @@ -55,22 +55,22 @@ void wallet_api::set_password( string password ) lock(); } -bool wallet_api::load_wallet_file( string wallet_filename ) +bool wallet_api::load_wallet_file(const string& wallet_filename ) { return my->load_wallet_file( wallet_filename ); } -void wallet_api::save_wallet_file( string wallet_filename ) +void wallet_api::save_wallet_file(const string& wallet_filename ) { my->save_wallet_file( wallet_filename ); } -void wallet_api::set_wallet_filename(string wallet_filename) +void wallet_api::set_wallet_filename(const string& wallet_filename) { my->_wallet_filename = wallet_filename; } -bool wallet_api::import_key(string account_name_or_id, string wif_key) +bool wallet_api::import_key(const string& account_name_or_id, const string& wif_key) { FC_ASSERT(!is_locked()); // backup wallet @@ -89,125 +89,6 @@ bool wallet_api::import_key(string account_name_or_id, string wif_key) return false; } -//obsolete -map wallet_api::import_accounts( string filename, string password ) -{ - FC_ASSERT( !is_locked() ); - FC_ASSERT( fc::exists( filename ) ); - - const auto imported_keys = fc::json::from_file( filename ); - - const auto password_hash = fc::sha512::hash( password ); - FC_ASSERT( fc::sha512::hash( password_hash ) == imported_keys.password_checksum ); - - map result; - for( const auto& item : imported_keys.account_keys ) - { - const auto import_this_account = [ & ]() -> bool - { - try - { - const account_object account = get_account( item.account_name ); - const auto& owner_keys = account.owner.get_keys(); - const auto& active_keys = account.active.get_keys(); - - for( const auto& public_key : item.public_keys ) - { - if( std::find( owner_keys.begin(), owner_keys.end(), public_key ) != owner_keys.end() ) - return true; - - if( std::find( active_keys.begin(), active_keys.end(), public_key ) != active_keys.end() ) - return true; - } - } - catch( ... ) - { - } - - return false; - }; - - const auto should_proceed = import_this_account(); - result[ item.account_name ] = should_proceed; - - if( should_proceed ) - { - uint32_t import_successes = 0; - uint32_t import_failures = 0; - // TODO: First check that all private keys match public keys - for( const auto& encrypted_key : item.encrypted_private_keys ) - { - try - { - const auto plain_text = fc::aes_decrypt( password_hash, encrypted_key ); - const auto private_key = fc::raw::unpack( plain_text ); - - import_key( item.account_name, string( graphene::utilities::key_to_wif( private_key ) ) ); - ++import_successes; - } - catch( const fc::exception& e ) - { - elog( "Couldn't import key due to exception ${e}", ("e", e.to_detail_string()) ); - ++import_failures; - } - } - ilog( "successfully imported ${n} keys for account ${name}", ("n", import_successes)("name", item.account_name) ); - if( import_failures > 0 ) - elog( "failed to import ${n} keys for account ${name}", ("n", import_failures)("name", item.account_name) ); - } - } - - return result; -} - -//obsolete -bool wallet_api::import_account_keys( string filename, string password, string src_account_name, string dest_account_name ) -{ - FC_ASSERT( !is_locked() ); - FC_ASSERT( fc::exists( filename ) ); - - bool is_my_account = false; - const auto accounts = list_my_accounts(); - for( const auto& account : accounts ) - { - if( account.name == dest_account_name ) - { - is_my_account = true; - break; - } - } - FC_ASSERT( is_my_account ); - - const auto imported_keys = fc::json::from_file( filename ); - - const auto password_hash = fc::sha512::hash( password ); - FC_ASSERT( fc::sha512::hash( password_hash ) == imported_keys.password_checksum ); - - bool found_account = false; - for( const auto& item : imported_keys.account_keys ) - { - if( item.account_name != src_account_name ) - continue; - - found_account = true; - - for( const auto& encrypted_key : item.encrypted_private_keys ) - { - const auto plain_text = fc::aes_decrypt( password_hash, encrypted_key ); - const auto private_key = fc::raw::unpack( plain_text ); - - my->import_key( dest_account_name, string( graphene::utilities::key_to_wif( private_key ) ) ); - } - - return true; - } - save_wallet_file(); - - FC_ASSERT( found_account ); - - return false; -} - map wallet_api::dump_private_keys() { FC_ASSERT(!is_locked()); From 1c7af667188bb1fbbc5d8eaaf67b8e16071c010a Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 21 Feb 2018 13:23:15 +0100 Subject: [PATCH 056/136] compile fix --- libraries/wallet/wallet.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index cc1ad0da..4649dc3a 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3334,10 +3334,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati #include "wallet_subscription.inl" #include "wallet_messaging.inl" - return result; - } - - #if 0 void wallet_api::dbg_make_mia(string creator, string symbol) From c462f97b69fd88b9eadef1325ee5a3f7bc3c2e96 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 21 Feb 2018 13:47:43 +0100 Subject: [PATCH 057/136] documentation fix --- libraries/chain/include/graphene/chain/database.hpp | 1 + libraries/wallet/include/graphene/wallet/account.hpp | 2 +- libraries/wallet/include/graphene/wallet/wallet.hpp | 2 -- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index a04f706c..b0fd1645 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -108,6 +108,7 @@ namespace graphene { namespace chain { /** * @brief wipe Delete database from disk, and potentially the raw chain as well. + * @param data_dir * @param include_blocks If true, delete the raw chain as well as the database. * * Will close the database before wiping. Database will be closed when this function returns. diff --git a/libraries/wallet/include/graphene/wallet/account.hpp b/libraries/wallet/include/graphene/wallet/account.hpp index a3626831..6189633e 100644 --- a/libraries/wallet/include/graphene/wallet/account.hpp +++ b/libraries/wallet/include/graphene/wallet/account.hpp @@ -96,7 +96,7 @@ vector search_account_history(const string& acc vector get_account_history(const string& name, int limit) const; /** - * @breif Get operations relevant to the specified account referenced + * @brief Get operations relevant to the specified account referenced * by an event numbering specific to the account. The current number of operations * for the account can be found in the account statistics (or use 0 for start). * @param name The account whose history should be queried diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 44c81a95..549c2b3d 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -251,8 +251,6 @@ namespace graphene { namespace wallet { * @defgroup WalletAPI_Mining Mining * @defgroup WalletAPI_Proposals Proposals * @defgroup WalletAPI_TransactionBuilder Transaction Builder - * @defgroup WalletAPI_Network Network - * @defgroup WalletAPI_Debug Debug * @} */ From 5112667c3fc05866af1f4fa278160b2018761360 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 22 Feb 2018 13:32:02 +0100 Subject: [PATCH 058/136] more conversion from string to const string& --- .../graphene/wallet/transaction_builder.hpp | 4 +- libraries/wallet/wallet.cpp | 250 +++++++++--------- .../wallet/wallet_transaction_builder.inl | 4 +- 3 files changed, 132 insertions(+), 126 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/transaction_builder.hpp b/libraries/wallet/include/graphene/wallet/transaction_builder.hpp index 347fef57..066b3193 100644 --- a/libraries/wallet/include/graphene/wallet/transaction_builder.hpp +++ b/libraries/wallet/include/graphene/wallet/transaction_builder.hpp @@ -62,7 +62,7 @@ void replace_operation_in_builder_transaction(transaction_handle_type handle, * @return total fee in specified asset * @ingroup WalletAPI_TransactionBuilder */ -asset set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset = GRAPHENE_SYMBOL); +asset set_fees_on_builder_transaction(transaction_handle_type handle, const string& fee_asset = string(GRAPHENE_SYMBOL)); /** * @brief Previews a transaction from transaction builder. @@ -109,7 +109,7 @@ signed_transaction propose_builder_transaction(transaction_handle_type handle, * @ingroup WalletAPI_TransactionBuilder */ signed_transaction propose_builder_transaction2(transaction_handle_type handle, - string account_name_or_id, + const string& account_name_or_id, time_point_sec expiration = time_point::now() + fc::minutes(1), uint32_t review_period_seconds = 0, bool broadcast = true); diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 4649dc3a..fd038f27 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -107,8 +107,8 @@ namespace detail { class seeders_tracker{ public: seeders_tracker(wallet_api_impl& wallet):_wallet(wallet) {}; - vector track_content(const string URI); - vector untrack_content(const string URI); + vector track_content(const string& URI); + vector untrack_content(const string& URI); bool is_empty() { return seeder_to_content.empty(); }; vector get_unfinished_seeders(); void set_initial_stats( const account_id_type& seeder, const uint64_t amount ); @@ -122,7 +122,7 @@ class seeders_tracker{ struct ipfs_stats_listener : public EventListenerInterface{ - ipfs_stats_listener(string URI, wallet_api_impl& api, account_id_type consumer):_URI(URI), _wallet(api), _consumer(consumer), + ipfs_stats_listener(const string& URI, wallet_api_impl& api, account_id_type consumer) : _URI(URI), _wallet(api), _consumer(consumer), _ipfs_client(PackageManagerConfigurator::instance().get_ipfs_host(), PackageManagerConfigurator::instance().get_ipfs_port()){} virtual void package_download_start(); @@ -225,7 +225,7 @@ fc::ecc::private_key derive_private_key( const std::string& prefix_string, return derived_key; } -string normalize_brain_key( string s ) +string normalize_brain_key(const string& s ) { size_t i = 0, n = s.length(); std::string result; @@ -597,7 +597,7 @@ class wallet_api_impl FC_ASSERT(rec); return *rec; } - account_object get_account(string account_name_or_id) const + account_object get_account(const string& account_name_or_id) const { FC_ASSERT( account_name_or_id.size() > 0 ); @@ -633,7 +633,7 @@ class wallet_api_impl return rec; } - optional find_asset(string asset_symbol_or_id)const + optional find_asset(const string& asset_symbol_or_id) const { FC_ASSERT( asset_symbol_or_id.size() > 0 ); @@ -661,19 +661,19 @@ class wallet_api_impl return *opt; } - asset_object get_asset(string asset_symbol_or_id)const + asset_object get_asset(const string& asset_symbol_or_id) const { auto opt = find_asset(asset_symbol_or_id); FC_ASSERT(opt); return *opt; } - string get_wallet_filename() const + string get_wallet_filename() const { return _wallet_filename; } - fc::ecc::private_key get_private_key(const public_key_type& id)const + fc::ecc::private_key get_private_key(const public_key_type& id)const { auto it = _keys.find(id); FC_ASSERT( it != _keys.end() ); @@ -695,7 +695,7 @@ class wallet_api_impl // given account name. // @returns true if the key matches a current active/owner/memo key for the named // account, false otherwise (but it is stored either way) - bool import_key(string account_name_or_id, string wif_key) + bool import_key(const string& account_name_or_id, const string& wif_key) { fc::optional optional_private_key = wif_to_key(wif_key); if (!optional_private_key) @@ -742,11 +742,11 @@ class wallet_api_impl return all_keys_for_account.find(wif_pub_key) != all_keys_for_account.end(); } - bool load_wallet_file(string wallet_filename = "") + bool load_wallet_file(string wallet_filename = string()) { // TODO: Merge imported wallet with existing wallet, // instead of replacing it - if( wallet_filename == "" ) + if( wallet_filename.empty() ) wallet_filename = _wallet_filename; if( ! fc::exists( wallet_filename ) ) @@ -804,7 +804,7 @@ class wallet_api_impl return true; } - void save_wallet_file(string wallet_filename = "") + void save_wallet_file(string wallet_filename = string() ) { // // Serialize in memory, then save to disk @@ -815,7 +815,7 @@ class wallet_api_impl encrypt_keys(); - if( wallet_filename == "" ) + if( wallet_filename.empty() ) wallet_filename = _wallet_filename; wlog( "saving wallet to file ${fn}", ("fn", wallet_filename) ); @@ -864,7 +864,7 @@ class wallet_api_impl FC_ASSERT( operation_index < trx.operations.size()); trx.operations[operation_index] = new_op; } - asset set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset = GRAPHENE_SYMBOL) + asset set_fees_on_builder_transaction(transaction_handle_type handle, const string& fee_asset = string(GRAPHENE_SYMBOL)) { FC_ASSERT(_builder_transactions.count(handle)); FC_ASSERT( fee_asset == GRAPHENE_SYMBOL, "fees can be paid in core asset"); @@ -910,7 +910,7 @@ class wallet_api_impl signed_transaction propose_builder_transaction2( transaction_handle_type handle, - string account_name_or_id, + const string& account_name_or_id, time_point_sec expiration = time_point::now() + fc::minutes(1), uint32_t review_period_seconds = 0, bool broadcast = true) { @@ -935,10 +935,10 @@ class wallet_api_impl } - signed_transaction register_account(string name, + signed_transaction register_account(const string& name, public_key_type owner, public_key_type active, - string registrar_account, + const string& registrar_account, bool broadcast = false) { try { FC_ASSERT( !self.is_locked() ); @@ -1030,8 +1030,8 @@ class wallet_api_impl //#define DECENTGO signed_transaction create_account_with_private_key(fc::ecc::private_key owner_privkey, - string account_name, - string registrar_account, + const string& account_name, + const string& registrar_account, bool import, bool broadcast = false, bool save_wallet = true) @@ -1108,9 +1108,9 @@ class wallet_api_impl return tx; } FC_CAPTURE_AND_RETHROW( (account_name)(registrar_account)(broadcast) ) } - signed_transaction create_account_with_brain_key(string brain_key, - string account_name, - string registrar_account, + signed_transaction create_account_with_brain_key(const string& brain_key, + const string& account_name, + const string& registrar_account, bool import, bool broadcast = false, bool save_wallet = true) @@ -1124,10 +1124,10 @@ class wallet_api_impl } FC_CAPTURE_AND_RETHROW( (account_name)(registrar_account) ) } - signed_transaction create_user_issued_asset(string issuer, - string symbol, + signed_transaction create_user_issued_asset(const string& issuer, + const string& symbol, uint8_t precision, - string description, + const string& description, uint64_t max_supply, price core_exchange_rate, bool is_exchangeable, @@ -1156,8 +1156,11 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (issuer)(symbol)(precision)(description)(max_supply)(is_exchangeable)(broadcast) ) } - signed_transaction issue_asset(string to_account, string amount, string symbol, - string memo, bool broadcast = false) + signed_transaction issue_asset(const string& to_account, + const string& amount, + const string& symbol, + const string& memo, + bool broadcast = false) { auto asset_obj = get_asset(symbol); @@ -1186,9 +1189,9 @@ class wallet_api_impl return sign_transaction(tx, broadcast); } - signed_transaction update_user_issued_asset(string symbol, - string new_issuer, - string description, + signed_transaction update_user_issued_asset(const string& symbol, + const string& new_issuer, + const string& description, uint64_t max_supply, price core_exchange_rate, bool is_exchangeable, @@ -1207,7 +1210,7 @@ class wallet_api_impl update_op.is_exchangeable = is_exchangeable; optional new_issuer_account_id; - if( new_issuer != "" ) + if( !new_issuer.empty() ) { account_object new_issuer_account = get_account(new_issuer); new_issuer_account_id = new_issuer_account.id; @@ -1222,11 +1225,11 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (symbol)(new_issuer)(description)(max_supply)(core_exchange_rate)(is_exchangeable)(broadcast) ) } - signed_transaction fund_asset_pools(string from, - string uia_amount, - string uia_symbol, - string DCT_amount, - string DCT_symbol, + signed_transaction fund_asset_pools(const string& from, + const string& uia_amount, + const string& uia_symbol, + const string& DCT_amount, + const string& DCT_symbol, bool broadcast /* = false */) { try { account_object from_account = get_account(from); @@ -1249,9 +1252,9 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (from)(uia_amount)(uia_symbol)(DCT_amount)(DCT_symbol)(broadcast) ) } - signed_transaction reserve_asset(string from, - string amount, - string symbol, + signed_transaction reserve_asset(const string& from, + const string& amount, + const string& symbol, bool broadcast /* = false */) { try { account_object from_account = get_account(from); @@ -1271,10 +1274,10 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (from)(amount)(symbol)(broadcast) ) } - signed_transaction claim_fees(string uia_amount, - string uia_symbol, - string dct_amount, - string dct_symbol, + signed_transaction claim_fees(const string& uia_amount, + const string& uia_symbol, + const string& dct_amount, + const string& dct_symbol, bool broadcast /* = false */) { try { optional uia_asset_to_claim = find_asset(uia_symbol); @@ -1298,10 +1301,10 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (uia_amount)(uia_symbol)(dct_amount)(dct_symbol)(broadcast) ) } - signed_transaction create_monitored_asset(string issuer, - string symbol, + signed_transaction create_monitored_asset(const string& issuer, + const string& symbol, uint8_t precision, - string description, + const string& description, uint32_t feed_lifetime_sec, uint8_t minimum_feeds, bool broadcast = false) @@ -1332,8 +1335,8 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (issuer)(symbol)(precision)(description)(feed_lifetime_sec)(minimum_feeds)(broadcast) ) } - signed_transaction update_monitored_asset(string symbol, - string description, + signed_transaction update_monitored_asset(const string& symbol, + const string& description, uint32_t feed_lifetime_sec, uint8_t minimum_feeds, bool broadcast /* = false */) @@ -1357,8 +1360,8 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (symbol)(description)(feed_lifetime_sec)(minimum_feeds)(broadcast) ) } - signed_transaction publish_asset_feed(string publishing_account, - string symbol, + signed_transaction publish_asset_feed(const string& publishing_account, + const string& symbol, price_feed feed, bool broadcast /* = false */) { try { @@ -1380,7 +1383,7 @@ class wallet_api_impl } FC_CAPTURE_AND_RETHROW( (publishing_account)(symbol)(feed)(broadcast) ) } - miner_object get_miner(string owner_account) + miner_object get_miner(const string& owner_account) { try { @@ -1415,9 +1418,9 @@ class wallet_api_impl FC_CAPTURE_AND_RETHROW( (owner_account) ) } - signed_transaction create_miner(string owner_account, - string url, - bool broadcast /* = false */) + signed_transaction create_miner(const string& owner_account, + const string& url, + bool broadcast /* = false */) { try { account_object miner_account = get_account(owner_account); fc::ecc::private_key active_private_key = get_private_key_for_account(miner_account); @@ -1443,10 +1446,10 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (owner_account)(broadcast) ) } - signed_transaction update_miner(string miner_name, - string url, - string block_signing_key, - bool broadcast /* = false */) + signed_transaction update_miner(const string& miner_name, + const string& url, + const string& block_signing_key, + bool broadcast /* = false */) { try { miner_object miner = get_miner(miner_name); account_object miner_account = get_account( miner.miner_account ); @@ -1455,9 +1458,9 @@ class wallet_api_impl miner_update_operation miner_update_op; miner_update_op.miner = miner.id; miner_update_op.miner_account = miner_account.id; - if( url != "" ) + if( !url.empty() ) miner_update_op.new_url = url; - if( block_signing_key != "" ) + if( !block_signing_key.empty() ) miner_update_op.new_signing_key = public_key_type( block_signing_key ); signed_transaction tx; @@ -1468,7 +1471,7 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (miner_name)(url)(block_signing_key)(broadcast) ) } - vector< vesting_balance_object_with_info > get_vesting_balances( string account_name ) + vector< vesting_balance_object_with_info > get_vesting_balances( const string& account_name ) { try { fc::optional vbid = maybe_id( account_name ); std::vector result; @@ -1496,11 +1499,10 @@ class wallet_api_impl } FC_CAPTURE_AND_RETHROW( (account_name) ) } - signed_transaction withdraw_vesting( - string miner_name, - string amount, - string asset_symbol, - bool broadcast = false ) + signed_transaction withdraw_vesting(const string& miner_name, + const string& amount, + const string& asset_symbol, + bool broadcast = false ) { try { asset_object asset_obj = get_asset( asset_symbol ); fc::optional vbid = maybe_id(miner_name); @@ -1527,10 +1529,10 @@ class wallet_api_impl } FC_CAPTURE_AND_RETHROW( (miner_name)(amount) ) } - signed_transaction vote_for_miner(string voting_account, - string miner, - bool approve, - bool broadcast /* = false */) + signed_transaction vote_for_miner(const string& voting_account, + const string& miner, + bool approve, + bool broadcast /* = false */) { try { account_object voting_account_object = get_account(voting_account); account_id_type miner_owner_account_id = get_account(miner).get_id(); @@ -1561,7 +1563,7 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (voting_account)(miner)(approve)(broadcast) ) } - signed_transaction set_voting_proxy(string account_to_modify, + signed_transaction set_voting_proxy(const string& account_to_modify, optional voting_account, bool broadcast /* = false */) { try { @@ -1592,9 +1594,9 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (account_to_modify)(voting_account)(broadcast) ) } - signed_transaction set_desired_miner_count(string account_to_modify, - uint16_t desired_number_of_miners, - bool broadcast /* = false */) + signed_transaction set_desired_miner_count(const string& account_to_modify, + uint16_t desired_number_of_miners, + bool broadcast /* = false */) { try { account_object account_object_to_modify = get_account(account_to_modify); @@ -1753,8 +1755,12 @@ class wallet_api_impl } - signed_transaction transfer(string from, string to, string amount, - string asset_symbol, string memo, bool broadcast = false) + signed_transaction transfer(const string& from, + const string& to, + const string& amount, + const string& asset_symbol, + const string& memo, + bool broadcast = false) { try { FC_ASSERT( !self.is_locked() ); fc::optional asset_obj = get_asset(asset_symbol); @@ -1788,12 +1794,12 @@ class wallet_api_impl return sign_transaction(tx, broadcast); } FC_CAPTURE_AND_RETHROW( (from)(to)(amount)(asset_symbol)(memo)(broadcast) ) } - void propose_transfer(string proposer, - string from, - string to, - string amount, - string asset_symbol, - string memo, + void propose_transfer(const string& proposer, + const string& from, + const string& to, + const string& amount, + const string& asset_symbol, + const string& memo, time_point_sec expiration) { int propose_num = begin_builder_transaction(); @@ -2274,8 +2280,8 @@ class wallet_api_impl FC_CAPTURE_AND_RETHROW( (author)(content_dir)(samples_dir)(protocol)(price_amounts)(seeders)(expiration)(synopsis) ) } -signed_transaction content_cancellation(string author, - string URI, +signed_transaction content_cancellation(const string& author, + const string& URI, bool broadcast) { try @@ -2294,7 +2300,7 @@ signed_transaction content_cancellation(string author, } FC_CAPTURE_AND_RETHROW( (author)(URI)(broadcast) ) } - optional get_download_status(string consumer, string URI) const { + optional get_download_status(const string& consumer, const string& URI) const { try { account_id_type acc = get_account(consumer).id; @@ -2400,11 +2406,11 @@ signed_transaction content_cancellation(string author, } - signed_transaction request_to_buy(string consumer, - string URI, - string price_asset_symbol, - string price_amount, - string str_region_code_from, + signed_transaction request_to_buy(const string& consumer, + const string& URI, + const string& price_asset_symbol, + const string& price_amount, + const string& str_region_code_from, bool broadcast/* = false */) { try { account_object consumer_account = get_account( consumer ); @@ -2441,10 +2447,10 @@ signed_transaction content_cancellation(string author, } FC_CAPTURE_AND_RETHROW( (consumer)(URI)(price_asset_symbol)(price_amount)(broadcast) ) } - void leave_rating_and_comment(string consumer, - string URI, + void leave_rating_and_comment(const string& consumer, + const string& URI, uint64_t rating, - string comment, + const string& comment, bool broadcast/* = false */) { try @@ -2469,14 +2475,14 @@ signed_transaction content_cancellation(string author, } FC_CAPTURE_AND_RETHROW( (consumer)(URI)(rating)(comment)(broadcast) ) } - void seeding_startup( string account_id_type_or_name, + void seeding_startup( const string& account_id_type_or_name, DInteger content_private_key, - string seeder_private_key, + const string& seeder_private_key, uint64_t free_space, uint32_t seeding_price, - string seeding_symbol, - string packages_path, - string region_code) + const string& seeding_symbol, + const string& packages_path, + const string& region_code) { account_id_type seeder = get_account( account_id_type_or_name ).get_id(); use_network_node_api(); @@ -2484,10 +2490,10 @@ signed_transaction content_cancellation(string author, (*_remote_net_node)->seeding_startup( seeder, content_private_key, seeder_priv_key, free_space, seeding_price, seeding_symbol, packages_path, region_code); } - signed_transaction subscribe_to_author( string from, - string to, - string price_amount, - string price_asset_symbol, + signed_transaction subscribe_to_author( const string& from, + const string& to, + const string& price_amount, + const string& price_asset_symbol, bool broadcast/* = false */) { try { fc::optional asset_obj = get_asset(price_asset_symbol); @@ -2506,8 +2512,8 @@ signed_transaction content_cancellation(string author, return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (from)(to)(price_amount)(price_asset_symbol)(broadcast) ) } - signed_transaction subscribe_by_author( string from, - string to, + signed_transaction subscribe_by_author( const string& from, + const string& to, bool broadcast/* = false */) { try { subscribe_by_author_operation subscribe_op; @@ -2522,11 +2528,11 @@ signed_transaction content_cancellation(string author, return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (from)(to)(broadcast)) } - signed_transaction set_subscription( string account, + signed_transaction set_subscription( const string& account, bool allow_subscription, uint32_t subscription_period, - string price_amount, - string price_asset_symbol, + const string& price_amount, + const string& price_asset_symbol, bool broadcast/* = false */) { try { fc::optional asset_obj = get_asset(price_asset_symbol); @@ -2549,7 +2555,7 @@ signed_transaction content_cancellation(string author, return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (account)(allow_subscription)(subscription_period)(price_amount)(price_asset_symbol)(broadcast) ) } - signed_transaction set_automatic_renewal_of_subscription( string account_id_or_name, + signed_transaction set_automatic_renewal_of_subscription( const string& account_id_or_name, subscription_id_type subscription_id, bool automatic_renewal, bool broadcast/* = false */) @@ -2573,7 +2579,7 @@ signed_transaction content_cancellation(string author, return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (account_id_or_name)(subscription_id)(automatic_renewal)(broadcast) ) } - DInteger restore_encryption_key(std::string account, buying_id_type buying ) + DInteger restore_encryption_key(const string& account, buying_id_type buying ) { account_object buyer_account = get_account( account ); const buying_object bo = get_object(buying); @@ -2664,7 +2670,7 @@ signed_transaction content_cancellation(string author, } FC_CAPTURE_AND_RETHROW((sender)(receiver)) } - vector get_messages(const std::string& receiver, uint32_t max_count)const + vector get_messages(const std::string& receiver, uint32_t max_count) const { FC_ASSERT(!is_locked()); const auto& mapi = _remote_api->messaging(); @@ -2724,7 +2730,7 @@ signed_transaction content_cancellation(string author, return messages; } - void send_message(string from, std::vector to, string text) + void send_message(const string& from, const std::vector& to, const string& text) { try { @@ -2769,7 +2775,7 @@ signed_transaction content_cancellation(string author, } FC_CAPTURE_AND_RETHROW((from)(to)(text)) } - void dbg_make_mia(string creator, string symbol) + void dbg_make_mia(const string& creator, const string& symbol) { create_monitored_asset(get_account(creator).name, symbol, 2, "abcd", 3600, 1, true); } @@ -2864,7 +2870,7 @@ signed_transaction content_cancellation(string author, return result; } - void flood_network(string prefix, uint32_t number_of_transactions) + void flood_network(const string& prefix, uint32_t number_of_transactions) { try { @@ -2906,7 +2912,7 @@ signed_transaction content_cancellation(string author, } - operation get_prototype_operation( string operation_name ) + operation get_prototype_operation( const string& operation_name ) { auto it = _prototype_ops.find( operation_name ); if( it == _prototype_ops.end() ) @@ -2949,7 +2955,7 @@ signed_transaction content_cancellation(string author, std::string operation_printer::fee(const asset& a)const { out << " (Fee: " << wallet.get_asset(a.asset_id).amount_to_pretty_string(a) << ")"; - return ""; + return std::string(); } template @@ -2968,11 +2974,11 @@ signed_transaction content_cancellation(string author, 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 != "" ) + if( !str_result.empty() ) { out << " result: " << str_result; } - return ""; + return std::string(); } string operation_printer::operator()(const transfer_operation& op) const @@ -3159,7 +3165,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati std::string operation_result_printer::operator()(const void_result& x) const { - return ""; + return std::string(); } std::string operation_result_printer::operator()(const object_id_type& oid) @@ -3172,7 +3178,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return _wallet.get_asset(a.asset_id).amount_to_pretty_string(a); } - vector seeders_tracker::track_content(const string URI) + vector seeders_tracker::track_content(const string& URI) { optional content = _wallet._remote_db->get_content( URI ); FC_ASSERT( content ); @@ -3196,7 +3202,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati return new_seeders; } - vector seeders_tracker::untrack_content(const string URI) + vector seeders_tracker::untrack_content(const string& URI) { optional content = _wallet._remote_db->get_content( URI ); FC_ASSERT( content ); @@ -3295,7 +3301,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati } } - void ipfs_stats_listener:: package_download_error(const std::string&) + void ipfs_stats_listener:: package_download_error(const std::string& ) { vector finished_seeders = _wallet._seeders_tracker.untrack_content( _URI); for( const auto& element : finished_seeders ) diff --git a/libraries/wallet/wallet_transaction_builder.inl b/libraries/wallet/wallet_transaction_builder.inl index 5dc2de8a..56fa668b 100644 --- a/libraries/wallet/wallet_transaction_builder.inl +++ b/libraries/wallet/wallet_transaction_builder.inl @@ -14,7 +14,7 @@ void wallet_api::replace_operation_in_builder_transaction(transaction_handle_typ my->replace_operation_in_builder_transaction(handle, operation_index, new_op); } -asset wallet_api::set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset) +asset wallet_api::set_fees_on_builder_transaction(transaction_handle_type handle, const string& fee_asset) { return my->set_fees_on_builder_transaction(handle, fee_asset); } @@ -40,7 +40,7 @@ signed_transaction wallet_api::propose_builder_transaction( signed_transaction wallet_api::propose_builder_transaction2( transaction_handle_type handle, - string account_name_or_id, + const string& account_name_or_id, time_point_sec expiration, uint32_t review_period_seconds, bool broadcast) From bec115d900131d511c7984cb457f1b6d32260760 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 22 Feb 2018 15:00:15 +0100 Subject: [PATCH 059/136] added fixed max_supply property --- libraries/chain/asset_evaluator.cpp | 3 +++ libraries/chain/include/graphene/chain/protocol/asset_ops.hpp | 2 ++ libraries/wallet/include/graphene/wallet/assets.hpp | 2 ++ libraries/wallet/wallet.cpp | 2 ++ libraries/wallet/wallet_assets.inl | 3 ++- 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 1323de83..1b099707 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -154,6 +154,9 @@ void_result user_issued_asset_update_evaluator::do_evaluate(const update_user_is if( o.new_issuer ) FC_ASSERT(d.find_object(*o.new_issuer)); + if (a.options.is_fixed_max_supply) + FC_ASSERT(o.max_supply == a.options.max_supply); + asset_to_update = &a; FC_ASSERT( o.issuer == a.issuer, "", ("o.issuer", o.issuer)("a.issuer", a.issuer) ); diff --git a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp index ef78133f..a0692aa1 100644 --- a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp +++ b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp @@ -48,6 +48,8 @@ namespace graphene { namespace chain { /// True to allow implicit conversion of this asset to/from core asset. bool is_exchangeable = true; + /// False when issuer can change max_supply, otherwise false + bool is_fixed_max_supply = false; extensions_type extensions; diff --git a/libraries/wallet/include/graphene/wallet/assets.hpp b/libraries/wallet/include/graphene/wallet/assets.hpp index 8275edbb..37330fe1 100644 --- a/libraries/wallet/include/graphene/wallet/assets.hpp +++ b/libraries/wallet/include/graphene/wallet/assets.hpp @@ -109,6 +109,7 @@ signed_transaction update_monitored_asset(const string& symbol, * created, create this price as though the new asset has instance ID 1, and * the chain will overwrite it with the new asset's ID * @param is_exchangeable \c true to allow implicit conversion of this asset to/from core asset + * @param is_fixed_max_supply * @param broadcast \c true to broadcast the transaction on the network * @return the signed transaction creating a new asset * @ingroup WalletAPI_Asset @@ -120,6 +121,7 @@ signed_transaction create_user_issued_asset(const string& issuer, uint64_t max_supply, price core_exchange_rate, bool is_exchangeable, + bool is_fixed_max_supply, bool broadcast = false); /** diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index fd038f27..eab9664c 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1131,6 +1131,7 @@ class wallet_api_impl uint64_t max_supply, price core_exchange_rate, bool is_exchangeable, + bool is_fixed_max_supply, bool broadcast = false) { try { account_object issuer_account = get_account( issuer ); @@ -1145,6 +1146,7 @@ class wallet_api_impl opts.max_supply = max_supply; opts.core_exchange_rate = core_exchange_rate; opts.is_exchangeable = is_exchangeable; + opts.is_fixed_max_supply = is_fixed_max_supply; create_op.options = opts; create_op.monitored_asset_opts = optional(); diff --git a/libraries/wallet/wallet_assets.inl b/libraries/wallet/wallet_assets.inl index 4ac9154c..74d54c30 100644 --- a/libraries/wallet/wallet_assets.inl +++ b/libraries/wallet/wallet_assets.inl @@ -46,9 +46,10 @@ signed_transaction wallet_api::create_user_issued_asset(const string& issuer, uint64_t max_supply, price core_exchange_rate, bool is_exchangeable, + bool is_fixed_max_supply, bool broadcast /* = false */) { - return my->create_user_issued_asset(issuer, symbol, precision, description, max_supply, core_exchange_rate, is_exchangeable, broadcast); + return my->create_user_issued_asset(issuer, symbol, precision, description, max_supply, core_exchange_rate, is_exchangeable, is_fixed_max_supply, broadcast); } signed_transaction wallet_api::issue_asset(const string& to_account, From d5b99563037dcb57648a6d2521b846f4b426a2d7 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 26 Feb 2018 13:41:04 +0100 Subject: [PATCH 060/136] merging DCT-568_store_el_gamal_keys --- .../include/decent/encrypt/crypto_types.hpp | 7 + .../wallet/include/graphene/wallet/wallet.hpp | 201 +++++++++--------- libraries/wallet/wallet.cpp | 104 +++++---- libraries/wallet/wallet_wallet_file.inl | 53 +++-- 4 files changed, 199 insertions(+), 166 deletions(-) diff --git a/libraries/encrypt/include/decent/encrypt/crypto_types.hpp b/libraries/encrypt/include/decent/encrypt/crypto_types.hpp index ab814923..505ed697 100644 --- a/libraries/encrypt/include/decent/encrypt/crypto_types.hpp +++ b/libraries/encrypt/include/decent/encrypt/crypto_types.hpp @@ -88,6 +88,13 @@ class DIntegerString{ DIntegerString& operator=(const DInteger& d); /* Comparision operator */ DIntegerString& operator=(const DIntegerString& _s) { s = _s.s; return *this;}; + /* Comparision operator */ + bool operator<(const DIntegerString& b) const + { + if( this->s.length() < b.s.length() ) + return true; + return this->s < b.s; + } }; /***** diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 549c2b3d..1aec3966 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -52,33 +52,6 @@ namespace graphene { namespace wallet { object* create_object( const variant& v ); - struct plain_keys - { - map keys; - fc::sha512 checksum; - }; - - struct brain_key_info - { - string brain_priv_key; - string wif_priv_key; - public_key_type pub_key; - }; - - struct regional_price_info - { - string region; - string amount; - string asset_symbol; - }; - - - struct operation_detail { - string memo; - string description; - operation_history_object op; - }; - struct wallet_data { /** Chain ID this wallet is used with */ @@ -128,6 +101,50 @@ namespace graphene { namespace wallet { string libtorrent_config_path; }; + struct el_gamal_key_pair + { + DInteger private_key; + DInteger public_key; + }; + + struct el_gamal_key_pair_str + { + DIntegerString private_key; + DIntegerString public_key; + }; + + /** + * Needed for backward compatibility. Old wallet json files use this struct to store encrypted ec keys. + */ + struct plain_keys + { + map ec_keys; + fc::sha512 checksum; + }; + + /** + * New wallet json files store encrypted ec keys along with derived el gamal keys. + */ + struct plain_ec_and_el_gamal_keys : public plain_keys + { + plain_ec_and_el_gamal_keys& operator=( const plain_keys& pk ) + { + ec_keys = pk.ec_keys; + checksum = pk.checksum; + return *this; + } + + plain_ec_and_el_gamal_keys() = default; + vector el_gamal_keys; + }; + + struct brain_key_info + { + string brain_priv_key; + string wif_priv_key; + public_key_type pub_key; + }; + struct exported_account_keys { string account_name; @@ -141,20 +158,6 @@ namespace graphene { namespace wallet { vector account_keys; }; - struct el_gamal_key_pair - { - DInteger private_key; - DInteger public_key; - }; - - struct el_gamal_key_pair_str - { - DIntegerString private_key; - DIntegerString public_key; - }; - - - struct approval_delta { vector active_approvals_to_add; @@ -165,6 +168,13 @@ namespace graphene { namespace wallet { vector key_approvals_to_remove; }; + struct regional_price_info + { + string region; + string amount; + string asset_symbol; + }; + struct content_download_status { int total_key_parts; @@ -173,7 +183,12 @@ namespace graphene { namespace wallet { int received_download_bytes; std::string status_text; }; - + + struct operation_detail { + string memo; + string description; + operation_history_object op; + }; struct buying_object_ex : public buying_object, public content_download_status { buying_object_ex(const buying_object& obj, const content_download_status& status) @@ -200,7 +215,6 @@ namespace graphene { namespace wallet { std::string author; }; - struct signed_block_with_info : public signed_block { signed_block_with_info( const signed_block& block ); @@ -231,8 +245,7 @@ namespace graphene { namespace wallet { namespace detail { class wallet_api_impl; } - - + /** * This wallet assumes it is connected to the database server with a high-bandwidth, low-latency connection and @@ -275,52 +288,35 @@ namespace graphene { namespace wallet { std::map> get_result_formatters() const; + void encrypt_keys(); fc::signal lock_changed; std::shared_ptr my; - void encrypt_keys(); - - - }; - } } -FC_REFLECT( graphene::wallet::plain_keys, (keys)(checksum) ) -FC_REFLECT( graphene::wallet::el_gamal_key_pair, (private_key)(public_key) ) -FC_REFLECT( graphene::wallet::el_gamal_key_pair_str, (private_key)(public_key) ) FC_REFLECT( graphene::wallet::wallet_data, (chain_id) - (my_accounts) - (cipher_keys) - (extra_keys) - (pending_account_registrations)(pending_miner_registrations) - (ws_server) - (ws_user) - (ws_password) -) + (my_accounts) + (cipher_keys) + (extra_keys) + (pending_account_registrations)(pending_miner_registrations) + (ws_server) + (ws_user) + (ws_password) + ) -FC_REFLECT( graphene::wallet::brain_key_info, - (brain_priv_key) - (wif_priv_key) - (pub_key) -) +FC_REFLECT( graphene::wallet::el_gamal_key_pair, (private_key)(public_key) ) -FC_REFLECT( graphene::wallet::regional_price_info, - (region) - (amount) - (asset_symbol) -) +FC_REFLECT( graphene::wallet::el_gamal_key_pair_str, (private_key)(public_key) ) + +FC_REFLECT( graphene::wallet::plain_keys, (ec_keys)(checksum) ) + +FC_REFLECT_DERIVED( graphene::wallet::plain_ec_and_el_gamal_keys, (graphene::wallet::plain_keys), (el_gamal_keys) ) -FC_REFLECT (graphene::wallet::content_download_status, - (total_key_parts) - (received_key_parts) - (total_download_bytes) - (received_download_bytes) - (status_text) - ) +FC_REFLECT( graphene::wallet::brain_key_info, (brain_priv_key)(wif_priv_key)(pub_key) ) FC_REFLECT( graphene::wallet::exported_account_keys, (account_name)(encrypted_private_keys)(public_keys) ) @@ -328,36 +324,43 @@ FC_REFLECT( graphene::wallet::exported_keys, (password_checksum)(account_keys) ) FC_REFLECT( graphene::wallet::approval_delta, (active_approvals_to_add) - (active_approvals_to_remove) - (owner_approvals_to_add) - (owner_approvals_to_remove) - (key_approvals_to_add) - (key_approvals_to_remove) -) + (active_approvals_to_remove) + (owner_approvals_to_add) + (owner_approvals_to_remove) + (key_approvals_to_add) + (key_approvals_to_remove) + ) -FC_REFLECT_DERIVED( graphene::wallet::signed_block_with_info, (graphene::chain::signed_block), - (block_id)(signing_key)(transaction_ids)(miner_reward) ) +FC_REFLECT( graphene::wallet::regional_price_info, (region)(amount)(asset_symbol) ) -FC_REFLECT_DERIVED( graphene::wallet::vesting_balance_object_with_info, (graphene::chain::vesting_balance_object), - (allowed_withdraw)(allowed_withdraw_time) ) +FC_REFLECT( graphene::wallet::content_download_status, + (total_key_parts) + (received_key_parts) + (total_download_bytes) + (received_download_bytes) + (status_text) + ) +FC_REFLECT( graphene::wallet::operation_detail, (memo)(description)(op) ) FC_REFLECT_DERIVED( graphene::wallet::buying_object_ex, - (graphene::chain::buying_object) - (graphene::wallet::content_download_status), - (id) - (author_account) - (AVG_rating) - (times_bought) - (hash) + (graphene::chain::buying_object) + (graphene::wallet::content_download_status), + (id) + (author_account) + (AVG_rating) + (times_bought) + (hash) ) -FC_REFLECT_DERIVED( graphene::wallet::rating_object_ex, - (graphene::chain::buying_object),(author) ) +FC_REFLECT_DERIVED( graphene::wallet::rating_object_ex, (graphene::chain::buying_object),(author) ) +FC_REFLECT_DERIVED( graphene::wallet::signed_block_with_info, (graphene::chain::signed_block), + (block_id)(signing_key)(transaction_ids)(miner_reward) ) + +FC_REFLECT_DERIVED( graphene::wallet::vesting_balance_object_with_info, (graphene::chain::vesting_balance_object), + (allowed_withdraw)(allowed_withdraw_time) ) -FC_REFLECT( graphene::wallet::operation_detail, - (memo)(description)(op) ) FC_API( graphene::wallet::wallet_api, //General diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index fd038f27..76b2f926 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -494,8 +494,11 @@ class wallet_api_impl { if( !is_locked() ) { - plain_keys data; - data.keys = _keys; + plain_ec_and_el_gamal_keys data; + data.ec_keys = _keys; + std::transform( _el_gamal_keys.begin(), _el_gamal_keys.end(), std::back_inserter( data.el_gamal_keys ), + [](const std::pair el_gamal_pair) { + return el_gamal_key_pair_str {el_gamal_pair.second, el_gamal_pair.first}; }); data.checksum = _checksum; auto plain_txt = fc::raw::pack(data); _wallet.cipher_keys = fc::aes_encrypt( data.checksum, plain_txt ); @@ -734,6 +737,8 @@ class wallet_api_impl all_keys_for_account.insert(account.options.memo_key); _keys[wif_pub_key] = wif_key; + DInteger el_gamal_priv_key = generate_private_el_gamal_key_from_secret( optional_private_key->get_secret() ); + _el_gamal_keys[get_public_el_gamal_key( el_gamal_priv_key )] = el_gamal_priv_key; _wallet.update_account(account); @@ -2588,12 +2593,13 @@ signed_transaction content_cancellation(const string& author, decent::encrypt::ShamirSecret ss( co.quorum, co.key_parts.size() ); decent::encrypt::point message; - DInteger el_gamal_priv_key = generate_private_el_gamal_key_from_secret ( get_private_key_for_account(buyer_account).get_secret() ); + const auto& el_gamal_priv_key = _el_gamal_keys.find( bo.pubKey ); + FC_ASSERT( el_gamal_priv_key != _el_gamal_keys.end(), "Wallet does not contain required ElGamal key" ); int i=0; for( const auto key_particle : bo.key_particles ) { - auto result = decent::encrypt::el_gamal_decrypt( decent::encrypt::Ciphertext( key_particle ), el_gamal_priv_key, message ); + auto result = decent::encrypt::el_gamal_decrypt( decent::encrypt::Ciphertext( key_particle ), el_gamal_priv_key->second, message ); FC_ASSERT(result == decent::encrypt::ok); decent::encrypt::DIntegerString a(message.first); @@ -2731,7 +2737,6 @@ signed_transaction content_cancellation(const string& author, } void send_message(const string& from, const std::vector& to, const string& text) - { try { FC_ASSERT(!is_locked()); @@ -2929,6 +2934,7 @@ signed_transaction content_cancellation(const string& author, wallet_data _wallet; map _keys; + map _el_gamal_keys; // public_key/private_key fc::sha512 _checksum; chain_id_type _chain_id; @@ -2958,8 +2964,7 @@ signed_transaction content_cancellation(const string& author, return std::string(); } - template - std::string operation_printer::operator()(const T& op)const + template std::string operation_printer::operator()(const T& op)const { //balance_accumulator acc; //op.get_balance_delta( acc, result ); @@ -3110,17 +3115,17 @@ signed_transaction content_cancellation(const string& author, return memo; } -std::string operation_printer::operator()(const leave_rating_and_comment_operation& op) const -{ - out << wallet.get_account(op.consumer).name; - if( op.comment.empty() ) - out << " rated " << op.URI << " -- Rating: " << op.rating; - else if( op.rating == 0 ) - out << " commented " << op.URI << " -- Comment: " << op.comment; - else - out << " rated and commented " << op.URI << " -- Rating: " << op.rating << " -- Comment: " << op.comment; - return fee(op.fee); -} + std::string operation_printer::operator()(const leave_rating_and_comment_operation& op) const + { + out << wallet.get_account(op.consumer).name; + if( op.comment.empty() ) + out << " rated " << op.URI << " -- Rating: " << op.rating; + else if( op.rating == 0 ) + out << " commented " << op.URI << " -- Comment: " << op.comment; + else + out << " rated and commented " << op.URI << " -- Rating: " << op.rating << " -- Comment: " << op.comment; + return fee(op.fee); + } std::string operation_printer::operator()(const account_create_operation& op) const @@ -3315,8 +3320,6 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati - - namespace graphene { namespace wallet { wallet_api::wallet_api(const wallet_data& initial_data, fc::api rapi) @@ -3369,8 +3372,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati } #endif - std::map > - wallet_api::get_result_formatters() const + std::map > wallet_api::get_result_formatters() const { return my->get_result_formatters(); } @@ -3380,9 +3382,7 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati my->encrypt_keys(); } - - signed_block_with_info::signed_block_with_info( const signed_block& block ) - : signed_block( block ) + signed_block_with_info::signed_block_with_info( const signed_block& block ) : signed_block( block ) { block_id = id(); signing_key = signee(); @@ -3398,46 +3398,44 @@ std::string operation_printer::operator()(const leave_rating_and_comment_operati allowed_withdraw_time = now; } + void graphene::wallet::detail::submit_transfer_listener::package_creation_complete() + { + uint64_t size = std::max((uint64_t)1, ( _info->get_size() + (1024 * 1024) -1 ) / (1024 * 1024)); + asset total_price_per_day; + for( int i =0; i < _op.seeders.size(); i++ ) + { + const auto& s = _wallet._remote_db->get_seeder( _op.seeders[i] ); + total_price_per_day += s->price.amount * size; + } + fc::microseconds duration = (_op.expiration - fc::time_point::now()); + uint64_t days = (duration.to_seconds()+3600*24-1) / 3600 / 24; -void graphene::wallet::detail::submit_transfer_listener::package_creation_complete() { - uint64_t size = std::max((uint64_t)1, ( _info->get_size() + (1024 * 1024) -1 ) / (1024 * 1024)); - - asset total_price_per_day; - for( int i =0; i < _op.seeders.size(); i++ ) - { - const auto& s = _wallet._remote_db->get_seeder( _op.seeders[i] ); - total_price_per_day += s->price.amount * size; - } + _op.hash = _info->get_hash(); + _op.size = size; + _op.publishing_fee = days * total_price_per_day; + _op.cd = _info->get_custody_data(); - fc::microseconds duration = (_op.expiration - fc::time_point::now()); - uint64_t days = (duration.to_seconds()+3600*24-1) / 3600 / 24; + _info->start_seeding(_protocol, false); + } - _op.hash = _info->get_hash(); - _op.size = size; - _op.publishing_fee = days * total_price_per_day; - _op.cd = _info->get_custody_data(); + void graphene::wallet::detail::submit_transfer_listener::package_seed_complete() + { - _info->start_seeding(_protocol, false); -} + _op.URI = _info->get_url(); -void graphene::wallet::detail::submit_transfer_listener::package_seed_complete() { - - _op.URI = _info->get_url(); - - signed_transaction tx; - tx.operations.push_back( _op ); - _wallet.set_operation_fees( tx, _wallet._remote_db->get_global_properties().parameters.current_fees); - tx.validate(); - _wallet.sign_transaction(tx, true); -} + signed_transaction tx; + tx.operations.push_back( _op ); + _wallet.set_operation_fees( tx, _wallet._remote_db->get_global_properties().parameters.current_fees); + tx.validate(); + _wallet.sign_transaction(tx, true); + } } } // graphene::wallet - void fc::to_variant(const account_multi_index_type& accts, fc::variant& vo) { vo = vector(accts.begin(), accts.end()); diff --git a/libraries/wallet/wallet_wallet_file.inl b/libraries/wallet/wallet_wallet_file.inl index 876d70ed..84b47b19 100644 --- a/libraries/wallet/wallet_wallet_file.inl +++ b/libraries/wallet/wallet_wallet_file.inl @@ -31,6 +31,7 @@ void wallet_api::lock() for( auto & key : my->_keys ) key.second = key_to_wif(fc::ecc::private_key()); my->_keys.clear(); + my->_el_gamal_keys.clear(); my->_checksum = fc::sha512(); my->self.lock_changed(true); } FC_CAPTURE_AND_RETHROW() } @@ -40,10 +41,36 @@ void wallet_api::unlock(const string& password) FC_ASSERT(password.size() > 0); auto pw = fc::sha512::hash(password.c_str(), password.size()); vector decrypted = fc::aes_decrypt(pw, my->_wallet.cipher_keys); - auto pk = fc::raw::unpack(decrypted); + plain_ec_and_el_gamal_keys pk; + bool update_wallet_file = false; + + // supporting backward compatibility of wallet json file + try { + pk = fc::raw::unpack(decrypted); + } + catch(const fc::exception&) + { + pk = fc::raw::unpack(decrypted); + // wallet file is in old format, derive corresponding el gamal keys from private keys + for( const auto& element : pk.ec_keys ) + { + el_gamal_key_pair_str el_gamal_keys_str; + el_gamal_keys_str.private_key = generate_private_el_gamal_key_from_secret( wif_to_key( element.second )->get_secret() ); + el_gamal_keys_str.public_key = get_public_el_gamal_key( el_gamal_keys_str.private_key ); + pk.el_gamal_keys.push_back( el_gamal_keys_str ); + } + update_wallet_file = true; + } FC_ASSERT(pk.checksum == pw); - my->_keys = std::move(pk.keys); + my->_keys = std::move(pk.ec_keys); + if( !pk.el_gamal_keys.empty() ) + std::transform( pk.el_gamal_keys.begin(), pk.el_gamal_keys.end(), std::inserter( my->_el_gamal_keys, my->_el_gamal_keys.end() ), + []( const el_gamal_key_pair_str el_gamal_pair ){ return std::make_pair(DInteger(el_gamal_pair.public_key),DInteger(el_gamal_pair.private_key)); }); my->_checksum = pk.checksum; + + if( update_wallet_file ) // upgrade structure for storing keys to new format + save_wallet_file(); + my->self.lock_changed(false); } FC_CAPTURE_AND_RETHROW() } @@ -73,26 +100,24 @@ void wallet_api::set_wallet_filename(const string& wallet_filename) bool wallet_api::import_key(const string& account_name_or_id, const string& wif_key) { FC_ASSERT(!is_locked()); - // backup wallet fc::optional optional_private_key = wif_to_key(wif_key); if (!optional_private_key) FC_THROW("Invalid private key"); - string base58_public_key = optional_private_key->get_public_key().to_base58(); -// copy_wallet_file( "before-import-key-" + base58_public_key ); - if( my->import_key(account_name_or_id, wif_key) ) - { - save_wallet_file(); -// copy_wallet_file( "after-import-key-" + base58_public_key ); - return true; - } - return false; + bool result = my->import_key(account_name_or_id, wif_key); + save_wallet_file(); + + return result; } -map wallet_api::dump_private_keys() +variant wallet_api::dump_private_keys() { FC_ASSERT(!is_locked()); - return my->_keys; + fc::mutable_variant_object result; + result["ec_keys"] = my->_keys; + result["el_gamal_keys"] = my->_el_gamal_keys; // map of public keys to private keys + + return result; } From cf403c50703dfa77327e758ffe4c61b7d9c7473e Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 26 Feb 2018 14:01:28 +0100 Subject: [PATCH 061/136] fix: dump_private_keys returns wrong type --- libraries/wallet/include/graphene/wallet/wallet_file.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet_file.hpp b/libraries/wallet/include/graphene/wallet/wallet_file.hpp index 73296a06..f019358d 100644 --- a/libraries/wallet/include/graphene/wallet/wallet_file.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet_file.hpp @@ -149,7 +149,7 @@ bool import_key(const string& account_name_or_id, const string& wif_key); * @return a map containing the private keys and corresponding public keys * @ingroup WalletAPI_Wallet */ -map dump_private_keys(); +variant dump_private_keys(); #endif //DECENT_WALLET_WALLET_FILE_H From 60962dd75ca06d5de09dba48cd94711980dbb68f Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Mon, 26 Feb 2018 16:58:18 +0100 Subject: [PATCH 062/136] DCT-521, Support for seeder blacklist.json which stores content by stop_content_seeding() or start_content_seeding() --- .../include/graphene/seeding/seeding.hpp | 10 +++ libraries/plugins/seeding/seeding.cpp | 77 ++++++++++++++----- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp b/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp index c6b6e5c2..ada3d2b6 100644 --- a/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp +++ b/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp @@ -201,6 +201,16 @@ class seeding_plugin_impl /*: public package_transfer_interface::transfer_listen */ void send_ready_to_publish(); + /** + * Loads blacklist configuration from file + */ + seeder_blacklist_cfg load_blacklist_cfg(); + + /** + * Saves seeder blacklist configuration to file + */ + void save_blacklist_cfg(const seeder_blacklist_cfg& cfg); + /** * Starts seeding of specified content */ diff --git a/libraries/plugins/seeding/seeding.cpp b/libraries/plugins/seeding/seeding.cpp index 89ae02e1..6d9a0a51 100644 --- a/libraries/plugins/seeding/seeding.cpp +++ b/libraries/plugins/seeding/seeding.cpp @@ -499,6 +499,11 @@ void seeding_plugin_impl::restore_state(){ content_itr--; if( content_itr->expiration < database().head_block_time() ) break; + + auto url_iter = std::find(seeder_cfg.content_blacklist.begin(), seeder_cfg.content_blacklist.end(), content_itr->URI); + if (url_iter != seeder_cfg.content_blacklist.end()) + break; + auto search_itr = content_itr->key_parts.find( sitr->seeder ); if( search_itr != content_itr->key_parts.end() ) { @@ -553,12 +558,14 @@ void seeding_plugin_impl::restore_state(){ database().modify(*citr, [](my_seeding_object& so){so.downloaded = true;}); }else{ - elog("restarting downloads, re-downloading package ${u}", ("u", citr->URI)); - package_handle = pm.get_package(citr->URI, citr->_hash); - decent::package::event_listener_handle_t sl = std::make_shared(*this, *citr , package_handle); - package_handle->remove_all_event_listeners(); - package_handle->add_event_listener(sl); - package_handle->download(false); + if (std::find(seeder_cfg.content_blacklist.begin(), seeder_cfg.content_blacklist.end(), citr->URI) == seeder_cfg.content_blacklist.end()) { + elog("restarting downloads, re-downloading package ${u}", ("u", citr->URI)); + package_handle = pm.get_package(citr->URI, citr->_hash); + decent::package::event_listener_handle_t sl = std::make_shared(*this, *citr, package_handle); + package_handle->remove_all_event_listeners(); + package_handle->add_event_listener(sl); + package_handle->download(false); + } } ++citr; } @@ -671,6 +678,12 @@ void seeding_plugin_impl::start_content_seeding(const std::string& url) } elog("restarting downloads, service thread end"); generate_pors(); + // remove from blacklist + auto url_iter = std::find(seeder_cfg.content_blacklist.begin(), seeder_cfg.content_blacklist.end(), url); + if (url_iter != seeder_cfg.content_blacklist.end()) + seeder_cfg.content_blacklist.erase(url_iter); + // save blacklist + save_blacklist_cfg(seeder_cfg); }); } FC_CAPTURE_AND_RETHROW() } @@ -709,8 +722,16 @@ void seeding_plugin_impl::stop_content_seeding(const std::string& url) seeder_object.free_space += mso.space; }); + std::string hash = package_handle->get_hash().str(); release_package(mso, package_handle); db.remove(mso); + + // store to blacklist + auto found_iter = std::find(seeder_cfg.content_blacklist.begin(), seeder_cfg.content_blacklist.end(), url); + if(found_iter == seeder_cfg.content_blacklist.end()) + seeder_cfg.content_blacklist.push_back(url); + // save blacklist + save_blacklist_cfg(seeder_cfg); ilog("seeding plugin_impl: stop_content_seeding() content cleaned, continue"); break; } @@ -718,6 +739,36 @@ void seeding_plugin_impl::stop_content_seeding(const std::string& url) }FC_CAPTURE_AND_RETHROW() } +seeder_blacklist_cfg seeding_plugin_impl::load_blacklist_cfg() +{ + fc::path seeder_blacklist_path = graphene::utilities::decent_path_finder::instance().get_decent_home(); + seeder_blacklist_path = seeder_blacklist_path / "seeder"; + if (!fc::exists(seeder_blacklist_path)) + fc::create_directories(seeder_blacklist_path); + + seeder_blacklist_path = seeder_blacklist_path / "blacklist.json"; + std::string string_path = seeder_blacklist_path.string(); + try { + if (fc::exists(seeder_blacklist_path)) { + variant tmp = fc::json::from_file(seeder_blacklist_path); + return tmp.as(); + } + } FC_CAPTURE_AND_LOG((string_path)); +} + +void seeding_plugin_impl::save_blacklist_cfg(const seeder_blacklist_cfg& cfg) +{ + fc::path seeder_blacklist_path = graphene::utilities::decent_path_finder::instance().get_decent_home(); + seeder_blacklist_path = seeder_blacklist_path / "seeder"; + if (!fc::exists(seeder_blacklist_path)) + fc::create_directories(seeder_blacklist_path); + + seeder_blacklist_path = seeder_blacklist_path / "blacklist.json"; + fc::variant tmp; + fc::to_variant(cfg, tmp); + fc::json::save_to_file(tmp, seeder_blacklist_path); +} + }// end namespace detail @@ -837,19 +888,7 @@ void seeding_plugin::plugin_pre_startup( const seeding_plugin_startup_options& s my = unique_ptr( new detail::seeding_plugin_impl( *this) ); // load blacklist - fc::path seeder_blacklist_path = graphene::utilities::decent_path_finder::instance().get_decent_home(); - seeder_blacklist_path = seeder_blacklist_path / "seeder"; - if (!fc::exists(seeder_blacklist_path)) - fc::create_directories(seeder_blacklist_path); - - seeder_blacklist_path = seeder_blacklist_path / "blacklist.json"; - std::string string_path = seeder_blacklist_path.string(); - try { - if (fc::exists(seeder_blacklist_path)) { - variant tmp = fc::json::from_file(seeder_blacklist_path); - my->seeder_cfg = tmp.as(); - } - } FC_CAPTURE_AND_LOG((string_path)); + my->seeder_cfg = my->load_blacklist_cfg(); my->service_thread = std::make_shared("seeding"); my->main_thread = &fc::thread::current(); From bd7d5995b0cc3888d509185d9a15eff82fd5ec16 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 27 Feb 2018 09:59:55 +0100 Subject: [PATCH 063/136] fixed FC_REFLECT-ion for new struct member --- libraries/chain/include/graphene/chain/protocol/asset_ops.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp index a0692aa1..71eaf40f 100644 --- a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp +++ b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp @@ -319,6 +319,7 @@ FC_REFLECT( graphene::chain::asset_options, (max_supply) (core_exchange_rate) (is_exchangeable) + (is_fixed_max_supply) (extensions) ) From e6cbf3e48025ff09daa6f4361ea79572937a3819 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 27 Feb 2018 10:39:17 +0100 Subject: [PATCH 064/136] comments updated. --- libraries/wallet/include/graphene/wallet/assets.hpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/assets.hpp b/libraries/wallet/include/graphene/wallet/assets.hpp index 8275edbb..efc4becb 100644 --- a/libraries/wallet/include/graphene/wallet/assets.hpp +++ b/libraries/wallet/include/graphene/wallet/assets.hpp @@ -104,11 +104,13 @@ signed_transaction update_monitored_asset(const string& symbol, * must be less than or equal to 12 * @param description asset description. Maximal length is 1000 chars * @param max_supply the maximum supply of this asset which may exist at any given time - * @param core_exchange_rate core_exchange_rate technically needs to store the asset ID of - * this new asset. Since this ID is not known at the time this operation is - * created, create this price as though the new asset has instance ID 1, and - * the chain will overwrite it with the new asset's ID - * @param is_exchangeable \c true to allow implicit conversion of this asset to/from core asset + * @param core_exchange_rate core_exchange_rate is a price struct which consist from base asset + * and quote asset (see price). One of the asset has to be core asset. + * Technically core_exchange_rate needs to store the asset id of + * this new asset. Since this id is not known at the time this operation is + * created, create this price as though the new asset id has instance 1, and + * the chain will overwrite it with the new asset's id + * @param is_exchangeable \c true to allow implicit conversion when buing content of this asset to/from core asset * @param broadcast \c true to broadcast the transaction on the network * @return the signed transaction creating a new asset * @ingroup WalletAPI_Asset From 5112d80a9df5af69288f8c5f4879047725439f0e Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 28 Feb 2018 13:42:02 +0100 Subject: [PATCH 065/136] added some exception info and comments --- libraries/chain/asset_evaluator.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 1b099707..46df605b 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -155,7 +155,7 @@ void_result user_issued_asset_update_evaluator::do_evaluate(const update_user_is FC_ASSERT(d.find_object(*o.new_issuer)); if (a.options.is_fixed_max_supply) - FC_ASSERT(o.max_supply == a.options.max_supply); + FC_ASSERT(o.max_supply == a.options.max_supply, "Asset ${uia} is fixed max_supply.", ("uia", a.symbol) ); asset_to_update = &a; FC_ASSERT( o.issuer == a.issuer, "", ("o.issuer", o.issuer)("a.issuer", a.issuer) ); @@ -170,11 +170,12 @@ void_result user_issued_asset_update_evaluator::do_apply(const update_user_issue d.modify(*asset_to_update, [&](asset_object& a) { if( o.new_issuer ) a.issuer = *o.new_issuer; - if( o.new_description != "" ) + if( !o.new_description.empty() ) a.description = o.new_description; a.options.max_supply = o.max_supply; a.options.core_exchange_rate = o.core_exchange_rate; a.options.is_exchangeable = o.is_exchangeable; + //a.options.is_fixed_max_supply can't be changed by update operation }); return void_result(); From cce975ae42d2dbd6ea214c62f4c823af2869bfae Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 28 Feb 2018 14:16:12 +0100 Subject: [PATCH 066/136] fixed merge --- libraries/wallet/include/graphene/wallet/wallet.hpp | 8 ++++---- libraries/wallet/wallet.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 11518b87..62322c46 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -506,9 +506,8 @@ FC_API( graphene::wallet::wallet_api, (get_message_objects) (get_messages) (get_sent_messages) - ) -#if 0 +#if 0 //Debug (dbg_make_mia) (dbg_push_blocks) @@ -522,5 +521,6 @@ FC_API( graphene::wallet::wallet_api, //Network (flood_network) #endif - - \ No newline at end of file + +) + diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 8aa037e7..61a7068b 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2815,7 +2815,7 @@ signed_transaction content_cancellation(const string& author, } FC_CAPTURE_AND_RETHROW((url)) } - void dbg_make_mia(string creator, string symbol) + void dbg_make_mia(const std::string& creator, const std::string& symbol) { create_monitored_asset(get_account(creator).name, symbol, 2, "abcd", 3600, 1, true); } From 9a71253db914770332695762981f3ba3124fb8e0 Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Wed, 28 Feb 2018 18:34:15 +0100 Subject: [PATCH 067/136] Temporary fix for building with clang --- libraries/app/api.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 3e1c3aab..e3355c71 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -257,7 +257,7 @@ namespace graphene { namespace app { FC_ASSERT(p); bool running = p->plugin_is_running(); FC_ASSERT(running, "Seeding plugin is not running"); - p->start_content_seeding(url); + //p->start_content_seeding(url); } void network_node_api::stop_content_seeding(const std::string& url) const @@ -266,7 +266,7 @@ namespace graphene { namespace app { FC_ASSERT(p); bool running = p->plugin_is_running(); FC_ASSERT(running, "Seeding plugin is not running"); - p->stop_content_seeding(url); + //p->stop_content_seeding(url); } fc::api login_api::network_broadcast()const From 12d4f414542834729238dd502cfc27385ab03e46 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 1 Mar 2018 09:06:36 +0100 Subject: [PATCH 068/136] added comment for new parameter --- libraries/wallet/include/graphene/wallet/assets.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/wallet/include/graphene/wallet/assets.hpp b/libraries/wallet/include/graphene/wallet/assets.hpp index 8a89e8b7..e1739322 100644 --- a/libraries/wallet/include/graphene/wallet/assets.hpp +++ b/libraries/wallet/include/graphene/wallet/assets.hpp @@ -111,7 +111,7 @@ signed_transaction update_monitored_asset(const string& symbol, * created, create this price as though the new asset id has instance 1, and * the chain will overwrite it with the new asset's id * @param is_exchangeable \c true to allow implicit conversion when buing content of this asset to/from core asset - * @param is_fixed_max_supply + * @param is_fixed_max_supply true to deny future modifications of 'max_supply' otherwise false * @param broadcast \c true to broadcast the transaction on the network * @return the signed transaction creating a new asset * @ingroup WalletAPI_Asset From c53240a1db2ce96bfee665f154c4146b9be70d47 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 1 Mar 2018 10:49:05 +0100 Subject: [PATCH 069/136] fixed compilation with seeding plugin --- libraries/app/CMakeLists.txt | 4 +--- libraries/app/api.cpp | 4 ++-- libraries/plugins/seeding/CMakeLists.txt | 4 +++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/app/CMakeLists.txt b/libraries/app/CMakeLists.txt index 6db7c858..15da684f 100644 --- a/libraries/app/CMakeLists.txt +++ b/libraries/app/CMakeLists.txt @@ -12,12 +12,10 @@ add_library( graphene_app ) # need to link graphene_debug_miner because plugins aren't sufficiently isolated #246 -target_link_libraries( graphene_app graphene_account_history graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities graphene_debug_miner nlohmann_json package_manager ) +target_link_libraries( graphene_app graphene_account_history graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities graphene_debug_miner decent_seeding nlohmann_json package_manager ) target_include_directories( graphene_app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" - "${CMAKE_CURRENT_SOURCE_DIR}/../plugins/seeding/include" - "${CMAKE_CURRENT_SOURCE_DIR}/../plugins/messaging/include" ) if(MSVC) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index e3355c71..3e1c3aab 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -257,7 +257,7 @@ namespace graphene { namespace app { FC_ASSERT(p); bool running = p->plugin_is_running(); FC_ASSERT(running, "Seeding plugin is not running"); - //p->start_content_seeding(url); + p->start_content_seeding(url); } void network_node_api::stop_content_seeding(const std::string& url) const @@ -266,7 +266,7 @@ namespace graphene { namespace app { FC_ASSERT(p); bool running = p->plugin_is_running(); FC_ASSERT(running, "Seeding plugin is not running"); - //p->stop_content_seeding(url); + p->stop_content_seeding(url); } fc::api login_api::network_broadcast()const diff --git a/libraries/plugins/seeding/CMakeLists.txt b/libraries/plugins/seeding/CMakeLists.txt index f5c0aed3..03946dfe 100644 --- a/libraries/plugins/seeding/CMakeLists.txt +++ b/libraries/plugins/seeding/CMakeLists.txt @@ -8,7 +8,9 @@ add_library( decent_seeding target_link_libraries( decent_seeding graphene_chain graphene_app graphene_time decent_encrypt package_manager fc ) target_include_directories( decent_seeding - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" + "${CMAKE_CURRENT_SOURCE_DIR}/../plugins/messaging/include" +) #install( TARGETS # decent_seeding From bbb59f82e722f55663b96da8e27ecb96d6395851 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Tue, 6 Mar 2018 10:01:07 +0100 Subject: [PATCH 070/136] bugfix: get_block crashes when a non-existing block is fetched --- libraries/wallet/wallet_general.inl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/wallet/wallet_general.inl b/libraries/wallet/wallet_general.inl index 11e1857a..db6169db 100644 --- a/libraries/wallet/wallet_general.inl +++ b/libraries/wallet/wallet_general.inl @@ -8,6 +8,8 @@ variant_object wallet_api::about() const optional wallet_api::get_block(uint32_t num) { optional result = my->_remote_db->get_block(num); + if( !result ) + return optional(); share_type miner_pay_from_reward = 0; share_type miner_pay_from_fees = 0; From 6d6d6e629d861ba902de23d823a512432de7b4e4 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Fri, 16 Mar 2018 10:40:46 +0100 Subject: [PATCH 071/136] + fixed ipfs process shutdown + changed catch(...) to exceptions and logging --- programs/gui_wallet/src/decent_button.cpp | 5 +- programs/gui_wallet/src/gui_wallet_global.cpp | 31 +++++--- programs/gui_wallet/src/mainwindow.cpp | 13 ++-- programs/gui_wallet/src/overview_tab.cpp | 26 ++++--- programs/gui_wallet/src/purchased_tab.cpp | 6 +- programs/gui_wallet/src/rev_history_dlg.cpp | 3 +- programs/gui_wallet/src/richdialog.cpp | 71 ++++++++++++------- programs/gui_wallet/src/transactions_tab.cpp | 2 +- programs/gui_wallet/src/transactions_tab.hpp | 4 +- programs/gui_wallet/src/upload_popup.cpp | 16 ++++- 10 files changed, 110 insertions(+), 67 deletions(-) diff --git a/programs/gui_wallet/src/decent_button.cpp b/programs/gui_wallet/src/decent_button.cpp index 4d4c76a2..6eff3911 100644 --- a/programs/gui_wallet/src/decent_button.cpp +++ b/programs/gui_wallet/src/decent_button.cpp @@ -9,10 +9,7 @@ namespace gui_wallet { -DecentButton::DecentButton(QWidget* pParent, - eType enType/* = Default*/, - eName enName/* = None*/) -: QPushButton(pParent) +DecentButton::DecentButton(QWidget* pParent, eType enType, eName enName) : QPushButton(pParent) { setMouseTracking(true); diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index d329fb4c..4ee5d980 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -573,24 +573,23 @@ class DaemonDetails fc::thread thread_decentd; fc::future future_decentd; }; + // // Globals // -Globals::Globals() -: m_connected_state(ConnectionState::Connecting) +Globals::Globals() : QObject() +, m_connected_state(ConnectionState::Connecting) , m_p_wallet_operator(nullptr) -, m_p_wallet_operator_thread(new QThread(this)) +, m_p_wallet_operator_thread(nullptr) , m_p_timer(new QTimer(this)) , m_p_locale(new QLocale()) , m_p_daemon_details(nullptr) , m_str_currentUser() , m_tp_started(std::chrono::steady_clock::now()) { - m_p_wallet_operator_thread->start(); m_p_timer->start(1000); - QObject::connect(m_p_timer, &QTimer::timeout, - this, &Globals::slot_timer); + QObject::connect(m_p_timer, &QTimer::timeout, this, &Globals::slot_timer); QLocale::setDefault(*m_p_locale); @@ -620,6 +619,10 @@ void Globals::startDaemons(BlockChainStartType type) if (nullptr == m_p_wallet_operator) { + Q_ASSERT(m_p_wallet_operator_thread == nullptr); + m_p_wallet_operator_thread = new QThread(this); + + bNeedNewConnection = true; m_p_wallet_operator = new WalletOperator(); m_p_wallet_operator->moveToThread(m_p_wallet_operator_thread); @@ -627,13 +630,16 @@ void Globals::startDaemons(BlockChainStartType type) m_p_wallet_operator, &WalletOperator::slot_connect); QObject::connect(m_p_wallet_operator, &WalletOperator::signal_connected, this, &Globals::slot_connected); + + connect(m_p_wallet_operator_thread, SIGNAL(finished()), m_p_wallet_operator_thread, SLOT(deleteLater())); + m_p_wallet_operator_thread->start(); } fc::thread& thread_decentd = m_p_daemon_details->thread_decentd; fc::promise::ptr& exit_promise = m_p_daemon_details->exit_promise; - QProcess* daemon_process = nullptr; + QProcess* daemon_process; daemon_process = run_ipfs_daemon(qApp, qApp->applicationDirPath()); m_p_daemon_details->ipfs_process = daemon_process; @@ -690,10 +696,13 @@ void Globals::stopDaemons() m_p_daemon_details->future_decentd.wait(); - if (m_p_daemon_details->ipfs_process) + if (m_p_daemon_details->ipfs_process) { m_p_daemon_details->ipfs_process->terminate(); - delete m_p_daemon_details->ipfs_process; - m_p_daemon_details->ipfs_process = nullptr; + m_p_daemon_details->ipfs_process->waitForFinished(); + + delete m_p_daemon_details->ipfs_process; + m_p_daemon_details->ipfs_process = nullptr; + } if (m_p_daemon_details) { @@ -984,7 +993,7 @@ int DecentTable::getCurrentHighlightedRow() const std::string DecentTable::getSortedColumn() const { if (_current_sort_index < 0) - return ""; + return std::string(); return (_is_ascending ? "+" : "-") + _cols[_current_sort_index].sortid; } diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 04a706fc..839eb7ec 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -733,13 +733,12 @@ void MainWindow::slot_checkDownloads() "\"\" " "\"-1\" "); } - catch(const std::exception& ex) - { + catch(const std::exception& ex) { std::cout << "runTaskParse() " << ex.what() << std::endl; return; } - catch(...) - { + catch(const fc::exception& ex) { + std::cout << "runTaskParse() " << ex.what() << std::endl; return; } @@ -763,11 +762,11 @@ void MainWindow::slot_checkDownloads() } catch(const std::exception& ex) { - std::cout << "runTask('download_package') " << ex.what() << std::endl; + std::cout << "runTask('download_package') URI:" << URI << "Ex:" << ex.what() << std::endl; } - catch(...) + catch(const fc::exception& ex) { - std::cout << "Cannot resume download: " << URI << std::endl; + std::cout << "runTask('download_package') URI:" << URI << "Ex:" << ex.what() << std::endl; } } } diff --git a/programs/gui_wallet/src/overview_tab.cpp b/programs/gui_wallet/src/overview_tab.cpp index 223ffa8d..dcf17797 100644 --- a/programs/gui_wallet/src/overview_tab.cpp +++ b/programs/gui_wallet/src/overview_tab.cpp @@ -161,24 +161,28 @@ void Overview_tab::slot_Details() { try { auto accountInfo = Globals::instance().runTaskParse("get_account " + m_strSelectedAccount.toStdString()); - + std::string id = accountInfo["id"].get(); std::string registrar = accountInfo["registrar"].get(); bool is_publishing_manager = accountInfo["rights_to_publish"]["is_publishing_manager"].get(); std::string name = accountInfo["name"].get(); int size = accountInfo["rights_to_publish"]["publishing_rights_received"].size(); bool is_publishing_rights_received = size; - - UserInfoWidget* userInfoWidget = new UserInfoWidget(nullptr, - is_publishing_manager, - is_publishing_rights_received, - QString::fromStdString(registrar), - QString::fromStdString(name), - QString::fromStdString(id)); - + + UserInfoWidget *userInfoWidget = new UserInfoWidget(nullptr, + is_publishing_manager, + is_publishing_rights_received, + QString::fromStdString(registrar), + QString::fromStdString(name), + QString::fromStdString(id)); + Globals::instance().signal_stackWidgetPush(userInfoWidget); - } catch(...) { - // Ignore for now + } + catch(const std::exception& ex) { + std::cout << "slot_Details('Overview_tab') " << ex.what() << std::endl; + } + catch(const fc::exception& ex) { + std::cout << "slot_Details('Overview_tab') " << ex.what() << std::endl; } } diff --git a/programs/gui_wallet/src/purchased_tab.cpp b/programs/gui_wallet/src/purchased_tab.cpp index 838d9083..a58128ed 100644 --- a/programs/gui_wallet/src/purchased_tab.cpp +++ b/programs/gui_wallet/src/purchased_tab.cpp @@ -286,7 +286,11 @@ void PurchasedTab::slot_ExtractionDirSelected(QString const& path) { if (dummy.find("exception:") != std::string::npos) { message = dummy; } - } catch (const std::exception& ex) { + } + catch (const std::exception& ex) { + message = ex.what(); + } + catch(const fc::exception& ex) { message = ex.what(); } diff --git a/programs/gui_wallet/src/rev_history_dlg.cpp b/programs/gui_wallet/src/rev_history_dlg.cpp index 6dab9a5b..eb36c849 100644 --- a/programs/gui_wallet/src/rev_history_dlg.cpp +++ b/programs/gui_wallet/src/rev_history_dlg.cpp @@ -16,8 +16,7 @@ using namespace gui_wallet; -Rev_history_dlg::Rev_history_dlg(const QString& revHistory, QWidget* pParent) - : QDialog(pParent) +Rev_history_dlg::Rev_history_dlg(const QString& revHistory, QWidget* pParent) : QDialog(pParent) , m_revHistory(revHistory) { diff --git a/programs/gui_wallet/src/richdialog.cpp b/programs/gui_wallet/src/richdialog.cpp index b8efb768..de133861 100644 --- a/programs/gui_wallet/src/richdialog.cpp +++ b/programs/gui_wallet/src/richdialog.cpp @@ -48,8 +48,7 @@ void PlaceInsideLabel(QWidget* pParent, QWidget* pChild) // // RatingWidget // -RatingWidget::RatingWidget(QWidget* pParent) - : QWidget(pParent) +RatingWidget::RatingWidget(QWidget* pParent) : QWidget(pParent) , m_bAutomation(false) { QHBoxLayout* pMainLayout = new QHBoxLayout(); @@ -111,8 +110,7 @@ void RatingWidget::slot_rating() // // StackLayerWidget // -StackLayerWidget::StackLayerWidget(QWidget* pParent) -: QWidget(pParent) +StackLayerWidget::StackLayerWidget(QWidget* pParent) : QWidget(pParent) { QObject::connect(this, &StackLayerWidget::accepted, this, &StackLayerWidget::closed); @@ -120,8 +118,7 @@ StackLayerWidget::StackLayerWidget(QWidget* pParent) // // TransferWidget // -TransferWidget::TransferWidget(QWidget* parent, QString const& userName/* = QString()*/) - : StackLayerWidget(parent) +TransferWidget::TransferWidget(QWidget* parent, QString const& userName) : StackLayerWidget(parent) , m_toUserName(userName) { QVBoxLayout* mainLayout = new QVBoxLayout(); @@ -235,8 +232,7 @@ void TransferWidget::Transfer() // // ImportKeyWidget // -ImportKeyWidget::ImportKeyWidget(QWidget* parent) -: StackLayerWidget(parent) +ImportKeyWidget::ImportKeyWidget(QWidget* parent) : StackLayerWidget(parent) { QObject::connect(this, &StackLayerWidget::accepted, &Globals::instance(), &Globals::signal_keyImported); @@ -374,6 +370,7 @@ UserInfoWidget::UserInfoWidget(QWidget* parent, setWindowTitle(name + " (" + id + ")"); setLayout(main_layout); } + // // ContentInfoWidget // @@ -640,8 +637,7 @@ CommentWidget::CommentWidget(QWidget* pParent, const std::string& content_author, const std::string& content_uri, const std::string& content_description, - const std::string& feedback_author/* = std::string()*/) -: QWidget(pParent) + const std::string& feedback_author) : QWidget(pParent) , m_pComment(new DecentTextEdit(this, DecentTextEdit::Info)) , m_pLabel(new DecentLabel(this, DecentLabel::RowLabel)) , m_pRatingWidget(new RatingWidget(this)) @@ -702,15 +698,20 @@ void CommentWidget::submit() if (m_pRatingWidget->m_rating == 0) return; - try - { + try { Globals::instance().runTaskParse("leave_rating_and_comment " - "\"" + Globals::instance().getCurrentUser() + "\" " - "\"" + m_content_uri + "\" " - "\"" + std::to_string(m_pRatingWidget->m_rating) + "\" " - "\"" + escape_string(m_pComment->toPlainText().toStdString() ) + "\" " - "true" ); - }catch(...){} + "\"" + Globals::instance().getCurrentUser() + "\" " + "\"" + m_content_uri + "\" " + "\"" + std::to_string(m_pRatingWidget->m_rating) + "\" " + "\"" + escape_string(m_pComment->toPlainText().toStdString()) + "\" " + "true"); + } + catch(const std::exception& ex) { + std::cout << "CommentWidget::submit " << ex.what() << std::endl; + } + catch(const fc::exception& ex) { + std::cout << "CommentWidget::submit " << ex.what() << std::endl; + } slot_Previous(); slot_Next(); @@ -750,7 +751,13 @@ void CommentWidget::update() feedback_rating = feedback[0]["rating"].get(); } } - }catch(...){} + } + catch(const std::exception& ex) { + std::cout << "CommentWidget::update " << ex.what() << std::endl; + } + catch(const fc::exception& ex) { + std::cout << "CommentWidget::update " << ex.what() << std::endl; + } int test_count = 0; @@ -907,8 +914,7 @@ bool CommentWidget::slot_Previous() } // PasswordWidget // -PasswordWidget::PasswordWidget(QWidget* pParent, eType enType) -: StackLayerWidget(pParent) +PasswordWidget::PasswordWidget(QWidget* pParent, eType enType) : StackLayerWidget(pParent) , m_enType(enType) , m_pError(new QLabel(this)) { @@ -959,7 +965,7 @@ PasswordWidget::PasswordWidget(QWidget* pParent, eType enType) setLayout(pMainLayout); } -void PasswordWidget::slot_set_password(QString const& strPassword) +void PasswordWidget::slot_set_password(const QString& strPassword) { m_strPassword = strPassword; } @@ -969,14 +975,21 @@ void PasswordWidget::slot_action() if (m_strPassword.isEmpty()) return; + QString error; if (m_enType == eSetPassword) { try { Globals::instance().runTask("set_password \"" + m_strPassword.toStdString() + "\""); } - catch(...) - { + catch(const std::exception& ex) { + error = ex.what(); + } + catch(const fc::exception& ex) { + error = ex.what(); + } + + if (!error.isEmpty()) { m_pError->setText(tr("Cannot set this password")); m_pError->show(); return; @@ -987,8 +1000,14 @@ void PasswordWidget::slot_action() { Globals::instance().runTask("unlock \"" + m_strPassword.toStdString() + "\""); } - catch(...) - { + catch(const std::exception& ex) { + error = ex.what(); + } + catch(const fc::exception& ex) { + error = ex.what(); + } + + if (!error.isEmpty()) { m_pError->setText(tr("Cannot unlock the wallet")); m_pError->show(); return; diff --git a/programs/gui_wallet/src/transactions_tab.cpp b/programs/gui_wallet/src/transactions_tab.cpp index 13cb719b..16ca42bb 100644 --- a/programs/gui_wallet/src/transactions_tab.cpp +++ b/programs/gui_wallet/src/transactions_tab.cpp @@ -152,7 +152,7 @@ void TransactionsTab::slot_SortingChanged(int index) reset(); } -void TransactionsTab::slot_SearchTermChanged(QString const& strSearchTerm) +void TransactionsTab::slot_SearchTermChanged(const QString& strSearchTerm) { m_strSearchTerm = strSearchTerm; reset(false); diff --git a/programs/gui_wallet/src/transactions_tab.hpp b/programs/gui_wallet/src/transactions_tab.hpp index 2ffc6e2c..8790ffcd 100644 --- a/programs/gui_wallet/src/transactions_tab.hpp +++ b/programs/gui_wallet/src/transactions_tab.hpp @@ -20,9 +20,9 @@ class TransactionsTab : public TabContentManager virtual std::string getUpdateCommand() override; signals: - void signal_setUserFilter(QString const& user_name); + void signal_setUserFilter(const QString & user_name); public slots: - void slot_SearchTermChanged(QString const& strSearchTerm); + void slot_SearchTermChanged(const QString & strSearchTerm); void slot_SortingChanged(int); public: diff --git a/programs/gui_wallet/src/upload_popup.cpp b/programs/gui_wallet/src/upload_popup.cpp index 8c5f5ddf..edbc8b53 100644 --- a/programs/gui_wallet/src/upload_popup.cpp +++ b/programs/gui_wallet/src/upload_popup.cpp @@ -560,7 +560,13 @@ void Upload_popup::getContents(string const& id, str_cd += " \"u_seed\": \"" + cd["u_seed"].get() + "\","; str_cd += " \"pubKey\": \"" + cd["pubKey"].get() + "\"}"; } - catch(...) {} + catch(const std::exception& ex) { + std::cout << "Upload_popup::getContents " << ex.what() << std::endl; + } + catch(const fc::exception& ex) { + std::cout << "Upload_popup::getContents " << ex.what() << std::endl; + } + } void Upload_popup::getContents(string const& id, string& title, @@ -611,7 +617,13 @@ void Upload_popup::getContents(string const& id, } } } - catch(...) {} + catch(const std::exception& ex) { + std::cout << "Upload_popup::getContents " << ex.what() << std::endl; + } + catch(const fc::exception& ex) { + std::cout << "Upload_popup::getContents " << ex.what() << std::endl; + } + } void Upload_popup::slot_UploadContent() From 6e95e1d9846fed740e729b476fadddbdbc305fdf Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 21 Mar 2018 12:53:08 +0100 Subject: [PATCH 072/136] added miner voting tab and some improvements and fixes --- .../wallet/include/graphene/wallet/mining.hpp | 15 ++ .../wallet/include/graphene/wallet/wallet.hpp | 13 +- libraries/wallet/wallet.cpp | 66 ++++++ libraries/wallet/wallet_mining.inl | 8 + programs/gui_wallet/CMakeLists.txt | 4 +- .../gui_wallet/src/browse_content_tab.cpp | 1 + programs/gui_wallet/src/gui_wallet_global.cpp | 33 ++- .../src/gui_wallet_tabcontentmanager.cpp | 26 ++- .../src/gui_wallet_tabcontentmanager.hpp | 7 +- programs/gui_wallet/src/mainwindow.cpp | 90 ++++++-- programs/gui_wallet/src/mainwindow.hpp | 3 + programs/gui_wallet/src/mining_vote_tab.cpp | 212 ++++++++++++++++++ programs/gui_wallet/src/mining_vote_tab.hpp | 42 ++++ programs/gui_wallet/src/overview_tab.cpp | 10 +- programs/gui_wallet/src/purchased_tab.cpp | 1 + programs/gui_wallet/src/transactions_tab.cpp | 1 + programs/gui_wallet/src/upload_tab.cpp | 1 + 17 files changed, 487 insertions(+), 46 deletions(-) create mode 100644 programs/gui_wallet/src/mining_vote_tab.cpp create mode 100644 programs/gui_wallet/src/mining_vote_tab.hpp diff --git a/libraries/wallet/include/graphene/wallet/mining.hpp b/libraries/wallet/include/graphene/wallet/mining.hpp index 11d1fa6d..d677ec1e 100644 --- a/libraries/wallet/include/graphene/wallet/mining.hpp +++ b/libraries/wallet/include/graphene/wallet/mining.hpp @@ -158,5 +158,20 @@ signed_transaction set_desired_miner_count(const string& account_to_modify, uint16_t desired_number_of_miners, bool broadcast = false); +/** + * @brief + * @param term search term + * @param order order field. Available options are defined in 'database_api.cpp' + * @param id the id of content object to start searching from + * @param count maximum number of contents to fetch (must not exceed 1000) + * @return the contents found + * @ingroup WalletAPI_Mining + */ +vector search_miner_voting(const string& term, + const string& order, + const string& account_id, + const string& id, + uint32_t count ) const; + #endif //DECENT_WALLET_MINING_H diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 11518b87..38ab465a 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -242,6 +242,15 @@ namespace graphene { namespace wallet { fc::time_point_sec allowed_withdraw_time; }; + struct miner_voting_info + { + miner_id_type id; + string name; + string url; + uint64_t total_votes; + bool voted; + }; + namespace detail { class wallet_api_impl; } @@ -361,6 +370,7 @@ FC_REFLECT_DERIVED( graphene::wallet::signed_block_with_info, (graphene::chain:: FC_REFLECT_DERIVED( graphene::wallet::vesting_balance_object_with_info, (graphene::chain::vesting_balance_object), (allowed_withdraw)(allowed_withdraw_time) ) +FC_REFLECT( graphene::wallet::miner_voting_info, (id)(name)(url)(total_votes)(voted) ) FC_API( graphene::wallet::wallet_api, //General @@ -447,6 +457,7 @@ FC_API( graphene::wallet::wallet_api, (vote_for_miner) (set_voting_proxy) (set_desired_miner_count) + (search_miner_voting) //Seeding (list_seeders_by_price) @@ -523,4 +534,4 @@ FC_API( graphene::wallet::wallet_api, (flood_network) #endif - \ No newline at end of file + diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index ce3df705..42dedcfe 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1622,6 +1622,72 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (account_to_modify)(desired_number_of_miners)(broadcast) ) } + vector search_miner_voting(const string& term, + const string& order, + const string& account_id, + const string& id, + uint32_t count ) const + { + optional acc_obj = _remote_db->get_account_by_name(account_id); + if (!acc_obj) { + FC_THROW("unknown account or invalid account name"); + } + + const auto& acc_votes = acc_obj->options.votes; + + map miners = _remote_db->lookup_miner_accounts("", 1000); + + vector result; + result.reserve(miners.size()); + for(auto item : miners) { + + miner_voting_info info; + info.id = item.second; + info.name = item.first; + + if (!term.empty() && item.first.find(term) == std::string::npos ) { + continue; + } + + miner_object obj = this->get_object(item.second); + + info.url = obj.url; + info.total_votes = obj.total_votes; + info.voted = acc_votes.find(obj.vote_id) != acc_votes.end(); + + result.push_back(info); + } + + struct miner_sorter { + miner_sorter(const string& sort) : sort_(sort) {} + + bool operator()(const miner_voting_info& lhs, const miner_voting_info& rhs) const { + if (sort_ == "+name") + return lhs.name.compare(rhs.name) < 0; + else if (sort_ == "-name") + return rhs.name.compare(lhs.name) < 0; + else if (sort_ == "+link") + return lhs.url.compare(rhs.url) < 0; + else if (sort_ == "-link") + return rhs.url.compare(lhs.url) < 0; + else if (sort_ == "+votes") + return lhs.total_votes < rhs.total_votes; + else if (sort_ == "-votes") + return rhs.total_votes < lhs.total_votes; + + return false; + } + + string sort_; + }; + + if (!order.empty()) { + std::sort(result.begin(), result.end(), miner_sorter(order)); + } + + return result; + } + signed_transaction sign_transaction(signed_transaction tx, bool broadcast = false) { flat_set req_active_approvals; diff --git a/libraries/wallet/wallet_mining.inl b/libraries/wallet/wallet_mining.inl index 44e69e42..203889ed 100644 --- a/libraries/wallet/wallet_mining.inl +++ b/libraries/wallet/wallet_mining.inl @@ -59,3 +59,11 @@ signed_transaction wallet_api::set_desired_miner_count(const string& account_to_ return my->set_desired_miner_count(account_to_modify, desired_number_of_miners, broadcast); } +vector wallet_api::search_miner_voting(const string& term, + const string& order, + const string& account_id, + const string& id, + uint32_t count ) const +{ + return my->search_miner_voting(term, order, account_id, id, count); +} diff --git a/programs/gui_wallet/CMakeLists.txt b/programs/gui_wallet/CMakeLists.txt index d8d47894..b3539b9e 100644 --- a/programs/gui_wallet/CMakeLists.txt +++ b/programs/gui_wallet/CMakeLists.txt @@ -47,14 +47,14 @@ add_executable(DECENT MACOSX_BUNDLE src/upload_popup.hpp src/upload_tab.cpp src/upload_tab.hpp - + src/mining_vote_tab.cpp + src/mining_vote_tab.hpp resources.qrc desktop.icns stdafx.h ) - target_include_directories( DECENT PUBLIC include . diff --git a/programs/gui_wallet/src/browse_content_tab.cpp b/programs/gui_wallet/src/browse_content_tab.cpp index ef80edc2..0f51effe 100644 --- a/programs/gui_wallet/src/browse_content_tab.cpp +++ b/programs/gui_wallet/src/browse_content_tab.cpp @@ -53,6 +53,7 @@ BrowseContentTab::BrowseContentTab(QWidget* pParent, QObject::connect(pFilterLineEdit, &QLineEdit::textChanged, this, &BrowseContentTab::slot_SearchTermChanged); + setFilterWidget(pFilterLineEdit); QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &BrowseContentTab::slot_SortingChanged); diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index d329fb4c..95d202fd 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -487,9 +487,7 @@ QString convertDateTimeToLocale(const std::string& s) // // WalletOperator // -WalletOperator::WalletOperator() -: QObject(nullptr) -, m_wallet_api() +WalletOperator::WalletOperator() : QObject(nullptr), m_wallet_api() { } @@ -579,15 +577,13 @@ class DaemonDetails Globals::Globals() : m_connected_state(ConnectionState::Connecting) , m_p_wallet_operator(nullptr) -, m_p_wallet_operator_thread(new QThread(this)) +, m_p_wallet_operator_thread(nullptr) , m_p_timer(new QTimer(this)) , m_p_locale(new QLocale()) , m_p_daemon_details(nullptr) , m_str_currentUser() , m_tp_started(std::chrono::steady_clock::now()) { - m_p_wallet_operator_thread->start(); - m_p_timer->start(1000); QObject::connect(m_p_timer, &QTimer::timeout, this, &Globals::slot_timer); @@ -620,6 +616,10 @@ void Globals::startDaemons(BlockChainStartType type) if (nullptr == m_p_wallet_operator) { + Q_ASSERT(m_p_wallet_operator_thread == nullptr); + m_p_wallet_operator_thread = new QThread(this); + + bNeedNewConnection = true; m_p_wallet_operator = new WalletOperator(); m_p_wallet_operator->moveToThread(m_p_wallet_operator_thread); @@ -627,6 +627,10 @@ void Globals::startDaemons(BlockChainStartType type) m_p_wallet_operator, &WalletOperator::slot_connect); QObject::connect(m_p_wallet_operator, &WalletOperator::signal_connected, this, &Globals::slot_connected); + + connect(m_p_wallet_operator_thread, SIGNAL(finished()), m_p_wallet_operator_thread, SLOT(deleteLater())); + + m_p_wallet_operator_thread->start(); } fc::thread& thread_decentd = m_p_daemon_details->thread_decentd; @@ -657,10 +661,12 @@ void Globals::startDaemons(BlockChainStartType type) #endif +#if 0 m_p_daemon_details->future_decentd = thread_decentd.async([type, &exit_promise]() -> int { return ::runDecentD(type, exit_promise); }); +#endif m_tp_started = std::chrono::steady_clock::now(); @@ -690,10 +696,15 @@ void Globals::stopDaemons() m_p_daemon_details->future_decentd.wait(); - if (m_p_daemon_details->ipfs_process) + if (m_p_daemon_details->ipfs_process) { m_p_daemon_details->ipfs_process->terminate(); - delete m_p_daemon_details->ipfs_process; - m_p_daemon_details->ipfs_process = nullptr; + if (!m_p_daemon_details->ipfs_process->waitForFinished()) { + m_p_daemon_details->ipfs_process->kill(); + } + + delete m_p_daemon_details->ipfs_process; + m_p_daemon_details->ipfs_process = nullptr; + } if (m_p_daemon_details) { @@ -717,7 +728,9 @@ void Globals::clear() if (m_p_wallet_operator_thread) { m_p_wallet_operator_thread->quit(); - m_p_wallet_operator_thread->wait(); + if (m_p_wallet_operator_thread->isRunning()) { + m_p_wallet_operator_thread->wait(); + } delete m_p_wallet_operator_thread; m_p_wallet_operator_thread = nullptr; } diff --git a/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp b/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp index 6fd1f8c4..c43d0228 100644 --- a/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp +++ b/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp @@ -21,19 +21,29 @@ void TabContentManager::tryToUpdate() { timeToUpdate(std::string()); return; } - - std::string result; + + std::string result, error; try { result = Globals::instance().runTask(command); - } catch (...) { - result.clear(); } + catch (std::exception &ex) { + error = ex.what(); + + } + catch (fc::exception& ex) { + error = ex.what(); + + } +// catch (...) { +// result.clear(); +// } + if (result != m_last_result) { m_last_result = result; timeToUpdate(result); } } catch (...) { - + } } @@ -93,4 +103,10 @@ std::string TabContentManager::next_iterator() const return str_iterator; } +void TabContentManager::setFilterWidget(QWidget* pWidget) +{ + m_pFilterWidget = pWidget; +} + + } // namespace gui_wallet diff --git a/programs/gui_wallet/src/gui_wallet_tabcontentmanager.hpp b/programs/gui_wallet/src/gui_wallet_tabcontentmanager.hpp index cc21738c..03d94161 100644 --- a/programs/gui_wallet/src/gui_wallet_tabcontentmanager.hpp +++ b/programs/gui_wallet/src/gui_wallet_tabcontentmanager.hpp @@ -14,7 +14,10 @@ class TabContentManager : public QWidget virtual void timeToUpdate(const std::string& result) = 0; virtual std::string getUpdateCommand() = 0; - + + void setFilterWidget(QWidget* pWidget); + virtual QWidget* getFilterWidget() const { return m_pFilterWidget; } + public: void tryToUpdate(); @@ -31,6 +34,8 @@ class TabContentManager : public QWidget std::string m_last_result; std::string m_next_iterator; std::vector m_iterators; + + QWidget* m_pFilterWidget; }; diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 04a706fc..08181a51 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -32,6 +32,7 @@ #include "upload_tab.hpp" #include "overview_tab.hpp" #include "purchased_tab.hpp" +#include "mining_vote_tab.hpp" #include "json.hpp" @@ -128,12 +129,17 @@ MainWindow::MainWindow() m_pButtonPurchased->setText(tr("Purchased")); m_pButtonPurchased->setCheckable(true); + m_pButtonMinerVoting = new DecentButton(pMainWidget, DecentButton::TabChoice); + m_pButtonMinerVoting->setText(tr("Miner Voting")); + m_pButtonMinerVoting->setCheckable(true); + QButtonGroup* pGroup = new QButtonGroup(pMainWidget); pGroup->addButton(m_pButtonBrowse); pGroup->addButton(m_pButtonTransactions); pGroup->addButton(m_pButtonPublish); pGroup->addButton(m_pButtonUsers); pGroup->addButton(m_pButtonPurchased); + pGroup->addButton(m_pButtonMinerVoting); // // 3rd row controls // @@ -175,6 +181,9 @@ MainWindow::MainWindow() m_pTabUsers->hide(); m_pTabPurchased = new PurchasedTab(pMainWidget, m_pFilterPurchased); m_pTabPurchased->hide(); + m_pTabMinerVoting = new MinerVotingTab(pMainWidget, m_pFilterUsers); + m_pTabMinerVoting->hide(); + // // 5th row controls // @@ -189,6 +198,7 @@ MainWindow::MainWindow() // QHBoxLayout* pSpacerLayout = new QHBoxLayout; pSpacerLayout->addWidget(m_pAccountList, Qt::AlignLeft); + pSpacerLayout->addWidget(m_pAccountList, Qt::AlignLeft); pSpacerLayout->addStretch(); pRow1Spacer->setLayout(pSpacerLayout); pSpacerLayout->setSpacing(0); @@ -209,6 +219,7 @@ MainWindow::MainWindow() pRow2Layout->addWidget(m_pButtonPublish); pRow2Layout->addWidget(m_pButtonUsers); pRow2Layout->addWidget(m_pButtonPurchased); + pRow2Layout->addWidget(m_pButtonMinerVoting); // // 3rd row layout // @@ -238,6 +249,7 @@ MainWindow::MainWindow() pRow4Layout->addWidget(m_pTabPublish); pRow4Layout->addWidget(m_pTabUsers); pRow4Layout->addWidget(m_pTabPurchased); + pRow4Layout->addWidget(m_pTabMinerVoting); pRow4Layout->setSpacing(0); pRow4Layout->setContentsMargins(5, 0, 5, 0); // @@ -300,6 +312,8 @@ MainWindow::MainWindow() this, &MainWindow::slot_UsersToggled); QObject::connect(m_pButtonPurchased, &QPushButton::toggled, this, &MainWindow::slot_PurchasedToggled); + QObject::connect(m_pButtonMinerVoting, &QPushButton::toggled, + this, &MainWindow::slot_MinerVotingToggled); QObject::connect(m_pPreviousPage, &QPushButton::clicked, this, &MainWindow::slot_PreviousPage); @@ -540,7 +554,7 @@ void MainWindow::slot_showPurchasedTab() void MainWindow::slot_showTransactionsTab(std::string const& account_name) { m_pButtonTransactions->setChecked(true); - m_pFilterTransactions->setText(account_name.c_str()); + m_pFilterTransactions->setText(QString::fromStdString(account_name)); slot_getContents(); } @@ -632,16 +646,17 @@ void MainWindow::slot_TransactionsToggled(bool toggled) // really a stupid hack to have the state change visible pSender->setEnabled(false); pSender->setEnabled(true); + + QWidget* pFilter = m_pTabTransactions->getFilterWidget(); + Q_ASSERT(pFilter); + pFilter->setHidden(!toggled); + // - if (toggled) - { - m_pFilterTransactions->show(); + if (toggled) { m_pTabTransactions->show(); slot_getContents(); } - else - { - m_pFilterTransactions->hide(); + else { m_pTabTransactions->hide(); } } @@ -653,17 +668,19 @@ void MainWindow::slot_PublishToggled(bool toggled) // really a stupid hack to have the state change visible pSender->setEnabled(false); pSender->setEnabled(true); + + QWidget* pFilter = m_pTabPublish->getFilterWidget(); + Q_ASSERT(pFilter); + pFilter->setHidden(!toggled); + // - if (toggled) - { - m_pFilterPublish->show(); + if (toggled) { m_pTabPublish->show(); m_pPublish->show(); slot_getContents(); } else { - m_pFilterPublish->hide(); m_pTabPublish->hide(); m_pPublish->hide(); } @@ -676,16 +693,17 @@ void MainWindow::slot_UsersToggled(bool toggled) // really a stupid hack to have the state change visible pSender->setEnabled(false); pSender->setEnabled(true); + + QWidget* pFilter = m_pTabUsers->getFilterWidget(); + Q_ASSERT(pFilter); + pFilter->setHidden(!toggled); + // - if (toggled) - { - m_pFilterUsers->show(); + if (toggled) { m_pTabUsers->show(); slot_getContents(); } - else - { - m_pFilterUsers->hide(); + else { m_pTabUsers->hide(); } } @@ -697,20 +715,44 @@ void MainWindow::slot_PurchasedToggled(bool toggled) // really a stupid hack to have the state change visible pSender->setEnabled(false); pSender->setEnabled(true); + + QWidget* pFilter = m_pTabPurchased->getFilterWidget(); + Q_ASSERT(pFilter); + pFilter->setHidden(!toggled); + // - if (toggled) - { - m_pFilterPurchased->show(); + if (toggled) { m_pTabPurchased->show(); slot_getContents(); } - else - { - m_pFilterPurchased->hide(); + else { m_pTabPurchased->hide(); } } +void MainWindow::slot_MinerVotingToggled(bool toggled) +{ + QWidget* pSender = qobject_cast(sender()); + // + // really a stupid hack to have the state change visible + pSender->setEnabled(false); + pSender->setEnabled(true); + + QWidget* pFilter = m_pTabMinerVoting->getFilterWidget(); + Q_ASSERT(pFilter); + pFilter->setHidden(!toggled); + + // + if (toggled) { + m_pTabMinerVoting->show(); + slot_getContents(); + } + else { + m_pTabMinerVoting->hide(); + } + +} + void MainWindow::slot_checkDownloads() { auto& global_instance = gui_wallet::Globals::instance(); @@ -844,6 +886,8 @@ TabContentManager* MainWindow::activeTable() const pTab = m_pTabUsers; else if (m_pTabPurchased->isVisible()) pTab = m_pTabPurchased; + else if (m_pTabMinerVoting->isVisible()) + pTab = m_pTabMinerVoting; return pTab; } diff --git a/programs/gui_wallet/src/mainwindow.hpp b/programs/gui_wallet/src/mainwindow.hpp index 500890d3..5da057d1 100644 --- a/programs/gui_wallet/src/mainwindow.hpp +++ b/programs/gui_wallet/src/mainwindow.hpp @@ -48,6 +48,7 @@ protected slots: void slot_PublishToggled(bool toggled); void slot_UsersToggled(bool toggled); void slot_PurchasedToggled(bool toggled); + void slot_MinerVotingToggled(bool toggled); void DisplayWalletContentGUI(); @@ -73,6 +74,7 @@ protected slots: DecentButton* m_pButtonPublish; DecentButton* m_pButtonUsers; DecentButton* m_pButtonPurchased; + DecentButton* m_pButtonMinerVoting; DecentButton* m_pPreviousPage; DecentButton* m_pResetPage; @@ -91,6 +93,7 @@ protected slots: TabContentManager* m_pTabPublish; TabContentManager* m_pTabUsers; TabContentManager* m_pTabPurchased; + TabContentManager* m_pTabMinerVoting; QAction* m_pActionImportKey; QAction* m_pActionReplayBlockchain; diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp new file mode 100644 index 00000000..7518d05b --- /dev/null +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -0,0 +1,212 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +#include "stdafx.h" + +#include "gui_wallet_global.hpp" +#include "decent_button.hpp" +#include "decent_line_edit.hpp" +#include "mining_vote_tab.hpp" + +#include + +#ifndef _MSC_VER +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "json.hpp" + +#endif + +using std::string; + +namespace gui_wallet { + +const char* g_vote_state_id = "vote-state"; + + +MinerVotingTab::MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit) : TabContentManager(pParent), + m_pTableWidget(new DecentTable(this)) +{ + m_pTableWidget->set_columns({ + {tr("Miner"), 15, "name"}, + {tr("Link to proposal"), 30, "link"}, + {tr("Votes"), -50, "votes"}, + {" ", 5}, + }); + + + QVBoxLayout* pMainLayout = new QVBoxLayout(); + pMainLayout->setContentsMargins(0, 5, 0, 0); + pMainLayout->setMargin(0); + pMainLayout->addWidget(m_pTableWidget); + pMainLayout->setSpacing(0); + + setLayout(pMainLayout); + + if (pFilterLineEdit) { + QObject::connect(pFilterLineEdit, &QLineEdit::textChanged, + this, &MinerVotingTab::slot_SearchTermChanged); + this->setFilterWidget(pFilterLineEdit); + } + + QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, + this, &MinerVotingTab::slot_SortingChanged); + + +} + +MinerVotingTab::~MinerVotingTab() = default; + +void MinerVotingTab::timeToUpdate(const std::string& result) +{ + if (result.empty()) { + m_pTableWidget->setRowCount(0); + return; + } + + auto contents = nlohmann::json::parse(result); + size_t iSize = contents.size(); + if (iSize > m_i_page_size) + iSize = m_i_page_size; + + m_buttonsToIndex.clear(); + m_pTableWidget->setRowCount(iSize); + + for (size_t iIndex = 0; iIndex < iSize; ++iIndex) { + auto const &content = contents[iIndex]; + + string name = content["name"].get(); + string url = content["url"].get(); + uint64_t total_votes = content["total_votes"].get(); + bool voted = content["voted"].get(); + + QTableWidgetItem* tabItem; + tabItem = new QTableWidgetItem(QString::fromStdString(name)); + tabItem->setTextAlignment(Qt::AlignHCenter); + m_pTableWidget->setItem(iIndex, 0, tabItem); + + tabItem = new QTableWidgetItem(QString::fromStdString(url)); + tabItem->setTextAlignment(Qt::AlignHCenter); + m_pTableWidget->setItem(iIndex, 1, tabItem); + + tabItem = new QTableWidgetItem(QString::number(total_votes)); + tabItem->setTextAlignment(Qt::AlignRight); + m_pTableWidget->setItem(iIndex, 2, tabItem); + + // Vote Button + // + DecentButton* pVoteButton = new DecentButton(m_pTableWidget); + pVoteButton->setEnabled(false); + if (!voted) { + pVoteButton->setText(tr("Vote")); + pVoteButton->setStyleSheet(""); + } + else { + pVoteButton->setText(tr("Un-vote")); + pVoteButton->setStyleSheet(" QPushButton:disabled { background-color: #E6A900 } "); + } + pVoteButton->setProperty(g_vote_state_id, QVariant(voted)); + + + m_pTableWidget->setCellWidget(iIndex, 3, pVoteButton); + m_buttonsToIndex.insert(pVoteButton, iIndex); + + QObject::connect(pVoteButton, &DecentButton::clicked, this, &MinerVotingTab::slot_MinerVote); + } + + if (contents.size() > m_i_page_size) + set_next_page_iterator(contents[m_i_page_size]["id"].get()); + else + set_next_page_iterator(string()); + +} + +std::string MinerVotingTab::getUpdateCommand() +{ + string currentUserName = Globals::instance().getCurrentUser(); + if (currentUserName.empty()) + return string(); + + graphene::chain::ContentObjectPropertyManager type_composer; + graphene::chain::ContentObjectTypeValue type(graphene::chain::EContentObjectApplication::DecentCore); + string str_type; + type.to_string(str_type); + + return "search_miner_voting " + "\"" + m_strSearchTerm.toStdString() + "\" " + "\"" + m_pTableWidget->getSortedColumn() + "\" " + "\"" + currentUserName + "\" " + "\"" + next_iterator() + "\" " + + std::to_string(m_i_page_size + 1); +} + +void MinerVotingTab::slot_SearchTermChanged(const QString& strSearchTerm) +{ + m_strSearchTerm = strSearchTerm; + reset(false); +} + +void MinerVotingTab::slot_SortingChanged(int index) +{ + reset(); +} + +void MinerVotingTab::slot_MinerVote() +{ + Q_ASSERT(sender() != nullptr); + auto find = m_buttonsToIndex.find(qobject_cast(sender())); + if (find == m_buttonsToIndex.end()) { + return; + } + + bool voteFlag = sender()->property(g_vote_state_id).toBool(); + int iIndex = find.value(); + + QTableWidgetItem* item = m_pTableWidget->item(iIndex, 0); + std::string miner_name = item->text().toStdString(); + + submit_vote(miner_name, !voteFlag); +} + +void MinerVotingTab::submit_vote(const std::string& miner_name, bool voteFlag) +{ + QString error; + + try { + std::string submitCommand; + submitCommand = "vote_for_miner "; + submitCommand += "\"" + Globals::instance().getCurrentUser() + "\" "; + submitCommand += "\"" + miner_name + "\" "; + submitCommand += voteFlag ? "true " : "false "; + submitCommand += "true"; + + Globals::instance().runTask(submitCommand); + } + catch(const std::exception& ex) { + error = QString::fromStdString( ex.what() ); + } + catch(const fc::exception& ex) { + error = QString::fromStdString( ex.what() ); + } + + if (!error.isEmpty()) { + ShowMessageBox(tr("Error"), tr("Failed to submit voting"), error); + } + +} + + + + + +} //namespace \ No newline at end of file diff --git a/programs/gui_wallet/src/mining_vote_tab.hpp b/programs/gui_wallet/src/mining_vote_tab.hpp new file mode 100644 index 00000000..21cacfce --- /dev/null +++ b/programs/gui_wallet/src/mining_vote_tab.hpp @@ -0,0 +1,42 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +#pragma once + +#include + +#include "gui_wallet_tabcontentmanager.hpp" +#include + +class QSignalMapper; +class QWidget; + +namespace gui_wallet +{ + class DecentTable; + class DecentLineEdit; + class DecentButton; + struct SDigitalContent; + + class MinerVotingTab : public TabContentManager { + Q_OBJECT + public: + MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit); + ~MinerVotingTab(); + + virtual void timeToUpdate(const std::string& result); + virtual std::string getUpdateCommand(); + + public slots: + void slot_SearchTermChanged(QString const& strSearchTerm); + void slot_SortingChanged(int index); + void slot_MinerVote(); + + private: + void submit_vote(const std::string& miner_name, bool voteFlag); + + public: + DecentTable* m_pTableWidget; + QString m_strSearchTerm; + + QMap m_buttonsToIndex; + }; +} \ No newline at end of file diff --git a/programs/gui_wallet/src/overview_tab.cpp b/programs/gui_wallet/src/overview_tab.cpp index 223ffa8d..6268d13b 100644 --- a/programs/gui_wallet/src/overview_tab.cpp +++ b/programs/gui_wallet/src/overview_tab.cpp @@ -46,9 +46,11 @@ Overview_tab::Overview_tab(QWidget* pParent, setLayout(pMainLayout); - if (pFilterLineEdit) - QObject::connect(pFilterLineEdit, &QLineEdit::textChanged, - this, &Overview_tab::slot_SearchTermChanged); + if (pFilterLineEdit) { + QObject::connect(pFilterLineEdit, &QLineEdit::textChanged, + this, &Overview_tab::slot_SearchTermChanged); + setFilterWidget(pFilterLineEdit); + } QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &Overview_tab::slot_SortingChanged); @@ -95,7 +97,7 @@ void Overview_tab::timeToUpdate(const std::string& result) { QObject::connect(pTransactionButton, &DecentButton::clicked, this, &Overview_tab::slot_Transactions); - m_pAccountSignalMapper->setMapping(pTransactionButton, name.c_str()); + m_pAccountSignalMapper->setMapping(pTransactionButton, QString::fromStdString(name)); m_pTableWidget->setCellWidget(iIndex, 2, pTransactionButton); // Details Button diff --git a/programs/gui_wallet/src/purchased_tab.cpp b/programs/gui_wallet/src/purchased_tab.cpp index 838d9083..cf123f45 100644 --- a/programs/gui_wallet/src/purchased_tab.cpp +++ b/programs/gui_wallet/src/purchased_tab.cpp @@ -60,6 +60,7 @@ PurchasedTab::PurchasedTab(QWidget* pParent, QObject::connect(pFilterLineEdit, &QLineEdit::textChanged, this, &PurchasedTab::slot_SearchTermChanged); + setFilterWidget(pFilterLineEdit); QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &PurchasedTab::slot_SortingChanged); diff --git a/programs/gui_wallet/src/transactions_tab.cpp b/programs/gui_wallet/src/transactions_tab.cpp index 13cb719b..d142a4c6 100644 --- a/programs/gui_wallet/src/transactions_tab.cpp +++ b/programs/gui_wallet/src/transactions_tab.cpp @@ -56,6 +56,7 @@ TransactionsTab::TransactionsTab(QWidget* pParent, QObject::connect(pFilterLineEdit, &QLineEdit::textChanged, this, &TransactionsTab::slot_SearchTermChanged); + setFilterWidget(pFilterLineEdit); QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &TransactionsTab::slot_SortingChanged); diff --git a/programs/gui_wallet/src/upload_tab.cpp b/programs/gui_wallet/src/upload_tab.cpp index 94557612..64cdaeb1 100644 --- a/programs/gui_wallet/src/upload_tab.cpp +++ b/programs/gui_wallet/src/upload_tab.cpp @@ -62,6 +62,7 @@ Upload_tab::Upload_tab(QWidget* pParent, QObject::connect(pFilterLineEdit, &QLineEdit::textChanged, this, &Upload_tab::slot_SearchTermChanged); + setFilterWidget(pFilterLineEdit); QObject::connect(pUploadButton, &QPushButton::clicked, this, &Upload_tab::slot_UploadPopup); From 267a8f9df6c84f9a8ac8da7974f07fef2f1e0511 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 21 Mar 2018 15:24:13 +0100 Subject: [PATCH 073/136] fixed empty miner voting table --- programs/gui_wallet/src/gui_wallet_global.cpp | 2 - programs/gui_wallet/src/mainwindow.cpp | 1 - programs/gui_wallet/src/mining_vote_tab.cpp | 92 +++++++++++-------- 3 files changed, 53 insertions(+), 42 deletions(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index 95d202fd..4462ff75 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -661,12 +661,10 @@ void Globals::startDaemons(BlockChainStartType type) #endif -#if 0 m_p_daemon_details->future_decentd = thread_decentd.async([type, &exit_promise]() -> int { return ::runDecentD(type, exit_promise); }); -#endif m_tp_started = std::chrono::steady_clock::now(); diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 08181a51..74f37c77 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -198,7 +198,6 @@ MainWindow::MainWindow() // QHBoxLayout* pSpacerLayout = new QHBoxLayout; pSpacerLayout->addWidget(m_pAccountList, Qt::AlignLeft); - pSpacerLayout->addWidget(m_pAccountList, Qt::AlignLeft); pSpacerLayout->addStretch(); pRow1Spacer->setLayout(pSpacerLayout); pSpacerLayout->setSpacing(0); diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp index 7518d05b..9e4eab22 100644 --- a/programs/gui_wallet/src/mining_vote_tab.cpp +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -40,7 +40,7 @@ MinerVotingTab::MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit m_pTableWidget->set_columns({ {tr("Miner"), 15, "name"}, {tr("Link to proposal"), 30, "link"}, - {tr("Votes"), -50, "votes"}, + {tr("Votes"), -150, "votes"}, {" ", 5}, }); @@ -82,48 +82,62 @@ void MinerVotingTab::timeToUpdate(const std::string& result) m_buttonsToIndex.clear(); m_pTableWidget->setRowCount(iSize); - for (size_t iIndex = 0; iIndex < iSize; ++iIndex) { - auto const &content = contents[iIndex]; - - string name = content["name"].get(); - string url = content["url"].get(); - uint64_t total_votes = content["total_votes"].get(); - bool voted = content["voted"].get(); - - QTableWidgetItem* tabItem; - tabItem = new QTableWidgetItem(QString::fromStdString(name)); - tabItem->setTextAlignment(Qt::AlignHCenter); - m_pTableWidget->setItem(iIndex, 0, tabItem); - - tabItem = new QTableWidgetItem(QString::fromStdString(url)); - tabItem->setTextAlignment(Qt::AlignHCenter); - m_pTableWidget->setItem(iIndex, 1, tabItem); - - tabItem = new QTableWidgetItem(QString::number(total_votes)); - tabItem->setTextAlignment(Qt::AlignRight); - m_pTableWidget->setItem(iIndex, 2, tabItem); - - // Vote Button - // - DecentButton* pVoteButton = new DecentButton(m_pTableWidget); - pVoteButton->setEnabled(false); - if (!voted) { - pVoteButton->setText(tr("Vote")); - pVoteButton->setStyleSheet(""); - } - else { - pVoteButton->setText(tr("Un-vote")); - pVoteButton->setStyleSheet(" QPushButton:disabled { background-color: #E6A900 } "); - } - pVoteButton->setProperty(g_vote_state_id, QVariant(voted)); - + try { - m_pTableWidget->setCellWidget(iIndex, 3, pVoteButton); - m_buttonsToIndex.insert(pVoteButton, iIndex); + for (size_t iIndex = 0; iIndex < iSize; ++iIndex) { + auto const &content = contents[iIndex]; + + string name = content["name"].get(); + string url = content["url"].get(); + uint64_t total_votes; + if (content["total_votes"].is_string() ) { + total_votes = std::stoull(content["total_votes"].get()); + } + else { + total_votes = content["total_votes"].get(); + } + bool voted = content["voted"].get(); + + QTableWidgetItem *tabItem; + tabItem = new QTableWidgetItem(QString::fromStdString(name)); + tabItem->setTextAlignment(Qt::AlignHCenter); + m_pTableWidget->setItem(iIndex, 0, tabItem); + + tabItem = new QTableWidgetItem(QString::fromStdString(url)); + tabItem->setTextAlignment(Qt::AlignHCenter); + m_pTableWidget->setItem(iIndex, 1, tabItem); + + tabItem = new QTableWidgetItem(QString::number(total_votes)); + tabItem->setTextAlignment(Qt::AlignRight); + m_pTableWidget->setItem(iIndex, 2, tabItem); + + // Vote Button + // + DecentButton* pVoteButton = new DecentButton(m_pTableWidget); + pVoteButton->setEnabled(false); + if (!voted) { + pVoteButton->setText(tr("Vote")); + pVoteButton->setStyleSheet(""); + } + else { + pVoteButton->setText(tr("Un-vote")); + pVoteButton->setStyleSheet(" QPushButton:disabled { background-color: #E6A900 } "); + } + pVoteButton->setProperty(g_vote_state_id, QVariant(voted)); + + + m_pTableWidget->setCellWidget(iIndex, 3, pVoteButton); + m_buttonsToIndex.insert(pVoteButton, iIndex); + + QObject::connect(pVoteButton, &DecentButton::clicked, this, &MinerVotingTab::slot_MinerVote); - QObject::connect(pVoteButton, &DecentButton::clicked, this, &MinerVotingTab::slot_MinerVote); + } + } + catch(const std::exception& ex) { + //TODO.. handle error } + if (contents.size() > m_i_page_size) set_next_page_iterator(contents[m_i_page_size]["id"].get()); else From 067bb0e898d48cbc9693ebacb7c5f6fa6e97a22b Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Thu, 22 Mar 2018 11:09:59 +0100 Subject: [PATCH 074/136] Revert "Merge branch 'feature/DCT-521' into develop", deferred to next release This reverts commit 2fe6b333a6f800a485165768e5c31a4b7153a9c9, reversing changes made to cf403c50703dfa77327e758ffe4c61b7d9c7473e. --- libraries/app/api.cpp | 35 --- libraries/app/application.cpp | 11 - libraries/app/include/graphene/app/api.hpp | 8 - .../app/include/graphene/app/application.hpp | 1 - libraries/app/include/graphene/app/plugin.hpp | 11 - libraries/app/plugin.cpp | 1 - .../account_history_plugin.cpp | 1 - libraries/plugins/debug_miner/debug_miner.cpp | 2 - .../delayed_node/delayed_node_plugin.cpp | 1 - libraries/plugins/messaging/messaging.cpp | 3 +- libraries/plugins/miner/miner.cpp | 2 - .../include/graphene/seeding/seeding.hpp | 32 --- libraries/plugins/seeding/seeding.cpp | 241 +----------------- .../include/graphene/wallet/general.hpp | 6 - .../include/graphene/wallet/seeding.hpp | 14 - .../wallet/include/graphene/wallet/wallet.hpp | 5 - libraries/wallet/wallet.cpp | 47 ---- 17 files changed, 13 insertions(+), 408 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 3e1c3aab..de4513f0 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include @@ -235,40 +234,6 @@ namespace graphene { namespace app { decent::seeding::seeding_promise->set_value( seeding_options ); } - std::vector network_node_api::get_running_plugins() const - { - std::vector roles; - int index = 0; - std::shared_ptr p = _app.get_plugin_by_index(index); - - while(p != nullptr) { - if(p->plugin_is_running()) - roles.push_back(p->plugin_name()); - index++; - p = _app.get_plugin_by_index(index); - } - - return roles; - } - - void network_node_api::start_content_seeding(const std::string& url) const - { - shared_ptr p = _app.get_plugin("seeding"); - FC_ASSERT(p); - bool running = p->plugin_is_running(); - FC_ASSERT(running, "Seeding plugin is not running"); - p->start_content_seeding(url); - } - - void network_node_api::stop_content_seeding(const std::string& url) const - { - shared_ptr p = _app.get_plugin("seeding"); - FC_ASSERT(p); - bool running = p->plugin_is_running(); - FC_ASSERT(running, "Seeding plugin is not running"); - p->stop_content_seeding(url); - } - fc::api login_api::network_broadcast()const { FC_ASSERT(_network_broadcast_api); diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index aa7f713f..a0ea03a1 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -1022,17 +1022,6 @@ std::shared_ptr application::get_plugin(const string& name) con return my->_plugins[name]; } -std::shared_ptr application::get_plugin_by_index(int index) const -{ - std::map>::iterator iter; - int cur_index = 0; - for (iter = my->_plugins.begin(); iter != my->_plugins.end(); ++iter, cur_index++) { - if (cur_index == index) - return (*iter).second; - } - return nullptr; -} - net::node_ptr application::p2p_node() { return my->_p2p_network; diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 744f3c30..39a766cd 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -261,11 +261,6 @@ namespace graphene { namespace app { const string packages_path, const string region_code = "" ); - std::vector get_running_plugins() const; - - void start_content_seeding(const std::string& url) const; - void stop_content_seeding(const std::string& url) const; - private: application& _app; }; @@ -489,9 +484,6 @@ FC_API(graphene::app::network_node_api, (get_advanced_node_parameters) (set_advanced_node_parameters) (seeding_startup) - (get_running_plugins) - (start_content_seeding) - (stop_content_seeding) ) FC_API(graphene::app::crypto_api, (blind_sign) diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index c30b52e7..26ae78ef 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -67,7 +67,6 @@ namespace graphene { namespace app { return plug; } std::shared_ptr get_plugin( const string& name )const; - std::shared_ptr get_plugin_by_index(int index)const; template std::shared_ptr get_plugin( const string& name ) const diff --git a/libraries/app/include/graphene/app/plugin.hpp b/libraries/app/include/graphene/app/plugin.hpp index 87461d46..87220744 100644 --- a/libraries/app/include/graphene/app/plugin.hpp +++ b/libraries/app/include/graphene/app/plugin.hpp @@ -87,15 +87,6 @@ class abstract_plugin boost::program_options::options_description& command_line_options, boost::program_options::options_description& config_file_options ) = 0; - - /** - * @brief Returns plugin state. - * - * This method retruns plugin state - * @return true if plugin_startup() was finished without exceptions. It returns - * false if plugin_shutdown() was called or if plugin_startup() throws some exception. - */ - virtual bool plugin_is_running() const = 0; }; /** @@ -120,10 +111,8 @@ class plugin : public abstract_plugin chain::database& database() { return *app().chain_database(); } application& app()const { assert(_app); return *_app; } - bool plugin_is_running()const override { return _running; } protected: net::node& p2p_node() { return *app().p2p_node(); } - bool _running = false; private: application* _app = nullptr; diff --git a/libraries/app/plugin.cpp b/libraries/app/plugin.cpp index 0c0cf3d3..8568d371 100644 --- a/libraries/app/plugin.cpp +++ b/libraries/app/plugin.cpp @@ -55,7 +55,6 @@ void plugin::plugin_startup() void plugin::plugin_shutdown() { - _running = false; return; } diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index 7ca942f1..bdd1fb23 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -192,7 +192,6 @@ void account_history_plugin::plugin_initialize(const boost::program_options::var void account_history_plugin::plugin_startup() { - _running = true; } flat_set account_history_plugin::tracked_accounts() const diff --git a/libraries/plugins/debug_miner/debug_miner.cpp b/libraries/plugins/debug_miner/debug_miner.cpp index 80374f2c..f8882889 100644 --- a/libraries/plugins/debug_miner/debug_miner.cpp +++ b/libraries/plugins/debug_miner/debug_miner.cpp @@ -101,7 +101,6 @@ void debug_miner_plugin::plugin_startup() _applied_block_conn = db.applied_block.connect([this](const graphene::chain::signed_block& b){ on_applied_block(b); }); _changed_objects_conn = db.changed_objects.connect([this](const std::vector& ids){ on_changed_objects(ids); }); _removed_objects_conn = db.removed_objects.connect([this](const std::vector& objs){ on_removed_objects(objs); }); - _running = true; return; } @@ -170,6 +169,5 @@ void debug_miner_plugin::plugin_shutdown() _json_object_stream->close(); _json_object_stream.reset(); } - _running = false; return; } diff --git a/libraries/plugins/delayed_node/delayed_node_plugin.cpp b/libraries/plugins/delayed_node/delayed_node_plugin.cpp index 7bb43edb..91edbbb8 100644 --- a/libraries/plugins/delayed_node/delayed_node_plugin.cpp +++ b/libraries/plugins/delayed_node/delayed_node_plugin.cpp @@ -145,7 +145,6 @@ void delayed_node_plugin::plugin_startup() { fc::from_variant( block_id, my->last_received_remote_head ); } ); - _running = true; return; } catch (const fc::exception& e) diff --git a/libraries/plugins/messaging/messaging.cpp b/libraries/plugins/messaging/messaging.cpp index f1bcdba2..eefb31bc 100644 --- a/libraries/plugins/messaging/messaging.cpp +++ b/libraries/plugins/messaging/messaging.cpp @@ -44,7 +44,7 @@ void messaging_plugin::plugin_startup() graphene::chain::custom_evaluator_register::instance().register_callback(graphene::chain::custom_operation_subtype_messaging, static_cast(this)); - _running = true; + ilog("messaging plugin: plugin_startup() end"); } FC_CAPTURE_AND_RETHROW() } @@ -52,7 +52,6 @@ void messaging_plugin::plugin_startup() void messaging_plugin::plugin_shutdown() { graphene::chain::custom_evaluator_register::instance().unregister_callback(graphene::chain::custom_operation_subtype_messaging); - _running = false; } void_result messaging_plugin::do_evaluate(const custom_operation& o) diff --git a/libraries/plugins/miner/miner.cpp b/libraries/plugins/miner/miner.cpp index 5238317e..050074aa 100644 --- a/libraries/plugins/miner/miner.cpp +++ b/libraries/plugins/miner/miner.cpp @@ -136,7 +136,6 @@ void miner_plugin::plugin_startup() _production_skip_flags |= graphene::chain::database::skip_undo_history_check; } schedule_production_loop(); - _running = true; } else elog("No miners configured! Please add miner IDs and private keys to configuration."); ilog("miner plugin: plugin_startup() end"); @@ -145,7 +144,6 @@ void miner_plugin::plugin_startup() void miner_plugin::plugin_shutdown() { graphene::time::shutdown_ntp_time(); - _running = false; return; } diff --git a/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp b/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp index 69b73115..8271de02 100644 --- a/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp +++ b/libraries/plugins/seeding/include/graphene/seeding/seeding.hpp @@ -76,12 +76,6 @@ class my_seeding_object : public graphene::db::abstract_object< my_seeding_objec }; }; -struct seeder_blacklist_cfg -{ - std::vector content_blacklist; -}; - - typedef graphene::chain::object_id< SEEDING_PLUGIN_SPACE_ID, seeding_object_type, my_seeding_object> my_seeding_id_type; typedef graphene::chain::object_id< SEEDING_PLUGIN_SPACE_ID, seeder_object_type, my_seeder_object> my_seeder_id_type; @@ -201,32 +195,11 @@ class seeding_plugin_impl /*: public package_transfer_interface::transfer_listen */ void send_ready_to_publish(); - /** - * Loads blacklist configuration from file - */ - void load_blacklist_cfg(seeder_blacklist_cfg& cfg); - - /** - * Saves seeder blacklist configuration to file - */ - void save_blacklist_cfg(const seeder_blacklist_cfg& cfg); - - /** - * Starts seeding of specified content - */ - void start_content_seeding(const std::string& url); - - /** - * Stops seeding of specified content - */ - void stop_content_seeding(const std::string& url); - std::vector listeners; seeding_plugin& _self; // std::map active_downloads; // service_thread; //The thread where the computation shall happen fc::thread* main_thread; //The main thread, used mainly for DB modifications - seeder_blacklist_cfg seeder_cfg; }; @@ -286,10 +259,6 @@ class seeding_plugin : public graphene::app::plugin */ void plugin_startup() override; - void start_content_seeding(const std::string& url); - - void stop_content_seeding(const std::string& url); - friend class detail::seeding_plugin_impl; std::unique_ptr my; @@ -299,6 +268,5 @@ class seeding_plugin : public graphene::app::plugin FC_REFLECT_DERIVED( decent::seeding::my_seeder_object, (graphene::db::object), (seeder)(content_privKey)(privKey)(free_space)(region_code)(price)(symbol) ); FC_REFLECT_DERIVED( decent::seeding::my_seeding_object, (graphene::db::object), (URI)(expiration)(cd)(seeder)(key)(space)(downloaded)(deleted)(_hash) ); -FC_REFLECT(decent::seeding::seeder_blacklist_cfg, (content_blacklist)); diff --git a/libraries/plugins/seeding/seeding.cpp b/libraries/plugins/seeding/seeding.cpp index 5ee64ba1..c67467b4 100644 --- a/libraries/plugins/seeding/seeding.cpp +++ b/libraries/plugins/seeding/seeding.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -499,11 +500,6 @@ void seeding_plugin_impl::restore_state(){ content_itr--; if( content_itr->expiration < database().head_block_time() ) break; - - auto url_iter = std::find(seeder_cfg.content_blacklist.begin(), seeder_cfg.content_blacklist.end(), content_itr->URI); - if (url_iter != seeder_cfg.content_blacklist.end()) - break; - auto search_itr = content_itr->key_parts.find( sitr->seeder ); if( search_itr != content_itr->key_parts.end() ) { @@ -558,14 +554,12 @@ void seeding_plugin_impl::restore_state(){ database().modify(*citr, [](my_seeding_object& so){so.downloaded = true;}); }else{ - if (std::find(seeder_cfg.content_blacklist.begin(), seeder_cfg.content_blacklist.end(), citr->URI) == seeder_cfg.content_blacklist.end()) { - elog("restarting downloads, re-downloading package ${u}", ("u", citr->URI)); - package_handle = pm.get_package(citr->URI, citr->_hash); - decent::package::event_listener_handle_t sl = std::make_shared(*this, *citr, package_handle); - package_handle->remove_all_event_listeners(); - package_handle->add_event_listener(sl); - package_handle->download(false); - } + elog("restarting downloads, re-downloading package ${u}", ("u", citr->URI)); + package_handle = pm.get_package(citr->URI, citr->_hash); + decent::package::event_listener_handle_t sl = std::make_shared(*this, *citr , package_handle); + package_handle->remove_all_event_listeners(); + package_handle->add_event_listener(sl); + package_handle->download(false); } ++citr; } @@ -573,202 +567,6 @@ void seeding_plugin_impl::restore_state(){ generate_pors(); }); } - -void seeding_plugin_impl::start_content_seeding(const std::string& url) -{ - try { - graphene::chain::database &db = database(); - - elog("start_content_seeding, main thread"); - service_thread->async([this, url]() { - if (std::abs((fc::time_point::now() - database().head_block_time()).count()) > int64_t(10000000)) - { - ilog("seeding plugin: start_content_seeding, waiting for sync"); - fc::usleep(fc::microseconds(1000000)); - } - elog("starting download of stopped content seeding, service thread"); - //start with rebuilding my_seeding_object database - const auto& sidx = database().get_index_type().indices().get(); - const auto& cidx = database().get_index_type().indices().get(); - - - const auto& c_idx = database().get_index_type().indices().get(); - auto sitr = sidx.begin(); - while (sitr != sidx.end()) - { - auto content_itr = c_idx.end(); - while (content_itr != c_idx.begin()) - // iterating backwards. - // Content objects are ordered increasingly by expiration time. - // This way we do not need to iterate over all ( expired ) objects - { - content_itr--; - if (content_itr->URI != url) - continue; - if (content_itr->expiration < database().head_block_time()) - break; - auto search_itr = content_itr->key_parts.find(sitr->seeder); - if (search_itr != content_itr->key_parts.end()) - { - - auto citr = cidx.find(content_itr->URI); - if (citr == cidx.end()) - { - const my_seeding_object& mso = database().create([&](my_seeding_object &so) { - so.URI = content_itr->URI; - so.seeder = sitr->seeder; - so._hash = content_itr->_hash; - so.space = content_itr->size; //we allocate the whole megabytes per content - so.key = search_itr->second; - so.expiration = content_itr->expiration; - so.cd = content_itr->cd; - }); - ilog("seeding_plugin: restore_state() creating seeding object for ${s}", ("s", mso)); - database().modify(*sitr, [&](my_seeder_object &mso) { - mso.free_space -= content_itr->size; //we allocate the whole megabytes per content - }); - sitr = sidx.end(); - break; - } - else { - ilog("seeding_plugin: content is already seeded"); - } - } - } - sitr++; - } - - //We need to rebuild the list of downloaded packages and compare it to the list of my_seeding_objects. - //For the downloaded packages we can issue PoR right away, the others needs to be downloaded - auto& pm = decent::package::PackageManager::instance(); - pm.recover_all_packages(); - auto packages = pm.get_all_known_packages(); - for (decent::package::package_handle_t package : packages) { - package->check(true); - if (package->get_data_state() != decent::package::PackageInfo::CHECKED) - pm.release_package(package); - } - - packages = pm.get_all_known_packages(); - - auto citr = cidx.begin(); - while (citr != cidx.end()) { - elog("restarting downloads, dealing with package ${u}", ("u", citr->URI)); - bool already_have = false; - decent::package::package_handle_t package_handle(0); - for (auto package : packages) - if (package->get_hash() == citr->_hash) { - already_have = true; - package_handle = package; - } - - if (already_have) { - database().modify(*citr, [](my_seeding_object& so) {so.downloaded = true; }); - - } - else { - elog("restarting downloads, re-downloading package ${u}", ("u", citr->URI)); - package_handle = pm.get_package(citr->URI, citr->_hash); - decent::package::event_listener_handle_t sl = std::make_shared(*this, *citr, package_handle); - package_handle->remove_all_event_listeners(); - package_handle->add_event_listener(sl); - package_handle->download(false); - } - ++citr; - } - elog("restarting downloads, service thread end"); - generate_pors(); - // remove from blacklist - auto url_iter = std::find(seeder_cfg.content_blacklist.begin(), seeder_cfg.content_blacklist.end(), url); - if (url_iter != seeder_cfg.content_blacklist.end()) - seeder_cfg.content_blacklist.erase(url_iter); - // save blacklist - save_blacklist_cfg(seeder_cfg); - }); - } FC_CAPTURE_AND_RETHROW() -} - -void seeding_plugin_impl::stop_content_seeding(const std::string& url) -{ - try { - graphene::chain::database &db = database(); - const auto &sidx = db.get_index_type().indices().get(); - const auto &seeding_idx = db.get_index_type().indices().get(); - ilog("seeding plugin_impl: stop_content_seeding() start"); - auto& pm = decent::package::PackageManager::instance(); - - for (const auto& mso : seeding_idx) { - - if (!mso.downloaded || mso.deleted) - continue; - - if (mso.URI != url) - continue; - - auto package_handle = pm.get_package(mso.URI, mso._hash); - package_handle->remove_all_event_listeners(); - - const auto &sritr = sidx.find(mso.seeder); - FC_ASSERT(sritr != sidx.end()); - const auto &content = mso.get_content(db); - - ilog("seeding plugin_impl: stop_content_seeding() content ${c} expired, clenaing up", ("c", mso.URI)); - - - const auto &idx = db.get_index_type().indices().get(); - auto seeder_itr = idx.begin(); - FC_ASSERT(seeder_itr != idx.end()); - db.modify(*seeder_itr, [&](my_seeder_object &seeder_object) { - seeder_object.free_space += mso.space; - }); - - std::string hash = package_handle->get_hash().str(); - release_package(mso, package_handle); - db.remove(mso); - - // store to blacklist - auto found_iter = std::find(seeder_cfg.content_blacklist.begin(), seeder_cfg.content_blacklist.end(), url); - if(found_iter == seeder_cfg.content_blacklist.end()) - seeder_cfg.content_blacklist.push_back(url); - // save blacklist - save_blacklist_cfg(seeder_cfg); - ilog("seeding plugin_impl: stop_content_seeding() content cleaned, continue"); - break; - } - ilog("seeding plugin_impl: stop_content_seeding() end"); - }FC_CAPTURE_AND_RETHROW() -} - -void seeding_plugin_impl::load_blacklist_cfg(seeder_blacklist_cfg& cfg) -{ - fc::path seeder_blacklist_path = graphene::utilities::decent_path_finder::instance().get_decent_home(); - seeder_blacklist_path = seeder_blacklist_path / "seeder"; - if (!fc::exists(seeder_blacklist_path)) - fc::create_directories(seeder_blacklist_path); - - seeder_blacklist_path = seeder_blacklist_path / "blacklist.json"; - std::string string_path = seeder_blacklist_path.string(); - try { - if (fc::exists(seeder_blacklist_path)) { - variant tmp = fc::json::from_file(seeder_blacklist_path); - cfg = tmp.as(); - } - } FC_CAPTURE_AND_LOG((string_path)); -} - -void seeding_plugin_impl::save_blacklist_cfg(const seeder_blacklist_cfg& cfg) -{ - fc::path seeder_blacklist_path = graphene::utilities::decent_path_finder::instance().get_decent_home(); - seeder_blacklist_path = seeder_blacklist_path / "seeder"; - if (!fc::exists(seeder_blacklist_path)) - fc::create_directories(seeder_blacklist_path); - - seeder_blacklist_path = seeder_blacklist_path / "blacklist.json"; - fc::variant tmp; - fc::to_variant(cfg, tmp); - fc::json::save_to_file(tmp, seeder_blacklist_path); -} - }// end namespace detail @@ -780,11 +578,12 @@ void seeding_plugin::plugin_startup() return; ilog("seeding plugin: plugin_startup() start"); + + my->restore_state(); fc::time_point next_call = fc::time_point::now() + fc::microseconds(30000000); elog("RtP planned at ${t}", ("t",next_call) ); my->service_thread->schedule([this](){elog("generating first ready to publish");my->send_ready_to_publish(); }, next_call, "Seeding plugin RtP generate"); - _running = true; ilog("seeding plugin: plugin_startup() end"); } @@ -886,10 +685,6 @@ void seeding_plugin::plugin_pre_startup( const seeding_plugin_startup_options& s ilog("starting service thread"); my = unique_ptr( new detail::seeding_plugin_impl( *this) ); - - // load blacklist - my->load_blacklist_cfg(my->seeder_cfg); - my->service_thread = std::make_shared("seeding"); my->main_thread = &fc::thread::current(); @@ -924,16 +719,6 @@ std::string seeding_plugin::plugin_name()const return "seeding"; } -void seeding_plugin::start_content_seeding(const std::string& url) -{ - my->start_content_seeding(url); -} - -void seeding_plugin::stop_content_seeding(const std::string& url) -{ - my->stop_content_seeding(url); -} - void seeding_plugin::plugin_set_program_options( boost::program_options::options_description& cli, boost::program_options::options_description& cfg) @@ -971,14 +756,12 @@ void detail::SeedingListener::package_download_complete() { const auto& mso = *mso_itr; decent::package::package_handle_t pi = _pi; - if (pi == nullptr) { - int a = 0; - } + size_t size = (_pi->get_size() + 1024 * 1024 - 1) / (1024 * 1024); if( size > mso_itr->space ) { ilog("seeding plugin: package_download_complete(): Fraud detected: real content size is greater than propagated in blockchain; deleting..."); //changing DB outside the main thread does not work properly, let's delete it from there - _my->main_thread->async([ this, &mso, pi ]() { _my->release_package(mso, pi); }); + _my->main_thread->async([ & ]() { _my->release_package(mso, pi); }); _pi.reset(); return; } @@ -986,7 +769,7 @@ void detail::SeedingListener::package_download_complete() { //Don't block package manager thread for too long. seeding_plugin_impl *my = _my; _my->database().modify(mso, [](my_seeding_object& so){so.downloaded = true;}); - _my->service_thread->async([ this, &mso, pi ]() { _my->generate_por_int(mso, pi); }); + _my->service_thread->async([ & ]() { _my->generate_por_int(mso, pi); }); }; diff --git a/libraries/wallet/include/graphene/wallet/general.hpp b/libraries/wallet/include/graphene/wallet/general.hpp index 02a79ff2..5e354424 100644 --- a/libraries/wallet/include/graphene/wallet/general.hpp +++ b/libraries/wallet/include/graphene/wallet/general.hpp @@ -141,11 +141,5 @@ void network_add_nodes( const vector& nodes ); */ vector< variant > network_get_connected_peers(); -/** -* @brief Returns list of running plugins -* @return vector of running plugins -*/ -std::vector get_running_plugins() const; - #endif //DECENT_WALLET_GENERAL_H diff --git a/libraries/wallet/include/graphene/wallet/seeding.hpp b/libraries/wallet/include/graphene/wallet/seeding.hpp index 2be175e7..66063b9a 100644 --- a/libraries/wallet/include/graphene/wallet/seeding.hpp +++ b/libraries/wallet/include/graphene/wallet/seeding.hpp @@ -58,18 +58,4 @@ vector list_seeders_by_region( const string& region_code )const; */ vector list_seeders_by_rating( const uint32_t count )const; -/** -* @brief Starts locally seeding of content by URL previously stopped by stop_content_seeding -* @param url of content -* @return vector of message objects -*/ -void start_content_seeding(const std::string& url) const; - -/** -* @brief Stops locally seeding of content by URL -* @param url of content -* @return vector of message objects -*/ -void stop_content_seeding(const std::string& url) const; - #endif //DECENT_WALLET_SEEDING_H diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 62322c46..85a816da 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -375,7 +375,6 @@ FC_API( graphene::wallet::wallet_api, (head_block_time) (network_add_nodes) (network_get_connected_peers) - (get_running_plugins) //Wallet file (list_my_accounts) @@ -453,8 +452,6 @@ FC_API( graphene::wallet::wallet_api, (list_seeders_by_upload) (list_seeders_by_region) (list_seeders_by_rating) - (start_content_seeding) - (stop_content_seeding) //Proposals (get_proposed_transactions) @@ -521,6 +518,4 @@ FC_API( graphene::wallet::wallet_api, //Network (flood_network) #endif - ) - diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 61a7068b..84ed649a 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2782,39 +2782,6 @@ signed_transaction content_cancellation(const string& author, } FC_CAPTURE_AND_RETHROW((from)(to)(text)) } - std::vector get_running_plugins() - { - try { - FC_ASSERT(!is_locked()); - - use_network_node_api(); - return (*_remote_net_node)->get_running_plugins(); - - } FC_CAPTURE_AND_RETHROW() - } - - void start_content_seeding(const std::string& url) - { - try { - FC_ASSERT(!is_locked()); - - use_network_node_api(); - (*_remote_net_node)->start_content_seeding(url); - - } FC_CAPTURE_AND_RETHROW((url)) - } - - void stop_content_seeding(const std::string& url) - { - try { - FC_ASSERT(!is_locked()); - - use_network_node_api(); - (*_remote_net_node)->stop_content_seeding(url); - - } FC_CAPTURE_AND_RETHROW((url)) - } - void dbg_make_mia(const std::string& creator, const std::string& symbol) { create_monitored_asset(get_account(creator).name, symbol, 2, "abcd", 3600, 1, true); @@ -3467,20 +3434,6 @@ signed_transaction content_cancellation(const string& author, _wallet.sign_transaction(tx, true); } - std::vector wallet_api::get_running_plugins() const - { - return my->get_running_plugins(); - } - - void wallet_api::stop_content_seeding(const std::string& url) const - { - my->stop_content_seeding(url); - } - - void wallet_api::start_content_seeding(const std::string& url) const - { - my->start_content_seeding(url); - } } } // graphene::wallet From 7531e4459741b13d91d4fdf21484472afd370bec Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 22 Mar 2018 17:19:31 +0100 Subject: [PATCH 075/136] GUI wallet improvements --- programs/gui_wallet/src/gui_wallet_global.cpp | 63 +++++++-- programs/gui_wallet/src/gui_wallet_global.hpp | 12 +- programs/gui_wallet/src/mainwindow.cpp | 48 +++++-- programs/gui_wallet/src/mainwindow.hpp | 8 ++ programs/gui_wallet/src/richdialog.cpp | 130 ++++++++++++------ programs/gui_wallet/src/richdialog.hpp | 10 +- programs/gui_wallet/src/upload_popup.cpp | 23 +++- 7 files changed, 218 insertions(+), 76 deletions(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index 4ee5d980..1a7eb6af 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -241,8 +241,6 @@ QString CalculateRemainingTime_Behind(QDateTime const& dt, QDateTime const& dtFu if (arrParts.size() > 1) str_result += " " + QObject::tr("and") + " " + arrParts[1]; - - str_result += " " + QObject::tr("to go"); } return str_result; @@ -588,9 +586,6 @@ Globals::Globals() : QObject() , m_tp_started(std::chrono::steady_clock::now()) { - m_p_timer->start(1000); - QObject::connect(m_p_timer, &QTimer::timeout, this, &Globals::slot_timer); - QLocale::setDefault(*m_p_locale); // *m_p_locale = ((QApplication*)QApplication::instance())->inputMethod()->locale(); @@ -635,6 +630,8 @@ void Globals::startDaemons(BlockChainStartType type) m_p_wallet_operator_thread->start(); } + QObject::connect(this, &Globals::walletConnectionStatusChanged, this, &Globals::slot_ConnectionStatusChange); + fc::thread& thread_decentd = m_p_daemon_details->thread_decentd; fc::promise::ptr& exit_promise = m_p_daemon_details->exit_promise; @@ -663,10 +660,12 @@ void Globals::startDaemons(BlockChainStartType type) #endif +#if 0 m_p_daemon_details->future_decentd = thread_decentd.async([type, &exit_promise]() -> int { return ::runDecentD(type, exit_promise); }); +#endif m_tp_started = std::chrono::steady_clock::now(); @@ -691,10 +690,12 @@ void Globals::stopDaemons() m_p_wallet_operator = nullptr; } +#if 0 fc::promise::ptr& exit_promise = m_p_daemon_details->exit_promise; exit_promise->set_value(); m_p_daemon_details->future_decentd.wait(); +#endif if (m_p_daemon_details->ipfs_process) { m_p_daemon_details->ipfs_process->terminate(); @@ -808,6 +809,18 @@ bool Globals::connected() const return m_connected_state != ConnectionState::Connecting; } +QString Globals::getAssetName() const +{ + uint8_t precision = 0; + std::string assetName; + + graphene::chain::asset_id_type asset_id; + fc::from_variant("1.3.0", asset_id ); + getWallet().LoadAssetInfo(assetName, precision, asset_id); + + return QString::fromStdString(assetName); +} + void Globals::setWalletUnlocked() { emit walletUnlocked(); @@ -888,12 +901,30 @@ void Globals::slot_showTransferDialog() void Globals::slot_connected(std::string const& str_error) { m_connected_state = ConnectionState::SyncingUp; - if (str_error.empty()) + if (str_error.empty()) { emit walletConnectionStatusChanged(ConnectionState::Connecting, ConnectionState::SyncingUp); + + m_blockStart = getWallet().HeadBlockTime(); + } else emit walletConnectionError(str_error); } +void Globals::slot_ConnectionStatusChange(ConnectionState from, ConnectionState to) +{ + if (ConnectionState::Connecting == from) { + + m_p_timer->start(1000); + QObject::connect(m_p_timer, &QTimer::timeout, this, &Globals::slot_timer); + } + else if (ConnectionState::SyncingUp == from && ConnectionState::Up == to) { + m_p_timer->stop(); + } + + + +} + void Globals::slot_timer() { auto duration = std::chrono::steady_clock::now() - m_tp_started; @@ -903,25 +934,31 @@ void Globals::slot_timer() if (ConnectionState::Connecting == m_connected_state) { if (duration > std::chrono::seconds(40)) - emit connectingProgress(tr("still connecting").toStdString()); + emit connectingProgress(tr("still connecting")); else if (duration > std::chrono::seconds(20)) - emit connectingProgress(tr("verifying the local database").toStdString()); + emit connectingProgress(tr("verifying the local database")); else - emit connectingProgress(tr("connecting").toStdString()); + emit connectingProgress(tr("connecting")); } else { + auto currBlockTime = Globals::instance().getWallet().HeadBlockTime(); + uint64_t value = std::chrono::duration_cast(currBlockTime - m_blockStart).count(); + uint64_t maxValue = std::chrono::duration_cast(std::chrono::system_clock::now() - m_blockStart).count(); + + emit updateProgress(value, maxValue); + QDateTime qdt; - qdt.setTime_t(std::chrono::system_clock::to_time_t(Globals::instance().getWallet().HeadBlockTime())); + qdt.setTime_t(std::chrono::system_clock::to_time_t(currBlockTime)); CalendarDuration duration = CalculateCalendarDuration(qdt, QDateTime::currentDateTime()); if (duration.sign == CalendarDuration::sign_negative) duration = CalendarDuration(); QString str_result = CalculateRemainingTime_Behind(qdt, QDateTime::currentDateTime()); - std::string result = str_result.toStdString(); - if (!result.empty()) - emit statusShowMessage(result.c_str(), 5000); + if (!str_result.isEmpty()) { + emit statusShowMessage(str_result, 5000); + } bool justbehind = false, farbehind = false; if (duration.years == 0 && diff --git a/programs/gui_wallet/src/gui_wallet_global.hpp b/programs/gui_wallet/src/gui_wallet_global.hpp index 463024f3..0af7736a 100644 --- a/programs/gui_wallet/src/gui_wallet_global.hpp +++ b/programs/gui_wallet/src/gui_wallet_global.hpp @@ -163,6 +163,7 @@ namespace gui_wallet std::vector getPublishers(); QLocale& locale() { return *m_p_locale; } bool connected() const; + QString getAssetName() const; public slots: void slot_updateAccountBalance(); @@ -187,11 +188,13 @@ namespace gui_wallet private slots: void slot_connected(std::string const& str_error); void slot_timer(); + void slot_ConnectionStatusChange(ConnectionState from, ConnectionState to); signals: - void connectingProgress(std::string const& str_progress); - void currentUserChanged(QString const& user); - void statusShowMessage(QString const& str_message, int timeout = 0); + void connectingProgress(const QString& str_progress); + void currentUserChanged(const QString& user); + void statusShowMessage(const QString& str_message, int timeout = 0); + void updateProgress(int value, int maxVal); void statusClearMessage(); void walletUnlocked(); @@ -207,6 +210,9 @@ namespace gui_wallet class DaemonDetails* m_p_daemon_details; std::string m_str_currentUser; std::chrono::steady_clock::time_point m_tp_started; + std::chrono::system_clock::time_point m_blockStart; + + std::map m_map_user_id_cache; }; diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 839eb7ec..14462414 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -100,6 +100,7 @@ MainWindow::MainWindow() DecentLabel* pRow1Spacer = new DecentLabel(pMainWidget, DecentLabel::Row1Spacer); m_pAccountList = new QComboBox(pMainWidget); m_pAccountList->setStyle(QStyleFactory::create("fusion")); + m_pAccountList->setMinimumContentsLength(70); m_pBalance = new DecentLabel(pMainWidget, DecentLabel::Balance); DecentButton* pTransferButton = new DecentButton(pMainWidget, DecentButton::Send); pTransferButton->setToolTip("Transfer DCT to account"); @@ -390,24 +391,33 @@ void MainWindow::slot_setSplash() m_iSplashWidgetIndex = m_pStackedWidget->count(); StackLayerWidget* pSplashScreen = new StackLayerWidget(this); - QProgressBar* pConnectingProgress = new QProgressBar(pSplashScreen); - pConnectingProgress->setValue(70); - DecentLabel* pConnectingLabel = new DecentLabel(pSplashScreen, DecentLabel::SplashInfo); - pConnectingLabel->setText(tr("Please wait, we are syncing with network…")); + m_pConnectingProgress = new QProgressBar(pSplashScreen); + m_pConnectingProgress->setFont(gui_wallet::ProgressInfoFont()); + m_pConnectingProgress->setFormat("%d%%"); + + DecentLabel* pPleaseWaitLabel = new DecentLabel(pSplashScreen, DecentLabel::SplashInfo); + pPleaseWaitLabel->setFont(gui_wallet::ProgressInfoFont()); + pPleaseWaitLabel->setText(tr("Please wait...")); + + //pConnectingProgress->setValue(70); + m_pConnectingLabel = new DecentLabel(pSplashScreen, DecentLabel::SplashInfo); + //pConnectingLabel->setText(QString(tr("Please wait, currently synchronized block is %1 old.")).arg("")); + m_pConnectingLabel->setFont(gui_wallet::ProgressInfoFont()); + StatusLabel* pSyncUpLabel = new StatusLabel(pSplashScreen, DecentLabel::SplashInfo); DecentButton* pButton = new DecentButton(this, DecentButton::SplashAction); - pConnectingLabel->setFont(gui_wallet::ProgressInfoFont()); pSyncUpLabel->setFont(gui_wallet::ProgressInfoFont()); pButton->hide(); pButton->setText(tr("Proceed")); QGridLayout* pLayoutSplash = new QGridLayout; - pLayoutSplash->addWidget(pConnectingProgress, 0, 0, Qt::AlignVCenter | Qt::AlignCenter); - pLayoutSplash->addWidget(pConnectingLabel, 1, 0, Qt::AlignVCenter | Qt::AlignCenter); - pLayoutSplash->addWidget(pSyncUpLabel, 2, 0, Qt::AlignVCenter | Qt::AlignCenter); - pLayoutSplash->addWidget(pButton, 3, 0, Qt::AlignVCenter | Qt::AlignCenter); + pLayoutSplash->addWidget(m_pConnectingProgress, 0, 0, Qt::AlignVCenter | Qt::AlignCenter); + pLayoutSplash->addWidget(pPleaseWaitLabel, 1, 0, Qt::AlignVCenter | Qt::AlignCenter); + pLayoutSplash->addWidget(m_pConnectingLabel, 2, 0, Qt::AlignVCenter | Qt::AlignCenter); + pLayoutSplash->addWidget(pSyncUpLabel, 3, 0, Qt::AlignVCenter | Qt::AlignCenter); + pLayoutSplash->addWidget(pButton, 4, 0, Qt::AlignVCenter | Qt::AlignCenter); pLayoutSplash->setSizeConstraint(QLayout::SetFixedSize); pLayoutSplash->setSpacing(10); @@ -416,12 +426,14 @@ void MainWindow::slot_setSplash() pSplashScreen->setLayout(pLayoutSplash); QObject::connect(&Globals::instance(), &Globals::statusShowMessage, - pSyncUpLabel, &StatusLabel::showMessage); + this, &MainWindow::slot_ConnectingUpdate); QObject::connect(&Globals::instance(), &Globals::statusClearMessage, pSyncUpLabel, &StatusLabel::clearMessage); + QObject::connect(&Globals::instance(), &Globals::updateProgress, + this, &MainWindow::slot_BlockchainUpdate); - QObject::connect(this, &MainWindow::signal_setSplashMainText, - pConnectingLabel, &QLabel::setText); +// QObject::connect(this, &MainWindow::signal_setSplashMainText, +// pConnectingLabel, &QLabel::setText); QObject::connect(this, &MainWindow::signal_setSplashMainText, pButton, &QWidget::show); @@ -531,6 +543,18 @@ void MainWindow::slot_connectionStatusChanged(Globals::ConnectionState from, Glo } } +void MainWindow::slot_ConnectingUpdate(const QString& time_text, int) +{ + Q_ASSERT(m_pConnectingLabel); + m_pConnectingLabel->setText(QString(tr("currently synchronized block is %1 old.")).arg(time_text)); +} + +void MainWindow::slot_BlockchainUpdate(int value, int max) +{ + m_pConnectingProgress->setMaximum(max); + m_pConnectingProgress->setValue(value); +} + void MainWindow::slot_showPurchasedTab() { m_pButtonPurchased->setChecked(true); diff --git a/programs/gui_wallet/src/mainwindow.hpp b/programs/gui_wallet/src/mainwindow.hpp index 500890d3..5babd72d 100644 --- a/programs/gui_wallet/src/mainwindow.hpp +++ b/programs/gui_wallet/src/mainwindow.hpp @@ -9,6 +9,7 @@ class QStackedWidget; class QComboBox; class QTimer; class QAction; +class QProgressBar; class UpdateManager; namespace gui_wallet @@ -19,6 +20,7 @@ class DecentLineEdit; class DecentButton; class TabContentManager; + class MainWindow : public QMainWindow { Q_OBJECT @@ -48,6 +50,8 @@ protected slots: void slot_PublishToggled(bool toggled); void slot_UsersToggled(bool toggled); void slot_PurchasedToggled(bool toggled); + void slot_ConnectingUpdate(const QString& time_text, int); + void slot_BlockchainUpdate(int value, int max); void DisplayWalletContentGUI(); @@ -99,6 +103,10 @@ protected slots: UpdateManager* m_pUpdateManager; std::set m_activeDownloads; + + QProgressBar* m_pConnectingProgress; + DecentLabel* m_pConnectingLabel; + }; } diff --git a/programs/gui_wallet/src/richdialog.cpp b/programs/gui_wallet/src/richdialog.cpp index de133861..d91641e1 100644 --- a/programs/gui_wallet/src/richdialog.cpp +++ b/programs/gui_wallet/src/richdialog.cpp @@ -135,18 +135,21 @@ TransferWidget::TransferWidget(QWidget* parent, QString const& userName) : Stack this, &TransferWidget::Transfer); QObject::connect(cancel, &QPushButton::clicked, this, &StackLayerWidget::closed); - + + QLabel* pLabel = new QLabel(this); + pLabel->setText(tr("Transfer of funds")); + DecentLineEdit* name = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); DecentLineEdit* amount = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); DecentLineEdit* memo = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); - name->setPlaceholderText(tr("Account")); + name->setPlaceholderText(tr("Reciever account name")); name->setAttribute(Qt::WA_MacShowFocusRect, 0); name->setText(m_toUserName); QObject::connect(name, &QLineEdit::textChanged, this, &TransferWidget::nameChanged); - amount->setPlaceholderText(tr("Amount")); + amount->setPlaceholderText(QString(tr("Amount of %1")).arg(Globals::instance().getAssetName()) ); amount->setAttribute(Qt::WA_MacShowFocusRect, 0); QDoubleValidator* dblValidator = new QDoubleValidator(0.0001, 100000, 4, this); @@ -155,11 +158,12 @@ TransferWidget::TransferWidget(QWidget* parent, QString const& userName) : Stack QObject::connect(amount, &QLineEdit::textChanged, this, &TransferWidget::amountChanged); - memo->setPlaceholderText(tr("Memo")); + memo->setPlaceholderText(tr("Memo (optional)")); memo->setAttribute(Qt::WA_MacShowFocusRect, 0); QObject::connect(memo, &QLineEdit::textChanged, this, &TransferWidget::memoChanged); - + + lineEditsLayout->addWidget(pLabel); lineEditsLayout->addWidget(name); lineEditsLayout->addWidget(amount); lineEditsLayout->addWidget(memo); @@ -174,6 +178,8 @@ TransferWidget::TransferWidget(QWidget* parent, QString const& userName) : Stack setLayout(mainLayout); + name->setFocus(); + #ifdef _MSC_VER int height = style()->pixelMetric(QStyle::PM_TitleBarHeight); setWindowIcon(height > 32 ? QIcon(":/icon/images/windows_decent_icon_32x32.png") @@ -236,7 +242,11 @@ ImportKeyWidget::ImportKeyWidget(QWidget* parent) : StackLayerWidget(parent) { QObject::connect(this, &StackLayerWidget::accepted, &Globals::instance(), &Globals::signal_keyImported); - + + DecentLabel* pLabel = new DecentLabel(this); + pLabel->setFont(gui_wallet::MainFont()); + pLabel->setText(tr("Import account")); + QVBoxLayout* mainLayout = new QVBoxLayout(); QVBoxLayout* lineEditsLayout = new QVBoxLayout(); QHBoxLayout* buttonsLayout = new QHBoxLayout(); @@ -244,7 +254,7 @@ ImportKeyWidget::ImportKeyWidget(QWidget* parent) : StackLayerWidget(parent) DecentButton* ok = new DecentButton(this, DecentButton::DialogAction); ok->setText(tr("Ok")); DecentButton* cancel = new DecentButton(this, DecentButton::DialogCancel); - cancel->setText(tr("Back")); + cancel->setText(tr("Cancel")); QObject::connect(ok, &QPushButton::clicked, this, &ImportKeyWidget::Import); @@ -254,16 +264,17 @@ ImportKeyWidget::ImportKeyWidget(QWidget* parent) : StackLayerWidget(parent) DecentLineEdit* name = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); DecentLineEdit* key = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); - name->setPlaceholderText(tr("Account")); + name->setPlaceholderText(tr("Account name")); name->setAttribute(Qt::WA_MacShowFocusRect, 0); QObject::connect(name, &QLineEdit::textChanged, this, &ImportKeyWidget::nameChanged); - key->setPlaceholderText(tr("Key")); + key->setPlaceholderText(tr("Private Key")); key->setAttribute(Qt::WA_MacShowFocusRect, 0); QObject::connect(key, &QLineEdit::textChanged, this, &ImportKeyWidget::keyChanged); + lineEditsLayout->addWidget(pLabel); lineEditsLayout->addWidget(name); lineEditsLayout->addWidget(key); @@ -914,73 +925,110 @@ bool CommentWidget::slot_Previous() } // PasswordWidget // + +const int g_maxPasswordLen = 50; + PasswordWidget::PasswordWidget(QWidget* pParent, eType enType) : StackLayerWidget(pParent) , m_enType(enType) , m_pError(new QLabel(this)) { - QLabel* pLabel = new QLabel(this); - pLabel->setText(tr("The password must be limited to 50 characters")); - DecentButton* pButton = new DecentButton(this, DecentButton::DialogAction); - m_pError->hide(); - if (enType == eSetPassword) - pButton->setText(tr("Set Password")); - else - pButton->setText(tr("Unlock")); + QLabel* pLabel = new QLabel(this); + m_pButton = new DecentButton(this, DecentButton::DialogAction); - DecentLineEdit* pEditPassword = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); - pEditPassword->setEchoMode(QLineEdit::Password); - pEditPassword->setAttribute(Qt::WA_MacShowFocusRect, 0); - pEditPassword->setPlaceholderText(QString(tr("Password"))); - pEditPassword->setMaxLength(50); + if (enType == eSetPassword) { + pLabel->setText(tr("Setup your password for DECENT wallet")); + m_pButton->setText(tr("Set Password")); + } + else { + pLabel->setText(tr("Unlock your DECENT wallet")); + m_pButton->setText(tr("Unlock")); + } - if (enType == eSetPassword) - setWindowTitle(tr("Set Password")); - else - { - pLabel->hide(); - setWindowTitle(tr("Unlock your wallet")); + m_line1Edit = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); + m_line1Edit->setEchoMode(QLineEdit::Password); + m_line1Edit->setAttribute(Qt::WA_MacShowFocusRect, 0); + if (enType == eSetPassword) { + m_line1Edit->setPlaceholderText(QString(tr("New password"))); } + else { + m_line1Edit->setPlaceholderText(QString(tr("Password"))); + } + m_line1Edit->setMaxLength(g_maxPasswordLen); + m_line1Edit->setToolTip(tr("The password must be limited to 50 characters")); + + m_line2Edit = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); + m_line2Edit->setEchoMode(QLineEdit::Password); + m_line2Edit->setAttribute(Qt::WA_MacShowFocusRect, 0); + m_line2Edit->setPlaceholderText(QString(tr("Reenter password"))); + m_line2Edit->setMaxLength(g_maxPasswordLen); + m_line2Edit->setToolTip(tr("The password must be limited to 50 characters")); int iRowIndex = 0; QGridLayout* pMainLayout = new QGridLayout; pMainLayout->addWidget(pLabel, iRowIndex++, 0, Qt::AlignCenter | Qt::AlignVCenter); pMainLayout->addWidget(m_pError, iRowIndex++, 0, Qt::AlignCenter | Qt::AlignVCenter); - pMainLayout->addWidget(pEditPassword, iRowIndex++, 0, Qt::AlignCenter | Qt::AlignVCenter); - pMainLayout->addWidget(pButton, iRowIndex++, 0, Qt::AlignCenter | Qt::AlignVCenter); + pMainLayout->addWidget(m_line1Edit, iRowIndex++, 0, Qt::AlignCenter | Qt::AlignVCenter); + if (enType == eSetPassword) { + pMainLayout->addWidget(m_line2Edit, iRowIndex++, 0, Qt::AlignCenter | Qt::AlignVCenter); + m_pButton->setEnabled(false); + } + else { + m_line2Edit->hide(); + } + pMainLayout->addWidget(m_pButton, iRowIndex++, 0, Qt::AlignCenter | Qt::AlignVCenter); pMainLayout->setSizeConstraint(QLayout::SetFixedSize); pMainLayout->setSpacing(20); pMainLayout->setContentsMargins(20, 20, 20, 20); - QObject::connect(pEditPassword, &QLineEdit::returnPressed, + QObject::connect(m_pButton, &QPushButton::clicked, this, &PasswordWidget::slot_action); - QObject::connect(pButton, &QPushButton::clicked, - this, &PasswordWidget::slot_action); - QObject::connect(pEditPassword, &QLineEdit::textChanged, - this, &PasswordWidget::slot_set_password); + if (enType == eUnlock) { + QObject::connect(m_line1Edit, &QLineEdit::returnPressed, + this, &PasswordWidget::slot_action); + } + QObject::connect(m_line1Edit, &QLineEdit::textChanged, + this, &PasswordWidget::slot_textChanged); + QObject::connect(m_line2Edit, &QLineEdit::textChanged, + this, &PasswordWidget::slot_textChanged); setLayout(pMainLayout); } -void PasswordWidget::slot_set_password(const QString& strPassword) +void PasswordWidget::slot_textChanged(const QString& ) { - m_strPassword = strPassword; + if (m_enType == eSetPassword) { + bool enabled = (!m_line1Edit->text().isEmpty() && !m_line2Edit->text().isEmpty()); + m_pButton->setEnabled(enabled); + } + else { + bool enabled = !m_line1Edit->text().isEmpty(); + m_pButton->setEnabled(enabled); + } } void PasswordWidget::slot_action() { - if (m_strPassword.isEmpty()) - return; + const QString& pass1 = m_line1Edit->text(); + const QString& pass2 = m_line2Edit->text(); + + if (m_enType == eSetPassword) { + if (pass1 != pass2) { + m_pError->setText(tr("Passwords are not equal")); + m_pError->show(); + return; + } + } QString error; if (m_enType == eSetPassword) { try { - Globals::instance().runTask("set_password \"" + m_strPassword.toStdString() + "\""); + Globals::instance().runTask("set_password \"" + pass1.toStdString() + "\""); } catch(const std::exception& ex) { error = ex.what(); @@ -998,7 +1046,7 @@ void PasswordWidget::slot_action() try { - Globals::instance().runTask("unlock \"" + m_strPassword.toStdString() + "\""); + Globals::instance().runTask("unlock \"" + pass1.toStdString() + "\""); } catch(const std::exception& ex) { error = ex.what(); diff --git a/programs/gui_wallet/src/richdialog.hpp b/programs/gui_wallet/src/richdialog.hpp index ab5a9af9..6ca8412a 100644 --- a/programs/gui_wallet/src/richdialog.hpp +++ b/programs/gui_wallet/src/richdialog.hpp @@ -188,6 +188,9 @@ public slots: // // PasswordWidget // + +class DecentLineEdit; + class PasswordWidget : public StackLayerWidget { Q_OBJECT @@ -197,12 +200,15 @@ class PasswordWidget : public StackLayerWidget protected slots: void slot_action(); - void slot_set_password(QString const&); + void slot_textChanged(const QString& ); private: eType m_enType; QLabel* m_pError; - QString m_strPassword; + + DecentLineEdit* m_line1Edit; + DecentLineEdit* m_line2Edit; + DecentButton* m_pButton; }; } diff --git a/programs/gui_wallet/src/upload_popup.cpp b/programs/gui_wallet/src/upload_popup.cpp index edbc8b53..a745d63d 100644 --- a/programs/gui_wallet/src/upload_popup.cpp +++ b/programs/gui_wallet/src/upload_popup.cpp @@ -36,8 +36,7 @@ using std::string; namespace gui_wallet { -Upload_popup::Upload_popup(QWidget* pParent, const std::string& id_modify/* = string()*/) -: StackLayerWidget(pParent) +Upload_popup::Upload_popup(QWidget* pParent, const std::string& id_modify/* = string()*/) : StackLayerWidget(pParent) , m_pStatusCheckTimer(new QTimer(this)) , m_pDescriptionText(new DecentTextEdit(this, DecentTextEdit::Editor)) , m_pLifeTime(new QDateEdit(this)) @@ -96,7 +95,7 @@ Upload_popup::Upload_popup(QWidget* pParent, const std::string& id_modify/* = st dblValidator->setLocale(Globals::instance().locale()); m_pPriceEditor = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); - m_pPriceEditor->setPlaceholderText(tr("Price")); + m_pPriceEditor->setPlaceholderText(QString(tr("Price in %1")).arg(Globals::instance().getAssetName()) ); m_pPriceEditor->setValidator(dblValidator); m_pPriceEditor->setAttribute(Qt::WA_MacShowFocusRect, 0); m_pPriceEditor->setTextMargins(5, 5, 5, 5); @@ -166,6 +165,10 @@ Upload_popup::Upload_popup(QWidget* pParent, const std::string& id_modify/* = st // // Layouts // + QVBoxLayout* pFirstRow = new QVBoxLayout(); + pFirstRow->addWidget(pTitleText); + pFirstRow->addWidget(m_pDescriptionText); + QHBoxLayout* pLifeTimeRow = new QHBoxLayout(); pLifeTimeRow->addWidget(pLifeTimeLabel); pLifeTimeRow->addWidget(m_pLifeTime); @@ -195,8 +198,7 @@ Upload_popup::Upload_popup(QWidget* pParent, const std::string& id_modify/* = st pButtonsLayout->addWidget(pCancelButton); QVBoxLayout* pMainLayout = new QVBoxLayout; - pMainLayout->addWidget(pTitleText); - pMainLayout->addWidget(m_pDescriptionText); + pMainLayout->addLayout(pFirstRow); pMainLayout->addLayout(pLifeTimeRow); pMainLayout->addLayout(pPriceRow); pMainLayout->addLayout(pSeedersRow); @@ -207,6 +209,12 @@ Upload_popup::Upload_popup(QWidget* pParent, const std::string& id_modify/* = st pMainLayout->setContentsMargins(10, 10, 10, 10); setLayout(pMainLayout); + QWidget::setTabOrder(pTitleText, m_pDescriptionText); + QWidget::setTabOrder(m_pDescriptionText, m_pLifeTime); + QWidget::setTabOrder(m_pLifeTime, m_pPriceEditor); + + + slot_UpdateStatus(); // // signal/slot conntections @@ -252,6 +260,11 @@ Upload_popup::Upload_popup(QWidget* pParent, const std::string& id_modify/* = st this, &Upload_popup::slot_UpdateStatus); m_pStatusCheckTimer->start(500); + pTitleText->show(); + pTitleText->setFocus(); + + + if (!m_id_modify.empty()) { string title, description, price, expiration; From 913640ba449ee3d7d8a161d1ec8ca88da817cf7a Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Fri, 23 Mar 2018 11:04:53 +0100 Subject: [PATCH 076/136] GUI wallet improvements --- programs/gui_wallet/src/mainwindow.cpp | 10 ++++++++-- programs/gui_wallet/styles/white_green.css | 17 ++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 14462414..a8f3e832 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -100,7 +100,7 @@ MainWindow::MainWindow() DecentLabel* pRow1Spacer = new DecentLabel(pMainWidget, DecentLabel::Row1Spacer); m_pAccountList = new QComboBox(pMainWidget); m_pAccountList->setStyle(QStyleFactory::create("fusion")); - m_pAccountList->setMinimumContentsLength(70); + m_pAccountList->setMinimumContentsLength(40); m_pBalance = new DecentLabel(pMainWidget, DecentLabel::Balance); DecentButton* pTransferButton = new DecentButton(pMainWidget, DecentButton::Send); pTransferButton->setToolTip("Transfer DCT to account"); @@ -607,7 +607,13 @@ void MainWindow::slot_stackWidgetPop() void MainWindow::slot_updateAccountBalance(Asset const& balance) { - m_pBalance->setText(balance.getStringBalance()); + QString blalanceText = balance.getStringBalance(); + + QFontMetrics fm(m_pBalance->font()); + int pxWidth = fm.width(blalanceText); + + m_pBalance->setMinimumWidth(pxWidth + 10); //10 is border.. + m_pBalance->setText(blalanceText); } void MainWindow::slot_replayBlockChain() diff --git a/programs/gui_wallet/styles/white_green.css b/programs/gui_wallet/styles/white_green.css index b7f64f42..5da0608d 100644 --- a/programs/gui_wallet/styles/white_green.css +++ b/programs/gui_wallet/styles/white_green.css @@ -75,22 +75,18 @@ QLabel[type='row1spacer'] } QLabel[type='balance'] { - image: url(':/icon/images/balance.svg'); - image-position: right; padding-top: 1.3em; padding-bottom: 1.3em; - padding-left: 1em; - padding-right: 1em; max-width: 10em; max-height: 1.9em; - min-width: 10em; + min-width: 5em; min-height: 1.9em; border-bottom: 1px solid rgb(240, 240, 240); border-right: 1px solid rgb(240, 240, 240); border-left: 0px; border-top: 0px; color: rgb(27, 176, 104); - /*qproperty-alignment: 'AlignLeft | AlignVCenter';*/ + qproperty-alignment: 'AlignRight | AlignVCenter'; } QLabel[type='tablesearchframe'] { @@ -404,12 +400,11 @@ QTextEdit QScrollBar::sub-line:vertical QProgressBar { border-radius: 0.27em; - max-height: 0.56em; - min-height: 0.56em; - width: 9.86em; - max-width: 9.86em; + max-height: 0.86em; + min-height: 0.86em; + width: 23.86em; + max-width: 23.86em; background: rgb(224, 229, 235); - qproperty-textVisible: false; } QProgressBar:chunk { From 9b83a92678a926e3102bc0eb02b82ca34a338a78 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Fri, 23 Mar 2018 13:20:24 +0100 Subject: [PATCH 077/136] GUI wallet improvements --- programs/gui_wallet/src/mainwindow.cpp | 8 +++----- programs/gui_wallet/styles/white_green.css | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index a8f3e832..6bb880eb 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -393,15 +393,13 @@ void MainWindow::slot_setSplash() StackLayerWidget* pSplashScreen = new StackLayerWidget(this); m_pConnectingProgress = new QProgressBar(pSplashScreen); m_pConnectingProgress->setFont(gui_wallet::ProgressInfoFont()); - m_pConnectingProgress->setFormat("%d%%"); DecentLabel* pPleaseWaitLabel = new DecentLabel(pSplashScreen, DecentLabel::SplashInfo); pPleaseWaitLabel->setFont(gui_wallet::ProgressInfoFont()); pPleaseWaitLabel->setText(tr("Please wait...")); - //pConnectingProgress->setValue(70); m_pConnectingLabel = new DecentLabel(pSplashScreen, DecentLabel::SplashInfo); - //pConnectingLabel->setText(QString(tr("Please wait, currently synchronized block is %1 old.")).arg("")); + m_pConnectingLabel->setText(tr("Connecting...")); m_pConnectingLabel->setFont(gui_wallet::ProgressInfoFont()); StatusLabel* pSyncUpLabel = new StatusLabel(pSplashScreen, DecentLabel::SplashInfo); @@ -413,8 +411,8 @@ void MainWindow::slot_setSplash() pButton->setText(tr("Proceed")); QGridLayout* pLayoutSplash = new QGridLayout; - pLayoutSplash->addWidget(m_pConnectingProgress, 0, 0, Qt::AlignVCenter | Qt::AlignCenter); - pLayoutSplash->addWidget(pPleaseWaitLabel, 1, 0, Qt::AlignVCenter | Qt::AlignCenter); + pLayoutSplash->addWidget(pPleaseWaitLabel, 0, 0, Qt::AlignVCenter | Qt::AlignCenter); + pLayoutSplash->addWidget(m_pConnectingProgress, 1, 0, Qt::AlignVCenter | Qt::AlignCenter); pLayoutSplash->addWidget(m_pConnectingLabel, 2, 0, Qt::AlignVCenter | Qt::AlignCenter); pLayoutSplash->addWidget(pSyncUpLabel, 3, 0, Qt::AlignVCenter | Qt::AlignCenter); pLayoutSplash->addWidget(pButton, 4, 0, Qt::AlignVCenter | Qt::AlignCenter); diff --git a/programs/gui_wallet/styles/white_green.css b/programs/gui_wallet/styles/white_green.css index 5da0608d..9c7c1829 100644 --- a/programs/gui_wallet/styles/white_green.css +++ b/programs/gui_wallet/styles/white_green.css @@ -405,6 +405,7 @@ QProgressBar width: 23.86em; max-width: 23.86em; background: rgb(224, 229, 235); + text-align: center; } QProgressBar:chunk { From a11a6acee0867a7c43d98d92c0e3317103bb78e6 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Mon, 26 Mar 2018 10:20:10 +0200 Subject: [PATCH 078/136] fixed paging in miner voting tab (next,prev) added info message for voting fee --- libraries/wallet/wallet.cpp | 36 +++++++++++++++---- programs/gui_wallet/src/gui_wallet_global.cpp | 4 +++ programs/gui_wallet/src/mainwindow.cpp | 13 +++++++ programs/gui_wallet/src/mainwindow.hpp | 1 + 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 42dedcfe..16cc7050 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1622,7 +1622,7 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (account_to_modify)(desired_number_of_miners)(broadcast) ) } - vector search_miner_voting(const string& term, + vector search_miner_voting(const string& filter, const string& order, const string& account_id, const string& id, @@ -1637,15 +1637,15 @@ class wallet_api_impl map miners = _remote_db->lookup_miner_accounts("", 1000); - vector result; - result.reserve(miners.size()); + vector miners_info; + miners_info.reserve(miners.size()); for(auto item : miners) { miner_voting_info info; info.id = item.second; info.name = item.first; - if (!term.empty() && item.first.find(term) == std::string::npos ) { + if (!filter.empty() && item.first.find(filter) == std::string::npos ) { continue; } @@ -1655,7 +1655,7 @@ class wallet_api_impl info.total_votes = obj.total_votes; info.voted = acc_votes.find(obj.vote_id) != acc_votes.end(); - result.push_back(info); + miners_info.push_back(info); } struct miner_sorter { @@ -1682,7 +1682,30 @@ class wallet_api_impl }; if (!order.empty()) { - std::sort(result.begin(), result.end(), miner_sorter(order)); + std::sort(miners_info.begin(), miners_info.end(), miner_sorter(order)); + } + + struct miner_search { + miner_search(const string& search_id) : search_id_(search_id) {} + + bool operator()(const miner_voting_info& info) const { + return info.id == search_id_; + } + + object_id_type search_id_; + }; + + vector result; + result.reserve(count); + + auto it = miners_info.begin(); + if (!id.empty()) { + it = std::find_if(miners_info.begin(), miners_info.end(), miner_search(id)); + } + + while(count && it != miners_info.end()) { + count--; + result.push_back(*it); ++it; } return result; @@ -3560,4 +3583,3 @@ void fc::from_variant(const fc::variant& var, account_multi_index_type& vo) vo = account_multi_index_type(v.begin(), v.end()); } - diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index 4462ff75..56e6af82 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -661,10 +661,12 @@ void Globals::startDaemons(BlockChainStartType type) #endif +#if 0 m_p_daemon_details->future_decentd = thread_decentd.async([type, &exit_promise]() -> int { return ::runDecentD(type, exit_promise); }); +#endif m_tp_started = std::chrono::steady_clock::now(); @@ -689,10 +691,12 @@ void Globals::stopDaemons() m_p_wallet_operator = nullptr; } +#if 0 fc::promise::ptr& exit_promise = m_p_daemon_details->exit_promise; exit_promise->set_value(); m_p_daemon_details->future_decentd.wait(); +#endif if (m_p_daemon_details->ipfs_process) { m_p_daemon_details->ipfs_process->terminate(); diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 74f37c77..ff385a4d 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -45,6 +45,7 @@ #endif #include +#include #include "update_manager.hpp" @@ -60,6 +61,7 @@ MainWindow::MainWindow() , m_pTimerDownloads(new QTimer(this)) , m_pTimerBalance(new QTimer(this)) , m_pTimerContents(new QTimer(this)) +, m_pTimerVoting(new QTimer(this)) , m_pStackedWidget(new QStackedWidget(this)) , m_pAccountList(nullptr) , m_pBalance(nullptr) @@ -379,6 +381,10 @@ MainWindow::MainWindow() QObject::connect(m_pTimerContents, &QTimer::timeout, this, &MainWindow::slot_getContents); +// m_pTimerVoting->setInterval(5000); +// QObject::connect(m_pTimerVoting, &QTimer::timeout, +// this, &MainWindow::slot_getContents); + resize(900, 600); #ifdef _MSC_VER @@ -743,6 +749,13 @@ void MainWindow::slot_MinerVotingToggled(bool toggled) // if (toggled) { + + QMessageBox info(this); + info.setIcon(QMessageBox::Information); + info.setText(QString(tr("For every vote or unvote opeation you will pay %1 fee")).arg("xyz DCT") ); //TODO: add fee price + info.exec(); + + m_pTabMinerVoting->show(); slot_getContents(); } diff --git a/programs/gui_wallet/src/mainwindow.hpp b/programs/gui_wallet/src/mainwindow.hpp index 5da057d1..a1c2a4d8 100644 --- a/programs/gui_wallet/src/mainwindow.hpp +++ b/programs/gui_wallet/src/mainwindow.hpp @@ -64,6 +64,7 @@ protected slots: QTimer* m_pTimerDownloads; QTimer* m_pTimerBalance; QTimer* m_pTimerContents; + QTimer* m_pTimerVoting; QStackedWidget* m_pStackedWidget; QComboBox* m_pAccountList; From 439695a3326c7ea5a6e9fc5214f6886a7c85b772 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Mon, 26 Mar 2018 13:04:39 +0200 Subject: [PATCH 079/136] added proper fee amount for information dialog removed trailing zeros from price/amount --- programs/gui_wallet/src/gui_wallet_global.cpp | 13 +++++++++++-- programs/gui_wallet/src/gui_wallet_global.hpp | 3 ++- programs/gui_wallet/src/mainwindow.cpp | 4 +++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index 56e6af82..62a55f48 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -534,7 +534,7 @@ QString Asset::getString() const QLocale& locale = Globals::instance().locale(); if (hasDecimals()) - return locale.toString(to_value(), 'f', g_max_number_of_decimal_places) + " " + QString::fromStdString(m_str_symbol); + return locale.toString(to_value(), 'g', g_max_number_of_decimal_places) + " " + QString::fromStdString(m_str_symbol); else return locale.toString((int)to_value()) + " " + QString::fromStdString(m_str_symbol); } @@ -546,7 +546,7 @@ QString Asset::getString() const QString Asset::getStringBalance() const { QLocale& locale = Globals::instance().locale(); - return locale.toString(to_value(), 'f' , g_max_number_of_decimal_places) + " " + QString::fromStdString(m_str_symbol); + return locale.toString(to_value(), 'g' , g_max_number_of_decimal_places) + " " + QString::fromStdString(m_str_symbol); } // // DaemonDetails @@ -842,6 +842,15 @@ std::string Globals::getAccountName(string const& accountId) return search->second; } +Asset Globals::getDCoreFees(int iOperation) +{ + nlohmann::json global_prop_info = runTaskParse("get_global_properties"); + nlohmann::json param = global_prop_info["parameters"]["current_fees"]["parameters"]; + nlohmann::json curr_fee = param[iOperation]; //account_update_operation + + return asset(curr_fee[1]["fee"].get() ); +} + void Globals::slot_updateAccountBalance() { if (!m_str_currentUser.empty()) diff --git a/programs/gui_wallet/src/gui_wallet_global.hpp b/programs/gui_wallet/src/gui_wallet_global.hpp index 463024f3..c5d50a2d 100644 --- a/programs/gui_wallet/src/gui_wallet_global.hpp +++ b/programs/gui_wallet/src/gui_wallet_global.hpp @@ -180,8 +180,9 @@ namespace gui_wallet public: void setWalletUnlocked(); void setWalletError(std::string const& error); - std::string getAccountName(const std::string& accountId); + Asset getDCoreFees(int iOperation); + signals: void signal_connect(); // for internal use private slots: diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index ff385a4d..24ecc7e4 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -750,9 +750,11 @@ void MainWindow::slot_MinerVotingToggled(bool toggled) // if (toggled) { + Asset opFee = Globals::instance().getDCoreFees(2); //account_update_operation + QMessageBox info(this); info.setIcon(QMessageBox::Information); - info.setText(QString(tr("For every vote or unvote opeation you will pay %1 fee")).arg("xyz DCT") ); //TODO: add fee price + info.setText(QString(tr("For every vote or unvote opeation you will pay %1 fee")).arg(opFee.getString()) ); info.exec(); From 530745ef782e55e49936658558fa1effbc686cc0 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Mon, 26 Mar 2018 14:54:19 +0200 Subject: [PATCH 080/136] added click on the link feature, fixed vert.alligment of the text --- programs/gui_wallet/src/mining_vote_tab.cpp | 24 ++++++++++++++++----- programs/gui_wallet/src/mining_vote_tab.hpp | 2 ++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp index 9e4eab22..3b9980b0 100644 --- a/programs/gui_wallet/src/mining_vote_tab.cpp +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -18,8 +18,7 @@ #include #include #include -#include -#include +#include #include @@ -100,15 +99,18 @@ void MinerVotingTab::timeToUpdate(const std::string& result) QTableWidgetItem *tabItem; tabItem = new QTableWidgetItem(QString::fromStdString(name)); - tabItem->setTextAlignment(Qt::AlignHCenter); + tabItem->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter); m_pTableWidget->setItem(iIndex, 0, tabItem); tabItem = new QTableWidgetItem(QString::fromStdString(url)); - tabItem->setTextAlignment(Qt::AlignHCenter); + tabItem->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter); m_pTableWidget->setItem(iIndex, 1, tabItem); + if (!url.empty()) { + m_indexToUrl.insert(iIndex, QString::fromStdString(url)); + } tabItem = new QTableWidgetItem(QString::number(total_votes)); - tabItem->setTextAlignment(Qt::AlignRight); + tabItem->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); m_pTableWidget->setItem(iIndex, 2, tabItem); // Vote Button @@ -137,6 +139,7 @@ void MinerVotingTab::timeToUpdate(const std::string& result) //TODO.. handle error } + QObject::connect(m_pTableWidget, &DecentTable::cellClicked, this, &MinerVotingTab::slot_cellClicked); if (contents.size() > m_i_page_size) set_next_page_iterator(contents[m_i_page_size]["id"].get()); @@ -175,6 +178,17 @@ void MinerVotingTab::slot_SortingChanged(int index) reset(); } +void MinerVotingTab::slot_cellClicked(int row, int col) +{ + if (col != 1) + return; + + auto find = m_indexToUrl.find(row); + if (find != m_indexToUrl.end()) { + QDesktopServices::openUrl(QUrl(find.value())); + } +} + void MinerVotingTab::slot_MinerVote() { Q_ASSERT(sender() != nullptr); diff --git a/programs/gui_wallet/src/mining_vote_tab.hpp b/programs/gui_wallet/src/mining_vote_tab.hpp index 21cacfce..dcc895fb 100644 --- a/programs/gui_wallet/src/mining_vote_tab.hpp +++ b/programs/gui_wallet/src/mining_vote_tab.hpp @@ -28,6 +28,7 @@ namespace gui_wallet public slots: void slot_SearchTermChanged(QString const& strSearchTerm); void slot_SortingChanged(int index); + void slot_cellClicked(int row, int col); void slot_MinerVote(); private: @@ -38,5 +39,6 @@ namespace gui_wallet QString m_strSearchTerm; QMap m_buttonsToIndex; + QMap m_indexToUrl; }; } \ No newline at end of file From adf667b9c4348fd18f70706c097813cbf6e702a3 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 27 Mar 2018 10:05:04 +0200 Subject: [PATCH 081/136] added "only my votes" checkbox --- .../wallet/include/graphene/wallet/mining.hpp | 10 +++--- libraries/wallet/wallet.cpp | 12 ++++--- libraries/wallet/wallet_mining.inl | 11 ++++--- programs/gui_wallet/src/mainwindow.cpp | 12 +++++-- programs/gui_wallet/src/mainwindow.hpp | 2 ++ programs/gui_wallet/src/mining_vote_tab.cpp | 32 ++++++++++++++++--- programs/gui_wallet/src/mining_vote_tab.hpp | 5 ++- 7 files changed, 64 insertions(+), 20 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/mining.hpp b/libraries/wallet/include/graphene/wallet/mining.hpp index d677ec1e..b4000e5a 100644 --- a/libraries/wallet/include/graphene/wallet/mining.hpp +++ b/libraries/wallet/include/graphene/wallet/mining.hpp @@ -161,6 +161,7 @@ signed_transaction set_desired_miner_count(const string& account_to_modify, /** * @brief * @param term search term + * @param only_my_votes * @param order order field. Available options are defined in 'database_api.cpp' * @param id the id of content object to start searching from * @param count maximum number of contents to fetch (must not exceed 1000) @@ -168,10 +169,11 @@ signed_transaction set_desired_miner_count(const string& account_to_modify, * @ingroup WalletAPI_Mining */ vector search_miner_voting(const string& term, - const string& order, - const string& account_id, - const string& id, - uint32_t count ) const; + bool only_my_votes, + const string& order, + const string& account_id, + const string& id, + uint32_t count ) const; #endif //DECENT_WALLET_MINING_H diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 16cc7050..86d0eb16 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1623,10 +1623,11 @@ class wallet_api_impl } FC_CAPTURE_AND_RETHROW( (account_to_modify)(desired_number_of_miners)(broadcast) ) } vector search_miner_voting(const string& filter, - const string& order, - const string& account_id, - const string& id, - uint32_t count ) const + bool only_my_votes, + const string& order, + const string& account_id, + const string& id, + uint32_t count ) const { optional acc_obj = _remote_db->get_account_by_name(account_id); if (!acc_obj) { @@ -1655,6 +1656,9 @@ class wallet_api_impl info.total_votes = obj.total_votes; info.voted = acc_votes.find(obj.vote_id) != acc_votes.end(); + if (only_my_votes && !info.voted) + continue; + miners_info.push_back(info); } diff --git a/libraries/wallet/wallet_mining.inl b/libraries/wallet/wallet_mining.inl index 203889ed..88e764c6 100644 --- a/libraries/wallet/wallet_mining.inl +++ b/libraries/wallet/wallet_mining.inl @@ -60,10 +60,11 @@ signed_transaction wallet_api::set_desired_miner_count(const string& account_to_ } vector wallet_api::search_miner_voting(const string& term, - const string& order, - const string& account_id, - const string& id, - uint32_t count ) const + bool only_my_votes, + const string& order, + const string& account_id, + const string& id, + uint32_t count ) const { - return my->search_miner_voting(term, order, account_id, id, count); + return my->search_miner_voting(term, only_my_votes, order, account_id, id, count); } diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 24ecc7e4..7758c8c7 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -46,6 +46,7 @@ #include #include +#include #include "update_manager.hpp" @@ -74,6 +75,7 @@ MainWindow::MainWindow() , m_pFilterUsers(nullptr) , m_pFilterPurchased(nullptr) , m_pPublish(nullptr) +, m_pOnlyMyVotes(nullptr) , m_pTabBrowse(nullptr) , m_pTabTransactions(nullptr) , m_pTabPublish(nullptr) @@ -170,6 +172,10 @@ MainWindow::MainWindow() m_pPublish = new DecentButton(pMainWidget, DecentButton::DialogAction); m_pPublish->setText(tr("Publish")); m_pPublish->hide(); + + m_pOnlyMyVotes = new QCheckBox(tr("Only my votes"), pMainWidget); + m_pOnlyMyVotes->hide(); + // // 4th row controls // @@ -183,7 +189,7 @@ MainWindow::MainWindow() m_pTabUsers->hide(); m_pTabPurchased = new PurchasedTab(pMainWidget, m_pFilterPurchased); m_pTabPurchased->hide(); - m_pTabMinerVoting = new MinerVotingTab(pMainWidget, m_pFilterUsers); + m_pTabMinerVoting = new MinerVotingTab(pMainWidget, m_pFilterUsers, m_pOnlyMyVotes); m_pTabMinerVoting->hide(); // @@ -240,6 +246,7 @@ MainWindow::MainWindow() pRow3Layout->addWidget(pRow3_LabelSearchFrame); pRow3Layout->addStretch(); pRow3Layout->addWidget(m_pPublish); + pRow3Layout->addWidget(m_pOnlyMyVotes); pRow3Layout->setContentsMargins(5, 0, 5, 0); // // 4th row layout @@ -757,11 +764,12 @@ void MainWindow::slot_MinerVotingToggled(bool toggled) info.setText(QString(tr("For every vote or unvote opeation you will pay %1 fee")).arg(opFee.getString()) ); info.exec(); - + m_pOnlyMyVotes->show(); m_pTabMinerVoting->show(); slot_getContents(); } else { + m_pOnlyMyVotes->hide(); m_pTabMinerVoting->hide(); } diff --git a/programs/gui_wallet/src/mainwindow.hpp b/programs/gui_wallet/src/mainwindow.hpp index a1c2a4d8..6b93e1ff 100644 --- a/programs/gui_wallet/src/mainwindow.hpp +++ b/programs/gui_wallet/src/mainwindow.hpp @@ -7,6 +7,7 @@ class QStackedWidget; class QComboBox; +class QCheckBox; class QTimer; class QAction; class UpdateManager; @@ -88,6 +89,7 @@ protected slots: DecentLineEdit* m_pFilterPurchased; DecentButton* m_pPublish; + QCheckBox* m_pOnlyMyVotes; TabContentManager* m_pTabBrowse; TabContentManager* m_pTabTransactions; diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp index 3b9980b0..fbc8cd11 100644 --- a/programs/gui_wallet/src/mining_vote_tab.cpp +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -33,8 +34,10 @@ namespace gui_wallet { const char* g_vote_state_id = "vote-state"; -MinerVotingTab::MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit) : TabContentManager(pParent), - m_pTableWidget(new DecentTable(this)) +MinerVotingTab::MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit, QCheckBox* pOnlyMyVotes) + : TabContentManager(pParent), + m_pTableWidget(new DecentTable(this)), + m_onlyMyVotes(false) { m_pTableWidget->set_columns({ {tr("Miner"), 15, "name"}, @@ -58,6 +61,11 @@ MinerVotingTab::MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit this->setFilterWidget(pFilterLineEdit); } + if (pOnlyMyVotes) { + QObject::connect(pOnlyMyVotes, &QCheckBox::stateChanged, this, &MinerVotingTab::slot_onlyMyVotes); + + } + QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &MinerVotingTab::slot_SortingChanged); @@ -69,7 +77,9 @@ MinerVotingTab::~MinerVotingTab() = default; void MinerVotingTab::timeToUpdate(const std::string& result) { if (result.empty()) { - m_pTableWidget->setRowCount(0); + while(m_pTableWidget->rowCount() > 0) { + m_pTableWidget->removeRow(0); + } return; } @@ -79,10 +89,17 @@ void MinerVotingTab::timeToUpdate(const std::string& result) iSize = m_i_page_size; m_buttonsToIndex.clear(); - m_pTableWidget->setRowCount(iSize); + m_indexToUrl.clear(); + + //clear table + while(m_pTableWidget->rowCount() > 0) { + m_pTableWidget->removeRow(0); + } try { + m_pTableWidget->setRowCount(iSize); + for (size_t iIndex = 0; iIndex < iSize; ++iIndex) { auto const &content = contents[iIndex]; @@ -161,6 +178,7 @@ std::string MinerVotingTab::getUpdateCommand() return "search_miner_voting " "\"" + m_strSearchTerm.toStdString() + "\" " + + (m_onlyMyVotes ? "true " : "false ") + "\"" + m_pTableWidget->getSortedColumn() + "\" " "\"" + currentUserName + "\" " "\"" + next_iterator() + "\" " @@ -189,6 +207,12 @@ void MinerVotingTab::slot_cellClicked(int row, int col) } } +void MinerVotingTab::slot_onlyMyVotes(int state) +{ + m_onlyMyVotes = (state == Qt::Checked); + reset(true); +} + void MinerVotingTab::slot_MinerVote() { Q_ASSERT(sender() != nullptr); diff --git a/programs/gui_wallet/src/mining_vote_tab.hpp b/programs/gui_wallet/src/mining_vote_tab.hpp index dcc895fb..cfbc2fff 100644 --- a/programs/gui_wallet/src/mining_vote_tab.hpp +++ b/programs/gui_wallet/src/mining_vote_tab.hpp @@ -8,6 +8,7 @@ class QSignalMapper; class QWidget; +class QCheckBox; namespace gui_wallet { @@ -19,7 +20,7 @@ namespace gui_wallet class MinerVotingTab : public TabContentManager { Q_OBJECT public: - MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit); + MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit, QCheckBox* pOnlyMyVotes); ~MinerVotingTab(); virtual void timeToUpdate(const std::string& result); @@ -30,6 +31,7 @@ namespace gui_wallet void slot_SortingChanged(int index); void slot_cellClicked(int row, int col); void slot_MinerVote(); + void slot_onlyMyVotes(int state); private: void submit_vote(const std::string& miner_name, bool voteFlag); @@ -37,6 +39,7 @@ namespace gui_wallet public: DecentTable* m_pTableWidget; QString m_strSearchTerm; + bool m_onlyMyVotes; QMap m_buttonsToIndex; QMap m_indexToUrl; From f0e62a2ec7051a6627bce88736781afe2e06d17d Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 27 Mar 2018 10:25:01 +0200 Subject: [PATCH 082/136] small improvements and fixes --- programs/gui_wallet/src/mining_vote_tab.cpp | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp index fbc8cd11..c32f72d4 100644 --- a/programs/gui_wallet/src/mining_vote_tab.cpp +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -27,8 +26,6 @@ #endif -using std::string; - namespace gui_wallet { const char* g_vote_state_id = "vote-state"; @@ -103,11 +100,11 @@ void MinerVotingTab::timeToUpdate(const std::string& result) for (size_t iIndex = 0; iIndex < iSize; ++iIndex) { auto const &content = contents[iIndex]; - string name = content["name"].get(); - string url = content["url"].get(); + std::string name = content["name"].get(); + std::string url = content["url"].get(); uint64_t total_votes; if (content["total_votes"].is_string() ) { - total_votes = std::stoull(content["total_votes"].get()); + total_votes = std::stoull(content["total_votes"].get()); } else { total_votes = content["total_votes"].get(); @@ -117,10 +114,12 @@ void MinerVotingTab::timeToUpdate(const std::string& result) QTableWidgetItem *tabItem; tabItem = new QTableWidgetItem(QString::fromStdString(name)); tabItem->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter); + tabItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); m_pTableWidget->setItem(iIndex, 0, tabItem); tabItem = new QTableWidgetItem(QString::fromStdString(url)); tabItem->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter); + tabItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); m_pTableWidget->setItem(iIndex, 1, tabItem); if (!url.empty()) { m_indexToUrl.insert(iIndex, QString::fromStdString(url)); @@ -128,6 +127,7 @@ void MinerVotingTab::timeToUpdate(const std::string& result) tabItem = new QTableWidgetItem(QString::number(total_votes)); tabItem->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + tabItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); m_pTableWidget->setItem(iIndex, 2, tabItem); // Vote Button @@ -159,21 +159,21 @@ void MinerVotingTab::timeToUpdate(const std::string& result) QObject::connect(m_pTableWidget, &DecentTable::cellClicked, this, &MinerVotingTab::slot_cellClicked); if (contents.size() > m_i_page_size) - set_next_page_iterator(contents[m_i_page_size]["id"].get()); + set_next_page_iterator(contents[m_i_page_size]["id"].get()); else - set_next_page_iterator(string()); + set_next_page_iterator(std::string()); } std::string MinerVotingTab::getUpdateCommand() { - string currentUserName = Globals::instance().getCurrentUser(); + std::string currentUserName = Globals::instance().getCurrentUser(); if (currentUserName.empty()) - return string(); + return std::string(); graphene::chain::ContentObjectPropertyManager type_composer; graphene::chain::ContentObjectTypeValue type(graphene::chain::EContentObjectApplication::DecentCore); - string str_type; + std::string str_type; type.to_string(str_type); return "search_miner_voting " From f5d71903b2565168fc0ee2ab4311207a48b97d80 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 27 Mar 2018 13:55:26 +0200 Subject: [PATCH 083/136] improved tabs refreshing, each tab has now own timer for refresh. --- .../gui_wallet/src/browse_content_tab.cpp | 2 + .../src/gui_wallet_tabcontentmanager.cpp | 21 ++- .../src/gui_wallet_tabcontentmanager.hpp | 6 + programs/gui_wallet/src/mainwindow.cpp | 144 ++++++++++++------ programs/gui_wallet/src/mainwindow.hpp | 6 +- programs/gui_wallet/src/mining_vote_tab.cpp | 4 +- programs/gui_wallet/src/purchased_tab.cpp | 2 + 7 files changed, 131 insertions(+), 54 deletions(-) diff --git a/programs/gui_wallet/src/browse_content_tab.cpp b/programs/gui_wallet/src/browse_content_tab.cpp index 0f51effe..141521d4 100644 --- a/programs/gui_wallet/src/browse_content_tab.cpp +++ b/programs/gui_wallet/src/browse_content_tab.cpp @@ -57,6 +57,8 @@ BrowseContentTab::BrowseContentTab(QWidget* pParent, QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &BrowseContentTab::slot_SortingChanged); + + setRefreshTimer(3000); } void BrowseContentTab::timeToUpdate(const std::string& result) diff --git a/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp b/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp index c43d0228..3e7c88e6 100644 --- a/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp +++ b/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp @@ -2,15 +2,18 @@ #include "gui_wallet_global.hpp" #include "gui_wallet_tabcontentmanager.hpp" +#include + using std::string; namespace gui_wallet { -TabContentManager::TabContentManager(QWidget* pParent/* = nullptr*/) -: QWidget(pParent) +TabContentManager::TabContentManager(QWidget* pParent/* = nullptr*/) : QWidget(pParent) , m_i_page_size(50) , m_last_result() , m_next_iterator() +, m_pFilterWidget(nullptr) +, m_pRefreshTimer(nullptr) { } @@ -34,9 +37,6 @@ void TabContentManager::tryToUpdate() { error = ex.what(); } -// catch (...) { -// result.clear(); -// } if (result != m_last_result) { m_last_result = result; @@ -108,5 +108,16 @@ void TabContentManager::setFilterWidget(QWidget* pWidget) m_pFilterWidget = pWidget; } +void TabContentManager::setRefreshTimer(int msec) +{ + if (m_pRefreshTimer == nullptr) { + m_pRefreshTimer = new QTimer(this); + m_pRefreshTimer->setInterval(msec); + } + else { + m_pRefreshTimer->setInterval(msec); + } +} + } // namespace gui_wallet diff --git a/programs/gui_wallet/src/gui_wallet_tabcontentmanager.hpp b/programs/gui_wallet/src/gui_wallet_tabcontentmanager.hpp index 03d94161..fead7b77 100644 --- a/programs/gui_wallet/src/gui_wallet_tabcontentmanager.hpp +++ b/programs/gui_wallet/src/gui_wallet_tabcontentmanager.hpp @@ -5,6 +5,8 @@ #include #include +class QTimer; + namespace gui_wallet { class TabContentManager : public QWidget @@ -18,6 +20,9 @@ class TabContentManager : public QWidget void setFilterWidget(QWidget* pWidget); virtual QWidget* getFilterWidget() const { return m_pFilterWidget; } + void setRefreshTimer(int msec); + QTimer* getRefreshTimer() const { return m_pRefreshTimer; } + public: void tryToUpdate(); @@ -36,6 +41,7 @@ class TabContentManager : public QWidget std::vector m_iterators; QWidget* m_pFilterWidget; + QTimer* m_pRefreshTimer; }; diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 7758c8c7..e742b680 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -59,10 +59,7 @@ using namespace utilities; MainWindow::MainWindow() : QMainWindow() , m_iSplashWidgetIndex(0) -, m_pTimerDownloads(new QTimer(this)) , m_pTimerBalance(new QTimer(this)) -, m_pTimerContents(new QTimer(this)) -, m_pTimerVoting(new QTimer(this)) , m_pStackedWidget(new QStackedWidget(this)) , m_pAccountList(nullptr) , m_pBalance(nullptr) @@ -380,13 +377,13 @@ MainWindow::MainWindow() &Globals::instance(), &Globals::slot_updateAccountBalance); - m_pTimerDownloads->setInterval(5000); - QObject::connect(m_pTimerDownloads, &QTimer::timeout, - this, &MainWindow::slot_checkDownloads); +// m_pTimerDownloads->setInterval(5000); +// QObject::connect(m_pTimerDownloads, &QTimer::timeout, +// this, &MainWindow::slot_checkDownloads); - m_pTimerContents->setInterval(1000); - QObject::connect(m_pTimerContents, &QTimer::timeout, - this, &MainWindow::slot_getContents); +// m_pTimerContents->setInterval(1000); +// QObject::connect(m_pTimerContents, &QTimer::timeout, +// this, &MainWindow::slot_getContents); // m_pTimerVoting->setInterval(5000); // QObject::connect(m_pTimerVoting, &QTimer::timeout, @@ -456,10 +453,6 @@ void MainWindow::slot_setSplash() slot_stackWidgetPush(pSplashScreen); - m_pTimerBalance->stop(); - m_pTimerDownloads->stop(); - m_pTimerContents->stop(); - m_pActionImportKey->setDisabled(true); } @@ -524,14 +517,13 @@ void MainWindow::closeSplash(bool bGonnaCoverAgain) DisplayWalletContentGUI(); m_pTimerBalance->start(); - m_pTimerDownloads->start(); - m_pTimerContents->start(); m_pActionImportKey->setEnabled(true); Globals::instance().slot_updateAccountBalance(); + slot_BrowseToggled(true); slot_checkDownloads(); - slot_getContents(); + updateActiveTable(); } } @@ -637,17 +629,37 @@ void MainWindow::slot_BrowseToggled(bool toggled) // really a stupid hack to have the state change visible pSender->setEnabled(false); pSender->setEnabled(true); + + TabContentManager* pActiveTab = m_pTabBrowse; + Q_ASSERT(pActiveTab); + + QWidget* pFilter = pActiveTab->getFilterWidget(); + Q_ASSERT(pFilter); + pFilter->setHidden(!toggled); + // if (toggled) { - m_pFilterBrowse->show(); - m_pTabBrowse->show(); - slot_getContents(); +// m_pFilterBrowse->show(); + pActiveTab->show(); + updateActiveTable(); + + QTimer* pTimer = pActiveTab->getRefreshTimer(); + if (pTimer) { + QObject::connect(pTimer, &QTimer::timeout, this, &MainWindow::slot_getContents); + pTimer->start(); + } } else { - m_pFilterBrowse->hide(); - m_pTabBrowse->hide(); +// m_pFilterBrowse->hide(); + pActiveTab->hide(); + + QTimer* pTimer = pActiveTab->getRefreshTimer(); + if (pTimer) { + pTimer->stop(); + QObject::disconnect(pTimer); + } } } @@ -659,17 +671,20 @@ void MainWindow::slot_TransactionsToggled(bool toggled) pSender->setEnabled(false); pSender->setEnabled(true); - QWidget* pFilter = m_pTabTransactions->getFilterWidget(); + TabContentManager* pActiveTab = m_pTabTransactions; + Q_ASSERT(pActiveTab); + + QWidget* pFilter = pActiveTab->getFilterWidget(); Q_ASSERT(pFilter); pFilter->setHidden(!toggled); // if (toggled) { - m_pTabTransactions->show(); - slot_getContents(); + pActiveTab->show(); + updateActiveTable(); } else { - m_pTabTransactions->hide(); + pActiveTab->hide(); } } @@ -681,19 +696,22 @@ void MainWindow::slot_PublishToggled(bool toggled) pSender->setEnabled(false); pSender->setEnabled(true); - QWidget* pFilter = m_pTabPublish->getFilterWidget(); + TabContentManager* pActiveTab = m_pTabPublish; + Q_ASSERT(pActiveTab); + + QWidget* pFilter = pActiveTab->getFilterWidget(); Q_ASSERT(pFilter); pFilter->setHidden(!toggled); // if (toggled) { - m_pTabPublish->show(); + pActiveTab->show(); m_pPublish->show(); - slot_getContents(); + updateActiveTable(); } else { - m_pTabPublish->hide(); + pActiveTab->hide(); m_pPublish->hide(); } } @@ -706,17 +724,20 @@ void MainWindow::slot_UsersToggled(bool toggled) pSender->setEnabled(false); pSender->setEnabled(true); - QWidget* pFilter = m_pTabUsers->getFilterWidget(); + TabContentManager* pActiveTab = m_pTabUsers; + Q_ASSERT(pActiveTab); + + QWidget* pFilter = pActiveTab->getFilterWidget(); Q_ASSERT(pFilter); pFilter->setHidden(!toggled); // if (toggled) { - m_pTabUsers->show(); - slot_getContents(); + pActiveTab->show(); + updateActiveTable(); } else { - m_pTabUsers->hide(); + pActiveTab->hide(); } } @@ -728,17 +749,32 @@ void MainWindow::slot_PurchasedToggled(bool toggled) pSender->setEnabled(false); pSender->setEnabled(true); - QWidget* pFilter = m_pTabPurchased->getFilterWidget(); + TabContentManager* pActiveTab = m_pTabPurchased; + Q_ASSERT(pActiveTab); + + QWidget* pFilter = pActiveTab->getFilterWidget(); Q_ASSERT(pFilter); pFilter->setHidden(!toggled); // if (toggled) { - m_pTabPurchased->show(); - slot_getContents(); + pActiveTab->show(); + updateActiveTable(); + + QTimer* pTimer = pActiveTab->getRefreshTimer(); + if (pTimer) { + QObject::connect(pTimer, &QTimer::timeout, this, &MainWindow::slot_getContents); + pTimer->start(); + } } else { - m_pTabPurchased->hide(); + pActiveTab->hide(); + + QTimer* pTimer = pActiveTab->getRefreshTimer(); + if (pTimer) { + pTimer->stop(); + QObject::disconnect(pTimer); + } } } @@ -750,7 +786,10 @@ void MainWindow::slot_MinerVotingToggled(bool toggled) pSender->setEnabled(false); pSender->setEnabled(true); - QWidget* pFilter = m_pTabMinerVoting->getFilterWidget(); + TabContentManager* pActiveTab = m_pTabMinerVoting; + Q_ASSERT(pActiveTab); + + QWidget* pFilter = pActiveTab->getFilterWidget(); Q_ASSERT(pFilter); pFilter->setHidden(!toggled); @@ -765,12 +804,24 @@ void MainWindow::slot_MinerVotingToggled(bool toggled) info.exec(); m_pOnlyMyVotes->show(); - m_pTabMinerVoting->show(); - slot_getContents(); + pActiveTab->show(); + updateActiveTable(); + + QTimer* pTimer = pActiveTab->getRefreshTimer(); + if (pTimer) { + QObject::connect(pTimer, &QTimer::timeout, this, &MainWindow::slot_getContents); + pTimer->start(); + } } else { m_pOnlyMyVotes->hide(); - m_pTabMinerVoting->hide(); + pActiveTab->hide(); + + QTimer* pTimer = pActiveTab->getRefreshTimer(); + if (pTimer) { + pTimer->stop(); + QObject::disconnect(pTimer); + } } } @@ -838,6 +889,11 @@ void MainWindow::slot_checkDownloads() } void MainWindow::slot_getContents() +{ + updateActiveTable(); +} + +void MainWindow::updateActiveTable() { TabContentManager* pTab = activeTable(); @@ -871,7 +927,7 @@ void MainWindow::slot_PreviousPage() if (pTab) pTab->previous(); - slot_getContents(); + updateActiveTable(); } void MainWindow::slot_ResetPage() @@ -881,7 +937,7 @@ void MainWindow::slot_ResetPage() if (pTab) pTab->reset(); - slot_getContents(); + updateActiveTable(); } void MainWindow::slot_NextPage() @@ -891,7 +947,7 @@ void MainWindow::slot_NextPage() if (pTab) pTab->next(); - slot_getContents(); + updateActiveTable(); } TabContentManager* MainWindow::activeTable() const diff --git a/programs/gui_wallet/src/mainwindow.hpp b/programs/gui_wallet/src/mainwindow.hpp index 6b93e1ff..e61dc0a7 100644 --- a/programs/gui_wallet/src/mainwindow.hpp +++ b/programs/gui_wallet/src/mainwindow.hpp @@ -59,14 +59,12 @@ protected slots: protected: void closeSplash(bool bGonnaCoverAgain); TabContentManager* activeTable() const; + void updateActiveTable(); protected: size_t m_iSplashWidgetIndex; - QTimer* m_pTimerDownloads; QTimer* m_pTimerBalance; - QTimer* m_pTimerContents; - QTimer* m_pTimerVoting; - + QStackedWidget* m_pStackedWidget; QComboBox* m_pAccountList; DecentLabel* m_pBalance; diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp index c32f72d4..0ab30a73 100644 --- a/programs/gui_wallet/src/mining_vote_tab.cpp +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -66,7 +66,7 @@ MinerVotingTab::MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &MinerVotingTab::slot_SortingChanged); - + setRefreshTimer(5000); } MinerVotingTab::~MinerVotingTab() = default; @@ -228,6 +228,8 @@ void MinerVotingTab::slot_MinerVote() std::string miner_name = item->text().toStdString(); submit_vote(miner_name, !voteFlag); + + reset(true); } void MinerVotingTab::submit_vote(const std::string& miner_name, bool voteFlag) diff --git a/programs/gui_wallet/src/purchased_tab.cpp b/programs/gui_wallet/src/purchased_tab.cpp index cf123f45..5bc0253e 100644 --- a/programs/gui_wallet/src/purchased_tab.cpp +++ b/programs/gui_wallet/src/purchased_tab.cpp @@ -64,6 +64,8 @@ PurchasedTab::PurchasedTab(QWidget* pParent, QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &PurchasedTab::slot_SortingChanged); + + setRefreshTimer(5000); } // From f50a07fb100e20cdb90d7c02672b0da73a678fc7 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Tue, 27 Mar 2018 16:01:07 +0200 Subject: [PATCH 084/136] payment_to_content draft --- libraries/app/impacted.cpp | 5 ++ libraries/chain/db_init.cpp | 1 + .../graphene/chain/protocol/operations.hpp | 1 + .../graphene/chain/protocol/transfer.hpp | 24 ++++++ .../graphene/chain/transfer_evaluator.hpp | 9 +++ libraries/chain/protocol/transfer.cpp | 7 ++ libraries/chain/transfer_evaluator.cpp | 75 +++++++++++++++++++ libraries/wallet/wallet.cpp | 24 ++++-- 8 files changed, 140 insertions(+), 6 deletions(-) diff --git a/libraries/app/impacted.cpp b/libraries/app/impacted.cpp index 6567f605..83d19f31 100644 --- a/libraries/app/impacted.cpp +++ b/libraries/app/impacted.cpp @@ -43,6 +43,11 @@ struct get_impacted_account_visitor _impacted.insert( op.to ); } + void operator()( const transfer2_operation& op ) + { + _impacted.insert( op.from ); + } + void operator()( const account_create_operation& op ) { _impacted.insert( op.registrar ); diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 30977ac1..243b4908 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -119,6 +119,7 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); + register_evaluator(); register_evaluator(); register_evaluator(); register_evaluator(); diff --git a/libraries/chain/include/graphene/chain/protocol/operations.hpp b/libraries/chain/include/graphene/chain/protocol/operations.hpp index fc2acdff..09b05d47 100644 --- a/libraries/chain/include/graphene/chain/protocol/operations.hpp +++ b/libraries/chain/include/graphene/chain/protocol/operations.hpp @@ -83,6 +83,7 @@ namespace graphene { namespace chain { update_user_issued_asset_operation, update_monitored_asset_operation, ready_to_publish2_operation, + transfer2_operation, disallow_automatic_renewal_of_subscription_operation, // VIRTUAL return_escrow_submission_operation, // VIRTUAL return_escrow_buying_operation, // VIRTUAL diff --git a/libraries/chain/include/graphene/chain/protocol/transfer.hpp b/libraries/chain/include/graphene/chain/protocol/transfer.hpp index de17975c..ac7f3f05 100644 --- a/libraries/chain/include/graphene/chain/protocol/transfer.hpp +++ b/libraries/chain/include/graphene/chain/protocol/transfer.hpp @@ -64,7 +64,31 @@ namespace graphene { namespace chain { void validate()const; }; + struct transfer2_operation : public base_operation + { + struct fee_parameters_type { + uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION / 1000; + }; + + asset fee; + /// Account to transfer asset from + account_id_type from; + /// Account to transfer asset to + object_id_type to; + /// The amount of asset to transfer from @ref from to @ref to + asset amount; + + /// User provided data encrypted to the memo key of the "to" account + optional memo; + extensions_type extensions; + + account_id_type fee_payer()const { return from; } + void validate()const; + }; + }} // graphene::chain FC_REFLECT( graphene::chain::transfer_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::transfer_operation, (fee)(from)(to)(amount)(memo)(extensions) ) +FC_REFLECT( graphene::chain::transfer2_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::chain::transfer2_operation, (fee)(from)(to)(amount)(memo)(extensions) ) \ No newline at end of file diff --git a/libraries/chain/include/graphene/chain/transfer_evaluator.hpp b/libraries/chain/include/graphene/chain/transfer_evaluator.hpp index 872486e2..66d6733c 100644 --- a/libraries/chain/include/graphene/chain/transfer_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/transfer_evaluator.hpp @@ -38,4 +38,13 @@ namespace graphene { namespace chain { void_result do_apply( const transfer_operation& o ); }; + class transfer2_evaluator : public evaluator + { + public: + typedef transfer2_operation operation_type; + + void_result do_evaluate( const transfer2_operation& o ); + void_result do_apply( const transfer2_operation& o ); + }; + } } // graphene::chain diff --git a/libraries/chain/protocol/transfer.cpp b/libraries/chain/protocol/transfer.cpp index 2c4f4059..4a7c41e2 100644 --- a/libraries/chain/protocol/transfer.cpp +++ b/libraries/chain/protocol/transfer.cpp @@ -34,4 +34,11 @@ void transfer_operation::validate()const FC_ASSERT( amount.amount > 0 ); } +void transfer2_operation::validate()const +{ + FC_ASSERT( fee.amount >= 0 ); + FC_ASSERT( from != to ); + FC_ASSERT( amount.amount > 0 ); +} + } } // graphene::chain diff --git a/libraries/chain/transfer_evaluator.cpp b/libraries/chain/transfer_evaluator.cpp index bea4bb1f..5f200bf4 100644 --- a/libraries/chain/transfer_evaluator.cpp +++ b/libraries/chain/transfer_evaluator.cpp @@ -27,6 +27,9 @@ #include #include #include +#include + +#include namespace graphene { namespace chain { void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) @@ -72,4 +75,76 @@ void_result transfer_evaluator::do_apply( const transfer_operation& o ) return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } +void_result transfer2_evaluator::do_evaluate( const transfer2_operation& op ) +{ try { + + FC_ASSERT( op.to.is() || op.to.is() ); + + const database& d = db(); + + const account_object& from_account = op.from(d); + const asset_object& asset_type = op.amount.asset_id(d); + + try { + + bool insufficient_balance = d.get_balance( from_account, asset_type ).amount >= op.amount.amount; + FC_ASSERT( insufficient_balance, + "Insufficient Balance: ${balance}, unable to transfer '${total_transfer}' from account '${a}' to '${t}'", + ("a",from_account.name)("t",op.to)("total_transfer",d.to_pretty_string(op.amount))("balance",d.to_pretty_string(d.get_balance(from_account, asset_type))) ); + + return void_result(); + } FC_RETHROW_EXCEPTIONS( error, "Unable to transfer ${a} from ${f} to ${t}", ("a",d.to_pretty_string(op.amount))("f",op.from(d).name)("t",op.to) ); + + } FC_CAPTURE_AND_RETHROW( (op) ) } + +void_result transfer2_evaluator::do_apply( const transfer2_operation& o ) +{ try { + db().adjust_balance( o.from, -o.amount ); + if( o.to.is() ) + db().adjust_balance( o.to, o.amount ); + else + { + auto& content_idx = db().get_index_type().indices().get(); + const auto& content_itr = content_idx.find( o.to ); + asset amount = o.amount; + + if( !content_itr->co_authors.empty() ) + { + boost::multiprecision::int128_t amount_for_co_author; + for( auto const &element : content_itr->co_authors ) + { + amount_for_co_author = ( o.amount.amount.value * element.second ) / 10000ll ; + db().adjust_balance( element.first, asset( static_cast(amount_for_co_author), o.amount.asset_id) ); + amount.amount -= amount_for_co_author; + } + } + + if( amount.amount != 0 ) { + FC_ASSERT( amount.amount > 0 ); + db().adjust_balance(content_itr->author, amount); + } + } + + + + + + + auto & d = db(); + + db().create([&o, &d](transaction_detail_object& obj) + { + obj.m_operation_type = (uint8_t)transaction_detail_object::transfer; + + obj.m_from_account = o.from; + obj.m_to_account = o.to; + obj.m_transaction_amount = o.amount; + obj.m_transaction_fee = o.fee; + obj.m_transaction_encrypted_memo = o.memo; + obj.m_str_description = "transfer"; + obj.m_timestamp = d.head_block_time(); + }); + return void_result(); + } FC_CAPTURE_AND_RETHROW( (o) ) } + } } // graphene::chain diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 84ed649a..86153be7 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1770,18 +1770,30 @@ class wallet_api_impl bool broadcast = false) { try { FC_ASSERT( !self.is_locked() ); - fc::optional asset_obj = get_asset(asset_symbol); - FC_ASSERT(asset_obj, "Could not find asset matching ${asset}", ("asset", asset_symbol)); account_object from_account = get_account(from); - account_object to_account = get_account(to); account_id_type from_id = from_account.id; - account_id_type to_id = get_account(to).get_id(); - transfer_operation xfer_op; + fc::optional asset_obj = get_asset(asset_symbol); + FC_ASSERT(asset_obj, "Could not find asset matching ${asset}", ("asset", asset_symbol)); + + account_object to_account; + object_id_type to_obj_id; + + try { + to_account = get_account(to); + to_obj_id = object_id_type(to_account.id); + } + catch ( fc::exception& e ) + { + to_obj_id = object_id_type(to); + to_account = get_account( get_object(to_obj_id.as()).author); + } + + transfer2_operation xfer_op; xfer_op.from = from_id; - xfer_op.to = to_id; + xfer_op.to = to_obj_id; xfer_op.amount = asset_obj->amount_from_string(amount); if( memo.size() ) From 0d1e759ed7cf928f61467fbd368a563143702814 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Wed, 28 Mar 2018 08:48:50 +0200 Subject: [PATCH 085/136] set level of default logger back to info --- programs/decentd/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/decentd/main.cpp b/programs/decentd/main.cpp index 28ca9292..edcfc814 100644 --- a/programs/decentd/main.cpp +++ b/programs/decentd/main.cpp @@ -309,7 +309,7 @@ void write_default_logging_config_to_stream(std::ostream& out) "# route any messages logged to the default logger to the \"stderr\" logger we\n" "# declared above, if they are info level are higher\n" "[logger.default]\n" - "level=error\n" + "level=info\n" "appenders=stderr\n\n" "# route messages sent to the \"p2p\" logger to the p2p appender declared above\n" "[logger.p2p]\n" From da143c016af1624f0e2ba0eb3b4d049cfb1b9c2b Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 28 Mar 2018 08:55:44 +0200 Subject: [PATCH 086/136] fixed endless loop when connecting --- .../decent/wallet_utility/wallet_utility.hpp | 2 +- libraries/wallet_utility/wallet_utility.cpp | 34 +++++++++++-------- programs/gui_wallet/src/gui_wallet_global.cpp | 22 ++++++++---- programs/gui_wallet/src/gui_wallet_global.hpp | 3 ++ 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/libraries/wallet_utility/include/decent/wallet_utility/wallet_utility.hpp b/libraries/wallet_utility/include/decent/wallet_utility/wallet_utility.hpp index 179f7b6b..bd2081e5 100644 --- a/libraries/wallet_utility/include/decent/wallet_utility/wallet_utility.hpp +++ b/libraries/wallet_utility/include/decent/wallet_utility/wallet_utility.hpp @@ -40,7 +40,7 @@ namespace wallet_utility WalletAPI(); ~WalletAPI(); - void Connent(); + void Connent(std::atomic_bool& cancellation_token); bool Connected(); bool IsNew(); bool IsLocked(); diff --git a/libraries/wallet_utility/wallet_utility.cpp b/libraries/wallet_utility/wallet_utility.cpp index 5953d445..75c410af 100644 --- a/libraries/wallet_utility/wallet_utility.cpp +++ b/libraries/wallet_utility/wallet_utility.cpp @@ -147,7 +147,7 @@ namespace wallet_utility { } - void WalletAPI::Connent() + void WalletAPI::Connent(std::atomic_bool& cancellation_token) { if (Connected()) throw wallet_exception("already connected"); @@ -158,9 +158,10 @@ namespace wallet_utility auto& pimpl = m_pimpl; fc::future future_connect = - m_pthread->async([&pimpl] () -> string + m_pthread->async([&pimpl, &cancellation_token] () -> string { - while (true) + std::string error; + while (! cancellation_token) { try { @@ -173,21 +174,26 @@ namespace wallet_utility } catch(fc::exception const& ex) { - std::string error = ex.what(); + error = ex.what(); } catch(std::exception const& ex) { - std::string error = ex.what(); + error = ex.what(); } - catch(...) - { + if (!error.empty()) { + //log error ?? } } + + if (cancellation_token) { + std::cout << "cancelation_token" << std::endl; + } + return string(); }); string str_result = future_connect.wait(); - if (false == str_result.empty()) + if (!str_result.empty()) throw wallet_exception(str_result); } @@ -199,7 +205,7 @@ namespace wallet_utility bool WalletAPI::IsNew() { - if (false == Connected()) + if (!Connected()) throw wallet_exception("not yet connected"); std::lock_guard lock(m_mutex); @@ -214,7 +220,7 @@ namespace wallet_utility } bool WalletAPI::IsLocked() { - if (false == Connected()) + if (!Connected()) throw wallet_exception("not yet connected"); std::lock_guard lock(m_mutex); @@ -229,7 +235,7 @@ namespace wallet_utility } std::chrono::system_clock::time_point WalletAPI::HeadBlockTime() { - if (false == Connected()) + if (!Connected()) throw wallet_exception("not yet connected"); std::lock_guard lock(m_mutex); @@ -245,7 +251,7 @@ namespace wallet_utility } void WalletAPI::SetPassword(string const& str_password) { - if (false == Connected()) + if (!Connected()) throw wallet_exception("not yet connected"); std::lock_guard lock(m_mutex); @@ -260,7 +266,7 @@ namespace wallet_utility } void WalletAPI::Unlock(string const& str_password) { - if (false == Connected()) + if (!Connected()) throw wallet_exception("not yet connected"); std::lock_guard lock(m_mutex); @@ -315,7 +321,7 @@ namespace wallet_utility void WalletAPI::SaveWalletFile() { - if (false == Connected()) + if (!Connected()) throw wallet_exception("not yet connected"); fc::path wallet_file(decent_path_finder::instance().get_decent_home() / "wallet.json"); diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index 1a7eb6af..5c4608db 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -485,16 +485,18 @@ QString convertDateTimeToLocale(const std::string& s) // // WalletOperator // -WalletOperator::WalletOperator() -: QObject(nullptr) +WalletOperator::WalletOperator() : QObject() , m_wallet_api() { - } WalletOperator::~WalletOperator() { +} +void WalletOperator::cancel() +{ + m_cancellation_token = true; } void WalletOperator::slot_connect() @@ -502,7 +504,7 @@ void WalletOperator::slot_connect() std::string str_error; try { - m_wallet_api.Connent(); + m_wallet_api.Connent(m_cancellation_token); } catch(const std::exception& ex) { @@ -511,10 +513,10 @@ void WalletOperator::slot_connect() emit signal_connected(str_error); } + // // Asset // - double Asset::to_value() const { uint64_t amount = m_amount / m_scale; @@ -682,9 +684,15 @@ void Globals::stopDaemons() if (backup_state != m_connected_state) emit walletConnectionStatusChanged(backup_state, m_connected_state); - if (m_p_wallet_operator && bConnected) + if (m_p_wallet_operator) { - m_p_wallet_operator->m_wallet_api.SaveWalletFile(); + if (bConnected) { + m_p_wallet_operator->m_wallet_api.SaveWalletFile(); + } + else { + m_p_wallet_operator->cancel(); + m_p_wallet_operator_thread->quit(); + } delete m_p_wallet_operator; m_p_wallet_operator = nullptr; diff --git a/programs/gui_wallet/src/gui_wallet_global.hpp b/programs/gui_wallet/src/gui_wallet_global.hpp index 0af7736a..b1adf876 100644 --- a/programs/gui_wallet/src/gui_wallet_global.hpp +++ b/programs/gui_wallet/src/gui_wallet_global.hpp @@ -98,12 +98,15 @@ namespace gui_wallet WalletOperator(); ~WalletOperator() override; + void cancel(); + public slots: void slot_connect(); signals: void signal_connected(std::string const& str_error); public: WalletAPI m_wallet_api; + std::atomic_bool m_cancellation_token; }; // Asset From 5fae7113c013f165f9198f70f1e67837de81b297 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 28 Mar 2018 09:38:44 +0200 Subject: [PATCH 087/136] fixed windows compile --- libraries/wallet/include/graphene/wallet/wallet.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 62322c46..5ee375c1 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -506,6 +506,7 @@ FC_API( graphene::wallet::wallet_api, (get_message_objects) (get_messages) (get_sent_messages) + ) #if 0 //Debug @@ -522,5 +523,3 @@ FC_API( graphene::wallet::wallet_api, (flood_network) #endif -) - From 251fe733203f5e01b5fb2140a514b1ea2ee56de5 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 28 Mar 2018 10:34:13 +0200 Subject: [PATCH 088/136] fixed crash on start --- programs/gui_wallet/src/mainwindow.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index e742b680..a258f956 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -625,10 +625,12 @@ void MainWindow::slot_importKey() void MainWindow::slot_BrowseToggled(bool toggled) { QWidget* pSender = qobject_cast(sender()); - // - // really a stupid hack to have the state change visible - pSender->setEnabled(false); - pSender->setEnabled(true); + if (pSender) { + // + // really a stupid hack to have the state change visible + pSender->setEnabled(false); + pSender->setEnabled(true); + } TabContentManager* pActiveTab = m_pTabBrowse; Q_ASSERT(pActiveTab); From 5a0e55224ff36031fe5c1aa9644b7e3344867443 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 28 Mar 2018 10:42:15 +0200 Subject: [PATCH 089/136] fixed windows compile --- programs/gui_wallet/stdafx.h | 1 + 1 file changed, 1 insertion(+) diff --git a/programs/gui_wallet/stdafx.h b/programs/gui_wallet/stdafx.h index 3d10d633..59c96522 100644 --- a/programs/gui_wallet/stdafx.h +++ b/programs/gui_wallet/stdafx.h @@ -55,6 +55,7 @@ #include #include #include +#include #include #include From 8a29fefa3c9ef307708de469bd120c9f5fdfd0db Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 28 Mar 2018 14:40:01 +0200 Subject: [PATCH 090/136] UI various fixes and improvements --- .../gui_wallet/src/browse_content_tab.cpp | 23 +++++-- .../gui_wallet/src/browse_content_tab.hpp | 3 +- programs/gui_wallet/src/decent_line_edit.cpp | 2 + programs/gui_wallet/src/decent_line_edit.hpp | 3 +- programs/gui_wallet/src/gui_wallet_global.cpp | 29 ++++++-- programs/gui_wallet/src/gui_wallet_global.hpp | 5 +- programs/gui_wallet/src/mainwindow.cpp | 8 +-- programs/gui_wallet/src/purchased_tab.cpp | 20 ++++-- programs/gui_wallet/src/purchased_tab.hpp | 1 + programs/gui_wallet/src/richdialog.cpp | 67 ++++++++++++------- programs/gui_wallet/src/richdialog.hpp | 3 +- programs/gui_wallet/src/upload_popup.cpp | 10 ++- programs/gui_wallet/src/upload_tab.cpp | 7 +- programs/gui_wallet/styles/white_green.css | 9 +++ 14 files changed, 136 insertions(+), 54 deletions(-) diff --git a/programs/gui_wallet/src/browse_content_tab.cpp b/programs/gui_wallet/src/browse_content_tab.cpp index ef80edc2..192834fc 100644 --- a/programs/gui_wallet/src/browse_content_tab.cpp +++ b/programs/gui_wallet/src/browse_content_tab.cpp @@ -56,6 +56,10 @@ BrowseContentTab::BrowseContentTab(QWidget* pParent, QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &BrowseContentTab::slot_SortingChanged); + + QObject::connect(m_pTableWidget, &DecentTable::cellClicked, + this, &BrowseContentTab::slot_cellClicked); + } void BrowseContentTab::timeToUpdate(const std::string& result) @@ -85,7 +89,6 @@ void BrowseContentTab::timeToUpdate(const std::string& result) cont.synopsis = json_item["synopsis"].get(); cont.URI = json_item["URI"].get(); cont.created = json_item["created"].get(); - cont.created = cont.created.substr(0, cont.created.find("T")); cont.expiration = json_item["expiration"].get(); cont.size = json_item["size"].get(); @@ -140,6 +143,15 @@ void BrowseContentTab::slot_Details(int iIndex) this, &BrowseContentTab::slot_Bought); } +void BrowseContentTab::slot_cellClicked(int row, int /*col*/) +{ + if (row < 0 || row >= _digital_contents.size()) { + throw std::out_of_range("Content index is out of range"); + } + + slot_Details(row); +} + void BrowseContentTab::slot_Bought() { Globals::instance().signal_showPurchasedTab(); @@ -208,16 +220,17 @@ void BrowseContentTab::ShowDigitalContentsGUI() { // Uploaded colIndex++; - m_pTableWidget->setItem(index, colIndex, new QTableWidgetItem(convertDateToLocale(item.created))); + std::string created_date = item.created.substr(0, item.created.find("T")); + m_pTableWidget->setItem(index, colIndex, new QTableWidgetItem(convertDateToLocale(created_date))); m_pTableWidget->item(index, colIndex)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter); m_pTableWidget->item(index, colIndex)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); // Expiration colIndex++; - QDateTime time = QDateTime::fromString(QString::fromStdString(item.expiration), "yyyy-MM-ddTHH:mm:ss"); - std::string e_str = CalculateRemainingTime(QDateTime::currentDateTime(), time); + QDateTime time = convertStringToDateTime(item.expiration); + QString e_str = CalculateRemainingTime(QDateTime::currentDateTime(), time); - m_pTableWidget->setItem(index, colIndex, new QTableWidgetItem(QString::fromStdString(e_str))); + m_pTableWidget->setItem(index, colIndex, new QTableWidgetItem(e_str)); m_pTableWidget->item(index, colIndex)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter); m_pTableWidget->item(index, colIndex)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); diff --git a/programs/gui_wallet/src/browse_content_tab.hpp b/programs/gui_wallet/src/browse_content_tab.hpp index 4638d117..74b543f4 100644 --- a/programs/gui_wallet/src/browse_content_tab.hpp +++ b/programs/gui_wallet/src/browse_content_tab.hpp @@ -1,4 +1,4 @@ -/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ #pragma once #include @@ -34,6 +34,7 @@ namespace gui_wallet void slot_Bought(); void slot_SearchTermChanged(QString const& strSearchTerm); void slot_SortingChanged(int); + void slot_cellClicked(int row, int col); protected: DecentTable* m_pTableWidget; diff --git a/programs/gui_wallet/src/decent_line_edit.cpp b/programs/gui_wallet/src/decent_line_edit.cpp index 1745ac31..a66bfb42 100644 --- a/programs/gui_wallet/src/decent_line_edit.cpp +++ b/programs/gui_wallet/src/decent_line_edit.cpp @@ -29,6 +29,8 @@ namespace gui_wallet switch (enName) { + case DlgImport: + setProperty("name", "import_dlg"); case None: default: break; diff --git a/programs/gui_wallet/src/decent_line_edit.hpp b/programs/gui_wallet/src/decent_line_edit.hpp index 8d5bf6db..6525ab89 100644 --- a/programs/gui_wallet/src/decent_line_edit.hpp +++ b/programs/gui_wallet/src/decent_line_edit.hpp @@ -18,7 +18,8 @@ namespace gui_wallet enum eName { - None + None, + DlgImport }; DecentLineEdit(QWidget* pParent, eType enType = Default, eName = None); diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index 5c4608db..b4d7dc1c 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -171,11 +171,11 @@ static CalendarDuration CalculateCalendarDuration(QDateTime const& dt, QDateTime } } -std::string CalculateRemainingTime(QDateTime const& dt, QDateTime const& dtFuture) +QString CalculateRemainingTime(const QDateTime& dt, const QDateTime& dtFuture) { CalendarDuration duration = CalculateCalendarDuration(dt, dtFuture); if (duration.sign == CalendarDuration::sign_negative) - return "expired"; + return QString(QObject::tr("expired")); else { std::vector arrParts; @@ -191,15 +191,17 @@ std::string CalculateRemainingTime(QDateTime const& dt, QDateTime const& dtFutur if (duration.minutes) arrParts.push_back(std::to_string(duration.minutes) + " min"); - std::string str_result; + QString str_result; if (arrParts.empty()) - str_result = "expiring in a minute"; + str_result = QString(QObject::tr("expiring in a minute")); else { - str_result = arrParts.front(); + str_result = QString::fromStdString( arrParts.front()); - if (arrParts.size() > 1) - str_result += " " + arrParts[1]; + if (arrParts.size() > 1) { + str_result.append(" "); + str_result.append(QString::fromStdString(arrParts[1])); + } } return str_result; @@ -471,6 +473,11 @@ QString convertDateToLocale(const std::string& s) return Globals::instance().locale().toString(time, QLocale::ShortFormat); } +QDateTime convertStringToDateTime(const std::string& s) +{ + return QDateTime::fromString(QString::fromStdString(s), "yyyy-MM-ddTHH:mm:ss"); +} + QString convertDateTimeToLocale(const std::string& s) { QDateTime time = QDateTime::fromString(QString::fromStdString(s), "yyyy-MM-dd hh:mm:ss"); @@ -480,7 +487,15 @@ QString convertDateTimeToLocale(const std::string& s) return Globals::instance().locale().toString(time, QLocale::ShortFormat); } +QString convertDateTimeToLocale2(const std::string& s) +{ + QDateTime time = convertStringToDateTime(s); + if (!time.isValid()) { + return QString("EEE"); + } + return Globals::instance().locale().toString(time, QLocale::ShortFormat); +} // // WalletOperator diff --git a/programs/gui_wallet/src/gui_wallet_global.hpp b/programs/gui_wallet/src/gui_wallet_global.hpp index b1adf876..57e7a908 100644 --- a/programs/gui_wallet/src/gui_wallet_global.hpp +++ b/programs/gui_wallet/src/gui_wallet_global.hpp @@ -73,7 +73,7 @@ namespace gui_wallet const int g_max_number_of_decimal_places = 8; //number of decimal places showed in asset price class StackLayerWidget; - std::string CalculateRemainingTime(QDateTime const& dt, QDateTime const& dtFuture); + QString CalculateRemainingTime(const QDateTime& dt, const QDateTime& dtFuture); QString CalculateRemainingTime_Behind(QDateTime const& dt, QDateTime const& dtFuture); void ShowMessageBox(QString const& strTitle, @@ -86,8 +86,11 @@ namespace gui_wallet std::size_t extra_space(const std::string& s) noexcept; std::string unescape_string(const std::string& s); std::string escape_string(const std::string& s); + QDateTime convertStringToDateTime(const std::string& s); QString convertDateToLocale(const std::string& s); QString convertDateTimeToLocale(const std::string& s); + QString convertDateTimeToLocale2(const std::string& s); + using WalletAPI = decent::wallet_utility::WalletAPI; diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 6bb880eb..1f42e91a 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -458,7 +458,7 @@ void MainWindow::closeSplash(bool bGonnaCoverAgain) StackLayerWidget* pLayer = nullptr; - signal_setSplashMainText(QString()); + emit signal_setSplashMainText(QString()); Globals::instance().statusShowMessage(QString()); if (!bGonnaCoverAgain) @@ -466,12 +466,12 @@ void MainWindow::closeSplash(bool bGonnaCoverAgain) if (Globals::instance().getWallet().IsNew()) { pLayer = new PasswordWidget(nullptr, PasswordWidget::eSetPassword); - signal_setSplashMainText(tr("Please set a password to encrypt your wallet")); + emit signal_setSplashMainText(tr("Please set a password to encrypt your wallet")); } else if (Globals::instance().getWallet().IsLocked()) { pLayer = new PasswordWidget(nullptr, PasswordWidget::eUnlock); - signal_setSplashMainText(tr("Please unlock your wallet")); + emit signal_setSplashMainText(tr("Please unlock your wallet")); } else { @@ -479,7 +479,7 @@ void MainWindow::closeSplash(bool bGonnaCoverAgain) if (accounts.empty()) { pLayer = new ImportKeyWidget(nullptr); - signal_setSplashMainText(tr("Please import your account in order to proceed")); + emit signal_setSplashMainText(tr("Please import your account in order to proceed")); } } } diff --git a/programs/gui_wallet/src/purchased_tab.cpp b/programs/gui_wallet/src/purchased_tab.cpp index a58128ed..f426420b 100644 --- a/programs/gui_wallet/src/purchased_tab.cpp +++ b/programs/gui_wallet/src/purchased_tab.cpp @@ -63,6 +63,9 @@ PurchasedTab::PurchasedTab(QWidget* pParent, QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &PurchasedTab::slot_SortingChanged); + + QObject::connect(m_pTableWidget, &DecentTable::cellClicked, + this, &PurchasedTab::slot_cellClicked); } // @@ -113,8 +116,7 @@ void PurchasedTab::timeToUpdate(const std::string& result) contentObject.created = content["created"].get(); contentObject.created = contentObject.created.substr(0, contentObject.created.find("T")); contentObject.purchased_time = content["expiration_or_delivery_time"].get(); - contentObject.purchased_time = contentObject.purchased_time.substr(0, contentObject.purchased_time.find("T")); - + contentObject.size = content["size"].get(); contentObject.id = content["id"].get(); contentObject.hash = content["hash"].get(); @@ -192,8 +194,9 @@ void PurchasedTab::ShowDigitalContentsGUI() m_pTableWidget->setItem(iIndex, 0, new QTableWidgetItem(QString::fromStdString(title))); m_pTableWidget->setItem(iIndex, 1, new QTableWidgetItem(QString::number(contentObject.size) + tr(" MB"))); m_pTableWidget->setItem(iIndex, 2, new QTableWidgetItem(contentObject.price.getString())); - - m_pTableWidget->setItem(iIndex, 3, new QTableWidgetItem(convertDateToLocale(contentObject.purchased_time))); + + std::string purchase_date = contentObject.purchased_time.substr(0, contentObject.purchased_time.find("T")); + m_pTableWidget->setItem(iIndex, 3, new QTableWidgetItem(convertDateToLocale(purchase_date))); uint32_t total_key_parts = contentObject.total_key_parts; uint32_t received_key_parts = contentObject.received_key_parts; @@ -338,6 +341,15 @@ void PurchasedTab::slot_Details(int iIndex) Globals::instance().signal_stackWidgetPush(pDetailsDialog); } +void PurchasedTab::slot_cellClicked(int row, int /*col*/) +{ + if (row < 0 || row >= _current_content.size()) { + throw std::out_of_range("Content index is out of range"); + } + + slot_Details(row); +} + void PurchasedTab::ShowMessageBox(const std::string& message) { if (message.empty()) diff --git a/programs/gui_wallet/src/purchased_tab.hpp b/programs/gui_wallet/src/purchased_tab.hpp index 2b7c42b0..a93c3351 100644 --- a/programs/gui_wallet/src/purchased_tab.hpp +++ b/programs/gui_wallet/src/purchased_tab.hpp @@ -35,6 +35,7 @@ public slots: void slot_ExtractPackage(int); void slot_Details(int); void slot_SortingChanged(int); + void slot_cellClicked(int row, int col); void slot_ExtractionDirSelected(QString const& path); void slot_SearchTermChanged(QString const& strSearchTerm); diff --git a/programs/gui_wallet/src/richdialog.cpp b/programs/gui_wallet/src/richdialog.cpp index d91641e1..2ee36b8e 100644 --- a/programs/gui_wallet/src/richdialog.cpp +++ b/programs/gui_wallet/src/richdialog.cpp @@ -261,9 +261,9 @@ ImportKeyWidget::ImportKeyWidget(QWidget* parent) : StackLayerWidget(parent) QObject::connect(cancel, &QPushButton::clicked, this, &StackLayerWidget::closed); - DecentLineEdit* name = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); - DecentLineEdit* key = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); - + DecentLineEdit* name = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit, DecentLineEdit::DlgImport); + DecentLineEdit* key = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit, DecentLineEdit::DlgImport); + name->setPlaceholderText(tr("Account name")); name->setAttribute(Qt::WA_MacShowFocusRect, 0); QObject::connect(name, &QLineEdit::textChanged, @@ -387,7 +387,7 @@ UserInfoWidget::UserInfoWidget(QWidget* parent, // ContentInfoWidget::ContentInfoWidget(QWidget* parent, const SDigitalContent& a_cnt_details) : StackLayerWidget(parent) - , m_getItOrPay(GetIt) + , m_getItOrPay(Download) , m_URI(a_cnt_details.URI) , m_amount(a_cnt_details.price.getString()) { @@ -396,6 +396,13 @@ ContentInfoWidget::ContentInfoWidget(QWidget* parent, const SDigitalContent& a_c main_layout->setContentsMargins(0, 0, 0, 15); int iRowIndex = 0; + // Title + // + DecentLabel* pTitleLabel = new DecentLabel(this, DecentLabel::RowLabel); + pTitleLabel->setText(tr("Details of content")); + main_layout->addWidget(pTitleLabel, iRowIndex, 0); + ++iRowIndex; + // Author // DecentLabel* labelAuthorTitle = new DecentLabel(this, DecentLabel::RowLabel); @@ -410,10 +417,10 @@ ContentInfoWidget::ContentInfoWidget(QWidget* parent, const SDigitalContent& a_c // DecentLabel* labelExpirationTitle = new DecentLabel(this, DecentLabel::RowLabel, DecentLabel::Highlighted); DecentLabel* labelExpirationInfo = new DecentLabel(this, DecentLabel::RowLabel, DecentLabel::HighlightedRight); - QDateTime time = QDateTime::fromString(QString::fromStdString(a_cnt_details.expiration), "yyyy-MM-ddTHH:mm:ss"); - std::string e_str = CalculateRemainingTime(QDateTime::currentDateTime(), time); + QDateTime time = convertStringToDateTime(a_cnt_details.expiration); + QString e_str = CalculateRemainingTime(QDateTime::currentDateTime(), time); labelExpirationTitle->setText(tr("Expiration")); - labelExpirationInfo->setText(QString::fromStdString(e_str)); + labelExpirationInfo->setText(e_str); main_layout->addWidget(labelExpirationTitle, iRowIndex, 0); main_layout->addWidget(labelExpirationInfo, iRowIndex, 1); ++iRowIndex; @@ -423,7 +430,7 @@ ContentInfoWidget::ContentInfoWidget(QWidget* parent, const SDigitalContent& a_c DecentLabel* labelUploadedTitle = new DecentLabel(this, DecentLabel::RowLabel); DecentLabel* labelUploadedInfo = new DecentLabel(this, DecentLabel::RowLabel, DecentLabel::Right); labelUploadedTitle->setText(tr("Uploaded")); - labelUploadedInfo->setText(QString::fromStdString(a_cnt_details.created)); + labelUploadedInfo->setText(convertDateTimeToLocale2(a_cnt_details.created)); main_layout->addWidget(labelUploadedTitle, iRowIndex, 0); main_layout->addWidget(labelUploadedInfo, iRowIndex, 1); ++iRowIndex; @@ -433,7 +440,7 @@ ContentInfoWidget::ContentInfoWidget(QWidget* parent, const SDigitalContent& a_c DecentLabel* labelAmountTitle = new DecentLabel(this, DecentLabel::RowLabel, DecentLabel::Highlighted); DecentLabel* labelAmountInfo = new DecentLabel(this, DecentLabel::RowLabel, DecentLabel::HighlightedRight); QString str_price = a_cnt_details.price.getString(); - labelAmountTitle->setText(tr("Amount")); + labelAmountTitle->setText(tr("Price")); labelAmountInfo->setText(str_price); main_layout->addWidget(labelAmountTitle, iRowIndex, 0); main_layout->addWidget(labelAmountInfo, iRowIndex, 1); @@ -479,7 +486,16 @@ ContentInfoWidget::ContentInfoWidget(QWidget* parent, const SDigitalContent& a_c DecentButton* getItButton = new DecentButton(this, DecentButton::DialogAction); DecentButton* cancelButton = new DecentButton(this, DecentButton::DialogCancel); - getItButton->setText(tr("Get it!")); + + if (a_cnt_details.price.m_amount == 0) { + m_getItOrPay = Download; + getItButton->setText(tr("Download")); + } + else { + m_getItOrPay = PayAndDownload; + getItButton->setText(tr("Buy && Download")); + } + cancelButton->setText(tr("Back")); QObject::connect(getItButton, &QPushButton::clicked, @@ -507,18 +523,16 @@ ContentInfoWidget::ContentInfoWidget(QWidget* parent, const SDigitalContent& a_c void ContentInfoWidget::ButtonWasClicked() { - QPushButton* button = (QPushButton*) sender(); - if (m_amount == "Free" || - m_getItOrPay == Pay) - { - m_getItOrPay = GetIt; - button->setText(tr("Get It!")); - Buy(); + QPushButton* pButton = qobject_cast(sender()); + Q_ASSERT(pButton); + + if (m_getItOrPay == PayAndDownload) { + m_getItOrPay = Download; + pButton->setText(tr("Download")); } - else - { - m_getItOrPay = Pay; - button->setText((tr("Pay") + " " + m_amount)); + else if (m_getItOrPay == Download) { + + Buy(); } } @@ -558,6 +572,13 @@ ContentReviewWidget::ContentReviewWidget(QWidget* parent, const SDigitalContent& main_layout->setContentsMargins(0, 0, 0, 15); int iRowIndex = 0; + // Title + // + DecentLabel* pTitleLabel = new DecentLabel(this, DecentLabel::RowLabel); + pTitleLabel->setText(tr("Details of content")); + main_layout->addWidget(pTitleLabel, iRowIndex, 0); + ++iRowIndex; + // Author // DecentLabel* labelAuthorTitle = new DecentLabel(this, DecentLabel::RowLabel, DecentLabel::Highlighted); @@ -573,7 +594,7 @@ ContentReviewWidget::ContentReviewWidget(QWidget* parent, const SDigitalContent& DecentLabel* labelExpirationTitle = new DecentLabel(this, DecentLabel::RowLabel); DecentLabel* labelExpirationInfo = new DecentLabel(this, DecentLabel::RowLabel, DecentLabel::Right); labelExpirationTitle->setText(tr("Purchased")); - labelExpirationInfo->setText(a_cnt_details.purchased_time.c_str()); + labelExpirationInfo->setText(convertDateTimeToLocale2(a_cnt_details.purchased_time)); main_layout->addWidget(labelExpirationTitle, iRowIndex, 0); main_layout->addWidget(labelExpirationInfo, iRowIndex, 1); ++iRowIndex; @@ -583,7 +604,7 @@ ContentReviewWidget::ContentReviewWidget(QWidget* parent, const SDigitalContent& DecentLabel* labelAmountTitle = new DecentLabel(this, DecentLabel::RowLabel, DecentLabel::Highlighted); DecentLabel* labelAmountInfo = new DecentLabel(this, DecentLabel::RowLabel, DecentLabel::HighlightedRight); QString str_price = a_cnt_details.price.getString(); - labelAmountTitle->setText(tr("Amount")); + labelAmountTitle->setText(tr("Price")); labelAmountInfo->setText(str_price); main_layout->addWidget(labelAmountTitle, iRowIndex, 0); main_layout->addWidget(labelAmountInfo, iRowIndex, 1); diff --git a/programs/gui_wallet/src/richdialog.hpp b/programs/gui_wallet/src/richdialog.hpp index 6ca8412a..423c6438 100644 --- a/programs/gui_wallet/src/richdialog.hpp +++ b/programs/gui_wallet/src/richdialog.hpp @@ -8,6 +8,7 @@ class QTextEdit; class QCloseEvent; +class QPushButton; namespace gui_wallet { @@ -120,7 +121,7 @@ public slots: void ButtonWasClicked(); private: - enum GetItOrPay {GetIt, Pay}; + enum GetItOrPay { PayAndDownload, Download }; GetItOrPay m_getItOrPay; std::string m_URI; QString m_amount; diff --git a/programs/gui_wallet/src/upload_popup.cpp b/programs/gui_wallet/src/upload_popup.cpp index a745d63d..ba3fdb9e 100644 --- a/programs/gui_wallet/src/upload_popup.cpp +++ b/programs/gui_wallet/src/upload_popup.cpp @@ -6,6 +6,7 @@ #include "decent_button.hpp" #include "decent_text_edit.hpp" #include "decent_line_edit.hpp" +#include "decent_label.hpp" #ifndef _MSC_VER #include @@ -52,7 +53,9 @@ Upload_popup::Upload_popup(QWidget* pParent, const std::string& id_modify/* = st } // - setWindowTitle(tr("Upload new content")); + DecentLabel* pTitleLabel = new DecentLabel(this); + pTitleLabel->setText(tr("Upload new content")); + // // Title field // @@ -86,7 +89,7 @@ Upload_popup::Upload_popup(QWidget* pParent, const std::string& id_modify/* = st pPriceLabel->setText(tr("Price")); Asset min_price_asset = Globals::instance().asset(1); - double min_price = min_price_asset.to_value(); + double min_price = 0; //min_price_asset.to_value(); Asset max_price_asset = Globals::instance().asset(100000 * pow(10, g_max_number_of_decimal_places)); double max_price = max_price_asset.to_value(); @@ -166,6 +169,7 @@ Upload_popup::Upload_popup(QWidget* pParent, const std::string& id_modify/* = st // Layouts // QVBoxLayout* pFirstRow = new QVBoxLayout(); + pFirstRow->addWidget(pTitleLabel); pFirstRow->addWidget(pTitleText); pFirstRow->addWidget(m_pDescriptionText); @@ -298,7 +302,7 @@ QStringList Upload_popup::getChosenPublishers() const Publisher const& seeder = seederItem.first; if (seederItem.second) - lstSummary << seeder.m_str_name.c_str(); + lstSummary << QString::fromStdString(seeder.m_str_name); } return lstSummary; diff --git a/programs/gui_wallet/src/upload_tab.cpp b/programs/gui_wallet/src/upload_tab.cpp index 94557612..0da69e9e 100644 --- a/programs/gui_wallet/src/upload_tab.cpp +++ b/programs/gui_wallet/src/upload_tab.cpp @@ -205,12 +205,11 @@ void Upload_tab::ShowDigitalContentsGUI() // Created m_pTableWidget->setItem(iIndex, eCreated, new QTableWidgetItem(convertDateToLocale(content.created))); - QDateTime time = QDateTime::fromString(QString::fromStdString(content.expiration), "yyyy-MM-ddTHH:mm:ss"); - - std::string e_str = CalculateRemainingTime(QDateTime::currentDateTime(), time); + QDateTime time = convertStringToDateTime(content.expiration); + QString e_str = CalculateRemainingTime(QDateTime::currentDateTime(), time); // Remaining - m_pTableWidget->setItem(iIndex, eRemaining, new QTableWidgetItem(QString::fromStdString(e_str))); + m_pTableWidget->setItem(iIndex, eRemaining, new QTableWidgetItem(e_str)); // Status m_pTableWidget->setItem(iIndex, eStatus, new QTableWidgetItem(QString::fromStdString(content.status))); diff --git a/programs/gui_wallet/styles/white_green.css b/programs/gui_wallet/styles/white_green.css index 9c7c1829..b071a988 100644 --- a/programs/gui_wallet/styles/white_green.css +++ b/programs/gui_wallet/styles/white_green.css @@ -362,6 +362,15 @@ QLineEdit[type='dialoglineedit'] padding-left: 0.5em; padding-right: 0.5em; } +QLineEdit[type='dialoglineedit'][name='import_dlg'] +{ + min-width: 22.0em; + min-height: 2.5em; + max-width: 25em; + max-height: 2.5em; + padding-left: 0.5em; + padding-right: 0.5em; +} QTextEdit[type='info'] { border: 0px; From 81c82ba0c13ad6b41c2e821b97633c611042d405 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 28 Mar 2018 15:18:12 +0200 Subject: [PATCH 091/136] fixed dates --- programs/gui_wallet/src/gui_wallet_global.cpp | 4 ++++ programs/gui_wallet/src/richdialog.cpp | 6 +++++- programs/gui_wallet/src/upload_tab.cpp | 8 ++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index b4d7dc1c..3a16a3bb 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -489,6 +489,10 @@ QString convertDateTimeToLocale(const std::string& s) } QString convertDateTimeToLocale2(const std::string& s) { + if (s.empty()) { + return QString(); + } + QDateTime time = convertStringToDateTime(s); if (!time.isValid()) { return QString("EEE"); diff --git a/programs/gui_wallet/src/richdialog.cpp b/programs/gui_wallet/src/richdialog.cpp index 2ee36b8e..d94d0a4d 100644 --- a/programs/gui_wallet/src/richdialog.cpp +++ b/programs/gui_wallet/src/richdialog.cpp @@ -430,7 +430,11 @@ ContentInfoWidget::ContentInfoWidget(QWidget* parent, const SDigitalContent& a_c DecentLabel* labelUploadedTitle = new DecentLabel(this, DecentLabel::RowLabel); DecentLabel* labelUploadedInfo = new DecentLabel(this, DecentLabel::RowLabel, DecentLabel::Right); labelUploadedTitle->setText(tr("Uploaded")); - labelUploadedInfo->setText(convertDateTimeToLocale2(a_cnt_details.created)); + std::string created_date; + if (a_cnt_details.created != "1970-01-01") { + created_date = a_cnt_details.created; + } + labelUploadedInfo->setText(convertDateTimeToLocale2(created_date)); main_layout->addWidget(labelUploadedTitle, iRowIndex, 0); main_layout->addWidget(labelUploadedInfo, iRowIndex, 1); ++iRowIndex; diff --git a/programs/gui_wallet/src/upload_tab.cpp b/programs/gui_wallet/src/upload_tab.cpp index 0da69e9e..0d11043b 100644 --- a/programs/gui_wallet/src/upload_tab.cpp +++ b/programs/gui_wallet/src/upload_tab.cpp @@ -99,7 +99,6 @@ void Upload_tab::timeToUpdate(const string& result) content.synopsis = json_content["synopsis"].get(); content.URI = json_content["URI"].get(); content.created = json_content["created"].get(); - content.created = content.created.substr(0, content.created.find("T")); content.expiration = json_content["expiration"].get(); content.size = json_content["size"].get(); content.status = json_content["status"].get(); @@ -203,7 +202,12 @@ void Upload_tab::ShowDigitalContentsGUI() m_pTableWidget->setItem(iIndex, ePrice, new QTableWidgetItem(content.price.getString())); // Created - m_pTableWidget->setItem(iIndex, eCreated, new QTableWidgetItem(convertDateToLocale(content.created))); + std::string created_date; + if (content.created != "1970-01-01") { + created_date = content.created.substr(0, content.created.find("T")); + } + + m_pTableWidget->setItem(iIndex, eCreated, new QTableWidgetItem(convertDateToLocale(created_date))); QDateTime time = convertStringToDateTime(content.expiration); QString e_str = CalculateRemainingTime(QDateTime::currentDateTime(), time); From ecbd141397f942ace43cea3b3fe383047387cd41 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 28 Mar 2018 23:27:46 +0200 Subject: [PATCH 092/136] first version of voting for miners count (backup copy) --- programs/gui_wallet/CMakeLists.txt | 3 + programs/gui_wallet/src/mainwindow.cpp | 16 ++ programs/gui_wallet/src/mainwindow.hpp | 2 + programs/gui_wallet/src/mining_vote_popup.cpp | 149 ++++++++++++++++++ programs/gui_wallet/src/mining_vote_popup.hpp | 38 +++++ 5 files changed, 208 insertions(+) create mode 100644 programs/gui_wallet/src/mining_vote_popup.cpp create mode 100644 programs/gui_wallet/src/mining_vote_popup.hpp diff --git a/programs/gui_wallet/CMakeLists.txt b/programs/gui_wallet/CMakeLists.txt index b3539b9e..4f3165a9 100644 --- a/programs/gui_wallet/CMakeLists.txt +++ b/programs/gui_wallet/CMakeLists.txt @@ -49,6 +49,9 @@ add_executable(DECENT MACOSX_BUNDLE src/upload_tab.hpp src/mining_vote_tab.cpp src/mining_vote_tab.hpp + src/mining_vote_popup.cpp + src/mining_vote_popup.hpp + resources.qrc desktop.icns diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index a258f956..730a7957 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -33,6 +33,7 @@ #include "overview_tab.hpp" #include "purchased_tab.hpp" #include "mining_vote_tab.hpp" +#include "mining_vote_popup.hpp" #include "json.hpp" @@ -81,6 +82,7 @@ MainWindow::MainWindow() , m_pActionImportKey(new QAction(tr("Import key"), this)) , m_pActionReplayBlockchain(new QAction(tr("Replay Blockchain"), this)) , m_pActionResyncBlockchain(new QAction(tr("Resync Blockchain"), this)) +, m_pAdvancedMinerVoting(new QAction(tr("Advanced MinerVoting"), this)) #ifdef UPDATE_MANAGER , m_pUpdateManager(new UpdateManager()) #else @@ -345,11 +347,17 @@ MainWindow::MainWindow() QObject::connect(m_pActionResyncBlockchain, &QAction::triggered, this, &MainWindow::slot_resyncBlockChain); + QObject::connect(m_pAdvancedMinerVoting, &QAction::triggered, + this, &MainWindow::slot_advancedMinerVoting); + QMenu* pMenuFile = menuBar()->addMenu(tr("&File")); pMenuFile->addAction(pActionExit); pMenuFile->addAction(m_pActionImportKey); pMenuFile->addAction(m_pActionReplayBlockchain); pMenuFile->addAction(m_pActionResyncBlockchain); + pMenuFile->addAction(m_pAdvancedMinerVoting); + + m_pAdvancedMinerVoting->setDisabled(true); } @@ -622,6 +630,12 @@ void MainWindow::slot_importKey() slot_stackWidgetPush(import_key); } +void MainWindow::slot_advancedMinerVoting() +{ + MiningVotePopup* mining_vote = new MiningVotePopup(nullptr); + slot_stackWidgetPush(mining_vote); +} + void MainWindow::slot_BrowseToggled(bool toggled) { QWidget* pSender = qobject_cast(sender()); @@ -795,6 +809,8 @@ void MainWindow::slot_MinerVotingToggled(bool toggled) Q_ASSERT(pFilter); pFilter->setHidden(!toggled); + m_pAdvancedMinerVoting->setEnabled(toggled); + // if (toggled) { diff --git a/programs/gui_wallet/src/mainwindow.hpp b/programs/gui_wallet/src/mainwindow.hpp index e61dc0a7..bb6e3ca6 100644 --- a/programs/gui_wallet/src/mainwindow.hpp +++ b/programs/gui_wallet/src/mainwindow.hpp @@ -50,6 +50,7 @@ protected slots: void slot_UsersToggled(bool toggled); void slot_PurchasedToggled(bool toggled); void slot_MinerVotingToggled(bool toggled); + void slot_advancedMinerVoting(); void DisplayWalletContentGUI(); @@ -99,6 +100,7 @@ protected slots: QAction* m_pActionImportKey; QAction* m_pActionReplayBlockchain; QAction* m_pActionResyncBlockchain; + QAction* m_pAdvancedMinerVoting; UpdateManager* m_pUpdateManager; diff --git a/programs/gui_wallet/src/mining_vote_popup.cpp b/programs/gui_wallet/src/mining_vote_popup.cpp new file mode 100644 index 00000000..5922bb91 --- /dev/null +++ b/programs/gui_wallet/src/mining_vote_popup.cpp @@ -0,0 +1,149 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +#include "stdafx.h" + +#include "gui_wallet_global.hpp" +#include "decent_button.hpp" +#include "decent_line_edit.hpp" +#include "mining_vote_popup.hpp" + +#include +#include +#include + +namespace gui_wallet { + +MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) +, m_minersVotedNum(0) +, m_curMinersVotedFor(0) +{ + + uint numOfActiveMiners = getNumberOfActualMiners(); + getMinerVotesForAccount(Globals::instance().getCurrentUser() ); + + m_minersVotedNum = 2; + + + QLabel* pInfoTextLabel = new QLabel(this); + pInfoTextLabel->setText(tr("bla bla bla blaaaa...blaaaa.. blaaaa")); + + + QLabel* pMinersVoteNumLabel = new QLabel(this); + pMinersVoteNumLabel->setText(tr("Number of miners you vote for")); + + QIntValidator* numValidator = new QIntValidator(0, 1001, this); + + m_pMinersNumVote = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); + m_pMinersNumVote->setValidator(numValidator); + m_pMinersNumVote->setAttribute(Qt::WA_MacShowFocusRect, 0); + m_pMinersNumVote->setTextMargins(5, 5, 5, 5); + if (m_minersVotedNum > 0) { + m_pMinersNumVote->setText(QString::number(m_minersVotedNum)); + } + + // Info + QLabel* pUserCurrVotesLabel = new QLabel(this); + pUserCurrVotesLabel->setText(QString(tr("Your miner votes count is %1.")).arg(m_curMinersVotedFor) ); + + m_pVoteButton = new DecentButton(this, DecentButton::DialogAction); + m_pResetButton = new DecentButton(this, DecentButton::DialogAction); + DecentButton* pCancelButton = new DecentButton(this, DecentButton::DialogCancel); + + m_pVoteButton->setText(tr("Apply Vote")); + m_pVoteButton->setFont(PopupButtonBigFont()); + m_pVoteButton->setEnabled(false); + + m_pResetButton->setText(tr("Reset Vote")); + m_pResetButton->setFont(PopupButtonBigFont()); + m_pResetButton->setEnabled(m_minersVotedNum > 0); + + pCancelButton->setText(tr("Back")); + pCancelButton->setFont(PopupButtonBigFont()); + + QHBoxLayout* pRow1Layout = new QHBoxLayout; + pRow1Layout->addWidget(pInfoTextLabel); + + QHBoxLayout* pRow2Layout = new QHBoxLayout; + pRow2Layout->addWidget(pMinersVoteNumLabel); + pRow2Layout->addWidget(m_pMinersNumVote); + + QHBoxLayout* pRow3Layout = new QHBoxLayout; + pRow3Layout->addWidget(pUserCurrVotesLabel); + + QHBoxLayout* pButtonsLayout = new QHBoxLayout; + pButtonsLayout->setContentsMargins(20, 20, 20, 20); + pButtonsLayout->addWidget(m_pVoteButton); + pButtonsLayout->addWidget(m_pResetButton); + pButtonsLayout->addWidget(pCancelButton); + + QVBoxLayout* pMainLayout = new QVBoxLayout; +// pMainLayout->addWidget(pTitleText); +// pMainLayout->addWidget(m_pDescriptionText); +// pMainLayout->addLayout(pLifeTimeRow); +// pMainLayout->addLayout(pPriceRow); +// pMainLayout->addLayout(pSeedersRow); +// pMainLayout->addLayout(pContentRow); +// pMainLayout->addLayout(pSamplesRow); +// pMainLayout->addLayout(pPublishTextRow); + pMainLayout->addLayout(pRow1Layout); + pMainLayout->addLayout(pRow2Layout); + pMainLayout->addLayout(pRow3Layout); + pMainLayout->addLayout(pButtonsLayout); + pMainLayout->setContentsMargins(10, 10, 10, 10); + setLayout(pMainLayout); + + QObject::connect(pCancelButton, &QPushButton::clicked, + this, &StackLayerWidget::closed); + + QObject::connect(m_pMinersNumVote, &DecentLineEdit::textChanged, + this, &MiningVotePopup::slot_MinersNumVoteChanged); + + QObject::connect(m_pVoteButton, &QPushButton::clicked, + this, &MiningVotePopup::slot_voteClicked); + + +} + +MiningVotePopup::~MiningVotePopup() +{ +} + +uint MiningVotePopup::getNumberOfActualMiners() +{ + nlohmann::json global_prop_info = Globals::instance().runTaskParse("get_global_properties"); + nlohmann::json active_miners = global_prop_info["active_miners"]; + + return active_miners.size(); +} + +void MiningVotePopup::getMinerVotesForAccount(const std::string& account_name) +{ + std::string cmd = "get_account "; + cmd += account_name; + + nlohmann::json account_obj = Globals::instance().runTaskParse(cmd); + + std::cout << account_obj["options"] << std::endl; + + m_minersVotedNum = account_obj["options"]["num_miner"].get(); + m_curMinersVotedFor = account_obj["options"]["votes"].size(); + +} + +void MiningVotePopup::slot_MinersNumVoteChanged(const QString& value) +{ + uint numMiners = value.toUInt(); + + m_pVoteButton->setEnabled(numMiners > 0); +} + +void MiningVotePopup::slot_voteClicked() +{ + uint numMiners = m_pMinersNumVote->text().toUInt(); + + //TODO: apply number of miners.. + +} + + + +} diff --git a/programs/gui_wallet/src/mining_vote_popup.hpp b/programs/gui_wallet/src/mining_vote_popup.hpp new file mode 100644 index 00000000..17b354a8 --- /dev/null +++ b/programs/gui_wallet/src/mining_vote_popup.hpp @@ -0,0 +1,38 @@ +/* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ +#pragma once + +#include "richdialog.hpp" + +class QWidget; + +namespace gui_wallet { + + class DecentButton; + class DecentLineEdit; + + class MiningVotePopup : public StackLayerWidget { + Q_OBJECT + public: + MiningVotePopup(QWidget* pParent); + ~MiningVotePopup(); + + private slots: + void slot_MinersNumVoteChanged(const QString& value); + void slot_voteClicked(); + + private: + uint getNumberOfActualMiners(); + void getMinerVotesForAccount(const std::string& account_name); + private: + + uint m_minersVotedNum; + uint m_curMinersVotedFor; + + DecentLineEdit* m_pMinersNumVote; + DecentButton* m_pVoteButton; + DecentButton* m_pResetButton; + + }; + + +} //namespace \ No newline at end of file From d5501066a0741f4144dfc0e254df1035d8704e67 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 29 Mar 2018 10:02:31 +0200 Subject: [PATCH 093/136] added submit desired number of miners and some fixes and improvements --- programs/gui_wallet/src/mining_vote_popup.cpp | 55 ++++++++++++++++--- programs/gui_wallet/src/mining_vote_popup.hpp | 4 ++ 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/programs/gui_wallet/src/mining_vote_popup.cpp b/programs/gui_wallet/src/mining_vote_popup.cpp index 5922bb91..6cd5316e 100644 --- a/programs/gui_wallet/src/mining_vote_popup.cpp +++ b/programs/gui_wallet/src/mining_vote_popup.cpp @@ -20,17 +20,14 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) uint numOfActiveMiners = getNumberOfActualMiners(); getMinerVotesForAccount(Globals::instance().getCurrentUser() ); - m_minersVotedNum = 2; - - QLabel* pInfoTextLabel = new QLabel(this); pInfoTextLabel->setText(tr("bla bla bla blaaaa...blaaaa.. blaaaa")); QLabel* pMinersVoteNumLabel = new QLabel(this); - pMinersVoteNumLabel->setText(tr("Number of miners you vote for")); + pMinersVoteNumLabel->setText(tr("Set desired number of miners")); - QIntValidator* numValidator = new QIntValidator(0, 1001, this); + QIntValidator* numValidator = new QIntValidator(1, 1001, this); m_pMinersNumVote = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); m_pMinersNumVote->setValidator(numValidator); @@ -39,10 +36,13 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) if (m_minersVotedNum > 0) { m_pMinersNumVote->setText(QString::number(m_minersVotedNum)); } + else { + m_pMinersNumVote->setPlaceholderText(QString(tr("Actual miners count is %1")).arg(numOfActiveMiners) ); + } // Info QLabel* pUserCurrVotesLabel = new QLabel(this); - pUserCurrVotesLabel->setText(QString(tr("Your miner votes count is %1.")).arg(m_curMinersVotedFor) ); + pUserCurrVotesLabel->setText(QString(tr("You have voted for %1 miners.")).arg(m_curMinersVotedFor) ); m_pVoteButton = new DecentButton(this, DecentButton::DialogAction); m_pResetButton = new DecentButton(this, DecentButton::DialogAction); @@ -97,9 +97,11 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) QObject::connect(m_pMinersNumVote, &DecentLineEdit::textChanged, this, &MiningVotePopup::slot_MinersNumVoteChanged); - QObject::connect(m_pVoteButton, &QPushButton::clicked, + QObject::connect(m_pVoteButton, &DecentButton::clicked, this, &MiningVotePopup::slot_voteClicked); + QObject::connect(m_pResetButton, &DecentButton::clicked, + this, &MiningVotePopup::slot_voteResetClicked); } @@ -140,10 +142,47 @@ void MiningVotePopup::slot_voteClicked() { uint numMiners = m_pMinersNumVote->text().toUInt(); - //TODO: apply number of miners.. + std::string ret = setDesiredNumOfMiners(Globals::instance().getCurrentUser(), numMiners); + if (!ret.empty()) { + ShowMessageBox(tr("Error"), tr("Failed to vote for miners"), QString::fromStdString(ret)); + } + + closed(); //close the popup +} + +void MiningVotePopup::slot_voteResetClicked() +{ + std::string ret = setDesiredNumOfMiners(Globals::instance().getCurrentUser(), 0); + if (!ret.empty()) { + ShowMessageBox(tr("Error"), tr("Failed to vote for miners"), QString::fromStdString(ret)); + } + closed(); //close the popup } +std::string MiningVotePopup::setDesiredNumOfMiners(const std::string& account_name, uint numMiners) +{ + std::string command = "set_desired_miner_count "; + command += account_name + " "; + command += std::to_string(numMiners); + command += " true"; + + std::string a_result, message; + try + { + a_result = Globals::instance().runTask(command); + if (a_result.find("exception:") != std::string::npos) + { + message = a_result; + } + } + catch (const std::exception& ex) + { + message = ex.what(); + } + + return message; +} } diff --git a/programs/gui_wallet/src/mining_vote_popup.hpp b/programs/gui_wallet/src/mining_vote_popup.hpp index 17b354a8..bd00847d 100644 --- a/programs/gui_wallet/src/mining_vote_popup.hpp +++ b/programs/gui_wallet/src/mining_vote_popup.hpp @@ -19,10 +19,14 @@ namespace gui_wallet { private slots: void slot_MinersNumVoteChanged(const QString& value); void slot_voteClicked(); + void slot_voteResetClicked(); private: uint getNumberOfActualMiners(); void getMinerVotesForAccount(const std::string& account_name); + + std::string setDesiredNumOfMiners(const std::string& account_name, uint number); + private: uint m_minersVotedNum; From 93c3758bcd5f2a302b24efd959bed4961d147d5d Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 29 Mar 2018 10:07:06 +0200 Subject: [PATCH 094/136] fixed windows compilation, missing include --- .../include/decent/wallet_utility/wallet_utility.hpp | 1 + programs/gui_wallet/src/gui_wallet_global.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/libraries/wallet_utility/include/decent/wallet_utility/wallet_utility.hpp b/libraries/wallet_utility/include/decent/wallet_utility/wallet_utility.hpp index bd2081e5..972a5c56 100644 --- a/libraries/wallet_utility/include/decent/wallet_utility/wallet_utility.hpp +++ b/libraries/wallet_utility/include/decent/wallet_utility/wallet_utility.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace graphene { diff --git a/programs/gui_wallet/src/gui_wallet_global.hpp b/programs/gui_wallet/src/gui_wallet_global.hpp index 57e7a908..3b608cd1 100644 --- a/programs/gui_wallet/src/gui_wallet_global.hpp +++ b/programs/gui_wallet/src/gui_wallet_global.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include From 611e9d10af958a41e55877459b3a5558d3d6997e Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 29 Mar 2018 10:47:52 +0200 Subject: [PATCH 095/136] text improvements and fixes --- programs/gui_wallet/src/mining_vote_popup.cpp | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/programs/gui_wallet/src/mining_vote_popup.cpp b/programs/gui_wallet/src/mining_vote_popup.cpp index 6cd5316e..0dba846c 100644 --- a/programs/gui_wallet/src/mining_vote_popup.cpp +++ b/programs/gui_wallet/src/mining_vote_popup.cpp @@ -16,18 +16,18 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) , m_minersVotedNum(0) , m_curMinersVotedFor(0) { + const std::string& account_name = Globals::instance().getCurrentUser(); uint numOfActiveMiners = getNumberOfActualMiners(); - getMinerVotesForAccount(Globals::instance().getCurrentUser() ); + getMinerVotesForAccount(account_name); QLabel* pInfoTextLabel = new QLabel(this); - pInfoTextLabel->setText(tr("bla bla bla blaaaa...blaaaa.. blaaaa")); - + pInfoTextLabel->setText(tr("The number of active miners this account votes the blockchain should appoint")); QLabel* pMinersVoteNumLabel = new QLabel(this); pMinersVoteNumLabel->setText(tr("Set desired number of miners")); - QIntValidator* numValidator = new QIntValidator(1, 1001, this); + QIntValidator* numValidator = new QIntValidator(1, 1001, this); //TODO: make max value read from global_properties m_pMinersNumVote = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); m_pMinersNumVote->setValidator(numValidator); @@ -41,8 +41,16 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) } // Info + QLabel* pInfoLabel = new QLabel(this); + pInfoLabel->setText(QString(tr("This number must not exceed the actual number of miners voted for in %1 account votes")) + .arg(QString::fromStdString(account_name))); + + Asset opFee = Globals::instance().getDCoreFees(2); + QLabel* pUserCurrVotesLabel = new QLabel(this); - pUserCurrVotesLabel->setText(QString(tr("You have voted for %1 miners.")).arg(m_curMinersVotedFor) ); + pUserCurrVotesLabel->setText(QString(tr("You have voted for %1 miners. You will pay %2 fee for voting.")) + .arg(m_curMinersVotedFor) + .arg(opFee.getString()) ); m_pVoteButton = new DecentButton(this, DecentButton::DialogAction); m_pResetButton = new DecentButton(this, DecentButton::DialogAction); @@ -67,6 +75,7 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) pRow2Layout->addWidget(m_pMinersNumVote); QHBoxLayout* pRow3Layout = new QHBoxLayout; + pRow3Layout->addWidget(pInfoLabel); pRow3Layout->addWidget(pUserCurrVotesLabel); QHBoxLayout* pButtonsLayout = new QHBoxLayout; @@ -134,8 +143,7 @@ void MiningVotePopup::getMinerVotesForAccount(const std::string& account_name) void MiningVotePopup::slot_MinersNumVoteChanged(const QString& value) { uint numMiners = value.toUInt(); - - m_pVoteButton->setEnabled(numMiners > 0); + m_pVoteButton->setEnabled(numMiners > 0 && numMiners <= m_curMinersVotedFor); } void MiningVotePopup::slot_voteClicked() @@ -146,6 +154,9 @@ void MiningVotePopup::slot_voteClicked() if (!ret.empty()) { ShowMessageBox(tr("Error"), tr("Failed to vote for miners"), QString::fromStdString(ret)); } + else { + ShowMessageBox(tr("Info"), tr("Your vote was accepted. Thank you")); + } closed(); //close the popup } @@ -156,6 +167,9 @@ void MiningVotePopup::slot_voteResetClicked() if (!ret.empty()) { ShowMessageBox(tr("Error"), tr("Failed to vote for miners"), QString::fromStdString(ret)); } + else { + ShowMessageBox(tr("Info"), tr("Your vote was accepted. Thank you")); + } closed(); //close the popup } From 1b214a75d89b5cbd60ddd7461ecc1bf23c374023 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 29 Mar 2018 12:35:37 +0200 Subject: [PATCH 096/136] text improvements and fixes --- programs/gui_wallet/src/mainwindow.cpp | 2 +- programs/gui_wallet/src/mining_vote_popup.cpp | 15 +++++---- programs/gui_wallet/src/mining_vote_tab.cpp | 32 +++++++++++++++++-- programs/gui_wallet/src/mining_vote_tab.hpp | 3 ++ 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 730a7957..a1be04b3 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -172,7 +172,7 @@ MainWindow::MainWindow() m_pPublish->setText(tr("Publish")); m_pPublish->hide(); - m_pOnlyMyVotes = new QCheckBox(tr("Only my votes"), pMainWidget); + m_pOnlyMyVotes = new QCheckBox(tr("My votes"), pMainWidget); m_pOnlyMyVotes->hide(); // diff --git a/programs/gui_wallet/src/mining_vote_popup.cpp b/programs/gui_wallet/src/mining_vote_popup.cpp index 0dba846c..0299f997 100644 --- a/programs/gui_wallet/src/mining_vote_popup.cpp +++ b/programs/gui_wallet/src/mining_vote_popup.cpp @@ -42,14 +42,13 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) // Info QLabel* pInfoLabel = new QLabel(this); - pInfoLabel->setText(QString(tr("This number must not exceed the actual number of miners voted for in %1 account votes")) - .arg(QString::fromStdString(account_name))); + pInfoLabel->setText(QString(tr("The desired miners count you are voting for must be equal to or less than %1 because \nthe number of miners you voted for is %1 (see My votes on the main screen).")) + .arg(m_curMinersVotedFor)); Asset opFee = Globals::instance().getDCoreFees(2); - QLabel* pUserCurrVotesLabel = new QLabel(this); - pUserCurrVotesLabel->setText(QString(tr("You have voted for %1 miners. You will pay %2 fee for voting.")) - .arg(m_curMinersVotedFor) + QLabel* pFeeInfoLabel = new QLabel(this); + pFeeInfoLabel->setText(QString(tr("You will pay %1 fee for voting.")) .arg(opFee.getString()) ); m_pVoteButton = new DecentButton(this, DecentButton::DialogAction); @@ -76,7 +75,9 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) QHBoxLayout* pRow3Layout = new QHBoxLayout; pRow3Layout->addWidget(pInfoLabel); - pRow3Layout->addWidget(pUserCurrVotesLabel); + + QHBoxLayout* pRow4Layout = new QHBoxLayout; + pRow4Layout->addWidget(pFeeInfoLabel); QHBoxLayout* pButtonsLayout = new QHBoxLayout; pButtonsLayout->setContentsMargins(20, 20, 20, 20); @@ -96,6 +97,7 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) pMainLayout->addLayout(pRow1Layout); pMainLayout->addLayout(pRow2Layout); pMainLayout->addLayout(pRow3Layout); + pMainLayout->addLayout(pRow4Layout); pMainLayout->addLayout(pButtonsLayout); pMainLayout->setContentsMargins(10, 10, 10, 10); setLayout(pMainLayout); @@ -137,7 +139,6 @@ void MiningVotePopup::getMinerVotesForAccount(const std::string& account_name) m_minersVotedNum = account_obj["options"]["num_miner"].get(); m_curMinersVotedFor = account_obj["options"]["votes"].size(); - } void MiningVotePopup::slot_MinersNumVoteChanged(const QString& value) diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp index 0ab30a73..7338b779 100644 --- a/programs/gui_wallet/src/mining_vote_tab.cpp +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -32,9 +32,11 @@ const char* g_vote_state_id = "vote-state"; MinerVotingTab::MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit, QCheckBox* pOnlyMyVotes) - : TabContentManager(pParent), - m_pTableWidget(new DecentTable(this)), - m_onlyMyVotes(false) + : TabContentManager(pParent) + , m_pTableWidget(new DecentTable(this)) + , m_onlyMyVotes(false) + , m_minersVotedNum(0) + , m_curMinersVotedFor(0) { m_pTableWidget->set_columns({ {tr("Miner"), 15, "name"}, @@ -67,6 +69,7 @@ MinerVotingTab::MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit this, &MinerVotingTab::slot_SortingChanged); setRefreshTimer(5000); + } MinerVotingTab::~MinerVotingTab() = default; @@ -227,6 +230,17 @@ void MinerVotingTab::slot_MinerVote() QTableWidgetItem* item = m_pTableWidget->item(iIndex, 0); std::string miner_name = item->text().toStdString(); + if (voteFlag) { + getDesiredMinersCount(); + + if (m_minersVotedNum != 0 && (m_curMinersVotedFor-1) < m_minersVotedNum) { + ShowMessageBox(tr("Error"), + QString(tr("You have set desired miners count to %1, number of miners you vote for can't be less than desired miners count.")) + .arg(m_minersVotedNum)); + return; + } + } + submit_vote(miner_name, !voteFlag); reset(true); @@ -259,7 +273,19 @@ void MinerVotingTab::submit_vote(const std::string& miner_name, bool voteFlag) } +void MinerVotingTab::getDesiredMinersCount() +{ + std::string cmd = "get_account "; + cmd += Globals::instance().getCurrentUser(); + + nlohmann::json account_obj = Globals::instance().runTaskParse(cmd); + + std::cout << account_obj["options"] << std::endl; + m_minersVotedNum = account_obj["options"]["num_miner"].get(); + m_curMinersVotedFor = account_obj["options"]["votes"].size(); + +} diff --git a/programs/gui_wallet/src/mining_vote_tab.hpp b/programs/gui_wallet/src/mining_vote_tab.hpp index cfbc2fff..50763e64 100644 --- a/programs/gui_wallet/src/mining_vote_tab.hpp +++ b/programs/gui_wallet/src/mining_vote_tab.hpp @@ -35,11 +35,14 @@ namespace gui_wallet private: void submit_vote(const std::string& miner_name, bool voteFlag); + void getDesiredMinersCount(); public: DecentTable* m_pTableWidget; QString m_strSearchTerm; bool m_onlyMyVotes; + uint m_minersVotedNum; + uint m_curMinersVotedFor; QMap m_buttonsToIndex; QMap m_indexToUrl; From 2b1342c8a0a11761518a1a95cff76a5a8cd44767 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 29 Mar 2018 12:48:58 +0200 Subject: [PATCH 097/136] added variable initialization --- programs/gui_wallet/src/gui_wallet_global.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index 3a16a3bb..18258dd7 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -506,12 +506,11 @@ QString convertDateTimeToLocale2(const std::string& s) // WalletOperator::WalletOperator() : QObject() , m_wallet_api() +, m_cancellation_token(false) { } -WalletOperator::~WalletOperator() -{ -} +WalletOperator::~WalletOperator() = default void WalletOperator::cancel() { From be62629bc6f7dc3fa8bd1c2b0faeeff12a6656c0 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 29 Mar 2018 13:50:53 +0200 Subject: [PATCH 098/136] compile fix --- programs/gui_wallet/src/gui_wallet_global.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index 18258dd7..a18e108e 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -510,7 +510,7 @@ WalletOperator::WalletOperator() : QObject() { } -WalletOperator::~WalletOperator() = default +WalletOperator::~WalletOperator() = default; void WalletOperator::cancel() { From df16e63c4f51058987d04147238ee390b97ef7f8 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 29 Mar 2018 13:59:07 +0200 Subject: [PATCH 099/136] removed debugging helpers --- programs/gui_wallet/src/gui_wallet_global.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index a18e108e..663962a3 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -680,12 +680,10 @@ void Globals::startDaemons(BlockChainStartType type) #endif -#if 0 m_p_daemon_details->future_decentd = thread_decentd.async([type, &exit_promise]() -> int { return ::runDecentD(type, exit_promise); }); -#endif m_tp_started = std::chrono::steady_clock::now(); @@ -716,12 +714,10 @@ void Globals::stopDaemons() m_p_wallet_operator = nullptr; } -#if 0 fc::promise::ptr& exit_promise = m_p_daemon_details->exit_promise; exit_promise->set_value(); m_p_daemon_details->future_decentd.wait(); -#endif if (m_p_daemon_details->ipfs_process) { m_p_daemon_details->ipfs_process->terminate(); From 3f83f837ba7e8e3df34a1dc3df7fe5e1159a08d7 Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Thu, 29 Mar 2018 14:13:22 +0200 Subject: [PATCH 100/136] Added *.inl to header list to have functional text searching tools --- libraries/wallet/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/wallet/CMakeLists.txt b/libraries/wallet/CMakeLists.txt index 325535b8..bc5cebb6 100644 --- a/libraries/wallet/CMakeLists.txt +++ b/libraries/wallet/CMakeLists.txt @@ -1,4 +1,4 @@ -file(GLOB HEADERS "include/graphene/wallet/*.hpp") +file(GLOB HEADERS "include/graphene/wallet/*.hpp" "*.inl") find_package( Perl ) find_package( Doxygen ) From 76cafb9d0d3d70b52fda14d3bcd61b513751de2f Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 29 Mar 2018 14:36:47 +0200 Subject: [PATCH 101/136] finalizing payment to content --- libraries/app/impacted.cpp | 3 +- .../graphene/chain/protocol/transfer.hpp | 20 +++++++++-- libraries/chain/protocol/transfer.cpp | 1 + libraries/chain/transfer_evaluator.cpp | 35 +++++++++---------- .../include/graphene/wallet/account.hpp | 6 ++-- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/libraries/app/impacted.cpp b/libraries/app/impacted.cpp index 83d19f31..2a346487 100644 --- a/libraries/app/impacted.cpp +++ b/libraries/app/impacted.cpp @@ -45,7 +45,8 @@ struct get_impacted_account_visitor void operator()( const transfer2_operation& op ) { - _impacted.insert( op.from ); + if( op.to.is() ) + _impacted.insert( op.to.as() ); } void operator()( const account_create_operation& op ) diff --git a/libraries/chain/include/graphene/chain/protocol/transfer.hpp b/libraries/chain/include/graphene/chain/protocol/transfer.hpp index ac7f3f05..77c43c02 100644 --- a/libraries/chain/include/graphene/chain/protocol/transfer.hpp +++ b/libraries/chain/include/graphene/chain/protocol/transfer.hpp @@ -64,6 +64,22 @@ namespace graphene { namespace chain { void validate()const; }; + /** + * @ingroup operations + * + * @brief Transfers an amount of one asset from one account to another account or to content. + * In the case of transferring to a content, amount is transferred to author and co-authors of the content, + * if they are specified. + * + * Fees are paid by the "from" account + * + * @pre amount.amount > 0 + * @pre fee.amount >= 0 + * @pre from != to + * @post from account's balance will be reduced by fee and amount + * @post to account's balance will be increased by amount + * @return n/a + */ struct transfer2_operation : public base_operation { struct fee_parameters_type { @@ -73,7 +89,7 @@ namespace graphene { namespace chain { asset fee; /// Account to transfer asset from account_id_type from; - /// Account to transfer asset to + /// Account or content to transfer asset to object_id_type to; /// The amount of asset to transfer from @ref from to @ref to asset amount; @@ -91,4 +107,4 @@ namespace graphene { namespace chain { FC_REFLECT( graphene::chain::transfer_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::transfer_operation, (fee)(from)(to)(amount)(memo)(extensions) ) FC_REFLECT( graphene::chain::transfer2_operation::fee_parameters_type, (fee) ) -FC_REFLECT( graphene::chain::transfer2_operation, (fee)(from)(to)(amount)(memo)(extensions) ) \ No newline at end of file +FC_REFLECT( graphene::chain::transfer2_operation, (fee)(from)(to)(amount)(memo)(extensions) ) diff --git a/libraries/chain/protocol/transfer.cpp b/libraries/chain/protocol/transfer.cpp index 4a7c41e2..e86e0285 100644 --- a/libraries/chain/protocol/transfer.cpp +++ b/libraries/chain/protocol/transfer.cpp @@ -37,6 +37,7 @@ void transfer_operation::validate()const void transfer2_operation::validate()const { FC_ASSERT( fee.amount >= 0 ); + FC_ASSERT( to.is() || to.is() ); FC_ASSERT( from != to ); FC_ASSERT( amount.amount > 0 ); } diff --git a/libraries/chain/transfer_evaluator.cpp b/libraries/chain/transfer_evaluator.cpp index 5f200bf4..be9a56a4 100644 --- a/libraries/chain/transfer_evaluator.cpp +++ b/libraries/chain/transfer_evaluator.cpp @@ -77,16 +77,11 @@ void_result transfer_evaluator::do_apply( const transfer_operation& o ) void_result transfer2_evaluator::do_evaluate( const transfer2_operation& op ) { try { - - FC_ASSERT( op.to.is() || op.to.is() ); - const database& d = db(); - const account_object& from_account = op.from(d); const asset_object& asset_type = op.amount.asset_id(d); try { - bool insufficient_balance = d.get_balance( from_account, asset_type ).amount >= op.amount.amount; FC_ASSERT( insufficient_balance, "Insufficient Balance: ${balance}, unable to transfer '${total_transfer}' from account '${a}' to '${t}'", @@ -99,12 +94,19 @@ void_result transfer2_evaluator::do_evaluate( const transfer2_operation& op ) void_result transfer2_evaluator::do_apply( const transfer2_operation& o ) { try { - db().adjust_balance( o.from, -o.amount ); + auto & d = db(); + account_id_type to_acc; + + d.adjust_balance( o.from, -o.amount ); + if( o.to.is() ) - db().adjust_balance( o.to, o.amount ); + { + to_acc = o.to.as(); + d.adjust_balance( to_acc, o.amount ); + } else { - auto& content_idx = db().get_index_type().indices().get(); + auto& content_idx = d.get_index_type().indices().get(); const auto& content_itr = content_idx.find( o.to ); asset amount = o.amount; @@ -114,30 +116,25 @@ void_result transfer2_evaluator::do_apply( const transfer2_operation& o ) for( auto const &element : content_itr->co_authors ) { amount_for_co_author = ( o.amount.amount.value * element.second ) / 10000ll ; - db().adjust_balance( element.first, asset( static_cast(amount_for_co_author), o.amount.asset_id) ); + d.adjust_balance( element.first, asset( static_cast(amount_for_co_author), o.amount.asset_id) ); amount.amount -= amount_for_co_author; } } + to_acc = content_itr->author; + if( amount.amount != 0 ) { FC_ASSERT( amount.amount > 0 ); - db().adjust_balance(content_itr->author, amount); + d.adjust_balance(to_acc, amount); } } - - - - - - auto & d = db(); - - db().create([&o, &d](transaction_detail_object& obj) + d.create([&o, &d, &to_acc](transaction_detail_object& obj) { obj.m_operation_type = (uint8_t)transaction_detail_object::transfer; obj.m_from_account = o.from; - obj.m_to_account = o.to; + obj.m_to_account = to_acc; obj.m_transaction_amount = o.amount; obj.m_transaction_fee = o.fee; obj.m_transaction_encrypted_memo = o.memo; diff --git a/libraries/wallet/include/graphene/wallet/account.hpp b/libraries/wallet/include/graphene/wallet/account.hpp index 6189633e..eb8db722 100644 --- a/libraries/wallet/include/graphene/wallet/account.hpp +++ b/libraries/wallet/include/graphene/wallet/account.hpp @@ -205,9 +205,11 @@ signed_transaction create_account_with_brain_key(const string& brain_key, bool broadcast = false); /** - * @brief Transfer an amount from one account to another. + * @brief Transfer an amount from one account to another account or to content. + * In the case of transferring to a content, amount is transferred to author and co-authors of the content, + * if they are specified. * @param from the name or id of the account sending the funds - * @param to the name or id of the account receiving the funds + * @param to the name or id of the account or id of the content receiving the funds * @param amount the amount to send (in nominal units -- to send half of a DCT, specify 0.5) * @param asset_symbol the symbol or id of the asset to send * @param memo a memo to attach to the transaction. The memo will be encrypted in the From c6c80cb103d2e82eb6e9680a67c82cda09f3634e Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 29 Mar 2018 17:09:47 +0200 Subject: [PATCH 102/136] minor bugfixes and adjustments --- libraries/app/api.cpp | 1 + libraries/chain/decent_evaluator.cpp | 2 +- libraries/chain/hardfork.d/2.hf | 5 +-- .../include/graphene/chain/protocol/types.hpp | 2 + libraries/chain/transfer_evaluator.cpp | 2 + libraries/wallet/wallet.cpp | 37 +++++++++++++++---- 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index ff1616a8..de4513f0 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -284,6 +284,7 @@ namespace graphene { namespace app { switch( (object_type)obj->id.type() ) { case null_object_type: + case base_object_type: case OBJECT_TYPE_COUNT: return result; case account_object_type:{ diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index 6a17887b..475d01be 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -745,7 +745,7 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri void_result ready_to_publish2_evaluator::do_evaluate(const ready_to_publish2_operation& o ) {try{ - FC_ASSERT(db().head_block_time() >= HARDFORK_1_TIME ); //TODO_DECENT HARDFORK reference + FC_ASSERT(db().head_block_time() >= HARDFORK_1_TIME ); }FC_CAPTURE_AND_RETHROW( (o) ) } void_result ready_to_publish2_evaluator::do_apply(const ready_to_publish2_operation& o ) diff --git a/libraries/chain/hardfork.d/2.hf b/libraries/chain/hardfork.d/2.hf index 7da28e07..9bbf0ce2 100644 --- a/libraries/chain/hardfork.d/2.hf +++ b/libraries/chain/hardfork.d/2.hf @@ -1,6 +1,5 @@ -// #2 - simple buying - +// #2 - simple content; payment to content; option to fix asset max supply; new wallet file format. #ifndef HARDFORK_2_TIME -#define HARDFORK_2_TIME (fc::time_point_sec( 1410238800 )) +#define HARDFORK_2_TIME (fc::time_point_sec( 1522800000 )) //2018-4-4 00:00:00 #endif diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index 6cd56407..257e3395 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -111,6 +111,7 @@ namespace graphene { namespace chain { enum object_type { null_object_type, + base_object_type, account_object_type, asset_object_type, miner_object_type, @@ -316,6 +317,7 @@ FC_REFLECT( graphene::chain::extended_private_key_type::binary_key, (check)(data FC_REFLECT_ENUM( graphene::chain::object_type, (null_object_type) + (base_object_type) (account_object_type) (asset_object_type) (miner_object_type) diff --git a/libraries/chain/transfer_evaluator.cpp b/libraries/chain/transfer_evaluator.cpp index be9a56a4..da81a986 100644 --- a/libraries/chain/transfer_evaluator.cpp +++ b/libraries/chain/transfer_evaluator.cpp @@ -78,6 +78,8 @@ void_result transfer_evaluator::do_apply( const transfer_operation& o ) void_result transfer2_evaluator::do_evaluate( const transfer2_operation& op ) { try { const database& d = db(); + + FC_ASSERT(db().head_block_time() >= HARDFORK_2_TIME ); const account_object& from_account = op.from(d); const asset_object& asset_type = op.amount.asset_id(d); diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 53e03397..35c25f07 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1790,13 +1790,16 @@ class wallet_api_impl to_account = get_account( get_object(to_obj_id.as()).author); } - transfer2_operation xfer_op; + signed_transaction tx; + if( head_block_time() >= HARDFORK_2_TIME ) + { + transfer2_operation xfer_op; - xfer_op.from = from_id; - xfer_op.to = to_obj_id; - xfer_op.amount = asset_obj->amount_from_string(amount); + xfer_op.from = from_id; + xfer_op.to = to_obj_id; + xfer_op.amount = asset_obj->amount_from_string(amount); - if( memo.size() ) + if( memo.size() ) { xfer_op.memo = memo_data(); xfer_op.memo->from = from_account.options.memo_key; @@ -1805,8 +1808,28 @@ class wallet_api_impl to_account.options.memo_key, memo); } - signed_transaction tx; - tx.operations.push_back(xfer_op); + tx.operations.push_back(xfer_op); + } + else + { + transfer_operation xfer_op; + + xfer_op.from = from_id; + xfer_op.to = to_obj_id; + xfer_op.amount = asset_obj->amount_from_string(amount); + + if( memo.size() ) + { + xfer_op.memo = memo_data(); + xfer_op.memo->from = from_account.options.memo_key; + xfer_op.memo->to = to_account.options.memo_key; + xfer_op.memo->set_message(get_private_key(from_account.options.memo_key), + to_account.options.memo_key, memo); + } + + tx.operations.push_back(xfer_op); + } + set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees); tx.validate(); From 6f1fc08a9965bac3e3adc71dfe9030080b1d9963 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 29 Mar 2018 17:52:27 +0200 Subject: [PATCH 103/136] fixed various issues and missing try/catch blocks --- libraries/wallet_utility/wallet_utility.cpp | 6 +- .../gui_wallet/src/browse_content_tab.cpp | 82 +++++++++++-------- programs/gui_wallet/src/gui_wallet_global.cpp | 11 +++ programs/gui_wallet/src/gui_wallet_global.hpp | 3 +- programs/gui_wallet/src/main_gui_wallet.cpp | 23 ++++-- programs/gui_wallet/src/mainwindow.cpp | 35 +++++--- programs/gui_wallet/src/mainwindow.hpp | 3 +- 7 files changed, 104 insertions(+), 59 deletions(-) diff --git a/libraries/wallet_utility/wallet_utility.cpp b/libraries/wallet_utility/wallet_utility.cpp index 75c410af..91998a41 100644 --- a/libraries/wallet_utility/wallet_utility.cpp +++ b/libraries/wallet_utility/wallet_utility.cpp @@ -186,9 +186,9 @@ namespace wallet_utility } } - if (cancellation_token) { - std::cout << "cancelation_token" << std::endl; - } +// if (cancellation_token) { +// std::cout << "cancelation_token" << std::endl; +// } return string(); }); diff --git a/programs/gui_wallet/src/browse_content_tab.cpp b/programs/gui_wallet/src/browse_content_tab.cpp index 192834fc..a60ebf08 100644 --- a/programs/gui_wallet/src/browse_content_tab.cpp +++ b/programs/gui_wallet/src/browse_content_tab.cpp @@ -70,46 +70,56 @@ void BrowseContentTab::timeToUpdate(const std::string& result) ShowDigitalContentsGUI(); return; } - - auto contents = nlohmann::json::parse(result); - size_t iSize = contents.size(); - if (iSize > m_i_page_size) - iSize = m_i_page_size; - - _digital_contents.resize(iSize); - - for (size_t iIndex = 0; iIndex < iSize; ++iIndex) - { - SDigitalContent& cont = _digital_contents[iIndex]; - auto const& json_item = contents[iIndex]; - - cont.type = DCT::GENERAL; - cont.author = json_item["author"].get(); - - cont.synopsis = json_item["synopsis"].get(); - cont.URI = json_item["URI"].get(); - cont.created = json_item["created"].get(); - cont.expiration = json_item["expiration"].get(); - cont.size = json_item["size"].get(); - - if (json_item["times_bought"].is_number()) { - cont.times_bought = json_item["times_bought"].get(); - } else { - cont.times_bought = 0; + + try { + + auto contents = nlohmann::json::parse(result); + size_t iSize = contents.size(); + if (iSize > m_i_page_size) + iSize = m_i_page_size; + + _digital_contents.resize(iSize); + + for (size_t iIndex = 0; iIndex < iSize; ++iIndex) { + SDigitalContent &cont = _digital_contents[iIndex]; + auto const &json_item = contents[iIndex]; + + cont.type = DCT::GENERAL; + cont.author = json_item["author"].get(); + + cont.synopsis = json_item["synopsis"].get(); + cont.URI = json_item["URI"].get(); + cont.created = json_item["created"].get(); + cont.expiration = json_item["expiration"].get(); + cont.size = json_item["size"].get(); + + if (json_item["times_bought"].is_number()) { + cont.times_bought = json_item["times_bought"].get(); + } else { + cont.times_bought = 0; + } + + uint64_t iPrice = json_to_int64(json_item["price"]["amount"]); + std::string iSymbolId = json_item["price"]["asset_id"]; + cont.price = Globals::instance().asset(iPrice, iSymbolId); + + cont.AVG_rating = json_item["AVG_rating"].get() / 1000; } - - uint64_t iPrice = json_to_int64(json_item["price"]["amount"]); - std::string iSymbolId = json_item["price"]["asset_id"]; - cont.price = Globals::instance().asset(iPrice, iSymbolId); - cont.AVG_rating = json_item["AVG_rating"].get() / 1000; + if (contents.size() > m_i_page_size) + set_next_page_iterator(contents[m_i_page_size]["id"].get()); + else + set_next_page_iterator(string()); + } + catch(const std::exception& ex) { + //TODO: exception... + std::cout << "exception:" << ex.what() << std::endl; + } + catch(const fc::exception& ex) { + //TODO: exception... + std::cout << "exception:" << ex.what() << std::endl; } - if (contents.size() > m_i_page_size) - set_next_page_iterator(contents[m_i_page_size]["id"].get()); - else - set_next_page_iterator(string()); - ShowDigitalContentsGUI(); } diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index 663962a3..f3fccc51 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -53,6 +53,8 @@ #include #endif +#define DECENT_WITHOUT_DAEMON + #include int runDecentD(gui_wallet::BlockChainStartType type, fc::promise::ptr& exit_promise); @@ -680,10 +682,12 @@ void Globals::startDaemons(BlockChainStartType type) #endif +#if !defined(DECENT_WITHOUT_DAEMON) m_p_daemon_details->future_decentd = thread_decentd.async([type, &exit_promise]() -> int { return ::runDecentD(type, exit_promise); }); +#endif m_tp_started = std::chrono::steady_clock::now(); @@ -714,10 +718,12 @@ void Globals::stopDaemons() m_p_wallet_operator = nullptr; } +#if !defined(DECENT_WITHOUT_DAEMON) fc::promise::ptr& exit_promise = m_p_daemon_details->exit_promise; exit_promise->set_value(); m_p_daemon_details->future_decentd.wait(); +#endif if (m_p_daemon_details->ipfs_process) { m_p_daemon_details->ipfs_process->terminate(); @@ -871,6 +877,11 @@ std::string Globals::getAccountName(string const& accountId) return search->second; } +void Globals::setCurrentAccount(const QString& account_name) +{ + m_str_currentUser = account_name.toStdString(); +} + void Globals::slot_updateAccountBalance() { if (!m_str_currentUser.empty()) diff --git a/programs/gui_wallet/src/gui_wallet_global.hpp b/programs/gui_wallet/src/gui_wallet_global.hpp index 3b608cd1..233f0344 100644 --- a/programs/gui_wallet/src/gui_wallet_global.hpp +++ b/programs/gui_wallet/src/gui_wallet_global.hpp @@ -188,8 +188,9 @@ namespace gui_wallet public: void setWalletUnlocked(); void setWalletError(std::string const& error); - std::string getAccountName(const std::string& accountId); + void setCurrentAccount(const QString& account_name); + signals: void signal_connect(); // for internal use private slots: diff --git a/programs/gui_wallet/src/main_gui_wallet.cpp b/programs/gui_wallet/src/main_gui_wallet.cpp index 5a50873d..1e48bd16 100644 --- a/programs/gui_wallet/src/main_gui_wallet.cpp +++ b/programs/gui_wallet/src/main_gui_wallet.cpp @@ -72,15 +72,26 @@ int main(int argc, char* argv[]) #endif + try { + qRegisterMetaType( "std::string" ); + qRegisterMetaType( "int64_t" ); + app.setApplicationDisplayName("DECENT"); - qRegisterMetaType( "std::string" ); - qRegisterMetaType( "int64_t" ); - app.setApplicationDisplayName("DECENT"); - aMainWindow.show(); - //aMainWindow.StartUpdateThread(); - app.exec(); + aMainWindow.show(); + //aMainWindow.StartUpdateThread(); + app.exec(); + } + catch(const std::exception& ex) { + std::cout << "exception:" << ex.what() << std::endl; + } + catch(const fc::exception& ex) { + std::cout << "exception:" << ex.what() << std::endl; + } + catch(...) { + std::cout << "yay! exception..." << std::endl; + } gui_wallet::Globals::instance().stopDaemons(); gui_wallet::Globals::instance().clear(); diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 1f42e91a..0e0eca16 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -284,10 +284,10 @@ MainWindow::MainWindow() setUnifiedTitleAndToolBarOnMac(false); - QObject::connect(m_pAccountList, (void(QComboBox::*)(QString const&))&QComboBox::currentIndexChanged, - &Globals::instance(), &Globals::slot_setCurrentUser); - QObject::connect(m_pAccountList, (void(QComboBox::*)(QString const&))&QComboBox::currentIndexChanged, - this, &MainWindow::slot_getContents); +// QObject::connect(m_pAccountList, QOverload::of(&QComboBox::currentIndexChanged), +// &Globals::instance(), &Globals::slot_setCurrentUser); + QObject::connect(m_pAccountList, QOverload::of(&QComboBox::currentIndexChanged), + this, &MainWindow::slot_currentAccountChanged); QObject::connect(pTransferButton, &QPushButton::clicked, &Globals::instance(), (void(Globals::*)())&Globals::slot_showTransferDialog); @@ -632,6 +632,14 @@ void MainWindow::slot_importKey() slot_stackWidgetPush(import_key); } +void MainWindow::slot_currentAccountChanged(int iIndex) +{ + QString account = m_pAccountList->itemText(iIndex); + Globals::instance().setCurrentAccount(account); + + slot_getContents(); +} + void MainWindow::slot_BrowseToggled(bool toggled) { QWidget* pSender = qobject_cast(sender()); @@ -885,22 +893,25 @@ void MainWindow::DisplayWalletContentGUI() { auto accs = Globals::instance().runTaskParse("list_my_accounts"); m_pAccountList->clear(); - + + std::string id, name; for (int i = 0; i < accs.size(); ++i) { - std::string id = accs[i]["id"].get(); - std::string name = accs[i]["name"].get(); + id = accs[i]["id"].get(); + name = accs[i]["name"].get(); - m_pAccountList->addItem(name.c_str()); + m_pAccountList->insertItem(i, QString::fromStdString(name)); } - if (accs.size() > 0) - { + if (accs.size() > 0) { m_pAccountList->setCurrentIndex(0); } } - catch (const std::exception& ex) - { + catch (const std::exception& ex) { + exception_text = ex.what(); + display_error_box = true; + } + catch (const fc::assert_exception& ex) { exception_text = ex.what(); display_error_box = true; } diff --git a/programs/gui_wallet/src/mainwindow.hpp b/programs/gui_wallet/src/mainwindow.hpp index 5babd72d..e833d4fa 100644 --- a/programs/gui_wallet/src/mainwindow.hpp +++ b/programs/gui_wallet/src/mainwindow.hpp @@ -52,11 +52,12 @@ protected slots: void slot_PurchasedToggled(bool toggled); void slot_ConnectingUpdate(const QString& time_text, int); void slot_BlockchainUpdate(int value, int max); + void slot_currentAccountChanged(int iIndex); void DisplayWalletContentGUI(); signals: - void signal_setSplashMainText(QString const&); + void signal_setSplashMainText(const QString & ); protected: void closeSplash(bool bGonnaCoverAgain); From de12301bee9ce2b67e63ba760104b199893ec2cf Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 29 Mar 2018 18:43:21 +0200 Subject: [PATCH 104/136] add hardfork variables --- libraries/chain/decent_evaluator.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index 475d01be..28bb5955 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -128,6 +128,10 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri void_result content_submit_evaluator::do_evaluate(const content_submit_operation& o ) {try{ + + if( o.key_parts.size() == 0 ) //simplified content - TODO + FC_ASSERT(db().head_block_time() >= HARDFORK_2_TIME); + db().get(o.author); //Submission rights feature is disabled //FC_ASSERT( !author_account.rights_to_publish.publishing_rights_received.empty(), "Author does not have permission to publish a content" ); @@ -435,6 +439,9 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri FC_ASSERT( o.price <= d.get_balance( o.consumer, o.price.asset_id ) ); FC_ASSERT( content->expiration > db().head_block_time() ); + if( content->key_parts.size() == 0 ) //simplified content buying - TODO + FC_ASSERT(d.head_block_time() >= HARDFORK_2_TIME); + optional content_price_got = content->price.GetPrice(o.region_code_from); FC_ASSERT( content_price_got.valid(), "content is not available for this region" ); @@ -490,8 +497,6 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri paid_price_after_conversion = asset( 0 ); } - - if( content_price.asset_id == o.price.asset_id ){ // no need to convert paid_price_after_conversion = paid_price; }else { @@ -502,7 +507,6 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri bool delivered = false; asset escrow = paid_price_after_conversion; if( content->key_parts.size() == 0 ){ //simplified content buying - TODO - FC_ASSERT(d.head_block_time() >= HARDFORK_2_TIME); delivered = true; escrow = asset(0); } From 2adef6c6375598fe4c0dd20d4503ca9cb5057ae2 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 29 Mar 2018 18:52:13 +0200 Subject: [PATCH 105/136] remove unnecessary if condition --- libraries/chain/decent_evaluator.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index 28bb5955..f98d8870 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -439,9 +439,6 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri FC_ASSERT( o.price <= d.get_balance( o.consumer, o.price.asset_id ) ); FC_ASSERT( content->expiration > db().head_block_time() ); - if( content->key_parts.size() == 0 ) //simplified content buying - TODO - FC_ASSERT(d.head_block_time() >= HARDFORK_2_TIME); - optional content_price_got = content->price.GetPrice(o.region_code_from); FC_ASSERT( content_price_got.valid(), "content is not available for this region" ); From b91d8d281ccbe99beb332dbb537f12a4adcb6987 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 29 Mar 2018 19:26:50 +0200 Subject: [PATCH 106/136] fixed small merge issues --- programs/gui_wallet/src/gui_wallet_global.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index caeba512..bf07b8e2 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -556,7 +556,7 @@ QString Asset::getString() const QLocale& locale = Globals::instance().locale(); if (hasDecimals()) - return locale.toString(to_value(), 'f', g_max_number_of_decimal_places) + " " + QString::fromStdString(m_str_symbol); + return locale.toString(to_value(), 'g', g_max_number_of_decimal_places) + " " + QString::fromStdString(m_str_symbol); else return locale.toString((int)to_value()) + " " + QString::fromStdString(m_str_symbol); } @@ -568,7 +568,7 @@ QString Asset::getString() const QString Asset::getStringBalance() const { QLocale& locale = Globals::instance().locale(); - return locale.toString(to_value(), 'f' , g_max_number_of_decimal_places) + " " + QString::fromStdString(m_str_symbol); + return locale.toString(to_value(), 'g' , g_max_number_of_decimal_places) + " " + QString::fromStdString(m_str_symbol); } // // DaemonDetails @@ -654,10 +654,6 @@ void Globals::startDaemons(BlockChainStartType type) QObject::connect(this, &Globals::walletConnectionStatusChanged, this, &Globals::slot_ConnectionStatusChange); - fc::thread& thread_decentd = m_p_daemon_details->thread_decentd; - - fc::promise::ptr& exit_promise = m_p_daemon_details->exit_promise; - QProcess* daemon_process; daemon_process = run_ipfs_daemon(qApp, qApp->applicationDirPath()); m_p_daemon_details->ipfs_process = daemon_process; @@ -683,6 +679,10 @@ void Globals::startDaemons(BlockChainStartType type) #endif #if !defined(DECENT_WITHOUT_DAEMON) + fc::thread& thread_decentd = m_p_daemon_details->thread_decentd; + + fc::promise::ptr& exit_promise = m_p_daemon_details->exit_promise; + m_p_daemon_details->future_decentd = thread_decentd.async([type, &exit_promise]() -> int { return ::runDecentD(type, exit_promise); From cce2e549c9256cdd70d721bf41f3f486c277cb72 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 29 Mar 2018 19:37:05 +0200 Subject: [PATCH 107/136] fix --- programs/gui_wallet/src/gui_wallet_global.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index bf07b8e2..0dbd2960 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -53,7 +53,7 @@ #include #endif -#define DECENT_WITHOUT_DAEMON +//#define DECENT_WITHOUT_DAEMON #include From 3b5fd7a4e3c74e9a2ea2f3123d73d9e6754242c9 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 3 Apr 2018 10:30:36 +0200 Subject: [PATCH 108/136] fixed account balance update issue --- programs/gui_wallet/src/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 190984fc..ed061b8a 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -662,6 +662,7 @@ void MainWindow::slot_currentAccountChanged(int iIndex) { QString account = m_pAccountList->itemText(iIndex); Globals::instance().setCurrentAccount(account); + Globals::instance().slot_updateAccountBalance(); slot_getContents(); } From 96129b88229040365b3889872041b21f89a436e3 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 4 Apr 2018 09:37:23 +0200 Subject: [PATCH 109/136] bug fixes --- programs/gui_wallet/src/gui_wallet_global.cpp | 14 +++++--------- programs/gui_wallet/src/gui_wallet_global.hpp | 1 - programs/gui_wallet/src/mainwindow.cpp | 19 +++++++++++++++---- programs/gui_wallet/src/overview_tab.cpp | 8 +++++--- programs/gui_wallet/src/overview_tab.hpp | 6 +++--- programs/gui_wallet/src/transactions_tab.cpp | 4 ++-- 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index 0dbd2960..ad735421 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -53,7 +53,7 @@ #include #endif -//#define DECENT_WITHOUT_DAEMON +#define DECENT_WITHOUT_DAEMON #include @@ -880,6 +880,9 @@ std::string Globals::getAccountName(string const& accountId) void Globals::setCurrentAccount(const QString& account_name) { m_str_currentUser = account_name.toStdString(); + emit currentUserChanged(account_name); + + slot_updateAccountBalance(); } Asset Globals::getDCoreFees(int iOperation) @@ -902,7 +905,7 @@ void Globals::slot_updateAccountBalance() else { Asset ast_balance = asset(0); - for ( auto balance:allBalances ){ + for ( auto balance : allBalances ) { if(balance["asset_id"].get() == "1.3.0") { if( balance[ "amount" ].is_number()) ast_balance.m_amount = balance[ "amount" ].get(); @@ -915,13 +918,6 @@ void Globals::slot_updateAccountBalance() } } -void Globals::slot_setCurrentUser(const QString& user) -{ - m_str_currentUser = user.toStdString(); - emit currentUserChanged(user); - slot_updateAccountBalance(); -} - void Globals::slot_showTransferDialog(const QString& user) { if(getCurrentUser().empty()) diff --git a/programs/gui_wallet/src/gui_wallet_global.hpp b/programs/gui_wallet/src/gui_wallet_global.hpp index e67fe9da..6ebe1160 100644 --- a/programs/gui_wallet/src/gui_wallet_global.hpp +++ b/programs/gui_wallet/src/gui_wallet_global.hpp @@ -174,7 +174,6 @@ namespace gui_wallet public slots: void slot_updateAccountBalance(); - void slot_setCurrentUser(const QString& user); void slot_showTransferDialog(const QString& user); void slot_showTransferDialog(); diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index ed061b8a..c3d7a20f 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -662,7 +662,6 @@ void MainWindow::slot_currentAccountChanged(int iIndex) { QString account = m_pAccountList->itemText(iIndex); Globals::instance().setCurrentAccount(account); - Globals::instance().slot_updateAccountBalance(); slot_getContents(); } @@ -711,7 +710,7 @@ void MainWindow::slot_BrowseToggled(bool toggled) QTimer* pTimer = pActiveTab->getRefreshTimer(); if (pTimer) { pTimer->stop(); - QObject::disconnect(pTimer); + pTimer->disconnect(); } } } @@ -761,11 +760,23 @@ void MainWindow::slot_PublishToggled(bool toggled) pActiveTab->show(); m_pPublish->show(); updateActiveTable(); + + QTimer* pTimer = pActiveTab->getRefreshTimer(); + if (pTimer) { + QObject::connect(pTimer, &QTimer::timeout, this, &MainWindow::slot_getContents); + pTimer->start(); + } } else { pActiveTab->hide(); m_pPublish->hide(); + + QTimer* pTimer = pActiveTab->getRefreshTimer(); + if (pTimer) { + pTimer->stop(); + pTimer->disconnect(); + } } } @@ -826,7 +837,7 @@ void MainWindow::slot_PurchasedToggled(bool toggled) QTimer* pTimer = pActiveTab->getRefreshTimer(); if (pTimer) { pTimer->stop(); - QObject::disconnect(pTimer); + pTimer->disconnect(); } } } @@ -875,7 +886,7 @@ void MainWindow::slot_MinerVotingToggled(bool toggled) QTimer* pTimer = pActiveTab->getRefreshTimer(); if (pTimer) { pTimer->stop(); - QObject::disconnect(pTimer); + pTimer->disconnect(); } } diff --git a/programs/gui_wallet/src/overview_tab.cpp b/programs/gui_wallet/src/overview_tab.cpp index 6a1153b0..ed1c1636 100644 --- a/programs/gui_wallet/src/overview_tab.cpp +++ b/programs/gui_wallet/src/overview_tab.cpp @@ -193,12 +193,13 @@ void Overview_tab::slot_Transfer() Globals::instance().slot_showTransferDialog(m_strSelectedAccount); } -void Overview_tab::slot_SearchTermChanged(QString const& strSearchTerm) +void Overview_tab::slot_SearchTermChanged(const QString& strSearchTerm) { m_strSearchTerm = strSearchTerm; - reset(false); + reset(true); } -void Overview_tab::slot_AccountChanged(QString const& strAccountName) + +void Overview_tab::slot_AccountChanged(const QString& strAccountName) { m_strSelectedAccount = strAccountName; } @@ -207,4 +208,5 @@ void Overview_tab::slot_SortingChanged(int index) { reset(); } + }// end namespace gui_wallet diff --git a/programs/gui_wallet/src/overview_tab.hpp b/programs/gui_wallet/src/overview_tab.hpp index 762ecc2a..0952cda6 100644 --- a/programs/gui_wallet/src/overview_tab.hpp +++ b/programs/gui_wallet/src/overview_tab.hpp @@ -1,7 +1,7 @@ /* (c) 2016, 2017 DECENT Services. For details refers to LICENSE.txt */ #pragma once -#include +#include #include "gui_wallet_tabcontentmanager.hpp" @@ -29,8 +29,8 @@ namespace gui_wallet void slot_Details(); void slot_Transactions(); void slot_Transfer(); - void slot_SearchTermChanged(QString const& strSearchTerm); - void slot_AccountChanged(QString const& strAccountName); + void slot_SearchTermChanged(const QString& strSearchTerm); + void slot_AccountChanged(const QString& strAccountName); void slot_SortingChanged(int index); public: diff --git a/programs/gui_wallet/src/transactions_tab.cpp b/programs/gui_wallet/src/transactions_tab.cpp index 80ba8a68..4086a3a5 100644 --- a/programs/gui_wallet/src/transactions_tab.cpp +++ b/programs/gui_wallet/src/transactions_tab.cpp @@ -138,7 +138,7 @@ void TransactionsTab::timeToUpdate(const string& result) string TransactionsTab::getUpdateCommand() { - if (m_strSearchTerm.toStdString().empty()) + if (m_strSearchTerm.isEmpty()) return string(); return "search_account_history " @@ -156,6 +156,6 @@ void TransactionsTab::slot_SortingChanged(int index) void TransactionsTab::slot_SearchTermChanged(const QString& strSearchTerm) { m_strSearchTerm = strSearchTerm; - reset(false); + reset(true); } } // end namespace gui_wallet From b87cb1978ae3cdac24387664d1a67e81084f0ef7 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 4 Apr 2018 10:53:59 +0200 Subject: [PATCH 110/136] added missing comments on 'search_miner_voting', rearragned fn.parameters --- libraries/wallet/include/graphene/wallet/mining.hpp | 13 +++++++------ libraries/wallet/wallet.cpp | 4 ++-- libraries/wallet/wallet_mining.inl | 6 +++--- programs/gui_wallet/src/mining_vote_tab.cpp | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/mining.hpp b/libraries/wallet/include/graphene/wallet/mining.hpp index b4000e5a..04a36712 100644 --- a/libraries/wallet/include/graphene/wallet/mining.hpp +++ b/libraries/wallet/include/graphene/wallet/mining.hpp @@ -159,19 +159,20 @@ signed_transaction set_desired_miner_count(const string& account_to_modify, bool broadcast = false); /** - * @brief - * @param term search term - * @param only_my_votes - * @param order order field. Available options are defined in 'database_api.cpp' + * @brief Get miner voting info by account that match search term. + * @param account_id account name + * @param term search term - miner name + * @param only_my_votes when \c true it selects only votes given by account + * @param order order field. Available options are 'name\link|votes' * @param id the id of content object to start searching from * @param count maximum number of contents to fetch (must not exceed 1000) * @return the contents found * @ingroup WalletAPI_Mining */ -vector search_miner_voting(const string& term, +vector search_miner_voting(const string& account_id, + const string& term, bool only_my_votes, const string& order, - const string& account_id, const string& id, uint32_t count ) const; diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 8917db16..144879bc 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1624,10 +1624,10 @@ class wallet_api_impl return sign_transaction( tx, broadcast ); } FC_CAPTURE_AND_RETHROW( (account_to_modify)(desired_number_of_miners)(broadcast) ) } - vector search_miner_voting(const string& filter, + vector search_miner_voting(const string& account_id, + const string& filter, bool only_my_votes, const string& order, - const string& account_id, const string& id, uint32_t count ) const { diff --git a/libraries/wallet/wallet_mining.inl b/libraries/wallet/wallet_mining.inl index 88e764c6..73be024a 100644 --- a/libraries/wallet/wallet_mining.inl +++ b/libraries/wallet/wallet_mining.inl @@ -59,12 +59,12 @@ signed_transaction wallet_api::set_desired_miner_count(const string& account_to_ return my->set_desired_miner_count(account_to_modify, desired_number_of_miners, broadcast); } -vector wallet_api::search_miner_voting(const string& term, +vector wallet_api::search_miner_voting(const string& account_id, + const string& term, bool only_my_votes, const string& order, - const string& account_id, const string& id, uint32_t count ) const { - return my->search_miner_voting(term, only_my_votes, order, account_id, id, count); + return my->search_miner_voting(account_id, term, only_my_votes, order, id, count); } diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp index 7338b779..8588ffb1 100644 --- a/programs/gui_wallet/src/mining_vote_tab.cpp +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -180,10 +180,10 @@ std::string MinerVotingTab::getUpdateCommand() type.to_string(str_type); return "search_miner_voting " + "\"" + currentUserName + "\" " "\"" + m_strSearchTerm.toStdString() + "\" " + (m_onlyMyVotes ? "true " : "false ") + "\"" + m_pTableWidget->getSortedColumn() + "\" " - "\"" + currentUserName + "\" " "\"" + next_iterator() + "\" " + std::to_string(m_i_page_size + 1); } From 8ad1ae418c3650f990dd1ebf170952e528c0b621 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Wed, 4 Apr 2018 22:06:38 +0200 Subject: [PATCH 111/136] fix payment to content --- libraries/wallet/wallet.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 144879bc..2fd4aff7 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1873,14 +1873,23 @@ class wallet_api_impl account_object to_account; object_id_type to_obj_id; + bool is_account = true; + try { to_account = get_account(to); to_obj_id = object_id_type(to_account.id); } - catch ( fc::exception& e ) + catch ( const fc::exception& e ) + { + is_account = false; + } + + if( !is_account ) { to_obj_id = object_id_type(to); - to_account = get_account( get_object(to_obj_id.as()).author); + content_id_type content_id = to_obj_id.as(); + const content_object content_obj = get_object(content_id); + to_account = get_account( content_obj.author); } signed_transaction tx; From 50b2df8cc30f9749296527636e10b24606af555f Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Thu, 5 Apr 2018 11:12:05 +0200 Subject: [PATCH 112/136] UI fixes, moved some functions to Globals, small improvements --- programs/gui_wallet/src/gui_wallet_global.cpp | 56 ++++++++++++ programs/gui_wallet/src/gui_wallet_global.hpp | 5 ++ programs/gui_wallet/src/mainwindow.cpp | 11 +-- programs/gui_wallet/src/mining_vote_popup.cpp | 90 +++++++++++-------- programs/gui_wallet/src/mining_vote_tab.cpp | 21 ++++- programs/gui_wallet/src/richdialog.cpp | 83 ++++++----------- programs/gui_wallet/src/richdialog.hpp | 2 +- programs/gui_wallet/src/upload_tab.cpp | 14 +++ programs/gui_wallet/src/upload_tab.hpp | 2 +- 9 files changed, 179 insertions(+), 105 deletions(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index ad735421..a265fdb9 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -918,6 +918,62 @@ void Globals::slot_updateAccountBalance() } } +std::string Globals::ImportAccount(const std::string& name, const std::string& key) +{ + std::string message; + + try + { + std::string command = "import_key "; + command += "\"" + name + "\" "; + command += "\"" + key + "\" "; + auto result = Globals::instance().runTaskParse(command); + bool tf = result.get(); + if (!tf) { + message = "Invalid key"; + } + } + catch (const std::exception& ex) + { + message = ex.what(); + } + catch (const fc::exception& ex) + { + message = ex.what(); + } + + return message; +} + +std::string Globals::TransferFunds(const std::string& from, const std::string to, + double amount, const std::string& asset_symbol, const std::string& memo) +{ + std::string result; + try { + std::string command = "transfer "; + command += "\"" + from + "\" "; + command += "\"" + to + "\" "; + command += "\"" + std::to_string(amount) + "\" " + asset_symbol + " "; + command += "\"" + memo + "\""; + command += " true"; + + std::string dummy = runTask(command); + if (dummy.find("exception:") != std::string::npos) { + result = dummy; + } + } + catch(const std::exception& ex) + { + result = ex.what(); + } + catch(const fc::exception& ex) + { + result = ex.what(); + } + + return result; +} + void Globals::slot_showTransferDialog(const QString& user) { if(getCurrentUser().empty()) diff --git a/programs/gui_wallet/src/gui_wallet_global.hpp b/programs/gui_wallet/src/gui_wallet_global.hpp index 6ebe1160..3f0067ce 100644 --- a/programs/gui_wallet/src/gui_wallet_global.hpp +++ b/programs/gui_wallet/src/gui_wallet_global.hpp @@ -172,6 +172,11 @@ namespace gui_wallet bool connected() const; QString getAssetName() const; + //functions + std::string ImportAccount(const std::string& name, const std::string& key); + std::string TransferFunds(const std::string& from, const std::string to, + double amount, const std::string& asset_symbol, const std::string& memo); + public slots: void slot_updateAccountBalance(); void slot_showTransferDialog(const QString& user); diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index c3d7a20f..ecfd8ba5 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -82,7 +82,7 @@ MainWindow::MainWindow() , m_pActionImportKey(new QAction(tr("Import key"), this)) , m_pActionReplayBlockchain(new QAction(tr("Replay Blockchain"), this)) , m_pActionResyncBlockchain(new QAction(tr("Resync Blockchain"), this)) -, m_pAdvancedMinerVoting(new QAction(tr("Advanced MinerVoting"), this)) +, m_pAdvancedMinerVoting(new QAction(tr("Advanced Voting"), this)) #ifdef UPDATE_MANAGER , m_pUpdateManager(new UpdateManager()) #else @@ -134,7 +134,7 @@ MainWindow::MainWindow() m_pButtonPurchased->setCheckable(true); m_pButtonMinerVoting = new DecentButton(pMainWidget, DecentButton::TabChoice); - m_pButtonMinerVoting->setText(tr("Miner Voting")); + m_pButtonMinerVoting->setText(tr("Voting")); m_pButtonMinerVoting->setCheckable(true); QButtonGroup* pGroup = new QButtonGroup(pMainWidget); @@ -862,13 +862,6 @@ void MainWindow::slot_MinerVotingToggled(bool toggled) // if (toggled) { - Asset opFee = Globals::instance().getDCoreFees(2); //account_update_operation - - QMessageBox info(this); - info.setIcon(QMessageBox::Information); - info.setText(QString(tr("For every vote or unvote opeation you will pay %1 fee")).arg(opFee.getString()) ); - info.exec(); - m_pOnlyMyVotes->show(); pActiveTab->show(); updateActiveTable(); diff --git a/programs/gui_wallet/src/mining_vote_popup.cpp b/programs/gui_wallet/src/mining_vote_popup.cpp index 0299f997..7cf158ae 100644 --- a/programs/gui_wallet/src/mining_vote_popup.cpp +++ b/programs/gui_wallet/src/mining_vote_popup.cpp @@ -21,11 +21,8 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) uint numOfActiveMiners = getNumberOfActualMiners(); getMinerVotesForAccount(account_name); - QLabel* pInfoTextLabel = new QLabel(this); - pInfoTextLabel->setText(tr("The number of active miners this account votes the blockchain should appoint")); - QLabel* pMinersVoteNumLabel = new QLabel(this); - pMinersVoteNumLabel->setText(tr("Set desired number of miners")); + pMinersVoteNumLabel->setText(tr("Vote for number of miners")); QIntValidator* numValidator = new QIntValidator(1, 1001, this); //TODO: make max value read from global_properties @@ -40,26 +37,28 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) m_pMinersNumVote->setPlaceholderText(QString(tr("Actual miners count is %1")).arg(numOfActiveMiners) ); } + Asset opFee = Globals::instance().getDCoreFees(2); + // Info QLabel* pInfoLabel = new QLabel(this); - pInfoLabel->setText(QString(tr("The desired miners count you are voting for must be equal to or less than %1 because \nthe number of miners you voted for is %1 (see My votes on the main screen).")) - .arg(m_curMinersVotedFor)); + pInfoLabel->setText(QString(tr("Number of miners should be smaller or equal to number of votes you have given (%1)\n" + "You will be charged %2 for this operation")) + .arg(m_curMinersVotedFor) + .arg(opFee.getString())); - Asset opFee = Globals::instance().getDCoreFees(2); - - QLabel* pFeeInfoLabel = new QLabel(this); - pFeeInfoLabel->setText(QString(tr("You will pay %1 fee for voting.")) - .arg(opFee.getString()) ); +// QLabel* pFeeInfoLabel = new QLabel(this); +// pFeeInfoLabel->setText(QString(tr("You will pay %1 fee for voting.")) +// .arg() ); m_pVoteButton = new DecentButton(this, DecentButton::DialogAction); m_pResetButton = new DecentButton(this, DecentButton::DialogAction); DecentButton* pCancelButton = new DecentButton(this, DecentButton::DialogCancel); - m_pVoteButton->setText(tr("Apply Vote")); + m_pVoteButton->setText(tr("Vote")); m_pVoteButton->setFont(PopupButtonBigFont()); m_pVoteButton->setEnabled(false); - m_pResetButton->setText(tr("Reset Vote")); + m_pResetButton->setText(tr("Un-vote")); m_pResetButton->setFont(PopupButtonBigFont()); m_pResetButton->setEnabled(m_minersVotedNum > 0); @@ -67,17 +66,14 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) pCancelButton->setFont(PopupButtonBigFont()); QHBoxLayout* pRow1Layout = new QHBoxLayout; - pRow1Layout->addWidget(pInfoTextLabel); + pRow1Layout->addWidget(pMinersVoteNumLabel); + pRow1Layout->addWidget(m_pMinersNumVote); QHBoxLayout* pRow2Layout = new QHBoxLayout; - pRow2Layout->addWidget(pMinersVoteNumLabel); - pRow2Layout->addWidget(m_pMinersNumVote); - - QHBoxLayout* pRow3Layout = new QHBoxLayout; - pRow3Layout->addWidget(pInfoLabel); + pRow2Layout->addWidget(pInfoLabel); - QHBoxLayout* pRow4Layout = new QHBoxLayout; - pRow4Layout->addWidget(pFeeInfoLabel); +// QHBoxLayout* pRow3Layout = new QHBoxLayout; +// pRow3Layout->addWidget(pFeeInfoLabel); QHBoxLayout* pButtonsLayout = new QHBoxLayout; pButtonsLayout->setContentsMargins(20, 20, 20, 20); @@ -86,18 +82,9 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) pButtonsLayout->addWidget(pCancelButton); QVBoxLayout* pMainLayout = new QVBoxLayout; -// pMainLayout->addWidget(pTitleText); -// pMainLayout->addWidget(m_pDescriptionText); -// pMainLayout->addLayout(pLifeTimeRow); -// pMainLayout->addLayout(pPriceRow); -// pMainLayout->addLayout(pSeedersRow); -// pMainLayout->addLayout(pContentRow); -// pMainLayout->addLayout(pSamplesRow); -// pMainLayout->addLayout(pPublishTextRow); pMainLayout->addLayout(pRow1Layout); pMainLayout->addLayout(pRow2Layout); - pMainLayout->addLayout(pRow3Layout); - pMainLayout->addLayout(pRow4Layout); +// pMainLayout->addLayout(pRow3Layout); pMainLayout->addLayout(pButtonsLayout); pMainLayout->setContentsMargins(10, 10, 10, 10); setLayout(pMainLayout); @@ -122,8 +109,21 @@ MiningVotePopup::~MiningVotePopup() uint MiningVotePopup::getNumberOfActualMiners() { - nlohmann::json global_prop_info = Globals::instance().runTaskParse("get_global_properties"); - nlohmann::json active_miners = global_prop_info["active_miners"]; + nlohmann::json active_miners; + try + { + nlohmann::json global_prop_info = Globals::instance().runTaskParse("get_global_properties"); + active_miners = global_prop_info["active_miners"]; + + } + catch (const std::exception& ex) + { + std::cout << "Error:" << ex.what() << std::endl; + } + catch (const fc::exception& ex) + { + std::cout << "Error:" << ex.what() << std::endl; + } return active_miners.size(); } @@ -133,12 +133,22 @@ void MiningVotePopup::getMinerVotesForAccount(const std::string& account_name) std::string cmd = "get_account "; cmd += account_name; - nlohmann::json account_obj = Globals::instance().runTaskParse(cmd); - - std::cout << account_obj["options"] << std::endl; + nlohmann::json account_obj; + try + { + account_obj = Globals::instance().runTaskParse(cmd); - m_minersVotedNum = account_obj["options"]["num_miner"].get(); - m_curMinersVotedFor = account_obj["options"]["votes"].size(); + m_minersVotedNum = account_obj["options"]["num_miner"].get(); + m_curMinersVotedFor = account_obj["options"]["votes"].size(); + } + catch (const std::exception& ex) + { + std::cout << "Error:" << ex.what() << std::endl; + } + catch (const fc::exception& ex) + { + std::cout << "Error:" << ex.what() << std::endl; + } } void MiningVotePopup::slot_MinersNumVoteChanged(const QString& value) @@ -195,6 +205,10 @@ std::string MiningVotePopup::setDesiredNumOfMiners(const std::string& account_na { message = ex.what(); } + catch (const fc::exception& ex) + { + message = ex.what(); + } return message; } diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp index 8588ffb1..ca64248e 100644 --- a/programs/gui_wallet/src/mining_vote_tab.cpp +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -8,6 +8,8 @@ #include +#include + #ifndef _MSC_VER #include #include @@ -225,6 +227,18 @@ void MinerVotingTab::slot_MinerVote() } bool voteFlag = sender()->property(g_vote_state_id).toBool(); + Asset opFee = Globals::instance().getDCoreFees(2); //account_update_operation + + QMessageBox info(this); + info.setIcon(QMessageBox::Information); + info.setText(QString(tr("For every vote or unvote opeation you will pay %1 fee")).arg(opFee.getString()) ); + info.addButton( !voteFlag ? tr("Vote") : tr("Un-vote"), QMessageBox::AcceptRole); + info.addButton( tr("Cancel"), QMessageBox::RejectRole); + int result = info.exec(); + if (result != QMessageBox::AcceptRole) { + return; + } + int iIndex = find.value(); QTableWidgetItem* item = m_pTableWidget->item(iIndex, 0); @@ -235,8 +249,11 @@ void MinerVotingTab::slot_MinerVote() if (m_minersVotedNum != 0 && (m_curMinersVotedFor-1) < m_minersVotedNum) { ShowMessageBox(tr("Error"), - QString(tr("You have set desired miners count to %1, number of miners you vote for can't be less than desired miners count.")) - .arg(m_minersVotedNum)); + QString(tr("Your vote for number of miners (%1) should be equal or smaller to number of votes you have given (%2)\n" + "\n" + "In order to un-vote, please change your vote for number of miners")) + .arg(m_minersVotedNum) + .arg(m_curMinersVotedFor)); return; } } diff --git a/programs/gui_wallet/src/richdialog.cpp b/programs/gui_wallet/src/richdialog.cpp index d94d0a4d..ca2f9046 100644 --- a/programs/gui_wallet/src/richdialog.cpp +++ b/programs/gui_wallet/src/richdialog.cpp @@ -118,7 +118,7 @@ StackLayerWidget::StackLayerWidget(QWidget* pParent) : QWidget(pParent) // // TransferWidget // -TransferWidget::TransferWidget(QWidget* parent, QString const& userName) : StackLayerWidget(parent) +TransferWidget::TransferWidget(QWidget* parent, const QString & userName) : StackLayerWidget(parent) , m_toUserName(userName) { QVBoxLayout* mainLayout = new QVBoxLayout(); @@ -131,10 +131,8 @@ TransferWidget::TransferWidget(QWidget* parent, QString const& userName) : Stack DecentButton* cancel = new DecentButton(this, DecentButton::DialogCancel); cancel->setText(tr("Back")); - QObject::connect(ok, &QPushButton::clicked, - this, &TransferWidget::Transfer); - QObject::connect(cancel, &QPushButton::clicked, - this, &StackLayerWidget::closed); + QObject::connect(ok, &QPushButton::clicked, this, &TransferWidget::Transfer); + QObject::connect(cancel, &QPushButton::clicked, this, &StackLayerWidget::closed); QLabel* pLabel = new QLabel(this); pLabel->setText(tr("Transfer of funds")); @@ -152,7 +150,13 @@ TransferWidget::TransferWidget(QWidget* parent, QString const& userName) : Stack amount->setPlaceholderText(QString(tr("Amount of %1")).arg(Globals::instance().getAssetName()) ); amount->setAttribute(Qt::WA_MacShowFocusRect, 0); - QDoubleValidator* dblValidator = new QDoubleValidator(0.0001, 100000, 4, this); + Asset min_price_asset = Globals::instance().asset(1); + double min_price = min_price_asset.to_value(); + + Asset max_price_asset = Globals::instance().asset(100000 * pow(10, g_max_number_of_decimal_places)); + double max_price = max_price_asset.to_value(); + + QDoubleValidator* dblValidator = new QDoubleValidator(min_price, max_price, g_max_number_of_decimal_places, this); dblValidator->setLocale(Globals::instance().locale()); amount->setValidator(dblValidator); QObject::connect(amount, &QLineEdit::textChanged, @@ -204,35 +208,24 @@ void TransferWidget::memoChanged(const QString & memo) void TransferWidget::Transfer() { - std::string message; - - if(m_fromUserName.isEmpty()) + if (m_fromUserName.isEmpty()) m_fromUserName = Globals::instance().getCurrentUser().c_str(); - - - QString strAssetSymbol = Globals::instance().asset(0).m_str_symbol.c_str(); - try { - QString run_str = "transfer " - "\"" + m_fromUserName + "\" " - "\"" + m_toUserName + "\" " - "\"" + QString::number(m_amount) + "\"" - "\"" + strAssetSymbol + "\" " - "\"" + m_memo + "\" " - "\"true\""; - Globals::instance().runTask(run_str.toStdString()); - } catch(const std::exception& ex){ - message = ex.what(); - } - - if (message.empty()) + std::string strAssetSymbol = Globals::instance().asset(0).m_str_symbol; + + auto result = Globals::instance().TransferFunds(m_fromUserName.toStdString(), + m_toUserName.toStdString(), + m_amount, strAssetSymbol, + m_memo.toStdString()); + + if (result.empty()) { emit accepted(); Globals::instance().slot_updateAccountBalance(); } else { - ShowMessageBox(tr("Error"), tr("Failed to transfer DCT"), message.c_str()); + ShowMessageBox(tr("Error"), tr("Failed to transfer DCT"), QString::fromStdString(result)); } } // @@ -301,30 +294,12 @@ void ImportKeyWidget::keyChanged(const QString & key) void ImportKeyWidget::Import() { - std::string message; - - try - { - QString csTaskStr = "import_key " - "\"" + m_userName + "\" " - "\"" + m_key + "\" "; - auto result = Globals::instance().runTaskParse(csTaskStr.toStdString()); - bool tf = result.get(); - if(tf == false) - message = "Invalid key"; - } - catch (const std::exception& ex) - { - message = ex.what(); - } - - if (message.empty()) - { + std::string result = Globals::instance().ImportAccount(m_userName.toStdString(), m_key.toStdString()); + if (result.empty()) { emit accepted(); } - else - { - ShowMessageBox(tr("Error"), tr("Cannot import key."), message.c_str()); + else { + ShowMessageBox(tr("Error"), tr("Cannot import key."), QString::fromStdString(result)); } } // @@ -542,8 +517,8 @@ void ContentInfoWidget::ButtonWasClicked() void ContentInfoWidget::Buy() { - std::string downloadCommand = "download_content"; - downloadCommand += " " + Globals::instance().getCurrentUser(); // consumer + std::string downloadCommand = "download_content "; + downloadCommand += Globals::instance().getCurrentUser(); // consumer downloadCommand += " \"" + m_URI + "\""; // URI downloadCommand += " \"\""; // region_code downloadCommand += " true"; // broadcast @@ -963,8 +938,8 @@ PasswordWidget::PasswordWidget(QWidget* pParent, eType enType) : StackLayerWidge m_pButton = new DecentButton(this, DecentButton::DialogAction); if (enType == eSetPassword) { - pLabel->setText(tr("Setup your password for DECENT wallet")); - m_pButton->setText(tr("Set Password")); + pLabel->setText(tr("Create your password for DECENT wallet")); + m_pButton->setText(tr("Create Password")); } else { pLabel->setText(tr("Unlock your DECENT wallet")); @@ -986,7 +961,7 @@ PasswordWidget::PasswordWidget(QWidget* pParent, eType enType) : StackLayerWidge m_line2Edit = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); m_line2Edit->setEchoMode(QLineEdit::Password); m_line2Edit->setAttribute(Qt::WA_MacShowFocusRect, 0); - m_line2Edit->setPlaceholderText(QString(tr("Reenter password"))); + m_line2Edit->setPlaceholderText(QString(tr("Re-enter password"))); m_line2Edit->setMaxLength(g_maxPasswordLen); m_line2Edit->setToolTip(tr("The password must be limited to 50 characters")); diff --git a/programs/gui_wallet/src/richdialog.hpp b/programs/gui_wallet/src/richdialog.hpp index 423c6438..a7f892bb 100644 --- a/programs/gui_wallet/src/richdialog.hpp +++ b/programs/gui_wallet/src/richdialog.hpp @@ -60,7 +60,7 @@ class TransferWidget : public StackLayerWidget { Q_OBJECT public: - TransferWidget(QWidget* parent, QString const& userName = QString()); + TransferWidget(QWidget* parent, const QString & userName = QString()); public slots: void nameChanged(const QString &); diff --git a/programs/gui_wallet/src/upload_tab.cpp b/programs/gui_wallet/src/upload_tab.cpp index 450bc7d9..cb3d54ee 100644 --- a/programs/gui_wallet/src/upload_tab.cpp +++ b/programs/gui_wallet/src/upload_tab.cpp @@ -60,6 +60,9 @@ Upload_tab::Upload_tab(QWidget* pParent, QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &Upload_tab::slot_SortingChanged); + QObject::connect(m_pTableWidget, &DecentTable::cellClicked, + this, &Upload_tab::slot_cellClicked); + QObject::connect(pFilterLineEdit, &QLineEdit::textChanged, this, &Upload_tab::slot_SearchTermChanged); setFilterWidget(pFilterLineEdit); @@ -300,5 +303,16 @@ void Upload_tab::slot_SearchTermChanged(QString const& strSearchTerm) reset(false); } +void Upload_tab::slot_cellClicked(int row, int /*col*/) +{ + if (row < 0 || row >= _digital_contents.size()) { + throw std::out_of_range("Content index is out of range"); + } + + slot_ShowContentPopup(row); +} + + + } // end namespace gui_wallet diff --git a/programs/gui_wallet/src/upload_tab.hpp b/programs/gui_wallet/src/upload_tab.hpp index f9a5aab8..5c561df5 100644 --- a/programs/gui_wallet/src/upload_tab.hpp +++ b/programs/gui_wallet/src/upload_tab.hpp @@ -34,7 +34,7 @@ namespace gui_wallet void slot_ShowContentPopup(int); void slot_UploadPopupResubmit(int); void slot_UploadPopup(); - + void slot_cellClicked(int row, int col); protected: DecentTable* m_pTableWidget; From 56005ed691fe56d596b13296f5da31a046693e75 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Fri, 6 Apr 2018 09:06:26 +0200 Subject: [PATCH 113/136] add operation printer for transfer2_op --- .../include/graphene/chain/protocol/types.hpp | 8 +- libraries/wallet/wallet.cpp | 245 ++++++++++-------- 2 files changed, 142 insertions(+), 111 deletions(-) diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index 257e3395..9fae088f 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -115,7 +115,7 @@ namespace graphene { namespace chain { account_object_type, asset_object_type, miner_object_type, - custom_object_type, + custom_object_type, // 5 proposal_object_type, operation_history_object_type, withdraw_permission_object_type, @@ -130,17 +130,17 @@ namespace graphene { namespace chain { impl_reserved0_object_type, // formerly index_meta_object_type, TODO: delete me impl_asset_dynamic_data_type, impl_account_balance_object_type, - impl_account_statistics_object_type, + impl_account_statistics_object_type, // 5 impl_transaction_object_type, impl_block_summary_object_type, impl_account_transaction_history_object_type, impl_chain_property_object_type, - impl_miner_schedule_object_type, + impl_miner_schedule_object_type, // 10 impl_budget_record_object_type, impl_buying_object_type, impl_content_object_type, impl_publisher_object_type, - impl_subscription_object_type, + impl_subscription_object_type, // 15 impl_seeding_statistics_object_type, impl_transaction_detail_object_type, impl_messaging_object_type diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 2fd4aff7..a5080747 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -190,6 +190,7 @@ struct operation_printer std::string operator()(const T& op)const; std::string operator()(const transfer_operation& op)const; + std::string operator()(const transfer2_operation& op)const; std::string operator()(const account_create_operation& op)const; std::string operator()(const account_update_operation& op)const; std::string operator()(const asset_create_operation& op)const; @@ -1970,6 +1971,103 @@ class wallet_api_impl propose_builder_transaction2(propose_num, proposer, expiration); } + std::string decrypt_memo( const memo_data& memo, const account_object& from_account, const account_object& to_account ) const + { + FC_ASSERT(_keys.count(memo.to) || _keys.count(memo.from), "Memo is encrypted to a key ${to} or ${from} not in this wallet.", ("to", memo.to)("from",memo.from)); + std::string memo_result; + if( _keys.count(memo.to) ) { + vector keys_to_try_to; + auto my_memo_key = wif_to_key(_keys.at(memo.to)); + + FC_ASSERT(my_memo_key, "Unable to recover private key to decrypt memo. Wallet may be corrupted."); + keys_to_try_to.push_back(*my_memo_key); + for( auto k: to_account.active.key_auths ) { + auto key_itr = _keys.find(k.first); + if( key_itr == _keys.end() ) + continue; + auto my_key = wif_to_key(key_itr->second); + if(my_key) + keys_to_try_to.push_back(*my_key); + } + for( auto k: to_account.owner.key_auths ) { + auto key_itr = _keys.find(k.first); + if( key_itr == _keys.end() ) + continue; + auto my_key = wif_to_key(key_itr->second); + if(my_key) + keys_to_try_to.push_back(*my_key); + } + + for( auto k : keys_to_try_to ){ + try{ + memo_result = memo.get_message(k, memo.from); + return memo_result; + }catch(...){} + } + + vector keys_to_try_from; + for( auto k : from_account.active.key_auths ){ + keys_to_try_from.push_back(k.first); + } + for( auto k : from_account.owner.key_auths ){ + keys_to_try_from.push_back(k.first); + } + for( auto k : keys_to_try_from ){ + try{ + memo_result = memo.get_message(*my_memo_key, k); + return memo_result; + }catch(...){} + } + + } else { + vector keys_to_try_from; + auto my_memo_key = wif_to_key(_keys.at(memo.from)); + + FC_ASSERT(my_memo_key, "Unable to recover private key to decrypt memo. Wallet may be corrupted."); + keys_to_try_from.push_back(*my_memo_key); + for( auto k: from_account.active.key_auths ) { + auto key_itr = _keys.find(k.first); + if( key_itr == _keys.end() ) + continue; + auto my_key = wif_to_key(key_itr->second); + if(my_key) + keys_to_try_from.push_back(*my_key); + } + for( auto k: from_account.owner.key_auths ) { + auto key_itr = _keys.find(k.first); + if( key_itr == _keys.end() ) + continue; + auto my_key = wif_to_key(key_itr->second); + if(my_key) + keys_to_try_from.push_back(*my_key); + } + + for( auto k : keys_to_try_from ){ + try{ + memo_result = memo.get_message(k, memo.to); + return memo_result; + }catch(...){} + } + + vector keys_to_try_to; + for( auto k : to_account.active.key_auths ) { + keys_to_try_to.push_back(k.first); + } + for( auto k : to_account.owner.key_auths ) { + keys_to_try_to.push_back(k.first); + } + for( auto k : keys_to_try_to ) { + try { + memo_result = memo.get_message(*my_memo_key, k); + return memo_result; + } catch( ... ) {} + } + + } + + FC_ASSERT(false); + } + std::map> get_result_formatters() const { std::map > m; @@ -3137,114 +3235,47 @@ signed_transaction content_cancellation(const string& author, if( wallet.is_locked() ) { out << " -- Unlock wallet to see memo."; - } else { - try { - - FC_ASSERT(wallet._keys.count(op.memo->to) || wallet._keys.count(op.memo->from), "Memo is encrypted to a key ${to} or ${from} not in this wallet.", ("to", op.memo->to)("from",op.memo->from)); - if( wallet._keys.count(op.memo->to) ) { - vector keys_to_try_to; - auto my_memo_key = wif_to_key(wallet._keys.at(op.memo->to)); - - FC_ASSERT(my_memo_key, "Unable to recover private key to decrypt memo. Wallet may be corrupted."); - keys_to_try_to.push_back(*my_memo_key); - for( auto k: to_account.active.key_auths ) { - auto key_itr = wallet._keys.find(k.first); - if( key_itr == wallet._keys.end() ) - continue; - auto my_key = wif_to_key(key_itr->second); - if(my_key) - keys_to_try_to.push_back(*my_key); - } - for( auto k: to_account.owner.key_auths ) { - auto key_itr = wallet._keys.find(k.first); - if( key_itr == wallet._keys.end() ) - continue; - auto my_key = wif_to_key(key_itr->second); - if(my_key) - keys_to_try_to.push_back(*my_key); - } - - bool found = false; - for( auto k : keys_to_try_to ){ - try{ - memo = op.memo->get_message(k, op.memo->from); - out << " -- Memo: " << memo; - found = true; - break; - - }catch(...){} - } - if(!found){ - vector keys_to_try_from; - for( auto k : from_account.active.key_auths ){ - keys_to_try_from.push_back(k.first); - } - for( auto k : from_account.owner.key_auths ){ - keys_to_try_from.push_back(k.first); - } - for( auto k : keys_to_try_from ){ - try{ - memo = op.memo->get_message(*my_memo_key, k); - out << " -- Memo: " << memo; - found = true; - break; - }catch(...){} - } - } - FC_ASSERT(found); - - } else { - vector keys_to_try_from; - auto my_memo_key = wif_to_key(wallet._keys.at(op.memo->from)); - - FC_ASSERT(my_memo_key, "Unable to recover private key to decrypt memo. Wallet may be corrupted."); - keys_to_try_from.push_back(*my_memo_key); - for( auto k: from_account.active.key_auths ) { - auto key_itr = wallet._keys.find(k.first); - if( key_itr == wallet._keys.end() ) - continue; - auto my_key = wif_to_key(key_itr->second); - if(my_key) - keys_to_try_from.push_back(*my_key); - } - for( auto k: from_account.owner.key_auths ) { - auto key_itr = wallet._keys.find(k.first); - if( key_itr == wallet._keys.end() ) - continue; - auto my_key = wif_to_key(key_itr->second); - if(my_key) - keys_to_try_from.push_back(*my_key); - } + } + else + { + try + { + memo = wallet.decrypt_memo( *op.memo, from_account, to_account ); + out << " -- Memo: " << memo; + } + catch (const fc::exception& e) + { + out << " -- could not decrypt memo"; + elog("Error when decrypting memo: ${e}", ("e", e.to_detail_string())); + } + } + } + fee(op.fee); + return memo; + } - bool found = false; - for( auto k : keys_to_try_from ){ - try{ - memo = op.memo->get_message(k, op.memo->to); - out << " -- Memo: " << memo; - found = true; - break; - }catch(...){} - } - if(!found) { - vector keys_to_try_to; - for( auto k : to_account.active.key_auths ) { - keys_to_try_to.push_back(k.first); - } - for( auto k : to_account.owner.key_auths ) { - keys_to_try_to.push_back(k.first); - } - for( auto k : keys_to_try_to ) { - try { - memo = op.memo->get_message(*my_memo_key, k); - out << " -- Memo: " << memo; - found = true; - break; - - } catch( ... ) {} - } - } - } - } catch (const fc::exception& e) { + string operation_printer::operator()(const transfer2_operation& op) const + { + const auto& from_account = wallet.get_account(op.from); + const auto& to_account = wallet.get_account(op.to); + out << "Transfer " << wallet.get_asset(op.amount.asset_id).amount_to_pretty_string(op.amount) + << " from " << from_account.name << " to " << to_account.name; + std::string memo; + if( op.memo ) + { + if( wallet.is_locked() ) + { + out << " -- Unlock wallet to see memo."; + } + else + { + try + { + memo = wallet.decrypt_memo( *op.memo, from_account, to_account ); + out << " -- Memo: " << memo; + } + catch (const fc::exception& e) + { out << " -- could not decrypt memo"; elog("Error when decrypting memo: ${e}", ("e", e.to_detail_string())); } From 2a93a15141a0632a727b05026bdbb5a69070b321 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Fri, 6 Apr 2018 10:36:12 +0200 Subject: [PATCH 114/136] comments update --- libraries/wallet/include/graphene/wallet/mining.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/mining.hpp b/libraries/wallet/include/graphene/wallet/mining.hpp index 04a36712..4963ff9b 100644 --- a/libraries/wallet/include/graphene/wallet/mining.hpp +++ b/libraries/wallet/include/graphene/wallet/mining.hpp @@ -159,13 +159,13 @@ signed_transaction set_desired_miner_count(const string& account_to_modify, bool broadcast = false); /** - * @brief Get miner voting info by account that match search term. + * @brief Get miner voting info list by account that match search term. * @param account_id account name * @param term search term - miner name * @param only_my_votes when \c true it selects only votes given by account * @param order order field. Available options are 'name\link|votes' - * @param id the id of content object to start searching from - * @param count maximum number of contents to fetch (must not exceed 1000) + * @param id the id of the miner to start searching from, or empty when start from beginning + * @param count maximum number of miners info to fetch (must not exceed 1000) * @return the contents found * @ingroup WalletAPI_Mining */ From 5578aa26ba89a553b59df165a75d1e5360988e0a Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Sun, 8 Apr 2018 16:32:05 +0200 Subject: [PATCH 115/136] add custom asset_ops extensions --- libraries/chain/asset_evaluator.cpp | 9 ++++++--- libraries/chain/decent_evaluator.cpp | 6 +++--- libraries/chain/hardfork.d/2.hf | 2 +- .../include/graphene/chain/protocol/asset_ops.hpp | 15 ++++++++++++--- .../include/graphene/chain/protocol/decent.hpp | 2 +- .../graphene/chain/protocol/operations.hpp | 6 +++--- libraries/chain/protocol/asset_ops.cpp | 2 +- libraries/chain/transfer_evaluator.cpp | 2 +- libraries/wallet/wallet.cpp | 4 ++-- 9 files changed, 30 insertions(+), 18 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 7d825aaf..0b906197 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -54,12 +54,16 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o core_fee_paid -= core_fee_paid.value/2; + bool is_fixed_max_supply = op.options.extensions.count( asset_options::fixed_max_supply_struct(true) ); + if( op.monitored_asset_opts.valid() ) { FC_ASSERT( op.monitored_asset_opts->feed_lifetime_sec > d.get_global_properties().parameters.block_interval ); FC_ASSERT( op.options.max_supply == 0 ); } + FC_ASSERT( d.head_block_time()>HARDFORK_2_TIME || !is_fixed_max_supply ); + return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -154,8 +158,8 @@ void_result user_issued_asset_update_evaluator::do_evaluate(const update_user_is if( o.new_issuer ) FC_ASSERT(d.find_object(*o.new_issuer)); - if (a.options.is_fixed_max_supply) - FC_ASSERT(o.max_supply == a.options.max_supply, "Asset ${uia} is fixed max_supply.", ("uia", a.symbol) ); + if( a.options.extensions.count( asset_options::fixed_max_supply_struct(true) )) + FC_ASSERT(o.max_supply == a.options.max_supply, "Asset ${uia} has fixed max supply.", ("uia", a.symbol) ); asset_to_update = &a; FC_ASSERT( o.issuer == a.issuer, "", ("o.issuer", o.issuer)("a.issuer", a.issuer) ); @@ -175,7 +179,6 @@ void_result user_issued_asset_update_evaluator::do_apply(const update_user_issue a.options.max_supply = o.max_supply; a.options.core_exchange_rate = o.core_exchange_rate; a.options.is_exchangeable = o.is_exchangeable; - //a.options.is_fixed_max_supply can't be changed by update operation }); return void_result(); diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index f98d8870..658b237e 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -129,8 +129,8 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri void_result content_submit_evaluator::do_evaluate(const content_submit_operation& o ) {try{ - if( o.key_parts.size() == 0 ) //simplified content - TODO - FC_ASSERT(db().head_block_time() >= HARDFORK_2_TIME); + if( o.key_parts.size() == 0 ) //simplified content + FC_ASSERT(db().head_block_time() > HARDFORK_2_TIME); db().get(o.author); //Submission rights feature is disabled @@ -503,7 +503,7 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri bool delivered = false; asset escrow = paid_price_after_conversion; - if( content->key_parts.size() == 0 ){ //simplified content buying - TODO + if( content->key_parts.size() == 0 ){ //simplified content buying delivered = true; escrow = asset(0); } diff --git a/libraries/chain/hardfork.d/2.hf b/libraries/chain/hardfork.d/2.hf index 9bbf0ce2..74599f5d 100644 --- a/libraries/chain/hardfork.d/2.hf +++ b/libraries/chain/hardfork.d/2.hf @@ -1,5 +1,5 @@ // #2 - simple content; payment to content; option to fix asset max supply; new wallet file format. #ifndef HARDFORK_2_TIME -#define HARDFORK_2_TIME (fc::time_point_sec( 1522800000 )) //2018-4-4 00:00:00 +#define HARDFORK_2_TIME (fc::time_point_sec( 1523145600 )) //2018-4-8 00:00:00 #endif diff --git a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp index 152e65a5..0612ab44 100644 --- a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp +++ b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp @@ -48,10 +48,18 @@ namespace graphene { namespace chain { /// True to allow implicit conversion of this asset to/from core asset. bool is_exchangeable = true; + + /// Extensions + /// False when issuer can change max_supply, otherwise false - bool is_fixed_max_supply = false; + struct fixed_max_supply_struct{ + bool is_fixed_max_supply; + fixed_max_supply_struct(bool is_fixed=false) : is_fixed_max_supply{ is_fixed } {}; + }; - extensions_type extensions; + typedef static_variant asset_options_extensions; + typedef flat_set asset_options_extensions_type; + asset_options_extensions_type extensions; /// Perform internal consistency checks. /// @throws fc::exception if any check fails @@ -322,11 +330,12 @@ FC_REFLECT( graphene::chain::monitored_asset_options, (minimum_feeds) ) +FC_REFLECT( graphene::chain::asset_options::fixed_max_supply_struct, (is_fixed_max_supply) ) +FC_REFLECT_TYPENAME( graphene::chain::asset_options::asset_options_extensions ) FC_REFLECT( graphene::chain::asset_options, (max_supply) (core_exchange_rate) (is_exchangeable) - (is_fixed_max_supply) (extensions) ) diff --git a/libraries/chain/include/graphene/chain/protocol/decent.hpp b/libraries/chain/include/graphene/chain/protocol/decent.hpp index 2a5b92cf..f84fbbd9 100644 --- a/libraries/chain/include/graphene/chain/protocol/decent.hpp +++ b/libraries/chain/include/graphene/chain/protocol/decent.hpp @@ -66,7 +66,7 @@ namespace graphene { namespace chain { */ struct content_submit_operation : public base_operation { - struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION / 1000; }; + struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION / 100; }; asset fee; account_id_type author; /// operation; /// @} // operations group diff --git a/libraries/chain/protocol/asset_ops.cpp b/libraries/chain/protocol/asset_ops.cpp index 1a5ac5f3..fd349fbc 100644 --- a/libraries/chain/protocol/asset_ops.cpp +++ b/libraries/chain/protocol/asset_ops.cpp @@ -91,7 +91,7 @@ void asset_create_operation::validate()const { FC_ASSERT( fee.amount >= 0 ); FC_ASSERT( is_valid_symbol(symbol) ); - FC_ASSERT(precision <= 12); + FC_ASSERT( precision <= 12 ); FC_ASSERT( description.length() <= 1000 ); if( monitored_asset_opts.valid() ) { diff --git a/libraries/chain/transfer_evaluator.cpp b/libraries/chain/transfer_evaluator.cpp index da81a986..14f4d9b6 100644 --- a/libraries/chain/transfer_evaluator.cpp +++ b/libraries/chain/transfer_evaluator.cpp @@ -79,7 +79,7 @@ void_result transfer2_evaluator::do_evaluate( const transfer2_operation& op ) { try { const database& d = db(); - FC_ASSERT(db().head_block_time() >= HARDFORK_2_TIME ); + FC_ASSERT(db().head_block_time() > HARDFORK_2_TIME ); const account_object& from_account = op.from(d); const asset_object& asset_type = op.amount.asset_id(d); diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index a5080747..135c7af9 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1152,7 +1152,7 @@ class wallet_api_impl opts.max_supply = max_supply; opts.core_exchange_rate = core_exchange_rate; opts.is_exchangeable = is_exchangeable; - opts.is_fixed_max_supply = is_fixed_max_supply; + opts.extensions.insert(asset_options::fixed_max_supply_struct(is_fixed_max_supply)); create_op.options = opts; create_op.monitored_asset_opts = optional(); @@ -1894,7 +1894,7 @@ class wallet_api_impl } signed_transaction tx; - if( head_block_time() >= HARDFORK_2_TIME ) + if( head_block_time() > HARDFORK_2_TIME ) { transfer2_operation xfer_op; From bd5e74999571c018245ad23d038a64720c9583a6 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Mon, 9 Apr 2018 09:20:51 +0200 Subject: [PATCH 116/136] Dialogs text updated --- programs/gui_wallet/src/mainwindow.cpp | 4 ++-- programs/gui_wallet/src/mining_vote_popup.cpp | 8 ++++---- programs/gui_wallet/src/richdialog.cpp | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index ecfd8ba5..ffbc3954 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -122,7 +122,7 @@ MainWindow::MainWindow() m_pButtonTransactions->setCheckable(true); m_pButtonPublish = new DecentButton(pMainWidget, DecentButton::TabChoice); - m_pButtonPublish->setText(tr("Publish")); + m_pButtonPublish->setText(tr("Items Published")); m_pButtonPublish->setCheckable(true); m_pButtonUsers = new DecentButton(pMainWidget, DecentButton::TabChoice); @@ -130,7 +130,7 @@ MainWindow::MainWindow() m_pButtonUsers->setCheckable(true); m_pButtonPurchased = new DecentButton(pMainWidget, DecentButton::TabChoice); - m_pButtonPurchased->setText(tr("Purchased")); + m_pButtonPurchased->setText(tr("Items Purchased")); m_pButtonPurchased->setCheckable(true); m_pButtonMinerVoting = new DecentButton(pMainWidget, DecentButton::TabChoice); diff --git a/programs/gui_wallet/src/mining_vote_popup.cpp b/programs/gui_wallet/src/mining_vote_popup.cpp index 7cf158ae..e3b03658 100644 --- a/programs/gui_wallet/src/mining_vote_popup.cpp +++ b/programs/gui_wallet/src/mining_vote_popup.cpp @@ -22,7 +22,7 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) getMinerVotesForAccount(account_name); QLabel* pMinersVoteNumLabel = new QLabel(this); - pMinersVoteNumLabel->setText(tr("Vote for number of miners")); + pMinersVoteNumLabel->setText(tr("Propose number of miners in mining pool")); QIntValidator* numValidator = new QIntValidator(1, 1001, this); //TODO: make max value read from global_properties @@ -34,15 +34,15 @@ MiningVotePopup::MiningVotePopup(QWidget *pParent) : StackLayerWidget(pParent) m_pMinersNumVote->setText(QString::number(m_minersVotedNum)); } else { - m_pMinersNumVote->setPlaceholderText(QString(tr("Actual miners count is %1")).arg(numOfActiveMiners) ); + m_pMinersNumVote->setPlaceholderText(QString(tr("Current miner pool size is %1")).arg(numOfActiveMiners) ); } Asset opFee = Globals::instance().getDCoreFees(2); // Info QLabel* pInfoLabel = new QLabel(this); - pInfoLabel->setText(QString(tr("Number of miners should be smaller or equal to number of votes you have given (%1)\n" - "You will be charged %2 for this operation")) + pInfoLabel->setText(QString(tr("You cannot propose a pool size larger than the number of miners you have currently voted for (%1)\n" + "This operation will cost %2")) .arg(m_curMinersVotedFor) .arg(opFee.getString())); diff --git a/programs/gui_wallet/src/richdialog.cpp b/programs/gui_wallet/src/richdialog.cpp index ca2f9046..21ef6d28 100644 --- a/programs/gui_wallet/src/richdialog.cpp +++ b/programs/gui_wallet/src/richdialog.cpp @@ -938,11 +938,11 @@ PasswordWidget::PasswordWidget(QWidget* pParent, eType enType) : StackLayerWidge m_pButton = new DecentButton(this, DecentButton::DialogAction); if (enType == eSetPassword) { - pLabel->setText(tr("Create your password for DECENT wallet")); + pLabel->setText(tr("Create your password for DECENT Wallet")); m_pButton->setText(tr("Create Password")); } else { - pLabel->setText(tr("Unlock your DECENT wallet")); + pLabel->setText(tr("Unlock your DECENT Wallet")); m_pButton->setText(tr("Unlock")); } @@ -956,7 +956,7 @@ PasswordWidget::PasswordWidget(QWidget* pParent, eType enType) : StackLayerWidge m_line1Edit->setPlaceholderText(QString(tr("Password"))); } m_line1Edit->setMaxLength(g_maxPasswordLen); - m_line1Edit->setToolTip(tr("The password must be limited to 50 characters")); + m_line1Edit->setToolTip(tr("The password is limited to a maximum of 50 characters ")); m_line2Edit = new DecentLineEdit(this, DecentLineEdit::DialogLineEdit); m_line2Edit->setEchoMode(QLineEdit::Password); From 7523d3fa2c361871b799d6eeffcbeac0b3f4f8bc Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 9 Apr 2018 13:06:49 +0200 Subject: [PATCH 117/136] add payment_to_content details to transaction_detail_object --- libraries/chain/transfer_evaluator.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/chain/transfer_evaluator.cpp b/libraries/chain/transfer_evaluator.cpp index 14f4d9b6..babed335 100644 --- a/libraries/chain/transfer_evaluator.cpp +++ b/libraries/chain/transfer_evaluator.cpp @@ -100,6 +100,7 @@ void_result transfer2_evaluator::do_apply( const transfer2_operation& o ) account_id_type to_acc; d.adjust_balance( o.from, -o.amount ); + string suffix; if( o.to.is() ) { @@ -124,6 +125,7 @@ void_result transfer2_evaluator::do_apply( const transfer2_operation& o ) } to_acc = content_itr->author; + suffix = " to content " + std::string(content_itr->id); if( amount.amount != 0 ) { FC_ASSERT( amount.amount > 0 ); @@ -131,7 +133,7 @@ void_result transfer2_evaluator::do_apply( const transfer2_operation& o ) } } - d.create([&o, &d, &to_acc](transaction_detail_object& obj) + d.create([&o, &d, &to_acc, &suffix](transaction_detail_object& obj) { obj.m_operation_type = (uint8_t)transaction_detail_object::transfer; @@ -140,7 +142,7 @@ void_result transfer2_evaluator::do_apply( const transfer2_operation& o ) obj.m_transaction_amount = o.amount; obj.m_transaction_fee = o.fee; obj.m_transaction_encrypted_memo = o.memo; - obj.m_str_description = "transfer"; + obj.m_str_description = "transfer" + suffix; obj.m_timestamp = d.head_block_time(); }); return void_result(); From c81bac81fc08f04c55f5119e0db63cf16a403e11 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Mon, 9 Apr 2018 18:14:38 +0200 Subject: [PATCH 118/136] bug fixes in usage of asset_ops extensions --- libraries/chain/asset_evaluator.cpp | 17 ++++++++++++++--- libraries/wallet/wallet.cpp | 7 +++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 0b906197..0a905242 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -54,15 +54,22 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o core_fee_paid -= core_fee_paid.value/2; - bool is_fixed_max_supply = op.options.extensions.count( asset_options::fixed_max_supply_struct(true) ); + bool count_fixed_max_supply_ext = op.options.extensions.count( asset_options::fixed_max_supply_struct() ); if( op.monitored_asset_opts.valid() ) { FC_ASSERT( op.monitored_asset_opts->feed_lifetime_sec > d.get_global_properties().parameters.block_interval ); FC_ASSERT( op.options.max_supply == 0 ); + FC_ASSERT( !count_fixed_max_supply_ext ); + } + else // UIA + { + if( d.head_block_time() > HARDFORK_2_TIME ) + FC_ASSERT( count_fixed_max_supply_ext ); + else + FC_ASSERT( !count_fixed_max_supply_ext ); } - FC_ASSERT( d.head_block_time()>HARDFORK_2_TIME || !is_fixed_max_supply ); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -158,7 +165,11 @@ void_result user_issued_asset_update_evaluator::do_evaluate(const update_user_is if( o.new_issuer ) FC_ASSERT(d.find_object(*o.new_issuer)); - if( a.options.extensions.count( asset_options::fixed_max_supply_struct(true) )) + auto itr = a.options.extensions.find( asset_options::fixed_max_supply_struct() ); + bool is_fixed_max_supply = false; + if( itr != a.options.extensions.end() ) + is_fixed_max_supply = itr->get().is_fixed_max_supply; + if( is_fixed_max_supply ) FC_ASSERT(o.max_supply == a.options.max_supply, "Asset ${uia} has fixed max supply.", ("uia", a.symbol) ); asset_to_update = &a; diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 135c7af9..0c939cf6 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1152,7 +1152,14 @@ class wallet_api_impl opts.max_supply = max_supply; opts.core_exchange_rate = core_exchange_rate; opts.is_exchangeable = is_exchangeable; + + if( head_block_time() > HARDFORK_2_TIME ) + { opts.extensions.insert(asset_options::fixed_max_supply_struct(is_fixed_max_supply)); + } + else + FC_ASSERT( !is_fixed_max_supply ); + create_op.options = opts; create_op.monitored_asset_opts = optional(); From 9c91c6e07483998669e0898d564f936ae2ebfd1d Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Tue, 10 Apr 2018 07:55:19 +0200 Subject: [PATCH 119/136] add comment to duplicate variable and obsolete op --- .../chain/include/graphene/chain/protocol/asset_ops.hpp | 2 +- .../chain/include/graphene/chain/protocol/transfer.hpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp index 0612ab44..71792e4c 100644 --- a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp +++ b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp @@ -128,7 +128,7 @@ namespace graphene { namespace chain { optional monitored_asset_opts; - /// True to allow implicit conversion of this asset to/from core asset. + /// WARNING! Duplicate variable. Do no use it. It does not have any effect. bool is_exchangeable = true; extensions_type extensions; diff --git a/libraries/chain/include/graphene/chain/protocol/transfer.hpp b/libraries/chain/include/graphene/chain/protocol/transfer.hpp index 77c43c02..3deedddb 100644 --- a/libraries/chain/include/graphene/chain/protocol/transfer.hpp +++ b/libraries/chain/include/graphene/chain/protocol/transfer.hpp @@ -31,10 +31,10 @@ namespace graphene { namespace chain { /** * @ingroup operations * - * @brief Transfers an amount of one asset from one account to another - * - * Fees are paid by the "from" account + * @brief Transfers an amount of one asset from one account to another. + * Fees are paid by the "from" account. * + * @warning Obsolete operation. Use \c transfer2_operation instead. * @pre amount.amount > 0 * @pre fee.amount >= 0 * @pre from != to From 2e090fe886d37f810c3b051e9e1e61b0d2517a33 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 10 Apr 2018 09:57:48 +0200 Subject: [PATCH 120/136] added version in wallet_data and storing/loading according it. --- .../wallet/include/graphene/wallet/wallet.hpp | 3 + libraries/wallet/wallet.cpp | 128 +++++++++++++++++- libraries/wallet/wallet_wallet_file.inl | 44 ++++-- 3 files changed, 154 insertions(+), 21 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 8012d359..041b092c 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -54,6 +54,7 @@ namespace graphene { namespace wallet { struct wallet_data { + int version = 0; /** Chain ID this wallet is used with */ chain_id_type chain_id; account_multi_index_type my_accounts; @@ -100,6 +101,7 @@ namespace graphene { namespace wallet { string ws_password; string packages_path = "./packages/"; string libtorrent_config_path; + string update_time; }; struct el_gamal_key_pair @@ -299,6 +301,7 @@ namespace graphene { namespace wallet { std::map> get_result_formatters() const; void encrypt_keys(); + void encrypt_keys2(); fc::signal lock_changed; std::shared_ptr my; diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 0c939cf6..2dbfe4ef 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -506,6 +506,24 @@ class wallet_api_impl } } + void encrypt_keys2() + { + if( !is_locked() ) + { + plain_ec_and_el_gamal_keys data; + data.ec_keys = _keys; + std::transform( _el_gamal_keys.begin(), _el_gamal_keys.end(), std::back_inserter( data.el_gamal_keys ), + [](const std::pair el_gamal_pair) { + return el_gamal_key_pair_str {el_gamal_pair.second, el_gamal_pair.first}; }); + data.checksum = _checksum; + auto data_string = fc::json::to_string(data); + vector plain_txt; + plain_txt.resize(data_string.length()); + memcpy(plain_txt.data(), data_string.data(), data_string.length()); + _wallet.cipher_keys = fc::aes_encrypt( data.checksum, plain_txt ); + } + } + void on_block_applied( const variant& block_id ) { fc::async([this]{resync();}, "Resync after block"); @@ -748,6 +766,50 @@ class wallet_api_impl return all_keys_for_account.find(wif_pub_key) != all_keys_for_account.end(); } + int get_wallet_file_version(const fc::variant& data) + { + try { + variant_object vo; + fc::from_variant( data, vo ); + return vo["version"].as(); + } + catch (const fc::exception& ex) { + return 0; + } + } + + bool load_old_wallet_file(const fc::variant& data, wallet_data& result) + { + bool ret; + try { + result = data.as(); + ret = true; + } + catch (const fc::exception& ex) { + ret = false; + } + return ret; + } + + bool load_new_wallet_file(const fc::variant& data, wallet_data& result) + { + bool ret; + try { + result = data.as(); + + const variant_object& vo = data.get_object(); + result.version = vo["version"].as(); + result.update_time = vo["update_time"].as_string(); + + ret = true; + } + catch (const fc::exception& ex) { + ret = false; + } + return ret; + } + + bool load_wallet_file(string wallet_filename = string()) { // TODO: Merge imported wallet with existing wallet, @@ -758,11 +820,28 @@ class wallet_api_impl if( ! fc::exists( wallet_filename ) ) return false; - _wallet = fc::json::from_file( wallet_filename ).as< wallet_data >(); - if( _wallet.chain_id != _chain_id ) - FC_THROW( "Wallet chain ID does not match", - ("wallet.chain_id", _wallet.chain_id) - ("chain_id", _chain_id) ); + fc::variant v = fc::json::from_file(wallet_filename); + int version = get_wallet_file_version(v); + + bool ret; + wallet_data load_data; + if (version == 0) { + ret = load_old_wallet_file(v, load_data); + } + else { + ret = load_new_wallet_file(v, load_data); + } + + if (!ret) { + return false; + } + + _wallet = load_data; + if( _wallet.chain_id != _chain_id ) { + FC_THROW("Wallet chain ID does not match", + ("wallet.chain_id", _wallet.chain_id) + ("chain_id", _chain_id)); + } size_t account_pagination = 100; vector< account_id_type > account_ids_to_send; @@ -810,6 +889,31 @@ class wallet_api_impl return true; } + + string save_old_wallet(const wallet_data& data) + { + return fc::json::to_pretty_string( _wallet ); + } + + string save_new_wallet(const wallet_data& data) + { + fc::mutable_variant_object mvo; + mvo["version"] = fc::variant(data.version); + mvo["update_time"] = fc::variant(data.update_time); + mvo["chain_id"] = fc::variant(data.chain_id); + mvo["my_accounts"] = fc::variant(data.my_accounts); + mvo["cipher_keys"] = fc::variant(data.cipher_keys); + mvo["extra_keys"] = fc::variant(data.extra_keys); + mvo["pending_account_registrations"] = fc::variant(data.pending_account_registrations); + mvo["pending_miner_registrations"] = fc::variant(data.pending_miner_registrations); + mvo["ws_server"] = fc::variant(data.ws_server); + mvo["ws_user"] = fc::variant(data.ws_user); + mvo["ws_password"] = fc::variant(data.ws_password); + + fc::variant v(mvo); + return fc::json::to_pretty_string( v ); + } + void save_wallet_file(string wallet_filename = string() ) { // @@ -819,14 +923,24 @@ class wallet_api_impl // if exceptions are thrown in serialization // - encrypt_keys(); + //allways save in new format + _wallet.version = 1; + _wallet.update_time = fc::time_point::now(); + encrypt_keys2(); if( wallet_filename.empty() ) wallet_filename = _wallet_filename; wlog( "saving wallet to file ${fn}", ("fn", wallet_filename) ); - string data = fc::json::to_pretty_string( _wallet ); + string data; + if (_wallet.version == 0) { + data = save_old_wallet( _wallet ); + } + else { + data = save_new_wallet( _wallet ); + } + try { enable_umask_protection(); diff --git a/libraries/wallet/wallet_wallet_file.inl b/libraries/wallet/wallet_wallet_file.inl index 84b47b19..59fc82c0 100644 --- a/libraries/wallet/wallet_wallet_file.inl +++ b/libraries/wallet/wallet_wallet_file.inl @@ -44,23 +44,39 @@ void wallet_api::unlock(const string& password) plain_ec_and_el_gamal_keys pk; bool update_wallet_file = false; - // supporting backward compatibility of wallet json file - try { - pk = fc::raw::unpack(decrypted); - } - catch(const fc::exception&) - { - pk = fc::raw::unpack(decrypted); - // wallet file is in old format, derive corresponding el gamal keys from private keys - for( const auto& element : pk.ec_keys ) + if (my->_wallet.version == 0) { + + // supporting backward compatibility of wallet json file + try { + pk = fc::raw::unpack(decrypted); + } + catch(const fc::exception&) { - el_gamal_key_pair_str el_gamal_keys_str; - el_gamal_keys_str.private_key = generate_private_el_gamal_key_from_secret( wif_to_key( element.second )->get_secret() ); - el_gamal_keys_str.public_key = get_public_el_gamal_key( el_gamal_keys_str.private_key ); - pk.el_gamal_keys.push_back( el_gamal_keys_str ); + pk = fc::raw::unpack(decrypted); + // wallet file is in old format, derive corresponding el gamal keys from private keys + for( const auto& element : pk.ec_keys ) + { + el_gamal_key_pair_str el_gamal_keys_str; + el_gamal_keys_str.private_key = generate_private_el_gamal_key_from_secret( wif_to_key( element.second )->get_secret() ); + el_gamal_keys_str.public_key = get_public_el_gamal_key( el_gamal_keys_str.private_key ); + pk.el_gamal_keys.push_back( el_gamal_keys_str ); + } + update_wallet_file = true; + } + } + else { + + try { + string data; + data.reserve(decrypted.size()); + std::copy(decrypted.begin(), decrypted.end(), back_inserter(data)); + pk = fc::json::from_string(data).as(); + } + catch(const fc::exception&) { + throw; } - update_wallet_file = true; } + FC_ASSERT(pk.checksum == pw); my->_keys = std::move(pk.ec_keys); if( !pk.el_gamal_keys.empty() ) From fca8e6de1be53e9034d3caa5aa400828ae5e6f7d Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 10 Apr 2018 10:46:02 +0200 Subject: [PATCH 121/136] added set save new wallet_file flag --- libraries/wallet/wallet_wallet_file.inl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libraries/wallet/wallet_wallet_file.inl b/libraries/wallet/wallet_wallet_file.inl index 59fc82c0..e4198248 100644 --- a/libraries/wallet/wallet_wallet_file.inl +++ b/libraries/wallet/wallet_wallet_file.inl @@ -49,6 +49,8 @@ void wallet_api::unlock(const string& password) // supporting backward compatibility of wallet json file try { pk = fc::raw::unpack(decrypted); + + update_wallet_file = true; } catch(const fc::exception&) { @@ -79,9 +81,13 @@ void wallet_api::unlock(const string& password) FC_ASSERT(pk.checksum == pw); my->_keys = std::move(pk.ec_keys); - if( !pk.el_gamal_keys.empty() ) - std::transform( pk.el_gamal_keys.begin(), pk.el_gamal_keys.end(), std::inserter( my->_el_gamal_keys, my->_el_gamal_keys.end() ), - []( const el_gamal_key_pair_str el_gamal_pair ){ return std::make_pair(DInteger(el_gamal_pair.public_key),DInteger(el_gamal_pair.private_key)); }); + if( !pk.el_gamal_keys.empty() ) { + std::transform(pk.el_gamal_keys.begin(), pk.el_gamal_keys.end(), + std::inserter(my->_el_gamal_keys, my->_el_gamal_keys.end()), + [](const el_gamal_key_pair_str el_gamal_pair) { + return std::make_pair(DInteger(el_gamal_pair.public_key), DInteger(el_gamal_pair.private_key)); + }); + } my->_checksum = pk.checksum; if( update_wallet_file ) // upgrade structure for storing keys to new format From 8e528beee9e78ac3fcbef5d971c0a8bdbb57ce16 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 10 Apr 2018 13:02:12 +0200 Subject: [PATCH 122/136] added hour-glass to lengthy operations fixed problem with links in voting tab --- .../gui_wallet/src/gui_wallet_tabcontentmanager.cpp | 11 +++++++++-- programs/gui_wallet/src/mainwindow.cpp | 1 + programs/gui_wallet/src/mining_vote_tab.cpp | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp b/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp index 3e7c88e6..6941d51b 100644 --- a/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp +++ b/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp @@ -3,6 +3,7 @@ #include "gui_wallet_tabcontentmanager.hpp" #include +#include using std::string; @@ -19,9 +20,14 @@ TabContentManager::TabContentManager(QWidget* pParent/* = nullptr*/) : QWidget(p void TabContentManager::tryToUpdate() { try { + + QApplication::setOverrideCursor(Qt::WaitCursor); + std::string command = getUpdateCommand(); if (command.empty()) { timeToUpdate(std::string()); + + QApplication::restoreOverrideCursor(); return; } @@ -31,17 +37,18 @@ void TabContentManager::tryToUpdate() { } catch (std::exception &ex) { error = ex.what(); - } catch (fc::exception& ex) { error = ex.what(); - } if (result != m_last_result) { m_last_result = result; timeToUpdate(result); } + + QApplication::restoreOverrideCursor(); + } catch (...) { } diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index ffbc3954..8134528b 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include "update_manager.hpp" diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp index ca64248e..4ac87157 100644 --- a/programs/gui_wallet/src/mining_vote_tab.cpp +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -70,6 +70,8 @@ MinerVotingTab::MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &MinerVotingTab::slot_SortingChanged); + QObject::connect(m_pTableWidget, &DecentTable::cellClicked, this, &MinerVotingTab::slot_cellClicked); + setRefreshTimer(5000); } @@ -161,8 +163,6 @@ void MinerVotingTab::timeToUpdate(const std::string& result) //TODO.. handle error } - QObject::connect(m_pTableWidget, &DecentTable::cellClicked, this, &MinerVotingTab::slot_cellClicked); - if (contents.size() > m_i_page_size) set_next_page_iterator(contents[m_i_page_size]["id"].get()); else From 38183cd1a715e22c524d709803161708491a74cd Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 10 Apr 2018 14:08:03 +0200 Subject: [PATCH 123/136] improved voting tab - showing votes in iso prefix units --- programs/gui_wallet/src/mining_vote_tab.cpp | 50 +++++++++++++++++++-- programs/gui_wallet/src/mining_vote_tab.hpp | 1 + 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp index 4ac87157..e5f409e5 100644 --- a/programs/gui_wallet/src/mining_vote_tab.cpp +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -78,6 +78,47 @@ MinerVotingTab::MinerVotingTab(QWidget *pParent, DecentLineEdit *pFilterLineEdit MinerVotingTab::~MinerVotingTab() = default; +QString MinerVotingTab::getVotesText(uint64_t total_votes) +{ + double votes = total_votes; + + int iCount = 0; + while(votes >= 1000.0) { + votes /= 1000.0; + iCount++; + + if (votes < 500000.0) + break; + } + + QString result = QString::number(votes); + result += ' '; + + switch(iCount) + { + case 1: + result += "kV"; //Kilo Votes + break; + case 2: + result += "MV"; //Mega Votes + break; + case 3: + result += "GV"; //Giga Votes + break; + case 4: + result += "TV"; //Tera Votes + break; + case 5: + result += "PV"; //Penta Votes + break; + case 6: + result += "EV"; //Exa Votes + break; + } + + return result; +} + void MinerVotingTab::timeToUpdate(const std::string& result) { if (result.empty()) { @@ -96,9 +137,9 @@ void MinerVotingTab::timeToUpdate(const std::string& result) m_indexToUrl.clear(); //clear table - while(m_pTableWidget->rowCount() > 0) { - m_pTableWidget->removeRow(0); - } +// while(m_pTableWidget->rowCount() > 0) { +// m_pTableWidget->removeRow(0); +// } try { @@ -132,7 +173,8 @@ void MinerVotingTab::timeToUpdate(const std::string& result) m_indexToUrl.insert(iIndex, QString::fromStdString(url)); } - tabItem = new QTableWidgetItem(QString::number(total_votes)); + tabItem = new QTableWidgetItem(getVotesText(total_votes)); + tabItem->setToolTip(QString::number(total_votes)); tabItem->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); tabItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); m_pTableWidget->setItem(iIndex, 2, tabItem); diff --git a/programs/gui_wallet/src/mining_vote_tab.hpp b/programs/gui_wallet/src/mining_vote_tab.hpp index 50763e64..89aeadc3 100644 --- a/programs/gui_wallet/src/mining_vote_tab.hpp +++ b/programs/gui_wallet/src/mining_vote_tab.hpp @@ -36,6 +36,7 @@ namespace gui_wallet private: void submit_vote(const std::string& miner_name, bool voteFlag); void getDesiredMinersCount(); + QString getVotesText(uint64_t total_votes); public: DecentTable* m_pTableWidget; From 36f346da30ec10e05e5b60c1639bcc23e5247fa6 Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Tue, 10 Apr 2018 14:51:34 +0200 Subject: [PATCH 124/136] BugFix: invalid reference --- libraries/plugins/seeding/seeding.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/plugins/seeding/seeding.cpp b/libraries/plugins/seeding/seeding.cpp index 50251435..5fa18f9c 100644 --- a/libraries/plugins/seeding/seeding.cpp +++ b/libraries/plugins/seeding/seeding.cpp @@ -772,7 +772,7 @@ void detail::SeedingListener::package_download_complete() { if( size > mso_itr->space ) { ilog("seeding plugin: package_download_complete(): Fraud detected: real content size is greater than propagated in blockchain; deleting..."); //changing DB outside the main thread does not work properly, let's delete it from there - _my->main_thread->async([ & ]() { _my->release_package(mso, pi); }); + _my->main_thread->async([ this, &mso, pi ]() { _my->release_package(mso, pi); }); _pi.reset(); return; } @@ -780,7 +780,7 @@ void detail::SeedingListener::package_download_complete() { //Don't block package manager thread for too long. seeding_plugin_impl *my = _my; _my->database().modify(mso, [](my_seeding_object& so){so.downloaded = true;}); - _my->service_thread->async([ & ]() { _my->generate_por_int(mso, pi); }); + _my->service_thread->async([ this, &mso, pi ]() { _my->generate_por_int(mso, pi); }); }; From 2200a19217d639fc0bb40dd7862150d865962cb5 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 10 Apr 2018 14:54:44 +0200 Subject: [PATCH 125/136] added disabling buy&download button when from publish tab added refresh table when window is resized (after 1 sec.) --- .../src/gui_wallet_tabcontentmanager.cpp | 8 +++- programs/gui_wallet/src/mainwindow.cpp | 13 ++++++ programs/gui_wallet/src/mainwindow.hpp | 3 ++ programs/gui_wallet/src/richdialog.cpp | 40 +++++++++++-------- programs/gui_wallet/src/richdialog.hpp | 4 +- programs/gui_wallet/src/upload_tab.cpp | 2 +- 6 files changed, 48 insertions(+), 22 deletions(-) diff --git a/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp b/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp index 6941d51b..0c6f51a5 100644 --- a/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp +++ b/programs/gui_wallet/src/gui_wallet_tabcontentmanager.cpp @@ -49,8 +49,12 @@ void TabContentManager::tryToUpdate() { QApplication::restoreOverrideCursor(); - } catch (...) { - + } + catch (const std::exception& ex) { + std::cout << "Exception:" << ex.what() << std::endl; + } + catch (const fc::exception& ex) { + std::cout << "Exception:" << ex.what() << std::endl; } } diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 8134528b..1f688d21 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -62,6 +62,7 @@ MainWindow::MainWindow() : QMainWindow() , m_iSplashWidgetIndex(0) , m_pTimerBalance(new QTimer(this)) +, m_pOneShotUpdateTimer(new QTimer(this)) , m_pStackedWidget(new QStackedWidget(this)) , m_pAccountList(nullptr) , m_pBalance(nullptr) @@ -386,6 +387,11 @@ MainWindow::MainWindow() QObject::connect(m_pTimerBalance, &QTimer::timeout, &Globals::instance(), &Globals::slot_updateAccountBalance); + m_pOneShotUpdateTimer->setInterval(1000); + m_pOneShotUpdateTimer->setSingleShot(true); + QObject::connect(m_pOneShotUpdateTimer, &QTimer::timeout, + this, &MainWindow::slot_getContents); + // m_pTimerDownloads->setInterval(5000); // QObject::connect(m_pTimerDownloads, &QTimer::timeout, @@ -1029,6 +1035,13 @@ TabContentManager* MainWindow::activeTable() const return pTab; } +void MainWindow::resizeEvent(QResizeEvent* event) +{ + QMainWindow::resizeEvent(event); + + m_pOneShotUpdateTimer->start(); +} + void MainWindow::DisplayWalletContentGUI() { Globals::instance().setWalletUnlocked(); diff --git a/programs/gui_wallet/src/mainwindow.hpp b/programs/gui_wallet/src/mainwindow.hpp index aea82ae8..f5dcacb1 100644 --- a/programs/gui_wallet/src/mainwindow.hpp +++ b/programs/gui_wallet/src/mainwindow.hpp @@ -67,9 +67,12 @@ protected slots: TabContentManager* activeTable() const; void updateActiveTable(); + void resizeEvent(QResizeEvent* event) override; + protected: size_t m_iSplashWidgetIndex; QTimer* m_pTimerBalance; + QTimer* m_pOneShotUpdateTimer; QStackedWidget* m_pStackedWidget; QComboBox* m_pAccountList; diff --git a/programs/gui_wallet/src/richdialog.cpp b/programs/gui_wallet/src/richdialog.cpp index 21ef6d28..9acd1670 100644 --- a/programs/gui_wallet/src/richdialog.cpp +++ b/programs/gui_wallet/src/richdialog.cpp @@ -360,7 +360,7 @@ UserInfoWidget::UserInfoWidget(QWidget* parent, // // ContentInfoWidget // -ContentInfoWidget::ContentInfoWidget(QWidget* parent, const SDigitalContent& a_cnt_details) +ContentInfoWidget::ContentInfoWidget(QWidget* parent, const SDigitalContent& a_cnt_details, bool bRemoveBuyButton) : StackLayerWidget(parent) , m_getItOrPay(Download) , m_URI(a_cnt_details.URI) @@ -462,30 +462,36 @@ ContentInfoWidget::ContentInfoWidget(QWidget* parent, const SDigitalContent& a_c main_layout->addWidget(pCommentWidget, iRowIndex, 0, 1, 2); pCommentWidget->update(); ++iRowIndex; - - DecentButton* getItButton = new DecentButton(this, DecentButton::DialogAction); - DecentButton* cancelButton = new DecentButton(this, DecentButton::DialogCancel); - - if (a_cnt_details.price.m_amount == 0) { - m_getItOrPay = Download; - getItButton->setText(tr("Download")); - } - else { - m_getItOrPay = PayAndDownload; - getItButton->setText(tr("Buy && Download")); - } + DecentButton* cancelButton = new DecentButton(this, DecentButton::DialogCancel); cancelButton->setText(tr("Back")); - - QObject::connect(getItButton, &QPushButton::clicked, - this, &ContentInfoWidget::ButtonWasClicked); + QObject::connect(cancelButton, &QPushButton::clicked, this, &StackLayerWidget::closed); + DecentButton* getItButton = nullptr; + if (!bRemoveBuyButton) { + getItButton = new DecentButton(this, DecentButton::DialogAction); + + if (a_cnt_details.price.m_amount == 0) { + m_getItOrPay = Download; + getItButton->setText(tr("Download")); + } + else { + m_getItOrPay = PayAndDownload; + getItButton->setText(tr("Buy && Download")); + } + + QObject::connect(getItButton, &QPushButton::clicked, + this, &ContentInfoWidget::ButtonWasClicked); + } + QHBoxLayout* pButtonsLayout = new QHBoxLayout(); // keeping buttons directly inside gridlayout cells leads to assymetry // so use hboxlayout - pButtonsLayout->addWidget(getItButton); + if (getItButton) { + pButtonsLayout->addWidget(getItButton); + } pButtonsLayout->addWidget(cancelButton); main_layout->addLayout(pButtonsLayout, iRowIndex, 0, 1, 2); diff --git a/programs/gui_wallet/src/richdialog.hpp b/programs/gui_wallet/src/richdialog.hpp index a7f892bb..ce7d1b13 100644 --- a/programs/gui_wallet/src/richdialog.hpp +++ b/programs/gui_wallet/src/richdialog.hpp @@ -114,8 +114,8 @@ class ContentInfoWidget : public StackLayerWidget { Q_OBJECT public: - ContentInfoWidget(QWidget* parent, const SDigitalContent& a_cnt_details); - + ContentInfoWidget(QWidget* parent, const SDigitalContent& a_cnt_details, bool bRemoveBuyButton = false); + void Buy(); public slots: void ButtonWasClicked(); diff --git a/programs/gui_wallet/src/upload_tab.cpp b/programs/gui_wallet/src/upload_tab.cpp index cb3d54ee..43f770b8 100644 --- a/programs/gui_wallet/src/upload_tab.cpp +++ b/programs/gui_wallet/src/upload_tab.cpp @@ -279,7 +279,7 @@ void Upload_tab::slot_ShowContentPopup(int iIndex) if (iIndex < 0 || iIndex >= _digital_contents.size()) throw std::out_of_range("Content index is out of range"); - ContentInfoWidget* pDetailsDialog = new ContentInfoWidget(nullptr, _digital_contents[iIndex]); + ContentInfoWidget* pDetailsDialog = new ContentInfoWidget(nullptr, _digital_contents[iIndex], true); Globals::instance().signal_stackWidgetPush(pDetailsDialog); QObject::connect(pDetailsDialog, &ContentInfoWidget::accepted, From a2e7ce30cf0bab8195ff7dcbce23e56e403f1733 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 10 Apr 2018 15:00:24 +0200 Subject: [PATCH 126/136] fixed linux compile error --- programs/gui_wallet/src/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index 1f688d21..c327b5cb 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -307,7 +307,7 @@ MainWindow::MainWindow() // QObject::connect(m_pAccountList, QOverload::of(&QComboBox::currentIndexChanged), // &Globals::instance(), &Globals::slot_setCurrentUser); - QObject::connect(m_pAccountList, QOverload::of(&QComboBox::currentIndexChanged), + QObject::connect(m_pAccountList, &QComboBox::currentIndexChanged, this, &MainWindow::slot_currentAccountChanged); QObject::connect(pTransferButton, &QPushButton::clicked, &Globals::instance(), (void(Globals::*)())&Globals::slot_showTransferDialog); From 68ed273d0d0b7ddd324bb1665cd82fbff063fd5e Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 10 Apr 2018 15:20:54 +0200 Subject: [PATCH 127/136] removed commented out lines --- programs/gui_wallet/src/mainwindow.cpp | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index c327b5cb..be654880 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -305,8 +305,6 @@ MainWindow::MainWindow() setUnifiedTitleAndToolBarOnMac(false); -// QObject::connect(m_pAccountList, QOverload::of(&QComboBox::currentIndexChanged), -// &Globals::instance(), &Globals::slot_setCurrentUser); QObject::connect(m_pAccountList, &QComboBox::currentIndexChanged, this, &MainWindow::slot_currentAccountChanged); QObject::connect(pTransferButton, &QPushButton::clicked, @@ -363,7 +361,6 @@ MainWindow::MainWindow() m_pAdvancedMinerVoting->setDisabled(true); } - QObject::connect(&Globals::instance(), &Globals::walletConnectionStatusChanged, this, &MainWindow::slot_connectionStatusChanged); @@ -392,19 +389,6 @@ MainWindow::MainWindow() QObject::connect(m_pOneShotUpdateTimer, &QTimer::timeout, this, &MainWindow::slot_getContents); - -// m_pTimerDownloads->setInterval(5000); -// QObject::connect(m_pTimerDownloads, &QTimer::timeout, -// this, &MainWindow::slot_checkDownloads); - -// m_pTimerContents->setInterval(1000); -// QObject::connect(m_pTimerContents, &QTimer::timeout, -// this, &MainWindow::slot_getContents); - -// m_pTimerVoting->setInterval(5000); -// QObject::connect(m_pTimerVoting, &QTimer::timeout, -// this, &MainWindow::slot_getContents); - resize(900, 600); #ifdef _MSC_VER @@ -468,8 +452,6 @@ void MainWindow::slot_setSplash() QObject::connect(&Globals::instance(), &Globals::updateProgress, this, &MainWindow::slot_BlockchainUpdate); -// QObject::connect(this, &MainWindow::signal_setSplashMainText, -// pConnectingLabel, &QLabel::setText); QObject::connect(this, &MainWindow::signal_setSplashMainText, pButton, &QWidget::show); @@ -699,7 +681,6 @@ void MainWindow::slot_BrowseToggled(bool toggled) // if (toggled) { -// m_pFilterBrowse->show(); pActiveTab->show(); updateActiveTable(); @@ -711,7 +692,6 @@ void MainWindow::slot_BrowseToggled(bool toggled) } else { -// m_pFilterBrowse->hide(); pActiveTab->hide(); QTimer* pTimer = pActiveTab->getRefreshTimer(); From 25e39d57d6c57fc8af69da1c4d79697861ed4c15 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Tue, 10 Apr 2018 16:25:38 +0200 Subject: [PATCH 128/136] changed displaying votes in voting tab --- programs/gui_wallet/src/mining_vote_tab.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp index e5f409e5..7ade003e 100644 --- a/programs/gui_wallet/src/mining_vote_tab.cpp +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -145,6 +145,8 @@ void MinerVotingTab::timeToUpdate(const std::string& result) m_pTableWidget->setRowCount(iSize); + Asset main_asset = Globals::instance().asset(0); + for (size_t iIndex = 0; iIndex < iSize; ++iIndex) { auto const &content = contents[iIndex]; @@ -173,7 +175,11 @@ void MinerVotingTab::timeToUpdate(const std::string& result) m_indexToUrl.insert(iIndex, QString::fromStdString(url)); } - tabItem = new QTableWidgetItem(getVotesText(total_votes)); + QString asset_text = QString::number((uint64_t) total_votes / main_asset.m_scale ); + asset_text += ' '; + asset_text += QString::fromStdString(main_asset.m_str_symbol); + + tabItem = new QTableWidgetItem(asset_text); tabItem->setToolTip(QString::number(total_votes)); tabItem->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); tabItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); From 8436882887cf67311c0f2f4d68e235bd00be6938 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 11 Apr 2018 09:02:55 +0200 Subject: [PATCH 129/136] added url check on voting tab --- programs/gui_wallet/src/mining_vote_tab.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/programs/gui_wallet/src/mining_vote_tab.cpp b/programs/gui_wallet/src/mining_vote_tab.cpp index 7ade003e..7754b074 100644 --- a/programs/gui_wallet/src/mining_vote_tab.cpp +++ b/programs/gui_wallet/src/mining_vote_tab.cpp @@ -146,6 +146,7 @@ void MinerVotingTab::timeToUpdate(const std::string& result) m_pTableWidget->setRowCount(iSize); Asset main_asset = Globals::instance().asset(0); + QUrl test_url; for (size_t iIndex = 0; iIndex < iSize; ++iIndex) { auto const &content = contents[iIndex]; @@ -170,10 +171,14 @@ void MinerVotingTab::timeToUpdate(const std::string& result) tabItem = new QTableWidgetItem(QString::fromStdString(url)); tabItem->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter); tabItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); - m_pTableWidget->setItem(iIndex, 1, tabItem); + if (!url.empty()) { - m_indexToUrl.insert(iIndex, QString::fromStdString(url)); + test_url.setUrl(QString::fromStdString(url)); + if (test_url.isValid()) { + m_indexToUrl.insert(iIndex, QString::fromStdString(url)); + } } + m_pTableWidget->setItem(iIndex, 1, tabItem); QString asset_text = QString::number((uint64_t) total_votes / main_asset.m_scale ); asset_text += ' '; From 65c3d1196e0911742d78271c549b963e05ad4281 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 11 Apr 2018 09:23:06 +0200 Subject: [PATCH 130/136] GUI Wallet with DECENT daemon --- programs/gui_wallet/src/gui_wallet_global.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index a265fdb9..dad94f60 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -53,7 +53,7 @@ #include #endif -#define DECENT_WITHOUT_DAEMON +//#define DECENT_WITHOUT_DAEMON #include From 078f5b80ff7d410b0e1ee679f59199069c9464f8 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Wed, 11 Apr 2018 09:58:11 +0200 Subject: [PATCH 131/136] minor bug fixes --- libraries/chain/decent_evaluator.cpp | 9 +++++++++ libraries/wallet/wallet.cpp | 20 ++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/libraries/chain/decent_evaluator.cpp b/libraries/chain/decent_evaluator.cpp index 658b237e..ed06d895 100644 --- a/libraries/chain/decent_evaluator.cpp +++ b/libraries/chain/decent_evaluator.cpp @@ -531,6 +531,15 @@ void_result set_publishing_right_evaluator::do_evaluate( const set_publishing_ri if(delivered) { content_payout(d, paid_price_after_conversion, *content); d.modify( *content, []( content_object& co ){ co.times_bought++; }); + + finish_buying_operation op; + op.author = content->author; + op.co_authors = content->co_authors; + op.payout = paid_price_after_conversion; + op.consumer = object.consumer; + op.buying = object.id; + + db().push_applied_operation(op); } const auto& idx2 = d.get_index_type().indices().get(); for( auto& element : content->key_parts ) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 2dbfe4ef..2b770668 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3378,9 +3378,25 @@ signed_transaction content_cancellation(const string& author, string operation_printer::operator()(const transfer2_operation& op) const { const auto& from_account = wallet.get_account(op.from); - const auto& to_account = wallet.get_account(op.to); + account_object to_account; + string receiver; + + if( op.to.is() ) + { + to_account = wallet.get_account(op.to); + receiver = to_account.name; + } + else + { + content_id_type content_id = op.to.as(); + const content_object content_obj = wallet.get_object(content_id); + to_account = wallet.get_account(content_obj.author); + receiver = std::string(op.to); + } + + out << "Transfer " << wallet.get_asset(op.amount.asset_id).amount_to_pretty_string(op.amount) - << " from " << from_account.name << " to " << to_account.name; + << " from " << from_account.name << " to " << receiver; std::string memo; if( op.memo ) { From 9ee3d543fbb0ce35ad9157a1f1da293066229ad1 Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Wed, 11 Apr 2018 10:01:22 +0200 Subject: [PATCH 132/136] Adjusted precompiled headers --- programs/gui_wallet/src/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/gui_wallet/src/mainwindow.cpp b/programs/gui_wallet/src/mainwindow.cpp index c327b5cb..6f0ae59e 100644 --- a/programs/gui_wallet/src/mainwindow.cpp +++ b/programs/gui_wallet/src/mainwindow.cpp @@ -43,12 +43,12 @@ #include #include -#endif #include #include #include #include +#endif #include "update_manager.hpp" From 459d3fdf4c19a7f4c5e58bca0dd93527d73c0b05 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 11 Apr 2018 10:26:55 +0200 Subject: [PATCH 133/136] set refresh times for Publish and Transaction tabs --- programs/gui_wallet/src/transactions_tab.cpp | 2 ++ programs/gui_wallet/src/upload_tab.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/programs/gui_wallet/src/transactions_tab.cpp b/programs/gui_wallet/src/transactions_tab.cpp index 4086a3a5..64700e7e 100644 --- a/programs/gui_wallet/src/transactions_tab.cpp +++ b/programs/gui_wallet/src/transactions_tab.cpp @@ -60,6 +60,8 @@ TransactionsTab::TransactionsTab(QWidget* pParent, QObject::connect(m_pTableWidget, &DecentTable::signal_SortingChanged, this, &TransactionsTab::slot_SortingChanged); + + setRefreshTimer(5000); } void TransactionsTab::timeToUpdate(const string& result) diff --git a/programs/gui_wallet/src/upload_tab.cpp b/programs/gui_wallet/src/upload_tab.cpp index 43f770b8..5e0f830c 100644 --- a/programs/gui_wallet/src/upload_tab.cpp +++ b/programs/gui_wallet/src/upload_tab.cpp @@ -70,6 +70,7 @@ Upload_tab::Upload_tab(QWidget* pParent, QObject::connect(pUploadButton, &QPushButton::clicked, this, &Upload_tab::slot_UploadPopup); + setRefreshTimer(5000); } // when class has forward declared members From 74f17ec025439dcb580565834fcdf00b90bc3cd5 Mon Sep 17 00:00:00 2001 From: MilanFranc Date: Wed, 11 Apr 2018 13:16:28 +0200 Subject: [PATCH 134/136] fixed shutdown issue with ipfs --- programs/gui_wallet/src/gui_wallet_global.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/programs/gui_wallet/src/gui_wallet_global.cpp b/programs/gui_wallet/src/gui_wallet_global.cpp index dad94f60..49398fc7 100644 --- a/programs/gui_wallet/src/gui_wallet_global.cpp +++ b/programs/gui_wallet/src/gui_wallet_global.cpp @@ -727,7 +727,9 @@ void Globals::stopDaemons() if (m_p_daemon_details->ipfs_process) { m_p_daemon_details->ipfs_process->terminate(); - m_p_daemon_details->ipfs_process->waitForFinished(); + if (!m_p_daemon_details->ipfs_process->waitForFinished(5000)) { + m_p_daemon_details->ipfs_process->kill(); + } delete m_p_daemon_details->ipfs_process; m_p_daemon_details->ipfs_process = nullptr; From 7293f2afd0178017aeb07d2ad07e9634f49257f7 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Wed, 11 Apr 2018 13:24:29 +0200 Subject: [PATCH 135/136] set HARDFORK_2_TIME variable --- libraries/chain/hardfork.d/2.hf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/hardfork.d/2.hf b/libraries/chain/hardfork.d/2.hf index 74599f5d..a2d34a40 100644 --- a/libraries/chain/hardfork.d/2.hf +++ b/libraries/chain/hardfork.d/2.hf @@ -1,5 +1,5 @@ // #2 - simple content; payment to content; option to fix asset max supply; new wallet file format. #ifndef HARDFORK_2_TIME -#define HARDFORK_2_TIME (fc::time_point_sec( 1523145600 )) //2018-4-8 00:00:00 +#define HARDFORK_2_TIME (fc::time_point_sec( 1524470400 )) //2018-04-23 08:00:00 #endif From 6d3755d1e91ca3eabe1626e59856f87133d778a5 Mon Sep 17 00:00:00 2001 From: ghbpeter Date: Wed, 11 Apr 2018 14:05:31 +0200 Subject: [PATCH 136/136] Windows build only: updated resource --- programs/gui_wallet/DECENT.rc | Bin 5148 -> 5148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/programs/gui_wallet/DECENT.rc b/programs/gui_wallet/DECENT.rc index fef052e3eca38775b8b860666b065e3d9ca95f03..833a9182e1b9283589661f9ed68e21404ce46843 100644 GIT binary patch delta 44 wcmbQEF-K!V9|xn+bL2Pg;Z0xz08G#hJOBUy delta 44 wcmbQEF-K!V9|xo1bL2Pg;Z0xz08CsCHvj+t