Repository navigation
Expand file tree
/
Copy pathtestStruct.sol
More file actions
70 lines (55 loc) · 1.75 KB
/
Copy pathtestStruct.sol
File metadata and controls
70 lines (55 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
pragma solidity ^0.8.0;
contract testStruct {
struct Person {
address account;
bool gender;
uint8 age;
}
Person public chairman;
function setChairman(address _acc, bool _g, uint8 _age) public {
// chairman = Person(_acc, _g, _age);
chairman = Person({
account: _acc,
age: _age,
gender: _g
}) ;
}
function getChairman() public view returns (address, bool, uint8 ) {
return (chairman.account, chairman.gender, chairman.age);
}
struct Student {
string name;
mapping(address=>uint) score;
int age;
}
struct Funder {
address addr;
uint amount;
}
mapping (uint => Funder) public funders;
mapping (uint => Student) public students;
function updateStudent(uint id) public {
Student storage student = students[id];
student.name = "abc";
student.age = 19;
// student = Student({ name: "abc", age : 19 });
}
function updateStudentKey(uint id, address key, uint value) public {
Student storage student = students[id];
student.score[key] = value;
}
function getStudentScore(uint id, address key) public view returns (uint) {
Student storage student = students[id];
return student.score[key];
}
function contribute(uint id) public payable {
funders[id] = Funder({addr: msg.sender, amount: msg.value});
// funders[id] = Funder(msg.sender, msg.value);
Funder storage funder = funders[id];
funder.addr = msg.sender;
funder.amount = msg.value;
}
function getFund(uint id) public view returns (address, uint ) {
return (funders[id].addr, funders[id].amount);
}
}