Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nkramer44 committed Oct 18, 2024
1 parent 1ec7628 commit 8828d84
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ public static SerializedType<?> getTypeByName(String name) {
public static String getNameByType(SerializedType<?> type) {
return typeMap.entrySet()
.stream()
// We only care about the class name, and the String passed to .apply is only used to figure
// out the radix of the JSON string for UInt64Types. Plus this method is only used in a test.
.filter(entry -> entry.getValue().get().getClass().equals(type.getClass()))
.map(Map.Entry::getKey)
.findAny()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -35,8 +35,7 @@
public class UInt64Type extends UIntType<UInt64Type> {

/**
* These fields are represented as base 10 Strings in JSON, whereas all other STUInt64s are represented
* in base16.
* These fields are represented as base 10 Strings in JSON, whereas all other STUInt64s are represented in base16.
*/
protected static final Set<String> BASE_10_UINT64_FIELD_NAMES = Sets.newHashSet(
"MaximumAmount", "OutstandingAmount", "MPTAmount"
Expand Down Expand Up @@ -64,7 +63,6 @@ public UInt64Type fromJson(JsonNode value) {
@Override
public UInt64Type fromJson(JsonNode value, FieldInstance fieldInstance) {
int radix = getRadix(fieldInstance);
// STUInt64s are represented as hex-encoded Strings in JSON.
return new UInt64Type(UnsignedLong.valueOf(value.asText(), radix));
}

Expand All @@ -80,6 +78,14 @@ public JsonNode toJson(FieldInstance fieldInstance) {
return new TextNode(UnsignedLong.valueOf(toHex(), 16).toString(radix).toUpperCase());
}

/**
* Most UInt64s are represented as hex Strings in JSON. However, some MPT related fields are represented in base 10 in
* JSON. This method determines the radix of the field based on the supplied {@link FieldInstance}'s name.
*
* @param fieldInstance A {@link FieldInstance}.
*
* @return An int representing the radix.
*/
private static int getRadix(FieldInstance fieldInstance) {
int radix = 16;
if (BASE_10_UINT64_FIELD_NAMES.contains(fieldInstance.name())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.common.primitives.UnsignedLong;
import org.xrpl.xrpl4j.codec.addresses.ByteUtils;
import org.xrpl.xrpl4j.codec.addresses.UnsignedByteArray;
import org.xrpl.xrpl4j.codec.binary.definitions.FieldInstance;

/**
* Base codec for XRPL UInt types.
Expand All @@ -51,5 +50,4 @@ UnsignedLong valueOf() {
public JsonNode toJson() {
return new TextNode(UnsignedLong.valueOf(toHex(), 16).toString());
}

}

0 comments on commit 8828d84

Please sign in to comment.