Search in sources :

Example 1 with EventInfo

use of com.jd.blockchain.ledger.EventInfo in project jdchain-core by blockchain-jd-com.

the class EventPublishingAccount method getEvents.

@Override
public Event[] getEvents(String eventName, long fromSequence, int count) {
    List<Event> events = new ArrayList<>();
    Dataset<String, TypedValue> ds = mklAccount.getDataset();
    long maxVersion = mklAccount.getDataset().getVersion(eventName) + 1;
    for (int i = 0; i < count && i <= maxVersion; i++) {
        TypedValue tv = ds.getValue(eventName, fromSequence + i);
        if (null == tv || tv.isNil()) {
            break;
        }
        Event event = BinaryProtocol.decode(tv.bytesValue());
        events.add(new EventInfo(event));
    }
    return events.toArray(new Event[events.size()]);
}
Also used : EventInfo(com.jd.blockchain.ledger.EventInfo) ArrayList(java.util.ArrayList) Event(com.jd.blockchain.ledger.Event) TypedValue(com.jd.blockchain.ledger.TypedValue)

Example 2 with EventInfo

use of com.jd.blockchain.ledger.EventInfo in project jdchain-core by blockchain-jd-com.

the class EventGroupPublisher method getEvents.

@Override
public Event[] getEvents(String eventName, long fromSequence, int maxCount) {
    List<Event> eventsList = new ArrayList<>();
    Bytes key = encodeKey(eventName);
    long maxVersion = events.getVersion(key);
    for (int i = 0; i < maxCount && i <= maxVersion; i++) {
        byte[] bs = events.getValue(key, fromSequence + i);
        if (null == bs) {
            break;
        }
        Event event = BinaryProtocol.decode(bs);
        eventsList.add(new EventInfo(event));
    }
    return eventsList.toArray(new Event[eventsList.size()]);
}
Also used : Bytes(utils.Bytes) EventInfo(com.jd.blockchain.ledger.EventInfo) ArrayList(java.util.ArrayList) Event(com.jd.blockchain.ledger.Event)

Aggregations

Event (com.jd.blockchain.ledger.Event)2 EventInfo (com.jd.blockchain.ledger.EventInfo)2 ArrayList (java.util.ArrayList)2 TypedValue (com.jd.blockchain.ledger.TypedValue)1 Bytes (utils.Bytes)1