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

53_覃昶栋_第五次作业 #501

Open
wants to merge 40 commits into
base: 53-覃昶栋
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d60b6b0
第一次作业
0xfynnix Jan 8, 2018
503a54a
拆分函数
0xfynnix Jan 9, 2018
371670a
.
0xfynnix Jan 9, 2018
da27d33
.
0xfynnix Jan 9, 2018
ce541bd
优化
0xfynnix Jan 9, 2018
ca137ac
Merge remote-tracking branch 'upstream/master'
0xfynnix Jan 10, 2018
adbbd41
Merge remote-tracking branch 'upstream/master'
0xfynnix Jan 13, 2018
31eeb02
第二课作业
0xfynnix Jan 13, 2018
afdae0c
Merge remote-tracking branch 'upstream/master'
0xfynnix Jan 15, 2018
c85308b
第三课
0xfynnix Jan 15, 2018
bd71370
第三课
0xfynnix Jan 15, 2018
718e0e6
第三课
0xfynnix Jan 15, 2018
08dd48c
修改附加题
0xfynnix Jan 19, 2018
3f5d92f
增加代码
0xfynnix Jan 20, 2018
d4860f1
修改作业
0xfynnix Jan 20, 2018
7617e21
Merge branch 'master' of https://github.com/linjie-1/guigulive-operation
0xfynnix Jan 20, 2018
064653a
forth homework
Jan 20, 2018
e026572
修改作业
0xfynnix Jan 21, 2018
88acde5
.
0xfynnix Jan 21, 2018
b224d03
.
0xfynnix Jan 24, 2018
1cf87df
Merge branch 'master' of https://github.com/yangfan1992/guigulive-ope…
0xfynnix Jan 24, 2018
d4e113b
Merge branch 'master' of https://github.com/linjie-1/guigulive-operat…
0xfynnix Jan 24, 2018
5c8bac9
第五课作业
0xfynnix Jan 24, 2018
c5669e8
创建第六、七课目录
lsdlinshunda Jan 25, 2018
962e58f
.
0xfynnix Jan 26, 2018
a60310a
Merge branch 'master' of https://github.com/yangfan1992/guigulive-ope…
0xfynnix Jan 26, 2018
d88202a
Merge branch 'fifth_homework' of https://github.com/yangfan1992/guigu…
0xfynnix Jan 26, 2018
a841e2f
修改
0xfynnix Jan 26, 2018
9bc0cae
修改作业
0xfynnix Jan 27, 2018
f9fbe17
修改作业
0xfynnix Jan 27, 2018
223a6e8
修改
0xfynnix Jan 28, 2018
791bcb9
解决冲突
0xfynnix Jan 28, 2018
0276f7a
解决冲突
0xfynnix Jan 28, 2018
076e71b
Merge pull request #488 from yangfan1992/fifth_homework
washingweb Jan 29, 2018
c5b1eaa
merge
BillyQin Jan 29, 2018
089cd9e
merge revert
BillyQin Jan 29, 2018
35aa80c
Merge branch '53-覃昶栋' of https://github.com/linjie-1/guigulive-operation
BillyQin Jan 29, 2018
fe8b214
merge revert
BillyQin Jan 29, 2018
b88281d
add lesson5 homework
BillyQin Jan 29, 2018
62571af
目录移动
BillyQin Jan 29, 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
15 changes: 15 additions & 0 deletions Lesson2/assignment/record_gas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Gas消耗记录

|序号|Transaction Cost|Execution Cost|Second Transaction Cost|Second Execution Cost|
|---|----------------|--------------|--------------------------|------------------------|
|1 |22966 |1694 |22124 |852 |
|2 |23747 |2475 |22124 |852 |
|3 |24528 |3256 |22124 |852 |
|4 |25309 |4037 |22124 |852 |
|5 |26090 |4818 |22124 |852 |
|6 |26871 |5599 |22124 |852 |
|7 |27652 |6380 |22124 |852 |
|8 |28433 |7161 |22124 |852 |
|9 |29214 |7942 |22124 |852 |
|10 |29995 |8723 | 22124 |852 |
因为每次都要循环遍历的缘故,没加一次雇员,需要更多的gas,所以我把totalSalary的运算放在其他函数,以降低gas的消耗
86 changes: 86 additions & 0 deletions Lesson2/assignment/yours.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
<<<<<<< HEAD
pragma solidity ^0.4.14;

