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

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

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

Address.getParameters介绍

[英]Examines the version byte of the address 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. You should be able to handle a null response from this method. Note that the parameters returned is not necessarily the same as the one the Address was created with.
[中]检查地址的版本字节并尝试查找匹配的NetworkParameters。如果您不确定该地址用于哪个网络(例如,它是由用户提供的),您可以使用该地址来确定它是否与当前钱包兼容。您应该能够处理来自此方法的空响应。请注意,返回的参数不一定与创建地址时使用的参数相同。

代码示例

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

  1. /**
  2. * Returns true if this address is a Pay-To-Script-Hash (P2SH) address.
  3. * See also https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki: Address Format for pay-to-script-hash
  4. */
  5. public boolean isP2SHAddress() {
  6. final NetworkParameters parameters = getParameters();
  7. return parameters != null && this.version == parameters.p2shHeader;
  8. }

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

  1. /**
  2. * Returns true if this address is a Pay-To-Witness-Script-Hash (P2WSH) address.
  3. * See also https://github.com/bitcoin/bips/blob/master/bip-0142.mediawiki: Address Format for Segregated Witness
  4. */
  5. public boolean isP2WSHAddress() {
  6. final NetworkParameters parameters = getParameters();
  7. return parameters != null && this.version == parameters.p2wshHeader;
  8. }

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

  1. /**
  2. * Returns true if this address is a Pay-To-Script-Hash (P2SH) address.
  3. * See also https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki: Address Format for pay-to-script-hash
  4. */
  5. public boolean isP2SHAddress() {
  6. final NetworkParameters parameters = getParameters();
  7. return parameters != null && this.version == parameters.p2shHeader;
  8. }

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

  1. /**
  2. * Returns true if this address is a Pay-To-Script-Hash (P2SH) address.
  3. * See also https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki: Address Format for pay-to-script-hash
  4. */
  5. public boolean isP2SHAddress() {
  6. final NetworkParameters parameters = getParameters();
  7. return parameters != null && this.version == parameters.p2shHeader;
  8. }

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

  1. /**
  2. * Returns true if this address is a Pay-To-Script-Hash (P2SH) address.
  3. * See also https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki: Address Format for pay-to-script-hash
  4. */
  5. public boolean isP2SHAddress() {
  6. final NetworkParameters parameters = getParameters();
  7. return parameters != null && this.version == parameters.p2shHeader;
  8. }

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

  1. /**
  2. * Returns true if this address is a Pay-To-Witness-Public-Key-Hash (P2WPKH) address.
  3. * See also https://github.com/bitcoin/bips/blob/master/bip-0142.mediawiki: Address Format for Segregated Witness
  4. */
  5. public boolean isP2WPKHAddress() {
  6. final NetworkParameters parameters = getParameters();
  7. return parameters != null && this.version == parameters.p2wpkhHeader;
  8. }

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

  1. /**
  2. * Given an address, examines the version byte and attempts to find a matching NetworkParameters. If you aren't sure
  3. * which network the address is intended for (eg, it was provided by a user), you can use this to decide if it is
  4. * compatible with the current wallet.
  5. * @return a NetworkParameters of the address
  6. * @throws AddressFormatException if the string wasn't of a known version
  7. */
  8. public static NetworkParameters getParametersFromAddress(String address) throws AddressFormatException {
  9. try {
  10. return Address.fromBase58(null, address).getParameters();
  11. } catch (WrongNetworkException e) {
  12. throw new RuntimeException(e); // Cannot happen.
  13. }
  14. }

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

  1. /**
  2. * Given an address, examines the version byte and attempts to find a matching NetworkParameters. If you aren't sure
  3. * which network the address is intended for (eg, it was provided by a user), you can use this to decide if it is
  4. * compatible with the current wallet.
  5. * @return a NetworkParameters of the address
  6. * @throws AddressFormatException if the string wasn't of a known version
  7. */
  8. public static NetworkParameters getParametersFromAddress(String address) throws AddressFormatException {
  9. try {
  10. return Address.fromBase58(null, address).getParameters();
  11. } catch (WrongNetworkException e) {
  12. throw new RuntimeException(e); // Cannot happen.
  13. }
  14. }

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

  1. /**
  2. * Simple Bitcoin URI builder using known good fields.
  3. *
  4. * @param address The Bitcoin address
  5. * @param amount The amount
  6. * @param label A label
  7. * @param message A message
  8. * @return A String containing the Bitcoin URI
  9. */
  10. public static String convertToBitcoinURI(Address address, Coin amount,
  11. String label, String message) {
  12. return convertToBitcoinURI(address.getParameters(), address.toString(), amount, label, message);
  13. }

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

  1. /**
  2. * Simple Bitcoin URI builder using known good fields.
  3. *
  4. * @param address The Bitcoin address
  5. * @param amount The amount
  6. * @param label A label
  7. * @param message A message
  8. * @return A String containing the Bitcoin URI
  9. */
  10. public static String convertToBitcoinURI(Address address, Coin amount,
  11. String label, String message) {
  12. return convertToBitcoinURI(address.getParameters(), address.toString(), amount, label, message);
  13. }

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

  1. /**
  2. * Simple Bitcoin URI builder using known good fields.
  3. *
  4. * @param address The Bitcoin address
  5. * @param amount The amount
  6. * @param label A label
  7. * @param message A message
  8. * @return A String containing the Bitcoin URI
  9. */
  10. public static String convertToBitcoinURI(Address address, Coin amount,
  11. String label, String message) {
  12. return convertToBitcoinURI(address.getParameters(), address.toString(), amount, label, message);
  13. }

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

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

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

  1. /**
  2. * Simple Bitcoin URI builder using known good fields.
  3. *
  4. * @param address The Bitcoin address
  5. * @param amount The amount
  6. * @param label A label
  7. * @param message A message
  8. * @return A String containing the Bitcoin URI
  9. */
  10. public static String convertToBitcoinURI(Address address, Coin amount,
  11. String label, String message) {
  12. return convertToBitcoinURI(address.getParameters(), address.toString(), amount, label, message);
  13. }

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

  1. public static SendRequest emptyWallet(Address destination) {
  2. SendRequest req = new SendRequest();
  3. final NetworkParameters parameters = destination.getParameters();
  4. checkNotNull(parameters, "Address is for an unknown network");
  5. req.tx = new Transaction(parameters);
  6. req.tx.addOutput(Coin.ZERO, destination);
  7. req.emptyWallet = true;
  8. return req;
  9. }

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

  1. public static SendRequest emptyWallet(Address destination) {
  2. SendRequest req = new SendRequest();
  3. final NetworkParameters parameters = destination.getParameters();
  4. checkNotNull(parameters, "Address is for an unknown network");
  5. req.tx = new Transaction(parameters);
  6. req.tx.addOutput(Coin.ZERO, destination);
  7. req.emptyWallet = true;
  8. return req;
  9. }

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

  1. public static SendRequest emptyWallet(Address destination) {
  2. SendRequest req = new SendRequest();
  3. final NetworkParameters parameters = destination.getParameters();
  4. checkNotNull(parameters, "Address is for an unknown network");
  5. req.tx = new Transaction(parameters);
  6. req.tx.addOutput(Coin.ZERO, destination);
  7. req.emptyWallet = true;
  8. return req;
  9. }

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

  1. public static SendRequest emptyWallet(Address destination) {
  2. SendRequest req = new SendRequest();
  3. final NetworkParameters parameters = destination.getParameters();
  4. checkNotNull(parameters, "Address is for an unknown network");
  5. req.tx = new Transaction(parameters);
  6. req.tx.addOutput(Coin.ZERO, destination);
  7. req.emptyWallet = true;
  8. return req;
  9. }

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

  1. /**
  2. * <p>Creates a new SendRequest to the given address for the given value.</p>
  3. *
  4. * <p>Be very careful when value is smaller than {@link Transaction#MIN_NONDUST_OUTPUT} as the transaction will
  5. * likely be rejected by the network in this case.</p>
  6. */
  7. public static SendRequest to(Address destination, Coin value) {
  8. SendRequest req = new SendRequest();
  9. final NetworkParameters parameters = destination.getParameters();
  10. checkNotNull(parameters, "Address is for an unknown network");
  11. req.tx = new Transaction(parameters);
  12. req.tx.addOutput(value, destination);
  13. return req;
  14. }

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

  1. @Test(expected = java.lang.IllegalStateException.class)
  2. public void sendCoinsNoBroadcasterTest() throws InsufficientMoneyException {
  3. ECKey key = ECKey.fromPrivate(BigInteger.TEN);
  4. SendRequest req = SendRequest.to(OTHER_ADDRESS.getParameters(), key, SATOSHI.multiply(12));
  5. wallet.sendCoins(req);
  6. }

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

  1. @Test
  2. public void sendCoinsWithBroadcasterTest() throws InsufficientMoneyException {
  3. ECKey key = ECKey.fromPrivate(BigInteger.TEN);
  4. receiveATransactionAmount(wallet, myAddress, Coin.COIN);
  5. MockTransactionBroadcaster broadcaster = new MockTransactionBroadcaster(wallet);
  6. wallet.setTransactionBroadcaster(broadcaster);
  7. SendRequest req = SendRequest.to(OTHER_ADDRESS.getParameters(), key, Coin.CENT);
  8. wallet.sendCoins(req);
  9. }

相关文章