Created
November 2, 2018 06:58
-
-
Save tlatkdgus1/80a28b3663e936dbe6c09a8e41cce0d3 to your computer and use it in GitHub Desktop.
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.24; | |
contract publicNetwork{ | |
mapping (address => uint) users; | |
privateNetwork public privateBlog; | |
event _CallbackShowForm(bytes32 _userName, bytes32 subject, bytes32 body); | |
function setPrivateNet(address _address){ | |
privateBlog = privateNetwork(_address); | |
} | |
function getOwner() public view returns(address){ | |
return privateBlog.owner(); | |
} | |
function createBlog(bytes32 _nickname){ | |
privateBlog.createBlog(_nickname, msg.sender); | |
} | |
function _callbackCreateBlog(uint _userId, address _msgSender){ | |
users[_msgSender] = _userId; | |
} | |
function writeForm(bool _secret, bytes32 _subject, bytes32 _body){ | |
uint userId = users[msg.sender]; | |
privateBlog.writeForm(userId, _secret, _subject, _body); | |
} | |
function showForm(uint _formId) public{ | |
uint userId = users[msg.sender]; | |
privateBlog.getPost(userId, _formId); | |
} | |
function _callbackShowForm(bytes32 _userName, bytes32 _subject, bytes32 _body){ | |
emit _CallbackShowForm(_userName, _subject, _body); | |
} | |
} | |
contract privateNetwork{ | |
publicNetwork public publicBlog; | |
event CreateBlog(uint userId, bytes32 nickname); | |
event WriteForm(uint userId, uint formId); | |
event CanShowFormList(uint userId, uint _showUserId, uint[] canshowIds); | |
struct User{ | |
uint userId; | |
bytes32 nickname; | |
} | |
struct Form{ | |
uint formId; | |
uint userId; | |
bool secret; | |
bytes32 subject; | |
bytes32 body; | |
} | |
User[] public users; | |
Form[] public forms; | |
mapping(uint=>Form[]) userForms; | |
address public owner; | |
constructor(address _address) { | |
owner = msg.sender; | |
publicBlog = publicNetwork(_address); | |
} | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
function transferOwnership(address newOwner) onlyOwner { | |
if (newOwner != address(0)) { | |
owner = newOwner; | |
} | |
} | |
uint userId = 0; | |
uint formId = 0; | |
function createBlog(bytes32 _nickname, address _msgSender) public{ | |
User storage user; | |
user.userId = userId; | |
user.nickname = _nickname; | |
users[userId] = user; | |
emit CreateBlog(userId, _nickname); | |
userId = userId+1; | |
publicBlog._callbackCreateBlog(user.userId, _msgSender); | |
} | |
function writeForm(uint _userId, bool _secret, bytes32 _subject, bytes32 _body){ | |
Form storage form; | |
form.formId = formId; | |
form.userId = _userId; | |
form.secret = _secret; | |
form.subject = _subject; | |
form.body = _body; | |
forms[formId] = form; | |
formId = formId+1; | |
userForms[_userId].push(form); | |
emit WriteForm(_userId, form.formId); | |
} | |
function canShowFormList(uint _userId, uint _showUserId) view{ | |
bool isSame = _userId == _showUserId; | |
uint[] canShowIds; | |
uint max = userForms[_showUserId].length; | |
for(uint i=0; i<max; i++){ | |
isSame == userForms[_showUserId][i].secret; | |
canShowIds.push(userForms[_showUserId][i].formId); | |
} | |
emit CanShowFormList(_userId, _showUserId, canShowIds); | |
} | |
function getPost(uint _userId, uint _formId){ | |
(bool result1, bytes32 userName) = getFormUser(_userId, _formId); | |
(bool result2, bytes32 subject) = getFormSubject(_userId, _formId); | |
(bool result3, bytes32 body) = getFormBody(_userId, _formId); | |
if(result1&&result2&&result3){ | |
publicBlog._callbackShowForm(userName, subject, body); | |
} | |
} | |
function getFormUser(uint _userId, uint _formId) returns(bool, bytes32){ | |
Form storage form = forms[_formId]; | |
bool isSame = _userId == form.userId; | |
bytes32 nickname = users[form.userId].nickname; | |
if(form.secret){ | |
if(isSame){ | |
return(true, nickname); | |
}else{ | |
return(false, ""); | |
} | |
}else{ | |
return(true, nickname); | |
} | |
} | |
function getFormSubject(uint _userId, uint _formId) returns(bool, bytes32){ | |
Form storage form = forms[_formId]; | |
bool isSame = _userId == form.userId; | |
if(form.secret){ | |
if(isSame){ | |
return(true, form.subject); | |
}else{ | |
return(false, ""); | |
} | |
}else{ | |
return(true, form.subject); | |
} | |
} | |
function getFormBody(uint _userId, uint _formId) returns(bool, bytes32){ | |
Form storage form = forms[_formId]; | |
bool isSame = _userId == form.userId; | |
if(form.secret){ | |
if(isSame){ | |
return(true, form.body); | |
}else{ | |
return(false, ""); | |
} | |
}else{ | |
return(true, form.body); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment