// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import "./HomeTransaction.sol"; contract Factory { HomeTransaction[] public contracts; mapping(address => HomeTransaction[]) public contractsByRealtor; mapping(address => HomeTransaction[]) public contractsBySeller; mapping(address => HomeTransaction[]) public contractsByBuyer; event ContractCreated( address indexed contractAddress, address indexed realtor, address indexed seller, address buyer, uint price ); function create( string memory _address, string memory _zip, string memory _city, uint _realtorFee, uint _price, address payable _seller, address payable _buyer ) external returns (HomeTransaction homeTransaction) { homeTransaction = new HomeTransaction( _address, _zip, _city, _realtorFee, _price, payable(msg.sender), // realtor is the caller _seller, _buyer ); contracts.push(homeTransaction); contractsByRealtor[msg.sender].push(homeTransaction); contractsBySeller[_seller].push(homeTransaction); contractsByBuyer[_buyer].push(homeTransaction); emit ContractCreated( address(homeTransaction), msg.sender, _seller, _buyer, _price ); } function getInstance(uint index) external view returns (HomeTransaction) { require(index < contracts.length, "Index out of range"); return contracts[index]; } function getInstances() external view returns (HomeTransaction[] memory) { return contracts; } function getInstanceCount() external view returns (uint) { return contracts.length; } function getContractsByRealtor(address realtor) external view returns (HomeTransaction[] memory) { return contractsByRealtor[realtor]; } function getContractsBySeller(address seller) external view returns (HomeTransaction[] memory) { return contractsBySeller[seller]; } function getContractsByBuyer(address buyer) external view returns (HomeTransaction[] memory) { return contractsByBuyer[buyer]; } }