Skip to content

Commit cbb3d5a

Browse files
authored
Merge pull request #709 from lightsail-network/add-protocol23-support
Add protocol23 support
2 parents eef61c2 + 7e0fa86 commit cbb3d5a

File tree

136 files changed

+3803
-1782
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+3803
-1782
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@
55
### Update:
66
- feat: add `pollTransaction` method to `SorobanServer` to poll transaction status with retry strategy. ([#696](https://github.com/stellar/java-stellar-sdk/pull/696))
77
- feat: implement message signing and verification according to [SEP-53](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0053.md), check `KeyPair.signMessage` and `KeyPair.verifyMessage` for more details. ([#698](https://github.com/stellar/java-stellar-sdk/pull/698))
8+
- feat: add `isValidEd25519SecretSeed`, `isValidPreAuthTx` and `isValidSha256Hash` to `StrKey` class, these functions can be used to validate the corresponding strkey.
9+
- feat: add med25519 public key support to `StrKey`.
10+
- feat: add muxed account, liquidity pool and claimable balance support to `Address` class.
11+
- feat: add `destinationMuxedId` and `destinationMuxedIdType` to `InvokeHostFunctionOperationResponse.AssetContractBalanceChange`.
12+
- feat: add `events` field to `GetTransactionsResponse.Transaction` and `GetTransactionResponse`, see [stellar-rpc#455](https://github.com/stellar/stellar-rpc/pull/455) for more details.
13+
- feat: add `oldestLedger`, `latestLedgerCloseTime` and `oldestLedgerCloseTime` fields to `GetEventsResponse`, and add `transactionIndex` and `operationIndex` fields to `GetEventsResponse.EventInfo`, check [Stellar RPC release log](https://github.com/stellar/stellar-rpc/releases/tag/v23.0.0-rc.1) for more information.
14+
- feat: add support for non-root authorization in `SorobanServer#simulateTransaction`.
15+
16+
### Breaking changes:
17+
- refactor!: the following functions in `StrKey` are marked as deprecated, they will be removed in the next major release; please refer to the documentation for each function to see the corresponding replacement functions:
18+
- `StrKey#encodeEd25519PublicKey(AccountID)`
19+
- `StrKey#encodeMuxedAccount(MuxedAccount)`
20+
- `StrKey#decodeMuxedAccount(String)`
21+
- `StrKey#encodeToXDRAccountId(String)`
22+
- `StrKey#encodeToXDRMuxedAccount(String)`
23+
- refactor!: remove `numArchivedContracts` and `archivedContractsAmount` from `AssetResponse`.
24+
- refactor!: `GetTransactionsResponse.Transaction#getDiagnosticEventsXdr()` and `GetTransactionsResponse.Transaction#parseDiagnosticEventsXdr()` has been marked as deprecated, they will be removed in Stellar RPC soon, use `GetTransactionsResponse.Transaction#getEvents()` instead.
25+
- refactor!: remove deprecated `pagingToken` field from `GetEventsResponse.EventInfo`.
26+
- refactor!: `inSuccessfulContractCall` in `GetEventsResponse.EventInfo` has been marked as deprecated, it will be removed in the next release.
827

928
## 1.5.0
1029

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ xdr/Stellar-contract-meta.x \
1010
xdr/Stellar-contract-spec.x \
1111
xdr/Stellar-contract.x \
1212
xdr/Stellar-internal.x \
13-
xdr/Stellar-contract-config-setting.x
13+
xdr/Stellar-contract-config-setting.x \
14+
xdr/Stellar-exporter.x
1415

1516
# xdrgen commit to use, see https://github.com/stellar/xdrgen
16-
XDRGEN_COMMIT=6d4d47b4bc6815e26a52d62fd6613cfb56676d4b
17+
XDRGEN_COMMIT=6b98787dcbb2b6407880adec5f74c6d88975ab0f
1718
# stellar-xdr commit to use, see https://github.com/stellar/stellar-xdr
18-
XDR_COMMIT=529d5176f24c73eeccfa5eba481d4e89c19b1181
19+
XDR_COMMIT=4b7a2ef7931ab2ca2499be68d849f38190b443ca
1920

2021
.PHONY: xdr xdr-clean xdr-update
2122

android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/MainActivity.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import org.stellar.sdk.xdr.ContractIDPreimage
4848
import org.stellar.sdk.xdr.ContractIDPreimage.ContractIDPreimageFromAddress
4949
import org.stellar.sdk.xdr.ContractIDPreimageType
5050
import org.stellar.sdk.xdr.CreateContractArgs
51-
import org.stellar.sdk.xdr.ExtensionPoint
5251
import org.stellar.sdk.xdr.HostFunction
5352
import org.stellar.sdk.xdr.HostFunctionType
5453
import org.stellar.sdk.xdr.Int64
@@ -187,13 +186,13 @@ private fun testSDK(): String {
187186
.readWrite(arrayOf())
188187
.build()
189188
)
190-
.readBytes(Uint32(XdrUnsignedInteger(699)))
189+
.diskReadBytes(Uint32(XdrUnsignedInteger(699)))
191190
.writeBytes(Uint32(XdrUnsignedInteger(0)))
192191
.instructions(Uint32(XdrUnsignedInteger(34567)))
193192
.build()
194193
)
195194
.resourceFee(Int64(100L))
196-
.ext(ExtensionPoint.builder().discriminant(0).build())
195+
.ext(SorobanTransactionData.SorobanTransactionDataExt.builder().discriminant(0).build())
197196
.build()
198197
val sorobanDataString = sorobanData.toXdrBase64()
199198

src/main/java/org/stellar/sdk/Address.java

Lines changed: 117 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
package org.stellar.sdk;
22

3+
import java.io.IOException;
4+
import java.util.Arrays;
35
import lombok.EqualsAndHashCode;
6+
import org.stellar.sdk.exception.UnexpectedException;
7+
import org.stellar.sdk.xdr.ClaimableBalanceID;
8+
import org.stellar.sdk.xdr.ClaimableBalanceIDType;
9+
import org.stellar.sdk.xdr.ContractID;
410
import org.stellar.sdk.xdr.Hash;
11+
import org.stellar.sdk.xdr.MuxedEd25519Account;
12+
import org.stellar.sdk.xdr.PoolID;
513
import org.stellar.sdk.xdr.SCAddress;
614
import org.stellar.sdk.xdr.SCVal;
715
import org.stellar.sdk.xdr.SCValType;
816

917
/**
10-
* Represents a single address in the Stellar network. An address can represent an account or a
11-
* contract.
18+
* Represents a single address in the Stellar network. An address can represent an account,
19+
* contract, muxed account, claimable balance, or liquidity pool.
1220
*/
1321
@EqualsAndHashCode
1422
public class Address {
@@ -18,9 +26,10 @@ public class Address {
1826
private final AddressType type;
1927

2028
/**
21-
* Creates a new {@link Address} from a Stellar public key or contract ID.
29+
* Creates a new {@link Address} from a Stellar public key (G...), contract ID (C...), med25519
30+
* public key (M...), liquidity pool ID (L...), or claimable balance ID (B...).
2231
*
23-
* @param address the StrKey encoded format of Stellar public key or contract ID.
32+
* @param address the StrKey encoded format of Stellar address.
2433
*/
2534
public Address(String address) {
2635
if (StrKey.isValidEd25519PublicKey(address)) {
@@ -29,6 +38,15 @@ public Address(String address) {
2938
} else if (StrKey.isValidContract(address)) {
3039
this.type = AddressType.CONTRACT;
3140
this.key = StrKey.decodeContract(address);
41+
} else if (StrKey.isValidMed25519PublicKey(address)) {
42+
this.type = AddressType.MUXED_ACCOUNT;
43+
this.key = StrKey.decodeMed25519PublicKey(address);
44+
} else if (StrKey.isValidClaimableBalance(address)) {
45+
this.type = AddressType.CLAIMABLE_BALANCE;
46+
this.key = StrKey.decodeClaimableBalance(address);
47+
} else if (StrKey.isValidLiquidityPool(address)) {
48+
this.type = AddressType.LIQUIDITY_POOL;
49+
this.key = StrKey.decodeLiquidityPool(address);
3250
} else {
3351
throw new IllegalArgumentException("Unsupported address type");
3452
}
@@ -37,7 +55,7 @@ public Address(String address) {
3755
/**
3856
* Creates a new {@link Address} from a Stellar public key.
3957
*
40-
* @param accountId the byte array of the Stellar public key.
58+
* @param accountId the byte array of the Stellar public key (G...).
4159
* @return a new {@link Address} object from the given Stellar public key.
4260
*/
4361
public static Address fromAccount(byte[] accountId) {
@@ -54,6 +72,36 @@ public static Address fromContract(byte[] contractId) {
5472
return new Address(StrKey.encodeContract(contractId));
5573
}
5674

75+
/**
76+
* Creates a new {@link Address} from a Stellar med25519 public key.
77+
*
78+
* @param muxedAccountId the byte array of the Stellar med25519 public key (M...).
79+
* @return a new {@link Address} object from the given Stellar med25519 public key.
80+
*/
81+
public static Address fromMuxedAccount(byte[] muxedAccountId) {
82+
return new Address(StrKey.encodeMed25519PublicKey(muxedAccountId));
83+
}
84+
85+
/**
86+
* Creates a new {@link Address} from a Stellar Claimable Balance ID.
87+
*
88+
* @param claimableBalanceId the byte array of the Stellar Claimable Balance ID (B...).
89+
* @return a new {@link Address} object from the given Stellar Claimable Balance ID.
90+
*/
91+
public static Address fromClaimableBalance(byte[] claimableBalanceId) {
92+
return new Address(StrKey.encodeClaimableBalance(claimableBalanceId));
93+
}
94+
95+
/**
96+
* Creates a new {@link Address} from a Stellar Liquidity Pool ID.
97+
*
98+
* @param liquidityPoolId the byte array of the Stellar Liquidity Pool ID (L...).
99+
* @return a new {@link Address} object from the given Stellar Liquidity Pool ID.
100+
*/
101+
public static Address fromLiquidityPool(byte[] liquidityPoolId) {
102+
return new Address(StrKey.encodeLiquidityPool(liquidityPoolId));
103+
}
104+
57105
/**
58106
* Creates a new {@link Address} from a {@link SCAddress} XDR object.
59107
*
@@ -63,9 +111,28 @@ public static Address fromContract(byte[] contractId) {
63111
public static Address fromSCAddress(SCAddress scAddress) {
64112
switch (scAddress.getDiscriminant()) {
65113
case SC_ADDRESS_TYPE_ACCOUNT:
66-
return new Address(StrKey.encodeEd25519PublicKey(scAddress.getAccountId()));
114+
return fromAccount(scAddress.getAccountId().getAccountID().getEd25519().getUint256());
67115
case SC_ADDRESS_TYPE_CONTRACT:
68-
return new Address(StrKey.encodeContract(scAddress.getContractId().getHash()));
116+
return fromContract(scAddress.getContractId().getContractID().getHash());
117+
case SC_ADDRESS_TYPE_MUXED_ACCOUNT:
118+
try {
119+
return fromMuxedAccount(scAddress.getMuxedAccount().toXdrByteArray());
120+
} catch (IOException e) {
121+
throw new UnexpectedException(e);
122+
}
123+
case SC_ADDRESS_TYPE_CLAIMABLE_BALANCE:
124+
if (scAddress.getClaimableBalanceId().getDiscriminant()
125+
!= ClaimableBalanceIDType.CLAIMABLE_BALANCE_ID_TYPE_V0) {
126+
throw new IllegalArgumentException(
127+
"The claimable balance ID type is not supported, it must be `CLAIMABLE_BALANCE_ID_TYPE_V0`.");
128+
}
129+
byte[] v0Bytes = scAddress.getClaimableBalanceId().getV0().getHash();
130+
byte[] withZeroPrefix = new byte[v0Bytes.length + 1];
131+
withZeroPrefix[0] = 0x00;
132+
System.arraycopy(v0Bytes, 0, withZeroPrefix, 1, v0Bytes.length);
133+
return fromClaimableBalance(withZeroPrefix);
134+
case SC_ADDRESS_TYPE_LIQUIDITY_POOL:
135+
return fromLiquidityPool(scAddress.getLiquidityPoolId().getPoolID().getHash());
69136
default:
70137
throw new IllegalArgumentException("Unsupported address type");
71138
}
@@ -100,7 +167,39 @@ public SCAddress toSCAddress() {
100167
break;
101168
case CONTRACT:
102169
scAddress.setDiscriminant(org.stellar.sdk.xdr.SCAddressType.SC_ADDRESS_TYPE_CONTRACT);
103-
scAddress.setContractId(new Hash(this.key));
170+
scAddress.setContractId(new ContractID(new Hash(this.key)));
171+
break;
172+
case MUXED_ACCOUNT:
173+
scAddress.setDiscriminant(org.stellar.sdk.xdr.SCAddressType.SC_ADDRESS_TYPE_MUXED_ACCOUNT);
174+
try {
175+
scAddress.setMuxedAccount(MuxedEd25519Account.fromXdrByteArray(this.key));
176+
} catch (IOException e) {
177+
throw new IllegalArgumentException("Invalid med25519 public key", e);
178+
}
179+
break;
180+
case CLAIMABLE_BALANCE:
181+
if (this.key[0] != 0x00) {
182+
throw new IllegalArgumentException(
183+
"The claimable balance ID type is not supported, it must be `CLAIMABLE_BALANCE_ID_TYPE_V0`.");
184+
}
185+
byte[] hashBytes = Arrays.copyOfRange(this.key, 1, this.key.length);
186+
Hash hash = new Hash(hashBytes);
187+
ClaimableBalanceID claimableBalanceID =
188+
ClaimableBalanceID.builder()
189+
.discriminant(ClaimableBalanceIDType.CLAIMABLE_BALANCE_ID_TYPE_V0)
190+
.v0(hash)
191+
.build();
192+
scAddress.setDiscriminant(
193+
org.stellar.sdk.xdr.SCAddressType.SC_ADDRESS_TYPE_CLAIMABLE_BALANCE);
194+
scAddress.setClaimableBalanceId(claimableBalanceID);
195+
break;
196+
case LIQUIDITY_POOL:
197+
scAddress.setDiscriminant(org.stellar.sdk.xdr.SCAddressType.SC_ADDRESS_TYPE_LIQUIDITY_POOL);
198+
try {
199+
scAddress.setLiquidityPoolId(PoolID.fromXdrByteArray(this.key));
200+
} catch (IOException e) {
201+
throw new IllegalArgumentException("Invalid liquidity pool ID", e);
202+
}
104203
break;
105204
default:
106205
throw new IllegalArgumentException("Unsupported address type");
@@ -145,6 +244,12 @@ public String toString() {
145244
return StrKey.encodeEd25519PublicKey(this.key);
146245
case CONTRACT:
147246
return StrKey.encodeContract(this.key);
247+
case MUXED_ACCOUNT:
248+
return StrKey.encodeMed25519PublicKey(this.key);
249+
case CLAIMABLE_BALANCE:
250+
return StrKey.encodeClaimableBalance(this.key);
251+
case LIQUIDITY_POOL:
252+
return StrKey.encodeLiquidityPool(this.key);
148253
default:
149254
throw new IllegalArgumentException("Unsupported address type");
150255
}
@@ -153,6 +258,9 @@ public String toString() {
153258
/** Represents the type of the address. */
154259
public enum AddressType {
155260
ACCOUNT,
156-
CONTRACT
261+
CONTRACT,
262+
MUXED_ACCOUNT,
263+
CLAIMABLE_BALANCE,
264+
LIQUIDITY_POOL
157265
}
158266
}

src/main/java/org/stellar/sdk/Asset.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,16 @@ public static Asset fromXdr(org.stellar.sdk.xdr.Asset xdr) {
7171
case ASSET_TYPE_CREDIT_ALPHANUM4:
7272
String assetCode4 =
7373
Util.paddedByteArrayToString(xdr.getAlphaNum4().getAssetCode().getAssetCode4());
74-
accountId = StrKey.encodeEd25519PublicKey(xdr.getAlphaNum4().getIssuer());
74+
accountId =
75+
StrKey.encodeEd25519PublicKey(
76+
xdr.getAlphaNum4().getIssuer().getAccountID().getEd25519().getUint256());
7577
return new AssetTypeCreditAlphaNum4(assetCode4, accountId);
7678
case ASSET_TYPE_CREDIT_ALPHANUM12:
7779
String assetCode12 =
7880
Util.paddedByteArrayToString(xdr.getAlphaNum12().getAssetCode().getAssetCode12());
79-
accountId = StrKey.encodeEd25519PublicKey(xdr.getAlphaNum12().getIssuer());
81+
accountId =
82+
StrKey.encodeEd25519PublicKey(
83+
xdr.getAlphaNum12().getIssuer().getAccountID().getEd25519().getUint256());
8084
return new AssetTypeCreditAlphaNum12(assetCode12, accountId);
8185
default:
8286
throw new IllegalArgumentException("Unknown asset type " + xdr.getDiscriminant());

src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum12.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public AssetType getType() {
3333

3434
public static AssetTypeCreditAlphaNum12 fromXdr(org.stellar.sdk.xdr.AlphaNum12 alphaNum12) {
3535
String assetCode12 = Util.paddedByteArrayToString(alphaNum12.getAssetCode().getAssetCode12());
36-
String accountId = StrKey.encodeEd25519PublicKey(alphaNum12.getIssuer());
36+
String accountId =
37+
StrKey.encodeEd25519PublicKey(
38+
alphaNum12.getIssuer().getAccountID().getEd25519().getUint256());
3739
return new AssetTypeCreditAlphaNum12(assetCode12, accountId);
3840
}
3941

@@ -45,7 +47,7 @@ public org.stellar.sdk.xdr.Asset toXdr() {
4547
AssetCode12 assetCode12 = new AssetCode12();
4648
assetCode12.setAssetCode12(Util.paddedByteArray(code, 12));
4749
credit.setAssetCode(assetCode12);
48-
credit.setIssuer(StrKey.encodeToXDRAccountId(issuer));
50+
credit.setIssuer(KeyPair.fromAccountId(issuer).getXdrAccountId());
4951
xdr.setAlphaNum12(credit);
5052
return xdr;
5153
}

src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum4.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public AssetType getType() {
3333

3434
public static AssetTypeCreditAlphaNum4 fromXdr(org.stellar.sdk.xdr.AlphaNum4 alphaNum4) {
3535
String assetCode4 = Util.paddedByteArrayToString(alphaNum4.getAssetCode().getAssetCode4());
36-
String accountId = StrKey.encodeEd25519PublicKey(alphaNum4.getIssuer());
36+
String accountId =
37+
StrKey.encodeEd25519PublicKey(
38+
alphaNum4.getIssuer().getAccountID().getEd25519().getUint256());
3739
return new AssetTypeCreditAlphaNum4(assetCode4, accountId);
3840
}
3941

@@ -45,7 +47,7 @@ public org.stellar.sdk.xdr.Asset toXdr() {
4547
AssetCode4 assetCode4 = new AssetCode4();
4648
assetCode4.setAssetCode4(Util.paddedByteArray(code, 4));
4749
credit.setAssetCode(assetCode4);
48-
credit.setIssuer(StrKey.encodeToXDRAccountId(issuer));
50+
credit.setIssuer(KeyPair.fromAccountId(issuer).getXdrAccountId());
4951
xdr.setAlphaNum4(credit);
5052
return xdr;
5153
}

src/main/java/org/stellar/sdk/FeeBumpTransaction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public static FeeBumpTransaction fromFeeBumpTransactionEnvelope(
120120
FeeBumpTransactionEnvelope envelope, Network network) {
121121
Transaction inner =
122122
Transaction.fromV1EnvelopeXdr(envelope.getTx().getInnerTx().getV1(), network);
123-
String feeSource = StrKey.encodeMuxedAccount(envelope.getTx().getFeeSource());
123+
String feeSource = MuxedAccount.fromXdr(envelope.getTx().getFeeSource()).getAddress();
124124
long fee = envelope.getTx().getFee().getInt64();
125125
FeeBumpTransaction feeBump = new FeeBumpTransaction(feeSource, fee, inner);
126126
feeBump.signatures.addAll(Arrays.asList(envelope.getSignatures()));
@@ -135,7 +135,7 @@ private org.stellar.sdk.xdr.FeeBumpTransaction toXdr() {
135135
Int64 xdrFee = new Int64();
136136
xdrFee.setInt64(fee);
137137
xdr.setFee(xdrFee);
138-
xdr.setFeeSource(StrKey.decodeMuxedAccount(this.feeSource));
138+
xdr.setFeeSource(new MuxedAccount(this.feeSource).toXdr());
139139
org.stellar.sdk.xdr.FeeBumpTransaction.FeeBumpTransactionInnerTx innerXDR =
140140
new org.stellar.sdk.xdr.FeeBumpTransaction.FeeBumpTransactionInnerTx();
141141
innerXDR.setDiscriminant(EnvelopeType.ENVELOPE_TYPE_TX);

0 commit comments

Comments
 (0)