1.0.1 • Published 11 months ago

@skalenetwork/filestorage v1.0.1

Weekly downloads
10
License
AGPL-3.0
Repository
github
Last release
11 months ago

SKALE Filestorage

Build Status codecov Discord

Filestorage - smart contract, that controls decentralized file storage on SKALE chains.

Description

Filestorage is a cost-effective storage layer within Ethereum capable of handling files up to 100MB. Filestorage uses UNIX-based filesystem of SKALE chains. Filestorage smart contract is a set of functions to interact with files on EVM. This contract may be predeployed on SKALE chains. It contains functions to work with Filestorage precompiled smart contracts.

Smart contract language - Solidity 0.5.3

API Reference

File interaction methods

To begin the uploading process, the file should be broken into chunks of 1MB (< 1MB for the last chunk) which are uploaded as separate transactions to FileStorage.sol. The pipeline of the uploading file is:

  1. creating empty file of fixed size on EVM by calling startUpload,
  2. uploading data chunk by chunk with uploadChunk,
  3. checking the file validity and finishing process with finishUpload.

startUpload

function startUpload(string memory filePath, uint256 fileSize)

Creates empty file on EVM with specific name and size. Owner of the file - message sender.

  • Function is called by file owner
  • Maximum amount of directories and files in one directory is 8196
  • Maximum filesize is 100,000,000 bytes
  • Owner should have enough free space

Parameters:

ParameterDescription
string filePathPath to the file in account directory
uint256 fileSizeUploaded file size in bytes

uploadChunk

function uploadChunk(string memory filePath, uint position, bytes memory data)

Uploads 1MB chunk of data from specific position in specific file by file owner.

  • Function is called by file owner.

Parameters:

ParameterDescription
string filePathPath to the file in account directory
uint positionUploaded chunk position
bytes dataUploaded chunk data

finishUpload

function finishUpload(string memory filePath)

Finishes uploading of the file. Checks whether all chunks are uploaded correctly.

  • Function is called by file owner.

Parameters:

ParameterDescription
string filePathPath to the file in account directory

deleteFile

function deleteFile(string memory filePath)

Deletes file from Filestorage.

  • Function is called by file owner.

Parameters:

ParameterDescription
string filePathPath to the file in account directory

readChunk

function readChunk(string memory storagePath, uint position, uint length)
        public
        view
        returns (bytes32[MAX_BLOCK_COUNT] memory out)

Reads chunk from file from specific position with specific length. Returns bytes32 array of fixed size with requested data.

  • Maximum length of the chunk to read is 1Mb

Parameters:

ParameterDescription
string storagePathFull path of the file in Filestorage
uint positionFirst byte to read from
uint lengthUploaded chunk length

Returns:

ParameterDescription
bytes32[] outRequested chunk data split across bytes32 array

getFileSize

function getFileSize(string memory storagePath) 
        public 
        view 
        returns (uint fileSize)

Gets size of the requested file in bytes.

Parameters:

ParameterDescription
string storagePathFull path of the file in Filestorage

Returns:

ParameterDescription
uint fileSizeSize of requested file

getFileStatus

function getFileStatus(string memory storagePath) 
        public 
        view 
        returns (int)

Returns status of the requested file:

  • 0 - file does not exist
  • 1 - file is created but has not finished uploading
  • 2 - file is fully uploaded

Parameters:

ParameterDescription
string storagePathFull path of the file in Filestorage

Returns:

ParameterDescription
uint fileStatusStatus of requested file

Directory interaction methods

Filestorage is represented with UNIX-based filesystem that consisted of files and directories. Directories are stored in Directory structure that contains information about its content in ContentInfo structure. Maximum amount of content in separate directory is 8196.

createDirectory

function createDirectory(string memory directoryPath)

Creates directory in Filestorage. Owner of the directory - message sender.

  • Function is called by directory owner
  • Maximum amount of directories and files in one directory is 8196

Parameters:

ParameterDescription
string directoryPathPath to the directory in account root directory

deleteDirectory

function deleteDirectory(string memory directoryPath)

Deletes directory from Filestorage.

  • Function is called by directory owner

Parameters:

ParameterDescription
string directoryPathPath to the directory in account root directory

listDirectory

function listDirectory(string memory storagePath) 
        public 
        view 
        returns (ContentInfo[])

List information about content of the specific directory.

Parameters:

ParameterDescription
string storagePathFull path of the directory in Filestorage

Returns:

ParameterDescription
ContentInfo[]Array of content stored in directory

Object ContentInfo can be file or directory and contains:

FieldDescription
string nameContent name
bool isFileWhether content is file
uint sizeFile size, in bytes
int statusFile uploading status
bool[] isChunkUploadedArray with statuses of each chunk (true - chunk uploaded, false - otherwise)

Build

Create an .env file with following data:

ENTRYPOINT='SKALE endpoint'
PRIVATEKEY='Private key for test account'

Compile FileStorage.sol:

truffle compile

Test

Tests run only on SKALE chains. Create an .env file with following data:

ENTRYPOINT='SKALE endpoint'
SCHAIN_OWNER_PK='Private key of SKALE endpoint owner (or account with money)'
PRIVATEKEY='Private key for test account'

Run tests:

truffle test --network skaled
1.1.0-beta.3

11 months ago

1.1.0-develop.8

1 year ago

1.1.0-develop.7

1 year ago

1.1.0-develop.6

2 years ago

1.1.0-beta.2

2 years ago

1.1.0-develop.5

2 years ago

1.1.0-develop.4

2 years ago

1.1.0-beta.1

2 years ago

1.1.0-develop.3

2 years ago

1.1.0-develop.2

2 years ago

1.1.0-develop.1

2 years ago

1.1.0-beta.0

2 years ago

1.0.1

2 years ago

1.0.1-beta.2

2 years ago

1.0.1-develop.14

2 years ago

1.0.1-develop.13

2 years ago

1.0.1-develop.12

2 years ago

1.0.1-beta.3

2 years ago

1.0.1-beta.1

2 years ago

1.0.1-develop.11

2 years ago

1.0.1-beta.0

2 years ago

1.0.1-develop.10

2 years ago

1.0.1-develop.3

3 years ago

1.0.1-develop.5

3 years ago

1.0.1-develop.7

3 years ago

1.0.1-develop.6

3 years ago

1.0.1-develop.9

2 years ago

1.0.1-develop.8

2 years ago

1.0.1-develop.2

3 years ago

1.0.1-develop.1

3 years ago

1.0.1-develop.0

3 years ago

1.0.0-develop.5

3 years ago

1.0.0-develop.4

3 years ago

1.0.0-develop.3

3 years ago

1.0.0-develop.2

3 years ago

1.0.0-develop.1

3 years ago

1.0.0-develop.0

3 years ago

0.4.0-develop.1

4 years ago