Seleziona un annuncio e pubblicalo su IPFS, poi scrivi hash/CID on-chain.
Contratto Solidity da deployare
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract MarketplaceCidRegistry {
struct ListingRef {
address seller;
bytes32 contentHash;
string cid;
uint256 timestamp;
bool active;
}
ListingRef[] private listings;
event ListingPublished(
uint256 indexed listingId,
address indexed seller,
bytes32 indexed contentHash,
string cid,
uint256 timestamp
);
event ListingStatusChanged(uint256 indexed listingId, bool active);
function publishListing(bytes32 contentHash, string calldata cid) external returns (uint256 listingId) {
require(contentHash != bytes32(0), "HASH_ZERO");
require(bytes(cid).length > 0, "CID_EMPTY");
listingId = listings.length;
listings.push(ListingRef({
seller: msg.sender,
contentHash: contentHash,
cid: cid,
timestamp: block.timestamp,
active: true
}));
emit ListingPublished(listingId, msg.sender, contentHash, cid, block.timestamp);
}
function setActive(uint256 listingId, bool active) external {
require(listingId < listings.length, "BAD_ID");
require(listings[listingId].seller == msg.sender, "NOT_SELLER");
listings[listingId].active = active;
emit ListingStatusChanged(listingId, active);
}
function getListing(uint256 listingId) external view returns (ListingRef memory) {
require(listingId < listings.length, "BAD_ID");
return listings[listingId];
}
function totalListings() external view returns (uint256) {
return listings.length;
}
}