Skip to content

Commit 7d79c23

Browse files
authored
Merge pull request #2476 from bitshares/samet-fund-impacted-accounts
Return owner account for SameT Fund borrow, repay
2 parents a729b64 + 4118c44 commit 7d79c23

File tree

6 files changed

+80
-8
lines changed

6 files changed

+80
-8
lines changed

libraries/chain/include/graphene/chain/samet_fund_evaluator.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
namespace graphene { namespace chain {
3030

31-
class asset_object;
32-
class asset_dynamic_data_object;
3331
class samet_fund_object;
3432

3533
class samet_fund_create_evaluator : public evaluator<samet_fund_create_evaluator>
@@ -69,7 +67,7 @@ namespace graphene { namespace chain {
6967
using operation_type = samet_fund_borrow_operation;
7068

7169
void_result do_evaluate( const samet_fund_borrow_operation& op );
72-
void_result do_apply( const samet_fund_borrow_operation& op ) const;
70+
object_id_type do_apply( const samet_fund_borrow_operation& op ) const;
7371

7472
const samet_fund_object* _fund = nullptr;
7573
};
@@ -80,7 +78,7 @@ namespace graphene { namespace chain {
8078
using operation_type = samet_fund_repay_operation;
8179

8280
void_result do_evaluate( const samet_fund_repay_operation& op );
83-
void_result do_apply( const samet_fund_repay_operation& op ) const;
81+
object_id_type do_apply( const samet_fund_repay_operation& op ) const;
8482

8583
const samet_fund_object* _fund = nullptr;
8684
};

libraries/chain/samet_fund_evaluator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void_result samet_fund_borrow_evaluator::do_evaluate(const samet_fund_borrow_ope
164164
return void_result();
165165
} FC_CAPTURE_AND_RETHROW( (op) ) }
166166

167-
void_result samet_fund_borrow_evaluator::do_apply( const samet_fund_borrow_operation& op) const
167+
object_id_type samet_fund_borrow_evaluator::do_apply( const samet_fund_borrow_operation& op) const
168168
{ try {
169169
database& d = db();
170170

@@ -177,7 +177,7 @@ void_result samet_fund_borrow_evaluator::do_apply( const samet_fund_borrow_opera
177177
// Defensive check
178178
FC_ASSERT( _fund->balance >= _fund->unpaid_amount, "Should not borrow more than available" );
179179

180-
return void_result();
180+
return _fund->owner_account;
181181
} FC_CAPTURE_AND_RETHROW( (op) ) }
182182

183183
void_result samet_fund_repay_evaluator::do_evaluate(const samet_fund_repay_operation& op)
@@ -204,7 +204,7 @@ void_result samet_fund_repay_evaluator::do_evaluate(const samet_fund_repay_opera
204204
return void_result();
205205
} FC_CAPTURE_AND_RETHROW( (op) ) }
206206

207-
void_result samet_fund_repay_evaluator::do_apply( const samet_fund_repay_operation& op) const
207+
object_id_type samet_fund_repay_evaluator::do_apply( const samet_fund_repay_operation& op) const
208208
{ try {
209209
database& d = db();
210210

@@ -215,7 +215,7 @@ void_result samet_fund_repay_evaluator::do_apply( const samet_fund_repay_operati
215215
sfo.unpaid_amount -= op.repay_amount.amount;
216216
});
217217

218-
return void_result();
218+
return _fund->owner_account;
219219
} FC_CAPTURE_AND_RETHROW( (op) ) }
220220

221221
} } // graphene::chain

