From a0e4ac59ff5d6b9874f94bab63265d70038f8ea5 Mon Sep 17 00:00:00 2001 From: gladcow Date: Fri, 1 Nov 2019 16:43:34 +0300 Subject: [PATCH] [SON-160] Fix create_vesting wallet_api call (#206) * Fix create_vesting wallet_api call * change type for vesting_type in create_vesting_balance --- .../wallet/include/graphene/wallet/wallet.hpp | 12 +++++---- libraries/wallet/wallet.cpp | 27 ++++++++----------- tests/cli/son.cpp | 5 ++-- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 9b3282c4..349ccea8 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1429,15 +1429,17 @@ class wallet_api /** Creates a vesting deposit owned by the given account. * - * @param owner_account the name or id of the account - * @param amount the amount to deposit + * @param owner_account vesting balance owner and creator (the name or id) + * @param amount amount to vest + * @param asset_symbol the symbol of the asset to vest * @param vesting_type "normal", "gpos" or "son" * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction registering a vesting object */ - signed_transaction create_vesting(string owner_account, + signed_transaction create_vesting_balance(string owner_account, string amount, - string vesting_type, + string asset_symbol, + vesting_balance_type vesting_type, bool broadcast = false); /** @@ -2118,7 +2120,7 @@ FC_API( graphene::wallet::wallet_api, (update_witness) (create_worker) (update_worker_votes) - (create_vesting) + (create_vesting_balance) (get_vesting_balances) (withdraw_vesting) (vote_for_committee_member) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 4244b7ef..edc59a65 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2107,27 +2107,21 @@ public: return sign_transaction( tx, broadcast ); } - signed_transaction create_vesting(string owner_account, + signed_transaction create_vesting_balance(string owner_account, string amount, - string vesting_type, + string asset_symbol, + vesting_balance_type vesting_type, bool broadcast /* = false */) { try { account_object son_account = get_account(owner_account); + fc::optional asset_obj = get_asset(asset_symbol); + FC_ASSERT(asset_obj, "Invalid asset symbol {asst}", ("asst", asset_symbol)); vesting_balance_create_operation op; op.creator = son_account.get_id(); op.owner = son_account.get_id(); - op.amount = asset_object().amount_from_string(amount); - if (vesting_type == "normal") - op.balance_type = vesting_balance_type::normal; - else if (vesting_type == "gpos") - op.balance_type = vesting_balance_type::gpos; - else if (vesting_type == "son") - op.balance_type = vesting_balance_type::son; - else - { - FC_ASSERT( false, "unknown vesting type value ${vt}", ("vt", vesting_type) ); - } + op.amount = asset_obj->amount_from_string(amount); + op.balance_type = vesting_type; if (op.balance_type == vesting_balance_type::son) op.policy = dormant_vesting_policy_initializer {}; @@ -4271,12 +4265,13 @@ committee_member_object wallet_api::get_committee_member(string owner_account) return my->get_committee_member(owner_account); } -signed_transaction wallet_api::create_vesting(string owner_account, +signed_transaction wallet_api::create_vesting_balance(string owner_account, string amount, - string vesting_type, + string asset_symbol, + vesting_balance_type vesting_type, bool broadcast /* = false */) { - return my->create_vesting(owner_account, amount, vesting_type, broadcast); + return my->create_vesting_balance(owner_account, amount, asset_symbol, vesting_type, broadcast); } signed_transaction wallet_api::create_son(string owner_account, diff --git a/tests/cli/son.cpp b/tests/cli/son.cpp index 1dfd8381..49779dfd 100644 --- a/tests/cli/son.cpp +++ b/tests/cli/son.cpp @@ -78,11 +78,12 @@ public: BOOST_CHECK(fixture_.generate_block()); // create deposit vesting - fixture_.con.wallet_api_ptr->create_vesting(account_name, "50000000", "son", true); + fixture_.con.wallet_api_ptr->create_vesting_balance(account_name, + "50", "1.3.0", vesting_balance_type::son, true); BOOST_CHECK(fixture_.generate_block()); // create pay_vb vesting - fixture_.con.wallet_api_ptr->create_vesting(account_name, "1000000", "normal", true); + fixture_.con.wallet_api_ptr->create_vesting_balance(account_name, "1", "1.3.0", vesting_balance_type::normal, true); BOOST_CHECK(fixture_.generate_block()); // check deposits are here