diff --git a/smart-contract/assembly/contracts/deweb-interface.ts b/smart-contract/assembly/contracts/deweb-interface.ts index bea20b9..0b7706a 100644 --- a/smart-contract/assembly/contracts/deweb-interface.ts +++ b/smart-contract/assembly/contracts/deweb-interface.ts @@ -3,7 +3,6 @@ import { Context, generateEvent, setBytecode, - sha256, transferCoins, } from '@massalabs/massa-as-sdk'; import { diff --git a/smart-contract/assembly/contracts/internals/chunks.ts b/smart-contract/assembly/contracts/internals/chunks.ts index 4400680..4d63a5e 100644 --- a/smart-contract/assembly/contracts/internals/chunks.ts +++ b/smart-contract/assembly/contracts/internals/chunks.ts @@ -44,6 +44,21 @@ export function _getTotalChunk(hashLocation: StaticArray): 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. + * @throws If the chunk is not found in storage. + */ +export function _getFileChunk( + hashLocation: StaticArray, + index: u32, +): StaticArray { + assert(Storage.has(fileChunkKey(hashLocation, index)), 'Chunk not found'); + return Storage.get(fileChunkKey(hashLocation, index)); +} + /* -------------------------------------------------------------------------- */ /* DELETE */ /* -------------------------------------------------------------------------- */ diff --git a/smart-contract/assembly/contracts/internals/storageKeys/tags.ts b/smart-contract/assembly/contracts/internals/storageKeys/tags.ts index fe08493..801ab4d 100644 --- a/smart-contract/assembly/contracts/internals/storageKeys/tags.ts +++ b/smart-contract/assembly/contracts/internals/storageKeys/tags.ts @@ -1,9 +1,9 @@ import { stringToBytes } from '@massalabs/as-types'; -export const FILE_TAG: StaticArray = stringToBytes('\x01FILE'); -export const FILE_LOCATION_TAG: StaticArray = stringToBytes('\x02LOCATION'); -export const CHUNK_TAG: StaticArray = stringToBytes('\x03CHUNK'); -export const CHUNK_NB_TAG: StaticArray = stringToBytes('\x04CHUNK_NB'); -export const FILE_METADATA_TAG: StaticArray = stringToBytes('\x05FM'); -export const GLOBAL_METADATA_TAG: StaticArray = 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');