mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-14 19:25:51 +00:00
Clean up toString and other string-related code.
This commit is contained in:
parent
fd52c86bf9
commit
820765753c
@ -142,13 +142,7 @@ public class AddressMessage extends Message {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
return "addr: " + Utils.join(addresses);
|
||||||
builder.append("addr: ");
|
|
||||||
for (PeerAddress a : addresses) {
|
|
||||||
builder.append(a.toString());
|
|
||||||
builder.append(" ");
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -585,27 +585,15 @@ public class Block extends Message {
|
|||||||
StringBuilder s = new StringBuilder("v");
|
StringBuilder s = new StringBuilder("v");
|
||||||
s.append(version);
|
s.append(version);
|
||||||
s.append(" block: \n");
|
s.append(" block: \n");
|
||||||
s.append(" previous block: ");
|
s.append(" previous block: ").append(getPrevBlockHash()).append("\n");
|
||||||
s.append(getPrevBlockHash());
|
s.append(" merkle root: ").append(getMerkleRoot()).append("\n");
|
||||||
s.append("\n");
|
s.append(" time: [").append(time).append("] ").append(Utils.dateTimeFormat(time * 1000)).append("\n");
|
||||||
s.append(" merkle root: ");
|
s.append(" difficulty target (nBits): ").append(difficultyTarget).append("\n");
|
||||||
s.append(getMerkleRoot());
|
s.append(" nonce: ").append(nonce).append("\n");
|
||||||
s.append("\n");
|
|
||||||
s.append(" time: [");
|
|
||||||
s.append(time);
|
|
||||||
s.append("] ");
|
|
||||||
s.append(Utils.dateTimeFormat(time * 1000));
|
|
||||||
s.append("\n");
|
|
||||||
s.append(" difficulty target (nBits): ");
|
|
||||||
s.append(difficultyTarget);
|
|
||||||
s.append("\n");
|
|
||||||
s.append(" nonce: ");
|
|
||||||
s.append(nonce);
|
|
||||||
s.append("\n");
|
|
||||||
if (transactions != null && transactions.size() > 0) {
|
if (transactions != null && transactions.size() > 0) {
|
||||||
s.append(" with ").append(transactions.size()).append(" transaction(s):\n");
|
s.append(" with ").append(transactions.size()).append(" transaction(s):\n");
|
||||||
for (Transaction tx : transactions) {
|
for (Transaction tx : transactions) {
|
||||||
s.append(tx.toString());
|
s.append(tx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s.toString();
|
return s.toString();
|
||||||
|
@ -76,13 +76,7 @@ public class GetBlocksMessage extends Message {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer b = new StringBuffer();
|
return "getblocks: " + Utils.join(locator);
|
||||||
b.append("getblocks: ");
|
|
||||||
for (Sha256Hash hash : locator) {
|
|
||||||
b.append(hash.toString());
|
|
||||||
b.append(" ");
|
|
||||||
}
|
|
||||||
return b.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,13 +35,7 @@ public class GetHeadersMessage extends GetBlocksMessage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer b = new StringBuffer();
|
return "getheaders: " + Utils.join(locator);
|
||||||
b.append("getheaders: ");
|
|
||||||
for (Sha256Hash hash : locator) {
|
|
||||||
b.append(hash.toString());
|
|
||||||
b.append(" ");
|
|
||||||
}
|
|
||||||
return b.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,7 +40,7 @@ public class InventoryItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return type.toString() + ": " + hash;
|
return type + ": " + hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -273,12 +273,8 @@ public class Peer extends PeerSocketHandler {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
PeerAddress addr = getAddress();
|
PeerAddress addr = getAddress();
|
||||||
if (addr == null) {
|
// if null, it's a user-provided NetworkConnection object
|
||||||
// User-provided NetworkConnection object.
|
return addr == null ? "Peer()" : addr.toString();
|
||||||
return "Peer()";
|
|
||||||
} else {
|
|
||||||
return addr.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -501,9 +497,9 @@ public class Peer extends PeerSocketHandler {
|
|||||||
private void processAlert(AlertMessage m) {
|
private void processAlert(AlertMessage m) {
|
||||||
try {
|
try {
|
||||||
if (m.isSignatureValid()) {
|
if (m.isSignatureValid()) {
|
||||||
log.info("Received alert from peer {}: {}", toString(), m.getStatusBar());
|
log.info("Received alert from peer {}: {}", this, m.getStatusBar());
|
||||||
} else {
|
} else {
|
||||||
log.warn("Received alert with invalid signature from peer {}: {}", toString(), m.getStatusBar());
|
log.warn("Received alert with invalid signature from peer {}: {}", this, m.getStatusBar());
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
// Signature checking can FAIL on Android platforms before Gingerbread apparently due to bugs in their
|
// Signature checking can FAIL on Android platforms before Gingerbread apparently due to bugs in their
|
||||||
@ -1306,7 +1302,7 @@ public class Peer extends PeerSocketHandler {
|
|||||||
}
|
}
|
||||||
if (log.isDebugEnabled())
|
if (log.isDebugEnabled())
|
||||||
log.debug("{}: blockChainDownloadLocked({}) current head = {}",
|
log.debug("{}: blockChainDownloadLocked({}) current head = {}",
|
||||||
toString(), toHash.toString(), chainHead.getHeader().getHashAsString());
|
this, toHash, chainHead.getHeader().getHashAsString());
|
||||||
StoredBlock cursor = chainHead;
|
StoredBlock cursor = chainHead;
|
||||||
for (int i = 100; cursor != null && i > 0; i--) {
|
for (int i = 100; cursor != null && i > 0; i--) {
|
||||||
blockLocator.add(cursor.getHeader().getHash());
|
blockLocator.add(cursor.getHeader().getHash());
|
||||||
|
@ -152,12 +152,8 @@ public class RejectMessage extends Message {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
Sha256Hash hash = getRejectedObjectHash();
|
Sha256Hash hash = getRejectedObjectHash();
|
||||||
if (hash != null)
|
return String.format("Reject: %s %s for reason '%s' (%d)", getRejectedMessage(),
|
||||||
return String.format("Reject: %s %s for reason '%s' (%d)", getRejectedMessage(), getRejectedObjectHash(),
|
hash != null ? hash : "", getReasonString(), getReasonCode().code);
|
||||||
getReasonString(), getReasonCode().code);
|
|
||||||
else
|
|
||||||
return String.format("Reject: %s for reason '%s' (%d)", getRejectedMessage(),
|
|
||||||
getReasonString(), getReasonCode().code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -86,6 +86,6 @@ public class StoredUndoableBlock implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Undoable Block " + blockHash.toString();
|
return "Undoable Block " + blockHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -647,7 +647,8 @@ public class Transaction extends ChildMessage implements Serializable {
|
|||||||
script = "???";
|
script = "???";
|
||||||
script2 = "???";
|
script2 = "???";
|
||||||
}
|
}
|
||||||
s.append(" == COINBASE TXN (scriptSig " + script + ") (scriptPubKey " + script2 + ")\n");
|
s.append(" == COINBASE TXN (scriptSig ").append(script)
|
||||||
|
.append(") (scriptPubKey ").append(script2).append(")\n");
|
||||||
return s.toString();
|
return s.toString();
|
||||||
}
|
}
|
||||||
for (TransactionInput in : inputs) {
|
for (TransactionInput in : inputs) {
|
||||||
|
@ -322,12 +322,7 @@ public class TransactionConfidence implements Serializable {
|
|||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
int peers = numBroadcastPeers();
|
int peers = numBroadcastPeers();
|
||||||
if (peers > 0) {
|
if (peers > 0) {
|
||||||
builder.append("Seen by ");
|
builder.append("Seen by ").append(peers).append(peers > 1 ? " peers. " : " peer. ");
|
||||||
builder.append(peers);
|
|
||||||
if (peers > 1)
|
|
||||||
builder.append(" peers. ");
|
|
||||||
else
|
|
||||||
builder.append(" peer. ");
|
|
||||||
}
|
}
|
||||||
switch (getConfidenceType()) {
|
switch (getConfidenceType()) {
|
||||||
case UNKNOWN:
|
case UNKNOWN:
|
||||||
|
@ -279,10 +279,8 @@ public class TransactionInput extends ChildMessage implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (isCoinBase())
|
|
||||||
return "TxIn: COINBASE";
|
|
||||||
try {
|
try {
|
||||||
return "TxIn for [" + outpoint + "]: " + getScriptSig();
|
return isCoinBase() ? "TxIn: COINBASE" : "TxIn for [" + outpoint + "]: " + getScriptSig();
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -193,10 +193,9 @@ public class TransactionOutPoint extends ChildMessage implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return hash.toString() + ":" + index;
|
return hash + ":" + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the hash of the transaction this outpoint references/spends/is connected to.
|
* Returns the hash of the transaction this outpoint references/spends/is connected to.
|
||||||
*/
|
*/
|
||||||
|
@ -354,8 +354,7 @@ public class TransactionOutput extends ChildMessage implements Serializable {
|
|||||||
buf.append(" to multisig");
|
buf.append(" to multisig");
|
||||||
else
|
else
|
||||||
buf.append(" (unknown type)");
|
buf.append(" (unknown type)");
|
||||||
buf.append(" script:");
|
buf.append(" script:").append(script);
|
||||||
buf.append(script);
|
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -156,7 +156,7 @@ public class UTXO implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("Stored TxOut of %s (%s:%d)", value.toFriendlyString(), hash.toString(), index);
|
return String.format("Stored TxOut of %s (%s:%d)", value.toFriendlyString(), hash, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,6 +54,8 @@ public class Utils {
|
|||||||
public static final String BITCOIN_SIGNED_MESSAGE_HEADER = "Bitcoin Signed Message:\n";
|
public static final String BITCOIN_SIGNED_MESSAGE_HEADER = "Bitcoin Signed Message:\n";
|
||||||
public static final byte[] BITCOIN_SIGNED_MESSAGE_HEADER_BYTES = BITCOIN_SIGNED_MESSAGE_HEADER.getBytes(Charsets.UTF_8);
|
public static final byte[] BITCOIN_SIGNED_MESSAGE_HEADER_BYTES = BITCOIN_SIGNED_MESSAGE_HEADER.getBytes(Charsets.UTF_8);
|
||||||
|
|
||||||
|
private static final Joiner SPACE_JOINER = Joiner.on(" ");
|
||||||
|
|
||||||
private static BlockingQueue<Boolean> mockSleepQueue;
|
private static BlockingQueue<Boolean> mockSleepQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -407,6 +409,18 @@ public class Utils {
|
|||||||
return iso8601.format(dateTime);
|
return iso8601.format(dateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string containing the string representation of the given items,
|
||||||
|
* delimited by a single space character.
|
||||||
|
*
|
||||||
|
* @param items the items to join
|
||||||
|
* @param <T> the item type
|
||||||
|
* @return the joined space-delimited string
|
||||||
|
*/
|
||||||
|
public static <T> String join(Iterable<T> items) {
|
||||||
|
return SPACE_JOINER.join(items);
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] copyOf(byte[] in, int length) {
|
public static byte[] copyOf(byte[] in, int length) {
|
||||||
byte[] out = new byte[length];
|
byte[] out = new byte[length];
|
||||||
System.arraycopy(in, 0, out, 0, Math.min(length, in.length));
|
System.arraycopy(in, 0, out, 0, Math.min(length, in.length));
|
||||||
|
@ -2768,9 +2768,7 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
|||||||
if (!watchedScripts.isEmpty()) {
|
if (!watchedScripts.isEmpty()) {
|
||||||
builder.append("\nWatched scripts:\n");
|
builder.append("\nWatched scripts:\n");
|
||||||
for (Script script : watchedScripts) {
|
for (Script script : watchedScripts) {
|
||||||
builder.append(" ");
|
builder.append(" ").append(script).append("\n");
|
||||||
builder.append(script.toString());
|
|
||||||
builder.append("\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,18 +617,11 @@ public class DeterministicKey extends ECKey {
|
|||||||
@Override
|
@Override
|
||||||
public void formatKeyWithAddress(boolean includePrivateKeys, StringBuilder builder, NetworkParameters params) {
|
public void formatKeyWithAddress(boolean includePrivateKeys, StringBuilder builder, NetworkParameters params) {
|
||||||
final Address address = toAddress(params);
|
final Address address = toAddress(params);
|
||||||
builder.append(" addr:");
|
builder.append(" addr:").append(address);
|
||||||
builder.append(address.toString());
|
builder.append(" hash160:").append(Utils.HEX.encode(getPubKeyHash()));
|
||||||
builder.append(" hash160:");
|
builder.append(" (").append(getPathAsString()).append(")\n");
|
||||||
builder.append(Utils.HEX.encode(getPubKeyHash()));
|
|
||||||
builder.append(" (");
|
|
||||||
builder.append(getPathAsString());
|
|
||||||
builder.append(")");
|
|
||||||
builder.append("\n");
|
|
||||||
if (includePrivateKeys) {
|
if (includePrivateKeys) {
|
||||||
builder.append(" ");
|
builder.append(" ").append(toStringWithPrivate(params)).append("\n");
|
||||||
builder.append(toStringWithPrivate(params));
|
|
||||||
builder.append("\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ public final class EncryptedData {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "EncryptedData [initialisationVector=" + Arrays.toString(initialisationVector) + ", encryptedPrivateKey=" + Arrays.toString(encryptedBytes) + "]";
|
return "EncryptedData [initialisationVector=" + Arrays.toString(initialisationVector)
|
||||||
|
+ ", encryptedPrivateKey=" + Arrays.toString(encryptedBytes) + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package org.bitcoinj.crypto;
|
|||||||
|
|
||||||
import org.bitcoinj.core.Sha256Hash;
|
import org.bitcoinj.core.Sha256Hash;
|
||||||
import org.bitcoinj.core.Utils;
|
import org.bitcoinj.core.Utils;
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -126,7 +125,7 @@ public class MnemonicCode {
|
|||||||
// used as a pseudo-random function. Desired length of the
|
// used as a pseudo-random function. Desired length of the
|
||||||
// derived key is 512 bits (= 64 bytes).
|
// derived key is 512 bits (= 64 bytes).
|
||||||
//
|
//
|
||||||
String pass = Joiner.on(' ').join(words);
|
String pass = Utils.join(words);
|
||||||
String salt = "mnemonic" + passphrase;
|
String salt = "mnemonic" + passphrase;
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
@ -79,6 +79,6 @@ public class PaymentChannelCloseException extends Exception {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "PaymentChannelCloseException for reason " + getCloseReason().toString();
|
return "PaymentChannelCloseException for reason " + getCloseReason();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ public class StoredServerChannel {
|
|||||||
" Client output: %s%n" +
|
" Client output: %s%n" +
|
||||||
" Refund unlock: %s (%d unix time)%n" +
|
" Refund unlock: %s (%d unix time)%n" +
|
||||||
" Contract: %s%n",
|
" Contract: %s%n",
|
||||||
connectedHandler != null ? "connected" : "disconnected", myKey, bestValueToMe.toString(),
|
connectedHandler != null ? "connected" : "disconnected", myKey, bestValueToMe,
|
||||||
clientOutput, new Date(refundTransactionUnlockTimeSecs * 1000), refundTransactionUnlockTimeSecs,
|
clientOutput, new Date(refundTransactionUnlockTimeSecs * 1000), refundTransactionUnlockTimeSecs,
|
||||||
contract.toString().replaceAll(newline, newline + " "));
|
contract.toString().replaceAll(newline, newline + " "));
|
||||||
}
|
}
|
||||||
|
@ -125,12 +125,7 @@ public class Script {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder buf = new StringBuilder();
|
return Utils.join(chunks);
|
||||||
for (ScriptChunk chunk : chunks)
|
|
||||||
buf.append(chunk).append(' ');
|
|
||||||
if (buf.length() > 0)
|
|
||||||
buf.setLength(buf.length() - 1);
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the serialized program as a newly created byte array. */
|
/** Returns the serialized program as a newly created byte array. */
|
||||||
@ -297,7 +292,7 @@ public class Script {
|
|||||||
// A large constant followed by an OP_CHECKSIG is the key.
|
// A large constant followed by an OP_CHECKSIG is the key.
|
||||||
return chunk0data;
|
return chunk0data;
|
||||||
} else {
|
} else {
|
||||||
throw new ScriptException("Script did not match expected form: " + toString());
|
throw new ScriptException("Script did not match expected form: " + this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,10 +139,7 @@ public class ScriptChunk {
|
|||||||
buf.append(getOpCodeName(opcode));
|
buf.append(getOpCodeName(opcode));
|
||||||
} else if (data != null) {
|
} else if (data != null) {
|
||||||
// Data chunk
|
// Data chunk
|
||||||
buf.append(getPushDataName(opcode));
|
buf.append(getPushDataName(opcode)).append("[").append(Utils.HEX.encode(data)).append("]");
|
||||||
buf.append("[");
|
|
||||||
buf.append(Utils.HEX.encode(data));
|
|
||||||
buf.append("]");
|
|
||||||
} else {
|
} else {
|
||||||
// Small num
|
// Small num
|
||||||
buf.append(Script.decodeFromOpN(opcode));
|
buf.append(Script.decodeFromOpN(opcode));
|
||||||
|
@ -68,7 +68,7 @@ class StoredTransactionOutPoint implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Stored transaction out point: " + hash.toString() + ":" + index;
|
return "Stored transaction out point: " + hash + ":" + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -337,7 +337,7 @@ public class BitcoinURI {
|
|||||||
} else {
|
} else {
|
||||||
builder.append(",");
|
builder.append(",");
|
||||||
}
|
}
|
||||||
builder.append("'").append(entry.getKey()).append("'=").append("'").append(entry.getValue().toString()).append("'");
|
builder.append("'").append(entry.getKey()).append("'=").append("'").append(entry.getValue()).append("'");
|
||||||
}
|
}
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
|
@ -1157,8 +1157,7 @@ public abstract class BtcFormat extends Format {
|
|||||||
* @throws IllegalArgumentException if the number of fraction places is negative.
|
* @throws IllegalArgumentException if the number of fraction places is negative.
|
||||||
*/
|
*/
|
||||||
public String format(Object qty, int minDecimals, int... fractionGroups) {
|
public String format(Object qty, int minDecimals, int... fractionGroups) {
|
||||||
return format(qty, new StringBuffer(), new FieldPosition(0), minDecimals, boxAsList(fractionGroups)).
|
return format(qty, new StringBuffer(), new FieldPosition(0), minDecimals, boxAsList(fractionGroups)).toString();
|
||||||
toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1542,9 +1541,9 @@ public abstract class BtcFormat extends Format {
|
|||||||
* returned by this method is localized, any currency signs expressed are literally, and
|
* returned by this method is localized, any currency signs expressed are literally, and
|
||||||
* optional fractional decimal places are shown grouped in parentheses. */
|
* optional fractional decimal places are shown grouped in parentheses. */
|
||||||
public String pattern() { synchronized(numberFormat) {
|
public String pattern() { synchronized(numberFormat) {
|
||||||
StringBuffer groups = new StringBuffer();
|
StringBuilder groups = new StringBuilder();
|
||||||
for (int group : decimalGroups) {
|
for (int group : decimalGroups) {
|
||||||
groups.append("(" + Strings.repeat("#",group) + ")");
|
groups.append("(").append(Strings.repeat("#", group)).append(")");
|
||||||
}
|
}
|
||||||
DecimalFormatSymbols s = numberFormat.getDecimalFormatSymbols();
|
DecimalFormatSymbols s = numberFormat.getDecimalFormatSymbols();
|
||||||
String digit = String.valueOf(s.getDigit());
|
String digit = String.valueOf(s.getDigit());
|
||||||
|
@ -25,7 +25,6 @@ import org.bitcoinj.script.Script;
|
|||||||
import org.bitcoinj.store.UnreadableWalletException;
|
import org.bitcoinj.store.UnreadableWalletException;
|
||||||
import org.bitcoinj.utils.Threading;
|
import org.bitcoinj.utils.Threading;
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterators;
|
import com.google.common.collect.Iterators;
|
||||||
import com.google.common.collect.PeekingIterator;
|
import com.google.common.collect.PeekingIterator;
|
||||||
@ -1333,7 +1332,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||||||
} else if (includePrivateKeys) {
|
} else if (includePrivateKeys) {
|
||||||
final List<String> words = seed.getMnemonicCode();
|
final List<String> words = seed.getMnemonicCode();
|
||||||
builder2.append(
|
builder2.append(
|
||||||
String.format("Seed as words: %s%nSeed as hex: %s%n", Joiner.on(' ').join(words),
|
String.format("Seed as words: %s%nSeed as hex: %s%n", Utils.join(words),
|
||||||
seed.toHexString())
|
seed.toHexString())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import org.bitcoinj.core.Utils;
|
|||||||
import org.bitcoinj.crypto.*;
|
import org.bitcoinj.crypto.*;
|
||||||
import org.bitcoinj.store.UnreadableWalletException;
|
import org.bitcoinj.store.UnreadableWalletException;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import org.spongycastle.crypto.params.KeyParameter;
|
import org.spongycastle.crypto.params.KeyParameter;
|
||||||
|
|
||||||
@ -132,10 +131,9 @@ public class DeterministicSeed implements EncryptableItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (isEncrypted())
|
return isEncrypted()
|
||||||
return "DeterministicSeed [encrypted]";
|
? "DeterministicSeed [encrypted]"
|
||||||
else
|
: "DeterministicSeed " + toHexString() + " " + Utils.join(mnemonicCode);
|
||||||
return "DeterministicSeed " + toHexString() + " " + Joiner.on(" ").join(mnemonicCode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the seed as hex or null if encrypted. */
|
/** Returns the seed as hex or null if encrypted. */
|
||||||
@ -185,7 +183,7 @@ public class DeterministicSeed implements EncryptableItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private byte[] getMnemonicAsBytes() {
|
private byte[] getMnemonicAsBytes() {
|
||||||
return Joiner.on(" ").join(mnemonicCode).getBytes(Charsets.UTF_8);
|
return Utils.join(mnemonicCode).getBytes(Charsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeterministicSeed decrypt(KeyCrypter crypter, String passphrase, KeyParameter aesKey) {
|
public DeterministicSeed decrypt(KeyCrypter crypter, String passphrase, KeyParameter aesKey) {
|
||||||
|
@ -104,12 +104,12 @@ public class KeyCrypterScryptTest {
|
|||||||
KeyCrypterScrypt keyCrypter = new KeyCrypterScrypt(scryptParameters);
|
KeyCrypterScrypt keyCrypter = new KeyCrypterScrypt(scryptParameters);
|
||||||
|
|
||||||
// create a longer encryption string
|
// create a longer encryption string
|
||||||
StringBuilder stringBuffer = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
stringBuffer.append(i).append(" ").append("The quick brown fox");
|
builder.append(i).append(" The quick brown fox");
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptedData data = keyCrypter.encrypt(stringBuffer.toString().getBytes(), keyCrypter.deriveKey(PASSWORD2));
|
EncryptedData data = keyCrypter.encrypt(builder.toString().getBytes(), keyCrypter.deriveKey(PASSWORD2));
|
||||||
assertNotNull(data);
|
assertNotNull(data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package org.bitcoinj.crypto;
|
package org.bitcoinj.crypto;
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
import org.bitcoinj.core.Utils;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -171,7 +171,7 @@ public class MnemonicCodeTest {
|
|||||||
byte[] entropy = mc.toEntropy(split(vecCode));
|
byte[] entropy = mc.toEntropy(split(vecCode));
|
||||||
|
|
||||||
assertEquals(vecData, HEX.encode(entropy));
|
assertEquals(vecData, HEX.encode(entropy));
|
||||||
assertEquals(vecCode, Joiner.on(' ').join(code));
|
assertEquals(vecCode, Utils.join(code));
|
||||||
assertEquals(vecSeed, HEX.encode(seed));
|
assertEquals(vecSeed, HEX.encode(seed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package org.bitcoinj.examples;
|
package org.bitcoinj.examples;
|
||||||
|
|
||||||
import org.bitcoinj.core.NetworkParameters;
|
import org.bitcoinj.core.NetworkParameters;
|
||||||
|
import org.bitcoinj.core.Utils;
|
||||||
import org.bitcoinj.core.Wallet;
|
import org.bitcoinj.core.Wallet;
|
||||||
import org.bitcoinj.params.TestNet3Params;
|
import org.bitcoinj.params.TestNet3Params;
|
||||||
import org.bitcoinj.wallet.DeterministicSeed;
|
import org.bitcoinj.wallet.DeterministicSeed;
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The following example shows you how to create a deterministic seed from a hierarchical deterministic wallet represented as a mnemonic code.
|
* The following example shows you how to create a deterministic seed from a hierarchical deterministic wallet represented as a mnemonic code.
|
||||||
@ -25,6 +25,6 @@ public class BackupToMnemonicSeed {
|
|||||||
System.out.println("seed: " + seed.toString());
|
System.out.println("seed: " + seed.toString());
|
||||||
|
|
||||||
System.out.println("creation time: " + seed.getCreationTimeSeconds());
|
System.out.println("creation time: " + seed.getCreationTimeSeconds());
|
||||||
System.out.println("mnemonicCode: " + Joiner.on(" ").join(seed.getMnemonicCode()));
|
System.out.println("mnemonicCode: " + Utils.join(seed.getMnemonicCode()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package wallettemplate;
|
package wallettemplate;
|
||||||
|
|
||||||
|
import org.bitcoinj.core.Utils;
|
||||||
import org.bitcoinj.crypto.MnemonicCode;
|
import org.bitcoinj.crypto.MnemonicCode;
|
||||||
import org.bitcoinj.wallet.DeterministicSeed;
|
import org.bitcoinj.wallet.DeterministicSeed;
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.util.concurrent.Service;
|
import com.google.common.util.concurrent.Service;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
@ -68,7 +68,7 @@ public class WalletSettingsController {
|
|||||||
// Set the mnemonic seed words.
|
// Set the mnemonic seed words.
|
||||||
final List<String> mnemonicCode = seed.getMnemonicCode();
|
final List<String> mnemonicCode = seed.getMnemonicCode();
|
||||||
checkNotNull(mnemonicCode); // Already checked for encryption.
|
checkNotNull(mnemonicCode); // Already checked for encryption.
|
||||||
String origWords = Joiner.on(" ").join(mnemonicCode);
|
String origWords = Utils.join(mnemonicCode);
|
||||||
wordsArea.setText(origWords);
|
wordsArea.setText(origWords);
|
||||||
|
|
||||||
// Validate words as they are being typed.
|
// Validate words as they are being typed.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user