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 all 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
Expand Up @@ -152,7 +152,15 @@ enum AccountObjectType {
/**
* State account object type.
*/
STATE("state");
STATE("state"),
/**
* MPToken Issuance object type.
*/
MPT_ISSUANCE("mpt_issuance"),
/**
* MPToken object type.
*/
MP_TOKEN("mptoken");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.xrpl.xrpl4j.model.ledger.DidObject;
import org.xrpl.xrpl4j.model.ledger.EscrowObject;
import org.xrpl.xrpl4j.model.ledger.LedgerObject;
import org.xrpl.xrpl4j.model.ledger.MpTokenIssuanceObject;
import org.xrpl.xrpl4j.model.ledger.MpTokenObject;
import org.xrpl.xrpl4j.model.ledger.NfTokenPageObject;
import org.xrpl.xrpl4j.model.ledger.OfferObject;
import org.xrpl.xrpl4j.model.ledger.OracleObject;
Expand All @@ -25,6 +27,7 @@
import org.xrpl.xrpl4j.model.ledger.TicketObject;
import org.xrpl.xrpl4j.model.transactions.Address;
import org.xrpl.xrpl4j.model.transactions.Hash256;
import org.xrpl.xrpl4j.model.transactions.MpTokenIssuanceId;
import org.xrpl.xrpl4j.model.transactions.XChainBridge;

import java.util.Optional;
Expand Down Expand Up @@ -361,6 +364,42 @@ static LedgerEntryRequestParams<OracleObject> oracle(
.build();
}

/**
* Construct a {@link LedgerEntryRequestParams} that requests a {@link MpTokenIssuanceObject} ledger entry.
*
* @param issuanceId The {@link MpTokenIssuanceId} of the token.
* @param ledgerSpecifier A {@link LedgerSpecifier} indicating the ledger to query data from.
*
* @return A {@link LedgerEntryRequestParams} for {@link OracleObject}.
*/
static LedgerEntryRequestParams<MpTokenIssuanceObject> mpTokenIssuance(
MpTokenIssuanceId issuanceId,
LedgerSpecifier ledgerSpecifier
) {
return ImmutableLedgerEntryRequestParams.<MpTokenIssuanceObject>builder()
.mptIssuance(issuanceId)
.ledgerSpecifier(ledgerSpecifier)
.build();
}

/**
* Construct a {@link LedgerEntryRequestParams} that requests a {@link MpTokenObject} ledger entry.
*
* @param mpToken The {@link MpTokenLedgerEntryParams} specifying the MPToken.
* @param ledgerSpecifier A {@link LedgerSpecifier} indicating the ledger to query data from.
*
* @return A {@link LedgerEntryRequestParams} for {@link OracleObject}.
*/
static LedgerEntryRequestParams<MpTokenObject> mpToken(
MpTokenLedgerEntryParams mpToken,
LedgerSpecifier ledgerSpecifier
) {
return ImmutableLedgerEntryRequestParams.<MpTokenObject>builder()
.mpToken(mpToken)
.ledgerSpecifier(ledgerSpecifier)
.build();
}

/**
* Specifies the ledger version to request. A ledger version can be specified by ledger hash, numerical ledger index,
* or a shortcut value.
Expand Down Expand Up @@ -494,6 +533,12 @@ default boolean binary() {
*/
Optional<OracleLedgerEntryParams> oracle();

@JsonProperty("mpt_issuance")
Optional<MpTokenIssuanceId> mptIssuance();

@JsonProperty("mptoken")
Optional<MpTokenLedgerEntryParams> mpToken();

/**
* The {@link Class} of {@link T}. This field is helpful when telling Jackson how to deserialize rippled's response to
* a {@link T}.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.xrpl.xrpl4j.model.client.ledger;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.immutables.value.Value.Immutable;
import org.xrpl.xrpl4j.model.transactions.Address;
import org.xrpl.xrpl4j.model.transactions.MpTokenIssuanceId;

@Immutable
@JsonSerialize(as = ImmutableMpTokenLedgerEntryParams.class)
@JsonDeserialize(as = ImmutableMpTokenLedgerEntryParams.class)
public interface MpTokenLedgerEntryParams {

/**
* Construct a {@code MpTokenLedgerEntryParams} builder.
*
* @return An {@link ImmutableMpTokenLedgerEntryParams.Builder}.
*/
static ImmutableMpTokenLedgerEntryParams.Builder builder() {
return ImmutableMpTokenLedgerEntryParams.builder();
}

@JsonProperty("mpt_issuance_id")
MpTokenIssuanceId mpTokenIssuanceId();

Address account();

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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.immutables.value.Value.Immutable;
import org.xrpl.xrpl4j.model.flags.MpTokenFlags;
import org.xrpl.xrpl4j.model.transactions.Address;
import org.xrpl.xrpl4j.model.transactions.Hash256;
import org.xrpl.xrpl4j.model.transactions.MpTokenAmount;
import org.xrpl.xrpl4j.model.transactions.MpTokenObjectAmount;

import java.util.Optional;

@Immutable
@JsonSerialize(as = ImmutableMptHoldersMpToken.class)
@JsonDeserialize(as = ImmutableMptHoldersMpToken.class)
public interface MptHoldersMpToken {

/**
* Construct a {@code MptHoldersMpToken} builder.
*
* @return An {@link ImmutableMptHoldersMpToken.Builder}.
*/
static ImmutableMptHoldersMpToken.Builder builder() {
return ImmutableMptHoldersMpToken.builder();
}

Address account();

MpTokenFlags flags();

@JsonProperty("mpt_amount")
MpTokenObjectAmount mptAmount();

@JsonProperty("locked_amount")
Optional<MpTokenAmount> lockedAmount();

@JsonProperty("mptoken_index")
Hash256 mpTokenIndex();

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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.primitives.UnsignedInteger;
import org.immutables.value.Value.Immutable;
import org.xrpl.xrpl4j.model.client.common.LedgerSpecifier;
import org.xrpl.xrpl4j.model.transactions.Marker;
import org.xrpl.xrpl4j.model.transactions.MpTokenIssuanceId;

import java.util.Optional;

@Immutable
@JsonSerialize(as = ImmutableMptHoldersRequestParams.class)
@JsonDeserialize(as = ImmutableMptHoldersRequestParams.class)
public interface MptHoldersRequestParams {

/**
* Construct a {@code MptHoldersRequestParams} builder.
*
* @return An {@link ImmutableMptHoldersRequestParams.Builder}.
*/
static ImmutableMptHoldersRequestParams.Builder builder() {
return ImmutableMptHoldersRequestParams.builder();
}

@JsonProperty("mpt_issuance_id")
MpTokenIssuanceId mpTokenIssuanceId();

@JsonUnwrapped
LedgerSpecifier ledgerSpecifier();

Optional<Marker> marker();

Optional<UnsignedInteger> limit();

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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.primitives.UnsignedInteger;
import org.immutables.value.Value.Immutable;
import org.xrpl.xrpl4j.model.client.common.LedgerIndex;
import org.xrpl.xrpl4j.model.transactions.Marker;
import org.xrpl.xrpl4j.model.transactions.MpTokenIssuanceId;

import java.util.List;
import java.util.Optional;

@Immutable
@JsonSerialize(as = ImmutableMptHoldersResponse.class)
@JsonDeserialize(as = ImmutableMptHoldersResponse.class)
public interface MptHoldersResponse {

/**
* Construct a {@code MptHoldersResponse} builder.
*
* @return An {@link ImmutableMptHoldersResponse.Builder}.
*/
static ImmutableMptHoldersResponse.Builder builder() {
return ImmutableMptHoldersResponse.builder();
}

@JsonProperty("mpt_issuance_id")
MpTokenIssuanceId mpTokenIssuanceId();

@JsonProperty("mptokens")
List<MptHoldersMpToken> mpTokens();

Optional<Marker> marker();

Optional<UnsignedInteger> limit();

// FIXME: Is this always the field, or does clio also return `ledger_hash` and potentially `ledger_current_index`?
@JsonProperty("ledger_index")
LedgerIndex ledgerIndex();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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 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);
}

}
Loading
Loading