Skip to content

Commit

Permalink
Merge pull request #19 from stellar/merge-base-sdk
Browse files Browse the repository at this point in the history
Merge java-stellar-base into java-stellar-sdk
  • Loading branch information
bartekn committed Feb 17, 2016
2 parents 5f4d188 + 3f28506 commit d148de3
Show file tree
Hide file tree
Showing 244 changed files with 13,233 additions and 1,036 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ repositories {
}

dependencies {
compile 'commons-codec:commons-codec:1.5'
compile 'org.apache.httpcomponents:httpclient:4.5.1'
compile 'org.apache.httpcomponents:fluent-hc:4.5.1'
compile 'com.moandjiezana.toml:toml4j:0.5.1'
Expand Down
Binary file added libs/net.i2p.crypto-4.0.0.jar
Binary file not shown.
Binary file removed libs/stellar-base.jar
Binary file not shown.
260 changes: 21 additions & 239 deletions src/main/java/org/stellar/sdk/Account.java
Original file line number Diff line number Diff line change
@@ -1,262 +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("limit")
private final String limit;
@SerializedName("balance")
private final String balance;

Balance(String assetType, String assetCode, String assetIssuer, String balance, String limit) {
this.assetType = checkNotNull(assetType, "assertType cannot be null");
this.balance = checkNotNull(balance, "balance cannot be null");
this.limit = limit;
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 String getLimit() {
return limit;
}
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++;
}
}
80 changes: 80 additions & 0 deletions src/main/java/org/stellar/sdk/AccountMergeOperation.java
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;
}
}
}
Loading

0 comments on commit d148de3

Please sign in to comment.