Skip to content

Instantly share code, notes, and snippets.

@joeharrison714
Created March 15, 2023 18:24
Show Gist options
  • Save joeharrison714/b4cf1c1497f80e59a25fb5c2a11c4bf3 to your computer and use it in GitHub Desktop.
Save joeharrison714/b4cf1c1497f80e59a25fb5c2a11c4bf3 to your computer and use it in GitHub Desktop.
SETTLEMENT_ADDRESS = 'bae24162efbd568f89bc7a340798a6118df0189eb9e3f8697bcea27af99f8f79'
async def read_spends(header_hash, node_client):
coin_spends = await node_client.get_block_spends(header_hash)
settlement_spends = []
for coin_spend in coin_spends:
if coin_spend.coin.puzzle_hash.hex() == SETTLEMENT_ADDRESS:
settlement_spend = {
"coin_name": coin_spend.coin.name().hex(),
"puzzle_annoucments": []
}
puzzle: Program = coin_spend.puzzle_reveal.to_program()
solution: Program = coin_spend.solution.to_program()
result: Program = puzzle.run(solution)
conditions = result.as_iter()
for condition in conditions:
if condition.first() == 62:
announcement_data = bytes.fromhex(disassemble(condition.rest().first())[2:])
announcement_id = sha256(coin_spend.coin.puzzle_hash + announcement_data)
#print(f'Announcement Id: {ann_id.hexdigest()}')
settlement_spend["puzzle_annoucments"].append(announcement_id.hexdigest())
settlement_spends.append(settlement_spend)
pprint(settlement_spends)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment