Skip to content

Commit d70d2dc

Browse files
authored
Add support for Permissioned DEX - XLS-0081d (#633)
* Add support for Permissioned DEX * Update existing transactions and ledger objects. * Add unit tests & ITs for Permissioned DEX * Update Meta objects for Credentials. * Update RPC request/response to hold a DomainID * Update checkstyle to allow `while` statements on the same line.
1 parent 898a21b commit d70d2dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2218
-591
lines changed

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/client/path/BookOffersOffer.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
import com.google.common.primitives.UnsignedInteger;
99
import org.immutables.value.Value;
1010
import org.xrpl.xrpl4j.model.flags.OfferFlags;
11+
import org.xrpl.xrpl4j.model.ledger.BookWrapper;
1112
import org.xrpl.xrpl4j.model.ledger.LedgerObject;
1213
import org.xrpl.xrpl4j.model.transactions.Address;
1314
import org.xrpl.xrpl4j.model.transactions.CurrencyAmount;
1415
import org.xrpl.xrpl4j.model.transactions.Hash256;
1516

1617
import java.math.BigDecimal;
18+
import java.util.List;
1719
import java.util.Optional;
1820

1921
/**
@@ -218,4 +220,21 @@ default Optional<BigDecimal> ownerFunds() {
218220
default BigDecimal quality() {
219221
return new BigDecimal(qualityString());
220222
}
221-
}
223+
224+
/**
225+
* The permissioned domain that the offer is part of.
226+
*
227+
* @return A {@link Hash256} representing DomainID.
228+
*/
229+
@JsonProperty("DomainID")
230+
Optional<Hash256> domainId();
231+
232+
/**
233+
* An additional list of order book directories that this offer belongs to. Currently, this field only applicable to
234+
* hybrid offers.
235+
*
236+
* @return A list of {@link BookWrapper} representing order book directories.
237+
*/
238+
@JsonProperty("AdditionalBooks")
239+
List<BookWrapper> additionalBooks();
240+
}

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/client/path/BookOffersRequestParams.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.xrpl.xrpl4j.model.client.common.LedgerSpecifier;
1111
import org.xrpl.xrpl4j.model.ledger.Issue;
1212
import org.xrpl.xrpl4j.model.transactions.Address;
13+
import org.xrpl.xrpl4j.model.transactions.Hash256;
1314

1415
import java.util.Optional;
1516

@@ -57,6 +58,16 @@ static ImmutableBookOffersRequestParams.Builder builder() {
5758
@JsonProperty("taker")
5859
Optional<Address> taker();
5960

61+
/**
62+
* The object ID of a PermissionedDomain object. If this field is provided, the response will include only valid
63+
* domain offers associated with that specific domain. If omitted, the response will include only hybrid and open
64+
* offers for the trading pair, excluding all domain-specific offers.
65+
*
66+
* @return An optionally-present {@link Hash256}.
67+
*/
68+
@JsonProperty("domain")
69+
Optional<Hash256> domain();
70+
6071
/**
6172
* Specifies the ledger version to request. A ledger version can be specified by ledger hash, numerical ledger index,
6273
* or a shortcut value.
@@ -74,4 +85,4 @@ static ImmutableBookOffersRequestParams.Builder builder() {
7485
* @return An optionally-present {@link UnsignedInteger}.
7586
*/
7687
Optional<UnsignedInteger> limit();
77-
}
88+
}

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/client/path/RipplePathFindRequestParams.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,6 +29,7 @@
2929
import org.xrpl.xrpl4j.model.client.common.LedgerSpecifier;
3030
import org.xrpl.xrpl4j.model.transactions.Address;
3131
import org.xrpl.xrpl4j.model.transactions.CurrencyAmount;
32+
import org.xrpl.xrpl4j.model.transactions.Hash256;
3233

3334
import java.util.List;
3435
import java.util.Optional;
@@ -72,9 +73,9 @@ static ImmutableRipplePathFindRequestParams.Builder builder() {
7273
* {@link CurrencyAmount} that the destination account would receive in a transaction.
7374
*
7475
* <p>Special case: You can specify "-1" (for XRP) or provide "-1" as the contents of
75-
* {@link org.xrpl.xrpl4j.model.transactions.IssuedCurrencyAmount#value()} (for non-XRP currencies).
76-
* This requests a path to deliver as much as possible, while spending no more than the amount specified in
77-
* {@link #sendMax()} (if provided).
76+
* {@link org.xrpl.xrpl4j.model.transactions.IssuedCurrencyAmount#value()} (for non-XRP currencies). This requests a
77+
* path to deliver as much as possible, while spending no more than the amount specified in {@link #sendMax()} (if
78+
* provided).
7879
*
7980
* @return A {@link CurrencyAmount} denoting the destination amount.
8081
*/
@@ -102,12 +103,21 @@ static ImmutableRipplePathFindRequestParams.Builder builder() {
102103
List<PathCurrency> sourceCurrencies();
103104

104105
/**
105-
* Specifies the ledger version to request. A ledger version can be specified by ledger hash,
106-
* numerical ledger index, or a shortcut value.
106+
* The object ID of a PermissionedDomain object. If this field is included, then only valid paths for this domain will
107+
* be returned.
108+
*
109+
* @return An optionally-present {@link Hash256}.
110+
*/
111+
@JsonProperty("domain")
112+
Optional<Hash256> domain();
113+
114+
/**
115+
* Specifies the ledger version to request. A ledger version can be specified by ledger hash, numerical ledger index,
116+
* or a shortcut value.
107117
*
108118
* @return A {@link LedgerSpecifier} specifying the ledger version to request.
109119
*/
110120
@JsonUnwrapped
111121
LedgerSpecifier ledgerSpecifier();
112-
113-
}
122+
123+
}

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/flags/OfferCreateFlags.java

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -47,6 +47,11 @@ public class OfferCreateFlags extends TransactionFlags {
4747
*/
4848
protected static final OfferCreateFlags SELL = new OfferCreateFlags(0x00080000L);
4949

50+
/**
51+
* Constant {@link OfferCreateFlags} for the {@code tfHybrid} flag.
52+
*/
53+
protected static final OfferCreateFlags HYBRID = new OfferCreateFlags(0x00100000L);
54+
5055
private OfferCreateFlags(long value) {
5156
super(value);
5257
}
@@ -79,21 +84,23 @@ private static OfferCreateFlags of(
7984
boolean tfPassive,
8085
boolean tfImmediateOrCancel,
8186
boolean tfFillOrKill,
82-
boolean tfSell
87+
boolean tfSell,
88+
boolean tfHybrid
8389
) {
8490
long value = Flags.of(
8591
tfFullyCanonicalSig ? TransactionFlags.FULLY_CANONICAL_SIG : UNSET,
8692
tfPassive ? PASSIVE : UNSET,
8793
tfImmediateOrCancel ? IMMEDIATE_OR_CANCEL : UNSET,
8894
tfFillOrKill ? FILL_OR_KILL : UNSET,
89-
tfSell ? SELL : UNSET
95+
tfSell ? SELL : UNSET,
96+
tfHybrid ? HYBRID : UNSET
9097
).getValue();
9198
return new OfferCreateFlags(value);
9299
}
93100

94101
/**
95-
* Construct an empty instance of {@link OfferCreateFlags}. Transactions with empty flags will
96-
* not be serialized with a {@code Flags} field.
102+
* Construct an empty instance of {@link OfferCreateFlags}. Transactions with empty flags will not be serialized with
103+
* a {@code Flags} field.
97104
*
98105
* @return An empty {@link OfferCreateFlags}.
99106
*/
@@ -102,8 +109,8 @@ public static OfferCreateFlags empty() {
102109
}
103110

104111
/**
105-
* If enabled, the offer does not consume offers that exactly match it, and instead becomes an
106-
* Offer object in the ledger. It still consumes offers that cross it.
112+
* If enabled, the offer does not consume offers that exactly match it, and instead becomes an Offer object in the
113+
* ledger. It still consumes offers that cross it.
107114
*
108115
* @return {@code true} if {@code tfPassive} is set, otherwise {@code false}.
109116
*/
@@ -112,10 +119,10 @@ public boolean tfPassive() {
112119
}
113120

114121
/**
115-
* Treat the offer as an Immediate or Cancel order . If enabled, the offer never becomes a ledger object:
116-
* it only tries to match existing offers in the ledger. If the offer cannot match any offers immediately,
117-
* it executes "successfully" without trading any currency. In this case, the transaction has the result code
118-
* tesSUCCESS, but creates no Offer objects in the ledger.
122+
* Treat the offer as an Immediate or Cancel order . If enabled, the offer never becomes a ledger object: it only
123+
* tries to match existing offers in the ledger. If the offer cannot match any offers immediately, it executes
124+
* "successfully" without trading any currency. In this case, the transaction has the result code tesSUCCESS, but
125+
* creates no Offer objects in the ledger.
119126
*
120127
* @return {@code true} if {@code tfImmediateOrCancel} is set, otherwise {@code false}.
121128
*/
@@ -124,10 +131,10 @@ public boolean tfImmediateOrCancel() {
124131
}
125132

126133
/**
127-
* Treat the offer as a Fill or Kill order . Only try to match existing offers in the ledger, and only do so if
128-
* the entire TakerPays quantity can be obtained. If the fix1578 amendment is enabled and the offer cannot be
129-
* executed when placed, the transaction has the result code tecKILLED; otherwise, the transaction uses the result
130-
* code tesSUCCESS even when it was killed without trading any currency.
134+
* Treat the offer as a Fill or Kill order . Only try to match existing offers in the ledger, and only do so if the
135+
* entire TakerPays quantity can be obtained. If the fix1578 amendment is enabled and the offer cannot be executed
136+
* when placed, the transaction has the result code tecKILLED; otherwise, the transaction uses the result code
137+
* tesSUCCESS even when it was killed without trading any currency.
131138
*
132139
* @return {@code true} if {@code tfFillOrKill} is set, otherwise {@code false}.
133140
*/
@@ -144,6 +151,14 @@ public boolean tfSell() {
144151
return this.isSet(OfferCreateFlags.SELL);
145152
}
146153

154+
/**
155+
* Indicates the offer is hybrid.
156+
*
157+
* @return {@code true} if {@code tfHybrid} is set, otherwise {@code false}.
158+
*/
159+
public boolean tfHybrid() {
160+
return this.isSet(OfferCreateFlags.HYBRID);
161+
}
147162

148163
/**
149164
* A builder class for {@link OfferCreateFlags} flags.
@@ -154,6 +169,7 @@ public static class Builder {
154169
private boolean tfImmediateOrCancel = false;
155170
private boolean tfFillOrKill = false;
156171
private boolean tfSell = false;
172+
private boolean tfHybrid = false;
157173

158174
/**
159175
* Set {@code tfPassive} to the given value.
@@ -203,6 +219,18 @@ public Builder tfSell(boolean tfSell) {
203219
return this;
204220
}
205221

222+
/**
223+
* Set {@code tfHybrid} to the given value.
224+
*
225+
* @param tfHybrid A boolean value.
226+
*
227+
* @return The same {@link Builder}.
228+
*/
229+
public Builder tfHybrid(boolean tfHybrid) {
230+
this.tfHybrid = tfHybrid;
231+
return this;
232+
}
233+
206234
/**
207235
* Build a new {@link OfferCreateFlags} from the current boolean values.
208236
*
@@ -214,8 +242,9 @@ public OfferCreateFlags build() {
214242
tfPassive,
215243
tfImmediateOrCancel,
216244
tfFillOrKill,
217-
tfSell
245+
tfSell,
246+
tfHybrid
218247
);
219248
}
220249
}
221-
}
250+
}

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/flags/OfferFlags.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -37,6 +37,11 @@ public class OfferFlags extends Flags {
3737
*/
3838
protected static final OfferFlags SELL = new OfferFlags(0x00020000);
3939

40+
/**
41+
* Constant {@link OfferFlags} for the {@code lsfHybrid} flag.
42+
*/
43+
protected static final OfferFlags HYBRID = new OfferFlags(0x00040000);
44+
4045
private OfferFlags(long value) {
4146
super(value);
4247
}
@@ -62,12 +67,21 @@ public boolean lsfPassive() {
6267
}
6368

6469
/**
65-
* The object was placed as a sell offer. This has no effect on the object in the ledger (because tfSell only
66-
* matters if you get a better rate than you asked for, which cannot happen after the object enters the ledger).
70+
* The object was placed as a sell offer. This has no effect on the object in the ledger (because tfSell only matters
71+
* if you get a better rate than you asked for, which cannot happen after the object enters the ledger).
6772
*
6873
* @return {@code true} if {@code lsfSell} is set, otherwise {@code false}.
6974
*/
7075
public boolean lsfSell() {
7176
return this.isSet(SELL);
7277
}
73-
}
78+
79+
/**
80+
* Indicates the offer is hybrid. (meaning it is part of both a domain and open order book).
81+
*
82+
* @return {@code true} if {@code lsfHybrid} is set, otherwise {@code false}.
83+
*/
84+
public boolean lsfHybrid() {
85+
return this.isSet(HYBRID);
86+
}
87+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.xrpl.xrpl4j.model.ledger;
2+
3+
/*-
4+
* ========================LICENSE_START=================================
5+
* xrpl4j :: model
6+
* %%
7+
* Copyright (C) 2020 - 2022 XRPL Foundation and its contributors
8+
* %%
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* =========================LICENSE_END==================================
21+
*/
22+
23+
import com.fasterxml.jackson.annotation.JsonProperty;
24+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
25+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
26+
import org.immutables.value.Value.Immutable;
27+
import org.xrpl.xrpl4j.model.transactions.Hash256;
28+
29+
/**
30+
* Object referencing a specific page of an offer directory.
31+
*/
32+
@Immutable
33+
@JsonSerialize(as = ImmutableBook.class)
34+
@JsonDeserialize(as = ImmutableBook.class)
35+
public interface Book {
36+
37+
/**
38+
* Construct a builder for this class.
39+
*
40+
* @return An {@link ImmutableBook.Builder}.
41+
*/
42+
static ImmutableBook.Builder builder() {
43+
return ImmutableBook.builder();
44+
}
45+
46+
/**
47+
* The ID of the Offer Directory that links to this offer.
48+
*
49+
* @return A {@link Hash256} containing the ID.
50+
*/
51+
@JsonProperty("BookDirectory")
52+
Hash256 bookDirectory();
53+
54+
/**
55+
* A hint indicating which page of the offer directory links to this object, in case the directory consists of
56+
* multiple pages.
57+
*
58+
* @return A {@link String} containing the hint.
59+
*/
60+
@JsonProperty("BookNode")
61+
String bookNode();
62+
63+
}

0 commit comments

Comments
 (0)