Improved check for sidechain transaction object creation

This commit is contained in:
Srdjan Obucina 2020-03-23 07:27:42 +01:00
parent f0eb24522c
commit 23d5779798
4 changed files with 20 additions and 24 deletions

View file

@ -13,9 +13,7 @@ namespace graphene { namespace chain {
account_id_type payer; account_id_type payer;
sidechain_type sidechain; sidechain_type sidechain;
optional<son_wallet_id_type> son_wallet_id; object_id_type object_id;
optional<son_wallet_deposit_id_type> son_wallet_deposit_id;
optional<son_wallet_withdraw_id_type> son_wallet_withdraw_id;
std::string transaction; std::string transaction;
std::vector<son_id_type> signers; std::vector<son_id_type> signers;
@ -56,9 +54,7 @@ namespace graphene { namespace chain {
FC_REFLECT( graphene::chain::sidechain_transaction_create_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::sidechain_transaction_create_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::sidechain_transaction_create_operation, (fee)(payer) FC_REFLECT( graphene::chain::sidechain_transaction_create_operation, (fee)(payer)
(sidechain) (sidechain)
(son_wallet_id) (object_id)
(son_wallet_deposit_id)
(son_wallet_withdraw_id)
(transaction) (transaction)
(signers) ) (signers) )

View file

@ -18,9 +18,7 @@ namespace graphene { namespace chain {
static const uint8_t type_id = sidechain_transaction_object_type; static const uint8_t type_id = sidechain_transaction_object_type;
sidechain_type sidechain; sidechain_type sidechain;
optional<son_wallet_id_type> son_wallet_id; object_id_type object_id;
optional<son_wallet_deposit_id_type> son_wallet_deposit_id;
optional<son_wallet_withdraw_id_type> son_wallet_withdraw_id;
std::string transaction; std::string transaction;
std::vector<std::pair<son_id_type, bool>> signers; std::vector<std::pair<son_id_type, bool>> signers;
@ -29,6 +27,7 @@ namespace graphene { namespace chain {
bool sent = false; bool sent = false;
}; };
struct by_object_id;
struct by_sidechain_and_complete; struct by_sidechain_and_complete;
struct by_sidechain_and_complete_and_sent; struct by_sidechain_and_complete_and_sent;
using sidechain_transaction_multi_index_type = multi_index_container< using sidechain_transaction_multi_index_type = multi_index_container<
@ -37,6 +36,9 @@ namespace graphene { namespace chain {
ordered_unique< tag<by_id>, ordered_unique< tag<by_id>,
member<object, object_id_type, &object::id> member<object, object_id_type, &object::id>
>, >,
ordered_unique< tag<by_object_id>,
member<sidechain_transaction_object, object_id_type, &sidechain_transaction_object::object_id>
>,
ordered_non_unique< tag<by_sidechain_and_complete>, ordered_non_unique< tag<by_sidechain_and_complete>,
composite_key<sidechain_transaction_object, composite_key<sidechain_transaction_object,
member<sidechain_transaction_object, sidechain_type, &sidechain_transaction_object::sidechain>, member<sidechain_transaction_object, sidechain_type, &sidechain_transaction_object::sidechain>,
@ -57,9 +59,7 @@ namespace graphene { namespace chain {
FC_REFLECT_DERIVED( graphene::chain::sidechain_transaction_object, (graphene::db::object ), FC_REFLECT_DERIVED( graphene::chain::sidechain_transaction_object, (graphene::db::object ),
(sidechain) (sidechain)
(son_wallet_id) (object_id)
(son_wallet_deposit_id)
(son_wallet_withdraw_id)
(transaction) (transaction)
(signers) (signers)
(valid) (valid)

View file

@ -13,11 +13,13 @@ void_result sidechain_transaction_create_evaluator::do_evaluate(const sidechain_
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK");
FC_ASSERT( op.payer == GRAPHENE_SON_ACCOUNT, "SON paying account must be set as payer." ); FC_ASSERT( op.payer == GRAPHENE_SON_ACCOUNT, "SON paying account must be set as payer." );
//FC_ASSERT( (!op.son_wallet_id && !op.son_wallet_deposit_id && !op.son_wallet_withdraw_id), "Sidechain transaction origin not set." ); FC_ASSERT((op.object_id.is<son_wallet_id_type>() || op.object_id.is<son_wallet_deposit_id_type>() || op.object_id.is<son_wallet_withdraw_id_type>()), "Invalid object id");
//FC_ASSERT( op.son_wallet_id && op.son_wallet_deposit_id, "Sidechain transaction origin ambiguous. Single origin required." );
//FC_ASSERT( op.son_wallet_id && op.son_wallet_withdraw_id, "Sidechain transaction origin ambiguous. Single origin required." ); const auto &sto_idx = db().get_index_type<sidechain_transaction_index>().indices().get<by_object_id>();
//FC_ASSERT( op.son_wallet_deposit_id && op.son_wallet_withdraw_id, "Sidechain transaction origin ambiguous. Single origin required." ); const auto &sto_obj = sto_idx.find(op.object_id);
FC_ASSERT( !op.transaction.empty(), "Sidechain transaction data not set." ); FC_ASSERT(sto_obj == sto_idx.end(), "Sidechain transaction for a given object is already created");
FC_ASSERT(!op.transaction.empty(), "Sidechain transaction data not set");
return void_result(); return void_result();
} FC_CAPTURE_AND_RETHROW( ( op ) ) } } FC_CAPTURE_AND_RETHROW( ( op ) ) }
@ -26,9 +28,7 @@ object_id_type sidechain_transaction_create_evaluator::do_apply(const sidechain_
{ try { { try {
const auto &new_sidechain_transaction_object = db().create<sidechain_transaction_object>([&](sidechain_transaction_object &sto) { const auto &new_sidechain_transaction_object = db().create<sidechain_transaction_object>([&](sidechain_transaction_object &sto) {
sto.sidechain = op.sidechain; sto.sidechain = op.sidechain;
sto.son_wallet_id = op.son_wallet_id; sto.object_id = op.object_id;
sto.son_wallet_deposit_id = op.son_wallet_deposit_id;
sto.son_wallet_withdraw_id = op.son_wallet_withdraw_id;
sto.transaction = op.transaction; sto.transaction = op.transaction;
std::transform(op.signers.begin(), op.signers.end(), std::inserter(sto.signers, sto.signers.end()), [](const son_id_type son_id) { std::transform(op.signers.begin(), op.signers.end(), std::inserter(sto.signers, sto.signers.end()), [](const son_id_type son_id) {
return std::make_pair(son_id, false); return std::make_pair(son_id, false);

View file

@ -834,7 +834,7 @@ void sidechain_net_handler_bitcoin::recreate_primary_wallet() {
son_wallet_update_operation op; son_wallet_update_operation op;
op.payer = GRAPHENE_SON_ACCOUNT; op.payer = GRAPHENE_SON_ACCOUNT;
op.son_wallet_id = (*active_sw).id; op.son_wallet_id = active_sw->id;
op.sidechain = sidechain_type::bitcoin; op.sidechain = sidechain_type::bitcoin;
op.address = res.str(); op.address = res.str();
@ -905,7 +905,7 @@ void sidechain_net_handler_bitcoin::recreate_primary_wallet() {
sidechain_transaction_create_operation stc_op; sidechain_transaction_create_operation stc_op;
stc_op.payer = GRAPHENE_SON_ACCOUNT; stc_op.payer = GRAPHENE_SON_ACCOUNT;
stc_op.son_wallet_id = (*prev_sw).id; stc_op.object_id = prev_sw->id;
stc_op.sidechain = sidechain; stc_op.sidechain = sidechain;
stc_op.transaction = tx_str; stc_op.transaction = tx_str;
stc_op.signers = signers; stc_op.signers = signers;
@ -981,7 +981,7 @@ bool sidechain_net_handler_bitcoin::process_deposit(const son_wallet_deposit_obj
sidechain_transaction_create_operation stc_op; sidechain_transaction_create_operation stc_op;
stc_op.payer = GRAPHENE_SON_ACCOUNT; stc_op.payer = GRAPHENE_SON_ACCOUNT;
stc_op.son_wallet_deposit_id = swdo.id; stc_op.object_id = swdo.id;
stc_op.sidechain = sidechain; stc_op.sidechain = sidechain;
stc_op.transaction = tx_str; stc_op.transaction = tx_str;
stc_op.signers = signers; stc_op.signers = signers;
@ -1063,7 +1063,7 @@ bool sidechain_net_handler_bitcoin::process_withdrawal(const son_wallet_withdraw
sidechain_transaction_create_operation stc_op; sidechain_transaction_create_operation stc_op;
stc_op.payer = GRAPHENE_SON_ACCOUNT; stc_op.payer = GRAPHENE_SON_ACCOUNT;
stc_op.son_wallet_withdraw_id = swwo.id; stc_op.object_id = swwo.id;
stc_op.sidechain = sidechain; stc_op.sidechain = sidechain;
stc_op.transaction = tx_str; stc_op.transaction = tx_str;
stc_op.signers = signers; stc_op.signers = signers;