Skip to content

Commit

Permalink
[HF1] Implemented credit deals logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslansalikhov committed Mar 13, 2018
1 parent 122cba5 commit 70e43aa
Show file tree
Hide file tree
Showing 33 changed files with 1,483 additions and 271 deletions.
60 changes: 59 additions & 1 deletion libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
uint32_t status
) const;

// Exchange rates request
map<string, string> list_last_exchange_rates()const;
map< std::string, std::map< account_id_type, string >> list_current_exchange_rates()const;
graphene::chain::chain_parameters::ext::credit_options list_global_extensions()const;

// Subscriptions
void set_subscribe_callback( std::function<void(const variant&)> cb, bool notify_remove_create );
void set_pending_transaction_callback( std::function<void(const variant&)> cb );
Expand Down Expand Up @@ -997,6 +1002,21 @@ vector<credit_object> database_api::fetch_credit_requests_stack( uint32_t from_i
cyrrency_symbol, user_id, status );
}

map<string, string> database_api::list_last_exchange_rates()const
{
return my->list_last_exchange_rates();
}

map< std::string, std::map< account_id_type, string >> database_api::list_current_exchange_rates()const
{
return my->list_current_exchange_rates();
}

graphene::chain::chain_parameters::ext::credit_options database_api::list_global_extensions()const
{
return my->list_global_extensions();
}

