-
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
81 changed files
with
2,128 additions
and
476 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
208 changes: 105 additions & 103 deletions
208
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,137 @@ | ||
package org.stellar.sdk; | ||
|
||
import org.stellar.sdk.xdr.CreatePassiveOfferOp; | ||
import org.stellar.sdk.xdr.CreatePassiveSellOfferOp; | ||
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 As the protocol is upgraded to version 11, CreatePassiveOffer has been renamed to CreatePassiveSellOffer, in order to avoid some unknown errors, please use {@link CreatePassiveSellOfferOperation} immediately. Will be removed in version 0.8.0. | ||
* Represents <a href="https://www.stellar.org/developers/learn/concepts/list-of-operations.html#create-passive-offer" target="_blank">CreatePassiveOffer</a> operation. | ||
*/ | ||
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; | ||
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"); | ||
} | ||
|
||
/** | ||
* Construct a new CreatePassiveOffer builder from a CreatePassiveOfferOp XDR. | ||
* @param op | ||
* The asset being sold in this operation | ||
*/ | ||
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(); | ||
public Asset getSelling() { | ||
return selling; | ||
} | ||
|
||
/** | ||
* 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. | ||
* The asset being bought in this operation | ||
*/ | ||
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"); | ||
public Asset getBuying() { | ||
return buying; | ||
} | ||
|
||
/** | ||
* Sets the source account for this operation. | ||
* @param sourceAccount The operation's source account. | ||
* @return Builder object so you can chain methods. | ||
* Amount of selling being sold. | ||
*/ | ||
public Builder setSourceAccount(KeyPair sourceAccount) { | ||
mSourceAccount = checkNotNull(sourceAccount, "sourceAccount cannot be null"); | ||
return this; | ||
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 an operation | ||
* Builds CreatePassiveOffer operation. | ||
* | ||
* @see CreatePassiveOfferOperation | ||
*/ | ||
public CreatePassiveOfferOperation build() { | ||
CreatePassiveOfferOperation operation = new CreatePassiveOfferOperation(selling, buying, amount, price); | ||
if (mSourceAccount != null) { | ||
operation.setSourceAccount(mSourceAccount); | ||
} | ||
return operation; | ||
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 CreatePassiveSellOfferOp 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 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; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.