├── docs ├── .vuepress │ ├── .gitignore │ ├── public │ │ └── .gitkeep │ ├── configSideBarBlockchain Notes.txt │ ├── configSideBarCool Contracts.txt │ ├── configSideBar.txt │ ├── configSideBarSmart Contracts.txt │ ├── enhanceApp.js │ ├── configNavbarDirAuto.txt │ ├── style.styl │ ├── override.styl │ └── config.js └── mindmap │ └── README.md ├── .gitattributes ├── website ├── static │ ├── img │ │ ├── favicon.png │ │ ├── TodoList.png │ │ ├── TrustLess.png │ │ ├── oss_logo.png │ │ ├── VueDappLogo.png │ │ └── favicon │ │ │ └── favicon.ico │ └── css │ │ └── custom.css ├── sidebars.json ├── blog │ ├── 2018-11-12-Fixing-pipeline-2018-11-18.md │ ├── 2018-08-25-CI-version-1.2.0.md │ └── 2018-09-08-Status-Report.md ├── package.json ├── pages │ └── en │ │ ├── users.js │ │ ├── help.js │ │ └── index.js ├── core │ └── Footer.js └── siteConfig.js ├── .gitignore ├── solidityDocs.js ├── contracts ├── games │ ├── Roulette.sol │ ├── SimpleLottery.sol │ ├── RNGLottery.sol │ ├── SatoshiDice.sol │ ├── RecurringLottery.sol │ ├── CasinoRoulette.sol │ ├── Powerball.sol │ ├── Itontine.sol │ ├── PredictionMarket.sol │ └── WhatDoesNadiaThink.sol ├── basic │ ├── Marriage.sol │ ├── Contract.sol │ ├── helloWorld.sol │ ├── bugSquash.sol │ ├── MyContract.sol │ └── ecom │ │ ├── Suppliers.sol │ │ └── Customer.sol ├── util │ ├── Welfare.sol │ ├── SafeMath.sol │ ├── MarriageInvestment.sol │ └── promiseBox.sol ├── tokens │ ├── AttendanceToken │ │ ├── Migrations.sol │ │ ├── EIP20Interface.sol │ │ ├── EIP20.sol │ │ ├── fixed-supply-erc20.sol │ │ └── attendancecoin-erc20.sol │ ├── TokenSale.sol │ ├── ERC20.sol │ └── BasicToken.sol ├── schemes │ ├── PonziScheme.sol │ ├── GradualPonzi.sol │ ├── SimplePyramid.sol │ └── Government.sol ├── other │ ├── CredVert │ │ ├── SafeMath32.sol │ │ ├── Pausable.sol │ │ ├── Ownable.sol │ │ ├── CredentialFactory.sol │ │ ├── CredentialFactoryOrg.sol │ │ └── ApplicantFactory.sol │ ├── URLShorter.sol │ └── marketplace │ │ └── workbenchbase.sol ├── datastruct │ ├── Stack.sol │ └── LinkedList.sol ├── finance │ ├── Mortgage.sol │ └── CrowdBank.sol ├── Users.sol ├── TodoList.sol └── Authentication.sol ├── .travis-vuepress.yml ├── .github └── FUNDING.yml ├── downloadBinary.sh ├── package.json ├── LICENSE ├── .travis.yml ├── Readme.Md └── ref ├── texBCNotes.tex └── markdownNotes.md /docs/.vuepress/.gitignore: -------------------------------------------------------------------------------- 1 | css 2 | dist -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity -------------------------------------------------------------------------------- /docs/.vuepress/public/.gitkeep: -------------------------------------------------------------------------------- 1 | ECHO is on. 2 | -------------------------------------------------------------------------------- /docs/.vuepress/configSideBarBlockchain Notes.txt: -------------------------------------------------------------------------------- 1 | [ '' ] -------------------------------------------------------------------------------- /docs/.vuepress/configSideBarCool Contracts.txt: -------------------------------------------------------------------------------- 1 | [ '/contracts/tokens/Users' ] -------------------------------------------------------------------------------- /docs/.vuepress/configSideBar.txt: -------------------------------------------------------------------------------- 1 | [ 'games/Users', '', 'TodoList', 'tokens/Users', 'Users' ] -------------------------------------------------------------------------------- /docs/.vuepress/configSideBarSmart Contracts.txt: -------------------------------------------------------------------------------- 1 | [ '', '/contracts/TodoList', '/contracts/Users' ] -------------------------------------------------------------------------------- /website/static/img/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FriendlyUser/solidity-smart-contracts/HEAD/website/static/img/favicon.png -------------------------------------------------------------------------------- /website/static/img/TodoList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FriendlyUser/solidity-smart-contracts/HEAD/website/static/img/TodoList.png -------------------------------------------------------------------------------- /website/static/img/TrustLess.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FriendlyUser/solidity-smart-contracts/HEAD/website/static/img/TrustLess.png -------------------------------------------------------------------------------- /website/static/img/oss_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FriendlyUser/solidity-smart-contracts/HEAD/website/static/img/oss_logo.png -------------------------------------------------------------------------------- /website/static/img/VueDappLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FriendlyUser/solidity-smart-contracts/HEAD/website/static/img/VueDappLogo.png -------------------------------------------------------------------------------- /docs/.vuepress/enhanceApp.js: -------------------------------------------------------------------------------- 1 | 2 | export default ({ Vue, options, router, siteData }) => { 3 | //Vue.use(VueChartkick, {adapter: Chart}) 4 | } 5 | -------------------------------------------------------------------------------- /website/static/img/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FriendlyUser/solidity-smart-contracts/HEAD/website/static/img/favicon/favicon.ico -------------------------------------------------------------------------------- /docs/.vuepress/configNavbarDirAuto.txt: -------------------------------------------------------------------------------- 1 | [ { text: 'Home', link: '/' }, 2 | { text: 'contracts', link: '/contracts/' }, 3 | { text: 'mindmap', link: '/mindmap/' }, 4 | { text: 'notes', link: '/notes/' } ] -------------------------------------------------------------------------------- /docs/.vuepress/style.styl: -------------------------------------------------------------------------------- 1 | .theme-container.custom-homepage-class { 2 | /* page-specific rules */ 3 | /* Make sure that padding behaves as expected */ 4 | } 5 | 6 | 7 | .theme-container.custom-seng460-class { 8 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | docs/.vuepress/dist 3 | *.zip 4 | ethereum-games-master/ 5 | 6 | *.pdf 7 | 8 | website/translated_docs 9 | 10 | website/build/ 11 | 12 | website/yarn.lock 13 | 14 | website/node_modules 15 | 16 | website/i18n/* -------------------------------------------------------------------------------- /website/static/css/custom.css: -------------------------------------------------------------------------------- 1 | /* your custom css */ 2 | 3 | @media only screen and (min-device-width: 360px) and (max-device-width: 736px) { 4 | } 5 | 6 | @media only screen and (min-width: 1024px) { 7 | } 8 | 9 | @media only screen and (max-width: 1023px) { 10 | } 11 | 12 | @media only screen and (min-width: 1400px) { 13 | } 14 | 15 | @media only screen and (min-width: 1500px) { 16 | } -------------------------------------------------------------------------------- /solidityDocs.js: -------------------------------------------------------------------------------- 1 | import soldoc from '@soldoc/soldoc'; 2 | 3 | /* default options */ 4 | soldoc.defaults = { 5 | in: './contracts', 6 | out: './docs/contracts', 7 | /* json: undefined, */ 8 | /*repoUrl: FriendlyUser/solidity-smart-contracts, */ 9 | log: ./docs/contracts/Soldoc.md, 10 | quiet: false, 11 | theme: '@soldoc/markdown', 12 | }; 13 | soldoc(options); // returns a promise -------------------------------------------------------------------------------- /website/sidebars.json: -------------------------------------------------------------------------------- 1 | { 2 | "components": { 3 | "First Category": ["TodoList.md", "Footer.md", "Dashboard.md", "HelloMetamask.md","MetamaskState.md","Signup.md"] 4 | }, 5 | "Application": { 6 | "App Files": ["App","main","users"], 7 | "Components": ["Dashboard","Signup"], 8 | "Router": ["index"] 9 | }, 10 | "Contracts": { 11 | "Users": ["sm-Users"], 12 | "Migrations": ["sm-Migrations"] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /website/blog/2018-11-12-Fixing-pipeline-2018-11-18.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Fixing Build Pipeline 3 | author: David Li 4 | authorURL: http://friendlyuser.github.io 5 | authorFBID: 661277175 6 | --- 7 | 8 | # Solidity-docgen travis CI issues 9 | 10 | Since the solc package was updated to version 5.0, and ppa eliminate previous versions, I found myself needed to install an old version. 11 | 12 | What I ended up doing is manually downloading the binary using wget and then linking it to path -------------------------------------------------------------------------------- /contracts/games/Roulette.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | 3 | /// @dev simple example 4 | contract Roulette { 5 | constructor() { 6 | 7 | } 8 | mapping(address => uint) balances; 9 | function betRed () payable { 10 | bool winner = (randomNumber() % 2 == 0); 11 | if (winner) 12 | balances[msg.sender] += msg.value * 2; 13 | } 14 | function randomNumber() returns (uint) { 15 | // we will implement this in a later section 16 | // for now, imagine it returns a number from 17 | // 0-36 18 | } 19 | } -------------------------------------------------------------------------------- /contracts/basic/Marriage.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | /// @title Marriage Contract 3 | contract Marriage { 4 | 5 | mapping (address => uint) balances; 6 | address wife = address(0); // dummy address 7 | address husband = address(1); // dummy address 8 | function withdraw () { 9 | uint amount = balances[msg.sender]; 10 | balances[msg.sender] = 0; 11 | msg.sender.transfer(amount); 12 | } 13 | function () payable { 14 | balances[wife] += msg.value / 2; 15 | balances[husband] += msg.value / 2; 16 | } 17 | } -------------------------------------------------------------------------------- /website/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "examples": "docusaurus-examples", 4 | "start": "docusaurus-start", 5 | "build": "docusaurus-build", 6 | "publish-gh-pages": "docusaurus-publish", 7 | "write-translations": "docusaurus-write-translations", 8 | "version": "docusaurus-version", 9 | "rename-version": "docusaurus-rename-version" 10 | }, 11 | "devDependencies": { 12 | "docusaurus": "^1.3.0" 13 | }, 14 | "dependencies": { 15 | "remarkable-plantuml": "^1.1.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/util/Welfare.sol: -------------------------------------------------------------------------------- 1 | contract Welfare { 2 | address[] recipients; 3 | uint totalFunding; 4 | mapping(address => uint) withdrawn; 5 | function register () { 6 | recipients.push(msg.sender); 7 | } 8 | function () payable { 9 | totalFunding += msg.value; 10 | } 11 | function withdraw () { 12 | uint withdrawnSoFar = withdrawn[msg.sender]; 13 | uint allocation = totalFunding / recipients.length; 14 | require(allocation > withdrawnSoFar); 15 | uint amount = allocation - withdrawnSoFar; 16 | withdrawn[msg.sender] = allocation; 17 | msg.sender.transfer(amount); 18 | } 19 | } -------------------------------------------------------------------------------- /contracts/basic/Contract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.8; 2 | contract A { 3 | uint[] public amounts; 4 | function init(uint[] _amounts) { 5 | amounts = _amounts; 6 | } 7 | } 8 | 9 | contract Factory { 10 | struct AData { 11 | uint[] amounts; 12 | } 13 | mapping (address => AData) listOfData; 14 | 15 | function set(uint[] _amounts) { 16 | listOfData[msg.sender] = AData(_amounts); 17 | } 18 | 19 | function make() returns(address) { 20 | A a = new A(); 21 | a.init(listOfData[msg.sender].amounts); 22 | return address(a); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/basic/helloWorld.sol: -------------------------------------------------------------------------------- 1 | /// @author David Li --- August 5, 2018 2 | /// @title helloWorld.sol simple contract 3 | pragma solidity ^0.4.15; 4 | contract HelloWorld { 5 | address owner; 6 | string greeting = "Hello World"; 7 | /// @dev Constructor function 8 | function HelloWorld () public { 9 | owner = msg.sender; 10 | } 11 | 12 | /// @dev return hello world greeting 13 | function greet () view public returns (string) { 14 | return greeting; 15 | } 16 | /// @dev only the owner can destroy the contract 17 | function kill () public { 18 | require(owner == msg.sender); 19 | selfdestruct(owner); 20 | } 21 | } -------------------------------------------------------------------------------- /contracts/tokens/AttendanceToken/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | constructor() public { 8 | owner = msg.sender; 9 | } 10 | 11 | modifier restricted() { 12 | if (msg.sender == owner) _; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) public restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /contracts/basic/bugSquash.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.8; 2 | /// @title BugSquash 3 | contract BugSquash { 4 | enum State { Alive, Squashed } 5 | State state; 6 | address owner; 7 | function BugSquash () { 8 | state = State.Alive; 9 | owner = msg.sender; 10 | } 11 | function squash () { 12 | // this should never throw an error 13 | assert(owner != address(0)); 14 | if (state == State.Alive) 15 | state = State.Squashed; 16 | else if (state == State.Squashed) 17 | revert(); // user error, refund gas 18 | } 19 | function kill () { 20 | // any nonowner trying to kill the contract 21 | // likely has malicious intent 22 | require(msg.sender == owner); 23 | selfdestruct(owner); 24 | } 25 | } -------------------------------------------------------------------------------- /contracts/schemes/PonziScheme.sol: -------------------------------------------------------------------------------- 1 | /// @title SimplePonzie, a simple ponzi scheme 2 | /// @author David Li 3 | /// @notice illustrate how a smart contract can be used as a ponzi scheme 4 | contract SimplePonzi { 5 | address public currentInvestor; 6 | uint public currentInvestment = 0; 7 | /// @dev new investments must be 10% greater than current 8 | function () payable public { 9 | uint minimumInvestment = currentInvestment * 11/10; 10 | require(msg.value > minimumInvestment); 11 | // document new investor 12 | address previousInvestor = currentInvestor; 13 | currentInvestor = msg.sender; 14 | currentInvestment = msg.value; 15 | // payout previous investor 16 | previousInvestor.send(msg.value); 17 | } 18 | } -------------------------------------------------------------------------------- /contracts/util/SafeMath.sol: -------------------------------------------------------------------------------- 1 | /// @author David Li 2 | /// @dev Safe Math, making sure overflow, and underflow don't occur. 3 | contract SafeMath { 4 | function safeMul(uint a, uint b) internal pure returns 5 | (uint) { 6 | uint c = a * b; 7 | assert(a == 0 || c / a == b); 8 | return c; 9 | } 10 | function safeDiv(uint a, uint b) internal pure returns 11 | (uint) { 12 | assert(b > 0); 13 | uint c = a / b; 14 | assert(a == b * c + a % b); 15 | return c; 16 | } 17 | function safeSub(uint a, uint b) internal pure returns 18 | (uint) { 19 | assert(b <= a); 20 | return a - b; 21 | } 22 | function safeAdd(uint a, uint b) internal pure returns 23 | (uint) { 24 | uint c = a + b; 25 | assert(c>=a && c>=b); 26 | return c; 27 | } 28 | } -------------------------------------------------------------------------------- /.travis-vuepress.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "10" 4 | env: 5 | - CXX=g++-4.8 6 | addons: 7 | apt: 8 | sources: 9 | - ubuntu-toolchain-r-test 10 | packages: 11 | - g++-4.8 12 | install: 13 | - npm install 14 | script: 15 | - npm run docs:build 16 | cache: 17 | directories: 18 | - "node_modules" 19 | notifications: 20 | email: false 21 | deploy: 22 | provider: pages 23 | skip-cleanup: true 24 | local_dir: docs/.vuepress/dist 25 | github-token: $GITHUB_TOKEN # Set in the settings page of your repository, as a secure variable 26 | repo: FriendlyUser/solidity-smart-contracts 27 | keep-history: true 28 | target-branch: gh-pages 29 | on: 30 | branch: master -------------------------------------------------------------------------------- /contracts/basic/MyContract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.8; 2 | 3 | contract MyContract { 4 | 5 | // naive recursion 6 | function sum(uint n) view returns(uint) { 7 | return n == 0 ? 0 : 8 | n + sum(n-1); 9 | } 10 | 11 | // loop 12 | function sumloop(uint n) view returns(uint) { 13 | uint256 total = 0; 14 | for(uint256 i=1; i<=n; i++) { 15 | total += i; 16 | } 17 | return total; 18 | } 19 | 20 | // tail-recursion 21 | function sumtailHelper(uint n, uint acc) private view returns(uint) { 22 | return n == 0 ? acc : 23 | sumtailHelper(n-1, acc + n); 24 | } 25 | function sumtail(uint n) view returns(uint) { 26 | return sumtailHelper(n, 0); 27 | } 28 | } -------------------------------------------------------------------------------- /contracts/schemes/GradualPonzi.sol: -------------------------------------------------------------------------------- 1 | /// @dev Gradual Ponzi 2 | /// @notice a more reasonable ponzi scheme 3 | contract GradualPonzi { 4 | address[] public investors; 5 | mapping (address => uint) public balances; 6 | uint public constant MINIMUM_INVESTMENT = 1e15; 7 | function GradualPonzi () public { 8 | investors.push(msg.sender); 9 | } 10 | 11 | function () public payable { 12 | require(msg.value >= MINIMUM_INVESTMENT); 13 | uint eachInvestorGets = msg.value / 14 | investors.length; 15 | for (uint i=0; i < investors.length; i++) { 16 | balances[investors[i]] += eachInvestorGets; 17 | } 18 | investors.push(msg.sender); 19 | } 20 | function withdraw () public { 21 | uint payout = balances[msg.sender]; 22 | balances[msg.sender] = 0; 23 | msg.sender.transfer(payout); 24 | } 25 | } -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [FriendlyUser] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /contracts/tokens/TokenSale.sol: -------------------------------------------------------------------------------- 1 | 2 | import './ERC20.sol'; 3 | contract TokenSale { 4 | enum State { Active, Suspended } 5 | address public owner; 6 | ERC20 public token; 7 | State public state; 8 | function TokenSale(address tokenContractAddress) { 9 | owner = msg.sender; 10 | token = ERC20(tokenContractAddress); 11 | state = State.Active; 12 | } 13 | // 1:1 exchange of ETH for token 14 | function buy() payable { 15 | require(state == State.Active); 16 | token.transfer(msg.sender, msg.value); 17 | } 18 | function suspend () { 19 | require(msg.sender == owner); 20 | state = State.Suspended; 21 | } 22 | function activate () { 23 | require(msg.sender == owner); 24 | state = State.Active; 25 | } 26 | function withdraw() { 27 | require(msg.sender == owner); 28 | owner.transfer(address(this).balance); 29 | } 30 | } -------------------------------------------------------------------------------- /downloadBinary.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # You can fetch some binary directly from release on github 4 | # 5 | # We encourage to build your own version from source. 6 | # 7 | 8 | GIT_USER=ethereum 9 | GIT_PROJECT=solidity 10 | BASE_URL=https://github.com/$GIT_USER/$GIT_PROJECT/releases/download 11 | RELEASE=v0.4.25 12 | BINARY=solc-static-linux 13 | 14 | if [[ -e $BINARY ]] 15 | then 16 | echo "file in the way: '$BINARY' remove it." 17 | exit 1 18 | fi 19 | 20 | if [[ $(getconf LONG_BIT) == "64" ]] 21 | then 22 | echo "I'm 64-bits" 23 | URL="$BASE_URL/$RELEASE/$BINARY" 24 | else 25 | echo "I'm 32-bits" 26 | URL="$BASE_URL/$RELEASE/${BINARY}-32bits" 27 | fi 28 | 29 | set -e 30 | echo "Fetching from: $URL" 31 | sudo wget --quiet --output-document /usr/local/bin/solc "$URL" 32 | # file $BINARY 33 | sudo chmod a+x /usr/local/bin/solc -------------------------------------------------------------------------------- /contracts/tokens/ERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | /// @title ERC20 interface 3 | /// @dev see https://github.com/ethereum/EIPs/issues/20 4 | contract ERC20 { 5 | function totalSupply() public view returns (uint256); 6 | 7 | function balanceOf(address _who) public view returns (uint256); 8 | 9 | function allowance(address _owner, address _spender) 10 | public view returns (uint256); 11 | 12 | function transfer(address _to, uint256 _value) public returns (bool); 13 | 14 | function approve(address _spender, uint256 _value) 15 | public returns (bool); 16 | 17 | function transferFrom(address _from, address _to, uint256 _value) 18 | public returns (bool); 19 | 20 | event Transfer( 21 | address indexed from, 22 | address indexed to, 23 | uint256 value 24 | ); 25 | 26 | event Approval( 27 | address indexed owner, 28 | address indexed spender, 29 | uint256 value 30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "solidity-smart-contracts", 3 | "version": "0.2.0", 4 | "main": "index.js", 5 | "description": "List of smart contracts in Solidity.", 6 | "repository": "https://github.com/FriendlyUser/solidity-smart-contracts/", 7 | "author": "FriendlyUser ", 8 | "license": "MIT", 9 | "keywords": [ 10 | "vue", 11 | "vuepress", 12 | "solidity", 13 | "smart-contracts" 14 | ], 15 | "scripts": { 16 | "docs:dev": "node node_modules/vuepress/bin/vuepress dev docs", 17 | "docs:build": "node node_modules/vuepress/bin/vuepress.js build docs", 18 | "dev": "vuepress dev docs", 19 | "build": "vuepress build docs", 20 | "solidity:docs": "node solidityDocs.js" 21 | }, 22 | "devDependencies": { 23 | "@soldoc/soldoc": "^0.4.3", 24 | "vuepress": "^0.13.0" 25 | }, 26 | "dependencies": { 27 | "markdown-it-plantuml": "^1.1.0", 28 | "markdown-it-task-lists": "^2.1.1" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /contracts/other/CredVert/SafeMath32.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.21; 2 | /** 3 | * @title SafeMath32 4 | * @dev SafeMath library implemented for uint32 5 | */ 6 | library SafeMath32 { 7 | 8 | function mul(uint32 a, uint32 b) internal pure returns (uint32) { 9 | if (a == 0) { 10 | return 0; 11 | } 12 | uint32 c = a * b; 13 | assert(c / a == b); 14 | return c; 15 | } 16 | 17 | function div(uint32 a, uint32 b) internal pure returns (uint32) { 18 | // assert(b > 0); // Solidity automatically throws when dividing by 0 19 | uint32 c = a / b; 20 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 21 | return c; 22 | } 23 | 24 | function sub(uint32 a, uint32 b) internal pure returns (uint32) { 25 | assert(b <= a); 26 | return a - b; 27 | } 28 | 29 | function add(uint32 a, uint32 b) internal pure returns (uint32) { 30 | uint32 c = a + b; 31 | assert(c >= a); 32 | return c; 33 | } 34 | } -------------------------------------------------------------------------------- /contracts/datastruct/Stack.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.11; 2 | 3 | contract Stack { 4 | event Popped(bytes32 top, uint number, string name); 5 | event Pushed(bytes32 top, uint number, string name); 6 | uint public height = 0; 7 | bytes32 public top; 8 | struct Object { 9 | bytes32 next; 10 | uint number; 11 | string name; 12 | } 13 | mapping(bytes32 => Object) public objects; 14 | 15 | function Stack() public { 16 | 17 | } 18 | 19 | function push(uint _number,string _name) public returns (bool) { 20 | Object memory newObj = Object(top, _number, _name); 21 | bytes32 id = keccak256(newObj.number, newObj.name, now, height); 22 | objects[id] = newObj; 23 | top = id; 24 | height = height + 1; 25 | Pushed(top, newObj.number, newObj.name); 26 | } 27 | 28 | function pop() public returns (bool) { 29 | require(height > 0); 30 | bytes32 _top = top; 31 | top = objects[top].next; 32 | Popped(top, objects[_top].number, objects[_top].name); 33 | delete objects[_top]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /contracts/games/SimpleLottery.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.18; 2 | 3 | contract SimpleLottery { 4 | uint public constant TICKET_PRICE = 1e16; // 0.01 ether 5 | 6 | address[] public tickets; 7 | address public winner; 8 | uint public ticketingCloses; 9 | 10 | function SimpleLottery (uint duration) public { 11 | ticketingCloses = now + duration; 12 | } 13 | 14 | function buy () public payable { 15 | require(msg.value == TICKET_PRICE); 16 | require(now < ticketingCloses); 17 | 18 | tickets.push(msg.sender); 19 | } 20 | 21 | function drawWinner () public { 22 | require(now > ticketingCloses + 5 minutes); 23 | require(winner == address(0)); 24 | 25 | bytes32 rand = keccak256( 26 | block.blockhash(block.number-1) 27 | ); 28 | winner = tickets[uint(rand) % tickets.length]; 29 | } 30 | 31 | 32 | function withdraw () public { 33 | require(msg.sender == winner); 34 | msg.sender.transfer(this.balance); 35 | } 36 | 37 | function () payable public { 38 | buy(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 David Li 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /contracts/other/URLShorter.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | contract e0x { 3 | event LinkVisited(string url, uint linkId); 4 | event LinkAdded(uint linkId, string url); 5 | 6 | struct LinkTemplate { 7 | address userAddress; 8 | string url; 9 | } 10 | 11 | uint lastLinkId; 12 | mapping (uint => LinkTemplate) public linkMapping; 13 | 14 | constructor() public { 15 | lastLinkId = 0; 16 | } 17 | 18 | 19 | function createNewLink(string url) public returns (uint) { 20 | lastLinkId++; 21 | linkMapping[lastLinkId] = LinkTemplate(msg.sender, url); 22 | emit LinkAdded(lastLinkId, url); 23 | return lastLinkId; 24 | } 25 | 26 | modifier linkExists(uint linkId) { 27 | //link with the given hash does not exist 28 | if(linkMapping[linkId].userAddress == 0x0000000000000000000000000000000000000000) { 29 | revert(); 30 | } 31 | _; 32 | } 33 | 34 | function getLink(uint linkId) linkExists(linkId) public constant 35 | returns( 36 | address, 37 | string 38 | ) { 39 | //emit LinkVisited(linkId, link.url); 40 | LinkTemplate memory link = linkMapping[linkId]; 41 | return( 42 | link.userAddress, 43 | link.url 44 | ); 45 | } 46 | } -------------------------------------------------------------------------------- /contracts/finance/Mortgage.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | contract Mortgage { 3 | 4 | address public owner; 5 | 6 | mapping (bytes32=>address[]) public ownerMap; 7 | mapping (address=>bytes32[]) public mortgageMap; 8 | 9 | function Mortgage() { 10 | owner = msg.sender; 11 | } 12 | 13 | function addData(bytes32 document) { 14 | address[] owners = ownerMap[document]; 15 | uint i; 16 | for(i=0;i uint) balances; 9 | address internal _stockAddress; 10 | constructor(address stock) { 11 | _stockAddress = stock; 12 | } 13 | 14 | function balanceOf(address owner) public returns (uint) { 15 | return balances[owner]; 16 | } 17 | 18 | function transfer(address _to, uint amount) public { 19 | uint test = 5; 20 | } 21 | } 22 | contract MarriageInvestment { 23 | address wife = address(0); // dummy address 24 | address husband = address(1); // dummy address 25 | Stock GOOG = Stock(address(2)); // dummy contract 26 | function split () public { 27 | uint amount = GOOG.balanceOf(address(this)); 28 | uint each = amount / 2; 29 | GOOG.transfer(husband, each); 30 | GOOG.transfer(wife, each); 31 | } 32 | 33 | function splitProper () public { 34 | uint amount = GOOG.balanceOf(address(this)); 35 | uint each = amount / 2; 36 | uint remainder = amount % 2; 37 | GOOG.transfer(husband, each + remainder); 38 | GOOG.transfer(wife, each); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /contracts/other/CredVert/Ownable.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.21; 2 | /** 3 | * @title Ownable 4 | * @dev The Ownable contract has an owner address, and provides basic authorization control 5 | * functions, this simplifies the implementation of "user permissions". 6 | */ 7 | contract Ownable { 8 | address public owner; 9 | 10 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 11 | 12 | /** 13 | * @dev The Ownable constructor sets the original `owner` of the contract to the sender 14 | * account. 15 | */ 16 | constructor () public { 17 | owner = msg.sender; 18 | } 19 | 20 | 21 | /** 22 | * @dev Throws if called by any account other than the owner. 23 | */ 24 | modifier onlyOwner() { 25 | require(msg.sender == owner); 26 | _; 27 | } 28 | 29 | 30 | /** 31 | * @dev Allows the current owner to transfer control of the contract to a newOwner. 32 | * @param newOwner The address to transfer ownership to. 33 | */ 34 | function transferOwnership(address newOwner) public onlyOwner { 35 | require(newOwner != address(0)); 36 | emit OwnershipTransferred(owner, newOwner); 37 | owner = newOwner; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /contracts/Users.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | 3 | /// @author David Li 4 | /// @title Users.sol 5 | /// @notice Basic user registerion system, could add timestamp, when user registered. 6 | /// @notice This is a todolist with storage on the blockchain, much more efficent to use a database 7 | contract Users { 8 | 9 | mapping(address => bytes32) public users; 10 | 11 | event UserCreated(address indexed _address, bytes32 _pseudo); 12 | event UserDestroyed(address indexed _address); 13 | 14 | function exists (address _address) public view returns (bool _exists) { 15 | return (users[_address] != bytes32(0)); 16 | } 17 | 18 | function authenticate () public view returns (bytes32 _pseudo) { 19 | require(exists(msg.sender)); 20 | return (users[msg.sender]); 21 | } 22 | 23 | function create (bytes32 _pseudo) public { 24 | users[msg.sender] = _pseudo ; 25 | emit UserCreated(msg.sender, _pseudo); 26 | } 27 | 28 | function destroy () public { 29 | require(exists(msg.sender)); 30 | delete users[msg.sender]; 31 | emit UserDestroyed(msg.sender); 32 | } 33 | 34 | function get (address _address) public view returns(bytes32 _pseudo) { 35 | require(exists(_address)); 36 | return (users[_address]); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | language: node_js 3 | node_js: 4 | - "8" 5 | script: 6 | - chmod a+x downloadBinary.sh 7 | - ./downloadBinary.sh 8 | # - sudo add-apt-repository -y ppa:ethereum/ethereum 9 | # - sudo apt-get update 10 | # - sudo apt-cache policy solc 11 | # - sudo apt-get -y install solc 12 | # - sudo apt-get -y install solc 13 | - rm -rf contracts/games/Powerball.sol 14 | - npm install -g solidity-docgen 15 | - solidity-docgen /home/travis/build/FriendlyUser/solidity-smart-contracts /home/travis/build/FriendlyUser/solidity-smart-contracts/contracts /home/travis/build/FriendlyUser/solidity-smart-contracts 16 | - cd website 17 | - npm install 18 | - npm run build 19 | - cd ../ 20 | - mv docs mddocs 21 | - mv mddocs website/build/solidity-smart-contracts 22 | - sed -i '6i ' website/build/**/*.html 23 | deploy: 24 | provider: pages 25 | skip-cleanup: true 26 | local_dir: website/build/solidity-smart-contracts # or remove this line to upload from root of repo 27 | github-token: $GITHUB_TOKEN # Set in the settings page of your repository, as a secure variable 28 | keep-history: true 29 | on: 30 | branch: master 31 | #after_script: 32 | # - npm run coverage && cat coverage/lcov.info | coveralls 33 | -------------------------------------------------------------------------------- /Readme.Md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/FriendlyUser/solidity-smart-contracts.svg?branch=master)](https://travis-ci.org/FriendlyUser/solidity-smart-contracts) [![DOI](https://zenodo.org/badge/143545024.svg)](https://zenodo.org/badge/latestdoi/143545024) 2 | # Solidity-smart contracts 3 | 4 | Since the solidity programming language is used in multiple blockchain platform including 5 | 6 | - Ethereum 7 | - Hedera 8 | 9 | learning solidity is invaluable as blockchain technologies and smart contracts will be eseential in the future. 10 | 11 | **Disclaimer** Getting contracts to compile on solidity *4.2x and 5 is quite difficult in addition to the rapid changes to the openzeppelin framework. 12 | 13 | I think I'll end up flattener all open zeppelin contracts just to be save in the future and may rely on other ways to generic solidity documentation. 14 | 15 | ## Documentation 16 | 17 | A statically generated site via vuepress and the soldoc solidity documentation which produces markdown. 18 | 19 | To generate markdown documentation make sure [soldoc](https://github.com/dev-matan-tsuberi/soldoc) is installed. 20 | ```sh 21 | soldoc -o ./docs/contracts --log ./docs/contracts/Soldoc.md 22 | ``` 23 | 24 | 25 | ### References 26 | 27 | * https://github.com/aunyks/vitruvius 28 | * https://github.com/PruthviKumarBK/Decentralized_eCom 29 | * https://github.com/woodydeck/What-Does-Nadia-Think 30 | -------------------------------------------------------------------------------- /docs/.vuepress/override.styl: -------------------------------------------------------------------------------- 1 | // showing default values 2 | // $accentColor = #0984e3 3 | // $textColor = #2c3e50 4 | // $borderColor = #eaecef 5 | // $codeBgColor = #282c34 6 | 7 | blockquote { 8 | margin: 0 auto; 9 | padding: 1em; 10 | border-left: 5px solid #999; 11 | } 12 | blockquote:before { 13 | display: none; 14 | } 15 | blockquote:not(:first-of-type) { 16 | margin-top: .5em; 17 | } 18 | blockquote p { 19 | color: #555; 20 | font-size: 12pt; 21 | line-height: 1.4; 22 | font-family: 'PT Serif', Cambria, 'Hoefler Text', Utopia, 'Liberation Serif', 'Nimbus Roman No9 L Regular', Times, 'Times New Roman', serif; 23 | } 24 | blockquote footer { 25 | margin-top: .5em; 26 | padding: 0; 27 | color: #777; 28 | font-size: 12pt; 29 | text-align: left; 30 | font-style: italic; 31 | } 32 | blockquote footer:before { 33 | content: '— '; 34 | } 35 | blockquote:nth-of-type(even) { 36 | text-align: right; 37 | border-left: none; 38 | border-right: 5px solid #999; 39 | } 40 | blockquote:nth-of-type(even) footer { 41 | text-align: right; 42 | } 43 | blockquote:nth-of-type(even) footer:before { 44 | content: ''; 45 | } 46 | blockquote:nth-of-type(even) footer:after { 47 | content: ' —'; 48 | } 49 | @element 'blockquote' and (min-width: 300px) { 50 | blockquote { 51 | padding: 1em 20% 1em 1em; 52 | } 53 | blockquote p { 54 | font-size: 14pt; 55 | } 56 | blockquote:nth-of-type(even) { 57 | padding: 1em 1em 1em 20%; 58 | } 59 | } -------------------------------------------------------------------------------- /contracts/schemes/SimplePyramid.sol: -------------------------------------------------------------------------------- 1 | contract SimplePyramid { 2 | uint public constant MINIMUM_INVESTMENT = 1e15; // 0.001 ether 3 | uint public numInvestors = 0; 4 | uint public depth = 0; 5 | address[] public investors; 6 | mapping(address => uint) public balances; 7 | function SimplePyramid () public payable { 8 | require(msg.value >= MINIMUM_INVESTMENT); 9 | investors.length = 3; 10 | investors[0] = msg.sender; 11 | numInvestors = 1; 12 | depth = 1; 13 | balances[address(this)] = msg.value; 14 | } 15 | function () payable public { 16 | require(msg.value >= MINIMUM_INVESTMENT); 17 | balances[address(this)] += msg.value; 18 | numInvestors += 1; 19 | investors[numInvestors - 1] = msg.sender; 20 | if (numInvestors == investors.length) { 21 | // pay out previous layer 22 | uint endIndex = numInvestors - 2**depth; 23 | uint startIndex = endIndex - 2**(depth-1); 24 | for (uint i = startIndex; i < endIndex; i++) 25 | balances[investors[i]] += MINIMUM_INVESTMENT; 26 | // spread remaining ether among all participants 27 | uint paid = MINIMUM_INVESTMENT * 2**(depth-1); 28 | uint eachInvestorGets = (balances[address(this)] - paid) / numInvestors; 29 | for(i = 0; i < numInvestors; i++) 30 | balances[investors[i]] += eachInvestorGets; 31 | // update state variables 32 | balances[address(this)] = 0; 33 | depth += 1; 34 | investors.length += 2**depth; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /website/pages/en/users.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | const React = require('react'); 9 | 10 | const CompLibrary = require('../../core/CompLibrary.js'); 11 | const Container = CompLibrary.Container; 12 | 13 | const siteConfig = require(process.cwd() + '/siteConfig.js'); 14 | 15 | class Users extends React.Component { 16 | render() { 17 | if ((siteConfig.users || []).length === 0) { 18 | return null; 19 | } 20 | const editUrl = siteConfig.repoUrl + '/edit/master/website/siteConfig.js'; 21 | const showcase = siteConfig.users.map((user, i) => { 22 | return ( 23 | 24 | {user.caption} 25 | 26 | ); 27 | }); 28 | 29 | return ( 30 |
31 | 32 |
33 |
34 |

Who's Using This?

35 |

This project is used by many folks

36 |
37 |
{showcase}
38 |

Are you using this project?

39 | 40 | Add your company 41 | 42 |
43 |
44 |
45 | ); 46 | } 47 | } 48 | 49 | module.exports = Users; 50 | -------------------------------------------------------------------------------- /contracts/TodoList.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | 3 | /// @author David Li 4 | /// @title Todo List Contract 5 | /// @notice A sample to do list for my Vue Dapp 6 | /// @dev This is a todolist with storage on the blockchain, much more efficent to use a database. 7 | 8 | contract TodoList { 9 | struct Todo { 10 | uint256 id; 11 | bytes32 content; 12 | address owner; 13 | bool isCompleted; 14 | uint256 timestamp; 15 | } 16 | uint256 public constant maxAmountOfTodos = 1000; 17 | /// @dev Owner => todos 18 | mapping(address => Todo[maxAmountOfTodos]) public todos; 19 | /// @dev Owner => last todo id 20 | mapping(address => uint256) public lastIds; 21 | modifier onlyOwner(address _owner) { 22 | require(msg.sender == _owner); 23 | _; 24 | } 25 | /// @notice Add a todo to the list 26 | /// @param _content list item to append. 27 | function addTodo(bytes32 _content) public { 28 | Todo memory myNote = Todo(lastIds[msg.sender], _content, msg.sender, false, now); 29 | todos[msg.sender][lastIds[msg.sender]] = myNote; 30 | if(lastIds[msg.sender] >= maxAmountOfTodos) lastIds[msg.sender] = 0; 31 | else lastIds[msg.sender]++; 32 | } 33 | /// @notice marking a todoitem as completed 34 | /// @param _todoId todolist item ID Mark a todo as completed 35 | function markTodoAsCompleted(uint256 _todoId) public onlyOwner(todos[msg.sender][_todoId].owner) { 36 | require(_todoId < maxAmountOfTodos); 37 | require(!todos[msg.sender][_todoId].isCompleted); 38 | todos[msg.sender][_todoId].isCompleted = true; 39 | } 40 | } -------------------------------------------------------------------------------- /contracts/games/RNGLottery.sol: -------------------------------------------------------------------------------- 1 | 2 | contract RNGLottery { 3 | uint constant public TICKET_PRICE = 1e16; 4 | 5 | address[] public tickets; 6 | address public winner; 7 | bytes32 public seed; 8 | mapping(address => bytes32) public commitments; 9 | 10 | uint public ticketDeadline; 11 | uint public revealDeadline; 12 | 13 | function RNGLottery (uint duration, uint revealDuration) public { 14 | ticketDeadline = block.number + duration; 15 | revealDeadline = ticketDeadline + revealDuration; 16 | } 17 | 18 | function createCommitment(address user, uint N) 19 | public pure returns (bytes32 commitment) { 20 | return keccak256(user, N); 21 | } 22 | 23 | function buy (bytes32 commitment) payable public { 24 | require(msg.value == TICKET_PRICE); 25 | require(block.number <= ticketDeadline); 26 | 27 | commitments[msg.sender] = commitment; 28 | } 29 | 30 | function reveal (uint N) public { 31 | require(block.number > ticketDeadline); 32 | require(block.number <= revealDeadline); 33 | 34 | bytes32 hash = createCommitment(msg.sender, N); 35 | require(hash == commitments[msg.sender]); 36 | 37 | seed = keccak256(seed, N); 38 | tickets.push(msg.sender); 39 | } 40 | 41 | function drawWinner () public { 42 | require(block.number > revealDeadline); 43 | require(winner == address(0)); 44 | 45 | uint randIndex = uint(seed) % tickets.length; 46 | winner = tickets[randIndex]; 47 | } 48 | 49 | function withdraw () public { 50 | require(msg.sender == winner); 51 | msg.sender.transfer(this.balance); 52 | } 53 | } -------------------------------------------------------------------------------- /website/pages/en/help.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | const React = require('react'); 9 | 10 | const CompLibrary = require('../../core/CompLibrary.js'); 11 | const Container = CompLibrary.Container; 12 | const GridBlock = CompLibrary.GridBlock; 13 | 14 | const siteConfig = require(process.cwd() + '/siteConfig.js'); 15 | 16 | function docUrl(doc, language) { 17 | return siteConfig.baseUrl + 'docs/' + (language ? language + '/' : '') + doc; 18 | } 19 | 20 | class Help extends React.Component { 21 | render() { 22 | let language = this.props.language || ''; 23 | const supportLinks = [ 24 | { 25 | content: `Learn more using the [documentation on this site.](${docUrl( 26 | 'api_TodoList.html', 27 | language 28 | )})`, 29 | title: 'Browse Docs', 30 | }, 31 | { 32 | content: 'Ask questions about the documentation and project', 33 | title: 'Join the community', 34 | }, 35 | { 36 | content: "Find out what's new with this project", 37 | title: 'Stay up to date', 38 | }, 39 | ]; 40 | 41 | return ( 42 |
43 | 44 |
45 |
46 |

