From 5f49e982ecf06ef10730ae643a0eeacf691ef83b Mon Sep 17 00:00:00 2001 From: Srdjan Obucina Date: Fri, 27 Mar 2020 20:47:48 +0100 Subject: [PATCH] Add checks is the transaction to be confirmed exactly the same as existing --- .../chain/son_wallet_deposit_evaluator.cpp | 29 ++++++++++++++----- .../chain/son_wallet_withdraw_evaluator.cpp | 29 +++++++++++++------ 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/libraries/chain/son_wallet_deposit_evaluator.cpp b/libraries/chain/son_wallet_deposit_evaluator.cpp index 8f0978fa..643c967c 100644 --- a/libraries/chain/son_wallet_deposit_evaluator.cpp +++ b/libraries/chain/son_wallet_deposit_evaluator.cpp @@ -11,6 +11,14 @@ void_result create_son_wallet_deposit_evaluator::do_evaluate(const son_wallet_de { try { FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); + const auto &son_idx = db().get_index_type().indices().get(); + const auto so = son_idx.find(op.son_id); + FC_ASSERT(so != son_idx.end(), "SON not found"); + FC_ASSERT(so->son_account == op.payer, "Payer is not SON account owner"); + + const auto &ss_idx = db().get_index_type().indices().get(); + FC_ASSERT(ss_idx.find(op.son_id) != ss_idx.end(), "Statistic object for a given SON ID does not exists"); + const auto &swdo_idx = db().get_index_type().indices().get(); const auto swdo = swdo_idx.find(op.sidechain_uid); if (swdo == swdo_idx.end()) { @@ -24,6 +32,19 @@ void_result create_son_wallet_deposit_evaluator::do_evaluate(const son_wallet_de } FC_ASSERT(expected, "Only active SON can create deposit"); } else { + bool exactly_the_same = true; + exactly_the_same = exactly_the_same && (swdo->sidechain == op.sidechain); + exactly_the_same = exactly_the_same && (swdo->sidechain_uid == op.sidechain_uid); + exactly_the_same = exactly_the_same && (swdo->sidechain_transaction_id == op.sidechain_transaction_id); + exactly_the_same = exactly_the_same && (swdo->sidechain_from == op.sidechain_from); + exactly_the_same = exactly_the_same && (swdo->sidechain_to == op.sidechain_to); + exactly_the_same = exactly_the_same && (swdo->sidechain_currency == op.sidechain_currency); + exactly_the_same = exactly_the_same && (swdo->sidechain_amount == op.sidechain_amount); + exactly_the_same = exactly_the_same && (swdo->peerplays_from == op.peerplays_from); + exactly_the_same = exactly_the_same && (swdo->peerplays_to == op.peerplays_to); + exactly_the_same = exactly_the_same && (swdo->peerplays_asset == op.peerplays_asset); + FC_ASSERT(exactly_the_same, "Invalid withdraw confirmation"); + bool expected = false; for (auto &exp : swdo->expected_reports) { if (op.son_id == exp.first) { @@ -34,14 +55,6 @@ void_result create_son_wallet_deposit_evaluator::do_evaluate(const son_wallet_de FC_ASSERT(expected, "Confirmation from this SON not expected"); } - const auto &son_idx = db().get_index_type().indices().get(); - const auto so = son_idx.find(op.son_id); - FC_ASSERT(so != son_idx.end(), "SON not found"); - FC_ASSERT(so->son_account == op.payer, "Payer is not SON account owner"); - - const auto &ss_idx = db().get_index_type().indices().get(); - FC_ASSERT(ss_idx.find(op.son_id) != ss_idx.end(), "Statistic object for a given SON ID does not exists"); - return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } diff --git a/libraries/chain/son_wallet_withdraw_evaluator.cpp b/libraries/chain/son_wallet_withdraw_evaluator.cpp index 8d2d53a8..8f843bd1 100644 --- a/libraries/chain/son_wallet_withdraw_evaluator.cpp +++ b/libraries/chain/son_wallet_withdraw_evaluator.cpp @@ -10,7 +10,14 @@ namespace graphene { namespace chain { void_result create_son_wallet_withdraw_evaluator::do_evaluate(const son_wallet_withdraw_create_operation& op) { try { FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); - FC_ASSERT( op.payer == db().get_global_properties().parameters.son_account(), "SON paying account must be set as payer." ); + + const auto &son_idx = db().get_index_type().indices().get(); + const auto so = son_idx.find(op.son_id); + FC_ASSERT(so != son_idx.end(), "SON not found"); + FC_ASSERT(so->son_account == op.payer, "Payer is not SON account owner"); + + const auto &ss_idx = db().get_index_type().indices().get(); + FC_ASSERT(ss_idx.find(op.son_id) != ss_idx.end(), "Statistic object for a given SON ID does not exists"); const auto &swwo_idx = db().get_index_type().indices().get(); const auto swwo = swwo_idx.find(op.peerplays_uid); @@ -25,6 +32,18 @@ void_result create_son_wallet_withdraw_evaluator::do_evaluate(const son_wallet_w } FC_ASSERT(expected, "Only active SON can create deposit"); } else { + bool exactly_the_same = true; + exactly_the_same = exactly_the_same && (swwo->sidechain == op.sidechain); + exactly_the_same = exactly_the_same && (swwo->peerplays_uid == op.peerplays_uid); + exactly_the_same = exactly_the_same && (swwo->peerplays_transaction_id == op.peerplays_transaction_id); + exactly_the_same = exactly_the_same && (swwo->peerplays_from == op.peerplays_from); + exactly_the_same = exactly_the_same && (swwo->peerplays_asset == op.peerplays_asset); + exactly_the_same = exactly_the_same && (swwo->withdraw_sidechain == op.withdraw_sidechain); + exactly_the_same = exactly_the_same && (swwo->withdraw_address == op.withdraw_address); + exactly_the_same = exactly_the_same && (swwo->withdraw_currency == op.withdraw_currency); + exactly_the_same = exactly_the_same && (swwo->withdraw_amount == op.withdraw_amount); + FC_ASSERT(exactly_the_same, "Invalid withdraw confirmation"); + bool expected = false; for (auto &exp : swwo->expected_reports) { if (op.son_id == exp.first) { @@ -35,14 +54,6 @@ void_result create_son_wallet_withdraw_evaluator::do_evaluate(const son_wallet_w FC_ASSERT(expected, "Confirmation from this SON not expected"); } - const auto &son_idx = db().get_index_type().indices().get(); - const auto so = son_idx.find(op.son_id); - FC_ASSERT(so != son_idx.end(), "SON not found"); - FC_ASSERT(so->son_account == op.payer, "Payer is not SON account owner"); - - const auto &ss_idx = db().get_index_type().indices().get(); - FC_ASSERT(ss_idx.find(op.son_id) != ss_idx.end(), "Statistic object for a given SON ID does not exists"); - return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) }