"""Research-only records. Never routed to either trading engine.""" import json import fcntl from pathlib import Path ROOT=Path(__file__).resolve().parent SEED=ROOT/'watchlist.json' DATA=ROOT/'data' SAVED=DATA/'research-watchlist.json' ALPHABET='123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' def read(): return json.loads((SAVED if SAVED.exists() else SEED).read_text()) def valid_mint(value): if not isinstance(value,str) or not 32<=len(value)<=44 or any(c not in ALPHABET for c in value): return False n=0 for c in value:n=n*58+ALPHABET.index(c) leading=len(value)-len(value.lstrip('1')) length=leading+((n.bit_length()+7)//8 if n else 0) return length==32 def update_mint(item_id,mint): if not isinstance(item_id,str) or not isinstance(mint,str):raise ValueError('ID and mint must be text.') mint=mint.strip() if mint and not valid_mint(mint):raise ValueError('Enter a Solana address encoding exactly 32 bytes, or leave blank.') DATA.mkdir(parents=True,exist_ok=True) with (DATA/'watchlist.lock').open('a') as lock: fcntl.flock(lock,fcntl.LOCK_EX) data=read() item=next((x for x in data['items'] if x['id']==item_id),None) if not item or item['kind']!='token':raise ValueError('Unknown research token.') item['mint']=mint item['status']='mint_supplied_not_verified' if mint else 'identity_unconfirmed' temp=SAVED.with_suffix('.tmp') temp.write_text(json.dumps(data,indent=2)+'\n');temp.replace(SAVED) return data