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

add backward compatibility for AccountProviderConfig #3633

Merged
merged 2 commits into from
Aug 10, 2022

Conversation

JerryKwan
Copy link
Contributor

add serde default for AccountProviderConfig's field named from_env

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: #3630

What is the new behavior?

backward to old version of config.toml

Other information

add serde default for AccountProviderConfig's field named from_env
@nkysg nkysg requested a review from pause125 August 10, 2022 02:40
@codecov
Copy link

codecov bot commented Aug 10, 2022

Codecov Report

Merging #3633 (443ae3a) into master (38e141e) will decrease coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3633      +/-   ##
==========================================
- Coverage   28.76%   28.70%   -0.06%     
==========================================
  Files         591      591              
  Lines       50428    50573     +145     
  Branches    23766    23849      +83     
==========================================
+ Hits        14503    14511       +8     
- Misses      21742    21825      +83     
- Partials    14183    14237      +54     
Flag Coverage Δ
unittests 28.70% <ø> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
config/src/account_provider_config.rs 25.40% <ø> (-1.58%) ⬇️
consensus/src/consensus.rs 39.69% <0.00%> (-15.87%) ⬇️
vm/types/src/transaction_metadata.rs 55.23% <0.00%> (-11.94%) ⬇️
vm/natives/src/vector.rs 8.34% <0.00%> (-8.33%) ⬇️
...mons/forkable-jellyfish-merkle/src/iterator/mod.rs 41.50% <0.00%> (-5.50%) ⬇️
...s/forkable-jellyfish-merkle/src/mock_tree_store.rs 27.59% <0.00%> (-5.17%) ⬇️
vm/natives/src/token.rs 20.00% <0.00%> (-4.44%) ⬇️
state/state-tree/src/mock/mod.rs 39.14% <0.00%> (-4.34%) ⬇️
vm/types/src/token/token_code.rs 34.53% <0.00%> (-2.38%) ⬇️
vm/transaction-builder/src/lib.rs 26.17% <0.00%> (-1.95%) ⬇️
... and 60 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce17ac4...443ae3a. Read the comment docs.

@nkysg nkysg self-requested a review August 10, 2022 03:09
@pause125
Copy link
Collaborator

另一个参数 secret_file 是不是也要加一下 ?

@@ -25,6 +25,7 @@ pub struct AccountProviderConfig {
pub secret_file: Option<PathBuf>,

/// Read private from env variable `STARCOIN_PRIVATE_KEY`.
#[serde(default)]
Copy link
Member

Choose a reason for hiding this comment

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

这个是不是应该设置成 Optoin, 然后加上

#[serde(skip_serializing_if = "Option::is_none")]

这样默认就不会变更配置文件。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what #[serde(skip_serializing_if)] does
Call a function to determine whether to skip serializing this field. The given function must be callable as fn(&T) -> bool, although it may be generic over T. For example skip_serializing_if = "Option::is_none" would skip an Option that is None.

Change the type to Option is a choice, but seem like there is no need to change a boolean value to Option, right?

Copy link
Member

Choose a reason for hiding this comment

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

有一些区别。bool 会默认序列化成 false 写到配置中。但使用的时候需要指定 --from-env true, 我们有一部分 bool 的 CLI 选项用的是 Option。不过 from-env 这个在配置文件中应该用不到,默认序列化成 false 也没问题。

@jolestar
Copy link
Member

另一个参数 secret_file 是不是也要加一下 ?

@JerryKwan 给这个加上

#[serde(skip_serializing_if = "Option::is_none")]

add skip_serializing_if to secret_file
@JerryKwan
Copy link
Contributor Author

@jolestar @0xpause #[serde(skip_serializing_if = "Option::is_none")] added to secret_file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants