コード例 #1
0
    def convert_a_single_block_to_dict(self, block):

        json_block = block.to_json()
        json_block[
            'transactions'] = Transaction.convert_all_transaction_block_to_ordered_dict(
                json_block['transactions'])
        return json_block
コード例 #2
0
    def add_transaction(self, recipient, sender, signature, amount=1.0):
        """ Append a new value as well as the last blockchain value to the blockchain.

        Arguments:
            :sender: The sender of the coins.
            :recipient: The recipient of the coins.
            :amount: The amount of coins sent with the transaction (default = 1.0)
        """

        if self._is_hosting_node_none():
            return False

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

        if Verification.verify_transaction(transaction, self.get_balance):

            signature = Wallet.verify_signature(transaction)

            if signature:
                self._open_transactions.append(transaction)
                self.save_data()
                return True
            return False

        self._delete_invalid_transaction_block()
        return False
コード例 #3
0
    def get_balance(self):
        """Calculate and return the balance for a participant."""

        if self.hosting_node is None:
            return None
        return Transaction.get_balance(self.hosting_node, self.chain,
                                       self._open_transactions)
コード例 #4
0
ファイル: environment.py プロジェクト: pitchup/spreedly-py
    def redact_payment_method(self, payment_method_token, options=None):
        options = options or {}

        body = self.redact_payment_method_body(options)
        xml_doc = ssl_requester.ssl_put(
            urls.redact_payment_method_url(payment_method_token), body,
            self.headers)
        return Transaction.from_xml(xml_doc)
コード例 #5
0
    def createTrans(self, sequance_number, signature, fromUser, toUser, transaction_fee, data, amount, transaction_time, transaction_sender=None):

      # Printing the info of tx
      dprint("\nCreating the transaction")
      dprint("***")
      dprint(sequance_number)
      dprint(signature)
      dprint(fromUser)
      dprint(toUser)
      dprint(data)
      dprint(amount)
      dprint("***\n")
      # End

      # Some data
      signature_class = Signature.fromBase64(signature)
      temp_signature = signature_class.toBase64()

      already_got = self.tx_already_got(temp_signature)
      # End

      # Validation
      dprint("\nValidation")
      if Ecdsa.verify((str(sequance_number)+str(fromUser)+str(toUser)+str(data)+str(amount)+str(transaction_fee)+str(transaction_time)), signature_class, PublicKey.fromPem(fromUser)) and not amount < self.minumum_transfer_amount and not transaction_fee < self.transaction_fee and not already_got and not (int(time.time()) - transaction_time) > 60:
        dprint("Signature is valid")

        dprint("Getsequancenumber: "+str(GetSequanceNumber(fromUser, self)+1))
        if sequance_number == (GetSequanceNumber(fromUser, self)+1):
          dprint("Sequance number is valid")

          balance = GetBalance(fromUser, self)

          if balance >= (float(amount)+float(transaction_fee)) and (balance - (float(amount)+float(transaction_fee))) > 2:
            dprint("Amount is valid")

            # Local saving
            the_tx = Transaction(
                sequance_number= sequance_number,
                signature=temp_signature,
                fromUser= fromUser,
                toUser=toUser,
                data = data,
                amount = amount,
                transaction_fee= transaction_fee,
                time_of_transaction = transaction_time
            )
            self.pendingTransaction.append(the_tx)
            self.change_transaction_fee()
            self.save_block()
            # End

            self.propagating_the_tx(the_tx)

            return True

      dprint(" Validation end")
コード例 #6
0
    def convert_entire_block_chain_to_dict(self):
        """"""

        chains_snapshot = [chain.to_json() for chain in self.chain]

        for chain in chains_snapshot:
            chain[
                'transactions'] = Transaction.convert_all_transaction_block_to_ordered_dict(
                    chain['transactions'])
        return chains_snapshot
コード例 #7
0
 def _update_current_open_transactions(self, open_transactions):
     """"""
     # We need to convert  the loaded data because Transactions should use OrderedDict
     updated_transactions = []
     for trans in open_transactions:
         updated_transaction = Transaction(trans['sender'],
                                           trans['recipient'],
                                           trans['signature'],
                                           trans['amount'])
         updated_transactions.append(updated_transaction)
     self._open_transactions = updated_transactions
コード例 #8
0
    def _update_current_block_chain(self, blockchain):
        """"""
        updated_blockchain = []

        for block in blockchain:
            trans_block = [
                Transaction(trans['sender'], trans['recipient'],
                            trans['signature'], trans['amount'])
                for trans in block['transactions']
            ]
            block = Block(block['index'], block['previous_hash'], trans_block,
                          block['proof'], block['timestamp'])
            updated_blockchain.append(block)

        self.chain = updated_blockchain
