From 5ee17e94c0ff36376b5ddd49a17f36a35f860249 Mon Sep 17 00:00:00 2001 From: ramin Date: Fri, 6 Oct 2023 10:27:19 +0100 Subject: [PATCH] naming nit we agreed to do after merging rpc, my feeling is NewFromContext is a more idiomatic name than ParseFromCtx --- cmd/rpc.go | 2 +- nodebuilder/blob/cmd/blob.go | 8 ++++---- nodebuilder/das/cmd/das.go | 2 +- nodebuilder/header/cmd/header.go | 10 +++++----- nodebuilder/node/cmd/node.go | 8 ++++---- nodebuilder/p2p/cmd/p2p.go | 34 ++++++++++++++++---------------- nodebuilder/share/cmd/share.go | 10 +++++----- nodebuilder/state/cmd/state.go | 24 +++++++++++----------- 8 files changed, 49 insertions(+), 49 deletions(-) diff --git a/cmd/rpc.go b/cmd/rpc.go index 62e9fe7923..4faa9c2211 100644 --- a/cmd/rpc.go +++ b/cmd/rpc.go @@ -89,7 +89,7 @@ func getToken(path string) (string, error) { type rpcClientKey struct{} -func ParseClientFromCtx(ctx context.Context) (*rpc.Client, error) { +func NewClientFromContext(ctx context.Context) (*rpc.Client, error) { client, ok := ctx.Value(rpcClientKey{}).(*rpc.Client) if !ok { return nil, errors.New("rpc client was not set") diff --git a/nodebuilder/blob/cmd/blob.go b/nodebuilder/blob/cmd/blob.go index f3510edfe1..63eb9d5f55 100644 --- a/nodebuilder/blob/cmd/blob.go +++ b/nodebuilder/blob/cmd/blob.go @@ -68,7 +68,7 @@ var getCmd = &cobra.Command{ Args: cobra.ExactArgs(3), Short: "Returns the blob for the given namespace by commitment at a particular height.", RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -104,7 +104,7 @@ var getAllCmd = &cobra.Command{ Args: cobra.ExactArgs(2), Short: "Returns all blobs for the given namespace at a particular height.", RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -137,7 +137,7 @@ var submitCmd = &cobra.Command{ "* only one blob is allowed to submit through the RPC.\n" + "* fee and gas.limit params will be calculated automatically if they are not provided as arguments", RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -175,7 +175,7 @@ var getProofCmd = &cobra.Command{ Args: cobra.ExactArgs(3), Short: "Retrieves the blob in the given namespaces at the given height by commitment and returns its Proof.", RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } diff --git a/nodebuilder/das/cmd/das.go b/nodebuilder/das/cmd/das.go index 7512861ac3..e0fb969ba6 100644 --- a/nodebuilder/das/cmd/das.go +++ b/nodebuilder/das/cmd/das.go @@ -22,7 +22,7 @@ var samplingStatsCmd = &cobra.Command{ Short: "Returns the current statistics over the DA sampling process", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } diff --git a/nodebuilder/header/cmd/header.go b/nodebuilder/header/cmd/header.go index b3bba1eb32..6f06a22e45 100644 --- a/nodebuilder/header/cmd/header.go +++ b/nodebuilder/header/cmd/header.go @@ -32,7 +32,7 @@ var localHeadCmd = &cobra.Command{ Short: "Returns the ExtendedHeader from the chain head.", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -48,7 +48,7 @@ var networkHeadCmd = &cobra.Command{ Short: "Provides the Syncer's view of the current network head.", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -64,7 +64,7 @@ var getByHashCmd = &cobra.Command{ Short: "Returns the header of the given hash from the node's header store.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -84,7 +84,7 @@ var getByHeightCmd = &cobra.Command{ Short: "Returns the ExtendedHeader at the given height if it is currently available.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -105,7 +105,7 @@ var syncStateCmd = &cobra.Command{ Short: "Returns the current state of the header Syncer.", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } diff --git a/nodebuilder/node/cmd/node.go b/nodebuilder/node/cmd/node.go index a65727fb03..acdda8f507 100644 --- a/nodebuilder/node/cmd/node.go +++ b/nodebuilder/node/cmd/node.go @@ -26,7 +26,7 @@ var nodeInfoCmd = &cobra.Command{ Args: cobra.NoArgs, Short: "Returns administrative information about the node.", RunE: func(c *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(c.Context()) + client, err := cmdnode.NewClientFromContext(c.Context()) if err != nil { return err } @@ -45,7 +45,7 @@ var logCmd = &cobra.Command{ "`DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL and their lower-case forms`.\n" + "To set all modules to a particular level `*:` should be passed", RunE: func(c *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(c.Context()) + client, err := cmdnode.NewClientFromContext(c.Context()) if err != nil { return err } @@ -72,7 +72,7 @@ var verifyCmd = &cobra.Command{ Short: "Returns the permissions assigned to the given token.", RunE: func(c *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(c.Context()) + client, err := cmdnode.NewClientFromContext(c.Context()) if err != nil { return err } @@ -88,7 +88,7 @@ var authCmd = &cobra.Command{ Args: cobra.MinimumNArgs(1), Short: "Signs and returns a new token with the given permissions.", RunE: func(c *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(c.Context()) + client, err := cmdnode.NewClientFromContext(c.Context()) if err != nil { return err } diff --git a/nodebuilder/p2p/cmd/p2p.go b/nodebuilder/p2p/cmd/p2p.go index 5951595fa4..058d37a942 100644 --- a/nodebuilder/p2p/cmd/p2p.go +++ b/nodebuilder/p2p/cmd/p2p.go @@ -49,7 +49,7 @@ var infoCmd = &cobra.Command{ Short: "Gets the node's peer info (peer id and multiaddresses)", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -78,7 +78,7 @@ var peersCmd = &cobra.Command{ Short: "Lists the peers we are connected to", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -107,7 +107,7 @@ var peerInfoCmd = &cobra.Command{ Short: "Gets PeerInfo for a given peer", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -139,7 +139,7 @@ var connectCmd = &cobra.Command{ Short: "Establishes a connection with the given peer", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -173,7 +173,7 @@ var closePeerCmd = &cobra.Command{ Short: "Closes the connection with the given peer", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -197,7 +197,7 @@ var connectednessCmd = &cobra.Command{ Short: "Checks the connection state between current and given peers", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -227,7 +227,7 @@ var natStatusCmd = &cobra.Command{ Short: "Gets the currrent NAT status", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -252,7 +252,7 @@ var blockPeerCmd = &cobra.Command{ Short: "Blocks the given peer", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -290,7 +290,7 @@ var unblockPeerCmd = &cobra.Command{ Short: "Unblocks the given peer", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -329,7 +329,7 @@ var blockedPeersCmd = &cobra.Command{ Short: "Lists the node's blocked peers", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -359,7 +359,7 @@ var protectCmd = &cobra.Command{ Short: "Protects the given peer from being pruned by the given tag", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -399,7 +399,7 @@ var unprotectCmd = &cobra.Command{ "The return value indicates whether the peer continues to be protected after this call, by way of a different tag", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -437,7 +437,7 @@ var protectedCmd = &cobra.Command{ Short: "Ensures that a given peer is protected under a specific tag", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -467,7 +467,7 @@ var bandwidthStatsCmd = &cobra.Command{ "received by the local peer, regardless of protocol or remote peer IDs", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -493,7 +493,7 @@ var peerBandwidthCmd = &cobra.Command{ Short: "Gets stats struct with bandwidth metrics associated with the given peer.ID", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -524,7 +524,7 @@ var bandwidthForProtocolCmd = &cobra.Command{ Short: "Gets stats struct with bandwidth metrics associated with the given protocol.ID", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -550,7 +550,7 @@ var pubsubPeersCmd = &cobra.Command{ Short: "Lists the peers we are connected to in the given topic", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } diff --git a/nodebuilder/share/cmd/share.go b/nodebuilder/share/cmd/share.go index fbf3e51db4..8e00bd49b4 100644 --- a/nodebuilder/share/cmd/share.go +++ b/nodebuilder/share/cmd/share.go @@ -35,7 +35,7 @@ var sharesAvailableCmd = &cobra.Command{ Short: "Subjectively validates if Shares committed to the given Root are available on the Network.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -78,7 +78,7 @@ var probabilityOfAvailabilityCmd = &cobra.Command{ Short: "Calculates the probability of the data square being available based on the number of samples collected.", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -94,7 +94,7 @@ var getSharesByNamespaceCmd = &cobra.Command{ Short: "Gets all shares from an EDS within the given namespace.", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -126,7 +126,7 @@ var getShare = &cobra.Command{ Short: "Gets a Share by coordinates in EDS.", Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -180,7 +180,7 @@ var getEDS = &cobra.Command{ Short: "Gets the full EDS identified by the given root", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } diff --git a/nodebuilder/state/cmd/state.go b/nodebuilder/state/cmd/state.go index d35c4a1b4f..7374af4d30 100644 --- a/nodebuilder/state/cmd/state.go +++ b/nodebuilder/state/cmd/state.go @@ -41,7 +41,7 @@ var accountAddressCmd = &cobra.Command{ Short: "Retrieves the address of the node's account/signer.", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -58,7 +58,7 @@ var balanceCmd = &cobra.Command{ "the corresponding block's AppHash.", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -75,7 +75,7 @@ var balanceForAddressCmd = &cobra.Command{ "the corresponding block's AppHash.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -96,7 +96,7 @@ var transferCmd = &cobra.Command{ Short: "Sends the given amount of coins from default wallet of the node to the given account address.", Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -135,7 +135,7 @@ var submitTxCmd = &cobra.Command{ Short: "Submits the given transaction/message to the Celestia network and blocks until the tx is included in a block.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -158,7 +158,7 @@ var cancelUnbondingDelegationCmd = &cobra.Command{ Short: "Cancels a user's pending undelegation from a validator.", Args: cobra.ExactArgs(5), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -206,7 +206,7 @@ var beginRedelegateCmd = &cobra.Command{ Short: "Sends a user's delegated tokens to a new validator for redelegation", Args: cobra.ExactArgs(5), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -253,7 +253,7 @@ var undelegateCmd = &cobra.Command{ Short: "Undelegates a user's delegated tokens, unbonding them from the current validator.", Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -293,7 +293,7 @@ var delegateCmd = &cobra.Command{ Short: "Sends a user's liquid tokens to a validator for delegation.", Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -335,7 +335,7 @@ var queryDelegationCmd = &cobra.Command{ Short: "Retrieves the delegation information between a delegator and a validator.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -356,7 +356,7 @@ var queryUnbondingCmd = &cobra.Command{ Short: "Retrieves the unbonding status between a delegator and a validator.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err } @@ -377,7 +377,7 @@ var queryRedelegationCmd = &cobra.Command{ Short: "Retrieves the status of the redelegations between a delegator and a validator.", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - client, err := cmdnode.ParseClientFromCtx(cmd.Context()) + client, err := cmdnode.NewClientFromContext(cmd.Context()) if err != nil { return err }