-
Notifications
You must be signed in to change notification settings - Fork 53
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
Update fungible token interface to check the type deposited in the deposit function #51
Conversation
contracts/FungibleToken.cdc
Outdated
from.getType().identifier.slice(from: 0, upTo: 18) == self.getType().identifier.slice(from: 0, upTo: 18): | ||
"Cannot deposit an incompatible token type" |
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 code does not match the comment, the code checks that the types are declared in the same account. Was that what you wanted to ensure?
If you really want to check that the type of the vault passes as an argument matches that of the vault that is accepting the deposit, you can just use self.isInstance
and from.getType()
:
from.getType().identifier.slice(from: 0, upTo: 18) == self.getType().identifier.slice(from: 0, upTo: 18): | |
"Cannot deposit an incompatible token type" | |
from.isInstance(self.getType()): | |
"Cannot deposit an incompatible token type" |
I've added a test case for this in onflow/cadence#779, see onflow/cadence@4f93166
It is als possible to just compare the types: from.getType() == self.getType()
:
from.getType().identifier.slice(from: 0, upTo: 18) == self.getType().identifier.slice(from: 0, upTo: 18): | |
"Cannot deposit an incompatible token type" | |
from.getType() == self.getType(): | |
"Cannot deposit an incompatible token type" |
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.
oh yeah that makes a lot more sense! I'll change it to that. Thanks for the 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.
Fixed in c84d060
@joshuahannan Updated the comment above |
@turbolent Does it look ok now? |
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!
What is the plan for releasing this? This change might break existing contracts, though to be fair, it should be rare and likely already a bug (forgetting to cast, accepting something else)
I'd like to upgrade it soon. I don't think it'll break any existing contracts because they should have already been doing the force cast anyway. But we might need to have a conversation with some other stakeholders to make sure this is ok. @robmyers @dete Are you ok with this change to the interface? |
Yup! Seems like a correct addition to me. |
does this not break forwarders? |
@bluesign yes, I think you're correct, though I am surprised that the tests didn't pick this up. The pre-condition should be in the |
@joshuahannan actually you have the correct implementation it seems. I had a total different imagination about forwarders, I was thinking they were implementing Vaults. Also somehow I had wrong understanding about pre/post treat model, I was thinking it is against hostile contract vs hostile user. |
yeah you're right. I thought I had put it in the receiver interface, but I had actually put it in the Vault definition, so we're all good. |
This is a nice use of modern Cadence rtti. 👍 |
No description provided.