Skip to content

Instantly share code, notes, and snippets.

@stephenlb
Last active January 31, 2018 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenlb/f5cfc43d970a0f966ee217b9adebfae4 to your computer and use it in GitHub Desktop.
Save stephenlb/f5cfc43d970a0f966ee217b9adebfae4 to your computer and use it in GitHub Desktop.
PubNub on Ethereum "Web3" Decentralized Network as a Smart Contract
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