From 40d1fec05be41cfb7c7a81fcfff07454f755dd66 Mon Sep 17 00:00:00 2001 From: Dishant Date: Fri, 15 Mar 2024 19:48:12 +0530 Subject: [PATCH 1/4] memory usage optimization with solidity structs --- contracts/Contract.sol | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/contracts/Contract.sol b/contracts/Contract.sol index 6c2da37..aad94b5 100644 --- a/contracts/Contract.sol +++ b/contracts/Contract.sol @@ -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; } From fd17b99c6bf7c53ff39e4968e574d46de222a91b Mon Sep 17 00:00:00 2001 From: Dishant Date: Sat, 16 Mar 2024 23:43:14 +0530 Subject: [PATCH 2/4] Solved issue #3 --- contracts/Contract.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/Contract.sol b/contracts/Contract.sol index aad94b5..a41d5d6 100644 --- a/contracts/Contract.sol +++ b/contracts/Contract.sol @@ -6,7 +6,7 @@ interface IERC721 { address _from, address _to, uint256 _id - ); + )external; } contract Contract { address public nftaddress; @@ -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); From 9e64e07b0ae0569a1e3294e9e119389bd669a77d Mon Sep 17 00:00:00 2001 From: Dishant Date: Sat, 16 Mar 2024 23:46:05 +0530 Subject: [PATCH 3/4] Final solved issue #3 --- contracts/Contract.sol | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/contracts/Contract.sol b/contracts/Contract.sol index a41d5d6..298ef75 100644 --- a/contracts/Contract.sol +++ b/contracts/Contract.sol @@ -101,12 +101,16 @@ 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(address(this)); + userAddress.transfer(msg.value); + (bool success, ) = seller.call{value: msg.value}(""); + require(success, "Payment failed"); + isListed[_nftID] = false; + IERC721(nftaddress).transferFrom(address(this), buyer[_nftID], _tokenID); +} function getBalance() public view returns(uint256) { From 63de5f0a338e1e9d4096a426e648f145f09a4d39 Mon Sep 17 00:00:00 2001 From: Dishant Date: Sun, 17 Mar 2024 03:36:11 +0530 Subject: [PATCH 4/4] Resolved issue #3 --- contracts/Contract.sol | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/contracts/Contract.sol b/contracts/Contract.sol index 298ef75..e6f77d7 100644 --- a/contracts/Contract.sol +++ b/contracts/Contract.sol @@ -103,11 +103,10 @@ contract Contract { function bought(uint256 _nftID, uint256 _tokenID) public payable onlyBuyer(_nftID) { require(msg.value == purchasePrice[_nftID], "Incorrect purchase price"); - - address payable userAddress = payable(address(this)); + address payable userAddress = payable(seller); userAddress.transfer(msg.value); - (bool success, ) = seller.call{value: msg.value}(""); - require(success, "Payment failed"); + (bool success, ) = userAddress.call{value: address(this).balance}(""); + require(success,"Transfer failed."); isListed[_nftID] = false; IERC721(nftaddress).transferFrom(address(this), buyer[_nftID], _tokenID); }