コード例 #1
0
 public static Address addressFromString(String someString, NetworkParameters network) {
   if (someString == null) {
     return null;
   }
   someString = someString.trim();
   if (someString.matches("[a-zA-Z0-9]*")) {
     // Raw format
     return Address.fromString(someString, network);
   } else {
     BitcoinUri b = BitcoinUri.parse(someString, network);
     if (b != null) {
       // On URI format
       return b.address;
     }
   }
   return null;
 }
コード例 #2
0
  public static BitcoinScanResult parseScanResult(final Intent intent, NetworkParameters network) {
    if (!("QR_CODE".equals(intent.getStringExtra("SCAN_RESULT_FORMAT")))) {
      return null;
    }
    String contents = intent.getStringExtra("SCAN_RESULT").trim();

    // Determine address string and amount
    if (contents.matches("[a-zA-Z0-9]*")) {
      // Raw format
      Address address = Address.fromString(contents.trim(), network);
      if (address == null) {
        return null;
      }
      return new BitcoinScanResult(address, null);
    } else {
      BitcoinUri b = BitcoinUri.parse(contents, network);
      if (b != null) {
        // On URI format
        return new BitcoinScanResult(b.address, b.amount);
      }
    }

    return null;
  }
コード例 #3
0
ファイル: BitcoinUriTest.java プロジェクト: rebroad/wallet
 private void testParse(
     String url, NetworkParameters np, Optional<? extends BitcoinUri> expected) {
   Log.d(BitcoinUriTest.class.getName(), "testParse: " + expected.toString());
   Optional<? extends BitcoinUri> actual = BitcoinUri.parse(url, np);
   assertEquals(expected.toString(), actual.toString());
 }