-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from awaismohammad23/AwaisTasks
Awais tasks
- Loading branch information
Showing
23 changed files
with
65,322 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"solidity.compileUsingRemoteVersion": "v0.8.16+commit.07a7930e" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
16,804 changes: 16,804 additions & 0 deletions
16,804
Project2/build/contracts/OrderProcessingContract.json
Large diffs are not rendered by default.
Oops, something went wrong.
17,104 changes: 17,104 additions & 0 deletions
17,104
Project2/build/contracts/discountsAndPromotions.json
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//SPDX-License-Identifier:MIT | ||
pragma solidity >=0.8.10 <0.8.20; | ||
import "./rewardsAndLoyalty.sol"; | ||
interface ERC20 { | ||
function totalSupply() external view returns (uint256); | ||
function balanceOf(address account) external view returns (uint256); | ||
function transfer(address recipient, uint256 amount) external returns (bool); | ||
function allowance(address owner, address spender) external view returns (uint256); | ||
function approve(address spender, uint256 value) external returns (bool); | ||
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); | ||
event Transfer(address from, address to, uint256 value); | ||
event Approval(address owner, address spender, uint256 value); | ||
} | ||
|
||
contract FASTCOIN is ERC20 { | ||
uint numTokens; | ||
mapping(address=>uint) balance; | ||
mapping(address=>uint) paymenttime; | ||
mapping(address=> mapping(address=>uint)) approvalLimit; | ||
mapping(address=>uint)daystreak; | ||
rewardsAndLoyalty public RAL; | ||
constructor (uint _numTokens) { | ||
numTokens = _numTokens; | ||
balance[msg.sender] = numTokens; | ||
} | ||
|
||
|
||
function totalSupply() external view returns (uint256){ | ||
return numTokens; | ||
} | ||
|
||
function balanceOf(address account) external view returns (uint256){ | ||
return balance[account]; | ||
} | ||
|
||
function transfer(address recipient, uint256 amount) external returns (bool){ | ||
require (balance[msg.sender] >= amount) ; | ||
balance[msg.sender] -= amount; | ||
balance[recipient] += amount; | ||
} | ||
|
||
function approve(address spender, uint256 value) external returns (bool){ | ||
require (balance[msg.sender] >= value); | ||
approvalLimit[msg.sender][spender] = value; | ||
} | ||
|
||
function allowance(address owner, address spender) external view returns | ||
(uint256){ | ||
return approvalLimit[owner][spender]; | ||
} | ||
|
||
function transferFrom(address sender, address recipient, uint256 amount) external returns | ||
(bool){ | ||
require (amount <= balance[sender]); | ||
require (amount <= approvalLimit[sender][msg.sender]); | ||
paymenttime[sender]=(block.timestamp - paymenttime[sender]) ; | ||
if (paymenttime[sender] > 24 hours){ | ||
daystreak[sender]=0; | ||
} else { | ||
uint [] memory stamt = RAL.getsentamount(); | ||
uint [] memory rwd = RAL.getreward(); | ||
uint [] memory bdystk = RAL.getbuydaysstreak(); | ||
uint [] memory rwdbdystk = RAL.getrewardforbuydays(); | ||
for (uint i = 0 ; i < stamt.length ; i++){ | ||
if (amount > stamt[i]){ | ||
balance[sender]+=rwd[i]; | ||
break; | ||
} | ||
} | ||
|
||
for (uint i = 0 ; i < bdystk.length ; i++){ | ||
if (daystreak[sender] > bdystk[i]){ | ||
balance[sender]+=rwdbdystk[i]; | ||
break; | ||
} | ||
} | ||
} | ||
balance[sender] -= amount; | ||
balance[recipient] += amount; | ||
approvalLimit[sender][msg.sender] -= amount; | ||
paymenttime[sender]=block.timestamp; | ||
daystreak[sender]+=1; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//SPDX-License-Identifier:MIT | ||
pragma solidity >=0.8.10 <0.8.20; | ||
import "./menuManagement.sol"; | ||
import "./discountsAndPromotions.sol"; | ||
contract OrderProcessingContract{ | ||
menuManagement public mn; | ||
discountsAndPromotions public discAPro; | ||
|
||
function setmenuanddiscountsandpromotions(address _addrmenu , address _addrdiscandpro)public{ | ||
mn=menuManagement(_addrmenu); | ||
discAPro=discountsAndPromotions(_addrdiscandpro); | ||
} | ||
|
||
function CheckinAvailability()public view returns(bool){ | ||
return mn.CheckAvailability("Pizza"); | ||
} | ||
|
||
function getMenuItems() public view returns(string [] memory , uint [] memory, uint [] memory){ | ||
string [] memory names = mn.getItemNames(); | ||
uint [] memory price = mn.getMenuPrice(); | ||
uint [] memory quantity = mn.getMenuQuantity(); | ||
return (names , price , quantity); | ||
} | ||
|
||
function CalculateOrderAmount(string [] memory itemnames , uint [] memory quantities) external returns(uint){ | ||
uint totalAmount; | ||
string [] memory names = mn.getItemNames(); | ||
uint [] memory price = mn.getMenuPrice(); | ||
uint [] memory quantity = mn.getMenuQuantity(); | ||
uint j = 0; | ||
for (uint i = 0 ; i < names.length ; i++){ | ||
if (keccak256(abi.encodePacked(names[i])) == keccak256(abi.encodePacked(itemnames[j]))) { | ||
string memory nm; | ||
uint typs; uint qt ; uint prcper ; uint dur; | ||
(nm , typs , qt , prcper , dur) = discAPro.PromotionsandDiscounts(names[i]); | ||
if (typs == 1){ | ||
mn.setQuantity(quantity[i] - quantities[j] - quantities[j]/qt, i); | ||
totalAmount += quantities[j] * price[i]; | ||
} else if (typs == 2) { | ||
mn.setQuantity(quantity[i] - quantities[j] - quantities[j]/qt, i); | ||
totalAmount += quantities[j] * (prcper / 100 * price[i]); | ||
} | ||
j++; | ||
} | ||
} | ||
return totalAmount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//SPDX-License-Identifier:MIT | ||
pragma solidity >=0.8.10 <0.8.20; | ||
import "./menuManagement.sol"; | ||
contract discountsAndPromotions { | ||
menuManagement public mn; | ||
string [] names ; | ||
uint [] prices; | ||
uint [] quantities; | ||
function setMenu(address _addrmenu) public{ | ||
mn=menuManagement(_addrmenu); | ||
} | ||
struct PromAndDisc { | ||
string name; | ||
uint types; | ||
uint quantity; | ||
uint pricepercentagededuction; | ||
uint duration; | ||
} | ||
mapping(string=> PromAndDisc) public PromotionsandDiscounts; | ||
|
||
//The Quantity here is the quantity | ||
//after which the customer will be eligible for free meal. | ||
function AddBuyAndGetFreePromotion (string [] memory items , uint quantity , uint _duration) public { | ||
require(quantity > 0 && _duration > 0 , "Quantity or duration cannot be zero."); | ||
names = mn.getItemNames(); | ||
prices = mn.getMenuPrice() ; | ||
quantities = mn.getMenuQuantity();//OPC.getMenuItems();//Tuples in solidity | ||
uint j = 0; | ||
for (uint i = 0 ; i < names.length ; i++){ | ||
if (keccak256(abi.encodePacked(names[i])) == keccak256(abi.encodePacked(items[j]))){ | ||
PromotionsandDiscounts[names[i]].quantity=quantity; | ||
PromotionsandDiscounts[names[i]].name=names[i]; | ||
PromotionsandDiscounts[names[i]].types=1; | ||
PromotionsandDiscounts[names[i]].duration= block.timestamp + _duration; | ||
j++; | ||
} | ||
} | ||
} | ||
|
||
function AddSimpleDiscount(string [] memory items , uint percentage , uint _duration) public { | ||
require(percentage <= 90 , "Percentage cannot exceeed 90"); | ||
names = mn.getItemNames(); | ||
prices = mn.getMenuPrice() ; | ||
quantities = mn.getMenuQuantity();//OPC.getMenuItems();//Tuples in solidity | ||
uint j = 0; | ||
for (uint i = 0 ; i < names.length ; i++){ | ||
if (keccak256(abi.encodePacked(names[i])) == keccak256(abi.encodePacked(items[j]))){ | ||
PromotionsandDiscounts[names[i]].name=names[i]; | ||
PromotionsandDiscounts[names[i]].types=2; | ||
PromotionsandDiscounts[names[i]].pricepercentagededuction=percentage; | ||
PromotionsandDiscounts[names[i]].duration= block.timestamp + _duration; | ||
j++; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//SPDX-License-Identifier:MIT | ||
pragma solidity >=0.8.10 <0.8.20; | ||
contract menuManagement{ | ||
struct Item { | ||
string name; | ||
uint price; | ||
uint quantity; | ||
bool availability; | ||
} | ||
mapping (string => Item)public itms; | ||
string [] public names; | ||
uint [] public prices; | ||
uint [] public quantities; | ||
address public admin; | ||
constructor(){ | ||
admin = msg.sender; | ||
} | ||
|
||
mapping(string => bool) itemExists; | ||
|
||
modifier exists(string memory name) { | ||
require(itemExists[name], "Item does not exist"); | ||
_; | ||
} | ||
|
||
function addItem(string memory name , uint price, uint qty) public { | ||
names.push(name); | ||
prices.push(price); | ||
quantities.push(qty); | ||
itms[name].name=name; | ||
itms[name].price=price; | ||
itms[name].quantity=qty; | ||
itms[name].availability=qty > 0; | ||
itemExists[name] = true; | ||
} | ||
|
||
function getItemNames() external view returns (string [] memory){ | ||
return names; | ||
} | ||
|
||
function setQuantity(uint qty , uint i) external{ | ||
quantities[i]=qty; | ||
} | ||
|
||
function UpdatePrice(string memory name, uint price) private exists(name) { | ||
require(price > 0, "Price cannot be 0"); | ||
itms[name].price=price; | ||
} | ||
|
||
function CheckAvailability(string memory name) exists(name) public view returns (bool) { | ||
return itms[name].availability; | ||
} | ||
|
||
function getMenuPrice() public view returns(uint [] memory){ | ||
return prices; | ||
} | ||
|
||
function getMenuQuantity() public view returns(uint [] memory){ | ||
/*uint [] memory qty1 = new uint[](1000); | ||
for (uint i = 0 ; i < names.length ; i++){ | ||
qty1[i] = itms[names[i]].quantity; | ||
}*/ | ||
return quantities; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//SPDX-License-Identifier:MIT | ||
pragma solidity >=0.8.10 <0.8.20; | ||
contract rewardsAndLoyalty { | ||
uint [] public sentamount = [10 , 50 , 100 , 200 , 250 , 500 , 750 , 1000 , 1500 , 2000 , 3000 , 5000 , 7500 , 10000]; | ||
uint [] public reward = [3 , 5 , 10 , 15 , 20 , 30 , 40 , 70 , 150 , 180 , 220 , 350 , 500 , 800]; | ||
uint [] public buydaysstreak = [3 , 5 , 10 , 30 , 60 , 90 , 180 , 365]; | ||
uint [] public rewardforbuydays = [1 , 2 , 3 , 10 , 30 , 50 , 70 , 100]; | ||
function getreward() public view returns(uint[] memory){ | ||
return reward; | ||
} | ||
function getsentamount() public view returns(uint[] memory){ | ||
return sentamount; | ||
} | ||
function getbuydaysstreak() public view returns(uint[] memory){ | ||
return buydaysstreak; | ||
} | ||
function getrewardforbuydays() public view returns(uint[] memory){ | ||
return rewardforbuydays; | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const menuManagement = artifacts.require("./menuManagement.sol"); | ||
|
||
module.exports = function(deployer){ | ||
deployer.deploy(menuManagement); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const RAL = artifacts.require("rewardsAndLoyalty"); | ||
|
||
module.exports = function(deployer){ | ||
deployer.deploy(RAL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const FASTCOIN = artifacts.require("FASTCOIN"); | ||
|
||
module.exports = function(deployer){ | ||
const initialoffering = 1000000; | ||
deployer.deploy(FASTCOIN , initialoffering); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const DiscPro = artifacts.require("discountsAndPromotions"); | ||
module.exports=function(deployer){ | ||
deployer.deploy(DiscPro); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const OPC = artifacts.require("./OrderProcessingContract.sol"); | ||
|
||
module.exports = function(deployer){ | ||
deployer.deploy(OPC); | ||
} |
Submodule project2
added at
bc3e5c
Empty file.
Oops, something went wrong.