Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encapsulate currency unit settings. #1023

Merged
merged 1 commit into from Sep 9, 2018

Conversation

toxeus
Copy link
Contributor

@toxeus toxeus commented Aug 27, 2018

No description provided.

@toxeus toxeus requested a review from evoskuil August 27, 2018 15:00
@coveralls
Copy link

coveralls commented Aug 27, 2018

Coverage Status

Coverage increased (+0.02%) to 81.725% when pulling bd5b43d on toxeus:recursive_money into e98ef82 on libbitcoin:master.

src/settings.cpp Outdated
@@ -41,7 +41,8 @@ settings::settings()
bip9_version_base(0x20000000),
satoshi_per_bitcoin(100000000),
initial_block_subsidy_bitcoin(50),
recursive_money(9999999989u)
recursive_money(max_money_recursive(bitcoin_to_satoshi(
initial_block_subsidy_bitcoin)))
Copy link
Member

Choose a reason for hiding this comment

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

This can’t be safely exposed as a property unless computed (vs. initialized). Same holds for other compued initializatuons above.

Copy link
Member

@evoskuil evoskuil left a comment

Choose a reason for hiding this comment

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

Not sure if you are planning this for subsequent PRs, but recursive money should not be a public setting since it's only used to derive maximum_money.

@toxeus
Copy link
Contributor Author

toxeus commented Aug 28, 2018

I was waiting for the PR with the renaming to be merged before continuing here because both manipulate the settings.cpp file and hence might conflict. The renaming has a higher prio because it blocked the parser PR in the node repo. I have updated the PR now.

@toxeus toxeus changed the title Derive bc::settings::recursive_money. Make bc::settings::max_money a function. Aug 28, 2018
@toxeus toxeus changed the title Make bc::settings::max_money a function. Encapsulate currency unit settings. Sep 5, 2018
@toxeus
Copy link
Contributor Author

toxeus commented Sep 5, 2018

As discussed on slack, I have properly encapsulated the currency unit settings. I have successfully tested the setter methods with boost::program_options and can confirm that it works as expected. Other bc::settings members that are derived will be cleaned up in upcoming PRs.

settings.bitcoin_to_satoshi(settings.initial_block_subsidy_bitcoin))
else if (!is_valid_coinbase_claim(state.height(),
settings.subsidy_interval(), settings.bitcoin_to_satoshi(
settings.initial_block_subsidy_bitcoin()))
)
Copy link
Member

@evoskuil evoskuil Sep 8, 2018

Choose a reason for hiding this comment

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

Style, don't balance parenthesis.

    else if (!is_valid_coinbase_claim(state.height(),
            settings.subsidy_interval(), settings.bitcoin_to_satoshi(
                settings.initial_block_subsidy_bitcoin())))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/settings.cpp Outdated
static const std::function<uint64_t(uint64_t)> recursive_money =
[](uint64_t money){
return money > 0 ? money + recursive_money(money >> 1u) : 0;
};
Copy link
Member

@evoskuil evoskuil Sep 8, 2018

Choose a reason for hiding this comment

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

Style: balance braces, use auto, avoid static with closures:

    const auto recursive_money = [](uint64_t money)
    {
        return money > 0 ? money + recursive_money(money >> 1u) : 0;
    };

Copy link
Contributor Author

@toxeus toxeus Sep 9, 2018

Choose a reason for hiding this comment

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

auto cannot deduce the type of recursive closures. Fixed the rest.

src/settings.cpp Outdated

uint64_t settings::bitcoin_to_satoshi(uint64_t bitcoin_units) const
{

Copy link
Member

Choose a reason for hiding this comment

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

Style: remove whitespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/settings.cpp Outdated
max_money_ = recursive_money_ * subsidy_interval_;
}

uint64_t settings::bitcoin_to_satoshi(uint64_t bitcoin_units) const
Copy link
Member

@evoskuil evoskuil Sep 9, 2018

Choose a reason for hiding this comment

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

For property methods I generally just use "value" for the parameter since the parameter name is redundant with the property name.

uint64_t settings::bitcoin_to_satoshi(uint64_t value) const

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

uint64_t initial_block_subsidy_bitcoin() const;
void subsidy_interval(uint64_t subsidy_interval);
uint64_t subsidy_interval() const;
uint64_t max_money() const;
Copy link
Member

Choose a reason for hiding this comment

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

It seems inevitable when creating a class with fields that eventually proper behavior will drive it into properties.

@toxeus toxeus force-pushed the recursive_money branch 2 times, most recently from 2487771 to bd5b43d Compare September 9, 2018 12:40
@evoskuil
Copy link
Member

evoskuil commented Sep 9, 2018

Looks good, please merge when ready.

@toxeus toxeus merged commit ba03375 into libbitcoin:master Sep 9, 2018
@toxeus toxeus deleted the recursive_money branch September 9, 2018 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants