Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add address subcommand to encode/decode address to/from puzzle hash #2

Merged
merged 10 commits into from
Sep 24, 2024

Conversation

leonid-ed
Copy link
Contributor

@leonid-ed leonid-ed commented Mar 10, 2024

This PR aims to add a new subcommand address:

  • address encode to encode address to puzzle hash
  • address decode to decode address from puzzle hash

Examples of usages:

$ coinset address encode xch1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqm6ks6e8mvy
{
  "address": "xch1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqm6ks6e8mvy",
  "puzzle_hash": "0x000000000000000000000000000000000000000000000000000000000000dead"
}

$ coinset address encode txch1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqm6ksh7qddh
{
  "address": "txch1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqm6ksh7qddh",
  "puzzle_hash": "0x000000000000000000000000000000000000000000000000000000000000dead"
}

$ coinset address decode 000000000000000000000000000000000000000000000000000000000000dead
{
  "address": "xch1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqm6ks6e8mvy",
  "puzzle_hash": "0x000000000000000000000000000000000000000000000000000000000000dead"
}

# it is allowed to pass puzzle hash argument values with the prefix '0x'
$ coinset address decode 0x000000000000000000000000000000000000000000000000000000000000dead
{
  "address": "xch1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqm6ks6e8mvy",
  "puzzle_hash": "0x000000000000000000000000000000000000000000000000000000000000dead"
}

# -t argument to use the testnet address prefix 'txch'
$ coinset address decode 000000000000000000000000000000000000000000000000000000000000dead -t
{
  "address": "txch1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqm6ksh7qddh",
  "puzzle_hash": "0x000000000000000000000000000000000000000000000000000000000000dead"
}

Also it adds the following help output for the new subcommand:

$ coinset address -h
Encode/decode address to/from puzzle hash.

Usage:
  coinset address [command]

Available Commands:
  decode      Decode address from puzzle hash
  encode      Encode address to puzzle hash

Flags:
  -h, --help   help for address

Global Flags:
  -q, --query string   filter to apply using jq syntax (default ".")
  -r, --raw            display output in raw json

Use "coinset address [command] --help" for more information about a command.

@cameroncooper
Copy link
Contributor

Thank you for adding this. Sorry I didn't see it until now. I like what you've done here. I've thought about adding things like this from cdv. I'm inclined to merge it as-is but I'd like to take a minute to think about the precent and see if this is in line with how we might want to do similar features in the future.

@cameroncooper
Copy link
Contributor

I think my main concern here is with the name get_address_by_puzzle_hash which looks like a RPC call but isn't. What would you think about using the encode/decode terminology used by cdv? Maybe coinset address encode 0x00000... and coinset address decode txch1qqqqqqqq. This leaves open opportunities for things like coinset clvm encode and coinset clvm decode.

What do you think @leonid-ed ?

@cameroncooper
Copy link
Contributor

@cmmarslender is this version of go-chia-libs ok or should we update?

@cmmarslender
Copy link

@cmmarslender is this version of go-chia-libs ok or should we update?

0.14.2 is latest, though the packages used here likely haven't changed since the version here (though that also should make this a fairly easy thing to update in the PR real quick)

@leonid-ed leonid-ed force-pushed the puzzle-hash-to-address branch from acc6c33 to 06a8dd1 Compare September 20, 2024 17:55
@leonid-ed leonid-ed changed the title add get_puzzle_hash_by_address, get_address_by_puzzle_hash add address subcommand to encode/decode address to/from puzzle hash Sep 20, 2024
@leonid-ed
Copy link
Contributor Author

@cameroncooper Thank you for review! Yes, your suggestion makes sense, I agree. I've updated the PR accordingly, please take a look.

@leonid-ed leonid-ed changed the title add address subcommand to encode/decode address to/from puzzle hash add address subcommand to encode/decode address to/from puzzle hash Sep 20, 2024
@leonid-ed leonid-ed force-pushed the puzzle-hash-to-address branch from 746edfc to 4851a9f Compare September 20, 2024 18:24
@leonid-ed
Copy link
Contributor Author

@cameroncooper I've also bumped up go-chia-libs version to 0.15.0 (the latest version released yesterday), but looks like it requires [email protected] and go.mod has been updated automatically, so now it also requires go version 1.21.

If this is an issue, then let me know and I will revert that change.

@leonid-ed leonid-ed force-pushed the puzzle-hash-to-address branch 2 times, most recently from ad3efff to 02009f0 Compare September 22, 2024 07:30
@leonid-ed leonid-ed force-pushed the puzzle-hash-to-address branch from 02009f0 to 237bd9f Compare September 22, 2024 12:46
@cameroncooper
Copy link
Contributor

cameroncooper commented Sep 24, 2024

I just pushed some changes, please see if you like them.

I made some tweaks to the naming so it's like:

coinset address decode <address>
coinset address encode <puzzle hash>

I removed the JSON formatting from these results because it felt unnecessary since they were not coming from the RPC server, but tell me if you disagree.

But while I was reverting the refactor to the JSON output, I made some tweaks while I was in there. I made it so you can use -q and -r at the saw time, which I thought would be nice.

@leonid-ed
Copy link
Contributor Author

@cameroncooper Your changes look good to me! Thank you!

commit 0481ae6
Author: Cameron Cooper <[email protected]>
Date:   Tue Sep 24 15:01:33 2024 -0500

    tag and release on push to main

commit 7cfe6cf
Author: Cameron Cooper <[email protected]>
Date:   Tue Sep 24 14:53:20 2024 -0500

    fix build tagging

commit dcbe259
Author: Cameron Cooper <[email protected]>
Date:   Tue Sep 24 14:50:37 2024 -0500

    fix build tagging

commit a833296
Author: cameroncooper <[email protected]>
Date:   Tue Sep 24 14:43:36 2024 -0500

    added get_aggsig_additional_data command (coinset-org#5)

    * added get_aggsig_additional_data command
@cameroncooper cameroncooper merged commit 1ac07ed into coinset-org:main Sep 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants