mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
offer_make / cancel works (some things still hardcoded)
This commit is contained in:
parent
50a185bcd8
commit
5ce77ebc3f
12 changed files with 134 additions and 44 deletions
|
@ -3,19 +3,26 @@ package io.bitsquare.api;
|
|||
import com.google.common.base.Strings;
|
||||
import com.google.inject.Inject;
|
||||
import io.bitsquare.api.api.*;
|
||||
import io.bitsquare.api.api.Currency;
|
||||
import io.bitsquare.btc.WalletService;
|
||||
import io.bitsquare.btc.pricefeed.PriceFeedService;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.locale.CurrencyUtil;
|
||||
import io.bitsquare.p2p.NodeAddress;
|
||||
import io.bitsquare.p2p.P2PService;
|
||||
import io.bitsquare.payment.CryptoCurrencyAccount;
|
||||
import io.bitsquare.trade.TradeManager;
|
||||
import io.bitsquare.trade.offer.Offer;
|
||||
import io.bitsquare.trade.offer.OfferBookService;
|
||||
import io.bitsquare.user.User;
|
||||
import jersey.repackaged.com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.core.Transaction;
|
||||
import org.bitcoinj.core.Wallet;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -33,12 +40,21 @@ public class BitsquareProxy {
|
|||
private TradeManager tradeManager;
|
||||
@Inject
|
||||
private OfferBookService offerBookService;
|
||||
@Inject
|
||||
private P2PService p2PService;
|
||||
@Inject
|
||||
private KeyRing keyRing;
|
||||
@Inject
|
||||
private PriceFeedService priceFeedService;
|
||||
|
||||
public BitsquareProxy(WalletService walletService, TradeManager tradeManager, OfferBookService offerBookService,
|
||||
User user) {
|
||||
P2PService p2PService, KeyRing keyRing, PriceFeedService priceFeedService, User user) {
|
||||
this.walletService = walletService;
|
||||
this.tradeManager = tradeManager;
|
||||
this.offerBookService = offerBookService;
|
||||
this.p2PService = p2PService;
|
||||
this.keyRing = keyRing;
|
||||
this.priceFeedService = priceFeedService;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
|
@ -62,26 +78,6 @@ public class BitsquareProxy {
|
|||
return marketList;
|
||||
}
|
||||
|
||||
public WalletDetails getWalletDetails() {
|
||||
Wallet wallet = walletService.getWallet();
|
||||
if (wallet == null) {
|
||||
return null;
|
||||
}
|
||||
Coin availableBalance = wallet.getBalance(Wallet.BalanceType.AVAILABLE);
|
||||
Coin reservedBalance = wallet.getBalance(Wallet.BalanceType.ESTIMATED_SPENDABLE);
|
||||
return new WalletDetails(availableBalance.longValue(), reservedBalance.longValue());
|
||||
}
|
||||
|
||||
// public WalletTransactions getWalletTransactions(long start, long end, long limit) {
|
||||
// boolean includeDeadTransactions = false;
|
||||
// Set<org.bitcoinj.core.Transaction> transactions = walletService.getWallet().getTransactions(includeDeadTransactions);
|
||||
// WalletTransactions walletTransactions = new WalletTransactions();
|
||||
// List<io.bitsquare.api.api.WalletTransaction> transactionList = walletTransactions.getTransactions();
|
||||
//
|
||||
// for (Transaction t : transactions) {
|
||||
// transactionList.add(new io.bitsquare.api.api.WalletTransaction(t.getValue(walletService.getWallet().getTransactionsByTime())))
|
||||
// }
|
||||
// }
|
||||
|
||||
public AccountList getAccountList() {
|
||||
AccountList accountList = new AccountList();
|
||||
|
@ -99,7 +95,7 @@ public class BitsquareProxy {
|
|||
return false;
|
||||
}
|
||||
// do something more intelligent here, maybe block till handler is called.
|
||||
offerBookService.removeOffer(offer.get(), () -> log.info("offer removed"), (err) -> log.error("Error removing offer" + err));
|
||||
offerBookService.removeOffer(offer.get(), () -> log.info("offer removed"), (err) -> log.error("Error removing offer: " + err));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -119,8 +115,60 @@ public class BitsquareProxy {
|
|||
return offer;
|
||||
|
||||
}
|
||||
public void offerMake() {
|
||||
// offerbookservice. public void addOffer(Offer offer, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
|
||||
|
||||
public void offerMake(String market, String accountId, String direction, BigDecimal amount, BigDecimal minAmount,
|
||||
String fixed, String price) {
|
||||
// TODO: detect bad direction, bad market, no paymentaccount for user
|
||||
|
||||
Offer offer = new Offer(UUID.randomUUID().toString(),
|
||||
p2PService.getAddress(),
|
||||
keyRing.getPubKeyRing(),
|
||||
Offer.Direction.valueOf(direction),
|
||||
Long.valueOf(price),
|
||||
1, //marketPriceMarginParam,
|
||||
true, //useMarketBasedPrice.get(),
|
||||
amount.longValueExact(),
|
||||
minAmount.longValueExact(),
|
||||
"MR", // currencycode
|
||||
(ArrayList<NodeAddress>) user.getAcceptedArbitratorAddresses(),
|
||||
getAccountList().getPaymentAccounts().stream().findAny().get().getPayment_method().toString(), //paymentAccount.getPaymentMethod().getId(),
|
||||
getAccountList().getPaymentAccounts().stream().findAny().get().getAccount_id(), //paymentAccount.getId(),
|
||||
null, //countryCode,
|
||||
null, //acceptedCountryCodes,
|
||||
null, //bankId,
|
||||
null, // acceptedBanks,
|
||||
priceFeedService); // priceFeedService);
|
||||
|
||||
offerBookService.addOffer(offer, () -> log.info("offer removed"), (err) -> log.error("Error removing offer: " + err));
|
||||
}
|
||||
|
||||
public WalletDetails getWalletDetails() {
|
||||
Wallet wallet = walletService.getWallet();
|
||||
if (wallet == null) {
|
||||
return null;
|
||||
}
|
||||
Coin availableBalance = wallet.getBalance(Wallet.BalanceType.AVAILABLE);
|
||||
Coin reservedBalance = wallet.getBalance(Wallet.BalanceType.ESTIMATED_SPENDABLE);
|
||||
return new WalletDetails(availableBalance.toPlainString(), reservedBalance.toPlainString());
|
||||
}
|
||||
|
||||
public WalletTransactions getWalletTransactions(long start, long end, long limit) {
|
||||
boolean includeDeadTransactions = false;
|
||||
Set<Transaction> transactions = walletService.getWallet().getTransactions(includeDeadTransactions);
|
||||
WalletTransactions walletTransactions = new WalletTransactions();
|
||||
List<io.bitsquare.api.api.WalletTransaction> transactionList = walletTransactions.getTransactions();
|
||||
|
||||
for (Transaction t : transactions) {
|
||||
// transactionList.add(new io.bitsquare.api.api.WalletTransaction(t.getValue(walletService.getWallet().getTransactionsByTime())))
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<WalletAddress> getWalletAddresses() {
|
||||
return user.getPaymentAccounts().stream()
|
||||
.filter(paymentAccount -> paymentAccount instanceof CryptoCurrencyAccount)
|
||||
.map(paymentAccount -> (CryptoCurrencyAccount) paymentAccount)
|
||||
.map(paymentAccount -> new WalletAddress(((CryptoCurrencyAccount) paymentAccount).getId(), paymentAccount.getPaymentMethod().toString(), ((CryptoCurrencyAccount) paymentAccount).getAddress()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.locale.TradeCurrency;
|
||||
import io.bitsquare.payment.PaymentAccount;
|
||||
import lombok.Data;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -64,9 +65,10 @@ import java.util.stream.Collectors;
|
|||
* ]
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
@Data
|
||||
public class Account {
|
||||
@JsonProperty
|
||||
String account_id;
|
||||
public String account_id;
|
||||
@JsonProperty
|
||||
long created;
|
||||
@JsonProperty
|
||||
|
|
14
api/src/main/java/io/bitsquare/api/api/WalletAddress.java
Normal file
14
api/src/main/java/io/bitsquare/api/api/WalletAddress.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package io.bitsquare.api.api;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class WalletAddress {
|
||||
@JsonProperty
|
||||
private String id;
|
||||
@JsonProperty
|
||||
private String paymentMethod;
|
||||
@JsonProperty
|
||||
private String address;
|
||||
}
|
|
@ -7,9 +7,9 @@ import lombok.Setter;
|
|||
@AllArgsConstructor
|
||||
public class WalletDetails {
|
||||
@JsonProperty
|
||||
private long available_balance;
|
||||
private String available_balance;
|
||||
@JsonProperty
|
||||
private long reserved_balance;
|
||||
private String reserved_balance;
|
||||
// @JsonProperty
|
||||
// private long locked_balance;
|
||||
}
|
||||
|
|
|
@ -38,8 +38,7 @@ public class Api {
|
|||
private final WalletService walletService;
|
||||
private final ApiModule apiModule;
|
||||
private final User user;
|
||||
|
||||
private P2PService p2pService;
|
||||
private final P2PService p2pService;
|
||||
|
||||
public static void setEnvironment(Environment env) {
|
||||
Api.env = env;
|
||||
|
|
|
@ -3,7 +3,6 @@ package io.bitsquare.api.service;
|
|||
import com.codahale.metrics.annotation.Timed;
|
||||
import io.bitsquare.api.BitsquareProxy;
|
||||
import io.bitsquare.api.api.*;
|
||||
import io.bitsquare.trade.offer.OfferBookService;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
@ -22,7 +21,7 @@ public class ApiResource {
|
|||
private final MarketList marketList;
|
||||
private final BitsquareProxy bitsquareProxy;
|
||||
// "0x7fffffff";
|
||||
private static final String STRING_END_MAX_VALUE = "2147483647";
|
||||
private static final String STRING_END_INT_MAX_VALUE = "2147483647";
|
||||
|
||||
public ApiResource(String template, String defaultName, BitsquareProxy bitsquareProxy) {
|
||||
this.template = template;
|
||||
|
@ -86,7 +85,7 @@ public class ApiResource {
|
|||
|
||||
}
|
||||
|
||||
@GET
|
||||
@DELETE
|
||||
@Timed
|
||||
@Path("/offer_detail")
|
||||
public OfferData offerDetail(@QueryParam("offer_id") String offerId) {
|
||||
|
@ -140,7 +139,7 @@ public class ApiResource {
|
|||
@QueryParam("min_amount") BigDecimal minAmount,
|
||||
@DefaultValue("fixed") @QueryParam("price_type") String fixed,
|
||||
@DefaultValue("100") @QueryParam("price") String price) {
|
||||
return;
|
||||
bitsquareProxy.offerMake(market, accountId, direction, amount, minAmount, fixed, price);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -187,6 +186,22 @@ public class ApiResource {
|
|||
return bitsquareProxy.getWalletDetails();
|
||||
}
|
||||
|
||||
/**
|
||||
* param type desc required values default
|
||||
* status string filter by wether each address has a non-zero balance or not funded | unfunded | both both
|
||||
* start int starting index, zero based 0
|
||||
* limit int max number of addresses to return. 100
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@Timed
|
||||
@Path("/wallet_addresses")
|
||||
public List<WalletAddress> walletAddresses(@DefaultValue("BOTH") @QueryParam("status") String status,
|
||||
@DefaultValue("0") @QueryParam("start") Integer start,
|
||||
@DefaultValue("100") @QueryParam("limit") Integer limit) {
|
||||
return bitsquareProxy.getWalletAddresses();
|
||||
}
|
||||
|
||||
/**
|
||||
* wallet_tx_list
|
||||
|
||||
|
@ -211,7 +226,7 @@ public class ApiResource {
|
|||
@Timed
|
||||
@Path("/wallet_tx_list")
|
||||
public WalletTransactions walletTransactionList(@DefaultValue("0") @QueryParam("start") Integer start,
|
||||
@DefaultValue(STRING_END_MAX_VALUE) @QueryParam("end") Integer end,
|
||||
@DefaultValue(STRING_END_INT_MAX_VALUE) @QueryParam("end") Integer end,
|
||||
@DefaultValue("100") @QueryParam("start") Integer limit
|
||||
) {
|
||||
// return bitsquareProxy.getWalletTransactions(start, end, limit);
|
||||
|
|
|
@ -3,6 +3,9 @@ package io.bitsquare.api.service;
|
|||
import com.google.inject.Inject;
|
||||
import io.bitsquare.api.BitsquareProxy;
|
||||
import io.bitsquare.btc.WalletService;
|
||||
import io.bitsquare.btc.pricefeed.PriceFeedService;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.p2p.P2PService;
|
||||
import io.bitsquare.trade.TradeManager;
|
||||
import io.bitsquare.trade.offer.OfferBookService;
|
||||
import io.bitsquare.user.User;
|
||||
|
@ -21,6 +24,15 @@ public class DropwizardApplication extends Application<ApiConfiguration> {
|
|||
@Inject
|
||||
OfferBookService offerBookService;
|
||||
|
||||
@Inject
|
||||
P2PService p2PService;
|
||||
|
||||
@Inject
|
||||
KeyRing keyRing;
|
||||
|
||||
@Inject
|
||||
PriceFeedService priceFeedService;
|
||||
|
||||
@Inject
|
||||
User user;
|
||||
|
||||
|
@ -43,7 +55,8 @@ public class DropwizardApplication extends Application<ApiConfiguration> {
|
|||
public void run(ApiConfiguration configuration,
|
||||
Environment environment) {
|
||||
// environment.getObjectMapper().configure(SerializationFeature.WRAP_ROOT_VALUE, false);
|
||||
BitsquareProxy bitsquareProxy = new BitsquareProxy(walletService, tradeManager, offerBookService, user);
|
||||
BitsquareProxy bitsquareProxy = new BitsquareProxy(walletService, tradeManager, offerBookService,
|
||||
p2PService, keyRing, priceFeedService, user);
|
||||
final ApiResource resource = new ApiResource(
|
||||
configuration.getTemplate(),
|
||||
configuration.getDefaultName(),
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
<artifactId>network</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sf.jopt-simple</groupId>
|
||||
<artifactId>jopt-simple</artifactId>
|
||||
|
|
|
@ -84,7 +84,8 @@ public class ArbitratorManager {
|
|||
"03df837a3a0f3d858e82f3356b71d1285327f101f7c10b404abed2abc1c94e7169",
|
||||
"0203a90fb2ab698e524a5286f317a183a84327b8f8c3f7fa4a98fec9e1cefd6b72",
|
||||
"023c99cc073b851c892d8c43329ca3beb5d2213ee87111af49884e3ce66cbd5ba5",
|
||||
"0274f772a98d23e7a0251ab30d7121897b5aebd11a2f1e45ab654aa57503173245"
|
||||
"0274f772a98d23e7a0251ab30d7121897b5aebd11a2f1e45ab654aa57503173245",
|
||||
"027a381b5333a56e1cc3d90d3a7d07f26509adf7029ed06fc997c656621f8da1ee"
|
||||
));
|
||||
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ public class BitsquareApp extends Application {
|
|||
bitsquareAppModule = new BitsquareAppModule(env, primaryStage);
|
||||
injector = Guice.createInjector(bitsquareAppModule);
|
||||
injector.getInstance(InjectorViewFactory.class).setInjector(injector);
|
||||
injector.getInstance(DropwizardApplication.class).run("server", "bitsquare-api.yml");
|
||||
// injector.getInstance(DropwizardApplication.class).run("server", "bitsquare-api.yml");
|
||||
|
||||
Version.setBtcNetworkId(injector.getInstance(BitsquareEnvironment.class).getBitcoinNetwork().ordinal());
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ class BitsquareAppModule extends AppModule {
|
|||
install(guiModule());
|
||||
install(alertModule());
|
||||
install(filterModule());
|
||||
install(apiModule());
|
||||
// install(apiModule());
|
||||
}
|
||||
|
||||
private TradeModule tradeModule() {
|
||||
|
|
3
pom.xml
3
pom.xml
|
@ -155,14 +155,13 @@
|
|||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.10</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--logging-->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.12</version>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
|
|
Loading…
Add table
Reference in a new issue