From d3592e42fa7bb0f7755b008603dfb7d86475a03f Mon Sep 17 00:00:00 2001 From: nkramer44 Date: Mon, 4 Dec 2023 10:25:33 -0500 Subject: [PATCH 1/8] take notes --- .../modules/BaseFeeDropsDeserializer.java | 48 +++++++++++ .../modules/BaseFeeDropsSerializer.java | 47 +++++++++++ .../xrpl4j/model/transactions/SetFee.java | 81 +++++++++++++++++-- .../xrpl4j/model/transactions/SetFeeTest.java | 33 +++++++- .../transactions/json/SetFeeJsonTests.java | 64 --------------- 5 files changed, 203 insertions(+), 70 deletions(-) create mode 100644 xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java create mode 100644 xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsSerializer.java delete mode 100644 xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/SetFeeJsonTests.java diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java new file mode 100644 index 000000000..d59d47396 --- /dev/null +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java @@ -0,0 +1,48 @@ +package org.xrpl.xrpl4j.model.jackson.modules; + +/*- + * ========================LICENSE_START================================= + * xrpl4j :: model + * %% + * Copyright (C) 2020 - 2022 XRPL Foundation and its contributors + * %% + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.google.common.primitives.UnsignedLong; +import org.xrpl.xrpl4j.model.transactions.Address; +import org.xrpl.xrpl4j.model.transactions.XrpCurrencyAmount; + +import java.io.IOException; + +/** + * Custom Jackson deserializer for {@link Address}es. + */ +public class BaseFeeDropsDeserializer extends StdDeserializer { + + /** + * No-args constructor. + */ + public BaseFeeDropsDeserializer() { + super(XrpCurrencyAmount.class); + } + + @Override + public XrpCurrencyAmount deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException { + return XrpCurrencyAmount.of(UnsignedLong.valueOf(jsonParser.getText(), 16)); + } +} diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsSerializer.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsSerializer.java new file mode 100644 index 000000000..d8926d1f0 --- /dev/null +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsSerializer.java @@ -0,0 +1,47 @@ +package org.xrpl.xrpl4j.model.jackson.modules; + +/*- + * ========================LICENSE_START================================= + * xrpl4j :: model + * %% + * Copyright (C) 2020 - 2022 XRPL Foundation and its contributors + * %% + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; +import org.xrpl.xrpl4j.model.transactions.Address; +import org.xrpl.xrpl4j.model.transactions.XrpCurrencyAmount; + +import java.io.IOException; + +/** + * Custom Jackson serializer for {@link Address}es. + */ +public class BaseFeeDropsSerializer extends StdScalarSerializer { + + /** + * No-args constructor. + */ + public BaseFeeDropsSerializer() { + super(XrpCurrencyAmount.class, false); + } + + @Override + public void serialize(XrpCurrencyAmount address, JsonGenerator gen, SerializerProvider provider) throws IOException { + gen.writeString(address.value().toString(16)); + } +} diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java index 65178f352..c4f1f8c2f 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java @@ -20,12 +20,17 @@ * =========================LICENSE_END================================== */ +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.google.common.primitives.UnsignedInteger; +import com.google.common.primitives.UnsignedLong; import org.immutables.value.Value; import org.xrpl.xrpl4j.model.client.common.LedgerIndex; +import org.xrpl.xrpl4j.model.jackson.modules.BaseFeeDropsDeserializer; +import org.xrpl.xrpl4j.model.jackson.modules.BaseFeeDropsSerializer; import java.util.Optional; @@ -45,6 +50,7 @@ public interface SetFee extends Transaction { * * @return An {@link ImmutableSetFee.Builder}. */ + // TODO say that we Assume no one will ever serialize a SetFee transaction to JSON... static ImmutableSetFee.Builder builder() { return ImmutableSetFee.builder(); } @@ -55,16 +61,63 @@ static ImmutableSetFee.Builder builder() { * * @return A hex {@link String} basefee value. */ - @JsonProperty("BaseFee") - String baseFee(); +// @JsonProperty("BaseFee") + @Value.Default + @Deprecated + @JsonIgnore + default String baseFee() { + return baseFeeDrops().value().toString(16); + } + + + /*@JsonProperty("BaseFeeDrops") + @JsonSerialize(using = BaseFeeDropsSerializer.class) + @JsonDeserialize(using = BaseFeeDropsDeserializer.class) + @Value.Default + default XrpCurrencyAmount baseFeeDrops() { + return XrpCurrencyAmount.of(UnsignedLong.valueOf(baseFee(), 16)); + }*/ + + @JsonProperty("BaseFeeDrops") + @JsonAlias({"BaseFee"}) + XrpCurrencyAmount baseFeeDrops(); + + /*@JsonProperty("BaseFee") + @Value.Default + default String baseFee() { + if isPostXrpFeesAmendment() { + return baseFeeDrops().toString(); + } else { + throw new RuntimeException(); + } + } + + @JsonProperty("BaseFeeDrops") + @Value.Default + default XrpCurrencyAmount baseFeeDrops() { + if isPostXrpFeesAmendment() { + throw new RuntimeException(); + } else { + return baseFee() + } + } + + @JsonIgnore + default boolean isPostXrpFeesAmendment() { + return false; + }*/ /** * The cost, in fee units, of the reference transaction. * * @return An {@link UnsignedInteger} cost of ref transaction. */ + // FIXME: Deprecate this and make it @Nullable. Add a new field Optional maybeReferenceFeeUnits() @JsonProperty("ReferenceFeeUnits") - UnsignedInteger referenceFeeUnits(); + @Value.Default + default UnsignedInteger referenceFeeUnits() { + return UnsignedInteger.ZERO; + } /** * The base reserve, in drops. @@ -72,7 +125,16 @@ static ImmutableSetFee.Builder builder() { * @return An {@link UnsignedInteger} base reverse value in {@link org.xrpl.xrpl4j.model.client.fees.FeeDrops}. */ @JsonProperty("ReserveBase") - UnsignedInteger reserveBase(); + @Value.Default + default UnsignedInteger reserveBase() { + return UnsignedInteger.valueOf(reserveBaseDrops().value().longValue()); + } + + @JsonProperty("ReserveBaseDrops") + @Value.Default + default XrpCurrencyAmount reserveBaseDrops() { + return XrpCurrencyAmount.ofDrops(reserveBase().longValue()); + } /** * The incremental reserve, in drops. @@ -80,7 +142,16 @@ static ImmutableSetFee.Builder builder() { * @return An {@link UnsignedInteger} incremental reserve in {@link org.xrpl.xrpl4j.model.client.fees.FeeDrops}. */ @JsonProperty("ReserveIncrement") - UnsignedInteger reserveIncrement(); + @Value.Default + default UnsignedInteger reserveIncrement() { + return UnsignedInteger.valueOf(reserveIncrementDrops().value().longValue()); + } + + @JsonProperty("ReserveIncrementDrops") + @Value.Default + default XrpCurrencyAmount reserveIncrementDrops() { + return XrpCurrencyAmount.ofDrops(reserveIncrement().longValue()); + } /** * The index of the ledger version where this pseudo-transaction appears. This distinguishes the pseudo-transaction diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java index dbf5c3118..41f576347 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java @@ -22,14 +22,17 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.fasterxml.jackson.core.JsonProcessingException; import com.google.common.primitives.UnsignedInteger; import com.google.common.primitives.UnsignedLong; +import org.json.JSONException; import org.junit.jupiter.api.Test; +import org.xrpl.xrpl4j.model.AbstractJsonTest; import org.xrpl.xrpl4j.model.client.common.LedgerIndex; import java.util.Optional; -public class SetFeeTest { +public class SetFeeTest extends AbstractJsonTest { @Test public void testBuilder() { @@ -53,4 +56,32 @@ public void testBuilder() { assertThat(setFee.reserveIncrement()).isEqualTo(UnsignedInteger.valueOf(5000000)); assertThat(setFee.reserveBase()).isEqualTo(UnsignedInteger.valueOf(20000000)); } + + @Test + public void testJson() throws JsonProcessingException, JSONException { + SetFee setFee = SetFee.builder() + .account(Address.of("rrrrrrrrrrrrrrrrrrrrrhoLvTp")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .sequence(UnsignedInteger.valueOf(2470665)) + .baseFee("000000000000000A") + .referenceFeeUnits(UnsignedInteger.valueOf(10)) + .reserveBase(UnsignedInteger.valueOf(20000000)) + .reserveIncrement(UnsignedInteger.valueOf(5000000)) + .ledgerSequence(Optional.of(LedgerIndex.of(UnsignedInteger.valueOf(67850752)))) + .build(); + + String json = "{" + + "\"Account\":\"rrrrrrrrrrrrrrrrrrrrrhoLvTp\"," + + "\"Fee\":\"12\"," + + "\"LedgerSequence\":67850752," + + "\"Sequence\":2470665," + + "\"SigningPubKey\":\"\"," + + "\"TransactionType\":\"SetFee\"," + + "\"ReserveIncrement\":5000000," + + "\"ReserveBase\":20000000," + + "\"ReferenceFeeUnits\":10," + + "\"BaseFee\":\"000000000000000A\"}"; + + assertCanSerializeAndDeserialize(setFee, json); + } } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/SetFeeJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/SetFeeJsonTests.java deleted file mode 100644 index 05e0fa594..000000000 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/SetFeeJsonTests.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.xrpl.xrpl4j.model.transactions.json; - -/*- - * ========================LICENSE_START================================= - * xrpl4j :: core - * %% - * Copyright (C) 2020 - 2023 XRPL Foundation and its contributors - * %% - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * =========================LICENSE_END================================== - */ - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.primitives.UnsignedInteger; -import org.json.JSONException; -import org.junit.jupiter.api.Test; -import org.xrpl.xrpl4j.model.AbstractJsonTest; -import org.xrpl.xrpl4j.model.client.common.LedgerIndex; -import org.xrpl.xrpl4j.model.transactions.Address; -import org.xrpl.xrpl4j.model.transactions.SetFee; -import org.xrpl.xrpl4j.model.transactions.XrpCurrencyAmount; - -import java.util.Optional; - -public class SetFeeJsonTests extends AbstractJsonTest { - - @Test - public void testJson() throws JsonProcessingException, JSONException { - SetFee setFee = SetFee.builder() - .account(Address.of("rrrrrrrrrrrrrrrrrrrrrhoLvTp")) - .fee(XrpCurrencyAmount.ofDrops(12)) - .sequence(UnsignedInteger.valueOf(2470665)) - .baseFee("000000000000000A") - .referenceFeeUnits(UnsignedInteger.valueOf(10)) - .reserveBase(UnsignedInteger.valueOf(20000000)) - .reserveIncrement(UnsignedInteger.valueOf(5000000)) - .ledgerSequence(Optional.of(LedgerIndex.of(UnsignedInteger.valueOf(67850752)))) - .build(); - - String json = "{" + - "\"Account\":\"rrrrrrrrrrrrrrrrrrrrrhoLvTp\"," + - "\"Fee\":\"12\"," + - "\"LedgerSequence\":67850752," + - "\"Sequence\":2470665," + - "\"SigningPubKey\":\"\"," + - "\"TransactionType\":\"SetFee\"," + - "\"ReserveIncrement\":5000000," + - "\"ReserveBase\":20000000," + - "\"ReferenceFeeUnits\":10," + - "\"BaseFee\":\"000000000000000A\"}"; - - assertCanSerializeAndDeserialize(setFee, json); - } -} From d86ce4b36c8c8b1bc4f945a850abf44ef1ee91c9 Mon Sep 17 00:00:00 2001 From: nkramer44 Date: Tue, 5 Dec 2023 14:52:22 -0500 Subject: [PATCH 2/8] adjust SetFee to work with post-XRPFees amendment format --- .../modules/BaseFeeDropsDeserializer.java | 48 ------- .../modules/BaseFeeDropsSerializer.java | 47 ------- .../xrpl4j/model/transactions/SetFee.java | 121 +++++++++--------- .../xrpl4j/model/transactions/SetFeeTest.java | 96 ++++++++++++-- 4 files changed, 146 insertions(+), 166 deletions(-) delete mode 100644 xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java delete mode 100644 xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsSerializer.java diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java deleted file mode 100644 index d59d47396..000000000 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.xrpl.xrpl4j.model.jackson.modules; - -/*- - * ========================LICENSE_START================================= - * xrpl4j :: model - * %% - * Copyright (C) 2020 - 2022 XRPL Foundation and its contributors - * %% - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * =========================LICENSE_END================================== - */ - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -import com.google.common.primitives.UnsignedLong; -import org.xrpl.xrpl4j.model.transactions.Address; -import org.xrpl.xrpl4j.model.transactions.XrpCurrencyAmount; - -import java.io.IOException; - -/** - * Custom Jackson deserializer for {@link Address}es. - */ -public class BaseFeeDropsDeserializer extends StdDeserializer { - - /** - * No-args constructor. - */ - public BaseFeeDropsDeserializer() { - super(XrpCurrencyAmount.class); - } - - @Override - public XrpCurrencyAmount deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException { - return XrpCurrencyAmount.of(UnsignedLong.valueOf(jsonParser.getText(), 16)); - } -} diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsSerializer.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsSerializer.java deleted file mode 100644 index d8926d1f0..000000000 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsSerializer.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.xrpl.xrpl4j.model.jackson.modules; - -/*- - * ========================LICENSE_START================================= - * xrpl4j :: model - * %% - * Copyright (C) 2020 - 2022 XRPL Foundation and its contributors - * %% - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * =========================LICENSE_END================================== - */ - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; -import org.xrpl.xrpl4j.model.transactions.Address; -import org.xrpl.xrpl4j.model.transactions.XrpCurrencyAmount; - -import java.io.IOException; - -/** - * Custom Jackson serializer for {@link Address}es. - */ -public class BaseFeeDropsSerializer extends StdScalarSerializer { - - /** - * No-args constructor. - */ - public BaseFeeDropsSerializer() { - super(XrpCurrencyAmount.class, false); - } - - @Override - public void serialize(XrpCurrencyAmount address, JsonGenerator gen, SerializerProvider provider) throws IOException { - gen.writeString(address.value().toString(16)); - } -} diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java index c4f1f8c2f..dfd508d0f 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java @@ -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. @@ -26,14 +26,13 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.google.common.primitives.UnsignedInteger; -import com.google.common.primitives.UnsignedLong; import org.immutables.value.Value; import org.xrpl.xrpl4j.model.client.common.LedgerIndex; -import org.xrpl.xrpl4j.model.jackson.modules.BaseFeeDropsDeserializer; -import org.xrpl.xrpl4j.model.jackson.modules.BaseFeeDropsSerializer; import java.util.Optional; +import javax.annotation.Nullable; + /** * A {@link SetFee} pseudo-transaction marks a change in transaction cost or reserve requirements as a result of Fee * Voting. @@ -50,7 +49,6 @@ public interface SetFee extends Transaction { * * @return An {@link ImmutableSetFee.Builder}. */ - // TODO say that we Assume no one will ever serialize a SetFee transaction to JSON... static ImmutableSetFee.Builder builder() { return ImmutableSetFee.builder(); } @@ -59,9 +57,10 @@ static ImmutableSetFee.Builder builder() { * The charge, in drops of XRP, for the reference transaction, as hex. (This is the transaction cost before scaling * for load.) * - * @return A hex {@link String} basefee value. + * @return A hex {@link String} baseFee value. + * + * @deprecated Prefer {@link #baseFeeDrops()} over this field. */ -// @JsonProperty("BaseFee") @Value.Default @Deprecated @JsonIgnore @@ -69,89 +68,95 @@ default String baseFee() { return baseFeeDrops().value().toString(16); } - - /*@JsonProperty("BaseFeeDrops") - @JsonSerialize(using = BaseFeeDropsSerializer.class) - @JsonDeserialize(using = BaseFeeDropsDeserializer.class) - @Value.Default - default XrpCurrencyAmount baseFeeDrops() { - return XrpCurrencyAmount.of(UnsignedLong.valueOf(baseFee(), 16)); - }*/ - + /** + * The charge, in drops of XRP, for the reference transaction (This is the transaction cost before scaling for load). + * + *

This field will also be populated with the {@code BaseFee} value from any {@link SetFee} transactions + * that occurred before the XRPFees amendment took effect.

+ * + * @return An {@link XrpCurrencyAmount}. + */ @JsonProperty("BaseFeeDrops") - @JsonAlias({"BaseFee"}) + @JsonAlias("BaseFee") XrpCurrencyAmount baseFeeDrops(); - /*@JsonProperty("BaseFee") - @Value.Default - default String baseFee() { - if isPostXrpFeesAmendment() { - return baseFeeDrops().toString(); - } else { - throw new RuntimeException(); - } - } - - @JsonProperty("BaseFeeDrops") - @Value.Default - default XrpCurrencyAmount baseFeeDrops() { - if isPostXrpFeesAmendment() { - throw new RuntimeException(); - } else { - return baseFee() - } - } - - @JsonIgnore - default boolean isPostXrpFeesAmendment() { - return false; - }*/ - /** - * The cost, in fee units, of the reference transaction. + * The cost, in fee units, of the reference transaction. This field can be {@code null} if this {@link SetFee} + * transaction was included in a ledger after the XRPFees amendment was enabled because this amendment removes the + * {@code ReferenceFeeUnits} field from the {@link SetFee} transaction. * * @return An {@link UnsignedInteger} cost of ref transaction. + * + * @deprecated Prefer {@link #maybeReferenceFeeUnits()} over this field. */ - // FIXME: Deprecate this and make it @Nullable. Add a new field Optional maybeReferenceFeeUnits() - @JsonProperty("ReferenceFeeUnits") + @Deprecated + @Nullable @Value.Default + @JsonIgnore default UnsignedInteger referenceFeeUnits() { - return UnsignedInteger.ZERO; + return maybeReferenceFeeUnits().orElse(null); } + /** + * The cost, in fee units, of the reference transaction, or empty if this {@link SetFee} transaction occurred after + * the XRPFees amendment was enabled. + * + * @return An optionally-present {@link UnsignedInteger}. + */ + @JsonProperty("ReferenceFeeUnits") + Optional maybeReferenceFeeUnits(); + /** * The base reserve, in drops. * - * @return An {@link UnsignedInteger} base reverse value in {@link org.xrpl.xrpl4j.model.client.fees.FeeDrops}. + * @return An {@link UnsignedInteger} base reserve value in {@link org.xrpl.xrpl4j.model.client.fees.FeeDrops}. + * + * @deprecated Prefer {@link #reserveBaseDrops()} over this field. */ - @JsonProperty("ReserveBase") @Value.Default + @Deprecated + @JsonIgnore default UnsignedInteger reserveBase() { return UnsignedInteger.valueOf(reserveBaseDrops().value().longValue()); } + /** + * The base reserve, as an {@link XrpCurrencyAmount}. + * + *

This field will also be populated with the {@code ReserveBase} value from any {@link SetFee} transactions + * that occurred before the XRPFees amendment took effect.

+ * + * @return An {@link XrpCurrencyAmount}. + */ @JsonProperty("ReserveBaseDrops") - @Value.Default - default XrpCurrencyAmount reserveBaseDrops() { - return XrpCurrencyAmount.ofDrops(reserveBase().longValue()); - } + @JsonAlias("ReserveBase") + XrpCurrencyAmount reserveBaseDrops(); /** * The incremental reserve, in drops. * * @return An {@link UnsignedInteger} incremental reserve in {@link org.xrpl.xrpl4j.model.client.fees.FeeDrops}. + * + * @deprecated Prefer {@link #reserveIncrementDrops()} over this field. */ - @JsonProperty("ReserveIncrement") + @Deprecated + @JsonIgnore @Value.Default default UnsignedInteger reserveIncrement() { return UnsignedInteger.valueOf(reserveIncrementDrops().value().longValue()); } + /** + * The incremental reserve, as an {@link XrpCurrencyAmount}. + * + *

This field will also be populated with the {@code ReserveIncrement} value from any {@link SetFee} transactions + * that occurred before the XRPFees amendment took effect.

+ * + * @return An {@link XrpCurrencyAmount}. + */ @JsonProperty("ReserveIncrementDrops") - @Value.Default - default XrpCurrencyAmount reserveIncrementDrops() { - return XrpCurrencyAmount.ofDrops(reserveIncrement().longValue()); - } + @JsonAlias("ReserveIncrement") + XrpCurrencyAmount reserveIncrementDrops(); /** * The index of the ledger version where this pseudo-transaction appears. This distinguishes the pseudo-transaction diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java index 41f576347..1743d80ac 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java @@ -35,15 +35,14 @@ public class SetFeeTest extends AbstractJsonTest { @Test - public void testBuilder() { + public void testConstructWithNoFeeUnits() { SetFee setFee = SetFee.builder() .account(Address.of("rrrrrrrrrrrrrrrrrrrrrhoLvTp")) .fee(XrpCurrencyAmount.ofDrops(12)) .sequence(UnsignedInteger.valueOf(2470665)) - .baseFee("000000000000000A") - .referenceFeeUnits(UnsignedInteger.valueOf(10)) - .reserveBase(UnsignedInteger.valueOf(20000000)) - .reserveIncrement(UnsignedInteger.valueOf(5000000)) + .baseFeeDrops(XrpCurrencyAmount.ofDrops(10)) + .reserveBaseDrops(XrpCurrencyAmount.ofDrops(20000000)) + .reserveIncrementDrops(XrpCurrencyAmount.ofDrops(5000000)) .ledgerSequence(Optional.of(LedgerIndex.of(UnsignedInteger.valueOf(67850752)))) .build(); @@ -52,21 +51,54 @@ public void testBuilder() { assertThat(setFee.fee().value()).isEqualTo(UnsignedLong.valueOf(12)); assertThat(setFee.sequence()).isEqualTo(UnsignedInteger.valueOf(2470665)); assertThat(setFee.ledgerSequence()).isNotEmpty().get().isEqualTo(LedgerIndex.of(UnsignedInteger.valueOf(67850752))); - assertThat(setFee.referenceFeeUnits()).isEqualTo(UnsignedInteger.valueOf(10)); + assertThat(setFee.baseFee()).isEqualTo("a"); + assertThat(setFee.baseFeeDrops()).isEqualTo(XrpCurrencyAmount.ofDrops(10)); + assertThat(setFee.referenceFeeUnits()).isNull(); + assertThat(setFee.maybeReferenceFeeUnits()).isEmpty(); assertThat(setFee.reserveIncrement()).isEqualTo(UnsignedInteger.valueOf(5000000)); + assertThat(setFee.reserveIncrementDrops()).isEqualTo(XrpCurrencyAmount.ofDrops(5000000)); assertThat(setFee.reserveBase()).isEqualTo(UnsignedInteger.valueOf(20000000)); + assertThat(setFee.reserveBaseDrops()).isEqualTo(XrpCurrencyAmount.ofDrops(20000000)); } @Test - public void testJson() throws JsonProcessingException, JSONException { + public void testConstructWithFeeUnits() { SetFee setFee = SetFee.builder() .account(Address.of("rrrrrrrrrrrrrrrrrrrrrhoLvTp")) .fee(XrpCurrencyAmount.ofDrops(12)) .sequence(UnsignedInteger.valueOf(2470665)) - .baseFee("000000000000000A") - .referenceFeeUnits(UnsignedInteger.valueOf(10)) - .reserveBase(UnsignedInteger.valueOf(20000000)) - .reserveIncrement(UnsignedInteger.valueOf(5000000)) + .baseFeeDrops(XrpCurrencyAmount.ofDrops(10)) + .reserveBaseDrops(XrpCurrencyAmount.ofDrops(20000000)) + .reserveIncrementDrops(XrpCurrencyAmount.ofDrops(5000000)) + .maybeReferenceFeeUnits(UnsignedInteger.valueOf(10)) + .ledgerSequence(Optional.of(LedgerIndex.of(UnsignedInteger.valueOf(67850752)))) + .build(); + + assertThat(setFee.transactionType()).isEqualTo(TransactionType.SET_FEE); + assertThat(setFee.account()).isEqualTo(Address.of("rrrrrrrrrrrrrrrrrrrrrhoLvTp")); + assertThat(setFee.fee().value()).isEqualTo(UnsignedLong.valueOf(12)); + assertThat(setFee.sequence()).isEqualTo(UnsignedInteger.valueOf(2470665)); + assertThat(setFee.ledgerSequence()).isNotEmpty().get().isEqualTo(LedgerIndex.of(UnsignedInteger.valueOf(67850752))); + assertThat(setFee.baseFee()).isEqualTo("a"); + assertThat(setFee.baseFeeDrops()).isEqualTo(XrpCurrencyAmount.ofDrops(10)); + assertThat(setFee.referenceFeeUnits()).isNotNull().isEqualTo(UnsignedInteger.valueOf(10)); + assertThat(setFee.maybeReferenceFeeUnits()).isNotEmpty().get().isEqualTo(UnsignedInteger.valueOf(10)); + assertThat(setFee.reserveIncrement()).isEqualTo(UnsignedInteger.valueOf(5000000)); + assertThat(setFee.reserveIncrementDrops()).isEqualTo(XrpCurrencyAmount.ofDrops(5000000)); + assertThat(setFee.reserveBase()).isEqualTo(UnsignedInteger.valueOf(20000000)); + assertThat(setFee.reserveBaseDrops()).isEqualTo(XrpCurrencyAmount.ofDrops(20000000)); + } + + @Test + public void testDeserializePreXrpFeesTransaction() throws JsonProcessingException { + SetFee expected = SetFee.builder() + .account(Address.of("rrrrrrrrrrrrrrrrrrrrrhoLvTp")) + .fee(XrpCurrencyAmount.ofDrops(12)) + .sequence(UnsignedInteger.valueOf(2470665)) + .baseFeeDrops(XrpCurrencyAmount.ofDrops(10)) + .maybeReferenceFeeUnits(UnsignedInteger.valueOf(10)) + .reserveBaseDrops(XrpCurrencyAmount.ofDrops(20000000)) + .reserveIncrementDrops(XrpCurrencyAmount.ofDrops(5000000)) .ledgerSequence(Optional.of(LedgerIndex.of(UnsignedInteger.valueOf(67850752)))) .build(); @@ -80,8 +112,46 @@ public void testJson() throws JsonProcessingException, JSONException { "\"ReserveIncrement\":5000000," + "\"ReserveBase\":20000000," + "\"ReferenceFeeUnits\":10," + - "\"BaseFee\":\"000000000000000A\"}"; + "\"BaseFee\":\"a\"}"; + + Transaction actual = objectMapper.readValue(json, Transaction.class); + assertThat(actual).isEqualTo(expected); + + String reserialized = objectMapper.writeValueAsString(actual); + Transaction redeserialized = objectMapper.readValue(reserialized, Transaction.class); + + assertThat(redeserialized).isEqualTo(expected); + } + + @Test + public void testDeserializePostXrpFeesTransaction() throws JsonProcessingException { + SetFee expected = SetFee.builder() + .account(Address.of("rrrrrrrrrrrrrrrrrrrrrhoLvTp")) + .fee(XrpCurrencyAmount.ofDrops(0)) + .sequence(UnsignedInteger.valueOf(0)) + .baseFeeDrops(XrpCurrencyAmount.ofDrops(10)) + .reserveBaseDrops(XrpCurrencyAmount.ofDrops(10000000)) + .reserveIncrementDrops(XrpCurrencyAmount.ofDrops(2000000)) + .ledgerSequence(Optional.of(LedgerIndex.of(UnsignedInteger.valueOf(66462465)))) + .build(); + + String json = "{\n" + + " \"Account\": \"rrrrrrrrrrrrrrrrrrrrrhoLvTp\",\n" + + " \"BaseFeeDrops\": \"10\",\n" + + " \"Fee\": \"0\",\n" + + " \"LedgerSequence\": 66462465,\n" + + " \"ReserveBaseDrops\": \"10000000\",\n" + + " \"ReserveIncrementDrops\": \"2000000\",\n" + + " \"Sequence\": 0,\n" + + " \"SigningPubKey\": \"\",\n" + + " \"TransactionType\": \"SetFee\"}"; + + Transaction actual = objectMapper.readValue(json, Transaction.class); + assertThat(actual).isEqualTo(expected); + + String reserialized = objectMapper.writeValueAsString(actual); + Transaction redeserialized = objectMapper.readValue(reserialized, Transaction.class); - assertCanSerializeAndDeserialize(setFee, json); + assertThat(redeserialized).isEqualTo(expected); } } From 4e29d83d522c1af3660c808b80456a886d16d0e7 Mon Sep 17 00:00:00 2001 From: nkramer44 Date: Tue, 5 Dec 2023 14:57:17 -0500 Subject: [PATCH 3/8] checkstyle --- .../src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java | 1 - 1 file changed, 1 deletion(-) diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java index dfd508d0f..3d4c26ed7 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java @@ -30,7 +30,6 @@ import org.xrpl.xrpl4j.model.client.common.LedgerIndex; import java.util.Optional; - import javax.annotation.Nullable; /** From a54ba7a5c60fce19cf300c4f75c2b5148ea3e919 Mon Sep 17 00:00:00 2001 From: nkramer44 Date: Tue, 5 Dec 2023 15:52:25 -0500 Subject: [PATCH 4/8] re introduce custom Deserializer for BaseFee/BaseFeeDrops because BaseFee is hex and BaseFeeDrops is decimal --- .../modules/BaseFeeDropsDeserializer.java | 53 +++++++++++++++++++ .../xrpl4j/model/transactions/SetFee.java | 2 + 2 files changed, 55 insertions(+) create mode 100644 xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java new file mode 100644 index 000000000..04ead38c3 --- /dev/null +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java @@ -0,0 +1,53 @@ +package org.xrpl.xrpl4j.model.jackson.modules; + +/*- + * ========================LICENSE_START================================= + * xrpl4j :: model + * %% + * Copyright (C) 2020 - 2022 XRPL Foundation and its contributors + * %% + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.google.common.primitives.UnsignedLong; +import org.xrpl.xrpl4j.model.transactions.XrpCurrencyAmount; + +import java.io.IOException; + +/** + * Custom Jackson deserializer for {@link XrpCurrencyAmount}s. + */ +public class BaseFeeDropsDeserializer extends StdDeserializer { + + /** + * No-args constructor. + */ + public BaseFeeDropsDeserializer() { + super(XrpCurrencyAmount.class); + } + + @Override + public XrpCurrencyAmount deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException { + // Pre-XRPFees SetFee transactions serialize `BaseFee` to a hex string. Post XRPFees SetFee transactions + // have a `BaseFeeDrops` field which is a decimal string. + if (jsonParser.currentName().equals("BaseFee")) { + return XrpCurrencyAmount.of(UnsignedLong.valueOf(jsonParser.getText(), 16)); + } else { + return XrpCurrencyAmount.ofDrops(jsonParser.getValueAsLong()); + } + } +} diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java index 3d4c26ed7..af1e539bd 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java @@ -28,6 +28,7 @@ import com.google.common.primitives.UnsignedInteger; import org.immutables.value.Value; import org.xrpl.xrpl4j.model.client.common.LedgerIndex; +import org.xrpl.xrpl4j.model.jackson.modules.BaseFeeDropsDeserializer; import java.util.Optional; import javax.annotation.Nullable; @@ -77,6 +78,7 @@ default String baseFee() { */ @JsonProperty("BaseFeeDrops") @JsonAlias("BaseFee") + @JsonDeserialize(using = BaseFeeDropsDeserializer.class) XrpCurrencyAmount baseFeeDrops(); /** From e5a77dd9a653f7597b149459a8a4d809b8075379 Mon Sep 17 00:00:00 2001 From: David Fuelling Date: Mon, 10 Jun 2024 14:17:06 -0400 Subject: [PATCH 5/8] Update Javadoc and comments --- .../jackson/modules/BaseFeeDropsDeserializer.java | 11 +++++++++-- .../org/xrpl/xrpl4j/model/transactions/SetFee.java | 3 ++- .../xrpl/xrpl4j/model/transactions/SetFeeTest.java | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java index 04ead38c3..0006b86e1 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java @@ -29,7 +29,14 @@ import java.io.IOException; /** - * Custom Jackson deserializer for {@link XrpCurrencyAmount}s. + * Custom Jackson deserializer for {@link XrpCurrencyAmount} instances found in {@link SetFee}. + *

+ * Before the XRPFees amendment, a {@link SetFee} + * transaction serializes its `BaseFee` to a hex string. After the + * XRPFees amendment, a {@link SetFee} transaction + * serializes its `BaseFee` to a decimal string. + * + * @see "https://xrpl.org/resources/known-amendments/#xrpfees" */ public class BaseFeeDropsDeserializer extends StdDeserializer { @@ -42,7 +49,7 @@ public BaseFeeDropsDeserializer() { @Override public XrpCurrencyAmount deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException { - // Pre-XRPFees SetFee transactions serialize `BaseFee` to a hex string. Post XRPFees SetFee transactions + // Pre-XRPFees, SetFee transactions serialize `BaseFee` to a hex string. Post XRPFees SetFee transactions // have a `BaseFeeDrops` field which is a decimal string. if (jsonParser.currentName().equals("BaseFee")) { return XrpCurrencyAmount.of(UnsignedLong.valueOf(jsonParser.getText(), 16)); diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java index af1e539bd..838bd7ba3 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java @@ -59,7 +59,8 @@ static ImmutableSetFee.Builder builder() { * * @return A hex {@link String} baseFee value. * - * @deprecated Prefer {@link #baseFeeDrops()} over this field. + * @deprecated Prefer {@link #baseFeeDrops()} over this field because the XRPFees ammendment now serializes this + * object's base fee into XRP drops. */ @Value.Default @Deprecated diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java index 1743d80ac..ea3703534 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java @@ -32,6 +32,9 @@ import java.util.Optional; +/** + * Unit tests for {@link SetFee}. + */ public class SetFeeTest extends AbstractJsonTest { @Test From 87469c96ce7a4f4cb8542d4bd424f5221a23ac4e Mon Sep 17 00:00:00 2001 From: nkramer44 Date: Wed, 16 Oct 2024 11:57:23 -0400 Subject: [PATCH 6/8] fix checkstyle --- .../xrpl/xrpl4j/model/client/ledger/LedgerEntryResult.java | 2 ++ .../model/jackson/modules/BaseFeeDropsDeserializer.java | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/client/ledger/LedgerEntryResult.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/client/ledger/LedgerEntryResult.java index 49d71c663..247a1b888 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/client/ledger/LedgerEntryResult.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/client/ledger/LedgerEntryResult.java @@ -26,6 +26,8 @@ public interface LedgerEntryResult extends XrplResult { /** * Construct a {@code LedgerEntryResult} builder. * + * @param The type of {@link LedgerObject}. + * * @return An {@link ImmutableLedgerEntryResult.Builder}. */ static ImmutableLedgerEntryResult.Builder builder() { diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java index 0006b86e1..e7d282fe0 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.java @@ -24,14 +24,15 @@ import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import com.google.common.primitives.UnsignedLong; +import org.xrpl.xrpl4j.model.transactions.SetFee; import org.xrpl.xrpl4j.model.transactions.XrpCurrencyAmount; import java.io.IOException; /** * Custom Jackson deserializer for {@link XrpCurrencyAmount} instances found in {@link SetFee}. - *

- * Before the XRPFees amendment, a {@link SetFee} + * + *

Before the XRPFees amendment, a {@link SetFee} * transaction serializes its `BaseFee` to a hex string. After the * XRPFees amendment, a {@link SetFee} transaction * serializes its `BaseFee` to a decimal string. From 58a20999f4912715b5fbd7c309cce429e66305da Mon Sep 17 00:00:00 2001 From: nkramer44 Date: Fri, 18 Oct 2024 10:23:55 -0400 Subject: [PATCH 7/8] break SetFee --- .../xrpl4j/model/transactions/SetFee.java | 50 +++++++------------ .../xrpl4j/model/transactions/SetFeeTest.java | 10 ++-- 2 files changed, 21 insertions(+), 39 deletions(-) diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java index 838bd7ba3..0c86c14d7 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java @@ -31,6 +31,7 @@ import org.xrpl.xrpl4j.model.jackson.modules.BaseFeeDropsDeserializer; import java.util.Optional; + import javax.annotation.Nullable; /** @@ -56,14 +57,13 @@ static ImmutableSetFee.Builder builder() { /** * The charge, in drops of XRP, for the reference transaction, as hex. (This is the transaction cost before scaling * for load.) + *

+ * This method only exists for historical purposes. When deserialized from a {@link SetFee} transaction from ledgers + * prior to the {@code XRPFees} amendment, this field will still be set based on {@link #baseFeeDrops()}. * * @return A hex {@link String} baseFee value. - * - * @deprecated Prefer {@link #baseFeeDrops()} over this field because the XRPFees ammendment now serializes this - * object's base fee into XRP drops. */ - @Value.Default - @Deprecated + @Value.Derived @JsonIgnore default String baseFee() { return baseFeeDrops().value().toString(16); @@ -83,40 +83,24 @@ default String baseFee() { XrpCurrencyAmount baseFeeDrops(); /** - * The cost, in fee units, of the reference transaction. This field can be {@code null} if this {@link SetFee} - * transaction was included in a ledger after the XRPFees amendment was enabled because this amendment removes the - * {@code ReferenceFeeUnits} field from the {@link SetFee} transaction. + * The cost, in fee units, of the reference transaction. {@link SetFee} transactions deserialized from ledgers prior + * to the {@code XRPFees} amendment will always have this field, but transactions deserialized from ledgers post + * {@code XRPFees} activation will never have this field. * * @return An {@link UnsignedInteger} cost of ref transaction. - * - * @deprecated Prefer {@link #maybeReferenceFeeUnits()} over this field. - */ - @Deprecated - @Nullable - @Value.Default - @JsonIgnore - default UnsignedInteger referenceFeeUnits() { - return maybeReferenceFeeUnits().orElse(null); - } - - /** - * The cost, in fee units, of the reference transaction, or empty if this {@link SetFee} transaction occurred after - * the XRPFees amendment was enabled. - * - * @return An optionally-present {@link UnsignedInteger}. */ @JsonProperty("ReferenceFeeUnits") - Optional maybeReferenceFeeUnits(); + Optional referenceFeeUnits(); /** * The base reserve, in drops. + *

+ * This method only exists for historical purposes. When deserialized from a {@link SetFee} transaction from ledgers + * prior to the {@code XRPFees} amendment, this field will still be set based on {@link #reserveBaseDrops()}}. * * @return An {@link UnsignedInteger} base reserve value in {@link org.xrpl.xrpl4j.model.client.fees.FeeDrops}. - * - * @deprecated Prefer {@link #reserveBaseDrops()} over this field. */ - @Value.Default - @Deprecated + @Value.Derived @JsonIgnore default UnsignedInteger reserveBase() { return UnsignedInteger.valueOf(reserveBaseDrops().value().longValue()); @@ -136,14 +120,14 @@ default UnsignedInteger reserveBase() { /** * The incremental reserve, in drops. + *

+ * This method only exists for historical purposes. When deserialized from a {@link SetFee} transaction from ledgers + * prior to the {@code XRPFees} amendment, this field will still be set based on {@link #reserveIncrementDrops()}. * * @return An {@link UnsignedInteger} incremental reserve in {@link org.xrpl.xrpl4j.model.client.fees.FeeDrops}. - * - * @deprecated Prefer {@link #reserveIncrementDrops()} over this field. */ - @Deprecated + @Value.Derived @JsonIgnore - @Value.Default default UnsignedInteger reserveIncrement() { return UnsignedInteger.valueOf(reserveIncrementDrops().value().longValue()); } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java index ea3703534..42018706f 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/SetFeeTest.java @@ -56,8 +56,7 @@ public void testConstructWithNoFeeUnits() { assertThat(setFee.ledgerSequence()).isNotEmpty().get().isEqualTo(LedgerIndex.of(UnsignedInteger.valueOf(67850752))); assertThat(setFee.baseFee()).isEqualTo("a"); assertThat(setFee.baseFeeDrops()).isEqualTo(XrpCurrencyAmount.ofDrops(10)); - assertThat(setFee.referenceFeeUnits()).isNull(); - assertThat(setFee.maybeReferenceFeeUnits()).isEmpty(); + assertThat(setFee.referenceFeeUnits()).isEmpty(); assertThat(setFee.reserveIncrement()).isEqualTo(UnsignedInteger.valueOf(5000000)); assertThat(setFee.reserveIncrementDrops()).isEqualTo(XrpCurrencyAmount.ofDrops(5000000)); assertThat(setFee.reserveBase()).isEqualTo(UnsignedInteger.valueOf(20000000)); @@ -73,7 +72,7 @@ public void testConstructWithFeeUnits() { .baseFeeDrops(XrpCurrencyAmount.ofDrops(10)) .reserveBaseDrops(XrpCurrencyAmount.ofDrops(20000000)) .reserveIncrementDrops(XrpCurrencyAmount.ofDrops(5000000)) - .maybeReferenceFeeUnits(UnsignedInteger.valueOf(10)) + .referenceFeeUnits(UnsignedInteger.valueOf(10)) .ledgerSequence(Optional.of(LedgerIndex.of(UnsignedInteger.valueOf(67850752)))) .build(); @@ -84,8 +83,7 @@ public void testConstructWithFeeUnits() { assertThat(setFee.ledgerSequence()).isNotEmpty().get().isEqualTo(LedgerIndex.of(UnsignedInteger.valueOf(67850752))); assertThat(setFee.baseFee()).isEqualTo("a"); assertThat(setFee.baseFeeDrops()).isEqualTo(XrpCurrencyAmount.ofDrops(10)); - assertThat(setFee.referenceFeeUnits()).isNotNull().isEqualTo(UnsignedInteger.valueOf(10)); - assertThat(setFee.maybeReferenceFeeUnits()).isNotEmpty().get().isEqualTo(UnsignedInteger.valueOf(10)); + assertThat(setFee.referenceFeeUnits()).isNotEmpty().get().isEqualTo(UnsignedInteger.valueOf(10)); assertThat(setFee.reserveIncrement()).isEqualTo(UnsignedInteger.valueOf(5000000)); assertThat(setFee.reserveIncrementDrops()).isEqualTo(XrpCurrencyAmount.ofDrops(5000000)); assertThat(setFee.reserveBase()).isEqualTo(UnsignedInteger.valueOf(20000000)); @@ -99,7 +97,7 @@ public void testDeserializePreXrpFeesTransaction() throws JsonProcessingExceptio .fee(XrpCurrencyAmount.ofDrops(12)) .sequence(UnsignedInteger.valueOf(2470665)) .baseFeeDrops(XrpCurrencyAmount.ofDrops(10)) - .maybeReferenceFeeUnits(UnsignedInteger.valueOf(10)) + .referenceFeeUnits(UnsignedInteger.valueOf(10)) .reserveBaseDrops(XrpCurrencyAmount.ofDrops(20000000)) .reserveIncrementDrops(XrpCurrencyAmount.ofDrops(5000000)) .ledgerSequence(Optional.of(LedgerIndex.of(UnsignedInteger.valueOf(67850752)))) From 50330acb4cee1b580d64b538b23af2a43748875f Mon Sep 17 00:00:00 2001 From: nkramer44 Date: Fri, 18 Oct 2024 10:26:10 -0400 Subject: [PATCH 8/8] checkstyle --- .../xrpl4j/model/transactions/SetFee.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java index 0c86c14d7..8b7ee2412 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/SetFee.java @@ -32,8 +32,6 @@ import java.util.Optional; -import javax.annotation.Nullable; - /** * A {@link SetFee} pseudo-transaction marks a change in transaction cost or reserve requirements as a result of Fee * Voting. @@ -57,9 +55,9 @@ static ImmutableSetFee.Builder builder() { /** * The charge, in drops of XRP, for the reference transaction, as hex. (This is the transaction cost before scaling * for load.) - *

- * This method only exists for historical purposes. When deserialized from a {@link SetFee} transaction from ledgers - * prior to the {@code XRPFees} amendment, this field will still be set based on {@link #baseFeeDrops()}. + * + *

This method only exists for historical purposes. When deserialized from a {@link SetFee} transaction from + * ledgers prior to the {@code XRPFees} amendment, this field will still be set based on {@link #baseFeeDrops()}. * * @return A hex {@link String} baseFee value. */ @@ -94,9 +92,9 @@ default String baseFee() { /** * The base reserve, in drops. - *

- * This method only exists for historical purposes. When deserialized from a {@link SetFee} transaction from ledgers - * prior to the {@code XRPFees} amendment, this field will still be set based on {@link #reserveBaseDrops()}}. + * + *

This method only exists for historical purposes. When deserialized from a {@link SetFee} transaction from + * ledgers prior to the {@code XRPFees} amendment, this field will still be set based on {@link #reserveBaseDrops()}}. * * @return An {@link UnsignedInteger} base reserve value in {@link org.xrpl.xrpl4j.model.client.fees.FeeDrops}. */ @@ -120,9 +118,10 @@ default UnsignedInteger reserveBase() { /** * The incremental reserve, in drops. - *

- * This method only exists for historical purposes. When deserialized from a {@link SetFee} transaction from ledgers - * prior to the {@code XRPFees} amendment, this field will still be set based on {@link #reserveIncrementDrops()}. + * + *

This method only exists for historical purposes. When deserialized from a {@link SetFee} transaction from + * ledgers prior to the {@code XRPFees} amendment, this field will still be set based on + * {@link #reserveIncrementDrops()}. * * @return An {@link UnsignedInteger} incremental reserve in {@link org.xrpl.xrpl4j.model.client.fees.FeeDrops}. */