use of com.radixdlt.atomos.SubstateDefinition in project radixdlt by radixdlt.
the class EpochUpdateConstraintScrypt method main.
@Override
public void main(Loader os) {
os.substate(new SubstateDefinition<>(ValidatorStakeData.class, SubstateTypeId.VALIDATOR_STAKE_DATA.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var isRegistered = REFieldSerialization.deserializeBoolean(buf);
var amount = REFieldSerialization.deserializeUInt256(buf);
var delegate = REFieldSerialization.deserializeKey(buf);
var ownership = REFieldSerialization.deserializeUInt256(buf);
var rakePercentage = REFieldSerialization.deserializeInt(buf);
var ownerAddress = REFieldSerialization.deserializeAccountREAddr(buf);
return ValidatorStakeData.create(delegate, amount, ownership, rakePercentage, ownerAddress, isRegistered);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeBoolean(buf, s.isRegistered());
buf.put(s.amount().toByteArray());
REFieldSerialization.serializeKey(buf, s.validatorKey());
buf.put(s.totalOwnership().toByteArray());
buf.putInt(s.rakePercentage());
REFieldSerialization.serializeREAddr(buf, s.ownerAddr());
}, buf -> REFieldSerialization.deserializeKey(buf), (k, buf) -> REFieldSerialization.serializeKey(buf, (ECPublicKey) k), k -> ValidatorStakeData.createVirtual((ECPublicKey) k)));
os.substate(new SubstateDefinition<>(StakeOwnership.class, SubstateTypeId.STAKE_OWNERSHIP.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var delegate = REFieldSerialization.deserializeKey(buf);
var owner = REFieldSerialization.deserializeAccountREAddr(buf);
var amount = REFieldSerialization.deserializeNonZeroUInt256(buf);
return new StakeOwnership(delegate, owner, amount);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeKey(buf, s.delegateKey());
REFieldSerialization.serializeREAddr(buf, s.owner());
buf.put(s.amount().toByteArray());
}));
os.substate(new SubstateDefinition<>(ExitingStake.class, SubstateTypeId.EXITING_STAKE.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var epochUnlocked = REFieldSerialization.deserializeNonNegativeLong(buf);
var delegate = REFieldSerialization.deserializeKey(buf);
var owner = REFieldSerialization.deserializeAccountREAddr(buf);
var amount = REFieldSerialization.deserializeNonZeroUInt256(buf);
return new ExitingStake(epochUnlocked, delegate, owner, amount);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
buf.putLong(s.epochUnlocked());
REFieldSerialization.serializeKey(buf, s.delegateKey());
REFieldSerialization.serializeREAddr(buf, s.owner());
buf.put(s.amount().toByteArray());
}));
registerGenesisTransitions(os);
// Epoch update
epochUpdate(os);
}
use of com.radixdlt.atomos.SubstateDefinition in project radixdlt by radixdlt.
the class RoundUpdateConstraintScrypt method main.
@Override
public void main(Loader os) {
os.substate(new SubstateDefinition<>(ValidatorBFTData.class, SubstateTypeId.VALIDATOR_BFT_DATA.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var key = REFieldSerialization.deserializeKey(buf);
var proposalsCompleted = REFieldSerialization.deserializeNonNegativeLong(buf);
var proposalsMissed = REFieldSerialization.deserializeNonNegativeLong(buf);
return new ValidatorBFTData(key, proposalsCompleted, proposalsMissed);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeKey(buf, s.validatorKey());
buf.putLong(s.completedProposals());
buf.putLong(s.missedProposals());
}, (k, buf) -> REFieldSerialization.serializeKey(buf, (ECPublicKey) k)));
os.procedure(new DownProcedure<>(VoidReducerState.class, RoundData.class, d -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (d, s, r, c) -> ReducerResult.incomplete(new EndPrevRound(d))));
os.procedure(new DownProcedure<>(EndPrevRound.class, ValidatorBFTData.class, d -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (d, s, r, c) -> {
var closedRound = s.getClosedRound().view();
var next = new StartValidatorBFTUpdate(closedRound);
next.beginUpdate(d);
return ReducerResult.incomplete(next);
}));
os.procedure(new DownProcedure<>(StartValidatorBFTUpdate.class, ValidatorBFTData.class, d -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (d, s, r, c) -> ReducerResult.incomplete(s.beginUpdate(d))));
os.procedure(new UpProcedure<>(StartValidatorBFTUpdate.class, ValidatorBFTData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> {
var next = s.exit();
return ReducerResult.incomplete(next.update(u, c));
}));
os.procedure(new UpProcedure<>(UpdatingValidatorBFTData.class, ValidatorBFTData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> ReducerResult.incomplete(s.update(u, c))));
os.procedure(new UpProcedure<>(StartNextRound.class, RoundData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> {
s.update(u);
return ReducerResult.complete();
}));
}
use of com.radixdlt.atomos.SubstateDefinition in project radixdlt by radixdlt.
the class StakingConstraintScryptV4 method main.
@Override
public void main(Loader os) {
os.substate(new SubstateDefinition<>(PreparedStake.class, SubstateTypeId.PREPARED_STAKE.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var delegate = REFieldSerialization.deserializeKey(buf);
var owner = REFieldSerialization.deserializeAccountREAddr(buf);
var amount = REFieldSerialization.deserializeNonZeroUInt256(buf);
return new PreparedStake(amount, owner, delegate);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeKey(buf, s.delegateKey());
REFieldSerialization.serializeREAddr(buf, s.owner());
buf.put(s.amount().toByteArray());
}));
os.substate(new SubstateDefinition<>(PreparedUnstakeOwnership.class, SubstateTypeId.PREPARED_UNSTAKE.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var delegate = REFieldSerialization.deserializeKey(buf);
var owner = REFieldSerialization.deserializeAccountREAddr(buf);
var amount = REFieldSerialization.deserializeNonZeroUInt256(buf);
return new PreparedUnstakeOwnership(delegate, owner, amount);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeKey(buf, s.delegateKey());
REFieldSerialization.serializeREAddr(buf, s.owner());
buf.put(s.amount().toByteArray());
}));
defineStaking(os);
}
use of com.radixdlt.atomos.SubstateDefinition in project radixdlt by radixdlt.
the class ValidatorRegisterConstraintScrypt method main.
@Override
public void main(Loader os) {
os.substate(new SubstateDefinition<>(ValidatorRegisteredCopy.class, SubstateTypeId.VALIDATOR_REGISTERED_FLAG_COPY.id(), buf -> {
REFieldSerialization.deserializeReservedByte(buf);
var epochUpdate = REFieldSerialization.deserializeOptionalNonNegativeLong(buf);
var key = REFieldSerialization.deserializeKey(buf);
var flag = REFieldSerialization.deserializeBoolean(buf);
return new ValidatorRegisteredCopy(epochUpdate, key, flag);
}, (s, buf) -> {
REFieldSerialization.serializeReservedByte(buf);
REFieldSerialization.serializeOptionalLong(buf, s.epochUpdate());
REFieldSerialization.serializeKey(buf, s.validatorKey());
buf.put((byte) (s.isRegistered() ? 1 : 0));
}, buf -> REFieldSerialization.deserializeKey(buf), (k, buf) -> REFieldSerialization.serializeKey(buf, (ECPublicKey) k), k -> new ValidatorRegisteredCopy(OptionalLong.empty(), (ECPublicKey) k, false)));
os.procedure(new DownProcedure<>(VoidReducerState.class, ValidatorRegisteredCopy.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 UpdatingRegisteredNeedToReadEpoch(d.validatorKey()));
}));
os.procedure(new ReadProcedure<>(UpdatingRegisteredNeedToReadEpoch.class, EpochData.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, u, r) -> ReducerResult.incomplete(s.readEpoch(u))));
os.procedure(new UpProcedure<>(UpdatingRegistered.class, ValidatorRegisteredCopy.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, u, c, r) -> {
s.update(u);
return ReducerResult.complete();
}));
}
use of com.radixdlt.atomos.SubstateDefinition 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();
}));
}
Aggregations