Skip to content

Commit

Permalink
Update Contract.sol to resolve iiitl#6
Browse files Browse the repository at this point in the history
extract the names of all sellers to display them on a new page by adding two functions addSeller and getAllSellers
  • Loading branch information
salonii04 authored Mar 17, 2024
1 parent 2f27a9c commit 8301675
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions contracts/Contract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ interface IERC721 {
);
}
contract Contract {

address[] public sellers; // to store addresses of sellers
mapping(address => string) public sellerNames; // to associate seller name with address
function addSeller(string memory name) public {
require(bytes(name).length > 0, "Name cannot be empty");
sellers.push(msg.sender);
sellerNames[msg.sender] = name;
}

function getAllSellers() public view returns (address[] memory, string[] memory) {
uint256 sellerCount = sellers.length;
address[] memory sellerAddresses = new address[](sellerCount);
string[] memory sellerNamesArray = new string[](sellerCount);
for (uint256 i = 0; i < sellerCount; i++) {
sellerAddresses[i] = sellers[i];
sellerNamesArray[i] = sellerNames[sellers[i]];
}
return (sellerAddresses, sellerNamesArray);
}


address public nftaddress;
address payable public seller;
mapping(uint256 => address) public buyer;
Expand Down

0 comments on commit 8301675

Please sign in to comment.