vector<credit_object> database_api_impl::list_credit_requests_stack( uint32_t limit )const
{
FC_ASSERT( limit <= 100 );
Expand Down Expand Up @@ -1104,6 +1124,44 @@ vector<credit_object> database_api_impl::fetch_credit_requests_stack( uint32_t f
return result;
}

map<string, string> database_api_impl::list_last_exchange_rates()const
{
const auto& exch_object = _db.get_index_type<exchange_rate_index>().indices().get<by_id>();

map<string, string> result;

for (auto const& x : (*exch_object.begin()).last_exchange_rate)
{
result[x.first] = std::to_string(x.second);
}

return result;
}

map< std::string, std::map< account_id_type, string >> database_api_impl::list_current_exchange_rates()const
{
const auto& exch_object = _db.get_index_type<exchange_rate_index>().indices().get<by_id>();

map< std::string, std::map< account_id_type, string >> result;

// by currency
for (auto const& current_exch_it : (*exch_object.begin()).current_exchange_rate)
{
// by accounts
for(auto const& account_id_it : current_exch_it.second)
{
result[current_exch_it.first][account_id_it.first] = std::to_string(account_id_it.second);
}
}

return result;
}

graphene::chain::chain_parameters::ext::credit_options database_api_impl::list_global_extensions()const
{
return get_global_properties().parameters.get_credit_options();
}

vector<asset_object> database_api_impl::list_assets(const string& lower_bound_symbol, uint32_t limit)const
{
FC_ASSERT( limit <= 100 );
Expand Down Expand Up @@ -1316,7 +1374,7 @@ market_ticker database_api_impl::get_ticker( const string& base, const string& q
FC_ASSERT( assets[1], "Invalid quote asset symbol: ${s}", ("s",quote) );

const fc::time_point_sec now = fc::time_point::now();
const fc::time_point_sec yesterday = fc::time_point_sec( now.sec_since_epoch() - 86400 );
//const fc::time_point_sec yesterday = fc::time_point_sec( now.sec_since_epoch() - 86400 );

market_ticker result;
result.time = now;
Expand Down
5 changes: 5 additions & 0 deletions libraries/app/impacted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ struct get_impacted_account_visitor
_impacted.insert( op.borrower );
}

void operator()( const exchange_rate_set_operation& op )
{
_impacted.insert( op.witness );
}

void operator()( const asset_claim_fees_operation& op ){}
void operator()( const limit_order_create_operation& op ) {}
void operator()( const limit_order_cancel_operation& op )
Expand Down
11 changes: 11 additions & 0 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <graphene/chain/worker_object.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/credit_object.hpp>
#include <graphene/chain/exchange_rate_object.hpp>

#include <graphene/market_history/market_history_plugin.hpp>

Expand Down Expand Up @@ -147,6 +148,11 @@ class database_api
uint32_t status
) const;

map<string, string> list_last_exchange_rates()const;
map< std::string, std::map< account_id_type, string >> list_current_exchange_rates()const;

graphene::chain::chain_parameters::ext::credit_options list_global_extensions()const;

/**
* @brief Get the objects corresponding to the provided IDs
* @param ids IDs of the objects to retrieve
Expand Down Expand Up @@ -700,6 +706,11 @@ FC_API(graphene::app::database_api,
(fetch_credit_requests_stack)
(list_credit_request_by_uuid)

// Exchange rate request
(list_last_exchange_rates)
(list_current_exchange_rates)
(list_global_extensions)

// Assets
(get_assets)
(list_assets)
Expand Down
3 changes: 3 additions & 0 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ add_library( graphene_chain
protocol/confidential.cpp
protocol/vote.cpp
protocol/credit.cpp
protocol/exchange_rate.cpp

genesis_state.cpp
get_config.cpp
Expand All @@ -81,13 +82,15 @@ add_library( graphene_chain
special_authority.cpp
buyback.cpp
credit_evaluator.cpp
exchange_rate_evaluator.cpp

account_object.cpp
asset_object.cpp
fba_object.cpp
proposal_object.cpp
vesting_balance_object.cpp
credit_object.cpp
exchange_rate_object.cpp

block_database.cpp

Expand Down
77 changes: 39 additions & 38 deletions libraries/chain/account_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,44 +302,45 @@ void_result account_update_evaluator::do_apply( const account_update_operation&
database& d = db();
bool sa_before, sa_after;
d.modify( *acnt, [&](account_object& a){
if( o.login )
a.pi.login = *(o.login);
if( o.email )
a.pi.email = *(o.email);
if( o.firstName )
a.pi.firstName = *(o.firstName);
if( o.lastName )
a.pi.lastName = *(o.lastName);
if( o.facebook )
a.pi.facebook = *(o.facebook);
if( o.mobile )
a.pi.mobile = *(o.mobile);
if( o.taxResidence )
a.pi.taxResidence = *(o.taxResidence);

if( o.bankName )
a.ba.bankName = *(o.bankName);
if( o.bankSwift )
a.ba.bankSwift = *(o.bankSwift);
if( o.bankAccount )
a.ba.bankAccount = *(o.bankAccount);
if( o.bankBenificiary )
a.ba.bankBenificiary = *(o.bankBenificiary);

if( o.about )
a.ai.about = *(o.about);
if( o.companyName )
a.ai.companyName = *(o.companyName);
if( o.companyActivity )
a.ai.companyActivity = *(o.companyActivity);
if( o.companyVat )
a.ai.companyVat = *(o.companyVat);
if( o.companyWebsite )
a.ai.companyWebsite = *(o.companyWebsite);
if( o.companyYoutube )
a.ai.companyYoutube = *(o.companyYoutube);
if( o.companyPdf )
a.ai.companyPdf = *(o.companyPdf);

if( o.login )
a.pi.login = *(o.login);
if( o.email )
a.pi.email = *(o.email);
if( o.firstName )
a.pi.firstName = *(o.firstName);
if( o.lastName )
a.pi.lastName = *(o.lastName);
if( o.facebook )
a.pi.facebook = *(o.facebook);
if( o.mobile )
a.pi.mobile = *(o.mobile);
if( o.taxResidence )
a.pi.taxResidence = *(o.taxResidence);

if( o.bankName )
a.ba.bankName = *(o.bankName);
if( o.bankSwift )
a.ba.bankSwift = *(o.bankSwift);
if( o.bankAccount )
a.ba.bankAccount = *(o.bankAccount);
if( o.bankBenificiary )
a.ba.bankBenificiary = *(o.bankBenificiary);

if( o.about )
a.ai.about = *(o.about);
if( o.companyName )
a.ai.companyName = *(o.companyName);
if( o.companyActivity )
a.ai.companyActivity = *(o.companyActivity);
if( o.companyVat )
a.ai.companyVat = *(o.companyVat);
if( o.companyWebsite )
a.ai.companyWebsite = *(o.companyWebsite);
if( o.companyYoutube )
a.ai.companyYoutube = *(o.companyYoutube);
if( o.companyPdf )
a.ai.companyPdf = *(o.companyPdf);

if( o.owner )
{
Expand Down
Loading

0 comments on commit 70e43aa

Please sign in to comment.