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

bug: chunk address() function doesn't return valid address #23

Open
mfw78 opened this issue Jul 29, 2023 · 1 comment
Open

bug: chunk address() function doesn't return valid address #23

mfw78 opened this issue Jul 29, 2023 · 1 comment
Assignees

Comments

@mfw78
Copy link

mfw78 commented Jul 29, 2023

Problem
When retrieving a chunk by it's address from the /chunks bee API endpoint, inserting the payload with makeChunk then calculating the address() does not return the address of the chunk that I retrieved from the /chunks API endpoint.

Solution
address() should return the same as that which I retrieved from the /chunks bee API endpoint.

@mfw78
Copy link
Author

mfw78 commented Jul 29, 2023

After investigating this further, there really should be an example of how to use to the bmt-js library to achieve common purposes such as using the /bytes, and /chunks API endpoints, and validating the data that is received.

For posterity's sake, /chunks returns the Chunk which with the current case, the first 8 bytes is reserved for the span. By doing a slice(0, 8) on the payload, you get the little-endian uint64 for the span value, which can be passed into the makeChunk parameter for the initial span value. The data for the makeChunk would be set to the slice(8) of the payload returned from the /chunks endpoint.

For example:

const span = uint64LEToNumber(decoded.data.slice(0, 8));
const chunk = makeChunk(decoded.data.slice(8), {startingSpanValue: span})

Now, chunk.address() will return the same value as the /chunks/{address} that was used to retrieve the chunk.

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

No branches or pull requests

2 participants