Need help?

47 |
48 |

This project is maintained by a dedicated group of people which includes myself.

49 | 50 |
51 |
52 |
53 | ); 54 | } 55 | } 56 | 57 | module.exports = Help; 58 | -------------------------------------------------------------------------------- /contracts/games/SatoshiDice.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.18; 2 | 3 | contract SatoshiDice { 4 | struct Bet { 5 | address user; 6 | uint block; 7 | uint cap; 8 | uint amount; 9 | } 10 | 11 | uint public constant FEE_NUMERATOR = 1; 12 | uint public constant FEE_DENOMINATOR = 100; 13 | uint public constant MAXIMUM_CAP = 100000; 14 | uint public constant MAXIMUM_BET_SIZE = 1e18; 15 | 16 | address owner; 17 | uint public counter = 0; 18 | mapping(uint => Bet) public bets; 19 | 20 | event BetPlaced(uint id, address user, uint cap, uint amount); 21 | event Roll(uint id, uint rolled); 22 | 23 | function SatoshiDice () public { 24 | owner = msg.sender; 25 | } 26 | 27 | function wager (uint cap) public payable { 28 | require(cap <= MAXIMUM_CAP); 29 | require(msg.value <= MAXIMUM_BET_SIZE); 30 | 31 | counter++; 32 | bets[counter] = Bet(msg.sender, block.number + 3, cap, msg.value); 33 | BetPlaced(counter, msg.sender, cap, msg.value); 34 | } 35 | 36 | function roll(uint id) public { 37 | Bet storage bet = bets[id]; 38 | require(msg.sender == bet.user); 39 | require(block.number >= bet.block); 40 | require(block.number <= bet.block + 255); 41 | 42 | bytes32 random = keccak256(block.blockhash(bet.block), id); 43 | uint rolled = uint(random) % MAXIMUM_CAP; 44 | if (rolled < bet.cap) { 45 | uint payout = bet.amount * MAXIMUM_CAP / bet.cap; 46 | uint fee = payout * FEE_NUMERATOR / FEE_DENOMINATOR; 47 | payout -= fee; 48 | msg.sender.transfer(payout); 49 | } 50 | 51 | emit Roll(id, rolled); 52 | delete bets[id]; 53 | } 54 | 55 | function fund () payable public {} 56 | 57 | function kill () public { 58 | require(msg.sender == owner); 59 | selfdestruct(owner); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /contracts/datastruct/LinkedList.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.11; 2 | 3 | contract LinkedList { 4 | 5 | event AddEntry(bytes32 head, uint number, string name, bytes32 next); 6 | event RemoveEntry(bytes32 head, uint number, string name, bytes32 next); 7 | uint public length = 0; 8 | bytes32 public head; 9 | struct Object { 10 | bytes32 next; 11 | uint number; 12 | string name; 13 | } 14 | mapping (bytes32 => Object) public objects; 15 | 16 | function LinkedList() public { 17 | } 18 | 19 | function addEntry(uint _number,string _name) public returns (bool) { 20 | Object memory object = Object(head,_number,_name); 21 | bytes32 id = keccak256(object.number,object.name,now,length); 22 | objects[id] = object; 23 | head = id; 24 | length = length + 1; 25 | AddEntry(head,object.number,object.name,object.next); 26 | } 27 | 28 | function removeEntry(bytes32 _id) public returns (bool) { 29 | require(length > 0); 30 | bytes32 current = head; 31 | while (current != 0 && current != _id && objects[current].next != _id) { 32 | current = objects[current].next; 33 | } 34 | // Let's not waste gas if the id doesn't exist 35 | require(current != 0); 36 | 37 | if (current != _id) { 38 | // Since we've found the node that points to the 39 | // node with id `_id`, we can point this node's 40 | // `next` to `_id`'s `next` 41 | objects[current].next = objects[_id].next; 42 | } else { 43 | // Since the current node is the head, 44 | // we can move the head to the next node 45 | // because this will soon be removed 46 | head = objects[_id].next; 47 | } 48 | length = length - 1; 49 | RemoveEntry(head, objects[_id].number, objects[_id].name, objects[_id].next); 50 | delete objects[_id]; 51 | } 52 | 53 | //needed for external contract access to struct 54 | function getEntry(bytes32 _id) view public returns (bytes32, uint, string) { 55 | return (objects[_id].next, objects[_id].number, objects[_id].name); 56 | } 57 | } -------------------------------------------------------------------------------- /contracts/basic/ecom/Suppliers.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Pruthvi Kumar 3 | * @email pruthvikumar.123@gmail.com 4 | * @create date 2018-09-20 16:50:12 5 | * @modify date 2018-09-20 16:50:12 6 | * @desc Supplier in our E-Com platform. 7 | */ 8 | pragma solidity ^0.4.17; 9 | // We have to specify what version of compiler this code will compile with 10 | 11 | contract Supplier { 12 | 13 | /* Events */ 14 | event ItemAdded(uint idItem); 15 | event ProcessAnOrder(uint idOfCustomer, uint idOrder, bool status); 16 | 17 | struct Item { 18 | uint idItem; 19 | bytes32 itemName; 20 | uint price; 21 | } 22 | 23 | struct Orderlog { 24 | uint idOfCustomer; 25 | uint idOrder; 26 | bool status; 27 | } 28 | 29 | // STATE Variables. 30 | uint numberOfItemsAvailableForSale; 31 | uint numberOfOrdersProcessed; 32 | 33 | // Mappings 34 | mapping (uint => Item) items; 35 | mapping (uint => Orderlog) orderLogs; 36 | 37 | 38 | /* TRANSACTIONS */ 39 | function addItem(bytes32 itemName, uint price) public { 40 | uint idItem = numberOfItemsAvailableForSale++; 41 | items[idItem] = Item(idItem, itemName, price); 42 | emit ItemAdded(idItem); 43 | } 44 | 45 | function processOrder(uint idOrder, uint idCustomer) public { 46 | orderLogs[idOrder] = Orderlog(idCustomer, idOrder, true); 47 | numberOfOrdersProcessed ++; 48 | emit ProcessAnOrder(idCustomer, idOrder, true); 49 | } 50 | 51 | /* GETTERS */ 52 | function getItem(uint idItem) view public returns (bytes32, uint){ 53 | /*returns itemName and its price*/ 54 | return (items[idItem].itemName, items[idItem].price); 55 | } 56 | 57 | function getStatus(uint idOrder) view public returns (bool) { 58 | /*returns completion status*/ 59 | return (orderLogs[idOrder].status); 60 | } 61 | 62 | function getTotalNumberOfAvailableItems() view public returns (uint) { 63 | return numberOfItemsAvailableForSale; 64 | } 65 | 66 | function getTotalNumberOfOrdersProcessed() view public returns (uint){ 67 | return numberOfOrdersProcessed; 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /contracts/basic/ecom/Customer.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Pruthvi Kumar 3 | * @email pruthvikumar.123@gmail.com 4 | * @create date 2018-09-20 16:50:12 5 | * @modify date 2018-09-20 16:50:12 6 | * @desc Customer in our E-Com platform. 7 | */ 8 | pragma solidity ^0.4.17; 9 | // We have to specify what version of compiler this code will compile with 10 | 11 | contract Customer { 12 | 13 | /* Events */ 14 | event OrderRaisedOrUpdated(uint idOrder); 15 | 16 | struct AvailableCustomer { 17 | uint idCustomer; 18 | bytes32 customerName; 19 | } 20 | 21 | struct Orderlog { 22 | uint idOrder; 23 | uint idCustomer; 24 | bytes32 itemName; 25 | uint quantity; 26 | bool status; 27 | } 28 | 29 | // STATE Variables. 30 | uint numberOfItemsPurchased; 31 | uint numberOfItemsReceived; 32 | 33 | // Mappings 34 | mapping (uint => AvailableCustomer) customers; 35 | mapping (uint => Orderlog) orderLogs; 36 | 37 | /* Constructor */ 38 | constructor() public { 39 | /* For the case of demo, adding a customer in constructor. You can take this idea and extend the contract to contain addCustomer section and hence maintain customerDB in the Blockchain! */ 40 | customers[0] = AvailableCustomer(1, "John Snow"); 41 | } 42 | 43 | /* TRANSACTIONS */ 44 | function purchaseItem(bytes32 itemName, uint quantity) public { 45 | uint idOrder = numberOfItemsPurchased++; 46 | orderLogs[idOrder] = Orderlog(idOrder, 0, itemName, quantity, false); 47 | emit OrderRaisedOrUpdated(idOrder); 48 | } 49 | 50 | function recieveItem(uint idOrder) public { 51 | numberOfItemsReceived++; 52 | orderLogs[idOrder].status = true; 53 | emit OrderRaisedOrUpdated(idOrder); 54 | } 55 | 56 | /* GETTERS */ 57 | function getOrderDetails(uint idOrder) view public returns (bytes32, uint, bool){ 58 | /*returns itemName, quantity & completionStatus*/ 59 | return (orderLogs[idOrder].itemName, orderLogs[idOrder].quantity, orderLogs[idOrder].status); 60 | } 61 | 62 | function getNumberOfItemsPurchased() view public returns (uint) { 63 | return numberOfItemsPurchased; 64 | } 65 | 66 | function getNumberOfItemsReceived() view public returns (uint) { 67 | return numberOfItemsReceived; 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /contracts/Authentication.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | 3 | /// @author David Li 4 | /// @dev basic authentication contract 5 | /// @notice tracks list of all users 6 | contract Authentication { 7 | struct User { 8 | bytes32 name; 9 | uint256 created_at; 10 | } 11 | 12 | event UserCreated(address indexed _address, bytes32 _name, uint256 _created_at); 13 | event UserUpdated(address indexed _address, bytes32 _name); 14 | event UserDeleted(address indexed _address); 15 | 16 | mapping (address => User) private users; 17 | 18 | // public array that contains list of all users that have registered 19 | address[] public allUsers; 20 | modifier onlyExistingUser { 21 | // Check if user exists or terminate 22 | 23 | require(!(users[msg.sender].name == 0x0)); 24 | _; 25 | } 26 | 27 | modifier onlyValidName(bytes32 name) { 28 | // Only valid names allowed 29 | 30 | require(!(name == 0x0)); 31 | _; 32 | } 33 | 34 | /// @return username 35 | function login() 36 | public 37 | view 38 | onlyExistingUser 39 | returns (bytes32) { 40 | return (users[msg.sender].name); 41 | } 42 | 43 | /// @param name the username to be created. 44 | /// @dev checks if user exists 45 | /// If yes return user name 46 | /// If no, check if name was sent 47 | /// If yes, create and return user 48 | /// @return username of created user 49 | function signup(bytes32 name) 50 | public 51 | payable 52 | onlyValidName(name) 53 | returns (bytes32) { 54 | 55 | if (users[msg.sender].name == 0x0) 56 | { 57 | users[msg.sender].name = name; 58 | users[msg.sender].created_at = now; 59 | 60 | allUsers.push(msg.sender); 61 | emit UserCreated(msg.sender,name,now); 62 | return (users[msg.sender].name); 63 | } 64 | 65 | return (users[msg.sender].name); 66 | } 67 | 68 | /// @param name updating username 69 | /// @dev updating user name 70 | /// @return updated username 71 | function update(bytes32 name) 72 | public 73 | payable 74 | onlyValidName(name) 75 | onlyExistingUser 76 | returns (bytes32) { 77 | // Update user name. 78 | 79 | if (users[msg.sender].name != 0x0) 80 | { 81 | users[msg.sender].name = name; 82 | 83 | emit UserUpdated(msg.sender,name); 84 | 85 | return (users[msg.sender].name); 86 | } 87 | } 88 | 89 | /// @dev destroy existing username 90 | function destroy () 91 | public 92 | onlyExistingUser { 93 | delete users[msg.sender]; 94 | emit UserDeleted(msg.sender); 95 | } 96 | } -------------------------------------------------------------------------------- /contracts/tokens/AttendanceToken/EIP20Interface.sol: -------------------------------------------------------------------------------- 1 | // Abstract contract for the full ERC 20 Token standard 2 | // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md 3 | pragma solidity ^0.4.21; 4 | 5 | 6 | contract EIP20Interface { 7 | /* This is a slight change to the ERC20 base standard. 8 | function totalSupply() constant returns (uint256 supply); 9 | is replaced with: 10 | uint256 public totalSupply; 11 | This automatically creates a getter function for the totalSupply. 12 | This is moved to the base contract since public getter functions are not 13 | currently recognised as an implementation of the matching abstract 14 | function by the compiler. 15 | */ 16 | /// total amount of tokens 17 | uint256 public totalSupply; 18 | 19 | /// @param _owner The address from which the balance will be retrieved 20 | /// @return The balance 21 | function balanceOf(address _owner) public view returns (uint256 balance); 22 | 23 | /// @notice send `_value` token to `_to` from `msg.sender` 24 | /// @param _to The address of the recipient 25 | /// @param _value The amount of token to be transferred 26 | /// @return Whether the transfer was successful or not 27 | function transfer(address _to, uint256 _value) public returns (bool success); 28 | 29 | /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` 30 | /// @param _from The address of the sender 31 | /// @param _to The address of the recipient 32 | /// @param _value The amount of token to be transferred 33 | /// @return Whether the transfer was successful or not 34 | function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); 35 | 36 | /// @notice `msg.sender` approves `_spender` to spend `_value` tokens 37 | /// @param _spender The address of the account able to transfer the tokens 38 | /// @param _value The amount of tokens to be approved for transfer 39 | /// @return Whether the approval was successful or not 40 | function approve(address _spender, uint256 _value) public returns (bool success); 41 | 42 | /// @param _owner The address of the account owning tokens 43 | /// @param _spender The address of the account able to transfer the tokens 44 | /// @return Amount of remaining tokens allowed to spent 45 | function allowance(address _owner, address _spender) public view returns (uint256 remaining); 46 | 47 | // solhint-disable-next-line no-simple-event-func-name 48 | event Transfer(address indexed _from, address indexed _to, uint256 _value); 49 | event Approval(address indexed _owner, address indexed _spender, uint256 _value); 50 | } -------------------------------------------------------------------------------- /contracts/tokens/BasicToken.sol: -------------------------------------------------------------------------------- 1 | // declare which version of Solidity we are using 2 | // different versions of Solidity have different 3 | pragma solidity ^0.4.18; 4 | 5 | // define a smart contract called "BasicToken" 6 | contract BasicToken { 7 | 8 | // examples of simple variables 9 | // string myName; 10 | // bool isApproved; 11 | // uint daysRemaining; 12 | 13 | // an array is a list of individuals values, e.g. list of numbers, list of names 14 | // uint256[] numbers; 15 | 16 | // a mapping is a list of pairs 17 | mapping(address => uint256) balances; // a mapping of all user's balances 18 | // 0xa5c => 10 Ether 19 | // 0x91b => 5 Ether 20 | // 0xcdd => 1.25 Ether 21 | 22 | // another mapping example 23 | // mapping(address => bool) signatures; // a mapping of signatures 24 | // 0xa2d => true (approved) 25 | // 0xb24 => true (approved) 26 | // 0x515 => false (not approved) 27 | 28 | // address myAddress = 0x1235647381947839275893275893; // ethereum address 29 | // uint256 count = 10; // unsigned (non-negative) integer, 256-bytes in size 30 | 31 | /** 32 | * @dev transfer token for a specified address 33 | * @param recipient The address to transfer to. 34 | * @param value The amount to be transferred. 35 | */ 36 | // define a function called "transfer" 37 | // inputs? (parameters) an address called "recipient" and a uint256 called "value" 38 | function transfer(address recipient, uint256 value) public { 39 | // msg.sender is a predefined variable that specifies the address of the 40 | // person sending this transaction 41 | // address msg.sender = 0x5ba...; 42 | 43 | // balances[msg.sender] -> set the balance of the sender 44 | // set the balance of the sender to their current balance minus value 45 | // withdrawing tokens from the sender's account 46 | balances[msg.sender] -= value; 47 | 48 | // balances[recipient] -> set the balance of the receiver (recipient) 49 | // set the balance of the receiver to their current balance plus value 50 | // depositing tokens into the receiver's account 51 | balances[recipient] += value; 52 | } 53 | 54 | /** 55 | * @dev Gets the balance of the specified address. 56 | * @param account The address to query the the balance of. 57 | * @return An uint256 representing the amount owned by the passed address. 58 | */ 59 | // define function called "balanceOf" 60 | // inputs? (parameters) the address of the owner (account) 61 | // ontputs? (returns) the balance (number) 62 | function balanceOf(address account) public view returns (uint256) { 63 | 64 | // balances[account] -> return the balance of the owner 65 | return balances[account]; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /contracts/games/RecurringLottery.sol: -------------------------------------------------------------------------------- 1 | 2 | pragma solidity ^0.4.18; 3 | contract RecurringLottery { 4 | struct Round { 5 | uint endBlock; 6 | uint drawBlock; 7 | Entry[] entries; 8 | uint totalQuantity; 9 | address winner; 10 | } 11 | struct Entry { 12 | address buyer; 13 | uint quantity; 14 | } 15 | 16 | uint constant public TICKET_PRICE = 1e15; 17 | 18 | mapping(uint => Round) public rounds; 19 | uint public round; 20 | uint public duration; 21 | mapping (address => uint) public balances; 22 | 23 | // duration is in blocks. 1 day = ~5500 blocks 24 | function RecurringLottery (uint _duration) public { 25 | duration = _duration; 26 | round = 1; 27 | rounds[round].endBlock = block.number + duration; 28 | rounds[round].drawBlock = block.number + duration + 5; 29 | } 30 | 31 | function buy () payable public { 32 | require(msg.value % TICKET_PRICE == 0); 33 | 34 | if (block.number > rounds[round].endBlock) { 35 | round += 1; 36 | rounds[round].endBlock = block.number + duration; 37 | rounds[round].drawBlock = block.number + duration + 5; 38 | } 39 | 40 | uint quantity = msg.value / TICKET_PRICE; 41 | Entry memory entry = Entry(msg.sender, quantity); 42 | rounds[round].entries.push(entry); 43 | rounds[round].totalQuantity += quantity; 44 | } 45 | 46 | function drawWinner (uint roundNumber) public { 47 | Round storage drawing = rounds[roundNumber]; 48 | require(drawing.winner == address(0)); 49 | require(block.number > drawing.drawBlock); 50 | require(drawing.entries.length > 0); 51 | 52 | // pick winner 53 | bytes32 rand = keccak256( 54 | block.blockhash(drawing.drawBlock) 55 | ); 56 | uint counter = uint(rand) % drawing.totalQuantity; 57 | for (uint i=0; i < drawing.entries.length; i++) { 58 | uint quantity = drawing.entries[i].quantity; 59 | if (quantity > counter) { 60 | drawing.winner = drawing.entries[i].buyer; 61 | break; 62 | } 63 | else 64 | counter -= quantity; 65 | } 66 | 67 | balances[drawing.winner] += TICKET_PRICE * drawing.totalQuantity; 68 | } 69 | 70 | function withdraw () public { 71 | uint amount = balances[msg.sender]; 72 | balances[msg.sender] = 0; 73 | msg.sender.transfer(amount); 74 | } 75 | 76 | function deleteRound (uint _round) public { 77 | require(block.number > rounds[_round].drawBlock + 100); 78 | require(rounds[_round].winner != address(0)); 79 | delete rounds[_round]; 80 | } 81 | 82 | function () payable public { 83 | buy(); 84 | } 85 | } -------------------------------------------------------------------------------- /contracts/games/CasinoRoulette.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.18; 2 | contract CasinoRoulette { 3 | enum BetType { Color, Number } 4 | 5 | struct Bet { 6 | address user; 7 | uint amount; 8 | BetType betType; 9 | uint block; 10 | 11 | // @prop choice: interpretation is based on BetType 12 | // BetType.Color: 0=black, 1=red 13 | // BetType.Number: -1=00, 0-36 for individual numbers 14 | int choice; 15 | } 16 | 17 | uint public constant NUM_POCKETS = 38; 18 | // RED_NUMBERS and BLACK_NUMBERS are constant, but 19 | // Solidity doesn't support array constants yet so 20 | // we use storage arrays instead 21 | uint8[18] public RED_NUMBERS = [ 22 | 1, 3, 5, 7, 9, 12, 23 | 14, 16, 18, 19, 21, 23, 24 | 25, 27, 30, 32, 34, 36 25 | ]; 26 | uint8[18] public BLACK_NUMBERS = [ 27 | 2, 4, 6, 8, 10, 11, 28 | 13, 15, 17, 20, 22, 24, 29 | 26, 28, 29, 31, 33, 35 30 | ]; 31 | // maps wheel numbers to colors 32 | mapping(int => int) public COLORS; 33 | 34 | address public owner; 35 | uint public counter = 0; 36 | mapping(uint => Bet) public bets; 37 | 38 | event BetPlaced(address user, uint amount, BetType betType, uint block, int choice); 39 | event Spin(uint id, int landed); 40 | 41 | function CasinoRoulette () public { 42 | owner = msg.sender; 43 | for (uint i=0; i < 18; i++) { 44 | COLORS[RED_NUMBERS[i]] = 1; 45 | } 46 | } 47 | 48 | function wager (BetType betType, int choice) payable public { 49 | require(msg.value > 0); 50 | if (betType == BetType.Color) 51 | require(choice == 0 || choice == 1); 52 | else 53 | require(choice >= -1 && choice <= 36); 54 | counter++; 55 | bets[counter] = Bet(msg.sender, msg.value, betType, block.number + 3, choice); 56 | BetPlaced(msg.sender, msg.value, betType, block.number + 3, choice); 57 | } 58 | 59 | function spin (uint id) public { 60 | Bet storage bet = bets[id]; 61 | require(msg.sender == bet.user); 62 | require(block.number >= bet.block); 63 | require(block.number <= bet.block + 255); 64 | 65 | bytes32 random = keccak256(block.blockhash(bet.block), id); 66 | int landed = int(uint(random) % NUM_POCKETS) - 1; 67 | 68 | if (bet.betType == BetType.Color) { 69 | if (landed > 0 && COLORS[landed] == bet.choice) 70 | msg.sender.transfer(bet.amount * 2); 71 | } 72 | else if (bet.betType == BetType.Number) { 73 | if (landed == bet.choice) 74 | msg.sender.transfer(bet.amount * 35); 75 | } 76 | 77 | delete bets[id]; 78 | Spin(id, landed); 79 | } 80 | 81 | function fund () public payable {} 82 | 83 | function kill () public { 84 | require(msg.sender == owner); 85 | selfdestruct(owner); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /contracts/tokens/AttendanceToken/EIP20.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Implements EIP20 token standard: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md 3 | .*/ 4 | 5 | 6 | pragma solidity ^0.4.21; 7 | 8 | import "./EIP20Interface.sol"; 9 | 10 | 11 | contract EIP20 is EIP20Interface { 12 | 13 | uint256 constant private MAX_UINT256 = 2**256 - 1; 14 | mapping (address => uint256) public balances; 15 | mapping (address => mapping (address => uint256)) public allowed; 16 | /* 17 | NOTE: 18 | The following variables are OPTIONAL vanities. One does not have to include them. 19 | They allow one to customise the token contract & in no way influences the core functionality. 20 | Some wallets/interfaces might not even bother to look at this information. 21 | */ 22 | string public name; //fancy name: eg Simon Bucks 23 | uint8 public decimals; //How many decimals to show. 24 | string public symbol; //An identifier: eg SBX 25 | 26 | constructor ( 27 | uint256 _initialAmount, 28 | string _tokenName, 29 | uint8 _decimalUnits, 30 | string _tokenSymbol 31 | ) public { 32 | balances[msg.sender] = _initialAmount; // Give the creator all initial tokens 33 | totalSupply = _initialAmount; // Update total supply 34 | name = _tokenName; // Set the name for display purposes 35 | decimals = _decimalUnits; // Amount of decimals for display purposes 36 | symbol = _tokenSymbol; // Set the symbol for display purposes 37 | } 38 | 39 | function transfer(address _to, uint256 _value) public returns (bool success) { 40 | require(balances[msg.sender] >= _value); 41 | balances[msg.sender] -= _value; 42 | balances[_to] += _value; 43 | emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, no-unused-vars 44 | return true; 45 | } 46 | 47 | function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { 48 | uint256 allowance = allowed[_from][msg.sender]; 49 | require(balances[_from] >= _value && allowance >= _value); 50 | balances[_to] += _value; 51 | balances[_from] -= _value; 52 | if (allowance < MAX_UINT256) { 53 | allowed[_from][msg.sender] -= _value; 54 | } 55 | emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars 56 | return true; 57 | } 58 | 59 | function balanceOf(address _owner) public view returns (uint256 balance) { 60 | return balances[_owner]; 61 | } 62 | 63 | function approve(address _spender, uint256 _value) public returns (bool success) { 64 | allowed[msg.sender][_spender] = _value; 65 | emit Approval(msg.sender, _spender, _value); //solhint-disable-line indent, no-unused-vars 66 | return true; 67 | } 68 | 69 | function allowance(address _owner, address _spender) public view returns (uint256 remaining) { 70 | return allowed[_owner][_spender]; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /website/core/Footer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | const React = require('react'); 9 | 10 | class Footer extends React.Component { 11 | docUrl(doc, language) { 12 | const baseUrl = this.props.config.baseUrl; 13 | return baseUrl + 'docs/' + (language ? language + '/' : '') + doc; 14 | } 15 | 16 | pageUrl(doc, language) { 17 | const baseUrl = this.props.config.baseUrl; 18 | return baseUrl + (language ? language + '/' : '') + doc; 19 | } 20 | 21 | render() { 22 | const currentYear = new Date().getFullYear(); 23 | return ( 24 | 85 | ); 86 | } 87 | } 88 | 89 | module.exports = Footer; 90 | -------------------------------------------------------------------------------- /docs/mindmap/README.md: -------------------------------------------------------------------------------- 1 | # Thoughts on blockchain technology 2 | 3 | Ethereum will be replaced by Hedera eventually. 4 | ### Topics for bchain Notes 5 | 6 | 7 | Reading version [](https://s3.amazonaws.com/hedera-hashgraph/hh-whitepaper-v1.1-180518.pdf) 8 | 9 | 10 | ### Hedera 11 | 12 | > Since the Hedera blockchain platform uses solidity, good idea to practise solidity and keep up with changes without banking too much on Ethereum. 13 | 14 | The Hedera blockchain platform appears better than bitcoin and ethereum. 15 | 16 | > No license will be required to use the Hedera platform. No license will be 17 | required to write software that uses the services of the Hedera platform. 18 | No license will be required to build smart contracts on top of the Hedera 19 | platform. 20 | 21 | ![48e02f0a.png](:storage\0465a229-b3e8-4a99-9d99-1032d5af9897\48e02f0a.png) 22 | 23 | A blockchain is like a tree that is continuously pruned as it grows - 24 | this pruning is necessary to keep the branches from growing out of 25 | control. In hashgraph, rather than pruning new growth, it is woven 26 | back into the body 27 | 28 | In hashgraph, every container is used, and none are discarded. All the 29 | branches continue to exist forever, and eventually grow back together 30 | into a single whole. This is more efficient. 31 | 32 | Finally, because the hashgraph doesn’t require pruning and therefore 33 | is simpler, it allows more powerful mathematical guarantees, such 34 | as Byzantine agreement and fairness. Distributed databases such as 35 | Paxos are Byzantine, but not fair. Blockchain is neither Byzantine nor 36 | fair. Hashgraph is both Byzantine and fair. 37 | 38 | The hashgraph algorithm accomplishes being fair, fast, Byzantine, 39 | ACID compliant, efficient, inexpensive, timestamped, and DoS 40 | resistant. 41 | 42 | The hashgraph is ACID compliant. ACID (Atomicity, Consistency, Isolation, Durability) is a database term, 43 | and applies to the hashgraph when it is used as a distributed database. A community of nodes uses it 44 | to reach a consensus on the order in which transactions occurred. After reaching consensus, each node 45 | feeds those transactions to that node’s local copy of the database, sending in each one in the consensus 46 | order. If the local database has all the standard properties of a database (ACID), then the community as a 47 | whole can be said to have a single, distributed database with those same properties. In blockchain, there is 48 | never a moment when you know that consensus has been reached, so it would not be ACID compliant. 49 | 50 | Hedera technical and legal controls ensure the platform will not fork into a competing platform and 51 | cryptocurrency. 52 | 53 | #### Sharding 54 | 55 | Consensus can consequently proceed in 56 | parallel. Shards trust each other, so one shard will honor requests to move cryptocurrency or to put a 57 | hold on various resources made by another shard - as long as those requests can be proven to reflect the 58 | consensus of the requesting shard. This allows the multi-shard ledger as a whole to achieve asynchronous 59 | Byzantine fault tolerance, and to prevent double spends or other illegal states, because each individual 60 | shard has those properties, and because all messages between them contain proofs that they are the 61 | consensus of that shard. 62 | 63 | 64 | The Hedera ledger will use proof-of-stake. When a node joins the system, it must declare one or more 65 | accounts that it can control, and prove that it has the private keys for those accounts. From then on, 66 | the amount of cryptocurrency in those accounts will be used to weight its votes in the hashgraph virtual 67 | voting algorithm. -------------------------------------------------------------------------------- /website/siteConfig.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // See https://docusaurus.io/docs/site-config.html for all the possible 9 | // site configuration options. 10 | 11 | /* List of projects/orgs using your project for the users page */ 12 | const users = [ 13 | { 14 | caption: 'User1', 15 | // You will need to prepend the image path with your baseUrl 16 | // if it is not '/', like: '/test-site/img/docusaurus.svg'. 17 | image: '/img/docusaurus.svg', 18 | infoLink: 'https://www.facebook.com', 19 | pinned: true, 20 | }, 21 | ]; 22 | 23 | const siteConfig = { 24 | title: 'Smart Contract info' /* title for your website */, 25 | tagline: 'Documentation for my smart contracts of Interest', 26 | url: 'https://friendlyuser.github.io/' /* your website url */, 27 | baseUrl: '/solidity-smart-contracts/' /* base url for your project */, 28 | // For github.io type URLs, you would set the url and baseUrl like: 29 | // url: 'https://facebook.github.io', 30 | // baseUrl: '/test-site/', 31 | 32 | // Used for publishing and more 33 | projectName: 'solidity-smart-contracts', 34 | organizationName: 'David Li', 35 | // For top-level user or org sites, the organization is still the same. 36 | // e.g., for the https://JoelMarcey.github.io site, it would be set like... 37 | // organizationName: 'JoelMarcey' 38 | 39 | // For no header links in the top nav bar -> headerLinks: [], 40 | headerLinks: [ 41 | {doc: 'Users', label: 'Contracts'}, 42 | {doc: 'TodoList', label: 'TodoList'}, 43 | {page: "help", label: "Help" }, 44 | // Links to href destination 45 | // Links to href destination 46 | { href: "https://github.com/FriendlyUser/solidity-smart-contracts/", label: "Github" }, 47 | {blog: true, label: 'Blog'}, 48 | ], 49 | 50 | // If you have users set above, you add it here: 51 | users, 52 | 53 | /* path to images for header/footer */ 54 | headerIcon: '/img/VueDappLogo.png', 55 | footerIcon: '/img/VueDappLogo.png', 56 | favicon: '/img/favicon.png', 57 | 58 | /* colors for website */ 59 | colors: { 60 | primaryColor: '#1A237E', 61 | secondaryColor: '#9FA8DA', 62 | }, 63 | 64 | /* custom fonts for website */ 65 | /*fonts: { 66 | myFont: [ 67 | "Times New Roman", 68 | "Serif" 69 | ], 70 | myOtherFont: [ 71 | "-apple-system", 72 | "system-ui" 73 | ] 74 | },*/ 75 | 76 | // This copyright info is used in /core/Footer.js and blog rss/atom feeds. 77 | copyright: 78 | 'Copyright © ' + 79 | new Date().getFullYear() + 80 | ' David Li', 81 | 82 | highlight: { 83 | // Highlight.js theme to use for syntax highlighting in code blocks 84 | theme: 'default', 85 | }, 86 | markdownPlugins: [ 87 | (md) => { 88 | require('remarkable-plantuml')(md, {base_path: './static'}); 89 | } 90 | ], 91 | 92 | // Add custom scripts here that would be placed in