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

x33g5p2x  于2022-02-01 转载在 其他  
字(2.3k)|赞(0)|评价(0)|浏览(97)

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

Utils.parseAsHexOrBase58介绍

[英]Attempts to parse the given string as arbitrary-length hex or base58 and then return the results, or null if neither parse was successful.
[中]尝试将给定字符串解析为任意长度的十六进制或base58,然后返回结果,如果两次解析都不成功,则返回null。

代码示例

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

/**
 * Create a wallet id from a formatted wallet id
 *
 * @param formattedWalletId The formatted wallet id you want to use (e.g. "66666666-77777777-88888888-99999999-aaaaaaaa")
 */
public WalletId(String formattedWalletId) {
 Preconditions.checkState(formattedWalletId.length() == LENGTH_OF_FORMATTED_WALLET_ID);
 // remove any embedded hyphens
 formattedWalletId = formattedWalletId.replaceAll("-", "");
 walletId = Utils.parseAsHexOrBase58(formattedWalletId);
}

代码示例来源:origin: terryjiao/BitcoinWallet

private static void generateSegwitAddress(String address) {
  byte[] decoded = Utils.parseAsHexOrBase58(address);
  // We should throw off header byte that is 0 for Bitcoin (Main)
  byte[] pureBytes = new byte[20];
  System.arraycopy(decoded, 1, pureBytes, 0, 20);
  // Than we should prepend the following bytes:
  byte[] scriptSig = new byte[pureBytes.length + 2];
  scriptSig[0] = 0x00;
  scriptSig[1] = 0x14;
  System.arraycopy(pureBytes, 0, scriptSig, 2, pureBytes.length);
  byte[] addressBytes = org.bitcoinj.core.Utils.sha256hash160(scriptSig);
  // Here are the address bytes
  byte[] readyForAddress = new byte[addressBytes.length + 1 + 4];
  // prepending p2sh header:
  readyForAddress[0] = (byte) 5;
  System.arraycopy(addressBytes, 0, readyForAddress, 1, addressBytes.length);
  // But we should also append check sum:
  byte[] checkSum = Sha256Hash.hashTwice(readyForAddress, 0, addressBytes.length + 1);
  System.arraycopy(checkSum, 0, readyForAddress, addressBytes.length + 1, 4);
  // To get the final address:
  String segwitAddress = Base58.base58Encode(readyForAddress);
  System.out.println("segwit address:" + segwitAddress);
}

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

byte[] decode = Utils.parseAsHexOrBase58(data);
  if (decode == null) {
    System.err.println("Could not understand --privkey as either hex or base58: " + data);
byte[] pubkey = Utils.parseAsHexOrBase58((String) options.valueOf("pubkey"));
key = ECKey.fromPublicOnly(pubkey);
key.setCreationTimeSeconds(creationTimeSeconds);

相关文章