Skip to content

Instantly share code, notes, and snippets.

@jpn0424
Last active November 7, 2018 03:42
Show Gist options
  • Save jpn0424/296ec19bf92431a2e724b7e4f3b72633 to your computer and use it in GitHub Desktop.
Save jpn0424/296ec19bf92431a2e724b7e4f3b72633 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 ManagePermission {
address private _admin;
constructor() public {
_admin = msg.sender;
}
function isAdmin() internal view returns(bool) {
return msg.sender == _admin;
}
modifier onlyAdmin() {
require(isAdmin());
_;
}
}
/* Template */
contract Template is ManagePermission {
/* structure */
struct contractList {
uint256 index; //可以被儲存的位置,初始是0
mapping(uint256 => address) contractAddress;
}
/* storage */
mapping(address => contractList) publisher;
/* status */
bool contracEff;
/* Contract List */ /* 希望導入ERC721,利用非同質代幣儲存發佈後的合約 */
/* rule */
/* Base */
/* address list -> Here can search List of contracts created by the user */
function searchAddressList(address _publisher, uint256 _index) view internal returns(address) {
require(_index != 0);
if(publisher[_publisher].index >= _index) _index--; // search the latest
else _index = publisher[_publisher].index-1;
return publisher[_publisher].contractAddress[_index];
}
bytes4 aaa = 0x01020304;
/* return arg by decode the input string for publisher that use to create a new contract */
function decodeBytesToArgs() view internal returns(bytes){
bytes memory arg1 = new bytes(1);
arg1[0] = 0xff;
return arg1;
}
//function getArg() view external returns(uint256 a, address b, string c) {
// return decodeStringToArgs();
//}
/* Operate */
/* user */
function createContract() public {
bytes memory a;
bytes memory b;
string memory c;
/* get arg */ //怎麼做? // 試看看型態轉換 // 改傳bytes
(a) = decodeBytesToArgs(); // 沒加var不行,但var被棄用了,可能需要修改
uint256[1] memory result;
for (uint i=0; i<8 && i<a.length; ++i) {
result[i] = uint256(a[i]);
}
/* crate & store in List */
publisher[msg.sender].contractAddress[publisher[msg.sender].index] = new Contract(msg.sender, result[0]);
/* point to the next position to be store */
publisher[msg.sender].index++;
}
function searchOwnAddressList(uint256 _index) view external returns(address) {
return searchAddressList(msg.sender, _index);
}
/* admin */
function searchuserAddressList(address _publisher, uint256 _index) onlyAdmin view external returns(address) {
return searchAddressList(_publisher, _index);
}
/* Oracle */
/* service */
}
/* Main content */
contract Contract {
address public creater; //use to debug
uint256 public a; //use to debug
address public b; //use to debug
string public c; //use to debug
constructor(address _creater, uint256 _arg1) public {
creater = _creater;
a = _arg1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment