Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: MPT Support #558

Draft
wants to merge 15 commits into
base: mpt-amounts
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
import org.xrpl.xrpl4j.model.transactions.EscrowCancel;
import org.xrpl.xrpl4j.model.transactions.EscrowCreate;
import org.xrpl.xrpl4j.model.transactions.EscrowFinish;
import org.xrpl.xrpl4j.model.transactions.MpTokenAuthorize;
import org.xrpl.xrpl4j.model.transactions.MpTokenIssuanceCreate;
import org.xrpl.xrpl4j.model.transactions.MpTokenIssuanceDestroy;
import org.xrpl.xrpl4j.model.transactions.MpTokenIssuanceSet;
import org.xrpl.xrpl4j.model.transactions.NfTokenAcceptOffer;
import org.xrpl.xrpl4j.model.transactions.NfTokenBurn;
import org.xrpl.xrpl4j.model.transactions.NfTokenCancelOffer;
Expand Down Expand Up @@ -391,6 +395,22 @@ public <T extends Transaction> SingleSignedTransaction<T> addSignatureToTransact
transactionWithSignature = OracleDelete.builder().from((OracleDelete) transaction)
.transactionSignature(signature)
.build();
} else if (MpTokenAuthorize.class.isAssignableFrom(transaction.getClass())) {
transactionWithSignature = MpTokenAuthorize.builder().from((MpTokenAuthorize) transaction)
.transactionSignature(signature)
.build();
} else if (MpTokenIssuanceCreate.class.isAssignableFrom(transaction.getClass())) {
transactionWithSignature = MpTokenIssuanceCreate.builder().from((MpTokenIssuanceCreate) transaction)
.transactionSignature(signature)
.build();
} else if (MpTokenIssuanceDestroy.class.isAssignableFrom(transaction.getClass())) {
transactionWithSignature = MpTokenIssuanceDestroy.builder().from((MpTokenIssuanceDestroy) transaction)
.transactionSignature(signature)
.build();
} else if (MpTokenIssuanceSet.class.isAssignableFrom(transaction.getClass())) {
transactionWithSignature = MpTokenIssuanceSet.builder().from((MpTokenIssuanceSet) transaction)
.transactionSignature(signature)
.build();
} else {
// Should never happen, but will in a unit test if we miss one.
throw new IllegalArgumentException("Signing fields could not be added to the transaction.");
Expand Down Expand Up @@ -602,6 +622,22 @@ public <T extends Transaction> T addMultiSignaturesToTransaction(T transaction,
transactionWithSignatures = OracleDelete.builder().from((OracleDelete) transaction)
.signers(signers)
.build();
} else if (MpTokenAuthorize.class.isAssignableFrom(transaction.getClass())) {
transactionWithSignatures = MpTokenAuthorize.builder().from((MpTokenAuthorize) transaction)
.signers(signers)
.build();
} else if (MpTokenIssuanceCreate.class.isAssignableFrom(transaction.getClass())) {
transactionWithSignatures = MpTokenIssuanceCreate.builder().from((MpTokenIssuanceCreate) transaction)
.signers(signers)
.build();
} else if (MpTokenIssuanceDestroy.class.isAssignableFrom(transaction.getClass())) {
transactionWithSignatures = MpTokenIssuanceDestroy.builder().from((MpTokenIssuanceDestroy) transaction)
.signers(signers)
.build();
} else if (MpTokenIssuanceSet.class.isAssignableFrom(transaction.getClass())) {
transactionWithSignatures = MpTokenIssuanceSet.builder().from((MpTokenIssuanceSet) transaction)
.signers(signers)
.build();
} else {
// Should never happen, but will in a unit test if we miss one.
throw new IllegalArgumentException("Signing fields could not be added to the transaction.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.xrpl.xrpl4j.model.flags;

/*-
* ========================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==================================
*/

/**
* A set of static {@link TransactionFlags} which can be set on
* {@link org.xrpl.xrpl4j.model.transactions.MpTokenAuthorize} transactions.
*/
@SuppressWarnings("abbreviationaswordinname")
public class MpTokenAuthorizeFlags extends TransactionFlags {

/**
* Constant {@link MpTokenAuthorizeFlags} for the {@code tfMPTLock} flag.
*/
public static final MpTokenAuthorizeFlags UNAUTHORIZE = new MpTokenAuthorizeFlags(0x00000001);

private MpTokenAuthorizeFlags(long value) {
super(value);
}

private MpTokenAuthorizeFlags() {
}

/**
* Construct {@link MpTokenAuthorizeFlags} with a given value.
*
* @param value The long-number encoded flags value of this {@link MpTokenAuthorizeFlags}.
*
* @return New {@link MpTokenAuthorizeFlags}.
*/
public static MpTokenAuthorizeFlags of(long value) {
nkramer44 marked this conversation as resolved.
Show resolved Hide resolved
return new MpTokenAuthorizeFlags(value);
}

/**
* Construct an empty instance of {@link MpTokenAuthorizeFlags}. Transactions with empty flags will not be serialized
* with a {@code Flags} field.
*
* @return An empty {@link MpTokenAuthorizeFlags}.
*/
public static MpTokenAuthorizeFlags empty() {
return new MpTokenAuthorizeFlags();
}

/**
* If set and transaction is submitted by a holder, it indicates that the holder no longer wants to hold the MPToken,
* which will be deleted as a result. If the the holder's MPToken has non-zero balance while trying to set this flag,
* the transaction will fail. On the other hand, if set and transaction is submitted by an issuer, it would mean that
* the issuer wants to unauthorize the holder (only applicable for allow-listing), which would unset the
* lsfMPTAuthorized flag on the MPToken.
*
* @return {@code true} if {@code tfMPTUnauthorize} is set, otherwise {@code false}.
*/
public boolean tfMptUnauthorize() {
return this.isSet(UNAUTHORIZE);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.xrpl.xrpl4j.model.flags;

/*-
* ========================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==================================
*/


/**
* A set of static {@link Flags} which can be set on {@link org.xrpl.xrpl4j.model.ledger.MpTokenObject}s.
*/
public class MpTokenFlags extends Flags {

/**
* Constant for an unset flag.
*/
public static final MpTokenFlags UNSET = new MpTokenFlags(0);

/**
* Constant {@link MpTokenFlags} for the {@code lsfMPTLocked} account flag.
*/
public static final MpTokenFlags LOCKED = new MpTokenFlags(0x00000001);
/**
* Constant {@link MpTokenFlags} for the {@code lsfMPTCanLock} account flag.
*/
public static final MpTokenFlags AUTHORIZED = new MpTokenFlags(0x00000002);

/**
* Required-args Constructor.
*
* @param value The long-number encoded flags value of this {@link MpTokenFlags}.
*/
private MpTokenFlags(final long value) {
super(value);
}

/**
* Construct {@link MpTokenFlags} with a given value.
*
* @param value The long-number encoded flags value of this {@link MpTokenFlags}.
*
* @return New {@link MpTokenFlags}.
*/
public static MpTokenFlags of(long value) {
nkramer44 marked this conversation as resolved.
Show resolved Hide resolved
return new MpTokenFlags(value);
}

/**
* If set, indicates that all balances are locked.
*
* @return {@code true} if {@code lsfMPTLocked} is set, otherwise {@code false}.
*/
public boolean lsfMptLocked() {
return this.isSet(MpTokenFlags.LOCKED);
}

/**
* (Only applicable for allow-listing) If set, indicates that the issuer has authorized the holder for the MPT. This
* flag can be set using a MPTokenAuthorize transaction; it can also be "un-set" using a MPTokenAuthorize transaction
* specifying the tfMPTUnauthorize flag.
*
* @return {@code true} if {@code lsfMPTAuthorized} is set, otherwise {@code false}.
*/
public boolean lsfMptAuthorized() {
return this.isSet(MpTokenFlags.AUTHORIZED);
}

}
Loading
Loading