use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.
the class SubstateDeserialization method deserialize.
public Particle deserialize(ByteBuffer buf) throws DeserializeException {
var typeByte = buf.get();
var deserializer = byteToDeserializer.get(typeByte);
if (deserializer == null) {
throw new DeserializeException("Unknown byte type: " + typeByte);
}
try {
return deserializer.deserializer().deserialize(buf);
} catch (Exception e) {
throw new SubstateDeserializationException(deserializer.substateClass(), e);
}
}
use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.
the class ValidatorUpdateRakeConstraintScrypt method main.
@Override
public void main(Loader os) {
os.substate(new SubstateDefinition<>(ValidatorFeeCopy.class, SubstateTypeId.VALIDATOR_RAKE_COPY.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
OptionalLong epochUpdate = REFieldSerialization.deserializeOptionalNonNegativeLong(buf);
var key = REFieldSerialization.deserializeKey(buf);
var curRakePercentage = REFieldSerialization.deserializeInt(buf);
if (curRakePercentage < RAKE_MIN || curRakePercentage > RAKE_MAX) {
throw new DeserializeException("Invalid rake percentage " + curRakePercentage);
}
return new ValidatorFeeCopy(epochUpdate, key, curRakePercentage);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeOptionalLong(buf, s.epochUpdate());
REFieldSerialization.serializeKey(buf, s.validatorKey());
buf.putInt(s.curRakePercentage());
}, buf -> REFieldSerialization.deserializeKey(buf), (k, buf) -> REFieldSerialization.serializeKey(buf, (ECPublicKey) k), k -> ValidatorFeeCopy.createVirtual((ECPublicKey) k)));
os.procedure(new DownProcedure<>(VoidReducerState.class, ValidatorFeeCopy.class, d -> new Authorization(PermissionLevel.USER, (r, c) -> {
if (!c.key().map(d.validatorKey()::equals).orElse(false)) {
throw new AuthorizationException("Key does not match.");
}
}), (d, s, r, c) -> {
return ReducerResult.incomplete(new UpdatingRakeNeedToReadCurrentRake(d.validatorKey()));
}));
os.procedure(new ReadProcedure<>(UpdatingRakeNeedToReadEpoch.class, EpochData.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, u, r) -> ReducerResult.incomplete(s.readEpoch(u))));
os.procedure(new ReadProcedure<>(UpdatingRakeNeedToReadCurrentRake.class, ValidatorStakeData.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, u, r) -> ReducerResult.incomplete(s.readValidatorStakeState(u))));
os.procedure(new UpProcedure<>(UpdatingRakeReady.class, ValidatorFeeCopy.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, u, c, r) -> {
s.update(u);
return ReducerResult.complete();
}));
}
use of com.radixdlt.serialization.DeserializeException 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