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

Import and deploy contracts from remote sources #71

Closed
sideninja opened this issue Feb 22, 2021 · 5 comments
Closed

Import and deploy contracts from remote sources #71

sideninja opened this issue Feb 22, 2021 · 5 comments
Assignees
Labels
Feature A new user feature or a new package API Feedback

Comments

@sideninja
Copy link
Contributor

Issue To Be Solved

When deploying contracts we currently need to have a copy of that contract locally.

Suggest A Solution

Contract deployment functionality (project deploy) allows us to automatically resolve imports from contracts on the fly and replace them with addresses. These imports are currently relative file locations of the contract source code.

Besides having a relative file location we should allow importing from remote locations (URLs, github repos...). This files should be pulled on the fly and deployed. Another option is that this would first pull the file and save it locally and then deploy it.

This change should also be supported by the language server so it resolves the files.

@psiemens
Copy link
Contributor

I think that both example you listed could be implemented as separate loaders.

  • URL loader: download a Cadence source file from a URL.
  • Git loader: import a file from a git repository, versioned by branch, tag or commit.

The URL loader is far simpler than git and would still unblock us in the short term. We can even achieve simple versioning by just specifying the right GitHub URL (e.g. https://github.com/onflow/flow-ft/blob/v0.1.2/src/contracts/FlowToken.cdc).

@sideninja
Copy link
Contributor Author

I agree. Loaders are a perfect fit.

I think files should be loaded locally and then deployed, but if someone finds good reasons to not store them locally we can also avoid that and just deploy it without saving.

The other problem I see currently is with resolving imports in cadence files. Of course, a possible solution is to have an URL directly stated at import like import https://github.com/onflow/flow-ft/blob/v0.1.2/src/contracts/FlowToken.cdc but I don't really like this.
Another better solution would be to have a link included in the configuration as an alias:
Proposed new config:

"FungibleToken": {
  "source": "https://github.com/onflow/flow-ft/blob/v0.1.2/src/contracts/FlowToken.cdc",
  "aliases": {
    "emulator": "ee82856bf20e2aa6",
    "testnet": "9a0766d93b6608b7"
   }
}

But this solution then still leaves us with the problem of resolving imports in cadence files by the language processor. Another possible solution is to specify in config location for the contract after the download and the location of the remote file:

"FungibleToken": {
  "localSource": "cadence/kibble/contracts/FungibleToken.cdc",
  "remoteSource": "https://github.com/onflow/flow-ft/blob/v0.1.2/src/contracts/FlowToken.cdc",
  "aliases": {
    "emulator": "ee82856bf20e2aa6",
    "testnet": "9a0766d93b6608b7"
   }
}

The above configuration would instruct CLI when running deploy command to first load and save the contract locally (location specified under localSource) and after deploy it. This solution would involve contracts having imports that would work without changing language processing.
import cadence/kibble/contracts/FungibleToken.cdc

The last solution would also allow us to also add a new command similar to package manager install where you would add contract from a remote location in a separate step something like project add FlowToken (for standard contracts) or project add @onflow/Kibble for non-standard contracts, but this would be a separate feature.

Tagging @joshuahannan since I believe you are currently most burdened by this problem.

@bjartek
Copy link
Collaborator

bjartek commented Feb 23, 2021

This would be very nice so that you do not have to have the source code for all contracts locally at all times. Especially when there will be more standard flow contracts available.

What about pulling a contract down from testnet and deploying to emulator?

@sideninja
Copy link
Contributor Author

sideninja commented Feb 23, 2021

What about pulling a contract down from testnet and deploying to the emulator?

Good idea.
We were thinking you would have some kind of remote resource formats and one of which could also be contracts from the Flow blockchain. So instead of URLs you would probably specify @onflow/kibble (not an actual solution just raw example) so you could have some kind of @testnet/address format.

@sideninja sideninja self-assigned this Feb 23, 2021
@bjartek
Copy link
Collaborator

bjartek commented Feb 26, 2021

That would work really well @sideninja

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature A new user feature or a new package API Feedback
Projects
None yet
Development

No branches or pull requests

3 participants