Search in sources :

Example 1 with ReservedSymbolException

use of com.radixdlt.constraintmachine.exceptions.ReservedSymbolException 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();
    }));
}
Also used : SubstateTypeId(com.radixdlt.atom.SubstateTypeId) TokenResourceMetadata(com.radixdlt.application.tokens.state.TokenResourceMetadata) Loader(com.radixdlt.atomos.Loader) REFieldSerialization(com.radixdlt.atom.REFieldSerialization) TokenResource(com.radixdlt.application.tokens.state.TokenResource) Set(java.util.Set) TokensInAccount(com.radixdlt.application.tokens.state.TokensInAccount) SubstateDefinition(com.radixdlt.atomos.SubstateDefinition) StandardCharsets(java.nio.charset.StandardCharsets) com.radixdlt.constraintmachine(com.radixdlt.constraintmachine) ResourceCreatedEvent(com.radixdlt.constraintmachine.REEvent.ResourceCreatedEvent) ReservedSymbolException(com.radixdlt.constraintmachine.exceptions.ReservedSymbolException) SystemConstraintScrypt(com.radixdlt.application.system.scrypt.SystemConstraintScrypt) ConstraintScrypt(com.radixdlt.atomos.ConstraintScrypt) ProcedureException(com.radixdlt.constraintmachine.exceptions.ProcedureException) Pattern(java.util.regex.Pattern) DeserializeException(com.radixdlt.serialization.DeserializeException) UInt256(com.radixdlt.utils.UInt256) TokenResource(com.radixdlt.application.tokens.state.TokenResource) TokenResourceMetadata(com.radixdlt.application.tokens.state.TokenResourceMetadata) ReservedSymbolException(com.radixdlt.constraintmachine.exceptions.ReservedSymbolException) TokensInAccount(com.radixdlt.application.tokens.state.TokensInAccount) ProcedureException(com.radixdlt.constraintmachine.exceptions.ProcedureException)

Aggregations

SystemConstraintScrypt (com.radixdlt.application.system.scrypt.SystemConstraintScrypt)1 TokenResource (com.radixdlt.application.tokens.state.TokenResource)1 TokenResourceMetadata (com.radixdlt.application.tokens.state.TokenResourceMetadata)1 TokensInAccount (com.radixdlt.application.tokens.state.TokensInAccount)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 com.radixdlt.constraintmachine (com.radixdlt.constraintmachine)1 ResourceCreatedEvent (com.radixdlt.constraintmachine.REEvent.ResourceCreatedEvent)1 ProcedureException (com.radixdlt.constraintmachine.exceptions.ProcedureException)1 ReservedSymbolException (com.radixdlt.constraintmachine.exceptions.ReservedSymbolException)1 DeserializeException (com.radixdlt.serialization.DeserializeException)1 UInt256 (com.radixdlt.utils.UInt256)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1