This commit is contained in:
Manfred Karrer 2016-02-09 00:36:59 +01:00
parent 96090b71ad
commit 86284fe644
30 changed files with 135 additions and 115 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.bitsquare</groupId>
<version>0.3.4-SNAPSHOT</version>
<version>0.3.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -50,6 +50,4 @@ public class Tuple3<A, B, C> implements Serializable {
result = 31 * result + (third != null ? third.hashCode() : 0);
return result;
}
}

View File

@ -6,7 +6,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.bitsquare</groupId>
<version>0.3.4-SNAPSHOT</version>
<version>0.3.4</version>
</parent>
<artifactId>core</artifactId>
@ -52,6 +52,5 @@
<version>4.8</version>
</dependency>
</dependencies>
</project>

View File

@ -61,7 +61,7 @@ public class FeePolicy {
}
// Some wallets (Mycelium) don't support higher fees
public static Coin getMinFundingFee() {
public static Coin getMinRequiredFeeForFundingTx() {
return Coin.valueOf(20_000);
}

View File

@ -4,10 +4,14 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.SettableFuture;
import com.google.inject.Inject;
import io.bitsquare.app.Log;
import io.bitsquare.btc.BitcoinNetwork;
import io.bitsquare.btc.FeePolicy;
import io.bitsquare.btc.blockchain.providers.BlockTrailProvider;
import io.bitsquare.btc.blockchain.providers.BlockchainApiProvider;
import io.bitsquare.btc.blockchain.providers.BlockrIOProvider;
import io.bitsquare.btc.blockchain.providers.TradeBlockProvider;
import io.bitsquare.user.Preferences;
import org.bitcoinj.core.Coin;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
@ -20,34 +24,47 @@ public class BlockchainService {
private static final Logger log = LoggerFactory.getLogger(BlockchainService.class);
private final ArrayList<BlockchainApiProvider> providers;
private final boolean isMainNet;
@Inject
public BlockchainService(Preferences preferences) {
isMainNet = preferences.getBitcoinNetwork() == BitcoinNetwork.MAINNET;
providers = new ArrayList<>(Arrays.asList(new BlockrIOProvider(), new BlockTrailProvider(), new TradeBlockProvider()));
}
public BlockchainService() {
isMainNet = false;
providers = new ArrayList<>(Arrays.asList(new BlockrIOProvider(), new BlockTrailProvider(), new TradeBlockProvider()));
}
public SettableFuture<Coin> requestFeeFromBlockchain(String transactionId) {
log.debug("Request fee from providers");
Log.traceCall(transactionId);
long startTime = System.currentTimeMillis();
final SettableFuture<Coin> resultFuture = SettableFuture.create();
for (BlockchainApiProvider provider : providers) {
GetFeeRequest getFeeRequest = new GetFeeRequest();
SettableFuture<Coin> future = getFeeRequest.requestFee(transactionId, provider);
Futures.addCallback(future, new FutureCallback<Coin>() {
public void onSuccess(Coin fee) {
if (!resultFuture.isDone()) {
log.info("Request fee from providers done after {} ms.", (System.currentTimeMillis() - startTime));
resultFuture.set(fee);
}
}
public void onFailure(@NotNull Throwable throwable) {
if (!resultFuture.isDone()) {
log.warn("Could not get the fee from any provider after repeated requests.");
resultFuture.setException(throwable);
if (isMainNet) {
for (BlockchainApiProvider provider : providers) {
GetFeeRequest getFeeRequest = new GetFeeRequest();
SettableFuture<Coin> future = getFeeRequest.requestFee(transactionId, provider);
Futures.addCallback(future, new FutureCallback<Coin>() {
public void onSuccess(Coin fee) {
if (!resultFuture.isDone()) {
log.info("Request fee from providers done after {} ms.", (System.currentTimeMillis() - startTime));
resultFuture.set(fee);
}
}
}
});
public void onFailure(@NotNull Throwable throwable) {
if (!resultFuture.isDone()) {
log.warn("Could not get the fee from any provider after repeated requests.");
resultFuture.setException(throwable);
}
}
});
}
} else {
// For regtest/testnet we dont care of the check and set the expected value
resultFuture.set(FeePolicy.getMinRequiredFeeForFundingTx());
}
return resultFuture;
}

View File

@ -31,18 +31,18 @@ public final class FinalizePayoutTxRequest extends TradeMessage implements Mailb
public final byte[] sellerSignature;
public final String sellerPayoutAddress;
public final long lockTime;
public final long lockTimeAsBlockHeight;
private final NodeAddress senderNodeAddress;
public FinalizePayoutTxRequest(String tradeId,
byte[] sellerSignature,
String sellerPayoutAddress,
long lockTime,
long lockTimeAsBlockHeight,
NodeAddress senderNodeAddress) {
super(tradeId);
this.sellerSignature = sellerSignature;
this.sellerPayoutAddress = sellerPayoutAddress;
this.lockTime = lockTime;
this.lockTimeAsBlockHeight = lockTimeAsBlockHeight;
this.senderNodeAddress = senderNodeAddress;
}
@ -59,7 +59,7 @@ public final class FinalizePayoutTxRequest extends TradeMessage implements Mailb
FinalizePayoutTxRequest that = (FinalizePayoutTxRequest) o;
if (lockTime != that.lockTime) return false;
if (lockTimeAsBlockHeight != that.lockTimeAsBlockHeight) return false;
if (!Arrays.equals(sellerSignature, that.sellerSignature)) return false;
if (sellerPayoutAddress != null ? !sellerPayoutAddress.equals(that.sellerPayoutAddress) : that.sellerPayoutAddress != null)
return false;
@ -72,7 +72,7 @@ public final class FinalizePayoutTxRequest extends TradeMessage implements Mailb
int result = super.hashCode();
result = 31 * result + (sellerSignature != null ? Arrays.hashCode(sellerSignature) : 0);
result = 31 * result + (sellerPayoutAddress != null ? sellerPayoutAddress.hashCode() : 0);
result = 31 * result + (int) (lockTime ^ (lockTime >>> 32));
result = 31 * result + (int) (lockTimeAsBlockHeight ^ (lockTimeAsBlockHeight >>> 32));
result = 31 * result + (senderNodeAddress != null ? senderNodeAddress.hashCode() : 0);
return result;
}

View File

@ -45,7 +45,7 @@ public class ProcessFinalizePayoutTxRequest extends TradeTask {
processModel.tradingPeer.setSignature(checkNotNull(message.sellerSignature));
processModel.tradingPeer.setPayoutAddressString(nonEmptyStringOf(message.sellerPayoutAddress));
trade.setLockTimeAsBlockHeight(nonNegativeLongOf(message.lockTime));
trade.setLockTimeAsBlockHeight(nonNegativeLongOf(message.lockTimeAsBlockHeight));
trade.setState(Trade.State.FIAT_PAYMENT_RECEIPT_MSG_RECEIVED);

View File

@ -72,7 +72,7 @@ public class Preferences implements Serializable {
private static Locale defaultLocale = Locale.getDefault();
//TODO test with other locales
//private static Locale defaultLocale = Locale.US;
// private static Locale defaultLocale = Locale.US;
public static Locale getDefaultLocale() {
return defaultLocale;
@ -416,5 +416,4 @@ public class Preferences implements Serializable {
public boolean getUseTorForBitcoinJ() {
return useTorForBitcoinJ;
}
}

View File

@ -22,7 +22,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.bitsquare</groupId>
<version>0.3.4-SNAPSHOT</version>
<version>0.3.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -56,6 +56,7 @@ import javafx.scene.layout.StackPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.bitcoinj.store.BlockStoreException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.controlsfx.dialog.Dialogs;
import org.reactfx.EventStreams;
@ -108,10 +109,15 @@ public class BitsquareApp extends Application {
// setup UncaughtExceptionHandler
Thread.UncaughtExceptionHandler handler = (thread, throwable) -> {
// Might come from another thread
log.error("Uncaught Exception from thread " + Thread.currentThread().getName());
log.error("Uncaught Exception throwableMessage= " + throwable.getMessage());
throwable.printStackTrace();
UserThread.execute(() -> showErrorPopup(throwable, false));
if (throwable.getCause() != null && throwable.getCause().getCause() != null &&
throwable.getCause().getCause() instanceof BlockStoreException) {
log.error(throwable.getMessage());
} else {
log.error("Uncaught Exception from thread " + Thread.currentThread().getName());
log.error("Uncaught Exception throwableMessage= " + throwable.getMessage());
throwable.printStackTrace();
UserThread.execute(() -> showErrorPopup(throwable, false));
}
};
Thread.setDefaultUncaughtExceptionHandler(handler);
Thread.currentThread().setUncaughtExceptionHandler(handler);
@ -135,7 +141,7 @@ public class BitsquareApp extends Application {
if (mainView != null)
mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
});
// load the main view and create the main scene
CachingViewLoader viewLoader = injector.getInstance(CachingViewLoader.class);
mainView = (MainView) viewLoader.load(MainView.class);

View File

@ -26,7 +26,6 @@ import javafx.scene.layout.Pane;
public class TitledGroupBg extends Pane {
private final Label label;
private final StringProperty text = new SimpleStringProperty();

View File

@ -637,7 +637,10 @@ public class MainViewModel implements ViewModel {
if (error instanceof TimeoutException) {
walletServiceErrorMsg.set("Connecting to the bitcoin network failed because of a timeout.");
} else if (error.getCause() instanceof BlockStoreException) {
walletServiceErrorMsg.set("Bitsquare is already running. You cannot run 2 instances of Bitsquare.");
new Popup().warning("Bitsquare is already running. You cannot run 2 instances of Bitsquare.")
.closeButtonText("Shut down")
.onClose(BitsquareApp.shutDownHandler::run)
.show();
} else if (error.getMessage() != null) {
walletServiceErrorMsg.set("Connection to the bitcoin network failed because of an error:" + error.getMessage());
} else {

View File

@ -29,7 +29,7 @@
<TableView fx:id="table" VBox.vgrow="ALWAYS">
<columns>
<TableColumn text="Date/Time" fx:id="dateColumn" minWidth="170" maxWidth="170"/>
<TableColumn text="Date/Time" fx:id="dateColumn" minWidth="180" maxWidth="180"/>
<TableColumn text="Details" fx:id="detailsColumn" minWidth="260"/>
<TableColumn text="Address" fx:id="addressColumn" minWidth="320" maxWidth="320">
<cellValueFactory>

View File

@ -28,12 +28,12 @@
</padding>
<TableView fx:id="table" VBox.vgrow="ALWAYS">
<columns>
<TableColumn text="Date/Time" fx:id="dateColumn" minWidth="160" maxWidth="160">
<TableColumn text="Date/Time" fx:id="dateColumn" minWidth="180" maxWidth="180">
<cellValueFactory>
<PropertyValueFactory property="date"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="Details" fx:id="detailsColumn" minWidth="210" maxWidth="210"/>
<TableColumn text="Details" fx:id="detailsColumn" minWidth="220" maxWidth="220"/>
<TableColumn text="Address" fx:id="addressColumn" minWidth="180"/>
<TableColumn text="Transaction" fx:id="transactionColumn" minWidth="100"/>
<TableColumn text="Amount (BTC)" fx:id="amountColumn" minWidth="110" maxWidth="110">

View File

@ -30,7 +30,7 @@
<TableView fx:id="table" VBox.vgrow="ALWAYS">
<columns>
<TableColumn text="Select" fx:id="selectColumn" minWidth="60" maxWidth="60" sortable="false"/>
<TableColumn text="Date/Time" fx:id="dateColumn" minWidth="170" maxWidth="170"/>
<TableColumn text="Date/Time" fx:id="dateColumn" minWidth="180" maxWidth="180"/>
<TableColumn text="Details" fx:id="detailsColumn" minWidth="160" maxWidth="160"/>
<TableColumn text="Address" fx:id="addressColumn" minWidth="320" maxWidth="320">
<cellValueFactory>

View File

@ -191,9 +191,9 @@ public class WithdrawalView extends ActivatableView<VBox, Void> {
new Popup().headLine("Confirm your withdrawal request")
.message("Sending: " + formatter.formatCoinWithCode(senderAmount) + "\n" +
"From address: " + withdrawFromTextField.getText() + "\n" +
"To receiving address: " + withdrawToTextField.getText() + ".\n\n" +
"Required transaction fee is: " + formatter.formatCoinWithCode(requiredFee) + "\n" +
"Recipient will receive: " + formatter.formatCoinWithCode(receiverAmount) + "\n\n" +
"To receiving address: " + withdrawToTextField.getText() + ".\n" +
"Required transaction fee is: " + formatter.formatCoinWithCode(requiredFee) + "\n\n" +
"The recipient will receive: " + formatter.formatCoinWithCode(receiverAmount) + "\n\n" +
"Are you sure you want to withdraw that amount?")
.onAction(() -> doWithdraw(receiverAmount, callback))
.show();

View File

@ -103,6 +103,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
final ObservableList<PaymentAccount> paymentAccounts = FXCollections.observableArrayList();
private PaymentAccount paymentAccount;
private WalletEventListener walletEventListener;
///////////////////////////////////////////////////////////////////////////////////////////
@ -138,42 +139,7 @@ class CreateOfferDataModel extends ActivatableDataModel {
};
paymentAccountsChangeListener = change -> paymentAccounts.setAll(user.getPaymentAccounts());
}
@Override
protected void activate() {
addBindings();
addListeners();
paymentAccounts.setAll(user.getPaymentAccounts());
updateBalance(walletService.getBalanceForAddress(getAddressEntry().getAddress()));
if (direction == Offer.Direction.BUY)
calculateTotalToPay();
}
@Override
protected void deactivate() {
removeBindings();
removeListeners();
}
private void addBindings() {
btcCode.bind(preferences.btcDenominationProperty());
}
private void removeBindings() {
btcCode.unbind();
}
boolean isFeeFromFundingTxSufficient() {
return feeFromFundingTxProperty.get().compareTo(FeePolicy.getMinFundingFee()) >= 0;
}
private void addListeners() {
walletService.addBalanceListener(balanceListener);
walletService.getWallet().addEventListener(new WalletEventListener() {
walletEventListener = new WalletEventListener() {
@Override
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
requestFeeFromBlockchain(tx.getHashAsString());
@ -202,28 +168,45 @@ class CreateOfferDataModel extends ActivatableDataModel {
@Override
public void onKeysAdded(List<ECKey> keys) {
}
});
user.getPaymentAccountsAsObservable().addListener(paymentAccountsChangeListener);
};
}
private void requestFeeFromBlockchain(String transactionId) {
SettableFuture<Coin> future = blockchainService.requestFeeFromBlockchain(transactionId);
Futures.addCallback(future, new FutureCallback<Coin>() {
public void onSuccess(Coin fee) {
UserThread.execute(() -> feeFromFundingTxProperty.set(fee));
}
@Override
protected void activate() {
addBindings();
addListeners();
public void onFailure(@NotNull Throwable throwable) {
UserThread.execute(() -> new Popup()
.warning("We did not get a result for the mining fee used in the funding transaction.")
.show());
}
});
paymentAccounts.setAll(user.getPaymentAccounts());
updateBalance(walletService.getBalanceForAddress(getAddressEntry().getAddress()));
if (direction == Offer.Direction.BUY)
calculateTotalToPay();
}
@Override
protected void deactivate() {
removeBindings();
removeListeners();
}
private void addBindings() {
btcCode.bind(preferences.btcDenominationProperty());
}
private void removeBindings() {
btcCode.unbind();
}
private void addListeners() {
walletService.addBalanceListener(balanceListener);
walletService.getWallet().addEventListener(walletEventListener);
user.getPaymentAccountsAsObservable().addListener(paymentAccountsChangeListener);
}
private void removeListeners() {
walletService.removeBalanceListener(balanceListener);
walletService.getWallet().removeEventListener(walletEventListener);
user.getPaymentAccountsAsObservable().removeListener(paymentAccountsChangeListener);
}
@ -343,10 +326,30 @@ class CreateOfferDataModel extends ActivatableDataModel {
return user.getAcceptedArbitrators().size() > 0;
}
boolean isFeeFromFundingTxSufficient() {
return feeFromFundingTxProperty.get().compareTo(FeePolicy.getMinRequiredFeeForFundingTx()) >= 0;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Utils
///////////////////////////////////////////////////////////////////////////////////////////
private void requestFeeFromBlockchain(String transactionId) {
SettableFuture<Coin> future = blockchainService.requestFeeFromBlockchain(transactionId);
Futures.addCallback(future, new FutureCallback<Coin>() {
public void onSuccess(Coin fee) {
UserThread.execute(() -> feeFromFundingTxProperty.set(fee));
}
public void onFailure(@NotNull Throwable throwable) {
UserThread.execute(() -> new Popup()
.warning("We did not get a response for the request of the mining fee used in the funding transaction.")
.show());
}
});
}
void calculateVolume() {
if (priceAsFiat.get() != null &&
amountAsCoin.get() != null &&

View File

@ -241,7 +241,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
"You can see the details when you move the mouse over the question mark.\n\n" +
"Important notice!\n" +
"Please take care that you use a mining fee of at least " +
model.formatter.formatCoinWithCode(FeePolicy.getMinFundingFee()) + " when you transfer bitcoin from your external " +
model.formatter.formatCoinWithCode(FeePolicy.getMinRequiredFeeForFundingTx()) + " when you transfer bitcoin from your external " +
"wallet to ensure the trade transactions will get into the blockchain.\n" +
"A too low mining fee might result in a delayed trade and will be rejected!")
.closeButtonText("I understand")
@ -448,7 +448,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
if (!model.dataModel.isFeeFromFundingTxSufficient()) {
new Popup().warning("The mining fee from your funding transaction is not sufficiently high.\n\n" +
"You need to use at least a mining fee of " +
model.formatCoin(FeePolicy.getMinFundingFee()) + ".\n\n" +
model.formatCoin(FeePolicy.getMinRequiredFeeForFundingTx()) + ".\n\n" +
"The fee used in your funding transaction was only " + model.formatCoin(newValue) + ".\n\n" +
"The trade transactions might take too much time to be included in " +
"a block if the fee is too low.\n" +

View File

@ -347,7 +347,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
"You can see the details when you move the mouse over the question mark.\n\n" +
"Important notice!\n" +
"Please take care that you use a mining fee of at least " +
model.formatter.formatCoinWithCode(FeePolicy.getMinFundingFee()) + " when you transfer bitcoin from your external " +
model.formatter.formatCoinWithCode(FeePolicy.getMinRequiredFeeForFundingTx()) + " when you transfer bitcoin from your external " +
"wallet to ensure the trade transactions will get into the blockchain.\n" +
"A too low mining fee might result in a delayed trade and will be rejected!")
.closeButtonText("I understand")

View File

@ -321,7 +321,8 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
}
public String getOpenDisputeTimeAsFormattedDate() {
return formatter.addBlocksToNowDateFormatted(getOpenDisputeTimeAsBlockHeight() - getBestChainHeight() + (getLockTime() - getBestChainHeight()));
return formatter.addBlocksToNowDateFormatted(getOpenDisputeTimeAsBlockHeight() - getBestChainHeight() +
(dataModel.getTrade().getOffer().getPaymentMethod().getLockTime()));
}
public String getReference() {

View File

@ -150,7 +150,6 @@ public abstract class TradeStepView extends AnchorPane {
tradeInfoTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 4, "Trade information");
txIdTextField = addLabelTxIdTextField(gridPane, gridRow, "Deposit transaction ID:", Layout.FIRST_ROW_DISTANCE).second;
//TODO
PaymentMethodForm.addAllowedPeriod(gridPane, ++gridRow, model.dataModel.getSellersPaymentAccountContractData(),
model.getOpenDisputeTimeAsFormattedDate());

View File

@ -294,8 +294,8 @@ public class FormBuilder {
InputTextField inputTextField = new InputTextField();
CheckBox checkBox = new CheckBox(checkBoxTitle);
checkBox.setPadding(new Insets(6, 0, 0, 0));
HBox.setMargin(checkBox, new Insets(4, 0, 0, 0));
HBox hBox = new HBox();
hBox.setSpacing(10);
hBox.getChildren().addAll(inputTextField, checkBox);

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.bitsquare</groupId>
<version>0.3.4-SNAPSHOT</version>
<version>0.3.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.bitsquare</groupId>
<version>0.3.4-SNAPSHOT</version>
<version>0.3.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.bitsquare</groupId>
<version>0.3.4-SNAPSHOT</version>
<version>0.3.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -23,11 +23,6 @@ public abstract class TorNode<M extends OnionProxyManager, C extends OnionProxyC
private static final Logger log = LoggerFactory.getLogger(TorNode.class);
private final OnionProxyManager tor;
public Socks5Proxy getProxy() {
return proxy;
}
private final Socks5Proxy proxy;
public TorNode(M mgr) throws IOException {

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.bitsquare</groupId>
<version>0.3.4-SNAPSHOT</version>
<version>0.3.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -16,11 +16,12 @@ public class SeedNodesRepository {
// regtest use port 8002
private Set<NodeAddress> torSeedNodeAddresses = Sets.newHashSet(
// mainnet
// 0.3.3
// v0.3.3
/* new NodeAddress("oyyii5ogv7y7iadi.onion:8000"),
new NodeAddress("ugcro2f5xnkguash.onion:8000"),
new NodeAddress("qarhpdsl6mfhbnud.onion:8000"),*/
// v0.3.4
new NodeAddress("lih5zsr2bvxi24pk.onion:8000"),
new NodeAddress("s5xpstlooosehtxm.onion:8000"),
new NodeAddress("izs5oz7i5ta7c2ir.onion:8000"),

View File

@ -6,7 +6,7 @@
<groupId>io.bitsquare</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>0.3.4-SNAPSHOT</version>
<version>0.3.4</version>
<description>Bitsquare - The decentralized bitcoin exchange</description>
<url>https://bitsquare.io</url>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.bitsquare</groupId>
<version>0.3.4-SNAPSHOT</version>
<version>0.3.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>