Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

79_bolun qi_hw6 #466

Open
wants to merge 72 commits into
base: 79-戚博伦
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
388575e
Merge pull request #1 from linjie-1/master
zli25 Jan 7, 2018
b90d86f
payroll homework
Jan 8, 2018
0c1e86f
Merge branch '91-Chris' of https://github.com/taojing10/guigulive-ope…
Jan 8, 2018
8512a0c
remove orginal address
Jan 8, 2018
901d828
first homework
seanxwzhang Jan 9, 2018
db44ac5
Revert "first homework"
seanxwzhang Jan 9, 2018
7952c08
第一次作业
BitEveryXW Jan 9, 2018
2874dfb
Merge pull request #2 from linjie-1/master
steven672 Jan 9, 2018
27587f6
Create 第一课作业
steven672 Jan 9, 2018
04d95b4
Delete 第一课作业
steven672 Jan 9, 2018
3040b06
Update yours.sol
steven672 Jan 9, 2018
c6032c2
Merge pull request #1 from linjie-1/master
zl777 Jan 10, 2018
602f1c1
Update yours.sol
zl777 Jan 10, 2018
9ee0a7b
第一次作业 第二次提交 @1/12/18
BitEveryXW Jan 12, 2018
61681d3
Merge pull request #145 from BitEveryXW/XW_dev
BitEveryXW Jan 12, 2018
e164779
Revert "Xw dev"
BitEveryXW Jan 12, 2018
67064fd
Merge pull request #146 from linjie-1/revert-145-XW_dev
BitEveryXW Jan 12, 2018
10b864f
根据要求加了require 函数, 并更新了源代码的基本function。 还请老师在看下~
steven672 Jan 12, 2018
60f2dcd
update
steven672 Jan 12, 2018
8a87868
update
steven672 Jan 12, 2018
9923178
Merge pull request #1 from linjie-1/master
zyzlouis Jan 13, 2018
7852900
Merge pull request #170 from zli25/master
zli25 Jan 13, 2018
d07ab7f
Update yours.sol
zl777 Jan 13, 2018
b99b727
Merge pull request #217 from linjie-1/zl777-patch-1
hezhihua81 Jan 13, 2018
55fac2b
Merge pull request #3 from linjie-1/master
steven672 Jan 13, 2018
5b96d76
revert last mis-checkin...
hezhihua81 Jan 13, 2018
31621b6
Update
steven672 Jan 13, 2018
2e095ae
update hw2
steven672 Jan 13, 2018
dbff9b0
创建第三课目录
lsdlinshunda Jan 14, 2018
78fa6e7
添加第三课说明
lsdlinshunda Jan 14, 2018
4d8f45b
添加第三课作业说明
lsdlinshunda Jan 14, 2018
a546926
Merge pull request #3 from linjie-1/master
qibolun Jan 14, 2018
798218c
submit hw3
qibolun Jan 14, 2018
1010b85
Merge branch 'master' into master
steven672 Jan 17, 2018
80e53bb
delete hw2
steven672 Jan 17, 2018
ec1f212
restore
steven672 Jan 17, 2018
e52488a
Merge pull request #2 from linjie-1/master
zyzlouis Jan 17, 2018
20e9d21
hw-2
Jan 17, 2018
68df86a
Merge pull request #304 from zl777/master
zl777 Jan 17, 2018
bf357cf
Create README.md
linjie-1 Jan 17, 2018
50c15e3
Create README.md
linjie-1 Jan 17, 2018
83e2b9b
Create payroll.sol
linjie-1 Jan 17, 2018
b38d0ff
Create README.md
linjie-1 Jan 17, 2018
953eab2
Create yours.sol
linjie-1 Jan 17, 2018
e28b1b3
Delete yours.sol
linjie-1 Jan 17, 2018
b72fc45
Create yours.sol
linjie-1 Jan 17, 2018
c66e0cc
Update yours.sol
linjie-1 Jan 17, 2018
159bd42
Revert "第3课的代码"
lsdlinshunda Jan 17, 2018
cdece6b
Merge pull request #315 from linjie-1/revert-304-master
lsdlinshunda Jan 17, 2018
656972c
Merge branch 'master' of https://github.com/linjie-1/guigulive-operation
Jan 17, 2018
d355bf4
HW-3
Jan 17, 2018
15f22fd
Merge pull request #321 from zyzlouis/master
zyzlouis Jan 18, 2018
e8a7a93
Revert "Get 第四课"
lsdlinshunda Jan 18, 2018
e8c390c
Merge pull request #327 from linjie-1/revert-321-master
lsdlinshunda Jan 18, 2018
fc220a6
Merge pull request #4 from linjie-1/master
qibolun Jan 20, 2018
902474f
a
qibolun Jan 20, 2018
386acd7
Merge pull request #316 from taojing10/master
LeapM Jan 20, 2018
cd83971
fix problem in hw3
qibolun Jan 21, 2018
3ec4c1e
Revert "91_HW-3"
lsdlinshunda Jan 22, 2018
1c6c8df
Merge pull request #396 from linjie-1/revert-316-master
lsdlinshunda Jan 22, 2018
e834fa8
添加第五课目录
lsdlinshunda Jan 22, 2018
5640fba
Merge pull request #5 from linjie-1/master
qibolun Jan 22, 2018
6aa2351
whatever
Jan 22, 2018
517920b
Merge pull request #6 from linjie-1/master
qibolun Jan 23, 2018
f96f46b
hw5
qibolun Jan 23, 2018
c5669e8
创建第六、七课目录
lsdlinshunda Jan 25, 2018
0252749
add event
qibolun Jan 25, 2018
ec1a8dd
add non-owner case
qibolun Jan 27, 2018
cec3bd9
Merge pull request #7 from linjie-1/master
qibolun Jan 27, 2018
e080ec2
hw4 update
qibolun Jan 27, 2018
d881af1
Merge branch 'master' of https://github.com/qibolun/guigulive-operati…
qibolun Jan 27, 2018
50416fd
hw6
qibolun Jan 27, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
16 changes: 16 additions & 0 deletions Lesson3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## 硅谷live以太坊智能合约频道官方地址

