Skip to content

Commit

Permalink
Update the SDK to the stable Protocol 20 release (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored Nov 3, 2023
1 parent badda6d commit e8cf617
Show file tree
Hide file tree
Showing 55 changed files with 1,095 additions and 1,265 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps.
* Update `LedgerResponse` and `AccountResponse`, remove outdated fields, and add missing fields. ([#549](https://github.com/stellar/java-stellar-sdk/pull/549))
* Add support for muxed accounts in `PaymentOperationResponse`. ([#550](https://github.com/stellar/java-stellar-sdk/pull/550))
* Use `Price` instead of `String` to represent prices. Change the type of `CreatePassiveSellOfferOperation.price`, `ManageBuyOfferOperation.price`, and `ManageBuyOfferOperation.price` from `String` to `Price`, this fixes the issue of incorrect operations parsed in certain specific scenarios. ([#554](https://github.com/stellar/java-stellar-sdk/pull/554))
* Update the SDK to the stable Protocol 20 release: [#553](https://github.com/stellar/java-stellar-sdk/pull/553)
- The `BumpFootprintExpirationOperation` is now `ExtendFootprintTTLOperation` and its `ledgersToExpire` field is now named `extendTo`, but it serves the same purpose.
- The `InvokeHostFunctionOperation.createTokenContractOperationBuilder` is now `InvokeHostFunctionOperation.createStellarAssetContractOperationBuilder`.
- `SorobanDataBuilder.setRefundableFee` is now `setResourceFee`.
- The RPC endpoint structure has changed, check [#552](https://github.com/stellar/java-stellar-sdk/issues/552) for more details.

## 0.41.1
* Add `org.stellar.sdk.spi.SdkProvider`, users can implement this interface to provide their own implementation of the SDK. We provide an [Android specific implementation](https://github.com/stellar/java-stellar-sdk-android-spi), if you are integrating this SDK into an Android project, be sure to check it out. ([#543](https://github.com/stellar/java-stellar-sdk/pull/543))
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ xdr/Stellar-internal.x \
xdr/Stellar-contract-config-setting.x

XDRGEN_COMMIT=7c9349c62844e376bc637be678695387e88d125f
XDRNEXT_COMMIT=9ac02641139e6717924fdad716f6e958d0168491
XDRNEXT_COMMIT=6a620d160aab22609c982d54578ff6a63bfcdc01

.PHONY: xdr xdr-clean xdr-update

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private fun testSDK(): String {
.instructions(Uint32(XdrUnsignedInteger(34567)))
.build()
)
.refundableFee(Int64(100L))
.resourceFee(Int64(100L))
.ext(ExtensionPoint.Builder().discriminant(0).build())
.build()
val sorobanDataString = sorobanData.toXdrBase64()
Expand All @@ -213,7 +213,7 @@ private fun testSDK(): String {
)
.executable(
ContractExecutable.Builder()
.discriminant(ContractExecutableType.CONTRACT_EXECUTABLE_TOKEN)
.discriminant(ContractExecutableType.CONTRACT_EXECUTABLE_STELLAR_ASSET)
.build()
)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.NonNull;
import lombok.Value;
import lombok.experimental.SuperBuilder;
import org.stellar.sdk.xdr.BumpFootprintExpirationOp;
import org.stellar.sdk.xdr.ExtendFootprintTTLOp;
import org.stellar.sdk.xdr.ExtensionPoint;
import org.stellar.sdk.xdr.OperationType;
import org.stellar.sdk.xdr.Uint32;
Expand All @@ -13,7 +13,7 @@
/**
* Represents <a
* href="https://github.com/stellar/go/blob/7ff6ffae29d278f979fcd6c6bed8cd0d4b4d2e08/txnbuild/bump_footprint_expiration.go#L8-L12"
* target="_blank">BumpFootprintExpiration</a> operation.
* target="_blank">ExtendFootprintTTL</a> operation.
*
* <p>Bump the expiration of a footprint (read and written ledger keys).
*
Expand All @@ -23,49 +23,48 @@
@EqualsAndHashCode(callSuper = true)
@SuperBuilder(toBuilder = true)
@Value
public class BumpFootprintExpirationOperation extends Operation {
public class ExtendFootprintTTLOperation extends Operation {

/**
* the number of ledgers past the LCL (last closed ledger) by which to extend the validity of the
* ledger keys in this transaction
*/
@NonNull Long ledgersToExpire;
@NonNull Long extendTo;

/**
* Constructs a new BumpFootprintExpirationOperation object from the XDR representation of the
* {@link BumpFootprintExpirationOperation}.
* Constructs a new ExtendFootprintTTLOperation object from the XDR representation of the {@link
* ExtendFootprintTTLOperation}.
*
* @param op the XDR representation of the {@link BumpFootprintExpirationOperation}.
* @param op the XDR representation of the {@link ExtendFootprintTTLOperation}.
*/
public static BumpFootprintExpirationOperation fromXdr(BumpFootprintExpirationOp op) {
return BumpFootprintExpirationOperation.builder()
.ledgersToExpire(op.getLedgersToExpire().getUint32().getNumber())
public static ExtendFootprintTTLOperation fromXdr(ExtendFootprintTTLOp op) {
return ExtendFootprintTTLOperation.builder()
.extendTo(op.getExtendTo().getUint32().getNumber())
.build();
}

@Override
org.stellar.sdk.xdr.Operation.OperationBody toOperationBody(AccountConverter accountConverter) {
BumpFootprintExpirationOp op = new BumpFootprintExpirationOp();
ExtendFootprintTTLOp op = new ExtendFootprintTTLOp();
op.setExt(new ExtensionPoint.Builder().discriminant(0).build());
op.setLedgersToExpire(new Uint32(new XdrUnsignedInteger(ledgersToExpire)));
op.setExtendTo(new Uint32(new XdrUnsignedInteger(extendTo)));

org.stellar.sdk.xdr.Operation.OperationBody body =
new org.stellar.sdk.xdr.Operation.OperationBody();
body.setDiscriminant(OperationType.BUMP_FOOTPRINT_EXPIRATION);
body.setBumpFootprintExpirationOp(op);
body.setDiscriminant(OperationType.EXTEND_FOOTPRINT_TTL);
body.setExtendFootprintTTLOp(op);
return body;
}

/** Customizing builder methods. Rest of the builder code will be auto generated by Lombok. */
public abstract static class BumpFootprintExpirationOperationBuilder<
C extends BumpFootprintExpirationOperation,
B extends BumpFootprintExpirationOperationBuilder<C, B>>
public abstract static class ExtendFootprintTTLOperationBuilder<
C extends ExtendFootprintTTLOperation, B extends ExtendFootprintTTLOperationBuilder<C, B>>
extends OperationBuilder<C, B> {
public B ledgersToExpire(Long ledgersToExpire) {
if (ledgersToExpire <= 0 || ledgersToExpire > 0xFFFFFFFFL) {
throw new IllegalArgumentException("ledgersToExpire isn't a ledger quantity (uint32)");
public B extendTo(Long extendTo) {
if (extendTo <= 0 || extendTo > 0xFFFFFFFFL) {
throw new IllegalArgumentException("extendTo isn't a ledger quantity (uint32)");
}
this.ledgersToExpire = ledgersToExpire;
this.extendTo = extendTo;
return self();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static InvokeHostFunctionOperation fromXdr(InvokeHostFunctionOp op) {
* @param asset The classic asset to wrap.
* @return {@link InvokeHostFunctionOperationBuilder}
*/
public static InvokeHostFunctionOperationBuilder<?, ?> createTokenContractOperationBuilder(
public static InvokeHostFunctionOperationBuilder<?, ?> createStellarAssetContractOperationBuilder(
Asset asset) {
CreateContractArgs createContractArgs =
new CreateContractArgs.Builder()
Expand All @@ -164,7 +164,7 @@ public static InvokeHostFunctionOperation fromXdr(InvokeHostFunctionOp op) {
.build())
.executable(
new ContractExecutable.Builder()
.discriminant(ContractExecutableType.CONTRACT_EXECUTABLE_TOKEN)
.discriminant(ContractExecutableType.CONTRACT_EXECUTABLE_STELLAR_ASSET)
.build())
.build();
HostFunction hostFunction =
Expand All @@ -185,7 +185,7 @@ public static InvokeHostFunctionOperation fromXdr(InvokeHostFunctionOp op) {
* generated.
* @return {@link InvokeHostFunctionOperationBuilder}
*/
public static InvokeHostFunctionOperationBuilder<?, ?> createTokenContractOperationBuilder(
public static InvokeHostFunctionOperationBuilder<?, ?> createStellarAssetContractOperationBuilder(
Address address, @Nullable byte[] salt) {
if (salt == null) {
salt = new byte[32];
Expand All @@ -207,7 +207,7 @@ public static InvokeHostFunctionOperation fromXdr(InvokeHostFunctionOp op) {
.build())
.executable(
new ContractExecutable.Builder()
.discriminant(ContractExecutableType.CONTRACT_EXECUTABLE_TOKEN)
.discriminant(ContractExecutableType.CONTRACT_EXECUTABLE_STELLAR_ASSET)
.build())
.build();
HostFunction hostFunction =
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/stellar/sdk/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ public static Operation fromXdr(
case INVOKE_HOST_FUNCTION:
operation = InvokeHostFunctionOperation.fromXdr(body.getInvokeHostFunctionOp());
break;
case BUMP_FOOTPRINT_EXPIRATION:
operation = BumpFootprintExpirationOperation.fromXdr(body.getBumpFootprintExpirationOp());
case EXTEND_FOOTPRINT_TTL:
operation = ExtendFootprintTTLOperation.fromXdr(body.getExtendFootprintTTLOp());
break;
case RESTORE_FOOTPRINT:
operation = RestoreFootprintOperation.fromXdr(body.getRestoreFootprintOp());
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/stellar/sdk/SorobanDataBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* Supports building {@link SorobanTransactionData} structures with various items set to specific
* values.
*
* <p>This is recommended for when you are building {@link BumpFootprintExpirationOperation} and
* {@link RestoreFootprintOperation} operations to avoid (re)building the entire data structure from
* <p>This is recommended for when you are building {@link ExtendFootprintTTLOperation} and {@link
* RestoreFootprintOperation} operations to avoid (re)building the entire data structure from
* scratch.
*/
public class SorobanDataBuilder {
Expand All @@ -41,7 +41,7 @@ public SorobanDataBuilder() {
.readBytes(new Uint32(new XdrUnsignedInteger(0)))
.writeBytes(new Uint32(new XdrUnsignedInteger(0)))
.build())
.refundableFee(new Int64(0L))
.resourceFee(new Int64(0L))
.ext(new ExtensionPoint.Builder().discriminant(0).build())
.build();
}
Expand Down Expand Up @@ -73,13 +73,13 @@ public SorobanDataBuilder(SorobanTransactionData sorobanData) {
}

/**
* Sets the "refundable" fee portion of the Soroban data.
* Sets the "resource" fee portion of the Soroban data.
*
* @param fee the refundable fee to set (int64)
* @param fee the resource fee to set (int64)
* @return this builder instance
*/
public SorobanDataBuilder setRefundableFee(long fee) {
data.setRefundableFee(new Int64(fee));
public SorobanDataBuilder setResourceFee(long fee) {
data.setResourceFee(new Int64(fee));
return this;
}

Expand Down
35 changes: 16 additions & 19 deletions src/main/java/org/stellar/sdk/SorobanServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,8 @@ public GetLatestLedgerResponse getLatestLedger() throws IOException, SorobanRpcE
* @see <a href="https://soroban.stellar.org/api/methods/simulateTransaction"
* target="_blank">simulateTransaction documentation</a>
* @param transaction The transaction to simulate. It should include exactly one operation, which
* must be one of {@link InvokeHostFunctionOperation}, {@link
* BumpFootprintExpirationOperation}, or {@link RestoreFootprintOperation}. Any provided
* footprint will be ignored.
* must be one of {@link InvokeHostFunctionOperation}, {@link ExtendFootprintTTLOperation}, or
* {@link RestoreFootprintOperation}. Any provided footprint will be ignored.
* @return A {@link SimulateTransactionResponse} object containing the cost, footprint,
* result/auth requirements (if applicable), and error of the transaction.
* @throws IOException If the request could not be executed due to cancellation, a connectivity
Expand Down Expand Up @@ -349,14 +348,13 @@ public SimulateTransactionResponse simulateTransaction(Transaction transaction)
* to inspect estimated fees for a given transaction in detail first, if that is of importance.
*
* @param transaction The transaction to prepare. It should include exactly one operation, which
* must be one of {@link InvokeHostFunctionOperation}, {@link
* BumpFootprintExpirationOperation}, or {@link RestoreFootprintOperation}. Any provided
* footprint will be ignored. You can use {@link Transaction#isSorobanTransaction()} to check
* if a transaction is a Soroban transaction. Any provided footprint will be overwritten.
* However, if your operation has existing auth entries, they will be preferred over ALL auth
* entries from the simulation. In other words, if you include auth entries, you don't care
* about the auth returned from the simulation. Other fields (footprint, etc.) will be filled
* as normal.
* must be one of {@link InvokeHostFunctionOperation}, {@link ExtendFootprintTTLOperation}, or
* {@link RestoreFootprintOperation}. Any provided footprint will be ignored. You can use
* {@link Transaction#isSorobanTransaction()} to check if a transaction is a Soroban
* transaction. Any provided footprint will be overwritten. However, if your operation has
* existing auth entries, they will be preferred over ALL auth entries from the simulation. In
* other words, if you include auth entries, you don't care about the auth returned from the
* simulation. Other fields (footprint, etc.) will be filled as normal.
* @return Returns a copy of the {@link Transaction}, with the expected authorizations (in the
* case of invocation) and ledger footprint added. The transaction fee will also automatically
* be padded with the contract's minimum resource fees discovered from the simulation.
Expand Down Expand Up @@ -384,14 +382,13 @@ public Transaction prepareTransaction(Transaction transaction)
* interaction with user to confirm it is acceptable.
*
* @param transaction The transaction to prepare. It should include exactly one operation, which
* must be one of {@link InvokeHostFunctionOperation}, {@link
* BumpFootprintExpirationOperation}, or {@link RestoreFootprintOperation}. Any provided
* footprint will be ignored. You can use {@link Transaction#isSorobanTransaction()} to check
* if a transaction is a Soroban transaction. Any provided footprint will be overwritten.
* However, if your operation has existing auth entries, they will be preferred over ALL auth
* entries from the simulation. In other words, if you include auth entries, you don't care
* about the auth returned from the simulation. Other fields (footprint, etc.) will be filled
* as normal.
* must be one of {@link InvokeHostFunctionOperation}, {@link ExtendFootprintTTLOperation}, or
* {@link RestoreFootprintOperation}. Any provided footprint will be ignored. You can use
* {@link Transaction#isSorobanTransaction()} to check if a transaction is a Soroban
* transaction. Any provided footprint will be overwritten. However, if your operation has
* existing auth entries, they will be preferred over ALL auth entries from the simulation. In
* other words, if you include auth entries, you don't care about the auth returned from the
* simulation. Other fields (footprint, etc.) will be filled as normal.
* @param simulateTransactionResponse The {@link SimulateTransactionResponse} to use for preparing
* the transaction.
* @return Returns a copy of the {@link Transaction}, with the expected authorizations (in the
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/stellar/sdk/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public boolean isSorobanTransaction() {

Operation op = mOperations[0];
return op instanceof InvokeHostFunctionOperation
|| op instanceof BumpFootprintExpirationOperation
|| op instanceof ExtendFootprintTTLOperation
|| op instanceof RestoreFootprintOperation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public OperationResponse deserialize(
return gson.fromJson(json, LiquidityPoolWithdrawOperationResponse.class);
case INVOKE_HOST_FUNCTION:
return gson.fromJson(json, InvokeHostFunctionOperationResponse.class);
case BUMP_FOOTPRINT_EXPIRATION:
return gson.fromJson(json, BumpFootprintExpirationOperationResponse.class);
case EXTEND_FOOTPRINT_TTL:
return gson.fromJson(json, ExtendFootprintTTLOperationResponse.class);
case RESTORE_FOOTPRINT:
return gson.fromJson(json, RestoreFootprintOperationResponse.class);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.google.gson.annotations.SerializedName;

/**
* Represents BumpFootprintExpiration operation response.
* Represents ExtendFootprintTTL operation response.
*
* <p>TODO: update link
*
* @see <a
* href="https://github.com/stellar/go/blob/7ff6ffae29d278f979fcd6c6bed8cd0d4b4d2e08/protocols/horizon/operations/main.go#L376-L381">Horizon
Expand All @@ -13,15 +15,15 @@
* @see org.stellar.sdk.requests.OperationsRequestBuilder
* @see org.stellar.sdk.Server#operations()
*/
public class BumpFootprintExpirationOperationResponse extends OperationResponse {
@SerializedName("ledgers_to_expire")
private final Long ledgersToExpire;
public class ExtendFootprintTTLOperationResponse extends OperationResponse {
@SerializedName("extend_to")
private final Long extendTo;

public BumpFootprintExpirationOperationResponse(Long ledgersToExpire) {
this.ledgersToExpire = ledgersToExpire;
public ExtendFootprintTTLOperationResponse(Long extendTo) {
this.extendTo = extendTo;
}

public Long getLedgersToExpire() {
return ledgersToExpire;
public Long getExtendTo() {
return extendTo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ public static class EventInfo {

List<String> topic;

EventInfoValue value;
String value;

Boolean inSuccessfulContractCall;
}

@AllArgsConstructor
@Value
public static class EventInfoValue {
String xdr;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ public static class LedgerEntryResult {

@SerializedName("lastModifiedLedgerSeq")
Long lastModifiedLedger;

@SerializedName("liveUntilLedgerSeq")
Long liveUntilLedger;
}
}
Loading

0 comments on commit e8cf617

Please sign in to comment.