Skip to content

Implement fungible and fungibles for tokens#517

Merged
zjb0807 merged 9 commits into
masterfrom
implement-fungible
Jun 14, 2021
Merged

Implement fungible and fungibles for tokens#517
zjb0807 merged 9 commits into
masterfrom
implement-fungible

Conversation

@zjb0807
Copy link
Copy Markdown
Member

@zjb0807 zjb0807 commented Jun 10, 2021

#417

currencies module is updating.

@zjb0807 zjb0807 requested a review from xlc June 10, 2021 03:04
@xlc xlc requested a review from shaunxw June 10, 2021 03:07
Comment thread tokens/src/lib.rs
Comment thread tokens/src/lib.rs
Comment thread tokens/src/lib.rs
Comment thread tokens/src/lib.rs
Comment thread tokens/src/lib.rs
Comment thread tokens/src/lib.rs Outdated
source: &T::AccountId,
dest: &T::AccountId,
amount: T::Balance,
_keep_alive: bool,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we shouldn't ignore keep_alive

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fn transfer(
currency_id: Self::CurrencyId,
from: &T::AccountId,
to: &T::AccountId,
amount: Self::Balance,
) -> DispatchResult {
if amount.is_zero() || from == to {
return Ok(());
}
Self::ensure_can_withdraw(currency_id, from, amount)?;
let from_balance = Self::free_balance(currency_id, from);
let to_balance = Self::free_balance(currency_id, to)
.checked_add(&amount)
.ok_or(ArithmeticError::Overflow)?;
// Cannot underflow because ensure_can_withdraw check
Self::set_free_balance(currency_id, from, from_balance - amount);
Self::set_free_balance(currency_id, to, to_balance);
Ok(())

Tokens transfer not handle the ExistenceRequirement

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we need a version that handles it, and transfer can call it with keep_alive: false

Comment thread tokens/src/lib.rs Outdated
Comment thread tokens/src/lib.rs
Comment thread tokens/src/lib.rs
Comment thread tokens/src/lib.rs
@zjb0807 zjb0807 requested review from shaunxw and xlc June 11, 2021 06:46
Comment thread traits/src/currency.rs Outdated
from: &AccountId,
to: &AccountId,
amount: Self::Balance,
existence_requirement: ExistenceRequirement,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this will break too many existing code.
I was thinking only update the transfer implementation of orml-tokens. Add a new helper method to take existence_requirement.

Comment thread traits/src/currency.rs Outdated
from: &AccountId,
to: &AccountId,
amount: Self::Balance,
existence_requirement: ExistenceRequirement,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove this as well

@zjb0807 zjb0807 requested a review from xlc June 14, 2021 03:00
@zjb0807 zjb0807 merged commit ffa1a26 into master Jun 14, 2021
@zjb0807 zjb0807 deleted the implement-fungible branch June 14, 2021 03:28
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