### 第三课《智能合约后端优化和产品化》

目录结构
<br/>|
<br/>|--orgin 课程初始代码
<br/>|
<br/>|--assignment 课程作业提交代码
<br/>
### 本节知识点
第3课:智能合约后端优化和产品化
- 如何通过数据结构优化降低合约执行成本
- 合约的继承
- 巧用modifier
- 以太坊函数库的使用和基本介绍
14 changes: 14 additions & 0 deletions Lesson3/assignment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## 硅谷live以太坊智能合约 第三课作业
这里是同学提交作业的目录

### 第三课:课后作业
- 第一题:完成今天所开发的合约产品化内容,使用Remix调用每一个函数,提交函数调用截图
- 第二题:增加 changePaymentAddress 函数,更改员工的薪水支付地址,思考一下能否使用modifier整合某个功能
- 第三题(加分题):自学C3 Linearization, 求以下 contract Z 的继承线
- contract O
- contract A is O
- contract B is O
- contract C is O
- contract K1 is A, B
- contract K2 is A, C
- contract Z is K1, K2
Binary file added Lesson3/assignment/addEmployee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lesson3/assignment/addFund.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions Lesson3/assignment/c3_sol.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- 第三题(加分题):自学C3 Linearization, 求以下 contract Z 的继承线
- contract O
- contract A is O
- contract B is O
- contract C is O
- contract K1 is A, B
- contract K2 is A, C
- contract Z is K1, K2

L(0) := [0]

L(A) := [A, 0]

L(B) := [B, 0]

L(C) := [C, 0]

L(K1) := [K1] + merge(L(B), L(A), [B, A])
= [K1] + merge([B, 0], [A, 0], [B, A])
= [K1, B] + merge([0], [A, 0], [A])
= [K1, B, A] + merge([0], [0])
= [K1, B, A, 0]

L(K2) := [K2] + merge(L(C), L(A), [C, A])
= [K2] + merge([C, 0], [A, 0], [C, A])
= [K2, C] + merge([0], [A, 0], [A])
= [K2, C, A] + merge([0], [0])
= [K2, C, A, 0]

L(Z) := [Z] + merge(L(K2), L(K1), [K2, K1])
= [Z] + merge([K2, C, A, 0], [K1, B, A, 0], [K2, K1])
= [Z, K2] + merge([C, A, 0], [K1, B, A, 0], [k1])
= [Z, K2, K1] + merge([C, A, 0], [B, A, 0])
= [Z, K2, K1, C] + merge([A, 0], [B, 0])
= [Z, K1, K2, C, A] + merge([0], [B, 0])
= [Z, K1, K2, C, A, B] + merge([0], [0])
= [Z, K1, K2, C, A, B, 0]
Binary file added Lesson3/assignment/calculateRunway.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lesson3/assignment/changePaymentAddress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lesson3/assignment/checkEmployee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lesson3/assignment/create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lesson3/assignment/getPaid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lesson3/assignment/hasEnoughFund.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lesson3/assignment/removeEmployee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lesson3/assignment/updateEmployee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions Lesson3/assignment/yours.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
pragma solidity ^0.4.14;

contract Payroll is Ownable{
struct Employee {
address id;
uint salary;
uint lastPayday;
}

uint constant payDuration = 10 seconds;

uint totalSalary;
address owner;
mapping(address=>Employee) employees;

function Payroll() public {
owner = msg.sender;
}

modifier onlyOwner {
require(msg.sender == owner);
_;
}

modifier employeeExist(address employeeId) {
var employee = employees[employeeId];
assert(employee.id != 0x0);
_;
}

modifier employeeNotExist(address employeeId) {
var employee = employees[employeeId];
assert(employee.id == 0x0);
_;
}



function _partialPaid(Employee employee) private {
uint payment = employee.salary * (now - employee.lastPayday) / payDuration;
employee.id.transfer(payment);
}

function addEmployee(address employeeId, uint salary) public onlyOwner employeeNotExist(employeeId){
employees[employeeId] = Employee(employeeId, salary * 1 ether, now);
totalSalary += salary * 1 ether;
}

function removeEmployee(address employeeId) public onlyOwner employeeExist(employeeId) {
var employee = employees[employeeId];

_partialPaid(employee);

totalSalary -= employee.salary;
delete employees[employeeId];

}

function updateEmployee(address employeeId, uint salary) public onlyOwner employeeExist(employeeId) {
var employee = employees[employeeId];
_partialPaid(employee);
totalSalary -= employees[employeeId].salary;
employees[employeeId].salary = salary * 1 ether;
totalSalary += employees[employeeId].salary;
employees[employeeId].lastPayday = now;
}

function changePaymentAddress(address newEmployeeId) public employeeExist(msg.sender) employeeNotExist(newEmployeeId){
//Only the employee can modify it's own address
var employee = employees[msg.sender];
uint oldlastPayday = employee.lastPayday;
uint oldSalary = employee.salary;
delete employees[msg.sender];

//create new employee
employees[newEmployeeId] = Employee(newEmployeeId, oldSalary, oldlastPayday);
}

function checkEmployee(address employeeId) public employeeExist(employeeId) returns (uint salary, uint lastPayday) {
var employee = employees[employeeId];
salary = employee.salary;
lastPayday =employee.lastPayday;
}

function addFund() payable public returns (uint) {
}

function calculateRunway() public returns (uint) {
return this.balance / totalSalary;
}

function hasEnoughFund() public returns (bool) {
return calculateRunway()>0;
}

function getPaid() public employeeExist(msg.sender){
var employee = employees[msg.sender];

uint nextPayday = employee.lastPayday + payDuration;
assert(nextPayday < now);
employees[msg.sender].lastPayday = nextPayday;
employee.id.transfer(employee.salary);
}
}
3 changes: 3 additions & 0 deletions Lesson3/orgin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 硅谷live以太坊智能合约 第三课

