Comments (11)
I was working on the Kitty Items repo today and ran into two problems that made me think of this issue.
I updated all the Cadence files to import contracts by filename rather than address, so the files no longer specify placeholders like 0xFUNGIBLETOKEN
.
-
After making that change, I wanted a way to use these same files in the Go tests. However, I could no longer do the simple
replace(0xFUNGIBLETOKEN, ...)
approach. It'd be great if the CLI were to resolve all of the contract filenames and use the new address replacement logic that's now in the CLI to generate a version of the contracts, transactions and scripts rewritten with emulator addresses. It would then be fairly trivial to then automatically generate Go bindings that could be used in the tests. -
Similarly, I used a hacky solution to replace the contract filenames in the
kitty-items-js
project. If we had something like a manifest file (generated by the CLI), it'd be much easier to just parse that JSON file in the JS app and load all of the address mappings.
@MaxStalker I think your generator code also solves problem 2 above. Is that right?
Seeing as we have partial solutions to these problems in both Go and JS, I wonder if we can create a generalized solution that can easily be replicated in other languages.
Here's a rough example of what I'm thinking 👇
// transferKibble.cdc
import Kibble from "../contracts/Kibble.cdc"
...
// kittyItems.manifest.json
{
"contracts": {
"Kibble": {
"testnet": "0xabcdef"
}
},
"transactions": {
"transferKibble": {
"arguments": [
{"name": "recipient", "type": "Address"},
{"name": "amount", "type": "UFix64"}
],
"code": "import Kibble from {Kibble} ... ",
}
},
"scripts": {
// ...
}
}
from flow-cli.
This sounds pretty great!
I left some comments on onflow/kitty-items#32 about this too, but I don't think this adequately solves some issues. In order to do it this way, you still have to copy and paste contracts and contract interfaces to your repos to import them, whereas we should have some way of importing them from another repo.
Same with providing an easy to use package for anyone to import the transaction templates from their app in any language. It looks like that's what you're talking about above though, so that is good. 👍
from flow-cli.
@MaxStalker yes. Ser the example I posted above.
from flow-cli.
I think we need to invite @turbolent as well, since that address
would also affect language server ability to resolve it to actual contract.
Also, feels a bit like we are re-inventing ABIs with this approach 😅
from flow-cli.
I agree, and I think the manifest idea is great. The contracts field can reflect contract addresses on each network.
Transactions and scripts are not "deployable" so we need to do address replacement and save them somewhere. Saving to manifest is one option the other is to have some kind of build folder.
I think the build folder is worth considering since it feels familiar to developers (think webpack, tsc etc.) and it offers a nice separation of files the same way we had them in the source file. Of course, the build folder doesn't allow any other metadata for which manifest is the correct solution if there is a need for such a thing. Another benefit of the build folder is there is no parsing and logic to implement manifest file (which would potentially be implemented in many places for many programming languages - probably would need to be included in the library).
In either case, I think an important aspect is also to think of changes and how are those reflected in any solution. Redeployment of contracts should of course change the state but also change of scripts and transaction files should. I think we could later add some kind of watch
feature. Before that developer should probably rerun the command.
Workflow with this functionality:
- When a developer deploys contracts, state should be updated with new addresses. When they run
flow project deploy
all this should happen automatically. - When a developer changes script or transaction files there should be a command they need to run. Maybe some kind of
build
command (but in manifest case not build since it implies there is a build folder) or maybeupdate
.
I think in any case there shouldn't be any manual work with the state since the state would be generated with CLI. By that I mean a developer shouldn't change anything in manifest or build files and should just have a CLI to generate that. That is because I don't think it is a good idea to have some things generated and some things manually inserted (problems with overwriting etc).
I think another thing to keep in mind is that our solution should work with task automation tools (grunt, gulp etc). This could even remove the need for us to implement a watch
feature. Maybe this is even more appropriate.
@psiemens I wondering why you specify this in an example:
"arguments": [
{"name": "recipient", "type": "Address"},
{"name": "amount", "type": "UFix64"}
],
from flow-cli.
I think there are two separate issues (both important):
- Once you deploy your contracts using the awesome new feature
flow project deploy
how do you execute your custom scripts/transactions without having to copy-paste previously deployed contract addresses in script/transactions imports (what this issue mostly targets) - You shouldn't have to copy-paste standard (or any other) contracts from github just for the deployment to work. I think this should be solved but I also think it can be solved separately since it opens more problems (vscode language processor should know how to parse remote imported contracts etc...). I will open an issue for this since I believe it is a major pain point when developing. @joshuahannan find more here: #71
from flow-cli.
Sending adresses as arguments to scripts contracts would also be nice to think about here. Could there be an cadence.Address method that does this lookup for you?
from flow-cli.
Sending adresses as arguments to scripts contracts would also be nice to think about here. Could there be an cadence.Address method that does this lookup for you?
Can you please give some examples of usage so I better understand?
from flow-cli.
https://github.com/versus-flow/auction-flow-contract/blob/master/examples/demo/main.go#L70
Transaction is signed as the marketplace account and the address of the artist is sent in as an argument.
from flow-cli.
@bjartek you mean you want to pass address as one of the arguments in the script? 🤔
from flow-cli.
https://github.com/versus-flow/auction-flow-contract/blob/master/examples/demo/main.go#L70
Transaction is signed as the marketplace account and the address of the artist is sent in as an argument.
I like your implementation, it reads really well. And yes ok I understand what you mean. Passing parameters to scripts is actually something @MaxStalker was working on.
from flow-cli.
Related Issues (20)
- Add config only flag to init to just generate flow.json
- Incomplete contracts deployed printed at emulator startup
- previewnet chain not known to dependency manager HOT 1
- [BUG] Fix dependencies/contracts conflict check
- Gracefully recovery from C1.0 contract update validation panics
- Import address feature for dependency manager HOT 2
- Staged contracts flag for dependency manager
- Cannot start EVM gateway
- `flow-c1 migrate state` no longer reports errors HOT 4
- Version check doesn't work
- Flow CLI cannot use struct encoding
- Flow CLI cannot use Dictionary encoding
- Dependency Manager: Extract core logic to flowkit package
- Dev super command: Extract core logic to flowkit package HOT 1
- "Commit" broken in `flow version`
- flow init should add previewnet to flow.json and create a .gitignore HOT 2
- Counter path on init is incorrect
- "flow accounts create", flags is not working HOT 3
- Master branch now uses `flow-c1` in install-scripts HOT 4
- flow-c1 init doesn't work with flow-go's local net HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flow-cli.