Skip to content

Commit

Permalink
fix: devex improvements (#260)
Browse files Browse the repository at this point in the history
* fix: new file permissions on generation

* Command not found error

* VSCode install, brew, wsl -d for distribution

* better examples and understanding for the nameservice based on feedback

* fix: use orm by default with tools.go
  • Loading branch information
Reecepbcups authored Oct 30, 2024
1 parent afe5b12 commit 32c85e6
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 49 deletions.
3 changes: 2 additions & 1 deletion cmd/spawn/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ func AddModuleToAppGo(logger *slog.Logger, extName string, feats *features) erro
logger.Debug("initParamsKeeper register", "extName", extName, "start", start, "end", end)
appGoLines = append(appGoLines[:end-3], append([]string{fmt.Sprintf(` paramsKeeper.Subspace(%stypes.ModuleName)`, extName)}, appGoLines[end-3:]...)...)

return os.WriteFile(appGoPath, []byte(strings.Join(appGoLines, "\n")), 0644)
// 777 is used as some users have weird setup / group environments w/ MacOS. 766 is more ideal but .sh files need to be executed.
return os.WriteFile(appGoPath, []byte(strings.Join(appGoLines, "\n")), 0777)
}

// appendNewImportsToSource appends new imports to the source file at the end of the import block (before the closing `)` ).
Expand Down
50 changes: 30 additions & 20 deletions docs/versioned_docs/version-v0.50.x/01-setup/01-system-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,30 @@ If you do not have these components installed, follow the instructions below to

## Install Dependencies

