-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #378 from stellar/374_change_trust_reponse_liquidi…
- Loading branch information
Showing
5 changed files
with
161 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.stellar.sdk; | ||
|
||
import com.google.common.base.Objects; | ||
|
||
/** | ||
* Represents Stellar liquidity pool share asset - <a href="https://developers.stellar.org/docs/glossary/liquidity-pool/#trustlines" target="_blank">lumens (XLM)</a> | ||
* @see <a href="https://developers.stellar.org/docs/glossary/liquidity-pool/#trustlines" target="_blank">Assets</a> | ||
*/ | ||
public final class AssetTypePoolShare extends Asset { | ||
|
||
private final String poolId; | ||
|
||
public AssetTypePoolShare(String poolId) { | ||
this.poolId = poolId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "liquidity_pool_shares"; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "liquidity_pool_shares"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (object == null || !this.getClass().equals(object.getClass())) { | ||
return false; | ||
} | ||
|
||
return (Objects.equal(((AssetTypePoolShare)object).getPoolId(), poolId)); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(poolId); | ||
} | ||
|
||
@Override | ||
public org.stellar.sdk.xdr.Asset toXdr() { | ||
throw new UnsupportedOperationException("liquidity_pool_shares are not defined as Asset in XDR"); | ||
} | ||
|
||
@Override | ||
public int compareTo(Asset other) { | ||
if (other == null || !this.getClass().equals(other.getClass())) { | ||
return -1; | ||
} | ||
|
||
AssetTypePoolShare otherPoolShare = (AssetTypePoolShare)other; | ||
|
||
if (poolId == null && otherPoolShare.getPoolId() == null) { | ||
return 0; | ||
} | ||
|
||
if (poolId == null) { | ||
return -1; | ||
} | ||
|
||
if (otherPoolShare.getPoolId() == null) { | ||
return 1; | ||
} | ||
|
||
return poolId.compareTo(otherPoolShare.getPoolId()); | ||
} | ||
|
||
public String getPoolId() { return poolId; } | ||
} |
24 changes: 15 additions & 9 deletions
24
src/main/java/org/stellar/sdk/responses/AssetDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,35 @@ | ||
package org.stellar.sdk.responses; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParseException; | ||
|
||
import org.stellar.sdk.Asset; | ||
import org.stellar.sdk.AssetTypeNative; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
import static com.google.common.base.Optional.fromNullable; | ||
|
||
class AssetDeserializer implements JsonDeserializer<Asset> { | ||
@Override | ||
public Asset deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | ||
if (!json.isJsonObject()) { | ||
// Probably a canonical string | ||
return Asset.create(json.getAsString()); | ||
} | ||
String type = json.getAsJsonObject().get("asset_type").getAsString(); | ||
if (type.equals("native")) { | ||
return new AssetTypeNative(); | ||
} else { | ||
String code = json.getAsJsonObject().get("asset_code").getAsString(); | ||
String issuer = json.getAsJsonObject().get("asset_issuer").getAsString(); | ||
return Asset.createNonNativeAsset(code, issuer); | ||
|
||
return Asset.create(json.getAsJsonObject().get("asset_type").getAsString(), | ||
fromNullable(json.getAsJsonObject().get("asset_code")).transform(ToString.FUNCTION).orNull(), | ||
fromNullable(json.getAsJsonObject().get("asset_issuer")).transform(ToString.FUNCTION).orNull(), | ||
fromNullable(json.getAsJsonObject().get("liquidity_pool_id")).transform(ToString.FUNCTION).orNull()); | ||
} | ||
|
||
enum ToString implements Function<JsonElement, String> { | ||
FUNCTION; | ||
@Override | ||
public String apply(JsonElement input) { | ||
return input.getAsString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters