本文整理汇总了Java中com.google.bitcoin.core.AddressFormatException类的典型用法代码示例。如果您正苦于以下问题:Java AddressFormatException类的具体用法?Java AddressFormatException怎么用?Java AddressFormatException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AddressFormatException类属于com.google.bitcoin.core包,在下文中一共展示了AddressFormatException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testVector
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
private void testVector(int testCase) throws AddressFormatException {
log.info("======= Test vector {}", testCase);
HDWTestVector tv = tvs[testCase];
DeterministicKey masterPrivateKey = HDKeyDerivation.createMasterPrivateKey(Hex.decode(tv.seed));
Assert.assertEquals(testEncode(tv.priv), testEncode(masterPrivateKey.serializePrivB58()));
Assert.assertEquals(testEncode(tv.pub), testEncode(masterPrivateKey.serializePubB58()));
DeterministicHierarchy dh = new DeterministicHierarchy(masterPrivateKey);
for (int i = 0; i < tv.derived.size(); i++) {
HDWTestVector.DerivedTestCase tc = tv.derived.get(i);
log.info("{}", tc.name);
Assert.assertEquals(tc.name, String.format("Test%d %s", testCase + 1, tc.getPathDescription()));
int depth = tc.path.length - 1;
DeterministicKey ehkey = dh.deriveChild(Arrays.asList(tc.path).subList(0, depth), false, true, tc.path[depth]);
Assert.assertEquals(testEncode(tc.priv), testEncode(ehkey.serializePrivB58()));
Assert.assertEquals(testEncode(tc.pub), testEncode(ehkey.serializePubB58()));
}
}
示例2: getToAddress
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
public String getToAddress(String inputAddress) {
final String userEntered = inputAddress;
if (userEntered.length() > 0) {
try {
new Address(Constants.NETWORK_PARAMETERS, userEntered);
return userEntered;
} catch (AddressFormatException e) {
List<Pair<String, String>> labels = this.getLabelList();
for (Pair<String, String> label : labels) {
if (label.first.toLowerCase(Locale.ENGLISH).equals(userEntered.toLowerCase(Locale.ENGLISH))) {
try {
new Address(Constants.NETWORK_PARAMETERS, label.second);
return label.second;
} catch (AddressFormatException e1) {}
}
}
}
}
return null;
}
示例3: createMasterPubKeyFromPubB58
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
public static DeterministicKey createMasterPubKeyFromPubB58(String xpubstr)
throws AddressFormatException
{
byte[] data = Base58.decodeChecked(xpubstr);
ByteBuffer ser = ByteBuffer.wrap(data);
if (ser.getInt() != 0x0488B21E)
throw new AddressFormatException("bad xpub version");
ser.get(); // depth
ser.getInt(); // parent fingerprint
ser.getInt(); // child number
byte[] chainCode = new byte[32];
ser.get(chainCode);
byte[] pubBytes = new byte[33];
ser.get(pubBytes);
return HDKeyDerivation.createMasterPubKeyFromBytes(pubBytes, chainCode);
}
示例4: validateAddress
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
private boolean validateAddress(String address) {
Boolean addressIsInvalid = Boolean.TRUE;
if (address != null && !address.isEmpty()) {
// Copy address to wallet preferences.
this.bitcoinController.getModel().setActiveWalletPreference(BitcoinModel.VALIDATION_ADDRESS_VALUE, address);
try {
new Address(this.bitcoinController.getModel().getNetworkParameters(), address);
addressIsInvalid = Boolean.FALSE;
} catch (AddressFormatException afe) {
// Carry on.
} catch (java.lang.StringIndexOutOfBoundsException e) {
// Carry on.
}
} else {
this.bitcoinController.getModel().setActiveWalletPreference(BitcoinModel.VALIDATION_ADDRESS_VALUE, "");
}
this.bitcoinController.getModel().setActiveWalletPreference(BitcoinModel.VALIDATION_ADDRESS_IS_INVALID, addressIsInvalid.toString());
return !addressIsInvalid.booleanValue();
}
示例5: validateAddress
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
private boolean validateAddress(String address) {
Boolean addressIsInvalid = Boolean.TRUE;
if (address != null && !address.isEmpty()) {
// Copy address to wallet preferences.
validationState.put(VALIDATION_ADDRESS_VALUE, address);
try {
new Address(this.bitcoinController.getModel().getNetworkParameters(), address);
addressIsInvalid = Boolean.FALSE;
} catch (AddressFormatException afe) {
// Carry on.
} catch (java.lang.StringIndexOutOfBoundsException e) {
// Carry on.
}
} else {
validationState.put(VALIDATION_ADDRESS_VALUE, "");
}
validationState.put(VALIDATION_ADDRESS_IS_INVALID, addressIsInvalid.toString());
return !addressIsInvalid.booleanValue();
}
示例6: testAddr
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
private boolean testAddr(String text) {
try {
new Address(params, text);
return true;
} catch (AddressFormatException e) {
return false;
}
}
示例7: getFromAddress
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
@Override
public Address getFromAddress() {
try {
return new Address(params, address);
} catch (AddressFormatException e) {
e.printStackTrace();
}
return null;
}
示例8: getToAddress
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
public Address getToAddress() {
try {
return new Address(params, address);
} catch (AddressFormatException e) {
e.printStackTrace();
}
return null;
}
示例9: HDAddress
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
public HDAddress(NetworkParameters params,
DeterministicKey chainKey,
JSONObject addrNode)
throws RuntimeException, JSONException {
mParams = params;
mAddrNum = addrNode.getInt("addrNum");
mPath = addrNode.getString("path");
// Derive ECKey.
byte[] prvBytes = null;
try {
mPubBytes = Base58.decode(addrNode.getString("pubBytes"));
} catch (AddressFormatException ex) {
throw new RuntimeException("failed to decode pubBytes");
}
mECKey = new ECKey(prvBytes, mPubBytes);
// Set creation time to BTCReceive epoch.
mECKey.setCreationTimeSeconds(EPOCH);
// Derive public key, public hash and address.
mPubKey = mECKey.getPubKey();
mPubKeyHash = mECKey.getPubKeyHash();
mAddress = mECKey.toAddress(mParams);
// Initialize transaction count and balance. If we don't have
// a persisted available amount, presume it is all available.
mNumTrans = addrNode.getInt("numTrans");
mBalance = addrNode.getLong("balance");
mAvailable = addrNode.has("available") ?
addrNode.getLong("available") : mBalance;
mLogger.info("read address " + mPath + ": " + mAddress.toString());
}
示例10: isValidAddress
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
public static boolean isValidAddress(String address) {
try {
new Address(params, address);
return true;
} catch(AddressFormatException e) {
return false;
}
}
示例11: verify
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
public ECKey verify(String input) throws WrongInputException {
try {
ECKey sk = new DumpedPrivateKey(params, input).getKey();
if (pkHash != null && !Arrays.equals(sk.getPubKeyHash(), pkHash)) {
throw new WrongInputException("The secret key does not correspond expected public key.");
}
return sk;
} catch (AddressFormatException e) {
throw new WrongInputException("Wrong format of the secret key.");
}
}
示例12: validateBitcoinAddress
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
public static boolean validateBitcoinAddress(String address, BitcoinController bitcoinController) {
boolean isValid = false;
if (address != null && !address.isEmpty()) {
try {
new Address(bitcoinController.getModel().getNetworkParameters(), address);
isValid = true;
} catch (AddressFormatException afe) {
// Carry on.
} catch (java.lang.StringIndexOutOfBoundsException e) {
// Carry on.
}
}
return isValid;
}
示例13: generate
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
public Address generate() throws AddressFormatException {
ECKey key = new DumpedPrivateKey(params, privKeys[(privKeyCounter++)
% privKeys.length]).getKey();
wallet.addKey(key);
byte[] pubKeyHash = key.getPubKeyHash();
return new Address(params, pubKeyHash);
}
示例14: importPrivateKey
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
public Address importPrivateKey(String privKey)
throws AddressFormatException {
ECKey key = new DumpedPrivateKey(params, privKey).getKey();
wallet.addKey(key);
byte[] pubKeyHash = key.getPubKeyHash();
return new Address(params, pubKeyHash);
}
示例15: testEncode
import com.google.bitcoin.core.AddressFormatException; //导入依赖的package包/类
private String testEncode(String what) throws AddressFormatException {
return new String(Hex.encode(Base58.decodeChecked(what)));
}