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

refactor: make lockable-ft example use Result-based error handling #750

Merged
merged 6 commits into from
Mar 17, 2022

Conversation

itegulov
Copy link
Contributor

Addresses #745 (review)

Also covered this example with workspaces-powered tests since that is the only way to test the new error handling behavior.

&mut self,
escrow_account_id: AccountId,
allowance: String,
) -> Result<(), &'static str> {
let allowance = u128::from_str(&allowance).expect("Failed to parse allowance");
Copy link
Member

Choose a reason for hiding this comment

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

probably preferable if we switch these .expect calls over to early returning an error since our error type is a str anyways, but not a big deal if we leave it as is

Copy link
Contributor

@austinabell austinabell left a comment

Choose a reason for hiding this comment

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

oops forgot to finalize this review comment

}

/// Locks an additional `lock_amount` to the caller of the function (`predecessor_id`) from
/// the `owner_id`.
/// Requirements:
/// * The (`predecessor_id`) should have enough allowance or be the owner.
/// * The owner should have enough unlocked balance.
pub fn lock(&mut self, owner_id: AccountId, lock_amount: String) {
#[return_result]
pub fn lock(&mut self, owner_id: AccountId, lock_amount: String) -> Result<(), &'static str> {
let lock_amount = u128::from_str(&lock_amount).expect("Failed to parse allow lock_amount");
Copy link
Contributor

Choose a reason for hiding this comment

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

If switching over to this pattern, probably worth switching this expect to mapping the error and using ?

&mut self,
owner_id: AccountId,
unlock_amount: String,
) -> Result<(), &'static str> {
let unlock_amount =
u128::from_str(&unlock_amount).expect("Failed to parse allow unlock_amount");
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, and a few other places

@itegulov itegulov merged commit 6d8bfca into master Mar 17, 2022
@itegulov itegulov deleted the daniyar/example-result-refactor branch March 17, 2022 03:32
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.

3 participants