コード例 #9
0
    def get_candidate_block(self, data, node):

        dprint("Getting the candidate block")
        from node.unl import node_is_unl
        if node_is_unl(node.id) and GetBlock(
        ).sequance_number == data["sequance_number"]:
            dprint("is unl")

            signature_list = []
            for element in data["transaction"]:
                signature_list.append(element["signature"])

            dprint("signature_list: " + str(signature_list))

            merkle_root_of_signature_list = MerkleTree(
                signature_list).getRootHash(
                ) if len(signature_list) != 0 else "0"

            dprint("signatureverify: " + str(
                Ecdsa.verify("myblock" + merkle_root_of_signature_list,
                             Signature.fromBase64(data["signature"]),
                             PublicKey.fromPem(node.id))))
            dprint("publickey from pem: " + str(node.id))

            dprint("merkleroot: " + merkle_root_of_signature_list)

            if Ecdsa.verify(
                    "myblock" + merkle_root_of_signature_list +
                    str(data["sequance_number"]),
                    Signature.fromBase64(data["signature"]),
                    PublicKey.fromPem(node.id)):
                dprint("ecdsa true")

                temp_tx = []

                for element in data["transaction"]:
                    temp_tx.append(Transaction.load_json(element))

                data["transaction"] = temp_tx

                node.candidate_block = data
コード例 #10
0
ファイル: environment.py プロジェクト: pitchup/spreedly-py
 def find_transaction(self, transaction_token):
     xml_doc = ssl_requester.ssl_get(
         urls.find_transaction_url(transaction_token), self.headers)
     return Transaction.from_xml(xml_doc)
コード例 #11
0
ファイル: environment.py プロジェクト: pitchup/spreedly-py
 def api_post(self, url, body, talking_to_gateway=True):
     xml_doc = ssl_requester.ssl_post(url, body, self.headers,
                                      talking_to_gateway)
     return Transaction.from_xml(xml_doc)
コード例 #12
0
ファイル: environment.py プロジェクト: pitchup/spreedly-py
    def redact_gateway(self, gateway_token, options=None):
        options = options or {}

        xml_doc = ssl_requester.ssl_put(urls.redact_gateway_url(gateway_token),
                                        '', self.headers)
        return Transaction.from_xml(xml_doc)
コード例 #13
0
ファイル: environment.py プロジェクト: pitchup/spreedly-py
    def redact_payment_method(self, payment_method_token, options=None):
        options = options or {}

        body = self.redact_payment_method_body(options)
        xml_doc = ssl_requester.ssl_put(urls.redact_payment_method_url(payment_method_token), body, self.headers)
        return Transaction.from_xml(xml_doc)
コード例 #14
0
ファイル: environment.py プロジェクト: pitchup/spreedly-py
 def find_transaction(self, transaction_token):
     xml_doc = ssl_requester.ssl_get(urls.find_transaction_url(transaction_token), self.headers)
     return Transaction.from_xml(xml_doc)
コード例 #15
0
ファイル: environment.py プロジェクト: pitchup/spreedly-py
 def api_post(self, url, body, talking_to_gateway=True):
     xml_doc = ssl_requester.ssl_post(url, body, self.headers, talking_to_gateway)
     return Transaction.from_xml(xml_doc)
コード例 #16
0
ファイル: environment.py プロジェクト: pitchup/spreedly-py
    def redact_gateway(self, gateway_token, options=None):
        options = options or {}

        xml_doc = ssl_requester.ssl_put(urls.redact_gateway_url(gateway_token), "", self.headers)
        return Transaction.from_xml(xml_doc)
コード例 #17
0
 def get_open_transactions(self):
     return Transaction.convert_all_transaction_block_to_ordered_dict(
         self._open_transactions)
コード例 #18
0
ファイル: block.py プロジェクト: EgbieAndersonUku1/BlockChain
 def hash_block(block):
     """"""
     hashed_block = block.to_json()
     hashed_block['transactions'] = Transaction.convert_all_transaction_block_to_ordered_dict(hashed_block['transactions'])
     return HashImplementer.hash_string_using_sha256(Converter.to_string(hashed_block))
コード例 #19
0
    def get_reward(hosting_node_id):

        MINING_REWARD = 10
        OWNER = ""

        return Transaction("MINING", hosting_node_id, MINING_REWARD)
コード例 #20
0
    def get_mine_reward(cls, host_name):

        return Transaction("MINING", host_name, amount=cls.MINING_REWARD)