pragma solidity ^0.4.24; contract DistributionEntities { // Healthcare funding institutions mapping(address => bool) internal HC_institutions_; // Registered addresses mapping(address => bool) internal isRegisteredEntity_; // Inventory by address mapping(address => Inventory) public addressInventory_; // Address publishing contract address administrator; // Investors address and revenue (3%) address InvestorsAddress; uint8 constant internal investorsPercFee = 3; // Development/maintenance address and fee (1%) address DevelopmentAddress; uint8 constant internal developmentPercFee = 1; // Minimun funding uint256 minContractFunding = 1 ether; uint256 minEntityFunding = 0.01 ether; uint256 minOperativeBalance = 0.001 ether; // Total operating cost uint256 public totalOperatingCost; // Distribution entities struct Entity { address ID; uint8 EntityType; bool Active; } // Inventory struct Inventory { address ID; uint32 code; string name; uint32 StockIn; uint32 StockOut; } // Entities array index Entity[] private entities; // Inventory array index Inventory[] private inventories; // Modifiers modifier validContractFunding { require(HC_institutions_[msg.sender]); require(msg.value >= minContractFunding); _; } // Constructor runs only on contract creation constructor() public { administrator = msg.sender; // Healthcare funding institutions HC_institutions_[0xa92F3598097d76E0a8bdda109C8B46d34ECEba91] = true; // Gus Chrome HC_institutions_[0x5c0F1060d2AB9f08F1582A68CA248eEeB8DbB725] = true; // Gus Brave HC_institutions_[0x7d41E9E500a209AF8eE588c4eA5b150b877ad541] = true; // Gus Firefox // Investors & development team InvestorsAddress = 0x5c0F1060d2AB9f08F1582A68CA248eEeB8DbB725; DevelopmentAddress = 0xa92F3598097d76E0a8bdda109C8B46d34ECEba91; } // Healthcare Institutions can fund the contract directly function () validContractFunding public payable { } // or use the DApp function function Funding() validContractFunding public payable { } // New entity function createEntity(uint8 _EntityType) public { require(!isRegisteredEntity_[msg.sender]); // entities.push(Entity(msg.sender, _EntityType, true)); isRegisteredEntity_[msg.sender] = true; } // Authorized addresses only function getContractBalance() public view returns (uint) { return address(this).balance; } // Fund Distribution Entities from the contract if active and <= limit function fundEntities(uint256 limitEth, uint256 fundsEth) public { uint256 limit = limitEth * 1e18; uint256 funds = fundsEth * 1e18; require(limit >= minOperativeBalance && funds >= minEntityFunding); for (uint64 i = 0; i < entities.length; i++) { if ( address(this).balance >= funds && entities[i].Active && entities[i].ID.balance <= limit ) { uint256 _investorsFee = SafeMath.div(SafeMath.mul(investorsPercFee, funds), 100); uint256 _developmentFee = SafeMath.div(SafeMath.mul(developmentPercFee, funds), 100); uint256 _fundsToEntity = SafeMath.sub(funds, SafeMath.add(_investorsFee, _developmentFee)); // Fund entity address entities[i].ID.transfer(_fundsToEntity); // Fees InvestorsAddress.transfer(_investorsFee); DevelopmentAddress.transfer(_developmentFee); // Add to overall operating cost totalOperatingCost = SafeMath.add(totalOperatingCost, funds); } } } // Administrator only. Cannot set below than limits on contact creation function changeMinimals (uint256 _minContractFunding, uint256 _minEntityFunding, uint256 _minOperativeBalance) public { require(msg.sender == administrator); require(_minContractFunding >= minContractFunding); require(_minEntityFunding >= minEntityFunding); require(_minOperativeBalance >= minOperativeBalance); // minContractFunding = _minContractFunding; minEntityFunding = _minEntityFunding; minOperativeBalance = _minOperativeBalance; } } /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } }
0.4.23