コード例 #1
0
    def add_transaction(self, recipient, amount=1.0, sender=None, signature='', is_receiving=False):
        """ Appends a new value as well as the last blockchain to the blockchain.
            :argument sender The sender of the coins.
            :argument recipient The recipient of the coins.
            :argument amount The amount of coins (default[1])
        """
        if self.hosting_node is None:
            return False

        transaction = Transaction(sender, recipient, amount, signature)

        if not Wallet.verify_transaction(transaction):
            return False

        if Verification.verify_transaction(transaction, self.get_balance):
            self.__open_transactions.append(transaction)
            self.save_data()
            if not is_receiving:
                for node in self.__peer_nodes:
                    url = 'http://{}/broadcast'.format(node)
                    try:
                        response = requests.post(url, json={'sender': sender, 'recipient': recipient, 'amount': amount,
                                                            'signature': signature})
                        if response.status_code == 400 or response.status_code == 500:
                            print('Transaction declined!')
                            return False
                    except requests.exceptions.ConnectionError:
                        continue
            return True
        return False
コード例 #2
0
    def add_transaction(self,
                        recipient: str,
                        sender: str,
                        signature: str,
                        amount: float = 1.0,
                        is_receiving=False) -> bool:
        if self.public_key is None:
            return False

        transaction = Transaction(sender, recipient, signature, amount)

        if Verification.verify_transaction(transaction, self.get_balance):
            self.__open_transactions.append(transaction)
            self.save_data()
            if not is_receiving:
                for node in self.__peer_nodes:
                    url = 'http://{}/broadcast-transaction'.format(node)
                    try:
                        response = requests.post(url,
                                                 json={
                                                     'sender': sender,
                                                     'recipient': recipient,
                                                     'amount': amount,
                                                     'signature': signature
                                                 })
                        if response.status_code == 400 or response.status_code == 500:
                            print('Transaction declined, needs resolving')
                            return False
                    except requests.exceptions.ConnectionError:
                        continue
            return True
        return False
コード例 #3
0
    def add_value(self, signature, sender, recipient, amount=1.0):
        """ appends a new value to the open transaction list.
        Arguments:
        :sender: The sender of the transaction.
        :recipient: Receiver of the transaction.
        :amount: The amount of the transaction.
        """
        # transaction = {
        #     "sender": sender,
        #     "recipient": recipient,
        #     "amount": amount
        # }
        if self.hosting_node == None:
            return False
        transaction = Transaction(signature, sender, recipient, amount)

        if not Wallet.verify_signature(transaction):
            return False

        if Verification.verify_transaction(transaction, self.get_balance):
            self.__open_transactions.append(transaction)
            self.save_data()
            return True

        print("insufficient funds")
        return False
コード例 #4
0
 def add_transaction(self,
                     recipient,
                     sender,
                     signature,
                     amount=1.0,
                     is_receiving=False):
     # if self.public_key == None:
     #     return False
     # Create transaction class object
     transaction = Transaction(sender, recipient, signature, amount)
     if Verification.verify_transaction(transaction, self.get_balance):
         self.__open_transactions.append(transaction)
         self.save_data()
         # send to all nodes the transaction added if there is not the direct receiving node
         if not is_receiving:
             for node in self.__peer_nodes:
                 url = 'http://{}/broadcast-transaction'.format(node)
                 try:
                     response = requests.post(url,
                                              json={
                                                  'sender': sender,
                                                  'recipient': recipient,
                                                  'amount': amount,
                                                  'signature': signature
                                              })
                     if response.status_code == 400 or response.status_code == 500:
                         print('Transaction declined, needs resolving')
                         return False
                 except requests.exceptions.ConnectionError:
                     continue
         return True
     return False
コード例 #5
0
 def add_transaction(self, recipient, sender, signature, amount=1.0):
     if self.public_key is None:
         return False
     transaction = Transaction(sender, recipient, signature, amount)
     if Verification.verify_transaction(transaction, self.get_balance):
         self.__open_transactions.append(transaction)
         self.save_data()
         return True
     return False
コード例 #6
0
    def add_transaction(self, recipient, sender, signature, amount=1.0):
        """ Adding value to the blockchain
        
            Arguments:
                :sender: The sender of the coins.
                :recipient: The recipient of the coins.
                :amount: The amount of coins sent. Default 1.0.
        
        """

        transaction = Transaction(sender, recipient, signature, amount)

        if Verification.verify_transaction(transaction, self.get_balance):
            self.__open_transactions.append(transaction)
            self.save_data()

            return True

        return False
コード例 #7
0
    def add_transaction(self,
                        recipient,
                        sender,
                        signature,
                        amount=1.0,
                        is_receiving=False):
        """ Append a new value as well as the last blockchain value to the blockchain.

        Arguments:
            :sender: Tecihe sender of the coins.
            :rpient: The recipient of the coins.
            :amount: The amount of coins sent with the transaction (default = 1.0)
        """
        # transaction = {
        #     'sender': sender,
        #     'recipient': recipient,
        #     'amount': amount
        # }
        # if self.public_key == None:
        #     return False
        transaction = Transaction(sender, recipient, signature, amount)
        if Verification.verify_transaction(transaction, self.get_balance):
            self.__open_transactions.append(transaction)
            self.save_data()
            if not is_receiving:
                for node in self.__peer_nodes:
                    url = 'http://{}/broadcast-transaction'.format(node)
                    try:
                        response = requests.post(url,
                                                 json={
                                                     'sender': sender,
                                                     'recipient': recipient,
                                                     'amount': amount,
                                                     'signature': signature
                                                 })
                        if response.status_code == 400 or response.status_code == 500:
                            print('Transaction declined, needs resolving')
                            return False
                    except requests.exceptions.ConnectionError:
                        continue
            return True
        return False
コード例 #8
0
ファイル: blockchain.py プロジェクト: nroshni/block-chain
    def add_transaction(self, recipient, sender, signature, amount=1.0):
        """
        Adds a new transaction (if valid) to the list of open transactions.

        Parameters
        ----------
            sender (String): The sender of the coins
            recipient (String): The recipient of the coins
            amount (float): The amount of coins sent in the transaction
                            (default = 1.0)
        """
        if self.hosting_node is None:
            return False

        transaction = Transaction(sender, recipient, signature, amount)

        if Verification.verify_transaction(transaction, self.get_balances):
            logger.info(
                'Valid transaction. Adding to list of open transactions.')
            self.__open_transactions.append(transaction)
            self.save_data()
            return True
        return False