Skip to content

Commit

Permalink
Merge pull request steemit#882 from steemit/880-api-update
Browse files Browse the repository at this point in the history
API and CLI updates
  • Loading branch information
Michael Vandeberg authored Feb 27, 2017
2 parents 27c0c6c + 2ea7ba2 commit 0a095bd
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 5 deletions.
11 changes: 11 additions & 0 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,17 @@ scheduled_hardfork database_api::get_next_scheduled_hardfork() const
});
}

reward_fund_api_obj database_api::get_reward_fund( string name )const
{
return my->_db.with_read_lock( [&]()
{
auto fund = my->_db.find< reward_fund_object, by_name >( name );
FC_ASSERT( fund != nullptr, "Invalid reward fund name" );

return *fund;
});
}

//////////////////////////////////////////////////////////////////////
// //
// Keys //
Expand Down
2 changes: 2 additions & 0 deletions libraries/app/include/steemit/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class database_api
witness_schedule_api_obj get_witness_schedule()const;
hardfork_version get_hardfork_version()const;
scheduled_hardfork get_next_scheduled_hardfork()const;
reward_fund_api_obj get_reward_fund( string name )const;

//////////
// Keys //
Expand Down Expand Up @@ -499,6 +500,7 @@ FC_API(steemit::app::database_api,
(get_witness_schedule)
(get_hardfork_version)
(get_next_scheduled_hardfork)
(get_reward_fund)

// Keys
(get_key_references)
Expand Down
26 changes: 24 additions & 2 deletions libraries/app/include/steemit/app/steem_api_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ typedef chain::witness_schedule_object witness_schedule_api_obj;
typedef chain::account_bandwidth_object account_bandwidth_api_obj;
typedef chain::vesting_delegation_object vesting_delegation_api_obj;
typedef chain::vesting_delegation_expiration_object vesting_delegation_expiration_api_obj;
typedef chain::reward_fund_object reward_fund_api_obj;

struct comment_api_obj
{
Expand Down Expand Up @@ -91,7 +92,12 @@ struct comment_api_obj
allow_replies( o.allow_replies ),
allow_votes( o.allow_votes ),
allow_curation_rewards( o.allow_curation_rewards )
{}
{
for( auto& route : o.beneficiaries )
{
beneficiaries.push_back( route );
}
}

comment_api_obj(){}

Expand Down Expand Up @@ -142,6 +148,7 @@ struct comment_api_obj
bool allow_replies;
bool allow_votes;
bool allow_curation_rewards;
vector< beneficiary_route_type > beneficiaries;
};

struct category_api_obj
Expand Down Expand Up @@ -220,9 +227,15 @@ struct account_api_obj
savings_sbd_seconds_last_update( a.savings_sbd_seconds_last_update ),
savings_sbd_last_interest_payment( a.savings_sbd_last_interest_payment ),
savings_withdraw_requests( a.savings_withdraw_requests ),
reward_sbd_balance( a.reward_sbd_balance ),
reward_steem_balance( a.reward_steem_balance ),
reward_vesting_balance( a.reward_vesting_balance ),
reward_vesting_steem( a.reward_vesting_steem ),
curation_rewards( a.curation_rewards ),
posting_rewards( a.posting_rewards ),
vesting_shares( a.vesting_shares ),
delegated_vesting_shares( a.delegated_vesting_shares ),
received_vesting_shares( a.received_vesting_shares ),
vesting_withdraw_rate( a.vesting_withdraw_rate ),
next_vesting_withdrawal( a.next_vesting_withdrawal ),
withdrawn( a.withdrawn ),
Expand Down Expand Up @@ -325,10 +338,17 @@ struct account_api_obj

uint8_t savings_withdraw_requests;

asset reward_sbd_balance;
asset reward_steem_balance;
asset reward_vesting_balance;
asset reward_vesting_steem;

share_type curation_rewards;
share_type posting_rewards;

asset vesting_shares;
asset delegated_vesting_shares;
asset received_vesting_shares;
asset vesting_withdraw_rate;
time_point_sec next_vesting_withdrawal;
share_type withdrawn;
Expand Down Expand Up @@ -491,6 +511,7 @@ FC_REFLECT( steemit::app::comment_api_obj,
(children_abs_rshares)(cashout_time)(max_cashout_time)
(total_vote_weight)(reward_weight)(total_payout_value)(curator_payout_value)(author_rewards)(net_votes)(root_comment)(mode)
(max_accepted_payout)(percent_steem_dollars)(allow_replies)(allow_votes)(allow_curation_rewards)
(beneficiaries)
)

FC_REFLECT( steemit::app::category_api_obj,
Expand All @@ -506,7 +527,8 @@ FC_REFLECT( steemit::app::account_api_obj,
(savings_balance)
(sbd_balance)(sbd_seconds)(sbd_seconds_last_update)(sbd_last_interest_payment)
(savings_sbd_balance)(savings_sbd_seconds)(savings_sbd_seconds_last_update)(savings_sbd_last_interest_payment)(savings_withdraw_requests)
(vesting_shares)(vesting_withdraw_rate)(next_vesting_withdrawal)(withdrawn)(to_withdraw)(withdraw_routes)
(reward_sbd_balance)(reward_steem_balance)(reward_vesting_balance)(reward_vesting_steem)
(vesting_shares)(delegated_vesting_shares)(received_vesting_shares)(vesting_withdraw_rate)(next_vesting_withdrawal)(withdrawn)(to_withdraw)(withdraw_routes)
(curation_rewards)
(posting_rewards)
(proxied_vsf_votes)(witnesses_voted_for)
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/steemit/chain/steem_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ namespace steemit { namespace chain {
c( *this );
}

reward_fund_object() {}

reward_fund_id_type id;
reward_fund_name_type name;
asset reward_balance = asset( 0, STEEM_SYMBOL );
Expand Down
52 changes: 52 additions & 0 deletions libraries/wallet/include/steemit/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,53 @@ class wallet_api
public_key_type memo,
bool broadcast )const;

/**
* This method will genrate new owner, active, and memo keys for the new account which
* will be controlable by this wallet. There is a fee associated with account creation
* that is paid by the creator. The current account creation fee can be found with the
* 'info' wallet command.
*
* These accounts are created with combination of STEEM and delegated SP
*
* @param creator The account creating the new account
* @param steem_fee The amount of the fee to be paid with STEEM
* @param delegated_vests The amount of the fee to be paid with delegation
* @param new_account_name The name of the new account
* @param json_meta JSON Metadata associated with the new account
* @param broadcast true if you wish to broadcast the transaction
*/
annotated_signed_transaction create_account_delegated( string creator, asset steem_fee, asset delegated_vests, string new_account_name, string json_meta, bool broadcast );

/**
* This method is used by faucets to create new accounts for other users which must
* provide their desired keys. The resulting account may not be controllable by this
* wallet. There is a fee associated with account creation that is paid by the creator.
* The current account creation fee can be found with the 'info' wallet command.
*
* These accounts are created with combination of STEEM and delegated SP
*
* @param creator The account creating the new account
* @param steem_fee The amount of the fee to be paid with STEEM
* @param delegated_vests The amount of the fee to be paid with delegation
* @param newname The name of the new account
* @param json_meta JSON Metadata associated with the new account
* @param owner public owner key of the new account
* @param active public active key of the new account
* @param posting public posting key of the new account
* @param memo public memo key of the new account
* @param broadcast true if you wish to broadcast the transaction
*/
annotated_signed_transaction create_account_with_keys_delegated( string creator,
asset steem_fee,
asset delegated_vests,
string newname,
string json_meta,
public_key_type owner,
public_key_type active,
public_key_type posting,
public_key_type memo,
bool broadcast )const;

/**
* This method updates the keys of an existing account.
*
Expand Down Expand Up @@ -930,6 +977,8 @@ class wallet_api
string decrypt_memo( string memo );

annotated_signed_transaction decline_voting_rights( string account, bool decline, bool broadcast );

annotated_signed_transaction claim_reward_balance( string account, asset reward_steem, asset reward_sbd, asset reward_vests, bool broadcast );
};

struct plain_keys {
Expand Down Expand Up @@ -987,6 +1036,8 @@ FC_API( steemit::wallet::wallet_api,
/// transaction api
(create_account)
(create_account_with_keys)
(create_account_delegated)
(create_account_with_keys_delegated)
(update_account)
(update_account_auth_key)
(update_account_auth_account)
Expand Down Expand Up @@ -1023,6 +1074,7 @@ FC_API( steemit::wallet::wallet_api,
(get_encrypted_memo)
(decrypt_memo)
(decline_voting_rights)
(claim_reward_balance)

// private message api
(send_private_message)
Expand Down
75 changes: 72 additions & 3 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ class wallet_api_impl
result["participation"] = (100*dynamic_props.recent_slots_filled.popcount()) / 128.0;
result["median_sbd_price"] = _remote_db->get_current_median_history_price();
result["account_creation_fee"] = _remote_db->get_chain_properties().account_creation_fee;
result["post_reward_fund"] = fc::variant(_remote_db->get_reward_fund( STEEMIT_POST_REWARD_FUND_NAME )).get_object();
result["comment_reward_fund"] = fc::variant(_remote_db->get_reward_fund( STEEMIT_COMMENT_REWARD_FUND_NAME )).get_object();
return result;
}

Expand All @@ -308,8 +310,6 @@ class wallet_api_impl
client_version = client_version.substr( pos + 1 );

fc::mutable_variant_object result;
//result["blockchain_name"] = BLOCKCHAIN_NAME;
//result["blockchain_description"] = BTS_BLOCKCHAIN_DESCRIPTION;
result["blockchain_version"] = STEEMIT_BLOCKCHAIN_VERSION;
result["client_version"] = client_version;
result["steem_revision"] = graphene::utilities::git_revision_sha;
Expand Down Expand Up @@ -1309,7 +1309,42 @@ annotated_signed_transaction wallet_api::create_account_with_keys( string creato
op.posting = authority( 1, posting, 1 );
op.memo_key = memo;
op.json_metadata = json_meta;
op.fee = my->_remote_db->get_chain_properties().account_creation_fee;
op.fee = my->_remote_db->get_chain_properties().account_creation_fee * asset( STEEMIT_CREATE_ACCOUNT_WITH_STEEM_MODIFIER, STEEM_SYMBOL );

signed_transaction tx;
tx.operations.push_back(op);
tx.validate();

return my->sign_transaction( tx, broadcast );
} FC_CAPTURE_AND_RETHROW( (creator)(new_account_name)(json_meta)(owner)(active)(memo)(broadcast) ) }

/**
* This method is used by faucets to create new accounts for other users which must
* provide their desired keys. The resulting account may not be controllable by this
* wallet.
*/
annotated_signed_transaction wallet_api::create_account_with_keys_delegated( string creator,
asset steem_fee,
asset delegated_vests,
string new_account_name,
string json_meta,
public_key_type owner,
public_key_type active,
public_key_type posting,
public_key_type memo,
bool broadcast )const
{ try {
FC_ASSERT( !is_locked() );
account_create_with_delegation_operation op;
op.creator = creator;
op.new_account_name = new_account_name;
op.owner = authority( 1, owner, 1 );
op.active = authority( 1, active, 1 );
op.posting = authority( 1, posting, 1 );
op.memo_key = memo;
op.json_metadata = json_meta;
op.fee = steem_fee;
op.delegation = delegated_vests;

signed_transaction tx;
tx.operations.push_back(op);
Expand Down Expand Up @@ -1671,6 +1706,24 @@ annotated_signed_transaction wallet_api::create_account( string creator, string
return create_account_with_keys( creator, new_account_name, json_meta, owner.pub_key, active.pub_key, posting.pub_key, memo.pub_key, broadcast );
} FC_CAPTURE_AND_RETHROW( (creator)(new_account_name)(json_meta) ) }

/**
* This method will genrate new owner, active, and memo keys for the new account which
* will be controlable by this wallet.
*/
annotated_signed_transaction wallet_api::create_account_delegated( string creator, asset steem_fee, asset delegated_vests, string new_account_name, string json_meta, bool broadcast )
{ try {
FC_ASSERT( !is_locked() );
auto owner = suggest_brain_key();
auto active = suggest_brain_key();
auto posting = suggest_brain_key();
auto memo = suggest_brain_key();
import_key( owner.wif_priv_key );
import_key( active.wif_priv_key );
import_key( posting.wif_priv_key );
import_key( memo.wif_priv_key );
return create_account_with_keys_delegated( creator, steem_fee, delegated_vests, new_account_name, json_meta, owner.pub_key, active.pub_key, posting.pub_key, memo.pub_key, broadcast );
} FC_CAPTURE_AND_RETHROW( (creator)(new_account_name)(json_meta) ) }


annotated_signed_transaction wallet_api::update_witness( string witness_account_name,
string url,
Expand Down Expand Up @@ -2059,6 +2112,22 @@ annotated_signed_transaction wallet_api::decline_voting_rights( string account,
return my->sign_transaction( tx, broadcast );
}

annotated_signed_transaction wallet_api::claim_reward_balance( string account, asset reward_steem, asset reward_sbd, asset reward_vests, bool broadcast )
{
FC_ASSERT( !is_locked() );
claim_reward_balance_operation op;
op.account = account;
op.reward_steem = reward_steem;
op.reward_sbd = reward_sbd;
op.reward_vests = reward_vests;

signed_transaction tx;
tx.operations.push_back( op );
tx.validate();

return my->sign_transaction( tx, broadcast );
}

map<uint32_t,applied_operation> wallet_api::get_account_history( string account, uint32_t from, uint32_t limit ) {
auto result = my->_remote_db->get_account_history(account,from,limit);
if( !is_locked() ) {
Expand Down

0 comments on commit 0a095bd

Please sign in to comment.