-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into df/add-unit-test-for-sig
- Loading branch information
Showing
6 changed files
with
246 additions
and
84 deletions.
There are no files selected for viewing
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
61 changes: 61 additions & 0 deletions
61
...4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/BaseFeeDropsDeserializer.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,61 @@ | ||
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.SetFee; | ||
import org.xrpl.xrpl4j.model.transactions.XrpCurrencyAmount; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Custom Jackson deserializer for {@link XrpCurrencyAmount} instances found in {@link SetFee}. | ||
* | ||
* <p>Before the <a href="https://xrpl.org/resources/known-amendments/#xrpfees">XRPFees amendment</a>, a {@link SetFee} | ||
* transaction serializes its `BaseFee` to a hex string. After the | ||
* <a href="https://xrpl.org/resources/known-amendments/#xrpfees">XRPFees amendment</a>, a {@link SetFee} transaction | ||
* serializes its `BaseFee` to a decimal string. | ||
* | ||
* @see "https://xrpl.org/resources/known-amendments/#xrpfees" | ||
*/ | ||
public class BaseFeeDropsDeserializer extends StdDeserializer<XrpCurrencyAmount> { | ||
|
||
/** | ||
* 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()); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.