use of com.radixdlt.atomos.Loader 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.Loader in project radixdlt by radixdlt.
the class EpochUpdateConstraintScrypt method epochUpdate.
private void epochUpdate(Loader os) {
// Epoch Update
os.procedure(new DownProcedure<>(EndPrevRound.class, EpochData.class, d -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (d, s, r, c) -> {
// TODO: Should move this authorization instead of checking epoch > 0
if (d.epoch() > 0 && s.getClosedRound().view() != maxRounds) {
throw new ProcedureException("Must execute epoch update on end of round " + maxRounds + " but is " + s.getClosedRound().view());
}
return ReducerResult.incomplete(new UpdatingEpoch(d));
}));
os.procedure(new ShutdownAllProcedure<>(ExitingStake.class, UpdatingEpoch.class, () -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, d, c, r) -> {
var exittingStake = new ProcessExittingStake(s);
return ReducerResult.incomplete(exittingStake.process(d));
}));
os.procedure(new UpProcedure<>(ProcessExittingStake.class, TokensInAccount.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> ReducerResult.incomplete(s.unlock(u))));
os.procedure(new ShutdownAllProcedure<>(ValidatorBFTData.class, RewardingValidators.class, () -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, d, c, r) -> ReducerResult.incomplete(s.process(d, c))));
os.procedure(new ShutdownAllProcedure<>(PreparedUnstakeOwnership.class, PreparingUnstake.class, () -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, d, c, r) -> ReducerResult.incomplete(s.unstakes(d))));
os.procedure(new DownProcedure<>(LoadingStake.class, ValidatorStakeData.class, d -> d.bucket().withdrawAuthorization(), (d, s, r, c) -> ReducerResult.incomplete(s.startUpdate(d))));
os.procedure(new UpProcedure<>(Unstaking.class, ExitingStake.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> ReducerResult.incomplete(s.exit(u))));
os.procedure(new ShutdownAllProcedure<>(PreparedStake.class, PreparingStake.class, () -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, d, c, r) -> ReducerResult.incomplete(s.prepareStakes(d))));
os.procedure(new ShutdownAllProcedure<>(ValidatorFeeCopy.class, PreparingRakeUpdate.class, () -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, d, c, r) -> ReducerResult.incomplete(s.prepareRakeUpdates(d))));
os.procedure(new UpProcedure<>(ResetRakeUpdate.class, ValidatorFeeCopy.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> ReducerResult.incomplete(s.reset(u))));
os.procedure(new ShutdownAllProcedure<>(ValidatorOwnerCopy.class, PreparingOwnerUpdate.class, () -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, d, c, r) -> ReducerResult.incomplete(s.prepareValidatorUpdate(d))));
os.procedure(new UpProcedure<>(ResetOwnerUpdate.class, ValidatorOwnerCopy.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> ReducerResult.incomplete(s.reset(u))));
os.procedure(new ShutdownAllProcedure<>(ValidatorRegisteredCopy.class, PreparingRegisteredUpdate.class, () -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, d, c, r) -> ReducerResult.incomplete(s.prepareRegisterUpdates(d))));
os.procedure(new UpProcedure<>(ResetRegisteredUpdate.class, ValidatorRegisteredCopy.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> ReducerResult.incomplete(s.reset(u))));
os.procedure(new UpProcedure<>(Staking.class, StakeOwnership.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> ReducerResult.incomplete(s.stake(u))));
os.procedure(new UpProcedure<>(UpdatingValidatorStakes.class, ValidatorStakeData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> ReducerResult.incomplete(s.updateStake(u))));
os.procedure(new ReadIndexProcedure<>(CreatingNextValidatorSet.class, ValidatorStakeData.class, () -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, d, c, r) -> ReducerResult.incomplete(s.readIndex(d, c))));
os.procedure(new UpProcedure<>(BootupValidator.class, ValidatorBFTData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> ReducerResult.incomplete(s.bootUp(u))));
os.procedure(new UpProcedure<>(StartingNextEpoch.class, EpochData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> ReducerResult.incomplete(s.nextEpoch(u))));
os.procedure(new UpProcedure<>(StartingEpochRound.class, RoundData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
}), (s, u, c, r) -> {
if (u.view() != 0) {
throw new ProcedureException("Epoch must start with view 0");
}
return ReducerResult.complete();
}));
}
use of com.radixdlt.atomos.Loader 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.Loader in project radixdlt by radixdlt.
the class TokensConstraintScryptV3 method defineTokenCreation.
private void defineTokenCreation(Loader os) {
os.procedure(new UpProcedure<>(SystemConstraintScrypt.REAddrClaim.class, TokenResource.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, u, c, r) -> {
if (!u.addr().equals(s.getAddr())) {
throw new ProcedureException("Addresses don't match");
}
var str = new String(s.getArg());
if (reservedSymbols.contains(str) && c.permissionLevel() != PermissionLevel.SYSTEM) {
throw new ReservedSymbolException(str);
}
if (!tokenSymbolPattern.matcher(str).matches()) {
throw new ProcedureException("invalid token symbol: " + str);
}
if (u.isMutable()) {
return ReducerResult.incomplete(new NeedMetadata(s.getArg(), u));
}
if (!u.granularity().equals(UInt256.ONE)) {
throw new ProcedureException("Granularity must be one.");
}
return ReducerResult.incomplete(new NeedFixedTokenSupply(s.getArg(), u));
}));
os.procedure(new UpProcedure<>(NeedFixedTokenSupply.class, TokensInAccount.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, u, c, r) -> {
if (!u.resourceAddr().equals(s.tokenResource.addr())) {
throw new ProcedureException("Addresses don't match.");
}
return ReducerResult.incomplete(new NeedMetadata(s.arg, s.tokenResource));
}));
os.procedure(new UpProcedure<>(NeedMetadata.class, TokenResourceMetadata.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, u, c, r) -> {
s.metadata(u, c);
return ReducerResult.complete();
}));
}
use of com.radixdlt.atomos.Loader in project radixdlt by radixdlt.
the class StakingConstraintScryptV4 method defineStaking.
private void defineStaking(Loader os) {
// Stake
os.procedure(new ReadProcedure<>(TokenHoldingBucket.class, AllowDelegationFlag.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, d, r) -> {
var nextState = (!d.allowsDelegation()) ? new OwnerStakePrepare(s, d) : new StakePrepare(s, d.validatorKey(), p -> true);
return ReducerResult.incomplete(nextState);
}));
os.procedure(new ReadProcedure<>(OwnerStakePrepare.class, ValidatorOwnerCopy.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, d, r) -> {
var nextState = s.readOwner(d);
return ReducerResult.incomplete(nextState);
}));
os.procedure(new UpProcedure<>(StakePrepare.class, PreparedStake.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, u, c, r) -> {
var nextState = s.withdrawTo(u);
return ReducerResult.incomplete(nextState);
}));
// Unstake
os.procedure(new DownProcedure<>(VoidReducerState.class, StakeOwnership.class, d -> d.bucket().withdrawAuthorization(), (d, s, r, c) -> ReducerResult.incomplete(new StakeOwnershipHoldingBucket(d))));
// Additional Unstake
os.procedure(new DownProcedure<>(StakeOwnershipHoldingBucket.class, StakeOwnership.class, d -> d.bucket().withdrawAuthorization(), (d, s, r, c) -> {
s.depositOwnership(d);
return ReducerResult.incomplete(s);
}));
// Change
os.procedure(new UpProcedure<>(StakeOwnershipHoldingBucket.class, StakeOwnership.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, u, c, r) -> {
var ownership = s.withdrawOwnership(u.amount());
if (!ownership.equals(u)) {
throw new MismatchException(ownership, u);
}
return ReducerResult.incomplete(s);
}));
os.procedure(new UpProcedure<>(StakeOwnershipHoldingBucket.class, PreparedUnstakeOwnership.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, u, c, r) -> {
var unstake = s.unstake(u.amount());
if (!unstake.equals(u)) {
throw new MismatchException(unstake, u);
}
return ReducerResult.incomplete(s);
}));
// Deallocate Stake Holding Bucket
os.procedure(new EndProcedure<>(StakeOwnershipHoldingBucket.class, s -> new Authorization(PermissionLevel.USER, (r, c) -> {
}), (s, c, r) -> s.destroy()));
}
Aggregations