Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,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 app/client/*.go debug"

.PHONY: build_and_watch
## Continous build Pocket's main entrypoint as files change
Expand Down
61 changes: 61 additions & 0 deletions app/client/cli/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cli

import (
"fmt"

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

func init() {
rootCmd.AddCommand(NewAccountCommand())
}

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() (cmds []*cobra.Command) {
sendCmd := &cobra.Command{
Use: "Send <fromAddr> <to> <amount>",
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(pocket/issues/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
// fromAddr := crypto.AddressFromString(args[0])
toAddr := crypto.AddressFromString(args[1])
amount := args[2]

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

// TODO(deblasis): implement RPC client, route and handler
fmt.Printf("sending %s from %s to %s\n", args[2], args[0], args[1])
return nil
},
}

cmds = append(cmds, sendCmd)

return cmds
}
217 changes: 217 additions & 0 deletions app/client/cli/actor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
package cli
Copy link
Collaborator

Choose a reason for hiding this comment

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

An issue I just realized is that validators (and maybe fisherman tentative the question I asked in #311) don't have relay chain IDs. I believe they will just be ignored so things will function E2E, but it'llbe very confusing to the user that they can pass that in.

I was thinking of just updating the docs saying "unneeded params will be ignored", but it still feels misleading and unclear.

Still thinking if we should create a follow up ticket for it or if there's a quick & easy fix here...

Copy link
Collaborator

Choose a reason for hiding this comment

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

@deblasis Can you create a ticket to track 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.

@Olshansk, @andrewnguyen22 : I was writing the ticket and meanwhile, I thought:

I guess this issue is similar to #177 (comment) with the exception that for that one we already have a dependency that could unlock it which is the keybase.

Since it looks like the end-to-end scenario is what we want to achieve short-term and that I added these arguments in the first place when I was more of a newbie just by referencing V0, shall we just remove them and add them back when the time comes to keep it stupid simple?

Ergo:

  • when we know which actors require a relay chain id and for which commands in V1, we'll add to the CLI and RPC accordingly
  • similarly, when we'll have a keybase, we'll accept a fromAddr argument where needed

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm okay with either approach of the following approach

  1. Leaving a comment + TODO + explanation of why the var isn't being used
  2. Removing it altogether

Feel free to take either one depending on your best judgment and time/work capacity

Copy link
Collaborator

Choose a reason for hiding this comment

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

Resolving this per the TODOs left alongside cobra.ExactArgs


import (
"encoding/json"
"fmt"
"log"
"math/big"
"regexp"
"strings"

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

func init() {
rootCmd.AddCommand(NewActorCommands()...)
}

var (
// DISCUSS(team): this should probably come from somewhere else
stakingRecommendationAmount = big.NewInt(15100000000)
pwd string
)

type actorCmdDef struct {
Name string
ActorType types.ActorType
}

func NewActorCommands() (cmds []*cobra.Command) {
actorCmdDefs := []actorCmdDef{
{"Application", types.ActorType_App},
{"Node", types.ActorType_Node},
{"Fisherman", types.ActorType_Fish},
{"Validator", types.ActorType_Val},
}

for _, cmdDef := range actorCmdDefs {

cmd := &cobra.Command{
Use: cmdDef.Name,
Short: fmt.Sprintf("%s actor specific commands", cmdDef.Name),
Aliases: []string{strings.ToLower(cmdDef.Name), cmdDef.ActorType.GetActorName()},
Args: cobra.ExactArgs(0),
}
cmd.AddCommand(newActorCommands(cmdDef)...)
cmds = append(cmds, cmd)
}

return cmds
}

func newActorCommands(cmdDef actorCmdDef) (cmds []*cobra.Command) {
stakeCmd := &cobra.Command{
Use: "Stake <fromAddr> <amount> <RelayChainIDs> <serviceURI>",
Short: "Stake a node in the network. Custodial stake uses the same address as operator/output for rewards/return of staked funds.",
Long: `Stake the node into the network, making it available for service.
Will prompt the user for the <fromAddr> account passphrase. If the node is already staked, this transaction acts as an *update* transaction.
A node can updated relayChainIDs, serviceURI, and raise the stake amount with this transaction.
If the node is currently staked at X and you submit an update with new stake Y. Only Y-X will be subtracted from an account
If no changes are desired for the parameter, just enter the current param value just as before`,
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
// TODO(pocket/issues/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
// fromAddr := crypto.AddressFromString(args[0])
amount := args[1]

am, err := sharedTypes.StringToBigInt(args[1])
if err != nil {
log.Fatal(err)
}

if sharedTypes.BigIntLessThan(am, stakingRecommendationAmount) {
fmt.Printf("The amount you are staking for is below the recommendation of %d POKT, would you still like to continue? y|n\n", stakingRecommendationAmount.Div(stakingRecommendationAmount, big.NewInt(1000000)).Int64())
if !Confirmation(pwd) {
return fmt.Errorf("aborted")
}
}

reg, err := regexp.Compile("[^,a-fA-F0-9]+")
if err != nil {
log.Fatal(err)
}
rawChains := reg.ReplaceAllString(args[2], "")
chains := strings.Split(rawChains, ",")
serviceURI := args[3]

fmt.Println("Enter Passphrase: ")
// TODO (team): passphrase is currently not used since there's no keybase yet, the prompt is here to mimick the real world UX
_ = Credentials(pwd)

msg := &types.MessageStake{
PublicKey: pk.PublicKey().Bytes(),
Chains: chains,
Amount: amount,
ServiceUrl: serviceURI,
OutputAddress: []byte{}, // TODO(deblasis): 👀
Signer: pk.Address(), // TODO(deblasis): figure out where I should get this from (https://github.com/pokt-network/pocket/pull/169#discussion_r953186602)
ActorType: cmdDef.ActorType,
}

codec := sharedTypes.GetCodec()
anyMsg, err := codec.ToAny(msg)

signature, _ := pk.Sign(msg.GetSignBytes())

tx := &utilityTypes.Transaction{
Msg: anyMsg,
Signature: &utilityTypes.Signature{
Signature: signature,
PublicKey: pk.PublicKey().Bytes(),
},
Nonce: "", // TODO(deblasis): figure out where I should get this from
}

j, err := json.Marshal(tx)
if err != nil {
return err
}

// TODO(deblasis): we need a single source of truth for routes, the empty string should be replaced with something like a constant that can be used to point to a specific route
// perhaps the routes could be centralized into a map[string]Route in #176 and accessed here
// I will do this in #169 since it has commits from #176 and #177
resp, err := QueryRPC("", j)
if err != nil {
return err
}
fmt.Println(resp)

return nil
},
}
cmds = append(cmds, stakeCmd)

editStakeCmd := &cobra.Command{
Use: "EditStake <fromAddr> <amount>",
Short: "EditStake <fromAddr> <amount>",
Long: fmt.Sprintf(`Stakes a new <amount> for the %s actor with address <fromAddr>`, cmdDef.Name),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
// TODO(pocket/issues/150): update when we have keybase
pk, err := readEd25519PrivateKeyFromFile(privateKeyFilePath)
if err != nil {
return err
}

amount := args[1]

_ = &types.MessageEditStake{
Address: pk.Address(),
Chains: []string{}, // TODO(deblasis): 👀
Amount: amount,
ServiceUrl: "", // TODO(deblasis): 👀
Signer: []byte{}, // TODO(deblasis): 👀
ActorType: cmdDef.ActorType,
}

return nil
},
}
cmds = append(cmds, editStakeCmd)

unstakeCmd := &cobra.Command{
Use: "Unstake <fromAddr>",
Short: "Unstake <fromAddr>",
Long: fmt.Sprintf(`Unstakes the prevously staked tokens for the %s actor with address <fromAddr>`, cmdDef.Name),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// TODO(pocket/issues/150): update when we have keybase
pk, err := readEd25519PrivateKeyFromFile(privateKeyFilePath)
if err != nil {
return err
}

_ = &types.MessageUnstake{
Address: pk.Address(),
Signer: []byte{}, // TODO(deblasis): 👀
ActorType: cmdDef.ActorType,
}

return nil
},
}
cmds = append(cmds, unstakeCmd)

unpauseCmd := &cobra.Command{
Use: "Unpause <fromAddr>",
Short: "Unpause <fromAddr>",
Long: fmt.Sprintf(`Unpauses the %s actor with address <fromAddr>`, cmdDef.Name),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// TODO(pocket/issues/150): update when we have keybase
pk, err := readEd25519PrivateKeyFromFile(privateKeyFilePath)
if err != nil {
return err
}

_ = &types.MessageUnpause{
Address: pk.Address(),
Signer: []byte{}, // TODO(deblasis): 👀
ActorType: cmdDef.ActorType,
}

return nil
},
}
cmds = append(cmds, unpauseCmd)

return cmds
}
48 changes: 48 additions & 0 deletions app/client/cli/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cli

import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"time"

"github.com/pokt-network/pocket/shared/types/genesis/test_artifacts"
)

func QueryRPC(path string, jsonArgs []byte) (string, error) {
cliURL := remoteCLIURL + path
fmt.Println(cliURL)
req, err := http.NewRequest("POST", cliURL, bytes.NewBuffer(jsonArgs))
if err != nil {
return "", err
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{
Timeout: time.Duration(test_artifacts.DefaultRpcTimeout) * time.Millisecond,
}
resp, err := client.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
bz, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
res, err := strconv.Unquote(string(bz))
if err == nil {
bz = []byte(res)
}
if resp.StatusCode == http.StatusOK {
var prettyJSON bytes.Buffer
err = json.Indent(&prettyJSON, bz, "", " ")
if err == nil {
return prettyJSON.String(), nil
}
return string(bz), nil
}
return "", fmt.Errorf("the http status code was not okay: %d, and the status was: %s, with a response of %v", resp.StatusCode, resp.Status, string(bz))
}
33 changes: 33 additions & 0 deletions app/client/cli/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cli

import (
"context"

"github.com/pokt-network/pocket/shared/types/genesis/test_artifacts"
"github.com/spf13/cobra"
)

const cliExecutableName = "client"

var (
remoteCLIURL string
privateKeyFilePath string
)

func init() {
rootCmd.PersistentFlags().StringVar(&remoteCLIURL, "remoteCLIURL", test_artifacts.DefaultRemoteCliUrl, "takes a remote endpoint in the form of <protocol>://<host> (uses RPC Port)")
rootCmd.PersistentFlags().StringVar(&privateKeyFilePath, "path_to_private_key_file", "./pk.json", "Path to private key to use when signing")
}

var rootCmd = &cobra.Command{
Use: cliExecutableName,
// TODO(deblasis): document
Short: "",
Long: "",
// TODO(deblasis): do we need some sort of teardown as well?

}

func ExecuteContext(ctx context.Context) error {
return rootCmd.ExecuteContext(ctx)
}
Loading