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

feat: cosmwasm plugin #2

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a17bada
Initialized with Ignite CLI
Aug 31, 2023
d30208b
started working on cosmwasm-plugin
Aug 31, 2023
0cd1607
added cosmwasm plugin for Ignite CLI
Aug 31, 2023
084e0f9
Written clearer instructions in README.md
Aug 31, 2023
9ae9622
using go's embed package to embed the template files in the plugin bi…
Sep 5, 2023
38af11e
removed 2 global variables, assigned chainName to the plugin instance…
Sep 8, 2023
b8ea91e
createFile calls made in a loop
Sep 8, 2023
a6c6f04
getChain() function removed for beeing obsolete
Sep 8, 2023
245a81d
added limitations in README.md
Sep 8, 2023
c46f39c
renaming plugin from cosmwasm-plugin -> cosmwasm
Sep 8, 2023
1332f8c
Hooks were removed from Manifest for beeing obsolete
Sep 8, 2023
3c10ada
removed some print statements
Sep 8, 2023
79f099d
removed long description and flags, added short description for cosmw…
Sep 8, 2023
f5cc05c
ExecuteHook functions refactored
Sep 8, 2023
65c25ba
added cosmwasm to gitignore
Sep 8, 2023
eecaa9b
added cosmwasm to gitignore
Sep 8, 2023
548b8fc
removed ioutil (deprecated dependancy)
Sep 15, 2023
440595f
set module name to github.com/ignite/plugins/cosmwasm , fix in README
Sep 15, 2023
27f2900
refactoring on chainName
Sep 15, 2023
be60f6c
removing function modifyExistingFiles(), not used
Sep 15, 2023
c84515a
changed print statements, when files are created to the user, new ver…
Sep 15, 2023
fc9fc29
function handleAddCommand() was reformated to method of plugin
Sep 15, 2023
a523a30
Applying .plush templates and genny for file generations
Sep 25, 2023
4a726bc
adding placeholders in app.go.plush to inject the WASM code
Sep 25, 2023
14efb7f
Merge branch 'ignite:main' into feat/cosmwasm-plugin
yerasyla Sep 25, 2023
d18c431
Merge branch 'feat/cosmwasm-plugin' of https://github.com/yerasyla/pl…
Sep 25, 2023
e9ba7b4
pull from main
Oct 9, 2023
78c053b
Implemented code injection with ASTs for first 5 placeholders
Oct 30, 2023
6c23e46
applied code injectin to app.go (with app6-10 plush files) using ASTs
Nov 1, 2023
e01e073
applied code injectin to app.go (with app11-14 plush files) using ASTs
Nov 3, 2023
f4a1fd5
applied code injectin to app.go (with app15.plush file) using ASTs
Nov 3, 2023
5099608
applied code injectin to app.go (with app16-18 plush file and deletin…
Nov 3, 2023
fef62f2
applied code injectin to app.go (with app19.plush file) using ASTs
Nov 3, 2023
6c8b433
applied code injectin to app.go (with app21-22 plush files) using ASTs
Nov 6, 2023
1dccb58
applied code injection to app.go (with app23.plush file) using ASTs
Nov 6, 2023
b0788d2
initial refactoring after injecting 23 plush files
Nov 6, 2023
ca7391e
bug fix, modified code injection in 3 locations
Nov 7, 2023
8b902fa
post merge commit
Nov 7, 2023
12ab470
Merge branch 'ignite:main' into feat/cosmwasm-plugin
yerasyla Nov 7, 2023
16fdb7f
update go workspace
Nov 8, 2023
d63692e
Merge branch 'ignite:main' into feat/cosmwasm-plugin
yerasyla Nov 14, 2023
1a6076a
fixing bug with importing dependancies
Nov 14, 2023
4fb0806
upgrading to wasmd v0.44.0, code refactoring
Nov 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cosmwasm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cosmwasm-plugin
cosmwasm
142 changes: 142 additions & 0 deletions cosmwasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# CosmWasm Plugin for Ignite CLI

**This repo contains** an Ignite CLI plugin that can help you to add CosmWasm module support for newly scaffolded app.

**Limitations:** the plugin works only for apps that were newly scaffolded with Ignite, custom changes and new modules should be added after cosmwasm module is integrated.

## Get started
First scaffold a chain with [Ignite CLI](https://docs.ignite.com).

1. Install Ignite CLI:
```
$ curl https://get.ignite.com/cli! | bash
```
2. Scaffold a chain
```
$ ignite scaffold chain planet
$ cd planet
```

3. Clone this repo locally

4. Add cosmwasm plugin within your project directory:
```
ignite plugin add github.com/ignite/plugins/cosmwasm
```

or globally

```
ignite plugin add -g github.com/ignite/plugins/cosmwasm
```

5. Run command
```
$ ignite cosmwasm add
```

6. Launch your chain with CosmWasm support

```
$ ignite chain serve
```
`serve` command installs dependencies, builds, initializes, and starts your blockchain in development.


## Testing Smart-Contracts

Testing CosmWasm smart-contract capabilities in your chain, can be performed by following these steps:

0. Prerequisites: install [rust](https://www.rust-lang.org/tools/install) and [docker](https://www.docker.com/) (for smart-contact optimization)

1. Launch chain locally:
```
$ ignite chain serve
```

2. Prepare cosmwasm smart-contract for deployment
```
$ git clone https://github.com/CosmWasm/cw-examples
$ cd cw-examples
$ cd contracts/nameservice
$ RUSTFLAGS='-C link-arg=-s' cargo wasm
```

Optimize contract to reduce gas
```
$ docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.12.12
```

For ARM64 machines:
```
$ docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer-arm64:0.12.12
```

3. Deploy smart-contract to your chain
```
$ planetd tx wasm store artifacts/cw_nameservice.wasm --from alice --gas=10000000
```

4. Check your smart-contract on chain
```
$ planetd query wasm list-code
code_infos:
- code_id: "1"
creator: cosmos1a4w3vwxa8zhy57nyy9kw7zhdasr4ue4wld0zpn
data_hash: DF3C9BC1341322810523AABCA28CC3FCDCA021C85061743967CE3D20F5580093
pagination: {}

# download wasm and diff with origin
$ CODE_ID=$(planetd query wasm list-code --output json | jq -r '.code_infos[0].code_id')
$ planetd query wasm code $CODE_ID download.wasm
$ diff artifacts/cw_nameservice.wasm download.wasm
```

5. Instantiate smart-contract, in CosmWasm deployment and instantiation are 2 different steps

```
$ INIT='{"purchase_price":{"amount":"100","denom":"stake"},"transfer_price":{"amount":"999","denom":"stake"}}'
$ planetd tx wasm instantiate 1 "$INIT" --from alice --chain-id "planet" --label "awesome name service" --no-admin

$ CONTRACT=$(planetd query wasm list-contract-by-code $CODE_ID --output json | jq -r '.contracts[-1]')
# check contract state (you should get contract address)
$ planetd query wasm contract $CONTRACT
address: cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s0phg4d
contract_info:
code_id: "1"
creator: cosmos1a4w3vwxa8zhy57nyy9kw7zhdasr4ue4wld0zpn
label: awesome name service
```

6. Interact with smart-contract
```
# purchase name
$ planetd tx wasm execute $CONTRACT '{"register":{"name":"test"}}' --amount 100stake --from alice $TXFLAG -y

# query registered name (you should see your address as owner of the name)
$ NAME_QUERY='{"resolve_record": {"name": "test"}}'
$ planetd query wasm contract-state smart $CONTRACT "$NAME_QUERY" --output json
```

## Compatibility

| Ignite CLI | Cosmos SDK | IBC | wasmd |
|-------------|-------------|-----------|---------------------------------------------------------------|
| v0.27.1 | v0.47.4 | v7.2.0 | v0.41.0 |

## Learn more

- [Ignite CLI](https://ignite.com/cli)
- [Tutorials](https://docs.ignite.com/guide)
- [Ignite CLI docs](https://docs.ignite.com)
- [Cosmos SDK docs](https://docs.cosmos.network)
- [Developer Chat](https://discord.gg/ignite)
- [CosmWasm](https://cosmwasm.com/)
- [Wasm module](https://github.com/CosmWasm/wasmd)
- [CosmWasm Smart Contract Tutorial](https://medium.com/haderech-dev/smart-contract-tutorial-3-cosmwasm-805860c91a88)
81 changes: 81 additions & 0 deletions cosmwasm/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
module github.com/ignite/plugins/cosmwasm

go 1.21

require (
github.com/gobuffalo/genny/v2 v2.1.0
github.com/gobuffalo/plush/v4 v4.1.16
github.com/hashicorp/go-plugin v1.5.1
github.com/ignite/cli v0.27.1
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/charmbracelet/lipgloss v0.6.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-git/go-git/v5 v5.6.1 // indirect
github.com/gobuffalo/flect v0.3.0 // indirect
github.com/gobuffalo/github_flavored_markdown v1.1.3 // indirect
github.com/gobuffalo/helpers v0.6.7 // indirect
github.com/gobuffalo/logger v1.0.7 // indirect
github.com/gobuffalo/packd v1.0.2 // indirect
github.com/gobuffalo/tags/v3 v3.1.4 // indirect
github.com/gobuffalo/validate/v3 v3.3.3 // indirect
github.com/gofrs/uuid v4.3.0+incompatible // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/hashicorp/go-hclog v1.2.0 // indirect
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/matryer/is v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/microcosm-cc/bluemonday v1.0.23 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.1 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.1.1 // indirect
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.16.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.56.2 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading