The coins module

class coins.Block(hash_prev, transactions, nonce, difficulty)
A block of transactions is:
  • transactions: a list of (transactions,signatures)
  • hash_prev: the hash of the previous block
  • nonce: the nonce
  • difficulty: the current difficulty
check_nonce()

Check nonce

The difficulty is how many zeros the (hexadecimal) hash() starts with

hash()

hexadecimal hash for this block

class coins.PrivateKey(N, e, d, name='')

A private key with modulo N, encryption exponent e and decryption exponent d, and a human readable name

pubkey()

Return only the public key part

class coins.PublicKey(N, e, name='')

A public key with modulo N and encrypting exponent e, and a human readable name.

class coins.Transaction(inputs, outputs, note='')
A transaction is
  • inputs: list of transaction inputs TxIn
  • outputs: list of transaction outputs TxOut
  • note: a description of the transaction str
hash()

a hexadecimal hash of the transaction

class coins.TxIn(pubkey=None, hash_prev='0', output_num=0)
A transaction input is
  • pubkey: public key of the party sending funds
  • hash_prev: hash of previous transaction
  • output_num: the output number in previous transaction
class coins.TxOut(pubkey, amount)
A transaction output is
  • pubkey: public key of party receiving funds
  • amount: how much funds to transfer
coins.tx_send_funds(wallet, origin, destination, amount, note)

makes a suitable transaction to go from origin to destination

coins.tx_sig(tx, privkey)

Sign a transaction

Note: all the input transactions are assumed to be from the same public key, so we just sign using one private key which is assumed to be that of the only owner of all inputs In bitcoin transactions, there is a “script” describing which keys to use to verify that the transaction is legit