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

feat: cli option to decode serialized Clarity values #1599

Merged
merged 3 commits into from
Nov 28, 2023
Merged

Conversation

zone117x
Copy link
Member

@zone117x zone117x commented Nov 27, 2023

This PR was published to npm with the version 6.9.1-pr.b33d848.0
e.g. npm install @stacks/[email protected] --save-exact

Description

New CLI feature to decode Clarity values into json/repr/pretty strings.

Example

The repr format string is returned by default:

$ stx decode_cv 0b00000003000000000000000000000000000000000100000000000000000000000000000000020000000000000000000000000000000003
(list 1 2 3)

Use --format json to output JSON:

$ stx decode_cv --format json 0b00000003000000000000000000000000000000000100000000000000000000000000000000020000000000000000000000000000000003
{"type":"(list 3 int)","value":[{"type":"int","value":"1"},{"type":"int","value":"2"},{"type":"int","value":"3"}]}

Use --format pretty to output a pretty-print repr string:

$ stx decode_cv --format pretty 0b00000003000000000000000000000000000000000100000000000000000000000000000000020000000000000000000000000000000003
(list
  1
  2
  3
)

Values can also be piped into the command by using - in place of the value:

$ echo 0x050011deadbeef11ababffff11deadbeef11ababffff | stx decode_cv --format json -
{"type":"principal","value":"S08XXBDYXW8TQAZZZW8XXBDYXW8TQAZZZZ88551S"}

Real world example of decoding output from a Stacks node RPC call:

$ curl -sX POST 'https://stacks-node-api.testnet.stacks.co/v2/map_entry/ST000000000000000000002AMW42H/pox-3/delegation-state?proof=0' -H 'Content-Type: application/json' -d '"0x0c0000000107737461636b65720515f1a77e086d9de40dfa879175c4fb22f426950c5d"' | jq -r .data | stx decode_cv --format pretty -
(some {
  amount-ustx: u10000000,
  delegated-to: 'SND3WM4FYSYFZM2C8K62K1XJD97W6YTXET0N4C6A,
  pox-addr: none,
  until-burn-ht: (some u2540805)
})

Checklist

Copy link

vercel bot commented Nov 27, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
stacksjs-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 27, 2023 4:52pm

Copy link

codecov bot commented Nov 27, 2023

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (debeb00) 66.18% compared to head (f4ad89d) 66.31%.
Report is 31 commits behind head on main.

❗ Current head f4ad89d differs from pull request most recent head b33d848. Consider uploading reports for the commit b33d848 to get more accurate results

Files Patch % Lines
packages/cli/src/cli.ts 82.35% 3 Missing ⚠️
packages/transactions/src/clarity/prettyPrint.ts 93.33% 3 Missing ⚠️
packages/transactions/src/cl.ts 60.00% 2 Missing ⚠️
packages/transactions/src/transaction.ts 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1599      +/-   ##
==========================================
+ Coverage   66.18%   66.31%   +0.13%     
==========================================
  Files         118      119       +1     
  Lines        8640     8690      +50     
  Branches     1908     1914       +6     
==========================================
+ Hits         5718     5763      +45     
- Misses       2685     2802     +117     
+ Partials      237      125     -112     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

packages/cli/src/cli.ts Show resolved Hide resolved
packages/cli/src/argparse.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@janniks janniks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very useful!! 🎉

@zone117x zone117x merged commit 25c821b into main Nov 28, 2023
8 checks passed
@zone117x zone117x deleted the feat/cli-cv-decode branch November 28, 2023 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants