Skip to content

Commit

Permalink
Merge pull request #4 from bitsquare/Development
Browse files Browse the repository at this point in the history
update fork
  • Loading branch information
SimonTuberlin authored Feb 9, 2017
2 parents 32de676 + 7aea53b commit d91e83d
Show file tree
Hide file tree
Showing 67 changed files with 397 additions and 176 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/io/bitsquare/app/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Version {

// The version no. of the current protocol. The offer holds that version.
// A taker will check the version of the offers to see if his version is compatible.
public static final int TRADE_PROTOCOL_VERSION = 1;
public static final int TRADE_PROTOCOL_VERSION = 2;
private static int p2pMessageVersion;

public static int getP2PMessageVersion() {
Expand Down
42 changes: 42 additions & 0 deletions common/src/main/java/io/bitsquare/common/util/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.bitsquare.io.LookAheadObjectInputStream;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -420,4 +421,45 @@ public static String toTruncatedString(Object message, int maxLenght) {
public static String toTruncatedString(Object message) {
return toTruncatedString(message, 200);
}

public static String getRandomPrefix(int minLength, int maxLength) {
int length = minLength + new Random().nextInt(maxLength - minLength + 1);
String result;
switch (new Random().nextInt(3)) {
case 0:
result = RandomStringUtils.randomAlphabetic(length);
break;
case 1:
result = RandomStringUtils.randomNumeric(length);
break;
case 2:
default:
result = RandomStringUtils.randomAlphanumeric(length);
}

switch (new Random().nextInt(3)) {
case 0:
result = result.toUpperCase();
break;
case 1:
result = result.toLowerCase();
break;
case 2:
default:
}

return result;
}

public static String getShortId(String id) {
return getShortId(id, "-");
}

public static String getShortId(String id, String sep) {
String[] chunks = id.split(sep);
if (chunks.length > 0)
return chunks[0];
else
return id.substring(0, Math.min(8, id.length()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public static void setDefaultAppName(String defaultAppName) {
public static final String DEFAULT_USER_DATA_DIR = defaultUserDataDir();
public static final String DEFAULT_APP_DATA_DIR = appDataDir(DEFAULT_USER_DATA_DIR, DEFAULT_APP_NAME);

//public static final String LOG_LEVEL_DEFAULT = (DevFlags.STRESS_TEST_MODE || DevFlags.DEV_MODE) ? Level.TRACE.levelStr : Level.INFO.levelStr;
public static final String LOG_LEVEL_DEFAULT = Level.INFO.levelStr;

static final String BITSQUARE_COMMANDLINE_PROPERTY_SOURCE_NAME = "bitsquareCommandLineProperties";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public class ArbitratorManager {
"02b517c0cbc3a49548f448ddf004ed695c5a1c52ec110be1bfd65fa0ca0761c94b",
"03df837a3a0f3d858e82f3356b71d1285327f101f7c10b404abed2abc1c94e7169",
"0203a90fb2ab698e524a5286f317a183a84327b8f8c3f7fa4a98fec9e1cefd6b72",
"023c99cc073b851c892d8c43329ca3beb5d2213ee87111af49884e3ce66cbd5ba5",
"0274f772a98d23e7a0251ab30d7121897b5aebd11a2f1e45ab654aa57503173245"
"023c99cc073b851c892d8c43329ca3beb5d2213ee87111af49884e3ce66cbd5ba5"
));


Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/io/bitsquare/arbitration/Dispute.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.bitsquare.app.Version;
import io.bitsquare.arbitration.messages.DisputeCommunicationMessage;
import io.bitsquare.common.crypto.PubKeyRing;
import io.bitsquare.common.util.Utilities;
import io.bitsquare.common.wire.Payload;
import io.bitsquare.storage.Storage;
import io.bitsquare.trade.Contract;
Expand Down Expand Up @@ -195,7 +196,7 @@ public String getTradeId() {
}

public String getShortTradeId() {
return tradeId.substring(0, 8);
return Utilities.getShortId(tradeId);
}

public int getTraderId() {
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/io/bitsquare/btc/AddressEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.bitsquare.app.Version;
import io.bitsquare.common.persistance.Persistable;
import io.bitsquare.common.util.Utilities;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.NetworkParameters;
Expand Down Expand Up @@ -136,7 +137,7 @@ public String getOfferId() {
// For display we usually only display the first 8 characters.
@Nullable
public String getShortOfferId() {
return getOfferId() != null ? getOfferId().substring(0, Math.min(8, getOfferId().length())) : null;
return offerId != null ? Utilities.getShortId(offerId) : null;
}

public Context getContext() {
Expand Down
33 changes: 16 additions & 17 deletions core/src/main/java/io/bitsquare/btc/FeePolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,27 @@ public class FeePolicy {
// With block getting filled up the needed fee to get fast into a black has become more expensive and less predictable.
// To see current fees check out:
// https://tradeblock.com/blockchain
// http://www.cointape.com
// https://jochen-hoenicke.de/queue/24h.html
// https://bitcoinfees.21.co/
// http://p2sh.info/dashboard/db/fee-estimation
// https://bitcoinfees.github.io/#1d
// Average values are 10-100 satoshis/byte in january 2016
// Average values are 60-140 satoshis/byte in february 2017
//
// Our trade transactions have a fixed set of inputs and outputs making the size very predictable
// (as long the user does not do multiple funding transactions)
//
// trade fee tx: 226 bytes // 88 satoshi/byte
// deposit tx: 336 bytes // 59 satoshi/byte
// payout tx: 371 bytes // 53 satoshi/byte
// disputed payout tx: 408 bytes // 49 satoshi/byte
// trade fee tx: 226 bytes // 221 satoshi/byte
// deposit tx: 336 bytes // 148 satoshi/byte
// payout tx: 371 bytes // 134 satoshi/byte
// disputed payout tx: 408 bytes // 122 satoshi/byte

// We set a fixed fee to make the needed amounts in the trade predictable.
// We use 0.0002 BTC (0.08 EUR @ 400 EUR/BTC) which is for our tx sizes about 50-90 satoshi/byte
// We use 0.0005 BTC (0.5 EUR @ 1000 EUR/BTC) which is for our tx sizes about 120-220 satoshi/byte
// We cannot make that user defined as it need to be the same for both users, so we can only change that in
// software updates
// TODO before Beta we should get a good future proof guess as a change causes incompatible versions
public static Coin getFixedTxFeeForTrades() {
return DevFlags.STRESS_TEST_MODE ? Coin.valueOf(5_000) : Coin.valueOf(20_000);
return DevFlags.STRESS_TEST_MODE ? Coin.valueOf(5_000) : Coin.valueOf(50_000);
}

// For non trade transactions (withdrawal) we use the default fee calculation
Expand All @@ -63,22 +64,20 @@ public static Coin getNonTradeFeePerKb() {
return NON_TRADE_FEE_PER_KB;
}

// 0.0005 BTC 0.05% of 1 BTC about 0.2 EUR @ 400 EUR/BTC
// 0.0008 BTC 0.08% of 1 BTC about 0.8 EUR @ 1000 EUR/BTC
public static Coin getCreateOfferFee() {
// We need to pay the quite high miner fee of 30_000 from the trading fee tx so 30_000 us our lower limit
// The arbitrator receive only 0.0002 BTC - less than the miners
return DevFlags.STRESS_TEST_MODE ? Coin.valueOf(10_000) : Coin.valueOf(50_000);
// We need to pay the quite high miner fee of 50_000 from the trading fee tx so 30_000 is what
// the arbitrator receives
return DevFlags.STRESS_TEST_MODE ? Coin.valueOf(10_000) : Coin.valueOf(80_000);
}

// 0.001 BTC 0.1% of 1 BTC about 0.4 EUR @ 400 EUR/BTC
// 0.001 BTC 0.1% of 1 BTC about 1 EUR @ 1000 EUR/BTC
public static Coin getTakeOfferFee() {
return DevFlags.STRESS_TEST_MODE ? Coin.valueOf(10_000) : Coin.valueOf(100_000);
}


// TODO will be increased once we get higher limits
// 0.01 BTC; about 4 EUR @ 400 EUR/BTC
// 0.03 BTC; about 30 EUR @ 1000 EUR/BTC
public static Coin getSecurityDeposit() {
return DevFlags.STRESS_TEST_MODE ? Coin.valueOf(5_000) : Coin.valueOf(1_000_000);
return DevFlags.STRESS_TEST_MODE ? Coin.valueOf(5_000) : Coin.valueOf(3_000_000);
}
}
32 changes: 18 additions & 14 deletions core/src/main/java/io/bitsquare/btc/TradeWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ OUT[0] dummyOutputAmount (inputAmount - tx fee)

verifyTransaction(dummyTX);

printTxWithInputs("dummyTX", dummyTX);
//printTxWithInputs("dummyTX", dummyTX);

List<RawTransactionInput> rawTransactionInputList = dummyTX.getInputs().stream()
.map(e -> {
Expand Down Expand Up @@ -407,7 +407,7 @@ public PreparedDepositTxAndOffererInputs offererCreatesAndSignsDepositTx(boolean

verifyTransaction(preparedDepositTx);

printTxWithInputs("preparedDepositTx", preparedDepositTx);
//printTxWithInputs("preparedDepositTx", preparedDepositTx);

return new PreparedDepositTxAndOffererInputs(offererRawTransactionInputs, preparedDepositTx.bitcoinSerialize());
}
Expand All @@ -429,14 +429,14 @@ public PreparedDepositTxAndOffererInputs offererCreatesAndSignsDepositTx(boolean
* @throws WalletException
*/
public Transaction takerSignsAndPublishesDepositTx(boolean takerIsSeller,
byte[] contractHash,
byte[] offerersDepositTxSerialized,
List<RawTransactionInput> buyerInputs,
List<RawTransactionInput> sellerInputs,
byte[] buyerPubKey,
byte[] sellerPubKey,
byte[] arbitratorPubKey,
FutureCallback<Transaction> callback) throws SigningException, TransactionVerificationException,
byte[] contractHash,
byte[] offerersDepositTxSerialized,
List<RawTransactionInput> buyerInputs,
List<RawTransactionInput> sellerInputs,
byte[] buyerPubKey,
byte[] sellerPubKey,
byte[] arbitratorPubKey,
FutureCallback<Transaction> callback) throws SigningException, TransactionVerificationException,
WalletException {
Transaction offerersDepositTx = new Transaction(params, offerersDepositTxSerialized);

Expand Down Expand Up @@ -493,7 +493,7 @@ public Transaction takerSignsAndPublishesDepositTx(boolean takerIsSeller,

// Add all outputs from offerersDepositTx to depositTx
offerersDepositTx.getOutputs().forEach(depositTx::addOutput);
printTxWithInputs("offerersDepositTx", offerersDepositTx);
//printTxWithInputs("offerersDepositTx", offerersDepositTx);

// Sign inputs
int start = takerIsSeller ? buyerInputs.size() : 0;
Expand Down Expand Up @@ -577,7 +577,7 @@ public byte[] sellerSignsPayoutTx(Transaction depositTx,

verifyTransaction(preparedPayoutTx);

printTxWithInputs("preparedPayoutTx", preparedPayoutTx);
//printTxWithInputs("preparedPayoutTx", preparedPayoutTx);

return sellerSignature.encodeToDER();
}
Expand Down Expand Up @@ -732,7 +732,7 @@ public byte[] arbitratorSignsDisputedPayoutTx(byte[] depositTxSerialized,

verifyTransaction(preparedPayoutTx);

printTxWithInputs("preparedPayoutTx", preparedPayoutTx);
//printTxWithInputs("preparedPayoutTx", preparedPayoutTx);

return arbitratorSignature.encodeToDER();
}
Expand Down Expand Up @@ -1122,7 +1122,11 @@ private Transaction createPayoutTx(Transaction depositTx,
}

private static void printTxWithInputs(String tracePrefix, Transaction tx) {
log.info(tracePrefix + ": " + tx.toString());
long fee = tx.getFee() != null ? tx.getFee().value : 0;
int size = tx.getMessageSize();
log.info(tracePrefix + ": " + tx.toString() + "\nSize (Byte): " + size + "\nFee (Satoshi/Byte): "
+ (fee / size));

for (TransactionInput input : tx.getInputs()) {
if (input.getConnectedOutput() != null)
log.info(tracePrefix + " input value: " + input.getConnectedOutput().getValue().toFriendlyString());
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/io/bitsquare/locale/CountryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public static List<Country> getAllCountries() {
}

allCountries.add(new Country("GE", "Georgia", new Region("AS", getRegionName("AS"))));

allCountries.add(new Country("BW", "Botswana", new Region("AF", getRegionName("AF"))));

final List<Country> allCountriesList = new ArrayList<>(allCountries);
allCountriesList.sort((locale1, locale2) -> locale1.name.compareTo(locale2.name));
return allCountriesList;
Expand All @@ -164,7 +165,7 @@ private static List<String> getNamesByCodes(List<String> countryCodes) {

// other source of countries: https://developers.braintreepayments.com/reference/general/countries/java
private static final String[] countryCodes = new String[]{"AE", "AL", "AR", "AT", "AU", "BA", "BE", "BG", "BH",
"BO", "BR", "BY", "CA", "CH", "CL", "CN", "CO", "CR", "CS", "CU", "CY", "CZ", "DE", "DK", "DO", "DZ",
"BO", "BR", "BW", "BY", "CA", "CH", "CL", "CN", "CO", "CR", "CS", "CU", "CY", "CZ", "DE", "DK", "DO", "DZ",
"EC", "EE", "EG", "ES", "FI", "FR", "GE", "GB", "GR", "GT", "HK", "HN", "HR", "HU", "ID", "IE", "IL", "IN",
"IQ", "IS", "IT", "JO", "JP", "KE", "KH", "KR", "KW", "KZ", "LB", "LT", "LU", "LV", "LY", "MA", "MD", "ME", "MK", "MT", "MX",
"MY", "NI", "NL", "NO", "NZ", "OM", "PA", "PE", "PH", "PL", "PR", "PT", "PY", "QA", "RO", "RS", "RU",
Expand All @@ -173,7 +174,7 @@ private static List<String> getNamesByCodes(List<String> countryCodes) {

private static final List<String> countryCodeList = Arrays.asList(countryCodes);
private static final String[] regionCodes = new String[]{"AS", "EU", "SA", "EU", "OC", "EU", "EU", "EU", "AS",
"SA", "SA", "EU", "NA", "EU", "SA", "AS", "SA", "NA", "EU", "NA", "EU", "EU", "EU", "EU", "NA", "AF",
"SA", "SA", "AF", "EU", "NA", "EU", "SA", "AS", "SA", "NA", "EU", "NA", "EU", "EU", "EU", "EU", "NA", "AF",
"SA", "EU", "AF", "EU", "EU", "EU", "AS", "EU", "EU", "NA", "AS", "NA", "EU", "EU", "AS", "EU", "AS", "AS",
"AS", "EU", "EU", "AS", "AS", "AF", "AS", "AS", "AS", "AS", "AS", "EU", "EU", "EU", "AF", "AF", "EU", "EU", "EU", "EU", "NA",
"AS", "NA", "EU", "EU", "OC", "AS", "NA", "SA", "AS", "EU", "NA", "EU", "SA", "AS", "EU", "EU", "EU",
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/io/bitsquare/locale/CurrencyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public static List<CryptoCurrency> createAllSortedCryptoCurrenciesList() {
result.add(new CryptoCurrency("JPYT", "JPY Tether"));
result.add(new CryptoCurrency("JBS", "Jumbucks"));
result.add(new CryptoCurrency("LBC", "LBRY Credits"));
result.add(new CryptoCurrency("LTBC", "LTBcoin"));
result.add(new CryptoCurrency("LSK", "Lisk"));
result.add(new CryptoCurrency("LTC", "Litecoin"));
result.add(new CryptoCurrency("MAID", "MaidSafeCoin"));
Expand All @@ -159,6 +160,7 @@ public static List<CryptoCurrency> createAllSortedCryptoCurrenciesList() {
result.add(new CryptoCurrency("PASC", "Pascal Coin"));
result.add(new CryptoCurrency("PPC", "Peercoin"));
result.add(new CryptoCurrency("PINK", "Pinkcoin"));
result.add(new CryptoCurrency("PIVX", "PIVX"));
result.add(new CryptoCurrency("XPTX", "PlatinumBar"));
result.add(new CryptoCurrency("PLU", "Plutons", true));
result.add(new CryptoCurrency("POST", "PostCoin"));
Expand All @@ -168,6 +170,7 @@ public static List<CryptoCurrency> createAllSortedCryptoCurrenciesList() {
result.add(new CryptoCurrency("REALEST", "RealEst. Coin"));
result.add(new CryptoCurrency("RDD", "ReddCoin"));
result.add(new CryptoCurrency("XRP", "Ripple"));
result.add(new CryptoCurrency("SFSC", "Safe FileSystem Coin"));
result.add(new CryptoCurrency("STEEM", "STEEM"));
result.add(new CryptoCurrency("SDC", "ShadowCash"));
result.add(new CryptoCurrency("SHIFT", "Shift"));
Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/io/bitsquare/trade/offer/Offer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.bitsquare.common.handlers.ResultHandler;
import io.bitsquare.common.util.JsonExclude;
import io.bitsquare.common.util.MathUtils;
import io.bitsquare.common.util.Utilities;
import io.bitsquare.locale.CurrencyUtil;
import io.bitsquare.p2p.NodeAddress;
import io.bitsquare.p2p.storage.payload.RequiresOwnerIsOnlinePayload;
Expand Down Expand Up @@ -276,10 +277,6 @@ public Fiat getMinOfferVolume() {
return getVolumeByAmount(getMinAmount());
}

public String getReferenceText() {
return getId().substring(0, Math.min(8, getId().length()));
}


///////////////////////////////////////////////////////////////////////////////////////////
// Availability
Expand Down Expand Up @@ -352,7 +349,7 @@ public String getId() {
}

public String getShortId() {
return getId().substring(0, Math.min(8, getId().length()));
return Utilities.getShortId(id);
}

public NodeAddress getOffererNodeAddress() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public class OfferAvailabilityProtocol {
private static final Logger log = LoggerFactory.getLogger(OfferAvailabilityProtocol.class);

private static final long TIMEOUT_SEC = 45;
private static final long TIMEOUT_SEC = 60;

private final OfferAvailabilityModel model;
private final ResultHandler resultHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public abstract class TradeProtocol {
private static final Logger log = LoggerFactory.getLogger(TradeProtocol.class);
private static final long TIMEOUT_SEC = 60;
private static final long TIMEOUT_SEC = 90;

protected final ProcessModel processModel;
private final DecryptedDirectMessageListener decryptedDirectMessageListener;
Expand Down
6 changes: 3 additions & 3 deletions doc/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ To contribute a patch, the workflow is as follows:
Please do not make pull requests to the Master branch but always use the Development branch!


Copyright
Workflow for merging code
---------

We are aiming to follow the principles and establish the workflow used at the Bitcoin Core project.
Please check out the [Bitcoin Core documentation](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md) for more info.
The full workflow is not used yet as there are not enough dedicated developers, but as soon that situation changes we will move
The full workflow is not used yet as there are not that many dedicated developers yet, but as soon that situation changes we will move
to a model with ACK/NACK, code reviews and maintainer roles.

Copyright
---------

By contributing to this repository, you agree to license your work under the AGPL license.
Please include the license header into your files.
Please include the Bitsquare license header into your files.
2 changes: 1 addition & 1 deletion doc/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ In Debian/Ubuntu systems with OpenJDK you'll need OpenJFX as well, i.e. you'll n

$ java -version

If `java` is not found, or your version is anything less than `1.8.0_112`, then follow the next steps, otherwise you can skip to step 2:
If `java` is not found, or your version is anything less than `1.8.0_121`, then follow the next steps, otherwise you can skip to step 2:

#### 1.1 Debian based systems (Ubuntu)

Expand Down
Loading

0 comments on commit d91e83d

Please sign in to comment.