stream method.
5 | */
6 | public interface EventListenerTimeBounds 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 theenum 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 | [](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 PageReturns 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 | * 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.GB5XVAABEQMY63WTHDQ5RXADGYF345VWMNPTN2GFUDZT57D57ZQTJ7PS) it simply returns the
19 | * given Account ID.