stacks-network / stacks-network/stacks-core

Add inverse of `buff-to-*` functions

Open
#7,147 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

clarity-new-builtin clarity-next-candidate
Dominant language
Rust
Stars
3.1k
Forks
762
Avg merge
4d 6h
Merged PRs (30d)
76

Description

Clarity provides functions to read byte buffers, but it should provide functions to write them too. It is currently possible, although awkward, to do this with to-consensus-buff?. For example, I wrote a function uint-to-buff-be:

(define-private (uint-to-buff-be (n uint))
  (unwrap-panic (slice? (unwrap-panic (to-consensus-buff? n)) u1 u17)))

But it's inefficient and I'd rather not have the unwrap-panics in there, as this should be infallible code. It should just be part of the language like the buffer read functions

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing Clarity buff-to-* functions and the to-consensus-buff? implementation referenced in the issue. Determine the intended inverse functions and their behavior for the supported integer types, then add coverage for infallible big-endian buffer conversion without requiring unwrap-panic.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.