Skip to content

Instantly share code, notes, and snippets.

@tlatkdgus1
Created October 28, 2018 20:22
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 tlatkdgus1/ec3e938b7e82485e0d41bc2d0586bfde to your computer and use it in GitHub Desktop.
Save tlatkdgus1/ec3e938b7e82485e0d41bc2d0586bfde to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.24;
contract publicNetwork{
mapping (address => uint) users;
privateNetwork public privateBlog;
function createBlog(bytes32 _nickname){
uint userId = privateBlog.createBlog(_nickname);
users[msg.sender] = userId;
}
function writeForm(bool _secret, bytes32 _subject, bytes32 _body){
uint userId = users[msg.sender];
privateBlog.writeForm(userId, _secret, _subject, _body);
}
function showForm(uint _formId) returns(bytes32, bytes32, bytes32){
uint userId = users[msg.sender];
(bool result1, bytes32 userName) = privateBlog.getFormUser(userId, _formId);
(bool result2, bytes32 subject) = privateBlog.getFormSubject(userId, _formId);
(bool result3, bytes32 body) = privateBlog.getFormBody(userId, _formId);
if(result1&&result2&&result3){
return (userName, subject, body);
}
}
}
contract privateNetwork{
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;
function createBlog(bytes32 _nickname) public returns(uint) {
uint userId = users.length;
User storage user = users[userId];
user.userId = userId;
user.nickname = _nickname;
emit CreateBlog(user.userId, user.nickname);
return (user.userId);
}
function writeForm(uint _userId, bool _secret, bytes32 _subject, bytes32 _body){
User storage user = users[_userId];
uint formId = forms.length;
Form storage form = forms[formId];
form.formId = formId;
form.userId = _userId;
form.secret = _secret;
form.subject = _subject;
form.body = _body;
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 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