-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added get_memos_by_coin_name * added get_fee_estimate
- Loading branch information
1 parent
ae83dc8
commit feae6e1
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
getFeeEstimateCmd.Flags().StringP("file", "f", "", "Path to file containing the spend bundle JSON") | ||
rootCmd.AddCommand(getFeeEstimateCmd) | ||
} | ||
|
||
var getFeeEstimateCmd = &cobra.Command{ | ||
Use: "get_fee_estimate [spend_bundle_json]", | ||
Short: "Get fee estimate for a spend bundle", | ||
Long: `Get fee estimate for a spend bundle. The spend bundle can be provided directly as an argument or via a file using the -f flag.`, | ||
} | ||
|
||
func init() { | ||
var spendBundleJson string | ||
var parsedJson map[string]interface{} | ||
|
||
getFeeEstimateCmd.Args = func(cmd *cobra.Command, args []string) error { | ||
fileFlag, _ := cmd.Flags().GetString("file") | ||
|
||
if (len(args) == 0 && fileFlag == "") || (len(args) > 0 && fileFlag != "") { | ||
return fmt.Errorf("must provide either spend bundle JSON as argument or file path with -f flag, but not both") | ||
} | ||
|
||
if len(args) > 0 { | ||
if len(args) > 1 { | ||
return fmt.Errorf("too many arguments provided. Did you forget to quote your JSON? Expected: get_fee_estimate '<json>' or get_fee_estimate -f <filename>") | ||
} | ||
spendBundleJson = args[0] | ||
} | ||
|
||
if fileFlag != "" { | ||
data, err := os.ReadFile(fileFlag) | ||
if err != nil { | ||
return fmt.Errorf("unable to read file %s: %v", fileFlag, err) | ||
} | ||
spendBundleJson = string(data) | ||
} | ||
|
||
if err := json.Unmarshal([]byte(spendBundleJson), &parsedJson); err != nil { | ||
return fmt.Errorf("invalid JSON: %v", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
getFeeEstimateCmd.Run = func(cmd *cobra.Command, args []string) { | ||
makeRequest("get_fee_estimate", parsedJson) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(getMemosByCoinNameCmd) | ||
} | ||
|
||
var getMemosByCoinNameCmd = &cobra.Command{ | ||
Use: "get_memos_by_coin_name <name>", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if err := cobra.ExactArgs(1)(cmd, args); err != nil { | ||
return err | ||
} | ||
if isHex(args[0]) { | ||
return nil | ||
} | ||
return fmt.Errorf("invalid hex value specified: %s", args[0]) | ||
}, | ||
Short: "Retrieves memos for a coin", | ||
Long: "Retrieves memos for a coin", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
jsonData := map[string]interface{}{} | ||
jsonData["name"] = formatHex(args[0]) | ||
makeRequest("get_memos_by_coin_name", jsonData) | ||
}, | ||
} |