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: raw and process snapshot commands #6

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f4163e5
add project structure
Pantani Dec 20, 2022
d9fbd3f
Merge remote-tracking branch 'origin/main' into feat/read-state
Pantani Dec 20, 2022
90ee563
add config tests
Pantani Dec 20, 2022
a3d26e0
add gofmt
Pantani Dec 20, 2022
96088b6
add unit tests for snapshot package
Pantani Dec 20, 2022
e4af165
add unit tests
Pantani Dec 21, 2022
4ab089e
improve command decription
Pantani Dec 21, 2022
b558b7e
remove local CLI project
Pantani Dec 21, 2022
a9b4fbf
update go.sum
Pantani Dec 21, 2022
b3b7bdf
fix lint
Pantani Dec 21, 2022
0dc61c6
update genesis testdata
Pantani Dec 21, 2022
7049bbc
fix ci coverage
Pantani Dec 21, 2022
266c26c
create snapshot filter methods
Pantani Dec 21, 2022
01bd413
add formula package
Pantani Dec 22, 2022
5c39b8f
add calculate rules
Pantani Dec 22, 2022
64d521c
add fixme for the calculation
Pantani Dec 22, 2022
ff34d98
add process commands
Pantani Dec 22, 2022
8179886
fix unit tests
Pantani Dec 22, 2022
4767728
fix panic
Pantani Dec 22, 2022
407a226
move debug to cmd
Pantani Dec 22, 2022
b6fbc2c
remove unused encoding parameters
Pantani Dec 22, 2022
18b69c2
run `make format`
Pantani Dec 22, 2022
bf95ca9
fix formula calculation
Pantani Dec 22, 2022
5241e27
add unit tests and fix filter
Pantani Dec 22, 2022
67be669
fix unit tests
Pantani Dec 22, 2022
c2b99f5
fix config typo
Pantani Dec 22, 2022
717a2e6
simplify filter struct
Pantani Dec 22, 2022
e52353c
add claim records to gen state
Pantani Dec 22, 2022
11f6305
- remove liquidy module
Pantani Dec 26, 2022
832f1ba
Merge remote-tracking branch 'origin/main' into feat/read-state
Pantani Jan 9, 2023
b66bf74
fetch balances
Pantani Jan 10, 2023
504e7e3
add output genesis arg
Pantani Jan 10, 2023
9901de7
rename filter to record
Pantani Jan 10, 2023
3cd32e1
fix test name
Pantani Jan 10, 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
13 changes: 0 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ jobs:
run: |
go test -v -coverprofile=coverage.txt -covermode=atomic -coverpkg=./... $(go list ./...)

- name: filter non-testable files
run: |
excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER')"
excludelist+=" $(find ./ -type f -name '*.pb.go')"
excludelist+=" $(find ./ -type f -name '*.pb.gw.go')"
excludelist+=" $(find ./cmd -type d)"
for filename in ${excludelist}; do
filename=${filename#".//"}
echo "Excluding ${filename} from coverage report..."
filename=$(echo "$filename" | sed 's/\//\\\//g')
sed -i.bak "/""$filename""/d" coverage.txt
done

- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cli-plugin-airdrop
.idea
.DS_STORE
.DS_STORE
coverage.txt
coverage.out
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ FIND_ARGS := -name '*.go' -type f -not -name '*.pb.go' -not -name '*.pb.gw.go'
## format: Run gofmt and goimports.
format:
@echo Formatting...
@go install mvdan.cc/gofumpt
@go install golang.org/x/tools/cmd/goimports
@find . $(FIND_ARGS) | xargs gofumpt -w .
@find . $(FIND_ARGS) | xargs goimports -w -local github.com/ignite/cli-plugin-airdrop

## lint: Run Golang CI Lint.
lint:
@echo Running gocilint...
@go install github.com/golangci/golangci-lint/cmd/golangci-lint
@golangci-lint run --out-format=tab --issues-exit-code=0

help: Makefile
Expand Down
139 changes: 137 additions & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,152 @@
package cmd

import (
"encoding/json"
"fmt"

"github.com/spf13/cobra"

"github.com/ignite/cli-plugin-airdrop/pkg/config"
"github.com/ignite/cli-plugin-airdrop/pkg/genesis"
"github.com/ignite/cli-plugin-airdrop/pkg/snapshot"
)

func NewAirdrop() *cobra.Command {
return &cobra.Command{
c := &cobra.Command{
Use: "airdrop",
Short: "Utility tool to create snapshots for an airdrop",
}

c.AddCommand(
NewAirdropGenerate(),
NewAirdropRaw(),
NewAirdropProcess(),
NewAirdropGenesis(),
)

return c
}

func NewAirdropGenerate() *cobra.Command {
return &cobra.Command{
Use: "generate [airdrop-config] [input-genesis]",
Short: "Utility tool to create snapshots for an airdrop",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
var (
airdropConfig = args[0]
inputGenesis = args[1]
)

c, err := config.ParseConfig(airdropConfig)
if err != nil {
return err
}

genState, err := genesis.GetGenStateFromPath(inputGenesis)
if err != nil {
return err
}

s, err := snapshot.Generate(genState)
if err != nil {
return err
}

filters := make(snapshot.Filters, 0)
Pantani marked this conversation as resolved.
Show resolved Hide resolved
for _, snap := range c.Snapshots {
filter := s.Filter(snapshot.FilterType(snap.Type), snap.Denom, snap.Formula, snap.Excluded)
filters = append(filters, filter)
}
filter := filters.Sum()

// export snapshot json
filterJSON, err := json.MarshalIndent(filter, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal snapshot: %w", err)
}

cmd.Println(string(filterJSON))
// TODO generate the genesis
return nil
},
}
}

func NewAirdropRaw() *cobra.Command {
return &cobra.Command{
Use: "raw [input-genesis]",
Short: "Generate raw airdrop data based on the input genesis",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the input genesis for the raw command? Is it the genesis that has been exported from the chain to parse snapshot from? It's a bit unclear since we should also have the "input genesis" where we populate the claim genesis state from the snapshot data

This may be implemented but I think we should let the use the ability to provide a RPC address for the chain, where the genesis would be automatically exported

Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
genState, err := genesis.GetGenStateFromPath(args[0])
if err != nil {
return err
}

s, err := snapshot.Generate(genState)
if err != nil {
return err
}

// export snapshot json
snapshotJSON, err := json.MarshalIndent(s, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal snapshot: %w", err)
}

cmd.Println(string(snapshotJSON))
return nil
},
}
}

func NewAirdropProcess() *cobra.Command {
return &cobra.Command{
Use: "process [airdrop-config] [raw-snapshot]",
Short: "Process the airdrop data based on the config file",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
var (
airdropConfig = args[0]
rawSnapshot = args[1]
)

c, err := config.ParseConfig(airdropConfig)
if err != nil {
return err
}

s, err := snapshot.ParseSnapshot(rawSnapshot)
if err != nil {
return err
}

filters := make(snapshot.Filters, 0)
for _, snap := range c.Snapshots {
filter := s.Filter(snapshot.FilterType(snap.Type), snap.Denom, snap.Formula, snap.Excluded)
filters = append(filters, filter)
}
filter := filters.Sum()

// export filter json
filterJSON, err := json.MarshalIndent(filter, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal snapshot: %w", err)
}

cmd.Println(string(filterJSON))
return nil
},
}
}

func NewAirdropGenesis() *cobra.Command {
return &cobra.Command{
Use: "genesis [airdrop-config] [raw-snapshot] [input-genesis]",
Short: "Generate a genesis based on processed files and airdrop config",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("Hello from airdrop command")
return nil
},
}
Expand Down
23 changes: 23 additions & 0 deletions cmd/debug/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/ignite/cli-plugin-airdrop/cmd"
)

var rootCmd = &cobra.Command{
Use: "cli-plugin-airdrop",
Short: "debug command for CLI airdrop plugin",
}

func main() {
rootCmd.AddCommand(cmd.NewAirdrop())
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Pantani marked this conversation as resolved.
Show resolved Hide resolved
Loading