本文整理了Java中org.bitcoinj.core.Address.getParametersFromAddress()
方法的一些代码示例,展示了Address.getParametersFromAddress()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.getParametersFromAddress()
方法的具体详情如下:
包路径:org.bitcoinj.core.Address
类名称:Address
方法名:getParametersFromAddress
[英]Given an address, examines the version byte and attempts to find a matching NetworkParameters. If you aren't sure which network the address is intended for (eg, it was provided by a user), you can use this to decide if it is compatible with the current wallet.
[中]给定地址,检查版本字节并尝试查找匹配的NetworkParameters。如果您不确定该地址用于哪个网络(例如,它是由用户提供的),您可以使用该地址来确定它是否与当前钱包兼容。
代码示例来源:origin: DanielKrawisz/Shufflepuff
public AddressImpl(String address) throws FormatException {
try {
this.address = new org.bitcoinj.core.Address(
org.bitcoinj.core.Address.getParametersFromAddress(address), address);
} catch (AddressFormatException e) {
throw new FormatException("Could not parse address " + address);
}
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void getNetwork() throws Exception {
NetworkParameters params = Address.getParametersFromAddress("17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL");
assertEquals(MainNetParams.get().getId(), params.getId());
params = Address.getParametersFromAddress("n4eA2nbYqErp7H6jebchxAN59DmNpksexv");
assertEquals(TestNet3Params.get().getId(), params.getId());
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void getAltNetwork() throws Exception {
// An alternative network
class AltNetwork extends MainNetParams {
AltNetwork() {
super();
id = "alt.network";
addressHeader = 48;
p2shHeader = 5;
acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
}
}
AltNetwork altNetwork = new AltNetwork();
// Add new network params
Networks.register(altNetwork);
// Check if can parse address
NetworkParameters params = Address.getParametersFromAddress("LLxSnHLN2CYyzB5eWTR9K9rS9uWtbTQFb6");
assertEquals(altNetwork.getId(), params.getId());
// Check if main network works as before
params = Address.getParametersFromAddress("17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL");
assertEquals(MainNetParams.get().getId(), params.getId());
// Unregister network
Networks.unregister(altNetwork);
try {
Address.getParametersFromAddress("LLxSnHLN2CYyzB5eWTR9K9rS9uWtbTQFb6");
fail();
} catch (AddressFormatException e) { }
}
代码示例来源: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());
}
内容来源于网络,如有侵权,请联系作者删除!