-
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.
- Loading branch information
Showing
15 changed files
with
576 additions
and
325 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
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
132 changes: 5 additions & 127 deletions
132
src/main/java/org/stellar/sdk/CreatePassiveOfferOperation.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,135 +1,13 @@ | ||
package org.stellar.sdk; | ||
|
||
import org.stellar.sdk.xdr.CreatePassiveOfferOp; | ||
import org.stellar.sdk.xdr.Int64; | ||
import org.stellar.sdk.xdr.OperationType; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.MathContext; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Represents <a href="https://www.stellar.org/developers/learn/concepts/list-of-operations.html#create-passive-offer" target="_blank">CreatePassiveOffer</a> operation. | ||
* @see <a href="https://www.stellar.org/developers/learn/concepts/list-of-operations.html" target="_blank">List of Operations</a> | ||
* @deprecated Use {@link CreatePassiveSellOfferOperation} | ||
*/ | ||
@Deprecated | ||
public class CreatePassiveOfferOperation extends Operation { | ||
private final Asset selling; | ||
private final Asset buying; | ||
private final String amount; | ||
private final String price; | ||
|
||
private CreatePassiveOfferOperation(Asset selling, Asset buying, String amount, String price) { | ||
this.selling = checkNotNull(selling, "selling cannot be null"); | ||
this.buying = checkNotNull(buying, "buying cannot be null"); | ||
this.amount = checkNotNull(amount, "amount cannot be null"); | ||
this.price = checkNotNull(price, "price cannot be null"); | ||
} | ||
|
||
/** | ||
* The asset being sold in this operation | ||
*/ | ||
public Asset getSelling() { | ||
return selling; | ||
} | ||
|
||
/** | ||
* The asset being bought in this operation | ||
*/ | ||
public Asset getBuying() { | ||
return buying; | ||
} | ||
|
||
/** | ||
* Amount of selling being sold. | ||
*/ | ||
public String getAmount() { | ||
return amount; | ||
} | ||
|
||
/** | ||
* Price of 1 unit of selling in terms of buying. | ||
*/ | ||
public String getPrice() { | ||
return price; | ||
} | ||
|
||
@Override | ||
org.stellar.sdk.xdr.Operation.OperationBody toOperationBody() { | ||
CreatePassiveOfferOp op = new CreatePassiveOfferOp(); | ||
op.setSelling(selling.toXdr()); | ||
op.setBuying(buying.toXdr()); | ||
Int64 amount = new Int64(); | ||
amount.setInt64(Operation.toXdrAmount(this.amount)); | ||
op.setAmount(amount); | ||
Price price = Price.fromString(this.price); | ||
op.setPrice(price.toXdr()); | ||
|
||
org.stellar.sdk.xdr.Operation.OperationBody body = new org.stellar.sdk.xdr.Operation.OperationBody(); | ||
body.setDiscriminant(OperationType.CREATE_PASSIVE_OFFER); | ||
body.setCreatePassiveOfferOp(op); | ||
|
||
return body; | ||
} | ||
|
||
/** | ||
* Builds CreatePassiveOffer operation. | ||
* @see CreatePassiveOfferOperation | ||
*/ | ||
public static class Builder { | ||
|
||
private final Asset selling; | ||
private final Asset buying; | ||
private final String amount; | ||
private final String price; | ||
|
||
private KeyPair mSourceAccount; | ||
|
||
/** | ||
* Construct a new CreatePassiveOffer builder from a CreatePassiveOfferOp XDR. | ||
* @param op | ||
*/ | ||
Builder(CreatePassiveOfferOp op) { | ||
selling = Asset.fromXdr(op.getSelling()); | ||
buying = Asset.fromXdr(op.getBuying()); | ||
amount = Operation.fromXdrAmount(op.getAmount().getInt64().longValue()); | ||
price = Price.fromXdr(op.getPrice()).toString(); | ||
} | ||
|
||
/** | ||
* Creates a new CreatePassiveOffer builder. | ||
* @param selling The asset being sold in this operation | ||
* @param buying The asset being bought in this operation | ||
* @param amount Amount of selling being sold. | ||
* @param price Price of 1 unit of selling in terms of buying. | ||
* @throws ArithmeticException when amount has more than 7 decimal places. | ||
*/ | ||
public Builder(Asset selling, Asset buying, String amount, String price) { | ||
this.selling = checkNotNull(selling, "selling cannot be null"); | ||
this.buying = checkNotNull(buying, "buying cannot be null"); | ||
this.amount = checkNotNull(amount, "amount cannot be null"); | ||
this.price = checkNotNull(price, "price cannot be null"); | ||
} | ||
|
||
/** | ||
* Sets the source account for this operation. | ||
* @param sourceAccount The operation's source account. | ||
* @return Builder object so you can chain methods. | ||
*/ | ||
public Builder setSourceAccount(KeyPair sourceAccount) { | ||
mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds an operation | ||
*/ | ||
public CreatePassiveOfferOperation build() { | ||
CreatePassiveOfferOperation operation = new CreatePassiveOfferOperation(selling, buying, amount, price); | ||
if (mSourceAccount != null) { | ||
operation.setSourceAccount(mSourceAccount); | ||
} | ||
return operation; | ||
@Override | ||
org.stellar.sdk.xdr.Operation.OperationBody toOperationBody() { | ||
return null; | ||
} | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
src/main/java/org/stellar/sdk/CreatePassiveSellOfferOperation.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,136 @@ | ||
package org.stellar.sdk; | ||
|
||
import org.stellar.sdk.xdr.CreatePassiveSellOfferOp; | ||
import org.stellar.sdk.xdr.Int64; | ||
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#create-passive-sell-offer" target="_blank">CreatePassiveSellOffer</a> operation. | ||
* @see <a href="https://www.stellar.org/developers/learn/concepts/list-of-operations.html" target="_blank">List of Operations</a> | ||
*/ | ||
public class CreatePassiveSellOfferOperation extends Operation { | ||
private final Asset selling; | ||
private final Asset buying; | ||
private final String amount; | ||
private final String price; | ||
|
||
private CreatePassiveSellOfferOperation(Asset selling, Asset buying, String amount, String price) { | ||
this.selling = checkNotNull(selling, "selling cannot be null"); | ||
this.buying = checkNotNull(buying, "buying cannot be null"); | ||
this.amount = checkNotNull(amount, "amount cannot be null"); | ||
this.price = checkNotNull(price, "price cannot be null"); | ||
} | ||
|
||
/** | ||
* The asset being sold in this operation | ||
*/ | ||
public Asset getSelling() { | ||
return selling; | ||
} | ||
|
||
/** | ||
* The asset being bought in this operation | ||
*/ | ||
public Asset getBuying() { | ||
return buying; | ||
} | ||
|
||
/** | ||
* Amount of selling being sold. | ||
*/ | ||
public String getAmount() { | ||
return amount; | ||
} | ||
|
||
/** | ||
* Price of 1 unit of selling in terms of buying. | ||
*/ | ||
public String getPrice() { | ||
return price; | ||
} | ||
|
||
@Override | ||
org.stellar.sdk.xdr.Operation.OperationBody toOperationBody() { | ||
CreatePassiveSellOfferOp op = new CreatePassiveSellOfferOp(); | ||
op.setSelling(selling.toXdr()); | ||
op.setBuying(buying.toXdr()); | ||
Int64 amount = new Int64(); | ||
amount.setInt64(Operation.toXdrAmount(this.amount)); | ||
op.setAmount(amount); | ||
Price price = Price.fromString(this.price); | ||
op.setPrice(price.toXdr()); | ||
|
||
org.stellar.sdk.xdr.Operation.OperationBody body = new org.stellar.sdk.xdr.Operation.OperationBody(); | ||
body.setDiscriminant(OperationType.CREATE_PASSIVE_SELL_OFFER); | ||
body.setCreatePassiveSellOfferOp(op); | ||
|
||
return body; | ||
} | ||
|
||
/** | ||
* Builds CreatePassiveSellOffer operation. | ||
* | ||
* @see CreatePassiveSellOfferOperation | ||
*/ | ||
public static class Builder { | ||
|
||
private final Asset selling; | ||
private final Asset buying; | ||
private final String amount; | ||
private final String price; | ||
|
||
private KeyPair mSourceAccount; | ||
|
||
/** | ||
* Construct a new CreatePassiveOffer builder from a CreatePassiveOfferOp XDR. | ||
* | ||
* @param op | ||
*/ | ||
Builder(CreatePassiveSellOfferOp op) { | ||
selling = Asset.fromXdr(op.getSelling()); | ||
buying = Asset.fromXdr(op.getBuying()); | ||
amount = Operation.fromXdrAmount(op.getAmount().getInt64().longValue()); | ||
price = Price.fromXdr(op.getPrice()).toString(); | ||
} | ||
|
||
/** | ||
* Creates a new CreatePassiveSellOffer builder. | ||
* | ||
* @param selling The asset being sold in this operation | ||
* @param buying The asset being bought in this operation | ||
* @param amount Amount of selling being sold. | ||
* @param price Price of 1 unit of selling in terms of buying. | ||
* @throws ArithmeticException when amount has more than 7 decimal places. | ||
*/ | ||
public Builder(Asset selling, Asset buying, String amount, String price) { | ||
this.selling = checkNotNull(selling, "selling cannot be null"); | ||
this.buying = checkNotNull(buying, "buying cannot be null"); | ||
this.amount = checkNotNull(amount, "amount cannot be null"); | ||
this.price = checkNotNull(price, "price cannot be null"); | ||
} | ||
|
||
/** | ||
* Sets the source account for this operation. | ||
* | ||
* @param sourceAccount The operation's source account. | ||
* @return Builder object so you can chain methods. | ||
*/ | ||
public CreatePassiveSellOfferOperation.Builder setSourceAccount(KeyPair sourceAccount) { | ||
mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds an operation | ||
*/ | ||
public CreatePassiveSellOfferOperation build() { | ||
CreatePassiveSellOfferOperation operation = new CreatePassiveSellOfferOperation(selling, buying, amount, price); | ||
if (mSourceAccount != null) { | ||
operation.setSourceAccount(mSourceAccount); | ||
} | ||
return operation; | ||
} | ||
} | ||
} |
Oops, something went wrong.