Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve 'bought' Function to Stop Direct Payment to Seller #3 #26

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions contracts/Contract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface IERC721 {
address _from,
address _to,
uint256 _id
);
)external;
}
contract Contract {
address public nftaddress;
Expand All @@ -20,21 +20,21 @@ contract Contract {
seller = _seller;
}
struct adds{
string memory city;
string memory country;
string memory addline;
string city;
string country;
string addline;
}
struct Property {
string memory name;
string memory email;
string memory phoneno;
string name;
string email;
string phoneno;
adds adds;
string memory proptype;
string memory amenities;
string proptype;
string amenities;
uint256 sqfoot;
uint256 bedno;
string memory img;
string memory descp;
string img;
string descp;
}


Expand All @@ -51,11 +51,12 @@ contract Contract {

function list1(
uint256 _nftID,
string _amenities,
// memory used to pass strings that won't be stored after function ends
string memory _amenities,
uint256 _sqfoot,
uint256 _bedno,
string _img,
string _descp,
string memory _img,
string memory _descp,
uint256 _purchasePrice,
uint256 _tokenID)public {
IERC721(nftaddress).transferFrom(seller, address(this), _tokenID);
Expand Down Expand Up @@ -101,13 +102,20 @@ contract Contract {
receive() external payable {}


function bought(uint256 _nftID,uint256 _tokenID) public onlyBuyer(_nftID) {
require(msg.value == purchasePrice[_nftID]);
(bool success, ) = (seller).call{value: address(this).balance}("");
isListed[_nftID] = false;
IERC721(nftaddress).transferFrom(address(this), buyer[_nftID], _tokenID);
}

function bought(uint256 _nftID,uint256 _tokenID) public payable onlyBuyer(_nftID) { //make the function payable to accept ether

require(msg.value == purchasePrice[_nftID], "Incorrect purchase price.");
require(isListed[_nftID] == true, "NFT is not listed for sale.");

//make seller address payable
address payable sellerAddress = payable(seller);
(bool success, ) = sellerAddress.call{value: msg.value}("");
require(success, "Transfer failed.");

isListed[_nftID] = false;
IERC721(nftaddress).transferFrom(address(this), msg.sender, _tokenID); //transfer the nft to the buyer
}

function getBalance() public view returns(uint256) {
return address(this).balance;
Expand Down