From f3a2cf16480ca71853354c1fd0b451f7b98c34f1 Mon Sep 17 00:00:00 2001 From: RickyShao Date: Thu, 4 Jul 2024 18:04:25 +0800 Subject: [PATCH] feat(nft-market): add getAllListings function and update README MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement a new function `getAllListings` in the NFTMarket contract to allow 外部调用者获取所有上市的信息。此外, 更新了README以反映新的合约地址。 --- members/veithly/task3/NFTMarket.sol | 16 +++++++++++++--- members/veithly/task3/README.md | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/members/veithly/task3/NFTMarket.sol b/members/veithly/task3/NFTMarket.sol index 4f70799d8..675bd9ec1 100644 --- a/members/veithly/task3/NFTMarket.sol +++ b/members/veithly/task3/NFTMarket.sol @@ -1,4 +1,5 @@ -pragma solidity ^0.8.0; +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; @@ -19,7 +20,7 @@ contract NFTMarket is Ownable { event NFTListed(uint256 listingId, address seller, address nftContract, uint256 tokenId, uint256 price); event NFTBought(uint256 listingId, address buyer); - constructor(address _currencyToken) { + constructor(address _currencyToken) Ownable(msg.sender) { currencyToken = IERC20(_currencyToken); } @@ -45,4 +46,13 @@ contract NFTMarket is Ownable { emit NFTBought(_listingId, msg.sender); } -} \ No newline at end of file + + + function getAllListings() external view returns (Listing[] memory) { + Listing[] memory allListings = new Listing[](listingCount); + for (uint256 i = 1; i <= listingCount; i++) { + allListings[i-1] = listings[i]; + } + return allListings; + } +} diff --git a/members/veithly/task3/README.md b/members/veithly/task3/README.md index f72101d92..c1e7d88c8 100644 --- a/members/veithly/task3/README.md +++ b/members/veithly/task3/README.md @@ -1,2 +1,2 @@ -List NFT: 0x9a659e39b29263ef2817c26a359e299580c1027982a27658dc486546adfa1097 -Buy NFT: 0x0b2f69f185a4936410509a1c16b8f5f5e5c0734ead93b871486cd00a7254d8a2 \ No newline at end of file +List NFT: 0xf563a73569698f80a82eab21e4ba4eaf5c73db5e85a398f03e7fa5aef2ca5e35 +Buy NFT: 0x7948cece92264265a0008d458f18f7f421036f95982082f1908ea712abf4a50d \ No newline at end of file