Example #1
0
 def test_reward_transactions(self):
     miner_wallet = Wallet(self.test_password,
                           self.test_private_key_pem,
                           self.test_public_key_pem,
                           balance=TEST_WALLET_BALANCE)
     transaction1 = Transaction.create_reward_transaction(1, miner_wallet)
     self.assertEqual(transaction1.outputs[0].address,
                      miner_wallet.public_key_hex)
     self.assertEqual(transaction1.outputs[0].amount, MINING_REWARD)
     self.assertEqual(transaction1.input.address,
                      REWARD_TRANSACTION_ADDRESS)
     self.assertEqual(transaction1.input.signature,
                      REWARD_TRANSACTION_SIGNATURE)
Example #2
0
 def mine(self):
     # 1. Add reward for the miner
     # 2. Create/mine block from valid transactions
     # 3. Sync the chain with other p2p servers (TODO: add after finishing proof of concept)
     # 4. Clear the local pool
     # 5. Broadcast that pool is clear to other nodes via p2p
     height = len(self.block_chain.chain) + 1
     valid_transactions = self.transaction_pool.get_valid_transactions()
     reward_transaction = Transaction.create_reward_transaction(height, self.wallet)
     valid_transactions.append(reward_transaction)
     block = self.block_chain.append_block(valid_transactions)
     # TODO: Broadcast Sync Chain action across p2p nodes
     self.transaction_pool.clear()
     # TODO: Broadcast Clear Transaction Pool action across p2p nodes
     return block