Fixed revert proposal: multiply createion; fix pw vin delete
This commit is contained in:
parent
0109bc8c04
commit
329c75668f
7 changed files with 22 additions and 18 deletions
|
|
@ -247,6 +247,8 @@ void_result bitcoin_transaction_revert_evaluator::do_apply( const bitcoin_transa
|
|||
|
||||
for( auto trx_info: op.transactions_info ) {
|
||||
const auto& btc_trx_obj = *btc_trx_idx.find( trx_info.transaction_id );
|
||||
d.pw_vout_manager.delete_vouts_after( btc_trx_obj.pw_vin );
|
||||
d.pw_vout_manager.mark_as_unused_vout( btc_trx_obj.pw_vin );
|
||||
|
||||
for( const auto& vout_id : btc_trx_obj.vouts ) {
|
||||
const auto& vout_obj = *vouts_info_idx.find( vout_id );
|
||||
|
|
|
|||
|
|
@ -349,12 +349,12 @@ fc::optional<operation> database::create_bitcoin_issue_proposals( const witness_
|
|||
|
||||
fc::optional<operation> database::create_bitcoin_revert_proposals( const witness_object& current_witness )
|
||||
{
|
||||
using iter_by_missing = btc_tx_confirmations_index::index<by_missing_first>::type::iterator;
|
||||
using iter_by_missing = btc_tx_confirmations_index::index<by_missing_and_not_used>::type::iterator;
|
||||
std::vector<revert_trx_info> trx_info;
|
||||
|
||||
bitcoin_confirmations.safe_for<by_missing_first>([&]( iter_by_missing itr_b, iter_by_missing itr_e ){
|
||||
bitcoin_confirmations.safe_for<by_missing_and_not_used>([&]( iter_by_missing itr_b, iter_by_missing itr_e ){
|
||||
for(auto iter = itr_b; iter != itr_e; iter++) {
|
||||
if( !iter->missing ) return;
|
||||
if( !iter->is_missing_and_not_used() ) return;
|
||||
|
||||
const auto& btc_trx_idx = get_index_type<bitcoin_transaction_index>().indices().get<by_transaction_id>();
|
||||
const auto& btc_tx = btc_trx_idx.find( iter->transaction_id );
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ struct bitcoin_transaction_confirmations
|
|||
uint64_t id;
|
||||
|
||||
bool is_confirmed_and_not_used() const { return !used && confirmed; }
|
||||
bool is_missing_and_not_used() const { return !used && missing; }
|
||||
|
||||
fc::sha256 transaction_id;
|
||||
std::set<fc::sha256> valid_vins;
|
||||
|
|
@ -47,13 +48,13 @@ struct bitcoin_transaction_confirmations
|
|||
|
||||
struct by_hash;
|
||||
struct by_confirmed_and_not_used;
|
||||
struct by_missing_first;
|
||||
struct by_missing_and_not_used;
|
||||
|
||||
using btc_tx_confirmations_index = boost::multi_index_container<bitcoin_transaction_confirmations,
|
||||
indexed_by<
|
||||
ordered_unique<tag<by_hash>, member<bitcoin_transaction_confirmations, fc::sha256, &bitcoin_transaction_confirmations::transaction_id>>,
|
||||
ordered_non_unique<tag<by_confirmed_and_not_used>, identity< bitcoin_transaction_confirmations >, bitcoin_transaction_confirmations::comparer >,
|
||||
ordered_non_unique<tag<by_missing_first>, member<bitcoin_transaction_confirmations, bool, &bitcoin_transaction_confirmations::missing>, std::greater<bool>>
|
||||
ordered_non_unique<tag<by_missing_and_not_used>, identity< bitcoin_transaction_confirmations >, bitcoin_transaction_confirmations::comparer >
|
||||
>
|
||||
>;
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public:
|
|||
|
||||
void create_new_vout( const sidechain::prev_out& out );
|
||||
|
||||
void delete_vout_with_newer( fc::sha256 hash_id );
|
||||
void delete_vouts_after( fc::sha256 hash_id );
|
||||
|
||||
void confirm_vout( fc::sha256 hash_id );
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ void primary_wallet_vout_manager::create_new_vout( const sidechain::prev_out& ou
|
|||
});
|
||||
}
|
||||
|
||||
void primary_wallet_vout_manager::delete_vout_with_newer( fc::sha256 hash_id )
|
||||
void primary_wallet_vout_manager::delete_vouts_after( fc::sha256 hash_id )
|
||||
{
|
||||
const auto& PW_vout_by_id = db.get_index_type<graphene::chain::primary_wallet_vout_index>().indices().get< graphene::chain::by_id >();
|
||||
auto vout_id = get_vout_id( hash_id );
|
||||
|
|
@ -52,6 +52,7 @@ void primary_wallet_vout_manager::delete_vout_with_newer( fc::sha256 hash_id )
|
|||
return;
|
||||
|
||||
auto itr = PW_vout_by_id.find( *vout_id );
|
||||
itr++;
|
||||
|
||||
while( itr != PW_vout_by_id.end() )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -78,28 +78,28 @@ BOOST_AUTO_TEST_CASE( delete_pw_vout_objects )
|
|||
BOOST_CHECK_EQUAL( idx.size(), 25 );
|
||||
|
||||
auto pw_vout = *pw_vout_manager.get_latest_unused_vout();
|
||||
pw_vout_manager.delete_vout_with_newer( create_hash_id( pw_vout.vout.hash_tx, pw_vout.vout.n_vout, pw_vout.id.instance() ) );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 24 );
|
||||
pw_vout_manager.delete_vouts_after( create_hash_id( pw_vout.vout.hash_tx, pw_vout.vout.n_vout, pw_vout.id.instance() ) );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 25 );
|
||||
|
||||
pw_vout_manager.delete_vout_with_newer( create_hash_id( "13", 13, 13 ) );
|
||||
pw_vout_manager.delete_vouts_after( create_hash_id( "13", 13, 13 ) );
|
||||
|
||||
BOOST_CHECK_EQUAL( idx.size(), 13 );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 14 );
|
||||
|
||||
for( auto itr: idx ) {
|
||||
BOOST_CHECK( itr.hash_id == create_hash_id( itr.vout.hash_tx, itr.vout.n_vout, itr.id.instance() ) );
|
||||
}
|
||||
|
||||
create_primary_wallet_vouts( pw_vout_manager, db, 8 );
|
||||
pw_vout_manager.delete_vout_with_newer( create_hash_id( "20", 20, 20 ) );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 21 );
|
||||
pw_vout_manager.delete_vouts_after( create_hash_id( "20", 20, 20 ) );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 22 );
|
||||
|
||||
for( auto itr: idx ) {
|
||||
BOOST_CHECK( itr.hash_id == create_hash_id( itr.vout.hash_tx, itr.vout.n_vout, itr.id.instance() ) );
|
||||
}
|
||||
|
||||
auto itr_primary_wallet = idx.begin();
|
||||
pw_vout_manager.delete_vout_with_newer( create_hash_id( itr_primary_wallet->vout.hash_tx, itr_primary_wallet->vout.n_vout, itr_primary_wallet->id.instance() ) );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 0 );
|
||||
pw_vout_manager.delete_vouts_after( create_hash_id( itr_primary_wallet->vout.hash_tx, itr_primary_wallet->vout.n_vout, itr_primary_wallet->id.instance() ) );
|
||||
BOOST_CHECK_EQUAL( idx.size(), 1 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( confirm_pw_vout_objects )
|
||||
|
|
|
|||
|
|
@ -313,14 +313,14 @@ void create_missing_bto( graphene::chain::database& db, uint32_t amount )
|
|||
|
||||
std::vector< revert_trx_info > get_transactions_info( graphene::chain::database& db, uint32_t amount )
|
||||
{
|
||||
using iter_by_missing = btc_tx_confirmations_index::index<by_missing_first>::type::iterator;
|
||||
using iter_by_missing = btc_tx_confirmations_index::index<by_missing_and_not_used>::type::iterator;
|
||||
std::vector< revert_trx_info > transactions_info;
|
||||
const auto& btc_trx_idx = db.get_index_type<graphene::chain::bitcoin_transaction_index>().indices().get<graphene::chain::by_transaction_id>();
|
||||
BOOST_CHECK_EQUAL( btc_trx_idx.size() , amount );
|
||||
|
||||
db.bitcoin_confirmations.safe_for<by_missing_first>([&]( iter_by_missing itr_b, iter_by_missing itr_e ){
|
||||
db.bitcoin_confirmations.safe_for<by_missing_and_not_used>([&]( iter_by_missing itr_b, iter_by_missing itr_e ){
|
||||
for(auto iter = itr_b; iter != itr_e; iter++) {
|
||||
if( !iter->missing ) return;
|
||||
if( !iter->is_missing_and_not_used() ) return;
|
||||
const auto& btc_tx = btc_trx_idx.find( iter->transaction_id );
|
||||
if( btc_tx == btc_trx_idx.end() ) continue;
|
||||
transactions_info.push_back( revert_trx_info( iter->transaction_id, iter->valid_vins ) );
|
||||
|
|
|
|||
Loading…
Reference in a new issue