Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom bigInteger decoder #198

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.optimism.config;

import java.math.BigInteger;
import org.apache.commons.lang3.StringUtils;
import org.github.gestalt.config.decoder.DecoderContext;
import org.github.gestalt.config.decoder.LeafDecoder;
import org.github.gestalt.config.decoder.Priority;
import org.github.gestalt.config.entity.ValidationError;
import org.github.gestalt.config.node.ConfigNode;
import org.github.gestalt.config.reflect.TypeCapture;
import org.github.gestalt.config.tag.Tags;
import org.github.gestalt.config.utils.GResultOf;

/**
* Decode BigInteger field in Chain Config.
*/
public class ChainBigIntegerDecoder extends LeafDecoder<BigInteger> {

/**
* ChainBigIntegerDecoder constructor.
*/
public ChainBigIntegerDecoder() {}

@Override
protected GResultOf<BigInteger> leafDecode(String path, ConfigNode node, DecoderContext decoderContext) {
GResultOf<BigInteger> results;
String value = node.getValue().orElse("");
if (!org.github.gestalt.config.utils.StringUtils.isReal(value)) {
results = GResultOf.errors(new ValidationError.DecodingNumberParsing(path, node, name()));
} else {
try {
BigInteger bigInteger = new BigInteger(value);
results = GResultOf.result(bigInteger);
} catch (NumberFormatException e) {
results = GResultOf.errors(new ValidationError.DecodingNumberParsing(path, node, name()));
}
}
return results;
}

@Override
public Priority priority() {
return Priority.HIGH;
}

@Override
public String name() {
return "BigInteger-Cust";
}

@Override
public boolean canDecode(String path, Tags tags, ConfigNode configNode, TypeCapture<?> type) {
if (StringUtils.isEmpty(path)) {
return false;
}
return path.startsWith("config.chainConfig") && BigInteger.class.isAssignableFrom(type.getRawType());
}
}
22 changes: 10 additions & 12 deletions hildr-node/src/main/java/io/optimism/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,27 @@ public static Config create(Path configPath, CliConfig cliConfig, ChainConfig ch
MapConfigSource cliConfigSource = new MapConfigSource(cliProvider);

Gestalt gestalt;
final GestaltBuilder gestaltBuilder = new GestaltBuilder()
.addDefaultDecoders()
.addDecoder(new ChainBigIntegerDecoder())
.addConfigLoader(environmentVarsLoader)
.addConfigLoader(mapConfigLoader)
.addConfigLoader(tomlLoader)
.addConfigLoader(propertyLoader)
.setTreatMissingValuesAsErrors(false);
if (configPath != null) {
FileConfigSource tomlConfigSource = new FileConfigSource(configPath);
gestalt = new GestaltBuilder()
.addConfigLoader(environmentVarsLoader)
.addConfigLoader(mapConfigLoader)
.addConfigLoader(tomlLoader)
.addConfigLoader(propertyLoader)
gestalt = gestaltBuilder
.addSource(defaultProviderConfigSource)
.addSource(chainConfigSource)
.addSource(tomlConfigSource)
.addSource(cliConfigSource)
.setTreatMissingValuesAsErrors(false)
.build();
} else {
gestalt = new GestaltBuilder()
.addConfigLoader(environmentVarsLoader)
.addConfigLoader(mapConfigLoader)
.addConfigLoader(tomlLoader)
.addConfigLoader(propertyLoader)
gestalt = gestaltBuilder
.addSource(defaultProviderConfigSource)
.addSource(chainConfigSource)
.addSource(cliConfigSource)
.setTreatMissingValuesAsErrors(false)
.build();
}
gestalt.loadConfigs();
Expand Down
5 changes: 4 additions & 1 deletion hildr-node/src/test/resources/test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
l2RpcUrl = "https://example2.com"

[config.chainConfig]
seqWindowSize = 111_111_111
seqWindowSize = 111_111_111

[config.chainConfig.systemConfig]
l1FeeScalar = 452312848583266388373324160190187140051835877600158453279134670530344387928
Loading