org.bitcoinj.core.Address.getHash160()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中org.bitcoinj.core.Address.getHash160()方法的一些代码示例,展示了Address.getHash160()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.getHash160()方法的具体详情如下:
包路径:org.bitcoinj.core.Address
类名称:Address
方法名:getHash160

Address.getHash160介绍

[英]The (big endian) 20 byte hash that is the core of a Bitcoin address.
[中]作为比特币地址核心的(大端)20字节散列。

代码示例

代码示例来源:origin: blockchain/thunder

@Override
public ECKey findKeyFromPubHash (byte[] pubkeyHash) {
  for (ECKey k : keyList) {
    if (Arrays.equals(pubkeyHash, k.toAddress(Constants.getNetwork()).getHash160())) {
      return k;
    }
  }
  return null;
}

代码示例来源:origin: HashEngineering/dashj

boolean setSporkAddress(String strAddress) {
  try {
    Address address = Address.fromBase58(context.getParams(), strAddress);
    sporkPubKeyId = address.getHash160();
  } catch (AddressFormatException x) {
    log.error("CSporkManager::SetSporkAddress -- Failed to parse spork address");
    return false;
  }
  return true;
}

代码示例来源:origin: blockchain/thunder

public LNEstablishAMessage (ECKey channelKeyServer, Transaction anchor, RevocationHash revocationHash, long clientAmount, long
    serverAmount, int minConfirmationAnchor, Address address, int feePerByte, long csvDelay) {
  this.channelKeyServer = channelKeyServer.getPubKey();
  this.minConfirmationAnchor = minConfirmationAnchor;
  this.anchorTransaction = anchor.bitcoinSerialize();
  this.revocationHash = revocationHash;
  this.amountClient = clientAmount;
  this.amountServer = serverAmount;
  this.addressBytes = address.getHash160();
  this.feePerByte = feePerByte;
  this.csvDelay = csvDelay;
}

代码示例来源:origin: Coinomi/coinomi-android

BitAddress(Address address) throws WrongNetworkException {
  this((CoinType) address.getParameters(), address.getVersion(), address.getHash160());
}

代码示例来源:origin: openwalletGH/openwallet-android

BitAddress(Address address) throws WrongNetworkException {
  this((CoinType) address.getParameters(), address.getVersion(), address.getHash160());
}

代码示例来源:origin: greenaddress/GreenBits

public void markP2SHAddressAsUsed(Address address) {
  checkArgument(address.isP2SHAddress());
  RedeemData data = findRedeemDataFromScriptHash(address.getHash160());
  if (data == null)
    return;   // Not our P2SH address.
  for (ECKey key : data.keys) {
    for (DeterministicKeyChain chain : chains) {
      DeterministicKey k = chain.findKeyFromPubKey(key.getPubKey());
      if (k == null) continue;
      chain.markKeyAsUsed(k);
      maybeMarkCurrentAddressAsUsed(address);
    }
  }
}

代码示例来源:origin: HashEngineering/dashj

