forked from bisq-network/bisq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoreApi.java
407 lines (335 loc) · 14.8 KB
/
CoreApi.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.core.api;
import bisq.core.api.model.AddressBalanceInfo;
import bisq.core.api.model.BalancesInfo;
import bisq.core.api.model.TxFeeRateInfo;
import bisq.core.btc.wallet.TxBroadcaster;
import bisq.core.offer.Offer;
import bisq.core.offer.OpenOffer;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.trade.bisq_v1.TradeResultHandler;
import bisq.core.trade.model.bisq_v1.Trade;
import bisq.core.trade.model.bsq_swap.BsqSwapTrade;
import bisq.core.trade.statistics.TradeStatistics3;
import bisq.core.trade.statistics.TradeStatisticsManager;
import bisq.common.app.Version;
import bisq.common.config.Config;
import bisq.common.handlers.ErrorMessageHandler;
import bisq.common.handlers.ResultHandler;
import org.bitcoinj.core.Transaction;
import javax.inject.Inject;
import javax.inject.Singleton;
import com.google.common.util.concurrent.FutureCallback;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import static bisq.proto.grpc.EditOfferRequest.EditType;
/**
* Provides high level interface to functionality of core Bisq features.
* E.g. useful for different APIs to access data of different domains of Bisq.
*/
@Singleton
@Slf4j
public class CoreApi {
@Getter
private final Config config;
private final CoreDisputeAgentsService coreDisputeAgentsService;
private final CoreHelpService coreHelpService;
private final CoreOffersService coreOffersService;
private final CorePaymentAccountsService paymentAccountsService;
private final CorePriceService corePriceService;
private final CoreTradesService coreTradesService;
private final CoreWalletsService walletsService;
private final TradeStatisticsManager tradeStatisticsManager;
@Inject
public CoreApi(Config config,
CoreDisputeAgentsService coreDisputeAgentsService,
CoreHelpService coreHelpService,
CoreOffersService coreOffersService,
CorePaymentAccountsService paymentAccountsService,
CorePriceService corePriceService,
CoreTradesService coreTradesService,
CoreWalletsService walletsService,
TradeStatisticsManager tradeStatisticsManager) {
this.config = config;
this.coreDisputeAgentsService = coreDisputeAgentsService;
this.coreHelpService = coreHelpService;
this.coreOffersService = coreOffersService;
this.paymentAccountsService = paymentAccountsService;
this.coreTradesService = coreTradesService;
this.corePriceService = corePriceService;
this.walletsService = walletsService;
this.tradeStatisticsManager = tradeStatisticsManager;
}
@SuppressWarnings("SameReturnValue")
public String getVersion() {
return Version.VERSION;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Dispute Agents
///////////////////////////////////////////////////////////////////////////////////////////
public void registerDisputeAgent(String disputeAgentType, String registrationKey) {
coreDisputeAgentsService.registerDisputeAgent(disputeAgentType, registrationKey);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Help
///////////////////////////////////////////////////////////////////////////////////////////
public String getMethodHelp(String methodName) {
return coreHelpService.getMethodHelp(methodName);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Offers
///////////////////////////////////////////////////////////////////////////////////////////
public Offer getBsqSwapOffer(String id) {
return coreOffersService.getBsqSwapOffer(id);
}
public Offer getOffer(String id) {
return coreOffersService.getOffer(id);
}
public OpenOffer getMyOffer(String id) {
return coreOffersService.getMyOffer(id);
}
public Offer getMyBsqSwapOffer(String id) {
return coreOffersService.getMyBsqSwapOffer(id);
}
public List<Offer> getBsqSwapOffers(String direction) {
return coreOffersService.getBsqSwapOffers(direction);
}
public List<Offer> getOffers(String direction, String currencyCode) {
return coreOffersService.getOffers(direction, currencyCode);
}
public List<OpenOffer> getMyOffers(String direction, String currencyCode) {
return coreOffersService.getMyOffers(direction, currencyCode);
}
public List<Offer> getMyBsqSwapOffers(String direction) {
return coreOffersService.getMyBsqSwapOffers(direction);
}
public OpenOffer getMyOpenBsqSwapOffer(String id) {
return coreOffersService.getMyOpenBsqSwapOffer(id);
}
public void createAndPlaceBsqSwapOffer(String directionAsString,
long amountAsLong,
long minAmountAsLong,
String priceAsString,
Consumer<Offer> resultHandler) {
coreOffersService.createAndPlaceBsqSwapOffer(directionAsString,
amountAsLong,
minAmountAsLong,
priceAsString,
resultHandler);
}
public void createAndPlaceOffer(String currencyCode,
String directionAsString,
String priceAsString,
boolean useMarketBasedPrice,
double marketPriceMargin,
long amountAsLong,
long minAmountAsLong,
double buyerSecurityDeposit,
long triggerPrice,
String paymentAccountId,
String makerFeeCurrencyCode,
Consumer<Offer> resultHandler) {
coreOffersService.createAndPlaceOffer(currencyCode,
directionAsString,
priceAsString,
useMarketBasedPrice,
marketPriceMargin,
amountAsLong,
minAmountAsLong,
buyerSecurityDeposit,
triggerPrice,
paymentAccountId,
makerFeeCurrencyCode,
resultHandler);
}
public void editOffer(String offerId,
String priceAsString,
boolean useMarketBasedPrice,
double marketPriceMargin,
long triggerPrice,
int enable,
EditType editType) {
coreOffersService.editOffer(offerId,
priceAsString,
useMarketBasedPrice,
marketPriceMargin,
triggerPrice,
enable,
editType);
}
public void cancelOffer(String id) {
coreOffersService.cancelOffer(id);
}
public boolean isMyOffer(String id) {
return coreOffersService.isMyOffer(id);
}
///////////////////////////////////////////////////////////////////////////////////////////
// PaymentAccounts
///////////////////////////////////////////////////////////////////////////////////////////
public PaymentAccount createPaymentAccount(String jsonString) {
return paymentAccountsService.createPaymentAccount(jsonString);
}
public Set<PaymentAccount> getPaymentAccounts() {
return paymentAccountsService.getPaymentAccounts();
}
public List<PaymentMethod> getFiatPaymentMethods() {
return paymentAccountsService.getFiatPaymentMethods();
}
public String getPaymentAccountForm(String paymentMethodId) {
return paymentAccountsService.getPaymentAccountFormAsString(paymentMethodId);
}
public PaymentAccount createCryptoCurrencyPaymentAccount(String accountName,
String currencyCode,
String address,
boolean tradeInstant) {
return paymentAccountsService.createCryptoCurrencyPaymentAccount(accountName,
currencyCode,
address,
tradeInstant);
}
public List<PaymentMethod> getCryptoCurrencyPaymentMethods() {
return paymentAccountsService.getCryptoCurrencyPaymentMethods();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Prices
///////////////////////////////////////////////////////////////////////////////////////////
public void getMarketPrice(String currencyCode, Consumer<Double> resultHandler) {
corePriceService.getMarketPrice(currencyCode, resultHandler);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Trades
///////////////////////////////////////////////////////////////////////////////////////////
public void takeBsqSwapOffer(String offerId,
String paymentAccountId,
String takerFeeCurrencyCode,
TradeResultHandler<BsqSwapTrade> tradeResultHandler,
ErrorMessageHandler errorMessageHandler) {
Offer bsqSwapOffer = coreOffersService.getBsqSwapOffer(offerId);
coreTradesService.takeBsqSwapOffer(bsqSwapOffer,
paymentAccountId,
takerFeeCurrencyCode,
tradeResultHandler,
errorMessageHandler);
}
public void takeOffer(String offerId,
String paymentAccountId,
String takerFeeCurrencyCode,
Consumer<Trade> resultHandler,
ErrorMessageHandler errorMessageHandler) {
Offer offer = coreOffersService.getOffer(offerId);
coreTradesService.takeOffer(offer,
paymentAccountId,
takerFeeCurrencyCode,
resultHandler,
errorMessageHandler);
}
public void confirmPaymentStarted(String tradeId) {
coreTradesService.confirmPaymentStarted(tradeId);
}
public void confirmPaymentReceived(String tradeId) {
coreTradesService.confirmPaymentReceived(tradeId);
}
public void keepFunds(String tradeId) {
coreTradesService.keepFunds(tradeId);
}
public void withdrawFunds(String tradeId, String address, String memo) {
coreTradesService.withdrawFunds(tradeId, address, memo);
}
public BsqSwapTrade getBsqSwapTrade(String tradeId) {
return coreTradesService.getBsqSwapTrade(tradeId);
}
public Trade getTrade(String tradeId) {
return coreTradesService.getTrade(tradeId);
}
public String getTradeRole(String tradeId) {
return coreTradesService.getTradeRole(tradeId);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Wallets
///////////////////////////////////////////////////////////////////////////////////////////
public BalancesInfo getBalances(String currencyCode) {
return walletsService.getBalances(currencyCode);
}
public long getAddressBalance(String addressString) {
return walletsService.getAddressBalance(addressString);
}
public AddressBalanceInfo getAddressBalanceInfo(String addressString) {
return walletsService.getAddressBalanceInfo(addressString);
}
public List<AddressBalanceInfo> getFundingAddresses() {
return walletsService.getFundingAddresses();
}
public String getUnusedBsqAddress() {
return walletsService.getUnusedBsqAddress();
}
public void sendBsq(String address,
String amount,
String txFeeRate,
TxBroadcaster.Callback callback) {
walletsService.sendBsq(address, amount, txFeeRate, callback);
}
public void sendBtc(String address,
String amount,
String txFeeRate,
String memo,
FutureCallback<Transaction> callback) {
walletsService.sendBtc(address, amount, txFeeRate, memo, callback);
}
public boolean verifyBsqSentToAddress(String address, String amount) {
return walletsService.verifyBsqSentToAddress(address, amount);
}
public void getTxFeeRate(ResultHandler resultHandler) {
walletsService.getTxFeeRate(resultHandler);
}
public void setTxFeeRatePreference(long txFeeRate,
ResultHandler resultHandler) {
walletsService.setTxFeeRatePreference(txFeeRate, resultHandler);
}
public void unsetTxFeeRatePreference(ResultHandler resultHandler) {
walletsService.unsetTxFeeRatePreference(resultHandler);
}
public TxFeeRateInfo getMostRecentTxFeeRateInfo() {
return walletsService.getMostRecentTxFeeRateInfo();
}
public Transaction getTransaction(String txId) {
return walletsService.getTransaction(txId);
}
public void setWalletPassword(String password, String newPassword) {
walletsService.setWalletPassword(password, newPassword);
}
public void lockWallet() {
walletsService.lockWallet();
}
public void unlockWallet(String password, long timeout) {
walletsService.unlockWallet(password, timeout);
}
public void removeWalletPassword(String password) {
walletsService.removeWalletPassword(password);
}
public List<TradeStatistics3> getTradeStatistics() {
return new ArrayList<>(tradeStatisticsManager.getObservableTradeStatisticsSet());
}
public int getNumConfirmationsForMostRecentTransaction(String addressString) {
return walletsService.getNumConfirmationsForMostRecentTransaction(addressString);
}
}