Skip to content

Commit

Permalink
feat(nft-market): add getAllListings function and update README
Browse files Browse the repository at this point in the history
Implement a new function `getAllListings` in the NFTMarket contract to allow
外部调用者获取所有上市的信息。此外, 更新了README以反映新的合约地址。
  • Loading branch information
veithly committed Jul 4, 2024
1 parent 41fc624 commit f3a2cf1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 13 additions & 3 deletions members/veithly/task3/NFTMarket.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
}

Expand All @@ -45,4 +46,13 @@ contract NFTMarket is Ownable {

emit NFTBought(_listingId, msg.sender);
}
}


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;
}
}
4 changes: 2 additions & 2 deletions members/veithly/task3/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
List NFT: 0x9a659e39b29263ef2817c26a359e299580c1027982a27658dc486546adfa1097
Buy NFT: 0x0b2f69f185a4936410509a1c16b8f5f5e5c0734ead93b871486cd00a7254d8a2
List NFT: 0xf563a73569698f80a82eab21e4ba4eaf5c73db5e85a398f03e7fa5aef2ca5e35
Buy NFT: 0x7948cece92264265a0008d458f18f7f421036f95982082f1908ea712abf4a50d

0 comments on commit f3a2cf1

Please sign in to comment.