Skip to content

Commit

Permalink
Merge branch 'main' of github.com:XRPLF/xrpl4j into df/add-unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
sappenin committed Aug 11, 2023
2 parents af6cdd6 + 42047e1 commit be66173
Show file tree
Hide file tree
Showing 57 changed files with 2,462 additions and 678 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.8.8</version>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>com.ripple.cryptoconditions</groupId>
Expand All @@ -74,7 +74,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.23.1</version>
<version>3.24.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -356,7 +356,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
<version>3.1.2</version>
<executions>
<execution>
<id>integration-tests</id>
Expand Down Expand Up @@ -445,7 +445,7 @@
<!-- org.jacoco:jacoc-maven-plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<version>0.8.8</version>
<version>0.8.10</version>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
Expand Down
22 changes: 22 additions & 0 deletions xrpl4j-client/src/main/java/org/xrpl/xrpl4j/client/XrplClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
import org.xrpl.xrpl4j.model.client.ledger.LedgerResult;
import org.xrpl.xrpl4j.model.client.nft.NftBuyOffersRequestParams;
import org.xrpl.xrpl4j.model.client.nft.NftBuyOffersResult;
import org.xrpl.xrpl4j.model.client.nft.NftInfoRequestParams;
import org.xrpl.xrpl4j.model.client.nft.NftInfoResult;
import org.xrpl.xrpl4j.model.client.nft.NftSellOffersRequestParams;
import org.xrpl.xrpl4j.model.client.nft.NftSellOffersResult;
import org.xrpl.xrpl4j.model.client.path.BookOffersRequestParams;
Expand Down Expand Up @@ -511,6 +513,26 @@ public NftSellOffersResult nftSellOffers(NftSellOffersRequestParams params) thro
return jsonRpcClient.send(request, NftSellOffersResult.class);
}

/**
* Returns information about a given NFT. This method is only supported on Clio servers. Sending this request to a
* Reporting Mode or rippled node will result in an exception.
*
* @param params The {@link NftInfoRequestParams} to send in the request.
*
* @return The {@link NftInfoResult} returned by the {@code nft_info} method call.
*
* @throws JsonRpcClientErrorException If {@code jsonRpcClient} throws an error, or if the request was made to a
* non-Clio node.
*/
public NftInfoResult nftInfo(NftInfoRequestParams params) throws JsonRpcClientErrorException {
JsonRpcRequest request = JsonRpcRequest.builder()
.method(XrplMethods.NFT_INFO)
.addParams(params)
.build();

return jsonRpcClient.send(request, NftInfoResult.class);
}

/**
* Get the {@link AccountObjectsResult} for the account specified in {@code params} by making an account_objects
* method call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
import org.xrpl.xrpl4j.model.client.ledger.LedgerResult;
import org.xrpl.xrpl4j.model.client.nft.NftBuyOffersRequestParams;
import org.xrpl.xrpl4j.model.client.nft.NftBuyOffersResult;
import org.xrpl.xrpl4j.model.client.nft.NftInfoRequestParams;
import org.xrpl.xrpl4j.model.client.nft.NftInfoResult;
import org.xrpl.xrpl4j.model.client.nft.NftSellOffersRequestParams;
import org.xrpl.xrpl4j.model.client.nft.NftSellOffersResult;
import org.xrpl.xrpl4j.model.client.path.BookOffersRequestParams;
Expand Down Expand Up @@ -1023,4 +1025,24 @@ public void nftSellOffers() throws JsonRpcClientErrorException {
assertThat(jsonRpcRequestArgumentCaptor.getValue().params().get(0)).isEqualTo(nftSellOffersRequestParams);
}

@Test
void nftInfo() throws JsonRpcClientErrorException {
NftInfoRequestParams params = NftInfoRequestParams.builder()
.nfTokenId(NfTokenId.of("000100001E962F495F07A990F4ED55ACCFEEF365DBAA76B6A048C0A200000007"))
.ledgerSpecifier(LedgerSpecifier.VALIDATED)
.build();

NftInfoResult mockResult = mock(NftInfoResult.class);
when(jsonRpcClientMock.send(
JsonRpcRequest.builder()
.method(XrplMethods.NFT_INFO)
.addParams(params)
.build(),
NftInfoResult.class
)).thenReturn(mockResult);

NftInfoResult result = xrplClient.nftInfo(params);

assertThat(result).isEqualTo(mockResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public class XrplMethods {
*/
public static final String NFT_SELL_OFFERS = "nft_sell_offers";

/**
* Constant for the nft_info Clio API method.
*/
public static final String NFT_INFO = "nft_info";

// Transaction methods
/**
* Constant for the <a href="https://xrpl.org/sign.html">sign</a> rippled API method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ static ImmutableBuyOffer.Builder builder() {
*
* @return The {@link CurrencyAmount}.
*/
@JsonProperty("Amount")
CurrencyAmount amount();

/**
Expand All @@ -62,7 +61,6 @@ static ImmutableBuyOffer.Builder builder() {
*
* @return The {@link NfTokenOfferFlags} for this object.
*/
@JsonProperty("Flags")
NfTokenOfferFlags flags();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
*/

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;
import org.xrpl.xrpl4j.model.client.XrplRequestParams;
import org.xrpl.xrpl4j.model.client.common.LedgerSpecifier;
import org.xrpl.xrpl4j.model.transactions.Marker;
import org.xrpl.xrpl4j.model.transactions.NfTokenId;

Expand Down Expand Up @@ -56,6 +58,21 @@ static ImmutableNftBuyOffersRequestParams.Builder builder() {
@JsonProperty("nft_id")
NfTokenId nfTokenId();

/**
* Specifies the ledger version to request. A ledger version can be specified by ledger hash,
* numerical ledger index, or a shortcut value.
*
* @return A {@link LedgerSpecifier} specifying the ledger version to request.
*/
@JsonUnwrapped
@Value.Default
// This field was missing in xrpl4j <= 3.1.2. Normally, this would be a required field, but in order
// to not make a breaking change, this needs to be defaulted. rippled will default to "validated" for you,
// so defaulting to LedgerSpecifier.VALIDATED preserves the existing 3.x.x behavior.
default LedgerSpecifier ledgerSpecifier() {
return LedgerSpecifier.VALIDATED;
}

/**
* Limit the number of buy offers for the {@link NfTokenId}. The server is not required to honor
* this value. Must be within the inclusive range 10 to 400.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
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;
import org.xrpl.xrpl4j.model.client.XrplResult;
import org.xrpl.xrpl4j.model.transactions.Marker;
import org.xrpl.xrpl4j.model.transactions.NfTokenId;

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

/**
* The result of an "nft_buy_offers" rippled API method call.
Expand Down Expand Up @@ -59,4 +62,19 @@ static ImmutableNftBuyOffersResult.Builder builder() {
* @return {@link List} of all {@link BuyOffer}s owned by an account.
*/
List<BuyOffer> offers();

/**
* The limit, as specified in the {@link NftBuyOffersRequestParams}.
*
* @return An optionally-present {@link UnsignedInteger}.
*/
Optional<UnsignedInteger> limit();

/**
* Server-defined value indicating the response is paginated. Pass this to the next call to resume where this
* call left off. Omitted when there are no additional pages after this one.
*
* @return An optionally-present {@link Marker} containing a marker.
*/
Optional<Marker> marker();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.xrpl.xrpl4j.model.client.nft;

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 org.immutables.value.Value.Immutable;
import org.xrpl.xrpl4j.model.client.XrplRequestParams;
import org.xrpl.xrpl4j.model.client.common.LedgerSpecifier;
import org.xrpl.xrpl4j.model.transactions.NfTokenId;

/**
* Request parameters for the {@code nft_info} RPC request. This request is only supported on Clio servers.
*/
@Immutable
@JsonSerialize(as = ImmutableNftInfoRequestParams.class)
@JsonDeserialize(as = ImmutableNftInfoRequestParams.class)
public interface NftInfoRequestParams extends XrplRequestParams {

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

/**
* A unique identifier for the non-fungible token (NFT).
*
* @return An {@link NfTokenId}.
*/
@JsonProperty("nft_id")
NfTokenId nfTokenId();

/**
* Specifies the ledger version to request. A ledger version can be specified by ledger hash, numerical ledger index,
* or a shortcut value.
*
* <p>Because {@code nft_info} is only supported on Clio nodes, and because Clio does not have access to non-validated
* ledgers, specifying a ledger that has not yet been validated, or specifying a ledger index shortcut other than
* {@link LedgerSpecifier#VALIDATED} will result in Clio returning an error.
*
* @return A {@link LedgerSpecifier} specifying the ledger version to request.
*/
@JsonUnwrapped
LedgerSpecifier ledgerSpecifier();

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

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 com.google.common.primitives.UnsignedLong;
import org.immutables.value.Value;
import org.xrpl.xrpl4j.model.client.XrplResult;
import org.xrpl.xrpl4j.model.client.common.LedgerIndex;
import org.xrpl.xrpl4j.model.flags.NfTokenFlags;
import org.xrpl.xrpl4j.model.transactions.Address;
import org.xrpl.xrpl4j.model.transactions.NfTokenId;
import org.xrpl.xrpl4j.model.transactions.NfTokenUri;
import org.xrpl.xrpl4j.model.transactions.TransferFee;

import java.util.Optional;

/**
* The result of an {@code nft_info} RPC call.
*/
@Value.Immutable
@JsonSerialize(as = ImmutableNftInfoResult.class)
@JsonDeserialize(as = ImmutableNftInfoResult.class)
public interface NftInfoResult extends XrplResult {

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

/**
* A unique identifier for the non-fungible token (NFT).
*
* @return An {@link NfTokenId}.
*/
@JsonProperty("nft_id")
NfTokenId nftId();

/**
* The ledger index of the most recent ledger version where the state of this NFT was modified, as in the NFT was
* minted (created), changed ownership (traded), or burned (destroyed). The information returned contains whatever
* happened most recently compared to the requested ledger.
*
* @return A {@link LedgerIndex}.
*/
@JsonProperty("ledger_index")
LedgerIndex ledgerIndex();

/**
* The account ID of this NFT's owner at this ledger index.
*
* @return An {@link Address}.
*/
Address owner();

/**
* Whether the NFT is burned at the request ledger.
*
* @return {@code true} if the NFT is burned at this ledger, or {@code false} otherwise.
*/
@JsonProperty("is_burned")
boolean burned();

/**
* The flag set of this NFT.
*
* @return An {@link NfTokenFlags}.
*/
NfTokenFlags flags();

/**
* The transfer fee of this NFT.
*
* @return A {@link TransferFee}.
*/
@JsonProperty("transfer_fee")
TransferFee transferFee();

/**
* The account ID which denotes the issuer of this NFT.
*
* @return An {@link Address}.
*/
Address issuer();

/**
* The NFT’s taxon.
*
* @return An {@link UnsignedLong} denoting the taxon.
*/
@JsonProperty("nft_taxon")
UnsignedLong nftTaxon();

/**
* The NFT’s sequence number.
*
* @return An {@link UnsignedInteger}.
*/
@JsonProperty("nft_serial")
UnsignedInteger nftSerial();

/**
* This field is empty if the NFT is not burned at this ledger but does not have a URI. If the NFT is not burned at
* this ledger, and it does have a URI, this field is a string containing the decoded URI of the NFT.
*
* <p>NOTE: If you need to retrieve the URI of a burnt token, re-request nft_info for this token, specifying the
* ledger_index as the one previous to the index where this token was burned.
*
* @return An optionally-present {@link NfTokenUri}.
*/
Optional<NfTokenUri> uri();

}
Loading

0 comments on commit be66173

Please sign in to comment.