Ejemplo n.º 1
0
def make_proof_deserializable(proof: list):
    proof_deserializable = []
    for item in proof:
        try:
            left: str = item["left"]
            proof_deserializable.append({"left": Hash32.fromhex(left)})
        except KeyError:
            right: str = item["right"]
            proof_deserializable.append({"right": Hash32.fromhex(right)})
    return proof_deserializable
Ejemplo n.º 2
0
    async def __get_block(self, block_data_filter, block_hash, block_height,
                          tx_data_filter):
        blockchain = self._channel_service.block_manager.get_blockchain()
        if block_hash == "" and block_height == -1:
            block_hash = blockchain.last_block.header.hash.hex()
        block_filter = re.sub(r'\s', '', block_data_filter).split(",")
        tx_filter = re.sub(r'\s', '', tx_data_filter).split(",")

        block = None
        confirm_info = b''
        fail_response_code = None
        if block_hash:
            block = blockchain.find_block_by_hash(block_hash)
            confirm_info = blockchain.find_confirm_info_by_hash(
                Hash32.fromhex(block_hash, True))
            if block is None:
                fail_response_code = message_code.Response.fail_wrong_block_hash
        elif block_height != -1:
            block = blockchain.find_block_by_height(block_height)
            confirm_info = blockchain.find_confirm_info_by_height(block_height)
            if block is None:
                fail_response_code = message_code.Response.fail_wrong_block_height
        else:
            fail_response_code = message_code.Response.fail_wrong_block_hash

        return block, block_filter, block_hash, bytes(
            confirm_info), fail_response_code, tx_filter
Ejemplo n.º 3
0
    async def get_receipt_proof(self, tx_hash: str) -> Union[list, dict]:
        blockchain = self._channel_service.block_manager.get_blockchain()
        try:
            proof = blockchain.get_receipt_proof(Hash32.fromhex(tx_hash))
        except Exception as e:
            return make_error_response(JsonError.INVALID_PARAMS, str(e))

        try:
            return make_proof_serializable(proof)
        except Exception as e:
            return make_error_response(JsonError.INTERNAL_ERROR, str(e))
Ejemplo n.º 4
0
    async def prove_tx(self, tx_hash: str, proof: list) -> Union[str, dict]:
        blockchain = self._channel_service.block_manager.get_blockchain()
        try:
            proof = make_proof_deserializable(proof)
        except Exception as e:
            return make_error_response(JsonError.INTERNAL_ERROR, str(e))

        try:
            return "0x1" if blockchain.prove_transaction(
                Hash32.fromhex(tx_hash), proof) else "0x0"
        except Exception as e:
            return make_error_response(JsonError.INVALID_PARAMS, str(e))
Ejemplo n.º 5
0
    def test_genesis_hash_compatibility(self):
        genesis_init_data = {
            "transaction_data": {
                "accounts": [{
                    "name": "god",
                    "address": "hxebf3a409845cd09dcb5af31ed5be5e34e2af9433",
                    "balance": "0x2961ffa20dd47f5c4700000"
                }, {
                    "name": "treasury",
                    "address": "hxd5775948cb745525d28ec8c1f0c84d73b38c78d4",
                    "balance": "0x0"
                }, {
                    "name": "test1",
                    "address": "hx670e692ffd3d5587c36c3a9d8442f6d2a8fcc795",
                    "balance": "0x0"
                }, {
                    "name": "test2",
                    "address": "hxdc8d79453ba6516bc140b7f53b6b9a012da7ff10",
                    "balance": "0x0"
                }, {
                    "name": "test3",
                    "address": "hxbedeeadea922dc7f196e22eaa763fb01aab0b64c",
                    "balance": "0x0"
                }, {
                    "name": "test4",
                    "address": "hxa88d8addc6495e4c21b0dda5b0bf6c9108c98da6",
                    "balance": "0x0"
                }, {
                    "name": "test5",
                    "address": "hx0260cc5b8777485b04e9dc938b1ee949910f41e1",
                    "balance": "0x0"
                }, {
                    "name": "test6",
                    "address": "hx09e89b468a1cdfdd24441668204911502fa3add9",
                    "balance": "0x0"
                }, {
                    "name": "test7",
                    "address": "hxeacd884f0e0b5b2e4a6b4ee87fa5184ab9f25cbe",
                    "balance": "0x0"
                }, {
                    "name": "test8",
                    "address": "hxa943122f57c7c2af7416c1f2e1af46838ad0958f",
                    "balance": "0x0"
                }, {
                    "name": "test9",
                    "address": "hxc0519e1c56030be070afc89fbf05783c89b15e2f",
                    "balance": "0x0"
                }, {
                    "name": "test10",
                    "address": "hxcebc788d5b922b356a1dccadc384d36964e87165",
                    "balance": "0x0"
                }, {
                    "name": "test11",
                    "address": "hx7f8f432ffdb5fc1d2df6dd452ca52eb719150f3c",
                    "balance": "0x0"
                }, {
                    "name": "test12",
                    "address": "hxa6c4468032824092ecdb3de2bb66947d69e07b59",
                    "balance": "0x0"
                }, {
                    "name": "test13",
                    "address": "hxc26d0b28b11732b38c0a2c0634283730258f272a",
                    "balance": "0x0"
                }, {
                    "name": "test14",
                    "address": "hx695ddb2d1e78f012e3e271e95ffbe4cc8fcd133b",
                    "balance": "0x0"
                }, {
                    "name": "test15",
                    "address": "hx80ab6b11b5d5c80448d011d10fb1a579c57e0a6c",
                    "balance": "0x0"
                }, {
                    "name": "test16",
                    "address": "hxa9c7881a53f2245ed12238412940c6f54874c4e3",
                    "balance": "0x0"
                }, {
                    "name": "test17",
                    "address": "hx4e53cffe116baaff5e1940a6a0c14ad54f7534f2",
                    "balance": "0x0"
                }, {
                    "name": "test18",
                    "address": "hxbbef9e3942d3d5d83b5293b3cbc20940b459e3eb",
                    "balance": "0x0"
                }],
                "message":
                "A rHizomE has no beGInning Or enD; it is alWays IN the miDDle, between tHings, interbeing, intermeZzO. ThE tree is fiLiatioN, but the rhizome is alliance, uniquelY alliance. The tree imposes the verb \"to be\" but the fabric of the rhizome is the conJUNction, \"AnD ... and ...and...\"THis conJunction carriEs enouGh force to shaKe and uproot the verb \"to be.\" Where are You goIng? Where are you coMing from? What are you heading for? These are totally useless questions.\n\n- 『Mille Plateaux』, Gilles Deleuze & Felix Guattari\n\n\"Hyperconnect the world\""
            }
        }

        genesis_hash_generator = build_hash_generator(0, "genesis_tx")
        genesis_tx_hash = genesis_hash_generator.generate_hash(
            genesis_init_data["transaction_data"])
        self.assertEqual(
            genesis_tx_hash,
            Hash32.fromhex(
                "6dbc389370253739f28b8c236f4e7acdcfcdb9cfe8386c32d809114d5b00ac65"
            ))