3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 10:15:52 +00:00

LegacyAddress: Deprecate getHash160().

This commit is contained in:
Andreas Schildbach 2018-02-28 17:01:56 +01:00
parent e11119b64f
commit c0d8039c82
10 changed files with 30 additions and 29 deletions

View File

@ -186,7 +186,8 @@ public class LegacyAddress extends Address {
return Base58.encodeChecked(getVersion(), bytes);
}
/** The (big endian) 20 byte hash that is the core of a Bitcoin address. */
/** @deprecated use {@link #getHash()} */
@Deprecated
public byte[] getHash160() {
return getHash();
}

View File

@ -261,13 +261,13 @@ public class ScriptBuilder {
// OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
builder.op(OP_DUP);
builder.op(OP_HASH160);
builder.data(toLegacy.getHash160());
builder.data(toLegacy.getHash());
builder.op(OP_EQUALVERIFY);
builder.op(OP_CHECKSIG);
} else if (scriptType == ScriptType.P2SH) {
// OP_HASH160 <scriptHash> OP_EQUAL
builder.op(OP_HASH160);
builder.data(toLegacy.getHash160());
builder.data(toLegacy.getHash());
builder.op(OP_EQUAL);
} else {
throw new IllegalStateException("Cannot handle " + scriptType);

View File

@ -429,7 +429,7 @@ public class LevelDBFullPrunedBlockStore implements FullPrunedBlockStore {
for (LegacyAddress a : addresses) {
ByteBuffer bb = ByteBuffer.allocate(21);
bb.put((byte) KeyType.ADDRESS_HASHINDEX.ordinal());
bb.put(a.getHash160());
bb.put(a.getHash());
ReadOptions ro = new ReadOptions();
Snapshot sn = db.getSnapshot();
@ -443,7 +443,7 @@ public class LevelDBFullPrunedBlockStore implements FullPrunedBlockStore {
bbKey.get(); // remove the address_hashindex byte.
byte[] addressKey = new byte[20];
bbKey.get(addressKey);
if (!Arrays.equals(addressKey, a.getHash160())) {
if (!Arrays.equals(addressKey, a.getHash())) {
break;
}
byte[] hashBytes = new byte[32];
@ -802,7 +802,7 @@ public class LevelDBFullPrunedBlockStore implements FullPrunedBlockStore {
}
ByteBuffer bb = ByteBuffer.allocate(57);
bb.put((byte) KeyType.ADDRESS_HASHINDEX.ordinal());
bb.put(a.getHash160());
bb.put(a.getHash());
bb.put(out.getHash().getBytes());
bb.putInt((int) out.getIndex());
byte[] value = new byte[0];
@ -887,10 +887,10 @@ public class LevelDBFullPrunedBlockStore implements FullPrunedBlockStore {
if (address == null || address.equals("")) {
Script sc = out.getScript();
a = sc.getToAddress(params);
hashBytes = a.getHash160();
hashBytes = a.getHash();
} else {
a = LegacyAddress.fromBase58(params, out.getAddress());
hashBytes = a.getHash160();
hashBytes = a.getHash();
}
} catch (AddressFormatException e) {
if (instrument)

View File

@ -358,7 +358,7 @@ public class KeyChainGroup implements KeyBag {
public void markP2SHAddressAsUsed(LegacyAddress address) {
checkArgument(address.isP2SHAddress());
RedeemData data = findRedeemDataFromScriptHash(address.getHash160());
RedeemData data = findRedeemDataFromScriptHash(address.getHash());
if (data == null)
return; // Not our P2SH address.
for (ECKey key : data.keys) {

View File

@ -70,10 +70,10 @@ public class LegacyAddressTest {
@Test
public void decoding() throws Exception {
LegacyAddress a = LegacyAddress.fromBase58(TESTNET, "n4eA2nbYqErp7H6jebchxAN59DmNpksexv");
assertEquals("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc", Utils.HEX.encode(a.getHash160()));
assertEquals("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc", Utils.HEX.encode(a.getHash()));
LegacyAddress b = LegacyAddress.fromBase58(MAINNET, "17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL");
assertEquals("4a22c3c4cbb31e4d03b15550636762bda0baf85a", Utils.HEX.encode(b.getHash160()));
assertEquals("4a22c3c4cbb31e4d03b15550636762bda0baf85a", Utils.HEX.encode(b.getHash()));
}
@Test

View File

@ -88,7 +88,7 @@ public class BitcoinURITest {
assertNotNull(testObject);
assertNull("Unexpected amount", testObject.getAmount());
assertNull("Unexpected label", testObject.getLabel());
assertEquals("Unexpected label", 20, testObject.getAddress().getHash160().length);
assertEquals("Unexpected label", 20, testObject.getAddress().getHash().length);
}
/**

View File

@ -75,7 +75,7 @@ public class DeterministicKeyChainTest {
final LegacyAddress address = LegacyAddress.fromBase58(UNITTEST, "n1bQNoEx8uhmCzzA5JPG6sFdtsUQhwiQJV");
assertEquals(address, LegacyAddress.fromKey(UNITTEST, key1));
assertEquals("mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R", LegacyAddress.fromKey(UNITTEST, key2).toString());
assertEquals(key1, chain.findKeyFromPubHash(address.getHash160()));
assertEquals(key1, chain.findKeyFromPubHash(address.getHash()));
assertEquals(key2, chain.findKeyFromPubKey(key2.getPubKey()));
key1.sign(Sha256Hash.ZERO_HASH);
@ -106,7 +106,7 @@ public class DeterministicKeyChainTest {
final LegacyAddress address = LegacyAddress.fromBase58(UNITTEST, "n2nHHRHs7TiZScTuVhZUkzZfTfVgGYwy6X");
assertEquals(address, LegacyAddress.fromKey(UNITTEST, key1));
assertEquals("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", LegacyAddress.fromKey(UNITTEST, key2).toString());
assertEquals(key1, chain1.findKeyFromPubHash(address.getHash160()));
assertEquals(key1, chain1.findKeyFromPubHash(address.getHash()));
assertEquals(key2, chain1.findKeyFromPubKey(key2.getPubKey()));
key1.sign(Sha256Hash.ZERO_HASH);
@ -165,7 +165,7 @@ public class DeterministicKeyChainTest {
ECKey key2 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertEquals("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", LegacyAddress.fromKey(UNITTEST, key2).toString());
assertEquals(key1, chain1.findKeyFromPubHash(address.getHash160()));
assertEquals(key1, chain1.findKeyFromPubHash(address.getHash()));
assertEquals(key2, chain1.findKeyFromPubKey(key2.getPubKey()));
key1.sign(Sha256Hash.ZERO_HASH);

View File

@ -202,7 +202,7 @@ public class KeyChainGroupTest {
// test our script hash
LegacyAddress address = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
RedeemData redeemData = group.findRedeemDataFromScriptHash(address.getHash160());
RedeemData redeemData = group.findRedeemDataFromScriptHash(address.getHash());
assertNotNull(redeemData);
assertNotNull(redeemData.redeemScript);
assertEquals(2, redeemData.keys.size());
@ -332,7 +332,7 @@ public class KeyChainGroupTest {
public void findRedeemScriptFromPubHash() throws Exception {
group = createMarriedKeyChainGroup();
LegacyAddress address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertTrue(group.findRedeemDataFromScriptHash(address.getHash160()) != null);
assertTrue(group.findRedeemDataFromScriptHash(address.getHash()) != null);
group.getBloomFilterElementCount();
KeyChainGroup group2 = createMarriedKeyChainGroup();
group2.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
@ -340,9 +340,9 @@ public class KeyChainGroupTest {
// test address from lookahead zone and lookahead threshold zone
for (int i = 0; i < group.getLookaheadSize() + group.getLookaheadThreshold(); i++) {
address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertTrue(group2.findRedeemDataFromScriptHash(address.getHash160()) != null);
assertTrue(group2.findRedeemDataFromScriptHash(address.getHash()) != null);
}
assertFalse(group2.findRedeemDataFromScriptHash(group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash160()) != null);
assertFalse(group2.findRedeemDataFromScriptHash(group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash()) != null);
}
@Test
@ -354,18 +354,18 @@ public class KeyChainGroupTest {
LegacyAddress address1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertEquals(expected, group.getBloomFilterElementCount());
BloomFilter filter = group.getBloomFilter(expected + 2, 0.001, (long)(Math.random() * Long.MAX_VALUE));
assertTrue(filter.contains(address1.getHash160()));
assertTrue(filter.contains(address1.getHash()));
LegacyAddress address2 = group.freshAddress(KeyChain.KeyPurpose.CHANGE);
assertTrue(filter.contains(address2.getHash160()));
assertTrue(filter.contains(address2.getHash()));
// Check that the filter contains the lookahead buffer.
for (int i = 0; i < bufferSize - 1 /* issued address */; i++) {
LegacyAddress address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertTrue("key " + i, filter.contains(address.getHash160()));
assertTrue("key " + i, filter.contains(address.getHash()));
}
// We ran ahead of the lookahead buffer.
assertFalse(filter.contains(group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash160()));
assertFalse(filter.contains(group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash()));
}
@Test
@ -581,7 +581,7 @@ public class KeyChainGroupTest {
LegacyAddress addr1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
LegacyAddress addr2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertEquals(addr1, addr2);
group.markPubKeyHashAsUsed(addr1.getHash160());
group.markPubKeyHashAsUsed(addr1.getHash());
LegacyAddress addr3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertNotEquals(addr2, addr3);
}

View File

@ -1764,7 +1764,7 @@ public class WalletTest extends TestWithWallet {
createMarriedWallet(2, 2);
LegacyAddress address = wallet.currentReceiveAddress();
assertTrue(wallet.getBloomFilter(0.001).contains(address.getHash160()));
assertTrue(wallet.getBloomFilter(0.001).contains(address.getHash()));
Transaction t1 = createFakeTx(UNITTEST, CENT, address);
TransactionOutPoint outPoint = new TransactionOutPoint(UNITTEST, 0, t1);
@ -2929,7 +2929,7 @@ public class WalletTest extends TestWithWallet {
assertEquals(THREE_CENTS.subtract(tx.getFee()), tx.getValueSentToMe(wallet));
// TX sends to one of our addresses (for now we ignore married wallets).
final LegacyAddress toAddress = tx.getOutput(0).getScriptPubKey().getToAddress(UNITTEST);
final ECKey rotatingToKey = wallet.findKeyFromPubHash(toAddress.getHash160());
final ECKey rotatingToKey = wallet.findKeyFromPubHash(toAddress.getHash());
assertNotNull(rotatingToKey);
assertFalse(wallet.isKeyRotating(rotatingToKey));
assertEquals(3, tx.getInputs().size());
@ -2969,7 +2969,7 @@ public class WalletTest extends TestWithWallet {
// Make a normal spend and check it's all ok.
wallet.sendCoins(broadcaster, OTHER_ADDRESS, wallet.getBalance());
tx = broadcaster.waitForTransaction();
assertArrayEquals(OTHER_ADDRESS.getHash160(), tx.getOutput(0).getScriptPubKey().getPubKeyHash());
assertArrayEquals(OTHER_ADDRESS.getHash(), tx.getOutput(0).getScriptPubKey().getPubKeyHash());
}
private Wallet roundTrip(Wallet wallet) throws UnreadableWalletException {
@ -3036,7 +3036,7 @@ public class WalletTest extends TestWithWallet {
List<Transaction> txns = wallet.doMaintenance(null, false).get();
assertEquals(1, txns.size());
LegacyAddress output = txns.get(0).getOutput(0).getAddressFromP2PKHScript(UNITTEST);
ECKey usedKey = wallet.findKeyFromPubHash(output.getHash160());
ECKey usedKey = wallet.findKeyFromPubHash(output.getHash());
assertEquals(goodKey.getCreationTimeSeconds(), usedKey.getCreationTimeSeconds());
assertEquals(goodKey.getCreationTimeSeconds(), wallet.freshReceiveKey().getCreationTimeSeconds());
assertEquals("mrM3TpCnav5YQuVA1xLercCGJH4DXujMtv", LegacyAddress.fromKey(UNITTEST, usedKey).toString());

View File

@ -1465,7 +1465,7 @@ public class WalletTool {
} else {
try {
LegacyAddress address = LegacyAddress.fromBase58(wallet.getParams(), addr);
key = wallet.findKeyFromPubHash(address.getHash160());
key = wallet.findKeyFromPubHash(address.getHash());
} catch (AddressFormatException e) {
System.err.println(addr + " does not parse as a Bitcoin address of the right network parameters.");
return;