Skip to content

Commit

Permalink
contract-fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
naveen-2111-dev committed Jan 24, 2025
1 parent 861cc77 commit 31ded58
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/file.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ pragma solidity ^0.8.13;
/// @title A Decentralized File Storage Contract
/// @author naveen_rajan m
/// @notice This contract allows users to store files on Arweave and manage metadata with burning and access control features.
contract Storage {
contract Storage {
/// @dev Event emitted when a file is successfully stored.
/// @param file, The transaction ID of the stored file on Arweave.
/// @param sender The address that uploaded the file.
/// @param count The ID of the file in the mapping or head of the stack kinda thing.
event Success(string file, address sender, uint256 count);


/// @dev Event emitted when a file is burned (removed from access).
/// @param file_Tx_id The transaction ID of the burned file.
/// @param burner The address that burned the file.
Expand All @@ -33,15 +32,15 @@ contract Storage {
bool hasAccess;
}

mapping (uint256 => Files) public stored_files;
mapping(uint256 => Files) public stored_files;
uint256 private count = 0;
uint256 private limit = 0;

/// @notice Stores metadata for a file on Arweave.
/// @dev This function adds the caller as the first access holder for the file.
/// @param _arweaveTxId The transaction ID from Arweave.
function SaveFile_metadata(string memory _arweaveTxId) external {
require(bytes(_arweaveTxId).length > 0 , "required a file Tx_id.../");
require(bytes(_arweaveTxId).length > 0, "required a file Tx_id.../");
count++;

Files storage newFile = stored_files[count];
Expand All @@ -58,18 +57,15 @@ contract Storage {
/// @param file_id The ID of the file to retrieve.
/// @return arweaveTxId The Arweave transaction ID of the file.
/// @return user The owner address of the file.
function Retrieve_files(uint256 file_id ) external view returns(string memory, address) {
require(file_id > 0 , "required file_id greater than zero.../");
function Retrieve_files(uint256 file_id) external view returns (string memory, address) {
require(file_id > 0, "required file_id greater than zero.../");
require(file_id <= count, "File ID does not exist");
Files storage files = stored_files[file_id];
require(
files.user != dead_state,
"File has been burned"
);
require(files.user != dead_state, "File has been burned");

bool IsAccess = false;
for (uint i = 0; i < files.access_holders.length; i++) {
if(files.access_holders[i] == msg.sender){
for (uint256 i = 0; i < files.access_holders.length; i++) {
if (files.access_holders[i] == msg.sender) {
IsAccess = true;
break;
}
Expand All @@ -80,9 +76,9 @@ contract Storage {

/// @notice Burns a file, making it inaccessible to anyone through ui.
/// @dev The file owner can burn the file, removing all access holders.
/// @param file_id The ID of the file to burn.
function Burn_file(uint256 file_id) external {
require(file_id > 0 , "required file_id greater than zero.../");
/// @param file_id The ID of the file to burn.
function Burn_file(uint256 file_id) external {
require(file_id > 0, "required file_id greater than zero.../");
require(file_id <= count, "File ID does not exist");
Files storage burn = stored_files[file_id];

Expand All @@ -98,15 +94,15 @@ contract Storage {
/// @dev The file owner can only add other peer_users of the file.
/// @param file_id The ID of the file to add access persons/address.
/// @param user address of the person who need access to this file.
function Addaccess_holders(uint256 file_id ,address user) external {
require(file_id > 0 , "required file_id greater than zero.../");
function Addaccess_holders(uint256 file_id, address user) external {
require(file_id > 0, "required file_id greater than zero.../");
require(file_id <= count, "File ID does not exist");
Files storage file = stored_files[file_id];

require(file.user == msg.sender, "Only the file_owner can grant access");

file.access_holders.push(user);
file.hasAccess = true;
emit IsAccess_accepted(user,file.arweaveTxId);
emit IsAccess_accepted(user, file.arweaveTxId);
}
}

0 comments on commit 31ded58

Please # to comment.