157 lines
5.9 KiB
Python
Executable File
157 lines
5.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Destroy Smartup Credits - Personal Work Receipt Management
|
|
Allows SC holders to destroy their own SC for system integrity or personal choice
|
|
Version: 0.1 - System integrity correction capability
|
|
"""
|
|
|
|
import argparse
|
|
import csv
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
class SCDestroyer:
|
|
def __init__(self):
|
|
self.base_path = Path(__file__).parent.parent
|
|
|
|
def get_sc_balance(self, owner_alias):
|
|
"""Calculate current SC balance for owner"""
|
|
sc_file = self.base_path / "ledger" / "smartup-credits" / "transactions.csv"
|
|
|
|
balance = 0
|
|
with open(sc_file, 'r') as f:
|
|
reader = csv.DictReader(f)
|
|
for row in reader:
|
|
if not row['timestamp'].startswith('#') and row['timestamp'] != '':
|
|
if row['to'] == owner_alias and row['type'] == 'SC':
|
|
balance += int(row['amount'])
|
|
elif row['from'] == owner_alias and row['type'] in ['REDEEM', 'DESTROY']:
|
|
balance -= int(row['amount'])
|
|
|
|
return balance
|
|
|
|
def validate_destruction(self, owner_alias, amount, destroyer_alias):
|
|
"""Validate destruction request"""
|
|
current_balance = self.get_sc_balance(owner_alias)
|
|
|
|
if amount > current_balance:
|
|
raise ValueError(f"Cannot destroy {amount} SC - {owner_alias} only has {current_balance} SC")
|
|
|
|
# For now, only allow self-destruction (future: democratic validation for large amounts)
|
|
if owner_alias != destroyer_alias:
|
|
raise ValueError(f"Only SC owner can destroy their own SC. {owner_alias} != {destroyer_alias}")
|
|
|
|
return current_balance
|
|
|
|
def create_destroy_transaction(self, owner_alias, amount, reason, destroyer_alias):
|
|
"""Create DESTROY transaction in SC ledger"""
|
|
sc_file = self.base_path / "ledger" / "smartup-credits" / "transactions.csv"
|
|
|
|
destroy_entry = [
|
|
datetime.now().isoformat(),
|
|
'DESTROY',
|
|
amount,
|
|
owner_alias, # from (person losing SC)
|
|
'', # to (nobody gets it)
|
|
'sc-destruction',
|
|
f"SC destroyed: {reason}",
|
|
destroyer_alias,
|
|
'validation',
|
|
'system-integrity'
|
|
]
|
|
|
|
with open(sc_file, 'a', newline='') as f:
|
|
writer = csv.writer(f)
|
|
writer.writerow(destroy_entry)
|
|
|
|
def update_treasury(self, amount_destroyed, reason):
|
|
"""Update treasury to reflect reduced SC liability"""
|
|
treasury_file = self.base_path / "ledger" / "treasury" / "balance.csv"
|
|
|
|
# Get current treasury state
|
|
current_sc_outstanding = 0
|
|
with open(treasury_file, 'r') as f:
|
|
reader = csv.DictReader(f)
|
|
for row in reader:
|
|
if not row['timestamp'].startswith('#') and row['timestamp'] != '':
|
|
current_sc_outstanding = int(row['sc_outstanding'])
|
|
|
|
# Calculate new state
|
|
new_sc_outstanding = current_sc_outstanding - amount_destroyed
|
|
|
|
treasury_entry = [
|
|
datetime.now().isoformat(),
|
|
'SC_DESTROYED',
|
|
0, # no EUR change
|
|
0, # EUR balance unchanged
|
|
new_sc_outstanding,
|
|
new_sc_outstanding, # SC liability = SC outstanding when no treasury
|
|
0.0, # ratio
|
|
f"SC destroyed: {reason}",
|
|
'sc-destruction'
|
|
]
|
|
|
|
with open(treasury_file, 'a', newline='') as f:
|
|
writer = csv.writer(f)
|
|
writer.writerow(treasury_entry)
|
|
|
|
return new_sc_outstanding
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Destroy Smartup Credits for system integrity or personal choice"
|
|
)
|
|
parser.add_argument('--owner', required=True,
|
|
help='SC owner alias (who owns the SC)')
|
|
parser.add_argument('--amount', type=int, required=True,
|
|
help='Amount of SC to destroy')
|
|
parser.add_argument('--reason', required=True,
|
|
help='Reason for destruction (audit trail)')
|
|
parser.add_argument('--destroyer', required=True,
|
|
help='Who is performing the destruction (for validation)')
|
|
|
|
args = parser.parse_args()
|
|
|
|
destroyer = SCDestroyer()
|
|
|
|
try:
|
|
# Validate destruction
|
|
current_balance = destroyer.validate_destruction(args.owner, args.amount, args.destroyer)
|
|
|
|
print(f"🔍 DESTRUCTION VALIDATION")
|
|
print(f"Owner: {args.owner}")
|
|
print(f"Current Balance: {current_balance} SC")
|
|
print(f"Amount to Destroy: {args.amount} SC")
|
|
print(f"Remaining Balance: {current_balance - args.amount} SC")
|
|
print(f"Reason: {args.reason}")
|
|
print()
|
|
|
|
# Confirm destruction
|
|
confirm = input("⚠️ This action cannot be undone. Continue? (yes/no): ")
|
|
if confirm.lower() != 'yes':
|
|
print("❌ Destruction cancelled")
|
|
return
|
|
|
|
# Execute destruction
|
|
destroyer.create_destroy_transaction(args.owner, args.amount, args.reason, args.destroyer)
|
|
new_total = destroyer.update_treasury(args.amount, args.reason)
|
|
|
|
print(f"✅ SC DESTRUCTION COMPLETED")
|
|
print(f"🔥 {args.amount} SC destroyed for {args.owner}")
|
|
print(f"📊 Total SC Outstanding: {new_total} SC")
|
|
print(f"📝 Work trail preserved in session logs")
|
|
print(f"🔗 Audit trail: {args.reason}")
|
|
print()
|
|
print("🔧 Next Steps:")
|
|
print("1. Run generate-reports.py to verify updated balances")
|
|
print("2. Commit changes to preserve audit trail")
|
|
|
|
except ValueError as e:
|
|
print(f"❌ Validation Error: {e}")
|
|
except Exception as e:
|
|
print(f"❌ Unexpected Error: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|