-
Notifications
You must be signed in to change notification settings - Fork 0
/
TruffleContractStructure.sol
57 lines (44 loc) · 1.21 KB
/
TruffleContractStructure.sol
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
pragma solidity ^0.5.1;
// contract definition
contract ContractStructure {
// state variables
int public truffleTrayCount;
string truffleTrayName;
address truffleTrayOnwer;
Truffle[] truffles;
// enum definition
enum Shape { Circle, Square, Diamond, Rectangle }
// struct definition
struct Truffle {
string name;
string description;
uint weightInGrams;
bool containsNuts;
Shape shape;
}
// function modifier
modifier ownsTruffle(){
if (msg.sender == truffleTrayOnwer) {
_;
}
}
// constructor
constructor(string memory _name) public {
truffleTrayName = _name;
}
// event declaration
event TruffleCreated(string);
// function definition
function createTruffle() ownsTruffle() payable external returns (bool) {
Truffle memory truffle = Truffle({
name: "",
description: "",
weightInGrams: 15,
containsNuts: false,
shape: Shape.Circle
});
truffles.push(truffle);
emit TruffleCreated(truffle.name);
return true;
}
}