Install [VSCode](https://code.visualstudio.com/download) if you do not already have a file editor. Once installed, the following extensions are useful
- [Golang Syntax Highlighting](https://marketplace.visualstudio.com/items?itemName=golang.Go)
- [Protobuf 3 Highlighting](https://marketplace.visualstudio.com/items?itemName=zxh404.vscode-proto3)
- [Improved Errors](https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens)

<Tabs defaultValue="macos">
<TabItem value="macos" label="MacOS">

```bash
# Base
brew install make
brew install gcc
brew install wget
brew install jq
# Setup Homebrew (https://brew.sh/)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
sudo echo 'export PATH=$PATH:/opt/homebrew/bin' >> ~/.zshrc

# Github CLI - https://github.com/cli/cli
brew install gh
gh auth login
# Base
brew install make wget jq gh gcc go

# Golang
brew install go
# (optional) Github CLI login
# gh auth login

# Docker
brew install --cask docker
open -a Docker # start docker desktop

# Start docker desktop
open -a Docker
# settings -> General -> Start Docker Desktop when you sign in to your computer
# Apply & Restart

Expand All @@ -55,32 +60,33 @@ If you do not have these components installed, follow the instructions below to
</TabItem>

<TabItem value="windows" label="Windows (WSL)" default>

```bash
# Install WSL in powershell
wsl --install
Restart-Computer
# Setup WSL Ubuntu Image
wsl.exe --install Ubuntu-24.04
wsl.exe --install -d Ubuntu-24.04
# Open wsl instance
wsl
# update and add snap if not already installed
sudo apt update && sudo apt install snapd
# Install Go (Snap)
sudo snap install go --channel=1.23/stable --classic
# Install Go (https://go.dev/wiki/Ubuntu)
sudo apt update
sudo apt install golang -y
# Install Base
sudo apt install make gcc git jq wget
sudo apt install make gcc git jq wget -y
# Install github-cli
sudo snap install gh
# Optional: Install github-cli
# sudo snap install gh
# Install docker
https://docs.docker.com/desktop/wsl/#turn-on-docker-desktop-wsl-2
# or snap:
# If you can't use snap, setup from:
# - https://docs.docker.com/desktop/wsl/#turn-on-docker-desktop-wsl-2
sudo snap install docker
# Fix versioning for interaction of commands
Expand All @@ -90,9 +96,13 @@ If you do not have these components installed, follow the instructions below to
git config --global user.email "yourEmail@gmail.com"
git config --global user.name "Your Name"
```

After installing VSCode and having your system setup, open a terminal and run `code` to open vscode. You can open the current directory with `code .`, where `.` in computer terms stands for the current directory.

</TabItem>

<TabItem value="ubuntu-linux" label="Linux (Ubuntu)">

<!-- markdown-link-check-disable -->
```bash
# Base
Expand Down
40 changes: 26 additions & 14 deletions docs/versioned_docs/version-v0.50.x/01-setup/02-install-spawn.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,33 @@ spawn
local-ic

heighliner
```

# If you get "command 'spawn' not found", run the following
# Linux / Windows / Some MacOS
echo 'export PATH=$PATH:$(go env GOPATH)/bin' >> ~/.bashrc
source ~/.bashrc

# MacOS
echo 'export PATH=$PATH:$(go env GOPATH)/bin' >> ~/.zshrc
source ~/.zshrc
## Command not found error

# Legacy MacOS Go
echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.zshrc
source ~/.zshrc
If you get "command 'spawn' not found", run:

# Sometimes it can be good to also clear your cache
# especially WSL users
go clean -cache
```bash
# Gets your operating system
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
MSYS_NT*) machine=MSys;;
*) machine="UNKNOWN:${unameOut}"
esac
echo "Your operating system is: $machine"
echo -e "\nAdding the go binary location to your PATH for global access.\n\tIt will now prompt you for your password."

# Adds the location of the binaries to your PATH for global execution.
cmd='export PATH=$PATH:$(go env GOPATH)/bin'
if [ $machine == "Linux" ]; then
sudo echo "$cmd" >> ~/.bashrc && source ~/.bashrc
elif [ $machine == "Mac" ]; then
sudo echo "$cmd" >> ~/.zshrc && source ~/.zshrc
else
echo 'Please add the following to your PATH: $(go env GOPATH)/bin'
fi
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ Building your first Cosmos-SDK blockchain with Spawn. This tutorial focuses on a
* Interacting with the network
:::

## How a Name Service works

Imagine you have a set of labeled containers, each with a unique name like "Essentials" "Electronics" and "Books". The label on each container is called the key, and what’s stored inside is the value. For example, the key "Books" leads you to a container full of books, while "Essentials" might have things like toiletries or basic supplies.

In a nameservice, this key-value system lets you quickly find or access specific data by referencing a unique name, or key, which reliably points you to the related value. This is useful for mapping names to specific information or resources, so with just the name, you can always find exactly what you're looking for.

For this tutorial we map a human readable name (like `"alice"`) to a complex wallet address (like `roll1efd63aw40lxf3n4mhf7dzhjkr453axur57cawh`) so it is easier to understand and view as a user.

## Prerequisites
- [System Setup](../01-setup/01-system-setup.md)
- [Install Spawn](../01-setup/02-install-spawn.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ slug: /build/name-service-application

# Save Storage Structure

You now need to set the data structure in the keeper to store the wallet to name pair. Keeper's are where the data is stored for future use.
You now need to set the data structure in the keeper to store the wallet to name pair. Keepers are where the data is stored for future use and handle the business logic.
Think of it like a box where you store your data and the methods used to modify this data. It is self contained and only gets further access if you allow the keeper to do so (shown in [part 2](../02-build-your-application/08-ibc-module.md)).

```go title="x/nameservice/keeper/keeper.go"

Expand All @@ -34,8 +35,6 @@ func NewKeeper() Keeper {
}
```

![keeper NewKeeper NameMapping](https://github.com/rollchains/spawn/assets/31943163/47ed4a41-4df2-4a5d-9ac5-bfb23aeefd94)

---

## Application Logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ The chain will begin to create (mint) new blocks. You can see the logs of the ne

### Interact Set Name

Using the newly built binary *(rolld from the --bin flag when the chain was created)*, you are going to execute the `set` transaction to your name. In this example, use "alice". This links account `acc1` address to the desired name in the keeper.
Using the newly built binary executable *(rolld from the --bin flag when the chain was created)*, you are going to execute the `set` action to your name. In this example, use "alice". This links account `acc1` address to the desired name in the keeper.

Then, resolve this name with the nameservice lookup. `$(rolld keys show acc1 -a)` is a substitute for the acc1's address. You can also use just `roll1hj5fveer5cjtn4wd6wstzugjfdxzl0xpg2te87` here.
You can either query or set data in the network using the command executable. If you wish to perform an action you submit a transaction (tx). If you wish to read data you are querying (q). The next sub command specifies which module will receive the action on. In this case, the `nameservice` module since our module is named nameservice. Then the `set` command is called, which was defined in the autocli.go.

```bash
rolld tx nameservice set alice --from=acc1 --yes
Expand Down
8 changes: 8 additions & 0 deletions simapp/app/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Description: This file is used to import all the packages that are used in the application, but may not be required currently.
// This is done to avoid the unused import errors when building modules. Leave this file unchanged.

package app

import (
_ "cosmossdk.io/orm"
)
2 changes: 1 addition & 1 deletion spawn/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func debugErrorFile(logger *slog.Logger, newDirname string) string {
}

fullPath := path.Join(debugDir, fname)
if err := os.WriteFile(fullPath, []byte(errFileText), 0644); err != nil {
if err := os.WriteFile(fullPath, []byte(errFileText), 0766); err != nil {
logger.Error("Error saving debug file", "err", err)
}

Expand Down
5 changes: 3 additions & 2 deletions spawn/file_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ func (fc *FileContent) Save() error {
return nil
}

if err := os.MkdirAll(path.Dir(fc.NewPath), 0755); err != nil {
// 777 is used as some users have weird setup / group environments w/ MacOS. 766 is more ideal but .sh files need to be executed.
if err := os.MkdirAll(path.Dir(fc.NewPath), 0777); err != nil {
return err
}

return os.WriteFile(fc.NewPath, []byte(fc.Contents), 0644)
return os.WriteFile(fc.NewPath, []byte(fc.Contents), 0777)
}
2 changes: 1 addition & 1 deletion spawn/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ func (mf MetadataFile) SaveJSON(loc string) error {
return err
}

return os.WriteFile(loc, bz, 0644)
return os.WriteFile(loc, bz, 0666)
}
2 changes: 1 addition & 1 deletion spawn/proto_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func ApplyMissingRPCMethodsToGoSourceFiles(logger *slog.Logger, missingRPCMethod
// append to the file content after a new line at the end
content = append(content, []byte("\n"+code)...)

if err := os.WriteFile(fileLoc, content, 0644); err != nil {
if err := os.WriteFile(fileLoc, content, 0666); err != nil {
logger.Error("error", "err", err)
return err
}
Expand Down
2 changes: 1 addition & 1 deletion spawn/types/chain_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ func (v ChainRegistryFormat) SaveJSON(loc string) error {
return err
}

return os.WriteFile(loc, bz, 0644)
return os.WriteFile(loc, bz, 0666)
}
2 changes: 1 addition & 1 deletion spawn/types/chain_registry_assets_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ func (v ChainRegistryAssetsList) SaveJSON(loc string) error {
return err
}

return os.WriteFile(loc, bz, 0644)
return os.WriteFile(loc, bz, 0666)
}
4 changes: 2 additions & 2 deletions spawn/version_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func DoOutdatedNotificationRunCheck(logger *slog.Logger) bool {
}

func WriteLastTimeToFile(logger *slog.Logger, lastCheckFile string, t time.Time) error {
return os.WriteFile(lastCheckFile, []byte(t.Format(time.RFC3339)), 0644)
return os.WriteFile(lastCheckFile, []byte(t.Format(time.RFC3339)), 0666)
}

// GetLatestVersionCheckFile grabs the check file used to determine when to run the version check.
Expand All @@ -236,7 +236,7 @@ func GetLatestVersionCheckFile(logger *slog.Logger) (string, error) {
}

epoch := time.Unix(0, 0)
if err := os.WriteFile(lastCheckFile, []byte(epoch.Format(time.RFC3339)), 0644); err != nil {
if err := os.WriteFile(lastCheckFile, []byte(epoch.Format(time.RFC3339)), 0666); err != nil {
logger.Error("Error writing last check file", "err", err)
return "", err
}
Expand Down

0 comments on commit 32c85e6

Please sign in to comment.