-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for muxed accounts in Horizon responses (#350)
- Loading branch information
Showing
21 changed files
with
1,002 additions
and
235 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
24 changes: 24 additions & 0 deletions
24
src/main/java/org/stellar/sdk/responses/ImmutableListDeserializer.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.stellar.sdk.responses; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.reflect.TypeToken; | ||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParseException; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.List; | ||
|
||
public class ImmutableListDeserializer implements JsonDeserializer<ImmutableList<?>> { | ||
|
||
@Override | ||
public ImmutableList<?> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { | ||
@SuppressWarnings("unchecked") | ||
final TypeToken<ImmutableList<?>> immutableListToken = (TypeToken<ImmutableList<?>>) TypeToken.of(type); | ||
final TypeToken<? super ImmutableList<?>> listToken = immutableListToken.getSupertype(List.class); | ||
final List<?> list = context.deserialize(json, listToken.getType()); | ||
return ImmutableList.copyOf(list); | ||
} | ||
|
||
} |
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,43 @@ | ||
package org.stellar.sdk.responses; | ||
|
||
import com.google.common.base.Objects; | ||
|
||
public class MuxedAccount { | ||
private final String muxedAddress; | ||
private final String unmuxedAddress; | ||
private final Long id; | ||
|
||
public MuxedAccount(String muxedAddress, String unmuxedAddress, Long id) { | ||
this.muxedAddress = muxedAddress; | ||
this.unmuxedAddress = unmuxedAddress; | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return muxedAddress; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getUnmuxedAddress() { | ||
return unmuxedAddress; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
return (getClass() == o.getClass()) && Objects.equal(muxedAddress, ((MuxedAccount)o).muxedAddress) | ||
&& Objects.equal(unmuxedAddress, ((MuxedAccount)o).unmuxedAddress) | ||
&& Objects.equal(id, ((MuxedAccount)o).id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(muxedAddress, unmuxedAddress, id); | ||
} | ||
} |
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
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
Oops, something went wrong.