Skip to content

Commit

Permalink
Add support for ledger_entry RPC (#489)
Browse files Browse the repository at this point in the history
* Add support for ledger_entry RPC

* use ledgerEntry in ITs
  • Loading branch information
nkramer44 authored Nov 27, 2023
1 parent 7ce8e7f commit 76fa607
Show file tree
Hide file tree
Showing 29 changed files with 2,800 additions and 215 deletions.
26 changes: 26 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 @@ -62,6 +62,8 @@
import org.xrpl.xrpl4j.model.client.common.LedgerIndex;
import org.xrpl.xrpl4j.model.client.common.LedgerSpecifier;
import org.xrpl.xrpl4j.model.client.fees.FeeResult;
import org.xrpl.xrpl4j.model.client.ledger.LedgerEntryRequestParams;
import org.xrpl.xrpl4j.model.client.ledger.LedgerEntryResult;
import org.xrpl.xrpl4j.model.client.ledger.LedgerRequestParams;
import org.xrpl.xrpl4j.model.client.ledger.LedgerResult;
import org.xrpl.xrpl4j.model.client.nft.NftBuyOffersRequestParams;
Expand Down Expand Up @@ -89,6 +91,7 @@
import org.xrpl.xrpl4j.model.client.transactions.TransactionResult;
import org.xrpl.xrpl4j.model.immutables.FluentCompareTo;
import org.xrpl.xrpl4j.model.jackson.ObjectMapperFactory;
import org.xrpl.xrpl4j.model.ledger.LedgerObject;
import org.xrpl.xrpl4j.model.transactions.Address;
import org.xrpl.xrpl4j.model.transactions.Hash256;
import org.xrpl.xrpl4j.model.transactions.Transaction;
Expand Down Expand Up @@ -672,6 +675,28 @@ public LedgerResult ledger(LedgerRequestParams params) throws JsonRpcClientError
return jsonRpcClient.send(request, LedgerResult.class);
}

/**
* Retrieve a {@link LedgerObject} by sending a {@code ledger_entry} RPC request.
*
* @param params A {@link LedgerEntryRequestParams} containing the request parameters.
* @param <T> The type of {@link LedgerObject} that should be returned in rippled's response.
*
* @return A {@link LedgerEntryResult} of type {@link T}.
*/
public <T extends LedgerObject> LedgerEntryResult<T> ledgerEntry(
LedgerEntryRequestParams<T> params
) throws JsonRpcClientErrorException {
JsonRpcRequest request = JsonRpcRequest.builder()
.method(XrplMethods.LEDGER_ENTRY)
.addParams(params)
.build();

JavaType resultType = objectMapper.getTypeFactory()
.constructParametricType(LedgerEntryResult.class, params.ledgerObjectClass());

return jsonRpcClient.send(request, resultType);
}

/**
* Try to find a payment path for a rippling payment by sending a ripple_path_find method request.
*
Expand Down Expand Up @@ -770,6 +795,7 @@ public GatewayBalancesResult gatewayBalances(
* @param params The {@link AmmInfoRequestParams} to send in the request.
*
* @return A {@link AmmInfoResult}.
*
* @throws JsonRpcClientErrorException if {@code jsonRpcClient} throws an error.
*/
@Beta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
import org.xrpl.xrpl4j.model.client.common.LedgerIndex;
import org.xrpl.xrpl4j.model.client.common.LedgerSpecifier;
import org.xrpl.xrpl4j.model.client.fees.FeeResult;
import org.xrpl.xrpl4j.model.client.ledger.LedgerEntryRequestParams;
import org.xrpl.xrpl4j.model.client.ledger.LedgerEntryResult;
import org.xrpl.xrpl4j.model.client.ledger.LedgerRequestParams;
import org.xrpl.xrpl4j.model.client.ledger.LedgerResult;
import org.xrpl.xrpl4j.model.client.nft.NftBuyOffersRequestParams;
Expand Down Expand Up @@ -104,8 +106,10 @@
import org.xrpl.xrpl4j.model.client.transactions.TransactionRequestParams;
import org.xrpl.xrpl4j.model.client.transactions.TransactionResult;
import org.xrpl.xrpl4j.model.flags.AccountRootFlags;
import org.xrpl.xrpl4j.model.jackson.ObjectMapperFactory;
import org.xrpl.xrpl4j.model.ledger.AccountRootObject;
import org.xrpl.xrpl4j.model.ledger.Issue;
import org.xrpl.xrpl4j.model.ledger.LedgerObject;
import org.xrpl.xrpl4j.model.transactions.Address;
import org.xrpl.xrpl4j.model.transactions.Hash256;
import org.xrpl.xrpl4j.model.transactions.NfTokenId;
Expand Down Expand Up @@ -1041,6 +1045,28 @@ void ammInfo() throws JsonRpcClientErrorException {
assertThat(result).isEqualTo(mockResult);
}

@Test
void ledgerEntry() throws JsonRpcClientErrorException {
LedgerEntryRequestParams<LedgerObject> params = LedgerEntryRequestParams.index(
Hash256.of("6B1011EF3BC3ED619B15979EF75C1C60D9181F3DDE641AD3019318D3900CEE2E"),
LedgerSpecifier.VALIDATED
);

LedgerEntryResult<?> mockResult = mock(LedgerEntryResult.class);
when(jsonRpcClientMock.send(
JsonRpcRequest.builder()
.method(XrplMethods.LEDGER_ENTRY)
.addParams(params)
.build(),
ObjectMapperFactory.create().getTypeFactory().constructParametricType(
LedgerEntryResult.class, LedgerObject.class
)
)).thenReturn(mockResult);

LedgerEntryResult<LedgerObject> result = xrplClient.ledgerEntry(params);
assertThat(result).isEqualTo(mockResult);
}

@Test
void nftInfo() throws JsonRpcClientErrorException {
NftInfoRequestParams params = NftInfoRequestParams.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.xrpl.xrpl4j.model.client.ledger;

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.ledger.Issue;

/**
* Parameters that uniquely identify an {@link org.xrpl.xrpl4j.model.ledger.AmmObject} on ledger that can be used
* in a {@link LedgerEntryRequestParams} to request an {@link org.xrpl.xrpl4j.model.ledger.AmmObject}.
*/
@Immutable
@JsonSerialize(as = ImmutableAmmLedgerEntryParams.class)
@JsonDeserialize(as = ImmutableAmmLedgerEntryParams.class)
public interface AmmLedgerEntryParams {

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

/**
* One of the two assets in the AMM's pool.
*
* @return An {@link Issue}.
*/
Issue asset();

/**
* The other of the two assets in the AMM's pool.
*
* @return An {@link Issue}.
*/
Issue asset2();

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

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;

/**
* Parameters that uniquely identify a {@link org.xrpl.xrpl4j.model.ledger.DepositPreAuthObject} on ledger that can be
* used in a {@link LedgerEntryRequestParams} to request an {@link org.xrpl.xrpl4j.model.ledger.DepositPreAuthObject}.
*/
@Immutable
@JsonSerialize(as = ImmutableDepositPreAuthLedgerEntryParams.class)
@JsonDeserialize(as = ImmutableDepositPreAuthLedgerEntryParams.class)
public interface DepositPreAuthLedgerEntryParams {

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

/**
* The {@link Address} of the account that provided the preauthorization.
*
* @return An {@link Address}.
*/
Address owner();

/**
* The {@link Address} of the account that received the preauthorization.
*
* @return An {@link Address}.
*/
Address authorized();

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

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.transactions.Address;

/**
* Parameters that uniquely identify an {@link org.xrpl.xrpl4j.model.ledger.EscrowObject} on ledger that can be used in
* a {@link LedgerEntryRequestParams} to request an {@link org.xrpl.xrpl4j.model.ledger.EscrowObject}.
*/
@Immutable
@JsonSerialize(as = ImmutableEscrowLedgerEntryParams.class)
@JsonDeserialize(as = ImmutableEscrowLedgerEntryParams.class)
public interface EscrowLedgerEntryParams {

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

/**
* The owner (sender) of the Escrow object.
*
* @return The {@link Address} of the owner.
*/
Address owner();

/**
* The Sequence Number of the transaction that created the Escrow object.
*
* @return An {@link UnsignedInteger}.
*/
UnsignedInteger seq();

}
Loading

0 comments on commit 76fa607

Please sign in to comment.