本文整理汇总了Java中org.bitcoinj.core.AddressFormatException类的典型用法代码示例。如果您正苦于以下问题:Java AddressFormatException类的具体用法?Java AddressFormatException怎么用?Java AddressFormatException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AddressFormatException类属于org.bitcoinj.core包,在下文中一共展示了AddressFormatException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMasterPubKeyFromXPub
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
/**
* Restore watch-only account deterministic public key from XPUB.
*
* @return DeterministicKey
*
*/
private DeterministicKey createMasterPubKeyFromXPub(String xpubstr) throws AddressFormatException {
byte[] xpubBytes = Base58.decodeChecked(xpubstr);
ByteBuffer bb = ByteBuffer.wrap(xpubBytes);
if(bb.getInt() != 0x0488B21E) {
throw new AddressFormatException("invalid xpub version");
}
byte[] chain = new byte[32];
byte[] pub = new byte[33];
// depth:
bb.get();
// parent fingerprint:
bb.getInt();
// child no.
bb.getInt();
bb.get(chain);
bb.get(pub);
return HDKeyDerivation.createMasterPubKeyFromBytes(pub, chain);
}
示例2: testConstructors
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
@Test
public void testConstructors() throws AddressFormatException {
// BTC
assertEquals(BTC_P2PKH_ADDR, new BitAddress(BTC, HASH160).toString());
assertEquals(BTC_P2PKH_ADDR, new BitAddress(BTC, BTC.getAddressHeader(), HASH160).toString());
assertEquals(BTC_P2PKH_ADDR, new BitAddress(BTC, BTC_P2PKH_ADDR).toString());
assertEquals(BTC_P2SH_ADDR, new BitAddress(BTC, BTC.getP2SHHeader(), HASH160).toString());
assertEquals(BTC_P2SH_ADDR, new BitAddress(BTC, BTC_P2SH_ADDR).toString());
// LTC
assertEquals(LTC_P2PKH_ADDR, new BitAddress(LTC, HASH160).toString());
assertEquals(LTC_P2PKH_ADDR, new BitAddress(LTC, LTC.getAddressHeader(), HASH160).toString());
assertEquals(LTC_P2PKH_ADDR, new BitAddress(LTC, LTC_P2PKH_ADDR).toString());
assertEquals(LTC_P2SH_ADDR, new BitAddress(LTC, LTC.getP2SHHeader(), HASH160).toString());
assertEquals(LTC_P2SH_ADDR, new BitAddress(LTC, LTC_P2SH_ADDR).toString());
}
示例3: validateReceivingAddress
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
private void validateReceivingAddress()
{
try
{
final String addressStr = receivingAddressView.getText().toString().trim();
if (!addressStr.isEmpty() && Constants.NETWORK_PARAMETERS.equals(Address.getParametersFromAddress(addressStr)))
{
final String label = AddressBookProvider.resolveLabel(activity, addressStr);
validatedAddress = new AddressAndLabel(Constants.NETWORK_PARAMETERS, addressStr, label);
receivingAddressView.setText(null);
}
}
catch (final AddressFormatException x)
{
// swallow
}
}
示例4: checkDoubleSpending
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
void checkDoubleSpending(Transaction t) throws InterruptedException, IOException,
FormatException, TimeoutException, Matrix, CoinNetworkException, AddressFormatException {
// Check for double spending.
Message doubleSpend = messages.make();
for (VerificationKey key : players.values()) {
Transaction o = coin.getConflictingTransaction(t, key.address(), amount);
if (o != null) {
doubleSpend = doubleSpend.attach(Blame.DoubleSpend(key, o));
}
}
if (!doubleSpend.isEmpty()) {
phase.set(Phase.Blame);
mailbox.broadcast(doubleSpend, phase.get());
throw fillBlameMatrix();
}
}
示例5: sendOffline
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
public String sendOffline(String destinationAddress, long amountSatoshis) throws InsufficientMoneyException {
Address addressj;
try {
addressj = new Address(params, destinationAddress);
} catch (AddressFormatException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
Coin amount = Coin.valueOf(amountSatoshis);
// create a SendRequest of amount to destinationAddress
Wallet.SendRequest sendRequest = Wallet.SendRequest.to(addressj, amount);
// set dynamic fee
sendRequest.feePerKb = getRecommendedFee();
// complete & sign tx
kit.wallet().completeTx(sendRequest);
kit.wallet().signTransaction(sendRequest);
// return tx bytes as hex encoded String
return Hex.encodeHexString(sendRequest.tx.bitcoinSerialize());
}
示例6: testVector
import org.bitcoinj.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));
assertEquals(testEncode(tv.priv), testEncode(masterPrivateKey.serializePrivB58()));
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);
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]);
assertEquals(testEncode(tc.priv), testEncode(ehkey.serializePrivB58()));
assertEquals(testEncode(tc.pub), testEncode(ehkey.serializePubB58()));
}
}
示例7: testVector
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
private void testVector(int testCase) throws AddressFormatException {
log.info("======= Test vector {}", testCase);
HDWTestVector tv = tvs[testCase];
NetworkParameters params = MainNetParams.get();
DeterministicKey masterPrivateKey = HDKeyDerivation.createMasterPrivateKey(HEX.decode(tv.seed));
assertEquals(testEncode(tv.priv), testEncode(masterPrivateKey.serializePrivB58(params)));
assertEquals(testEncode(tv.pub), testEncode(masterPrivateKey.serializePubB58(params)));
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);
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]);
assertEquals(testEncode(tc.priv), testEncode(ehkey.serializePrivB58(params)));
assertEquals(testEncode(tc.pub), testEncode(ehkey.serializePubB58(params)));
}
}
示例8: getPubKeyFromAccount
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
/**
*
* @param accountIndex
* @param type
* @param addressKey
* @param iKnowAddressFromKeyIsNotWatched
* @return
* @throws AddressNotWatchedByWalletException
* @throws CannotGetHDKeyException
*/
public DeterministicKey getPubKeyFromAccount(int accountIndex,
HierarchyAddressTypes type,
int addressKey,
boolean iKnowAddressFromKeyIsNotWatched) throws AddressNotWatchedByWalletException, CannotGetHDKeyException, AddressFormatException{
try {
ATAccount acc = this.getAccount(accountIndex);
ATAccountAddressHierarchy H = type == HierarchyAddressTypes.External? acc.getAccountExternalHierarchy():acc.getAccountInternalHierarchy();
DeterministicKey ret = authenticatorWalletHierarchy.getPubKeyFromAccount(accountIndex, type, addressKey, H);
if(!iKnowAddressFromKeyIsNotWatched && !isWatchingAddress(ret.toAddress(getNetworkParams())))
throw new AddressNotWatchedByWalletException("You are trying to get an unwatched address");
return ret;
}
catch(KeyIndexOutOfRangeException | AccountWasNotFoundException e) {
throw new CannotGetHDKeyException(e.toString());
}
}
示例9: isValidBitcoinAddress
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
public boolean isValidBitcoinAddress(String address) {
try {
Address.fromBase58(getBitcoinNetworkParameters(), address);
return true;
} catch(AddressFormatException e) {
return false;
}
}
示例10: isValidAddress
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
public boolean isValidAddress(String address) {
try {
Address.fromBase58(getNetworkParameters(), address);
return true;
} catch(AddressFormatException e) {
return false;
}
}
示例11: testAddr
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
private boolean testAddr(String text) {
try {
new Address(params, text);
return true;
} catch (AddressFormatException e) {
return false;
}
}
示例12: Wallet
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
/**
* Constructor for watch-only wallet initialized from submitted XPUB(s).
*
* @param NetworkParameters params
* @param String[] xpub array of XPUB strings
*
*/
public Wallet(NetworkParameters params, String[] xpub) throws AddressFormatException {
this.params = params;
accounts = new ArrayList<Account>();
for(int i = 0; i < xpub.length; i++) {
accounts.add(new Account(params, xpub[i], i));
}
}
示例13: getInstance
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
/**
* Return instance for a watch only wallet. No seed, no private keys.
*
* @param Context ctx app context
* @param String[] xpub restore these accounts only
*
* @return WalletFactory
*
*/
public static WalletFactory getInstance(String[] xpub) throws AddressFormatException {
if(instance == null) {
locale = new Locale("en", "US");
wallets = new ArrayList<Wallet>();
instance = new WalletFactory();
}
if(watch_only_wallet == null) {
watch_only_wallet = new Wallet(MainNetParams.get(), xpub);
}
return instance;
}
示例14: newWalletTest
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
@Test
public void newWalletTest() throws AddressFormatException, MnemonicLengthException, MnemonicWordException, MnemonicChecksumException, IOException, DecoderException {
String MNEMONIC_STRING = "sword acquire little despair wave swear during expect target science banana eyebrow";
String passphrase = "";
org.matthiaszimmermann.bitcoin.pwg.Wallet hdWallet = WalletFactory.getInstance().restoreWallet(MNEMONIC_STRING, passphrase);
System.out.println(hdWallet.toJSON().toString(4));
}
示例15: handleRequest
import org.bitcoinj.core.AddressFormatException; //导入依赖的package包/类
private void handleRequest() {
try {
final String[] addresses = donationAddresses();
final NetworkParameters params = Address.getParametersFromAddress(addresses[0]);
final Protos.Output.Builder output1 = Protos.Output.newBuilder();
output1.setAmount(AMOUNT);
output1.setScript(ByteString
.copyFrom(ScriptBuilder.createOutputScript(new Address(params, addresses[0])).getProgram()));
final Protos.Output.Builder output2 = Protos.Output.newBuilder();
output2.setAmount(AMOUNT);
output2.setScript(ByteString
.copyFrom(ScriptBuilder.createOutputScript(new Address(params, addresses[1])).getProgram()));
final Protos.PaymentDetails.Builder paymentDetails = Protos.PaymentDetails.newBuilder();
paymentDetails.setNetwork(params.getPaymentProtocolId());
paymentDetails.addOutputs(output1);
paymentDetails.addOutputs(output2);
paymentDetails.setMemo(MEMO);
paymentDetails.setTime(System.currentTimeMillis());
final Protos.PaymentRequest.Builder paymentRequest = Protos.PaymentRequest.newBuilder();
paymentRequest.setSerializedPaymentDetails(paymentDetails.build().toByteString());
BitcoinIntegration.requestForResult(SampleActivity.this, REQUEST_CODE,
paymentRequest.build().toByteArray());
} catch (final AddressFormatException x) {
throw new RuntimeException(x);
}
}