Last active
January 31, 2018 22:13
-
-
Save stephenlb/f5cfc43d970a0f966ee217b9adebfae4 to your computer and use it in GitHub Desktop.
PubNub on Ethereum "Web3" Decentralized Network as a Smart Contract
This file contains 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; | |
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | |
// PubNub on Ethereum "Web3" Decentralized Network as a Smart Contract | |
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | |
contract PubNubV1 { | |
mapping(bytes32 => mapping(bytes32 => bytes32)) private channel_groups; | |
mapping(bytes32 => mapping(bytes32 => bytes32)) private channel_presence; | |
event Message( | |
address indexed from | |
, bytes32 indexed channel | |
, string message | |
); | |
// TODO Byte Array for Message (allows sym-encryption) | |
function publish( bytes32 channel, string message ) public { | |
Message( msg.sender, channel, message ); | |
} | |
// helper function to get as bytestring | |
function channelHash(string channel) internal pure returns (bytes32) { | |
return stringToBytes32(channel); | |
} | |
function stringToBytes32(string memory source) internal pure returns (bytes32 result) { | |
bytes memory tempEmptyStringTest = bytes(source); | |
if (tempEmptyStringTest.length == 0) { | |
return 0x0; | |
} | |
assembly { | |
result := mload(add(source, 32)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment