Skip to content

Instantly share code, notes, and snippets.

@dima91
Created May 28, 2018 18:02
Show Gist options
  • Save dima91/fc1d127b910aea91928706ab878a5e0b to your computer and use it in GitHub Desktop.
Save dima91/fc1d127b910aea91928706ab878a5e0b to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=true&gist=
pragma solidity ^0.4.24;
contract BaseContentManagementContract {
address internal owner;
constructor () public {
owner= msg.sender;
}
}
pragma solidity ^0.4.24;
import "./sharedTypes.sol";
contract CatalogSmartContract {
// True if 'selfdestruct' function wasn't called
bool active= false;
// The contract's owner
address owner;
constructor () public {
active= true;
owner= msg.sender;
}
modifier isActive () {
require (active == true);
_;
}
/*
// Returns the number of views for each content
function getStatistics () public view returns (...) {
}
// Returns the list of contents without the number of views
function getContentList () public view returns (...) {
}
// Returns the list of x newest contents
function getNewContentList (uint n) public view returns (...) {
}
// Returns the most recent content with genre x
function getLatestByGenre (...) public view returns (...) {
}
// Returns the content with genre x, which has received the maximum number of views
function getMostPopularByGenre (...) public view returns (...) {
}
// Returns the most recent content of the author x
function getLatestByAuthor (...) public view returns (...) {
}
// Returns the content with most views of the author x
function getMostPopularByAuthor (...) public view returns (...) {
}
// Returns true if x holds a still valid premium account, false otherwise
function isPremium (...) public view returns (...) {
}
// Pays for access to content x
function getContent (...) public {
}
// Requests access to content x without paying, premium accounts only
function getContentPremium (...) public {
}
// Pays for granting access to content x to the user u
function giftContent (..., ...) {
}
// Pays for granting a Premium Account to the user u
function giftPremium (...) {
}
// Starts a new premium subscription
function buyPremium () {
}
*/
}
pragma solidity ^0.4.24;
pragma solidity ^0.4.24;
import "./baseContentManagementContract.sol";
contract SongManagementContract is BaseContentManagementContract {
}
// ********************************************* //
// ********************************************* //
// ********************************************* //
contract VideoManagementContract is BaseContentManagementContract {
}
pragma solidity ^0.4.24;
import "./mortal.sol";
contract Crowdfund {
struct Funder {
address addr;
uint amount;
}
struct Project {
bool created;
bool opened;
string name;
address owner;
mapping (uint => Funder) funders;
uint fundersSize;
uint amount;
uint fundingGoal;
}
event ProjectCreated (string _name, uint _fundingGoal);
event FundTransferred (address _backer, string _project, uint _amount, uint _remainingAmount);
event fundingGoalReached (string project);
address private owner;
mapping (string => Project) private projects;
modifier ProjectNotExists (string _name) {
require (projects[_name].created == false);
_;
}
modifier ProjectExists (string _name) {
require (projects[_name].created == true);
_;
}
constructor () public {
owner= msg.sender;
}
function createProject (string _projectName, uint _amount) public ProjectNotExists (_projectName) {
projects[_projectName]= Project (true, true, _projectName, msg.sender, 0, 0, _amount);
emit ProjectCreated (_projectName, _amount);
}
function sendMoney (string _projectName, uint _sum) public ProjectExists (_projectName) {
Project storage p= projects[_projectName];
p.funders[p.fundersSize]= Funder (msg.sender, _sum);
p.fundersSize++;
p.amount += _sum;
uint remaining= p.fundingGoal - _sum;
emit FundTransferred (msg.sender, _projectName, _sum, remaining);
checkGoalReached (_projectName);
}
function checkGoalReached (string _projectName) private returns (bool) {
Project storage p= projects[_projectName];
if (p.fundingGoal <= p.amount) {
emit fundingGoalReached (_projectName);
p.opened= false;
return true;
}
return false;
}
function getProject (string _projectName) public view returns (bool, address, uint, uint, uint, bool) {
Project storage p= projects[_projectName];
return (p.opened, p.owner, p.fundersSize, p.amount, p.fundingGoal, p.opened);
}
}
pragma solidity ^0.4.24;
contract Mortal {
address owner;
constructor () public {
owner= msg.sender;
}
function kill () public {
if (msg.sender == owner)
selfdestruct (owner);
}
}
pragma solidity ^0.4.24;
library SharedTypes {
// Kind of account
enum AccountType {standard, premium}
// Type for registered users, both authors or customers
struct User {
address _addr;
AccountType accType;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment