Merge branch 'feature/SONs-base' into feature/SON-307

This commit is contained in:
Srdjan Obucina 2020-03-30 22:50:06 +02:00
commit d773dcb100
7 changed files with 75 additions and 16 deletions

View file

@ -11,14 +11,17 @@ build:
- rm -rf .git/modules/* ./docs ./libraries/fc
- git submodule sync
- git submodule update --init --recursive
- cmake .
- rm -rf build
- mkdir build
- cd build
- cmake ..
- make -j$(nproc)
artifacts:
untracked: true
paths:
- libraries/
- programs/
- tests/
- build/libraries/
- build/programs/
- build/tests/
tags:
- builder
@ -27,9 +30,9 @@ test:
dependencies:
- build
script:
- ./tests/betting_test --log_level=message
- ./tests/chain_test --log_level=message
- ./tests/cli_test --log_level=message
- ./build/tests/betting_test --log_level=message
- ./build/tests/chain_test --log_level=message
- ./build/tests/cli_test --log_level=message
tags:
- builder

View file

@ -1844,7 +1844,10 @@ void perform_son_tasks(database& db)
{
const auto& son_account = db.create<account_object>([&](account_object& a) {
a.name = "son-account";
a.statistics = db.create<account_statistics_object>([&](account_statistics_object& s){s.owner = a.id;}).id;
a.statistics = db.create<account_statistics_object>([&a](account_statistics_object& s){
s.owner = a.id;
s.name = a.name;
}).id;
a.owner.weight_threshold = 1;
a.active.weight_threshold = 0;
a.registrar = a.lifetime_referrer = a.referrer = a.id;

View file

@ -1,4 +1,5 @@
// GPOS HARDFORK Monday, 31 Dec 2019 00:00:00 GMT
// GPOS HARDFORK Monday, 31 Dec 2019 00:00:00 GMT - 1577750400
// GPOS HARDFORK Monday, March 30, 2020 2:00:00 PM - 1585569600
#ifndef HARDFORK_GPOS_TIME
#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1577750400 ))
#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1585569600 ))
#endif

View file

@ -1,6 +1,7 @@
// SON HARDFORK Wednesday, January 1, 2020 12:00:00 AM - 1577836800
// SON HARDFORK Monday, March 30, 2020 3:00:00 PM - 1585573200
// SON HARDFORK Monday, September 21, 2020 1:43:11 PM - 1600695791
#ifndef HARDFORK_SON_TIME
#include <ctime>
#define HARDFORK_SON_TIME (fc::time_point_sec( 1577836800 ))
#define HARDFORK_SON_TIME (fc::time_point_sec( 1585573200 ))
#endif

View file

@ -1339,6 +1339,25 @@ class wallet_api
flat_map<sidechain_type, string> sidechain_public_keys,
bool broadcast = false);
/** Creates a SON object owned by the given account.
*
* Tries to create a SON object owned by the given account using
* existing vesting balances, fails if can't quess matching
* vesting balance objects. If several vesting balance objects matches
* this function uses the recent one.
*
* @param owner_account the name or id of the account which is creating the SON
* @param url a URL to include in the SON record in the blockchain. Clients may
* display this when showing a list of SONs. May be blank.
* @param sidechain_public_keys The new set of sidechain public keys.
* @param broadcast true to broadcast the transaction on the network
* @returns the signed transaction registering a SON
*/
signed_transaction try_create_son(string owner_account,
string url,
flat_map<sidechain_type, string> sidechain_public_keys,
bool broadcast = false);
/**
* Update a SON object owned by the given account.
*
@ -2298,6 +2317,7 @@ FC_API( graphene::wallet::wallet_api,
(list_witnesses)
(list_committee_members)
(create_son)
(try_create_son)
(update_son)
(delete_son)
(list_sons)

View file

@ -4727,6 +4727,37 @@ signed_transaction wallet_api::create_son(string owner_account,
return my->create_son(owner_account, url, deposit_id, pay_vb_id, sidechain_public_keys, broadcast);
}
signed_transaction wallet_api::try_create_son(string owner_account,
string url,
flat_map<sidechain_type, string> sidechain_public_keys,
bool broadcast /* = false */)
{
vesting_balance_id_type deposit_id;
bool deposit_found = false;
vesting_balance_id_type pay_vb_id;
bool pay_vb_found = false;
vector<vesting_balance_object_with_info> vbs = get_vesting_balances(owner_account);
for(const auto& vb: vbs)
{
if ((vb.balance_type == vesting_balance_type::son) &&
(vb.get_asset_amount() >= my->get_global_properties().parameters.son_vesting_amount()) &&
(vb.policy.which() == vesting_policy::tag<dormant_vesting_policy>::value))
{
deposit_found = true;
deposit_id = vb.id;
}
if ((vb.balance_type == vesting_balance_type::normal) &&
(vb.policy.which() == vesting_policy::tag<linear_vesting_policy>::value))
{
pay_vb_found = true;
pay_vb_id = vb.id;
}
}
if (!deposit_found || !pay_vb_found)
FC_THROW("Failed to find vesting balance objects");
return my->create_son(owner_account, url, deposit_id, pay_vb_id, sidechain_public_keys, broadcast);
}
signed_transaction wallet_api::update_son(string owner_account,
string url,
string block_signing_key,

View file

@ -205,8 +205,8 @@ BOOST_AUTO_TEST_CASE( son_voting )
son_object son2_obj;
signed_transaction vote_son1_tx;
signed_transaction vote_son2_tx;
int son1_start_votes, son1_end_votes;
int son2_start_votes, son2_end_votes;
uint64_t son1_start_votes, son1_end_votes;
uint64_t son2_start_votes, son2_end_votes;
son1_obj = con.wallet_api_ptr->get_son("son1account");
son1_start_votes = son1_obj.total_votes;
@ -436,8 +436,8 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
son_object son1_obj;
son_object son2_obj;
int son1_start_votes, son1_end_votes;
int son2_start_votes, son2_end_votes;
uint64_t son1_start_votes, son1_end_votes;
uint64_t son2_start_votes, son2_end_votes;
// Get votes at start
son1_obj = con.wallet_api_ptr->get_son("son1account");
@ -488,7 +488,7 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
son2_obj = con.wallet_api_ptr->get_son("son2account");
// voice distribution changed, SON2 now has all voices
son2_end_votes = son2_obj.total_votes;
BOOST_CHECK(son2_end_votes > son2_start_votes);
BOOST_CHECK((son2_end_votes > 0) && (son2_end_votes <= son2_start_votes)); // nathan spent funds for vb, it has different voting power
son2_start_votes = son2_end_votes;
// Try to reject incorrect SON