forked from optimism-java/hildr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a444ed2
commit bf714f3
Showing
4 changed files
with
74 additions
and
14 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/main/java/io/optimism/config/ChainBigIntegerDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters