1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2024-11-12 02:49:26 +00:00
bitcoinbook/code/rpc_block.py
David A. Harding 5b1a5bff0a CH03-04: edits for Murchandamus feedback
- Mention the reason for the long validation time is the verification of
  transactions.  We previously implied it was download time, but some
  people have really fast internet.

- Better describe bitcoind cookie authentication and provide an example
  to make it even more clear.

- Add a link to bitcoin-s

- Make the long sidebar on collision attacks even longer by descripting
  a pre-image attack in addition to the previous descriptions of second
  pre-image and collision.  That way we don't conflate pre-image and
  second pre-image.

- Remove redundant tip box about an oddity in language about compressed
  and uncompressed private keys.

- Link to information about vanity address "mining" (brute forcing)
2023-08-01 07:13:47 -10:00

35 lines
972 B
Python

from bitcoin.rpc import RawProxy
p = RawProxy()
# The block height where Alice's transaction was recorded
blockheight = 775072
# Get the block hash of the block at the given height
blockhash = p.getblockhash(blockheight)
# Retrieve the block by its hash
block = p.getblock(blockhash)
# Element tx contains the list of all transaction IDs in the block
transactions = block['tx']
block_value = 0
# Iterate through each transaction ID in the block
for txid in transactions:
tx_value = 0
# Retrieve the raw transaction by ID
raw_tx = p.getrawtransaction(txid)
# Decode the transaction
decoded_tx = p.decoderawtransaction(raw_tx)
# Iterate through each output in the transaction
for output in decoded_tx['vout']:
# Add up the value of each output
tx_value = tx_value + output['value']
# Add the value of this transaction to the total
block_value = block_value + tx_value
print("Total value in block: ", block_value)