From 7a5c5c476d9762cbba1d745447191523ca5cd601 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Wed, 2 Dec 2015 15:15:20 -0500 Subject: [PATCH 1/4] wallet.cpp: Implement propose_builder_transaction2 #467 --- .../wallet/include/graphene/wallet/wallet.hpp | 19 ++++++-- libraries/wallet/wallet.cpp | 45 +++++++++++++++++-- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 952b1b33..a8d9c747 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -443,9 +443,21 @@ class wallet_api /** * @ingroup Transaction Builder API */ - 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 + ); + + 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 + ); + /** * @ingroup Transaction Builder API */ @@ -1469,6 +1481,7 @@ FC_API( graphene::wallet::wallet_api, (preview_builder_transaction) (sign_builder_transaction) (propose_builder_transaction) + (propose_builder_transaction2) (remove_builder_transaction) (is_new) (is_locked) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 3858f4c1..977e1dc5 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -821,9 +821,10 @@ public: return _builder_transactions[transaction_handle] = sign_transaction(_builder_transactions[transaction_handle], broadcast); } - 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) { FC_ASSERT(_builder_transactions.count(handle)); proposal_create_operation op; @@ -838,6 +839,28 @@ public: return trx = sign_transaction(trx, broadcast); } + + 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) + { + FC_ASSERT(_builder_transactions.count(handle)); + proposal_create_operation op; + op.fee_paying_account = get_account(account_name_or_id).get_id(); + op.expiration_time = expiration; + signed_transaction& trx = _builder_transactions[handle]; + std::transform(trx.operations.begin(), trx.operations.end(), std::back_inserter(op.proposed_ops), + [](const operation& op) -> op_wrapper { return op; }); + if( review_period_seconds ) + op.review_period_seconds = review_period_seconds; + trx.operations = {op}; + _remote_db->get_global_properties().parameters.current_fees->set_fee( trx.operations.front() ); + + return trx = sign_transaction(trx, broadcast); + } + void remove_builder_transaction(transaction_handle_type handle) { _builder_transactions.erase(handle); @@ -2681,11 +2704,25 @@ signed_transaction wallet_api::sign_builder_transaction(transaction_handle_type 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) +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); From 51c10580fa9c547d8dafbd6e374d713850140ff6 Mon Sep 17 00:00:00 2001 From: Fabian Schuh Date: Fri, 18 Dec 2015 16:17:40 +0100 Subject: [PATCH 2/4] [LICENSE] Change to MIT --- LICENSE.md | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 03942c69..0415b22c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,12 +1,22 @@ Copyright (c) 2015 Cryptonomex, Inc., and contributors. -All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +The MIT License -1. Any modified source or binaries are used only with the BitShares network. +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: -2. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. -3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +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. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From dd5b7708b4f3c22ba70b5f077250917f6dadb9d5 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Sun, 3 Jan 2016 20:40:21 -0500 Subject: [PATCH 3/4] potential fix for hung chain --- libraries/chain/db_block.cpp | 5 ++++- libraries/chain/db_update.cpp | 6 ++++++ libraries/chain/include/graphene/chain/database.hpp | 3 ++- .../chain/include/graphene/chain/protocol/asset_ops.hpp | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 770951b6..ceb9d4be 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -548,7 +548,10 @@ processed_transaction database::apply_transaction(const signed_transaction& trx, processed_transaction database::_apply_transaction(const signed_transaction& trx) { try { uint32_t skip = get_node_properties().skip_flags; - trx.validate(); + + if( !(skip&skip_validate) ) + trx.validate(); + auto& trx_idx = get_mutable_index_type(); const chain_id_type& chain_id = get_chain_id(); auto trx_id = trx.id(); diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index 2b6ba2e7..37c0a5de 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -348,6 +348,12 @@ void database::clear_expired_orders() assert(itr != call_index.end() && itr->debt_type() == mia_object.get_id()); asset max_settlement = max_settlement_volume - settled; + if( order.balance.amount == 0 ) + { + wlog( "0 settlement detected" ); + cancel_order( order ); + break; + } try { settled += match(*itr, order, settlement_price, max_settlement); } diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index c44e687d..9326004c 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -70,7 +70,8 @@ namespace graphene { namespace chain { skip_merkle_check = 1 << 7, ///< used while reindexing skip_assert_evaluation = 1 << 8, ///< used while reindexing skip_undo_history_check = 1 << 9, ///< used while reindexing - skip_witness_schedule_check = 1 << 10 ///< used whiel reindexing + skip_witness_schedule_check = 1 << 10, ///< used while reindexing + skip_validate = 1 << 11 ///< used prior to checkpoint, skips validate() call on transaction }; /** diff --git a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp index 154c599d..13376053 100644 --- a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp +++ b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp @@ -225,7 +225,9 @@ namespace graphene { namespace chain { extensions_type extensions; account_id_type fee_payer()const { return account; } - void validate()const {} + void validate()const { + FC_ASSERT( amount.amount > 0, "Must settle at least 1 unit" ); + } share_type calculate_fee(const fee_parameters_type& params)const { return 0; } From c56cbfe2a73be7620892c2e1eabe6ae19b248487 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Thu, 7 Jan 2016 11:42:16 -0500 Subject: [PATCH 4/4] account.cpp: Move account_options::validate() implementation from account_object.cpp #498 --- libraries/chain/account_object.cpp | 15 --------------- libraries/chain/protocol/account.cpp | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index a68c8260..9b89b024 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -136,21 +136,6 @@ void account_statistics_object::pay_fee( share_type core_fee, share_type cashbac pending_vested_fees += core_fee; } -void account_object::options_type::validate() const -{ - auto needed_witnesses = num_witness; - auto needed_committee = num_committee; - - for( vote_id_type id : votes ) - if( id.type() == vote_id_type::witness && needed_witnesses ) - --needed_witnesses; - else if ( id.type() == vote_id_type::committee && needed_committee ) - --needed_committee; - - FC_ASSERT( needed_witnesses == 0 && needed_committee == 0, - "May not specify fewer witnesses or committee members than the number voted for."); -} - set account_member_index::get_account_members(const account_object& a)const { set result; diff --git a/libraries/chain/protocol/account.cpp b/libraries/chain/protocol/account.cpp index 003af663..3742914d 100644 --- a/libraries/chain/protocol/account.cpp +++ b/libraries/chain/protocol/account.cpp @@ -141,6 +141,21 @@ bool is_cheap_name( const string& n ) return false; } +void account_options::validate() const +{ + auto needed_witnesses = num_witness; + auto needed_committee = num_committee; + + for( vote_id_type id : votes ) + if( id.type() == vote_id_type::witness && needed_witnesses ) + --needed_witnesses; + else if ( id.type() == vote_id_type::committee && needed_committee ) + --needed_committee; + + FC_ASSERT( needed_witnesses == 0 && needed_committee == 0, + "May not specify fewer witnesses or committee members than the number voted for."); +} + share_type account_create_operation::calculate_fee( const fee_parameters_type& k )const { auto core_fee_required = k.basic_fee;