def do_block_event_extractor():
     block_header = BlockHeader(block_num=85,
                                state_root_hash="0987654321fedcba",
                                previous_block_id="0000000000000000")
     block = BlockWrapper(
         Block(header_signature="abcdef1234567890",
               header=block_header.SerializeToString()))
     extractor = BlockEventExtractor(block)
     events = extractor.extract(
         [EventSubscription(event_type="sawtooth/block-commit")])
     assert events == [
         Event(event_type="sawtooth/block-commit",
               attributes=[
                   Event.Attribute(key="block_id",
                                   value="abcdef1234567890"),
                   Event.Attribute(key="block_num", value="85"),
                   Event.Attribute(key="state_root_hash",
                                   value="0987654321fedcba"),
                   Event.Attribute(key="previous_block_id",
                                   value="0000000000000000")
               ])
     ]
    def get_events_for_block(self, blkw, subscriptions):
        receipts = []
        for batch in blkw.block.batches:
            for txn in batch.transactions:
                try:
                    receipts.append(
                        self._receipt_store.get(txn.header_signature))
                except KeyError:
                    LOGGER.warning(
                        "Transaction id %s not found in receipt store "
                        " while looking"
                        " up events for block id %s",
                        txn.header_signature[:10], blkw.identifier[:10])

        block_event_extractor = BlockEventExtractor(blkw)
        receipt_event_extractor = ReceiptEventExtractor(receipts=receipts)

        events = []
        events.extend(block_event_extractor.extract(subscriptions))
        events.extend(receipt_event_extractor.extract(subscriptions))

        return events
示例#3
0
    def get_events_for_block(self, blkw, subscriptions):
        receipts = []
        for batch in blkw.block.batches:
            for txn in batch.transactions:
                try:
                    receipts.append(self._receipt_store.get(
                        txn.header_signature))
                except KeyError:
                    LOGGER.warning(
                        "Transaction id %s not found in receipt store "
                        " while looking"
                        " up events for block id %s",
                        txn.header_signature[:10],
                        blkw.identifier[:10])

        block_event_extractor = BlockEventExtractor(blkw)
        receipt_event_extractor = ReceiptEventExtractor(receipts=receipts)

        events = []
        events.extend(block_event_extractor.extract(subscriptions))
        events.extend(receipt_event_extractor.extract(subscriptions))

        return events
示例#4
0
 def test_block_event_extractor(self):
     """Test that a sawtooth/block-commit event is generated correctly."""
     block_header = BlockHeader(
         block_num=85,
         state_root_hash="0987654321fedcba",
         previous_block_id="0000000000000000")
     block = BlockWrapper(Block(
         header_signature="abcdef1234567890",
         header=block_header.SerializeToString()))
     extractor = BlockEventExtractor(block)
     events = extractor.extract([EventSubscription(
         event_type="sawtooth/block-commit")])
     self.assertEqual(events, [
         Event(
             event_type="sawtooth/block-commit",
             attributes=[
                 Event.Attribute(key="block_id", value="abcdef1234567890"),
                 Event.Attribute(key="block_num", value="85"),
                 Event.Attribute(
                     key="state_root_hash", value="0987654321fedcba"),
                 Event.Attribute(
                     key="previous_block_id",
                     value="0000000000000000")])])
示例#5
0
 def test_block_event_extractor(self):
     """Test that a sawtooth/block-commit event is generated correctly."""
     block_header = BlockHeader(block_num=85,
                                state_root_hash="0987654321fedcba",
                                previous_block_id="0000000000000000")
     block = BlockWrapper(
         Block(header_signature="abcdef1234567890",
               header=block_header.SerializeToString()))
     extractor = BlockEventExtractor(block)
     events = extractor.extract(
         [EventSubscription(event_type="sawtooth/block-commit")])
     self.assertEqual(events, [
         Event(event_type="sawtooth/block-commit",
               attributes=[
                   Event.Attribute(key="block_id",
                                   value="abcdef1234567890"),
                   Event.Attribute(key="block_num", value="85"),
                   Event.Attribute(key="state_root_hash",
                                   value="0987654321fedcba"),
                   Event.Attribute(key="previous_block_id",
                                   value="0000000000000000")
               ])
     ])