use of com.jd.blockchain.ledger.core.LedgerQuery in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getTransactions.
@RequestMapping(method = RequestMethod.GET, path = GET_TRANSACTIONS_ON_BLOCK_HASH)
@Override
public LedgerTransaction[] getTransactions(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "blockHash") HashDigest blockHash, @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex, @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock ledgerBlock = ledger.getBlock(blockHash);
if (null == ledgerBlock) {
return null;
}
QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, (int) ledger.getTransactionSet(ledgerBlock).getTotalCount());
LedgerTransaction[] txs = ledger.getTransactionSet(ledgerBlock).getTransactions(queryArgs.getFrom(), queryArgs.getCount());
return txsDecorator(txs);
// LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
// LedgerBlock ledgerBlock = ledger.getBlock(blockHash);
// long height = ledgerBlock.getHeight();
// TransactionQuery transactionSet = ledger.getTransactionSet(ledgerBlock);
// TransactionQuery origTransactionSet = null;
// int lastHeightTxTotalNums = 0;
//
// if (height > 0) {
// origTransactionSet = ledger.getTransactionSet(ledger.getBlock(height - 1));
// lastHeightTxTotalNums = (int) origTransactionSet.getTotalCount();
// }
//
// int currentHeightTxTotalNums = (int) ledger.getTransactionSet(ledger.getBlock(height)).getTotalCount();
// // 取当前块hash的增量交易数,在增量交易里进行查找
// int currentHeightTxNums = currentHeightTxTotalNums - lastHeightTxTotalNums;
//
// QueryArgs queryArgs = QueryUtils.calFromIndexAndCount(fromIndex, count, currentHeightTxNums);
// LedgerTransaction[] txs = transactionSet.getBlockTxs(queryArgs.getFrom(), queryArgs.getCount(), origTransactionSet);
// return txsDecorator(txs);
}
use of com.jd.blockchain.ledger.core.LedgerQuery in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getConsensusParticipants.
@RequestMapping(method = RequestMethod.GET, path = GET_CONSENSUS_PARTICIPANTS)
@Override
public ParticipantNode[] getConsensusParticipants(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerAdminInfo ledgerAdministration = ledger.getAdminInfo();
long participantCount = ledgerAdministration.getParticipantCount();
if (participantCount <= 0) {
return null;
}
ParticipantNode[] participantNodes = ledgerAdministration.getParticipants();
// 重新封装,处理Proxy的问题
if (participantNodes != null && participantNodes.length > 0) {
ParticipantNode[] convertNodes = new ParticipantNode[participantNodes.length];
for (int i = 0, length = participantNodes.length; i < length; i++) {
convertNodes[i] = new ParticipantCertData(participantNodes[i]);
}
return convertNodes;
}
return null;
}
use of com.jd.blockchain.ledger.core.LedgerQuery in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getTransactionCount.
@RequestMapping(method = RequestMethod.GET, path = GET_TRANSACTION_COUNT_ON_BLOCK_HEIGHT)
@Override
public long getTransactionCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "blockHeight") long blockHeight) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHeight);
if (null == block) {
return 0;
}
TransactionSet txSet = ledger.getTransactionSet(block);
return txSet.getTotalCount();
}
use of com.jd.blockchain.ledger.core.LedgerQuery in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getDataEntries.
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, path = GET_LATEST_KV_LIST)
@Override
public TypedKVEntry[] getDataEntries(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address, @RequestParam("keys") String... keys) {
if (keys == null || keys.length == 0) {
return null;
}
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;
}
TypedKVEntry[] entries = new TypedKVEntry[keys.length];
long ver;
for (int i = 0; i < entries.length; i++) {
ver = dataAccount.getDataset().getVersion(keys[i]);
if (ver < 0) {
entries[i] = new TypedKVData(keys[i], -1, null);
} else {
BytesValue value = dataAccount.getDataset().getValue(keys[i], ver);
entries[i] = new TypedKVData(keys[i], ver, value);
}
}
return entries;
}
use of com.jd.blockchain.ledger.core.LedgerQuery in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getContract.
@RequestMapping(method = RequestMethod.GET, path = GET_LATEST_COMPILED_CONTRACT)
@Override
public ContractInfo getContract(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
ContractAccountSet contractAccountSet = ledger.getContractAccountSet(block);
return contractAccountSet.getAccount(Bytes.fromBase58(address));
}
Aggregations