TimeCoin – Source Code (Forkable) Overview Language: Python (readable, extensible). Modules: Separate classes for blockchain, users, treasury, PoH, PoT, and PoWfH. Extensibility: Comments indicate where to add new features. Requirements Python 3.x. Libraries: hashlib (built-in), time, random. import hashlib import time import random from typing import List, Dict # Constants TOTAL_SUPPLY = 21_000_000 # 21 million TimeCoins TEMPUS_PER_TIMECOIN = 100_000_000 # 1 TimeCoin = 100 million tempus BLOCK_TIME = 10 * 60 # 10 minutes in seconds (simulation) INITIAL_REWARD = 10 # 10 TimeCoins per block TREASURY_INITIAL_YEARS = 4 # 4 years of initial treasury contribution TREASURY_RATE_INITIAL = 2 # 2 TimeCoins/block to treasury TREASURY_RATE_LONG = 0.01 # 1% of rewards for 15 years HALVING_INTERVAL = 1 # Halving every year (52,560 blocks) BOOST_INTERVAL = 24 # Boost every 24 years BOOST_FACTOR = 1.5 # +50% reward class Block: def __init__(self, index: int, previous_hash: str, timestamp: float, transactions: List[Dict], reward: float): self.index = index self.previous_hash = previous_hash self.timestamp = timestamp self.transactions = transactions self.reward = reward # In TimeCoins self.hash = self.calculate_hash() def calculate_hash(self) -> str: value = f"{self.index}{self.previous_hash}{self.timestamp}{self.transactions}{self.reward}" return hashlib.sha256(value.encode()).hexdigest() class User: def __init__(self, public_key: str): self.public_key = public_key self.humanity_token = self.generate_humanity_token() self.active_time = 0 # Hours of activity self.balance = 0 # In TimeCoins self.loyalty_multiplier = 1.0 self.robot_token = None def generate_humanity_token(self) -> str: # Simulation of ZKP - in practice, use zk-SNARKs return hashlib.sha256(f"{self.public_key}{random.randint(0, 1000000)}".encode()).hexdigest() def invite(self, new_user: 'User', deposit: float = 0.1) -> bool: if self.balance >= deposit and self.active_time >= 8760: # 1 year = 8760 hours self.balance -= deposit new_user.humanity_token = self.generate_humanity_token() return True return False def register_robot(self, deposit: float = 0.01) -> bool: if self.balance >= deposit and not self.robot_token: self.robot_token = hashlib.sha256(f"{self.public_key}robot{random.randint(0, 1000)}".encode()).hexdigest() self.balance -= deposit return True return False class Treasury: def __init__(self): self.balance = 0 # In TimeCoins self.locked_until = {} # {year: amount} def add(self, amount: float, year: int): lock_year = year + 10 # Locked for 10 years self.locked_until[lock_year] = self.locked_until.get(lock_year, 0) + amount self.balance += amount def release(self, year: int, amount: float) -> float: available = self.locked_until.get(year, 0) if available >= amount and amount <= self.balance * 0.05: # Max 5% per year self.balance -= amount self.locked_until[year] -= amount return amount return 0 class TimeCoinBlockchain: def __init__(self): self.chain: List[Block] = [self.create_genesis_block()] self.users: Dict[str, User] = {} self.treasury = Treasury() self.current_year = 2025 self.blocks_per_year = 52_560 # 10-minute blocks per year def create_genesis_block(self) -> Block: return Block(0, "0", time.time(), [], INITIAL_REWARD) def get_latest_block(self) -> Block: return self.chain[-1] def add_user(self, public_key: str, inviter_key: str = None) -> bool: if public_key not in self.users: user = User(public_key) if inviter_key and inviter_key in self.users: if self.users[inviter_key].invite(user): self.users[public_key] = user return True elif len(self.users) == 0: # First user (genesis) self.users[public_key] = user return True return False def calculate_reward(self, block_index: int) -> float: year = self.current_year + (block_index // self.blocks_per_year) years_passed = year - 2025 halving_count = years_passed // HALVING_INTERVAL reward = INITIAL_REWARD * (0.7937 ** halving_count) # ~20.63% reduction per year # Boost every 24 years if years_passed % BOOST_INTERVAL == 0 and block_index % self.blocks_per_year < self.blocks_per_year: reward = min(reward * BOOST_FACTOR, 2.5) # Max 2.5 TimeCoins # Treasury: 2 TimeCoins for 4 years, then 1% treasury_contribution = 0 if years_passed < TREASURY_INITIAL_YEARS: treasury_contribution = min(TREASURY_RATE_INITIAL, reward * 0.2) if years_passed < 15: treasury_contribution += reward * TREASURY_RATE_LONG return reward - treasury_contribution, treasury_contribution def mine_block(self, miner_key: str, transactions: List[Dict]) -> bool: if miner_key not in self.users: return False miner = self.users[miner_key] block_index = len(self.chain) reward, treasury_contribution = self.calculate_reward(block_index) # Proof-of-Time: Limit 1 TimeCoin/h hours_active = miner.active_time / 3600 max_reward = min(hours_active, 1) * miner.loyalty_multiplier # Max 1 TimeCoin/h miner_reward = min(reward / len(self.users), max_reward) # Shared among users # Simulation of heartbeat and human activity if random.random() < 0.95: # 95% chance of human activity miner.active_time += BLOCK_TIME miner.balance += miner_reward # Update loyalty multiplier years_active = miner.active_time / (8760 * 3600) if years_active >= 20: miner.loyalty_multiplier = 3.0 elif years_active >= 10: miner.loyalty_multiplier = 2.0 # Add to treasury self.treasury.add(treasury_contribution, self.current_year + (block_index // self.blocks_per_year)) new_block = Block(block_index, self.get_latest_block().hash, time.time(), transactions, reward) self.chain.append(new_block) return True return False def robot_work(self, owner_key: str, task_result: str, hours: float) -> float: if owner_key not in self.users or not self.users[owner_key].robot_token: return 0 # Proof-of-Work-for-Humans: Reward for task reward_per_hour = 0.01 # 0.01 TimeCoin/h total_reward = min(reward_per_hour * hours, 0.24) # Max 0.24 TimeCoin/day available = self.treasury.release(self.current_year, total_reward) if available > 0: self.users[owner_key].balance += available return available return 0 def bonus_for_new_users(self): year = self.current_year + (len(self.chain) // self.blocks_per_year) if year % 5 == 0: # Bonus every 5 years bonus = self.treasury.balance * 0.01 # 1% of treasury new_users = [u for u in self.users.values() if u.active_time < 8760 * 3600] if new_users: per_user = bonus / len(new_users) for user in new_users: user.balance += per_user # Simulation if __name__ == "__main__": blockchain = TimeCoinBlockchain() # Add users blockchain.add_user("alice") blockchain.add_user("bob", "alice") # Simulate mining for i in range(5): transactions = [{"from": "alice", "to": "bob", "amount": 0.1}] blockchain.mine_block("alice", transactions) print(f"Block {i+1}: Alice balance = {blockchain.users['alice'].balance:.8f} TimeCoins") # Simulate robot work blockchain.users["alice"].register_robot() reward = blockchain.robot_work("alice", "Cleaned room", 2) print(f"Robot reward: {reward:.8f} TimeCoins") Explanation of the Code Block Class: Represents a block in the blockchain with index, previous hash, timestamp, transactions, and reward. calculate_hash: Simple SHA-256 hash (expandable to more complex PoW if needed). User Class: Manages user data: public key, humanity token (PoH), active time, balance, loyalty multiplier, and robot token. generate_humanity_token: Simulates ZKP (replace with real zk-SNARKs for production). invite: Implements PoH via invitations with a deposit. register_robot: Registers an AI/robot with a deposit. Treasury Class: Handles treasury funds with a 10-year lock and 5% annual withdrawal limit. add: Adds funds with a lock period. release: Releases funds for AI rewards or bonuses. TimeCoinBlockchain Class: Core blockchain logic. add_user: Registers users with PoH (invitation or genesis). calculate_reward: Computes block reward with halving, boost, and treasury contributions. mine_block: Simulates Proof-of-Time mining with a 1 TimeCoin/h limit and loyalty multiplier. robot_work: Implements Proof-of-Work-for-Humans for AI/robots, funded from treasury. bonus_for_new_users: Distributes 1% of treasury every 5 years to new users. How to Expand (Fork) Network Layer: Add P2P networking (e.g., using asyncio or socket) to sync blocks across nodes. Replace random.random() in mine_block with real heartbeat checks. Cryptography: Implement full ZKP (e.g., pyzkp) for generate_humanity_token. Add ECDSA signatures for transactions. Database: Store blockchain in a persistent database (e.g., SQLite or LevelDB) instead of memory. AI/Robot Tasks: Extend robot_work with a task verification system (e.g., proof submission via IPFS). Consensus: Enhance mine_block with a more robust consensus (e.g., random node selection based on active time). UI/CLI: Add a command-line interface or GUI for user interaction. Running the Code Run the script to simulate a basic blockchain with Alice mining blocks and Bob joining via invitation. The robot simulation shows how AI earns small rewards. This is a starting point – a forkable base you can build upon. Let me know if you want to expand specific parts (e.g., networking, full ZKP, or transaction system)!