Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Referral program implemented #295 #942

Merged
merged 1 commit into from
Sep 11, 2018

Conversation

maslenitsa93
Copy link

@maslenitsa93 maslenitsa93 commented Aug 26, 2018

#295

Creating referral account. Hardfork check. Disabled breaking referral

  1. Create test account and it's testref referral account.
./cli_wallet --server-rpc-endpoint=ws://127.0.0.1:8091
set_password qwer
unlock qwer
import_key 5JVFFWRLwz6JoP9kguuRFfytToGU6cLgBVTL9t6NB3D3BQLbUBS
create_account cyberfounder test "{}" "300.000 GOLOS" true
transfer_to_vesting cyberfounder test "30.000 GOLOS" true
transfer cyberfounder test "0.200 GOLOS" "" true
create_account_referral test "0.200 GOLOS" "0.000001 GESTS" testref "{}" {"referrer": "test", "interest_rate": 900, "end_date": "2018-09-26T14:00:00", "break_fee": "0.000 GOLOS"} true
  1. You have a fail with message about unsupported operation because you done it before 19 hardfork applied. Wait for this hardfork and run again.

  2. See the Mongo.

Result: account_object has an object will following fields:

   ...
    "referrer_account" : "test", 
    "referrer_interest_rate" : NumberLong(900), 
    "referral_end_date" : ISODate("2018-09-26T14:00:00.000+0000"), 
    "referral_break_fee_value" : 0.0, 
    "referral_break_fee_symbol" : "GOLOS", 
    ...
}
  1. See the get_accounts API with following HTML page in browser:
<script src="node_modules/golos-js/dist/golos.min.js"></script>
Hello world
<script>
golos.config.set('websocket', 'ws://127.0.0.1:8091');
golos.api.getAccounts(['test', 'testref'], function (err, result) {
document.body.innerHTML += '<pre>' + JSON.stringify(result, null, 2) + "</pre>";
});
</script>

Result:

    "referrer_account": "test",
    "referrer_interest_rate": 900,
    "referral_end_date": "2018-09-26T14:00:00",
    "referral_break_fee": "0.000 GOLOS"
  }
]
  1. Try to break referral program:
break_free_referral testref true

Result: fail - no right to break referral.

Enabled breaking referral. Try to break referral without enough balance

  1. Create another referral account:
create_account_referral test "0.200 GOLOS" "0.000001 GESTS" testref2 "{}" {"referrer": "test", "interest_rate": 900, "end_date": "2018-09-26T14:00:00", "break_fee": "0.001 GOLOS"} true
  1. Check it:
get_account testref2

Result:

  ...
  "referrer_account": "test",
  "referrer_interest_rate": 900,
  "referral_end_date": "2018-09-26T14:00:00",
  "referral_break_fee": "0.001 GOLOS"
}
  1. Try to break referral (without enough balance):
break_free_referral testref2 true

Result: fail - does not have sufficient funds.

  1. Transfer some money to balance and try again:
transfer cyberfounder testref2 "0.200 GOLOS" "" true
break_free_referral testref2 true

Result: success.

  1. Check referral (in past) account:
get_account testref2

Result:

  ...
  "balance": "0.199 GOLOS",
  ...
  "referrer_account": "",
  "referrer_interest_rate": 0,
  "referral_end_date": "1970-01-01T00:00:00",
  "referral_break_fee": "0.000 GOLOS"
}
  1. Check referrer account:
get_account test

Result:

  ...
  "balance": "0.001 GOLOS",
  ...
}

Creating comment before breaking referral and after it

  1. Create referral account:
create_account_referral test "0.200 GOLOS" "0.000001 GESTS" testref3 "{}" {"referrer": "test", "interest_rate": 900, "end_date": "2018-09-26T14:00:00", "break_fee": "0.001 GOLOS"} true
  1. Post comment from it:
post_comment testref3 test "" test hello world "{}" true
  1. Check comment in Mongo. Result:
    ...
    "beneficiaries" : [
        {
            "account" : "test", 
            "weight" : NumberLong(900)
        }
    ], 
    ...
  1. Break referral:
transfer cyberfounder testref3 "0.200 GOLOS" "" true
break_free_referral testref3 true
  1. Wait for 5 minutes and post comment again:
post_comment testref3 test2 "" test hello world "{}" true
  1. Check comment in Mongo.
    Result: no object with account="test" in beneficiaries.

@maslenitsa93
Copy link
Author

Do not write me about code style in code what is not my but is near. I will do big code style fix after all work.

@maslenitsa93
Copy link
Author

maslenitsa93 commented Aug 27, 2018

I have the problems with adding and resetting referrer's beneficiary in comment_evaluator.

Problem 1. See here: c72edaa#diff-04f6af9cdbf180a31ccdbf6335b8f240R704
comment_object::beneficiaries is a vector, therefore it is too complex to push only single value - we should check if this value isn't exist already.
Also, it is complex to remove value from it.

Problem 2. comment_options_evaluator checks if beneficiaries aren't added already - it will fail because we will set them in comment_evaluator.
At all, currently beneficiaries are not designed to be setted multiple times.

Questions:

  1. Couldn't we rewrite beneficiaries field to flat_set?
  2. What to do with comment_options operation?

@afalaleev afalaleev modified the milestones: 0.18.5, 0.19.0 Aug 27, 2018
@afalaleev
Copy link
Member

  1. should be enough one of the:
  1. in the comment_options_evaluator you should check
  • beneficiaries.size() == 0 || (beneficiaries.size() == 1 && beneficiaries.front() == referrer)
  • sum of weights <= 100%
  • number of beneficiaries
  • unique names of beneficiaries

@maslenitsa93
Copy link
Author

maslenitsa93 commented Aug 28, 2018

Bug fixed:
b29cbc8#diff-ddf0678389d8cc985093894138e0c595L141

And this one ("Benficiaries") couldn't be fixed:
b29cbc8#diff-ddf0678389d8cc985093894138e0c595L151
because it is not good to change messages of exceptions (automatic parsing of them is dirty trick but it don't stop some persons)

void operator()(const account_referral_options& aro) const {
if (!_db.has_hardfork(STEEMIT_HARDFORK_0_19__295)) {
FC_THROW_EXCEPTION(golos::unsupported_operation,
"account_referral_options is not supported until STEEMIT_HARDFORK_0_19__295");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with ASSERT_REQ_HF()

com.cashout_time = com.created + STEEMIT_CASHOUT_WINDOW_SECONDS;
}

if (_db.has_hardfork(STEEMIT_HARDFORK_0_19__295)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed case.
Referrer appears on create of account, it can't appear after some time.
So, additing of beneficiary can happen only on create post/comment.

if (!_db.has_hardfork(STEEMIT_HARDFORK_0_19__295)) {
FC_THROW_EXCEPTION(golos::unsupported_operation,
"break_free_referral_operation is not supported until STEEMIT_HARDFORK_0_19__295");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASSERT_REQ_HF()

@maslenitsa93
Copy link
Author

maslenitsa93 commented Aug 29, 2018

ASSERT_REQ_HF:

98b46dd#diff-d28716ca583d6a29157aac7c681bf2e1L7

  • Using of db() was making this macro unworkable in many cases including my one. _db seems better. Replaced.
  • But additionally, added ASSERT_REQ_HF_IN_DB macro for cases with custom db variable.

@maslenitsa93
Copy link
Author

maslenitsa93 commented Aug 29, 2018

GET_ACTOR:

No such get_account method. It couldn't work.
Added `db->':
60ccf3f#diff-39d175fc7ddf571106cb34222239fb3bR239
(But it is not useful macro anyway. Currently not used)

libraries/chain/steem_evaluator.cpp Outdated Show resolved Hide resolved
libraries/chain/steem_evaluator.cpp Outdated Show resolved Hide resolved
libraries/chain/steem_evaluator.cpp Outdated Show resolved Hide resolved
libraries/wallet/wallet.cpp Outdated Show resolved Hide resolved
libraries/chain/steem_evaluator.cpp Outdated Show resolved Hide resolved
libraries/chain/steem_evaluator.cpp Outdated Show resolved Hide resolved
libraries/chain/steem_evaluator.cpp Outdated Show resolved Hide resolved
}
});

GOLOS_CHECK_VALUE(total_weight <= STEEMIT_100_PERCENT,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors still diffirent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors still different.

@maslenitsa93 maslenitsa93 requested review from afalaleev and removed request for afalaleev September 3, 2018 07:27
@maslenitsa93
Copy link
Author

Fixing tests now.


void validate() const;
};

typedef static_variant <
using comment_options_extension = static_variant<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you change these lines? Issue doesn't require it.


typedef flat_set <comment_options_extension> comment_options_extensions_type;
using comment_options_extensions_type = flat_set<comment_options_extension>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you change these lines? Issue doesn't require it.

@@ -865,7 +889,7 @@ namespace golos { namespace protocol {
void validate() const;
};

typedef fc::static_variant<pow2, equihash_pow> pow2_work;
using pow2_work = fc::static_variant<pow2, equihash_pow>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you change this line? Issue doesn't require it.

libraries/protocol/steem_operations.cpp Outdated Show resolved Hide resolved
}
});

GOLOS_CHECK_VALUE(total_weight <= STEEMIT_100_PERCENT,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors still different.

@maslenitsa93
Copy link
Author

Not yet

ASSERT_REQ_HF(STEEMIT_HARDFORK_0_19__295, "chain_properties_19");
result_type r;
r = p;
return r;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to pass reference to witness properties and set value here.
In this case it will be not overwrite values from different versions of chain_properties.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to block using of chain_properties_18 in HF 19.

@afalaleev afalaleev merged commit 17ef058 into golos-v0.19.0 Sep 11, 2018
@afalaleev afalaleev deleted the 295-referral-program-impl2 branch September 11, 2018 13:16
AKorpusenko added a commit that referenced this pull request Sep 18, 2018
…eward poll. #898

Merge pull request #937 from GolosChain/golos-v0.18.4

Golos v0.18.4
Add chain_properties_19 #295

Merge pull request #938 from GolosChain/295-referral-program

chain_properties_19 #295
Made auction window votable. Fixed rewards calculations. #898

Merge branch 'master' into golos-v0.19.0

Fix naming in chain_properties_19 #295

Merge pull request #939 from GolosChain/295-chain-propertie

Fix naming in chain_properties_19 #295
Updated with current 19.0

Added auction_window_size to wallet update_chain_properties. #898

Fixed some codestyle errors. Changed auction_window_weight to uint128_t. #898

Added HF19 checks. Fixed auction_window_size in update_chain_properties. #898

Added auction_window_max_size constant to config. Added HF19 checks in steem_evaluator. #898

Fixed some comment reward logic in tests. #898

Referral program, ASSERT_REQ_HF improved, HF 19 #295

Merge pull request #942 from GolosChain/295-referral-program-impl2

Referral program implemented #295
Update with current 19.0. #898

Fixed auction window tokens return to reward fund. #898

Renamed modify reward fund function. #898
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants