-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from linjie-1/master
lesson 2
- Loading branch information
Showing
10 changed files
with
99 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## 硅谷live以太坊智能合约频道官方地址 | ||
|
||
### 第二课《智能合约设计进阶-多员工薪酬系统》 | ||
|
||
目录结构 | ||
<br/>| | ||
<br/>|--orgin 课程初始代码 | ||
<br/>| | ||
<br/>|--assignment 课程作业提交代码 | ||
<br/> | ||
### 本节知识点 | ||
第2课:智能合约设计进阶-多员工薪酬系统 | ||
- 动态静态数组的不同 | ||
- 函数输入参数检查 revert | ||
- 循环与遍历的安全性 | ||
- 程序运行错误检查和容错:assert与require |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## 硅谷live以太坊智能合约 第二课作业 | ||
这里是同学提交作业的目录 | ||
|
||
### 第二课:课后作业 | ||
完成今天的智能合约添加100ETH到合约中 | ||
- 加入十个员工,每个员工的薪水都是1ETH | ||
每次加入一个员工后调用calculateRunway这个函数,并且记录消耗的gas是多少?Gas变化么?如果有 为什么? | ||
- 如何优化calculateRunway这个函数来减少gas的消耗? | ||
提交:智能合约代码,gas变化的记录,calculateRunway函数的优化 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/*作业请提交在这个目录下*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 硅谷live以太坊智能合约 第二课《智能合约设计进阶-多员工薪酬系统》 | ||
|
||
这里是每一课的初始代码,有需要的同学可以参考 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
pragma solidity ^0.4.14; | ||
|
||
contract Payroll { | ||
struct Employee { | ||
address id; | ||
uint salary; | ||
uint lastPayday; | ||
} | ||
|
||
uint constant payDuration = 10 seconds; | ||
|
||
address owner; | ||
Employee[] employees; | ||
|
||
function Payroll() { | ||
owner = msg.sender; | ||
} | ||
|
||
function _partialPaid(Employee employee) private { | ||
} | ||
|
||
function _findEmployee(address employeeId) private returns (Employee, uint) { | ||
} | ||
|
||
function addEmployee(address employeeId, uint salary) { | ||
} | ||
|
||
function removeEmployee(address employeeId) { | ||
} | ||
|
||
function updateEmployee(address employeeId, uint salary) { | ||
} | ||
|
||
function addFund() payable returns (uint) { | ||
} | ||
|
||
function calculateRunway() returns (uint) { | ||
uint totalSalary = 0; | ||
for (uint i = 0; i < employees.length; i++) { | ||
totalSalary += employees[i].salary; | ||
} | ||
return this.balance / totalSalary; | ||
} | ||
|
||
function hasEnoughFund() returns (bool) { | ||
} | ||
|
||
function getPaid() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
## 老董区块链干货铺 | ||
## 硅谷live以太坊智能合约频道官方地址 | ||
|
||
### 第一课《智能合约设计初阶-单员工薪酬系统》 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
## 老董区块链干货铺 第一课作业 | ||
## 硅谷live以太坊智能合约 第一课作业 | ||
这里是同学提交作业的目录 | ||
|
||
### 第一课:课后作业 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
## 老董区块链干货铺 第一课《智能合约设计初阶-单员工薪酬系统》 | ||
## 硅谷live以太坊智能合约 第一课《智能合约设计初阶-单员工薪酬系统》 | ||
|
||
这里是每一课的初始代码,有需要的同学可以参考 |