Open
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements encoding and decoding for goset claim messages and updates related helper functions.
- Added encode/decode functionality for GOSetClaim with proper construction of the claim message.
- Updated the count and xor methods in GOSet, and added related tests.
- Introduced a public LENGTH constant for FeedId and GOSetXor to support the new implementations.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/lib.rs | Removed unused imports and commented out deprecated code |
| src/go_set/mod.rs | Implemented count and improved xor method with tests |
| src/go_set/go_set_xor.rs | Added LENGTH constant and exposed encoding functionality |
| src/go_set/go_set_claim.rs | Implemented encode and decode for goset claims with error handling |
| src/feed_id.rs | Added LENGTH constant to support encoding |
mixmix
commented
May 5, 2025
Comment on lines
+21
to
+26
| const GOSET_DMX: [u8; 7] = [0, 1, 2, 3, 4, 5, 6]; | ||
| // TODO: calculate actual DMX | ||
| // ``` | ||
| // GOSET_DMX_MATERIAL = "tinySSB-0.1 GOset 1" | ||
| // GOSET_DMX = first 7 bytes of SHA256(GOSET_DMX_MATERIAL) | ||
| // ``` |
mixmix
commented
May 5, 2025
src/go_set/go_set_claim.rs
Outdated
Comment on lines
28
to
61
| pub fn encode(go_set: &GOSet) -> [u8; 105] { | ||
| // NOTE: we're gonna want to make a range of claims | ||
| // 1. how do we deal with the concept of a "subset" of a claim? | ||
| // 2. where does the logic live about comparing a claim with a goset? | ||
| // 3. what's the algorithm for the claim-dance? | ||
|
|
||
| // [DMX (7B) | 'c' (1 byte) | lowest FeedId (32 bytes) | highest FeedId (32 bytes) | XOR (32 bytes) | cnt (1 byte) ] | ||
| let mut claim = [0; 105]; | ||
|
|
||
| let dmx = Self::GOSET_DMX; | ||
| let type_code: [u8; 1] = [b'c']; | ||
| let lowest_feed_id = go_set.lowest_feed_id().unwrap().encode(); | ||
| let highest_feed_id = go_set.highest_feed_id().unwrap().encode(); | ||
| let xor = go_set.xor().encode(); | ||
| let count: [u8; 1] = [go_set.count()]; | ||
|
|
||
| let chunks: [&[u8]; 6] = [ | ||
| &dmx, | ||
| &type_code, | ||
| &lowest_feed_id, | ||
| &highest_feed_id, | ||
| &xor, | ||
| &count, | ||
| ]; | ||
|
|
||
| let mut offset: usize = 0; | ||
| for chunk in chunks { | ||
| let len = chunk.len(); | ||
| claim[offset..offset + len].copy_from_slice(chunk); | ||
| offset += len; | ||
| } | ||
|
|
||
| claim | ||
| } |
Contributor
Author
There was a problem hiding this comment.
This is the tidiest / most readable way I could write the pattern of concatenating / splitting.
I'm quite interested to know if there is a tidier was to concat/ split, as this feels... somewhat clunky (esp for concat).
ChatGPT suggested copy_from_slice which I was delighted to find. I was doing byte-wise copying before that!
Make some suggestions
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Had a go at implementing encode/ decode on goset
claimmessages🔥 This PR is missing the calculation of
GOSET_CLAIM_DMX(needs some string encoding + hashing)