use of com.jd.blockchain.ledger.LedgerBlock in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getDataAccount.
@RequestMapping(method = RequestMethod.GET, path = GET_DATA_ACCOUNT)
@Override
public DataAccountInfo getDataAccount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
return dataAccountSet.getAccount(Bytes.fromBase58(address));
}
use of com.jd.blockchain.ledger.LedgerBlock in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getTransactionStateByContentHash.
@RequestMapping(method = RequestMethod.GET, path = GET_TRANSACTION_STATE)
@Override
public TransactionState getTransactionStateByContentHash(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "contentHash") HashDigest contentHash) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
TransactionSet txset = ledger.getTransactionSet(block);
return txset.getState(contentHash);
}
use of com.jd.blockchain.ledger.LedgerBlock in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getDataEntries.
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, path = GET_LATEST_KV_SEQUENCE)
@Override
public TypedKVEntry[] getDataEntries(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));
if (dataAccount == null) {
return null;
}
QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount());
fromIndex = queryArgs.getFrom();
count = queryArgs.getCount();
SkippingIterator<DataEntry<String, TypedValue>> iterator = ((IteratorDataset) dataAccount.getDataset()).kvIterator();
iterator.skip(fromIndex);
TypedKVEntry[] typedKVEntries = iterator.next(count, TypedKVEntry.class, new Mapper<DataEntry<String, TypedValue>, TypedKVEntry>() {
@Override
public TypedKVEntry from(DataEntry<String, TypedValue> entry) {
return entry == null ? null : new TypedKVData(entry.getKey(), entry.getVersion(), entry.getValue());
}
});
return typedKVEntries;
}
use of com.jd.blockchain.ledger.LedgerBlock in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getDataEntriesTotalCount.
@RequestMapping(method = RequestMethod.GET, path = GET_KV_COUNT)
@Override
public long getDataEntriesTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));
if (dataAccount == null) {
return 0;
}
return dataAccount.getDataset().getDataCount();
}
use of com.jd.blockchain.ledger.LedgerBlock in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getLatestSystemEvent.
@RequestMapping(method = RequestMethod.GET, path = GET_LATEST_SYSTEM_EVENT)
@Override
public Event getLatestSystemEvent(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "eventName") String eventName) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
EventGroup systemEvents = ledger.getSystemEventGroup(block);
return systemEvents.getLatest(eventName);
}
Aggregations