├── Archive ├── initial_terra0_prototype │ ├── contracts │ │ ├── .placeholder │ │ ├── Migrations.sol │ │ ├── Tree_sell.sol │ │ ├── owned.sol │ │ ├── sapling.sol │ │ ├── terra.sol │ │ └── token.sol │ ├── migrations │ │ └── 1_initial_migration.js │ ├── test │ │ └── .placeholder │ └── truffle.js └── terra0 │ ├── contracts │ ├── acl.sol │ └── treeregister.sol │ ├── migrations │ ├── 1_initial_migration.js │ └── 2_deploy_contracts.js │ ├── test │ ├── TestMetacoin.sol │ └── metacoin.js │ └── truffle.js ├── Flowertokens ├── contracts │ ├── .soliumignore │ ├── .soliumrc.json │ ├── AddressUtils.sol │ ├── ERC721Basic.sol │ ├── ERC721BasicToken.sol │ ├── Migrations.sol │ ├── Ownable.sol │ ├── SafeMath.sol │ ├── acl.sol │ ├── bloomingPool.sol │ ├── buyable.sol │ ├── infrastructurePool.sol │ ├── strings.sol │ ├── testreg.sol │ └── update.sol ├── migrations │ ├── 1_initial_migration.js │ └── 2_deploy_contracts.js ├── package-lock.json ├── test │ └── initalisation.js ├── truffle-config.js └── truffle.js ├── Premna Daemon ├── .soliumignore ├── .soliumrc.json └── contracts │ ├── Migrations.sol │ └── bonsai.sol ├── README.md ├── README.md.orig └── package-lock.json /Archive/initial_terra0_prototype/contracts/.placeholder: -------------------------------------------------------------------------------- 1 | This is a placeholder file to ensure the parent directory in the git repository. Feel free to remove. 2 | -------------------------------------------------------------------------------- /Archive/initial_terra0_prototype/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.2; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) _; 9 | } 10 | 11 | function Migrations() { 12 | owner = msg.sender; 13 | } 14 | 15 | function setCompleted(uint completed) restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Archive/initial_terra0_prototype/contracts/Tree_sell.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.2; 2 | 3 | import "./owned.sol"; 4 | 5 | contract Tree_sell is owned { 6 | string Location; 7 | 8 | 9 | function Tree_sell (string location) { 10 | Location = location; 11 | 12 | } 13 | /*function ownership_transfer() { 14 | transferOwnership_Tree(); 15 | 16 | }*/ 17 | function returndata()public constant returns (string){ 18 | return Location; 19 | } 20 | /*function buy_tree()payable public returns (string){ 21 | token c = new token(); 22 | c.buy(); 23 | return Location; 24 | }*/ 25 | } 26 | -------------------------------------------------------------------------------- /Archive/initial_terra0_prototype/contracts/owned.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.2; 2 | 3 | contract owned { 4 | function owned() 5 | { owner = msg.sender; 6 | oracle = msg.sender; 7 | } 8 | address public owner; 9 | address public oracle; 10 | 11 | modifier onlyOwner { 12 | if (msg.sender != owner) 13 | throw; 14 | _; 15 | } 16 | modifier onlyOracle { 17 | if (msg.sender != oracle) 18 | throw; 19 | _; 20 | } 21 | function transferOwnership_final() onlyOracle { 22 | owner = this; 23 | } 24 | function transferOwnership_Tree(){ 25 | owner = msg.sender; 26 | } 27 | function kill_switch() { 28 | if (msg.sender == owner) selfdestruct(owner); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Archive/initial_terra0_prototype/contracts/sapling.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.7; 2 | 3 | contract sapling { 4 | ///this contract is written for terra0 saplings in the NEW WORLD ORDER exhibition @ furtherfield 5 | ///This is part of terra0 6 | ///http://www.furtherfield.org/programmes/exhibition/new-world-order 7 | ///not finished yet 8 | 9 | address public owner = msg.sender; 10 | address public terra0adress = msg.sender; 11 | bool onetime = true; 12 | uint256 public contractinit_time = now; 13 | uint256 public age_of_the_tree; 14 | uint256 public value = 0; 15 | uint256 public startprice = 853608000000000000; 16 | uint256 factor2 = 110079510; 17 | 18 | 19 | modifier onlyterra0 { 20 | if (msg.sender != terra0adress) 21 | throw; 22 | _; 23 | } 24 | 25 | function changestartvalues(uint256 startpricenew, uint256 factor2new ) onlyterra0{ 26 | startprice = startpricenew; 27 | factor2 = factor2new; 28 | } 29 | 30 | 31 | function transferOwnership(address newowner)internal{ 32 | owner = newowner; 33 | if (onetime == true){ 34 | if (!terra0adress.send(this.balance)) 35 | throw; 36 | } 37 | onetime = false; 38 | } 39 | 40 | function get_Ownership()constant returns(address){ 41 | return owner; 42 | } 43 | function thebalance()constant returns(uint256){ 44 | return this.balance; 45 | } 46 | function get_age()constant returns(uint){ 47 | return age_of_the_tree; 48 | } 49 | function get_value()constant returns(uint){ 50 | return value; 51 | } 52 | 53 | function Purchase() payable { 54 | uint amount = msg.value; 55 | if (value > amount) throw; 56 | uint rest = amount - value; 57 | if (!msg.sender.send(rest)) 58 | throw; 59 | transferOwnership(msg.sender); 60 | } 61 | 62 | function calculatevalue(){ 63 | age_of_the_tree = now - contractinit_time; 64 | uint256 calval = age_of_the_tree * factor2; 65 | value = startprice + calval; 66 | } 67 | 68 | //web3.eth 69 | //web3.eth.sendTransaction({from:web3.eth.coinbase, to:'0xdfCE4d0Ce94E3644c510EA027f2DBA838811BA1F', value: 50}) 70 | 71 | } 72 | -------------------------------------------------------------------------------- /Archive/initial_terra0_prototype/contracts/terra.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.2; 2 | 3 | import "./owned.sol"; 4 | import "./token.sol"; 5 | import "./Tree_sell.sol"; 6 | 7 | contract terra0 is owned, token { 8 | int indexcount = 0; 9 | address[] public newContracts; 10 | //int numboftokens = 0; 11 | 12 | struct Dataset { 13 | int max_age; 14 | uint256 price; 15 | } 16 | 17 | mapping(string => Dataset) DataTreespecs; 18 | 19 | struct Tree { 20 | int age; 21 | string kind; 22 | int mass; 23 | string location; /// float 24 | string health; 25 | bool dead; 26 | int indexvalue; 27 | uint256 price; 28 | } 29 | 30 | mapping(int => Tree) public dataItems; 31 | 32 | function balance_check_WT_Tree(uint i)constant returns (uint256){ 33 | return coinBalanceOf[1][newContracts[i]]; 34 | } 35 | 36 | 37 | function addTreeitem(int index,int age,string kind,int mass,string location,string health,bool dead)onlyOracle() external { 38 | uint256 pricefortree = 0; 39 | if (index == dataItems[index].indexvalue){ 40 | indexcount = indexcount -1; 41 | } 42 | dataItems[index].indexvalue = index; 43 | dataItems[index].age = age; 44 | dataItems[index].kind = kind; 45 | dataItems[index].mass = mass; 46 | dataItems[index].location = location; 47 | dataItems[index].health = health; 48 | dataItems[index].dead = dead; 49 | pricefortree = uint256(DataTreespecs[kind].price) * uint256(mass); 50 | dataItems[index].price = pricefortree; 51 | indexcount = indexcount + 1; 52 | mintToken(pricefortree); 53 | 54 | } 55 | ///terra0.addTreeitem(1,200,'Eiche',42,'whateva','good','false',{gas:1000000}) 56 | 57 | function addDataItem(string treetype,int alter,uint256 price)onlyOracle() { 58 | DataTreespecs[treetype].max_age = alter; 59 | DataTreespecs[treetype].price = price; 60 | } 61 | ///terra0.addDataItem('Eiche',99,30) 62 | 63 | function getmaxage(string treetype) constant returns (int) { 64 | return DataTreespecs[treetype].max_age; 65 | } 66 | 67 | function getvalue1(int _number) constant returns (int) { 68 | return dataItems[_number].age; 69 | } 70 | 71 | /*function numberdic() constant returns (int) { 72 | return indexcount; 73 | }*/ 74 | function buy_tree(uint indexnumber) payable returns (uint amount4){ 75 | uint amount3 = msg.value / buyPrice_Wood_Token; // calculates the amount 76 | if (coinBalanceOf[1][newContracts[indexnumber]] < amount3) throw; // checks if it has enough to sell 77 | coinBalanceOf[1][msg.sender] += amount3; // adds the amount to buyer's balance 78 | coinBalanceOf[1][newContracts[indexnumber]] -= amount3; // subtracts amount from seller's balance 79 | CoinTransfer(1,newContracts[indexnumber], msg.sender, amount3); 80 | return amount3; // execute an event reflecting the change 81 | 82 | } 83 | 84 | function algo()onlyOracle() { 85 | uint256 sum = 0; 86 | for(int i=0;i<=indexcount;i++){ 87 | if(dataItems[i].age > DataTreespecs[dataItems[i].kind].max_age){ 88 | dataItems[i].dead = true; 89 | address newContract = new Tree_sell(string(dataItems[i].location)); 90 | newContracts.push(newContract); 91 | distributeCoin(1,newContract,dataItems[i].price); 92 | //&& dataItems[i].dead == false 93 | } 94 | 95 | } 96 | } 97 | /*function filltree()onlyOracle(){ 98 | distributeCoin(1,newContracts[0],90); 99 | }*/ 100 | } 101 | ///terra0.addDataItem('Eiche',99,30) 102 | ///terra0.addTreeitem(1,200,'Eiche',42,'whateva','good','false',{gas:1000000}) 103 | //terra0.algo({gas:4000000}) 104 | //terra0.newContracts() 105 | //terra0.balance_check_WT_Tree(0) 106 | //Tree_sell.buy_tree({value : 3000000}) 107 | //terra0.buy_tree(0,{value:20000000000000000,gas:4000000}) 108 | 109 | //terra0.filltree({gas:4000000}) 110 | //terra0.filltree({gas:4000000}) 111 | //'0xc7649a4c9d5f88b96f910ee0f84094bd664e83d9' 112 | 113 | 114 | /*function createContract (int location) { 115 | }*/ 116 | 117 | /*function addcoins(uint256 a)onlyOracle(){ 118 | mintToken(a); 119 | }*/ 120 | -------------------------------------------------------------------------------- /Archive/initial_terra0_prototype/contracts/token.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.2; 2 | 3 | import "./owned.sol"; 4 | 5 | contract token is owned { 6 | uint256 public numCoinTypes; 7 | uint256 public supply_Wood_Token; 8 | uint256 public supply_Terra0_Token; 9 | uint256 public buyPrice_Wood_Token; 10 | uint256 public sellPrice_Terra0_Token; 11 | //address public owner; 12 | uint256 public totalSupply_Wood_Token; 13 | uint256 public totalSupply_Terra0_Token; 14 | 15 | mapping (uint => mapping (address => uint)) public coinBalanceOf; 16 | 17 | event CoinTransfer(uint coinType, address sender, address receiver, uint amount); 18 | 19 | /* Initializes contract with initial supply tokens to the creator of the contract */ 20 | function token() { 21 | buyPrice_Wood_Token = 20000000000000000; 22 | sellPrice_Terra0_Token = 20000000000000000; 23 | supply_Wood_Token = 0; 24 | supply_Terra0_Token = 20000000; 25 | owner = msg.sender; 26 | numCoinTypes = 2; 27 | totalSupply_Wood_Token = supply_Wood_Token; 28 | totalSupply_Terra0_Token = supply_Terra0_Token; 29 | coinBalanceOf[0][msg.sender] = supply_Terra0_Token; 30 | coinBalanceOf[1][this] = supply_Wood_Token; 31 | } 32 | 33 | function sendCoin(uint coinType, address receiver, uint amount) returns(bool sufficient) { 34 | if (coinBalanceOf[coinType][msg.sender] < amount) return false; 35 | /* if (coinBalanceOf[coinType][receiver] + amount < coinBalanceOf[coinType][receiver]) throw;*/ 36 | coinBalanceOf[coinType][msg.sender] -= amount; 37 | coinBalanceOf[coinType][receiver] += amount; 38 | CoinTransfer(coinType, msg.sender, receiver, amount); 39 | return true; 40 | } 41 | 42 | function distributeCoin(uint coinType, address receiver, uint amount) returns(bool sufficient) { 43 | if (coinBalanceOf[coinType][this] < amount) return false; 44 | /* if (coinBalanceOf[coinType][receiver] + amount < coinBalanceOf[coinType][receiver]) throw;*/ 45 | coinBalanceOf[coinType][this] -= amount; 46 | coinBalanceOf[coinType][receiver] += amount; 47 | CoinTransfer(coinType, this, receiver, amount); 48 | return true; 49 | } 50 | 51 | 52 | function sell(uint amount)public returns (uint revenue){ 53 | if (coinBalanceOf[0][msg.sender] < amount ) throw; // checks if the sender has enough to sell 54 | coinBalanceOf[0][this] += amount; // adds the amount to owner's balance 55 | coinBalanceOf[0][msg.sender] -= amount; // subtracts the amount from seller's balance 56 | revenue = amount * sellPrice_Terra0_Token; 57 | if (!msg.sender.send(revenue)) { // sends ether to the seller: it's important 58 | throw; // to do this last to prevent recursion attacks 59 | } else { 60 | CoinTransfer(0,this, msg.sender, amount); // executes an event reflecting on the change 61 | return revenue; // ends function and returns 62 | } 63 | } 64 | 65 | 66 | 67 | function mintToken(uint256 mintedAmount) onlyOracle { 68 | totalSupply_Wood_Token += mintedAmount; 69 | coinBalanceOf[1][this] += mintedAmount; 70 | CoinTransfer(1,0, this, mintedAmount); 71 | } 72 | 73 | function balance_check_self_WT()constant returns (uint256){ 74 | return coinBalanceOf[1][this]; 75 | } 76 | function balance_check_WT()constant returns (uint256){ 77 | return coinBalanceOf[1][msg.sender]; 78 | } 79 | function balance_check_self_TT()constant returns (uint256){ 80 | return coinBalanceOf[0][this]; 81 | } 82 | function balance_check_TT()constant returns (uint256){ 83 | return coinBalanceOf[0][msg.sender]; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Archive/initial_terra0_prototype/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require("./Migrations.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /Archive/initial_terra0_prototype/test/.placeholder: -------------------------------------------------------------------------------- 1 | This is a placeholder file to ensure the parent directory in the git repository. Feel free to remove. 2 | -------------------------------------------------------------------------------- /Archive/initial_terra0_prototype/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | host: "localhost", 5 | port: 8545, 6 | network_id: "*" // Match any network id 7 | } 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /Archive/terra0/contracts/acl.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | //This is the first version of a simple ACL / Permission Management System 4 | //It might differentiate from other Permission Management Systems and therefore be more restrictive in the following points: 5 | // Every User can just have one Role (similar to a state machine) 6 | // No new Roles "Positions" can be generated 7 | // Therefore all possible Roles must be defined at the beginning 8 | 9 | 10 | contract acl{ 11 | 12 | enum Role { 13 | USER, 14 | ORACLE, 15 | ADMIN 16 | } 17 | 18 | mapping (address=> Role) permissions; 19 | 20 | constructor(){ 21 | permissions[msg.sender] = Role(2); 22 | } 23 | 24 | function setRole(uint8 rolevalue,address entity)external check(2){ 25 | permissions[entity] = Role(rolevalue); 26 | } 27 | 28 | function getRole(address entity)public view returns(Role){ 29 | return permissions[entity]; 30 | } 31 | 32 | modifier check(uint8 role) { 33 | require(uint8(getRole(msg.sender)) == role); 34 | _; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Archive/terra0/contracts/treeregister.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | 4 | contract treeregister { 5 | 6 | struct EntityStruct { 7 | bytes BCHTransactionid; 8 | bool isEntity; 9 | } 10 | 11 | 12 | mapping(address => mapping(bytes32 => EntityStruct)) internal entityStructs; 13 | mapping(address => uint)internal NumberofAssets; 14 | mapping(address => bool) internal KnownAdresses; 15 | address[] internal OwnerList; 16 | bytes32[] internal IDList; 17 | 18 | 19 | function isEntity(address entityAddress,bytes32 uniqueID) public constant returns(bool isIndeed) { 20 | return entityStructs[entityAddress][uniqueID].isEntity; 21 | } 22 | 23 | function isAdressknown(address entityAddress) public constant returns(bool isIndeed) { 24 | return KnownAdresses[entityAddress]; 25 | } 26 | 27 | function getAllOwner() public constant returns(uint entityCount) { 28 | return OwnerList.length; 29 | } 30 | 31 | function getAllTrees() public constant returns(uint entityCount) { 32 | return IDList.length; 33 | } 34 | 35 | function getTreesof(address entityAddress) public constant returns(uint entityCount) { 36 | return NumberofAssets[entityAddress] ; 37 | } 38 | 39 | function newEntity(address entityAddress, bytes entityData) public returns(uint rowNumber, bytes32 _UniqueID) { 40 | bytes32 UniqueID = keccak256(entityData); 41 | if(isEntity(entityAddress,UniqueID)) revert(); 42 | entityStructs[entityAddress][UniqueID].BCHTransactionid = entityData; 43 | entityStructs[entityAddress][UniqueID].isEntity = true; 44 | NumberofAssets[entityAddress]= NumberofAssets[entityAddress] +1; 45 | IDList.push(UniqueID); 46 | if (isAdressknown(entityAddress)){ 47 | return (0,UniqueID); 48 | }else{ 49 | KnownAdresses[entityAddress] = true; 50 | return (OwnerList.push(entityAddress) - 1,UniqueID); //somethingdontwork here 51 | } 52 | } 53 | 54 | function updateData(address entityAddress,bytes32 uniqueID,bytes entityData) public returns(bool success) { 55 | if(!isEntity(entityAddress,uniqueID)) revert(); 56 | entityStructs[entityAddress][uniqueID].BCHTransactionid = entityData; 57 | return true; 58 | } 59 | 60 | function transferownership(address Owner, address NewOwner,bytes32 uniqueID)public returns(bool success){ 61 | if(isEntity(Owner,uniqueID)){ 62 | entityStructs[NewOwner][uniqueID].BCHTransactionid = entityStructs[Owner][uniqueID].BCHTransactionid; 63 | entityStructs[NewOwner][uniqueID].isEntity = true; 64 | entityStructs[Owner][uniqueID].isEntity = false; 65 | NumberofAssets[Owner]= NumberofAssets[Owner] -1; 66 | NumberofAssets[NewOwner]= NumberofAssets[NewOwner] +1; ///needs to add new ownwers 67 | return true; 68 | } 69 | else{ 70 | return false; 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /Archive/terra0/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require("./Migrations.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /Archive/terra0/migrations/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | var ConvertLib = artifacts.require("./ConvertLib.sol"); 2 | var MetaCoin = artifacts.require("./MetaCoin.sol"); 3 | 4 | module.exports = function(deployer) { 5 | deployer.deploy(ConvertLib); 6 | deployer.link(ConvertLib, MetaCoin); 7 | deployer.deploy(MetaCoin); 8 | }; 9 | -------------------------------------------------------------------------------- /Archive/terra0/test/TestMetacoin.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.2; 2 | 3 | import "truffle/Assert.sol"; 4 | import "truffle/DeployedAddresses.sol"; 5 | import "../contracts/MetaCoin.sol"; 6 | 7 | contract TestMetacoin { 8 | 9 | function testInitialBalanceUsingDeployedContract() { 10 | MetaCoin meta = MetaCoin(DeployedAddresses.MetaCoin()); 11 | 12 | uint expected = 10000; 13 | 14 | Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially"); 15 | } 16 | 17 | function testInitialBalanceWithNewMetaCoin() { 18 | MetaCoin meta = new MetaCoin(); 19 | 20 | uint expected = 10000; 21 | 22 | Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Archive/terra0/test/metacoin.js: -------------------------------------------------------------------------------- 1 | var MetaCoin = artifacts.require("./MetaCoin.sol"); 2 | 3 | contract('MetaCoin', function(accounts) { 4 | it("should put 10000 MetaCoin in the first account", function() { 5 | return MetaCoin.deployed().then(function(instance) { 6 | return instance.getBalance.call(accounts[0]); 7 | }).then(function(balance) { 8 | assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account"); 9 | }); 10 | }); 11 | it("should call a function that depends on a linked library", function() { 12 | var meta; 13 | var metaCoinBalance; 14 | var metaCoinEthBalance; 15 | 16 | return MetaCoin.deployed().then(function(instance) { 17 | meta = instance; 18 | return meta.getBalance.call(accounts[0]); 19 | }).then(function(outCoinBalance) { 20 | metaCoinBalance = outCoinBalance.toNumber(); 21 | return meta.getBalanceInEth.call(accounts[0]); 22 | }).then(function(outCoinBalanceEth) { 23 | metaCoinEthBalance = outCoinBalanceEth.toNumber(); 24 | }).then(function() { 25 | assert.equal(metaCoinEthBalance, 2 * metaCoinBalance, "Library function returned unexpected function, linkage may be broken"); 26 | }); 27 | }); 28 | it("should send coin correctly", function() { 29 | var meta; 30 | 31 | // Get initial balances of first and second account. 32 | var account_one = accounts[0]; 33 | var account_two = accounts[1]; 34 | 35 | var account_one_starting_balance; 36 | var account_two_starting_balance; 37 | var account_one_ending_balance; 38 | var account_two_ending_balance; 39 | 40 | var amount = 10; 41 | 42 | return MetaCoin.deployed().then(function(instance) { 43 | meta = instance; 44 | return meta.getBalance.call(account_one); 45 | }).then(function(balance) { 46 | account_one_starting_balance = balance.toNumber(); 47 | return meta.getBalance.call(account_two); 48 | }).then(function(balance) { 49 | account_two_starting_balance = balance.toNumber(); 50 | return meta.sendCoin(account_two, amount, {from: account_one}); 51 | }).then(function() { 52 | return meta.getBalance.call(account_one); 53 | }).then(function(balance) { 54 | account_one_ending_balance = balance.toNumber(); 55 | return meta.getBalance.call(account_two); 56 | }).then(function(balance) { 57 | account_two_ending_balance = balance.toNumber(); 58 | 59 | assert.equal(account_one_ending_balance, account_one_starting_balance - amount, "Amount wasn't correctly taken from the sender"); 60 | assert.equal(account_two_ending_balance, account_two_starting_balance + amount, "Amount wasn't correctly sent to the receiver"); 61 | }); 62 | }); 63 | }); 64 | -------------------------------------------------------------------------------- /Archive/terra0/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | host: "localhost", 5 | port: 8545, 6 | network_id: "*" // Match any network id 7 | } 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /Flowertokens/contracts/.soliumignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /Flowertokens/contracts/.soliumrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solium:recommended", 3 | "plugins": [ 4 | "security" 5 | ], 6 | "rules": { 7 | "quotes": [ 8 | "error", 9 | "double" 10 | ], 11 | "indentation": [ 12 | "error", 13 | 4 14 | ] 15 | } 16 | } -------------------------------------------------------------------------------- /Flowertokens/contracts/AddressUtils.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | /** 4 | * Utility library of inline functions on addresses 5 | */ 6 | library AddressUtils { 7 | 8 | /** 9 | * Returns whether the target address is a contract 10 | * @dev This function will return false if invoked during the constructor of a contract, 11 | * as the code is not actually created until after the constructor finishes. 12 | * @param addr address to check 13 | * @return whether the target address is a contract 14 | */ 15 | function isContract(address addr) internal view returns (bool) { 16 | uint256 size; 17 | // XXX Currently there is no better way to check if there is a contract in an address 18 | // than to check the size of the code at that address. 19 | // See https://ethereum.stackexchange.com/a/14016/36603 20 | // for more details about how this works. 21 | // TODO Check this again before the Serenity release, because all addresses will be 22 | // contracts then. 23 | assembly { size := extcodesize(addr) } // solium-disable-line security/no-inline-assembly 24 | return size > 0; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Flowertokens/contracts/ERC721Basic.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | /** 4 | * @title ERC721 Non-Fungible Token Standard basic interface 5 | * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md 6 | */ 7 | contract ERC721Basic { 8 | event Transfer(address indexed _from, address indexed _to, uint256 _tokenId); 9 | event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId); 10 | event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved); 11 | 12 | function balanceOf(address _owner) public view returns (uint256 _balance); 13 | function ownerOf(uint256 _tokenId) public view returns (address _owner); 14 | function exists(uint256 _tokenId) public view returns (bool _exists); 15 | 16 | function approve(address _to, uint256 _tokenId) public; 17 | function getApproved(uint256 _tokenId) public view returns (address _operator); 18 | 19 | function setApprovalForAll(address _operator, bool _approved) public; 20 | function isApprovedForAll(address _owner, address _operator) public view returns (bool); 21 | 22 | function transferFrom(address _from, address _to, uint256 _tokenId) public; 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Flowertokens/contracts/ERC721BasicToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | import "./ERC721Basic.sol"; 4 | import "./SafeMath.sol"; 5 | import "./AddressUtils.sol"; 6 | import "./acl.sol"; 7 | 8 | 9 | /** 10 | * @title ERC721 Non-Fungible Token Standard basic implementation 11 | * @dev edited verison of Open Zepplin implementation 12 | * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md 13 | * @dev edited _mint & isApprovedOrOwner modifiers 14 | */ 15 | contract ERC721BasicToken is ERC721Basic, acl { 16 | using SafeMath for uint256; 17 | using AddressUtils for address; 18 | 19 | uint public numTokensTotal; 20 | 21 | // Mapping from token ID to owner 22 | mapping (uint256 => address) internal tokenOwner; 23 | 24 | // Mapping from token ID to approved address 25 | mapping (uint256 => address) internal tokenApprovals; 26 | 27 | // Mapping from owner to number of owned token 28 | mapping (address => uint256) internal ownedTokensCount; 29 | 30 | // Mapping from owner to operator approvals 31 | mapping (address => mapping (address => bool)) internal operatorApprovals; 32 | 33 | /** 34 | * @dev Guarantees msg.sender is owner of the given token 35 | * @param _tokenId uint256 ID of the token to validate its ownership belongs to msg.sender 36 | */ 37 | modifier onlyOwnerOf(uint256 _tokenId) { 38 | require(ownerOf(_tokenId) == msg.sender); 39 | _; 40 | } 41 | 42 | /** 43 | * @dev Checks msg.sender can transfer a token, by being owner, approved, or operator 44 | * @param _tokenId uint256 ID of the token to validate 45 | */ 46 | modifier canTransfer(uint256 _tokenId) { 47 | require(isApprovedOrOwner(msg.sender, _tokenId)); 48 | _; 49 | } 50 | 51 | /** 52 | * @dev Gets the balance of the specified address 53 | * @param _owner address to query the balance of 54 | * @return uint256 representing the amount owned by the passed address 55 | */ 56 | function balanceOf(address _owner) public view returns (uint256) { 57 | require(_owner != address(0)); 58 | return ownedTokensCount[_owner]; 59 | } 60 | 61 | /** 62 | * @dev Gets the owner of the specified token ID 63 | * @param _tokenId uint256 ID of the token to query the owner of 64 | * @return owner address currently marked as the owner of the given token ID 65 | */ 66 | function ownerOf(uint256 _tokenId) public view returns (address) { 67 | address owner = tokenOwner[_tokenId]; 68 | /* require(owner != address(0)); */ 69 | return owner; 70 | } 71 | 72 | /** 73 | * @dev Returns whether the specified token exists 74 | * @param _tokenId uint256 ID of the token to query the existence of 75 | * @return whether the token exists 76 | */ 77 | function exists(uint256 _tokenId) public view returns (bool) { 78 | address owner = tokenOwner[_tokenId]; 79 | return owner != address(0); 80 | } 81 | 82 | /** 83 | * @dev Approves another address to transfer the given token ID 84 | * @dev The zero address indicates there is no approved address. 85 | * @dev There can only be one approved address per token at a given time. 86 | * @dev Can only be called by the token owner or an approved operator. 87 | * @param _to address to be approved for the given token ID 88 | * @param _tokenId uint256 ID of the token to be approved 89 | */ 90 | function approve(address _to, uint256 _tokenId) public { 91 | address owner = tokenOwner[_tokenId]; 92 | 93 | tokenApprovals[_tokenId] = _to; 94 | 95 | require(_to != ownerOf(_tokenId)); 96 | require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); 97 | 98 | tokenApprovals[_tokenId] = _to; 99 | emit Approval(owner, _to, _tokenId); 100 | } 101 | 102 | /** 103 | * @dev Gets the approved address for a token ID, or zero if no address set 104 | * @param _tokenId uint256 ID of the token to query the approval of 105 | * @return address currently approved for the given token ID 106 | */ 107 | function getApproved(uint256 _tokenId) public view returns (address) { 108 | return tokenApprovals[_tokenId]; 109 | } 110 | 111 | /** 112 | * @dev Sets or unsets the approval of a given operator 113 | * @dev An operator is allowed to transfer all tokens of the sender on their behalf 114 | * @param _to operator address to set the approval 115 | * @param _approved representing the status of the approval to be set 116 | */ 117 | function setApprovalForAll(address _to, bool _approved) public { 118 | require(_to != msg.sender); 119 | operatorApprovals[msg.sender][_to] = _approved; 120 | emit ApprovalForAll(msg.sender, _to, _approved); 121 | } 122 | 123 | function isApprovedForAll(address _owner, address _operator) public view returns (bool) { 124 | return operatorApprovals[_owner][_operator]; 125 | } 126 | 127 | /** 128 | * @dev Transfers the ownership of a given token ID to another address 129 | * @dev Usage of this method is discouraged, use `safeTransferFrom` whenever possible 130 | * @dev Requires the msg sender to be the owner, approved, or operator 131 | * @param _from current owner of the token 132 | * @param _to address to receive the ownership of the given token ID 133 | * @param _tokenId uint256 ID of the token to be transferred 134 | */ 135 | function transferFrom(address _from, address _to, uint256 _tokenId) public canTransfer(_tokenId) { 136 | require(_from != address(0)); 137 | require(_to != address(0)); 138 | 139 | clearApproval(_from, _tokenId); 140 | removeTokenFrom(_from, _tokenId); 141 | addTokenTo(_to, _tokenId); 142 | 143 | emit Transfer(_from, _to, _tokenId); 144 | } 145 | 146 | 147 | 148 | /** 149 | * @dev Returns whether the given spender can transfer a given token ID 150 | * @param _spender address of the spender to query 151 | * @param _tokenId uint256 ID of the token to be transferred 152 | * @return bool whether the msg.sender is approved for the given token ID, 153 | * is an operator of the owner, or is the owner of the token 154 | */ 155 | function isApprovedOrOwner(address _spender, uint256 _tokenId) public view returns (bool) { 156 | address owner = ownerOf(_tokenId); 157 | return _spender == owner || getApproved(_tokenId) == _spender || isApprovedForAll(owner, _spender); 158 | } 159 | 160 | /** 161 | * @dev Internal function to mint a new token 162 | * @dev Reverts if the given token ID already exists 163 | * @param _to The address that will own the minted token 164 | * @param _tokenId uint256 ID of the token to be minted by the msg.sender 165 | * @dev _check(2) checks msg.sender == ADMIN 166 | */ 167 | function _mint(address _to, uint256 _tokenId) external check(2) { 168 | require(_to != address(0)); 169 | addTokenTo(_to, _tokenId); 170 | numTokensTotal = numTokensTotal.add(1); 171 | emit Transfer(address(0), _to, _tokenId); 172 | } 173 | 174 | /** 175 | * @dev Internal function to burn a specific token 176 | * @dev Reverts if the token does not exist 177 | * @param _tokenId uint256 ID of the token being burned by the msg.sender 178 | */ 179 | function _burn(address _owner, uint256 _tokenId) external check(2) { 180 | clearApproval(_owner, _tokenId); 181 | removeTokenFrom(_owner, _tokenId); 182 | numTokensTotal = numTokensTotal.sub(1); 183 | emit Transfer(_owner, address(0), _tokenId); 184 | } 185 | 186 | /** 187 | * @dev Internal function to clear current approval of a given token ID 188 | * @dev Reverts if the given address is not indeed the owner of the token 189 | * @param _owner owner of the token 190 | * @param _tokenId uint256 ID of the token to be transferred 191 | */ 192 | function clearApproval(address _owner, uint256 _tokenId) internal { 193 | require(ownerOf(_tokenId) == _owner); 194 | if (tokenApprovals[_tokenId] != address(0)) { 195 | tokenApprovals[_tokenId] = address(0); 196 | emit Approval(_owner, address(0), _tokenId); 197 | } 198 | } 199 | 200 | /** 201 | * @dev Internal function to add a token ID to the list of a given address 202 | * @param _to address representing the new owner of the given token ID 203 | * @param _tokenId uint256 ID of the token to be added to the tokens list of the given address 204 | */ 205 | function addTokenTo(address _to, uint256 _tokenId) internal { 206 | require(tokenOwner[_tokenId] == address(0)); 207 | tokenOwner[_tokenId] = _to; 208 | ownedTokensCount[_to] = ownedTokensCount[_to].add(1); 209 | } 210 | 211 | /** 212 | * @dev Internal function to remove a token ID from the list of a given address 213 | * @param _from address representing the previous owner of the given token ID 214 | * @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address 215 | */ 216 | function removeTokenFrom(address _from, uint256 _tokenId) internal { 217 | require(ownerOf(_tokenId) == _from); 218 | ownedTokensCount[_from] = ownedTokensCount[_from].sub(1); 219 | tokenOwner[_tokenId] = address(0); 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /Flowertokens/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | constructor() public { 8 | owner = msg.sender; 9 | } 10 | 11 | modifier restricted() { 12 | if (msg.sender == owner) _; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) public restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Flowertokens/contracts/Ownable.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | 4 | /** 5 | * @title Ownable 6 | * @dev The Ownable contract has an owner address, and provides basic authorization control 7 | * functions, this simplifies the implementation of "user permissions". 8 | */ 9 | contract Ownable { 10 | address public owner; 11 | 12 | 13 | event OwnershipRenounced(address indexed previousOwner); 14 | event OwnershipTransferred( 15 | address indexed previousOwner, 16 | address indexed newOwner 17 | ); 18 | 19 | 20 | /** 21 | * @dev The Ownable constructor sets the original `owner` of the contract to the sender 22 | * account. 23 | */ 24 | constructor() public { 25 | owner = msg.sender; 26 | } 27 | 28 | /** 29 | * @dev Throws if called by any account other than the owner. 30 | */ 31 | modifier onlyOwner() { 32 | require(msg.sender == owner); 33 | _; 34 | } 35 | 36 | /** 37 | * @dev Allows the current owner to relinquish control of the contract. 38 | */ 39 | function renounceOwnership() public onlyOwner { 40 | emit OwnershipRenounced(owner); 41 | owner = address(0); 42 | } 43 | 44 | /** 45 | * @dev Allows the current owner to transfer control of the contract to a newOwner. 46 | * @param _newOwner The address to transfer ownership to. 47 | */ 48 | function transferOwnership(address _newOwner) public onlyOwner { 49 | _transferOwnership(_newOwner); 50 | } 51 | 52 | /** 53 | * @dev Transfers control of the contract to a newOwner. 54 | * @param _newOwner The address to transfer ownership to. 55 | */ 56 | function _transferOwnership(address _newOwner) internal { 57 | require(_newOwner != address(0)); 58 | emit OwnershipTransferred(owner, _newOwner); 59 | owner = _newOwner; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Flowertokens/contracts/SafeMath.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | /** 4 | * @title SafeMath 5 | * @dev Math operations with safety checks that throw on error 6 | */ 7 | library SafeMath { 8 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 9 | if (a == 0) { 10 | return 0; 11 | } 12 | uint256 c = a * b; 13 | assert(c / a == b); 14 | return c; 15 | } 16 | 17 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 18 | // assert(b > 0); // Solidity automatically throws when dividing by 0 19 | uint256 c = a / b; 20 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 21 | return c; 22 | } 23 | 24 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 25 | assert(b <= a); 26 | return a - b; 27 | } 28 | 29 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 30 | uint256 c = a + b; 31 | assert(c >= a); 32 | return c; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Flowertokens/contracts/acl.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | /** 4 | * This is the first version of a simple ACL / Permission Management System 5 | * It might differentiate from other Permission Management Systems and therefore be more restrictive in the following points: 6 | * Every User can just have one Role 7 | * No new Roles can be generated 8 | * Therefore all possible Roles must be defined at the beginning 9 | */ 10 | 11 | contract acl{ 12 | 13 | enum Role { 14 | USER, 15 | ORACLE, 16 | ADMIN 17 | } 18 | 19 | /// @dev mapping address to particular role 20 | mapping (address=> Role) permissions; 21 | 22 | /// @dev constructor function to map deploying address to ADMIN role 23 | constructor() public { 24 | permissions[msg.sender] = Role(2); 25 | } 26 | 27 | /// @dev function to map address to certain role 28 | /// @param rolevalue uint to set role as either USER, ORACLE, or ADMIN 29 | /// @param entity address to be mapped to particlar role 30 | function setRole(uint8 rolevalue,address entity)external check(2){ 31 | permissions[entity] = Role(rolevalue); 32 | } 33 | 34 | /// @dev function to return role of entity based on address 35 | /// @param entity address of entity who's role is to be returned 36 | /// @return returns role of entity 37 | function getRole(address entity)public view returns(Role){ 38 | return permissions[entity]; 39 | } 40 | 41 | /// @dev function modifier to check entity can call smart contract function 42 | modifier check(uint8 role) { 43 | require(uint8(getRole(msg.sender)) == role); 44 | _; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Flowertokens/contracts/bloomingPool.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | import "./update.sol"; 3 | import "./SafeMath.sol"; 4 | 5 | /// @dev altered version of Open Zepplin's 'SplitPayment' contract for use by Blooming Pool 6 | 7 | contract bloomingPool is update { 8 | 9 | using SafeMath for uint256; 10 | 11 | uint256 public totalShares = 0; 12 | uint256 public totalReleased = 0; 13 | bool public freeze; 14 | 15 | /// @dev mapping address to number of held shares 16 | mapping(address => uint256) public shares; 17 | 18 | constructor() public { 19 | freeze = false; 20 | } 21 | 22 | /// @ dev fallback payment function 23 | function() public payable { } 24 | 25 | /// @dev function to calculate the total shares held by a user 26 | /// @param _shares number of shares mapped to the unique_id of a token 27 | /// @param unique_id unique id of token 28 | function calculate_total_shares(uint256 _shares,uint256 unique_id )internal{ 29 | shares[tokenOwner[unique_id]] = shares[tokenOwner[unique_id]].add(_shares); 30 | totalShares = totalShares.add(_shares); 31 | } 32 | 33 | /// @dev function called by oracle to calculate the total shares for a given token 34 | /// @param unique_id id number of a token 35 | /// @modifier check(1) checks role of entity calling function by address has ORACLE role 36 | function oracle_call(uint256 unique_id) external check(1){ 37 | calculate_total_shares(1,unique_id); 38 | } 39 | 40 | /// @dev function to find the number of shares held by entity calling function 41 | /// @return individual_shares returns uint of shares held by entity 42 | function get_shares() external view returns(uint256 individual_shares){ 43 | return shares[msg.sender]; 44 | } 45 | 46 | /// @dev emergency function to freeze withdrawls from Blooming Pool contract 47 | /// @param _freeze boolean to set global variable allowing / not allowing withdrawls 48 | /// @modifier check(2) checks role of entity calling function by address has ADMIN role 49 | function freeze_pool(bool _freeze) external check(2){ 50 | freeze = _freeze; 51 | } 52 | 53 | /// @dev function to reset shares of entity to 0 after withdrawl 54 | /// @param address denotes entity to reset shares of to 0 by address 55 | function reset_individual_shares(address payee)internal { 56 | shares[payee] = 0; 57 | } 58 | 59 | /// @dev function to remove certain number of shares from entity's total share count 60 | /// @param _shares number of shares to remove from entity's total 61 | function substract_individual_shares(uint256 _shares)internal { 62 | totalShares = totalShares - _shares; 63 | } 64 | 65 | /// @dev function called by entity to claim number of shares mapped to address 66 | function claim()public{ 67 | payout(msg.sender); 68 | } 69 | 70 | /// @dev function to payout Eth to entity 71 | /// @param to address of entity to transfer Eth 72 | function payout(address to) internal returns(bool){ 73 | require(freeze == false); 74 | address payee = to; 75 | require(shares[payee] > 0); 76 | 77 | uint256 volume = address(this).balance; 78 | uint256 payment = volume.mul(shares[payee]).div(totalShares); 79 | 80 | require(payment != 0); 81 | require(address(this).balance >= payment); 82 | 83 | totalReleased = totalReleased.add(payment); 84 | payee.transfer(payment); 85 | substract_individual_shares(shares[payee]); 86 | reset_individual_shares(payee); 87 | } 88 | 89 | /// @dev emergency function to withdraw Eth from contract in case of OpSec failure 90 | /// @param amount amount of Eth to be transferred to entity calling function 91 | /// @modifier check(2) checks role of entity calling function by address has ADMIN role 92 | function emergency_withdraw(uint amount) external check(2) { 93 | require(amount <= this.balance); 94 | msg.sender.transfer(amount); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /Flowertokens/contracts/buyable.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | import "./bloomingPool.sol"; 3 | import "./ERC721BasicToken.sol"; 4 | 5 | /** 6 | * Functions for purchase and selling of Flowertokens, as well as viewing availability of tokens. 7 | */ 8 | 9 | contract buyable is bloomingPool { 10 | 11 | address INFRASTRUCTURE_POOL_ADDRESS; 12 | mapping (uint256 => uint256) TokenIdtosetprice; 13 | mapping (uint256 => uint256) TokenIdtoprice; 14 | 15 | event Set_price_and_sell(uint256 tokenId, uint256 Price); 16 | event Stop_sell(uint256 tokenId); 17 | 18 | constructor() public {} 19 | 20 | /// @dev function to set INFRASTRUCTURE_POOL_ADDRESS global var to address of deployed infrastructurePool contract 21 | /// @param _infrastructure_address address of deployed infrastructurePool contract 22 | /// @modifier check(2) checks role of entity calling function by address has ADMIN role 23 | function initialisation(address _infrastructure_address) public check(2){ 24 | INFRASTRUCTURE_POOL_ADDRESS = _infrastructure_address; 25 | } 26 | 27 | /// @dev function to set the price of a Flowertoken and also put it up for sale 28 | /// @param UniqueID unique identification number of Flowertoken to be sold 29 | /// @param Price price Flowertoken is to be sold for 30 | function set_price_and_sell(uint256 UniqueID,uint256 Price) external { 31 | approve(address(this), UniqueID); 32 | TokenIdtosetprice[UniqueID] = Price; 33 | emit Set_price_and_sell(UniqueID, Price); 34 | } 35 | 36 | /// @dev function to take Flowertoken which is for sale off the market 37 | /// @param UniqueID unique identification number of Flowertoken to be sold 38 | function stop_sell(uint256 UniqueID) external payable{ 39 | require(tokenOwner[UniqueID] == msg.sender); 40 | clearApproval(tokenOwner[UniqueID],UniqueID); 41 | emit Stop_sell(UniqueID); 42 | } 43 | 44 | /// @dev function to purchase Flowertoken 45 | /// @param UniqueID unique identification number of Flowertoken to be sold 46 | function buy(uint256 UniqueID) external payable { 47 | address _to = msg.sender; 48 | require(TokenIdtosetprice[UniqueID] == msg.value); 49 | TokenIdtoprice[UniqueID] = msg.value; 50 | uint _blooming = msg.value.div(20); 51 | uint _infrastructure = msg.value.div(20); 52 | uint _combined = _blooming.add(_infrastructure); 53 | uint _amount_for_seller = msg.value.sub(_combined); 54 | require(tokenOwner[UniqueID].call.gas(99999).value(_amount_for_seller)()); 55 | this.transferFrom(tokenOwner[UniqueID], _to, UniqueID); 56 | if(!INFRASTRUCTURE_POOL_ADDRESS.call.gas(99999).value(_infrastructure)()){ 57 | revert("transfer to infrastructurePool failed"); 58 | } 59 | } 60 | 61 | /// @dev function which returns the price and availability of specified Flowertoken 62 | /// @param _tokenId unique identification number of Flowertoken to be sold 63 | /// @return price and availability of specified Flowertoken 64 | function get_token_data(uint256 _tokenId) external view returns(uint256 _price, uint256 _setprice, bool _buyable){ 65 | _price = TokenIdtoprice[_tokenId]; 66 | _setprice = TokenIdtosetprice[_tokenId]; 67 | if (tokenApprovals[_tokenId] != address(0)){ 68 | _buyable = true; 69 | } 70 | } 71 | 72 | /// @dev function which returns availability of specified Flowertoken 73 | /// @param _tokenId unique identification number of Flowertoken to be sold 74 | /// @return returns boolean denoting availability of specified Flowertoken 75 | function get_token_data_buyable(uint256 _tokenId) external view returns(bool _buyable) { 76 | if (tokenApprovals[_tokenId] != address(0)){ 77 | _buyable = true; 78 | } 79 | } 80 | 81 | /// @dev function which returns array denoting availability of all Flowertokens 82 | /// @return array denoting availability of all Flowertokens 83 | function get_all_sellable_token()external view returns(bool[101] list_of_available){ 84 | uint i; 85 | for(i = 0;i<101;i++) { 86 | if (tokenApprovals[i] != address(0)){ 87 | list_of_available[i] = true; 88 | }else{ 89 | list_of_available[i] = false; 90 | } 91 | } 92 | } 93 | 94 | /// @dev function which returns array denoting whether entity calling function is owner of each Flowertoken 95 | /// @return array denoting ownership of each Flowertoken 96 | function get_my_tokens()external view returns(bool[101] list_of_my_tokens){ 97 | uint i; 98 | address _owner = msg.sender; 99 | for(i = 0;i<101;i++) { 100 | if (tokenOwner[i] == _owner){ 101 | list_of_my_tokens[i] = true; 102 | }else{ 103 | list_of_my_tokens[i] = false; 104 | } 105 | } 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /Flowertokens/contracts/infrastructurePool.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | import "./SafeMath.sol"; 4 | import "./Ownable.sol"; 5 | 6 | contract infrastructurePool is Ownable { 7 | 8 | using SafeMath for uint256; 9 | 10 | constructor() public {} 11 | 12 | function() payable {} 13 | 14 | function withdrawFunds(uint amount) external onlyOwner { 15 | require(amount <= this.balance); 16 | msg.sender.transfer(amount); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Flowertokens/contracts/strings.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @title String & slice utility library for Solidity contracts. 3 | * @author Nick Johnson 4 | * 5 | * @dev Functionality in this library is largely implemented using an 6 | * abstraction called a 'slice'. A slice represents a part of a string - 7 | * anything from the entire string to a single character, or even no 8 | * characters at all (a 0-length slice). Since a slice only has to specify 9 | * an offset and a length, copying and manipulating slices is a lot less 10 | * expensive than copying and manipulating the strings they reference. 11 | * 12 | * To further reduce gas costs, most functions on slice that need to return 13 | * a slice modify the original one instead of allocating a new one; for 14 | * instance, `s.split(".")` will return the text up to the first '.', 15 | * modifying s to only contain the remainder of the string after the '.'. 16 | * In situations where you do not want to modify the original slice, you 17 | * can make a copy first with `.copy()`, for example: 18 | * `s.copy().split(".")`. Try and avoid using this idiom in loops; since 19 | * Solidity has no memory management, it will result in allocating many 20 | * short-lived slices that are later discarded. 21 | * 22 | * Functions that return two slices come in two versions: a non-allocating 23 | * version that takes the second slice as an argument, modifying it in 24 | * place, and an allocating version that allocates and returns the second 25 | * slice; see `nextRune` for example. 26 | * 27 | * Functions that have to copy string data will return strings rather than 28 | * slices; these can be cast back to slices for further processing if 29 | * required. 30 | * 31 | * For convenience, some functions are provided with non-modifying 32 | * variants that create a new slice and return both; for instance, 33 | * `s.splitNew('.')` leaves s unmodified, and returns two values 34 | * corresponding to the left and right parts of the string. 35 | */ 36 | 37 | //pragma solidity ^0.4.11; 38 | pragma solidity ^0.4.14; 39 | 40 | library strings { 41 | struct slice { 42 | uint _len; 43 | uint _ptr; 44 | } 45 | 46 | function memcpy(uint dest, uint src, uint len) private pure { 47 | // Copy word-length chunks while possible 48 | for(; len >= 32; len -= 32) { 49 | assembly { 50 | mstore(dest, mload(src)) 51 | } 52 | dest += 32; 53 | src += 32; 54 | } 55 | 56 | // Copy remaining bytes 57 | uint mask = 256 ** (32 - len) - 1; 58 | assembly { 59 | let srcpart := and(mload(src), not(mask)) 60 | let destpart := and(mload(dest), mask) 61 | mstore(dest, or(destpart, srcpart)) 62 | } 63 | } 64 | 65 | /* 66 | * @dev Returns a slice containing the entire string. 67 | * @param self The string to make a slice from. 68 | * @return A newly allocated slice containing the entire string. 69 | */ 70 | function toSlice(string self) internal pure returns (slice) { 71 | uint ptr; 72 | assembly { 73 | ptr := add(self, 0x20) 74 | } 75 | return slice(bytes(self).length, ptr); 76 | } 77 | 78 | /* 79 | * @dev Returns the length of a null-terminated bytes32 string. 80 | * @param self The value to find the length of. 81 | * @return The length of the string, from 0 to 32. 82 | */ 83 | function len(bytes32 self) internal pure returns (uint) { 84 | uint ret; 85 | if (self == 0) 86 | return 0; 87 | if (self & 0xffffffffffffffffffffffffffffffff == 0) { 88 | ret += 16; 89 | self = bytes32(uint(self) / 0x100000000000000000000000000000000); 90 | } 91 | if (self & 0xffffffffffffffff == 0) { 92 | ret += 8; 93 | self = bytes32(uint(self) / 0x10000000000000000); 94 | } 95 | if (self & 0xffffffff == 0) { 96 | ret += 4; 97 | self = bytes32(uint(self) / 0x100000000); 98 | } 99 | if (self & 0xffff == 0) { 100 | ret += 2; 101 | self = bytes32(uint(self) / 0x10000); 102 | } 103 | if (self & 0xff == 0) { 104 | ret += 1; 105 | } 106 | return 32 - ret; 107 | } 108 | 109 | /* 110 | * @dev Returns a slice containing the entire bytes32, interpreted as a 111 | * null-termintaed utf-8 string. 112 | * @param self The bytes32 value to convert to a slice. 113 | * @return A new slice containing the value of the input argument up to the 114 | * first null. 115 | */ 116 | function toSliceB32(bytes32 self) internal pure returns (slice ret) { 117 | // Allocate space for `self` in memory, copy it there, and point ret at it 118 | assembly { 119 | let ptr := mload(0x40) 120 | mstore(0x40, add(ptr, 0x20)) 121 | mstore(ptr, self) 122 | mstore(add(ret, 0x20), ptr) 123 | } 124 | ret._len = len(self); 125 | } 126 | 127 | /* 128 | * @dev Returns a new slice containing the same data as the current slice. 129 | * @param self The slice to copy. 130 | * @return A new slice containing the same data as `self`. 131 | */ 132 | function copy(slice self) internal pure returns (slice) { 133 | return slice(self._len, self._ptr); 134 | } 135 | 136 | /* 137 | * @dev Copies a slice to a new string. 138 | * @param self The slice to copy. 139 | * @return A newly allocated string containing the slice's text. 140 | */ 141 | function toString(slice self) internal pure returns (string) { 142 | string memory ret = new string(self._len); 143 | uint retptr; 144 | assembly { retptr := add(ret, 32) } 145 | 146 | memcpy(retptr, self._ptr, self._len); 147 | return ret; 148 | } 149 | 150 | /* 151 | * @dev Returns the length in runes of the slice. Note that this operation 152 | * takes time proportional to the length of the slice; avoid using it 153 | * in loops, and call `slice.empty()` if you only need to know whether 154 | * the slice is empty or not. 155 | * @param self The slice to operate on. 156 | * @return The length of the slice in runes. 157 | */ 158 | function len(slice self) internal pure returns (uint l) { 159 | // Starting at ptr-31 means the LSB will be the byte we care about 160 | uint ptr = self._ptr - 31; 161 | uint end = ptr + self._len; 162 | for (l = 0; ptr < end; l++) { 163 | uint8 b; 164 | assembly { b := and(mload(ptr), 0xFF) } 165 | if (b < 0x80) { 166 | ptr += 1; 167 | } else if(b < 0xE0) { 168 | ptr += 2; 169 | } else if(b < 0xF0) { 170 | ptr += 3; 171 | } else if(b < 0xF8) { 172 | ptr += 4; 173 | } else if(b < 0xFC) { 174 | ptr += 5; 175 | } else { 176 | ptr += 6; 177 | } 178 | } 179 | } 180 | 181 | /* 182 | * @dev Returns true if the slice is empty (has a length of 0). 183 | * @param self The slice to operate on. 184 | * @return True if the slice is empty, False otherwise. 185 | */ 186 | function empty(slice self) internal pure returns (bool) { 187 | return self._len == 0; 188 | } 189 | 190 | /* 191 | * @dev Returns a positive number if `other` comes lexicographically after 192 | * `self`, a negative number if it comes before, or zero if the 193 | * contents of the two slices are equal. Comparison is done per-rune, 194 | * on unicode codepoints. 195 | * @param self The first slice to compare. 196 | * @param other The second slice to compare. 197 | * @return The result of the comparison. 198 | */ 199 | function compare(slice self, slice other) internal pure returns (int) { 200 | uint shortest = self._len; 201 | if (other._len < self._len) 202 | shortest = other._len; 203 | 204 | uint selfptr = self._ptr; 205 | uint otherptr = other._ptr; 206 | for (uint idx = 0; idx < shortest; idx += 32) { 207 | uint a; 208 | uint b; 209 | assembly { 210 | a := mload(selfptr) 211 | b := mload(otherptr) 212 | } 213 | if (a != b) { 214 | // Mask out irrelevant bytes and check again 215 | uint256 mask = ~(2 ** (8 * (32 - shortest + idx)) - 1); 216 | uint256 diff = (a & mask) - (b & mask); 217 | if (diff != 0) 218 | return int(diff); 219 | } 220 | selfptr += 32; 221 | otherptr += 32; 222 | } 223 | return int(self._len) - int(other._len); 224 | } 225 | 226 | /* 227 | * @dev Returns true if the two slices contain the same text. 228 | * @param self The first slice to compare. 229 | * @param self The second slice to compare. 230 | * @return True if the slices are equal, false otherwise. 231 | */ 232 | function equals(slice self, slice other) internal pure returns (bool) { 233 | return compare(self, other) == 0; 234 | } 235 | 236 | /* 237 | * @dev Extracts the first rune in the slice into `rune`, advancing the 238 | * slice to point to the next rune and returning `self`. 239 | * @param self The slice to operate on. 240 | * @param rune The slice that will contain the first rune. 241 | * @return `rune`. 242 | */ 243 | function nextRune(slice self, slice rune) internal pure returns (slice) { 244 | rune._ptr = self._ptr; 245 | 246 | if (self._len == 0) { 247 | rune._len = 0; 248 | return rune; 249 | } 250 | 251 | uint l; 252 | uint b; 253 | // Load the first byte of the rune into the LSBs of b 254 | assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) } 255 | if (b < 0x80) { 256 | l = 1; 257 | } else if(b < 0xE0) { 258 | l = 2; 259 | } else if(b < 0xF0) { 260 | l = 3; 261 | } else { 262 | l = 4; 263 | } 264 | 265 | // Check for truncated codepoints 266 | if (l > self._len) { 267 | rune._len = self._len; 268 | self._ptr += self._len; 269 | self._len = 0; 270 | return rune; 271 | } 272 | 273 | self._ptr += l; 274 | self._len -= l; 275 | rune._len = l; 276 | return rune; 277 | } 278 | 279 | /* 280 | * @dev Returns the first rune in the slice, advancing the slice to point 281 | * to the next rune. 282 | * @param self The slice to operate on. 283 | * @return A slice containing only the first rune from `self`. 284 | */ 285 | function nextRune(slice self) internal pure returns (slice ret) { 286 | nextRune(self, ret); 287 | } 288 | 289 | /* 290 | * @dev Returns the number of the first codepoint in the slice. 291 | * @param self The slice to operate on. 292 | * @return The number of the first codepoint in the slice. 293 | */ 294 | function ord(slice self) internal pure returns (uint ret) { 295 | if (self._len == 0) { 296 | return 0; 297 | } 298 | 299 | uint word; 300 | uint length; 301 | uint divisor = 2 ** 248; 302 | 303 | // Load the rune into the MSBs of b 304 | assembly { word:= mload(mload(add(self, 32))) } 305 | uint b = word / divisor; 306 | if (b < 0x80) { 307 | ret = b; 308 | length = 1; 309 | } else if(b < 0xE0) { 310 | ret = b & 0x1F; 311 | length = 2; 312 | } else if(b < 0xF0) { 313 | ret = b & 0x0F; 314 | length = 3; 315 | } else { 316 | ret = b & 0x07; 317 | length = 4; 318 | } 319 | 320 | // Check for truncated codepoints 321 | if (length > self._len) { 322 | return 0; 323 | } 324 | 325 | for (uint i = 1; i < length; i++) { 326 | divisor = divisor / 256; 327 | b = (word / divisor) & 0xFF; 328 | if (b & 0xC0 != 0x80) { 329 | // Invalid UTF-8 sequence 330 | return 0; 331 | } 332 | ret = (ret * 64) | (b & 0x3F); 333 | } 334 | 335 | return ret; 336 | } 337 | 338 | /* 339 | * @dev Returns the keccak-256 hash of the slice. 340 | * @param self The slice to hash. 341 | * @return The hash of the slice. 342 | */ 343 | function keccak(slice self) internal pure returns (bytes32 ret) { 344 | assembly { 345 | ret := keccak256(mload(add(self, 32)), mload(self)) 346 | } 347 | } 348 | 349 | /* 350 | * @dev Returns true if `self` starts with `needle`. 351 | * @param self The slice to operate on. 352 | * @param needle The slice to search for. 353 | * @return True if the slice starts with the provided text, false otherwise. 354 | */ 355 | function startsWith(slice self, slice needle) internal pure returns (bool) { 356 | if (self._len < needle._len) { 357 | return false; 358 | } 359 | 360 | if (self._ptr == needle._ptr) { 361 | return true; 362 | } 363 | 364 | bool equal; 365 | assembly { 366 | let length := mload(needle) 367 | let selfptr := mload(add(self, 0x20)) 368 | let needleptr := mload(add(needle, 0x20)) 369 | equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) 370 | } 371 | return equal; 372 | } 373 | 374 | /* 375 | * @dev If `self` starts with `needle`, `needle` is removed from the 376 | * beginning of `self`. Otherwise, `self` is unmodified. 377 | * @param self The slice to operate on. 378 | * @param needle The slice to search for. 379 | * @return `self` 380 | */ 381 | function beyond(slice self, slice needle) internal pure returns (slice) { 382 | if (self._len < needle._len) { 383 | return self; 384 | } 385 | 386 | bool equal = true; 387 | if (self._ptr != needle._ptr) { 388 | assembly { 389 | let length := mload(needle) 390 | let selfptr := mload(add(self, 0x20)) 391 | let needleptr := mload(add(needle, 0x20)) 392 | equal := eq(sha3(selfptr, length), sha3(needleptr, length)) 393 | } 394 | } 395 | 396 | if (equal) { 397 | self._len -= needle._len; 398 | self._ptr += needle._len; 399 | } 400 | 401 | return self; 402 | } 403 | 404 | /* 405 | * @dev Returns true if the slice ends with `needle`. 406 | * @param self The slice to operate on. 407 | * @param needle The slice to search for. 408 | * @return True if the slice starts with the provided text, false otherwise. 409 | */ 410 | function endsWith(slice self, slice needle) internal pure returns (bool) { 411 | if (self._len < needle._len) { 412 | return false; 413 | } 414 | 415 | uint selfptr = self._ptr + self._len - needle._len; 416 | 417 | if (selfptr == needle._ptr) { 418 | return true; 419 | } 420 | 421 | bool equal; 422 | assembly { 423 | let length := mload(needle) 424 | let needleptr := mload(add(needle, 0x20)) 425 | equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) 426 | } 427 | 428 | return equal; 429 | } 430 | 431 | /* 432 | * @dev If `self` ends with `needle`, `needle` is removed from the 433 | * end of `self`. Otherwise, `self` is unmodified. 434 | * @param self The slice to operate on. 435 | * @param needle The slice to search for. 436 | * @return `self` 437 | */ 438 | function until(slice self, slice needle) internal pure returns (slice) { 439 | if (self._len < needle._len) { 440 | return self; 441 | } 442 | 443 | uint selfptr = self._ptr + self._len - needle._len; 444 | bool equal = true; 445 | if (selfptr != needle._ptr) { 446 | assembly { 447 | let length := mload(needle) 448 | let needleptr := mload(add(needle, 0x20)) 449 | equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) 450 | } 451 | } 452 | 453 | if (equal) { 454 | self._len -= needle._len; 455 | } 456 | 457 | return self; 458 | } 459 | 460 | event log_bytemask(bytes32 mask); 461 | 462 | // Returns the memory address of the first byte of the first occurrence of 463 | // `needle` in `self`, or the first byte after `self` if not found. 464 | function findPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) { 465 | uint ptr = selfptr; 466 | uint idx; 467 | 468 | if (needlelen <= selflen) { 469 | if (needlelen <= 32) { 470 | bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); 471 | 472 | bytes32 needledata; 473 | assembly { needledata := and(mload(needleptr), mask) } 474 | 475 | uint end = selfptr + selflen - needlelen; 476 | bytes32 ptrdata; 477 | assembly { ptrdata := and(mload(ptr), mask) } 478 | 479 | while (ptrdata != needledata) { 480 | if (ptr >= end) 481 | return selfptr + selflen; 482 | ptr++; 483 | assembly { ptrdata := and(mload(ptr), mask) } 484 | } 485 | return ptr; 486 | } else { 487 | // For long needles, use hashing 488 | bytes32 hash; 489 | assembly { hash := sha3(needleptr, needlelen) } 490 | 491 | for (idx = 0; idx <= selflen - needlelen; idx++) { 492 | bytes32 testHash; 493 | assembly { testHash := sha3(ptr, needlelen) } 494 | if (hash == testHash) 495 | return ptr; 496 | ptr += 1; 497 | } 498 | } 499 | } 500 | return selfptr + selflen; 501 | } 502 | 503 | // Returns the memory address of the first byte after the last occurrence of 504 | // `needle` in `self`, or the address of `self` if not found. 505 | function rfindPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) { 506 | uint ptr; 507 | 508 | if (needlelen <= selflen) { 509 | if (needlelen <= 32) { 510 | bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1)); 511 | 512 | bytes32 needledata; 513 | assembly { needledata := and(mload(needleptr), mask) } 514 | 515 | ptr = selfptr + selflen - needlelen; 516 | bytes32 ptrdata; 517 | assembly { ptrdata := and(mload(ptr), mask) } 518 | 519 | while (ptrdata != needledata) { 520 | if (ptr <= selfptr) 521 | return selfptr; 522 | ptr--; 523 | assembly { ptrdata := and(mload(ptr), mask) } 524 | } 525 | return ptr + needlelen; 526 | } else { 527 | // For long needles, use hashing 528 | bytes32 hash; 529 | assembly { hash := sha3(needleptr, needlelen) } 530 | ptr = selfptr + (selflen - needlelen); 531 | while (ptr >= selfptr) { 532 | bytes32 testHash; 533 | assembly { testHash := sha3(ptr, needlelen) } 534 | if (hash == testHash) 535 | return ptr + needlelen; 536 | ptr -= 1; 537 | } 538 | } 539 | } 540 | return selfptr; 541 | } 542 | 543 | /* 544 | * @dev Modifies `self` to contain everything from the first occurrence of 545 | * `needle` to the end of the slice. `self` is set to the empty slice 546 | * if `needle` is not found. 547 | * @param self The slice to search and modify. 548 | * @param needle The text to search for. 549 | * @return `self`. 550 | */ 551 | function find(slice self, slice needle) internal pure returns (slice) { 552 | uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); 553 | self._len -= ptr - self._ptr; 554 | self._ptr = ptr; 555 | return self; 556 | } 557 | 558 | /* 559 | * @dev Modifies `self` to contain the part of the string from the start of 560 | * `self` to the end of the first occurrence of `needle`. If `needle` 561 | * is not found, `self` is set to the empty slice. 562 | * @param self The slice to search and modify. 563 | * @param needle The text to search for. 564 | * @return `self`. 565 | */ 566 | function rfind(slice self, slice needle) internal pure returns (slice) { 567 | uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); 568 | self._len = ptr - self._ptr; 569 | return self; 570 | } 571 | 572 | /* 573 | * @dev Splits the slice, setting `self` to everything after the first 574 | * occurrence of `needle`, and `token` to everything before it. If 575 | * `needle` does not occur in `self`, `self` is set to the empty slice, 576 | * and `token` is set to the entirety of `self`. 577 | * @param self The slice to split. 578 | * @param needle The text to search for in `self`. 579 | * @param token An output parameter to which the first token is written. 580 | * @return `token`. 581 | */ 582 | function split(slice self, slice needle, slice token) internal pure returns (slice) { 583 | uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr); 584 | token._ptr = self._ptr; 585 | token._len = ptr - self._ptr; 586 | if (ptr == self._ptr + self._len) { 587 | // Not found 588 | self._len = 0; 589 | } else { 590 | self._len -= token._len + needle._len; 591 | self._ptr = ptr + needle._len; 592 | } 593 | return token; 594 | } 595 | 596 | /* 597 | * @dev Splits the slice, setting `self` to everything after the first 598 | * occurrence of `needle`, and returning everything before it. If 599 | * `needle` does not occur in `self`, `self` is set to the empty slice, 600 | * and the entirety of `self` is returned. 601 | * @param self The slice to split. 602 | * @param needle The text to search for in `self`. 603 | * @return The part of `self` up to the first occurrence of `delim`. 604 | */ 605 | function split(slice self, slice needle) internal pure returns (slice token) { 606 | split(self, needle, token); 607 | } 608 | 609 | /* 610 | * @dev Splits the slice, setting `self` to everything before the last 611 | * occurrence of `needle`, and `token` to everything after it. If 612 | * `needle` does not occur in `self`, `self` is set to the empty slice, 613 | * and `token` is set to the entirety of `self`. 614 | * @param self The slice to split. 615 | * @param needle The text to search for in `self`. 616 | * @param token An output parameter to which the first token is written. 617 | * @return `token`. 618 | */ 619 | function rsplit(slice self, slice needle, slice token) internal pure returns (slice) { 620 | uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr); 621 | token._ptr = ptr; 622 | token._len = self._len - (ptr - self._ptr); 623 | if (ptr == self._ptr) { 624 | // Not found 625 | self._len = 0; 626 | } else { 627 | self._len -= token._len + needle._len; 628 | } 629 | return token; 630 | } 631 | 632 | /* 633 | * @dev Splits the slice, setting `self` to everything before the last 634 | * occurrence of `needle`, and returning everything after it. If 635 | * `needle` does not occur in `self`, `self` is set to the empty slice, 636 | * and the entirety of `self` is returned. 637 | * @param self The slice to split. 638 | * @param needle The text to search for in `self`. 639 | * @return The part of `self` after the last occurrence of `delim`. 640 | */ 641 | function rsplit(slice self, slice needle) internal pure returns (slice token) { 642 | rsplit(self, needle, token); 643 | } 644 | 645 | /* 646 | * @dev Counts the number of nonoverlapping occurrences of `needle` in `self`. 647 | * @param self The slice to search. 648 | * @param needle The text to search for in `self`. 649 | * @return The number of occurrences of `needle` found in `self`. 650 | */ 651 | function count(slice self, slice needle) internal pure returns (uint cnt) { 652 | uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) + needle._len; 653 | while (ptr <= self._ptr + self._len) { 654 | cnt++; 655 | ptr = findPtr(self._len - (ptr - self._ptr), ptr, needle._len, needle._ptr) + needle._len; 656 | } 657 | } 658 | 659 | /* 660 | * @dev Returns True if `self` contains `needle`. 661 | * @param self The slice to search. 662 | * @param needle The text to search for in `self`. 663 | * @return True if `needle` is found in `self`, false otherwise. 664 | */ 665 | function contains(slice self, slice needle) internal pure returns (bool) { 666 | return rfindPtr(self._len, self._ptr, needle._len, needle._ptr) != self._ptr; 667 | } 668 | 669 | /* 670 | * @dev Returns a newly allocated string containing the concatenation of 671 | * `self` and `other`. 672 | * @param self The first slice to concatenate. 673 | * @param other The second slice to concatenate. 674 | * @return The concatenation of the two strings. 675 | */ 676 | function concat(slice self, slice other) internal pure returns (string) { 677 | string memory ret = new string(self._len + other._len); 678 | uint retptr; 679 | assembly { retptr := add(ret, 32) } 680 | memcpy(retptr, self._ptr, self._len); 681 | memcpy(retptr + self._len, other._ptr, other._len); 682 | return ret; 683 | } 684 | 685 | /* 686 | * @dev Joins an array of slices, using `self` as a delimiter, returning a 687 | * newly allocated string. 688 | * @param self The delimiter to use. 689 | * @param parts A list of slices to join. 690 | * @return A newly allocated string containing all the slices in `parts`, 691 | * joined with `self`. 692 | */ 693 | function join(slice self, slice[] parts) internal pure returns (string) { 694 | if (parts.length == 0) 695 | return ""; 696 | 697 | uint length = self._len * (parts.length - 1); 698 | for(uint i = 0; i < parts.length; i++) 699 | length += parts[i]._len; 700 | 701 | string memory ret = new string(length); 702 | uint retptr; 703 | assembly { retptr := add(ret, 32) } 704 | 705 | for(i = 0; i < parts.length; i++) { 706 | memcpy(retptr, parts[i]._ptr, parts[i]._len); 707 | retptr += parts[i]._len; 708 | if (i < parts.length - 1) { 709 | memcpy(retptr, self._ptr, self._len); 710 | retptr += self._len; 711 | } 712 | } 713 | 714 | return ret; 715 | } 716 | } 717 | -------------------------------------------------------------------------------- /Flowertokens/contracts/testreg.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | import "./ERC721BasicToken.sol"; 3 | 4 | /** 5 | * Minimal token registry for Flowertokens linking each token to its accompanying metadata 6 | */ 7 | 8 | contract testreg is ERC721BasicToken { 9 | 10 | struct TokenStruct { 11 | string token_uri; 12 | } 13 | 14 | /// @dev mapping of token identification number to uri containing metadata 15 | mapping (uint256 => TokenStruct) TokenId; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Flowertokens/contracts/update.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | import "./testreg.sol"; 3 | 4 | /** 5 | * Functions to update metadata link for tokens and token minting on project initialisation 6 | */ 7 | 8 | contract update is testreg { 9 | 10 | event UpdateToken(uint256 _tokenId, string new_uri); 11 | 12 | /// @dev function to update the uri linked to a specified Flowertoken 13 | /// @param _tokenId unique identification number for specified Flowertoken 14 | /// @param new_uri new uri linking metadata to specified Flowertoken 15 | /// @modifier check(1) checks role of entity calling function by address has ORACLE role 16 | function updatetoken(uint256 _tokenId, string new_uri) external check(1){ 17 | TokenId[_tokenId].token_uri = new_uri; 18 | 19 | emit UpdateToken(_tokenId, new_uri); 20 | } 21 | 22 | /// @dev function to mint Flowertokens with initial uri 23 | /// @param _to entity given ownership of minted Flowertoken 24 | /// @param _tokenId unique identification number for specified Flowertoken 25 | /// @param new_uri new uri linking metadata to specified Flowertoken 26 | /// @modifier check(2) checks role of entity calling function by address has ADMIN role 27 | function _mint_with_uri(address _to, uint256 _tokenId, string new_uri) external check(2) { 28 | require(_to != address(0)); 29 | addTokenTo(_to, _tokenId); 30 | numTokensTotal = numTokensTotal.add(1); 31 | TokenId[_tokenId].token_uri = new_uri; 32 | emit Transfer(address(0), _to, _tokenId); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Flowertokens/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require("./Migrations.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /Flowertokens/migrations/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | var acl = artifacts.require("./acl.sol"); 2 | var bloomingPool = artifacts.require("./bloomingPool.sol"); 3 | var buyable = artifacts.require("./buyable.sol"); 4 | var testreg = artifacts.require("./testreg.sol"); 5 | var update = artifacts.require("./update.sol"); 6 | var erc721BasicToken = artifacts.require("./ERC721BasicToken.sol"); 7 | var infrastructurePool = artifacts.require("./infrastructurePool.sol") 8 | var ownable = artifacts.require("./Ownable.sol") 9 | 10 | module.exports = function(deployer) { 11 | deployer.deploy(buyable) 12 | deployer.deploy(infrastructurePool) 13 | } 14 | -------------------------------------------------------------------------------- /Flowertokens/test/initalisation.js: -------------------------------------------------------------------------------- 1 | var acl = artifacts.require("acl"); 2 | var bloomingPool = artifacts.require("bloomingPool"); 3 | var buyable = artifacts.require("buyable"); 4 | var testreg = artifacts.require("testreg"); 5 | var update = artifacts.require("update"); 6 | var erc721 = artifacts.require("ERC721BasicToken.sol"); 7 | var infrastructurePool = artifacts.require("infrastructurePool.sol"); 8 | 9 | buyable.setProvider(web3.currentProvider); 10 | 11 | var buyable; 12 | var infrastructure; 13 | 14 | buyable.deployed() 15 | .then(function(instance){ 16 | buyable = instance; 17 | console.log("\nbuyable.sol deployed properly...") 18 | }).then(function(){ 19 | return infrastructurePool.deployed() 20 | }).then(function(instance){ 21 | infrastructure = instance; 22 | console.log('\infrastructurePool.sol deployed properly...') 23 | }).then(function(){ 24 | console.log(`\nbuyable: ${buyable.address}, \ninfrastructure: ${infrastructure.address}`) 25 | }).then(function(){ 26 | console.log("\n\nbeginning minting...") 27 | }).then(function(){ 28 | return buyable.balanceOf(web3.eth.accounts[0]) 29 | }).then(function(instance){ 30 | balance = instance.toNumber(); 31 | }).then(function(){ 32 | console.log(`tokens owned by coinbase: ${balance}`) 33 | }).then(function(){ 34 | var i; 35 | for (i = 0; i < 101; i++) { 36 | buyable._mint(web3.eth.accounts[0],i) 37 | console.log(`minted token ${i}`) 38 | } 39 | }).then(function(){ 40 | return buyable.balanceOf(web3.eth.accounts[0]) 41 | }).then(function(instance){ 42 | balance = instance.toNumber(); 43 | }).then(function(){ 44 | console.log(`tokens owned by coinbase: ${balance}\n...minting finished`) 45 | }).then(function(instance){ 46 | return buyable.getRole(web3.eth.accounts[0],{from:web3.eth.accounts[0]}) 47 | }).then(function(instance){ 48 | console.log(`\nROLE of coinbase: ${instance.toNumber()} (ADMIN) `) 49 | }).then(function(){ 50 | buyable.setRole(1,web3.eth.accounts[5]) 51 | console.log("ROLE of web.eth.accounts[5]: 1 (ORACLE)") 52 | }).then(function(){ 53 | buyable.initialisation(infrastructure.address) 54 | console.log("Initialised state variables of BUYABLE CONTRACT for INFRASTRUCTURE POOL") 55 | }).then(function(){ 56 | process.exit() 57 | }).catch(function(error) { 58 | console.log(error); 59 | }); 60 | -------------------------------------------------------------------------------- /Flowertokens/truffle-config.js: -------------------------------------------------------------------------------- 1 | var HDWalletProvider = require("truffle-hdwallet-provider"); 2 | const dotenv = require('dotenv') 3 | require('dotenv').config() 4 | 5 | var mnemonic = process.env.MNEMONIC; 6 | var infura = process.env.INFURA; 7 | 8 | module.exports = { 9 | networks: { 10 | development: { 11 | host: "localhost", 12 | port: 8545, 13 | network_id: "*" // Match any network id 14 | }, 15 | ropsten: { 16 | provider: function() { 17 | return new HDWalletProvider(mnemonic, `https://ropsten.infura.io/${infura}`) 18 | }, 19 | network_id: 3, 20 | gas: 4000000 21 | }, 22 | mainnet: { 23 | provider: function() { 24 | return new HDWalletProvider(mnemonic, `https://mainnet.infura.io${infura}`) 25 | }, 26 | network_id: 1, 27 | gas: 5000000 28 | } 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /Flowertokens/truffle.js: -------------------------------------------------------------------------------- 1 | var HDWalletProvider = require("truffle-hdwallet-provider"); 2 | const dotenv = require('dotenv') 3 | require('dotenv').config() 4 | 5 | var mnemonic = process.env.MNEMONIC; 6 | var infura = process.env.INFURA; 7 | 8 | module.exports = { 9 | networks: { 10 | development: { 11 | host: "localhost", 12 | port: 8545, 13 | network_id: "*" // Match any network id 14 | }, 15 | ropsten: { 16 | provider: function() { 17 | return new HDWalletProvider(mnemonic, `https://ropsten.infura.io/${infura}`) 18 | }, 19 | network_id: 3, 20 | gas: 4000000 21 | }, 22 | mainnet: { 23 | provider: function() { 24 | return new HDWalletProvider(mnemonic, `https://mainnet.infura.io${infura}`) 25 | }, 26 | network_id: 1, 27 | gas: 5000000 28 | } 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /Premna Daemon/.soliumignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | contracts/Migrations.sol 3 | -------------------------------------------------------------------------------- /Premna Daemon/.soliumrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solium:recommended", 3 | "plugins": [ 4 | "security" 5 | ], 6 | "rules": { 7 | "quotes": [ 8 | "error", 9 | "double" 10 | ], 11 | "indentation": [ 12 | "error", 13 | 4 14 | ] 15 | } 16 | } -------------------------------------------------------------------------------- /Premna Daemon/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | constructor() public { 8 | owner = msg.sender; 9 | } 10 | 11 | modifier restricted() { 12 | if (msg.sender == owner) _; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) public restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Premna Daemon/contracts/bonsai.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | /** 4 | * @title Bonsai 5 | * @dev The Bonsai contract has an attached adreess which can trigger actions, it also has varios pools 6 | * which can be tipped. This is more or less a wallet for a bot with diffrent pools. 7 | */ 8 | 9 | contract bonsai { 10 | address public trigger; 11 | mapping (string => uint256) poolbalance; 12 | mapping (string => uint256) portion; 13 | mapping (string => address) pooladresses; 14 | 15 | /** 16 | * @dev The constructor sets the original `trigger` of the contract to the sender 17 | * account. 18 | */ 19 | 20 | constructor() public { 21 | trigger = msg.sender; 22 | } 23 | 24 | /** 25 | * @dev checks if value of message corresponding to set portion. 26 | * @param _pool string name of the pool. 27 | */ 28 | 29 | modifier check_value(string pool) { 30 | assert (msg.value == portion[pool]); 31 | _; 32 | } 33 | 34 | /** 35 | * @dev modifier for restricting functions to trigger adress 36 | */ 37 | 38 | modifier restricted() { 39 | assert (msg.sender == trigger); 40 | _; 41 | } 42 | 43 | /** 44 | * @dev set payout adress for a pool. 45 | * @param _pool string name of the pool, _address payout adress for pool 46 | */ 47 | 48 | function set_adreses(string pool, address _address ) public restricted { 49 | pooladresses[pool] = _address; 50 | } 51 | 52 | /** 53 | * @dev set portion for a pool. 54 | * @param _pool string name of the pool, _pool_output input portion 55 | */ 56 | 57 | function set_portion(string pool, uint256 _pool_output) public restricted { 58 | portion[pool] = _pool_output; 59 | } 60 | 61 | /** 62 | * @dev tipping function for tip a specif pool. 63 | * @param _pool string name of the pool 64 | */ 65 | 66 | function tip(string pool) public payable check_value(pool) { 67 | poolbalance[pool] += msg.value; 68 | } 69 | 70 | /** 71 | * @dev function for payout a specific pool. 72 | * @param _pool string name of the pool 73 | */ 74 | 75 | function payout_pool(string pool)public restricted { 76 | if(poolbalance[pool] >= portion[pool]){ 77 | if(!pooladresses[pool].call.gas(99999).value(portion[pool])()){ 78 | revert("transfer to address failed"); 79 | } 80 | poolbalance[pool] = poolbalance[pool] - portion[pool]; 81 | } 82 | } 83 | 84 | function check_pool(string pool) external view returns(uint256){ 85 | return poolbalance[pool]; 86 | } 87 | 88 | function check_adress(string pool) external view returns(address){ 89 | return pooladresses[pool]; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # terra0 🌲 2 | terra0 is a project building a modular, open-source framework for automated ecosystem and natural resources management, community farming initiatives, and natural asset - NFT binding. 3 | 4 | This repository contains the smart contract and python repos for our most recent projects, Flowertokens and Premna Daemon, as well an archive of our initial code prototypes. 5 | 6 | ## Flowertokens 💮
7 | *Flowertokens* was an experimental project centered around the tokenization and verification of natural commodities, and a first attempt at creating a combined crypto-collectible physical asset. 8 | 9 | The project is now in archive mode. 10 | 11 | - [Web interface](https://flowertokens.terra0.org/)
12 | - [Documentation Part 1: Project Overview](https://medium.com/@terra0/everything-you-wanted-to-know-about-flowertokens-but-were-afraid-to-ask-part-1-general-concept-ea50427b718b)
13 | - [Documentation Part 2: Physical Installation](https://medium.com/@terra0/everything-you-wanted-to-know-about-flowertokens-but-were-afraid-to-ask-part-2-physical-12e9fc611b7)
14 | - [Documentation Part 3: Oracles and Natural Asset Verification](https://medium.com/@terra0/everything-you-wanted-to-know-about-flowertokens-but-were-afraid-to-ask-part-3-the-oracle-and-c301091b19d1)
15 | - [Documentation Part 4: Blooming Pool and Infrastructure Pool](https://medium.com/@terra0/everything-you-wanted-to-know-about-flowertokens-but-were-afraid-to-ask-part-4-blooming-and-96e9de024767)
16 | - [Documentation Part 5: Project Archiving](https://medium.com/@terra0/when-bloom-the-end-of-flowertokens-project-archiving-and-the-end-of-trading-47d5bf1d379a) 17 | 18 | ## Premna Daemon 👁️
19 | *Premna Daemon* is an installation for the Proof of Work exhibition at Berlin’s Schinkel Pavillon. The installation consists of an augmented Premna Microphylla plant, a web interface, and an Ethereum smart contract. The software and hardware system(s) the tree is embedded within - a set of technological prostheses the plant is augmented with - allow for the creation of a financially-mediated social contract to come into being between the operators of the the Proof of Work exhibition and this hybrid entity. The operators have committed to care for the various needs of the Premna Daemon (watering, lighting, leaf trimming, etc) only when Premna itself requests assistance by sending Ethereum to a wallet owned by the gallery. The Eth used for these requests is donated to Premna by users via the web interface. 20 | 21 | The installation will run until December 21st, 2018. 22 | 23 | - [Web interface](https://premna.terra0.org/)
24 | - [Documentation](https://medium.com/@terra0/premna-daemon-an-introduction-via-a-history-of-autonomy-in-the-cryptosphere-3cee15e92fe2)
25 | 26 | ## Archive 📒
27 | These contracts make up some of the abstract, early sketches of the sort of logic that a DAO-managed ecosystem would have to contain. 28 | 29 | ## Community Links
30 | - [terra0.org](https://terra0.org/) 31 | - [Twitter](https://twitter.com/_terra0) 32 | - [Medium](https://medium.com/@terra0) 33 | - [Slack](https://terra0.slack.com/home) 34 | 35 | 36 | If you'd like to join the Slack channel (or reach out for any other reason), get in touch with us at info@terra0.org. -------------------------------------------------------------------------------- /README.md.orig: -------------------------------------------------------------------------------- 1 | # terra0 🌲🌳🌿 2 | terra0 is a collection of decentralized programs / smartcontracts for environmental management and tokenizing of natural resources. The inital contracts where written as a prototype. Everything in this repo is therefore highly experimental software and should not be used in production. 3 | 4 | For more infos see terra0.org 5 | or talk to us in our slack: 6 | http://slack.terra0.org/ 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "lockfileVersion": 1 3 | } 4 | --------------------------------------------------------------------------------