コード例 #1
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)
コード例 #2
0
    def send_full_node_list(self, node=None):
        from config import CONNECTED_NODE_PATH
        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 == None:
                self.send_to_node(node, data)
            else:
                self.send_to_nodes(data)

            SendData = file.read(1024)