Skip to content

Conversation

@mixmix
Copy link
Contributor

@mixmix mixmix commented May 5, 2025

Had a go at implementing encode/ decode on goset claim messages

🔥 This PR is missing the calculation of GOSET_CLAIM_DMX (needs some string encoding + hashing)

@mixmix mixmix requested review from Copilot and pietgeursen May 5, 2025 01:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

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)
// ```
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🔥 TODO

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
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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!

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.

2 participants