public void markP2SHAddressAsUsed(Address address) {
  checkArgument(address.isP2SHAddress());
  RedeemData data = findRedeemDataFromScriptHash(address.getHash160());
  if (data == null)
    return;   // Not our P2SH address.
  for (ECKey key : data.keys) {
    for (DeterministicKeyChain chain : chains) {
      DeterministicKey k = chain.findKeyFromPubKey(key.getPubKey());
      if (k == null) continue;
      chain.markKeyAsUsed(k);
      maybeMarkCurrentAddressAsUsed(address);
    }
  }
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

public void markP2SHAddressAsUsed(Address address) {
  checkArgument(address.isP2SHAddress());
  RedeemData data = findRedeemDataFromScriptHash(address.getHash160());
  if (data == null)
    return;   // Not our P2SH address.
  for (ECKey key : data.keys) {
    for (DeterministicKeyChain chain : chains) {
      DeterministicKey k = chain.findKeyFromPubKey(key.getPubKey());
      if (k == null) continue;
      chain.markKeyAsUsed(k);
      maybeMarkCurrentAddressAsUsed(address);
    }
  }
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void decoding() throws Exception {
  Address a = Address.fromBase58(testParams, "n4eA2nbYqErp7H6jebchxAN59DmNpksexv");
  assertEquals("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc", Utils.HEX.encode(a.getHash160()));
  Address b = Address.fromBase58(mainParams, "17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL");
  assertEquals("4a22c3c4cbb31e4d03b15550636762bda0baf85a", Utils.HEX.encode(b.getHash160()));
}

代码示例来源:origin: fr.acinq/bitcoinj-core

public void markP2SHAddressAsUsed(Address address) {
  checkArgument(address.isP2SHAddress());
  RedeemData data = findRedeemDataFromScriptHash(address.getHash160());
  if (data == null)
    return;   // Not our P2SH address.
  for (ECKey key : data.keys) {
    for (DeterministicKeyChain chain : chains) {
      DeterministicKey k = chain.findKeyFromPubKey(key.getPubKey());
      if (k == null) continue;
      chain.markKeyAsUsed(k);
      maybeMarkCurrentAddressAsUsed(address);
      if (data.isP2SHofP2WPKH) maybeMarkCurrentKeyAsUsed(k);
    }
  }
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

/** Creates a scriptPubKey that encodes payment to the given address. */
public static Script createOutputScript(Address to) {
  if (to.isP2SHAddress()) {
    // OP_HASH160 <scriptHash> OP_EQUAL
    return new ScriptBuilder()
      .op(OP_HASH160)
      .data(to.getHash160())
      .op(OP_EQUAL)
      .build();
  } else {
    // OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
    return new ScriptBuilder()
      .op(OP_DUP)
      .op(OP_HASH160)
      .data(to.getHash160())
      .op(OP_EQUALVERIFY)
      .op(OP_CHECKSIG)
      .build();
  }
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void findRedeemScriptFromPubHash() throws Exception {
  group = createMarriedKeyChainGroup();
  Address address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  assertTrue(group.findRedeemDataFromScriptHash(address.getHash160()) != null);
  group.getBloomFilterElementCount();
  KeyChainGroup group2 = createMarriedKeyChainGroup();
  group2.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  group2.getBloomFilterElementCount();  // Force lookahead.
  // 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);
  }
  assertFalse(group2.findRedeemDataFromScriptHash(group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash160()) != null);
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void markAsUsed() throws Exception {
  Address addr1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  Address addr2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  assertEquals(addr1, addr2);
  group.markPubKeyHashAsUsed(addr1.getHash160());
  Address addr3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  assertNotEquals(addr2, addr3);
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void findRedeemData() throws Exception {
  group = createMarriedKeyChainGroup();
  // test script hash that we don't have
  assertNull(group.findRedeemDataFromScriptHash(new ECKey().getPubKey()));
  // test our script hash
  Address address = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  RedeemData redeemData = group.findRedeemDataFromScriptHash(address.getHash160());
  assertNotNull(redeemData);
  assertNotNull(redeemData.redeemScript);
  assertEquals(2, redeemData.keys.size());
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void testGood_Simple() throws BitcoinURIParseException {
  testObject = new BitcoinURI(MAINNET, BITCOIN_SCHEME + ":" + MAINNET_GOOD_ADDRESS);
  assertNotNull(testObject);
  assertNull("Unexpected amount", testObject.getAmount());
  assertNull("Unexpected label", testObject.getLabel());
  assertEquals("Unexpected label", 20, testObject.getAddress().getHash160().length);
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void marriedKeychainBloomFilter() throws Exception {
  createMarriedWallet(2, 2);
  Address address = wallet.currentReceiveAddress();
  assertTrue(wallet.getBloomFilter(0.001).contains(address.getHash160()));
  Transaction t1 = createFakeTx(PARAMS, CENT, address);
  TransactionOutPoint outPoint = new TransactionOutPoint(PARAMS, 0, t1);
  assertFalse(wallet.getBloomFilter(0.001).contains(outPoint.unsafeBitcoinSerialize()));
  sendMoneyToWallet(BlockChain.NewBlockType.BEST_CHAIN, t1);
  assertTrue(wallet.getBloomFilter(0.001).contains(outPoint.unsafeBitcoinSerialize()));
}

代码示例来源:origin: Coinomi/coinomi-android

@Test
public void derive() throws Exception {
  ECKey key1 = chain.getKey(SimpleHDKeyChain.KeyPurpose.RECEIVE_FUNDS);
  ECKey key2 = chain.getKey(SimpleHDKeyChain.KeyPurpose.RECEIVE_FUNDS);
  final Address address = new Address(UnitTestParams.get(), "n1bQNoEx8uhmCzzA5JPG6sFdtsUQhwiQJV");
  assertEquals(address, key1.toAddress(UnitTestParams.get()));
  assertEquals("mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R", key2.toAddress(UnitTestParams.get()).toString());
  assertEquals(key1, chain.findKeyFromPubHash(address.getHash160()));
  assertEquals(key2, chain.findKeyFromPubKey(key2.getPubKey()));
  key1.sign(Sha256Hash.ZERO_HASH);
  ECKey key3 = chain.getKey(SimpleHDKeyChain.KeyPurpose.CHANGE);
  assertEquals("mqumHgVDqNzuXNrszBmi7A2UpmwaPMx4HQ", key3.toAddress(UnitTestParams.get()).toString());
  key3.sign(Sha256Hash.ZERO_HASH);
}

代码示例来源:origin: openwalletGH/openwallet-android

@Test
public void derive() throws Exception {
  ECKey key1 = chain.getKey(SimpleHDKeyChain.KeyPurpose.RECEIVE_FUNDS);
  ECKey key2 = chain.getKey(SimpleHDKeyChain.KeyPurpose.RECEIVE_FUNDS);
  final Address address = new Address(UnitTestParams.get(), "n1bQNoEx8uhmCzzA5JPG6sFdtsUQhwiQJV");
  assertEquals(address, key1.toAddress(UnitTestParams.get()));
  assertEquals("mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R", key2.toAddress(UnitTestParams.get()).toString());
  assertEquals(key1, chain.findKeyFromPubHash(address.getHash160()));
  assertEquals(key2, chain.findKeyFromPubKey(key2.getPubKey()));
  key1.sign(Sha256Hash.ZERO_HASH);
  ECKey key3 = chain.getKey(SimpleHDKeyChain.KeyPurpose.CHANGE);
  assertEquals("mqumHgVDqNzuXNrszBmi7A2UpmwaPMx4HQ", key3.toAddress(UnitTestParams.get()).toString());
  key3.sign(Sha256Hash.ZERO_HASH);
}

代码示例来源:origin: greenaddress/GreenBits

@Test
public void deriveAccountOne() throws Exception {
  long secs = 1389353062L;
  DeterministicKeyChain chain1 = new AccountOneChain(ENTROPY, "", secs);
  ECKey key1 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  ECKey key2 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  final Address address = Address.fromBase58(UnitTestParams.get(), "n2nHHRHs7TiZScTuVhZUkzZfTfVgGYwy6X");
  assertEquals(address, key1.toAddress(UnitTestParams.get()));
  assertEquals("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", key2.toAddress(UnitTestParams.get()).toString());
  assertEquals(key1, chain1.findKeyFromPubHash(address.getHash160()));
  assertEquals(key2, chain1.findKeyFromPubKey(key2.getPubKey()));
  key1.sign(Sha256Hash.ZERO_HASH);
  ECKey key3 = chain1.getKey(KeyChain.KeyPurpose.CHANGE);
  assertEquals("mpjRhk13rvV7vmnszcUQVYVQzy4HLTPTQU", key3.toAddress(UnitTestParams.get()).toString());
  key3.sign(Sha256Hash.ZERO_HASH);
}

代码示例来源:origin: Coinomi/coinomi-android

@Test
public void deriveCoin() throws Exception {
  DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey);
  DeterministicKey rootKey = hierarchy.get(BitcoinMain.get().getBip44Path(0), false, true);
  chain = new SimpleHDKeyChain(rootKey);
  ECKey key1 = chain.getKey(SimpleHDKeyChain.KeyPurpose.RECEIVE_FUNDS);
  ECKey key2 = chain.getKey(SimpleHDKeyChain.KeyPurpose.RECEIVE_FUNDS);
  final Address address = new Address(BitcoinMain.get(), "1Fp7CA7ZVqZNFVNQ9TpeqWUas7K28K9zig");
  assertEquals(address, key1.toAddress(BitcoinMain.get()));
  assertEquals("1AKqkQM4VqyVis6hscj8695WHPCCzgHNY3", key2.toAddress(BitcoinMain.get()).toString());
  assertEquals(key1, chain.findKeyFromPubHash(address.getHash160()));
  assertEquals(key2, chain.findKeyFromPubKey(key2.getPubKey()));
  key1.sign(Sha256Hash.ZERO_HASH);
  ECKey key3 = chain.getKey(SimpleHDKeyChain.KeyPurpose.CHANGE);
  assertEquals("18YvGiRqXKxrzB72ckfrRSizWeHgwRP94V", key3.toAddress(BitcoinMain.get()).toString());
  key3.sign(Sha256Hash.ZERO_HASH);
  ECKey key4 = chain.getKey(SimpleHDKeyChain.KeyPurpose.CHANGE);
  assertEquals("1861TX2MbyPEUrxDQVWgV4Tp9991bK1zpy", key4.toAddress(BitcoinMain.get()).toString());
  key4.sign(Sha256Hash.ZERO_HASH);
}

相关文章