use of com.jd.blockchain.ledger.KVDataVO in project jdchain-core by blockchain-jd-com.
the class LedgerQueryController method getDataEntries.
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, path = GET_KV_VERSION_LIST)
@Override
public TypedKVEntry[] getDataEntries(@PathVariable(name = "ledgerHash") HashDigest ledgerHash, @PathVariable(name = "address") String address, @RequestBody KVInfoVO kvInfoVO) {
// parse kvInfoVO;
List<String> keyList = new ArrayList<>();
List<Long> versionList = new ArrayList<>();
if (kvInfoVO != null) {
for (KVDataVO kvDataVO : kvInfoVO.getData()) {
for (Long version : kvDataVO.getVersion()) {
keyList.add(kvDataVO.getKey());
versionList.add(version);
}
}
}
String[] keys = keyList.toArray(new String[keyList.size()]);
Long[] versions = versionList.toArray(new Long[versionList.size()]);
if (keys == null || keys.length == 0) {
return null;
}
if (versions == null || versions.length == 0) {
return null;
}
if (keys.length != versions.length) {
throw new ContractException("keys.length!=versions.length!");
}
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 = -1;
for (int i = 0; i < entries.length; i++) {
// ver = dataAccount.getDataVersion(Bytes.fromString(keys[i]));
ver = versions[i];
if (ver < 0) {
entries[i] = new TypedKVData(keys[i], -1, null);
} else {
if (dataAccount.getDataset().getDataCount() == 0 || dataAccount.getDataset().getValue(keys[i], ver) == null) {
// is the address is not exist; the result is null;
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.KVDataVO in project jdchain-core by blockchain-jd-com.
the class UncommittedLedgerQueryService method getDataEntries.
@Override
public TypedKVEntry[] getDataEntries(String address, KVInfoVO kvInfoVO) {
List<String> keyList = new ArrayList<>();
List<Long> versionList = new ArrayList<>();
if (kvInfoVO != null) {
for (KVDataVO kvDataVO : kvInfoVO.getData()) {
for (Long version : kvDataVO.getVersion()) {
keyList.add(kvDataVO.getKey());
versionList.add(version);
}
}
}
String[] keys = keyList.toArray(new String[keyList.size()]);
Long[] versions = versionList.toArray(new Long[versionList.size()]);
if (keys.length == 0) {
return null;
}
if (versions.length == 0) {
return null;
}
if (keys.length != versions.length) {
throw null;
}
DataAccount dataAccount = transactionContext.getDataset().getDataAccountSet().getAccount(address);
TypedKVEntry[] entries = new TypedKVEntry[keys.length];
long ver = -1L;
for (int i = 0; i < entries.length; i++) {
ver = versions[i];
if (ver < 0) {
entries[i] = new TypedKVData(keys[i], -1, null);
} else {
if (dataAccount.getDataset().getDataCount() == 0 || dataAccount.getDataset().getValue(keys[i], ver) == null) {
// is the address is not exist; the result is null;
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.KVDataVO in project jdchain-core by blockchain-jd-com.
the class ContractLedgerQueryService method getDataEntries.
@Override
public TypedKVEntry[] getDataEntries(String address, KVInfoVO kvInfoVO) {
List<String> keyList = new ArrayList<>();
List<Long> versionList = new ArrayList<>();
if (kvInfoVO != null) {
for (KVDataVO kvDataVO : kvInfoVO.getData()) {
for (Long version : kvDataVO.getVersion()) {
keyList.add(kvDataVO.getKey());
versionList.add(version);
}
}
}
String[] keys = keyList.toArray(new String[keyList.size()]);
Long[] versions = versionList.toArray(new Long[versionList.size()]);
if (keys.length == 0) {
return null;
}
if (versions.length == 0) {
return null;
}
if (keys.length != versions.length) {
throw null;
}
DataAccount dataAccount = ledgerQuery.getDataAccountSet().getAccount(address);
TypedKVEntry[] entries = new TypedKVEntry[keys.length];
long ver = -1L;
for (int i = 0; i < entries.length; i++) {
ver = versions[i];
if (ver < 0) {
entries[i] = new TypedKVData(keys[i], -1, null);
} else {
if (dataAccount.getDataset().getDataCount() == 0 || dataAccount.getDataset().getValue(keys[i], ver) == null) {
// is the address is not exist; the result is null;
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;
}
Aggregations