use of com.radixdlt.constraintmachine.EndProcedure 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