import json,requests
from rpc import call
NR="https://bsc-mainnet.nodereal.io/v1/64a9df0874fb4a93b9d0a3849de012d3"
TRE="0x7c34e9e21ee28a49ff0b84b61774119e6633359f"
d=json.load(open('day.json'))
def nr(p): return requests.post(NR,json={"jsonrpc":"2.0","id":1,"method":"nr_getAssetTransfers","params":[p]},timeout=60).json()['result']['transfers']
out={}
for cat in ["external","20"]:
    t=nr({"category":[cat],"fromAddress":TRE,"fromBlock":hex(d['first']),"toBlock":hex(d['last']),"order":"asc","maxCount":"0x64"})
    out[cat]=t
    for x in t: print(cat,int(x['blockNum'],16),x['hash'],x.get('to'),x.get('contractAddress'),int(x['value'],16)/1e18 if x.get('value') else None)
L={l['transactionHash'] for l in json.load(open('logs.json'))}
# find extra: scan treasury txs by nonce via external+erc20 lists
z=nr({"category":["external"],"fromAddress":"0x689c2b8a0812bb76dae3bf3ba148111480f96f6f","order":"asc","maxCount":"0x14"})
print('689c n=',int(call("eth_getTransactionCount",["0x689c2b8a0812bb76dae3bf3ba148111480f96f6f","latest"],[NR]),16),'code',call("eth_getCode",["0x689c2b8a0812bb76dae3bf3ba148111480f96f6f","latest"],[NR])[:20])
for x in z[:8]: 
    tx=call("eth_getTransactionByHash",[x['hash']]); print(int(x['blockNum'],16),x['to'],int(x['value'],16),tx['input'][:74])
json.dump(out,open('tre_out.json','w'),indent=1)
