-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExternalReturnValuePatterns.sol
More file actions
60 lines (54 loc) · 1.25 KB
/
ExternalReturnValuePatterns.sol
File metadata and controls
60 lines (54 loc) · 1.25 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
pragma solidity ^0.4.6;
/// @title Return value pattern examples
/// @author Adam Lemmon - <adamjlemmon@gmail.com>
contract ReturnValues {
/**
* Storage
*/
enum State { inactive, active }
struct MyStruct {
bytes32 id;
bytes32 structType;
State state;
}
mapping(bytes32=>MyStruct) structIdToStructDetail;
/**
* Events
*/
event LogStructGet(
bytes32 id,
bytes32 structType,
uint8 state,
address sender
);
/**
* External
*/
/// @dev Get the values of a struct via TX
/// @param id The id of the struct
/// @return bytes32 id, bytes32 structType, uint8 state
function structGet(bytes32 id)
external
returns(bytes32, bytes32, uint8)
{
MyStruct myStruct = structIdToStructDetail[id];
LogStructGet(
id,
myStruct.structType,
uint8(myStruct.state),
msg.sender
);
}
/// @dev Get the values of a struct via constant
/// @param id The id of the struct
/// @return bytes32 id, bytes32 structType, uint8 state
function structGetCONSTANT(bytes32 id)
external
constant
returns(bytes32 structId, bytes32 structType, uint8 state)
{
structId = id;
structType = structIdToStructDetail[id].structType;
state = uint8(structIdToStructDetail[id].state);
}
}