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

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

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

Address.toString介绍

暂无

代码示例

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

/**
  * @return The contact name if present, otherwise the Bitcoin address
  */
 public String getSummary() {

  if (contact.isPresent()) {
   return contact.get().getName();
  }

  // The Base58 representation of this address
  return bitcoinAddress.toString();
 }
}

代码示例来源:origin: uncleleonfan/FunWallet

@Override
  public void run() {
    Coin balance = wallet.getBalance(Wallet.BalanceType.ESTIMATED);
    mAddressText.setText(address.toString());
    String balanceString = String.valueOf(balance.value / 100000) + " mBTC";
    mBalanceText.setText(balanceString);
    BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
    bitmapDrawable.setFilterBitmap(false);
    mQrImageView.setImageDrawable(bitmapDrawable);
  }
});

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

/**
 * Simple Bitcoin URI builder using known good fields.
 *
 * @param address The Bitcoin address
 * @param amount The amount
 * @param label A label
 * @param message A message
 * @return A String containing the Bitcoin URI
 */
public static String convertToBitcoinURI(Address address, Coin amount,
                     String label, String message) {
  return convertToBitcoinURI(address.getParameters(), address.toString(), amount, label, message);
}

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

/**
 * Simple Bitcoin URI builder using known good fields.
 *
 * @param address The Bitcoin address
 * @param amount The amount
 * @param label A label
 * @param message A message
 * @return A String containing the Bitcoin URI
 */
public static String convertToBitcoinURI(Address address, Coin amount,
                     String label, String message) {
  return convertToBitcoinURI(address.getParameters(), address.toString(), amount, label, message);
}

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

private void selectNameOrBitcoinAddress(Optional<Recipient> recipient) {
 if (recipient.get().getContact().isPresent()) {
  editor.setText(recipient.get().getContact().get().getName());
 } else {
  editor.setText(recipient.get().getBitcoinAddress().toString());
 }
}

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

public ECKey decrypt(String passphrase) throws BadPassphraseException {
  String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC);
  ECKey key = ecMultiply ? decryptEC(normalizedPassphrase) : decryptNoEC(normalizedPassphrase);
  Sha256Hash hash = Sha256Hash.twiceOf(key.toAddress(params).toString().getBytes(Charsets.US_ASCII));
  byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4);
  if (!Arrays.equals(actualAddressHash, addressHash))
    throw new BadPassphraseException();
  return key;
}

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

public ECKey decrypt(String passphrase) throws BadPassphraseException {
  String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC);
  ECKey key = ecMultiply ? decryptEC(normalizedPassphrase) : decryptNoEC(normalizedPassphrase);
  Sha256Hash hash = Sha256Hash.twiceOf(key.toAddress(params).toString().getBytes(Charsets.US_ASCII));
  byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4);
  if (!Arrays.equals(actualAddressHash, addressHash))
    throw new BadPassphraseException();
  return key;
}

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

public ECKey decrypt(String passphrase) throws BadPassphraseException {
  String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC);
  ECKey key = ecMultiply ? decryptEC(normalizedPassphrase) : decryptNoEC(normalizedPassphrase);
  Sha256Hash hash = Sha256Hash.twiceOf(key.toAddress(params).toString().getBytes(Charsets.US_ASCII));
  byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4);
  if (!Arrays.equals(actualAddressHash, addressHash))
    throw new BadPassphraseException();
  return key;
}

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

@Test
public void testSend() throws Exception {
 WalletAppKit nomKit = bitcoinCryptoNoP.getKit();
 Wallet wallet = nomKit.wallet();
 System.out.println("Current Receive Address: " + wallet.currentReceiveAddress().toString() + "\nIssued Receive Addresses: \n" + wallet.getIssuedReceiveAddresses().toString() + "\nMnemonic: " + wallet.getActiveKeychain().getMnemonicCode().toString() + "\nWallets Balance: " + wallet.getBalance().toPlainString() + " BTC");
 // Get a ready to send TX in its Raw HEX format
 System.out.println("Raw TX HEX: " + bitcoinCryptoNoP.sendOffline("n2ooxjPCQ19f56ivrCBq93DM6a71TA89bc", 10000));
 // Create and send transaciton using the wallets broadcast
 org.bitcoinj.core.Transaction sentTransaction = bitcoinCryptoNoP.send("n2ooxjPCQ19f56ivrCBq93DM6a71TA89bc", 10000);
 System.out.println("Transaction sent. Find txid: " + sentTransaction.getHashAsString());
}

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

@Test
public void testScriptSig() throws Exception {
  byte[] sigProgBytes = HEX.decode(sigProg);
  Script script = new Script(sigProgBytes);
  // Test we can extract the from address.
  byte[] hash160 = Utils.sha256hash160(script.getPubKey());
  Address a = new Address(PARAMS, hash160);
  assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", a.toString());
}

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

@Test
public void testScriptPubKey() throws Exception {
  // Check we can extract the to address
  byte[] pubkeyBytes = HEX.decode(pubkeyProg);
  Script pubkey = new Script(pubkeyBytes);
  assertEquals("DUP HASH160 PUSHDATA(20)[33e81a941e64cda12c6a299ed322ddbdd03f8d0e] EQUALVERIFY CHECKSIG", pubkey.toString());
  Address toAddr = new Address(PARAMS, pubkey.getPubKeyHash());
  assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", toAddr.toString());
}

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

@Test
  public void testMini() throws Exception {
    SerializedKey serializedKey = new SerializedKey(BTC_MINI_PRIV);
    assertFalse(serializedKey.isEncrypted());
    SerializedKey.TypedKey key = serializedKey.getKey();
    assertTrue(key.possibleType.contains(BTC));
    assertEquals(BTC_MINI_ADDR, key.key.toAddress(BTC).toString());
  }
}

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

@Test
public void testWif() throws Exception {
  SerializedKey serializedKey = new SerializedKey(BTC_WIF_PRIV);
  assertFalse(serializedKey.isEncrypted());
  SerializedKey.TypedKey key = serializedKey.getKey();
  assertTrue(key.possibleType.contains(BTC));
  assertEquals(BTC_WIF_ADDR, key.key.toAddress(BTC).toString());
}

代码示例来源:origin: openwalletGH/openwallet-android

@Test
  public void testMini() throws Exception {
    SerializedKey serializedKey = new SerializedKey(BTC_MINI_PRIV);
    assertFalse(serializedKey.isEncrypted());
    SerializedKey.TypedKey key = serializedKey.getKey();
    assertTrue(key.possibleType.contains(BTC));
    assertEquals(BTC_MINI_ADDR, key.key.toAddress(BTC).toString());
  }
}

代码示例来源:origin: openwalletGH/openwallet-android

@Test
public void testWif() throws Exception {
  SerializedKey serializedKey = new SerializedKey(BTC_WIF_PRIV);
  assertFalse(serializedKey.isEncrypted());
  SerializedKey.TypedKey key = serializedKey.getKey();
  assertTrue(key.possibleType.contains(BTC));
  assertEquals(BTC_WIF_ADDR, key.key.toAddress(BTC).toString());
}

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

@Test
public void brokenURIs() throws BitcoinURIParseException {
  // Check we can parse the incorrectly formatted URIs produced by blockchain.info and its iPhone app.
  String str = "bitcoin://1KzTSfqjF2iKCduwz59nv2uqh1W2JsTxZH?amount=0.01000000";
  BitcoinURI uri = new BitcoinURI(str);
  assertEquals("1KzTSfqjF2iKCduwz59nv2uqh1W2JsTxZH", uri.getAddress().toString());
  assertEquals(CENT, uri.getAmount());
}

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

@Test
public void base58Encoding() throws Exception {
  String addr = "mqAJmaxMcG5pPHHc3H3NtyXzY7kGbJLuMF";
  String privkey = "92shANodC6Y4evT5kFzjNFQAdjqTtHAnDTLzqBBq4BbKUPyx6CD";
  ECKey key = DumpedPrivateKey.fromBase58(TestNet3Params.get(), privkey).getKey();
  assertEquals(privkey, key.getPrivateKeyEncoded(TestNet3Params.get()).toString());
  assertEquals(addr, key.toAddress(TestNet3Params.get()).toString());
}

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

相关文章