-
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.
Merge java-stellar-base into java-stellar-sdk
- Loading branch information
Showing
240 changed files
with
12,872 additions
and
656 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
Binary file not shown.
Binary file not shown.
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,255 +1,44 @@ | ||
package org.stellar.sdk; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
import org.stellar.base.KeyPair; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Represents account response. | ||
* @see <a href="https://www.stellar.org/developers/horizon/reference/resources/account.html" target="_blank">Account documentation</a> | ||
* @see org.stellar.sdk.requests.AccountsRequestBuilder | ||
* @see org.stellar.sdk.Server#accounts() | ||
* Represents an account in Stellar network with it's sequence number. | ||
* Account object is required to build a {@link Transaction}. | ||
* @see org.stellar.sdk.Transaction.Builder | ||
*/ | ||
public class Account implements org.stellar.base.TransactionBuilderAccount { | ||
@SerializedName("account_id") /* KeyPairTypeAdapter used */ | ||
private KeyPair keypair; | ||
@SerializedName("sequence") | ||
private Long sequenceNumber; | ||
@SerializedName("paging_token") | ||
private String pagingToken; | ||
@SerializedName("subentry_count") | ||
private Integer subentryCount; | ||
@SerializedName("inflation_destination") | ||
private String inflationDestination; | ||
@SerializedName("home_domain") | ||
private String homeDomain; | ||
@SerializedName("thresholds") | ||
private Thresholds thresholds; | ||
@SerializedName("flags") | ||
private Flags flags; | ||
@SerializedName("balances") | ||
private Balance[] balances; | ||
@SerializedName("signers") | ||
private Signer[] signers; | ||
@SerializedName("_links") | ||
private Links links; | ||
|
||
Account(KeyPair keypair) { | ||
this.keypair = keypair; | ||
} | ||
|
||
public Account(KeyPair keypair, Long sequenceNumber) { | ||
this.keypair = keypair; | ||
this.sequenceNumber = sequenceNumber; | ||
} | ||
|
||
@Override | ||
public KeyPair getKeypair() { | ||
return keypair; | ||
} | ||
|
||
@Override | ||
public Long getSequenceNumber() { | ||
return sequenceNumber; | ||
} | ||
|
||
@Override | ||
public void incrementSequenceNumber() { | ||
sequenceNumber++; | ||
} | ||
|
||
public String getPagingToken() { | ||
return pagingToken; | ||
} | ||
|
||
public Integer getSubentryCount() { | ||
return subentryCount; | ||
} | ||
|
||
public String getInflationDestination() { | ||
return inflationDestination; | ||
} | ||
|
||
public String getHomeDomain() { | ||
return homeDomain; | ||
} | ||
|
||
public Thresholds getThresholds() { | ||
return thresholds; | ||
} | ||
|
||
public Flags getFlags() { | ||
return flags; | ||
} | ||
|
||
public Balance[] getBalances() { | ||
return balances; | ||
} | ||
|
||
public Signer[] getSigners() { | ||
return signers; | ||
} | ||
public class Account implements TransactionBuilderAccount { | ||
private final KeyPair mKeyPair; | ||
private Long mSequenceNumber; | ||
|
||
/** | ||
* Represents account thresholds. | ||
* Class constructor. | ||
* @param keypair KeyPair associated with this Account | ||
* @param sequenceNumber Current sequence number of the account (can be obtained using java-stellar-sdk or horizon server) | ||
*/ | ||
public static class Thresholds { | ||
@SerializedName("low_threshold") | ||
private final int lowThreshold; | ||
@SerializedName("med_threshold") | ||
private final int medThreshold; | ||
@SerializedName("high_threshold") | ||
private final int highThreshold; | ||
|
||
Thresholds(int lowThreshold, int medThreshold, int highThreshold) { | ||
this.lowThreshold = lowThreshold; | ||
this.medThreshold = medThreshold; | ||
this.highThreshold = highThreshold; | ||
} | ||
|
||
public int getLowThreshold() { | ||
return lowThreshold; | ||
} | ||
|
||
public int getMedThreshold() { | ||
return medThreshold; | ||
} | ||
|
||
public int getHighThreshold() { | ||
return highThreshold; | ||
} | ||
} | ||
|
||
/** | ||
* Represents account flags. | ||
*/ | ||
public static class Flags { | ||
@SerializedName("auth_required") | ||
private final boolean authRequired; | ||
@SerializedName("auth_revocable") | ||
private final boolean authRevocable; | ||
|
||
Flags(boolean authRequired, boolean authRevocable) { | ||
this.authRequired = authRequired; | ||
this.authRevocable = authRevocable; | ||
} | ||
|
||
public boolean getAuthRequired() { | ||
return authRequired; | ||
} | ||
|
||
public boolean getAuthRevocable() { | ||
return authRevocable; | ||
} | ||
public Account(KeyPair keypair, Long sequenceNumber) { | ||
mKeyPair = checkNotNull(keypair, "keypair cannot be null"); | ||
mSequenceNumber = checkNotNull(sequenceNumber, "sequenceNumber cannot be null"); | ||
} | ||
|
||
/** | ||
* Represents account balance. | ||
* Returns keypair associated with this Account | ||
*/ | ||
public static class Balance { | ||
@SerializedName("asset_type") | ||
private final String assetType; | ||
@SerializedName("asset_code") | ||
private final String assetCode; | ||
@SerializedName("asset_issuer") | ||
private final String assetIssuer; | ||
@SerializedName("balance") | ||
private final String balance; | ||
|
||
Balance(String assetType, String assetCode, String assetIssuer, String balance) { | ||
this.assetType = checkNotNull(assetType, "assertType cannot be null"); | ||
this.balance = checkNotNull(balance, "balance cannot be null"); | ||
this.assetCode = assetCode; | ||
this.assetIssuer = assetIssuer; | ||
} | ||
|
||
public String getAssetType() { | ||
return assetType; | ||
} | ||
|
||
public String getAssetCode() { | ||
return assetCode; | ||
} | ||
|
||
public String getAssetIssuer() { | ||
return assetIssuer; | ||
} | ||
|
||
public String getBalance() { | ||
return balance; | ||
} | ||
public KeyPair getKeypair() { | ||
return mKeyPair; | ||
} | ||
|
||
/** | ||
* Represents account signers. | ||
* Returns current sequence number ot this Account. | ||
*/ | ||
public static class Signer { | ||
@SerializedName("public_key") | ||
private final String accountId; | ||
@SerializedName("weight") | ||
private final int weight; | ||
|
||
Signer(String accountId, int weight) { | ||
this.accountId = checkNotNull(accountId, "accountId cannot be null"); | ||
this.weight = checkNotNull(weight, "weight cannot be null"); | ||
} | ||
|
||
public String getAccountId() { | ||
return accountId; | ||
} | ||
|
||
public int getWeight() { | ||
return weight; | ||
} | ||
} | ||
|
||
public Links getLinks() { | ||
return links; | ||
public Long getSequenceNumber() { | ||
return mSequenceNumber; | ||
} | ||
|
||
/** | ||
* Links connected to account. | ||
* Increments sequence number in this object by one. | ||
*/ | ||
public static class Links { | ||
@SerializedName("effects") | ||
private final Link effects; | ||
@SerializedName("offers") | ||
private final Link offers; | ||
@SerializedName("operations") | ||
private final Link operations; | ||
@SerializedName("self") | ||
private final Link self; | ||
@SerializedName("transactions") | ||
private final Link transactions; | ||
|
||
Links(Link effects, Link offers, Link operations, Link self, Link transactions) { | ||
this.effects = effects; | ||
this.offers = offers; | ||
this.operations = operations; | ||
this.self = self; | ||
this.transactions = transactions; | ||
} | ||
|
||
public Link getEffects() { | ||
return effects; | ||
} | ||
|
||
public Link getOffers() { | ||
return offers; | ||
} | ||
|
||
public Link getOperations() { | ||
return operations; | ||
} | ||
|
||
public Link getSelf() { | ||
return self; | ||
} | ||
|
||
public Link getTransactions() { | ||
return transactions; | ||
} | ||
public void incrementSequenceNumber() { | ||
mSequenceNumber++; | ||
} | ||
} |
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,80 @@ | ||
package org.stellar.sdk; | ||
|
||
import org.stellar.sdk.xdr.AccountID; | ||
import org.stellar.sdk.xdr.Operation.OperationBody; | ||
import org.stellar.sdk.xdr.OperationType; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Represents <a href="https://www.stellar.org/developers/learn/concepts/list-of-operations.html#account-merge" target="_blank">AccountMerge</a> operation. | ||
* @see <a href="https://www.stellar.org/developers/learn/concepts/list-of-operations.html" target="_blank">List of Operations</a> | ||
*/ | ||
public class AccountMergeOperation extends Operation { | ||
|
||
private final KeyPair destination; | ||
|
||
private AccountMergeOperation(KeyPair destination) { | ||
this.destination = checkNotNull(destination, "destination cannot be null"); | ||
} | ||
|
||
/** | ||
* The account that receives the remaining XLM balance of the source account. | ||
*/ | ||
public KeyPair getDestination() { | ||
return destination; | ||
} | ||
|
||
@Override | ||
OperationBody toOperationBody() { | ||
OperationBody body = new org.stellar.sdk.xdr.Operation.OperationBody(); | ||
AccountID destination = new AccountID(); | ||
destination.setAccountID(this.destination.getXdrPublicKey()); | ||
body.setDestination(destination); | ||
body.setDiscriminant(OperationType.ACCOUNT_MERGE); | ||
return body; | ||
} | ||
|
||
/** | ||
* Builds AccountMerge operation. | ||
* @see AccountMergeOperation | ||
*/ | ||
public static class Builder { | ||
private final KeyPair destination; | ||
|
||
private KeyPair mSourceAccount; | ||
|
||
Builder(OperationBody op) { | ||
destination = KeyPair.fromXdrPublicKey(op.getDestination().getAccountID()); | ||
} | ||
|
||
/** | ||
* Creates a new AccountMerge builder. | ||
* @param destination The account that receives the remaining XLM balance of the source account. | ||
*/ | ||
public Builder(KeyPair destination) { | ||
this.destination = destination; | ||
} | ||
|
||
/** | ||
* Set source account of this operation | ||
* @param sourceAccount Source account | ||
* @return Builder object so you can chain methods. | ||
*/ | ||
public Builder setSourceAccount(KeyPair sourceAccount) { | ||
mSourceAccount = sourceAccount; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds an operation | ||
*/ | ||
public AccountMergeOperation build() { | ||
AccountMergeOperation operation = new AccountMergeOperation(destination); | ||
if (mSourceAccount != null) { | ||
operation.setSourceAccount(mSourceAccount); | ||
} | ||
return operation; | ||
} | ||
} | ||
} |
Oops, something went wrong.