コード例 #1
0
ファイル: wallet_node.py プロジェクト: Mu-L/chia-blockchain
    async def _messages_to_resend(self) -> List[Tuple[Message, Set[bytes32]]]:
        if self.wallet_state_manager is None or self.backup_initialized is False or self._shut_down:
            return []
        messages: List[Tuple[Message, Set[bytes32]]] = []

        records: List[TransactionRecord] = await self.wallet_state_manager.tx_store.get_not_sent()

        for record in records:
            if record.spend_bundle is None:
                continue
            msg = make_msg(
                ProtocolMessageTypes.send_transaction,
                wallet_protocol.SendTransaction(record.spend_bundle),
            )
            already_sent = set()
            for peer, status, _ in record.sent_to:
                already_sent.add(hexstr_to_bytes(peer))
            messages.append((msg, already_sent))

        return messages
コード例 #2
0
    async def test_transaction_freeze(self, wallet_node_30_freeze):
        num_blocks = 5
        full_nodes, wallets = wallet_node_30_freeze
        full_node_api: FullNodeSimulator = full_nodes[0]
        full_node_server = full_node_api.server
        wallet_node, server_2 = wallets[0]
        wallet = wallet_node.wallet_state_manager.main_wallet
        ph = await wallet.get_new_puzzlehash()
        incoming_queue, node_id = await add_dummy_connection(
            full_node_server, 12312)

        await server_2.start_client(
            PeerInfo(self_hostname, uint16(full_node_server._port)), None)
        for i in range(num_blocks):
            await full_node_api.farm_new_transaction_block(
                FarmNewBlockProtocol(ph))

        funds = sum([
            calculate_pool_reward(uint32(i)) +
            calculate_base_farmer_reward(uint32(i))
            for i in range(1, num_blocks)
        ])
        # funds += calculate_base_farmer_reward(0)
        await asyncio.sleep(2)
        print(await wallet.get_confirmed_balance(), funds)
        await time_out_assert(10, wallet.get_confirmed_balance, funds)
        assert int(time.time(
        )) < full_node_api.full_node.constants.INITIAL_FREEZE_END_TIMESTAMP
        tx: TransactionRecord = await wallet.generate_signed_transaction(
            100, ph, 0)
        spend = wallet_protocol.SendTransaction(tx.spend_bundle)
        response = await full_node_api.send_transaction(spend)
        assert wallet_protocol.TransactionAck.from_bytes(
            response.data).status == MempoolInclusionStatus.FAILED

        new_spend = full_node_protocol.NewTransaction(tx.spend_bundle.name(),
                                                      1, 0)
        response = await full_node_api.new_transaction(new_spend)
        assert response is None

        peer = full_node_server.all_connections[node_id]
        new_spend = full_node_protocol.RespondTransaction(tx.spend_bundle)
        response = await full_node_api.respond_transaction(new_spend,
                                                           peer=peer)
        assert response is None

        for i in range(26):
            await asyncio.sleep(2)
            await full_node_api.farm_new_transaction_block(
                FarmNewBlockProtocol(ph))
            if int(
                    time.time()
            ) > full_node_api.full_node.constants.INITIAL_FREEZE_END_TIMESTAMP:
                break

        new_spend = full_node_protocol.NewTransaction(tx.spend_bundle.name(),
                                                      1, 0)
        response = await full_node_api.new_transaction(new_spend)
        assert response is not None
        assert ProtocolMessageTypes(
            response.type) == ProtocolMessageTypes.request_transaction

        tx: TransactionRecord = await wallet.generate_signed_transaction(
            100, ph, 0)
        spend = wallet_protocol.SendTransaction(tx.spend_bundle)
        response = await full_node_api.send_transaction(spend)
        assert response is not None

        assert wallet_protocol.TransactionAck.from_bytes(
            response.data).status == MempoolInclusionStatus.SUCCESS
        assert ProtocolMessageTypes(
            response.type) == ProtocolMessageTypes.transaction_ack
コード例 #3
0
    program,
    program,
)

respond_puzzle_solution = wallet_protocol.RespondPuzzleSolution(
    puzzle_solution_response, )

reject_puzzle_solution = wallet_protocol.RejectPuzzleSolution(
    bytes32(
        bytes.fromhex(
            "2f16254e8e7a0b3fbe7bc709d29c5e7d2daa23ce1a2964e3f77b9413055029dd")
    ),
    uint32(2039721496),
)

send_transaction = wallet_protocol.SendTransaction(spend_bundle, )

transaction_ack = wallet_protocol.TransactionAck(
    bytes32(
        bytes.fromhex(
            "fc30d2df70f4ca0a138d5135d352611ddf268ea46c59cde48c29c43d9472532c")
    ),
    uint8(30),
    "None",
)

new_peak_wallet = wallet_protocol.NewPeakWallet(
    bytes32(
        bytes.fromhex(
            "ee50e45652cb6a60e3ab0031aa425a6019648fe5344ae860e6fc14af1aa3c2fa")
    ),