// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; contract AssetToken is ERC721Enumerable,Ownable{ using Counters for Counters.Counter; using SafeMath for uint256; string private _baseuri; Counters.Counter private _lasttokenID; mapping(address=>uint256) _EscrowMoney; //This will hold account of everyone who has put the money in escrow. mapping(uint256=>Asset) _AssetIdToAssetMap; //map asset sales data with asset id uint256[] public registeredAssets; //array to keep track of all registered assets. Each element of this array contains assetid passed at the time of registration mapping(uint256=>uint256) _TokenToAssetMap; //for each token holds the asset id it points to constructor() ERC721("ShareToWin","STW"){} struct Asset{ uint256 currentSalePrice; bool isAvailableForSale; uint256 AssetTokenID; } //This function will mint a new NFT. For each AssetID that is passed from the rest api, there is a NFT, represented by the token id, //that is associated. function registerAsset(uint256 assetID,uint256 salePrice,string calldata _uri) public returns(uint256 newTokenID) { _lasttokenID.increment(); newTokenID=_lasttokenID.current(); _safeMint(msg.sender, newTokenID); _baseuri=_uri; Asset memory newAsset; newAsset.currentSalePrice=salePrice; newAsset.isAvailableForSale=true; newAsset.AssetTokenID=newTokenID; _AssetIdToAssetMap[assetID]=newAsset; registeredAssets.push(assetID); _TokenToAssetMap[newTokenID]=assetID; emit AssetRegistered(newTokenID); return newTokenID; } //This function is part of the smart contract for convenience. This information can also be queried from the dynamoDb. function getAllRegisteredAsset() view public returns(uint256[] memory r){ return registeredAssets; } //For a given asset id, it will return asset last/current sale price,boolean to indicate if it is on sale, NFT id and the address of the current owner function getAssetByID(uint256 assetID) view public returns(uint256,bool,uint256,address){ return (_AssetIdToAssetMap[assetID].currentSalePrice,_AssetIdToAssetMap[assetID].isAvailableForSale,_AssetIdToAssetMap[assetID].AssetTokenID,ownerOf(_AssetIdToAssetMap[assetID].AssetTokenID)); } // Return the count of NFT token whose owner has indicated that they are willing to exchange these NFT. function getAssetOnSaleCount() view public returns(uint256){ uint totalAssetonMarket; for(uint i=0;i