mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-03-15 10:26:37 -04:00
update to bitcoinJ master
This commit is contained in:
parent
2190772370
commit
0f04d3c483
9
pom.xml
9
pom.xml
@ -110,12 +110,19 @@
|
||||
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google</groupId>
|
||||
<artifactId>bitcoinj</artifactId>
|
||||
<version>0.12-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>com.google</groupId>
|
||||
<artifactId>bitcoinj</artifactId>
|
||||
<version>0.11.3</version>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<dependency>
|
||||
<groupId>net.tomp2p</groupId>
|
||||
|
@ -138,7 +138,9 @@ public class BitSquare extends Application
|
||||
private MenuBar getMenuBar()
|
||||
{
|
||||
MenuBar menuBar = new MenuBar();
|
||||
menuBar.setUseSystemMenuBar(true);
|
||||
// on mac we could placemenu bar in the systems menu
|
||||
// menuBar.setUseSystemMenuBar(true);
|
||||
menuBar.setUseSystemMenuBar(false);
|
||||
|
||||
Menu fileMenu = new Menu("_File");
|
||||
fileMenu.setMnemonicParsing(true);
|
||||
|
@ -6,10 +6,7 @@ import com.google.bitcoin.wallet.CoinSelection;
|
||||
import com.google.bitcoin.wallet.DefaultCoinSelector;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -45,38 +42,33 @@ class AddressBasedCoinSelector extends DefaultCoinSelector
|
||||
@VisibleForTesting
|
||||
static void sortOutputs(ArrayList<TransactionOutput> outputs)
|
||||
{
|
||||
Collections.sort(outputs, (a, b) -> {
|
||||
int depth1 = 0;
|
||||
int depth2 = 0;
|
||||
TransactionConfidence conf1 = a.getParentTransaction().getConfidence();
|
||||
TransactionConfidence conf2 = b.getParentTransaction().getConfidence();
|
||||
if (conf1.getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)
|
||||
Collections.sort(outputs, new Comparator<TransactionOutput>()
|
||||
{
|
||||
@Override
|
||||
public int compare(TransactionOutput a, TransactionOutput b)
|
||||
{
|
||||
depth1 = conf1.getDepthInBlocks();
|
||||
int depth1 = 0;
|
||||
int depth2 = 0;
|
||||
TransactionConfidence conf1 = a.getParentTransaction().getConfidence();
|
||||
TransactionConfidence conf2 = b.getParentTransaction().getConfidence();
|
||||
if (conf1.getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)
|
||||
depth1 = conf1.getDepthInBlocks();
|
||||
if (conf2.getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)
|
||||
depth2 = conf2.getDepthInBlocks();
|
||||
Coin aValue = a.getValue();
|
||||
Coin bValue = b.getValue();
|
||||
BigInteger aCoinDepth = BigInteger.valueOf(aValue.value).multiply(BigInteger.valueOf(depth1));
|
||||
BigInteger bCoinDepth = BigInteger.valueOf(bValue.value).multiply(BigInteger.valueOf(depth2));
|
||||
int c1 = bCoinDepth.compareTo(aCoinDepth);
|
||||
if (c1 != 0) return c1;
|
||||
// The "coin*days" destroyed are equal, sort by value alone to get the lowest transaction size.
|
||||
int c2 = bValue.compareTo(aValue);
|
||||
if (c2 != 0) return c2;
|
||||
// They are entirely equivalent (possibly pending) so sort by hash to ensure a total ordering.
|
||||
BigInteger aHash = a.getParentTransaction().getHash().toBigInteger();
|
||||
BigInteger bHash = b.getParentTransaction().getHash().toBigInteger();
|
||||
return aHash.compareTo(bHash);
|
||||
}
|
||||
if (conf2.getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)
|
||||
{
|
||||
depth2 = conf2.getDepthInBlocks();
|
||||
}
|
||||
BigInteger aValue = a.getValue();
|
||||
BigInteger bValue = b.getValue();
|
||||
BigInteger aCoinDepth = aValue.multiply(BigInteger.valueOf(depth1));
|
||||
BigInteger bCoinDepth = bValue.multiply(BigInteger.valueOf(depth2));
|
||||
int c1 = bCoinDepth.compareTo(aCoinDepth);
|
||||
if (c1 != 0)
|
||||
{
|
||||
return c1;
|
||||
}
|
||||
// The "coin*days" destroyed are equal, sort by value alone to get the lowest transaction size.
|
||||
int c2 = bValue.compareTo(aValue);
|
||||
if (c2 != 0)
|
||||
{
|
||||
return c2;
|
||||
}
|
||||
// They are entirely equivalent (possibly pending) so sort by hash to ensure a total ordering.
|
||||
BigInteger aHash = a.getParentTransaction().getHash().toBigInteger();
|
||||
BigInteger bHash = b.getParentTransaction().getHash().toBigInteger();
|
||||
return aHash.compareTo(bHash);
|
||||
});
|
||||
}
|
||||
|
||||
@ -129,7 +121,7 @@ class AddressBasedCoinSelector extends DefaultCoinSelector
|
||||
}
|
||||
|
||||
|
||||
public CoinSelection select(BigInteger biTarget, LinkedList<TransactionOutput> candidates)
|
||||
public CoinSelection select(Coin biTarget, LinkedList<TransactionOutput> candidates)
|
||||
{
|
||||
long target = biTarget.longValue();
|
||||
HashSet<TransactionOutput> selected = new HashSet<>();
|
||||
@ -163,7 +155,7 @@ class AddressBasedCoinSelector extends DefaultCoinSelector
|
||||
}
|
||||
// Total may be lower than target here, if the given candidates were insufficient to create to requested
|
||||
// transaction.
|
||||
return new CoinSelection(BigInteger.valueOf(total), selected);
|
||||
return new CoinSelection(Coin.valueOf(total), selected);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1,25 +1,28 @@
|
||||
package io.bitsquare.btc;
|
||||
|
||||
import com.google.bitcoin.core.Address;
|
||||
import com.google.bitcoin.core.ECKey;
|
||||
import com.google.bitcoin.core.NetworkParameters;
|
||||
import com.google.bitcoin.core.Utils;
|
||||
import com.google.bitcoin.crypto.DeterministicKey;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class AddressEntry implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 5501603992599920416L;
|
||||
private final ECKey key;
|
||||
private transient DeterministicKey key;
|
||||
private final NetworkParameters params;
|
||||
private final AddressContext addressContext;
|
||||
private final byte[] pubKeyHash;
|
||||
|
||||
private String tradeId = null;
|
||||
|
||||
public AddressEntry(ECKey key, NetworkParameters params, AddressContext addressContext)
|
||||
public AddressEntry(DeterministicKey key, NetworkParameters params, AddressContext addressContext)
|
||||
{
|
||||
this.key = key;
|
||||
this.params = params;
|
||||
this.addressContext = addressContext;
|
||||
|
||||
pubKeyHash = key.getPubOnly().getPubKeyHash();
|
||||
}
|
||||
|
||||
|
||||
@ -45,10 +48,10 @@ public class AddressEntry implements Serializable
|
||||
|
||||
public String getPubKeyAsHexString()
|
||||
{
|
||||
return Utils.bytesToHexString(key.getPubKey());
|
||||
return Utils.HEX.encode(key.getPubKey());
|
||||
}
|
||||
|
||||
public ECKey getKey()
|
||||
public DeterministicKey getKey()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
@ -58,6 +61,16 @@ public class AddressEntry implements Serializable
|
||||
return key.toAddress(params);
|
||||
}
|
||||
|
||||
public void setDeterministicKey(DeterministicKey key)
|
||||
{
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public byte[] getPubKeyHash()
|
||||
{
|
||||
return pubKeyHash;
|
||||
}
|
||||
|
||||
public static enum AddressContext
|
||||
{
|
||||
REGISTRATION_FEE,
|
||||
|
@ -1,25 +0,0 @@
|
||||
package io.bitsquare.btc;
|
||||
|
||||
import com.google.bitcoin.core.NetworkParameters;
|
||||
import com.google.bitcoin.core.Wallet;
|
||||
import com.google.bitcoin.crypto.KeyCrypter;
|
||||
import java.io.Serializable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class BitSquareWallet extends Wallet implements Serializable
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(BitSquareWallet.class);
|
||||
private static final long serialVersionUID = -6231929674475881549L;
|
||||
|
||||
public BitSquareWallet(NetworkParameters params)
|
||||
{
|
||||
super(params);
|
||||
}
|
||||
|
||||
private BitSquareWallet(NetworkParameters params, KeyCrypter keyCrypter)
|
||||
{
|
||||
super(params, keyCrypter);
|
||||
}
|
||||
|
||||
}
|
@ -1,171 +0,0 @@
|
||||
package io.bitsquare.btc;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.kits.WalletAppKit;
|
||||
import com.google.bitcoin.net.discovery.DnsDiscovery;
|
||||
import com.google.bitcoin.store.BlockStoreException;
|
||||
import com.google.bitcoin.store.SPVBlockStore;
|
||||
import com.google.bitcoin.store.WalletProtobufSerializer;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BitSquareWalletAppKit extends WalletAppKit
|
||||
{
|
||||
|
||||
public BitSquareWalletAppKit(NetworkParameters params, File directory)
|
||||
{
|
||||
super(params, directory, WalletFacade.WALLET_PREFIX);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
// Runs in a separate thread.
|
||||
if (!directory.exists())
|
||||
{
|
||||
if (!directory.mkdir())
|
||||
{
|
||||
throw new IOException("Could not create named directory " + directory.getCanonicalPath());
|
||||
}
|
||||
}
|
||||
FileInputStream walletStream = null;
|
||||
try
|
||||
{
|
||||
File chainFile = new File(directory, filePrefix + ".spvchain");
|
||||
boolean chainFileExists = chainFile.exists();
|
||||
vWalletFile = new File(directory, filePrefix + ".wallet");
|
||||
boolean shouldReplayWallet = vWalletFile.exists() && !chainFileExists;
|
||||
|
||||
vStore = new SPVBlockStore(params, chainFile);
|
||||
if (!chainFileExists && checkpoints != null)
|
||||
{
|
||||
// Ugly hack! We have to create the wallet once here to learn the earliest key time, and then throw it
|
||||
// away. The reason is that wallet extensions might need access to peergroups/chains/etc so we have to
|
||||
// create the wallet later, but we need to know the time early here before we create the BlockChain
|
||||
// object.
|
||||
long time = Long.MAX_VALUE;
|
||||
if (vWalletFile.exists())
|
||||
{
|
||||
Wallet wallet = new BitSquareWallet(params);
|
||||
FileInputStream stream = new FileInputStream(vWalletFile);
|
||||
new WalletProtobufSerializer().readWallet(WalletProtobufSerializer.parseToProto(stream), wallet);
|
||||
time = wallet.getEarliestKeyCreationTime();
|
||||
}
|
||||
CheckpointManager.checkpoint(params, checkpoints, vStore, time);
|
||||
}
|
||||
vChain = new BlockChain(params, vStore);
|
||||
vPeerGroup = createPeerGroup();
|
||||
|
||||
vPeerGroup.setBloomFilterFalsePositiveRate(0.001); // 0,1% instead of default 0,05%
|
||||
|
||||
if (this.userAgent != null)
|
||||
{
|
||||
vPeerGroup.setUserAgent(userAgent, version);
|
||||
}
|
||||
if (vWalletFile.exists())
|
||||
{
|
||||
walletStream = new FileInputStream(vWalletFile);
|
||||
vWallet = new BitSquareWallet(params);
|
||||
addWalletExtensions(); // All extensions must be present before we deserialize
|
||||
new WalletProtobufSerializer().readWallet(WalletProtobufSerializer.parseToProto(walletStream), vWallet);
|
||||
if (shouldReplayWallet)
|
||||
{
|
||||
vWallet.clearTransactions(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vWallet = new BitSquareWallet(params);
|
||||
vWallet.addKey(new ECKey());
|
||||
addWalletExtensions();
|
||||
}
|
||||
if (useAutoSave)
|
||||
{
|
||||
vWallet.autosaveToFile(vWalletFile, 1, TimeUnit.SECONDS, null);
|
||||
}
|
||||
// Set up peer addresses or discovery first, so if wallet extensions try to broadcast a transaction
|
||||
// before we're actually connected the broadcast waits for an appropriate number of connections.
|
||||
if (peerAddresses != null)
|
||||
{
|
||||
for (PeerAddress addr : peerAddresses)
|
||||
{
|
||||
vPeerGroup.addAddress(addr);
|
||||
}
|
||||
peerAddresses = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
vPeerGroup.addPeerDiscovery(new DnsDiscovery(params));
|
||||
}
|
||||
vChain.addWallet(vWallet);
|
||||
vPeerGroup.addWallet(vWallet);
|
||||
onSetupCompleted();
|
||||
|
||||
if (blockingStartup)
|
||||
{
|
||||
vPeerGroup.startAsync();
|
||||
vPeerGroup.awaitRunning();
|
||||
// Make sure we shut down cleanly.
|
||||
installShutdownHook();
|
||||
// TODO: Be able to use the provided download listener when doing a blocking startup.
|
||||
final DownloadListener listener = new DownloadListener();
|
||||
vPeerGroup.startBlockChainDownload(listener);
|
||||
listener.await();
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO deprecated
|
||||
Futures.addCallback(vPeerGroup.start(), new FutureCallback<State>()
|
||||
{
|
||||
@Override
|
||||
public void onSuccess(State result)
|
||||
{
|
||||
final PeerEventListener l = downloadListener == null ? new DownloadListener() : downloadListener;
|
||||
vPeerGroup.startBlockChainDownload(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t)
|
||||
{
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (BlockStoreException e)
|
||||
{
|
||||
throw new IOException(e);
|
||||
} finally
|
||||
{
|
||||
if (walletStream != null)
|
||||
{
|
||||
walletStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void installShutdownHook()
|
||||
{
|
||||
if (autoStop)
|
||||
{
|
||||
Runtime.getRuntime().addShutdownHook(new Thread()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
BitSquareWalletAppKit.this.stopAsync();
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package io.bitsquare.btc;
|
||||
|
||||
import com.google.bitcoin.core.Utils;
|
||||
import io.bitsquare.gui.util.BitSquareConverter;
|
||||
import java.math.BigInteger;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Locale;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
// TODO
|
||||
public class BtcFormatter
|
||||
{
|
||||
private static final BigInteger BTC = new BigInteger("100000000");
|
||||
private static final Logger log = LoggerFactory.getLogger(BtcFormatter.class);
|
||||
|
||||
public static BigInteger mBTC = new BigInteger("100000");
|
||||
|
||||
|
||||
public static String formatSatoshis(BigInteger value)
|
||||
{
|
||||
return Utils.bitcoinValueToFriendlyString(value);
|
||||
}
|
||||
|
||||
//TODO
|
||||
public static double satoshiToBTC(BigInteger satoshis)
|
||||
{
|
||||
return satoshis.doubleValue() / BTC.doubleValue();
|
||||
}
|
||||
|
||||
public static BigInteger stringValueToSatoshis(String value)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Utils.toNanoCoins(String.valueOf(BitSquareConverter.stringToDouble(value)));
|
||||
} catch (ArithmeticException e)
|
||||
{
|
||||
log.warn("ArithmeticException " + e);
|
||||
}
|
||||
return BigInteger.ZERO;
|
||||
}
|
||||
|
||||
public static BigInteger doubleValueToSatoshis(double value)
|
||||
{
|
||||
try
|
||||
{
|
||||
// only "." as decimal sep supported by Utils.toNanoCoins
|
||||
final DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(Locale.ENGLISH);
|
||||
decimalFormat.setMaximumFractionDigits(10);
|
||||
decimalFormat.setMinimumFractionDigits(10);
|
||||
String stringValue = decimalFormat.format(value);
|
||||
return Utils.toNanoCoins(stringValue);
|
||||
} catch (Exception e)
|
||||
{
|
||||
log.warn("Exception at doubleValueToSatoshis " + e.getMessage());
|
||||
return BigInteger.ZERO;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
package io.bitsquare.btc;
|
||||
|
||||
import com.google.bitcoin.core.Address;
|
||||
import com.google.bitcoin.core.AddressFormatException;
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.NetworkParameters;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import java.math.BigInteger;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class BtcValidator
|
||||
@ -17,12 +15,12 @@ public class BtcValidator
|
||||
BtcValidator.params = params;
|
||||
}
|
||||
|
||||
public static boolean isMinSpendableAmount(BigInteger amount)
|
||||
public static boolean isMinSpendableAmount(Coin amount)
|
||||
{
|
||||
return amount != null && amount.compareTo(FeePolicy.TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT)) > 0;
|
||||
}
|
||||
|
||||
public boolean isAddressValid(String addressString)
|
||||
/* public boolean isAddressValid(String addressString)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -32,6 +30,6 @@ public class BtcValidator
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,16 @@
|
||||
package io.bitsquare.btc;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import java.math.BigInteger;
|
||||
import javax.inject.Inject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class FeePolicy
|
||||
{
|
||||
public static final BigInteger TX_FEE = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE;
|
||||
public static final BigInteger ACCOUNT_REGISTRATION_FEE = Utils.toNanoCoins("0.01");
|
||||
public static final BigInteger CREATE_OFFER_FEE = Utils.toNanoCoins("0.001");
|
||||
public static final BigInteger TAKE_OFFER_FEE = CREATE_OFFER_FEE;
|
||||
public static final Coin TX_FEE = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE;
|
||||
public static final Coin ACCOUNT_REGISTRATION_FEE = Coin.CENT; // 0.01
|
||||
public static final Coin CREATE_OFFER_FEE = Coin.MILLICOIN; // 0.001
|
||||
public static final Coin TAKE_OFFER_FEE = CREATE_OFFER_FEE;
|
||||
private static final Logger log = LoggerFactory.getLogger(FeePolicy.class);
|
||||
private static final String registrationFeeAddress = "mvkDXt4QmN4Nq9dRUsRigBCaovde9nLkZR";
|
||||
private static final String createOfferFeeAddress = "n2upbsaKAe4PD3cc4JfS7UCqPC5oNd7Ckg";
|
||||
|
@ -1,7 +1,9 @@
|
||||
package io.bitsquare.btc;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.crypto.DeterministicKey;
|
||||
import com.google.bitcoin.crypto.TransactionSignature;
|
||||
import com.google.bitcoin.kits.WalletAppKit;
|
||||
import com.google.bitcoin.params.MainNetParams;
|
||||
import com.google.bitcoin.params.RegTestParams;
|
||||
import com.google.bitcoin.script.Script;
|
||||
@ -18,6 +20,7 @@ import io.bitsquare.btc.listeners.BalanceListener;
|
||||
import io.bitsquare.btc.listeners.ConfidenceListener;
|
||||
import io.bitsquare.crypto.CryptoFacade;
|
||||
import io.bitsquare.storage.Persistence;
|
||||
import io.bitsquare.util.StorageDirectory;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
@ -30,10 +33,9 @@ import javax.inject.Inject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static com.google.bitcoin.script.ScriptOpCodes.OP_RETURN;
|
||||
|
||||
/**
|
||||
* TODO: use walletextension (with protobuffer) instead of saving addressEntryList via storage
|
||||
* TODO: use HD wallet features instead of addressEntryList
|
||||
*/
|
||||
public class WalletFacade
|
||||
{
|
||||
@ -49,14 +51,14 @@ public class WalletFacade
|
||||
|
||||
|
||||
private final NetworkParameters params;
|
||||
private final BitSquareWalletAppKit walletAppKit;
|
||||
private WalletAppKit walletAppKit;
|
||||
private final FeePolicy feePolicy;
|
||||
private final CryptoFacade cryptoFacade;
|
||||
private final Persistence persistence;
|
||||
private final List<DownloadListener> downloadListeners = new ArrayList<>();
|
||||
private final List<ConfidenceListener> confidenceListeners = new ArrayList<>();
|
||||
private final List<BalanceListener> balanceListeners = new ArrayList<>();
|
||||
private BitSquareWallet wallet;
|
||||
private Wallet wallet;
|
||||
private WalletEventListener walletEventListener;
|
||||
|
||||
@GuardedBy("lock")
|
||||
@ -67,10 +69,9 @@ public class WalletFacade
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Inject
|
||||
public WalletFacade(NetworkParameters params, BitSquareWalletAppKit walletAppKit, FeePolicy feePolicy, CryptoFacade cryptoFacade, Persistence persistence)
|
||||
public WalletFacade(NetworkParameters params, FeePolicy feePolicy, CryptoFacade cryptoFacade, Persistence persistence)
|
||||
{
|
||||
this.params = params;
|
||||
this.walletAppKit = walletAppKit;
|
||||
this.feePolicy = feePolicy;
|
||||
this.cryptoFacade = cryptoFacade;
|
||||
this.persistence = persistence;
|
||||
@ -81,7 +82,7 @@ public class WalletFacade
|
||||
// Public Methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void initWallet()
|
||||
public void initialize(StartupListener startupListener)
|
||||
{
|
||||
// Tell bitcoinj to execute event handlers on the JavaFX UI thread. This keeps things simple and means
|
||||
// we cannot forget to switch threads when adding event handlers. Unfortunately, the DownloadListener
|
||||
@ -89,9 +90,27 @@ public class WalletFacade
|
||||
// a future version.
|
||||
Threading.USER_THREAD = Platform::runLater;
|
||||
|
||||
// If seed is non-null it means we are restoring from backup.
|
||||
walletAppKit = new WalletAppKit(params, StorageDirectory.getStorageDirectory(), WALLET_PREFIX)
|
||||
{
|
||||
@Override
|
||||
protected void onSetupCompleted()
|
||||
{
|
||||
// Don't make the user wait for confirmations for now, as the intention is they're sending it
|
||||
// their own money!
|
||||
walletAppKit.wallet().allowSpendingUnconfirmedTransactions();
|
||||
if (params != RegTestParams.get())
|
||||
walletAppKit.peerGroup().setMaxConnections(11);
|
||||
walletAppKit.peerGroup().setBloomFilterFalsePositiveRate(0.00001);
|
||||
initWallet();
|
||||
Platform.runLater(startupListener::completed);
|
||||
}
|
||||
};
|
||||
// Now configure and start the appkit. This will take a second or two - we could show a temporary splash screen
|
||||
// or progress widget to keep the user engaged whilst we initialise, but we don't.
|
||||
if (params == RegTestParams.get())
|
||||
{
|
||||
walletAppKit.connectToLocalHost(); // You should execute a regtest mode bitcoind locally.
|
||||
walletAppKit.connectToLocalHost(); // You should run a regtest mode bitcoind locally.
|
||||
}
|
||||
else if (params == MainNetParams.get())
|
||||
{
|
||||
@ -99,23 +118,21 @@ public class WalletFacade
|
||||
// in the checkpoints file and then download the rest from the network. It makes things much faster.
|
||||
// Checkpoint files are made using the BuildCheckpoints tool and usually we have to download the
|
||||
// last months worth or more (takes a few seconds).
|
||||
walletAppKit.setCheckpoints(getClass().getResourceAsStream("/wallet/checkpoints"));
|
||||
walletAppKit.setCheckpoints(getClass().getResourceAsStream("checkpoints"));
|
||||
// As an example!
|
||||
// walletAppKit.useTor();
|
||||
}
|
||||
walletAppKit.setDownloadListener(new BlockChainDownloadListener())
|
||||
.setBlockingStartup(false)
|
||||
.restoreWalletFromSeed(null)
|
||||
.setUserAgent("BitSquare", "0.1");
|
||||
|
||||
walletAppKit.setAutoSave(true);
|
||||
|
||||
// add well known stable nodes
|
||||
//walletAppKit.peerGroup().addAddress();
|
||||
|
||||
// Now configure and start the appkit. This will take a second or two - we could show a temporary splash screen
|
||||
// or progress widget to keep the user engaged whilst we initialise, but we don't.
|
||||
walletAppKit.setDownloadListener(new BlockChainDownloadListener());
|
||||
walletAppKit.setBlockingStartup(false);
|
||||
walletAppKit.setUserAgent("BitSquare", "0.1");
|
||||
walletAppKit.startAsync();
|
||||
walletAppKit.awaitRunning();
|
||||
}
|
||||
|
||||
wallet = (BitSquareWallet) walletAppKit.wallet();
|
||||
private void initWallet()
|
||||
{
|
||||
wallet = walletAppKit.wallet();
|
||||
|
||||
wallet.allowSpendingUnconfirmedTransactions();
|
||||
//walletAppKit.peerGroup().setMaxConnections(11);
|
||||
@ -127,45 +144,48 @@ public class WalletFacade
|
||||
/* else
|
||||
walletAppKit.peerGroup().setMinBroadcastConnections(2); */
|
||||
|
||||
|
||||
walletEventListener = new WalletEventListener()
|
||||
{
|
||||
@Override
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
|
||||
{
|
||||
notifyBalanceListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
|
||||
{
|
||||
notifyBalanceListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReorganize(Wallet wallet)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
|
||||
{
|
||||
notifyConfidenceListeners(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
notifyBalanceListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReorganize(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalletChanged(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(Wallet wallet, List<ECKey> keys)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScriptsAdded(Wallet wallet, List<Script> scripts)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(List<ECKey> keys)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
wallet.addEventListener(walletEventListener);
|
||||
@ -174,12 +194,16 @@ public class WalletFacade
|
||||
List<AddressEntry> persistedAddressEntryList = (List<AddressEntry>) serializable;
|
||||
if (serializable instanceof List)
|
||||
{
|
||||
for (AddressEntry persistedAddressEntry : persistedAddressEntryList)
|
||||
{
|
||||
persistedAddressEntry.setDeterministicKey((DeterministicKey) wallet.findKeyFromPubHash(persistedAddressEntry.getPubKeyHash()));
|
||||
}
|
||||
addressEntryList = persistedAddressEntryList;
|
||||
}
|
||||
else
|
||||
{
|
||||
lock.lock();
|
||||
ECKey registrationKey = wallet.getKeys().get(0);
|
||||
DeterministicKey registrationKey = wallet.currentReceiveKey();
|
||||
addressEntryList.add(new AddressEntry(registrationKey, params, AddressEntry.AddressContext.REGISTRATION_FEE));
|
||||
lock.unlock();
|
||||
saveAddressInfoList();
|
||||
@ -330,9 +354,8 @@ public class WalletFacade
|
||||
{
|
||||
lock.lock();
|
||||
wallet.getLock().lock();
|
||||
ECKey key = new ECKey();
|
||||
wallet.addKey(key);
|
||||
wallet.addWatchedAddress(key.toAddress(params));
|
||||
|
||||
DeterministicKey key = wallet.freshReceiveKey();
|
||||
AddressEntry addressEntry = new AddressEntry(key, params, addressContext);
|
||||
addressEntryList.add(addressEntry);
|
||||
saveAddressInfoList();
|
||||
@ -483,14 +506,14 @@ public class WalletFacade
|
||||
// Balance
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public BigInteger getBalanceForAddress(Address address)
|
||||
public Coin getBalanceForAddress(Address address)
|
||||
{
|
||||
return getBalance(wallet.calculateAllSpendCandidates(true), address);
|
||||
}
|
||||
|
||||
private BigInteger getBalance(LinkedList<TransactionOutput> transactionOutputs, Address address)
|
||||
private Coin getBalance(LinkedList<TransactionOutput> transactionOutputs, Address address)
|
||||
{
|
||||
BigInteger balance = BigInteger.ZERO;
|
||||
Coin balance = Coin.ZERO;
|
||||
for (TransactionOutput transactionOutput : transactionOutputs)
|
||||
{
|
||||
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH())
|
||||
@ -509,7 +532,7 @@ public class WalletFacade
|
||||
{
|
||||
for (BalanceListener balanceListener : balanceListeners)
|
||||
{
|
||||
BigInteger balance;
|
||||
Coin balance;
|
||||
if (balanceListener.getAddress() != null)
|
||||
{
|
||||
balance = getBalanceForAddress(balanceListener.getAddress());
|
||||
@ -523,24 +546,24 @@ public class WalletFacade
|
||||
}
|
||||
}
|
||||
|
||||
public BigInteger getWalletBalance()
|
||||
public Coin getWalletBalance()
|
||||
{
|
||||
return wallet.getBalance(Wallet.BalanceType.ESTIMATED);
|
||||
}
|
||||
|
||||
BigInteger getRegistrationBalance()
|
||||
Coin getRegistrationBalance()
|
||||
{
|
||||
return getBalanceForAddress(getRegistrationAddressInfo().getAddress());
|
||||
}
|
||||
|
||||
public BigInteger getArbitratorDepositBalance()
|
||||
public Coin getArbitratorDepositBalance()
|
||||
{
|
||||
return getBalanceForAddress(getArbitratorDepositAddressInfo().getAddress());
|
||||
}
|
||||
|
||||
public boolean isRegistrationFeeBalanceNonZero()
|
||||
{
|
||||
return getRegistrationBalance().compareTo(BigInteger.ZERO) > 0;
|
||||
return getRegistrationBalance().compareTo(Coin.ZERO) > 0;
|
||||
}
|
||||
|
||||
public boolean isRegistrationFeeBalanceSufficient()
|
||||
@ -551,14 +574,14 @@ public class WalletFacade
|
||||
public boolean isUnusedTradeAddressBalanceAboveCreationFee()
|
||||
{
|
||||
AddressEntry unUsedAddressEntry = getUnusedTradeAddressInfo();
|
||||
BigInteger unUsedAddressInfoBalance = getBalanceForAddress(unUsedAddressEntry.getAddress());
|
||||
Coin unUsedAddressInfoBalance = getBalanceForAddress(unUsedAddressEntry.getAddress());
|
||||
return unUsedAddressInfoBalance.compareTo(FeePolicy.CREATE_OFFER_FEE) > 0;
|
||||
}
|
||||
|
||||
public boolean isUnusedTradeAddressBalanceAboveTakeOfferFee()
|
||||
{
|
||||
AddressEntry unUsedAddressEntry = getUnusedTradeAddressInfo();
|
||||
BigInteger unUsedAddressInfoBalance = getBalanceForAddress(unUsedAddressEntry.getAddress());
|
||||
Coin unUsedAddressInfoBalance = getBalanceForAddress(unUsedAddressEntry.getAddress());
|
||||
return unUsedAddressInfoBalance.compareTo(FeePolicy.TAKE_OFFER_FEE) > 0;
|
||||
}
|
||||
|
||||
@ -582,11 +605,12 @@ public class WalletFacade
|
||||
|
||||
Transaction tx = new Transaction(params);
|
||||
|
||||
byte[] data = cryptoFacade.getEmbeddedAccountRegistrationData(getRegistrationAddressInfo().getKey(), stringifiedBankAccounts);
|
||||
tx.addOutput(Transaction.MIN_NONDUST_OUTPUT, new ScriptBuilder().op(OP_RETURN).data(data).build());
|
||||
//TODO priv key is null, use other signing key or find out why it is null at that moment
|
||||
//byte[] data = cryptoFacade.getEmbeddedAccountRegistrationData(getRegistrationAddressInfo().getKey(), stringifiedBankAccounts);
|
||||
//tx.addOutput(Transaction.MIN_NONDUST_OUTPUT, new ScriptBuilder().op(OP_RETURN).data(data).build());
|
||||
|
||||
BigInteger fee = FeePolicy.ACCOUNT_REGISTRATION_FEE.subtract(Transaction.MIN_NONDUST_OUTPUT).subtract(FeePolicy.TX_FEE);
|
||||
log.trace("fee: " + BtcFormatter.formatSatoshis(fee));
|
||||
Coin fee = FeePolicy.ACCOUNT_REGISTRATION_FEE.subtract(Transaction.MIN_NONDUST_OUTPUT).subtract(FeePolicy.TX_FEE);
|
||||
log.trace("fee: " + fee.toFriendlyString());
|
||||
tx.addOutput(fee, feePolicy.getAddressForRegistrationFee());
|
||||
|
||||
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
|
||||
@ -595,7 +619,21 @@ public class WalletFacade
|
||||
sendRequest.coinSelector = new AddressBasedCoinSelector(params, getRegistrationAddressInfo(), false);
|
||||
sendRequest.changeAddress = getRegistrationAddressInfo().getAddress();
|
||||
Wallet.SendResult sendResult = wallet.sendCoins(sendRequest);
|
||||
//Object k = getRegistrationAddressInfo().getKey();
|
||||
Futures.addCallback(sendResult.broadcastComplete, callback);
|
||||
/*Futures.addCallback(sendResult.broadcastComplete, new FutureCallback<Transaction>(){
|
||||
@Override
|
||||
public void onSuccess(@Nullable Transaction result)
|
||||
{
|
||||
Object k = getRegistrationAddressInfo().getKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t)
|
||||
{
|
||||
|
||||
}
|
||||
}); */
|
||||
|
||||
log.debug("Registration transaction: " + tx);
|
||||
printInputs("payRegistrationFee", tx);
|
||||
@ -604,8 +642,8 @@ public class WalletFacade
|
||||
public String payCreateOfferFee(String offerId, FutureCallback<Transaction> callback) throws InsufficientMoneyException
|
||||
{
|
||||
Transaction tx = new Transaction(params);
|
||||
BigInteger fee = FeePolicy.CREATE_OFFER_FEE.subtract(FeePolicy.TX_FEE);
|
||||
log.trace("fee: " + BtcFormatter.formatSatoshis(fee));
|
||||
Coin fee = FeePolicy.CREATE_OFFER_FEE.subtract(FeePolicy.TX_FEE);
|
||||
log.trace("fee: " + fee.toFriendlyString());
|
||||
tx.addOutput(fee, feePolicy.getAddressForCreateOfferFee());
|
||||
|
||||
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
|
||||
@ -625,8 +663,8 @@ public class WalletFacade
|
||||
public String payTakeOfferFee(String offerId, FutureCallback<Transaction> callback) throws InsufficientMoneyException
|
||||
{
|
||||
Transaction tx = new Transaction(params);
|
||||
BigInteger fee = FeePolicy.TAKE_OFFER_FEE.subtract(FeePolicy.TX_FEE);
|
||||
log.trace("fee: " + BtcFormatter.formatSatoshis(fee));
|
||||
Coin fee = FeePolicy.TAKE_OFFER_FEE.subtract(FeePolicy.TX_FEE);
|
||||
log.trace("fee: " + fee.toFriendlyString());
|
||||
tx.addOutput(fee, feePolicy.getAddressForTakeOfferFee());
|
||||
|
||||
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
|
||||
@ -651,7 +689,7 @@ public class WalletFacade
|
||||
public String sendFunds(String withdrawFromAddress,
|
||||
String withdrawToAddress,
|
||||
String changeAddress,
|
||||
BigInteger amount,
|
||||
Coin amount,
|
||||
FutureCallback<Transaction> callback) throws AddressFormatException, InsufficientMoneyException, IllegalArgumentException
|
||||
{
|
||||
Transaction tx = new Transaction(params);
|
||||
@ -673,7 +711,7 @@ public class WalletFacade
|
||||
}
|
||||
|
||||
|
||||
// TODO: Trade process - use P2SH instead and optimize data exchange
|
||||
// TODO: Trade process - use P2SH instead and optimize tx creation and data exchange
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Trade process
|
||||
@ -682,7 +720,7 @@ public class WalletFacade
|
||||
// 1. step: deposit tx
|
||||
// Offerer creates the 2of3 multiSig deposit tx with his unsigned input and change output
|
||||
|
||||
public Transaction offererCreatesMSTxAndAddPayment(BigInteger offererInputAmount,
|
||||
public Transaction offererCreatesMSTxAndAddPayment(Coin offererInputAmount,
|
||||
String offererPubKey,
|
||||
String takerPubKey,
|
||||
String arbitratorPubKey,
|
||||
@ -690,15 +728,15 @@ public class WalletFacade
|
||||
{
|
||||
log.debug("offererCreatesMSTxAndAddPayment");
|
||||
log.trace("inputs: ");
|
||||
log.trace("offererInputAmount=" + BtcFormatter.formatSatoshis(offererInputAmount));
|
||||
log.trace("offererInputAmount=" + offererInputAmount.toFriendlyString());
|
||||
log.trace("offererPubKey=" + offererPubKey);
|
||||
log.trace("takerPubKey=" + takerPubKey);
|
||||
log.trace("arbitratorPubKey=" + arbitratorPubKey);
|
||||
log.trace("offererInputAmount=" + BtcFormatter.formatSatoshis(offererInputAmount));
|
||||
log.trace("offererInputAmount=" + offererInputAmount.toFriendlyString());
|
||||
|
||||
// we need to subtract the fee as it will go to the miners
|
||||
BigInteger amountToPay = offererInputAmount.subtract(FeePolicy.TX_FEE);
|
||||
log.trace("amountToPay=" + BtcFormatter.formatSatoshis(amountToPay));
|
||||
Coin amountToPay = offererInputAmount.subtract(FeePolicy.TX_FEE);
|
||||
log.trace("amountToPay=" + amountToPay.toFriendlyString());
|
||||
|
||||
// We pay the offererInputAmount to a temporary MS output which will be changed later to the correct value.
|
||||
// With the usage of completeTx() we get all the work done with fee calculation, validation and coin selection.
|
||||
@ -742,8 +780,8 @@ public class WalletFacade
|
||||
// 2. step: deposit tx
|
||||
// Taker adds his input and change output, changes the multiSig amount to the correct value and sign his input
|
||||
|
||||
public Transaction takerAddPaymentAndSignTx(BigInteger takerInputAmount,
|
||||
BigInteger msOutputAmount,
|
||||
public Transaction takerAddPaymentAndSignTx(Coin takerInputAmount,
|
||||
Coin msOutputAmount,
|
||||
String offererPubKey,
|
||||
String takerPubKey,
|
||||
String arbitratorPubKey,
|
||||
@ -752,8 +790,8 @@ public class WalletFacade
|
||||
{
|
||||
log.debug("takerAddPaymentAndSignTx");
|
||||
log.trace("inputs: ");
|
||||
log.trace("takerInputAmount=" + BtcFormatter.formatSatoshis(takerInputAmount));
|
||||
log.trace("msOutputAmount=" + BtcFormatter.formatSatoshis(msOutputAmount));
|
||||
log.trace("takerInputAmount=" + takerInputAmount.toFriendlyString());
|
||||
log.trace("msOutputAmount=" + msOutputAmount.toFriendlyString());
|
||||
log.trace("offererPubKey=" + offererPubKey);
|
||||
log.trace("takerPubKey=" + takerPubKey);
|
||||
log.trace("arbitratorPubKey=" + arbitratorPubKey);
|
||||
@ -1017,21 +1055,21 @@ public class WalletFacade
|
||||
// 5. step payout tx: Offerer creates payout tx and signs it
|
||||
|
||||
public Pair<ECKey.ECDSASignature, String> offererCreatesAndSignsPayoutTx(String depositTxID,
|
||||
BigInteger offererPaybackAmount,
|
||||
BigInteger takerPaybackAmount,
|
||||
Coin offererPaybackAmount,
|
||||
Coin takerPaybackAmount,
|
||||
String takerAddress,
|
||||
String tradeID) throws AddressFormatException
|
||||
{
|
||||
log.debug("offererCreatesAndSignsPayoutTx");
|
||||
log.trace("inputs: ");
|
||||
log.trace("depositTxID=" + depositTxID);
|
||||
log.trace("offererPaybackAmount=" + BtcFormatter.formatSatoshis(offererPaybackAmount));
|
||||
log.trace("takerPaybackAmount=" + BtcFormatter.formatSatoshis(takerPaybackAmount));
|
||||
log.trace("offererPaybackAmount=" + offererPaybackAmount.toFriendlyString());
|
||||
log.trace("takerPaybackAmount=" + takerPaybackAmount.toFriendlyString());
|
||||
log.trace("takerAddress=" + takerAddress);
|
||||
|
||||
// Offerer has published depositTx earlier, so he has it in his wallet
|
||||
Transaction depositTx = wallet.getTransaction(new Sha256Hash(depositTxID));
|
||||
String depositTxAsHex = Utils.bytesToHexString(depositTx.bitcoinSerialize());
|
||||
String depositTxAsHex = Utils.HEX.encode(depositTx.bitcoinSerialize());
|
||||
|
||||
// We create the payout tx
|
||||
Transaction tx = createPayoutTx(depositTxAsHex, offererPaybackAmount, takerPaybackAmount, getAddressInfoByTradeID(tradeID).getAddressString(), takerAddress);
|
||||
@ -1054,8 +1092,8 @@ public class WalletFacade
|
||||
public void takerSignsAndSendsTx(String depositTxAsHex,
|
||||
String offererSignatureR,
|
||||
String offererSignatureS,
|
||||
BigInteger offererPaybackAmount,
|
||||
BigInteger takerPaybackAmount,
|
||||
Coin offererPaybackAmount,
|
||||
Coin takerPaybackAmount,
|
||||
String offererAddress,
|
||||
String tradeID,
|
||||
FutureCallback<Transaction> callback) throws AddressFormatException
|
||||
@ -1065,8 +1103,8 @@ public class WalletFacade
|
||||
log.trace("depositTxAsHex=" + depositTxAsHex);
|
||||
log.trace("offererSignatureR=" + offererSignatureR);
|
||||
log.trace("offererSignatureS=" + offererSignatureS);
|
||||
log.trace("offererPaybackAmount=" + BtcFormatter.formatSatoshis(offererPaybackAmount));
|
||||
log.trace("takerPaybackAmount=" + BtcFormatter.formatSatoshis(takerPaybackAmount));
|
||||
log.trace("offererPaybackAmount=" + offererPaybackAmount.toFriendlyString());
|
||||
log.trace("takerPaybackAmount=" + takerPaybackAmount.toFriendlyString());
|
||||
log.trace("offererAddress=" + offererAddress);
|
||||
log.trace("callback=" + callback);
|
||||
|
||||
@ -1124,24 +1162,25 @@ public class WalletFacade
|
||||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
private Script getMultiSigScript(String offererPubKey, String takerPubKey, String arbitratorPubKey)
|
||||
{
|
||||
ECKey offererKey = new ECKey(null, Utils.parseAsHexOrBase58(offererPubKey));
|
||||
ECKey takerKey = new ECKey(null, Utils.parseAsHexOrBase58(takerPubKey));
|
||||
ECKey arbitratorKey = new ECKey(null, Utils.parseAsHexOrBase58(arbitratorPubKey));
|
||||
ECKey offererKey = wallet.findKeyFromPubKey(Utils.parseAsHexOrBase58(offererPubKey));
|
||||
ECKey takerKey = ECKey.fromPublicOnly(Utils.parseAsHexOrBase58(takerPubKey));
|
||||
ECKey arbitratorKey = ECKey.fromPublicOnly(Utils.parseAsHexOrBase58(arbitratorPubKey));
|
||||
|
||||
List<ECKey> keys = ImmutableList.of(offererKey, takerKey, arbitratorKey);
|
||||
return ScriptBuilder.createMultiSigOutputScript(2, keys);
|
||||
}
|
||||
|
||||
|
||||
private Transaction createPayoutTx(String depositTxAsHex, BigInteger offererPaybackAmount, BigInteger takerPaybackAmount, String offererAddress, String takerAddress) throws AddressFormatException
|
||||
private Transaction createPayoutTx(String depositTxAsHex, Coin offererPaybackAmount, Coin takerPaybackAmount, String offererAddress, String takerAddress) throws AddressFormatException
|
||||
{
|
||||
log.trace("createPayoutTx");
|
||||
log.trace("inputs: ");
|
||||
log.trace("depositTxAsHex=" + depositTxAsHex);
|
||||
log.trace("offererPaybackAmount=" + BtcFormatter.formatSatoshis(offererPaybackAmount));
|
||||
log.trace("takerPaybackAmount=" + BtcFormatter.formatSatoshis(takerPaybackAmount));
|
||||
log.trace("offererPaybackAmount=" + offererPaybackAmount.toFriendlyString());
|
||||
log.trace("takerPaybackAmount=" + takerPaybackAmount.toFriendlyString());
|
||||
log.trace("offererAddress=" + offererAddress);
|
||||
log.trace("takerAddress=" + takerAddress);
|
||||
|
||||
@ -1161,7 +1200,7 @@ public class WalletFacade
|
||||
{
|
||||
if (input.getConnectedOutput() != null)
|
||||
{
|
||||
log.trace(tracePrefix + " input value : " + BtcFormatter.formatSatoshis(input.getConnectedOutput().getValue()));
|
||||
log.trace(tracePrefix + " input value : " + input.getConnectedOutput().getValue().toFriendlyString());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1175,6 +1214,11 @@ public class WalletFacade
|
||||
// Inner classes
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static interface StartupListener
|
||||
{
|
||||
void completed();
|
||||
}
|
||||
|
||||
public static interface DownloadListener
|
||||
{
|
||||
void progress(double percent);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package io.bitsquare.btc.listeners;
|
||||
|
||||
import com.google.bitcoin.core.Address;
|
||||
import java.math.BigInteger;
|
||||
import com.google.bitcoin.core.Coin;
|
||||
|
||||
public class BalanceListener
|
||||
{
|
||||
@ -21,7 +21,7 @@ public class BalanceListener
|
||||
return address;
|
||||
}
|
||||
|
||||
public void onBalanceChanged(BigInteger balance)
|
||||
public void onBalanceChanged(Coin balance)
|
||||
{
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ public class CryptoFacade
|
||||
|
||||
public boolean verifyHash(String hashAsHexStringToVerify, String msg, String sig)
|
||||
{
|
||||
String hashAsHexString = Utils.bytesToHexString(createHash(msg, sig));
|
||||
String hashAsHexString = Utils.HEX.encode(createHash(msg, sig));
|
||||
return hashAsHexString.equals(hashAsHexStringToVerify);
|
||||
}
|
||||
|
||||
|
@ -9,11 +9,11 @@ import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.name.Named;
|
||||
import com.google.inject.name.Names;
|
||||
import io.bitsquare.btc.BitSquareWalletAppKit;
|
||||
import io.bitsquare.btc.BlockChainFacade;
|
||||
import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.crypto.CryptoFacade;
|
||||
import io.bitsquare.gui.util.BitSquareFormatter;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.SeedNodeAddress;
|
||||
import io.bitsquare.settings.Settings;
|
||||
@ -22,7 +22,6 @@ import io.bitsquare.trade.Trading;
|
||||
import io.bitsquare.trade.orderbook.OrderBook;
|
||||
import io.bitsquare.trade.orderbook.OrderBookFilter;
|
||||
import io.bitsquare.user.User;
|
||||
import io.bitsquare.util.StorageDirectory;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class BitSquareModule extends AbstractModule
|
||||
@ -45,6 +44,8 @@ public class BitSquareModule extends AbstractModule
|
||||
bind(MessageFacade.class).asEagerSingleton();
|
||||
|
||||
bind(Trading.class).asEagerSingleton();
|
||||
bind(BitSquareFormatter.class).asEagerSingleton();
|
||||
|
||||
|
||||
//bind(String.class).annotatedWith(Names.named("networkType")).toInstance(WalletFacade.MAIN_NET);
|
||||
// how to use reg test see description in the readme file
|
||||
@ -52,7 +53,6 @@ public class BitSquareModule extends AbstractModule
|
||||
//test net not working yet: http://sourceforge.net/p/bitcoin/mailman/message/32349208/
|
||||
//bind(String.class).annotatedWith(Names.named("networkType")).toInstance(WalletFacade.TEST_NET);
|
||||
bind(NetworkParameters.class).toProvider(NetworkParametersProvider.class).asEagerSingleton();
|
||||
bind(BitSquareWalletAppKit.class).toProvider(BitSquareWalletAppKitProvider.class).asEagerSingleton();
|
||||
|
||||
// bind(Boolean.class).annotatedWith(Names.named("useDiskStorage")).toInstance(new Boolean(true));
|
||||
bind(Boolean.class).annotatedWith(Names.named("useDiskStorage")).toInstance(new Boolean(false));
|
||||
@ -61,23 +61,6 @@ public class BitSquareModule extends AbstractModule
|
||||
}
|
||||
}
|
||||
|
||||
class BitSquareWalletAppKitProvider implements Provider<BitSquareWalletAppKit>
|
||||
{
|
||||
private final NetworkParameters networkParameters;
|
||||
|
||||
@Inject
|
||||
public BitSquareWalletAppKitProvider(NetworkParameters networkParameters)
|
||||
{
|
||||
this.networkParameters = networkParameters;
|
||||
}
|
||||
|
||||
|
||||
public BitSquareWalletAppKit get()
|
||||
{
|
||||
return new BitSquareWalletAppKit(networkParameters, StorageDirectory.getStorageDirectory());
|
||||
}
|
||||
}
|
||||
|
||||
class NetworkParametersProvider implements Provider<NetworkParameters>
|
||||
{
|
||||
private final String networkType;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package io.bitsquare.gui;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import io.bitsquare.bank.BankAccount;
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.btc.listeners.BalanceListener;
|
||||
import io.bitsquare.di.GuiceFXMLLoader;
|
||||
@ -19,7 +19,6 @@ import io.bitsquare.trade.Trading;
|
||||
import io.bitsquare.user.User;
|
||||
import io.bitsquare.util.AWTSystemTray;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.application.Platform;
|
||||
@ -59,6 +58,8 @@ public class MainController implements Initializable, NavigationController
|
||||
private Image prevToggleButtonIcon;
|
||||
private ToggleButton buyButton, sellButton, homeButton, msgButton, ordersButton, fundsButton, settingsButton;
|
||||
private Pane ordersButtonButtonHolder;
|
||||
private boolean messageFacadeInited;
|
||||
private boolean walletFacadeInited;
|
||||
|
||||
@FXML
|
||||
private Pane contentPane;
|
||||
@ -182,21 +183,15 @@ public class MainController implements Initializable, NavigationController
|
||||
@Override
|
||||
public void onCompleted()
|
||||
{
|
||||
messageFacadeInited();
|
||||
messageFacadeInited = true;
|
||||
if (walletFacadeInited) initialisationDone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Throwable throwable)
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void messageFacadeInited()
|
||||
{
|
||||
|
||||
trading.addTakeOfferRequestListener(this::onTakeOfferRequested);
|
||||
|
||||
walletFacade.addDownloadListener(new WalletFacade.DownloadListener()
|
||||
{
|
||||
@ -212,9 +207,16 @@ public class MainController implements Initializable, NavigationController
|
||||
networkSyncPane.doneDownload();
|
||||
}
|
||||
});
|
||||
walletFacade.initialize(() -> {
|
||||
walletFacadeInited = true;
|
||||
if (messageFacadeInited) initialisationDone();
|
||||
});
|
||||
|
||||
walletFacade.initWallet();
|
||||
trading.addTakeOfferRequestListener(this::onTakeOfferRequested);
|
||||
}
|
||||
|
||||
private void initialisationDone()
|
||||
{
|
||||
addNavigation();
|
||||
|
||||
Transitions.fadeOutAndRemove(loadingLabel);
|
||||
@ -320,13 +322,13 @@ public class MainController implements Initializable, NavigationController
|
||||
balanceTextField.setEditable(false);
|
||||
balanceTextField.setPrefWidth(90);
|
||||
balanceTextField.setId("nav-balance-label");
|
||||
balanceTextField.setText(BtcFormatter.formatSatoshis(walletFacade.getWalletBalance()));
|
||||
balanceTextField.setText(walletFacade.getWalletBalance().toFriendlyString());
|
||||
walletFacade.addBalanceListener(new BalanceListener()
|
||||
{
|
||||
@Override
|
||||
public void onBalanceChanged(BigInteger balance)
|
||||
public void onBalanceChanged(Coin balance)
|
||||
{
|
||||
balanceTextField.setText(BtcFormatter.formatSatoshis(balance));
|
||||
balanceTextField.setText(balance.toFriendlyString());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
package io.bitsquare.gui.arbitrators.registration;
|
||||
|
||||
import com.google.bitcoin.core.ECKey;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.bitcoin.core.Wallet;
|
||||
import com.google.bitcoin.core.WalletEventListener;
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.script.Script;
|
||||
import de.jensd.fx.fontawesome.AwesomeDude;
|
||||
import de.jensd.fx.fontawesome.AwesomeIcon;
|
||||
@ -24,7 +21,6 @@ import io.bitsquare.user.Arbitrator;
|
||||
import io.bitsquare.user.Reputation;
|
||||
import io.bitsquare.user.User;
|
||||
import io.bitsquare.util.DSAKeyUtil;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import javafx.collections.FXCollections;
|
||||
@ -376,44 +372,50 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon
|
||||
});
|
||||
|
||||
confidenceDisplay = new ConfidenceDisplay(walletFacade.getWallet(), confirmationLabel, balanceTextField, progressIndicator);
|
||||
paymentDoneButton.setDisable(walletFacade.getArbitratorDepositBalance().compareTo(BigInteger.ZERO) == 0);
|
||||
paymentDoneButton.setDisable(walletFacade.getArbitratorDepositBalance().isZero());
|
||||
log.debug("getArbitratorDepositBalance " + walletFacade.getArbitratorDepositBalance());
|
||||
walletFacade.getWallet().addEventListener(new WalletEventListener()
|
||||
{
|
||||
@Override
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
|
||||
{
|
||||
paymentDoneButton.setDisable(newBalance.compareTo(BigInteger.ZERO) == 0);
|
||||
paymentDoneButton.setDisable(newBalance.isZero());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReorganize(Wallet wallet)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalletChanged(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(Wallet wallet, List<ECKey> keys)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScriptsAdded(Wallet wallet, List<Script> scripts)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(List<ECKey> keys)
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
package io.bitsquare.gui.components.btc;
|
||||
|
||||
import com.google.bitcoin.core.Address;
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.TransactionConfidence;
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.btc.listeners.BalanceListener;
|
||||
import io.bitsquare.btc.listeners.ConfidenceListener;
|
||||
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
||||
import java.math.BigInteger;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
@ -80,7 +79,7 @@ public class BalanceTextField extends AnchorPane
|
||||
balanceListener = walletFacade.addBalanceListener(new BalanceListener(address)
|
||||
{
|
||||
@Override
|
||||
public void onBalanceChanged(BigInteger balance)
|
||||
public void onBalanceChanged(Coin balance)
|
||||
{
|
||||
updateBalance(balance);
|
||||
}
|
||||
@ -133,11 +132,12 @@ public class BalanceTextField extends AnchorPane
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBalance(BigInteger balance)
|
||||
private void updateBalance(Coin balance)
|
||||
{
|
||||
if (balance != null)
|
||||
{
|
||||
balanceTextField.setText(BtcFormatter.formatSatoshis(balance));
|
||||
//TODO use BitSquareFormatter
|
||||
balanceTextField.setText(balance.toFriendlyString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,10 @@
|
||||
package io.bitsquare.gui.funds.transactions;
|
||||
|
||||
import com.google.bitcoin.core.Address;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.bitcoin.core.TransactionConfidence;
|
||||
import com.google.bitcoin.core.TransactionOutput;
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
import com.google.bitcoin.core.*;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.btc.listeners.ConfidenceListener;
|
||||
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
||||
import io.bitsquare.gui.util.BitSquareFormatter;
|
||||
import java.math.BigInteger;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.scene.control.Tooltip;
|
||||
@ -35,12 +30,13 @@ public class TransactionsListItem
|
||||
{
|
||||
this.walletFacade = walletFacade;
|
||||
|
||||
BigInteger valueSentToMe = transaction.getValueSentToMe(walletFacade.getWallet());
|
||||
BigInteger valueSentFromMe = transaction.getValueSentFromMe(walletFacade.getWallet());
|
||||
Coin valueSentToMe = transaction.getValueSentToMe(walletFacade.getWallet());
|
||||
Coin valueSentFromMe = transaction.getValueSentFromMe(walletFacade.getWallet());
|
||||
Address address = null;
|
||||
if (valueSentToMe.compareTo(BigInteger.ZERO) == 0)
|
||||
if (valueSentToMe.isZero())
|
||||
{
|
||||
amount.set("-" + BtcFormatter.formatSatoshis(valueSentFromMe));
|
||||
//TODO use BitSquareFormatter
|
||||
amount.set("-" + valueSentFromMe.toFriendlyString());
|
||||
|
||||
for (TransactionOutput transactionOutput : transaction.getOutputs())
|
||||
{
|
||||
@ -48,7 +44,7 @@ public class TransactionsListItem
|
||||
{
|
||||
type.set("Sent to");
|
||||
|
||||
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH())
|
||||
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isPayToScriptHash())
|
||||
{
|
||||
address = transactionOutput.getScriptPubKey().getToAddress(walletFacade.getWallet().getParams());
|
||||
addressString = address.toString();
|
||||
@ -60,16 +56,17 @@ public class TransactionsListItem
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (valueSentFromMe.compareTo(BigInteger.ZERO) == 0)
|
||||
else if (valueSentFromMe.isZero())
|
||||
{
|
||||
amount.set(BtcFormatter.formatSatoshis(valueSentToMe));
|
||||
//TODO use BitSquareFormatter
|
||||
amount.set(valueSentToMe.toFriendlyString());
|
||||
type.set("Received with");
|
||||
|
||||
for (TransactionOutput transactionOutput : transaction.getOutputs())
|
||||
{
|
||||
if (transactionOutput.isMine(walletFacade.getWallet()))
|
||||
{
|
||||
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH())
|
||||
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isPayToScriptHash())
|
||||
{
|
||||
address = transactionOutput.getScriptPubKey().getToAddress(walletFacade.getWallet().getParams());
|
||||
addressString = address.toString();
|
||||
@ -83,7 +80,8 @@ public class TransactionsListItem
|
||||
}
|
||||
else
|
||||
{
|
||||
amount.set(BtcFormatter.formatSatoshis(valueSentToMe.subtract(valueSentFromMe)));
|
||||
//TODO use BitSquareFormatter
|
||||
amount.set(valueSentToMe.subtract(valueSentFromMe).toFriendlyString());
|
||||
|
||||
boolean outgoing = false;
|
||||
for (TransactionOutput transactionOutput : transaction.getOutputs())
|
||||
@ -91,7 +89,7 @@ public class TransactionsListItem
|
||||
if (!transactionOutput.isMine(walletFacade.getWallet()))
|
||||
{
|
||||
outgoing = true;
|
||||
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH())
|
||||
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isPayToScriptHash())
|
||||
{
|
||||
address = transactionOutput.getScriptPubKey().getToAddress(walletFacade.getWallet().getParams());
|
||||
addressString = address.toString();
|
||||
|
@ -1,18 +1,22 @@
|
||||
package io.bitsquare.gui.funds.withdrawal;
|
||||
|
||||
import com.google.bitcoin.core.AddressFormatException;
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.InsufficientMoneyException;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import de.jensd.fx.fontawesome.AwesomeDude;
|
||||
import de.jensd.fx.fontawesome.AwesomeIcon;
|
||||
import io.bitsquare.btc.*;
|
||||
import io.bitsquare.btc.AddressEntry;
|
||||
import io.bitsquare.btc.BtcValidator;
|
||||
import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.ChildController;
|
||||
import io.bitsquare.gui.Hibernate;
|
||||
import io.bitsquare.gui.NavigationController;
|
||||
import io.bitsquare.gui.popups.Popups;
|
||||
import io.bitsquare.gui.util.BitSquareFormatter;
|
||||
import io.bitsquare.gui.util.BitSquareValidator;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
@ -81,9 +85,9 @@ public class WithdrawalController implements Initializable, ChildController, Hib
|
||||
{
|
||||
BitSquareValidator.resetTextFields(withdrawFromTextField, withdrawToTextField, amountTextField, changeAddressTextField);
|
||||
|
||||
if (BigInteger.ZERO.compareTo(newValue.getBalance()) <= 0)
|
||||
if (Coin.ZERO.compareTo(newValue.getBalance()) <= 0)
|
||||
{
|
||||
amountTextField.setText(BtcFormatter.formatSatoshis(newValue.getBalance()));
|
||||
amountTextField.setText(newValue.getBalance().toPlainString());
|
||||
withdrawFromTextField.setText(newValue.getAddressEntry().getAddressString());
|
||||
changeAddressTextField.setText(newValue.getAddressEntry().getAddressString());
|
||||
}
|
||||
@ -151,7 +155,7 @@ public class WithdrawalController implements Initializable, ChildController, Hib
|
||||
BitSquareValidator.textFieldsNotEmpty(amountTextField, withdrawFromTextField, withdrawToTextField, changeAddressTextField);
|
||||
BitSquareValidator.textFieldsHasDoubleValueWithReset(amountTextField);
|
||||
|
||||
BigInteger amount = BtcFormatter.stringValueToSatoshis(amountTextField.getText());
|
||||
Coin amount = BitSquareFormatter.parseBtcToCoin(amountTextField.getText());
|
||||
if (BtcValidator.isMinSpendableAmount(amount))
|
||||
{
|
||||
FutureCallback<Transaction> callback = new FutureCallback<Transaction>()
|
||||
@ -177,8 +181,8 @@ public class WithdrawalController implements Initializable, ChildController, Hib
|
||||
"Amount: " + amountTextField.getText() + " BTC\n" +
|
||||
"Sending address: " + withdrawFromTextField.getText() + "\n" +
|
||||
"Receiving address: " + withdrawToTextField.getText() + "\n" +
|
||||
"Transaction fee: " + BtcFormatter.formatSatoshis(FeePolicy.TX_FEE) + "\n" +
|
||||
"You receive in total: " + BtcFormatter.formatSatoshis(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" +
|
||||
"Transaction fee: " + BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.TX_FEE) + "\n" +
|
||||
"You receive in total: " + BitSquareFormatter.formatCoinToBtcWithCode(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" +
|
||||
"Are you sure you withdraw that amount?");
|
||||
if (response == Dialog.Actions.OK)
|
||||
{
|
||||
|
@ -1,14 +1,13 @@
|
||||
package io.bitsquare.gui.funds.withdrawal;
|
||||
|
||||
import com.google.bitcoin.core.Address;
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.TransactionConfidence;
|
||||
import io.bitsquare.btc.AddressEntry;
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.btc.listeners.BalanceListener;
|
||||
import io.bitsquare.btc.listeners.ConfidenceListener;
|
||||
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
||||
import java.math.BigInteger;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.scene.control.Label;
|
||||
@ -30,7 +29,7 @@ public class WithdrawalListItem
|
||||
|
||||
private final Tooltip tooltip;
|
||||
|
||||
private BigInteger balance;
|
||||
private Coin balance;
|
||||
|
||||
public WithdrawalListItem(AddressEntry addressEntry, WalletFacade walletFacade)
|
||||
{
|
||||
@ -63,7 +62,7 @@ public class WithdrawalListItem
|
||||
balanceListener = walletFacade.addBalanceListener(new BalanceListener(getAddress())
|
||||
{
|
||||
@Override
|
||||
public void onBalanceChanged(BigInteger balance)
|
||||
public void onBalanceChanged(Coin balance)
|
||||
{
|
||||
updateBalance(balance);
|
||||
}
|
||||
@ -78,12 +77,13 @@ public class WithdrawalListItem
|
||||
walletFacade.removeBalanceListener(balanceListener);
|
||||
}
|
||||
|
||||
private void updateBalance(BigInteger balance)
|
||||
private void updateBalance(Coin balance)
|
||||
{
|
||||
this.balance = balance;
|
||||
if (balance != null)
|
||||
{
|
||||
balanceLabel.setText(BtcFormatter.formatSatoshis(balance));
|
||||
//TODO use BitSquareFormatter
|
||||
balanceLabel.setText(balance.toFriendlyString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ public class WithdrawalListItem
|
||||
}
|
||||
|
||||
|
||||
public BigInteger getBalance()
|
||||
public Coin getBalance()
|
||||
{
|
||||
return balance;
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package io.bitsquare.gui.market.createOffer;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.InsufficientMoneyException;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import io.bitsquare.BitSquare;
|
||||
import io.bitsquare.bank.BankAccount;
|
||||
import io.bitsquare.btc.AddressEntry;
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.ChildController;
|
||||
@ -19,6 +19,7 @@ import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
||||
import io.bitsquare.gui.popups.Popups;
|
||||
import io.bitsquare.gui.util.BitSquareConverter;
|
||||
import io.bitsquare.gui.util.BitSquareFormatter;
|
||||
import io.bitsquare.gui.util.BitSquareValidator;
|
||||
import io.bitsquare.locale.Localisation;
|
||||
import io.bitsquare.settings.Settings;
|
||||
import io.bitsquare.trade.Direction;
|
||||
@ -28,7 +29,6 @@ import io.bitsquare.trade.orderbook.OrderBookFilter;
|
||||
import io.bitsquare.user.Arbitrator;
|
||||
import io.bitsquare.user.User;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.util.Random;
|
||||
import java.util.ResourceBundle;
|
||||
@ -53,6 +53,7 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
private final Settings settings;
|
||||
private final User user;
|
||||
|
||||
|
||||
private NavigationController navigationController;
|
||||
private Direction direction;
|
||||
private Offer offer;
|
||||
@ -61,7 +62,7 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
@FXML
|
||||
private AnchorPane rootContainer;
|
||||
@FXML
|
||||
private Label buyLabel, placeOfferTitle, confirmationLabel, txTitleLabel;
|
||||
private Label buyLabel, placeOfferTitle, confirmationLabel, txTitleLabel, collateralLabel;
|
||||
@FXML
|
||||
private TextField volumeTextField, amountTextField, priceTextField, totalTextField;
|
||||
@FXML
|
||||
@ -85,6 +86,7 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
this.walletFacade = walletFacade;
|
||||
this.settings = settings;
|
||||
this.user = user;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -95,11 +97,15 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
public void setOrderBookFilter(OrderBookFilter orderBookFilter)
|
||||
{
|
||||
direction = orderBookFilter.getDirection();
|
||||
//TODO
|
||||
amountTextField.setText(BitSquareFormatter.formatPrice(orderBookFilter.getAmount()));
|
||||
//TODO
|
||||
minAmountTextField.setText(BitSquareFormatter.formatPrice(orderBookFilter.getAmount()));
|
||||
|
||||
priceTextField.setText(BitSquareFormatter.formatPrice(orderBookFilter.getPrice()));
|
||||
buyLabel.setText(BitSquareFormatter.formatDirection(direction, false) + ":");
|
||||
collateralTextField.setText(BitSquareFormatter.formatVolume(settings.getMinCollateral()));
|
||||
collateralLabel.setText("Collateral (" + getCollateralAsPercent() + "):");
|
||||
|
||||
updateVolume();
|
||||
updateTotals();
|
||||
|
||||
@ -109,18 +115,17 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
//amountTextField.setText("" + (int) (new Random().nextDouble() * 100 / 10 + 1));
|
||||
amountTextField.setText("1");
|
||||
priceTextField.setText("" + (int) (499 - new Random().nextDouble() * 1000 / 100));
|
||||
minAmountTextField.setText("0,1");
|
||||
minAmountTextField.setText("0.1");
|
||||
}
|
||||
|
||||
//TODO derive form arbitrators
|
||||
collateralTextField.setText("10");
|
||||
|
||||
updateVolume();
|
||||
updateTotals();
|
||||
applyCollateral();
|
||||
|
||||
amountTextField.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
updateVolume();
|
||||
updateTotals();
|
||||
applyCollateral();
|
||||
});
|
||||
|
||||
priceTextField.textProperty().addListener((observable, oldValue, newValue) -> updateVolume());
|
||||
@ -143,7 +148,7 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
}
|
||||
acceptedCountriesTextField.setText(BitSquareFormatter.countryLocalesToString(settings.getAcceptedCountries()));
|
||||
acceptedLanguagesTextField.setText(BitSquareFormatter.languageLocalesToString(settings.getAcceptedLanguageLocales()));
|
||||
feeLabel.setText(BtcFormatter.formatSatoshis(FeePolicy.CREATE_OFFER_FEE));
|
||||
feeLabel.setText(BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.CREATE_OFFER_FEE.add(FeePolicy.TX_FEE)));
|
||||
|
||||
addressEntry = walletFacade.getUnusedTradeAddressInfo();
|
||||
addressTextField.setAddress(addressEntry.getAddress().toString());
|
||||
@ -197,8 +202,9 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
return;
|
||||
}
|
||||
|
||||
int collateral = (int) (BitSquareConverter.stringToDouble(collateralTextField.getText()));
|
||||
Arbitrator arbitrator = settings.getRandomArbitrator(collateral, getAmountAsBI());
|
||||
//TODO will be derived form arbitrators
|
||||
double collateral = getCollateral();
|
||||
Arbitrator arbitrator = settings.getRandomArbitrator(collateral, getAmountAsCoin());
|
||||
if (arbitrator == null)
|
||||
{
|
||||
Popups.openWarningPopup("No arbitrator available", "No arbitrator from your arbitrator list does match the collateral and amount value.");
|
||||
@ -207,11 +213,14 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
|
||||
if (user.getCurrentBankAccount() != null)
|
||||
{
|
||||
Coin amountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
Coin minAmountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
|
||||
offer = new Offer(user.getMessagePublicKey(),
|
||||
direction,
|
||||
BitSquareConverter.stringToDouble(priceTextField.getText()),
|
||||
BtcFormatter.stringValueToSatoshis(amountTextField.getText()),
|
||||
BtcFormatter.stringValueToSatoshis(minAmountTextField.getText()),
|
||||
amountAsCoin,
|
||||
minAmountAsCoin,
|
||||
user.getCurrentBankAccount().getBankAccountType(),
|
||||
user.getCurrentBankAccount().getCurrency(),
|
||||
user.getCurrentBankAccount().getCountry(),
|
||||
@ -292,12 +301,10 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
|
||||
private void updateTotals()
|
||||
{
|
||||
double amountAsDouble = BitSquareConverter.stringToDouble(amountTextField.getText());
|
||||
double collateralPercentAsDouble = BitSquareConverter.stringToDouble(collateralTextField.getText());
|
||||
double collateralAmountAsDouble = collateralPercentAsDouble * amountAsDouble / 100;
|
||||
BigInteger collateral = BtcFormatter.doubleValueToSatoshis(collateralAmountAsDouble);
|
||||
BigInteger totals = FeePolicy.CREATE_OFFER_FEE.add(collateral).add(FeePolicy.TX_FEE);
|
||||
totalTextField.setText(BtcFormatter.formatSatoshis(totals));
|
||||
Coin amountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
Coin collateral = amountAsCoin.divide((long) (1d / getCollateral()));
|
||||
Coin totals = FeePolicy.CREATE_OFFER_FEE.add(collateral).add(FeePolicy.TX_FEE);
|
||||
totalTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(totals));
|
||||
}
|
||||
|
||||
private void updateVolume()
|
||||
@ -307,23 +314,57 @@ public class CreateOfferController implements Initializable, ChildController, Hi
|
||||
|
||||
private double getVolume()
|
||||
{
|
||||
double amountAsDouble = BitSquareConverter.stringToDouble(amountTextField.getText());
|
||||
double amountAsDouble = BitSquareConverter.stringToDouble(getAmountString());
|
||||
double priceAsDouble = BitSquareConverter.stringToDouble(priceTextField.getText());
|
||||
return amountAsDouble * priceAsDouble;
|
||||
}
|
||||
|
||||
private BigInteger getAmountAsBI()
|
||||
private void applyCollateral()
|
||||
{
|
||||
return BtcFormatter.stringValueToSatoshis(amountTextField.getText());
|
||||
collateralTextField.setText(getFormattedCollateralAsBtc());
|
||||
}
|
||||
|
||||
private String getFormattedCollateralAsBtc()
|
||||
{
|
||||
Coin amountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
Coin collateralAsCoin = amountAsCoin.divide((long) (1d / getCollateral()));
|
||||
return BitSquareFormatter.formatCoinToBtc(collateralAsCoin);
|
||||
}
|
||||
|
||||
private String getCollateralAsPercent()
|
||||
{
|
||||
return BitSquareFormatter.formatCollateralPercent(getCollateral());
|
||||
}
|
||||
|
||||
|
||||
private Coin getAmountAsCoin()
|
||||
{
|
||||
return BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
}
|
||||
|
||||
private String getAmountString()
|
||||
{
|
||||
try
|
||||
{
|
||||
BitSquareValidator.textFieldsHasPositiveDoubleValueWithReset(amountTextField);
|
||||
return amountTextField.getText();
|
||||
} catch (BitSquareValidator.ValidationException e)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
private double getCollateral()
|
||||
{
|
||||
// TODO
|
||||
return settings.getCollateral();
|
||||
}
|
||||
|
||||
//TODO
|
||||
@SuppressWarnings("UnusedAssignment")
|
||||
private boolean inputValid()
|
||||
{
|
||||
double priceAsDouble = BitSquareConverter.stringToDouble(priceTextField.getText());
|
||||
double minAmountAsDouble = BitSquareConverter.stringToDouble(minAmountTextField.getText());
|
||||
double amountAsDouble = BitSquareConverter.stringToDouble(amountTextField.getText());
|
||||
double amountAsDouble = BitSquareConverter.stringToDouble(getAmountString());
|
||||
double collateralAsDouble = BitSquareConverter.stringToDouble(collateralTextField.getText());
|
||||
|
||||
return priceAsDouble > 0 &&
|
||||
|
@ -27,19 +27,19 @@
|
||||
<Label text="Min. Amount:" GridPane.rowIndex="2"/>
|
||||
<TextField fx:id="minAmountTextField" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
|
||||
|
||||
<Label text="Collateral (%):" GridPane.rowIndex="3"/>
|
||||
<Label fx:id="collateralLabel" text="Collateral:" GridPane.rowIndex="3"/>
|
||||
<TextField fx:id="collateralTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
|
||||
|
||||
<Label text="Offer fee:" GridPane.rowIndex="4"/>
|
||||
<Label text="Total Fees (Offer + tx)" GridPane.rowIndex="4"/>
|
||||
<TextField fx:id="feeLabel" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
|
||||
|
||||
<Label text="Total BTC funds needed:" GridPane.rowIndex="5"/>
|
||||
<Label text="Total funds needed:" GridPane.rowIndex="5"/>
|
||||
<TextField fx:id="totalTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="5"/>
|
||||
|
||||
<Label text="BTC address for deposit:" GridPane.rowIndex="6"/>
|
||||
<AddressTextField fx:id="addressTextField" GridPane.columnIndex="1" GridPane.rowIndex="6"/>
|
||||
|
||||
<Label text="Balance:" GridPane.rowIndex="7"/>
|
||||
<Label text="Actual balance:" GridPane.rowIndex="7"/>
|
||||
<BalanceTextField fx:id="balanceTextField" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
|
||||
|
||||
<!--
|
||||
|
@ -1,10 +1,10 @@
|
||||
package io.bitsquare.gui.market.orderbook;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.InsufficientMoneyException;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import io.bitsquare.bank.BankAccountType;
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.ChildController;
|
||||
@ -29,7 +29,6 @@ import io.bitsquare.trade.orderbook.OrderBook;
|
||||
import io.bitsquare.trade.orderbook.OrderBookFilter;
|
||||
import io.bitsquare.user.User;
|
||||
import io.bitsquare.util.Utilities;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
@ -66,6 +65,7 @@ public class OrderBookController implements Initializable, ChildController
|
||||
private final WalletFacade walletFacade;
|
||||
private final Settings settings;
|
||||
private final Persistence persistence;
|
||||
|
||||
private final Image buyIcon = Icons.getIconImage(Icons.BUY);
|
||||
private final Image sellIcon = Icons.getIconImage(Icons.SELL);
|
||||
@FXML
|
||||
@ -230,7 +230,7 @@ public class OrderBookController implements Initializable, ChildController
|
||||
else
|
||||
{
|
||||
Action response = Popups.openErrorPopup("Missing registration fee",
|
||||
"You have not funded the full registration fee of " + BtcFormatter.formatSatoshis(FeePolicy.ACCOUNT_REGISTRATION_FEE) + " BTC.");
|
||||
"You have not funded the full registration fee of " + BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.ACCOUNT_REGISTRATION_FEE) + " BTC.");
|
||||
if (response == Dialog.Actions.OK)
|
||||
{
|
||||
MainController.GET_INSTANCE().navigateToView(NavigationItem.FUNDS);
|
||||
@ -341,10 +341,10 @@ public class OrderBookController implements Initializable, ChildController
|
||||
{
|
||||
TakerOfferController takerOfferController = (TakerOfferController) navigationController.navigateToView(NavigationItem.TAKE_OFFER);
|
||||
|
||||
BigInteger requestedAmount;
|
||||
Coin requestedAmount;
|
||||
if (!"".equals(amount.getText()))
|
||||
{
|
||||
requestedAmount = BtcFormatter.stringValueToSatoshis(amount.getText());
|
||||
requestedAmount = BitSquareFormatter.parseBtcToCoin(amount.getText());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.bitsquare.gui.market.orderbook;
|
||||
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
import io.bitsquare.gui.util.BitSquareFormatter;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
@ -20,11 +19,7 @@ public class OrderBookListItem
|
||||
{
|
||||
this.offer = offer;
|
||||
this.price.set(BitSquareFormatter.formatPrice(offer.getPrice()));
|
||||
|
||||
double amountAsBtcDouble = BtcFormatter.satoshiToBTC(offer.getAmount());
|
||||
double minAmountAsBtcDouble = BtcFormatter.satoshiToBTC(offer.getMinAmount());
|
||||
this.amount.set(BitSquareFormatter.formatAmountWithMinAmount(amountAsBtcDouble, minAmountAsBtcDouble));
|
||||
|
||||
this.amount.set(BitSquareFormatter.formatCoinToBtc(offer.getAmount()) + " (" + BitSquareFormatter.formatCoinToBtc(offer.getMinAmount()) + ")");
|
||||
this.volume.set(BitSquareFormatter.formatVolumeWithMinVolume(offer.getVolume(), offer.getMinVolume()));
|
||||
}
|
||||
|
||||
|
@ -27,13 +27,13 @@
|
||||
<Label text="Volume (EUR):" GridPane.rowIndex="3"/>
|
||||
<TextField fx:id="volumeTextField" editable="false" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
|
||||
|
||||
<Label text="Collateral (BTC):" GridPane.rowIndex="4"/>
|
||||
<Label fx:id="collateralLabel" text="Collateral:" GridPane.rowIndex="4"/>
|
||||
<TextField fx:id="collateralTextField" editable="false" GridPane.rowIndex="4" GridPane.columnIndex="1"/>
|
||||
|
||||
<Label text="Fee (BTC):" GridPane.rowIndex="5"/>
|
||||
<Label text="Total Fees (Offer + tx):" GridPane.rowIndex="5"/>
|
||||
<TextField fx:id="feeTextField" editable="false" GridPane.rowIndex="5" GridPane.columnIndex="1"/>
|
||||
|
||||
<Label text="Total (BTC):" GridPane.rowIndex="6"/>
|
||||
<Label text="Total:" GridPane.rowIndex="6"/>
|
||||
<TextField fx:id="totalTextField" editable="false" GridPane.rowIndex="6" GridPane.columnIndex="1"/>
|
||||
|
||||
<Button fx:id="takeOfferButton" text="Take offer and pay" onAction="#onTakeOffer" defaultButton="true" GridPane.rowIndex="7" GridPane.columnIndex="1"/>
|
||||
|
@ -1,7 +1,7 @@
|
||||
package io.bitsquare.gui.market.trade;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import io.bitsquare.btc.AddressEntry;
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.ChildController;
|
||||
@ -18,7 +18,6 @@ import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.Trading;
|
||||
import io.bitsquare.trade.protocol.taker.ProtocolForTakerAsSeller;
|
||||
import io.bitsquare.trade.protocol.taker.ProtocolForTakerAsSellerListener;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.fxml.FXML;
|
||||
@ -38,9 +37,10 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
private final WalletFacade walletFacade;
|
||||
private final MessageFacade messageFacade;
|
||||
|
||||
|
||||
private NavigationController navigationController;
|
||||
private Offer offer;
|
||||
private BigInteger requestedAmount;
|
||||
private Coin requestedAmount;
|
||||
private String tradeId;
|
||||
private String depositTxId;
|
||||
|
||||
@ -57,7 +57,7 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
supportedLanguagesTextField, supportedCountriesTextField, depositTxIdTextField, summaryPaidTextField, summaryReceivedTextField, summaryFeesTextField, summaryCollateralTextField,
|
||||
summaryDepositTxIdTextField, summaryPayoutTxIdTextField;
|
||||
@FXML
|
||||
private Label infoLabel, headLineLabel;
|
||||
private Label infoLabel, headLineLabel, collateralLabel;
|
||||
@FXML
|
||||
private Button takeOfferButton, receivedFiatButton;
|
||||
|
||||
@ -78,10 +78,10 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
// Public methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void initWithData(Offer offer, BigInteger requestedAmount)
|
||||
public void initWithData(Offer offer, Coin requestedAmount)
|
||||
{
|
||||
this.offer = offer;
|
||||
this.requestedAmount = requestedAmount.compareTo(BigInteger.ZERO) == 0 ? offer.getAmount() : requestedAmount;
|
||||
this.requestedAmount = requestedAmount.compareTo(Coin.ZERO) == 0 ? offer.getAmount() : requestedAmount;
|
||||
|
||||
if (amountTextField != null)
|
||||
{
|
||||
@ -101,13 +101,14 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
|
||||
public void applyData()
|
||||
{
|
||||
amountTextField.setText(BtcFormatter.formatSatoshis(requestedAmount));
|
||||
amountTextField.setPromptText(BtcFormatter.formatSatoshis(offer.getMinAmount()) + " - " + BtcFormatter.formatSatoshis(offer.getAmount()));
|
||||
amountTextField.setText(requestedAmount.toPlainString());
|
||||
amountTextField.setPromptText(BitSquareFormatter.formatCoinToBtcWithCode(offer.getMinAmount()) + " - " + BitSquareFormatter.formatCoinToBtcWithCode(offer.getAmount()));
|
||||
priceTextField.setText(BitSquareFormatter.formatPrice(offer.getPrice()));
|
||||
applyVolume();
|
||||
collateralLabel.setText("Collateral (" + getCollateralAsPercent() + "):");
|
||||
applyCollateral();
|
||||
applyTotal();
|
||||
feeTextField.setText(BtcFormatter.formatSatoshis(getFee()));
|
||||
feeTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(getFee()));
|
||||
totalTextField.setText(getFormattedTotal());
|
||||
|
||||
bankAccountTypeTextField.setText(offer.getBankAccountType().toString());
|
||||
@ -123,7 +124,6 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
applyVolume();
|
||||
applyCollateral();
|
||||
applyTotal();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
public void onTakeOffer()
|
||||
{
|
||||
AddressEntry addressEntry = walletFacade.getAddressInfoByTradeID(offer.getId());
|
||||
BigInteger amount = BtcFormatter.stringValueToSatoshis(amountTextField.getText());
|
||||
Coin amount = BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
// TODO more validation (fee payment, blacklist,...)
|
||||
if (amountTextField.isInvalid())
|
||||
{
|
||||
@ -200,10 +200,10 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
public void onPayoutTxPublished(Trade trade, String payoutTxId)
|
||||
{
|
||||
accordion.setExpandedPane(summaryTitledPane);
|
||||
summaryPaidTextField.setText(BtcFormatter.formatSatoshis(trade.getTradeAmount()));
|
||||
summaryReceivedTextField.setText(BitSquareFormatter.formatVolume(trade.getOffer().getPrice() * BtcFormatter.satoshiToBTC(trade.getTradeAmount())));
|
||||
summaryFeesTextField.setText(BtcFormatter.formatSatoshis(FeePolicy.TAKE_OFFER_FEE.add(FeePolicy.TX_FEE)));
|
||||
summaryCollateralTextField.setText(BtcFormatter.formatSatoshis(trade.getCollateralAmount()));
|
||||
summaryPaidTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(trade.getTradeAmount()));
|
||||
summaryReceivedTextField.setText(BitSquareFormatter.formatVolume(trade.getOffer().getPrice() * trade.getTradeAmount().value));
|
||||
summaryFeesTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.TAKE_OFFER_FEE.add(FeePolicy.TX_FEE)));
|
||||
summaryCollateralTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(trade.getCollateralAmount()));
|
||||
summaryDepositTxIdTextField.setText(depositTxId);
|
||||
summaryPayoutTxIdTextField.setText(payoutTxId);
|
||||
}
|
||||
@ -261,7 +261,7 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
|
||||
private void applyCollateral()
|
||||
{
|
||||
collateralTextField.setText(getFormattedCollateral());
|
||||
collateralTextField.setText(getFormattedCollateralAsBtc());
|
||||
}
|
||||
|
||||
private void applyVolume()
|
||||
@ -282,23 +282,31 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
|
||||
private String getFormattedTotal()
|
||||
{
|
||||
return BitSquareFormatter.formatDouble(BtcFormatter.satoshiToBTC(getTotal()), 4);
|
||||
return BitSquareFormatter.formatCoinToBtcWithCode(getTotal());
|
||||
}
|
||||
|
||||
private String getFormattedCollateral()
|
||||
{
|
||||
return BtcFormatter.formatSatoshis(getCollateralInSatoshis());
|
||||
}
|
||||
|
||||
// values
|
||||
private double getAmountAsDouble()
|
||||
{
|
||||
return BitSquareConverter.stringToDouble(amountTextField.getText());
|
||||
return BitSquareConverter.stringToDouble(getAmountString());
|
||||
}
|
||||
|
||||
private BigInteger getAmountInSatoshis()
|
||||
private Coin getAmountInSatoshis()
|
||||
{
|
||||
return BtcFormatter.stringValueToSatoshis(amountTextField.getText());
|
||||
return BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
}
|
||||
|
||||
private String getAmountString()
|
||||
{
|
||||
try
|
||||
{
|
||||
BitSquareValidator.textFieldsHasPositiveDoubleValueWithReset(amountTextField);
|
||||
return amountTextField.getText();
|
||||
} catch (BitSquareValidator.ValidationException e)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
private double getVolume()
|
||||
@ -306,23 +314,39 @@ public class TakerOfferController implements Initializable, ChildController
|
||||
return offer.getPrice() * getAmountAsDouble();
|
||||
}
|
||||
|
||||
private BigInteger getFee()
|
||||
private Coin getFee()
|
||||
{
|
||||
return FeePolicy.TAKE_OFFER_FEE.add(FeePolicy.TX_FEE);
|
||||
}
|
||||
|
||||
private BigInteger getTotal()
|
||||
private Coin getTotal()
|
||||
{
|
||||
return getFee().add(getAmountInSatoshis()).add(getCollateralInSatoshis());
|
||||
return getFee().add(getAmountInSatoshis()).add(getCollateralAsCoin());
|
||||
}
|
||||
|
||||
private BigInteger getCollateralInSatoshis()
|
||||
private Coin getCollateralAsCoin()
|
||||
{
|
||||
double amount = BitSquareConverter.stringToDouble(amountTextField.getText());
|
||||
double resultDouble = amount * (double) offer.getCollateral() / 100.0;
|
||||
return BtcFormatter.doubleValueToSatoshis(resultDouble);
|
||||
Coin amountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
return amountAsCoin.divide((long) (1d / offer.getCollateral()));
|
||||
}
|
||||
|
||||
private String getFormattedCollateralAsBtc()
|
||||
{
|
||||
Coin amountAsCoin = BitSquareFormatter.parseBtcToCoin(getAmountString());
|
||||
Coin collateralAsCoin = amountAsCoin.divide((long) (1d / getCollateral()));
|
||||
return BitSquareFormatter.formatCoinToBtc(collateralAsCoin);
|
||||
}
|
||||
|
||||
private String getCollateralAsPercent()
|
||||
{
|
||||
return BitSquareFormatter.formatCollateralPercent(getCollateral());
|
||||
}
|
||||
|
||||
private double getCollateral()
|
||||
{
|
||||
// TODO
|
||||
return offer.getCollateral();
|
||||
}
|
||||
|
||||
public void setTradeId(String tradeId)
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.bitsquare.gui.orders.offer;
|
||||
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
import io.bitsquare.gui.util.BitSquareFormatter;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
@ -23,10 +22,7 @@ public class OfferListItem
|
||||
this.date.set(BitSquareFormatter.formatDateTime(offer.getCreationDate()));
|
||||
this.price.set(BitSquareFormatter.formatPrice(offer.getPrice()));
|
||||
|
||||
double amountAsBtcDouble = BtcFormatter.satoshiToBTC(offer.getAmount());
|
||||
double minAmountAsBtcDouble = BtcFormatter.satoshiToBTC(offer.getMinAmount());
|
||||
this.amount.set(BitSquareFormatter.formatAmountWithMinAmount(amountAsBtcDouble, minAmountAsBtcDouble));
|
||||
|
||||
this.amount.set(BitSquareFormatter.formatCoinToBtc(offer.getAmount()) + " (" + BitSquareFormatter.formatCoinToBtc(offer.getMinAmount()) + ")");
|
||||
this.volume.set(BitSquareFormatter.formatVolumeWithMinVolume(offer.getVolume(), offer.getMinVolume()));
|
||||
this.offerId = offer.getId();
|
||||
}
|
||||
|
@ -1,15 +1,11 @@
|
||||
package io.bitsquare.gui.orders.pending;
|
||||
|
||||
import com.google.bitcoin.core.ECKey;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.bitcoin.core.Wallet;
|
||||
import com.google.bitcoin.core.WalletEventListener;
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.script.Script;
|
||||
import de.jensd.fx.fontawesome.AwesomeDude;
|
||||
import de.jensd.fx.fontawesome.AwesomeIcon;
|
||||
import io.bitsquare.bank.BankAccount;
|
||||
import io.bitsquare.bank.BankAccountType;
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.ChildController;
|
||||
@ -26,7 +22,6 @@ import io.bitsquare.trade.Offer;
|
||||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.Trading;
|
||||
import io.bitsquare.util.AWTSystemTray;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
@ -54,6 +49,7 @@ public class PendingTradeController implements Initializable, ChildController, H
|
||||
|
||||
private Trading trading;
|
||||
private WalletFacade walletFacade;
|
||||
|
||||
private Trade currentTrade;
|
||||
private NavigationController navigationController;
|
||||
private Image buyIcon = Icons.getIconImage(Icons.BUY);
|
||||
@ -221,12 +217,12 @@ public class PendingTradeController implements Initializable, ChildController, H
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
|
||||
{
|
||||
}
|
||||
|
||||
@ -242,13 +238,14 @@ public class PendingTradeController implements Initializable, ChildController, H
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(Wallet wallet, List<ECKey> keys)
|
||||
public void onScriptsAdded(Wallet wallet, List<Script> scripts)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScriptsAdded(Wallet wallet, List<Script> scripts)
|
||||
public void onKeysAdded(List<ECKey> keys)
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -300,12 +297,13 @@ public class PendingTradeController implements Initializable, ChildController, H
|
||||
primaryBankAccountIDTitleLabel.setText("Total fees (offer fee + tx fee):");
|
||||
secondaryBankAccountIDTitleLabel.setText("Refunded collateral:");
|
||||
|
||||
String fiatPayed = BitSquareFormatter.formatVolume(trade.getOffer().getPrice() * BtcFormatter.satoshiToBTC(trade.getTradeAmount()));
|
||||
//TODO
|
||||
String fiatPayed = BitSquareFormatter.formatVolume(trade.getOffer().getPrice() * trade.getTradeAmount().value);
|
||||
|
||||
bankAccountTypeTextField.setText(BtcFormatter.formatSatoshis(trade.getTradeAmount()));
|
||||
bankAccountTypeTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(trade.getTradeAmount()));
|
||||
holderNameTextField.setText(fiatPayed);
|
||||
primaryBankAccountIDTextField.setText(BtcFormatter.formatSatoshis(FeePolicy.CREATE_OFFER_FEE.add(FeePolicy.TX_FEE)));
|
||||
secondaryBankAccountIDTextField.setText(BtcFormatter.formatSatoshis(trade.getCollateralAmount()));
|
||||
primaryBankAccountIDTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(FeePolicy.CREATE_OFFER_FEE.add(FeePolicy.TX_FEE)));
|
||||
secondaryBankAccountIDTextField.setText(BitSquareFormatter.formatCoinToBtcWithCode(trade.getCollateralAmount()));
|
||||
|
||||
holderNameCopyIcon.setVisible(false);
|
||||
primaryBankAccountIDCopyIcon.setVisible(false);
|
||||
|
@ -138,7 +138,7 @@ public class SettingsController implements Initializable, ChildController, Navig
|
||||
{
|
||||
if (settings.getAcceptedArbitrators().isEmpty())
|
||||
{
|
||||
String pubKeyAsHex = Utils.bytesToHexString(new ECKey().getPubKey());
|
||||
String pubKeyAsHex = Utils.HEX.encode(new ECKey().getPubKey());
|
||||
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
|
||||
List<Locale> languages = new ArrayList<>();
|
||||
languages.add(LanguageUtil.getDefaultLanguageLocale());
|
||||
@ -603,6 +603,7 @@ public class SettingsController implements Initializable, ChildController, Navig
|
||||
persistence.write(user);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Bank Account Settings
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1,99 +1,86 @@
|
||||
package io.bitsquare.gui.util;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.locale.Localisation;
|
||||
import io.bitsquare.trade.Direction;
|
||||
import io.bitsquare.user.Arbitrator;
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Currency;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
//TODO cleanup...
|
||||
public class BitSquareFormatter
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(BitSquareFormatter.class);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BTC
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static String formatCoinToBtc(Coin coin)
|
||||
{
|
||||
return coin.toFriendlyString();
|
||||
}
|
||||
|
||||
/* public static String formatCoinToBtcWithSymbol(Coin coin)
|
||||
{
|
||||
return "฿ " + coin.toPlainString();
|
||||
} */
|
||||
|
||||
public static String formatCoinToBtcWithCode(Coin coin)
|
||||
{
|
||||
return coin.toFriendlyString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param input String input in decimal or integer format. Both decimal marks (",", ".") are supported.
|
||||
* If input has an incorrect format it returns a zero value coin.
|
||||
* @return
|
||||
*/
|
||||
public static Coin parseBtcToCoin(String input)
|
||||
{
|
||||
try
|
||||
{
|
||||
input = input.replace(",", ".");
|
||||
Double.parseDouble(input);
|
||||
|
||||
} catch (NumberFormatException | NullPointerException e)
|
||||
{
|
||||
log.warn("Exception at parseBtcToCoin: " + e.toString());
|
||||
input = "0";
|
||||
}
|
||||
return Coin.parseCoin(input);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// FIAT
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static String formatPrice(double price)
|
||||
{
|
||||
return formatDouble(price);
|
||||
}
|
||||
|
||||
|
||||
public static String formatPriceWithCurrencyPair(double price, Currency currency)
|
||||
{
|
||||
return formatDouble(price) + " " + currency + "/BTC";
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
|
||||
public static String formatAmount(double amount, boolean useBTC, boolean exact)
|
||||
{
|
||||
return formatDouble(amount, (exact ? 4 : 2)) + (useBTC ? " BTC" : "");
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
|
||||
public static String formatAmount(double amount, boolean useBTC)
|
||||
{
|
||||
return formatAmount(amount, useBTC, false);
|
||||
}
|
||||
|
||||
|
||||
public static String formatAmount(double amount)
|
||||
{
|
||||
return formatAmount(amount, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
|
||||
public static String formatAmountWithMinAmount(double amount, double minAmount, boolean useBTC)
|
||||
{
|
||||
if (useBTC)
|
||||
{
|
||||
return formatDouble(amount) + " BTC (" + formatDouble(minAmount) + " BTC)";
|
||||
}
|
||||
else
|
||||
{
|
||||
return formatDouble(amount) + " (" + formatDouble(minAmount) + ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String formatAmountWithMinAmount(double amount, double minAmount)
|
||||
{
|
||||
return formatAmountWithMinAmount(amount, minAmount, false);
|
||||
}
|
||||
|
||||
public static String formatVolume(double volume)
|
||||
{
|
||||
return formatDouble(volume);
|
||||
}
|
||||
|
||||
|
||||
public static String formatVolume(double volume, Currency currency)
|
||||
{
|
||||
return formatDouble(volume) + " " + currency;
|
||||
}
|
||||
|
||||
|
||||
public static String formatVolumeWithMinVolume(double volume, double minVolume, Currency currency)
|
||||
{
|
||||
return formatDouble(volume) + " " + currency + " (" + formatDouble(minVolume) + " " + currency + ")";
|
||||
}
|
||||
|
||||
|
||||
public static String formatVolumeWithMinVolume(double volume, double minVolume)
|
||||
{
|
||||
return formatDouble(volume) + " (" + formatDouble(minVolume) + ")";
|
||||
}
|
||||
|
||||
|
||||
public static String formatCollateral(double collateral, double amount)
|
||||
{
|
||||
return formatPercent(collateral) + " (" + formatDouble(collateral * amount, 4) + " BTC)";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Other
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static String formatDirection(Direction direction, boolean allUpperCase)
|
||||
{
|
||||
@ -105,13 +92,6 @@ public class BitSquareFormatter
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static String formatList(List<String> list)
|
||||
{
|
||||
String s = list.toString();
|
||||
return s.substring(1, s.length() - 1);
|
||||
}
|
||||
|
||||
public static String formatDouble(double value)
|
||||
{
|
||||
return formatDouble(value, 2);
|
||||
@ -123,7 +103,6 @@ public class BitSquareFormatter
|
||||
return decimalFormat.format(value);
|
||||
}
|
||||
|
||||
|
||||
public static DecimalFormat getDecimalFormat(int fractionDigits)
|
||||
{
|
||||
DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(Locale.getDefault());
|
||||
@ -133,13 +112,6 @@ public class BitSquareFormatter
|
||||
return decimalFormat;
|
||||
}
|
||||
|
||||
|
||||
private static String formatPercent(double value)
|
||||
{
|
||||
return value * 100 + "%";
|
||||
}
|
||||
|
||||
|
||||
public static String countryLocalesToString(List<Country> countries)
|
||||
{
|
||||
String result = "";
|
||||
@ -206,7 +178,6 @@ public class BitSquareFormatter
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static String formatDateTime(Date date)
|
||||
{
|
||||
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.getDefault());
|
||||
@ -214,5 +185,8 @@ public class BitSquareFormatter
|
||||
return dateFormatter.format(date) + " " + timeFormatter.format(date);
|
||||
}
|
||||
|
||||
|
||||
public static String formatCollateralPercent(double collateral)
|
||||
{
|
||||
return getDecimalFormat(2).format(collateral * 100) + " %";
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.bitsquare.gui.util;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import io.bitsquare.bank.BankAccountType;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import java.math.BigInteger;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.effect.BlurType;
|
||||
import javafx.scene.effect.DropShadow;
|
||||
@ -15,14 +15,14 @@ public class BitSquareValidator
|
||||
private static final Effect invalidEffect = new DropShadow(BlurType.GAUSSIAN, Color.RED, 4, 0.0, 0, 0);
|
||||
private static final String invalidStyle = "-fx-border-color: red";
|
||||
|
||||
public static boolean tradeAmountOutOfRange(BigInteger tradeAmount, Offer offer)
|
||||
public static boolean tradeAmountOutOfRange(Coin tradeAmount, Offer offer)
|
||||
{
|
||||
return tradeAmount.compareTo(offer.getAmount()) > 0 || tradeAmount.compareTo(offer.getMinAmount()) < 0;
|
||||
}
|
||||
|
||||
public static boolean greaterThanZero(BigInteger value)
|
||||
public static boolean greaterThanZero(Coin value)
|
||||
{
|
||||
return value.compareTo(BigInteger.ZERO) > 0;
|
||||
return value.compareTo(Coin.ZERO) > 0;
|
||||
}
|
||||
|
||||
public static void textFieldsNotEmptyWithReset(TextField... textFields) throws ValidationException
|
||||
@ -74,7 +74,7 @@ public class BitSquareValidator
|
||||
|
||||
public static void textFieldHasDoubleValue(TextField textField) throws ValidationException
|
||||
{
|
||||
if (!validateStringAsDouble(textField.getText()))
|
||||
if (!validateStringAsDouble(textField.getText().replace(",", ".")))
|
||||
{
|
||||
textField.setEffect(invalidEffect);
|
||||
textField.setStyle(invalidStyle);
|
||||
@ -82,6 +82,42 @@ public class BitSquareValidator
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void textFieldsHasPositiveDoubleValueWithReset(TextField... textFields) throws ValidationException
|
||||
{
|
||||
resetTextFields(textFields);
|
||||
textFieldsHasPositiveDoubleValue(textFields);
|
||||
}
|
||||
|
||||
public static void textFieldsHasPositiveDoubleValue(TextField... textFields) throws ValidationException
|
||||
{
|
||||
for (TextField textField : textFields)
|
||||
{
|
||||
textFieldHasPositiveDoubleValue(textField);
|
||||
}
|
||||
}
|
||||
|
||||
public static void textFieldHasPositiveDoubleValue(TextField textField) throws ValidationException
|
||||
{
|
||||
String input = textField.getText().replace(",", ".");
|
||||
if (!validateStringAsDouble(input))
|
||||
{
|
||||
textField.setEffect(invalidEffect);
|
||||
textField.setStyle(invalidStyle);
|
||||
throw new ValidationException();
|
||||
}
|
||||
else
|
||||
{
|
||||
double val = Double.parseDouble(input);
|
||||
if (val <= 0)
|
||||
{
|
||||
textField.setEffect(invalidEffect);
|
||||
textField.setStyle(invalidStyle);
|
||||
throw new ValidationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
public static void textFieldBankAccountPrimaryIDIsValid(TextField textField, BankAccountType bankAccountType) throws ValidationException
|
||||
|
@ -2,9 +2,7 @@ package io.bitsquare.gui.util;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.script.Script;
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javafx.scene.control.Label;
|
||||
@ -45,12 +43,24 @@ public class ConfidenceDisplay
|
||||
walletEventListener = new WalletEventListener()
|
||||
{
|
||||
@Override
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
|
||||
{
|
||||
updateBalance(newBalance);
|
||||
// log.debug("onCoinsReceived " + newBalance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
|
||||
{
|
||||
updateBalance(newBalance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReorganize(Wallet wallet)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
|
||||
{
|
||||
@ -58,30 +68,22 @@ public class ConfidenceDisplay
|
||||
// log.debug("onTransactionConfidenceChanged tx " + tx.getHashAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
updateBalance(newBalance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReorganize(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalletChanged(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(Wallet wallet, List<ECKey> keys)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScriptsAdded(Wallet wallet, List<Script> scripts)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(List<ECKey> keys)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
wallet.addEventListener(walletEventListener);
|
||||
@ -104,7 +106,7 @@ public class ConfidenceDisplay
|
||||
walletEventListener = new WalletEventListener()
|
||||
{
|
||||
@Override
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
|
||||
{
|
||||
if (tx.getHashAsString().equals(transaction.getHashAsString()))
|
||||
{
|
||||
@ -113,6 +115,21 @@ public class ConfidenceDisplay
|
||||
// log.debug("onCoinsReceived " + newBalance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
|
||||
{
|
||||
if (tx.getHashAsString().equals(transaction.getHashAsString()))
|
||||
{
|
||||
updateBalance(newBalance);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReorganize(Wallet wallet)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
|
||||
{
|
||||
@ -123,33 +140,22 @@ public class ConfidenceDisplay
|
||||
// log.debug("onTransactionConfidenceChanged newTransaction " + newTransaction.getHashAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
if (tx.getHashAsString().equals(transaction.getHashAsString()))
|
||||
{
|
||||
updateBalance(newBalance);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReorganize(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalletChanged(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(Wallet wallet, List<ECKey> keys)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScriptsAdded(Wallet wallet, List<Script> scripts)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(List<ECKey> keys)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
wallet.addEventListener(walletEventListener);
|
||||
@ -166,9 +172,9 @@ public class ConfidenceDisplay
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBalance(BigInteger balance)
|
||||
private void updateBalance(Coin balance)
|
||||
{
|
||||
if (balance.compareTo(BigInteger.ZERO) > 0)
|
||||
if (balance.compareTo(Coin.ZERO) > 0)
|
||||
{
|
||||
confirmationLabel.setVisible(true);
|
||||
progressIndicator.setVisible(true);
|
||||
@ -198,7 +204,8 @@ public class ConfidenceDisplay
|
||||
|
||||
if (balanceTextField != null)
|
||||
{
|
||||
balanceTextField.setText(BtcFormatter.formatSatoshis(balance));
|
||||
//TODO
|
||||
balanceTextField.setText(balance.toFriendlyString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class P2PNode
|
||||
// just for lightweight client test
|
||||
public static void main(String[] args)
|
||||
{
|
||||
P2PNode p2pNode = new P2PNode(DSAKeyUtil.generateKeyPair(), false, SeedNodeAddress.StaticSeedNodeAddresses.LOCALHOST,
|
||||
P2PNode p2pNode = new P2PNode(DSAKeyUtil.generateKeyPair(), false, SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN,
|
||||
(message, peerAddress) -> log.debug("handleMessage: message= " + message + "/ peerAddress=" + peerAddress));
|
||||
p2pNode.start(new FutureCallback<PeerDHT>()
|
||||
{
|
||||
|
@ -1,9 +1,9 @@
|
||||
package io.bitsquare.settings;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.user.Arbitrator;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -16,8 +16,7 @@ public class Settings implements Serializable
|
||||
private List<Locale> acceptedLanguageLocales = new ArrayList<>();
|
||||
private List<Country> acceptedCountryLocales = new ArrayList<>();
|
||||
private List<Arbitrator> acceptedArbitrators = new ArrayList<>();
|
||||
private int maxCollateral;
|
||||
private int minCollateral;
|
||||
private double collateral = 0.01;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -40,8 +39,7 @@ public class Settings implements Serializable
|
||||
acceptedLanguageLocales = persistedSettings.getAcceptedLanguageLocales();
|
||||
acceptedCountryLocales = persistedSettings.getAcceptedCountries();
|
||||
acceptedArbitrators = persistedSettings.getAcceptedArbitrators();
|
||||
maxCollateral = persistedSettings.getMaxCollateral();
|
||||
minCollateral = persistedSettings.getMinCollateral();
|
||||
collateral = persistedSettings.getCollateral();
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +108,7 @@ public class Settings implements Serializable
|
||||
//TODO
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
|
||||
public Arbitrator getRandomArbitrator(@SuppressWarnings("UnusedParameters") Integer collateral, @SuppressWarnings("UnusedParameters") BigInteger amount)
|
||||
public Arbitrator getRandomArbitrator(@SuppressWarnings("UnusedParameters") double collateral, @SuppressWarnings("UnusedParameters") Coin amount)
|
||||
{
|
||||
List<Arbitrator> candidates = new ArrayList<>();
|
||||
//noinspection Convert2streamapi
|
||||
@ -125,24 +123,10 @@ public class Settings implements Serializable
|
||||
return !candidates.isEmpty() ? candidates.get((int) (Math.random() * candidates.size())) : null;
|
||||
}
|
||||
|
||||
int getMaxCollateral()
|
||||
{
|
||||
return maxCollateral;
|
||||
}
|
||||
|
||||
public void setMaxCollateral(int maxCollateral)
|
||||
public double getCollateral()
|
||||
{
|
||||
this.maxCollateral = maxCollateral;
|
||||
}
|
||||
|
||||
public int getMinCollateral()
|
||||
{
|
||||
return minCollateral;
|
||||
}
|
||||
|
||||
public void setMinCollateral(int minCollateral)
|
||||
{
|
||||
this.minCollateral = minCollateral;
|
||||
return collateral;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package io.bitsquare.trade;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import io.bitsquare.bank.BankAccount;
|
||||
import io.bitsquare.util.DSAKeyUtil;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
import java.security.PublicKey;
|
||||
|
||||
public class Contract implements Serializable
|
||||
@ -12,7 +12,7 @@ public class Contract implements Serializable
|
||||
|
||||
private final Offer offer;
|
||||
private final String takeOfferFeeTxID;
|
||||
private final BigInteger tradeAmount;
|
||||
private final Coin tradeAmount;
|
||||
private final String offererAccountID;
|
||||
private final String takerAccountID;
|
||||
private final BankAccount offererBankAccount;
|
||||
@ -21,7 +21,7 @@ public class Contract implements Serializable
|
||||
private final String takerMessagePublicKeyAsString;
|
||||
|
||||
public Contract(Offer offer,
|
||||
BigInteger tradeAmount,
|
||||
Coin tradeAmount,
|
||||
String takeOfferFeeTxID,
|
||||
String offererAccountID,
|
||||
String takerAccountID,
|
||||
@ -56,7 +56,7 @@ public class Contract implements Serializable
|
||||
return takeOfferFeeTxID;
|
||||
}
|
||||
|
||||
public BigInteger getTradeAmount()
|
||||
public Coin getTradeAmount()
|
||||
{
|
||||
return tradeAmount;
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
package io.bitsquare.trade;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import io.bitsquare.bank.BankAccountType;
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
import io.bitsquare.locale.Country;
|
||||
import io.bitsquare.user.Arbitrator;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
import java.security.PublicKey;
|
||||
import java.util.*;
|
||||
|
||||
@ -22,13 +21,13 @@ public class Offer implements Serializable
|
||||
private final Date creationDate;
|
||||
|
||||
private final double price;
|
||||
private final BigInteger amount;
|
||||
private final BigInteger minAmount;
|
||||
private final Coin amount;
|
||||
private final Coin minAmount;
|
||||
private final PublicKey messagePublicKey;
|
||||
private final BankAccountType bankAccountType;
|
||||
private final Country bankAccountCountry;
|
||||
|
||||
private final int collateral;
|
||||
private final double collateral;
|
||||
private final List<Country> acceptedCountries;
|
||||
private final List<Locale> acceptedLanguageLocales;
|
||||
private final String bankAccountUID;
|
||||
@ -43,14 +42,14 @@ public class Offer implements Serializable
|
||||
public Offer(PublicKey messagePublicKey,
|
||||
Direction direction,
|
||||
double price,
|
||||
BigInteger amount,
|
||||
BigInteger minAmount,
|
||||
Coin amount,
|
||||
Coin minAmount,
|
||||
BankAccountType bankAccountType,
|
||||
Currency currency,
|
||||
Country bankAccountCountry,
|
||||
String bankAccountUID,
|
||||
Arbitrator arbitrator,
|
||||
int collateral,
|
||||
double collateral,
|
||||
List<Country> acceptedCountries,
|
||||
List<Locale> acceptedLanguageLocales)
|
||||
{
|
||||
@ -98,12 +97,12 @@ public class Offer implements Serializable
|
||||
return price;
|
||||
}
|
||||
|
||||
public BigInteger getAmount()
|
||||
public Coin getAmount()
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
|
||||
public BigInteger getMinAmount()
|
||||
public Coin getMinAmount()
|
||||
{
|
||||
return minAmount;
|
||||
}
|
||||
@ -140,12 +139,12 @@ public class Offer implements Serializable
|
||||
|
||||
public double getVolume()
|
||||
{
|
||||
return price * BtcFormatter.satoshiToBTC(amount);
|
||||
return price * amount.value;
|
||||
}
|
||||
|
||||
public double getMinVolume()
|
||||
{
|
||||
return price * BtcFormatter.satoshiToBTC(minAmount);
|
||||
return price * minAmount.value;
|
||||
}
|
||||
|
||||
public String getOfferFeePaymentTxID()
|
||||
@ -163,7 +162,7 @@ public class Offer implements Serializable
|
||||
return arbitrator;
|
||||
}
|
||||
|
||||
public int getCollateral()
|
||||
public double getCollateral()
|
||||
{
|
||||
return collateral;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.bitsquare.trade;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
|
||||
@ -12,7 +12,7 @@ public class Trade implements Serializable
|
||||
|
||||
private final Offer offer;
|
||||
private String takeOfferFeeTxID;
|
||||
private BigInteger tradeAmount;
|
||||
private Coin tradeAmount;
|
||||
private Contract contract;
|
||||
private String contractAsJson;
|
||||
private String takerSignature;
|
||||
@ -53,12 +53,12 @@ public class Trade implements Serializable
|
||||
this.takeOfferFeeTxID = takeOfferFeeTxID;
|
||||
}
|
||||
|
||||
public BigInteger getTradeAmount()
|
||||
public Coin getTradeAmount()
|
||||
{
|
||||
return tradeAmount;
|
||||
}
|
||||
|
||||
public void setTradeAmount(BigInteger tradeAmount)
|
||||
public void setTradeAmount(Coin tradeAmount)
|
||||
{
|
||||
this.tradeAmount = tradeAmount;
|
||||
}
|
||||
@ -172,9 +172,9 @@ public class Trade implements Serializable
|
||||
return _stateChangedProperty;
|
||||
}
|
||||
|
||||
public BigInteger getCollateralAmount()
|
||||
public Coin getCollateralAmount()
|
||||
{
|
||||
return getTradeAmount().multiply(BigInteger.valueOf(getOffer().getCollateral())).divide(BigInteger.valueOf(100));
|
||||
return tradeAmount.divide((long) (1d / offer.getCollateral()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bitsquare.trade;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.bitcoin.core.TransactionConfidence;
|
||||
import com.google.bitcoin.core.Utils;
|
||||
@ -15,7 +16,6 @@ import io.bitsquare.trade.protocol.offerer.*;
|
||||
import io.bitsquare.trade.protocol.taker.*;
|
||||
import io.bitsquare.user.User;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -146,7 +146,7 @@ public class Trading
|
||||
messageFacade.removeOffer(offer);
|
||||
}
|
||||
|
||||
public Trade takeOffer(BigInteger amount, Offer offer, ProtocolForTakerAsSellerListener listener)
|
||||
public Trade takeOffer(Coin amount, Offer offer, ProtocolForTakerAsSellerListener listener)
|
||||
{
|
||||
Trade trade = createTrade(offer);
|
||||
trade.setTradeAmount(amount);
|
||||
|
@ -115,7 +115,8 @@ public class OrderBook implements OrderBookListener
|
||||
boolean amountResult = true;
|
||||
if (orderBookFilter.getAmount() > 0)
|
||||
{
|
||||
amountResult = orderBookFilter.getAmount() <= offer.getAmount().doubleValue();
|
||||
//TODO
|
||||
amountResult = orderBookFilter.getAmount() <= offer.getAmount().value;
|
||||
}
|
||||
|
||||
// The requested trade direction must be opposite of the offerList trade direction
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.bitsquare.trade.protocol.offerer;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import io.bitsquare.trade.protocol.TradeMessage;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class BankTransferInitedMessage implements Serializable, TradeMessage
|
||||
{
|
||||
@ -12,16 +12,16 @@ public class BankTransferInitedMessage implements Serializable, TradeMessage
|
||||
private String depositTxAsHex;
|
||||
private String offererSignatureR;
|
||||
private String offererSignatureS;
|
||||
private BigInteger offererPaybackAmount;
|
||||
private BigInteger takerPaybackAmount;
|
||||
private Coin offererPaybackAmount;
|
||||
private Coin takerPaybackAmount;
|
||||
private String offererPayoutAddress;
|
||||
|
||||
public BankTransferInitedMessage(String tradeId,
|
||||
String depositTxAsHex,
|
||||
String offererSignatureR,
|
||||
String offererSignatureS,
|
||||
BigInteger offererPaybackAmount,
|
||||
BigInteger takerPaybackAmount,
|
||||
Coin offererPaybackAmount,
|
||||
Coin takerPaybackAmount,
|
||||
String offererPayoutAddress)
|
||||
{
|
||||
this.tradeId = tradeId;
|
||||
@ -54,12 +54,12 @@ public class BankTransferInitedMessage implements Serializable, TradeMessage
|
||||
return offererSignatureS;
|
||||
}
|
||||
|
||||
public BigInteger getOffererPaybackAmount()
|
||||
public Coin getOffererPaybackAmount()
|
||||
{
|
||||
return offererPaybackAmount;
|
||||
}
|
||||
|
||||
public BigInteger getTakerPaybackAmount()
|
||||
public Coin getTakerPaybackAmount()
|
||||
{
|
||||
return takerPaybackAmount;
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package io.bitsquare.trade.protocol.offerer;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.InsufficientMoneyException;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.bitcoin.core.Utils;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.trade.protocol.FaultHandler;
|
||||
import java.math.BigInteger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -17,7 +17,7 @@ public class CreateDepositTx
|
||||
FaultHandler faultHandler,
|
||||
WalletFacade walletFacade,
|
||||
String tradeId,
|
||||
BigInteger offererInputAmount,
|
||||
Coin offererInputAmount,
|
||||
String takerMultiSigPubKey,
|
||||
String arbitratorPubKeyAsHex)
|
||||
{
|
||||
@ -27,7 +27,7 @@ public class CreateDepositTx
|
||||
String offererPubKey = walletFacade.getAddressInfoByTradeID(tradeId).getPubKeyAsHexString();
|
||||
Transaction transaction = walletFacade.offererCreatesMSTxAndAddPayment(offererInputAmount, offererPubKey, takerMultiSigPubKey, arbitratorPubKeyAsHex, tradeId);
|
||||
|
||||
String preparedOffererDepositTxAsHex = Utils.bytesToHexString(transaction.bitcoinSerialize());
|
||||
String preparedOffererDepositTxAsHex = Utils.HEX.encode(transaction.bitcoinSerialize());
|
||||
long offererTxOutIndex = transaction.getInput(0).getOutpoint().getIndex();
|
||||
|
||||
resultHandler.onResult(offererPubKey, preparedOffererDepositTxAsHex, offererTxOutIndex);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bitsquare.trade.protocol.offerer;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.ECKey;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import io.bitsquare.bank.BankAccount;
|
||||
@ -15,7 +16,6 @@ import io.bitsquare.trade.protocol.taker.PayoutTxPublishedMessage;
|
||||
import io.bitsquare.trade.protocol.taker.RequestOffererPublishDepositTxMessage;
|
||||
import io.bitsquare.trade.protocol.taker.TakeOfferFeePayedMessage;
|
||||
import io.bitsquare.user.User;
|
||||
import java.math.BigInteger;
|
||||
import java.security.PublicKey;
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -176,7 +176,7 @@ public class ProtocolForOffererAsBuyer
|
||||
checkState(state == State.HandleTakeOfferRequest);
|
||||
checkArgument(tradeId.equals(message.getTradeId()));
|
||||
String takeOfferFeeTxId = nonEmptyStringOf(message.getTakeOfferFeeTxId());
|
||||
BigInteger tradeAmount = nonNegativeBigIntegerOf(nonZeroBigIntegerOf(message.getTradeAmount()));
|
||||
Coin tradeAmount = positiveCoinOf(nonZeroCoinOf(message.getTradeAmount()));
|
||||
String takerPubKey = nonEmptyStringOf(message.getTakerPubKey());
|
||||
|
||||
// apply new state
|
||||
@ -195,8 +195,8 @@ public class ProtocolForOffererAsBuyer
|
||||
{
|
||||
log.debug("onResultVerifyTakeOfferFeePayment called " + step++);
|
||||
|
||||
BigInteger collateral = trade.getCollateralAmount();
|
||||
BigInteger offererInputAmount = collateral.add(FeePolicy.TX_FEE);
|
||||
Coin collateral = trade.getCollateralAmount();
|
||||
Coin offererInputAmount = collateral.add(FeePolicy.TX_FEE);
|
||||
state = State.CreateDepositTx;
|
||||
CreateDepositTx.run(this::onResultCreateDepositTx, this::onFault, walletFacade, tradeId, offererInputAmount, takerPubKey, arbitratorPubKey);
|
||||
}
|
||||
@ -270,7 +270,7 @@ public class ProtocolForOffererAsBuyer
|
||||
{
|
||||
log.debug("onResultVerifyTakerAccount called " + step++);
|
||||
|
||||
BigInteger tradeAmount = trade.getTradeAmount();
|
||||
Coin tradeAmount = trade.getTradeAmount();
|
||||
state = State.VerifyAndSignContract;
|
||||
VerifyAndSignContract.run(this::onResultVerifyAndSignContract,
|
||||
this::onFault,
|
||||
@ -352,8 +352,8 @@ public class ProtocolForOffererAsBuyer
|
||||
|
||||
// next task
|
||||
String depositTransactionId = trade.getDepositTransaction().getHashAsString();
|
||||
BigInteger tradeAmount = trade.getTradeAmount();
|
||||
BigInteger collateral = trade.getCollateralAmount();
|
||||
Coin tradeAmount = trade.getTradeAmount();
|
||||
Coin collateral = trade.getCollateralAmount();
|
||||
state = State.SendSignedPayoutTx;
|
||||
SendSignedPayoutTx.run(this::onResultSendSignedPayoutTx,
|
||||
this::onFault,
|
||||
|
@ -17,7 +17,7 @@ public class SendDepositTxIdToTaker
|
||||
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, PeerAddress peerAddress, MessageFacade messageFacade, String tradeId, Transaction depositTransaction)
|
||||
{
|
||||
log.trace("Run task");
|
||||
DepositTxPublishedMessage tradeMessage = new DepositTxPublishedMessage(tradeId, Utils.bytesToHexString(depositTransaction.bitcoinSerialize()));
|
||||
DepositTxPublishedMessage tradeMessage = new DepositTxPublishedMessage(tradeId, Utils.HEX.encode(depositTransaction.bitcoinSerialize()));
|
||||
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener()
|
||||
{
|
||||
@Override
|
||||
|
@ -1,12 +1,12 @@
|
||||
package io.bitsquare.trade.protocol.offerer;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.ECKey;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.trade.protocol.FaultHandler;
|
||||
import io.bitsquare.trade.protocol.ResultHandler;
|
||||
import java.math.BigInteger;
|
||||
import javafx.util.Pair;
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
import org.slf4j.Logger;
|
||||
@ -25,14 +25,14 @@ public class SendSignedPayoutTx
|
||||
String takerPayoutAddress,
|
||||
String offererPayoutAddress,
|
||||
String depositTransactionId,
|
||||
BigInteger collateral,
|
||||
BigInteger tradeAmount)
|
||||
Coin collateral,
|
||||
Coin tradeAmount)
|
||||
{
|
||||
log.trace("Run task");
|
||||
try
|
||||
{
|
||||
BigInteger offererPaybackAmount = tradeAmount.add(collateral);
|
||||
BigInteger takerPaybackAmount = collateral;
|
||||
Coin offererPaybackAmount = tradeAmount.add(collateral);
|
||||
Coin takerPaybackAmount = collateral;
|
||||
|
||||
Pair<ECKey.ECDSASignature, String> result = walletFacade.offererCreatesAndSignsPayoutTx(depositTransactionId, offererPaybackAmount, takerPaybackAmount, takerPayoutAddress, tradeId);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bitsquare.trade.protocol.offerer;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.ECKey;
|
||||
import io.bitsquare.bank.BankAccount;
|
||||
import io.bitsquare.crypto.CryptoFacade;
|
||||
@ -7,7 +8,6 @@ import io.bitsquare.trade.Contract;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import io.bitsquare.trade.protocol.FaultHandler;
|
||||
import io.bitsquare.util.Utilities;
|
||||
import java.math.BigInteger;
|
||||
import java.security.PublicKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -20,7 +20,7 @@ public class VerifyAndSignContract
|
||||
FaultHandler faultHandler,
|
||||
CryptoFacade cryptoFacade,
|
||||
String accountId,
|
||||
BigInteger tradeAmount,
|
||||
Coin tradeAmount,
|
||||
String takeOfferFeeTxId,
|
||||
PublicKey messagePublicKey,
|
||||
Offer offer,
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bitsquare.trade.protocol.taker;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.ECKey;
|
||||
import io.bitsquare.bank.BankAccount;
|
||||
import io.bitsquare.crypto.CryptoFacade;
|
||||
@ -7,7 +8,6 @@ import io.bitsquare.trade.Contract;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import io.bitsquare.trade.protocol.FaultHandler;
|
||||
import io.bitsquare.util.Utilities;
|
||||
import java.math.BigInteger;
|
||||
import java.security.PublicKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -20,7 +20,7 @@ public class CreateAndSignContract
|
||||
FaultHandler faultHandler,
|
||||
CryptoFacade cryptoFacade,
|
||||
Offer offer,
|
||||
BigInteger tradeAmount,
|
||||
Coin tradeAmount,
|
||||
String takeOfferFeeTxId,
|
||||
String accountId,
|
||||
BankAccount bankAccount,
|
||||
@ -36,7 +36,9 @@ public class CreateAndSignContract
|
||||
Contract contract = new Contract(offer, tradeAmount, takeOfferFeeTxId, peersAccountId, accountId, peersBankAccount, bankAccount, peersMessagePublicKey, messagePublicKey);
|
||||
|
||||
String contractAsJson = Utilities.objectToJson(contract);
|
||||
String signature = cryptoFacade.signContract(registrationKey, contractAsJson);
|
||||
//TODO priv key is null, use other signing key or find out why it is null at that moment
|
||||
// String signature = cryptoFacade.signContract(registrationKey, contractAsJson);
|
||||
String signature = "TODO priv key is null, use other signing key or find out why it is null at that moment";
|
||||
resultHandler.onResult(contract, contractAsJson, signature);
|
||||
} catch (Throwable t)
|
||||
{
|
||||
|
@ -1,10 +1,10 @@
|
||||
package io.bitsquare.trade.protocol.taker;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.InsufficientMoneyException;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.trade.protocol.FaultHandler;
|
||||
import java.math.BigInteger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -15,8 +15,8 @@ public class PayDeposit
|
||||
public static void run(ResultHandler resultHandler,
|
||||
FaultHandler faultHandler,
|
||||
WalletFacade walletFacade,
|
||||
BigInteger collateral,
|
||||
BigInteger tradeAmount,
|
||||
Coin collateral,
|
||||
Coin tradeAmount,
|
||||
String tradeId,
|
||||
String pubKeyForThatTrade,
|
||||
String arbitratorPubKey,
|
||||
@ -26,8 +26,8 @@ public class PayDeposit
|
||||
log.trace("Run task");
|
||||
try
|
||||
{
|
||||
BigInteger amountToPay = tradeAmount.add(collateral);
|
||||
BigInteger msOutputAmount = amountToPay.add(collateral);
|
||||
Coin amountToPay = tradeAmount.add(collateral);
|
||||
Coin msOutputAmount = amountToPay.add(collateral);
|
||||
|
||||
Transaction signedTakerDepositTx = walletFacade.takerAddPaymentAndSignTx(amountToPay,
|
||||
msOutputAmount,
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.bitsquare.trade.protocol.taker;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.ECKey;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import io.bitsquare.bank.BankAccount;
|
||||
@ -15,7 +16,6 @@ import io.bitsquare.trade.protocol.offerer.DepositTxPublishedMessage;
|
||||
import io.bitsquare.trade.protocol.offerer.RequestTakerDepositPaymentMessage;
|
||||
import io.bitsquare.trade.protocol.offerer.RespondToTakeOfferRequestMessage;
|
||||
import io.bitsquare.user.User;
|
||||
import java.math.BigInteger;
|
||||
import java.security.PublicKey;
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
import org.slf4j.Logger;
|
||||
@ -68,11 +68,11 @@ public class ProtocolForTakerAsSeller
|
||||
private final BankAccount bankAccount;
|
||||
private final String accountId;
|
||||
private final PublicKey messagePublicKey;
|
||||
private final BigInteger tradeAmount;
|
||||
private final Coin tradeAmount;
|
||||
private final String pubKeyForThatTrade;
|
||||
private final ECKey accountKey;
|
||||
private final PublicKey peersMessagePublicKey;
|
||||
private final BigInteger collateral;
|
||||
private final Coin collateral;
|
||||
private final String arbitratorPubKey;
|
||||
|
||||
// written/read by task
|
||||
@ -88,8 +88,8 @@ public class ProtocolForTakerAsSeller
|
||||
private String depositTxAsHex;
|
||||
private String offererSignatureR;
|
||||
private String offererSignatureS;
|
||||
private BigInteger offererPaybackAmount;
|
||||
private BigInteger takerPaybackAmount;
|
||||
private Coin offererPaybackAmount;
|
||||
private Coin takerPaybackAmount;
|
||||
private String offererPayoutAddress;
|
||||
|
||||
|
||||
@ -319,8 +319,8 @@ public class ProtocolForTakerAsSeller
|
||||
String depositTxAsHex = nonEmptyStringOf(message.getDepositTxAsHex());
|
||||
String offererSignatureR = nonEmptyStringOf(message.getOffererSignatureR());
|
||||
String offererSignatureS = nonEmptyStringOf(message.getOffererSignatureS());
|
||||
BigInteger offererPaybackAmount = nonNegativeBigIntegerOf(nonZeroBigIntegerOf(message.getOffererPaybackAmount()));
|
||||
BigInteger takerPaybackAmount = nonNegativeBigIntegerOf(nonZeroBigIntegerOf(message.getTakerPaybackAmount()));
|
||||
Coin offererPaybackAmount = positiveCoinOf(nonZeroCoinOf(message.getOffererPaybackAmount()));
|
||||
Coin takerPaybackAmount = positiveCoinOf(nonZeroCoinOf(message.getTakerPaybackAmount()));
|
||||
String offererPayoutAddress = nonEmptyStringOf(message.getOffererPayoutAddress());
|
||||
|
||||
// apply state
|
||||
|
@ -38,12 +38,12 @@ public class SendSignedTakerDepositTxAsHex
|
||||
bankAccount,
|
||||
accountId,
|
||||
messagePublicKey,
|
||||
Utils.bytesToHexString(signedTakerDepositTx.bitcoinSerialize()),
|
||||
Utils.bytesToHexString(signedTakerDepositTx.getInput(1).getScriptBytes()),
|
||||
Utils.bytesToHexString(signedTakerDepositTx.getInput(1)
|
||||
.getConnectedOutput()
|
||||
.getParentTransaction()
|
||||
.bitcoinSerialize()),
|
||||
Utils.HEX.encode(signedTakerDepositTx.bitcoinSerialize()),
|
||||
Utils.HEX.encode(signedTakerDepositTx.getInput(1).getScriptBytes()),
|
||||
Utils.HEX.encode(signedTakerDepositTx.getInput(1)
|
||||
.getConnectedOutput()
|
||||
.getParentTransaction()
|
||||
.bitcoinSerialize()),
|
||||
contractAsJson,
|
||||
takerSignature,
|
||||
walletFacade.getAddressInfoByTradeID(tradeId).getAddressString(),
|
||||
|
@ -1,10 +1,10 @@
|
||||
package io.bitsquare.trade.protocol.taker;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.trade.protocol.FaultHandler;
|
||||
import io.bitsquare.trade.protocol.ResultHandler;
|
||||
import java.math.BigInteger;
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -19,7 +19,7 @@ public class SendTakeOfferFeePayedTxId
|
||||
MessageFacade messageFacade,
|
||||
String tradeId,
|
||||
String takeOfferFeeTxId,
|
||||
BigInteger tradeAmount,
|
||||
Coin tradeAmount,
|
||||
String pubKeyForThatTradeAsHex)
|
||||
{
|
||||
log.trace("Run task");
|
||||
|
@ -1,11 +1,11 @@
|
||||
package io.bitsquare.trade.protocol.taker;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.bitcoin.core.Utils;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.trade.protocol.FaultHandler;
|
||||
import java.math.BigInteger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -20,8 +20,8 @@ public class SignAndPublishPayoutTx
|
||||
String depositTxAsHex,
|
||||
String offererSignatureR,
|
||||
String offererSignatureS,
|
||||
BigInteger offererPaybackAmount,
|
||||
BigInteger takerPaybackAmount,
|
||||
Coin offererPaybackAmount,
|
||||
Coin takerPaybackAmount,
|
||||
String offererPayoutAddress)
|
||||
{
|
||||
log.trace("Run task");
|
||||
@ -41,7 +41,7 @@ public class SignAndPublishPayoutTx
|
||||
public void onSuccess(Transaction transaction)
|
||||
{
|
||||
log.debug("takerSignsAndSendsTx " + transaction);
|
||||
String payoutTxAsHex = Utils.bytesToHexString(transaction.bitcoinSerialize());
|
||||
String payoutTxAsHex = Utils.HEX.encode(transaction.bitcoinSerialize());
|
||||
resultHandler.onResult(transaction.getHashAsString(), payoutTxAsHex);
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,19 @@
|
||||
package io.bitsquare.trade.protocol.taker;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import io.bitsquare.trade.protocol.TradeMessage;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class TakeOfferFeePayedMessage implements Serializable, TradeMessage
|
||||
{
|
||||
private static final long serialVersionUID = -5057935061275354312L;
|
||||
private final String tradeId;
|
||||
|
||||
private BigInteger tradeAmount;
|
||||
private Coin tradeAmount;
|
||||
private String takeOfferFeeTxID;
|
||||
private String takerPubKey;
|
||||
|
||||
public TakeOfferFeePayedMessage(String tradeId, String takeOfferFeeTxID, BigInteger tradeAmount, String takerPubKey)
|
||||
public TakeOfferFeePayedMessage(String tradeId, String takeOfferFeeTxID, Coin tradeAmount, String takerPubKey)
|
||||
{
|
||||
this.tradeId = tradeId;
|
||||
this.takeOfferFeeTxID = takeOfferFeeTxID;
|
||||
@ -27,7 +27,7 @@ public class TakeOfferFeePayedMessage implements Serializable, TradeMessage
|
||||
return tradeId;
|
||||
}
|
||||
|
||||
public BigInteger getTradeAmount()
|
||||
public Coin getTradeAmount()
|
||||
{
|
||||
return tradeAmount;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class DSAKeyUtil
|
||||
public static String getHexStringFromPublicKey(PublicKey publicKey)
|
||||
{
|
||||
final X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(publicKey.getEncoded());
|
||||
return Utils.bytesToHexString(x509EncodedKeySpec.getEncoded());
|
||||
return Utils.HEX.encode(x509EncodedKeySpec.getEncoded());
|
||||
}
|
||||
|
||||
public static KeyPair generateKeyPair()
|
||||
|
@ -66,7 +66,7 @@ public class Utilities
|
||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
|
||||
objectOutputStream.writeObject(serializable);
|
||||
|
||||
result = com.google.bitcoin.core.Utils.bytesToHexString(byteArrayOutputStream.toByteArray());
|
||||
result = com.google.bitcoin.core.Utils.HEX.encode(byteArrayOutputStream.toByteArray());
|
||||
byteArrayOutputStream.close();
|
||||
objectOutputStream.close();
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.bitsquare.util;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -24,17 +24,17 @@ public class Validator
|
||||
return value;
|
||||
}
|
||||
|
||||
public static BigInteger nonZeroBigIntegerOf(BigInteger value)
|
||||
public static Coin nonZeroCoinOf(Coin value)
|
||||
{
|
||||
checkNotNull(value);
|
||||
checkArgument(value.compareTo(BigInteger.ZERO) != 0);
|
||||
checkArgument(!value.isZero());
|
||||
return value;
|
||||
}
|
||||
|
||||
public static BigInteger nonNegativeBigIntegerOf(BigInteger value)
|
||||
public static Coin positiveCoinOf(Coin value)
|
||||
{
|
||||
checkNotNull(value);
|
||||
checkArgument(value.compareTo(BigInteger.ZERO) >= 0);
|
||||
checkArgument(value.isPositive());
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
<logger name="com.google.bitcoin" level="WARN"/>
|
||||
|
||||
|
||||
<logger name="net.tomp2p" level="WARN"/>
|
||||
<logger name="net.tomp2p" level="DEBUG"/>
|
||||
|
||||
<logger name="io.netty.util" level="WARN"/>
|
||||
<logger name="io.netty.channel" level="WARN"/>
|
||||
|
@ -1,7 +1,7 @@
|
||||
package io.bitsquare.btc;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import java.math.BigInteger;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@ -12,11 +12,11 @@ public class BtcValidatorTest
|
||||
@Test
|
||||
public void testIsMinSpendableAmount()
|
||||
{
|
||||
BigInteger amount = null;
|
||||
Coin amount = null;
|
||||
//noinspection ConstantConditions
|
||||
assertFalse("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount));
|
||||
|
||||
amount = BigInteger.ZERO;
|
||||
amount = Coin.ZERO;
|
||||
assertFalse("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount));
|
||||
|
||||
amount = FeePolicy.TX_FEE;
|
||||
@ -28,7 +28,7 @@ public class BtcValidatorTest
|
||||
amount = FeePolicy.TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT);
|
||||
assertFalse("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount));
|
||||
|
||||
amount = FeePolicy.TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT).add(BigInteger.ONE);
|
||||
amount = FeePolicy.TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT).add(Coin.valueOf(1));
|
||||
assertTrue("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user