这里是每一课的初始代码,有需要的同学可以参考
Empty file added Lesson3/orgin/payroll.sol
Empty file.
Binary file added Lesson4/.DS_Store
Binary file not shown.
16 changes: 16 additions & 0 deletions Lesson4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## 硅谷live以太坊智能合约频道官方地址

### 第四课《使用Truffle架构进行前后端交互,测试,部署》

目录结构
<br/>|
<br/>|--orgin 课程初始代码
<br/>|
<br/>|--assignment 课程作业提交代码
<br/>
### 本节知识点
第4课:使用Truffle架构进行前后端交互,测试,部署
- 为什么要用Truffle,Truffle的基本概念
- Truffle 的command line 功能
- 初始化项目与Truffle项目目录结构
- 编译部署合约到testrpc
12 changes: 12 additions & 0 deletions Lesson4/assignment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## 硅谷live以太坊智能合约 第四课作业
这里是同学提交作业的目录

### 第四课:课后作业
- 将第三课完成的payroll.sol程序导入truffle工程
- 在test文件夹中,写出对如下两个函数的单元测试:
- function addEmployee(address employeeId, uint salary) onlyOwner
- function removeEmployee(address employeeId) onlyOwner employeeExist(employeeId)
- 思考一下我们如何能覆盖所有的测试路径,包括函数异常的捕捉
- (加分题,选作)
- 写出对以下函数的基于solidity或javascript的单元测试 function getPaid() employeeExist(msg.sender)
- Hint:思考如何对timestamp进行修改,是否需要对所测试的合约进行修改来达到测试的目的?
Binary file added Lesson4/assignment/box-img-lg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lesson4/assignment/box-img-sm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions Lesson4/assignment/build/contracts/Migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"contract_name": "Migrations",
"abi": [
{
"constant": false,
"inputs": [
{
"name": "new_address",
"type": "address"
}
],
"name": "upgrade",
"outputs": [],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "last_completed_migration",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "completed",
"type": "uint256"
}
],
"name": "setCompleted",
"outputs": [],
"payable": false,
"type": "function"
},
{
"inputs": [],
"payable": false,
"type": "constructor"
}
],
"unlinked_binary": "0x6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b6101e58061003c6000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630900f010811461005e578063445df0ac1461007f5780638da5cb5b146100a4578063fdacd576146100d3575b600080fd5b341561006957600080fd5b61007d600160a060020a03600435166100eb565b005b341561008a57600080fd5b610092610182565b60405190815260200160405180910390f35b34156100af57600080fd5b6100b7610188565b604051600160a060020a03909116815260200160405180910390f35b34156100de57600080fd5b61007d600435610197565b005b6000805433600160a060020a039081169116141561017c5781905080600160a060020a031663fdacd5766001546040517c010000000000000000000000000000000000000000000000000000000063ffffffff84160281526004810191909152602401600060405180830381600087803b151561016757600080fd5b6102c65a03f1151561017857600080fd5b5050505b5b5b5050565b60015481565b600054600160a060020a031681565b60005433600160a060020a03908116911614156101b45760018190555b5b5b505600a165627a7a72305820374a88e40b1a420f950c108b1f20a730496e9356f88fbe85169b500a1ae4e2f00029",
"networks": {
"1516414008735": {
"events": {},
"links": {},
"address": "0x02296ac68137b01fe647749758a6e5a78c1ce818",
"updated_at": 1516415853338
},
"1516418804860": {
"events": {},
"links": {},
"address": "0xabe8f6841727fe4403930be6e4df812334b687e2",
"updated_at": 1516420561621
}
},
"schema_version": "0.0.5",
"updated_at": 1516420561621
}
Loading