-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: new oracle address #121
Conversation
WalkthroughThe recent updates revolve around integrating an Changes
This table provides a concise overview of the modifications implemented across multiple files, emphasizing the systematic integration of the oracle address and its operational implications. Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Additional Context UsedGitHub Check Runs (1)
Additional comments not posted (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 2
// update oracle contract address v3 | ||
if msg.oracle_address.is_some() { | ||
let oracle_address = msg.oracle_address.unwrap(); | ||
let address = validate_address(&oracle_address, "osmo")?; | ||
config.oracle_address = Some(address); | ||
} | ||
|
||
CONFIG.save(deps.storage, &config)?; | ||
|
||
Ok(Response::new().add_attribute("action", "update_oracle_contract_address_v2")) | ||
Ok(Response::new().add_attribute("action", "update_oracle_address")) |
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.
Update oracle address handling in migration.
- if msg.oracle_address.is_some() {
- let oracle_address = msg.oracle_address.unwrap();
- let address = validate_address(&oracle_address, "osmo")?;
- config.oracle_address = Some(address);
- }
+ config.oracle_address = msg.oracle_address.map(|addr| validate_address(&addr, "osmo").unwrap());
Refactor the handling of the new oracle address in the migration function to use more idiomatic Rust patterns, reducing redundancy and potential for errors.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
// update oracle contract address v3 | |
if msg.oracle_address.is_some() { | |
let oracle_address = msg.oracle_address.unwrap(); | |
let address = validate_address(&oracle_address, "osmo")?; | |
config.oracle_address = Some(address); | |
} | |
CONFIG.save(deps.storage, &config)?; | |
Ok(Response::new().add_attribute("action", "update_oracle_contract_address_v2")) | |
Ok(Response::new().add_attribute("action", "update_oracle_address")) | |
// update oracle contract address v3 | |
config.oracle_address = msg.oracle_address.map(|addr| validate_address(&addr, "osmo").unwrap()); | |
CONFIG.save(deps.storage, &config)?; | |
Ok(Response::new().add_attribute("action", "update_oracle_address")) |
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.
From my perspective, we can ignore this.
The suggested code will make the contract panic if we receive an invalid address, while with the original code, we return an error to the user.
If we want to make this more idiomatic Rust, I would prefer to remove the unwrap
call from inside the map
and use transpose
on the returned Option<Result<Addr>>
so that we can return the error to the user instead of panicking. However, this is more of a coding style decision that we should all agree on.
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.
@manu0466, I completely agree with your perspective. Handling potential errors gracefully rather than causing the contract to panic is indeed a more robust approach. Using transpose
on the returned Option<Result<Addr>>
is a great suggestion as it aligns with idiomatic Rust practices and ensures that errors are handled appropriately.
Here's how the code could be refactored to incorporate your suggestion:
// update oracle contract address v3
config.oracle_address = msg.oracle_address.map(|addr| validate_address(&addr, "osmo")).transpose()?;
CONFIG.save(deps.storage, &config)?;
Ok(Response::new().add_attribute("action", "update_oracle_address"))
This modification uses map
to apply validate_address
to the oracle_address
if it is Some
, and then transpose
is used to convert Option<Result<Addr>>
into Result<Option<Addr>>
, which can be propagated using ?
if there is an error. This ensures that any address validation errors are returned as a contract error rather than causing a panic.
Thank you for pointing this out and for your insightful suggestion! If there's anything else you'd like to adjust or further discuss, feel free to let me know.
if oracle_address.is_some() { | ||
let oracle_address = oracle_address.unwrap(); | ||
let address = validate_address(&oracle_address, "osmo")?; | ||
config.oracle_address = Some(address); | ||
} | ||
|
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.
Refactor handling of the new oracle address in configuration updates.
- if oracle_address.is_some() {
- let oracle_address = oracle_address.unwrap();
- let address = validate_address(&oracle_address, "osmo")?;
- config.oracle_address = Some(address);
- }
+ config.oracle_address = oracle_address.map(|addr| validate_address(&addr, "osmo").unwrap());
Simplify the handling of the new oracle address in the update_config
function to use more idiomatic Rust patterns, reducing redundancy and potential for errors.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
if oracle_address.is_some() { | |
let oracle_address = oracle_address.unwrap(); | |
let address = validate_address(&oracle_address, "osmo")?; | |
config.oracle_address = Some(address); | |
} | |
config.oracle_address = oracle_address.map(|addr| validate_address(&addr, "osmo").unwrap()); |
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.
Same as the other suggestion.
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.
@manu0466, thank you for confirming. If there's anything else you need help with or further adjustments to be made, feel free to let me know!
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.
Looks good to me. Let's decide if we want to ignore the suggestions from coderabbitai or refactor the code.
// update oracle contract address v3 | ||
if msg.oracle_address.is_some() { | ||
let oracle_address = msg.oracle_address.unwrap(); | ||
let address = validate_address(&oracle_address, "osmo")?; | ||
config.oracle_address = Some(address); | ||
} | ||
|
||
CONFIG.save(deps.storage, &config)?; | ||
|
||
Ok(Response::new().add_attribute("action", "update_oracle_contract_address_v2")) | ||
Ok(Response::new().add_attribute("action", "update_oracle_address")) |
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.
From my perspective, we can ignore this.
The suggested code will make the contract panic if we receive an invalid address, while with the original code, we return an error to the user.
If we want to make this more idiomatic Rust, I would prefer to remove the unwrap
call from inside the map
and use transpose
on the returned Option<Result<Addr>>
so that we can return the error to the user instead of panicking. However, this is more of a coding style decision that we should all agree on.
if oracle_address.is_some() { | ||
let oracle_address = oracle_address.unwrap(); | ||
let address = validate_address(&oracle_address, "osmo")?; | ||
config.oracle_address = Some(address); | ||
} | ||
|
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.
Same as the other suggestion.
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.
LGTM
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.
Actionable comments posted: 0
Out of diff range and nitpick comments (1)
contracts/staking/src/oracle.rs (1)
Line range hint
3-3
: Remove the unused importDecimal
to clean up the code.- use cosmwasm_std::{Binary, Decimal}; + use cosmwasm_std::Binary;
Overview
closes: #XXXX
What changes have been made in this PR?
Checklist
Summary by CodeRabbit