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

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

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

Address.isP2SHAddress介绍

[英]Returns true if this address is a Pay-To-Script-Hash (P2SH) address. See also https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki: Address Format for pay-to-script-hash
[中]如果此地址是付费脚本哈希(P2SH)地址,则返回true。另见https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki:支付到脚本哈希的地址格式

代码示例

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

/** If the given P2SH address is "current", advance it to a new one. */
private void maybeMarkCurrentAddressAsUsed(Address address) {
  checkArgument(address.isP2SHAddress());
  for (Map.Entry<KeyChain.KeyPurpose, Address> entry : currentAddresses.entrySet()) {
    if (entry.getValue() != null && entry.getValue().equals(address)) {
      log.info("Marking P2SH address as used: {}", address);
      currentAddresses.put(entry.getKey(), freshAddress(entry.getKey()));
      return;
    }
  }
}

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

/** If the given P2SH address is "current", advance it to a new one. */
private void maybeMarkCurrentAddressAsUsed(Address address) {
  checkArgument(address.isP2SHAddress());
  for (Map.Entry<KeyChain.KeyPurpose, Address> entry : currentAddresses.entrySet()) {
    if (entry.getValue() != null && entry.getValue().equals(address)) {
      log.info("Marking P2SH address as used: {}", address);
      currentAddresses.put(entry.getKey(), freshAddress(entry.getKey()));
      return;
    }
  }
}

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

/** If the given P2SH address is "current", advance it to a new one. */
private void maybeMarkCurrentAddressAsUsed(Address address) {
  checkArgument(address.isP2SHAddress());
  for (Map.Entry<KeyChain.KeyPurpose, Address> entry : currentAddresses.entrySet()) {
    if (entry.getValue() != null && entry.getValue().equals(address)) {
      log.info("Marking P2SH address as used: {}", address);
      currentAddresses.put(entry.getKey(), freshAddress(entry.getKey()));
      return;
    }
  }
}

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

/** If the given P2SH address is "current", advance it to a new one. */
private void maybeMarkCurrentAddressAsUsed(Address address) {
  checkArgument(address.isP2SHAddress());
  for (Map.Entry<KeyChain.KeyPurpose, Address> entry : currentAddresses.entrySet()) {
    if (entry.getValue() != null && entry.getValue().equals(address)) {
      log.info("Marking P2SH address as used: {}", address);
      currentAddresses.put(entry.getKey(), freshAddress(entry.getKey()));
      return;
    }
  }
}

代码示例来源: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

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: 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: greenaddress/GreenBits

@Test
public void stringification() throws Exception {
  // Test a testnet address.
  Address a = new Address(testParams, HEX.decode("fda79a24e50ff70ff42f7d89585da5bd19d9e5cc"));
  assertEquals("n4eA2nbYqErp7H6jebchxAN59DmNpksexv", a.toString());
  assertFalse(a.isP2SHAddress());
  Address b = new Address(mainParams, HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
  assertEquals("17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL", b.toString());
  assertFalse(b.isP2SHAddress());
}

代码示例来源:origin: Multibit-Legacy/multibit-hardware

if (address.isP2SHAddress()) {
 outputScriptType = TrezorType.OutputScriptType.PAYTOSCRIPTHASH;
} else {

代码示例来源:origin: Multibit-Legacy/multibit-hardware

if (address.isP2SHAddress()) {
 outputScriptType = KeepKeyType.OutputScriptType.PAYTOSCRIPTHASH;
} else {

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

/** 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: fr.acinq/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 currentP2SHAddress() throws Exception {
  group = createMarriedKeyChainGroup();
  Address a1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  assertTrue(a1.isP2SHAddress());
  Address a2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  assertEquals(a1, a2);
  Address a3 = group.currentAddress(KeyChain.KeyPurpose.CHANGE);
  assertNotEquals(a2, a3);
}

代码示例来源: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 freshAddress() throws Exception {
  group = createMarriedKeyChainGroup();
  Address a1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  Address a2 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  assertTrue(a1.isP2SHAddress());
  assertNotEquals(a1, a2);
  group.getBloomFilterElementCount();
  assertEquals(((group.getLookaheadSize() + group.getLookaheadThreshold()) * 2)   // * 2 because of internal/external
      + (2 - group.getLookaheadThreshold())  // keys issued
      + group.getActiveKeyChain().getAccountPath().size() + 3  /* master, account, int, ext */, group.numKeys());
  Address a3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
  assertEquals(a2, a3);
}

代码示例来源:origin: Multibit-Legacy/multibit-hardware

if (address.isP2SHAddress()) {

代码示例来源:origin: Multibit-Legacy/multibit-hardware

if (address.isP2SHAddress()) {

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

/** 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 if (to.isP2WPKHAddress() || to.isP2WSHAddress()) {
    return new ScriptBuilder()
      .smallNum(0)
      .data(to.getHash())
      .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 p2shAddress() throws Exception {
  // Test that we can construct P2SH addresses
  Address mainNetP2SHAddress = Address.fromBase58(MainNetParams.get(), "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
  assertEquals(mainNetP2SHAddress.version, MainNetParams.get().p2shHeader);
  assertTrue(mainNetP2SHAddress.isP2SHAddress());
  Address testNetP2SHAddress = Address.fromBase58(TestNet3Params.get(), "2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe");
  assertEquals(testNetP2SHAddress.version, TestNet3Params.get().p2shHeader);
  assertTrue(testNetP2SHAddress.isP2SHAddress());
  // Test that we can determine what network a P2SH address belongs to
  NetworkParameters mainNetParams = Address.getParametersFromAddress("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
  assertEquals(MainNetParams.get().getId(), mainNetParams.getId());
  NetworkParameters testNetParams = Address.getParametersFromAddress("2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe");
  assertEquals(TestNet3Params.get().getId(), testNetParams.getId());
  // Test that we can convert them from hashes
  byte[] hex = HEX.decode("2ac4b0b501117cc8119c5797b519538d4942e90e");
  Address a = Address.fromP2SHHash(mainParams, hex);
  assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", a.toString());
  Address b = Address.fromP2SHHash(testParams, HEX.decode("18a0e827269b5211eb51a4af1b2fa69333efa722"));
  assertEquals("2MuVSxtfivPKJe93EC1Tb9UhJtGhsoWEHCe", b.toString());
  Address c = Address.fromP2SHScript(mainParams, ScriptBuilder.createP2SHOutputScript(hex));
  assertEquals("35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU", c.toString());
}

相关文章