-
Notifications
You must be signed in to change notification settings - Fork 1
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
Added library config #160
Added library config #160
Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
examples/Cookbook.ipynb
Outdated
"source": [ | ||
"### Changing the default hrp\n", | ||
"\n", | ||
"We have a configuration class, called `LibraryConfig`, that only stores the **default hrp** of the addresses. The default value is `erd`. The hrp can be changed when instantiating an address, or it can be changed in the `LibraryConfig` class, and all the addresses created will have the newly set hrp. " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that only stores ...
- "for now" / "for the moment".
Maybe, in the future, we'll move the most of the constants (that we use for default values in various parts). That way, the constants will be "promoted" to static variables.
@@ -36,7 +37,7 @@ def __init__(self, pubkey: bytes, hrp: str) -> None: | |||
raise ErrBadPubkeyLength(len(pubkey), PUBKEY_LENGTH) | |||
|
|||
self.pubkey = bytes(pubkey) | |||
self.hrp = hrp | |||
self.hrp = hrp if hrp else LibraryConfig.default_address_hrp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right, good change.
Generally speaking, this configuration should only be altered on exotic use cases | ||
it can be seen as a collection of constants (or , to be more precise, rarely changed variables) that are used throughout the library. | ||
|
||
Never alter the configuration within a library! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Only in an end application.
Altering within a library (several times) might lead to ambiguity and conflicts.
multiversx_sdk/core/config.py
Outdated
it can be seen as a collection of constants (or , to be more precise, rarely changed variables) that are used throughout the library. | ||
|
||
Never alter the configuration within a library! | ||
Only alter the configuration(if needed) within an(end) application that uses this library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo / spacing.
DELEGATION_MANAGER_SC_ADDRESS = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6" | ||
|
||
# left it for compatibility reasons, will be deleted in the future |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
config: Optional[NetworkProviderConfig] = None | ||
) -> None: | ||
self.url = url | ||
self.auth = auth | ||
self.address_hrp = address_hrp | ||
self.address_hrp = address_hrp or DEFAULT_ADDRESS_HRP | ||
self.address_hrp = address_hrp or LibraryConfig.default_address_hrp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
|
||
# this is duplicated code, added here to get rid of a circular dependency | ||
# will be removed in V1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Added a
LibraryConfig
that stores the defaulthrp
value.