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

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

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

Address.fromP2SHHash介绍

[英]Returns an Address that represents the given P2SH script hash.
[中]返回表示给定P2SH脚本哈希的地址。

代码示例

代码示例来源:origin: ICOnator/ICOnator-backend

public boolean isValidAddress(byte[] address) {
  try {
    Address.fromP2SHHash(TestNet3Params.get(), address);
    return true;
  } catch (AddressFormatException e) {
    return false;
  }
}

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

/** Returns an Address that represents the script hash extracted from the given scriptPubKey */
public static Address fromP2SHScript(NetworkParameters params, Script scriptPubKey) {
  checkArgument(scriptPubKey.isPayToScriptHash(), "Not a P2SH script");
  return fromP2SHHash(params, scriptPubKey.getPubKeyHash());
}

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

/** Returns an Address that represents the script hash extracted from the given scriptPubKey */
public static Address fromP2SHScript(NetworkParameters params, Script scriptPubKey) {
  checkArgument(scriptPubKey.isPayToScriptHash(), "Not a P2SH script");
  return fromP2SHHash(params, scriptPubKey.getPubKeyHash());
}

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

/** Returns an Address that represents the script hash extracted from the given scriptPubKey. */
public static Address fromP2SHScript(NetworkParameters params, Script scriptPubKey) {
  checkArgument(scriptPubKey.isPayToScriptHash(), "Not a P2SH script");
  return fromP2SHHash(params, scriptPubKey.getPubKeyHash());
}

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

/** Returns an Address that represents the script hash extracted from the given scriptPubKey */
public static Address fromP2SHScript(NetworkParameters params, Script scriptPubKey) {
  checkArgument(scriptPubKey.isPayToScriptHash(), "Not a P2SH script");
  return fromP2SHHash(params, scriptPubKey.getPubKeyHash());
}

代码示例来源: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());
}

相关文章