├── settings.gradle ├── libs └── net.i2p.crypto-4.0.0.jar ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src ├── main │ └── java │ │ └── org │ │ └── stellar │ │ └── sdk │ │ ├── federation │ │ ├── ConnectionErrorException.java │ │ ├── NotFoundException.java │ │ ├── ServerErrorException.java │ │ ├── MalformedAddressException.java │ │ ├── NoFederationServerException.java │ │ ├── StellarTomlNotFoundInvalidException.java │ │ ├── FederationServerInvalidException.java │ │ ├── FederationResponse.java │ │ └── Federation.java │ │ ├── responses │ │ ├── effects │ │ │ ├── SignerRemovedEffectResponse.java │ │ │ ├── AccountRemovedEffectResponse.java │ │ │ ├── DataCreatedEffectResponse.java │ │ │ ├── DataRemovedEffectResponse.java │ │ │ ├── DataUpdatedEffectResponse.java │ │ │ ├── OfferCreatedEffectResponse.java │ │ │ ├── OfferRemovedEffectResponse.java │ │ │ ├── OfferUpdatedEffectResponse.java │ │ │ ├── AccountInflationDestinationUpdatedEffectResponse.java │ │ │ ├── SignerCreatedEffectResponse.java │ │ │ ├── SignerUpdatedEffectResponse.java │ │ │ ├── SignerEffectResponse.java │ │ │ ├── TrustlineCreatedEffectResponse.java │ │ │ ├── TrustlineRemovedEffectResponse.java │ │ │ ├── TrustlineUpdatedEffectResponse.java │ │ │ ├── TrustlineAuthorizedEffectResponse.java │ │ │ ├── TrustlineDeauthorizedEffectResponse.java │ │ │ ├── AccountCreatedEffectResponse.java │ │ │ ├── AccountHomeDomainUpdatedEffectResponse.java │ │ │ ├── TrustlineAuthorizationResponse.java │ │ │ ├── AccountFlagsUpdatedEffectResponse.java │ │ │ ├── TrustlineCUDResponse.java │ │ │ ├── AccountThresholdsUpdatedEffectResponse.java │ │ │ ├── AccountDebitedEffectResponse.java │ │ │ └── AccountCreditedEffectResponse.java │ │ ├── TypedResponse.java │ │ ├── operations │ │ │ ├── InflationOperationResponse.java │ │ │ ├── ManageDataOperationResponse.java │ │ │ ├── AccountMergeOperationResponse.java │ │ │ ├── CreateAccountOperationResponse.java │ │ │ ├── PaymentOperationResponse.java │ │ │ ├── ChangeTrustOperationResponse.java │ │ │ └── AllowTrustOperationResponse.java │ │ ├── KeyPairTypeAdapter.java │ │ ├── Link.java │ │ ├── AssetDeserializer.java │ │ └── Response.java │ │ ├── FormatException.java │ │ ├── MemoTooLongException.java │ │ ├── MemoNone.java │ │ ├── NoNetworkSelectedException.java │ │ ├── requests │ │ ├── EventListener.java │ │ ├── ErrorResponse.java │ │ ├── TooManyRequestsException.java │ │ ├── AssetsRequestBuilder.java │ │ └── ResponseHandler.java │ │ ├── NotEnoughSignaturesException.java │ │ ├── AssetCodeLengthInvalidException.java │ │ ├── MemoHash.java │ │ ├── TransactionBuilderAccount.java │ │ ├── MemoReturnHash.java │ │ ├── InflationOperation.java │ │ ├── MemoId.java │ │ ├── xdr │ │ ├── Int64.java │ │ ├── Int32.java │ │ ├── Uint64.java │ │ ├── Uint32.java │ │ ├── NodeID.java │ │ ├── String32.java │ │ ├── String64.java │ │ ├── AccountID.java │ │ ├── Hash.java │ │ ├── Auth.java │ │ ├── SequenceNumber.java │ │ ├── Value.java │ │ ├── Uint256.java │ │ ├── IPAddrType.java │ │ ├── PublicKeyType.java │ │ ├── OperationMeta.java │ │ ├── BucketEntryType.java │ │ ├── OfferEntryFlags.java │ │ ├── TrustLineFlags.java │ │ ├── Thresholds.java │ │ ├── DataValue.java │ │ ├── Signature.java │ │ ├── HmacSha256Key.java │ │ ├── HmacSha256Mac.java │ │ ├── Price.java │ │ ├── Curve25519Public.java │ │ ├── Curve25519Secret.java │ │ ├── SignatureHint.java │ │ ├── UpgradeType.java │ │ ├── Error.java │ │ ├── LedgerEntryType.java │ │ ├── EnvelopeType.java │ │ ├── CryptoKeyType.java │ │ ├── Signer.java │ │ ├── AssetType.java │ │ ├── ManageOfferEffect.java │ │ ├── SCPBallot.java │ │ ├── DontHave.java │ │ ├── InflationResultCode.java │ │ ├── MemoType.java │ │ ├── LedgerUpgradeType.java │ │ ├── OperationResultCode.java │ │ ├── SCPStatementType.java │ │ ├── TimeBounds.java │ │ ├── SignerKeyType.java │ │ ├── ThresholdIndexes.java │ │ ├── ThresholdIndices.java │ │ ├── ChangeTrustOp.java │ │ ├── ErrorCode.java │ │ ├── SCPEnvelope.java │ │ ├── InflationPayout.java │ │ ├── PaymentResult.java │ │ ├── CreateAccountOp.java │ │ ├── DecoratedSignature.java │ │ ├── LedgerEntryChangeType.java │ │ ├── AllowTrustResult.java │ │ ├── ManageDataResult.java │ │ ├── SetOptionsResult.java │ │ ├── TransactionResultSet.java │ │ ├── ChangeTrustResult.java │ │ ├── LedgerEntryChanges.java │ │ ├── TransactionResultPair.java │ │ ├── CreateAccountResult.java │ │ ├── PublicKey.java │ │ ├── SCPHistoryEntry.java │ │ ├── AccountFlags.java │ │ ├── ManageDataOp.java │ │ ├── AuthCert.java │ │ ├── PaymentOp.java │ │ ├── SimplePaymentResult.java │ │ ├── TransactionSet.java │ │ ├── LedgerSCPMessages.java │ │ ├── AccountMergeResultCode.java │ │ ├── ManageDataResultCode.java │ │ ├── OperationType.java │ │ ├── CreateAccountResultCode.java │ │ ├── ManageOfferResult.java │ │ └── SCPHistoryEntryV0.java │ │ ├── MemoText.java │ │ ├── AssetTypeNative.java │ │ ├── TimeBounds.java │ │ ├── AccountFlag.java │ │ ├── Account.java │ │ ├── AssetTypeCreditAlphaNum4.java │ │ ├── AssetTypeCreditAlphaNum12.java │ │ ├── AssetTypeCreditAlphaNum.java │ │ └── MemoHashAbstract.java └── test │ └── java │ └── org │ └── stellar │ └── sdk │ ├── AccountFlagTest.java │ ├── requests │ ├── LedgersRequestBuilderTest.java │ ├── AccountsRequestBuilderTest.java │ ├── OffersRequestBuilderTest.java │ ├── AssetsRequestBuilderTest.java │ ├── OrderBookRequestBuilderTest.java │ ├── TradeAggregationsRequestBuilderTest.java │ ├── TradesRequestBuilderTest.java │ ├── PathsRequestBuilderTest.java │ └── TransactionsRequestBuilderTest.java │ ├── NetworkTest.java │ ├── xdr │ ├── PaddingTest.java │ └── XdrDataStreamTest.java │ ├── responses │ └── AssetDeserializerTest.java │ ├── StrKeyTest.java │ ├── AccountTest.java │ └── federation │ └── FederationTest.java ├── .gitignore ├── CONTRIBUTING.md ├── after_deploy.sh ├── readme.md ├── .travis.yml └── xdr └── Stellar-types.x /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'java-stellar-sdk' 2 | 3 | -------------------------------------------------------------------------------- /libs/net.i2p.crypto-4.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hubs/java-stellar-sdk/master/libs/net.i2p.crypto-4.0.0.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hubs/java-stellar-sdk/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/federation/ConnectionErrorException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.federation; 2 | 3 | public class ConnectionErrorException extends RuntimeException { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/federation/NotFoundException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.federation; 2 | 3 | /** 4 | * Stellar address not found by federation server 5 | */ 6 | public class NotFoundException extends RuntimeException { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/federation/ServerErrorException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.federation; 2 | 3 | /** 4 | * Federation server responded with error 5 | */ 6 | public class ServerErrorException extends RuntimeException { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/federation/MalformedAddressException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.federation; 2 | 3 | /** 4 | * Given Stellar address is malformed. 5 | */ 6 | public class MalformedAddressException extends RuntimeException { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/federation/NoFederationServerException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.federation; 2 | 3 | /** 4 | * Federation server was not found in stellar.toml file. 5 | */ 6 | public class NoFederationServerException extends RuntimeException { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/federation/StellarTomlNotFoundInvalidException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.federation; 2 | 3 | /** 4 | * Stellar.toml file was not found or was malformed. 5 | */ 6 | public class StellarTomlNotFoundInvalidException extends RuntimeException { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/federation/FederationServerInvalidException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.federation; 2 | 3 | /** 4 | * Federation server is invalid (malformed URL, not HTTPS, etc.) 5 | */ 6 | public class FederationServerInvalidException extends RuntimeException { 7 | } 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Sep 09 23:28:22 CEST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Java class files 2 | *.class 3 | 4 | # Intellij project files 5 | *.iml 6 | *.ipr 7 | *.iws 8 | .idea/ 9 | /local.properties 10 | 11 | # Eclipse project files 12 | .settings 13 | .classpath 14 | .project 15 | 16 | # Gradle 17 | .gradle 18 | build 19 | 20 | # Mac 21 | .DS_Store 22 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | Please read the [Contribution Guide](https://github.com/stellar/docs/blob/master/CONTRIBUTING.md). 4 | 5 | Then please [sign the Contributor License Agreement](https://docs.google.com/forms/d/1g7EF6PERciwn7zfmfke5Sir2n10yddGGSXyZsq98tVY/viewform?usp=send_form). 6 | 7 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/SignerRemovedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents signer_removed effect response. 5 | */ 6 | public class SignerRemovedEffectResponse extends SignerEffectResponse { 7 | SignerRemovedEffectResponse(Integer weight, String publicKey) { 8 | super(weight, publicKey); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/FormatException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | /** 4 | * Indicates that there was a problem decoding strkey encoded string. 5 | * @see KeyPair 6 | */ 7 | public class FormatException extends RuntimeException { 8 | public FormatException() { 9 | super(); 10 | } 11 | 12 | public FormatException(String message) { 13 | super(message); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/MemoTooLongException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | /** 4 | * Indicates that value passed to Memo 5 | * @see Memo 6 | */ 7 | public class MemoTooLongException extends RuntimeException { 8 | public MemoTooLongException() { 9 | super(); 10 | } 11 | 12 | public MemoTooLongException(String message) { 13 | super(message); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/MemoNone.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.stellar.sdk.xdr.MemoType; 4 | 5 | /** 6 | * Represents MEMO_NONE. 7 | */ 8 | public class MemoNone extends Memo { 9 | @Override 10 | org.stellar.sdk.xdr.Memo toXdr() { 11 | org.stellar.sdk.xdr.Memo memo = new org.stellar.sdk.xdr.Memo(); 12 | memo.setDiscriminant(MemoType.MEMO_NONE); 13 | return memo; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/NoNetworkSelectedException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | /** 4 | * Indicates that no network was selected. 5 | */ 6 | public class NoNetworkSelectedException extends RuntimeException { 7 | public NoNetworkSelectedException() { 8 | super("No network selected. Use `Network.use`, `Network.usePublicNetwork` or `Network.useTestNetwork` helper methods to select network."); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/requests/EventListener.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | /** 4 | * This interface is used in {@link RequestBuilder} classes stream method. 5 | */ 6 | public interface EventListener { 7 | /** 8 | * This method will be called when new event is sent by a server. 9 | * @param object object deserialized from the event data 10 | */ 11 | void onEvent(T object); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/TypedResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses; 2 | 3 | import com.google.gson.reflect.TypeToken; 4 | 5 | /** 6 | * Indicates a generic container that requires type information to be provided after initialisation. 7 | * 8 | * @param the type of the objects in this response container. 9 | */ 10 | public interface TypedResponse { 11 | 12 | void setType(TypeToken type); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/NotEnoughSignaturesException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | /** 4 | * Indicates that the object that has to be signed has not enough signatures. 5 | */ 6 | public class NotEnoughSignaturesException extends RuntimeException { 7 | public NotEnoughSignaturesException() { 8 | super(); 9 | } 10 | 11 | public NotEnoughSignaturesException(String message) { 12 | super(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/AccountFlagTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class AccountFlagTest { 8 | @Test 9 | public void testValues() { 10 | assertEquals(1, AccountFlag.AUTH_REQUIRED_FLAG.getValue()); 11 | assertEquals(2, AccountFlag.AUTH_REVOCABLE_FLAG.getValue()); 12 | assertEquals(4, AccountFlag.AUTH_IMMUTABLE_FLAG.getValue()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/AccountRemovedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents account_removed effect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class AccountRemovedEffectResponse extends EffectResponse {} 10 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/DataCreatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents data_created effect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class DataCreatedEffectResponse extends EffectResponse { 10 | // 11 | } -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/DataRemovedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents data_removed effect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class DataRemovedEffectResponse extends EffectResponse { 10 | // 11 | } -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/DataUpdatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents data_updatedeffect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class DataUpdatedEffectResponse extends EffectResponse { 10 | // 11 | } -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/OfferCreatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents offer_created effect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class OfferCreatedEffectResponse extends EffectResponse { 10 | // 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/OfferRemovedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents offer_removed effect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class OfferRemovedEffectResponse extends EffectResponse { 10 | // 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/OfferUpdatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents offer_updated effect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class OfferUpdatedEffectResponse extends EffectResponse { 10 | // 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/AssetCodeLengthInvalidException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | /** 4 | * Indicates that asset code is not valid for a specified asset class 5 | * @see AssetTypeCreditAlphaNum4 6 | * @see AssetTypeCreditAlphaNum12 7 | */ 8 | public class AssetCodeLengthInvalidException extends RuntimeException { 9 | public AssetCodeLengthInvalidException() { 10 | super(); 11 | } 12 | 13 | public AssetCodeLengthInvalidException(String message) { 14 | super(message); 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/operations/InflationOperationResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.operations; 2 | 3 | /** 4 | * Represents Inflation operation response. 5 | * @see Operation documentation 6 | * @see org.stellar.sdk.requests.OperationsRequestBuilder 7 | * @see org.stellar.sdk.Server#operations() 8 | */ 9 | public class InflationOperationResponse extends OperationResponse { 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/AccountInflationDestinationUpdatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents account_inflation_destination_updated effect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class AccountInflationDestinationUpdatedEffectResponse extends EffectResponse { 10 | // 11 | } 12 | -------------------------------------------------------------------------------- /after_deploy.sh: -------------------------------------------------------------------------------- 1 | echo "machine github.com login stellar-jenkins password $GITHUB_TOKEN" >~/.netrc 2 | git clone -b gh-pages "https://stellar-jenkins@github.com/stellar/java-stellar-sdk.git" javadoc 3 | 4 | if [ ! -d "javadoc" ]; then 5 | echo "Error cloning" 6 | exit 1 7 | fi 8 | 9 | rm -rf javadoc/* # Remove all files without hidden (.git) 10 | javadoc -public -splitindex -windowtitle "java-stellar-sdk documentation" -d ./javadoc -sourcepath ./src/main/java/ -subpackages org.stellar.sdk -exclude org.stellar.sdk.xdr 11 | cd javadoc 12 | git add . 13 | git commit -m $TRAVIS_TAG 14 | git push origin gh-pages 15 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/SignerCreatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents signer_created effect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class SignerCreatedEffectResponse extends SignerEffectResponse { 10 | SignerCreatedEffectResponse(Integer weight, String publicKey) { 11 | super(weight, publicKey); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/SignerUpdatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents signed_updated effect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class SignerUpdatedEffectResponse extends SignerEffectResponse { 10 | SignerUpdatedEffectResponse(Integer weight, String publicKey) { 11 | super(weight, publicKey); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/requests/ErrorResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | /** 4 | * Exception thrown when request returned an non-success HTTP code. 5 | */ 6 | public class ErrorResponse extends RuntimeException { 7 | private int code; 8 | private String body; 9 | 10 | public ErrorResponse(int code, String body) { 11 | super("Error response from the server."); 12 | this.code = code; 13 | this.body = body; 14 | } 15 | 16 | public int getCode() { 17 | return code; 18 | } 19 | 20 | public String getBody() { 21 | return body; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/KeyPairTypeAdapter.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses; 2 | 3 | import com.google.gson.TypeAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import com.google.gson.stream.JsonWriter; 6 | 7 | import org.stellar.sdk.KeyPair; 8 | 9 | import java.io.IOException; 10 | 11 | class KeyPairTypeAdapter extends TypeAdapter { 12 | @Override 13 | public void write(JsonWriter out, KeyPair value) throws IOException { 14 | // Don't need this. 15 | } 16 | 17 | @Override 18 | public KeyPair read(JsonReader in) throws IOException { 19 | return KeyPair.fromAccountId(in.nextString()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/requests/LedgersRequestBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | import okhttp3.HttpUrl; 4 | import org.junit.Test; 5 | import org.stellar.sdk.Server; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | 9 | public class LedgersRequestBuilderTest { 10 | @Test 11 | public void testAccounts() { 12 | Server server = new Server("https://horizon-testnet.stellar.org"); 13 | HttpUrl uri = server.ledgers() 14 | .limit(200) 15 | .order(RequestBuilder.Order.ASC) 16 | .buildUri(); 17 | assertEquals("https://horizon-testnet.stellar.org/ledgers?limit=200&order=asc", uri.toString()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/SignerEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | abstract class SignerEffectResponse extends EffectResponse { 6 | @SerializedName("weight") 7 | protected final Integer weight; 8 | @SerializedName("public_key") 9 | protected final String publicKey; 10 | 11 | public SignerEffectResponse(Integer weight, String publicKey) { 12 | this.weight = weight; 13 | this.publicKey = publicKey; 14 | } 15 | 16 | public Integer getWeight() { 17 | return weight; 18 | } 19 | 20 | public String getPublicKey() { 21 | return publicKey; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/TrustlineCreatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents trustline_created effect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class TrustlineCreatedEffectResponse extends TrustlineCUDResponse { 10 | TrustlineCreatedEffectResponse(String limit, String assetType, String assetCode, String assetIssuer) { 11 | super(limit, assetType, assetCode, assetIssuer); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/TrustlineRemovedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents trustline_removed effect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class TrustlineRemovedEffectResponse extends TrustlineCUDResponse { 10 | TrustlineRemovedEffectResponse(String limit, String assetType, String assetCode, String assetIssuer) { 11 | super(limit, assetType, assetCode, assetIssuer); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/TrustlineUpdatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | /** 4 | * Represents trustline_updated effect response. 5 | * @see Effect documentation 6 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 7 | * @see org.stellar.sdk.Server#effects() 8 | */ 9 | public class TrustlineUpdatedEffectResponse extends TrustlineCUDResponse { 10 | TrustlineUpdatedEffectResponse(String limit, String assetType, String assetCode, String assetIssuer) { 11 | super(limit, assetType, assetCode, assetIssuer); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/MemoHash.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.stellar.sdk.xdr.MemoType; 4 | 5 | /** 6 | * Represents MEMO_HASH. 7 | */ 8 | public class MemoHash extends MemoHashAbstract { 9 | public MemoHash(byte[] bytes) { 10 | super(bytes); 11 | } 12 | 13 | public MemoHash(String hexString) { 14 | super(hexString); 15 | } 16 | 17 | @Override 18 | org.stellar.sdk.xdr.Memo toXdr() { 19 | org.stellar.sdk.xdr.Memo memo = new org.stellar.sdk.xdr.Memo(); 20 | memo.setDiscriminant(MemoType.MEMO_HASH); 21 | 22 | org.stellar.sdk.xdr.Hash hash = new org.stellar.sdk.xdr.Hash(); 23 | hash.setHash(bytes); 24 | 25 | memo.setHash(hash); 26 | return memo; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/TrustlineAuthorizedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | import org.stellar.sdk.KeyPair; 4 | 5 | /** 6 | * Represents trustline_authorized effect response. 7 | * @see Effect documentation 8 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 9 | * @see org.stellar.sdk.Server#effects() 10 | */ 11 | public class TrustlineAuthorizedEffectResponse extends TrustlineAuthorizationResponse { 12 | TrustlineAuthorizedEffectResponse(KeyPair trustor, String assetType, String assetCode) { 13 | super(trustor, assetType, assetCode); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/TrustlineDeauthorizedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | import org.stellar.sdk.KeyPair; 4 | 5 | /** 6 | * Represents trustline_deauthorized effect response. 7 | * @see Effect documentation 8 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 9 | * @see org.stellar.sdk.Server#effects() 10 | */ 11 | public class TrustlineDeauthorizedEffectResponse extends TrustlineAuthorizationResponse { 12 | TrustlineDeauthorizedEffectResponse(KeyPair trustor, String assetType, String assetCode) { 13 | super(trustor, assetType, assetCode); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/requests/AccountsRequestBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | import okhttp3.HttpUrl; 4 | import org.junit.Test; 5 | import org.stellar.sdk.Server; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | 9 | public class AccountsRequestBuilderTest { 10 | @Test 11 | public void testAccounts() { 12 | Server server = new Server("https://horizon-testnet.stellar.org"); 13 | HttpUrl uri = server.accounts() 14 | .cursor("13537736921089") 15 | .limit(200) 16 | .order(RequestBuilder.Order.ASC) 17 | .buildUri(); 18 | assertEquals("https://horizon-testnet.stellar.org/accounts?cursor=13537736921089&limit=200&order=asc", uri.toString()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/TransactionBuilderAccount.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | /** 4 | * Specifies interface for Account object used in {@link org.stellar.sdk.Transaction.Builder} 5 | */ 6 | public interface TransactionBuilderAccount { 7 | /** 8 | * Returns keypair associated with this Account 9 | */ 10 | KeyPair getKeypair(); 11 | 12 | /** 13 | * Returns current sequence number ot this Account. 14 | */ 15 | Long getSequenceNumber(); 16 | 17 | /** 18 | * Returns sequence number incremented by one, but does not increment internal counter. 19 | */ 20 | Long getIncrementedSequenceNumber(); 21 | 22 | /** 23 | * Increments sequence number in this object by one. 24 | */ 25 | void incrementSequenceNumber(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/MemoReturnHash.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.stellar.sdk.xdr.Memo; 4 | import org.stellar.sdk.xdr.MemoType; 5 | 6 | /** 7 | * Represents MEMO_RETURN. 8 | */ 9 | public class MemoReturnHash extends MemoHashAbstract { 10 | public MemoReturnHash(byte[] bytes) { 11 | super(bytes); 12 | } 13 | 14 | public MemoReturnHash(String hexString) { 15 | super(hexString); 16 | } 17 | 18 | @Override 19 | Memo toXdr() { 20 | org.stellar.sdk.xdr.Memo memo = new org.stellar.sdk.xdr.Memo(); 21 | memo.setDiscriminant(MemoType.MEMO_RETURN); 22 | 23 | org.stellar.sdk.xdr.Hash hash = new org.stellar.sdk.xdr.Hash(); 24 | hash.setHash(bytes); 25 | 26 | memo.setHash(hash); 27 | return memo; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/InflationOperation.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.stellar.sdk.xdr.OperationType; 4 | 5 | /** 6 | * Represents Inflation operation. 7 | * @see List of Operations 8 | */ 9 | public class InflationOperation extends Operation { 10 | @Override 11 | org.stellar.sdk.xdr.Operation.OperationBody toOperationBody() { 12 | org.stellar.sdk.xdr.Operation.OperationBody body = new org.stellar.sdk.xdr.Operation.OperationBody(); 13 | body.setDiscriminant(OperationType.INFLATION); 14 | return body; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/requests/TooManyRequestsException.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | /** 4 | * Exception thrown when too many requests were sent to the Horizon server. 5 | * @see Rate Limiting 6 | */ 7 | public class TooManyRequestsException extends RuntimeException { 8 | private int retryAfter; 9 | 10 | public TooManyRequestsException(int retryAfter) { 11 | super("The rate limit for the requesting IP address is over its alloted limit."); 12 | this.retryAfter = retryAfter; 13 | } 14 | 15 | /** 16 | * Returns number of seconds a client should wait before sending requests again. 17 | */ 18 | public int getRetryAfter() { 19 | return retryAfter; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/MemoId.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.stellar.sdk.xdr.MemoType; 4 | import org.stellar.sdk.xdr.Uint64; 5 | 6 | /** 7 | * Represents MEMO_ID. 8 | */ 9 | public class MemoId extends Memo { 10 | private long id; 11 | 12 | public MemoId(long id) { 13 | if (id < 0) { 14 | throw new IllegalArgumentException("id must be a positive number"); 15 | } 16 | this.id = id; 17 | } 18 | 19 | public long getId() { 20 | return id; 21 | } 22 | 23 | @Override 24 | org.stellar.sdk.xdr.Memo toXdr() { 25 | org.stellar.sdk.xdr.Memo memo = new org.stellar.sdk.xdr.Memo(); 26 | memo.setDiscriminant(MemoType.MEMO_ID); 27 | Uint64 idXdr = new Uint64(); 28 | idXdr.setUint64(id); 29 | memo.setId(idXdr); 30 | return memo; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/AccountCreatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Represents account_created effect response. 7 | * @see Effect documentation 8 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 9 | * @see org.stellar.sdk.Server#effects() 10 | */ 11 | public class AccountCreatedEffectResponse extends EffectResponse { 12 | @SerializedName("starting_balance") 13 | protected final String startingBalance; 14 | 15 | AccountCreatedEffectResponse(String startingBalance) { 16 | this.startingBalance = startingBalance; 17 | } 18 | 19 | public String getStartingBalance() { 20 | return startingBalance; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/AccountHomeDomainUpdatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Represents account_home_domain_updated effect response. 7 | * @see Effect documentation 8 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 9 | * @see org.stellar.sdk.Server#effects() 10 | */ 11 | public class AccountHomeDomainUpdatedEffectResponse extends EffectResponse { 12 | @SerializedName("home_domain") 13 | protected final String homeDomain; 14 | 15 | AccountHomeDomainUpdatedEffectResponse(String homeDomain) { 16 | this.homeDomain = homeDomain; 17 | } 18 | 19 | public String getHomeDomain() { 20 | return homeDomain; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/requests/OffersRequestBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | import okhttp3.HttpUrl; 4 | import org.junit.Test; 5 | import org.stellar.sdk.KeyPair; 6 | import org.stellar.sdk.Server; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | public class OffersRequestBuilderTest { 11 | @Test 12 | public void testForAccount() { 13 | Server server = new Server("https://horizon-testnet.stellar.org"); 14 | HttpUrl uri = server.offers() 15 | .forAccount(KeyPair.fromAccountId("GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H")) 16 | .limit(200) 17 | .order(RequestBuilder.Order.DESC) 18 | .buildUri(); 19 | assertEquals("https://horizon-testnet.stellar.org/accounts/GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H/offers?limit=200&order=desc", uri.toString()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/Link.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.net.URI; 6 | import java.net.URISyntaxException; 7 | 8 | /** 9 | * Represents links in responses. 10 | */ 11 | public class Link { 12 | @SerializedName("href") 13 | private final String href; 14 | @SerializedName("templated") 15 | private final boolean templated; 16 | 17 | Link(String href, boolean templated) { 18 | this.href = href; 19 | this.templated = templated; 20 | } 21 | 22 | public String getHref() { 23 | // TODO templated 24 | return href; 25 | } 26 | 27 | public URI getUri() { 28 | // TODO templated 29 | try { 30 | return new URI(href); 31 | } catch (URISyntaxException e) { 32 | throw new RuntimeException(e); 33 | } 34 | } 35 | 36 | public boolean isTemplated() { 37 | return templated; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/NetworkTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.junit.After; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertNull; 8 | 9 | public class NetworkTest { 10 | @After 11 | public void resetNetwork() { 12 | Network.use(null); 13 | } 14 | 15 | @Test 16 | public void testNoDefaultNetwork() { 17 | assertNull(Network.current()); 18 | } 19 | 20 | @Test 21 | public void testSwitchToTestNetwork() { 22 | Network.useTestNetwork(); 23 | assertEquals("Test SDF Network ; September 2015", Network.current().getNetworkPassphrase()); 24 | } 25 | 26 | @Test 27 | public void testSwitchToPublicNetwork() { 28 | Network.usePublicNetwork(); 29 | assertEquals("Public Global Stellar Network ; September 2015", Network.current().getNetworkPassphrase()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/TrustlineAuthorizationResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import org.stellar.sdk.KeyPair; 6 | 7 | abstract class TrustlineAuthorizationResponse extends EffectResponse { 8 | @SerializedName("trustor") 9 | protected final KeyPair trustor; 10 | @SerializedName("asset_type") 11 | protected final String assetType; 12 | @SerializedName("asset_code") 13 | protected final String assetCode; 14 | 15 | TrustlineAuthorizationResponse(KeyPair trustor, String assetType, String assetCode) { 16 | this.trustor = trustor; 17 | this.assetType = assetType; 18 | this.assetCode = assetCode; 19 | } 20 | 21 | public KeyPair getTrustor() { 22 | return trustor; 23 | } 24 | 25 | public String getAssetType() { 26 | return assetType; 27 | } 28 | 29 | public String getAssetCode() { 30 | return assetCode; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/operations/ManageDataOperationResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.operations; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Represents ManageDataoperation response. 7 | * @see Operation documentation 8 | * @see org.stellar.sdk.requests.OperationsRequestBuilder 9 | * @see org.stellar.sdk.Server#operations() 10 | */ 11 | public class ManageDataOperationResponse extends OperationResponse { 12 | @SerializedName("name") 13 | protected final String name; 14 | @SerializedName("value") 15 | protected final String value; 16 | 17 | ManageDataOperationResponse(String name, String value) { 18 | this.name = name; 19 | this.value = value; 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public String getValue() { 27 | return value; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Int64.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef hyper int64; 12 | 13 | // =========================================================================== 14 | public class Int64 { 15 | private Long int64; 16 | public Long getInt64() { 17 | return this.int64; 18 | } 19 | public void setInt64(Long value) { 20 | this.int64 = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, Int64 encodedInt64) throws IOException { 23 | stream.writeLong(encodedInt64.int64); 24 | } 25 | public static Int64 decode(XdrDataInputStream stream) throws IOException { 26 | Int64 decodedInt64 = new Int64(); 27 | decodedInt64.int64 = stream.readLong(); 28 | return decodedInt64; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Int32.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef int int32; 12 | 13 | // =========================================================================== 14 | public class Int32 { 15 | private Integer int32; 16 | public Integer getInt32() { 17 | return this.int32; 18 | } 19 | public void setInt32(Integer value) { 20 | this.int32 = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, Int32 encodedInt32) throws IOException { 23 | stream.writeInt(encodedInt32.int32); 24 | } 25 | public static Int32 decode(XdrDataInputStream stream) throws IOException { 26 | Int32 decodedInt32 = new Int32(); 27 | decodedInt32.int32 = stream.readInt(); 28 | return decodedInt32; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/requests/AssetsRequestBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | import okhttp3.HttpUrl; 4 | import org.junit.Test; 5 | import org.stellar.sdk.Server; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | 9 | public class AssetsRequestBuilderTest { 10 | @Test 11 | public void testAccounts() { 12 | Server server = new Server("https://horizon-testnet.stellar.org"); 13 | HttpUrl uri = server.assets() 14 | .assetCode("USD") 15 | .assetIssuer("GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN") 16 | .cursor("13537736921089") 17 | .limit(200) 18 | .order(RequestBuilder.Order.ASC) 19 | .buildUri(); 20 | assertEquals("https://horizon-testnet.stellar.org/assets?asset_code=USD&asset_issuer=GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN&cursor=13537736921089&limit=200&order=asc", uri.toString()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/MemoText.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.stellar.sdk.xdr.MemoType; 4 | 5 | import java.nio.charset.Charset; 6 | 7 | import static com.google.common.base.Preconditions.checkNotNull; 8 | 9 | /** 10 | * Represents MEMO_TEXT. 11 | */ 12 | public class MemoText extends Memo { 13 | private String text; 14 | 15 | public MemoText(String text) { 16 | this.text = checkNotNull(text, "text cannot be null"); 17 | 18 | int length = text.getBytes((Charset.forName("UTF-8"))).length; 19 | if (length > 28) { 20 | throw new MemoTooLongException("text must be <= 28 bytes. length=" + String.valueOf(length)); 21 | } 22 | } 23 | 24 | public String getText() { 25 | return text; 26 | } 27 | 28 | @Override 29 | org.stellar.sdk.xdr.Memo toXdr() { 30 | org.stellar.sdk.xdr.Memo memo = new org.stellar.sdk.xdr.Memo(); 31 | memo.setDiscriminant(MemoType.MEMO_TEXT); 32 | memo.setText(text); 33 | return memo; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Uint64.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef unsigned hyper uint64; 12 | 13 | // =========================================================================== 14 | public class Uint64 { 15 | private Long uint64; 16 | public Long getUint64() { 17 | return this.uint64; 18 | } 19 | public void setUint64(Long value) { 20 | this.uint64 = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, Uint64 encodedUint64) throws IOException { 23 | stream.writeLong(encodedUint64.uint64); 24 | } 25 | public static Uint64 decode(XdrDataInputStream stream) throws IOException { 26 | Uint64 decodedUint64 = new Uint64(); 27 | decodedUint64.uint64 = stream.readLong(); 28 | return decodedUint64; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Uint32.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef unsigned int uint32; 12 | 13 | // =========================================================================== 14 | public class Uint32 { 15 | private Integer uint32; 16 | public Integer getUint32() { 17 | return this.uint32; 18 | } 19 | public void setUint32(Integer value) { 20 | this.uint32 = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, Uint32 encodedUint32) throws IOException { 23 | stream.writeInt(encodedUint32.uint32); 24 | } 25 | public static Uint32 decode(XdrDataInputStream stream) throws IOException { 26 | Uint32 decodedUint32 = new Uint32(); 27 | decodedUint32.uint32 = stream.readInt(); 28 | return decodedUint32; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/AssetTypeNative.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.stellar.sdk.xdr.AssetType; 4 | 5 | /** 6 | * Represents Stellar native asset - lumens (XLM) 7 | * @see Assets 8 | */ 9 | public final class AssetTypeNative extends Asset { 10 | 11 | public AssetTypeNative() {} 12 | 13 | @Override 14 | public String getType() { 15 | return "native"; 16 | } 17 | 18 | @Override 19 | public boolean equals(Object object) { 20 | return this.getClass().equals(object.getClass()); 21 | } 22 | 23 | @Override 24 | public int hashCode() { 25 | return 0; 26 | } 27 | 28 | @Override 29 | public org.stellar.sdk.xdr.Asset toXdr() { 30 | org.stellar.sdk.xdr.Asset xdr = new org.stellar.sdk.xdr.Asset(); 31 | xdr.setDiscriminant(AssetType.ASSET_TYPE_NATIVE); 32 | return xdr; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/NodeID.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef PublicKey NodeID; 12 | 13 | // =========================================================================== 14 | public class NodeID { 15 | private PublicKey NodeID; 16 | public PublicKey getNodeID() { 17 | return this.NodeID; 18 | } 19 | public void setNodeID(PublicKey value) { 20 | this.NodeID = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, NodeID encodedNodeID) throws IOException { 23 | PublicKey.encode(stream, encodedNodeID.NodeID); 24 | } 25 | public static NodeID decode(XdrDataInputStream stream) throws IOException { 26 | NodeID decodedNodeID = new NodeID(); 27 | decodedNodeID.NodeID = PublicKey.decode(stream); 28 | return decodedNodeID; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/operations/AccountMergeOperationResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.operations; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import org.stellar.sdk.KeyPair; 6 | 7 | /** 8 | * Represents AccountMerge operation response. 9 | * @see Operation documentation 10 | * @see org.stellar.sdk.requests.OperationsRequestBuilder 11 | * @see org.stellar.sdk.Server#operations() 12 | */ 13 | public class AccountMergeOperationResponse extends OperationResponse { 14 | @SerializedName("account") 15 | protected final KeyPair account; 16 | @SerializedName("into") 17 | protected final KeyPair into; 18 | 19 | AccountMergeOperationResponse(KeyPair account, KeyPair into) { 20 | this.account = account; 21 | this.into = into; 22 | } 23 | 24 | public KeyPair getAccount() { 25 | return account; 26 | } 27 | 28 | public KeyPair getInto() { 29 | return into; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/String32.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef string string32<32>; 12 | 13 | // =========================================================================== 14 | public class String32 { 15 | private String string32; 16 | public String getString32() { 17 | return this.string32; 18 | } 19 | public void setString32(String value) { 20 | this.string32 = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, String32 encodedString32) throws IOException { 23 | stream.writeString(encodedString32.string32); 24 | } 25 | public static String32 decode(XdrDataInputStream stream) throws IOException { 26 | String32 decodedString32 = new String32(); 27 | decodedString32.string32 = stream.readString(); 28 | return decodedString32; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/String64.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef string string64<64>; 12 | 13 | // =========================================================================== 14 | public class String64 { 15 | private String string64; 16 | public String getString64() { 17 | return this.string64; 18 | } 19 | public void setString64(String value) { 20 | this.string64 = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, String64 encodedString64) throws IOException { 23 | stream.writeString(encodedString64.string64); 24 | } 25 | public static String64 decode(XdrDataInputStream stream) throws IOException { 26 | String64 decodedString64 = new String64(); 27 | decodedString64.string64 = stream.readString(); 28 | return decodedString64; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/AccountID.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef PublicKey AccountID; 12 | 13 | // =========================================================================== 14 | public class AccountID { 15 | private PublicKey AccountID; 16 | public PublicKey getAccountID() { 17 | return this.AccountID; 18 | } 19 | public void setAccountID(PublicKey value) { 20 | this.AccountID = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, AccountID encodedAccountID) throws IOException { 23 | PublicKey.encode(stream, encodedAccountID.AccountID); 24 | } 25 | public static AccountID decode(XdrDataInputStream stream) throws IOException { 26 | AccountID decodedAccountID = new AccountID(); 27 | decodedAccountID.AccountID = PublicKey.decode(stream); 28 | return decodedAccountID; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/AssetDeserializer.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses; 2 | 3 | import com.google.gson.JsonDeserializationContext; 4 | import com.google.gson.JsonDeserializer; 5 | import com.google.gson.JsonElement; 6 | import com.google.gson.JsonParseException; 7 | 8 | import org.stellar.sdk.Asset; 9 | import org.stellar.sdk.AssetTypeNative; 10 | import org.stellar.sdk.KeyPair; 11 | 12 | import java.lang.reflect.Type; 13 | 14 | class AssetDeserializer implements JsonDeserializer { 15 | @Override 16 | public Asset deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { 17 | String type = json.getAsJsonObject().get("asset_type").getAsString(); 18 | if (type.equals("native")) { 19 | return new AssetTypeNative(); 20 | } else { 21 | String code = json.getAsJsonObject().get("asset_code").getAsString(); 22 | String issuer = json.getAsJsonObject().get("asset_issuer").getAsString(); 23 | return Asset.createNonNativeAsset(code, KeyPair.fromAccountId(issuer)); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Hash.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef opaque Hash[32]; 12 | 13 | // =========================================================================== 14 | public class Hash { 15 | private byte[] Hash; 16 | public byte[] getHash() { 17 | return this.Hash; 18 | } 19 | public void setHash(byte[] value) { 20 | this.Hash = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, Hash encodedHash) throws IOException { 23 | int Hashsize = encodedHash.Hash.length; 24 | stream.write(encodedHash.getHash(), 0, Hashsize); 25 | } 26 | public static Hash decode(XdrDataInputStream stream) throws IOException { 27 | Hash decodedHash = new Hash(); 28 | int Hashsize = 32; 29 | decodedHash.Hash = new byte[Hashsize]; 30 | stream.read(decodedHash.Hash, 0, Hashsize); 31 | return decodedHash; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Auth.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct Auth 12 | // { 13 | // // Empty message, just to confirm 14 | // // establishment of MAC keys. 15 | // int unused; 16 | // }; 17 | 18 | // =========================================================================== 19 | public class Auth { 20 | public Auth () {} 21 | private Integer unused; 22 | public Integer getUnused() { 23 | return this.unused; 24 | } 25 | public void setUnused(Integer value) { 26 | this.unused = value; 27 | } 28 | public static void encode(XdrDataOutputStream stream, Auth encodedAuth) throws IOException{ 29 | stream.writeInt(encodedAuth.unused); 30 | } 31 | public static Auth decode(XdrDataInputStream stream) throws IOException { 32 | Auth decodedAuth = new Auth(); 33 | decodedAuth.unused = stream.readInt(); 34 | return decodedAuth; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/AccountFlagsUpdatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Represents account_flags_updated effect response. 7 | * @see Effect documentation 8 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 9 | * @see org.stellar.sdk.Server#effects() 10 | */ 11 | public class AccountFlagsUpdatedEffectResponse extends EffectResponse { 12 | @SerializedName("auth_required_flag") 13 | protected final Boolean authRequiredFlag; 14 | @SerializedName("auth_revokable_flag") 15 | protected final Boolean authRevokableFlag; 16 | 17 | AccountFlagsUpdatedEffectResponse(Boolean authRequiredFlag, Boolean authRevokableFlag) { 18 | this.authRequiredFlag = authRequiredFlag; 19 | this.authRevokableFlag = authRevokableFlag; 20 | } 21 | 22 | public Boolean getAuthRequiredFlag() { 23 | return authRequiredFlag; 24 | } 25 | 26 | public Boolean getAuthRevokableFlag() { 27 | return authRevokableFlag; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/SequenceNumber.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef uint64 SequenceNumber; 12 | 13 | // =========================================================================== 14 | public class SequenceNumber { 15 | private Uint64 SequenceNumber; 16 | public Uint64 getSequenceNumber() { 17 | return this.SequenceNumber; 18 | } 19 | public void setSequenceNumber(Uint64 value) { 20 | this.SequenceNumber = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, SequenceNumber encodedSequenceNumber) throws IOException { 23 | Uint64.encode(stream, encodedSequenceNumber.SequenceNumber); 24 | } 25 | public static SequenceNumber decode(XdrDataInputStream stream) throws IOException { 26 | SequenceNumber decodedSequenceNumber = new SequenceNumber(); 27 | decodedSequenceNumber.SequenceNumber = Uint64.decode(stream); 28 | return decodedSequenceNumber; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Value.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef opaque Value<>; 12 | 13 | // =========================================================================== 14 | public class Value { 15 | private byte[] Value; 16 | public byte[] getValue() { 17 | return this.Value; 18 | } 19 | public void setValue(byte[] value) { 20 | this.Value = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, Value encodedValue) throws IOException { 23 | int Valuesize = encodedValue.Value.length; 24 | stream.writeInt(Valuesize); 25 | stream.write(encodedValue.getValue(), 0, Valuesize); 26 | } 27 | public static Value decode(XdrDataInputStream stream) throws IOException { 28 | Value decodedValue = new Value(); 29 | int Valuesize = stream.readInt(); 30 | decodedValue.Value = new byte[Valuesize]; 31 | stream.read(decodedValue.Value, 0, Valuesize); 32 | return decodedValue; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Uint256.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef opaque uint256[32]; 12 | 13 | // =========================================================================== 14 | public class Uint256 { 15 | private byte[] uint256; 16 | public byte[] getUint256() { 17 | return this.uint256; 18 | } 19 | public void setUint256(byte[] value) { 20 | this.uint256 = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, Uint256 encodedUint256) throws IOException { 23 | int uint256size = encodedUint256.uint256.length; 24 | stream.write(encodedUint256.getUint256(), 0, uint256size); 25 | } 26 | public static Uint256 decode(XdrDataInputStream stream) throws IOException { 27 | Uint256 decodedUint256 = new Uint256(); 28 | int uint256size = 32; 29 | decodedUint256.uint256 = new byte[uint256size]; 30 | stream.read(decodedUint256.uint256, 0, uint256size); 31 | return decodedUint256; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/IPAddrType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum IPAddrType 12 | // { 13 | // IPv4 = 0, 14 | // IPv6 = 1 15 | // }; 16 | 17 | // =========================================================================== 18 | public enum IPAddrType { 19 | IPv4(0), 20 | IPv6(1), 21 | ; 22 | private int mValue; 23 | 24 | IPAddrType(int value) { 25 | mValue = value; 26 | } 27 | 28 | public int getValue() { 29 | return mValue; 30 | } 31 | 32 | static IPAddrType decode(XdrDataInputStream stream) throws IOException { 33 | int value = stream.readInt(); 34 | switch (value) { 35 | case 0: return IPv4; 36 | case 1: return IPv6; 37 | default: 38 | throw new RuntimeException("Unknown enum value: " + value); 39 | } 40 | } 41 | 42 | static void encode(XdrDataOutputStream stream, IPAddrType value) throws IOException { 43 | stream.writeInt(value.getValue()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/PublicKeyType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum PublicKeyType 12 | // { 13 | // PUBLIC_KEY_TYPE_ED25519 = KEY_TYPE_ED25519 14 | // }; 15 | 16 | // =========================================================================== 17 | public enum PublicKeyType { 18 | PUBLIC_KEY_TYPE_ED25519(0), 19 | ; 20 | private int mValue; 21 | 22 | PublicKeyType(int value) { 23 | mValue = value; 24 | } 25 | 26 | public int getValue() { 27 | return mValue; 28 | } 29 | 30 | static PublicKeyType decode(XdrDataInputStream stream) throws IOException { 31 | int value = stream.readInt(); 32 | switch (value) { 33 | case 0: return PUBLIC_KEY_TYPE_ED25519; 34 | default: 35 | throw new RuntimeException("Unknown enum value: " + value); 36 | } 37 | } 38 | 39 | static void encode(XdrDataOutputStream stream, PublicKeyType value) throws IOException { 40 | stream.writeInt(value.getValue()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/xdr/PaddingTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.xdr; 2 | 3 | import junit.framework.TestCase; 4 | import org.junit.Test; 5 | 6 | import java.io.ByteArrayInputStream; 7 | import java.io.IOException; 8 | 9 | public class PaddingTest extends TestCase { 10 | @Test 11 | public void testString() throws IOException { 12 | byte[] bytes = {0, 0, 0, 2, 'a', 'b', 1, 0}; 13 | 14 | try { 15 | String32 xdrObject = String32.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); 16 | fail("Didn't throw IOException"); 17 | } catch (IOException expectedException) { 18 | assertEquals("non-zero padding", expectedException.getMessage()); 19 | } 20 | } 21 | 22 | @Test 23 | public void testVarOpaque() throws IOException { 24 | byte[] bytes = {0, 0, 0, 2, 'a', 'b', 1, 0}; 25 | 26 | try { 27 | DataValue xdrObject = DataValue.decode(new XdrDataInputStream(new ByteArrayInputStream(bytes))); 28 | fail("Didn't throw IOException"); 29 | } catch (IOException expectedException) { 30 | assertEquals("non-zero padding", expectedException.getMessage()); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/TimeBounds.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.stellar.sdk.xdr.Uint64; 4 | 5 | /** 6 | *

TimeBounds represents the time interval that a transaction is valid.

7 | * @see Transaction 8 | */ 9 | final public class TimeBounds { 10 | final private long mMinTime; 11 | final private long mMaxTime; 12 | 13 | /** 14 | * @param minTime 64bit Unix timestamp 15 | * @param maxTime 64bit Unix timestamp 16 | */ 17 | public TimeBounds(long minTime, long maxTime) { 18 | if(minTime >= maxTime) { 19 | throw new IllegalArgumentException("minTime must be >= maxTime"); 20 | } 21 | 22 | mMinTime = minTime; 23 | mMaxTime = maxTime; 24 | } 25 | 26 | public long getMinTime() { 27 | return mMinTime; 28 | } 29 | 30 | public long getMaxTime() { 31 | return mMaxTime; 32 | } 33 | 34 | public org.stellar.sdk.xdr.TimeBounds toXdr() { 35 | org.stellar.sdk.xdr.TimeBounds timeBounds = new org.stellar.sdk.xdr.TimeBounds(); 36 | Uint64 minTime = new Uint64(); 37 | Uint64 maxTime = new Uint64(); 38 | minTime.setUint64(mMinTime); 39 | maxTime.setUint64(mMaxTime); 40 | timeBounds.setMinTime(minTime); 41 | timeBounds.setMaxTime(maxTime); 42 | return timeBounds; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/AccountFlag.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.stellar.sdk.xdr.AccountFlags; 4 | 5 | /** 6 | * AccountFlag is the enum that can be used in {@link SetOptionsOperation}. 7 | * @see Account Flags 8 | */ 9 | public enum AccountFlag { 10 | /** 11 | * Authorization required (0x1): Requires the issuing account to give other accounts permission before they can hold the issuing account’s credit. 12 | */ 13 | AUTH_REQUIRED_FLAG(AccountFlags.AUTH_REQUIRED_FLAG.getValue()), 14 | /** 15 | * Authorization revocable (0x2): Allows the issuing account to revoke its credit held by other accounts. 16 | */ 17 | AUTH_REVOCABLE_FLAG(AccountFlags.AUTH_REVOCABLE_FLAG.getValue()), 18 | /** 19 | * Authorization immutable (0x4): If this is set then none of the authorization flags can be set and the account can never be deleted. 20 | */ 21 | AUTH_IMMUTABLE_FLAG(AccountFlags.AUTH_IMMUTABLE_FLAG.getValue()), 22 | ; 23 | 24 | private final int value; 25 | AccountFlag(int value) { 26 | this.value = value; 27 | } 28 | 29 | public int getValue() { 30 | return value; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/OperationMeta.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct OperationMeta 12 | // { 13 | // LedgerEntryChanges changes; 14 | // }; 15 | 16 | // =========================================================================== 17 | public class OperationMeta { 18 | public OperationMeta () {} 19 | private LedgerEntryChanges changes; 20 | public LedgerEntryChanges getChanges() { 21 | return this.changes; 22 | } 23 | public void setChanges(LedgerEntryChanges value) { 24 | this.changes = value; 25 | } 26 | public static void encode(XdrDataOutputStream stream, OperationMeta encodedOperationMeta) throws IOException{ 27 | LedgerEntryChanges.encode(stream, encodedOperationMeta.changes); 28 | } 29 | public static OperationMeta decode(XdrDataInputStream stream) throws IOException { 30 | OperationMeta decodedOperationMeta = new OperationMeta(); 31 | decodedOperationMeta.changes = LedgerEntryChanges.decode(stream); 32 | return decodedOperationMeta; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/BucketEntryType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum BucketEntryType 12 | // { 13 | // LIVEENTRY = 0, 14 | // DEADENTRY = 1 15 | // }; 16 | 17 | // =========================================================================== 18 | public enum BucketEntryType { 19 | LIVEENTRY(0), 20 | DEADENTRY(1), 21 | ; 22 | private int mValue; 23 | 24 | BucketEntryType(int value) { 25 | mValue = value; 26 | } 27 | 28 | public int getValue() { 29 | return mValue; 30 | } 31 | 32 | static BucketEntryType decode(XdrDataInputStream stream) throws IOException { 33 | int value = stream.readInt(); 34 | switch (value) { 35 | case 0: return LIVEENTRY; 36 | case 1: return DEADENTRY; 37 | default: 38 | throw new RuntimeException("Unknown enum value: " + value); 39 | } 40 | } 41 | 42 | static void encode(XdrDataOutputStream stream, BucketEntryType value) throws IOException { 43 | stream.writeInt(value.getValue()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/OfferEntryFlags.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum OfferEntryFlags 12 | // { 13 | // // issuer has authorized account to perform transactions with its credit 14 | // PASSIVE_FLAG = 1 15 | // }; 16 | 17 | // =========================================================================== 18 | public enum OfferEntryFlags { 19 | PASSIVE_FLAG(1), 20 | ; 21 | private int mValue; 22 | 23 | OfferEntryFlags(int value) { 24 | mValue = value; 25 | } 26 | 27 | public int getValue() { 28 | return mValue; 29 | } 30 | 31 | static OfferEntryFlags decode(XdrDataInputStream stream) throws IOException { 32 | int value = stream.readInt(); 33 | switch (value) { 34 | case 1: return PASSIVE_FLAG; 35 | default: 36 | throw new RuntimeException("Unknown enum value: " + value); 37 | } 38 | } 39 | 40 | static void encode(XdrDataOutputStream stream, OfferEntryFlags value) throws IOException { 41 | stream.writeInt(value.getValue()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/TrustLineFlags.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum TrustLineFlags 12 | // { 13 | // // issuer has authorized account to perform transactions with its credit 14 | // AUTHORIZED_FLAG = 1 15 | // }; 16 | 17 | // =========================================================================== 18 | public enum TrustLineFlags { 19 | AUTHORIZED_FLAG(1), 20 | ; 21 | private int mValue; 22 | 23 | TrustLineFlags(int value) { 24 | mValue = value; 25 | } 26 | 27 | public int getValue() { 28 | return mValue; 29 | } 30 | 31 | static TrustLineFlags decode(XdrDataInputStream stream) throws IOException { 32 | int value = stream.readInt(); 33 | switch (value) { 34 | case 1: return AUTHORIZED_FLAG; 35 | default: 36 | throw new RuntimeException("Unknown enum value: " + value); 37 | } 38 | } 39 | 40 | static void encode(XdrDataOutputStream stream, TrustLineFlags value) throws IOException { 41 | stream.writeInt(value.getValue()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/TrustlineCUDResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import org.stellar.sdk.Asset; 6 | import org.stellar.sdk.AssetTypeNative; 7 | import org.stellar.sdk.KeyPair; 8 | 9 | abstract class TrustlineCUDResponse extends EffectResponse { 10 | @SerializedName("limit") 11 | protected final String limit; 12 | @SerializedName("asset_type") 13 | protected final String assetType; 14 | @SerializedName("asset_code") 15 | protected final String assetCode; 16 | @SerializedName("asset_issuer") 17 | protected final String assetIssuer; 18 | 19 | public TrustlineCUDResponse(String limit, String assetType, String assetCode, String assetIssuer) { 20 | this.limit = limit; 21 | this.assetType = assetType; 22 | this.assetCode = assetCode; 23 | this.assetIssuer = assetIssuer; 24 | } 25 | 26 | public String getLimit() { 27 | return limit; 28 | } 29 | 30 | public Asset getAsset() { 31 | if (assetType.equals("native")) { 32 | return new AssetTypeNative(); 33 | } else { 34 | KeyPair issuer = KeyPair.fromAccountId(assetIssuer); 35 | return Asset.createNonNativeAsset(assetCode, issuer); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Thresholds.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef opaque Thresholds[4]; 12 | 13 | // =========================================================================== 14 | public class Thresholds { 15 | private byte[] Thresholds; 16 | public byte[] getThresholds() { 17 | return this.Thresholds; 18 | } 19 | public void setThresholds(byte[] value) { 20 | this.Thresholds = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, Thresholds encodedThresholds) throws IOException { 23 | int Thresholdssize = encodedThresholds.Thresholds.length; 24 | stream.write(encodedThresholds.getThresholds(), 0, Thresholdssize); 25 | } 26 | public static Thresholds decode(XdrDataInputStream stream) throws IOException { 27 | Thresholds decodedThresholds = new Thresholds(); 28 | int Thresholdssize = 4; 29 | decodedThresholds.Thresholds = new byte[Thresholdssize]; 30 | stream.read(decodedThresholds.Thresholds, 0, Thresholdssize); 31 | return decodedThresholds; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/DataValue.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef opaque DataValue<64>; 12 | 13 | // =========================================================================== 14 | public class DataValue { 15 | private byte[] DataValue; 16 | public byte[] getDataValue() { 17 | return this.DataValue; 18 | } 19 | public void setDataValue(byte[] value) { 20 | this.DataValue = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, DataValue encodedDataValue) throws IOException { 23 | int DataValuesize = encodedDataValue.DataValue.length; 24 | stream.writeInt(DataValuesize); 25 | stream.write(encodedDataValue.getDataValue(), 0, DataValuesize); 26 | } 27 | public static DataValue decode(XdrDataInputStream stream) throws IOException { 28 | DataValue decodedDataValue = new DataValue(); 29 | int DataValuesize = stream.readInt(); 30 | decodedDataValue.DataValue = new byte[DataValuesize]; 31 | stream.read(decodedDataValue.DataValue, 0, DataValuesize); 32 | return decodedDataValue; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Signature.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef opaque Signature<64>; 12 | 13 | // =========================================================================== 14 | public class Signature { 15 | private byte[] Signature; 16 | public byte[] getSignature() { 17 | return this.Signature; 18 | } 19 | public void setSignature(byte[] value) { 20 | this.Signature = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, Signature encodedSignature) throws IOException { 23 | int Signaturesize = encodedSignature.Signature.length; 24 | stream.writeInt(Signaturesize); 25 | stream.write(encodedSignature.getSignature(), 0, Signaturesize); 26 | } 27 | public static Signature decode(XdrDataInputStream stream) throws IOException { 28 | Signature decodedSignature = new Signature(); 29 | int Signaturesize = stream.readInt(); 30 | decodedSignature.Signature = new byte[Signaturesize]; 31 | stream.read(decodedSignature.Signature, 0, Signaturesize); 32 | return decodedSignature; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/HmacSha256Key.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct HmacSha256Key 12 | // { 13 | // opaque key[32]; 14 | // }; 15 | 16 | // =========================================================================== 17 | public class HmacSha256Key { 18 | public HmacSha256Key () {} 19 | private byte[] key; 20 | public byte[] getKey() { 21 | return this.key; 22 | } 23 | public void setKey(byte[] value) { 24 | this.key = value; 25 | } 26 | public static void encode(XdrDataOutputStream stream, HmacSha256Key encodedHmacSha256Key) throws IOException{ 27 | int keysize = encodedHmacSha256Key.key.length; 28 | stream.write(encodedHmacSha256Key.getKey(), 0, keysize); 29 | } 30 | public static HmacSha256Key decode(XdrDataInputStream stream) throws IOException { 31 | HmacSha256Key decodedHmacSha256Key = new HmacSha256Key(); 32 | int keysize = 32; 33 | decodedHmacSha256Key.key = new byte[keysize]; 34 | stream.read(decodedHmacSha256Key.key, 0, keysize); 35 | return decodedHmacSha256Key; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/HmacSha256Mac.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct HmacSha256Mac 12 | // { 13 | // opaque mac[32]; 14 | // }; 15 | 16 | // =========================================================================== 17 | public class HmacSha256Mac { 18 | public HmacSha256Mac () {} 19 | private byte[] mac; 20 | public byte[] getMac() { 21 | return this.mac; 22 | } 23 | public void setMac(byte[] value) { 24 | this.mac = value; 25 | } 26 | public static void encode(XdrDataOutputStream stream, HmacSha256Mac encodedHmacSha256Mac) throws IOException{ 27 | int macsize = encodedHmacSha256Mac.mac.length; 28 | stream.write(encodedHmacSha256Mac.getMac(), 0, macsize); 29 | } 30 | public static HmacSha256Mac decode(XdrDataInputStream stream) throws IOException { 31 | HmacSha256Mac decodedHmacSha256Mac = new HmacSha256Mac(); 32 | int macsize = 32; 33 | decodedHmacSha256Mac.mac = new byte[macsize]; 34 | stream.read(decodedHmacSha256Mac.mac, 0, macsize); 35 | return decodedHmacSha256Mac; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/operations/CreateAccountOperationResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.operations; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import org.stellar.sdk.KeyPair; 6 | 7 | /** 8 | * Represents CreateAccount operation response. 9 | * @see Operation documentation 10 | * @see org.stellar.sdk.requests.OperationsRequestBuilder 11 | * @see org.stellar.sdk.Server#operations() 12 | */ 13 | public class CreateAccountOperationResponse extends OperationResponse { 14 | @SerializedName("account") 15 | protected final KeyPair account; 16 | @SerializedName("funder") 17 | protected final KeyPair funder; 18 | @SerializedName("starting_balance") 19 | protected final String startingBalance; 20 | 21 | CreateAccountOperationResponse(KeyPair funder, String startingBalance, KeyPair account) { 22 | this.funder = funder; 23 | this.startingBalance = startingBalance; 24 | this.account = account; 25 | } 26 | 27 | public KeyPair getAccount() { 28 | return account; 29 | } 30 | 31 | public String getStartingBalance() { 32 | return startingBalance; 33 | } 34 | 35 | public KeyPair getFunder() { 36 | return funder; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Price.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct Price 12 | // { 13 | // int32 n; // numerator 14 | // int32 d; // denominator 15 | // }; 16 | 17 | // =========================================================================== 18 | public class Price { 19 | public Price () {} 20 | private Int32 n; 21 | public Int32 getN() { 22 | return this.n; 23 | } 24 | public void setN(Int32 value) { 25 | this.n = value; 26 | } 27 | private Int32 d; 28 | public Int32 getD() { 29 | return this.d; 30 | } 31 | public void setD(Int32 value) { 32 | this.d = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, Price encodedPrice) throws IOException{ 35 | Int32.encode(stream, encodedPrice.n); 36 | Int32.encode(stream, encodedPrice.d); 37 | } 38 | public static Price decode(XdrDataInputStream stream) throws IOException { 39 | Price decodedPrice = new Price(); 40 | decodedPrice.n = Int32.decode(stream); 41 | decodedPrice.d = Int32.decode(stream); 42 | return decodedPrice; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/requests/OrderBookRequestBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | import okhttp3.HttpUrl; 4 | import org.junit.Test; 5 | import org.stellar.sdk.Asset; 6 | import org.stellar.sdk.KeyPair; 7 | import org.stellar.sdk.Server; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class OrderBookRequestBuilderTest { 12 | @Test 13 | public void testOrderBook() { 14 | Server server = new Server("https://horizon-testnet.stellar.org"); 15 | HttpUrl uri = server.orderBook() 16 | .buyingAsset(Asset.createNonNativeAsset("EUR", KeyPair.fromAccountId("GAUPA4HERNBDPVO4IUA3MJXBCRRK5W54EVXTDK6IIUTGDQRB6D5W242W"))) 17 | .sellingAsset(Asset.createNonNativeAsset("USD", KeyPair.fromAccountId("GDRRHSJMHXDTQBT4JTCILNGF5AS54FEMTXL7KOLMF6TFTHRK6SSUSUZZ"))) 18 | .buildUri(); 19 | 20 | assertEquals( 21 | "https://horizon-testnet.stellar.org/order_book?" + 22 | "buying_asset_type=credit_alphanum4&" + 23 | "buying_asset_code=EUR&" + 24 | "buying_asset_issuer=GAUPA4HERNBDPVO4IUA3MJXBCRRK5W54EVXTDK6IIUTGDQRB6D5W242W&" + 25 | "selling_asset_type=credit_alphanum4&" + 26 | "selling_asset_code=USD&" + 27 | "selling_asset_issuer=GDRRHSJMHXDTQBT4JTCILNGF5AS54FEMTXL7KOLMF6TFTHRK6SSUSUZZ", 28 | uri.toString()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Curve25519Public.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct Curve25519Public 12 | // { 13 | // opaque key[32]; 14 | // }; 15 | 16 | // =========================================================================== 17 | public class Curve25519Public { 18 | public Curve25519Public () {} 19 | private byte[] key; 20 | public byte[] getKey() { 21 | return this.key; 22 | } 23 | public void setKey(byte[] value) { 24 | this.key = value; 25 | } 26 | public static void encode(XdrDataOutputStream stream, Curve25519Public encodedCurve25519Public) throws IOException{ 27 | int keysize = encodedCurve25519Public.key.length; 28 | stream.write(encodedCurve25519Public.getKey(), 0, keysize); 29 | } 30 | public static Curve25519Public decode(XdrDataInputStream stream) throws IOException { 31 | Curve25519Public decodedCurve25519Public = new Curve25519Public(); 32 | int keysize = 32; 33 | decodedCurve25519Public.key = new byte[keysize]; 34 | stream.read(decodedCurve25519Public.key, 0, keysize); 35 | return decodedCurve25519Public; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Curve25519Secret.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct Curve25519Secret 12 | // { 13 | // opaque key[32]; 14 | // }; 15 | 16 | // =========================================================================== 17 | public class Curve25519Secret { 18 | public Curve25519Secret () {} 19 | private byte[] key; 20 | public byte[] getKey() { 21 | return this.key; 22 | } 23 | public void setKey(byte[] value) { 24 | this.key = value; 25 | } 26 | public static void encode(XdrDataOutputStream stream, Curve25519Secret encodedCurve25519Secret) throws IOException{ 27 | int keysize = encodedCurve25519Secret.key.length; 28 | stream.write(encodedCurve25519Secret.getKey(), 0, keysize); 29 | } 30 | public static Curve25519Secret decode(XdrDataInputStream stream) throws IOException { 31 | Curve25519Secret decodedCurve25519Secret = new Curve25519Secret(); 32 | int keysize = 32; 33 | decodedCurve25519Secret.key = new byte[keysize]; 34 | stream.read(decodedCurve25519Secret.key, 0, keysize); 35 | return decodedCurve25519Secret; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/responses/AssetDeserializerTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses; 2 | 3 | import junit.framework.TestCase; 4 | import org.junit.Test; 5 | import org.stellar.sdk.Asset; 6 | import org.stellar.sdk.AssetTypeCreditAlphaNum; 7 | 8 | public class AssetDeserializerTest extends TestCase { 9 | @Test 10 | public void testDeserializeNative() { 11 | String json = "{\"asset_type\": \"native\"}"; 12 | Asset asset = GsonSingleton.getInstance().fromJson(json, Asset.class); 13 | assertEquals(asset.getType(), "native"); 14 | } 15 | 16 | @Test 17 | public void testDeserializeCredit() { 18 | String json = "{\n" + 19 | " \"asset_type\": \"credit_alphanum4\",\n" + 20 | " \"asset_code\": \"CNY\",\n" + 21 | " \"asset_issuer\": \"GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX\"\n" + 22 | "}"; 23 | Asset asset = GsonSingleton.getInstance().fromJson(json, Asset.class); 24 | assertEquals(asset.getType(), "credit_alphanum4"); 25 | AssetTypeCreditAlphaNum creditAsset = (AssetTypeCreditAlphaNum) asset; 26 | assertEquals(creditAsset.getCode(), "CNY"); 27 | assertEquals(creditAsset.getIssuer().getAccountId(), "GAREELUB43IRHWEASCFBLKHURCGMHE5IF6XSE7EXDLACYHGRHM43RFOX"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/AccountThresholdsUpdatedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Represents account_thresholds_updated effect response. 7 | * @see Effect documentation 8 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 9 | * @see org.stellar.sdk.Server#effects() 10 | */ 11 | public class AccountThresholdsUpdatedEffectResponse extends EffectResponse { 12 | @SerializedName("low_threshold") 13 | protected final Integer lowThreshold; 14 | @SerializedName("med_threshold") 15 | protected final Integer medThreshold; 16 | @SerializedName("high_threshold") 17 | protected final Integer highThreshold; 18 | 19 | AccountThresholdsUpdatedEffectResponse(Integer lowThreshold, Integer medThreshold, Integer highThreshold) { 20 | this.lowThreshold = lowThreshold; 21 | this.medThreshold = medThreshold; 22 | this.highThreshold = highThreshold; 23 | } 24 | 25 | public Integer getLowThreshold() { 26 | return lowThreshold; 27 | } 28 | 29 | public Integer getMedThreshold() { 30 | return medThreshold; 31 | } 32 | 33 | public Integer getHighThreshold() { 34 | return highThreshold; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/SignatureHint.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef opaque SignatureHint[4]; 12 | 13 | // =========================================================================== 14 | public class SignatureHint { 15 | private byte[] SignatureHint; 16 | public byte[] getSignatureHint() { 17 | return this.SignatureHint; 18 | } 19 | public void setSignatureHint(byte[] value) { 20 | this.SignatureHint = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, SignatureHint encodedSignatureHint) throws IOException { 23 | int SignatureHintsize = encodedSignatureHint.SignatureHint.length; 24 | stream.write(encodedSignatureHint.getSignatureHint(), 0, SignatureHintsize); 25 | } 26 | public static SignatureHint decode(XdrDataInputStream stream) throws IOException { 27 | SignatureHint decodedSignatureHint = new SignatureHint(); 28 | int SignatureHintsize = 4; 29 | decodedSignatureHint.SignatureHint = new byte[SignatureHintsize]; 30 | stream.read(decodedSignatureHint.SignatureHint, 0, SignatureHintsize); 31 | return decodedSignatureHint; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/UpgradeType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef opaque UpgradeType<128>; 12 | 13 | // =========================================================================== 14 | public class UpgradeType { 15 | private byte[] UpgradeType; 16 | public byte[] getUpgradeType() { 17 | return this.UpgradeType; 18 | } 19 | public void setUpgradeType(byte[] value) { 20 | this.UpgradeType = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, UpgradeType encodedUpgradeType) throws IOException { 23 | int UpgradeTypesize = encodedUpgradeType.UpgradeType.length; 24 | stream.writeInt(UpgradeTypesize); 25 | stream.write(encodedUpgradeType.getUpgradeType(), 0, UpgradeTypesize); 26 | } 27 | public static UpgradeType decode(XdrDataInputStream stream) throws IOException { 28 | UpgradeType decodedUpgradeType = new UpgradeType(); 29 | int UpgradeTypesize = stream.readInt(); 30 | decodedUpgradeType.UpgradeType = new byte[UpgradeTypesize]; 31 | stream.read(decodedUpgradeType.UpgradeType, 0, UpgradeTypesize); 32 | return decodedUpgradeType; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Error.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct Error 12 | // { 13 | // ErrorCode code; 14 | // string msg<100>; 15 | // }; 16 | 17 | // =========================================================================== 18 | public class Error { 19 | public Error () {} 20 | private ErrorCode code; 21 | public ErrorCode getCode() { 22 | return this.code; 23 | } 24 | public void setCode(ErrorCode value) { 25 | this.code = value; 26 | } 27 | private String msg; 28 | public String getMsg() { 29 | return this.msg; 30 | } 31 | public void setMsg(String value) { 32 | this.msg = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, Error encodedError) throws IOException{ 35 | ErrorCode.encode(stream, encodedError.code); 36 | stream.writeString(encodedError.msg); 37 | } 38 | public static Error decode(XdrDataInputStream stream) throws IOException { 39 | Error decodedError = new Error(); 40 | decodedError.code = ErrorCode.decode(stream); 41 | decodedError.msg = stream.readString(); 42 | return decodedError; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/LedgerEntryType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum LedgerEntryType 12 | // { 13 | // ACCOUNT = 0, 14 | // TRUSTLINE = 1, 15 | // OFFER = 2, 16 | // DATA = 3 17 | // }; 18 | 19 | // =========================================================================== 20 | public enum LedgerEntryType { 21 | ACCOUNT(0), 22 | TRUSTLINE(1), 23 | OFFER(2), 24 | DATA(3), 25 | ; 26 | private int mValue; 27 | 28 | LedgerEntryType(int value) { 29 | mValue = value; 30 | } 31 | 32 | public int getValue() { 33 | return mValue; 34 | } 35 | 36 | static LedgerEntryType decode(XdrDataInputStream stream) throws IOException { 37 | int value = stream.readInt(); 38 | switch (value) { 39 | case 0: return ACCOUNT; 40 | case 1: return TRUSTLINE; 41 | case 2: return OFFER; 42 | case 3: return DATA; 43 | default: 44 | throw new RuntimeException("Unknown enum value: " + value); 45 | } 46 | } 47 | 48 | static void encode(XdrDataOutputStream stream, LedgerEntryType value) throws IOException { 49 | stream.writeInt(value.getValue()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/EnvelopeType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum EnvelopeType 12 | // { 13 | // ENVELOPE_TYPE_SCP = 1, 14 | // ENVELOPE_TYPE_TX = 2, 15 | // ENVELOPE_TYPE_AUTH = 3 16 | // }; 17 | 18 | // =========================================================================== 19 | public enum EnvelopeType { 20 | ENVELOPE_TYPE_SCP(1), 21 | ENVELOPE_TYPE_TX(2), 22 | ENVELOPE_TYPE_AUTH(3), 23 | ; 24 | private int mValue; 25 | 26 | EnvelopeType(int value) { 27 | mValue = value; 28 | } 29 | 30 | public int getValue() { 31 | return mValue; 32 | } 33 | 34 | static EnvelopeType decode(XdrDataInputStream stream) throws IOException { 35 | int value = stream.readInt(); 36 | switch (value) { 37 | case 1: return ENVELOPE_TYPE_SCP; 38 | case 2: return ENVELOPE_TYPE_TX; 39 | case 3: return ENVELOPE_TYPE_AUTH; 40 | default: 41 | throw new RuntimeException("Unknown enum value: " + value); 42 | } 43 | } 44 | 45 | static void encode(XdrDataOutputStream stream, EnvelopeType value) throws IOException { 46 | stream.writeInt(value.getValue()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/CryptoKeyType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum CryptoKeyType 12 | // { 13 | // KEY_TYPE_ED25519 = 0, 14 | // KEY_TYPE_PRE_AUTH_TX = 1, 15 | // KEY_TYPE_HASH_X = 2 16 | // }; 17 | 18 | // =========================================================================== 19 | public enum CryptoKeyType { 20 | KEY_TYPE_ED25519(0), 21 | KEY_TYPE_PRE_AUTH_TX(1), 22 | KEY_TYPE_HASH_X(2), 23 | ; 24 | private int mValue; 25 | 26 | CryptoKeyType(int value) { 27 | mValue = value; 28 | } 29 | 30 | public int getValue() { 31 | return mValue; 32 | } 33 | 34 | static CryptoKeyType decode(XdrDataInputStream stream) throws IOException { 35 | int value = stream.readInt(); 36 | switch (value) { 37 | case 0: return KEY_TYPE_ED25519; 38 | case 1: return KEY_TYPE_PRE_AUTH_TX; 39 | case 2: return KEY_TYPE_HASH_X; 40 | default: 41 | throw new RuntimeException("Unknown enum value: " + value); 42 | } 43 | } 44 | 45 | static void encode(XdrDataOutputStream stream, CryptoKeyType value) throws IOException { 46 | stream.writeInt(value.getValue()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/federation/FederationResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.federation; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Object to hold a response from a federation server. 7 | * @see Federation docs 8 | */ 9 | public class FederationResponse { 10 | @SerializedName("stellar_address") 11 | private final String stellarAddress; 12 | @SerializedName("account_id") 13 | private final String accountId; 14 | @SerializedName("memo_type") 15 | private final String memoType; 16 | @SerializedName("memo") 17 | private final String memo; 18 | 19 | public FederationResponse(String stellarAddress, String accountId, String memoType, String memo) { 20 | this.stellarAddress = stellarAddress; 21 | this.accountId = accountId; 22 | this.memoType = memoType; 23 | this.memo = memo; 24 | } 25 | 26 | public String getStellarAddress() { 27 | return stellarAddress; 28 | } 29 | 30 | public String getAccountId() { 31 | return accountId; 32 | } 33 | 34 | /** 35 | * @return Memo type or null when no memo attached 36 | */ 37 | public String getMemoType() { 38 | return memoType; 39 | } 40 | 41 | /** 42 | * @return Memo value or null when no memo attached 43 | */ 44 | public String getMemo() { 45 | return memo; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/Signer.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct Signer 12 | // { 13 | // SignerKey key; 14 | // uint32 weight; // really only need 1byte 15 | // }; 16 | 17 | // =========================================================================== 18 | public class Signer { 19 | public Signer () {} 20 | private SignerKey key; 21 | public SignerKey getKey() { 22 | return this.key; 23 | } 24 | public void setKey(SignerKey value) { 25 | this.key = value; 26 | } 27 | private Uint32 weight; 28 | public Uint32 getWeight() { 29 | return this.weight; 30 | } 31 | public void setWeight(Uint32 value) { 32 | this.weight = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, Signer encodedSigner) throws IOException{ 35 | SignerKey.encode(stream, encodedSigner.key); 36 | Uint32.encode(stream, encodedSigner.weight); 37 | } 38 | public static Signer decode(XdrDataInputStream stream) throws IOException { 39 | Signer decodedSigner = new Signer(); 40 | decodedSigner.key = SignerKey.decode(stream); 41 | decodedSigner.weight = Uint32.decode(stream); 42 | return decodedSigner; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/StrKeyTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import org.junit.Test; 6 | 7 | import java.io.IOException; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | import static org.junit.Assert.fail; 11 | 12 | public class StrKeyTest { 13 | @Test 14 | public void testDecodeEncode() throws IOException, FormatException { 15 | String seed = "SDJHRQF4GCMIIKAAAQ6IHY42X73FQFLHUULAPSKKD4DFDM7UXWWCRHBE"; 16 | byte[] secret = StrKey.decodeCheck(StrKey.VersionByte.SEED, seed.toCharArray()); 17 | char[] encoded = StrKey.encodeCheck(StrKey.VersionByte.SEED, secret); 18 | assertEquals(seed, String.valueOf(encoded)); 19 | } 20 | 21 | @Test() 22 | public void testDecodeInvalidVersionByte() { 23 | String address = "GCZHXL5HXQX5ABDM26LHYRCQZ5OJFHLOPLZX47WEBP3V2PF5AVFK2A5D"; 24 | try { 25 | StrKey.decodeCheck(StrKey.VersionByte.SEED, address.toCharArray()); 26 | fail(); 27 | } catch (FormatException e) {} 28 | } 29 | 30 | @Test() 31 | public void testDecodeInvalidSeed() { 32 | String seed = "SAA6NXOBOXP3RXGAXBW6PGFI5BPK4ODVAWITS4VDOMN5C2M4B66ZML"; 33 | try { 34 | StrKey.decodeCheck(StrKey.VersionByte.SEED, seed.toCharArray()); 35 | fail(); 36 | } catch (Exception e) {} 37 | } 38 | 39 | // TODO more tests 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/AssetType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum AssetType 12 | // { 13 | // ASSET_TYPE_NATIVE = 0, 14 | // ASSET_TYPE_CREDIT_ALPHANUM4 = 1, 15 | // ASSET_TYPE_CREDIT_ALPHANUM12 = 2 16 | // }; 17 | 18 | // =========================================================================== 19 | public enum AssetType { 20 | ASSET_TYPE_NATIVE(0), 21 | ASSET_TYPE_CREDIT_ALPHANUM4(1), 22 | ASSET_TYPE_CREDIT_ALPHANUM12(2), 23 | ; 24 | private int mValue; 25 | 26 | AssetType(int value) { 27 | mValue = value; 28 | } 29 | 30 | public int getValue() { 31 | return mValue; 32 | } 33 | 34 | static AssetType decode(XdrDataInputStream stream) throws IOException { 35 | int value = stream.readInt(); 36 | switch (value) { 37 | case 0: return ASSET_TYPE_NATIVE; 38 | case 1: return ASSET_TYPE_CREDIT_ALPHANUM4; 39 | case 2: return ASSET_TYPE_CREDIT_ALPHANUM12; 40 | default: 41 | throw new RuntimeException("Unknown enum value: " + value); 42 | } 43 | } 44 | 45 | static void encode(XdrDataOutputStream stream, AssetType value) throws IOException { 46 | stream.writeInt(value.getValue()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/Account.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import static com.google.common.base.Preconditions.checkNotNull; 4 | 5 | /** 6 | * Represents an account in Stellar network with it's sequence number. 7 | * Account object is required to build a {@link Transaction}. 8 | * @see org.stellar.sdk.Transaction.Builder 9 | */ 10 | public class Account implements TransactionBuilderAccount { 11 | private final KeyPair mKeyPair; 12 | private Long mSequenceNumber; 13 | 14 | /** 15 | * Class constructor. 16 | * @param keypair KeyPair associated with this Account 17 | * @param sequenceNumber Current sequence number of the account (can be obtained using java-stellar-sdk or horizon server) 18 | */ 19 | public Account(KeyPair keypair, Long sequenceNumber) { 20 | mKeyPair = checkNotNull(keypair, "keypair cannot be null"); 21 | mSequenceNumber = checkNotNull(sequenceNumber, "sequenceNumber cannot be null"); 22 | } 23 | 24 | @Override 25 | public KeyPair getKeypair() { 26 | return mKeyPair; 27 | } 28 | 29 | @Override 30 | public Long getSequenceNumber() { 31 | return mSequenceNumber; 32 | } 33 | 34 | @Override 35 | public Long getIncrementedSequenceNumber() { 36 | return new Long(mSequenceNumber + 1); 37 | } 38 | 39 | /** 40 | * Increments sequence number in this object by one. 41 | */ 42 | public void incrementSequenceNumber() { 43 | mSequenceNumber++; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/ManageOfferEffect.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum ManageOfferEffect 12 | // { 13 | // MANAGE_OFFER_CREATED = 0, 14 | // MANAGE_OFFER_UPDATED = 1, 15 | // MANAGE_OFFER_DELETED = 2 16 | // }; 17 | 18 | // =========================================================================== 19 | public enum ManageOfferEffect { 20 | MANAGE_OFFER_CREATED(0), 21 | MANAGE_OFFER_UPDATED(1), 22 | MANAGE_OFFER_DELETED(2), 23 | ; 24 | private int mValue; 25 | 26 | ManageOfferEffect(int value) { 27 | mValue = value; 28 | } 29 | 30 | public int getValue() { 31 | return mValue; 32 | } 33 | 34 | static ManageOfferEffect decode(XdrDataInputStream stream) throws IOException { 35 | int value = stream.readInt(); 36 | switch (value) { 37 | case 0: return MANAGE_OFFER_CREATED; 38 | case 1: return MANAGE_OFFER_UPDATED; 39 | case 2: return MANAGE_OFFER_DELETED; 40 | default: 41 | throw new RuntimeException("Unknown enum value: " + value); 42 | } 43 | } 44 | 45 | static void encode(XdrDataOutputStream stream, ManageOfferEffect value) throws IOException { 46 | stream.writeInt(value.getValue()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/SCPBallot.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct SCPBallot 12 | // { 13 | // uint32 counter; // n 14 | // Value value; // x 15 | // }; 16 | 17 | // =========================================================================== 18 | public class SCPBallot { 19 | public SCPBallot () {} 20 | private Uint32 counter; 21 | public Uint32 getCounter() { 22 | return this.counter; 23 | } 24 | public void setCounter(Uint32 value) { 25 | this.counter = value; 26 | } 27 | private Value value; 28 | public Value getValue() { 29 | return this.value; 30 | } 31 | public void setValue(Value value) { 32 | this.value = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, SCPBallot encodedSCPBallot) throws IOException{ 35 | Uint32.encode(stream, encodedSCPBallot.counter); 36 | Value.encode(stream, encodedSCPBallot.value); 37 | } 38 | public static SCPBallot decode(XdrDataInputStream stream) throws IOException { 39 | SCPBallot decodedSCPBallot = new SCPBallot(); 40 | decodedSCPBallot.counter = Uint32.decode(stream); 41 | decodedSCPBallot.value = Value.decode(stream); 42 | return decodedSCPBallot; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/DontHave.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct DontHave 12 | // { 13 | // MessageType type; 14 | // uint256 reqHash; 15 | // }; 16 | 17 | // =========================================================================== 18 | public class DontHave { 19 | public DontHave () {} 20 | private MessageType type; 21 | public MessageType getType() { 22 | return this.type; 23 | } 24 | public void setType(MessageType value) { 25 | this.type = value; 26 | } 27 | private Uint256 reqHash; 28 | public Uint256 getReqHash() { 29 | return this.reqHash; 30 | } 31 | public void setReqHash(Uint256 value) { 32 | this.reqHash = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, DontHave encodedDontHave) throws IOException{ 35 | MessageType.encode(stream, encodedDontHave.type); 36 | Uint256.encode(stream, encodedDontHave.reqHash); 37 | } 38 | public static DontHave decode(XdrDataInputStream stream) throws IOException { 39 | DontHave decodedDontHave = new DontHave(); 40 | decodedDontHave.type = MessageType.decode(stream); 41 | decodedDontHave.reqHash = Uint256.decode(stream); 42 | return decodedDontHave; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/InflationResultCode.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum InflationResultCode 12 | // { 13 | // // codes considered as "success" for the operation 14 | // INFLATION_SUCCESS = 0, 15 | // // codes considered as "failure" for the operation 16 | // INFLATION_NOT_TIME = -1 17 | // }; 18 | 19 | // =========================================================================== 20 | public enum InflationResultCode { 21 | INFLATION_SUCCESS(0), 22 | INFLATION_NOT_TIME(-1), 23 | ; 24 | private int mValue; 25 | 26 | InflationResultCode(int value) { 27 | mValue = value; 28 | } 29 | 30 | public int getValue() { 31 | return mValue; 32 | } 33 | 34 | static InflationResultCode decode(XdrDataInputStream stream) throws IOException { 35 | int value = stream.readInt(); 36 | switch (value) { 37 | case 0: return INFLATION_SUCCESS; 38 | case -1: return INFLATION_NOT_TIME; 39 | default: 40 | throw new RuntimeException("Unknown enum value: " + value); 41 | } 42 | } 43 | 44 | static void encode(XdrDataOutputStream stream, InflationResultCode value) throws IOException { 45 | stream.writeInt(value.getValue()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/MemoType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum MemoType 12 | // { 13 | // MEMO_NONE = 0, 14 | // MEMO_TEXT = 1, 15 | // MEMO_ID = 2, 16 | // MEMO_HASH = 3, 17 | // MEMO_RETURN = 4 18 | // }; 19 | 20 | // =========================================================================== 21 | public enum MemoType { 22 | MEMO_NONE(0), 23 | MEMO_TEXT(1), 24 | MEMO_ID(2), 25 | MEMO_HASH(3), 26 | MEMO_RETURN(4), 27 | ; 28 | private int mValue; 29 | 30 | MemoType(int value) { 31 | mValue = value; 32 | } 33 | 34 | public int getValue() { 35 | return mValue; 36 | } 37 | 38 | static MemoType decode(XdrDataInputStream stream) throws IOException { 39 | int value = stream.readInt(); 40 | switch (value) { 41 | case 0: return MEMO_NONE; 42 | case 1: return MEMO_TEXT; 43 | case 2: return MEMO_ID; 44 | case 3: return MEMO_HASH; 45 | case 4: return MEMO_RETURN; 46 | default: 47 | throw new RuntimeException("Unknown enum value: " + value); 48 | } 49 | } 50 | 51 | static void encode(XdrDataOutputStream stream, MemoType value) throws IOException { 52 | stream.writeInt(value.getValue()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum4.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.stellar.sdk.xdr.AccountID; 4 | import org.stellar.sdk.xdr.AssetType; 5 | 6 | /** 7 | * Represents all assets with codes 1-4 characters long. 8 | * @see Assets 9 | */ 10 | public final class AssetTypeCreditAlphaNum4 extends AssetTypeCreditAlphaNum { 11 | 12 | /** 13 | * Class constructor 14 | * @param code Asset code 15 | * @param issuer Asset issuer 16 | */ 17 | public AssetTypeCreditAlphaNum4(String code, KeyPair issuer) { 18 | super(code, issuer); 19 | if (code.length() < 1 || code.length() > 4) { 20 | throw new AssetCodeLengthInvalidException(); 21 | } 22 | } 23 | 24 | @Override 25 | public String getType() { 26 | return "credit_alphanum4"; 27 | } 28 | 29 | @Override 30 | public org.stellar.sdk.xdr.Asset toXdr() { 31 | org.stellar.sdk.xdr.Asset xdr = new org.stellar.sdk.xdr.Asset(); 32 | xdr.setDiscriminant(AssetType.ASSET_TYPE_CREDIT_ALPHANUM4); 33 | org.stellar.sdk.xdr.Asset.AssetAlphaNum4 credit = new org.stellar.sdk.xdr.Asset.AssetAlphaNum4(); 34 | credit.setAssetCode(Util.paddedByteArray(mCode, 4)); 35 | AccountID accountID = new AccountID(); 36 | accountID.setAccountID(mIssuer.getXdrPublicKey()); 37 | credit.setIssuer(accountID); 38 | xdr.setAlphaNum4(credit); 39 | return xdr; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum12.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.stellar.sdk.xdr.AccountID; 4 | import org.stellar.sdk.xdr.AssetType; 5 | 6 | /** 7 | * Represents all assets with codes 5-12 characters long. 8 | * @see Assets 9 | */ 10 | public final class AssetTypeCreditAlphaNum12 extends AssetTypeCreditAlphaNum { 11 | 12 | /** 13 | * Class constructor 14 | * @param code Asset code 15 | * @param issuer Asset issuer 16 | */ 17 | public AssetTypeCreditAlphaNum12(String code, KeyPair issuer) { 18 | super(code, issuer); 19 | if (code.length() < 5 || code.length() > 12) { 20 | throw new AssetCodeLengthInvalidException(); 21 | } 22 | } 23 | 24 | @Override 25 | public String getType() { 26 | return "credit_alphanum12"; 27 | } 28 | 29 | @Override 30 | public org.stellar.sdk.xdr.Asset toXdr() { 31 | org.stellar.sdk.xdr.Asset xdr = new org.stellar.sdk.xdr.Asset(); 32 | xdr.setDiscriminant(AssetType.ASSET_TYPE_CREDIT_ALPHANUM12); 33 | org.stellar.sdk.xdr.Asset.AssetAlphaNum12 credit = new org.stellar.sdk.xdr.Asset.AssetAlphaNum12(); 34 | credit.setAssetCode(Util.paddedByteArray(mCode, 12)); 35 | AccountID accountID = new AccountID(); 36 | accountID.setAccountID(mIssuer.getXdrPublicKey()); 37 | credit.setIssuer(accountID); 38 | xdr.setAlphaNum12(credit); 39 | return xdr; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/LedgerUpgradeType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum LedgerUpgradeType 12 | // { 13 | // LEDGER_UPGRADE_VERSION = 1, 14 | // LEDGER_UPGRADE_BASE_FEE = 2, 15 | // LEDGER_UPGRADE_MAX_TX_SET_SIZE = 3 16 | // }; 17 | 18 | // =========================================================================== 19 | public enum LedgerUpgradeType { 20 | LEDGER_UPGRADE_VERSION(1), 21 | LEDGER_UPGRADE_BASE_FEE(2), 22 | LEDGER_UPGRADE_MAX_TX_SET_SIZE(3), 23 | ; 24 | private int mValue; 25 | 26 | LedgerUpgradeType(int value) { 27 | mValue = value; 28 | } 29 | 30 | public int getValue() { 31 | return mValue; 32 | } 33 | 34 | static LedgerUpgradeType decode(XdrDataInputStream stream) throws IOException { 35 | int value = stream.readInt(); 36 | switch (value) { 37 | case 1: return LEDGER_UPGRADE_VERSION; 38 | case 2: return LEDGER_UPGRADE_BASE_FEE; 39 | case 3: return LEDGER_UPGRADE_MAX_TX_SET_SIZE; 40 | default: 41 | throw new RuntimeException("Unknown enum value: " + value); 42 | } 43 | } 44 | 45 | static void encode(XdrDataOutputStream stream, LedgerUpgradeType value) throws IOException { 46 | stream.writeInt(value.getValue()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/OperationResultCode.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum OperationResultCode 12 | // { 13 | // opINNER = 0, // inner object result is valid 14 | // 15 | // opBAD_AUTH = -1, // too few valid signatures / wrong network 16 | // opNO_ACCOUNT = -2 // source account was not found 17 | // }; 18 | 19 | // =========================================================================== 20 | public enum OperationResultCode { 21 | opINNER(0), 22 | opBAD_AUTH(-1), 23 | opNO_ACCOUNT(-2), 24 | ; 25 | private int mValue; 26 | 27 | OperationResultCode(int value) { 28 | mValue = value; 29 | } 30 | 31 | public int getValue() { 32 | return mValue; 33 | } 34 | 35 | static OperationResultCode decode(XdrDataInputStream stream) throws IOException { 36 | int value = stream.readInt(); 37 | switch (value) { 38 | case 0: return opINNER; 39 | case -1: return opBAD_AUTH; 40 | case -2: return opNO_ACCOUNT; 41 | default: 42 | throw new RuntimeException("Unknown enum value: " + value); 43 | } 44 | } 45 | 46 | static void encode(XdrDataOutputStream stream, OperationResultCode value) throws IOException { 47 | stream.writeInt(value.getValue()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/SCPStatementType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum SCPStatementType 12 | // { 13 | // SCP_ST_PREPARE = 0, 14 | // SCP_ST_CONFIRM = 1, 15 | // SCP_ST_EXTERNALIZE = 2, 16 | // SCP_ST_NOMINATE = 3 17 | // }; 18 | 19 | // =========================================================================== 20 | public enum SCPStatementType { 21 | SCP_ST_PREPARE(0), 22 | SCP_ST_CONFIRM(1), 23 | SCP_ST_EXTERNALIZE(2), 24 | SCP_ST_NOMINATE(3), 25 | ; 26 | private int mValue; 27 | 28 | SCPStatementType(int value) { 29 | mValue = value; 30 | } 31 | 32 | public int getValue() { 33 | return mValue; 34 | } 35 | 36 | static SCPStatementType decode(XdrDataInputStream stream) throws IOException { 37 | int value = stream.readInt(); 38 | switch (value) { 39 | case 0: return SCP_ST_PREPARE; 40 | case 1: return SCP_ST_CONFIRM; 41 | case 2: return SCP_ST_EXTERNALIZE; 42 | case 3: return SCP_ST_NOMINATE; 43 | default: 44 | throw new RuntimeException("Unknown enum value: " + value); 45 | } 46 | } 47 | 48 | static void encode(XdrDataOutputStream stream, SCPStatementType value) throws IOException { 49 | stream.writeInt(value.getValue()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/TimeBounds.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct TimeBounds 12 | // { 13 | // uint64 minTime; 14 | // uint64 maxTime; // 0 here means no maxTime 15 | // }; 16 | 17 | // =========================================================================== 18 | public class TimeBounds { 19 | public TimeBounds () {} 20 | private Uint64 minTime; 21 | public Uint64 getMinTime() { 22 | return this.minTime; 23 | } 24 | public void setMinTime(Uint64 value) { 25 | this.minTime = value; 26 | } 27 | private Uint64 maxTime; 28 | public Uint64 getMaxTime() { 29 | return this.maxTime; 30 | } 31 | public void setMaxTime(Uint64 value) { 32 | this.maxTime = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, TimeBounds encodedTimeBounds) throws IOException{ 35 | Uint64.encode(stream, encodedTimeBounds.minTime); 36 | Uint64.encode(stream, encodedTimeBounds.maxTime); 37 | } 38 | public static TimeBounds decode(XdrDataInputStream stream) throws IOException { 39 | TimeBounds decodedTimeBounds = new TimeBounds(); 40 | decodedTimeBounds.minTime = Uint64.decode(stream); 41 | decodedTimeBounds.maxTime = Uint64.decode(stream); 42 | return decodedTimeBounds; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/SignerKeyType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum SignerKeyType 12 | // { 13 | // SIGNER_KEY_TYPE_ED25519 = KEY_TYPE_ED25519, 14 | // SIGNER_KEY_TYPE_PRE_AUTH_TX = KEY_TYPE_PRE_AUTH_TX, 15 | // SIGNER_KEY_TYPE_HASH_X = KEY_TYPE_HASH_X 16 | // }; 17 | 18 | // =========================================================================== 19 | public enum SignerKeyType { 20 | SIGNER_KEY_TYPE_ED25519(0), 21 | SIGNER_KEY_TYPE_PRE_AUTH_TX(1), 22 | SIGNER_KEY_TYPE_HASH_X(2), 23 | ; 24 | private int mValue; 25 | 26 | SignerKeyType(int value) { 27 | mValue = value; 28 | } 29 | 30 | public int getValue() { 31 | return mValue; 32 | } 33 | 34 | static SignerKeyType decode(XdrDataInputStream stream) throws IOException { 35 | int value = stream.readInt(); 36 | switch (value) { 37 | case 0: return SIGNER_KEY_TYPE_ED25519; 38 | case 1: return SIGNER_KEY_TYPE_PRE_AUTH_TX; 39 | case 2: return SIGNER_KEY_TYPE_HASH_X; 40 | default: 41 | throw new RuntimeException("Unknown enum value: " + value); 42 | } 43 | } 44 | 45 | static void encode(XdrDataOutputStream stream, SignerKeyType value) throws IOException { 46 | stream.writeInt(value.getValue()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/ThresholdIndexes.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum ThresholdIndexes 12 | // { 13 | // THRESHOLD_MASTER_WEIGHT = 0, 14 | // THRESHOLD_LOW = 1, 15 | // THRESHOLD_MED = 2, 16 | // THRESHOLD_HIGH = 3 17 | // }; 18 | 19 | // =========================================================================== 20 | public enum ThresholdIndexes { 21 | THRESHOLD_MASTER_WEIGHT(0), 22 | THRESHOLD_LOW(1), 23 | THRESHOLD_MED(2), 24 | THRESHOLD_HIGH(3), 25 | ; 26 | private int mValue; 27 | 28 | ThresholdIndexes(int value) { 29 | mValue = value; 30 | } 31 | 32 | public int getValue() { 33 | return mValue; 34 | } 35 | 36 | static ThresholdIndexes decode(XdrDataInputStream stream) throws IOException { 37 | int value = stream.readInt(); 38 | switch (value) { 39 | case 0: return THRESHOLD_MASTER_WEIGHT; 40 | case 1: return THRESHOLD_LOW; 41 | case 2: return THRESHOLD_MED; 42 | case 3: return THRESHOLD_HIGH; 43 | default: 44 | throw new RuntimeException("Unknown enum value: " + value); 45 | } 46 | } 47 | 48 | static void encode(XdrDataOutputStream stream, ThresholdIndexes value) throws IOException { 49 | stream.writeInt(value.getValue()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/ThresholdIndices.java: -------------------------------------------------------------------------------- 1 | // Automatically generated on 2015-11-05T11:21:06-08:00 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum ThresholdIndexes 12 | // { 13 | // THRESHOLD_MASTER_WEIGHT = 0, 14 | // THRESHOLD_LOW = 1, 15 | // THRESHOLD_MED = 2, 16 | // THRESHOLD_HIGH = 3 17 | // }; 18 | 19 | // =========================================================================== 20 | public enum ThresholdIndices { 21 | THRESHOLD_MASTER_WEIGHT(0), 22 | THRESHOLD_LOW(1), 23 | THRESHOLD_MED(2), 24 | THRESHOLD_HIGH(3), 25 | ; 26 | private int mValue; 27 | 28 | ThresholdIndices(int value) { 29 | mValue = value; 30 | } 31 | 32 | public int getValue() { 33 | return mValue; 34 | } 35 | 36 | static ThresholdIndices decode(XdrDataInputStream stream) throws IOException { 37 | int value = stream.readInt(); 38 | switch (value) { 39 | case 0: return THRESHOLD_MASTER_WEIGHT; 40 | case 1: return THRESHOLD_LOW; 41 | case 2: return THRESHOLD_MED; 42 | case 3: return THRESHOLD_HIGH; 43 | default: 44 | throw new RuntimeException("Unknown enum value: " + value); 45 | } 46 | } 47 | 48 | static void encode(XdrDataOutputStream stream, ThresholdIndices value) throws IOException { 49 | stream.writeInt(value.getValue()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/ChangeTrustOp.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct ChangeTrustOp 12 | // { 13 | // Asset line; 14 | // 15 | // // if limit is set to 0, deletes the trust line 16 | // int64 limit; 17 | // }; 18 | 19 | // =========================================================================== 20 | public class ChangeTrustOp { 21 | public ChangeTrustOp () {} 22 | private Asset line; 23 | public Asset getLine() { 24 | return this.line; 25 | } 26 | public void setLine(Asset value) { 27 | this.line = value; 28 | } 29 | private Int64 limit; 30 | public Int64 getLimit() { 31 | return this.limit; 32 | } 33 | public void setLimit(Int64 value) { 34 | this.limit = value; 35 | } 36 | public static void encode(XdrDataOutputStream stream, ChangeTrustOp encodedChangeTrustOp) throws IOException{ 37 | Asset.encode(stream, encodedChangeTrustOp.line); 38 | Int64.encode(stream, encodedChangeTrustOp.limit); 39 | } 40 | public static ChangeTrustOp decode(XdrDataInputStream stream) throws IOException { 41 | ChangeTrustOp decodedChangeTrustOp = new ChangeTrustOp(); 42 | decodedChangeTrustOp.line = Asset.decode(stream); 43 | decodedChangeTrustOp.limit = Int64.decode(stream); 44 | return decodedChangeTrustOp; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/ErrorCode.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum ErrorCode 12 | // { 13 | // ERR_MISC = 0, // Unspecific error 14 | // ERR_DATA = 1, // Malformed data 15 | // ERR_CONF = 2, // Misconfiguration error 16 | // ERR_AUTH = 3, // Authentication failure 17 | // ERR_LOAD = 4 // System overloaded 18 | // }; 19 | 20 | // =========================================================================== 21 | public enum ErrorCode { 22 | ERR_MISC(0), 23 | ERR_DATA(1), 24 | ERR_CONF(2), 25 | ERR_AUTH(3), 26 | ERR_LOAD(4), 27 | ; 28 | private int mValue; 29 | 30 | ErrorCode(int value) { 31 | mValue = value; 32 | } 33 | 34 | public int getValue() { 35 | return mValue; 36 | } 37 | 38 | static ErrorCode decode(XdrDataInputStream stream) throws IOException { 39 | int value = stream.readInt(); 40 | switch (value) { 41 | case 0: return ERR_MISC; 42 | case 1: return ERR_DATA; 43 | case 2: return ERR_CONF; 44 | case 3: return ERR_AUTH; 45 | case 4: return ERR_LOAD; 46 | default: 47 | throw new RuntimeException("Unknown enum value: " + value); 48 | } 49 | } 50 | 51 | static void encode(XdrDataOutputStream stream, ErrorCode value) throws IOException { 52 | stream.writeInt(value.getValue()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/requests/TradeAggregationsRequestBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | import okhttp3.HttpUrl; 4 | import org.junit.Test; 5 | import org.stellar.sdk.Asset; 6 | import org.stellar.sdk.AssetTypeNative; 7 | import org.stellar.sdk.KeyPair; 8 | import org.stellar.sdk.Server; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class TradeAggregationsRequestBuilderTest { 13 | @Test 14 | public void testTradeAggregations() { 15 | Server server = new Server("https://horizon-testnet.stellar.org"); 16 | HttpUrl uri = server.tradeAggregations( 17 | new AssetTypeNative(), 18 | Asset.createNonNativeAsset("BTC", KeyPair.fromAccountId("GATEMHCCKCY67ZUCKTROYN24ZYT5GK4EQZ65JJLDHKHRUZI3EUEKMTCH")), 19 | 1512689100000L, 20 | 1512775500000L, 21 | 300000L 22 | ).limit(200).order(RequestBuilder.Order.ASC).buildUri(); 23 | 24 | assertEquals("https://horizon-testnet.stellar.org/trade_aggregations?" + 25 | "base_asset_type=native&" + 26 | "counter_asset_type=credit_alphanum4&" + 27 | "counter_asset_code=BTC&" + 28 | "counter_asset_issuer=GATEMHCCKCY67ZUCKTROYN24ZYT5GK4EQZ65JJLDHKHRUZI3EUEKMTCH&" + 29 | "start_time=1512689100000&" + 30 | "end_time=1512775500000&" + 31 | "resolution=300000&" + 32 | "limit=200&" + 33 | "order=asc", uri.toString()); 34 | 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/SCPEnvelope.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct SCPEnvelope 12 | // { 13 | // SCPStatement statement; 14 | // Signature signature; 15 | // }; 16 | 17 | // =========================================================================== 18 | public class SCPEnvelope { 19 | public SCPEnvelope () {} 20 | private SCPStatement statement; 21 | public SCPStatement getStatement() { 22 | return this.statement; 23 | } 24 | public void setStatement(SCPStatement value) { 25 | this.statement = value; 26 | } 27 | private Signature signature; 28 | public Signature getSignature() { 29 | return this.signature; 30 | } 31 | public void setSignature(Signature value) { 32 | this.signature = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, SCPEnvelope encodedSCPEnvelope) throws IOException{ 35 | SCPStatement.encode(stream, encodedSCPEnvelope.statement); 36 | Signature.encode(stream, encodedSCPEnvelope.signature); 37 | } 38 | public static SCPEnvelope decode(XdrDataInputStream stream) throws IOException { 39 | SCPEnvelope decodedSCPEnvelope = new SCPEnvelope(); 40 | decodedSCPEnvelope.statement = SCPStatement.decode(stream); 41 | decodedSCPEnvelope.signature = Signature.decode(stream); 42 | return decodedSCPEnvelope; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/AccountDebitedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import org.stellar.sdk.Asset; 6 | import org.stellar.sdk.AssetTypeNative; 7 | import org.stellar.sdk.KeyPair; 8 | 9 | /** 10 | * Represents account_debited effect response. 11 | * @see Effect documentation 12 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 13 | * @see org.stellar.sdk.Server#effects() 14 | */ 15 | public class AccountDebitedEffectResponse extends EffectResponse { 16 | @SerializedName("amount") 17 | protected final String amount; 18 | @SerializedName("asset_type") 19 | protected final String assetType; 20 | @SerializedName("asset_code") 21 | protected final String assetCode; 22 | @SerializedName("asset_issuer") 23 | protected final String assetIssuer; 24 | 25 | AccountDebitedEffectResponse(String amount, String assetType, String assetCode, String assetIssuer) { 26 | this.amount = amount; 27 | this.assetType = assetType; 28 | this.assetCode = assetCode; 29 | this.assetIssuer = assetIssuer; 30 | } 31 | 32 | public String getAmount() { 33 | return amount; 34 | } 35 | 36 | public Asset getAsset() { 37 | if (assetType.equals("native")) { 38 | return new AssetTypeNative(); 39 | } else { 40 | KeyPair issuer = KeyPair.fromAccountId(assetIssuer); 41 | return Asset.createNonNativeAsset(assetCode, issuer); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/effects/AccountCreditedEffectResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.effects; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import org.stellar.sdk.Asset; 6 | import org.stellar.sdk.AssetTypeNative; 7 | import org.stellar.sdk.KeyPair; 8 | 9 | 10 | /** 11 | * Represents account_credited effect response. 12 | * @see Effect documentation 13 | * @see org.stellar.sdk.requests.EffectsRequestBuilder 14 | * @see org.stellar.sdk.Server#effects() 15 | */ 16 | public class AccountCreditedEffectResponse extends EffectResponse { 17 | @SerializedName("amount") 18 | protected final String amount; 19 | @SerializedName("asset_type") 20 | protected final String assetType; 21 | @SerializedName("asset_code") 22 | protected final String assetCode; 23 | @SerializedName("asset_issuer") 24 | protected final String assetIssuer; 25 | 26 | AccountCreditedEffectResponse(String amount, String assetType, String assetCode, String assetIssuer) { 27 | this.amount = amount; 28 | this.assetType = assetType; 29 | this.assetCode = assetCode; 30 | this.assetIssuer = assetIssuer; 31 | } 32 | 33 | public String getAmount() { 34 | return amount; 35 | } 36 | 37 | public Asset getAsset() { 38 | if (assetType.equals("native")) { 39 | return new AssetTypeNative(); 40 | } else { 41 | KeyPair issuer = KeyPair.fromAccountId(assetIssuer); 42 | return Asset.createNonNativeAsset(assetCode, issuer); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/AccountTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | import static org.junit.Assert.fail; 7 | 8 | public class AccountTest { 9 | @Test 10 | public void testNullArguments() { 11 | try { 12 | new Account(null, 10L); 13 | fail(); 14 | } catch (NullPointerException e) {} 15 | 16 | try { 17 | new Account(KeyPair.random(), null); 18 | fail(); 19 | } catch (NullPointerException e) {} 20 | } 21 | 22 | @Test 23 | public void testGetIncrementedSequenceNumber() { 24 | Account account = new Account(KeyPair.random(), 100L); 25 | Long incremented; 26 | incremented = account.getIncrementedSequenceNumber(); 27 | assertEquals(new Long(100L), account.getSequenceNumber()); 28 | assertEquals(new Long(101L), incremented); 29 | incremented = account.getIncrementedSequenceNumber(); 30 | assertEquals(new Long(100L), account.getSequenceNumber()); 31 | assertEquals(new Long(101L), incremented); 32 | } 33 | 34 | @Test 35 | public void testIncrementSequenceNumber() { 36 | Account account = new Account(KeyPair.random(), 100L); 37 | account.incrementSequenceNumber(); 38 | assertEquals(account.getSequenceNumber(), new Long(101L)); 39 | } 40 | 41 | @Test 42 | public void testGetters() { 43 | KeyPair keypair = KeyPair.random(); 44 | Account account = new Account(keypair, 100L); 45 | assertEquals(account.getKeypair().getAccountId(), keypair.getAccountId()); 46 | assertEquals(account.getSequenceNumber(), new Long(100L)); 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/InflationPayout.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct InflationPayout // or use PaymentResultAtom to limit types? 12 | // { 13 | // AccountID destination; 14 | // int64 amount; 15 | // }; 16 | 17 | // =========================================================================== 18 | public class InflationPayout { 19 | public InflationPayout () {} 20 | private AccountID destination; 21 | public AccountID getDestination() { 22 | return this.destination; 23 | } 24 | public void setDestination(AccountID value) { 25 | this.destination = value; 26 | } 27 | private Int64 amount; 28 | public Int64 getAmount() { 29 | return this.amount; 30 | } 31 | public void setAmount(Int64 value) { 32 | this.amount = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, InflationPayout encodedInflationPayout) throws IOException{ 35 | AccountID.encode(stream, encodedInflationPayout.destination); 36 | Int64.encode(stream, encodedInflationPayout.amount); 37 | } 38 | public static InflationPayout decode(XdrDataInputStream stream) throws IOException { 39 | InflationPayout decodedInflationPayout = new InflationPayout(); 40 | decodedInflationPayout.destination = AccountID.decode(stream); 41 | decodedInflationPayout.amount = Int64.decode(stream); 42 | return decodedInflationPayout; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/requests/TradesRequestBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | import okhttp3.HttpUrl; 4 | import org.junit.Test; 5 | import org.stellar.sdk.Asset; 6 | import org.stellar.sdk.KeyPair; 7 | import org.stellar.sdk.Server; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class TradesRequestBuilderTest { 12 | @Test 13 | public void testOrderBook() { 14 | Server server = new Server("https://horizon-testnet.stellar.org"); 15 | HttpUrl uri = server.trades() 16 | .baseAsset(Asset.createNonNativeAsset("EUR", KeyPair.fromAccountId("GAUPA4HERNBDPVO4IUA3MJXBCRRK5W54EVXTDK6IIUTGDQRB6D5W242W"))) 17 | .counterAsset(Asset.createNonNativeAsset("USD", KeyPair.fromAccountId("GDRRHSJMHXDTQBT4JTCILNGF5AS54FEMTXL7KOLMF6TFTHRK6SSUSUZZ"))) 18 | .cursor("13537736921089") 19 | .limit(200) 20 | .order(RequestBuilder.Order.ASC) 21 | .buildUri(); 22 | 23 | assertEquals("https://horizon-testnet.stellar.org/trades?" + 24 | "base_asset_type=credit_alphanum4&" + 25 | "base_asset_code=EUR&" + 26 | "base_asset_issuer=GAUPA4HERNBDPVO4IUA3MJXBCRRK5W54EVXTDK6IIUTGDQRB6D5W242W&" + 27 | "counter_asset_type=credit_alphanum4&" + 28 | "counter_asset_code=USD&" + 29 | "counter_asset_issuer=GDRRHSJMHXDTQBT4JTCILNGF5AS54FEMTXL7KOLMF6TFTHRK6SSUSUZZ&" + 30 | "cursor=13537736921089&" + 31 | "limit=200&" + 32 | "order=asc", uri.toString()); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/PaymentResult.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // union PaymentResult switch (PaymentResultCode code) 12 | // { 13 | // case PAYMENT_SUCCESS: 14 | // void; 15 | // default: 16 | // void; 17 | // }; 18 | 19 | // =========================================================================== 20 | public class PaymentResult { 21 | public PaymentResult () {} 22 | PaymentResultCode code; 23 | public PaymentResultCode getDiscriminant() { 24 | return this.code; 25 | } 26 | public void setDiscriminant(PaymentResultCode value) { 27 | this.code = value; 28 | } 29 | public static void encode(XdrDataOutputStream stream, PaymentResult encodedPaymentResult) throws IOException { 30 | stream.writeInt(encodedPaymentResult.getDiscriminant().getValue()); 31 | switch (encodedPaymentResult.getDiscriminant()) { 32 | case PAYMENT_SUCCESS: 33 | break; 34 | default: 35 | break; 36 | } 37 | } 38 | public static PaymentResult decode(XdrDataInputStream stream) throws IOException { 39 | PaymentResult decodedPaymentResult = new PaymentResult(); 40 | PaymentResultCode discriminant = PaymentResultCode.decode(stream); 41 | decodedPaymentResult.setDiscriminant(discriminant); 42 | switch (decodedPaymentResult.getDiscriminant()) { 43 | case PAYMENT_SUCCESS: 44 | break; 45 | default: 46 | break; 47 | } 48 | return decodedPaymentResult; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # java-stellar-sdk 2 | 3 | [![Build Status](https://travis-ci.org/stellar/java-stellar-sdk.svg)](https://travis-ci.org/stellar/java-stellar-sdk) 4 | 5 | The Java Stellar Sdk library provides APIs to build transactions and connect to [Horizon](https://github.com/stellar/horizon). 6 | 7 | ## Installation 8 | 9 | ### Maven 10 | 11 | Use [jitpack.io](https://jitpack.io)'s Maven repository: 12 | 13 | ``` 14 | repositories { 15 | maven { url "https://jitpack.io" } 16 | } 17 | 18 | dependencies { 19 | implementation 'com.github.stellar:java-stellar-sdk:{version}' 20 | } 21 | ``` 22 | 23 | The list of versions to install can be found in the [Releases](./releases) section. More information can be found in [jitpack.io docs](https://jitpack.io/docs/). 24 | 25 | ### JAR 26 | 27 | Download the latest jar from the GitHub repo's [releases tab](https://github.com/stellar/java-stellar-sdk/releases). Add the `jar` package to your project according to how your environment is set up. 28 | 29 | ## Basic Usage 30 | For some examples on how to use this library, take a look at the [Get Started docs in the developers site](https://www.stellar.org/developers/guides/get-started/create-account.html). 31 | 32 | ## Documentation 33 | Javadoc is available at https://stellar.github.io/java-stellar-sdk 34 | 35 | ## Contributing 36 | For information on how to contribute, please refer to our [contribution guide](https://github.com/stellar/java-stellar-sdk/blob/master/CONTRIBUTING.md). 37 | 38 | ## License 39 | java-stellar-sdk is licensed under an Apache-2.0 license. See the [LICENSE](https://github.com/stellar/java-stellar-sdk/blob/master/LICENSE) file for details. 40 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/requests/AssetsRequestBuilder.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | import com.google.gson.reflect.TypeToken; 4 | import okhttp3.HttpUrl; 5 | import okhttp3.OkHttpClient; 6 | import okhttp3.Request; 7 | import okhttp3.Response; 8 | import org.stellar.sdk.responses.Page; 9 | import org.stellar.sdk.responses.AssetResponse; 10 | 11 | import java.io.IOException; 12 | 13 | public class AssetsRequestBuilder extends RequestBuilder { 14 | public AssetsRequestBuilder(OkHttpClient httpClient, HttpUrl serverURI) { 15 | super(httpClient, serverURI, "assets"); 16 | } 17 | 18 | public AssetsRequestBuilder assetCode(String assetCode) { 19 | uriBuilder.setQueryParameter("asset_code", assetCode); 20 | return this; 21 | } 22 | 23 | public AssetsRequestBuilder assetIssuer(String assetIssuer) { 24 | uriBuilder.setQueryParameter("asset_issuer", assetIssuer); 25 | return this; 26 | } 27 | 28 | public static Page execute(OkHttpClient httpClient, HttpUrl uri) throws IOException, TooManyRequestsException { 29 | TypeToken type = new TypeToken>() {}; 30 | ResponseHandler> responseHandler = new ResponseHandler>(type); 31 | 32 | Request request = new Request.Builder().get().url(uri).build(); 33 | Response response = httpClient.newCall(request).execute(); 34 | 35 | return responseHandler.handleResponse(response); 36 | } 37 | 38 | public Page execute() throws IOException, TooManyRequestsException { 39 | return this.execute(this.httpClient, this.buildUri()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | env: 3 | global: 4 | # GITHUB_TOKEN 5 | - secure: "sLQlgb6CU0tHrF4tXwJno/Xqme+mmgu74Qd9H9KuJexfb4OyYw593Q6tn3wMWrImyZlTmcbum1EYIFsgJGhCn8kMuF6PuOywGFPC44LooyBL9Pg4RTYeigQaAEwV4Nfofb7wf7Od09WVbwrb2+e25ya9b7DqtMEVAeFCXqVeGWtudHk+yxyG6N9usA3zvwMGd/Ku3s2WPlviNbGyd0h2aRBuhiAZcgC8OPSgwZNXm2nFgRs/GSxo40LeUSnoO8ilJ4Mp4JbGswXjacj21RGmVCXtwhIOJsy4dk8I0RApv04fCq9/e37K+N0K8Zf4l+n7DyfJzXAT8j/mSzea1RQQlv5lOkj4vBV6q6PBvBgnjrg/1POoP83cPHoJHv/6dbsQJ1GbBDDAbCIuyqXaLDrixvTXJc7x8SPnFUJHXOjzwcsX+oOo7DRqvwS1B4CUYbWnjvxxwHAxbDzW2G3iUKaNdtvBk1Ht/6AFnl2GqSlcEZDfwjIHtOcLNyAhMn2sw9Fjqsn+wXRH0ya9+VlgL+z8VvnJHzhrqUhrn1QJ+1YrpWShsJv61JKoMzQLvgiWoahjcXAnQ0YfAf+SUDlYrGvSgIZdJJfTcHFsdiXyJZuXwmeTNPeOrBS/WNVMJJWwCiYw/Z9KgRZdh8+/EhRSgLBZ0uSfIRbO37uOpdTWHkIFB4w=" 6 | before_deploy: "./gradlew jar" 7 | after_deploy: ./after_deploy.sh 8 | deploy: 9 | provider: releases 10 | api_key: 11 | secure: qvr18ooYvp+7hKbhulo9dKeiBrimnhEOFDfdq6TQk3mxul7zrY7Xe8ubPCubYqGbZR7vPIXUoprF+A7CZMizNbqiZGtljqw+svC4OlcPYQF8zKxwqGrQ98xf5bQB5X8lihZ4qVrcZy6XLHVKJXrEnMk61X0iD0RBUfBODG7J9njlRXtaeBcgpoTafd1dzVE5qnSEFLS93QCyg2NvbWTwh0XHhB+wNZN28Ij7E9HJdKm8RxK57wgXpvQ/025U1UseQc8Q77aHYRtgtaR+1YGBUMcqb1AfTZ4cHhAhlrrGErNMRqQFOFHzSsJl3d5JMAJYHAPNlGbeODVbhIGmST3WZHqiBHEJrjB1elbX5MnCpeMg0T7LlhwdiiZvm2m8/8mjxNxxb9RQdWROJtx0XTESTU2lQwsefZ0qoiTpDiuuFzLlNC3C2ri3EBWxFwunVF2VWjw46UYeb9/n6kOAcPZR1Te1YseOWKD6wo8qUhaeq1XvUKs5R8q2LDjmizu58wekFpDdmk3tqFRTUNSW5Ii+BnQXA0PIE42NHRKAlrRZ4nOeDhmPVY0Dkpqim5qhQa8+ijbba+CITUSrNatw7j4ySjdKCTZ49wX4ssrYL3XtXBOgOCL+ArFU5t1im9Yf/HKmCfeVwuaq+IqlzmJitt89ptrRcNDr2Dt5xURaqBQu/5Y= 12 | file: "./build/libs/stellar-sdk.jar" 13 | skip_cleanup: true 14 | on: 15 | repo: stellar/java-stellar-sdk 16 | tags: true 17 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/CreateAccountOp.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct CreateAccountOp 12 | // { 13 | // AccountID destination; // account to create 14 | // int64 startingBalance; // amount they end up with 15 | // }; 16 | 17 | // =========================================================================== 18 | public class CreateAccountOp { 19 | public CreateAccountOp () {} 20 | private AccountID destination; 21 | public AccountID getDestination() { 22 | return this.destination; 23 | } 24 | public void setDestination(AccountID value) { 25 | this.destination = value; 26 | } 27 | private Int64 startingBalance; 28 | public Int64 getStartingBalance() { 29 | return this.startingBalance; 30 | } 31 | public void setStartingBalance(Int64 value) { 32 | this.startingBalance = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, CreateAccountOp encodedCreateAccountOp) throws IOException{ 35 | AccountID.encode(stream, encodedCreateAccountOp.destination); 36 | Int64.encode(stream, encodedCreateAccountOp.startingBalance); 37 | } 38 | public static CreateAccountOp decode(XdrDataInputStream stream) throws IOException { 39 | CreateAccountOp decodedCreateAccountOp = new CreateAccountOp(); 40 | decodedCreateAccountOp.destination = AccountID.decode(stream); 41 | decodedCreateAccountOp.startingBalance = Int64.decode(stream); 42 | return decodedCreateAccountOp; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/DecoratedSignature.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct DecoratedSignature 12 | // { 13 | // SignatureHint hint; // last 4 bytes of the public key, used as a hint 14 | // Signature signature; // actual signature 15 | // }; 16 | 17 | // =========================================================================== 18 | public class DecoratedSignature { 19 | public DecoratedSignature () {} 20 | private SignatureHint hint; 21 | public SignatureHint getHint() { 22 | return this.hint; 23 | } 24 | public void setHint(SignatureHint value) { 25 | this.hint = value; 26 | } 27 | private Signature signature; 28 | public Signature getSignature() { 29 | return this.signature; 30 | } 31 | public void setSignature(Signature value) { 32 | this.signature = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, DecoratedSignature encodedDecoratedSignature) throws IOException{ 35 | SignatureHint.encode(stream, encodedDecoratedSignature.hint); 36 | Signature.encode(stream, encodedDecoratedSignature.signature); 37 | } 38 | public static DecoratedSignature decode(XdrDataInputStream stream) throws IOException { 39 | DecoratedSignature decodedDecoratedSignature = new DecoratedSignature(); 40 | decodedDecoratedSignature.hint = SignatureHint.decode(stream); 41 | decodedDecoratedSignature.signature = Signature.decode(stream); 42 | return decodedDecoratedSignature; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/LedgerEntryChangeType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum LedgerEntryChangeType 12 | // { 13 | // LEDGER_ENTRY_CREATED = 0, // entry was added to the ledger 14 | // LEDGER_ENTRY_UPDATED = 1, // entry was modified in the ledger 15 | // LEDGER_ENTRY_REMOVED = 2, // entry was removed from the ledger 16 | // LEDGER_ENTRY_STATE = 3 // value of the entry 17 | // }; 18 | 19 | // =========================================================================== 20 | public enum LedgerEntryChangeType { 21 | LEDGER_ENTRY_CREATED(0), 22 | LEDGER_ENTRY_UPDATED(1), 23 | LEDGER_ENTRY_REMOVED(2), 24 | LEDGER_ENTRY_STATE(3), 25 | ; 26 | private int mValue; 27 | 28 | LedgerEntryChangeType(int value) { 29 | mValue = value; 30 | } 31 | 32 | public int getValue() { 33 | return mValue; 34 | } 35 | 36 | static LedgerEntryChangeType decode(XdrDataInputStream stream) throws IOException { 37 | int value = stream.readInt(); 38 | switch (value) { 39 | case 0: return LEDGER_ENTRY_CREATED; 40 | case 1: return LEDGER_ENTRY_UPDATED; 41 | case 2: return LEDGER_ENTRY_REMOVED; 42 | case 3: return LEDGER_ENTRY_STATE; 43 | default: 44 | throw new RuntimeException("Unknown enum value: " + value); 45 | } 46 | } 47 | 48 | static void encode(XdrDataOutputStream stream, LedgerEntryChangeType value) throws IOException { 49 | stream.writeInt(value.getValue()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/AllowTrustResult.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // union AllowTrustResult switch (AllowTrustResultCode code) 12 | // { 13 | // case ALLOW_TRUST_SUCCESS: 14 | // void; 15 | // default: 16 | // void; 17 | // }; 18 | 19 | // =========================================================================== 20 | public class AllowTrustResult { 21 | public AllowTrustResult () {} 22 | AllowTrustResultCode code; 23 | public AllowTrustResultCode getDiscriminant() { 24 | return this.code; 25 | } 26 | public void setDiscriminant(AllowTrustResultCode value) { 27 | this.code = value; 28 | } 29 | public static void encode(XdrDataOutputStream stream, AllowTrustResult encodedAllowTrustResult) throws IOException { 30 | stream.writeInt(encodedAllowTrustResult.getDiscriminant().getValue()); 31 | switch (encodedAllowTrustResult.getDiscriminant()) { 32 | case ALLOW_TRUST_SUCCESS: 33 | break; 34 | default: 35 | break; 36 | } 37 | } 38 | public static AllowTrustResult decode(XdrDataInputStream stream) throws IOException { 39 | AllowTrustResult decodedAllowTrustResult = new AllowTrustResult(); 40 | AllowTrustResultCode discriminant = AllowTrustResultCode.decode(stream); 41 | decodedAllowTrustResult.setDiscriminant(discriminant); 42 | switch (decodedAllowTrustResult.getDiscriminant()) { 43 | case ALLOW_TRUST_SUCCESS: 44 | break; 45 | default: 46 | break; 47 | } 48 | return decodedAllowTrustResult; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/ManageDataResult.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // union ManageDataResult switch (ManageDataResultCode code) 12 | // { 13 | // case MANAGE_DATA_SUCCESS: 14 | // void; 15 | // default: 16 | // void; 17 | // }; 18 | 19 | // =========================================================================== 20 | public class ManageDataResult { 21 | public ManageDataResult () {} 22 | ManageDataResultCode code; 23 | public ManageDataResultCode getDiscriminant() { 24 | return this.code; 25 | } 26 | public void setDiscriminant(ManageDataResultCode value) { 27 | this.code = value; 28 | } 29 | public static void encode(XdrDataOutputStream stream, ManageDataResult encodedManageDataResult) throws IOException { 30 | stream.writeInt(encodedManageDataResult.getDiscriminant().getValue()); 31 | switch (encodedManageDataResult.getDiscriminant()) { 32 | case MANAGE_DATA_SUCCESS: 33 | break; 34 | default: 35 | break; 36 | } 37 | } 38 | public static ManageDataResult decode(XdrDataInputStream stream) throws IOException { 39 | ManageDataResult decodedManageDataResult = new ManageDataResult(); 40 | ManageDataResultCode discriminant = ManageDataResultCode.decode(stream); 41 | decodedManageDataResult.setDiscriminant(discriminant); 42 | switch (decodedManageDataResult.getDiscriminant()) { 43 | case MANAGE_DATA_SUCCESS: 44 | break; 45 | default: 46 | break; 47 | } 48 | return decodedManageDataResult; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/SetOptionsResult.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // union SetOptionsResult switch (SetOptionsResultCode code) 12 | // { 13 | // case SET_OPTIONS_SUCCESS: 14 | // void; 15 | // default: 16 | // void; 17 | // }; 18 | 19 | // =========================================================================== 20 | public class SetOptionsResult { 21 | public SetOptionsResult () {} 22 | SetOptionsResultCode code; 23 | public SetOptionsResultCode getDiscriminant() { 24 | return this.code; 25 | } 26 | public void setDiscriminant(SetOptionsResultCode value) { 27 | this.code = value; 28 | } 29 | public static void encode(XdrDataOutputStream stream, SetOptionsResult encodedSetOptionsResult) throws IOException { 30 | stream.writeInt(encodedSetOptionsResult.getDiscriminant().getValue()); 31 | switch (encodedSetOptionsResult.getDiscriminant()) { 32 | case SET_OPTIONS_SUCCESS: 33 | break; 34 | default: 35 | break; 36 | } 37 | } 38 | public static SetOptionsResult decode(XdrDataInputStream stream) throws IOException { 39 | SetOptionsResult decodedSetOptionsResult = new SetOptionsResult(); 40 | SetOptionsResultCode discriminant = SetOptionsResultCode.decode(stream); 41 | decodedSetOptionsResult.setDiscriminant(discriminant); 42 | switch (decodedSetOptionsResult.getDiscriminant()) { 43 | case SET_OPTIONS_SUCCESS: 44 | break; 45 | default: 46 | break; 47 | } 48 | return decodedSetOptionsResult; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/TransactionResultSet.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct TransactionResultSet 12 | // { 13 | // TransactionResultPair results<>; 14 | // }; 15 | 16 | // =========================================================================== 17 | public class TransactionResultSet { 18 | public TransactionResultSet () {} 19 | private TransactionResultPair[] results; 20 | public TransactionResultPair[] getResults() { 21 | return this.results; 22 | } 23 | public void setResults(TransactionResultPair[] value) { 24 | this.results = value; 25 | } 26 | public static void encode(XdrDataOutputStream stream, TransactionResultSet encodedTransactionResultSet) throws IOException{ 27 | int resultssize = encodedTransactionResultSet.getResults().length; 28 | stream.writeInt(resultssize); 29 | for (int i = 0; i < resultssize; i++) { 30 | TransactionResultPair.encode(stream, encodedTransactionResultSet.results[i]); 31 | } 32 | } 33 | public static TransactionResultSet decode(XdrDataInputStream stream) throws IOException { 34 | TransactionResultSet decodedTransactionResultSet = new TransactionResultSet(); 35 | int resultssize = stream.readInt(); 36 | decodedTransactionResultSet.results = new TransactionResultPair[resultssize]; 37 | for (int i = 0; i < resultssize; i++) { 38 | decodedTransactionResultSet.results[i] = TransactionResultPair.decode(stream); 39 | } 40 | return decodedTransactionResultSet; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/ChangeTrustResult.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // union ChangeTrustResult switch (ChangeTrustResultCode code) 12 | // { 13 | // case CHANGE_TRUST_SUCCESS: 14 | // void; 15 | // default: 16 | // void; 17 | // }; 18 | 19 | // =========================================================================== 20 | public class ChangeTrustResult { 21 | public ChangeTrustResult () {} 22 | ChangeTrustResultCode code; 23 | public ChangeTrustResultCode getDiscriminant() { 24 | return this.code; 25 | } 26 | public void setDiscriminant(ChangeTrustResultCode value) { 27 | this.code = value; 28 | } 29 | public static void encode(XdrDataOutputStream stream, ChangeTrustResult encodedChangeTrustResult) throws IOException { 30 | stream.writeInt(encodedChangeTrustResult.getDiscriminant().getValue()); 31 | switch (encodedChangeTrustResult.getDiscriminant()) { 32 | case CHANGE_TRUST_SUCCESS: 33 | break; 34 | default: 35 | break; 36 | } 37 | } 38 | public static ChangeTrustResult decode(XdrDataInputStream stream) throws IOException { 39 | ChangeTrustResult decodedChangeTrustResult = new ChangeTrustResult(); 40 | ChangeTrustResultCode discriminant = ChangeTrustResultCode.decode(stream); 41 | decodedChangeTrustResult.setDiscriminant(discriminant); 42 | switch (decodedChangeTrustResult.getDiscriminant()) { 43 | case CHANGE_TRUST_SUCCESS: 44 | break; 45 | default: 46 | break; 47 | } 48 | return decodedChangeTrustResult; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/LedgerEntryChanges.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // typedef LedgerEntryChange LedgerEntryChanges<>; 12 | 13 | // =========================================================================== 14 | public class LedgerEntryChanges { 15 | private LedgerEntryChange[] LedgerEntryChanges; 16 | public LedgerEntryChange[] getLedgerEntryChanges() { 17 | return this.LedgerEntryChanges; 18 | } 19 | public void setLedgerEntryChanges(LedgerEntryChange[] value) { 20 | this.LedgerEntryChanges = value; 21 | } 22 | public static void encode(XdrDataOutputStream stream, LedgerEntryChanges encodedLedgerEntryChanges) throws IOException { 23 | int LedgerEntryChangessize = encodedLedgerEntryChanges.getLedgerEntryChanges().length; 24 | stream.writeInt(LedgerEntryChangessize); 25 | for (int i = 0; i < LedgerEntryChangessize; i++) { 26 | LedgerEntryChange.encode(stream, encodedLedgerEntryChanges.LedgerEntryChanges[i]); 27 | } 28 | } 29 | public static LedgerEntryChanges decode(XdrDataInputStream stream) throws IOException { 30 | LedgerEntryChanges decodedLedgerEntryChanges = new LedgerEntryChanges(); 31 | int LedgerEntryChangessize = stream.readInt(); 32 | decodedLedgerEntryChanges.LedgerEntryChanges = new LedgerEntryChange[LedgerEntryChangessize]; 33 | for (int i = 0; i < LedgerEntryChangessize; i++) { 34 | decodedLedgerEntryChanges.LedgerEntryChanges[i] = LedgerEntryChange.decode(stream); 35 | } 36 | return decodedLedgerEntryChanges; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/requests/PathsRequestBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | import okhttp3.HttpUrl; 4 | import org.junit.Test; 5 | import org.stellar.sdk.Asset; 6 | import org.stellar.sdk.KeyPair; 7 | import org.stellar.sdk.Server; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class PathsRequestBuilderTest { 12 | @Test 13 | public void testAccounts() { 14 | Server server = new Server("https://horizon-testnet.stellar.org"); 15 | HttpUrl uri = server.paths() 16 | .destinationAccount(KeyPair.fromAccountId("GB24QI3BJNKBY4YNJZ2I37HFIYK56BL2OURFML76X46RQQKDLVT7WKJF")) 17 | .sourceAccount(KeyPair.fromAccountId("GD4KO3IOYYWIYVI236Y35K2DU6VNYRH3BPNFJSH57J5BLLCQHBIOK3IN")) 18 | .destinationAmount("20.50") 19 | .destinationAsset(Asset.createNonNativeAsset("USD", KeyPair.fromAccountId("GAYSHLG75RPSMXWJ5KX7O7STE6RSZTD6NE4CTWAXFZYYVYIFRUVJIBJH"))) 20 | .cursor("13537736921089") 21 | .limit(200) 22 | .order(RequestBuilder.Order.ASC) 23 | .buildUri(); 24 | 25 | assertEquals("https://horizon-testnet.stellar.org/paths?" + 26 | "destination_account=GB24QI3BJNKBY4YNJZ2I37HFIYK56BL2OURFML76X46RQQKDLVT7WKJF&" + 27 | "source_account=GD4KO3IOYYWIYVI236Y35K2DU6VNYRH3BPNFJSH57J5BLLCQHBIOK3IN&" + 28 | "destination_amount=20.50&" + 29 | "destination_asset_type=credit_alphanum4&" + 30 | "destination_asset_code=USD&" + 31 | "destination_asset_issuer=GAYSHLG75RPSMXWJ5KX7O7STE6RSZTD6NE4CTWAXFZYYVYIFRUVJIBJH&" + 32 | "cursor=13537736921089&" + 33 | "limit=200&" + 34 | "order=asc", uri.toString()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/AssetTypeCreditAlphaNum.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import java.util.Arrays; 4 | 5 | import static com.google.common.base.Preconditions.checkNotNull; 6 | 7 | /** 8 | * Base class for AssetTypeCreditAlphaNum4 and AssetTypeCreditAlphaNum12 subclasses. 9 | * @see Assets 10 | */ 11 | public abstract class AssetTypeCreditAlphaNum extends Asset { 12 | protected final String mCode; 13 | protected final KeyPair mIssuer; 14 | 15 | public AssetTypeCreditAlphaNum(String code, KeyPair issuer) { 16 | checkNotNull(code, "code cannot be null"); 17 | checkNotNull(issuer, "issuer cannot be null"); 18 | mCode = new String(code); 19 | mIssuer = KeyPair.fromAccountId(issuer.getAccountId()); 20 | } 21 | 22 | /** 23 | * Returns asset code 24 | */ 25 | public String getCode() { 26 | return new String(mCode); 27 | } 28 | 29 | /** 30 | * Returns asset issuer 31 | */ 32 | public KeyPair getIssuer() { 33 | return KeyPair.fromAccountId(mIssuer.getAccountId()); 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | return Arrays.hashCode(new Object[]{this.getCode(), this.getIssuer().getAccountId()}); 39 | } 40 | 41 | @Override 42 | public boolean equals(Object object) { 43 | if (!this.getClass().equals(object.getClass())) { 44 | return false; 45 | } 46 | 47 | AssetTypeCreditAlphaNum o = (AssetTypeCreditAlphaNum) object; 48 | 49 | return this.getCode().equals(o.getCode()) && 50 | this.getIssuer().getAccountId().equals(o.getIssuer().getAccountId()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/requests/TransactionsRequestBuilderTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | import okhttp3.HttpUrl; 4 | import org.junit.Test; 5 | import org.stellar.sdk.KeyPair; 6 | import org.stellar.sdk.Server; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | public class TransactionsRequestBuilderTest { 11 | @Test 12 | public void testTransactions() { 13 | Server server = new Server("https://horizon-testnet.stellar.org"); 14 | HttpUrl uri = server.transactions() 15 | .limit(200) 16 | .order(RequestBuilder.Order.DESC) 17 | .buildUri(); 18 | assertEquals("https://horizon-testnet.stellar.org/transactions?limit=200&order=desc", uri.toString()); 19 | } 20 | 21 | @Test 22 | public void testForAccount() { 23 | Server server = new Server("https://horizon-testnet.stellar.org"); 24 | HttpUrl uri = server.transactions() 25 | .forAccount(KeyPair.fromAccountId("GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H")) 26 | .limit(200) 27 | .order(RequestBuilder.Order.DESC) 28 | .buildUri(); 29 | assertEquals("https://horizon-testnet.stellar.org/accounts/GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H/transactions?limit=200&order=desc", uri.toString()); 30 | } 31 | 32 | @Test 33 | public void testForLedger() { 34 | Server server = new Server("https://horizon-testnet.stellar.org"); 35 | HttpUrl uri = server.transactions() 36 | .forLedger(200000000000L) 37 | .limit(50) 38 | .order(RequestBuilder.Order.ASC) 39 | .buildUri(); 40 | assertEquals("https://horizon-testnet.stellar.org/ledgers/200000000000/transactions?limit=50&order=asc", uri.toString()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/TransactionResultPair.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct TransactionResultPair 12 | // { 13 | // Hash transactionHash; 14 | // TransactionResult result; // result for the transaction 15 | // }; 16 | 17 | // =========================================================================== 18 | public class TransactionResultPair { 19 | public TransactionResultPair () {} 20 | private Hash transactionHash; 21 | public Hash getTransactionHash() { 22 | return this.transactionHash; 23 | } 24 | public void setTransactionHash(Hash value) { 25 | this.transactionHash = value; 26 | } 27 | private TransactionResult result; 28 | public TransactionResult getResult() { 29 | return this.result; 30 | } 31 | public void setResult(TransactionResult value) { 32 | this.result = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, TransactionResultPair encodedTransactionResultPair) throws IOException{ 35 | Hash.encode(stream, encodedTransactionResultPair.transactionHash); 36 | TransactionResult.encode(stream, encodedTransactionResultPair.result); 37 | } 38 | public static TransactionResultPair decode(XdrDataInputStream stream) throws IOException { 39 | TransactionResultPair decodedTransactionResultPair = new TransactionResultPair(); 40 | decodedTransactionResultPair.transactionHash = Hash.decode(stream); 41 | decodedTransactionResultPair.result = TransactionResult.decode(stream); 42 | return decodedTransactionResultPair; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/CreateAccountResult.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // union CreateAccountResult switch (CreateAccountResultCode code) 12 | // { 13 | // case CREATE_ACCOUNT_SUCCESS: 14 | // void; 15 | // default: 16 | // void; 17 | // }; 18 | 19 | // =========================================================================== 20 | public class CreateAccountResult { 21 | public CreateAccountResult () {} 22 | CreateAccountResultCode code; 23 | public CreateAccountResultCode getDiscriminant() { 24 | return this.code; 25 | } 26 | public void setDiscriminant(CreateAccountResultCode value) { 27 | this.code = value; 28 | } 29 | public static void encode(XdrDataOutputStream stream, CreateAccountResult encodedCreateAccountResult) throws IOException { 30 | stream.writeInt(encodedCreateAccountResult.getDiscriminant().getValue()); 31 | switch (encodedCreateAccountResult.getDiscriminant()) { 32 | case CREATE_ACCOUNT_SUCCESS: 33 | break; 34 | default: 35 | break; 36 | } 37 | } 38 | public static CreateAccountResult decode(XdrDataInputStream stream) throws IOException { 39 | CreateAccountResult decodedCreateAccountResult = new CreateAccountResult(); 40 | CreateAccountResultCode discriminant = CreateAccountResultCode.decode(stream); 41 | decodedCreateAccountResult.setDiscriminant(discriminant); 42 | switch (decodedCreateAccountResult.getDiscriminant()) { 43 | case CREATE_ACCOUNT_SUCCESS: 44 | break; 45 | default: 46 | break; 47 | } 48 | return decodedCreateAccountResult; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/xdr/XdrDataStreamTest.java: -------------------------------------------------------------------------------- 1 | 2 | package org.stellar.sdk.xdr; 3 | 4 | import java.io.ByteArrayInputStream; 5 | import java.io.ByteArrayOutputStream; 6 | import java.io.IOException; 7 | import java.nio.charset.StandardCharsets; 8 | import static org.junit.Assert.assertEquals; 9 | import org.junit.Test; 10 | 11 | 12 | public class XdrDataStreamTest { 13 | //helper for tests below. 14 | public static String backAndForthXdrStreaming(String inputString) throws IOException { 15 | 16 | //String to XDR 17 | ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); 18 | XdrDataOutputStream xdrOutputStream = new XdrDataOutputStream(byteOutputStream); 19 | xdrOutputStream.writeString(inputString); 20 | 21 | byte[] xdrByteOutput = byteOutputStream.toByteArray(); 22 | 23 | //XDR back to String 24 | XdrDataInputStream xdrInputStream = new XdrDataInputStream(new ByteArrayInputStream(xdrByteOutput)); 25 | String outputString = xdrInputStream.readString(); 26 | 27 | return outputString; 28 | 29 | } 30 | 31 | @Test 32 | public void backAndForthXdrStreamingWithStandardAscii() throws IOException { 33 | String memo = "Dollar Sign $"; 34 | assertEquals(memo, backAndForthXdrStreaming(memo)); 35 | 36 | } 37 | 38 | @Test 39 | public void backAndForthXdrStreamingWithNonStandardAscii() throws IOException { 40 | String memo = "Euro Sign €"; 41 | assertEquals(memo, backAndForthXdrStreaming(memo)); 42 | } 43 | 44 | @Test 45 | public void backAndForthXdrStreamingWithAllNonStandardAscii() throws IOException { 46 | String memo = "øûý™€♠♣♥†‡µ¢£€"; 47 | assertEquals(memo, backAndForthXdrStreaming(memo)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/PublicKey.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // union PublicKey switch (PublicKeyType type) 12 | // { 13 | // case PUBLIC_KEY_TYPE_ED25519: 14 | // uint256 ed25519; 15 | // }; 16 | 17 | // =========================================================================== 18 | public class PublicKey { 19 | public PublicKey () {} 20 | PublicKeyType type; 21 | public PublicKeyType getDiscriminant() { 22 | return this.type; 23 | } 24 | public void setDiscriminant(PublicKeyType value) { 25 | this.type = value; 26 | } 27 | private Uint256 ed25519; 28 | public Uint256 getEd25519() { 29 | return this.ed25519; 30 | } 31 | public void setEd25519(Uint256 value) { 32 | this.ed25519 = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, PublicKey encodedPublicKey) throws IOException { 35 | stream.writeInt(encodedPublicKey.getDiscriminant().getValue()); 36 | switch (encodedPublicKey.getDiscriminant()) { 37 | case PUBLIC_KEY_TYPE_ED25519: 38 | Uint256.encode(stream, encodedPublicKey.ed25519); 39 | break; 40 | } 41 | } 42 | public static PublicKey decode(XdrDataInputStream stream) throws IOException { 43 | PublicKey decodedPublicKey = new PublicKey(); 44 | PublicKeyType discriminant = PublicKeyType.decode(stream); 45 | decodedPublicKey.setDiscriminant(discriminant); 46 | switch (decodedPublicKey.getDiscriminant()) { 47 | case PUBLIC_KEY_TYPE_ED25519: 48 | decodedPublicKey.ed25519 = Uint256.decode(stream); 49 | break; 50 | } 51 | return decodedPublicKey; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/SCPHistoryEntry.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // union SCPHistoryEntry switch (int v) 12 | // { 13 | // case 0: 14 | // SCPHistoryEntryV0 v0; 15 | // }; 16 | 17 | // =========================================================================== 18 | public class SCPHistoryEntry { 19 | public SCPHistoryEntry () {} 20 | Integer v; 21 | public Integer getDiscriminant() { 22 | return this.v; 23 | } 24 | public void setDiscriminant(Integer value) { 25 | this.v = value; 26 | } 27 | private SCPHistoryEntryV0 v0; 28 | public SCPHistoryEntryV0 getV0() { 29 | return this.v0; 30 | } 31 | public void setV0(SCPHistoryEntryV0 value) { 32 | this.v0 = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, SCPHistoryEntry encodedSCPHistoryEntry) throws IOException { 35 | stream.writeInt(encodedSCPHistoryEntry.getDiscriminant().intValue()); 36 | switch (encodedSCPHistoryEntry.getDiscriminant()) { 37 | case 0: 38 | SCPHistoryEntryV0.encode(stream, encodedSCPHistoryEntry.v0); 39 | break; 40 | } 41 | } 42 | public static SCPHistoryEntry decode(XdrDataInputStream stream) throws IOException { 43 | SCPHistoryEntry decodedSCPHistoryEntry = new SCPHistoryEntry(); 44 | Integer discriminant = stream.readInt(); 45 | decodedSCPHistoryEntry.setDiscriminant(discriminant); 46 | switch (decodedSCPHistoryEntry.getDiscriminant()) { 47 | case 0: 48 | decodedSCPHistoryEntry.v0 = SCPHistoryEntryV0.decode(stream); 49 | break; 50 | } 51 | return decodedSCPHistoryEntry; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/AccountFlags.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum AccountFlags 12 | // { // masks for each flag 13 | // 14 | // // Flags set on issuer accounts 15 | // // TrustLines are created with authorized set to "false" requiring 16 | // // the issuer to set it for each TrustLine 17 | // AUTH_REQUIRED_FLAG = 0x1, 18 | // // If set, the authorized flag in TrustLines can be cleared 19 | // // otherwise, authorization cannot be revoked 20 | // AUTH_REVOCABLE_FLAG = 0x2, 21 | // // Once set, causes all AUTH_* flags to be read-only 22 | // AUTH_IMMUTABLE_FLAG = 0x4 23 | // }; 24 | 25 | // =========================================================================== 26 | public enum AccountFlags { 27 | AUTH_REQUIRED_FLAG(1), 28 | AUTH_REVOCABLE_FLAG(2), 29 | AUTH_IMMUTABLE_FLAG(4), 30 | ; 31 | private int mValue; 32 | 33 | AccountFlags(int value) { 34 | mValue = value; 35 | } 36 | 37 | public int getValue() { 38 | return mValue; 39 | } 40 | 41 | static AccountFlags decode(XdrDataInputStream stream) throws IOException { 42 | int value = stream.readInt(); 43 | switch (value) { 44 | case 1: return AUTH_REQUIRED_FLAG; 45 | case 2: return AUTH_REVOCABLE_FLAG; 46 | case 4: return AUTH_IMMUTABLE_FLAG; 47 | default: 48 | throw new RuntimeException("Unknown enum value: " + value); 49 | } 50 | } 51 | 52 | static void encode(XdrDataOutputStream stream, AccountFlags value) throws IOException { 53 | stream.writeInt(value.getValue()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/ManageDataOp.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct ManageDataOp 12 | // { 13 | // string64 dataName; 14 | // DataValue* dataValue; // set to null to clear 15 | // }; 16 | 17 | // =========================================================================== 18 | public class ManageDataOp { 19 | public ManageDataOp () {} 20 | private String64 dataName; 21 | public String64 getDataName() { 22 | return this.dataName; 23 | } 24 | public void setDataName(String64 value) { 25 | this.dataName = value; 26 | } 27 | private DataValue dataValue; 28 | public DataValue getDataValue() { 29 | return this.dataValue; 30 | } 31 | public void setDataValue(DataValue value) { 32 | this.dataValue = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, ManageDataOp encodedManageDataOp) throws IOException{ 35 | String64.encode(stream, encodedManageDataOp.dataName); 36 | if (encodedManageDataOp.dataValue != null) { 37 | stream.writeInt(1); 38 | DataValue.encode(stream, encodedManageDataOp.dataValue); 39 | } else { 40 | stream.writeInt(0); 41 | } 42 | } 43 | public static ManageDataOp decode(XdrDataInputStream stream) throws IOException { 44 | ManageDataOp decodedManageDataOp = new ManageDataOp(); 45 | decodedManageDataOp.dataName = String64.decode(stream); 46 | int dataValuePresent = stream.readInt(); 47 | if (dataValuePresent != 0) { 48 | decodedManageDataOp.dataValue = DataValue.decode(stream); 49 | } 50 | return decodedManageDataOp; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/AuthCert.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct AuthCert 12 | // { 13 | // Curve25519Public pubkey; 14 | // uint64 expiration; 15 | // Signature sig; 16 | // }; 17 | 18 | // =========================================================================== 19 | public class AuthCert { 20 | public AuthCert () {} 21 | private Curve25519Public pubkey; 22 | public Curve25519Public getPubkey() { 23 | return this.pubkey; 24 | } 25 | public void setPubkey(Curve25519Public value) { 26 | this.pubkey = value; 27 | } 28 | private Uint64 expiration; 29 | public Uint64 getExpiration() { 30 | return this.expiration; 31 | } 32 | public void setExpiration(Uint64 value) { 33 | this.expiration = value; 34 | } 35 | private Signature sig; 36 | public Signature getSig() { 37 | return this.sig; 38 | } 39 | public void setSig(Signature value) { 40 | this.sig = value; 41 | } 42 | public static void encode(XdrDataOutputStream stream, AuthCert encodedAuthCert) throws IOException{ 43 | Curve25519Public.encode(stream, encodedAuthCert.pubkey); 44 | Uint64.encode(stream, encodedAuthCert.expiration); 45 | Signature.encode(stream, encodedAuthCert.sig); 46 | } 47 | public static AuthCert decode(XdrDataInputStream stream) throws IOException { 48 | AuthCert decodedAuthCert = new AuthCert(); 49 | decodedAuthCert.pubkey = Curve25519Public.decode(stream); 50 | decodedAuthCert.expiration = Uint64.decode(stream); 51 | decodedAuthCert.sig = Signature.decode(stream); 52 | return decodedAuthCert; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/requests/ResponseHandler.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.requests; 2 | 3 | import com.google.gson.reflect.TypeToken; 4 | 5 | import org.stellar.sdk.responses.GsonSingleton; 6 | import org.stellar.sdk.responses.TypedResponse; 7 | 8 | import java.io.IOException; 9 | 10 | import okhttp3.Response; 11 | 12 | public class ResponseHandler { 13 | 14 | private TypeToken type; 15 | 16 | /** 17 | * "Generics on a type are typically erased at runtime, except when the type is compiled with the 18 | * generic parameter bound. In that case, the compiler inserts the generic type information into 19 | * the compiled class. In other cases, that is not possible." 20 | * More info: http://stackoverflow.com/a/14506181 21 | * @param type 22 | */ 23 | public ResponseHandler(TypeToken type) { 24 | this.type = type; 25 | } 26 | 27 | public T handleResponse(final Response response) throws IOException, TooManyRequestsException { 28 | try { 29 | // Too Many Requests 30 | if (response.code() == 429) { 31 | int retryAfter = Integer.parseInt(response.header("Retry-After")); 32 | throw new TooManyRequestsException(retryAfter); 33 | } 34 | 35 | String content = response.body().string(); 36 | 37 | // Other errors 38 | if (response.code() >= 300) { 39 | throw new ErrorResponse(response.code(), content); 40 | } 41 | 42 | T object = GsonSingleton.getInstance().fromJson(content, type.getType()); 43 | if (object instanceof org.stellar.sdk.responses.Response) { 44 | ((org.stellar.sdk.responses.Response) object).setHeaders(response.headers()); 45 | } 46 | if(object instanceof TypedResponse) { 47 | ((TypedResponse) object).setType(type); 48 | } 49 | return object; 50 | } finally { 51 | response.close(); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /xdr/Stellar-types.x: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Stellar Development Foundation and contributors. Licensed 2 | // under the Apache License, Version 2.0. See the COPYING file at the root 3 | // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 4 | 5 | namespace stellar 6 | { 7 | 8 | typedef opaque Hash[32]; 9 | typedef opaque uint256[32]; 10 | 11 | typedef unsigned int uint32; 12 | typedef int int32; 13 | 14 | typedef unsigned hyper uint64; 15 | typedef hyper int64; 16 | 17 | enum CryptoKeyType 18 | { 19 | KEY_TYPE_ED25519 = 0, 20 | KEY_TYPE_PRE_AUTH_TX = 1, 21 | KEY_TYPE_HASH_X = 2 22 | }; 23 | 24 | enum PublicKeyType 25 | { 26 | PUBLIC_KEY_TYPE_ED25519 = KEY_TYPE_ED25519 27 | }; 28 | 29 | enum SignerKeyType 30 | { 31 | SIGNER_KEY_TYPE_ED25519 = KEY_TYPE_ED25519, 32 | SIGNER_KEY_TYPE_PRE_AUTH_TX = KEY_TYPE_PRE_AUTH_TX, 33 | SIGNER_KEY_TYPE_HASH_X = KEY_TYPE_HASH_X 34 | }; 35 | 36 | union PublicKey switch (PublicKeyType type) 37 | { 38 | case PUBLIC_KEY_TYPE_ED25519: 39 | uint256 ed25519; 40 | }; 41 | 42 | union SignerKey switch (SignerKeyType type) 43 | { 44 | case SIGNER_KEY_TYPE_ED25519: 45 | uint256 ed25519; 46 | case SIGNER_KEY_TYPE_PRE_AUTH_TX: 47 | /* Hash of Transaction structure */ 48 | uint256 preAuthTx; 49 | case SIGNER_KEY_TYPE_HASH_X: 50 | /* Hash of random 256 bit preimage X */ 51 | uint256 hashX; 52 | }; 53 | 54 | // variable size as the size depends on the signature scheme used 55 | typedef opaque Signature<64>; 56 | 57 | typedef opaque SignatureHint[4]; 58 | 59 | typedef PublicKey NodeID; 60 | 61 | struct Curve25519Secret 62 | { 63 | opaque key[32]; 64 | }; 65 | 66 | struct Curve25519Public 67 | { 68 | opaque key[32]; 69 | }; 70 | 71 | struct HmacSha256Key 72 | { 73 | opaque key[32]; 74 | }; 75 | 76 | struct HmacSha256Mac 77 | { 78 | opaque mac[32]; 79 | }; 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/Response.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses; 2 | 3 | import okhttp3.Headers; 4 | 5 | public abstract class Response { 6 | protected int rateLimitLimit; 7 | protected int rateLimitRemaining; 8 | protected int rateLimitReset; 9 | 10 | public void setHeaders(Headers headers) { 11 | if (headers.get("X-Ratelimit-Limit") != null) { 12 | this.rateLimitLimit = Integer.parseInt(headers.get("X-Ratelimit-Limit")); 13 | } 14 | if (headers.get("X-Ratelimit-Remaining") != null) { 15 | this.rateLimitRemaining = Integer.parseInt(headers.get("X-Ratelimit-Remaining")); 16 | } 17 | if (headers.get("X-Ratelimit-Reset") != null) { 18 | this.rateLimitReset = Integer.parseInt(headers.get("X-Ratelimit-Reset")); 19 | } 20 | } 21 | 22 | /** 23 | * Returns X-RateLimit-Limit header from the response. 24 | * This number represents the he maximum number of requests that the current client can 25 | * make in one hour. 26 | * @see Rate Limiting 27 | */ 28 | public int getRateLimitLimit() { 29 | return rateLimitLimit; 30 | } 31 | 32 | /** 33 | * Returns X-RateLimit-Remaining header from the response. 34 | * The number of remaining requests for the current window. 35 | * @see Rate Limiting 36 | */ 37 | public int getRateLimitRemaining() { 38 | return rateLimitRemaining; 39 | } 40 | 41 | /** 42 | * Returns X-RateLimit-Reset header from the response. Seconds until a new window starts. 43 | * @see Rate Limiting 44 | */ 45 | public int getRateLimitReset() { 46 | return rateLimitReset; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/PaymentOp.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct PaymentOp 12 | // { 13 | // AccountID destination; // recipient of the payment 14 | // Asset asset; // what they end up with 15 | // int64 amount; // amount they end up with 16 | // }; 17 | 18 | // =========================================================================== 19 | public class PaymentOp { 20 | public PaymentOp () {} 21 | private AccountID destination; 22 | public AccountID getDestination() { 23 | return this.destination; 24 | } 25 | public void setDestination(AccountID value) { 26 | this.destination = value; 27 | } 28 | private Asset asset; 29 | public Asset getAsset() { 30 | return this.asset; 31 | } 32 | public void setAsset(Asset value) { 33 | this.asset = value; 34 | } 35 | private Int64 amount; 36 | public Int64 getAmount() { 37 | return this.amount; 38 | } 39 | public void setAmount(Int64 value) { 40 | this.amount = value; 41 | } 42 | public static void encode(XdrDataOutputStream stream, PaymentOp encodedPaymentOp) throws IOException{ 43 | AccountID.encode(stream, encodedPaymentOp.destination); 44 | Asset.encode(stream, encodedPaymentOp.asset); 45 | Int64.encode(stream, encodedPaymentOp.amount); 46 | } 47 | public static PaymentOp decode(XdrDataInputStream stream) throws IOException { 48 | PaymentOp decodedPaymentOp = new PaymentOp(); 49 | decodedPaymentOp.destination = AccountID.decode(stream); 50 | decodedPaymentOp.asset = Asset.decode(stream); 51 | decodedPaymentOp.amount = Int64.decode(stream); 52 | return decodedPaymentOp; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/operations/PaymentOperationResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.operations; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import org.stellar.sdk.Asset; 6 | import org.stellar.sdk.AssetTypeNative; 7 | import org.stellar.sdk.KeyPair; 8 | 9 | /** 10 | * Represents Payment operation response. 11 | * @see Operation documentation 12 | * @see org.stellar.sdk.requests.OperationsRequestBuilder 13 | * @see org.stellar.sdk.Server#operations() 14 | */ 15 | public class PaymentOperationResponse extends OperationResponse { 16 | @SerializedName("amount") 17 | protected final String amount; 18 | @SerializedName("asset_type") 19 | protected final String assetType; 20 | @SerializedName("asset_code") 21 | protected final String assetCode; 22 | @SerializedName("asset_issuer") 23 | protected final String assetIssuer; 24 | @SerializedName("from") 25 | protected final KeyPair from; 26 | @SerializedName("to") 27 | protected final KeyPair to; 28 | 29 | PaymentOperationResponse(String amount, String assetType, String assetCode, String assetIssuer, KeyPair from, KeyPair to) { 30 | this.amount = amount; 31 | this.assetType = assetType; 32 | this.assetCode = assetCode; 33 | this.assetIssuer = assetIssuer; 34 | this.from = from; 35 | this.to = to; 36 | } 37 | 38 | public String getAmount() { 39 | return amount; 40 | } 41 | 42 | public Asset getAsset() { 43 | if (assetType.equals("native")) { 44 | return new AssetTypeNative(); 45 | } else { 46 | KeyPair issuer = KeyPair.fromAccountId(assetIssuer); 47 | return Asset.createNonNativeAsset(assetCode, issuer); 48 | } 49 | } 50 | 51 | public KeyPair getFrom() { 52 | return from; 53 | } 54 | 55 | public KeyPair getTo() { 56 | return to; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/SimplePaymentResult.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct SimplePaymentResult 12 | // { 13 | // AccountID destination; 14 | // Asset asset; 15 | // int64 amount; 16 | // }; 17 | 18 | // =========================================================================== 19 | public class SimplePaymentResult { 20 | public SimplePaymentResult () {} 21 | private AccountID destination; 22 | public AccountID getDestination() { 23 | return this.destination; 24 | } 25 | public void setDestination(AccountID value) { 26 | this.destination = value; 27 | } 28 | private Asset asset; 29 | public Asset getAsset() { 30 | return this.asset; 31 | } 32 | public void setAsset(Asset value) { 33 | this.asset = value; 34 | } 35 | private Int64 amount; 36 | public Int64 getAmount() { 37 | return this.amount; 38 | } 39 | public void setAmount(Int64 value) { 40 | this.amount = value; 41 | } 42 | public static void encode(XdrDataOutputStream stream, SimplePaymentResult encodedSimplePaymentResult) throws IOException{ 43 | AccountID.encode(stream, encodedSimplePaymentResult.destination); 44 | Asset.encode(stream, encodedSimplePaymentResult.asset); 45 | Int64.encode(stream, encodedSimplePaymentResult.amount); 46 | } 47 | public static SimplePaymentResult decode(XdrDataInputStream stream) throws IOException { 48 | SimplePaymentResult decodedSimplePaymentResult = new SimplePaymentResult(); 49 | decodedSimplePaymentResult.destination = AccountID.decode(stream); 50 | decodedSimplePaymentResult.asset = Asset.decode(stream); 51 | decodedSimplePaymentResult.amount = Int64.decode(stream); 52 | return decodedSimplePaymentResult; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/TransactionSet.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct TransactionSet 12 | // { 13 | // Hash previousLedgerHash; 14 | // TransactionEnvelope txs<>; 15 | // }; 16 | 17 | // =========================================================================== 18 | public class TransactionSet { 19 | public TransactionSet () {} 20 | private Hash previousLedgerHash; 21 | public Hash getPreviousLedgerHash() { 22 | return this.previousLedgerHash; 23 | } 24 | public void setPreviousLedgerHash(Hash value) { 25 | this.previousLedgerHash = value; 26 | } 27 | private TransactionEnvelope[] txs; 28 | public TransactionEnvelope[] getTxs() { 29 | return this.txs; 30 | } 31 | public void setTxs(TransactionEnvelope[] value) { 32 | this.txs = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, TransactionSet encodedTransactionSet) throws IOException{ 35 | Hash.encode(stream, encodedTransactionSet.previousLedgerHash); 36 | int txssize = encodedTransactionSet.getTxs().length; 37 | stream.writeInt(txssize); 38 | for (int i = 0; i < txssize; i++) { 39 | TransactionEnvelope.encode(stream, encodedTransactionSet.txs[i]); 40 | } 41 | } 42 | public static TransactionSet decode(XdrDataInputStream stream) throws IOException { 43 | TransactionSet decodedTransactionSet = new TransactionSet(); 44 | decodedTransactionSet.previousLedgerHash = Hash.decode(stream); 45 | int txssize = stream.readInt(); 46 | decodedTransactionSet.txs = new TransactionEnvelope[txssize]; 47 | for (int i = 0; i < txssize; i++) { 48 | decodedTransactionSet.txs[i] = TransactionEnvelope.decode(stream); 49 | } 50 | return decodedTransactionSet; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/MemoHashAbstract.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk; 2 | 3 | import com.google.common.io.BaseEncoding; 4 | 5 | abstract class MemoHashAbstract extends Memo { 6 | protected byte[] bytes; 7 | 8 | public MemoHashAbstract(byte[] bytes) { 9 | if (bytes.length < 32) { 10 | bytes = Util.paddedByteArray(bytes, 32); 11 | } else if (bytes.length > 32) { 12 | throw new MemoTooLongException("MEMO_HASH can contain 32 bytes at max."); 13 | } 14 | 15 | this.bytes = bytes; 16 | } 17 | 18 | public MemoHashAbstract(String hexString) { 19 | // We change to lowercase because we want to decode both: upper cased and lower cased alphabets. 20 | this(BaseEncoding.base16().lowerCase().decode(hexString.toLowerCase())); 21 | } 22 | 23 | /** 24 | * Returns 32 bytes long array contained in this memo. 25 | */ 26 | public byte[] getBytes() { 27 | return bytes; 28 | } 29 | 30 | /** 31 | *

Returns hex representation of bytes contained in this memo.

32 | * 33 | *

Example:

34 | * 35 | * MemoHash memo = new MemoHash("4142434445"); 36 | * memo.getHexValue(); // 4142434445000000000000000000000000000000000000000000000000000000 37 | * memo.getTrimmedHexValue(); // 4142434445 38 | * 39 | */ 40 | public String getHexValue() { 41 | return BaseEncoding.base16().lowerCase().encode(this.bytes); 42 | } 43 | 44 | /** 45 | *

Returns hex representation of bytes contained in this memo until null byte (0x00) is found.

46 | * 47 | *

Example:

48 | * 49 | * MemoHash memo = new MemoHash("4142434445"); 50 | * memo.getHexValue(); // 4142434445000000000000000000000000000000000000000000000000000000 51 | * memo.getTrimmedHexValue(); // 4142434445 52 | * 53 | */ 54 | public String getTrimmedHexValue() { 55 | return this.getHexValue().split("00")[0]; 56 | } 57 | 58 | @Override 59 | abstract org.stellar.sdk.xdr.Memo toXdr(); 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/LedgerSCPMessages.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct LedgerSCPMessages 12 | // { 13 | // uint32 ledgerSeq; 14 | // SCPEnvelope messages<>; 15 | // }; 16 | 17 | // =========================================================================== 18 | public class LedgerSCPMessages { 19 | public LedgerSCPMessages () {} 20 | private Uint32 ledgerSeq; 21 | public Uint32 getLedgerSeq() { 22 | return this.ledgerSeq; 23 | } 24 | public void setLedgerSeq(Uint32 value) { 25 | this.ledgerSeq = value; 26 | } 27 | private SCPEnvelope[] messages; 28 | public SCPEnvelope[] getMessages() { 29 | return this.messages; 30 | } 31 | public void setMessages(SCPEnvelope[] value) { 32 | this.messages = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, LedgerSCPMessages encodedLedgerSCPMessages) throws IOException{ 35 | Uint32.encode(stream, encodedLedgerSCPMessages.ledgerSeq); 36 | int messagessize = encodedLedgerSCPMessages.getMessages().length; 37 | stream.writeInt(messagessize); 38 | for (int i = 0; i < messagessize; i++) { 39 | SCPEnvelope.encode(stream, encodedLedgerSCPMessages.messages[i]); 40 | } 41 | } 42 | public static LedgerSCPMessages decode(XdrDataInputStream stream) throws IOException { 43 | LedgerSCPMessages decodedLedgerSCPMessages = new LedgerSCPMessages(); 44 | decodedLedgerSCPMessages.ledgerSeq = Uint32.decode(stream); 45 | int messagessize = stream.readInt(); 46 | decodedLedgerSCPMessages.messages = new SCPEnvelope[messagessize]; 47 | for (int i = 0; i < messagessize; i++) { 48 | decodedLedgerSCPMessages.messages[i] = SCPEnvelope.decode(stream); 49 | } 50 | return decodedLedgerSCPMessages; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/operations/ChangeTrustOperationResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.operations; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import org.stellar.sdk.Asset; 6 | import org.stellar.sdk.AssetTypeNative; 7 | import org.stellar.sdk.KeyPair; 8 | 9 | /** 10 | * Represents ChangeTrust operation response. 11 | * @see Operation documentation 12 | * @see org.stellar.sdk.requests.OperationsRequestBuilder 13 | * @see org.stellar.sdk.Server#operations() 14 | */ 15 | public class ChangeTrustOperationResponse extends OperationResponse { 16 | @SerializedName("trustor") 17 | protected final KeyPair trustor; 18 | @SerializedName("trustee") 19 | protected final KeyPair trustee; 20 | @SerializedName("asset_type") 21 | protected final String assetType; 22 | @SerializedName("asset_code") 23 | protected final String assetCode; 24 | @SerializedName("asset_issuer") 25 | protected final String assetIssuer; 26 | @SerializedName("limit") 27 | protected final String limit; 28 | 29 | ChangeTrustOperationResponse(KeyPair trustor, KeyPair trustee, String assetType, String assetCode, String assetIssuer, String limit) { 30 | this.trustor = trustor; 31 | this.trustee = trustee; 32 | this.assetType = assetType; 33 | this.assetCode = assetCode; 34 | this.assetIssuer = assetIssuer; 35 | this.limit = limit; 36 | } 37 | 38 | public KeyPair getTrustor() { 39 | return trustor; 40 | } 41 | 42 | public KeyPair getTrustee() { 43 | return trustee; 44 | } 45 | 46 | public String getLimit() { 47 | return limit; 48 | } 49 | 50 | public Asset getAsset() { 51 | if (assetType.equals("native")) { 52 | return new AssetTypeNative(); 53 | } else { 54 | KeyPair issuer = KeyPair.fromAccountId(assetIssuer); 55 | return Asset.createNonNativeAsset(assetCode, issuer); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/responses/operations/AllowTrustOperationResponse.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.responses.operations; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import org.stellar.sdk.Asset; 6 | import org.stellar.sdk.AssetTypeNative; 7 | import org.stellar.sdk.KeyPair; 8 | 9 | /** 10 | * Represents AllowTrust operation response. 11 | * @see Operation documentation 12 | * @see org.stellar.sdk.requests.OperationsRequestBuilder 13 | * @see org.stellar.sdk.Server#operations() 14 | */ 15 | public class AllowTrustOperationResponse extends OperationResponse { 16 | @SerializedName("trustor") 17 | protected final KeyPair trustor; 18 | @SerializedName("trustee") 19 | protected final KeyPair trustee; 20 | @SerializedName("asset_type") 21 | protected final String assetType; 22 | @SerializedName("asset_code") 23 | protected final String assetCode; 24 | @SerializedName("asset_issuer") 25 | protected final String assetIssuer; 26 | @SerializedName("authorize") 27 | protected final boolean authorize; 28 | 29 | AllowTrustOperationResponse(boolean authorize, String assetIssuer, String assetCode, String assetType, KeyPair trustee, KeyPair trustor) { 30 | this.authorize = authorize; 31 | this.assetIssuer = assetIssuer; 32 | this.assetCode = assetCode; 33 | this.assetType = assetType; 34 | this.trustee = trustee; 35 | this.trustor = trustor; 36 | } 37 | 38 | public KeyPair getTrustor() { 39 | return trustor; 40 | } 41 | 42 | public KeyPair getTrustee() { 43 | return trustee; 44 | } 45 | 46 | public boolean isAuthorize() { 47 | return authorize; 48 | } 49 | 50 | public Asset getAsset() { 51 | if (assetType.equals("native")) { 52 | return new AssetTypeNative(); 53 | } else { 54 | KeyPair issuer = KeyPair.fromAccountId(assetIssuer); 55 | return Asset.createNonNativeAsset(assetCode, issuer); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/AccountMergeResultCode.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum AccountMergeResultCode 12 | // { 13 | // // codes considered as "success" for the operation 14 | // ACCOUNT_MERGE_SUCCESS = 0, 15 | // // codes considered as "failure" for the operation 16 | // ACCOUNT_MERGE_MALFORMED = -1, // can't merge onto itself 17 | // ACCOUNT_MERGE_NO_ACCOUNT = -2, // destination does not exist 18 | // ACCOUNT_MERGE_IMMUTABLE_SET = -3, // source account has AUTH_IMMUTABLE set 19 | // ACCOUNT_MERGE_HAS_SUB_ENTRIES = -4 // account has trust lines/offers 20 | // }; 21 | 22 | // =========================================================================== 23 | public enum AccountMergeResultCode { 24 | ACCOUNT_MERGE_SUCCESS(0), 25 | ACCOUNT_MERGE_MALFORMED(-1), 26 | ACCOUNT_MERGE_NO_ACCOUNT(-2), 27 | ACCOUNT_MERGE_IMMUTABLE_SET(-3), 28 | ACCOUNT_MERGE_HAS_SUB_ENTRIES(-4), 29 | ; 30 | private int mValue; 31 | 32 | AccountMergeResultCode(int value) { 33 | mValue = value; 34 | } 35 | 36 | public int getValue() { 37 | return mValue; 38 | } 39 | 40 | static AccountMergeResultCode decode(XdrDataInputStream stream) throws IOException { 41 | int value = stream.readInt(); 42 | switch (value) { 43 | case 0: return ACCOUNT_MERGE_SUCCESS; 44 | case -1: return ACCOUNT_MERGE_MALFORMED; 45 | case -2: return ACCOUNT_MERGE_NO_ACCOUNT; 46 | case -3: return ACCOUNT_MERGE_IMMUTABLE_SET; 47 | case -4: return ACCOUNT_MERGE_HAS_SUB_ENTRIES; 48 | default: 49 | throw new RuntimeException("Unknown enum value: " + value); 50 | } 51 | } 52 | 53 | static void encode(XdrDataOutputStream stream, AccountMergeResultCode value) throws IOException { 54 | stream.writeInt(value.getValue()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/org/stellar/sdk/federation/FederationTest.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.federation; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import okhttp3.HttpUrl; 6 | import okhttp3.mockwebserver.MockResponse; 7 | import okhttp3.mockwebserver.MockWebServer; 8 | import org.junit.After; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | import java.io.IOException; 13 | 14 | public class FederationTest extends TestCase { 15 | @Before 16 | public void setUp() throws IOException { 17 | FederationServer.httpsConnection = false; 18 | } 19 | 20 | @After 21 | public void tearDown() throws IOException { 22 | FederationServer.httpsConnection = true; 23 | } 24 | 25 | @Test 26 | public void testResolveSuccess() throws IOException { 27 | MockWebServer mockWebServer = new MockWebServer(); 28 | mockWebServer.start(); 29 | 30 | HttpUrl baseUrl = mockWebServer.url(""); 31 | String domain = String.format("%s:%d", baseUrl.host(), baseUrl.port()); 32 | 33 | String stellarToml = 34 | "FEDERATION_SERVER = \"http://"+domain+"/federation\""; 35 | String successResponse = 36 | "{\"stellar_address\":\"bob*"+domain+"\",\"account_id\":\"GCW667JUHCOP5Y7KY6KGDHNPHFM4CS3FCBQ7QWDUALXTX3PGXLSOEALY\"}"; 37 | 38 | mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(stellarToml)); 39 | mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(successResponse)); 40 | 41 | FederationResponse response = Federation.resolve("bob*"+domain); 42 | assertEquals(response.getStellarAddress(), "bob*"+domain); 43 | assertEquals(response.getAccountId(), "GCW667JUHCOP5Y7KY6KGDHNPHFM4CS3FCBQ7QWDUALXTX3PGXLSOEALY"); 44 | assertNull(response.getMemoType()); 45 | assertNull(response.getMemo()); 46 | } 47 | 48 | @Test 49 | public void testMalformedAddress() { 50 | try { 51 | FederationResponse response = Federation.resolve("bob*stellar.org*test"); 52 | fail("Expected exception"); 53 | } catch (MalformedAddressException e) { 54 | // 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/ManageDataResultCode.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum ManageDataResultCode 12 | // { 13 | // // codes considered as "success" for the operation 14 | // MANAGE_DATA_SUCCESS = 0, 15 | // // codes considered as "failure" for the operation 16 | // MANAGE_DATA_NOT_SUPPORTED_YET = -1, // The network hasn't moved to this protocol change yet 17 | // MANAGE_DATA_NAME_NOT_FOUND = -2, // Trying to remove a Data Entry that isn't there 18 | // MANAGE_DATA_LOW_RESERVE = -3, // not enough funds to create a new Data Entry 19 | // MANAGE_DATA_INVALID_NAME = -4 // Name not a valid string 20 | // }; 21 | 22 | // =========================================================================== 23 | public enum ManageDataResultCode { 24 | MANAGE_DATA_SUCCESS(0), 25 | MANAGE_DATA_NOT_SUPPORTED_YET(-1), 26 | MANAGE_DATA_NAME_NOT_FOUND(-2), 27 | MANAGE_DATA_LOW_RESERVE(-3), 28 | MANAGE_DATA_INVALID_NAME(-4), 29 | ; 30 | private int mValue; 31 | 32 | ManageDataResultCode(int value) { 33 | mValue = value; 34 | } 35 | 36 | public int getValue() { 37 | return mValue; 38 | } 39 | 40 | static ManageDataResultCode decode(XdrDataInputStream stream) throws IOException { 41 | int value = stream.readInt(); 42 | switch (value) { 43 | case 0: return MANAGE_DATA_SUCCESS; 44 | case -1: return MANAGE_DATA_NOT_SUPPORTED_YET; 45 | case -2: return MANAGE_DATA_NAME_NOT_FOUND; 46 | case -3: return MANAGE_DATA_LOW_RESERVE; 47 | case -4: return MANAGE_DATA_INVALID_NAME; 48 | default: 49 | throw new RuntimeException("Unknown enum value: " + value); 50 | } 51 | } 52 | 53 | static void encode(XdrDataOutputStream stream, ManageDataResultCode value) throws IOException { 54 | stream.writeInt(value.getValue()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/OperationType.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum OperationType 12 | // { 13 | // CREATE_ACCOUNT = 0, 14 | // PAYMENT = 1, 15 | // PATH_PAYMENT = 2, 16 | // MANAGE_OFFER = 3, 17 | // CREATE_PASSIVE_OFFER = 4, 18 | // SET_OPTIONS = 5, 19 | // CHANGE_TRUST = 6, 20 | // ALLOW_TRUST = 7, 21 | // ACCOUNT_MERGE = 8, 22 | // INFLATION = 9, 23 | // MANAGE_DATA = 10 24 | // }; 25 | 26 | // =========================================================================== 27 | public enum OperationType { 28 | CREATE_ACCOUNT(0), 29 | PAYMENT(1), 30 | PATH_PAYMENT(2), 31 | MANAGE_OFFER(3), 32 | CREATE_PASSIVE_OFFER(4), 33 | SET_OPTIONS(5), 34 | CHANGE_TRUST(6), 35 | ALLOW_TRUST(7), 36 | ACCOUNT_MERGE(8), 37 | INFLATION(9), 38 | MANAGE_DATA(10), 39 | ; 40 | private int mValue; 41 | 42 | OperationType(int value) { 43 | mValue = value; 44 | } 45 | 46 | public int getValue() { 47 | return mValue; 48 | } 49 | 50 | static OperationType decode(XdrDataInputStream stream) throws IOException { 51 | int value = stream.readInt(); 52 | switch (value) { 53 | case 0: return CREATE_ACCOUNT; 54 | case 1: return PAYMENT; 55 | case 2: return PATH_PAYMENT; 56 | case 3: return MANAGE_OFFER; 57 | case 4: return CREATE_PASSIVE_OFFER; 58 | case 5: return SET_OPTIONS; 59 | case 6: return CHANGE_TRUST; 60 | case 7: return ALLOW_TRUST; 61 | case 8: return ACCOUNT_MERGE; 62 | case 9: return INFLATION; 63 | case 10: return MANAGE_DATA; 64 | default: 65 | throw new RuntimeException("Unknown enum value: " + value); 66 | } 67 | } 68 | 69 | static void encode(XdrDataOutputStream stream, OperationType value) throws IOException { 70 | stream.writeInt(value.getValue()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/CreateAccountResultCode.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // enum CreateAccountResultCode 12 | // { 13 | // // codes considered as "success" for the operation 14 | // CREATE_ACCOUNT_SUCCESS = 0, // account was created 15 | // 16 | // // codes considered as "failure" for the operation 17 | // CREATE_ACCOUNT_MALFORMED = -1, // invalid destination 18 | // CREATE_ACCOUNT_UNDERFUNDED = -2, // not enough funds in source account 19 | // CREATE_ACCOUNT_LOW_RESERVE = 20 | // -3, // would create an account below the min reserve 21 | // CREATE_ACCOUNT_ALREADY_EXIST = -4 // account already exists 22 | // }; 23 | 24 | // =========================================================================== 25 | public enum CreateAccountResultCode { 26 | CREATE_ACCOUNT_SUCCESS(0), 27 | CREATE_ACCOUNT_MALFORMED(-1), 28 | CREATE_ACCOUNT_UNDERFUNDED(-2), 29 | CREATE_ACCOUNT_LOW_RESERVE(-3), 30 | CREATE_ACCOUNT_ALREADY_EXIST(-4), 31 | ; 32 | private int mValue; 33 | 34 | CreateAccountResultCode(int value) { 35 | mValue = value; 36 | } 37 | 38 | public int getValue() { 39 | return mValue; 40 | } 41 | 42 | static CreateAccountResultCode decode(XdrDataInputStream stream) throws IOException { 43 | int value = stream.readInt(); 44 | switch (value) { 45 | case 0: return CREATE_ACCOUNT_SUCCESS; 46 | case -1: return CREATE_ACCOUNT_MALFORMED; 47 | case -2: return CREATE_ACCOUNT_UNDERFUNDED; 48 | case -3: return CREATE_ACCOUNT_LOW_RESERVE; 49 | case -4: return CREATE_ACCOUNT_ALREADY_EXIST; 50 | default: 51 | throw new RuntimeException("Unknown enum value: " + value); 52 | } 53 | } 54 | 55 | static void encode(XdrDataOutputStream stream, CreateAccountResultCode value) throws IOException { 56 | stream.writeInt(value.getValue()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/federation/Federation.java: -------------------------------------------------------------------------------- 1 | package org.stellar.sdk.federation; 2 | 3 | /** 4 | * Helper class for resolving Stellar addresses. 5 | * 6 | * @see Federation docs 7 | */ 8 | public class Federation { 9 | private Federation() { 10 | } 11 | 12 | /** 13 | * This method is a helper method for handling user inputs that contain `destination` value. 14 | * It accepts two types of values: 15 | *
    16 | *
  • For Stellar address (ex. bob*stellar.org`) it splits Stellar address and then tries to find information about 17 | * federation server in stellar.toml file for a given domain.
  • 18 | *
  • For account ID (ex. GB5XVAABEQMY63WTHDQ5RXADGYF345VWMNPTN2GFUDZT57D57ZQTJ7PS) it simply returns the 19 | * given Account ID.
  • 20 | *
21 | * @param value Stellar address or account id 22 | * @throws MalformedAddressException Address is malformed 23 | * @throws ConnectionErrorException Connection problems 24 | * @throws NoFederationServerException Stellar.toml does not contain federation server info 25 | * @throws FederationServerInvalidException Federation server is invalid (malformed URL, not HTTPS, etc.) 26 | * @throws StellarTomlNotFoundInvalidException Stellar.toml file was not found or was malformed. 27 | * @throws NotFoundException Stellar address not found by federation server 28 | * @throws ServerErrorException Federation server responded with error 29 | * @return FederationResponse 30 | */ 31 | public static FederationResponse resolve(String value) { 32 | String[] tokens = value.split("\\*"); 33 | if (tokens.length == 1) { 34 | // accountId 35 | return new FederationResponse(null, value, null, null); 36 | } else if (tokens.length == 2) { 37 | String domain = tokens[1]; 38 | FederationServer server = FederationServer.createForDomain(domain); 39 | return server.resolveAddress(value); 40 | } else { 41 | throw new MalformedAddressException(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/ManageOfferResult.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // union ManageOfferResult switch (ManageOfferResultCode code) 12 | // { 13 | // case MANAGE_OFFER_SUCCESS: 14 | // ManageOfferSuccessResult success; 15 | // default: 16 | // void; 17 | // }; 18 | 19 | // =========================================================================== 20 | public class ManageOfferResult { 21 | public ManageOfferResult () {} 22 | ManageOfferResultCode code; 23 | public ManageOfferResultCode getDiscriminant() { 24 | return this.code; 25 | } 26 | public void setDiscriminant(ManageOfferResultCode value) { 27 | this.code = value; 28 | } 29 | private ManageOfferSuccessResult success; 30 | public ManageOfferSuccessResult getSuccess() { 31 | return this.success; 32 | } 33 | public void setSuccess(ManageOfferSuccessResult value) { 34 | this.success = value; 35 | } 36 | public static void encode(XdrDataOutputStream stream, ManageOfferResult encodedManageOfferResult) throws IOException { 37 | stream.writeInt(encodedManageOfferResult.getDiscriminant().getValue()); 38 | switch (encodedManageOfferResult.getDiscriminant()) { 39 | case MANAGE_OFFER_SUCCESS: 40 | ManageOfferSuccessResult.encode(stream, encodedManageOfferResult.success); 41 | break; 42 | default: 43 | break; 44 | } 45 | } 46 | public static ManageOfferResult decode(XdrDataInputStream stream) throws IOException { 47 | ManageOfferResult decodedManageOfferResult = new ManageOfferResult(); 48 | ManageOfferResultCode discriminant = ManageOfferResultCode.decode(stream); 49 | decodedManageOfferResult.setDiscriminant(discriminant); 50 | switch (decodedManageOfferResult.getDiscriminant()) { 51 | case MANAGE_OFFER_SUCCESS: 52 | decodedManageOfferResult.success = ManageOfferSuccessResult.decode(stream); 53 | break; 54 | default: 55 | break; 56 | } 57 | return decodedManageOfferResult; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/stellar/sdk/xdr/SCPHistoryEntryV0.java: -------------------------------------------------------------------------------- 1 | // Automatically generated by xdrgen 2 | // DO NOT EDIT or your changes may be overwritten 3 | 4 | package org.stellar.sdk.xdr; 5 | 6 | 7 | import java.io.IOException; 8 | 9 | // === xdr source ============================================================ 10 | 11 | // struct SCPHistoryEntryV0 12 | // { 13 | // SCPQuorumSet quorumSets<>; // additional quorum sets used by ledgerMessages 14 | // LedgerSCPMessages ledgerMessages; 15 | // }; 16 | 17 | // =========================================================================== 18 | public class SCPHistoryEntryV0 { 19 | public SCPHistoryEntryV0 () {} 20 | private SCPQuorumSet[] quorumSets; 21 | public SCPQuorumSet[] getQuorumSets() { 22 | return this.quorumSets; 23 | } 24 | public void setQuorumSets(SCPQuorumSet[] value) { 25 | this.quorumSets = value; 26 | } 27 | private LedgerSCPMessages ledgerMessages; 28 | public LedgerSCPMessages getLedgerMessages() { 29 | return this.ledgerMessages; 30 | } 31 | public void setLedgerMessages(LedgerSCPMessages value) { 32 | this.ledgerMessages = value; 33 | } 34 | public static void encode(XdrDataOutputStream stream, SCPHistoryEntryV0 encodedSCPHistoryEntryV0) throws IOException{ 35 | int quorumSetssize = encodedSCPHistoryEntryV0.getQuorumSets().length; 36 | stream.writeInt(quorumSetssize); 37 | for (int i = 0; i < quorumSetssize; i++) { 38 | SCPQuorumSet.encode(stream, encodedSCPHistoryEntryV0.quorumSets[i]); 39 | } 40 | LedgerSCPMessages.encode(stream, encodedSCPHistoryEntryV0.ledgerMessages); 41 | } 42 | public static SCPHistoryEntryV0 decode(XdrDataInputStream stream) throws IOException { 43 | SCPHistoryEntryV0 decodedSCPHistoryEntryV0 = new SCPHistoryEntryV0(); 44 | int quorumSetssize = stream.readInt(); 45 | decodedSCPHistoryEntryV0.quorumSets = new SCPQuorumSet[quorumSetssize]; 46 | for (int i = 0; i < quorumSetssize; i++) { 47 | decodedSCPHistoryEntryV0.quorumSets[i] = SCPQuorumSet.decode(stream); 48 | } 49 | decodedSCPHistoryEntryV0.ledgerMessages = LedgerSCPMessages.decode(stream); 50 | return decodedSCPHistoryEntryV0; 51 | } 52 | } 53 | --------------------------------------------------------------------------------