mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 10:45:51 +00:00
DeterministicKey, ECKey: In toString(), add a comment so that the role of the key in a keychain becomes clear.
This commit is contained in:
parent
09d5d33313
commit
4baeeaf44a
@ -1290,7 +1290,7 @@ public class ECKey implements EncryptableItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void formatKeyWithAddress(boolean includePrivateKeys, @Nullable KeyParameter aesKey, StringBuilder builder,
|
public void formatKeyWithAddress(boolean includePrivateKeys, @Nullable KeyParameter aesKey, StringBuilder builder,
|
||||||
NetworkParameters params, Script.ScriptType outputScriptType) {
|
NetworkParameters params, Script.ScriptType outputScriptType, @Nullable String comment) {
|
||||||
builder.append(" addr:");
|
builder.append(" addr:");
|
||||||
if (outputScriptType != null) {
|
if (outputScriptType != null) {
|
||||||
builder.append(Address.fromKey(params, this, outputScriptType));
|
builder.append(Address.fromKey(params, this, outputScriptType));
|
||||||
@ -1306,6 +1306,8 @@ public class ECKey implements EncryptableItem {
|
|||||||
if (creationTimeSeconds > 0)
|
if (creationTimeSeconds > 0)
|
||||||
builder.append(" creationTimeSeconds:").append(creationTimeSeconds).append(" [")
|
builder.append(" creationTimeSeconds:").append(creationTimeSeconds).append(" [")
|
||||||
.append(Utils.dateTimeFormat(creationTimeSeconds * 1000)).append("]");
|
.append(Utils.dateTimeFormat(creationTimeSeconds * 1000)).append("]");
|
||||||
|
if (comment != null)
|
||||||
|
builder.append(" (").append(comment).append(")");
|
||||||
builder.append("\n");
|
builder.append("\n");
|
||||||
if (includePrivateKeys) {
|
if (includePrivateKeys) {
|
||||||
builder.append(" ");
|
builder.append(" ");
|
||||||
|
@ -632,10 +632,13 @@ public class DeterministicKey extends ECKey {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void formatKeyWithAddress(boolean includePrivateKeys, @Nullable KeyParameter aesKey, StringBuilder builder,
|
public void formatKeyWithAddress(boolean includePrivateKeys, @Nullable KeyParameter aesKey, StringBuilder builder,
|
||||||
NetworkParameters params, Script.ScriptType outputScriptType) {
|
NetworkParameters params, Script.ScriptType outputScriptType, @Nullable String comment) {
|
||||||
builder.append(" addr:").append(Address.fromKey(params, this, outputScriptType).toString());
|
builder.append(" addr:").append(Address.fromKey(params, this, outputScriptType).toString());
|
||||||
builder.append(" hash160:").append(Utils.HEX.encode(getPubKeyHash()));
|
builder.append(" hash160:").append(Utils.HEX.encode(getPubKeyHash()));
|
||||||
builder.append(" (").append(getPathAsString()).append(")\n");
|
builder.append(" (").append(getPathAsString());
|
||||||
|
if (comment != null)
|
||||||
|
builder.append(", ").append(comment);
|
||||||
|
builder.append(")\n");
|
||||||
if (includePrivateKeys) {
|
if (includePrivateKeys) {
|
||||||
builder.append(" ").append(toStringWithPrivate(aesKey, params)).append("\n");
|
builder.append(" ").append(toStringWithPrivate(aesKey, params)).append("\n");
|
||||||
}
|
}
|
||||||
|
@ -626,7 +626,7 @@ public class BasicKeyChain implements EncryptableKeyChain {
|
|||||||
List<ECKey> keys = getKeys();
|
List<ECKey> keys = getKeys();
|
||||||
Collections.sort(keys, ECKey.AGE_COMPARATOR);
|
Collections.sort(keys, ECKey.AGE_COMPARATOR);
|
||||||
for (ECKey key : keys)
|
for (ECKey key : keys)
|
||||||
key.formatKeyWithAddress(includePrivateKeys, aesKey, builder, params, null);
|
key.formatKeyWithAddress(includePrivateKeys, aesKey, builder, params, null, "imported");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1402,8 +1402,22 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
|||||||
|
|
||||||
protected void formatAddresses(boolean includePrivateKeys, @Nullable KeyParameter aesKey, NetworkParameters params,
|
protected void formatAddresses(boolean includePrivateKeys, @Nullable KeyParameter aesKey, NetworkParameters params,
|
||||||
StringBuilder builder) {
|
StringBuilder builder) {
|
||||||
for (ECKey key : getKeys(false, true))
|
for (DeterministicKey key : getKeys(false, true)) {
|
||||||
key.formatKeyWithAddress(includePrivateKeys, aesKey, builder, params, outputScriptType);
|
String comment = null;
|
||||||
|
if (key.equals(rootKey))
|
||||||
|
comment = "root";
|
||||||
|
else if (key.equals(getWatchingKey()))
|
||||||
|
comment = "account";
|
||||||
|
else if (key.equals(internalParentKey))
|
||||||
|
comment = "internal";
|
||||||
|
else if (key.equals(externalParentKey))
|
||||||
|
comment = "external";
|
||||||
|
else if (internalParentKey.equals(key.getParent()) && key.getChildNumber().i() >= issuedInternalKeys)
|
||||||
|
comment = "*";
|
||||||
|
else if (externalParentKey.equals(key.getParent()) && key.getChildNumber().i() >= issuedExternalKeys)
|
||||||
|
comment = "*";
|
||||||
|
key.formatKeyWithAddress(includePrivateKeys, aesKey, builder, params, outputScriptType, comment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The number of signatures required to spend coins received by this keychain. */
|
/** The number of signatures required to spend coins received by this keychain. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user