Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/maven/jackson.version-2.15.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nkramer44 authored Nov 30, 2023
2 parents 6d3e5e4 + 45d33c7 commit 4f20155
Show file tree
Hide file tree
Showing 140 changed files with 11,751 additions and 1,268 deletions.
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ current [BOM](https://howtodoinjava.com/maven/maven-bom-bill-of-materials-depend
<dependency>
<groupId>org.xrpl</groupId>
<artifactId>xrpl4j-bom</artifactId>
<version>3.0.1</version>
<version>3.2.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -141,17 +141,17 @@ For use-cases that require private keys to exist inside the running JVM, the fol
generate a keypair, and also how to derive an XRPL address from there:

```java
import org.xrpl.xrpl4j.crypto.core.keys.Seed;
import org.xrpl.xrpl4j.crypto.core.keys.PrivateKey;
import org.xrpl.xrpl4j.crypto.core.keys.PublicKey;
import org.xrpl.xrpl4j.crypto.keys.KeyPair;
import org.xrpl.xrpl4j.crypto.keys.PrivateKey;
import org.xrpl.xrpl4j.crypto.keys.PublicKey;
import org.xrpl.xrpl4j.crypto.keys.Seed;
import org.xrpl.xrpl4j.model.transactions.Address;

...

Seed seed = Seed.ed255519Seed(); // <-- Generates a random seed.
PrivateKey privateKey = seed.derivePrivateKey(); // <-- Derive a private key from the seed.
PublicKey publicKey = privateKey.derivePublicKey(); // <-- Derive a public key from the private key.
Address address = publicKey.deriveAddress(); // <-- Derive an address from the public key.
Seed seed = Seed.ed25519Seed(); // <-- Generates a random seed.
KeyPair keyPair = seed.deriveKeyPair(); // <-- Derive a KeyPair from the seed.
PrivateKey privateKey = keyPair.privateKey(); // <-- Derive a privateKey from the KeyPair.
PublicKey publicKey = keyPair.publicKey(); // <-- Derive a publicKey from the KeyPair.
Address address = publicKey.deriveAddress(); // <-- Derive an address from the publicKey
```

#### Private Key References (`PrivateKeyReference`)
Expand Down Expand Up @@ -183,23 +183,24 @@ The following example illustrates how to construct a payment transaction, sign i
then submit that transaction to the XRP Ledger for processing and validation:

```java
import org.xrpl.xrpl4j.crypto.core.keys.Seed;
import org.xrpl.xrpl4j.crypto.core.keys.KeyPair;
import org.xrpl.xrpl4j.crypto.core.keys.PrivateKey;
import org.xrpl.xrpl4j.crypto.core.keys.PublicKey;
import org.xrpl.xrpl4j.client.XrplClient;
import org.xrpl.xrpl4j.crypto.keys.PrivateKey;
import org.xrpl.xrpl4j.crypto.keys.Seed;
import org.xrpl.xrpl4j.crypto.signing.SignatureService;
import org.xrpl.xrpl4j.crypto.signing.SingleSignedTransaction;
import org.xrpl.xrpl4j.model.client.transactions.SubmitResult;
import org.xrpl.xrpl4j.model.transactions.Address;
import org.xrpl.xrpl4j.crypto.core.signing.SignatureService;

import org.xrpl.xrpl4j.crypto.signing.bc.BcSignatureService;
import org.xrpl.xrpl4j.model.transactions.Payment;

// Construct a SignatureService that uses in-memory Keys (see SignatureService.java for alternatives).
SignatureService signatureService = new BcSignatureService();

// Sender (using ed25519 key)
Seed senderSeed = Seed.ed255519Seed();
PrivateKey senderPrivateKey = senderSeed.derivePrivateKey();
PublicKey senderPublicKey = senderPrivateKey.derivePublicKey();
Address senderAddress = senderPublicKey.deriveAddress();

Seed seed = Seed.ed25519Seed(); // <-- Generates a random seed.
PrivateKey senderPrivateKey = seed.deriveKeyPair().privateKey();

// Receiver (using secp256k1 key)
Address receiverAddress = Address.of("r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59");

Expand All @@ -208,15 +209,15 @@ Payment payment = ...; // See V3 ITs for examples.

SingleSignedTransaction<Payment> signedTransaction = signatureService.sign(sourcePrivateKey,payment);
SubmitResult<Payment> result = xrplClient.submit(signedTransaction);
assertThat(result.result()).isEqualTo("tesSUCCESS");
assert result.engineResult().equals("tesSUCCESS");
```

### Codecs
This library relies upon two important sub-modules called Codecs (One for the XRPL binary encoding, and one for XRPL
canonical JSON encoding). Read more about each here:

- [Binary Codec](https://github.com/XRPLF/xrpl4j/tree/main/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/codec/binary/README.md)
- [Address Coded](https://github.com/XRPLF/xrpl4j/tree/main/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/codec/addresses/README.md)
- [Address Codec](https://github.com/XRPLF/xrpl4j/tree/main/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/codec/addresses/README.md)

## Development

Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@
<version>3.3.0</version>
<inherited>true</inherited>
<configuration>
<encoding>UTF-8</encoding>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
<consoleOutput>true</consoleOutput>
<linkXRef>false</linkXRef>
<failOnViolation>true</failOnViolation>
Expand Down
4 changes: 2 additions & 2 deletions xrpl4j-bom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ POM file. For example:
<dependency>
<groupId>org.xrpl.xrpl4j</groupId>
<artifactId>xrpl4j-bom</artifactId>
<version>3.0.0</version>
<version>3.2.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -31,7 +31,7 @@ POM file. For example:

With this in place, whenever you want to add a `<dependency/>` you won't need to worry about specifying the version.
Instead, version numbers are controlled by the BOM you import, as in the example above, which will use only
version `3.0.0` of all xrpl-4j dependencies.
version `3.2.1` of all xrpl-4j dependencies.

For more information on how BOM files work, consult this [tutorial](https://www.baeldung.com/spring-maven-bom) or others
on Google.
48 changes: 48 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 @@ -55,11 +55,15 @@
import org.xrpl.xrpl4j.model.client.accounts.AccountTransactionsResult;
import org.xrpl.xrpl4j.model.client.accounts.GatewayBalancesRequestParams;
import org.xrpl.xrpl4j.model.client.accounts.GatewayBalancesResult;
import org.xrpl.xrpl4j.model.client.amm.AmmInfoRequestParams;
import org.xrpl.xrpl4j.model.client.amm.AmmInfoResult;
import org.xrpl.xrpl4j.model.client.channels.ChannelVerifyRequestParams;
import org.xrpl.xrpl4j.model.client.channels.ChannelVerifyResult;
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 @@ -87,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 @@ -670,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 @@ -762,6 +789,27 @@ public GatewayBalancesResult gatewayBalances(
return jsonRpcClient.send(request, GatewayBalancesResult.class);
}

/**
* Get info about an AMM by making a call to the amm_info rippled RPC method.
*
* @param params The {@link AmmInfoRequestParams} to send in the request.
*
* @return A {@link AmmInfoResult}.
*
* @throws JsonRpcClientErrorException if {@code jsonRpcClient} throws an error.
*/
@Beta
public AmmInfoResult ammInfo(
AmmInfoRequestParams params
) throws JsonRpcClientErrorException {
JsonRpcRequest request = JsonRpcRequest.builder()
.method(XrplMethods.AMM_INFO)
.addParams(params)
.build();

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

public JsonRpcClient getJsonRpcClient() {
return jsonRpcClient;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@
import org.xrpl.xrpl4j.model.client.accounts.AccountTransactionsResult;
import org.xrpl.xrpl4j.model.client.accounts.GatewayBalancesRequestParams;
import org.xrpl.xrpl4j.model.client.accounts.GatewayBalancesResult;
import org.xrpl.xrpl4j.model.client.amm.AmmInfoRequestParams;
import org.xrpl.xrpl4j.model.client.amm.AmmInfoResult;
import org.xrpl.xrpl4j.model.client.channels.ChannelVerifyRequestParams;
import org.xrpl.xrpl4j.model.client.channels.ChannelVerifyResult;
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 @@ -102,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 @@ -1025,6 +1031,42 @@ public void nftSellOffers() throws JsonRpcClientErrorException {
assertThat(jsonRpcRequestArgumentCaptor.getValue().params().get(0)).isEqualTo(nftSellOffersRequestParams);
}

@Test
void ammInfo() throws JsonRpcClientErrorException {
AmmInfoRequestParams params = mock(AmmInfoRequestParams.class);
JsonRpcRequest expectedRequest = JsonRpcRequest.builder()
.method(XrplMethods.AMM_INFO)
.addParams(params)
.build();
AmmInfoResult mockResult = mock(AmmInfoResult.class);
when(jsonRpcClientMock.send(expectedRequest, AmmInfoResult.class)).thenReturn(mockResult);
AmmInfoResult result = xrplClient.ammInfo(params);

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
Expand Up @@ -9,9 +9,9 @@
* 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.
Expand Down Expand Up @@ -56,7 +56,7 @@ public static String encode(
Objects.requireNonNull(expectedLength);

if (expectedLength.intValue() != bytes.getUnsignedBytes().size()) {
throw new EncodeException("Length of bytes does not match expectedLength.");
throw new EncodeException(String.format("Length of bytes does not match expectedLength of %s.", expectedLength));
}

return encodeChecked(bytes.toByteArray(), versions);
Expand Down Expand Up @@ -99,6 +99,7 @@ public static String encodeChecked(final byte[] bytes, final List<Version> versi
* @param version The {@link Version} to try decoding with.
*
* @return A {@link Decoded} containing the decoded value and version.
*
* @throws EncodingFormatException If the version bytes of the Base58 value are invalid.
*/
public static Decoded decode(
Expand Down Expand Up @@ -136,14 +137,14 @@ public static Decoded decode(
* Decode a Base58Check {@link String}.
*
* @param base58Value The Base58Check encoded {@link String} to be decoded.
* @param keyTypes A {@link List} of {@link KeyType}s which can be associated with the result of this
* method.
* @param keyTypes A {@link List} of {@link KeyType}s which can be associated with the result of this method.
* @param versions A {@link List} of {@link Version}s to try decoding with.
* @param expectedLength The expected length of the decoded value.
*
* @return A {@link Decoded} containing the decoded value, version, and type.
* @throws EncodingFormatException If more than one version is supplied without an expectedLength value present,
* or if the version bytes of the Base58 value are invalid.
*
* @throws EncodingFormatException If more than one version is supplied without an expectedLength value present, or if
* the version bytes of the Base58 value are invalid.
*/
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public static Decoded decode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* 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.
Expand Down Expand Up @@ -86,7 +86,10 @@ public UnsignedByteArray decodeAccountId(final Address accountId) {
* @param publicKey An {@link UnsignedByteArray} containing the public key to be encoded.
*
* @return The Base58 representation of publicKey.
*
* @deprecated Prefer {@link PublicKeyCodec#encodeNodePublicKey(UnsignedByteArray)}.
*/
@Deprecated
public String encodeNodePublicKey(final UnsignedByteArray publicKey) {
Objects.requireNonNull(publicKey);

Expand All @@ -101,7 +104,9 @@ public String encodeNodePublicKey(final UnsignedByteArray publicKey) {
* @return An {@link UnsignedByteArray} containing the decoded public key.
*
* @see "https://xrpl.org/base58-encodings.html"
* @deprecated Prefer {@link PublicKeyCodec#decodeNodePublicKey(String)}.
*/
@Deprecated
public UnsignedByteArray decodeNodePublicKey(final String publicKey) {
Objects.requireNonNull(publicKey);

Expand Down
Loading

0 comments on commit 4f20155

Please sign in to comment.