Skip to content

Commit

Permalink
Merge branch 'main' into chore/libp2p-2
Browse files Browse the repository at this point in the history
* main:
  [Libp2p] Add libp2p module directories and helpers (part 1) (#534)
  [P2P, Runtime] Update P2P & base config (part 2) (#535)
  [Utility] Foundational bugs, tests, code cleanup and improvements (2/3) (#550)
  [CONSENSUS] Find issue with sending metadata request (#548)
  [Tooling] SLIP-0010 HD Child Key Generation (#510)
  • Loading branch information
bryanchriswhite committed Mar 3, 2023
2 parents ceb20c2 + f03197f commit d5f33e6
Show file tree
Hide file tree
Showing 206 changed files with 2,684 additions and 1,961 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -518,4 +518,4 @@ check_cross_module_imports: ## Lists cross-module imports

.PHONY: send_local_tx
send_local_tx: ## A hardcoded send tx to make LocalNet debugging easier
go run app/client/*.go Account Send 00104055c00bed7c983a48aac7dc6335d7c607a7 00204737d2a165ebe4be3a7d5b0af905b0ea91d8 1000
go run app/client/*.go Account Send --non_interactive 00104055c00bed7c983a48aac7dc6335d7c607a7 00204737d2a165ebe4be3a7d5b0af905b0ea91d8 1000
8 changes: 4 additions & 4 deletions app/client/cli/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ If no changes are desired for the parameter, just enter the current param value
// removing all invalid characters from rawChains argument
rawChains := rawChainCleanupRegex.ReplaceAllString(args[2], "")
chains := strings.Split(rawChains, ",")
serviceURI := args[3]
serviceURL := args[3]

msg := &typesUtil.MessageStake{
PublicKey: pk.PublicKey().Bytes(),
Chains: chains,
Amount: amount,
ServiceUrl: serviceURI,
ServiceUrl: serviceURL,
OutputAddress: pk.Address(),
Signer: pk.Address(),
ActorType: cmdDef.ActorType,
Expand Down Expand Up @@ -201,13 +201,13 @@ func newEditStakeCmd(cmdDef actorCmdDef) *cobra.Command {
// removing all invalid characters from rawChains argument
rawChains := rawChainCleanupRegex.ReplaceAllString(args[2], "")
chains := strings.Split(rawChains, ",")
serviceURI := args[3]
serviceURL := args[3]

msg := &typesUtil.MessageEditStake{
Address: fromAddr,
Chains: chains,
Amount: amount,
ServiceUrl: serviceURI,
ServiceUrl: serviceURL,
Signer: pk.Address(),
ActorType: cmdDef.ActorType,
}
Expand Down
6 changes: 3 additions & 3 deletions app/client/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ func NewDebugCommand() *cobra.Command {
bus := runtimeMgr.GetBus()
modulesRegistry := bus.GetModulesRegistry()

rpcUrl := fmt.Sprintf("http://%s:%s", rpcHost, defaults.DefaultRPCPort)
rpcURL := fmt.Sprintf("http://%s:%s", rpcHost, defaults.DefaultRPCPort)

addressBookProvider := rpcABP.NewRPCAddrBookProvider(
rpcABP.WithP2PConfig(
runtimeMgr.GetConfig().P2P,
),
rpcABP.WithCustomRPCUrl(rpcUrl),
rpcABP.WithCustomRPCURL(rpcURL),
)
modulesRegistry.RegisterModule(addressBookProvider)

currentHeightProvider := rpcCHP.NewRPCCurrentHeightProvider(
rpcCHP.WithCustomRPCUrl(rpcUrl),
rpcCHP.WithCustomRPCURL(rpcURL),
)
modulesRegistry.RegisterModule(currentHeightProvider)

Expand Down
87 changes: 75 additions & 12 deletions app/client/cli/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"bytes"
"encoding/hex"
"fmt"
"path/filepath"
"strconv"
"strings"

"github.com/pokt-network/pocket/logger"
"github.com/pokt-network/pocket/shared/codec"
"github.com/pokt-network/pocket/shared/converters"
coreTypes "github.com/pokt-network/pocket/shared/core/types"
"github.com/pokt-network/pocket/shared/crypto"
utilTypes "github.com/pokt-network/pocket/utility/types"
"path/filepath"
"strings"
"github.com/pokt-network/pocket/shared/utils"

"github.com/pokt-network/pocket/app/client/keybase"
"github.com/spf13/cobra"
Expand All @@ -23,6 +25,9 @@ var (
importAs string
hint string
newPwd string
storeChild bool
childPwd string
childHint string
)

func init() {
Expand All @@ -45,6 +50,7 @@ func NewKeysCommand() *cobra.Command {
importCmds := keysImportCommands()
signMsgCmds := keysSignMsgCommands()
signTxCmds := keysSignTxCommands()
slipCmds := keysSlipCommands()

// Add --pwd and --hint flags
applySubcommandOptions(createCmds, attachPwdFlagToSubcommands())
Expand Down Expand Up @@ -77,6 +83,12 @@ func NewKeysCommand() *cobra.Command {
applySubcommandOptions(signTxCmds, attachInputFlagToSubcommands())
applySubcommandOptions(signTxCmds, attachOutputFlagToSubcommands())

// Add --pwd, --store_child, --child_pwd, --child_hint flags
applySubcommandOptions(slipCmds, attachPwdFlagToSubcommands())
applySubcommandOptions(slipCmds, attachStoreChildFlagToSubcommands())
applySubcommandOptions(slipCmds, attachChildPwdFlagToSubcommands())
applySubcommandOptions(slipCmds, attachChildHintFlagToSubcommands())

cmd.AddCommand(createCmds...)
cmd.AddCommand(updateCmds...)
cmd.AddCommand(deleteCmds...)
Expand All @@ -85,6 +97,7 @@ func NewKeysCommand() *cobra.Command {
cmd.AddCommand(importCmds...)
cmd.AddCommand(signMsgCmds...)
cmd.AddCommand(signTxCmds...)
cmd.AddCommand(slipCmds...)

return cmd
}
Expand Down Expand Up @@ -351,7 +364,7 @@ func keysExportCommands() []*cobra.Command {

logger.Global.Info().Str("output_file", outputFile).Msg("Exporting private key string to file...")

return converters.WriteOutput(exportString, outputFile)
return utils.WriteOutput(exportString, outputFile)
},
},
}
Expand All @@ -372,7 +385,7 @@ func keysImportCommands() []*cobra.Command {
if len(args) == 1 {
privateKeyString = args[0]
} else if inputFile != "" {
privateKeyBz, err := converters.ReadInput(inputFile)
privateKeyBz, err := utils.ReadInput(inputFile)
privateKeyString = string(privateKeyBz)
if err != nil {
return err
Expand Down Expand Up @@ -566,11 +579,11 @@ func keysSignTxCommands() []*cobra.Command {
}

// Unmarshal Tx from input file
txBz, err := converters.ReadInput(inputFile)
txBz, err := utils.ReadInput(inputFile)
if err != nil {
return err
}
txProto := new(utilTypes.Transaction)
txProto := new(coreTypes.Transaction)
if err := codec.GetCodec().Unmarshal(txBz, txProto); err != nil {
return err
}
Expand All @@ -587,7 +600,7 @@ func keysSignTxCommands() []*cobra.Command {
}

// Add signature to the transaction
sig := new(utilTypes.Signature)
sig := new(coreTypes.Signature)
sig.PublicKey = privKey.PublicKey().Bytes()
sig.Signature = sigBz
txProto.Signature = sig
Expand All @@ -598,7 +611,7 @@ func keysSignTxCommands() []*cobra.Command {
return err
}

if err := converters.WriteOutput(txBz, outputFile); err != nil {
if err := utils.WriteOutput(txBz, outputFile); err != nil {
return err
}

Expand Down Expand Up @@ -638,11 +651,11 @@ func keysSignTxCommands() []*cobra.Command {
}

// Unmarshal Tx from input file
txBz, err := converters.ReadInput(inputFile)
txBz, err := utils.ReadInput(inputFile)
if err != nil {
return err
}
txProto := new(utilTypes.Transaction)
txProto := new(coreTypes.Transaction)
if err := codec.GetCodec().Unmarshal(txBz, txProto); err != nil {
return err
}
Expand Down Expand Up @@ -680,3 +693,53 @@ func keysSignTxCommands() []*cobra.Command {
}
return cmds
}

func keysSlipCommands() []*cobra.Command {
cmds := []*cobra.Command{
{
Use: "DeriveChild <parentAddrHex> <index>",
Short: "Derive the child key at the given index from a parent key",
Long: "Derive the child key at <index> from the parent key provided optionally store it in the keybase with [--store_child]",
Aliases: []string{"derivechild"},
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
// Unpack CLI args
parentAddr := args[0]
idx64, err := strconv.ParseUint(args[1], 10, 32)
if err != nil {
return err
}
index := uint32(idx64)

// Open the debug keybase at the specified path
pocketDir := strings.TrimSuffix(dataDir, "/")
keybasePath, err := filepath.Abs(pocketDir + keybaseSuffix)
if err != nil {
return err
}
kb, err := keybase.NewKeybase(keybasePath)
if err != nil {
return err
}

if !nonInteractive {
pwd = readPassphrase(pwd)
}

kp, err := kb.DeriveChildFromKey(parentAddr, pwd, index, childPwd, childHint, storeChild)
if err != nil {
return err
}

if err := kb.Stop(); err != nil {
return err
}

logger.Global.Info().Str("address", kp.GetAddressString()).Str("parent", parentAddr).Uint32("index", index).Bool("stored", storeChild).Msg("Child key derived")

return nil
},
},
}
return cmds
}
29 changes: 24 additions & 5 deletions app/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
"github.com/pokt-network/pocket/logger"
"github.com/pokt-network/pocket/rpc"
"github.com/pokt-network/pocket/shared/codec"
"github.com/pokt-network/pocket/shared/converters"
coreTypes "github.com/pokt-network/pocket/shared/core/types"
"github.com/pokt-network/pocket/shared/crypto"
"github.com/pokt-network/pocket/shared/utils"
typesUtil "github.com/pokt-network/pocket/utility/types"
"github.com/spf13/cobra"
"golang.org/x/term"
Expand Down Expand Up @@ -89,7 +90,7 @@ func prepareTxBytes(msg typesUtil.Message, pk crypto.PrivateKey) ([]byte, error)
return nil, err
}

tx := &typesUtil.Transaction{
tx := &coreTypes.Transaction{
Msg: anyMsg,
Nonce: fmt.Sprintf("%d", crypto.GetNonce()),
}
Expand All @@ -104,7 +105,7 @@ func prepareTxBytes(msg typesUtil.Message, pk crypto.PrivateKey) ([]byte, error)
return nil, err
}

tx.Signature = &typesUtil.Signature{
tx.Signature = &coreTypes.Signature{
Signature: signature,
PublicKey: pk.PublicKey().Bytes(),
}
Expand Down Expand Up @@ -155,13 +156,13 @@ func readPassphraseMessage(currPwd, prompt string) string {
}

func validateStakeAmount(amount string) error {
am, err := converters.StringToBigInt(amount)
am, err := utils.StringToBigInt(amount)
if err != nil {
return err
}

sr := big.NewInt(stakingRecommendationAmount)
if converters.BigIntLessThan(am, sr) {
if utils.BigIntLessThan(am, sr) {
fmt.Printf("The amount you are staking for is below the recommendation of %d POKT, would you still like to continue? y|n\n", sr.Div(sr, oneMillion).Int64())
if !confirmation(pwd) {
return fmt.Errorf("aborted")
Expand Down Expand Up @@ -220,6 +221,24 @@ func attachHintFlagToSubcommands() []cmdOption {
}}
}

func attachStoreChildFlagToSubcommands() []cmdOption {
return []cmdOption{func(c *cobra.Command) {
c.Flags().BoolVar(&storeChild, "store_child", true, "store the derived child key in the keybase")
}}
}

func attachChildHintFlagToSubcommands() []cmdOption {
return []cmdOption{func(c *cobra.Command) {
c.Flags().StringVar(&childHint, "child_hint", "", "hint for the passphrase of the derived child's private key")
}}
}

func attachChildPwdFlagToSubcommands() []cmdOption {
return []cmdOption{func(c *cobra.Command) {
c.Flags().StringVar(&childPwd, "child_pwd", "", "passphrase for the derived child's private key")
}}
}

func unableToConnectToRpc(err error) error {
fmt.Printf("❌ Unable to connect to the RPC @ %s\n\nError: %s", boldText(remoteCLIURL), err)
return nil
Expand Down
9 changes: 9 additions & 0 deletions app/client/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.19] - 2023-02-28

- Renamed the package names for some basic helpers

## [0.0.0.18] - 2023-02-28

- Implement SLIP-0010 HD child key derivation with the keybase
- Add CLI endpoints to derive child keys by index

## [0.0.0.17] - 2023-02-23

- Add CLI endpoints to interact with the keybase
Expand Down
2 changes: 1 addition & 1 deletion app/client/doc/commands/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ The CLI is meant to be an user but also a machine friendly way for interacting w
* [client Validator](client_Validator.md) - Validator actor specific commands
* [client debug](client_debug.md) - Debug utility for rapid development

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Account.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Account specific commands
* [client](client.md) - Pocket Network Command Line Interface (CLI)
* [client Account Send](client_Account_Send.md) - Send <fromAddr> <to> <amount>

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Account_Send.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Account Send <fromAddr> <to> <amount> [flags]

* [client Account](client_Account.md) - Account specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Application.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Application actor specific commands
* [client Application Unpause](client_Application_Unpause.md) - Unpause <fromAddr>
* [client Application Unstake](client_Application_Unstake.md) - Unstake <fromAddr>

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Application_EditStake.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Application EditStake <fromAddr> <amount> <relayChainIDs> <serviceURI> [f

* [client Application](client_Application.md) - Application actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Application_Stake.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ client Application Stake <fromAddr> <amount> <relayChainIDs> <serviceURI> [flags

* [client Application](client_Application.md) - Application actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Application_Unpause.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Application Unpause <fromAddr> [flags]

* [client Application](client_Application.md) - Application actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Application_Unstake.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ client Application Unstake <fromAddr> [flags]

* [client Application](client_Application.md) - Application actor specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Consensus.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Consensus specific commands
* [client Consensus State](client_Consensus_State.md) - Returns "Height/Round/Step"
* [client Consensus Step](client_Consensus_Step.md) - Returns the Step

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Consensus_Height.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ client Consensus Height [flags]

* [client Consensus](client_Consensus.md) - Consensus specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Consensus_Round.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ client Consensus Round [flags]

* [client Consensus](client_Consensus.md) - Consensus specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
2 changes: 1 addition & 1 deletion app/client/doc/commands/client_Consensus_State.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ client Consensus State [flags]

* [client Consensus](client_Consensus.md) - Consensus specific commands

###### Auto generated by spf13/cobra on 23-Feb-2023
###### Auto generated by spf13/cobra on 24-Feb-2023
Loading

0 comments on commit d5f33e6

Please sign in to comment.