Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparations for http api #2207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions core/src/main/java/bisq/core/CoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import bisq.core.app.AppOptionKeys;
import bisq.core.app.AvoidStandbyModeService;
import bisq.core.app.BisqEnvironment;
import bisq.core.app.BisqFacade;
import bisq.core.app.BisqSetup;
import bisq.core.app.P2PNetworkSetup;
import bisq.core.app.WalletAppSetup;
Expand Down Expand Up @@ -83,7 +82,6 @@ protected void configure() {
bind(BisqSetup.class).in(Singleton.class);
bind(P2PNetworkSetup.class).in(Singleton.class);
bind(WalletAppSetup.class).in(Singleton.class);
bind(BisqFacade.class).in(Singleton.class);

bind(BisqEnvironment.class).toInstance((BisqEnvironment) environment);

Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/bisq/core/app/BisqExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
import static java.lang.String.format;

@Slf4j
public abstract class BisqExecutable implements GracefulShutDownHandler {
public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSetup.BisqSetupCompleteListener {

private final String fullName;
private final String scriptName;
Expand Down Expand Up @@ -271,9 +271,12 @@ protected void onApplicationStarted() {

protected void startAppSetup() {
BisqSetup bisqSetup = injector.getInstance(BisqSetup.class);
bisqSetup.addBisqSetupCompleteListener(this);
bisqSetup.start();
}

public abstract void onSetupComplete();


///////////////////////////////////////////////////////////////////////////////////////////
// GracefulShutDownHandler implementation
Expand Down
53 changes: 0 additions & 53 deletions core/src/main/java/bisq/core/app/BisqFacade.java

This file was deleted.

6 changes: 6 additions & 0 deletions core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ protected void onApplicationLaunched() {
headlessApp.setGracefulShutDownHandler(this);
}

@Override
public void onSetupComplete() {
log.info("onSetupComplete");
}


///////////////////////////////////////////////////////////////////////////////////////////
// We continue with a series of synchronous execution tasks
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup,
this.formatter = formatter;
}


///////////////////////////////////////////////////////////////////////////////////////////
// Setup
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ protected void configUserThread() {
UserThread.setExecutor(Executors.newSingleThreadExecutor(threadFactory));
}

@Override
public void onSetupComplete() {
log.info("onSetupComplete");
}

// We don't use the gracefulShutDown implementation of the super class as we have a limited set of modules
@Override
public void gracefulShutDown(ResultHandler resultHandler) {
Expand Down
10 changes: 7 additions & 3 deletions core/src/main/java/bisq/core/btc/model/AddressEntryList.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ public static AddressEntryList fromProto(PB.AddressEntryList proto) {

@Override
public Message toProtoMessage() {
// We clone list as we got ConcurrentModificationExceptions
List<AddressEntry> clone = new ArrayList<>(list);
List<PB.AddressEntry> addressEntries = clone.stream()
.map(AddressEntry::toProtoMessage)
.collect(Collectors.toList());

return PB.PersistableEnvelope.newBuilder()
.setAddressEntryList(PB.AddressEntryList.newBuilder()
.addAllAddressEntry(list.stream()
.map(AddressEntry::toProtoMessage)
.collect(Collectors.toList())))
.addAllAddressEntry(addressEntries))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@

package bisq.core.btc.model;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nullable;

import static com.google.common.base.Preconditions.checkArgument;

public class InputsAndChangeOutput {
public final ArrayList<RawTransactionInput> rawTransactionInputs;
public final List<RawTransactionInput> rawTransactionInputs;

// Is set to 0L in case we don't have an output
public final long changeOutputValue;
@Nullable
public final String changeOutputAddress;

public InputsAndChangeOutput(ArrayList<RawTransactionInput> rawTransactionInputs, long changeOutputValue, @Nullable String changeOutputAddress) {
public InputsAndChangeOutput(List<RawTransactionInput> rawTransactionInputs, long changeOutputValue, @Nullable String changeOutputAddress) {
checkArgument(!rawTransactionInputs.isEmpty(), "rawInputs.isEmpty()");

this.rawTransactionInputs = rawTransactionInputs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public void onSuccess(Transaction transaction) {
// returned (tradeFeeTx would be null in that case)
UserThread.execute(() -> {
if (!completed) {
offer.setOfferFeePaymentTxId(tradeFeeTx.getHashAsString());
model.setTransaction(tradeFeeTx);
offer.setOfferFeePaymentTxId(transaction.getHashAsString());
model.setTransaction(transaction);
walletService.swapTradeEntryToAvailableEntry(id, AddressEntry.Context.OFFER_FUNDING);

model.getOffer().setState(Offer.State.OFFER_FEE_PAID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ protected void run() {
"maxTradePeriod must be positive. maxTradePeriod=" + offer.getMaxTradePeriod());
// TODO check upper and lower bounds for fiat
// TODO check rest of new parameters
// TODO check for account age witness base tradeLimit is missing

complete();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,14 @@ public long getMyAccountAge(PaymentAccountPayload paymentAccountPayload) {
}

public long getMyTradeLimit(PaymentAccount paymentAccount, String currencyCode) {
final Optional<AccountAgeWitness> witnessOptional = Optional.of(getMyWitness(paymentAccount.getPaymentAccountPayload()));
return getTradeLimit(paymentAccount.getPaymentMethod()
.getMaxTradeLimitAsCoin(currencyCode), currencyCode, witnessOptional, new Date());
if (paymentAccount == null)
return 0;

Optional<AccountAgeWitness> witnessOptional = Optional.of(getMyWitness(paymentAccount.getPaymentAccountPayload()));
return getTradeLimit(paymentAccount.getPaymentMethod().getMaxTradeLimitAsCoin(currencyCode),
currencyCode,
witnessOptional,
new Date());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import bisq.core.trade.Trade;
import bisq.core.trade.protocol.tasks.TradeTask;

import bisq.common.UserThread;
import bisq.common.taskrunner.TaskRunner;

import org.bitcoinj.core.Address;
Expand All @@ -41,7 +40,6 @@

@Slf4j
public class CreateTakerFeeTx extends TradeTask {
private Transaction tradeFeeTx;

@SuppressWarnings({"WeakerAccess", "unused"})
public CreateTakerFeeTx(TaskRunner taskHandler, Trade trade) {
Expand All @@ -65,7 +63,7 @@ protected void run() {
Address changeAddress = changeAddressEntry.getAddress();
final TradeWalletService tradeWalletService = processModel.getTradeWalletService();
if (trade.isCurrencyForTakerFeeBtc()) {
tradeFeeTx = tradeWalletService.createBtcTradingFeeTx(
tradeWalletService.createBtcTradingFeeTx(
fundingAddress,
reservedForTradeAddress,
changeAddress,
Expand All @@ -77,20 +75,15 @@ protected void run() {
new TxBroadcaster.Callback() {
@Override
public void onSuccess(Transaction transaction) {
// we delay one render frame to be sure we don't get called before the method call has
// returned (tradeFeeTx would be null in that case)
UserThread.execute(() -> {
if (!completed) {
processModel.setTakeOfferFeeTx(tradeFeeTx);
trade.setTakerFeeTxId(tradeFeeTx.getHashAsString());
walletService.swapTradeEntryToAvailableEntry(id, AddressEntry.Context.OFFER_FUNDING);
trade.setState(Trade.State.TAKER_PUBLISHED_TAKER_FEE_TX);

complete();
} else {
log.warn("We got the onSuccess callback called after the timeout has been triggered a complete().");
}
});
if (!completed) {
processModel.setTakeOfferFeeTx(transaction);
trade.setTakerFeeTxId(transaction.getHashAsString());
walletService.swapTradeEntryToAvailableEntry(id, AddressEntry.Context.OFFER_FUNDING);
trade.setState(Trade.State.TAKER_PUBLISHED_TAKER_FEE_TX);
complete();
} else {
log.warn("We got the onSuccess callback called after the timeout has been triggered a complete().");
}
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
*/
@Slf4j
@AllArgsConstructor
public final class User implements PersistedDataHost {
public class User implements PersistedDataHost {
final private Storage<UserPayload> storage;
final private KeyRing keyRing;

Expand Down
11 changes: 7 additions & 4 deletions desktop/src/main/java/bisq/desktop/app/BisqAppMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public static void main(String[] args) throws Exception {
}
}

@Override
public void onSetupComplete() {
log.debug("onSetupComplete");
}


///////////////////////////////////////////////////////////////////////////////////////////
// First synchronous execution tasks
Expand Down Expand Up @@ -131,13 +136,11 @@ protected void onApplicationStarted() {
super.onApplicationStarted();

/* if (runWithHttpApi()) {
final BisqFacade bisqFacade = injector.getInstance(BisqFacade.class);
bisqHttpApiServer = new BisqHttpApiServer(bisqFacade);
bisqHttpApiServer = new BisqHttpApiServer();
}*/
/*
if (runWithGrpcApi()) {
final BisqFacade bisqFacade = injector.getInstance(BisqFacade.class);
bisqGrpcServer = new BisqGrpcServer(bisqFacade);
bisqGrpcServer = new BisqGrpcServer();
}*/
}

Expand Down