def send_my_response_on_transaction(self, temp_transaction, response, transaction_sender):
     items = {
         "transactionresponse": 1,
         "fromUser": mynode.main_node.id,
         "response": response,
         "transaction_signature": temp_transaction.signature,
         "signature": Ecdsa.sign(
             response+str(temp_transaction.signature),
             PrivateKey.fromPem(Wallet_Import(0, 1))
             ).toBase64()
     }
     mynode.main_node.send_data_to_node(transaction_sender, items)
Exemplo n.º 2
0
    def send_full_blockshash(self, node=None):
        dprint("Sending full chain to node or nodes." + " Node: " + str(node))
        file = open(TEMP_BLOCKSHASH_PATH, "rb")
        SendData = file.read(1024)
        while SendData:

            data = {
                "fullblockshash":
                1,
                "byte": (SendData.decode(encoding='iso-8859-1')),
                "signature":
                Ecdsa.sign(
                    "fullblockshash" + str(
                        (SendData.decode(encoding='iso-8859-1'))),
                    PrivateKey.fromPem(Wallet_Import(0, 1))).toBase64()
            }
            if not node is None:
                self.send_data_to_node(node, data)
            else:
                self.send_data_to_nodes(data)

            SendData = file.read(1024)

            dprint(SendData)

            if not SendData:
                data = {
                    "fullblockshash":
                    1,
                    "byte":
                    "end",
                    "signature":
                    Ecdsa.sign("fullblockshash" + "end",
                               PrivateKey.fromPem(Wallet_Import(
                                   0, 1))).toBase64()
                }
                if not node is None:
                    self.send_data_to_node(node, data)
                else:
                    self.send_data_to_nodes(data)
Exemplo n.º 3
0
def send(my_public_key, my_private_key, to_user, password, data=None, amount=None):
    """
    The main function for sending the transaction.

    Inputs:
      * my_public_key: Sender's public key.
      * my_private_key: Sender's private key.
      * to_user: Receiver's address.
      * data: A text that can be written into the transaction. (Can be None)
      * amount: A int or float amount to be sent. (Can be None)
    """

    my_public_key = "".join(
        [
            l.strip()
            for l in my_public_key.splitlines()
            if l and not l.startswith("-----")
        ]
    )

    system = GetBlock()
    sequance_number = GetSequanceNumber(my_public_key, system) + 1

    # Get the current fee
    transaction_fee = system.transaction_fee

    tx_time = int(time.time())

    the_tx = system.createTrans(
        sequance_number=sequance_number,
        signature=Ecdsa.sign(
            str(sequance_number)
            + str(my_public_key)
            + str(to_user)
            + str(data)
            + str(amount)
            + str(transaction_fee)
            + str(tx_time),
            PrivateKey.fromPem(my_private_key),
        ).toBase64(),
        fromUser=str(my_public_key),
        toUser=str(to_user),
        data=data,
        amount=amount,
        transaction_fee=transaction_fee,
        transaction_sender=None,
        transaction_time=tx_time,
    )

    SavetoMyTransaction(the_tx)
Exemplo n.º 4
0
def send(my_public_key, my_private_key, to_user, data=None, amount=None):
    from ledger.ledger_main import get_ledger
    system = get_ledger()
    sequance_number = (system.getSequanceNumber(my_public_key)) + 1
    transaction_fee = 0.02
    system.createTrans(
        sequance_number=sequance_number,
        signature=Ecdsa.sign(
            str(sequance_number) + str(my_public_key) + str(to_user) +
            str(data) + str(amount) + str(transaction_fee),
            PrivateKey.fromPem(my_private_key)).toBase64(),
        fromUser=str(my_public_key),
        toUser=str(to_user),
        data=str(data),
        amount=amount,
        transaction_fee=transaction_fee)
Exemplo n.º 5
0
 def send_my_response_on_transaction(self, temp_transaction, response,
                                     transaction_sender):
     from node.myownp2pn import MyOwnPeer2PeerNode
     MyOwnPeer2PeerNode.main_node.send_to_node(
         transaction_sender, {
             "transactionresponse":
             1,
             "fromUser":
             MyOwnPeer2PeerNode.main_node.id,
             "response":
             response,
             "transaction_signature":
             temp_transaction.signature,
             "signature":
             Ecdsa.sign(response + str(temp_transaction.signature),
                        PrivateKey.fromPem(Wallet_Import(0, 1))).toBase64()
         })
Exemplo n.º 6
0
    def send_my_block_hash(self, nodes):
        system = GetBlock()

        if system.raund_1 and not system.raund_2:

            data = {
                "action":
                "myblockhash",
                "hash":
                system.hash,
                "sequance_number":
                system.sequance_number,
                "signature":
                Ecdsa.sign(
                    "myblockhash" + system.hash + str(system.sequance_number),
                    PrivateKey.fromPem(Wallet_Import(0, 1))).toBase64()
            }

            for each_node in nodes:
                dprint("Raund 2: second ok of get candidate block hashes: " +
                       str(each_node.__dict__))
                self.send_data_to_node(each_node, data)
Exemplo n.º 7
0
def send(my_public_key, my_private_key, to_user, data=None, amount=None):
    from ledger.ledger_main import get_ledger
    system = get_ledger()
    sequance_number = (system.getSequanceNumber(my_public_key)) + 1
    transaction_fee = 0.02

    my_public_key = "".join([
        l.strip() for l in my_public_key.splitlines()
        if l and not l.startswith("-----")
    ])

    system.createTrans(
        sequance_number=sequance_number,
        signature=Ecdsa.sign(
            str(sequance_number) + str(my_public_key) + str(to_user) +
            str(data) + str(amount) + str(transaction_fee),
            PrivateKey.fromPem(my_private_key)).toBase64(),
        fromUser=str(my_public_key),
        toUser=str(to_user),
        data=data,
        amount=amount,
        transaction_fee=transaction_fee,
        my_tx=True)
Exemplo n.º 8
0
    def send_full_node_list(self, node=None):
        file = open(CONNECTED_NODE_PATH, "rb")
        SendData = file.read(1024)
        while SendData:

            data = {
                "fullnodelist":
                1,
                "byte": (SendData.decode(encoding='iso-8859-1')),
                "signature":
                Ecdsa.sign(
                    "fullnodelist" + str(
                        (SendData.decode(encoding='iso-8859-1'))),
                    PrivateKey.fromPem(Wallet_Import(0, 1))).toBase64()
            }
            print(data)
            print(type(data))
            if not node is None:
                self.send_data_to_node(node, data)
            else:
                self.send_data_to_nodes(data)

            SendData = file.read(1024)
Exemplo n.º 9
0
    def send_full_chain(self, node=None):
        from config import LEDGER_PATH
        dprint("Sending full chain to node or nodes." + " Node: " + str(node))
        file = open(LEDGER_PATH, "rb")
        SendData = file.read(1024)
        while SendData:

            data = {
                "fullledger":
                1,
                "byte": (SendData.decode(encoding='iso-8859-1')),
                "signature":
                Ecdsa.sign(
                    "fullledger" + str(
                        (SendData.decode(encoding='iso-8859-1'))),
                    PrivateKey.fromPem(Wallet_Import(0, 1))).toBase64()
            }
            if not node == None:
                self.send_to_node(node, data)
            else:
                self.send_to_nodes(data)

            SendData = file.read(1024)
Exemplo n.º 10
0
    def send_my_block(self, nodes):
        system = GetBlock()

        new_list = []

        signature_list = []

        for element in system.validating_list:
            new_list.append(element.dump_json())
            signature_list.append(element.signature)

        dprint("signature_list: " + str(signature_list))
        dprint("publickey from pem: " + str(Wallet_Import(0, 1)))

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

        dprint("\nmerkleroot: " + Merkle_signature_list)

        data = {
            "action":
            "myblock",
            "transaction":
            new_list,
            "sequance_number":
            system.sequance_number,
            "signature":
            Ecdsa.sign(
                "myblock" + Merkle_signature_list +
                str(system.sequance_number),
                PrivateKey.fromPem(Wallet_Import(0, 1))).toBase64()
        }

        for each_node in nodes:
            dprint("Raund 1: second ok of get candidate block: " +
                   str(each_node.__dict__))
            self.send_data_to_node(each_node, data)