tachybase_todo/packages/plugins/@tachybase/plugin-blockchain/contracts/DataStorage.sol
hua 54a7f5dc40 feat: blockchain (#1408)
Co-authored-by: root <root@huahua.daoyoucloud.com>
Co-authored-by: bai.zixv <bai.zixv@foxmail.com>
Co-authored-by: sealday <zhanglin@daoyoucloud.com>
Co-authored-by: TomyJan <TomyJan6@gmail.com>
Co-authored-by: luliangqiang <2650321653@qq.com>
Co-authored-by: yoona <1486343814@qq.com>
Co-authored-by: wjh <wwwjh0710@163.com>
Reviewed-on: daoyoucloud/tachybase#1408
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
Co-authored-by: hua <1494133104@qq.com>
Co-committed-by: hua <1494133104@qq.com>
2024-07-31 15:26:28 +08:00

32 lines
1.0 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract DataStorage {
struct Data {
string hashedData;
string salt;
}
mapping(uint256 => Data) private data;
event DataStored(uint256 indexed id, string hashedData, string salt);
event DataDeleted(uint256 indexed id);
function storeData(uint256 id, string memory hashedData, string memory salt) public {
require(bytes(data[id].hashedData).length == 0, "Data already exists for this ID");
data[id] = Data(hashedData, salt);
emit DataStored(id, hashedData, salt);
}
function getData(uint256 id) public view returns (string memory hashedData, string memory salt) {
Data storage item = data[id];
require(bytes(item.hashedData).length != 0, "Data not found");
return (item.hashedData, item.salt);
}
function deleteData(uint256 id) public {
require(bytes(data[id].hashedData).length != 0, "Data not found");
delete data[id];
emit DataDeleted(id);
}
}