Skip to content

Commit e4efdc2

Browse files
authored
Merge branch 'main' into dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.12.1
2 parents 9af88a1 + 613339d commit e4efdc2

File tree

6 files changed

+451
-153
lines changed

6 files changed

+451
-153
lines changed

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/AmmWithdraw.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static ImmutableAmmWithdraw.Builder builder() {
9696
*
9797
* @return An optionally present {@link IssuedCurrencyAmount}.
9898
*/
99-
@JsonProperty("LPTokensIn")
99+
@JsonProperty("LPTokenIn")
100100
Optional<CurrencyAmount> lpTokensIn();
101101

102102
}

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/EscrowFinish.java

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import com.ripple.cryptoconditions.CryptoConditionReader;
3333
import com.ripple.cryptoconditions.CryptoConditionWriter;
3434
import com.ripple.cryptoconditions.Fulfillment;
35+
import com.ripple.cryptoconditions.PreimageSha256Fulfillment;
36+
import com.ripple.cryptoconditions.PreimageSha256Fulfillment.AbstractPreimageSha256Fulfillment;
3537
import com.ripple.cryptoconditions.der.DerEncodingException;
3638
import org.immutables.value.Value;
3739
import org.slf4j.Logger;
@@ -41,6 +43,7 @@
4143
import org.xrpl.xrpl4j.model.transactions.AccountSet.AccountSetFlag;
4244

4345
import java.util.Arrays;
46+
import java.util.Base64;
4447
import java.util.Locale;
4548
import java.util.Objects;
4649
import java.util.Optional;
@@ -69,25 +72,39 @@ static ImmutableEscrowFinish.Builder builder() {
6972
* transaction increases if it contains a fulfillment. If the transaction contains a fulfillment, the transaction cost
7073
* is 330 drops of XRP plus another 10 drops for every 16 bytes in size of the preimage.
7174
*
72-
* @param currentLedgerFeeDrops The number of drops that the ledger demands at present.
73-
* @param fulfillment The {@link Fulfillment} that is being presented to the ledger for computation
74-
* purposes.
75+
* @param currentLedgerBaseFeeDrops The number of drops that the ledger demands at present.
76+
* @param fulfillment The {@link Fulfillment} that is being presented to the ledger for computation
77+
* purposes.
7578
*
7679
* @return An {@link XrpCurrencyAmount} representing the computed fee.
7780
*
7881
* @see "https://xrpl.org/escrowfinish.html"
7982
*/
80-
static XrpCurrencyAmount computeFee(final XrpCurrencyAmount currentLedgerFeeDrops, final Fulfillment fulfillment) {
81-
Objects.requireNonNull(currentLedgerFeeDrops);
83+
static XrpCurrencyAmount computeFee(
84+
final XrpCurrencyAmount currentLedgerBaseFeeDrops,
85+
final Fulfillment<?> fulfillment
86+
) {
87+
Objects.requireNonNull(currentLedgerBaseFeeDrops);
8288
Objects.requireNonNull(fulfillment);
8389

84-
UnsignedLong newFee =
85-
currentLedgerFeeDrops.value() // <-- usually 10 drops, per the docs.
86-
// <-- https://github.com/ripple/rippled/blob/develop/src/ripple/app/tx/impl/Escrow.cpp#L362
87-
.plus(UnsignedLong.valueOf(320))
88-
// <-- 10 drops for each additional 16 bytes.
89-
.plus(UnsignedLong.valueOf(10 * (fulfillment.getDerivedCondition().getCost() / 16)));
90-
return XrpCurrencyAmount.of(newFee);
90+
if (PreimageSha256Fulfillment.class.isAssignableFrom(fulfillment.getClass())) {
91+
92+
final long fulfillmentByteSize = Base64.getUrlDecoder().decode(
93+
((PreimageSha256Fulfillment) fulfillment).getEncodedPreimage()
94+
).length;
95+
// See https://xrpl.org/docs/references/protocol/transactions/types/escrowfinish#escrowfinish-fields for
96+
// computing the additional fee for Escrows.
97+
// In particular: `extraFee = view.fees().base * (32 + (fb->size() / 16))`
98+
// See https://github.com/XRPLF/rippled/blob/master/src/xrpld/app/tx/detail/Escrow.cpp#L368
99+
final long baseFee = currentLedgerBaseFeeDrops.value().longValue();
100+
final long extraFeeDrops = baseFee * (32 + (fulfillmentByteSize / 16));
101+
final long totalFeeDrops = baseFee + extraFeeDrops; // <-- Add an extra base fee
102+
return XrpCurrencyAmount.of(
103+
UnsignedLong.valueOf(totalFeeDrops)
104+
);
105+
} else {
106+
throw new RuntimeException("Only PreimageSha256Fulfillment is supported.");
107+
}
91108
}
92109

93110
/**
@@ -144,11 +161,11 @@ default TransactionFlags flags() {
144161
*
145162
* <p>Note that a similar field does not exist on {@link EscrowCreate},
146163
* {@link org.xrpl.xrpl4j.model.ledger.EscrowObject}, or
147-
* {@link org.xrpl.xrpl4j.model.transactions.metadata.MetaEscrowObject} because {@link EscrowCreate}s with
148-
* malformed conditions will never be included in a ledger by the XRPL. Because of this fact, an
164+
* {@link org.xrpl.xrpl4j.model.transactions.metadata.MetaEscrowObject} because {@link EscrowCreate}s with malformed
165+
* conditions will never be included in a ledger by the XRPL. Because of this fact, an
149166
* {@link org.xrpl.xrpl4j.model.ledger.EscrowObject} and
150-
* {@link org.xrpl.xrpl4j.model.transactions.metadata.MetaEscrowObject} will also never contain a malformed
151-
* crypto condition.</p>
167+
* {@link org.xrpl.xrpl4j.model.transactions.metadata.MetaEscrowObject} will also never contain a malformed crypto
168+
* condition.</p>
152169
*
153170
* @return An {@link Optional} {@link String} containing the hex-encoded PREIMAGE-SHA-256 condition.
154171
*/
@@ -191,8 +208,8 @@ default TransactionFlags flags() {
191208
* <p>If {@link #condition()} is present but {@link #conditionRawValue()} is empty, we set
192209
* {@link #conditionRawValue()} to the underlying value of {@link #condition()}.</p>
193210
* <p>If {@link #condition()} is empty and {@link #conditionRawValue()} is present, we will set
194-
* {@link #condition()} to the {@link Condition} representing the raw condition value, or leave
195-
* {@link #condition()} empty if {@link #conditionRawValue()} is a malformed {@link Condition}.</p>
211+
* {@link #condition()} to the {@link Condition} representing the raw condition value, or leave {@link #condition()}
212+
* empty if {@link #conditionRawValue()} is a malformed {@link Condition}.</p>
196213
*
197214
* @return A normalized {@link EscrowFinish}.
198215
*/

0 commit comments

Comments
 (0)