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

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

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

Address.fromBase58介绍

[英]Construct an address from its Base58 representation.
[中]从其Base58表示形式构造一个地址。

代码示例

代码示例来源:origin: ConsensusJ/consensusj

@Override
  public Object deserializeKey(String key, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    return Address.fromBase58(netParams, key);
  }
}

代码示例来源:origin: ConsensusJ/consensusj

public AddressGroupingItem(List<Object> addressItem, NetworkParameters netParams) {
  String addressStr = (String) addressItem.get(0);
  //TODO: Try to avoid using Double
  Double balanceDouble = (Double) addressItem.get(1);
  account = (addressItem.size() > 2) ? (String) addressItem.get(2) : null;
  address = Address.fromBase58(netParams, addressStr);
  balance = Coin.valueOf(((Double)(balanceDouble * 100000000.0)).longValue());
}

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

public boolean isValidBitcoinAddress(String address) {
  try {
    Address.fromBase58(getBitcoinNetworkParameters(), address);
    return true;
  } catch (AddressFormatException e) {
    return false;
  }
}

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

public boolean isValidAddress(String address) {
  try {
    Address.fromBase58(getNetworkParameters(), address);
    return true;
  } catch (AddressFormatException e) {
    return false;
  }
}

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

@Override
public synchronized void addPaymentAddressesForMonitoring(String addressString, Long addressCreationTimestamp) {
  final Address address = Address.fromBase58(bitcoinNetworkParameters, addressString);
  LOG.info("Add monitored Bitcoin Address: {}", addressString);
  wallet.addWatchedAddress(address, addressCreationTimestamp);
}

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

/**
 * 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.
 * @return a NetworkParameters of the address
 * @throws AddressFormatException if the string wasn't of a known version
 */
public static NetworkParameters getParametersFromAddress(String address) throws AddressFormatException {
  try {
    return Address.fromBase58(null, address).getParameters();
  } catch (WrongNetworkException e) {
    throw new RuntimeException(e);  // Cannot happen.
  }
}

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

/**
 * 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.
 * @return a NetworkParameters of the address
 * @throws AddressFormatException if the string wasn't of a known version
 */
public static NetworkParameters getParametersFromAddress(String address) throws AddressFormatException {
  try {
    return Address.fromBase58(null, address).getParameters();
  } catch (WrongNetworkException e) {
    throw new RuntimeException(e);  // Cannot happen.
  }
}

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

public String pay(String paymentToBTCAddress, BigDecimal amount)
    throws InterruptedException, ExecutionException, InsufficientMoneyException {
  LOG.debug("BTC: Sending funds to {}, amount {}.", paymentToBTCAddress, amount.toPlainString());
  Address targetAddress = Address.fromBase58(this.bitcoinNetworkParameters, paymentToBTCAddress);
  Wallet.SendResult result = this.bitcoinWallet.sendCoins(peerGroup, targetAddress, Coin.parseCoin(amount.toPlainString()));
  // Wait for the transaction to propagate across the P2P network, indicating acceptance.
  result.broadcastComplete.get();
  return result.tx.getHashAsString();
}

代码示例来源:origin: blockchain/unused-My-Wallet-V3-jar

public static boolean isValidBitcoinAddress(final String address) {
  boolean ret;
  try {
    Address.fromBase58(PersistentUrls.getInstance().getCurrentNetworkParams(), address);
    ret = true;
  } catch (WrongNetworkException wne) {
    ret = false;
  } catch (AddressFormatException afe) {
    ret = false;
  }
  return ret;
}

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

@Test
public void comparisonGreaterThan() throws Exception {
  Address a = Address.fromBase58(mainParams, "1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P");
  Address b = Address.fromBase58(mainParams, "1Dorian4RoXcnBv9hnQ4Y2C1an6NJ4UrjX");
  int result = a.compareTo(b);
  assertTrue(result > 0);
}

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

@Test
public void comparisonLessThan() throws Exception {
  Address a = Address.fromBase58(mainParams, "1Dorian4RoXcnBv9hnQ4Y2C1an6NJ4UrjX");
  Address b = Address.fromBase58(mainParams, "1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P");
  int result = a.compareTo(b);
  assertTrue(result < 0);
}

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

@Test
  public void comparisonBytesVsString() throws Exception {
    // TODO: To properly test this we need a much larger data set
    Address a = Address.fromBase58(mainParams, "1Dorian4RoXcnBv9hnQ4Y2C1an6NJ4UrjX");
    Address b = Address.fromBase58(mainParams, "1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P");

    int resultBytes = a.compareTo(b);
    int resultsString = a.toString().compareTo(b.toString());
    assertTrue( resultBytes < 0 );
    assertTrue( resultsString < 0 );
  }
}

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

@Test
public void roundtripBase58() throws Exception {
  String base58 = "17kzeh4N8g49GFvdDzSf8PjaPfyoD1MndL";
  assertEquals(base58, Address.fromBase58(null, base58).toBase58());
}

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

@Test
public void comparisonCloneEqualTo() throws Exception {
  Address a = Address.fromBase58(mainParams, "1Dorian4RoXcnBv9hnQ4Y2C1an6NJ4UrjX");
  Address b = a.clone();
  int result = a.compareTo(b);
  assertEquals(0, result);
}

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

@Test
public void comparisonEqualTo() throws Exception {
  Address a = Address.fromBase58(mainParams, "1Dorian4RoXcnBv9hnQ4Y2C1an6NJ4UrjX");
  Address b = a.clone();
  int result = a.compareTo(b);
  assertEquals(0, result);
}

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

@Test
public void testP2SHOutputScript() throws Exception {
  Address p2shAddress = Address.fromBase58(MainNetParams.get(), "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
  assertTrue(ScriptBuilder.createOutputScript(p2shAddress).isPayToScriptHash());
}

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

@Test
public void verifyMessage() throws Exception {
  // Test vector generated by Bitcoin-Qt.
  String message = "hello";
  String sigBase64 = "HxNZdo6ggZ41hd3mM3gfJRqOQPZYcO8z8qdX2BwmpbF11CaOQV+QiZGGQxaYOncKoNW61oRuSMMF8udfK54XqI8=";
  Address expectedAddress = Address.fromBase58(MainNetParams.get(), "14YPSNPi6NSXnUxtPAsyJSuw3pv7AU3Cag");
  ECKey key = ECKey.signedMessageToKey(message, sigBase64);
  Address gotAddress = key.toAddress(MainNetParams.get());
  assertEquals(expectedAddress, gotAddress);
}

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

@Test
public void testP2SHOutputScript() throws Exception {
  String P2SHAddressString = "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU";
  Address P2SHAddress = Address.fromBase58(MainNetParams.get(), P2SHAddressString);
  Script script = ScriptBuilder.createOutputScript(P2SHAddress);
  Transaction tx = new Transaction(MainNetParams.get());
  tx.addOutput(Coin.COIN, script);
  assertEquals(P2SHAddressString, tx.getOutput(0).getAddressFromP2SH(MainNetParams.get()).toString());
}

相关文章