Skip to content

Instantly share code, notes, and snippets.

@Khanisic
Created August 14, 2022 17:57
Show Gist options
  • Save Khanisic/c43747b79e6bee21d71243fd0c03fe00 to your computer and use it in GitHub Desktop.
Save Khanisic/c43747b79e6bee21d71243fd0c03fe00 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.16+commit.07a7930e.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.15;
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract MVR is ERC721URIStorage{
// address of the owner
address payable owner;
// pause minting
bool public paused = false;
constructor() ERC721 ("MVR Shares", "MVR"){
owner = payable(msg.sender);
}
// Counters from library
using Counters for Counters.Counter;
// to count the number of tokens in the contract
Counters.Counter private _tokenIds;
Counters.Counter private _itemsSold;
// access to tht owner
modifier onlyOwner {
require(msg.sender == owner);
_;
}
struct PropertyItem{
address owner;
}
mapping ( uint => PropertyItem ) idToProperty;
function fetchMarketItems() public view returns (PropertyItem[] memory) {
uint itemCount = _tokenIds.current();
uint unsoldItemCount = _tokenIds.current() - _itemsSold.current();
uint currentIndex = 0;
PropertyItem[] memory items = new PropertyItem[](unsoldItemCount);
for (uint i = 0; i < itemCount; i++) {
if (idToProperty[i + 1].owner == address(this)) {
uint currentId = i + 1;
PropertyItem storage currentItem = idToProperty[currentId];
items[currentIndex] = currentItem;
currentIndex += 1;
}
}
return items;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment