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 #35

Closed
wants to merge 4 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
43 changes: 23 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,11 @@ contract Contract {

function list1(
uint256 _nftID,
string _amenities,
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,12 +101,15 @@ 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) {
require(msg.value == purchasePrice[_nftID], "Incorrect purchase price");
address payable userAddress = payable(seller);
userAddress.transfer(msg.value);
(bool success, ) = userAddress.call{value: address(this).balance}("");
require(success,"Transfer failed.");
isListed[_nftID] = false;
IERC721(nftaddress).transferFrom(address(this), buyer[_nftID], _tokenID);
}


function getBalance() public view returns(uint256) {
Expand Down