Skip to content

Commit 898a21b

Browse files
authored
Add support for Permissioned Domains - XLS - 0080 (#629)
* Add Credential Ledger Object * Add Credential Ledger Entry * Update existing transactions * Add unit & integration tests
1 parent e48a8f6 commit 898a21b

29 files changed

+1623
-8
lines changed

checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<module name="RightCurly">
8282
<property name="option" value="alone"/>
8383
<property name="tokens"
84-
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
84+
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT, INSTANCE_INIT"/>
8585
</module>
8686
<module name="WhitespaceAround">
8787
<property name="allowEmptyConstructors" value="true"/>

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/crypto/signing/SignatureUtils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
import org.xrpl.xrpl4j.model.transactions.PaymentChannelClaim;
7171
import org.xrpl.xrpl4j.model.transactions.PaymentChannelCreate;
7272
import org.xrpl.xrpl4j.model.transactions.PaymentChannelFund;
73+
import org.xrpl.xrpl4j.model.transactions.PermissionedDomainDelete;
74+
import org.xrpl.xrpl4j.model.transactions.PermissionedDomainSet;
7375
import org.xrpl.xrpl4j.model.transactions.SetRegularKey;
7476
import org.xrpl.xrpl4j.model.transactions.SignerListSet;
7577
import org.xrpl.xrpl4j.model.transactions.SignerWrapper;
@@ -431,6 +433,14 @@ public <T extends Transaction> SingleSignedTransaction<T> addSignatureToTransact
431433
transactionWithSignature = CredentialDelete.builder().from((CredentialDelete) transaction)
432434
.transactionSignature(signature)
433435
.build();
436+
} else if (PermissionedDomainSet.class.isAssignableFrom(transaction.getClass())) {
437+
transactionWithSignature = PermissionedDomainSet.builder().from((PermissionedDomainSet) transaction)
438+
.transactionSignature(signature)
439+
.build();
440+
} else if (PermissionedDomainDelete.class.isAssignableFrom(transaction.getClass())) {
441+
transactionWithSignature = PermissionedDomainDelete.builder().from((PermissionedDomainDelete) transaction)
442+
.transactionSignature(signature)
443+
.build();
434444
} else {
435445
// Should never happen, but will in a unit test if we miss one.
436446
throw new IllegalArgumentException("Signing fields could not be added to the transaction.");
@@ -674,6 +684,14 @@ public <T extends Transaction> T addMultiSignaturesToTransaction(T transaction,
674684
transactionWithSignatures = CredentialDelete.builder().from((CredentialDelete) transaction)
675685
.signers(signers)
676686
.build();
687+
} else if (PermissionedDomainSet.class.isAssignableFrom(transaction.getClass())) {
688+
transactionWithSignatures = PermissionedDomainSet.builder().from((PermissionedDomainSet) transaction)
689+
.signers(signers)
690+
.build();
691+
} else if (PermissionedDomainDelete.class.isAssignableFrom(transaction.getClass())) {
692+
transactionWithSignatures = PermissionedDomainDelete.builder().from((PermissionedDomainDelete) transaction)
693+
.signers(signers)
694+
.build();
677695
} else {
678696
// Should never happen, but will in a unit test if we miss one.
679697
throw new IllegalArgumentException("Signing fields could not be added to the transaction.");

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/client/accounts/AccountObjectsRequestParams.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ enum AccountObjectType {
145145
* Payment channel account object type.
146146
*/
147147
PAYMENT_CHANNEL("payment_channel"),
148+
/**
149+
* Permissioned domain account object type.
150+
*/
151+
PERMISSIONED_DOMAIN("permissioned_domain"),
148152
/**
149153
* Signer list account object type.
150154
*/

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/client/ledger/LedgerEntryRequestParams.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.xrpl.xrpl4j.model.ledger.OfferObject;
2525
import org.xrpl.xrpl4j.model.ledger.OracleObject;
2626
import org.xrpl.xrpl4j.model.ledger.PayChannelObject;
27+
import org.xrpl.xrpl4j.model.ledger.PermissionedDomainObject;
2728
import org.xrpl.xrpl4j.model.ledger.RippleStateObject;
2829
import org.xrpl.xrpl4j.model.ledger.TicketObject;
2930
import org.xrpl.xrpl4j.model.transactions.Address;
@@ -426,6 +427,24 @@ static LedgerEntryRequestParams<MpTokenObject> mpToken(
426427
.build();
427428
}
428429

430+
/**
431+
* Construct a {@link LedgerEntryRequestParams} that requests a {@link PermissionedDomainObject} ledger entry.
432+
*
433+
* @param params The {@link PermissionedDomainLedgerEntryParams} specifying the Permissioned domain.
434+
* @param ledgerSpecifier A {@link LedgerSpecifier} indicating the ledger to query data from.
435+
*
436+
* @return A {@link LedgerEntryRequestParams} for {@link PermissionedDomainObject}.
437+
*/
438+
static LedgerEntryRequestParams<PermissionedDomainObject> permissionedDomain(
439+
PermissionedDomainLedgerEntryParams params,
440+
LedgerSpecifier ledgerSpecifier
441+
) {
442+
return ImmutableLedgerEntryRequestParams.<PermissionedDomainObject>builder()
443+
.permissionedDomain(params)
444+
.ledgerSpecifier(ledgerSpecifier)
445+
.build();
446+
}
447+
429448
/**
430449
* Specifies the ledger version to request. A ledger version can be specified by ledger hash, numerical ledger index,
431450
* or a shortcut value.
@@ -582,6 +601,15 @@ default boolean binary() {
582601
@JsonProperty("mptoken")
583602
Optional<MpTokenLedgerEntryParams> mpToken();
584603

604+
/**
605+
* Look up a {@link org.xrpl.xrpl4j.model.ledger.PermissionedDomainObject} by
606+
* {@link PermissionedDomainLedgerEntryParams}.
607+
*
608+
* @return An {@link Optional} {@link PermissionedDomainLedgerEntryParams}.
609+
*/
610+
@JsonProperty("permissioned_domain")
611+
Optional<PermissionedDomainLedgerEntryParams> permissionedDomain();
612+
585613
/**
586614
* The {@link Class} of {@link T}. This field is helpful when telling Jackson how to deserialize rippled's response to
587615
* a {@link T}.
@@ -655,6 +683,10 @@ default Class<T> ledgerObjectClass() {
655683
return (Class<T>) MpTokenObject.class;
656684
}
657685

686+
if (permissionedDomain().isPresent()) {
687+
return (Class<T>) PermissionedDomainObject.class;
688+
}
689+
658690
return (Class<T>) LedgerObject.class;
659691
}
660692
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.xrpl.xrpl4j.model.client.ledger;
2+
3+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
4+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
5+
import com.google.common.primitives.UnsignedInteger;
6+
import org.immutables.value.Value.Immutable;
7+
import org.xrpl.xrpl4j.model.transactions.Address;
8+
9+
/**
10+
* Parameters that uniquely identifies a {@link org.xrpl.xrpl4j.model.ledger.PermissionedDomainObject} on ledger that
11+
* can be used in a {@link LedgerEntryRequestParams} to request
12+
* {@link org.xrpl.xrpl4j.model.ledger.PermissionedDomainObject}.
13+
*/
14+
@Immutable
15+
@JsonSerialize(as = ImmutablePermissionedDomainLedgerEntryParams.class)
16+
@JsonDeserialize(as = ImmutablePermissionedDomainLedgerEntryParams.class)
17+
public interface PermissionedDomainLedgerEntryParams {
18+
19+
/**
20+
* Construct a {@code PermissionedDomainLedgerEntryParams} builder.
21+
*
22+
* @return An {@link ImmutablePermissionedDomainLedgerEntryParams.Builder}.
23+
*/
24+
static ImmutablePermissionedDomainLedgerEntryParams.Builder builder() {
25+
return ImmutablePermissionedDomainLedgerEntryParams.builder();
26+
}
27+
28+
/**
29+
* The owner of the permissioned domain.
30+
*
31+
* @return The unique {@link Address} of the owner of this
32+
* {@link org.xrpl.xrpl4j.model.ledger.PermissionedDomainObject}.
33+
*/
34+
Address account();
35+
36+
/**
37+
* The Sequence Number of the transaction that created the
38+
* {@link org.xrpl.xrpl4j.model.ledger.PermissionedDomainObject}.
39+
*
40+
* @return An {@link UnsignedInteger} representing transaction sequence.
41+
*/
42+
UnsignedInteger seq();
43+
}

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/ledger/LedgerObject.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
@JsonSubTypes.Type(value = ImmutableNfTokenOfferObject.class, name = "NFTokenOffer"),
5252
@JsonSubTypes.Type(value = ImmutableOfferObject.class, name = "Offer"),
5353
@JsonSubTypes.Type(value = ImmutablePayChannelObject.class, name = "PayChannel"),
54+
@JsonSubTypes.Type(value = ImmutablePermissionedDomainObject.class, name = "PermissionedDomain"),
5455
@JsonSubTypes.Type(value = ImmutableRippleStateObject.class, name = "RippleState"),
5556
@JsonSubTypes.Type(value = ImmutableSignerListObject.class, name = "SignerList"),
5657
@JsonSubTypes.Type(value = ImmutableTicketObject.class, name = "Ticket"),
@@ -138,6 +139,11 @@ enum LedgerEntryType {
138139
*/
139140
PAY_CHANNEL("PayChannel"),
140141

142+
/**
143+
* The {@link LedgerEntryType} for {@code PermissionedDomain} ledger objects.
144+
*/
145+
PERMISSIONED_DOMAIN("PermissionedDomain"),
146+
141147
/**
142148
* The {@link LedgerEntryType} for {@code RippleState} ledger objects.
143149
*/
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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 com.google.common.primitives.UnsignedInteger;
27+
import org.immutables.value.Value;
28+
import org.xrpl.xrpl4j.model.flags.Flags;
29+
import org.xrpl.xrpl4j.model.transactions.Address;
30+
import org.xrpl.xrpl4j.model.transactions.CredentialWrapper;
31+
import org.xrpl.xrpl4j.model.transactions.Hash256;
32+
33+
import java.util.List;
34+
35+
/**
36+
* This object represents a permissioned domain controlled by the {@link PermissionedDomainObject#owner}.
37+
*/
38+
@Value.Immutable
39+
@JsonSerialize(as = ImmutablePermissionedDomainObject.class)
40+
@JsonDeserialize(as = ImmutablePermissionedDomainObject.class)
41+
public interface PermissionedDomainObject extends LedgerObject {
42+
43+
/**
44+
* Construct a builder for this class.
45+
*
46+
* @return An {@link ImmutablePermissionedDomainObject.Builder}.
47+
*/
48+
static ImmutablePermissionedDomainObject.Builder builder() {
49+
return ImmutablePermissionedDomainObject.builder();
50+
}
51+
52+
/**
53+
* Indicates that this object is a {@link PermissionedDomainObject} object.
54+
*
55+
* @return Always {@link LedgerEntryType#PERMISSIONED_DOMAIN}.
56+
*/
57+
@JsonProperty("LedgerEntryType")
58+
@Value.Derived
59+
default LedgerEntryType ledgerEntryType() {
60+
return LedgerEntryType.PERMISSIONED_DOMAIN;
61+
}
62+
63+
/**
64+
* A bit-map of boolean flags. No flags are defined for {@link PermissionedDomainObject}, so this value is always 0.
65+
*
66+
* @return Always {@link Flags#UNSET}.
67+
*/
68+
@JsonProperty("Flags")
69+
@Value.Derived
70+
default Flags flags() {
71+
return Flags.UNSET;
72+
}
73+
74+
/**
75+
* The account that controls the settings of the domain.
76+
*
77+
* @return The {@link Address} of the domain owner.
78+
*/
79+
@JsonProperty("Owner")
80+
Address owner();
81+
82+
/**
83+
* A hint indicating which page of the sender's owner directory links to this object, in case the directory consists
84+
* of multiple pages.
85+
*
86+
* @return A {@link String} containing the owner node hint.
87+
*/
88+
@JsonProperty("OwnerNode")
89+
String ownerNode();
90+
91+
/**
92+
* The Sequence value of the {@link org.xrpl.xrpl4j.model.transactions.PermissionedDomainSet} transaction that created
93+
* this domain. Used in combination with the {@link PermissionedDomainObject#owner} to identify this domain.
94+
*
95+
* @return An {@link UnsignedInteger}.
96+
*/
97+
@JsonProperty("Sequence")
98+
UnsignedInteger sequence();
99+
100+
/**
101+
* The credentials that are accepted by the domain. Ownership of one of these credentials automatically makes you a
102+
* member of the domain.
103+
*
104+
* @return A list of {@link CredentialWrapper}.
105+
*/
106+
@JsonProperty("AcceptedCredentials")
107+
List<CredentialWrapper> acceptedCredentials();
108+
109+
/**
110+
* The identifying hash of the transaction that most recently modified this object.
111+
*
112+
* @return A {@link Hash256} containing the previous transaction hash.
113+
*/
114+
@JsonProperty("PreviousTxnID")
115+
Hash256 previousTxnId();
116+
117+
/**
118+
* The index of the ledger that contains the transaction that most recently modified this object.
119+
*
120+
* @return A {@link UnsignedInteger} representing the previous transaction sequence.
121+
*/
122+
@JsonProperty("PreviousTxnLgrSeq")
123+
UnsignedInteger previousTransactionLedgerSequence();
124+
125+
/**
126+
* The unique ID of the {@link PermissionedDomainObject}.
127+
*
128+
* @return A {@link Hash256}.
129+
*/
130+
Hash256 index();
131+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.xrpl.xrpl4j.model.transactions;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
5+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
6+
import org.immutables.value.Value;
7+
import org.xrpl.xrpl4j.model.flags.TransactionFlags;
8+
import org.xrpl.xrpl4j.model.ledger.PermissionedDomainObject;
9+
10+
/**
11+
* This transaction deletes a {@link PermissionedDomainObject}.
12+
*/
13+
@Value.Immutable
14+
@JsonSerialize(as = ImmutablePermissionedDomainDelete.class)
15+
@JsonDeserialize(as = ImmutablePermissionedDomainDelete.class)
16+
public interface PermissionedDomainDelete extends Transaction {
17+
18+
/**
19+
* Construct a {@code PermissionedDomainDelete} builder.
20+
*
21+
* @return An {@link ImmutablePermissionedDomainDelete.Builder}.
22+
*/
23+
static ImmutablePermissionedDomainDelete.Builder builder() {
24+
return ImmutablePermissionedDomainDelete.builder();
25+
}
26+
27+
/**
28+
* The ledger entry ID of an existing permissioned domain to delete.
29+
*
30+
* @return A {@link Hash256} representing DomainID.
31+
*/
32+
@JsonProperty("DomainID")
33+
Hash256 domainId();
34+
35+
/**
36+
* Set of {@link TransactionFlags}'s for this {@link PermissionedDomainDelete}, which only allows the
37+
* {@code tfFullyCanonicalSig} flag, which is deprecated.
38+
*
39+
* @return Always {@link TransactionFlags#EMPTY}.
40+
*/
41+
@JsonProperty("Flags")
42+
@Value.Default
43+
default TransactionFlags flags() {
44+
return TransactionFlags.EMPTY;
45+
}
46+
}

0 commit comments

Comments
 (0)