Created
September 11, 2018 09:40
-
-
Save jpn0424/c3127a66705db4831c6a0cd936e81bec 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=
This file contains hidden or 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 Factory { | |
address[] newContracts; | |
function createContract (bytes32 name) public { | |
address newContract = new Contract(name); | |
newContracts.push(newContract); | |
} | |
} | |
contract Contract { | |
bytes32 public Name; | |
constructor (bytes32 name) public { | |
Name = name; | |
} | |
} |
This file contains hidden or 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 ManagePermission { | |
address private _admin; | |
address private _creater; | |
constructor() public { | |
_admin = msg.sender; | |
} | |
function isAdmin() public view returns(bool) { | |
return msg.sender == _admin; | |
} | |
modifier onlyAdmin() { | |
require(isAdmin()); | |
_; | |
} | |
function isCreater() public view returns(bool) { | |
return msg.sender == _creater; | |
} | |
modifier onlyCreater() { | |
require(isCreater()); | |
_; | |
} | |
} | |
//這裡提供合約樣板 | |
contract ContractTemplate is ManagePermission { | |
struct templateDetail { | |
string author; | |
string contractInfo; | |
address _templateAddress; | |
} | |
mapping (uint256 => templateDetail) templateInfo; //id => templateDetail 透過id找Template | |
function setTemplateAddress(address _address, uint256 _id) external onlyAdmin() { | |
templateInfo[_id]._templateAddress = _address; | |
} | |
function _createTemplate() external { | |
} | |
} | |
contract FbActManage is ManagePermission { | |
struct contractDetail { | |
uint actNonce; //事件數 | |
bytes32 transHash; //交易號 | |
bool effectiveness; //有效性 | |
} | |
struct userDetail { | |
address[] myActivity; //使用者建立 | |
address[] joinActivity; //使用者參加 | |
} | |
mapping (address => userDetail) userInfo; // store activity's contract address | |
mapping (address => contractDetail) contractInfo; // contract's detail info | |
function createNewActivity() external onlyCreater() { | |
//透過樣板發佈合約 | |
//提供樣板發佈者資訊 | |
} | |
} |
This file contains hidden or 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.18; | |
contract Fbethorder { | |
uint256 constant public FEE = 0.5 ether; | |
uint256 constant public ReFEE = 0.2 ether; | |
mapping (uint256 => address) public id2Addr; | |
mapping (address => uint256) public userId; | |
mapping (address => bool) public useratt; | |
address public FbWallet; | |
uint256 public nowtime; | |
uint256 public userAmount; | |
uint256 public maxAttendees; | |
uint256 public startTime; | |
uint256 public endTime; | |
bool public classstart; | |
function Fbethorder(address _FbWallet, uint256 _maxAttendees, uint256 _startTime) public { | |
FbWallet = _FbWallet; | |
maxAttendees = _maxAttendees; | |
userAmount = 0; | |
startTime = _startTime; | |
classstart = false; | |
} | |
function getnow() public { | |
nowtime = now; | |
} | |
function () payable external { | |
getTicket(msg.sender); | |
} | |
function getTicket (address _attendee) payable public { | |
require(now >= startTime && msg.value >= FEE && userId[_attendee] == 0); | |
userAmount ++; | |
require(userAmount <= maxAttendees); | |
userId[_attendee] = userAmount; | |
id2Addr[userAmount] = _attendee; | |
} | |
/* 發起人設定結束時間,時間使用UTC+8 */ | |
function EndTime(uint256 _endTime) public { | |
require( FbWallet == msg.sender ); | |
endTime = _endTime; | |
classstart = true; | |
} | |
function Useratt( ) public { | |
/* 確定開課,確任使用者是有報名成功的出席者123 */ | |
require(classstart == true && userId[msg.sender] != 0 && useratt[msg.sender] == false); | |
useratt[msg.sender] = true; | |
} | |
/* 課程結束,準時退回押金,延遲罰款 */ | |
function withdraw () public { | |
require(FbWallet == msg.sender); | |
for(uint i = 1; i <= userAmount; i++){ | |
if(useratt[id2Addr[i]] == false) continue; | |
/* 這邊時間要減去 UTC+8 */ | |
if(now <= endTime + 2 minutes){ | |
id2Addr[i].transfer(ReFEE); | |
}else { | |
id2Addr[i].transfer(ReFEE + 0.1 ether); | |
} | |
} | |
FbWallet.transfer(this.balance); | |
} | |
} |
This file contains hidden or 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 TemplateTest { | |
function createContract() public returns(address){ | |
address result = new Contract(); | |
return result; | |
} | |
} | |
contract Contract { | |
string public info; | |
constructor () public { | |
info = 'Write Contract in Here'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment