From c2514c84bc5af2dbd7398eead466decd132c500a Mon Sep 17 00:00:00 2001 From: osmannyildiz Date: Sun, 17 Dec 2023 08:01:10 +0300 Subject: [PATCH] up --- contracts/CubLearn.sol | 34 +++++++++++++++++++++------------- contracts/DTLToken.sol | 20 ++++++++++++++------ contracts/NftCertificate.sol | 18 +++++++++--------- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/contracts/CubLearn.sol b/contracts/CubLearn.sol index 32c93b3..9b381e8 100644 --- a/contracts/CubLearn.sol +++ b/contracts/CubLearn.sol @@ -24,19 +24,27 @@ contract CubLearn is Ownable { dtlContract = DTLToken(dtlContractAddress); cubcertContract = NftCertificate(cubcertContractAddress); - coursePrices["1"] = 300; - coursePrices["2"] = 500; - coursePrices["3"] = 200; - coursePrices["4"] = 150; - coursePrices["5"] = 250; - coursePrices["6"] = 250; - coursePrices["7"] = 450; - + coursePrices["1"] = 300; + coursePrices["2"] = 500; + coursePrices["3"] = 200; + coursePrices["4"] = 150; + coursePrices["5"] = 250; + coursePrices["6"] = 250; + coursePrices["7"] = 450; + cashbackPercentage = 50; } + function amIEnrolledInCourse(string courseId) external view returns (bool) { + return enrolledCourses[courseId][msg.sender]; + } + + function didICompleteCourse(string courseId) external view returns (bool) { + return issuedCertificates[courseId][msg.sender]; + } + function setCashbackPercentage(uint256 newValue) external onlyOwner { - require(newValue <= 100, "Cashback percentage cannot be more than 100."); + require(newValue <= 100, "Cashback percentage cannot be more than 100."); cashbackPercentage = newValue; } @@ -46,7 +54,7 @@ contract CubLearn is Ownable { dtlContract.transferFrom(msg.sender, address(this), coursePrices[courseId]); - enrolledCourses[courseId][msg.sender] = true; + enrolledCourses[courseId][msg.sender] = true; } function finishCourse( @@ -63,9 +71,9 @@ contract CubLearn is Ownable { // Mark the certificate as issued issuedCertificates[courseId][msg.sender] = true; - // Cashback - uint256 cashbackAmount = coursePrices[courseId] * cashbackPercentage / 100; - dtlContract.transfer(msg.sender, cashbackAmount); + // Cashback + uint256 cashbackAmount = coursePrices[courseId] * cashbackPercentage / 100; + dtlContract.transfer(msg.sender, cashbackAmount); } function getDTLBalance() external view onlyOwner returns (uint256) { diff --git a/contracts/DTLToken.sol b/contracts/DTLToken.sol index d8b2a0c..5752fb7 100644 --- a/contracts/DTLToken.sol +++ b/contracts/DTLToken.sol @@ -8,11 +8,19 @@ contract DTLToken is ERC20 { _mint(initialHolder, 1000000000); } - function decimals() public view virtual override returns (uint8) { - return 0; - } + function decimals() public view virtual override returns (uint8) { + return 0; + } - function approveMax(address spender) external returns (bool) { - return approve(spender, totalSupply()); - } + function getAllowanceOfSpender(address spender) external view returns (uint256) { + return allowance(msg.sender, spender); + } + + function approveMax(address spender) external returns (bool) { + return approve(spender, totalSupply()); + } + + function getMyBalance() external view returns (uint) { + return balanceOf(msg.sender); + } } diff --git a/contracts/NftCertificate.sol b/contracts/NftCertificate.sol index 235db56..b94595b 100644 --- a/contracts/NftCertificate.sol +++ b/contracts/NftCertificate.sol @@ -48,15 +48,15 @@ contract NftCertificate is ERC721 { }); } - function getCertificateInfo(uint256 tokenId) - external - view - returns ( - CertificateInfo memory certInfo - ) - { - return certificateInfoMapping[tokenId]; - } + // function getCertificateInfo(uint256 tokenId) + // external + // view + // returns ( + // CertificateInfo memory certInfo + // ) + // { + // return certificateInfoMapping[tokenId]; + // } function _getSvg(uint256 tokenId) internal view returns (string memory) { CertificateInfo storage certInfo = certificateInfoMapping[tokenId];