libraries/plugins/account_history/account_history_plugin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ void account_history_plugin_impl::update_account_histories( const signed_block&
135135
if( op.op.is_type< account_create_operation >() )
136136
impacted.insert( op.result.get<object_id_type>() );
137137
else
138+
{
138139
operation_get_impacted_accounts( op.op, impacted,
139140
MUST_IGNORE_CUSTOM_OP_REQD_AUTHS( db.head_block_time() ) );
141+
if( op.op.is_type< samet_fund_borrow_operation >() || op.op.is_type< samet_fund_repay_operation >() )
142+
impacted.insert( op.result.get<object_id_type>() );
143+
}
140144

141145
for( auto& a : other )
142146
for( auto& item : a.account_auths )

libraries/plugins/elasticsearch/elasticsearch_plugin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,12 @@ bool elasticsearch_plugin_impl::update_account_histories( const signed_block& b
165165
if( op.op.is_type< account_create_operation >() )
166166
impacted.insert( op.result.get<object_id_type>() );
167167
else
168+
{
168169
operation_get_impacted_accounts( op.op, impacted,
169170
MUST_IGNORE_CUSTOM_OP_REQD_AUTHS( db.head_block_time() ) );
171+
if( op.op.is_type< samet_fund_borrow_operation >() || op.op.is_type< samet_fund_repay_operation >() )
172+
impacted.insert( op.result.get<object_id_type>() );
173+
}
170174

171175
for( auto& a : other )
172176
for( auto& item : a.account_auths )

libraries/protocol/include/graphene/protocol/samet_fund.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ namespace graphene { namespace protocol {
9090
/**
9191
* @brief Borrow from a SameT Fund
9292
* @ingroup operations
93+
* @note The result of this operation is the ID of the owner account of the SameT Fund
9394
*/
9495
struct samet_fund_borrow_operation : public base_operation
9596
{
@@ -109,6 +110,7 @@ namespace graphene { namespace protocol {
109110
/**
110111
* @brief Repay to a SameT Fund
111112
* @ingroup operations
113+
* @note The result of this operation is the ID of the owner account of the SameT Fund
112114
*/
113115
struct samet_fund_repay_operation : public base_operation
114116
{

tests/tests/samet_fund_tests.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,4 +1162,68 @@ BOOST_AUTO_TEST_CASE( samet_fund_apis_test )
11621162
}
11631163
}
11641164

1165+
BOOST_AUTO_TEST_CASE( samet_fund_account_history_test )
1166+
{ try {
1167+
1168+
// Pass the hard fork time
1169+
generate_blocks( HARDFORK_CORE_2351_TIME );
1170+
set_expiration( db, trx );
1171+
1172+
ACTORS((sam)(ted));
1173+
1174+
auto init_amount = 10000000 * GRAPHENE_BLOCKCHAIN_PRECISION;
1175+
fund( sam, asset(init_amount) );
1176+
fund( ted, asset(init_amount) );
1177+
1178+
asset_id_type core_id;
1179+
1180+
// create samet funds
1181+
const samet_fund_object& sfo1 = create_samet_fund( sam_id, core_id, 10000, 10000u ); // fee rate is 1%
1182+
samet_fund_id_type sf1_id = sfo1.id;
1183+
1184+
generate_block();
1185+
1186+
// Check history API
1187+
graphene::app::history_api hist_api(app);
1188+
1189+
// Sam's last operation is fund creation
1190+
auto histories = hist_api.get_relative_account_history( "sam", 0, 1, 0 );
1191+
BOOST_REQUIRE_EQUAL( histories.size(), 1u );
1192+
BOOST_CHECK( histories[0].op.is_type<samet_fund_create_operation>() );
1193+
1194+
// Ted's last operation is transfer
1195+
histories = hist_api.get_relative_account_history( "ted", 0, 1, 0 );
1196+
BOOST_REQUIRE_EQUAL( histories.size(), 1u );
1197+
BOOST_CHECK( histories[0].op.is_type<transfer_operation>() );
1198+
1199+
// Ted borrow and repay
1200+
{
1201+
auto bop1 = make_samet_fund_borrow_op( ted_id, sf1_id, asset(1) );
1202+
auto rop1 = make_samet_fund_repay_op( ted_id, sf1_id, asset(1), asset(1) );
1203+
trx.operations.clear();
1204+
trx.operations.push_back(bop1);
1205+
trx.operations.push_back(rop1);
1206+
PUSH_TX( db, trx, ~0 );
1207+
}
1208+
1209+
generate_block();
1210+
1211+
// Sam's last 2 operations are Ted's borrowing and repayment
1212+
histories = hist_api.get_relative_account_history( "sam", 0, 2, 0 );
1213+
BOOST_REQUIRE_EQUAL( histories.size(), 2u );
1214+
BOOST_CHECK( histories[0].op.is_type<samet_fund_repay_operation>() );
1215+
BOOST_CHECK( histories[1].op.is_type<samet_fund_borrow_operation>() );
1216+
1217+
// Ted's last 2 operations are the same
1218+
auto histories_ted = hist_api.get_relative_account_history( "ted", 0, 2, 0 );
1219+
BOOST_REQUIRE_EQUAL( histories_ted.size(), 2u );
1220+
BOOST_CHECK( histories[0].id == histories_ted[0].id );
1221+
BOOST_CHECK( histories[1].id == histories_ted[1].id );
1222+
1223+
} catch (fc::exception& e) {
1224+
edump((e.to_detail_string()));
1225+
throw;
1226+
}
1227+
}
1228+
11651229
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)