Skip to content

Commit

Permalink
#3593: Add delegation pool support to the cli wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
sgerbino committed Feb 11, 2020
1 parent 14b7631 commit fd40d47
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
53 changes: 53 additions & 0 deletions libraries/wallet/include/steem/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,54 @@ class wallet_api
*/
vector< asset_symbol_type > get_nai_pool();

/**
* Delegate from a user to a pool.
*
* @param from_account The source account
* @param to_pool The destination pool
* @param amount The amount to delegate
* @param broadcast To broadcast this transaction or not
*/
condenser_api::legacy_signed_transaction delegate_to_pool(
account_name_type from_account,
account_name_type to_pool,
asset amount,
bool broadcast );

/**
* Delegate from a pool to a user.
*
* @param from_pool The source pool
* @param to_account The destination account
* @param to_slot The slot
* @param asset_symbol The symbol of the delegation
* @param drc_max_mana The maximum mana to delegate
* @param broadcast To broadcast this transaction or not
*/
condenser_api::legacy_signed_transaction delegate_drc_from_pool(
account_name_type from_pool,
account_name_type to_account,
uint8_t to_slot,
asset_symbol_type asset_symbol,
int64_t drc_max_mana,
bool broadcast );

/**
* Designate an account the privilege to delegate a slot.
*
* @param from_pool The source pool
* @param to_account The destination account
* @param to_slot The slot
* @param signer The appointed delegator
* @param broadcast To broadcast this transaction or not
*/
condenser_api::legacy_signed_transaction set_slot_delegator(
account_name_type from_pool,
account_name_type to_account,
uint8_t to_slot,
account_name_type signer,
bool broadcast );

std::map<string,std::function<string(fc::variant,const fc::variants&)>> get_result_formatters() const;
fc::signal<void(bool)> lock_changed;

Expand Down Expand Up @@ -1442,6 +1490,11 @@ FC_API( steem::wallet::wallet_api,
(smt_setup)
(smt_contribute)
(get_nai_pool)

/// delegation pool api
(delegate_to_pool)
(delegate_drc_from_pool)
(set_slot_delegator)
)

FC_REFLECT( steem::wallet::memo_data, (from)(to)(nonce)(check)(encrypted) )
92 changes: 92 additions & 0 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <steem/wallet/remote_node_api.hpp>

#include <steem/plugins/follow/follow_operations.hpp>
#include <steem/plugins/rc/rc_objects.hpp>
#include <steem/plugins/rc/rc_operations.hpp>
#include <steem/plugins/rc/rc_plugin.hpp>

#include <algorithm>
#include <cctype>
Expand Down Expand Up @@ -2789,4 +2792,93 @@ condenser_api::legacy_signed_transaction wallet_api::follow( string follower, st
return my->_remote_api->get_nai_pool();
}

condenser_api::legacy_signed_transaction wallet_api::delegate_to_pool(
account_name_type from_account,
account_name_type to_pool,
asset amount,
bool broadcast )
{
using namespace plugins::rc;
FC_ASSERT( !is_locked() );

delegate_to_pool_operation cop;
cop.from_account = from_account;
cop.to_pool = to_pool;
cop.amount = amount;

custom_json_operation op;
op.json = fc::json::to_string( rc_plugin_operation( cop ) );
op.id = STEEM_RC_PLUGIN_NAME;

flat_set< account_name_type > required_auths;
cop.get_required_active_authorities( required_auths );
op.required_auths = required_auths;

signed_transaction trx;
trx.operations.push_back( op );
trx.validate();
return my->sign_transaction( trx, broadcast );
}

condenser_api::legacy_signed_transaction wallet_api::delegate_drc_from_pool(
account_name_type from_pool,
account_name_type to_account,
uint8_t to_slot,
asset_symbol_type asset_symbol,
int64_t drc_max_mana,
bool broadcast )
{
using namespace plugins::rc;
FC_ASSERT( !is_locked() );

delegate_drc_from_pool_operation cop;
cop.from_pool = from_pool;
cop.to_account = to_account;
cop.to_slot = to_slot;
cop.drc_max_mana = drc_max_mana;

custom_json_operation op;
op.json = fc::json::to_string( rc_plugin_operation( cop ) );
op.id = STEEM_RC_PLUGIN_NAME;

flat_set< account_name_type > required_auths;
cop.get_required_active_authorities( required_auths );
op.required_auths = required_auths;

signed_transaction trx;
trx.operations.push_back( op );
trx.validate();
return my->sign_transaction( trx, broadcast );
}

condenser_api::legacy_signed_transaction wallet_api::set_slot_delegator(
account_name_type from_pool,
account_name_type to_account,
uint8_t to_slot,
account_name_type signer,
bool broadcast )
{
using namespace plugins::rc;
FC_ASSERT( !is_locked() );

set_slot_delegator_operation cop;
cop.from_pool = from_pool;
cop.to_account = to_account;
cop.to_slot = to_slot;
cop.signer = signer;

custom_json_operation op;
op.json = fc::json::to_string( rc_plugin_operation( cop ) );
op.id = STEEM_RC_PLUGIN_NAME;

flat_set< account_name_type > required_auths;
cop.get_required_active_authorities( required_auths );
op.required_auths = required_auths;

signed_transaction trx;
trx.operations.push_back( op );
trx.validate();
return my->sign_transaction( trx, broadcast );
}

} } // steem::wallet

0 comments on commit fd40d47

Please sign in to comment.