Created
August 22, 2018 16:58
-
-
Save eolszewski/28aa16b31d85098930391a325bd0ecf8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
pragma solidity ^0.4.19; | |
library EventStoreLib { | |
event Event( | |
uint index, | |
address sender, | |
bytes32 key, | |
bytes32 value | |
); | |
struct EventStruct { | |
uint index; | |
address sender; | |
bytes32 key; | |
bytes32 value; | |
} | |
struct Storage { | |
EventStruct[] events; | |
} | |
function write( | |
Storage storage self, | |
bytes32 key, | |
bytes32 value | |
) public returns (uint) { | |
EventStruct memory evt; | |
evt.index = self.events.length; | |
evt.sender = msg.sender; | |
evt.key = key; | |
evt.value = value; | |
emit Event(evt.index, evt.sender, evt.key, evt.value); | |
self.events.push(evt); | |
return evt.index; | |
} | |
function read(Storage storage self, uint index) public constant | |
returns (uint, address, bytes32, bytes32 ) { | |
EventStruct memory evt = self.events[index]; | |
return ( | |
evt.index, | |
evt.sender, | |
evt.key, | |
evt.value | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment