Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 0 additions & 54 deletions Lesson-1/assignment/56_胡闰祺_第一次作业.sol

This file was deleted.

1 change: 1 addition & 0 deletions Lesson-1/assignment/yours.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*作业请提交在这个目录下*/
16 changes: 16 additions & 0 deletions Lesson-3/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
- 以太坊函数库的使用和基本介绍
140 changes: 140 additions & 0 deletions Lesson-3/assignment/56_胡闰祺_第三次作业.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*作业请提交在这个目录下*/

/*作业请提交在这个目录下*/

############################################## Codes for Question 1. and Question 2. #########################################

pragma solidity ^0.4.14;

contract Payroll {

struct Employee {
address EmployeeAddress;
uint salary;
uint lastPayday;
}

mapping(address => Employee) public employees;

uint constant payDuration = 30 seconds;

address OwnerAddress;

uint totalSalary = 0;

address thisAddress = this;

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

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

modifier employeeExist(address curr_EmployeeAddress) {

var curr_employee = employees[curr_EmployeeAddress];
assert(curr_employee.EmployeeAddress != 0x0);
_;

}

function addEmployee(address curr_EmployeeAddress, uint curr_salary) onlyOwner {

assert(employees[curr_EmployeeAddress].EmployeeAddress == 0x0);

uint unitSalary = curr_salary * 1 ether;
employees[curr_EmployeeAddress] = Employee(curr_EmployeeAddress, unitSalary, now);

totalSalary += unitSalary;

}

modifier partialPay(address curr_EmployeeAddress) {

_partialPay(employees[curr_EmployeeAddress]);
_;

}
function _partialPay(Employee employee) private {

uint tempSalary = employee.salary * (now - employee.lastPayday);
tempSalary = tempSalary / payDuration;

employee.EmployeeAddress.transfer(tempSalary);

}


function removeEmployee(address curr_EmployeeAddress) onlyOwner employeeExist(curr_EmployeeAddress) partialPay(curr_EmployeeAddress) {

var curr_employee = employees[curr_EmployeeAddress];
totalSalary -= curr_employee.salary;

delete employees[curr_EmployeeAddress];

}

function updateEmployee(address curr_EmployeeAddress, uint new_salary) onlyOwner employeeExist(curr_EmployeeAddress) partialPay(curr_EmployeeAddress) {

var curr_employee = employees[curr_EmployeeAddress];

uint unitSalary = new_salary * 1 ether;
totalSalary = totalSalary - curr_employee.salary + unitSalary;

curr_employee.salary = unitSalary;
curr_employee.lastPayday = now;

}

function changePaymentAddress(address curr_EmployeeAddress, address new_EmployeeAddress) onlyOwner employeeExist(curr_EmployeeAddress) partialPay(curr_EmployeeAddress) {

var curr_employee = employees[curr_EmployeeAddress];

curr_employee.EmployeeAddress = new_EmployeeAddress;

}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function changePaymentAddress(address newEmployeeId) employeeExist(msg.sender) employeeNonExist(newEmployeeId) {
require(newEmployeeId != 0x0);
var oldEmployee = employees[msg.sender];
employees[newEmployeeId] = Employee(newEmployeeId, oldEmployee.salary, oldEmployee.lastPayday);
delete employees[msg.sender];
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(1) require new addr non-zero

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(2) better for employees to change their addresses


function addFund() payable public returns (uint) {

return thisAddress.balance;

}

function calculateRunway() public view returns (uint) {

return thisAddress.balance / totalSalary;

}

function hasEnoughFund() public view returns (bool) {

return calculateRunway() > 0;

}

function getPaid() employeeExist(msg.sender){

var curr_employee = employees[msg.sender];

var newPayday = curr_employee.lastPayday + payDuration;
assert(newPayday < now);

curr_employee.lastPayday = newPayday;
curr_employee.EmployeeAddress.transfer(curr_employee.salary);

}
}

################################################### Snapshots for Question 1. ##############################################
### attached ###

######################################################### Question 3. ######################################################

|-----> B-----|
| |------> K1------|
O ---->|-----> A--|--| |-----> Z
| |---------> K2------|
|-----> C--|
Binary file not shown.
14 changes: 14 additions & 0 deletions Lesson-3/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
3 changes: 3 additions & 0 deletions Lesson-3/orgin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 硅谷live以太坊智能合约 第三课

这里是每一课的初始代码,有需要的同学可以参考
Empty file added Lesson-3/orgin/payroll.sol
Empty file.
16 changes: 16 additions & 0 deletions Lesson-4/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 Lesson-4/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进行修改,是否需要对所测试的合约进行修改来达到测试的目的?
1 change: 1 addition & 0 deletions Lesson-4/assignment/yours.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*作业请提交在这个目录下*/
3 changes: 3 additions & 0 deletions Lesson-4/orgin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 硅谷live以太坊智能合约 第四课

这里是每一课的初始代码,有需要的同学可以参考
1 change: 1 addition & 0 deletions Lesson-4/orgin/payroll.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

13 changes: 13 additions & 0 deletions Lesson-5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## 硅谷live以太坊智能合约频道官方地址

### 第五课

目录结构
<br/>|
<br/>|--orgin 课程初始代码
<br/>|
<br/>|--assignment 课程作业提交代码
<br/>

### 本节知识点

Binary file not shown.
2 changes: 2 additions & 0 deletions Lesson-5/assignment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## 硅谷live以太坊智能合约 第五课作业
这里是同学提交作业的目录
1 change: 1 addition & 0 deletions Lesson-5/assignment/yours.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*作业请提交在这个目录下*/
Loading