=======
/*作业请提交在这个目录下*/
pragma solidity ^0.4.14;
//因为每次都要循环遍历的缘故,没加一次雇员,需要更多的gas,所以我把totalSalary的运算放在其他会改动totalSalary的函数,以降低gas的消耗
>>>>>>> 076e71b01aac7c084a0c31ab12daf43d1cf839ec
contract Payroll {
struct Employee {
address id;
uint salary;
uint lastPayday;
}
<<<<<<< HEAD

uint constant payDuration = 10 seconds;

address owner;
Employee[] employees;
uint totalSalary = 0;
=======

uint constant payDuration = 10 seconds;
uint totalSalary;

address owner;
Employee[] employees;
>>>>>>> 076e71b01aac7c084a0c31ab12daf43d1cf839ec

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

function _partialPaid(Employee employee) private {
uint payment = employee.salary * (now - employee.lastPayday) / payDuration;
Expand Down Expand Up @@ -93,5 +109,75 @@ contract Payroll {

employees[index].lastPayday = nextPayday;
employees[index].id.transfer(employees[index].salary);
=======

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

function _findEmployee(address employeeId) private returns (Employee, uint) {
for(uint i = 0; i < employees.length; i++) {
if (employees[i].id == employeeId) {
return (employees[i], i);
}
}
}

function addEmployee(address employeeId, uint salary) {
require(msg.sender == owner);

var (employee, index) = _findEmployee(employeeId);
assert(employee.id == 0x0);
totalSalary = totalSalary + salary;
employees.push(Employee(employeeId, salary, now));
}

function removeEmployee(address employeeId) {
require(msg.sender == owner);

var (employee, index) = _findEmployee(employeeId);
assert(employee.id != 0x0);
_partialPaid(employees[index]);
totalSalary = totalSalary - employee.salary;
delete employees[index];
employees[index] = employees[employees.length -1];
employees.length -= 1;

}

function updateEmployee(address employeeId, uint salary) {
require(msg.sender == owner);

var (employee, index) = _findEmployee(employeeId);
assert(employee.id != 0x0);
_partialPaid(employee);
totalSalary = totalSalary + salary - employee.salary;
employee.salary = salary;
employee.lastPayday = now;
}

function addFund() payable returns (uint) {
return this.balance;
}

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

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

function getPaid() {
var (employee, index) = _findEmployee(msg.sender);
assert(employee.id != 0x0);

uint nextPayday = employee.lastPayday + payDuration;
assert(nextPayday < now);

employee.lastPayday = nextPayday;
employee.id.transfer(employee.salary);
>>>>>>> 076e71b01aac7c084a0c31ab12daf43d1cf839ec
}
}
19 changes: 19 additions & 0 deletions Lesson3/assignment/image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 截图
## 图床存在google,显示可能需要等一会儿

![](https://lh3.googleusercontent.com/-Z7wmwDmr2Yo/Wly58wMqz8I/AAAAAAAACN4/k7H-zjCS3jouLSKjn64eLfQfurpUxFBKgCHMYCw/I/15160261093451.jpg)

![](https://lh3.googleusercontent.com/-TZc_49k37sM/Wly59-DMw6I/AAAAAAAACN8/Km_W5izGcq85DsSIHZhf6xozL8JJIhJowCHMYCw/I/15160261452190.jpg)

![](https://lh3.googleusercontent.com/-uKY9K0s4beY/Wly5-sH9xOI/AAAAAAAACOA/hw4AuE-TBHoRxEEnGXu6TcPP8tpM4RCXQCHMYCw/I/15160261645468.jpg)

![](https://lh3.googleusercontent.com/-9Yckg2u56oM/Wly5_-LfakI/AAAAAAAACOE/oWWfUNd5x4MUkP2xaS_wR41urE9t5OiLwCHMYCw/I/15160261984761.jpg)

![](https://lh3.googleusercontent.com/-f4cw-uiTsnc/Wly6BSxuTjI/AAAAAAAACOI/RUCjK81MEfMce0nOj--JcCdvi_rE42XSwCHMYCw/I/15160262186508.jpg)

![](https://lh3.googleusercontent.com/-13qPZ-xrYNg/Wly6Ch4chOI/AAAAAAAACOM/JppTGYZiOQ0nE_GkJrrQrCmEslDBHIlFgCHMYCw/I/15160262349547.jpg)

![](https://lh3.googleusercontent.com/-2PtUNchpvW8/Wly6DI-hiPI/AAAAAAAACOQ/xUkK0jlu5M0nZZmaOHPEv97iwDrVpn-BwCHMYCw/I/15160262540190.jpg)

![](https://lh3.googleusercontent.com/-Jmzv3ST6x8I/Wly6D9S6zRI/AAAAAAAACOU/bC7wZuoDp6EPH_bSyZ-O_M318ah0pY9pACHMYCw/I/15160262764811.jpg)

123 changes: 123 additions & 0 deletions Lesson3/assignment/yours.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
pragma solidity ^0.4.14;

import './Owner.sol';
Expand Down Expand Up @@ -81,5 +82,127 @@ contract Payroll is Ownable {

employee.lastPayday = nextPayday;
employee.id.transfer(employee.salary);
=======
/*作业请提交在这个目录下*/
//新增更改员工薪水的支付地址的函数
function changePaymentAddress(address employeeId, address newEmployeeId) onlyOwner employeeExist(employeeId) {
var employee = employees[employeeId];

employees[employeeId].id = newEmployeeId;
}

//加分题
L[O] = 0

L[A] = A + merge[L[0],0]
= [A,0]

L[B] = B + merge[L[0],0]
= [B,0]

L[C] = C + merge[L[0],0]
= [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,0]

L[K2] = K2 + merge[L[C],L[A],C,A]
= K2 + merge[[C,0]],[A,0]],[C,A]]
= [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],[B,A,0],K1]
= [Z,K2,K1] + merge[[C,A,0],[B,A,0]]
= [Z,K2,K1,C,A,B,0]


//源码
pragma solidity ^0.4.14;

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

uint constant payDuration = 10 seconds;

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

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

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

modifier employeeExist(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) onlyOwner {
var employee = employees[employeeId];
assert(employee.id == 0x0);
totalSalary += salary * 1 ether;

employees[employeeId] = Employee(employeeId, salary * 1 ether, now);
}

function removeEmployee(address employeeId) onlyOwner employeeExist(employeeId) {

var employee = employees[employeeId];

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

}

function updateEmployee(address employeeId, uint salary) 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 addFund() payable returns (uint) {
return this.balance;
}

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

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

function getPaid() 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);
>>>>>>> 076e71b01aac7c084a0c31ab12daf43d1cf839ec
}
}
16 changes: 0 additions & 16 deletions Lesson4/README.md

This file was deleted.

Loading