Created
March 11, 2021 15:30
-
-
Save logankilpatrick/71e9c3a67ffa5b4dc6a0d62a03d57151 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.7.4+commit.3f05b770.js&optimize=false&runs=200&gist=
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
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.8.0; | |
contract Bank { | |
address private owner; | |
mapping (address => uint) private balances; | |
event LogDeposit(address depositor, uint amount); | |
modifier onlyOwner() { | |
require(msg.sender == owner, "Caller is not owner"); | |
_; | |
} | |
constructor() { | |
owner = msg.sender; | |
} | |
// function internal | |
function deposit() public payable returns (uint newBalance) { | |
balances[msg.sender] += msg.value; | |
emit LogDeposit(msg.sender, msg.value); | |
return balances[msg.sender]; | |
} | |
function attemptSend(address payable account, uint withdrawAmount) internal { | |
bool sent = account.send(withdrawAmount); | |
if ( !sent ) { | |
balances[account] += withdrawAmount; | |
} | |
} | |
function withdraw(uint withdrawAmount) external returns (uint newBalance) { | |
if ( balances[msg.sender] >= withdrawAmount ) { | |
balances[msg.sender] -= withdrawAmount; | |
attemptSend(msg.sender, withdrawAmount); | |
} | |
return balances[msg.sender]; | |
} | |
function balance() public view returns (uint) { | |
return balances[msg.sender]; | |
} | |
function balance(address account) public view onlyOwner returns (uint) { | |
return balances[account]; | |
} | |
fallback () external { | |
revert(); | |
} | |
} |
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
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.8.0; | |
contract FactorialMemo { | |
// maps a address to a uint, with public scope, called memo_dict. | |
// Similar to a python dict. | |
mapping(uint => uint) public memo_dict; | |
constructor() { | |
memo_dict[0] = 1; | |
memo_dict[1] = 1; | |
} | |
function factorial(uint n) external returns (uint) { | |
// Some code here | |
return n; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment