-
Notifications
You must be signed in to change notification settings - Fork 138
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
Multiple contracts per account #221
Comments
It seems to me like |
Also, should we add an |
I think that for the first version, we should just model I'm not sure I understand the question about imports. I always think of the import statements more like defining a set of aliases, rather than building some kind of lasting connection. In other words, I think of the first block below as shorthand for the second block (even though I don't think the second block should be legal syntax).
Under this mindset, imports in one contract don't impact imports on another contract. They are completely separate (but, of course, welcome to import the same Contract definitions.) |
I think most of the updates can be done without a When updating contract interfaces we might need a To update resources, I imagine the owner would need to sign, so it won't be possible to update all resources at once. In this case, instead of a global migrate(oldResource, newResource) {
newResource.foobar = oldResource.foo + oldResource.bar + 10
} where the developer could copy some attributes from the old resource if needed. The function will swap the 2 resources automatically and check their types. |
We had a working session for this and discussed the API and behaviour more.
|
Further refined the API and updated the description |
There's a problem with the current API: There are The Once Ideas/Options:
|
I'm surprised that the checker can't run without knowing the deployment address. I would assume that everything that the deployment address would impact would be a dynamic check (like accessing storage), not a static check. Is it because there is some sugar for importing other contracts from "the same account"? I personally think that getting rid of the undeployed contract type is totally fine. |
I'm with Dete, I think getting rid of the undeployed type is fine. 🙆♂️ |
The checker requires a location because all types are qualified with it. That way there is no possibility for a type confusion. So checking the code first with a temporary a location creates types that are not the same as the types that will be declared at the account the contract will be deployed. Given we're all OK with just having the deployed contract type, I'll update the API. Thank you all for the giving feedback so quickly, this unblocks me 👍 |
What do we want the behaviour be for scenarios like: removing a contract, but continuing to use it (the contract singleton); removing and then adding another contract with the same name. For the update function we know about the issues and call it Should we maybe forbid the use of the contract singleton after it was removed? (dynamic check) |
So you're saying we could have a flag that basically says that if some code in a transaction tries to access a contract that has been removed, it fails, even if a new contract with the same name and functionality have been deployed? Or only if it was removed? It seems like we should still allow it if it is the same contract. Might be easier to just disallow though. Doesn't really matter to me. |
Given that remove + add is just as problematic as remove, because the add could have totally different code and would be a different object (! – or we would need to replace the contract singleton variable with the newly instantiated contract object), I'd say be conservative and disallow it in both cases. |
Yeah disallowing it sounds fine with me. Good to be safe |
Context
Currently account code may only declare up to one contract, and multiple contract interfaces.
There is one function,
fun AuthAccount.setCode(_ code: [UInt8], ... initializerArguments)
, which updates the account's code,and (if any) instantiates the contract and stores it in the world state.
The function is used both for initial contract deployment and for contract updates.
For the latter use case, this means that the existing contract instance is overwritten / lost.
Update this API to add support for adding, updating, and removing multiple contracts and contract interfaces, independently.
Proposal
Add new types:
Contract
:A contract that can be deployed to an account.
The initializer checks the code and aborts if:
DeployedContract
:A contract that is deployed at a given account.
AuthAccountContracts
:The deployed contracts of an authorized account.
Allows introspection, and also addition and removal.
fun add(contract: Contract, ... initializerArguments): DeployedContract
The initializer arguments are passed to the initializer of the contract (if any)
fun update__experimental(contract: Contract): DeployedContract
fun get(name: String): DeployedContract?
fun delete(name: String): DeployedContract?
Add the following member to
AuthAccount
:let contracts: AuthAccountContracts
Add special function
migrate
to composites, the migration function, which is called automatically as part ofAuthAccount.contracts.update
:it is not passed any version information
migrate
is a special function, likeinit
anddestroy
;A user declaration
fun migrate()
won't be allowed.This prevents unintentionally implementing a migration function
migrate
behaves similar toinit
Future Possibilities
[UInt8]
, could be replaced with a dedicatedCode
type,e.g. to support other encodings
Code
could be added. This would allow use of the contract after it is added/updated (the static analysis needs to have access to the type declarations in the passed code).Open Questions
migrate
?Definition of Done
The text was updated successfully, but these errors were encountered: