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

[Utility] Local Proof of Stake CLI - CLI and RPC client [part 1/2] - Issue #112 #177

Merged
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
b0f2531
chore(P2P): discuss comment on redundant line
deblasis Aug 24, 2022
78c8d7d
feat(CLI): scaffolding
deblasis Aug 24, 2022
32e3072
feat(CLI): scaffolding
deblasis Aug 24, 2022
4f791f0
feat(CLI): scaffolding
deblasis Aug 24, 2022
ee1003a
feat(CLI): scaffolding
deblasis Aug 24, 2022
83ec894
typo(P2P): redundant line
deblasis Aug 24, 2022
d7c8f5d
fix(CLI): merge conflict fix
deblasis Aug 24, 2022
2bda3f3
chore(go.mod): tidy + vendor
deblasis Aug 29, 2022
bc6ad76
feat(Utility): CLI RPC client function
deblasis Aug 29, 2022
e60ea54
feat(Utility): RPC defaults const
deblasis Aug 29, 2022
ec76e05
feat(Utility): GetSignBytes
deblasis Aug 29, 2022
6ae396e
feat(Utility): CLI utils
deblasis Aug 29, 2022
b87b721
feat(Utility): stake cmd scaffolding
deblasis Aug 29, 2022
b80a57c
fix(Utility): CLI: making use of the pwd flag
deblasis Aug 30, 2022
5e185e4
fix(Utility): CLI: code review feedback
deblasis Sep 5, 2022
ecc360c
fix(Utility): CLI custodial stake command: OutputAddr = fromAddr
deblasis Sep 5, 2022
655f3d0
refactor(Utility): CLI: refactor command bindings
deblasis Sep 5, 2022
d876e0e
refactor(Utility): CLI: named return values fix
deblasis Sep 5, 2022
ae0faa4
test(Utility): CLI: simplified tests for PK parsing from file
deblasis Sep 5, 2022
a86e273
feat(Utility): RPC OpenApi spec and code generation
deblasis Sep 6, 2022
a2eb0e9
feat(Utility): Updated RPC spec
deblasis Sep 7, 2022
349ea3a
docs(Utility): CLI docs barebones
deblasis Sep 7, 2022
6081c34
fix(Utility): CLI: added missing message handling for account
deblasis Sep 7, 2022
0bebfa8
fix(Shared): fixed RPC config
deblasis Sep 7, 2022
1e8e2de
feat(Utility): CLI updated to use the generated RPC client
deblasis Sep 7, 2022
0633550
refactor(Shared): RPC config defaults -changing soon,I'm centralizin
deblasis Sep 7, 2022
5726671
feat(Utility): CLI: updated to use test_artifacts default
deblasis Sep 7, 2022
915fcfb
docs(Utility): CLI: Changelog
deblasis Sep 7, 2022
a4e7e79
fix(Utility): CLI: fixed output to user. It shouldn't be logging
deblasis Sep 7, 2022
d258fd5
fix(Utility): CLI code review feedback
deblasis Sep 8, 2022
d07c14a
style(Utility): code review feedback
deblasis Sep 8, 2022
653f6d7
feat(Tooling): Updated makefile commands to better handle codegen
deblasis Sep 8, 2022
dda85a0
fix(Utility): Fix duplicated models
deblasis Sep 8, 2022
e5c3ae5
feat(Utility): CLI documentation generator + first stab at docs
deblasis Sep 9, 2022
bd42240
Merge remote-tracking branch 'upstream/main' into issue/utility_local…
deblasis Sep 15, 2022
35914a8
fix(Utility): CLI specific fixes
deblasis Sep 15, 2022
377cf14
fix(Utility): types fixes
deblasis Sep 15, 2022
21459d3
fix(Utility): RPC configs post-merge
deblasis Sep 15, 2022
7823a87
feat(Consensus): configOptions
deblasis Sep 15, 2022
e7d9c4e
feat(P2P): configOptions
deblasis Sep 15, 2022
60d3c14
feat(Utility): CLI: using configOptions to inject PK
deblasis Sep 15, 2022
2625979
Merge branch 'main' into issue/utility_local_proof_of_stake_cli_CLI
deblasis Sep 19, 2022
2283910
Merge remote-tracking branch 'upstream/main' into issue/utility_local…
deblasis Oct 13, 2022
2cea452
fix(go.mod): tidy
deblasis Oct 13, 2022
2b8a9d1
fix(CLI): test_artifacts
deblasis Oct 13, 2022
663fb8a
fix(go.mod): tidy
deblasis Oct 14, 2022
dca3786
fix(CLI): updated to use new typesUtil.ActorType
deblasis Oct 14, 2022
c04285b
fix(CLI): runtime based init
deblasis Oct 14, 2022
5b61539
fix(test_artifacts): fix
deblasis Oct 14, 2022
daffff9
fix(CLI): runtime using WithRandomPK()
deblasis Oct 14, 2022
0c85a8c
fix(CLI): fixed client-only initialization
deblasis Oct 14, 2022
7458c0a
fix(Makefile): protogen first
deblasis Oct 14, 2022
40b93b6
feat(Utility): GetActorName function (can we autogenerate these?)
deblasis Oct 14, 2022
20f2ebc
fix(CLI): debug commands are now feature flagged
deblasis Oct 17, 2022
52b46a3
chore(go.mod): tidy
deblasis Oct 17, 2022
f40f742
chore(CLI): git rm app/pocket/rpc/client.gen.go
deblasis Oct 17, 2022
42a3831
chore(CLI): s/j/tx and s/prepareTx/prepareTxJson
deblasis Oct 17, 2022
accd5c8
refactor(shared): converters
deblasis Oct 17, 2022
dbdeccf
fix(CLI): debug nits
deblasis Oct 17, 2022
8aef547
refactor(CLI): confirmation and credentials
deblasis Oct 17, 2022
f02a670
chore(CLI): removed HACK todo
deblasis Oct 17, 2022
69ffc84
fix(Makefile): premature protoc
deblasis Oct 17, 2022
1b1a0ed
fix(RPC): added imports used in codegen files
deblasis Oct 17, 2022
8763125
refactor(RPC): moved scaffolding into rpc module
deblasis Oct 17, 2022
35f8ef2
Update app/client/cli/utils.go
deblasis Oct 19, 2022
bf38384
fix(RPC): gitignoring generated files
deblasis Oct 19, 2022
db4bbdd
style(Persistence): reverting space change
deblasis Oct 19, 2022
aa1c737
refactor(Defaults): runtime/defaults package
deblasis Oct 19, 2022
65326d5
chore(CLI): issue handle
deblasis Oct 19, 2022
e626d93
chore(CLI): Issue #310 links
deblasis Oct 19, 2022
67bc84c
refactor(CLI): preallocation fix
deblasis Oct 19, 2022
d3c726a
style(CLI): oneMillion
deblasis Oct 19, 2022
8d7a1a4
style(CLI): s/RelayChainIDs/relayChainIDs
deblasis Oct 19, 2022
27e36c2
feat(Utility): ActorType.GetName()
deblasis Oct 19, 2022
1eabec4
chore(Utility): tracking issue #142
deblasis Oct 19, 2022
13485a2
chore(Utility): GetBytes -> GetCanonicalBytes
deblasis Oct 24, 2022
ce28724
chore(CLI): actorCmd -> accountCmd
deblasis Oct 24, 2022
e91a1ab
docs(CLI): fromAddr note (address currently sourced from pk)
deblasis Oct 24, 2022
476b124
Merge remote-tracking branch 'upstream/main' into issue/utility_local…
deblasis Oct 24, 2022
3c0f0ba
chore(Runtime): new default value from main
deblasis Oct 24, 2022
c740614
refactor(CLI): moving utility functions in utils.go
deblasis Oct 24, 2022
1a95835
chore(CLI): NewDebug -> NewDebugCommand
deblasis Oct 24, 2022
f75a872
docs(CLI): added todos for exactArgs
deblasis Oct 25, 2022
4cfae32
feat(RPC): /v1/consensus/round_state
deblasis Oct 31, 2022
c9efa96
refactor(CLI): Stake command
deblasis Nov 1, 2022
20c3918
fix(CLI): tx message signing
deblasis Oct 31, 2022
b0a5a78
feat(CLI): reporting statuscode and body
deblasis Nov 1, 2022
225be2f
Update utility/types/message.go
deblasis Nov 2, 2022
5cecd49
chore(Runtime): comment spacing
deblasis Nov 2, 2022
7238b03
docs(CLI): Changelog
deblasis Nov 2, 2022
d9743f5
refactor(Consensus): mocks with Return(nil) and not Do(...)
deblasis Oct 25, 2022
2ec2448
chore(Consensus): SetBus mock Do(func(modules.Bus) {}) -> Return()
deblasis Nov 3, 2022
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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
version: ${{ env.PROTOC_VERSION }}
- name: install cli dependencies
run: make install_cli_deps
- name: generate protobufs and mocks
run: make protogen_local && make mockgen
- name: generate protobufs, RPC server, RPC client and mocks
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
run: make protogen_local && make mockgen && make generate_rpc_openapi
- name: run all tests
run: make test_all_with_json
- name: Annotate tests on GitHub
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ coverage.out
# Output of `make build_and_watch`
main

# generated RPC server and client from openapi.yaml
rpc/server.gen.go
rpc/client.gen.go

# Ignored generated files by build/config/main.go
build/config/gen*.json
build/config/gen*.json
42 changes: 36 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ go_protoc-go-inject-tag:
fi; \
}

.PHONY: go_oapi-codegen
### Checks if oapi-codegen is installed
go_oapi-codegen:
{ \
if ! command -v oapi-codegen >/dev/null; then \
echo "Install with 'go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.11.0'"; \
fi; \
}

.PHONY: go_clean_deps
deblasis marked this conversation as resolved.
Show resolved Hide resolved
## Runs `go mod tidy` && `go mod vendor`
go_clean_deps:
Expand All @@ -95,21 +104,27 @@ gofmt:
gofmt -w -s .

.PHONY: install_cli_deps
## Installs `protoc-gen-go` and `mockgen`
## Installs `protoc-gen-go`, `mockgen`, 'protoc-go-inject-tag' and other tooling
install_cli_deps:
go install "google.golang.org/protobuf/cmd/protoc-gen-go@v1.28" && protoc-gen-go --version
go install "github.com/golang/mock/mockgen@v1.6.0" && mockgen --version
go install "github.com/favadi/protoc-go-inject-tag@latest"
go install "github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.11.0"

.PHONY: develop_start
## Run all of the make commands necessary to develop on the project
develop_start:
make protogen_clean && make protogen_local && \
make go_clean_deps && \
make mockgen && \
make generate_rpc_openapi

.PHONY: develop_test
## Run all of the make commands necessary to develop on the project and verify the tests pass
develop_test: docker_check
make go_clean_deps && \
make mockgen && \
make protogen_clean && make protogen_local && \
make develop_start && \
make test_all


.PHONY: client_start
## Run a client daemon which is only used for debugging purposes
client_start: docker_check
Expand All @@ -118,7 +133,7 @@ client_start: docker_check
.PHONY: client_connect
## Connect to the running client debugging daemon
client_connect: docker_check
docker exec -it client /bin/bash -c "go run app/client/*.go"
docker exec -it client /bin/bash -c "go run -tags=debug app/client/*.go debug"

.PHONY: build_and_watch
## Continous build Pocket's main entrypoint as files change
Expand Down Expand Up @@ -242,6 +257,21 @@ protogen_docker_m1: docker_check
protogen_docker: docker_check
docker build -t pocket/proto-generator -f ./build/Dockerfile.proto . && docker run -it -v $(CWD)/:/usr/src/app/ pocket/proto-generator

.PHONY: generate_rpc_openapi
## (Re)generates the RPC server and client infra code from the openapi spec file (./rpc/v1/openapi.yaml)
generate_rpc_openapi: go_oapi-codegen
oapi-codegen --config ./rpc/server.gen.config.yml ./rpc/v1/openapi.yaml > ./rpc/server.gen.go
oapi-codegen --config ./rpc/client.gen.config.yml ./rpc/v1/openapi.yaml > ./rpc/client.gen.go
echo "OpenAPI client and server generated"

.PHONY: generate_cli_commands_docs
### (Re)generates the CLI commands docs (this is meant to be called by CI)
generate_cli_commands_docs:
$(eval cli_docs_dir = "app/client/cli/doc/commands")
rm ${cli_docs_dir}/*.md >/dev/null 2>&1 || true
cd app/client/cli/docgen && go run .
echo "CLI commands docs generated in ${cli_docs_dir}"

.PHONY: test_all
## Run all go unit tests
test_all: # generate_mocks
Expand Down
72 changes: 72 additions & 0 deletions app/client/cli/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cli

import (
"fmt"

"github.com/pokt-network/pocket/shared/crypto"
"github.com/pokt-network/pocket/utility/types"
"github.com/spf13/cobra"
)

func init() {
actorCmd := NewAccountCommand()
deblasis marked this conversation as resolved.
Show resolved Hide resolved
actorCmd.Flags().StringVar(&pwd, "pwd", "", "passphrase used by the cmd, non empty usage bypass interactive prompt")
rootCmd.AddCommand(actorCmd)
}

func NewAccountCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "Account",
Short: "Account specific commands",
Aliases: []string{"account"},
Args: cobra.ExactArgs(0),
}

cmd.AddCommand(accountCommands()...)

return cmd
}

func accountCommands() []*cobra.Command {
cmds := []*cobra.Command{
{
Use: "Send <fromAddr> <to> <amount>",
Copy link
Member

Choose a reason for hiding this comment

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

I'm excited for this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

soon 🚀

Short: "Send <fromAddr> <to> <amount>",
Long: "Sends <amount> to address <to> from address <fromAddr>",
Aliases: []string{"send"},
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
// TODO(#150): update when we have keybase
pk, err := readEd25519PrivateKeyFromFile(privateKeyFilePath)
if err != nil {
return err
}
// currently ignored since we are using the address from the PrivateKey
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some detail about the path forward on this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please let me know if this is OK and/or enough e91a1ab

// fromAddr := crypto.AddressFromString(args[0])
toAddr := crypto.AddressFromString(args[1])
amount := args[2]

msg := &types.MessageSend{
FromAddress: pk.Address(),
ToAddress: toAddr,
Amount: amount,
}

tx, err := prepareTxJson(msg, pk)
if err != nil {
return err
}

resp, err := postRawTx(cmd.Context(), pk, tx)
if err != nil {
return err
}
// DISCUSS(#310): define UX for return values - should we return the raw response or a parsed/human readable response? For now, I am simply printing to stdout
fmt.Println(resp)

return nil
},
},
}
return cmds
}
Loading