use of com.radixdlt.application.tokens.state.TokenResourceMetadata 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;
});
}
use of com.radixdlt.application.tokens.state.TokenResourceMetadata in project radixdlt by radixdlt.
the class TokensConstraintScryptV3 method registerParticles.
private void registerParticles(Loader os) {
os.substate(new SubstateDefinition<>(TokenResource.class, SubstateTypeId.TOKEN_RESOURCE.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var addr = REFieldSerialization.deserializeResourceAddr(buf);
var granularity = REFieldSerialization.deserializeNonZeroUInt256(buf);
if (!granularity.equals(UInt256.ONE)) {
throw new DeserializeException("Granularity must be one.");
}
var isMutable = REFieldSerialization.deserializeBoolean(buf);
var minter = REFieldSerialization.deserializeOptionalKey(buf);
return new TokenResource(addr, granularity, isMutable, minter.orElse(null));
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeREAddr(buf, s.addr());
REFieldSerialization.serializeUInt256(buf, UInt256.ONE);
REFieldSerialization.serializeBoolean(buf, s.isMutable());
REFieldSerialization.serializeOptionalKey(buf, s.optionalOwner());
}));
os.substate(new SubstateDefinition<>(TokenResourceMetadata.class, SubstateTypeId.TOKEN_RESOURCE_METADATA.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var addr = REFieldSerialization.deserializeResourceAddr(buf);
var symbol = REFieldSerialization.deserializeString(buf);
var name = REFieldSerialization.deserializeString(buf);
var description = REFieldSerialization.deserializeString(buf);
var url = REFieldSerialization.deserializeUrl(buf);
var iconUrl = REFieldSerialization.deserializeUrl(buf);
return new TokenResourceMetadata(addr, symbol, name, description, iconUrl, url);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeREAddr(buf, s.addr());
REFieldSerialization.serializeString(buf, s.symbol());
REFieldSerialization.serializeString(buf, s.name());
REFieldSerialization.serializeString(buf, s.description());
REFieldSerialization.serializeString(buf, s.url());
REFieldSerialization.serializeString(buf, s.iconUrl());
}));
os.substate(new SubstateDefinition<>(TokensInAccount.class, SubstateTypeId.TOKENS.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var holdingAddr = REFieldSerialization.deserializeAccountREAddr(buf);
var addr = REFieldSerialization.deserializeResourceAddr(buf);
var amount = REFieldSerialization.deserializeNonZeroUInt256(buf);
return new TokensInAccount(holdingAddr, addr, amount);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeREAddr(buf, s.holdingAddress());
REFieldSerialization.serializeREAddr(buf, s.resourceAddr());
buf.put(s.amount().toByteArray());
}));
}
Aggregations