-
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_puzzle_and_solution_with_conditions (#11)
* added get_puzzle_and_solution_with_conditions * added coin_id command * updated README
- Loading branch information
1 parent
a40abd4
commit 62a9d91
Showing
3 changed files
with
119 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
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,59 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/chia-network/go-chia-libs/pkg/types" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var coin types.Coin | ||
|
||
func init() { | ||
rootCmd.AddCommand(coinIdCmd) | ||
} | ||
|
||
var coinIdCmd = &cobra.Command{ | ||
Use: "coin_id <parent_coin_id> <puzzle_hash> <amount>", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if err := cobra.ExactArgs(3)(cmd, args); err != nil { | ||
return err | ||
} | ||
|
||
// Parent | ||
if !isHex(args[0]) { | ||
return fmt.Errorf("invalid hex value specified: %s", args[0]) | ||
} | ||
parent, err := types.Bytes32FromHexString(formatHex(args[0])) | ||
if err != nil { | ||
return fmt.Errorf("invalid hex value specified: %s", args[0]) | ||
} | ||
coin.ParentCoinInfo = parent | ||
|
||
// Puzzle Hash | ||
if !isHex(args[1]) { | ||
return fmt.Errorf("invalid hex value specified: %s", args[1]) | ||
} | ||
puzzle_hash, err := types.Bytes32FromHexString(formatHex(args[1])) | ||
if err != nil { | ||
return fmt.Errorf("invalid hex value specified: %s", args[1]) | ||
} | ||
coin.PuzzleHash = puzzle_hash | ||
|
||
// Amount | ||
amount, err := strconv.ParseUint(args[2], 10, 64) | ||
if err != nil { | ||
return fmt.Errorf("invalid amount: %s", args[2]) | ||
} | ||
coin.Amount = amount | ||
|
||
return nil | ||
}, | ||
Short: "Compute a coin id from parent, puzzle and amount", | ||
Long: `Compute a coin id from parent, puzzle and amount`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Printf("%s\n", coin.ID().String()) | ||
}, | ||
} |
31 changes: 31 additions & 0 deletions
31
internal/cmd/coinset/get_puzzle_and_solution_with_conditions.go
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(getPuzzleAndSolutionWithConditionsCmd) | ||
} | ||
|
||
var getPuzzleAndSolutionWithConditionsCmd = &cobra.Command{ | ||
Use: "get_puzzle_and_solution_with_conditions <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 a coin's spend record by its name including conditions", | ||
Long: "Retrieves a coin's spend record by its name including conditions", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
jsonData := map[string]interface{}{} | ||
jsonData["coin_id"] = formatHex(args[0]) | ||
makeRequest("get_puzzle_and_solution_with_conditions", jsonData) | ||
}, | ||
} |