Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
Intiial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
muellerberndt committed Oct 28, 2018
0 parents commit 959a2cb
Show file tree
Hide file tree
Showing 25 changed files with 11,470 additions and 0 deletions.
1,380 changes: 1,380 additions & 0 deletions exercise1/build/contracts/Migrations.json

Large diffs are not rendered by default.

2,414 changes: 2,414 additions & 0 deletions exercise1/build/contracts/TokenSale.json

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions exercise1/contracts/Migrations.sol
@@ -0,0 +1,23 @@
pragma solidity ^0.4.23;

contract Migrations {
address public owner;
uint public last_completed_migration;

constructor() public {
owner = msg.sender;
}

modifier restricted() {
if (msg.sender == owner) _;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}

function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
27 changes: 27 additions & 0 deletions exercise1/contracts/Tokensale.sol
@@ -0,0 +1,27 @@
pragma solidity ^0.4.21;

contract TokenSale {
mapping(address => uint256) public balanceOf;
uint256 constant PRICE_PER_TOKEN = 1 ether;

function TokenSale(address _player) public payable {
require(msg.value == 1 ether);
}

function isComplete() public view returns (bool) {
return address(this).balance < 1 ether;
}

function buy(uint256 numTokens) public payable {
require(msg.value == numTokens * PRICE_PER_TOKEN);

balanceOf[msg.sender] += numTokens;
}

function sell(uint256 numTokens) public {
require(balanceOf[msg.sender] >= numTokens);

balanceOf[msg.sender] -= numTokens;
msg.sender.transfer(numTokens * PRICE_PER_TOKEN);
}
}
5 changes: 5 additions & 0 deletions exercise1/migrations/1_initial_migration.js
@@ -0,0 +1,5 @@
var Migrations = artifacts.require("./Migrations.sol");

module.exports = function(deployer) {
deployer.deploy(Migrations);
};
18 changes: 18 additions & 0 deletions exercise1/truffle-config.js
@@ -0,0 +1,18 @@
/*
* NB: since truffle-hdwallet-provider 0.0.5 you must wrap HDWallet providers in a
* function when declaring them. Failure to do so will cause commands to hang. ex:
* ```
* mainnet: {
* provider: function() {
* return new HDWalletProvider(mnemonic, 'https://mainnet.infura.io/<infura-key>')
* },
* network_id: '1',
* gas: 4500000,
* gasPrice: 10000000000,
* },
*/

module.exports = {
// See <http://truffleframework.com/docs/advanced/configuration>
// to customize your Truffle configuration!
};
18 changes: 18 additions & 0 deletions exercise1/truffle.js
@@ -0,0 +1,18 @@
/*
* NB: since truffle-hdwallet-provider 0.0.5 you must wrap HDWallet providers in a
* function when declaring them. Failure to do so will cause commands to hang. ex:
* ```
* mainnet: {
* provider: function() {
* return new HDWalletProvider(mnemonic, 'https://mainnet.infura.io/<infura-key>')
* },
* network_id: '1',
* gas: 4500000,
* gasPrice: 10000000000,
* },
*/

module.exports = {
// See <http://truffleframework.com/docs/advanced/configuration>
// to customize your Truffle configuration!
};

0 comments on commit 959a2cb

Please sign in to comment.