Skip to content

Commit

Permalink
Refactor tag constants and add file chunk retrieval function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey committed Oct 10, 2024
1 parent 1358254 commit e43f64c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
1 change: 0 additions & 1 deletion smart-contract/assembly/contracts/deweb-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Context,
generateEvent,
setBytecode,
sha256,
transferCoins,
} from '@massalabs/massa-as-sdk';
import {
Expand Down
15 changes: 15 additions & 0 deletions smart-contract/assembly/contracts/internals/chunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ export function _getTotalChunk(hashLocation: StaticArray<u8>): u32 {
return bytesToU32(Storage.get(fileChunkCountKey(hashLocation)));
}

/**
* Retrieves a specific chunk of a file.
* @param hashLocation - The hash of the file location.
* @param index - The index of the chunk to retrieve.
* @returns The chunk data as a StaticArray<u8>.
* @throws If the chunk is not found in storage.
*/
export function _getFileChunk(
hashLocation: StaticArray<u8>,
index: u32,
): StaticArray<u8> {
assert(Storage.has(fileChunkKey(hashLocation, index)), 'Chunk not found');
return Storage.get(fileChunkKey(hashLocation, index));
}

/* -------------------------------------------------------------------------- */
/* DELETE */
/* -------------------------------------------------------------------------- */
Expand Down
12 changes: 6 additions & 6 deletions smart-contract/assembly/contracts/internals/storageKeys/tags.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { stringToBytes } from '@massalabs/as-types';

export const FILE_TAG: StaticArray<u8> = stringToBytes('\x01FILE');
export const FILE_LOCATION_TAG: StaticArray<u8> = stringToBytes('\x02LOCATION');
export const CHUNK_TAG: StaticArray<u8> = stringToBytes('\x03CHUNK');
export const CHUNK_NB_TAG: StaticArray<u8> = stringToBytes('\x04CHUNK_NB');
export const FILE_METADATA_TAG: StaticArray<u8> = stringToBytes('\x05FM');
export const GLOBAL_METADATA_TAG: StaticArray<u8> = stringToBytes('\x06GM');
export const FILE_TAG = stringToBytes('\x01FILE');
export const FILE_LOCATION_TAG = stringToBytes('\x02LOCATION');
export const CHUNK_TAG = stringToBytes('\x03CHUNK');
export const CHUNK_NB_TAG = stringToBytes('\x04CHUNK_NB');
export const FILE_METADATA_TAG = stringToBytes('\x05FM');
export const GLOBAL_METADATA_TAG = stringToBytes('\x06GM');
export const DEWEB_VERSION_TAG = stringToBytes('\xFFDEWEB_VERSION');

0 comments on commit e43f64c

Please sign in to comment.