Last active
September 5, 2025 06:04
-
-
Save gwenf/359b1ec2c53f4cba3e01d8d3de1e7811 to your computer and use it in GitHub Desktop.
Revisions
-
gwenf revised this gist
Mar 20, 2020 . 1 changed file with 58 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,20 +7,25 @@ pragma solidity >=0.4.22 <0.7.0; contract PhoneCompany { uint public chargeAmount; uint public coinPrice; address companyOwner; // a list of phone numbers attached to my address // only the user can view their own phonebook mapping(uint => uint[]) whitelisted; struct User { string name; uint phoneNumber; uint coins; } mapping(address => User) users; constructor(uint amount, uint price) public { companyOwner = msg.sender; chargeAmount = amount; coinPrice = price; } function updateAmount(uint amount) public { @@ -31,13 +36,57 @@ contract PhoneCompany { chargeAmount = amount; } function initNewUser(uint phoneNumber, string memory name) payable public returns(string memory) { // check amount paid require( msg.value >= coinPrice * 100, "You didn't send enough money to buy 100 coins." ); users[msg.sender] = User({ phoneNumber: phoneNumber, name: name, coins: 100 }); return 'Success! You now have 100 coins.'; } function coinBalance() public view returns(uint) { return users[msg.sender].coins; } // add a phone number to a users phone book, whitelist function addPhoneNumber(uint phoneNumber) public { whitelisted[users[msg.sender].phoneNumber].push(phoneNumber); } function makeCall(uint phoneNumber) public returns(uint) { bool isWhitelisted = false; uint userPhone = users[msg.sender].phoneNumber; for (uint i; i < whitelisted[userPhone].length; i++) { if (whitelisted[userPhone][i] == phoneNumber) { isWhitelisted = true; break; } } if (!isWhitelisted) { users[msg.sender].coins = users[msg.sender].coins - chargeAmount; } return users[msg.sender].coins; } // users can restock their coins function buyCoins() public payable returns(uint) { require( msg.value >= coinPrice, "You didn't send enough money to buy coins." ); uint coinNum = msg.value / coinPrice; users[msg.sender].coins = users[msg.sender].coins + coinNum; return users[msg.sender].coins; } // addLastCallerToWhitelist // store info of last caller and return coins } -
gwenf created this gist
Mar 13, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ pragma solidity >=0.4.22 <0.7.0; // phone company dapp // charge telemarkers coins for calls // whitelist people don't get charged // anyone not on the whitelist has to pay a small fee contract PhoneCompany { uint public chargeAmount; address companyOwner; // a list of phone numbers attached to my address // only the user can view their own phonebook struct Entry { string name; uint phoneNumber; } mapping(address => Entry[]) phoneBook; constructor(uint amount) public { companyOwner = msg.sender; chargeAmount = amount; } function updateAmount(uint amount) public { require( msg.sender == companyOwner, "Only the company owner can update charge amount." ); chargeAmount = amount; } function initNewUser(uint phoneNumber, string memory name) public { // msg.sender; // return coins } function addPhoneNumber(uint phoneNumber, string memory name) public { // add a phone number to a users phone book } }