Skip to content

Commit 62a9d91

Browse files
added get_puzzle_and_solution_with_conditions (#11)
* added get_puzzle_and_solution_with_conditions * added coin_id command * updated README
1 parent a40abd4 commit 62a9d91

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,35 @@ $ coinset get_coin_records_by_parent_ids 0xa908ee64a5821b7bda5d798c053a79c8b3d7c
7878
}
7979
```
8080

81+
### Coin IDs
82+
83+
Using the `coin_id` command you can encode coin IDs. For example:
84+
85+
```bash
86+
coinset coin_id 0xeca65946d1b80b527bcab5e94673f30bb3fd8a9466b31379fa5fa1f49c492031 0x66e55285340258cb79e6eda4d16f230bec2df7a2d7b40b8c6268247be9e659cb 2000000007
87+
```
88+
```bash
89+
0xce2a2dd052bdbcf7fffc309e2a5e1f8589513335f85232a6c8cfb4a7d49ee32b
90+
```
91+
92+
### Address Encoding
93+
94+
Using the `address` command you can encode and decode adresses. For example:
95+
96+
```bash
97+
coinset address encode 0xbf3d35bba83d984be6cc4db0d6c84922e275a39ca4f8e1dd3cddfe2fa5eb2e2f
98+
```
99+
```bash
100+
xch1hu7ntwag8kvyhekvfkcddjzfyt38tguu5nuwrhfumhlzlf0t9chs6cj5k8
101+
```
102+
103+
```bash
104+
coinset address decode xch1hu7ntwag8kvyhekvfkcddjzfyt38tguu5nuwrhfumhlzlf0t9chs6cj5k8
105+
```
106+
```bash
107+
0xbf3d35bba83d984be6cc4db0d6c84922e275a39ca4f8e1dd3cddfe2fa5eb2e2f
108+
```
109+
81110
### JQ Filtering
82111

83112
Using the `-q` option you can pass in a jq filter to be used on the output. For example:

internal/cmd/coinset/coin_id.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
7+
"github.com/chia-network/go-chia-libs/pkg/types"
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var coin types.Coin
13+
14+
func init() {
15+
rootCmd.AddCommand(coinIdCmd)
16+
}
17+
18+
var coinIdCmd = &cobra.Command{
19+
Use: "coin_id <parent_coin_id> <puzzle_hash> <amount>",
20+
Args: func(cmd *cobra.Command, args []string) error {
21+
if err := cobra.ExactArgs(3)(cmd, args); err != nil {
22+
return err
23+
}
24+
25+
// Parent
26+
if !isHex(args[0]) {
27+
return fmt.Errorf("invalid hex value specified: %s", args[0])
28+
}
29+
parent, err := types.Bytes32FromHexString(formatHex(args[0]))
30+
if err != nil {
31+
return fmt.Errorf("invalid hex value specified: %s", args[0])
32+
}
33+
coin.ParentCoinInfo = parent
34+
35+
// Puzzle Hash
36+
if !isHex(args[1]) {
37+
return fmt.Errorf("invalid hex value specified: %s", args[1])
38+
}
39+
puzzle_hash, err := types.Bytes32FromHexString(formatHex(args[1]))
40+
if err != nil {
41+
return fmt.Errorf("invalid hex value specified: %s", args[1])
42+
}
43+
coin.PuzzleHash = puzzle_hash
44+
45+
// Amount
46+
amount, err := strconv.ParseUint(args[2], 10, 64)
47+
if err != nil {
48+
return fmt.Errorf("invalid amount: %s", args[2])
49+
}
50+
coin.Amount = amount
51+
52+
return nil
53+
},
54+
Short: "Compute a coin id from parent, puzzle and amount",
55+
Long: `Compute a coin id from parent, puzzle and amount`,
56+
Run: func(cmd *cobra.Command, args []string) {
57+
fmt.Printf("%s\n", coin.ID().String())
58+
},
59+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func init() {
10+
rootCmd.AddCommand(getPuzzleAndSolutionWithConditionsCmd)
11+
}
12+
13+
var getPuzzleAndSolutionWithConditionsCmd = &cobra.Command{
14+
Use: "get_puzzle_and_solution_with_conditions <name>",
15+
Args: func(cmd *cobra.Command, args []string) error {
16+
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
17+
return err
18+
}
19+
if isHex(args[0]) {
20+
return nil
21+
}
22+
return fmt.Errorf("invalid hex value specified: %s", args[0])
23+
},
24+
Short: "Retrieves a coin's spend record by its name including conditions",
25+
Long: "Retrieves a coin's spend record by its name including conditions",
26+
Run: func(cmd *cobra.Command, args []string) {
27+
jsonData := map[string]interface{}{}
28+
jsonData["coin_id"] = formatHex(args[0])
29+
makeRequest("get_puzzle_and_solution_with_conditions", jsonData)
30+
},
31+
}

0 commit comments

Comments
 (0)