Beispiel #1
0
    def new_block(self,
                  transaction_sender_id,
                  transaction_recipient_id,
                  amount,
                  proof,
                  prev_hash=None):
        """ Adds a new block to the blockchain.

        :param transaction_sender_id: Id of the user who initiated the transaction.
        :param type: int
        :param transaction_recipient_id: Id of the user who recieved the transaction.
        :param type: int
        :param amount: Amount of money used in transaction
        :param type: int
        :param prev_hash: Hash of the previous transaction
        :param type: String
        :param proof: Proof of work for the transaction.
        :param type: String
        """

        block = Block(timestamp=datetime.now(),
                      transaction_sender_id=transaction_sender_id,
                      transaction_recipient_id=transaction_recipient_id,
                      transaction_amount=amount,
                      proof=proof,
                      previous_hash=prev_hash)
        self.current_transactions = []
        block.create()
Beispiel #2
0
 def save_to_db(self, block_info):
     block = Block.create(number=block_info['number'],
                          blockhash=block_info['hash'],
                          parenthash=block_info['parentHash'],
                          miner=block_info['miner'],
                          logs_bloom=block_info['logsBloom'],
                          timestamp=block_info['timestamp'])
     for item in block_info['transactions']:
         Txn.create()