| Listing 1. Smart contract code. |
|
pragma solidity 0.5.0;
contract DStorage { string public name = "DStorage"; uint public fileCount = 0; mapping(uint => File) public files; struct File { uint fileId; string fileHash; uint fileSize; string fileType; string fileName; string fileDescription; uint uploadTime; address payable uploader; } event FileUploaded( uint fileId, string fileHash, uint fileSize, string fileType, string fileName, string fileDescription, uint uploadTime, address payable uploader ); // ERC-20 Token implementation //The unique token can be used to ensure that only authorized participants can access the data, by providing a means of verifying the identity of the user attempting to access the information. string public constant symbol = "DST"; string public constant name = "DStorage Token"; uint8 public constant decimals = 18; uint256 public totalSupply; mapping(address => uint256) public balanceOf; event Transfer(address indexed from, address indexed to, uint256 value); constructor(uint256 initialSupply) public { totalSupply = initialSupply; balanceOf[msg.sender] = initialSupply; } function transfer(address _to, uint256 _value) public returns (bool success) { require(balanceOf[msg.sender] >= _value); balanceOf[msg.sender] -= _value; balanceOf[_to] += _value; emit Transfer(msg.sender, _to, _value); return true; } // File storage functions function uploadFile( string memory _fileHash, uint _fileSize, string memory _fileType, string memory _fileName, string memory _fileDescription ) public { require(bytes(_fileHash).length > 0, "File hash is required"); require(bytes(_fileType).length > 0, "File type is required"); require(bytes(_fileDescription).length > 0, "File description is required"); require(bytes(_fileName).length > 0, "File name is required"); require(msg.sender != address(0), "Uploader address is required"); require(_fileSize > 0, "File size must be greater than zero"); fileCount++; files[fileCount] = File( fileCount, _fileHash, _fileSize, _fileType, _fileName, _fileDescription, now, msg.sender ); emit FileUploaded( fileCount, _fileHash, _fileSize, _fileType, _fileName, _fileDescription, now, msg.sender ); } } |