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();
}));
}
Aggregations