From fd40d47240d24ea74cc99d468b453daf3ed7eb56 Mon Sep 17 00:00:00 2001 From: Steve Gerbino Date: Tue, 11 Feb 2020 16:31:01 -0500 Subject: [PATCH] #3593: Add delegation pool support to the cli wallet --- .../wallet/include/steem/wallet/wallet.hpp | 53 +++++++++++ libraries/wallet/wallet.cpp | 92 +++++++++++++++++++ 2 files changed, 145 insertions(+) diff --git a/libraries/wallet/include/steem/wallet/wallet.hpp b/libraries/wallet/include/steem/wallet/wallet.hpp index c1f30839ba..4fe3c07d83 100644 --- a/libraries/wallet/include/steem/wallet/wallet.hpp +++ b/libraries/wallet/include/steem/wallet/wallet.hpp @@ -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> get_result_formatters() const; fc::signal lock_changed; @@ -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) ) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index a4d74c9c1a..5bd6a5cef2 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -12,6 +12,9 @@ #include #include +#include +#include +#include #include #include @@ -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