All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hyperledger.fabric.client.ChaincodeEventIterator Maven / Gradle / Ivy

There is a newer version: 1.7.1
Show newest version
/*
 * Copyright 2021 IBM All Rights Reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

package org.hyperledger.fabric.client;

import java.util.Collections;
import java.util.Iterator;

import org.hyperledger.fabric.protos.gateway.ChaincodeEventsResponse;

final class ChaincodeEventIterator implements CloseableIterator {
    private final CloseableIterator responseIter;
    private Iterator eventIter = Collections.emptyIterator();
    private long blockNumber;

    ChaincodeEventIterator(final CloseableIterator responseIter) {
        this.responseIter = responseIter;
    }

    @Override
    public boolean hasNext() {
        return eventIter.hasNext() || responseIter.hasNext();
    }

    @Override
    public ChaincodeEvent next() {
        while (!eventIter.hasNext()) {
            ChaincodeEventsResponse response = responseIter.next();
            eventIter = response.getEventsList().iterator();
            blockNumber = response.getBlockNumber();
        }

        return new ChaincodeEventImpl(blockNumber, eventIter.next());
    }

    @Override
    public void close() {
        responseIter.close();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy