Search in sources :

Example 1 with ValidatorOwnerCopy

use of com.radixdlt.application.validators.state.ValidatorOwnerCopy in project radixdlt by radixdlt.

the class UpdateValidatorOwnerConstructor method construct.

@Override
public void construct(UpdateValidatorOwner action, TxBuilder txBuilder) throws TxBuilderException {
    txBuilder.down(ValidatorOwnerCopy.class, action.validatorKey());
    var curEpoch = txBuilder.readSystem(EpochData.class);
    txBuilder.up(new ValidatorOwnerCopy(OptionalLong.of(curEpoch.epoch() + 1), action.validatorKey(), action.ownerAddress()));
    txBuilder.end();
}
Also used : ValidatorOwnerCopy(com.radixdlt.application.validators.state.ValidatorOwnerCopy)

Example 2 with ValidatorOwnerCopy

use of com.radixdlt.application.validators.state.ValidatorOwnerCopy in project radixdlt by radixdlt.

the class ValidatorUpdateOwnerConstraintScrypt method main.

@Override
public void main(Loader os) {
    os.substate(new SubstateDefinition<>(ValidatorOwnerCopy.class, SubstateTypeId.VALIDATOR_OWNER_COPY.id(), buf -> {
        REFieldSerialization.deserializeReservedByte(buf);
        OptionalLong epochUpdate = REFieldSerialization.deserializeOptionalNonNegativeLong(buf);
        var key = REFieldSerialization.deserializeKey(buf);
        var owner = REFieldSerialization.deserializeAccountREAddr(buf);
        return new ValidatorOwnerCopy(epochUpdate, key, owner);
    }, (s, buf) -> {
        REFieldSerialization.serializeReservedByte(buf);
        REFieldSerialization.serializeOptionalLong(buf, s.epochUpdate());
        REFieldSerialization.serializeKey(buf, s.validatorKey());
        REFieldSerialization.serializeREAddr(buf, s.owner());
    }, buf -> REFieldSerialization.deserializeKey(buf), (k, buf) -> REFieldSerialization.serializeKey(buf, (ECPublicKey) k), k -> ValidatorOwnerCopy.createVirtual((ECPublicKey) k)));
    os.procedure(new DownProcedure<>(VoidReducerState.class, ValidatorOwnerCopy.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) -> ReducerResult.incomplete(new UpdatingOwnerNeedToReadEpoch(d.validatorKey()))));
    os.procedure(new ReadProcedure<>(UpdatingOwnerNeedToReadEpoch.class, EpochData.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
    }), (s, u, r) -> ReducerResult.incomplete(s.readEpoch(u))));
    os.procedure(new UpProcedure<>(UpdatingValidatorOwner.class, ValidatorOwnerCopy.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
    }), (s, u, c, r) -> {
        s.update(u);
        return ReducerResult.complete();
    }));
}
Also used : SubstateTypeId(com.radixdlt.atom.SubstateTypeId) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) ReducerResult(com.radixdlt.constraintmachine.ReducerResult) ReadProcedure(com.radixdlt.constraintmachine.ReadProcedure) VoidReducerState(com.radixdlt.constraintmachine.VoidReducerState) Loader(com.radixdlt.atomos.Loader) ReducerState(com.radixdlt.constraintmachine.ReducerState) REFieldSerialization(com.radixdlt.atom.REFieldSerialization) Authorization(com.radixdlt.constraintmachine.Authorization) SubstateDefinition(com.radixdlt.atomos.SubstateDefinition) PermissionLevel(com.radixdlt.constraintmachine.PermissionLevel) ECPublicKey(com.radixdlt.crypto.ECPublicKey) OptionalLong(java.util.OptionalLong) UpProcedure(com.radixdlt.constraintmachine.UpProcedure) ConstraintScrypt(com.radixdlt.atomos.ConstraintScrypt) ValidatorOwnerCopy(com.radixdlt.application.validators.state.ValidatorOwnerCopy) DownProcedure(com.radixdlt.constraintmachine.DownProcedure) ProcedureException(com.radixdlt.constraintmachine.exceptions.ProcedureException) EpochData(com.radixdlt.application.system.state.EpochData) EpochData(com.radixdlt.application.system.state.EpochData) VoidReducerState(com.radixdlt.constraintmachine.VoidReducerState) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) Authorization(com.radixdlt.constraintmachine.Authorization) ValidatorOwnerCopy(com.radixdlt.application.validators.state.ValidatorOwnerCopy) OptionalLong(java.util.OptionalLong)

Aggregations

ValidatorOwnerCopy (com.radixdlt.application.validators.state.ValidatorOwnerCopy)2 EpochData (com.radixdlt.application.system.state.EpochData)1 REFieldSerialization (com.radixdlt.atom.REFieldSerialization)1 SubstateTypeId (com.radixdlt.atom.SubstateTypeId)1 ConstraintScrypt (com.radixdlt.atomos.ConstraintScrypt)1 Loader (com.radixdlt.atomos.Loader)1 SubstateDefinition (com.radixdlt.atomos.SubstateDefinition)1 Authorization (com.radixdlt.constraintmachine.Authorization)1 DownProcedure (com.radixdlt.constraintmachine.DownProcedure)1 PermissionLevel (com.radixdlt.constraintmachine.PermissionLevel)1 ReadProcedure (com.radixdlt.constraintmachine.ReadProcedure)1 ReducerResult (com.radixdlt.constraintmachine.ReducerResult)1 ReducerState (com.radixdlt.constraintmachine.ReducerState)1 UpProcedure (com.radixdlt.constraintmachine.UpProcedure)1 VoidReducerState (com.radixdlt.constraintmachine.VoidReducerState)1 AuthorizationException (com.radixdlt.constraintmachine.exceptions.AuthorizationException)1 ProcedureException (com.radixdlt.constraintmachine.exceptions.ProcedureException)1 ECPublicKey (com.radixdlt.crypto.ECPublicKey)1 OptionalLong (java.util.OptionalLong)1