Skip to content

Commit

Permalink
Always use US locale when formatting debug strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
schildbach committed Jan 6, 2016
1 parent 0de458d commit feca024
Show file tree
Hide file tree
Showing 24 changed files with 68 additions and 54 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/core/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ private void checkTimestamp() throws VerificationException {
// Allow injection of a fake clock to allow unit testing.
long currentTime = Utils.currentTimeSeconds();
if (time > currentTime + ALLOWED_TIME_DRIFT)
throw new VerificationException(String.format("Block too far in future: %d vs %d", time, currentTime + ALLOWED_TIME_DRIFT));
throw new VerificationException(String.format(Locale.US, "Block too far in future: %d vs %d", time, currentTime + ALLOWED_TIME_DRIFT));
}

private void checkSigOps() throws VerificationException {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/core/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ private void processVersionMessage(VersionMessage m) throws ProtocolException {
peerVersion,
vPeerVersionMessage.subVer,
vPeerVersionMessage.localServices,
String.format("%tF %tT", peerTime, peerTime),
String.format(Locale.US, "%tF %tT", peerTime, peerTime),
vPeerVersionMessage.bestHeight);
// Now it's our turn ...
// Send an ACK message stating we accept the peers protocol version.
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/bitcoinj/core/PeerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ private void calculate() {
for (long sample : samples) average += sample;
average /= samples.length;

log.info(String.format("%d blocks/sec, %d tx/sec, %d pre-filtered tx/sec, avg/last %.2f/%.2f kilobytes per sec (stall threshold <%.2f KB/sec for %d seconds)",
log.info(String.format(Locale.US, "%d blocks/sec, %d tx/sec, %d pre-filtered tx/sec, avg/last %.2f/%.2f kilobytes per sec (stall threshold <%.2f KB/sec for %d seconds)",
blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond, average / 1024.0, bytesInLastSecond / 1024.0,
minSpeedBytesPerSec / 1024.0, samples.length));

Expand All @@ -1736,7 +1736,7 @@ private void calculate() {
log.warn("This network seems to be slower than the requested stall threshold - won't do stall disconnects any more.");
} else {
Peer peer = getDownloadPeer();
log.warn(String.format("Chain download stalled: received %.2f KB/sec for %d seconds, require average of %.2f KB/sec, disconnecting %s", average / 1024.0, samples.length, minSpeedBytesPerSec / 1024.0, peer));
log.warn(String.format(Locale.US, "Chain download stalled: received %.2f KB/sec for %d seconds, require average of %.2f KB/sec, disconnecting %s", average / 1024.0, samples.length, minSpeedBytesPerSec / 1024.0, peer));
peer.close();
// Reset the sample buffer and give the next peer time to get going.
samples = null;
Expand All @@ -1746,7 +1746,7 @@ private void calculate() {
} else {
warmupSeconds--;
if (bytesInLastSecond > 0)
log.info(String.format("%d blocks/sec, %d tx/sec, %d pre-filtered tx/sec, last %.2f kilobytes per sec",
log.info(String.format(Locale.US, "%d blocks/sec, %d tx/sec, %d pre-filtered tx/sec, last %.2f kilobytes per sec",
blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond, bytesInLastSecond / 1024.0));
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/bitcoinj/core/RejectMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.base.Objects;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Locale;

/**
* A message sent by nodes when a message we sent was rejected (ie a transaction had too little fee/was invalid/etc)
Expand Down Expand Up @@ -145,7 +146,7 @@ public String getReasonString() {
@Override
public String toString() {
Sha256Hash hash = getRejectedObjectHash();
return String.format("Reject: %s %s for reason '%s' (%d)", getRejectedMessage(),
return String.format(Locale.US, "Reject: %s %s for reason '%s' (%d)", getRejectedMessage(),
hash != null ? hash : "", getReasonString(), getReasonCode().code);
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/bitcoinj/core/StoredBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.Locale;

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

Expand Down Expand Up @@ -143,7 +144,7 @@ public static StoredBlock deserializeCompact(NetworkParameters params, ByteBuffe

@Override
public String toString() {
return String.format("Block %s at height %d: %s",
return String.format(Locale.US, "Block %s at height %d: %s",
getHeader().getHashAsString(), getHeight(), getHeader().toString());
}
}
14 changes: 7 additions & 7 deletions core/src/main/java/org/bitcoinj/core/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ public String toString() {
public String toString(@Nullable AbstractBlockChain chain) {
// Basic info about the tx.
StringBuilder s = new StringBuilder();
s.append(String.format(" %s: %s%n", getHashAsString(), getConfidence()));
s.append(String.format(Locale.US, " %s: %s%n", getHashAsString(), getConfidence()));
if (isTimeLocked()) {
String time;
if (lockTime < LOCKTIME_THRESHOLD) {
Expand All @@ -648,10 +648,10 @@ public String toString(@Nullable AbstractBlockChain chain) {
} else {
time = new Date(lockTime*1000).toString();
}
s.append(String.format(" time locked until %s%n", time));
s.append(String.format(Locale.US, " time locked until %s%n", time));
}
if (inputs.size() == 0) {
s.append(String.format(" INCOMPLETE: No inputs!%n"));
s.append(String.format(Locale.US, " INCOMPLETE: No inputs!%n"));
return s.toString();
}
if (isCoinBase()) {
Expand Down Expand Up @@ -692,7 +692,7 @@ public String toString(@Nullable AbstractBlockChain chain) {
} catch (Exception e) {
s.append("[exception: ").append(e.getMessage()).append("]");
}
s.append(String.format("%n"));
s.append(String.format(Locale.US, "%n"));
}
for (TransactionOutput out : outputs) {
s.append(" ");
Expand All @@ -712,13 +712,13 @@ public String toString(@Nullable AbstractBlockChain chain) {
} catch (Exception e) {
s.append("[exception: ").append(e.getMessage()).append("]");
}
s.append(String.format("%n"));
s.append(String.format(Locale.US, "%n"));
}
Coin fee = getFee();
if (fee != null)
s.append(" fee ").append(fee.toFriendlyString()).append(String.format("%n"));
s.append(" fee ").append(fee.toFriendlyString()).append(String.format(Locale.US, "%n"));
if (purpose != null)
s.append(" prps ").append(purpose).append(String.format("%n"));
s.append(" prps ").append(purpose).append(String.format(Locale.US, "%n"));
return s.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public synchronized String toString() {
builder.append("In conflict.");
break;
case BUILDING:
builder.append(String.format("Appeared in best chain at height %d, depth %d.",
builder.append(String.format(Locale.US, "Appeared in best chain at height %d, depth %d.",
getAppearedAtChainHeight(), getDepthInBlocks()));
break;
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/bitcoinj/core/UTXO.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.*;
import java.math.*;
import java.util.Locale;

// TODO: Fix this class: should not talk about addresses, height should be optional/support mempool height etc

Expand Down Expand Up @@ -156,7 +157,7 @@ public String getAddress() {

@Override
public String toString() {
return String.format("Stored TxOut of %s (%s:%d)", value.toFriendlyString(), hash, index);
return String.format(Locale.US, "Stored TxOut of %s (%s:%d)", value.toFriendlyString(), hash, index);
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/org/bitcoinj/core/VersionMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Locale;

/**
* A VersionMessage holds information exchanged during connection setup with another peer. Most of the fields are not
Expand Down Expand Up @@ -259,9 +260,9 @@ public void appendToSubVer(String name, String version, @Nullable String comment
checkSubVerComponent(version);
if (comments != null) {
checkSubVerComponent(comments);
subVer = subVer.concat(String.format("%s:%s(%s)/", name, version, comments));
subVer = subVer.concat(String.format(Locale.US, "%s:%s(%s)/", name, version, comments));
} else {
subVer = subVer.concat(String.format("%s:%s/", name, version));
subVer = subVer.concat(String.format(Locale.US, "%s:%s/", name, version));
}
}

Expand Down
18 changes: 9 additions & 9 deletions core/src/main/java/org/bitcoinj/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ public void receivePending(Transaction tx, @Nullable List<Transaction> dependenc
Coin valueSentToMe = tx.getValueSentToMe(this);
Coin valueSentFromMe = tx.getValueSentFromMe(this);
if (log.isInfoEnabled()) {
log.info(String.format("Received a pending transaction %s that spends %s from our own wallet," +
log.info(String.format(Locale.US, "Received a pending transaction %s that spends %s from our own wallet," +
" and sends us %s", tx.getHashAsString(), valueSentFromMe.toFriendlyString(),
valueSentToMe.toFriendlyString()));
}
Expand Down Expand Up @@ -2943,27 +2943,27 @@ public String toString(boolean includePrivateKeys, boolean includeTransactions,
StringBuilder builder = new StringBuilder();
Coin estimatedBalance = getBalance(BalanceType.ESTIMATED);
Coin availableBalance = getBalance(BalanceType.AVAILABLE_SPENDABLE);
builder.append(String.format("Wallet containing %s BTC (spendable: %s BTC) in:%n",
builder.append(String.format(Locale.US, "Wallet containing %s BTC (spendable: %s BTC) in:%n",
estimatedBalance.toPlainString(), availableBalance.toPlainString()));
builder.append(String.format(" %d pending transactions%n", pending.size()));
builder.append(String.format(" %d unspent transactions%n", unspent.size()));
builder.append(String.format(" %d spent transactions%n", spent.size()));
builder.append(String.format(" %d dead transactions%n", dead.size()));
builder.append(String.format(Locale.US, " %d pending transactions%n", pending.size()));
builder.append(String.format(Locale.US, " %d unspent transactions%n", unspent.size()));
builder.append(String.format(Locale.US, " %d spent transactions%n", spent.size()));
builder.append(String.format(Locale.US, " %d dead transactions%n", dead.size()));
final Date lastBlockSeenTime = getLastBlockSeenTime();
final String lastBlockSeenTimeStr = lastBlockSeenTime == null ? "time unknown" : lastBlockSeenTime.toString();
builder.append(String.format("Last seen best block: %d (%s): %s%n",
builder.append(String.format(Locale.US, "Last seen best block: %d (%s): %s%n",
getLastBlockSeenHeight(), lastBlockSeenTimeStr, getLastBlockSeenHash()));
final KeyCrypter crypter = keyChainGroup.getKeyCrypter();
if (crypter != null)
builder.append(String.format("Encryption: %s%n", crypter));
builder.append(String.format(Locale.US, "Encryption: %s%n", crypter));
if (isWatching())
builder.append("Wallet is watching.\n");

// Do the keys.
builder.append("\nKeys:\n");
final long keyRotationTime = vKeyRotationTimestamp * 1000;
if (keyRotationTime > 0)
builder.append(String.format("Key rotation time: %s\n", Utils.dateTimeFormat(keyRotationTime)));
builder.append(String.format(Locale.US, "Key rotation time: %s\n", Utils.dateTimeFormat(keyRotationTime)));
builder.append(keyChainGroup.toString(includePrivateKeys));

if (!watchedScripts.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import javax.annotation.*;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.ExecutionException;

/**
Expand Down Expand Up @@ -86,7 +87,7 @@ public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock f
* @param date the date of the last block downloaded
*/
protected void progress(double pct, int blocksSoFar, Date date) {
log.info(String.format("Chain download %d%% done with %d blocks to go, block date %s", (int) pct, blocksSoFar,
log.info(String.format(Locale.US, "Chain download %d%% done with %d blocks to go, block date %s", (int) pct, blocksSoFar,
Utils.dateTimeFormat(date)));
}

Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/org/bitcoinj/crypto/ChildNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.bitcoinj.crypto;

import java.util.Locale;

import com.google.common.primitives.Ints;

/**
Expand Down Expand Up @@ -73,7 +75,7 @@ public int num() {

@Override
public String toString() {
return String.format("%d%s", num(), isHardened() ? "H" : "");
return String.format(Locale.US, "%d%s", num(), isHardened() ? "H" : "");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.Maps;

import java.util.List;
import java.util.Locale;
import java.util.Map;

import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -85,7 +86,7 @@ public DeterministicKey get(List<ChildNumber> path, boolean relativePath, boolea
: ImmutableList.copyOf(path);
if (!keys.containsKey(absolutePath)) {
if (!create)
throw new IllegalArgumentException(String.format("No key found for %s path %s.",
throw new IllegalArgumentException(String.format(Locale.US, "No key found for %s path %s.",
relativePath ? "relative" : "absolute", HDUtils.formatPath(path)));
checkArgument(absolutePath.size() > 0, "Can't derive the master key: nothing to derive from.");
DeterministicKey parent = get(absolutePath.subList(0, absolutePath.size() - 1), false, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Locale;

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

Expand Down Expand Up @@ -399,7 +400,7 @@ public synchronized ListenableFuture<Transaction> close() throws InsufficientMon
feePaidForPayment = req.tx.getFee();
log.info("Calculated fee is {}", feePaidForPayment);
if (feePaidForPayment.compareTo(bestValueToMe) > 0) {
final String msg = String.format("Had to pay more in fees (%s) than the channel was worth (%s)",
final String msg = String.format(Locale.US, "Had to pay more in fees (%s) than the channel was worth (%s)",
feePaidForPayment, bestValueToMe);
throw new InsufficientMoneyException(feePaidForPayment.subtract(bestValueToMe), msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import javax.annotation.Nullable;
import java.util.Date;
import java.util.Locale;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
Expand Down Expand Up @@ -371,9 +372,9 @@ long expiryTimeSeconds() {

@Override
public String toString() {
final String newline = String.format("%n");
final String newline = String.format(Locale.US, "%n");
final String closeStr = close == null ? "still open" : close.toString().replaceAll(newline, newline + " ");
return String.format("Stored client channel for server ID %s (%s)%n" +
return String.format(Locale.US, "Stored client channel for server ID %s (%s)%n" +
" Key: %s%n" +
" Value left: %s%n" +
" Refund fees: %s%n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.annotation.Nullable;
import java.util.Date;
import java.util.Locale;

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

Expand Down Expand Up @@ -103,8 +104,8 @@ public synchronized PaymentChannelServerState getOrCreateState(Wallet wallet, Tr

@Override
public synchronized String toString() {
final String newline = String.format("%n");
return String.format("Stored server channel (%s)%n" +
final String newline = String.format(Locale.US, "%n");
return String.format(Locale.US, "Stored server channel (%s)%n" +
" Key: %s%n" +
" Value to me: %s%n" +
" Client output: %s%n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ public void dumpSizes() throws SQLException, BlockStoreException {
count++;
}
rs.close();
System.out.printf("Settings size: %d, count: %d, average size: %f%n", size, count, (double)size/count);
System.out.printf(Locale.US, "Settings size: %d, count: %d, average size: %f%n", size, count, (double)size/count);

totalSize += size; size = 0; count = 0;
rs = s.executeQuery(getSelectHeadersDumpSQL());
Expand All @@ -1227,7 +1227,7 @@ public void dumpSizes() throws SQLException, BlockStoreException {
count++;
}
rs.close();
System.out.printf("Headers size: %d, count: %d, average size: %f%n", size, count, (double)size/count);
System.out.printf(Locale.US, "Headers size: %d, count: %d, average size: %f%n", size, count, (double)size/count);

totalSize += size; size = 0; count = 0;
rs = s.executeQuery(getSelectUndoableblocksDumpSQL());
Expand All @@ -1244,7 +1244,7 @@ public void dumpSizes() throws SQLException, BlockStoreException {
count++;
}
rs.close();
System.out.printf("Undoable Blocks size: %d, count: %d, average size: %f%n", size, count, (double)size/count);
System.out.printf(Locale.US, "Undoable Blocks size: %d, count: %d, average size: %f%n", size, count, (double)size/count);

totalSize += size; size = 0; count = 0;
long scriptSize = 0;
Expand All @@ -1259,7 +1259,7 @@ public void dumpSizes() throws SQLException, BlockStoreException {
count++;
}
rs.close();
System.out.printf("Open Outputs size: %d, count: %d, average size: %f, average script size: %f (%d in id indexes)%n",
System.out.printf(Locale.US, "Open Outputs size: %d, count: %d, average size: %f, average script size: %f (%d in id indexes)%n",
size, count, (double)size/count, (double)scriptSize/count, count * 8);

totalSize += size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ private void readTransaction(Protos.Transaction txProto, NetworkParameters param
// Transaction should now be complete.
Sha256Hash protoHash = byteStringToHash(txProto.getHash());
if (!tx.getHash().equals(protoHash))
throw new UnreadableWalletException(String.format("Transaction did not deserialize completely: %s vs %s", tx.getHash(), protoHash));
throw new UnreadableWalletException(String.format(Locale.US, "Transaction did not deserialize completely: %s vs %s", tx.getHash(), protoHash));
if (txMap.containsKey(txProto.getHash()))
throw new UnreadableWalletException("Wallet contained duplicate transaction " + byteStringToHash(txProto.getHash()));
txMap.put(txProto.getHash(), tx);
Expand Down Expand Up @@ -699,7 +699,7 @@ private WalletTransaction connectTransactionOutputs(final NetworkParameters para
final ByteString spentByTransactionHash = transactionOutput.getSpentByTransactionHash();
Transaction spendingTx = txMap.get(spentByTransactionHash);
if (spendingTx == null) {
throw new UnreadableWalletException(String.format("Could not connect %s to %s",
throw new UnreadableWalletException(String.format(Locale.US, "Could not connect %s to %s",
tx.getHashAsString(), byteStringToHash(spentByTransactionHash)));
}
final int spendingIndex = transactionOutput.getSpentByTransactionIndex();
Expand Down

0 comments on commit feca024

Please sign in to comment.