Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- [x] Added Memory keyword for string datatype
- [x] Memory usage Optimization
- [x] Made function payable and transferred nft after successful
  transfer of funds to the user
- [x] remove unnecessary code and optimized the function for seller
- [x] added visiblity keyword external for ERC721 interface
- [x] Completed the deployment script of Contract.sol
  • Loading branch information
vishal18713 committed Mar 15, 2024
1 parent 22d9310 commit 8ab6da7
Show file tree
Hide file tree
Showing 21 changed files with 6,400 additions and 6,496 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\..\\..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\..\\..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\..\\..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\..\\..\\..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\..\\..\\..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\..\\..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\..\\..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\..\\..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
2 changes: 1 addition & 1 deletion artifacts/contracts/Contract.sol/Contract.dbg.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\build-info\\dbf2d9d471c032570678876827378bb3.json"
}
101 changes: 2 additions & 99 deletions artifacts/contracts/Contract.sol/Contract.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion artifacts/contracts/Contract.sol/IERC721.dbg.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\build-info\\dbf2d9d471c032570678876827378bb3.json"
}
2 changes: 1 addition & 1 deletion artifacts/contracts/RealEstate.sol/RealEstate.dbg.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/58e80b410d37a11575dc501a2bebf175.json"
"buildInfo": "..\\..\\build-info\\bc8cb46f11f8679e378bb1f6786fcf74.json"
}
4 changes: 2 additions & 2 deletions artifacts/contracts/RealEstate.sol/RealEstate.json

Large diffs are not rendered by default.

101 changes: 54 additions & 47 deletions contracts/Contract.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

interface IERC721 {
function transferFrom(
function transferFrom (
address _from,
address _to,
uint256 _id
);
) external; //Issue8 While importing this into other contracts it needs to be specified as external
}
contract Contract {
address public nftaddress;
Expand All @@ -18,25 +19,25 @@ contract Contract {
nftaddress = _nftaddress;
seller = _seller;
}
struct adds{
string memory city;
string memory country;
string memory addline;
struct adds{ //Structs cannot have memory keyword inside them
string city;
string country;
string addline;
}
struct Property {
string memory name;
string memory email;
string memory phoneno;
struct Property { // Issue2
string name; // memory keyword cannot be used inside the struct
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;
}


mapping(uint256 => Property) public metadata;
modifier OnlySeller(){
require(msg.sender == seller,"Only seller can use this method");
Expand All @@ -48,39 +49,35 @@ contract Contract {
_;
}

function list1(
uint256 _nftID,
string memory _amenities,
uint256 _sqfoot,
uint256 _bedno,
string memory _img,
string memory _descp,
uint256 _purchasePrice,
uint256 _tokenID
) public {
function list1( // Issue1
uint256 _nftID,
string memory _amenities, // As string can't be directly stored inside the blockchain unlike uint256, memory keyword is used
uint256 _sqfoot,
uint256 _bedno,
string memory _img,
string memory _descp,
uint256 _purchasePrice,
uint256 _tokenID)public {
IERC721(nftaddress).transferFrom(seller, address(this), _tokenID);
purchasePrice[_nftID] = _purchasePrice;
isListed[_nftID] = true;
metadata[_nftID] = Property({
amenities: _amenities,
sqfoot: _sqfoot,
bedno: _bedno,
img: _img,
descp: _descp
});

index += 1;
metadata[_nftID].amenities = _amenities;
metadata[_nftID].sqfoot = _sqfoot;
metadata[_nftID].bedno = _bedno;
metadata[_nftID].img = _img;
metadata[_nftID].descp = _descp;
index+=1;
}

function list2(
uint256 _nftID,
string memory _city,
string memory _country,
string memory _addline

)public {


metadata[_nftID].adds.city = _city;
metadata[_nftID].adds.country = _country;
metadata[_nftID].adds.addline = _addline;
Expand All @@ -91,31 +88,35 @@ contract Contract {
string memory _email,
string memory _proptype
)public {

metadata[_nftID].name = _name;
metadata[_nftID].email = _email;

metadata[_nftID].proptype = _proptype;

}
function declareBuyer(uint256 _nftID, address _buyer) public {
buyer[_nftID] = _buyer;
}
receive() external payable {}


function bought(uint256 _nftID,uint256 _tokenID) public payable onlyBuyer(_nftID) {//Issue3 : made payable
require(msg.value == purchasePrice[_nftID]);

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);
require(success,"Transfer Failed"); // Check whether the transfer to seller is successful or not

IERC721(nftaddress).transferFrom(address(this), buyer[_nftID], _tokenID); // Transfer The NFT to the Buyer

isListed[_nftID] = false;//Update the listing status
}


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

function meta1(uint256 _nftID) private view returns(string memory,uint256,uint256,string memory,string memory) {
return (
metadata[_nftID].amenities,
Expand Down Expand Up @@ -143,8 +144,14 @@ contract Contract {
return isListed[_nftID];
}
function cancelSale(uint256 _nftID) public {
require(1==1);
(bool success, ) = payable(buyer[_nftID]).call{value: address(this).balance}("");
require(msg.sender == seller, "Only seller can cancel the sale");
require(isListed[_nftID], "NFT is not listed for sale");

// Transfer the NFT back to the seller
IERC721(nftaddress).transferFrom(address(this), seller, _nftID);

// Set the listing status to false
isListed[_nftID] = false;
}

function retprice (uint256 _nftID) public view returns (uint256) {
Expand Down
10 changes: 5 additions & 5 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module.exports ={
solidity: "0.8.17",
networks:{
hardhat :{},
polygon_mumbai:{
url:"https://polygon-mumbai.g.alchemy.com/v2/Gc_VlMr5WTe57ynQps7sKYAEFoqIqxfY",
accounts: [`0x${"e2b2fc0a72f1489e47c5dc05c2c46e77adbfeed2e0b5d11f64445d36d0ba9ebd"}`]
arbitrum:{
url:"https://arb-sepolia.g.alchemy.com/v2/q5H8ozuIHQGI8jCVWw1bLiWj2HM2Ftyu",
accounts: [`15757a2dae66ec6da64ca0286fa8bda822183312b8ace298051796d048751ba2`]
}
},
gasPrice:200,
}
gasPrice:200000000000000,
};
23 changes: 11 additions & 12 deletions scripts/Deploy.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
const { expect } = require('chai');
const { ethers } = require('hardhat');
const tokens = (n) => {
return ethers.utils.parseUnits(n.toString(), 'ether')
}

async function main() {
const [deployer] = await ethers.getSigners();

const RealEstate =await ethers.getContractFactory('RealEstate');
// Deploy RealEstate contract
const RealEstate = await ethers.getContractFactory('RealEstate');
const realEstate = await RealEstate.deploy();
await realEstate.deployed();
console.log('RealEstate contract deployed to:', realEstate.address);

console.log('realEstate address' + realEstate.address);
console.log("Mining starting");


// Deploy Contract (renamed from your other contract)
const Contract = await ethers.getContractFactory('Contract');
const contract = await Contract.deploy(realEstate.address, deployer.address);
await contract.deployed();
console.log('Contract deployed to:', contract.address);


console.log("Mining starting");
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

});
Loading

0 comments on commit 8ab6da7

Please sign in to comment.