use of com.radixdlt.api.core.model.CoreApiException in project radixdlt by radixdlt.
the class NodeApiClient method getUnstakes.
public List<ResourceAmount> getUnstakes(REAddr addr, ECPublicKey validatorKey) {
var networkIdentifier = new NetworkIdentifier().network("localnet");
var unstakingDelayEpochLength = unstakingDelayEpochLength();
var unstakes = new ArrayList<ResourceAmount>();
try {
var statusResponse = engineStatusHandler.handleRequest(new EngineStatusRequest().networkIdentifier(networkIdentifier));
var curEpoch = statusResponse.getEngineStateIdentifier().getEpoch();
var maxEpoch = curEpoch + unstakingDelayEpochLength + 1;
for (long epochUnstake = curEpoch; epochUnstake <= maxEpoch; epochUnstake++) {
var response = entityHandler.handleRequest(new EntityRequest().networkIdentifier(networkIdentifier).entityIdentifier(coreModelMapper.entityIdentifierExitingStake(addr, validatorKey, epochUnstake)));
unstakes.addAll(response.getBalances());
}
} catch (CoreApiException e) {
throw new IllegalStateException(e);
}
return unstakes;
}
use of com.radixdlt.api.core.model.CoreApiException in project radixdlt by radixdlt.
the class EntityHandler method handleRequest.
@Override
public EntityResponse handleRequest(EntityRequest request) throws CoreApiException {
modelMapper.verifyNetwork(request.getNetworkIdentifier());
var entity = modelMapper.entity(request.getEntityIdentifier());
var keyQueries = entity.getKeyQueries();
var resourceQueries = entity.getResourceQueries();
// This must be read atomically
return radixEngine.read(reader -> {
Function<REAddr, String> addressToSymbol = addr -> {
var mapKey = SystemMapKey.ofResourceData(addr, SubstateTypeId.TOKEN_RESOURCE_METADATA.id());
var substate = reader.get(mapKey).orElseThrow();
var tokenResource = (TokenResourceMetadata) substate;
return tokenResource.symbol();
};
var proof = reader.getMetadata().getProof();
var response = new EntityResponse().stateIdentifier(modelMapper.stateIdentifier(proof.getAccumulatorState()));
for (var resourceQuery : resourceQueries) {
resourceQuery.fold((index, bucketPredicate) -> reader.reduceResources(index, ResourceInBucket::bucket, bucketPredicate).entrySet().stream().map(e -> modelMapper.resourceOperation(e.getKey(), e.getValue(), addressToSymbol)), systemMapKey -> reader.get(systemMapKey).map(ResourceInBucket.class::cast).stream().map(b -> modelMapper.resourceOperation(b, true, addressToSymbol))).forEach(response::addBalancesItem);
}
for (var keyQuery : keyQueries) {
var substate = keyQuery.get(reader);
substate.flatMap(modelMapper::dataObject).ifPresent(response::addDataObjectsItem);
}
return response;
});
}
Aggregations