org.bitcoinj.core.WrongNetworkException Java Examples

The following examples show how to use org.bitcoinj.core.WrongNetworkException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WIFValidator.java    From token-core-android with Apache License 2.0 5 votes vote down vote up
@Override
public String validate() {
  try {
    DumpedPrivateKey.fromBase58(network, wif);
  } catch (WrongNetworkException addressException) {
    throw new TokenException(Messages.WIF_WRONG_NETWORK);
  } catch (AddressFormatException addressFormatException) {
    throw new TokenException(Messages.WIF_INVALID);
  }
  if (requireCompressed && !DumpedPrivateKey.fromBase58(network, wif).getKey().isCompressed()) {
    throw new TokenException(Messages.SEGWIT_NEEDS_COMPRESS_PUBLIC_KEY);
  }
  return this.wif;
}
 
Example #2
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOListLtcNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #3
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOListQtum(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #4
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOListBtgNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #5
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOListBch(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #6
Source File: ConfidentialAddress.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public ConfidentialAddress(final NetworkParameters params, final int version, final byte[] hash, final byte[] blindingPubKey)
        throws WrongNetworkException, WrongLengthException {
    super(4, getBytes(params, version, hash, blindingPubKey));
    checkNotNull(params);
    if (!isAcceptableVersion(params, version))
        throw new WrongNetworkException(version, params.getAcceptableAddressCodes());
    if (!isAcceptableLength(params, version, hash.length))
        throw new WrongLengthException(hash.length);
}
 
Example #7
Source File: ConfidentialAddress.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
protected ConfidentialAddress(final NetworkParameters params, final String address) throws AddressFormatException {
    super(address);

    checkNotNull(params);

    if (version != 4)
        throw new WrongNetworkException(version, params.getAcceptableAddressCodes());

    final byte[] hash = bytes;
    if (!isAcceptableLength(params, version, hash.length - 1 - 33)) // len - version - pubkey
        throw new WrongLengthException(hash.length);
}
 
Example #8
Source File: ConfidentialAddress.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public static ConfidentialAddress fromP2SHHash(final NetworkParameters params, final byte[] hash160, final byte[] blindingPubKey) {
    try {
        return new ConfidentialAddress(params, params.getP2SHHeader(), hash160, blindingPubKey);
    } catch (final WrongNetworkException e) {
        throw new RuntimeException(e);  // Cannot happen.
    }
}
 
Example #9
Source File: ConfidentialAddress.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
public ConfidentialAddress(final NetworkParameters params, final int version, final byte[] hash, final byte[] blindingPubKey)
        throws WrongNetworkException, WrongLengthException {
    super(4, getBytes(params, version, hash, blindingPubKey));
    checkNotNull(params);
    if (!isAcceptableVersion(params, version))
        throw new WrongNetworkException(version, params.getAcceptableAddressCodes());
    if (!isAcceptableLength(params, version, hash.length))
        throw new WrongLengthException(hash.length);
}
 
Example #10
Source File: ConfidentialAddress.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
protected ConfidentialAddress(final NetworkParameters params, final String address) throws AddressFormatException {
    super(address);

    checkNotNull(params);

    if (version != 4)
        throw new WrongNetworkException(version, params.getAcceptableAddressCodes());

    final byte[] hash = bytes;
    if (!isAcceptableLength(params, version, hash.length - 1 - 33)) // len - version - pubkey
        throw new WrongLengthException(hash.length);
}
 
Example #11
Source File: ConfidentialAddress.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
public static ConfidentialAddress fromP2SHHash(final NetworkParameters params, final byte[] hash160, final byte[] blindingPubKey) {
    try {
        return new ConfidentialAddress(params, params.getP2SHHeader(), hash160, blindingPubKey);
    } catch (final WrongNetworkException e) {
        throw new RuntimeException(e);  // Cannot happen.
    }
}
 
Example #12
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (AddressFormatException afe) {
        Log.e("psd", "restoreFromBlockByWif2: " + afe.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOListDgbNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItemDgb> utxos = (List<UTXOItemDgb>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #13
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOListSbtcNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            try {
                List<UTXOItem> utxos = (List<UTXOItem>)response;
                setUTXO(utxos);
            } catch (ClassCastException cce) {
                Log.d("psd", "restoreFromBlockByWif2 - getUTXOList ClassCastException: " + cce.getMessage());
            }
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #14
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        FirebaseCrash.report(wne);
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    } catch (NullPointerException npe) {
        FirebaseCrash.report(npe);
        Log.e("psd", "restoreFromBlockByWif2: " + npe.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOList(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            UTXOListResponse utxoResponse = (UTXOListResponse) response;
            setUTXO(utxoResponse.getUTXOList());
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #15
Source File: Trezor.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
public List<byte[]> signTransaction(final PreparedTransaction ptx, final String coinName) {
    mTx = ptx;
    mGAKey = makeHDKey(HDKey.getGAPublicKeys(ptx.mSubAccount, null, mNetwork)[0]);

    mBackupKey = null;
    if (ptx.mTwoOfThreeBackupChaincode != null)
        mBackupKey = makeHDKey(HDKey.getRecoveryKeys(ptx.mTwoOfThreeBackupChaincode,
                                                     ptx.mTwoOfThreeBackupPubkey, null)[0]);

    mChangeAddress = null;
    if (getChangePointer() != null) {
        byte[] script = GaService.createOutScript(ptx.mSubAccount, getChangePointer(),
                                                  ptx.mTwoOfThreeBackupPubkey,
                                                  ptx.mTwoOfThreeBackupChaincode, mNetwork);
        try {
            if (mTx.mChangeOutput.mIsSegwit)
                script = GaService.getSegWitScript(script);
            mChangeAddress = new org.bitcoinj.core.Address(mNetworkParameters, mNetworkParameters.getP2SHHeader(),
                                                           Wally.hash160(script));
            Log.d(TAG, "Change address: " + mChangeAddress.toString());
        } catch (final WrongNetworkException e) {
        }
    }

    mUserKey = makeHDKey(HDClientKey.getMyPublicKey(ptx.mSubAccount, null));

    final int numInputs = ptx.mDecoded.getInputs().size();
    final int numOutputs = ptx.mDecoded.getOutputs().size();

    mSignatures.clear();
    for (int i = 0; i < numInputs; ++i)
        mSignatures.add("");

    final String[] sigs;
    sigs = io(SignTx.newBuilder().setInputsCount(numInputs)
                                 .setOutputsCount(numOutputs)
                                 .setCoinName(coinName)
                                 .setLockTime((int) ptx.mDecoded.getLockTime()))
                                 .split(";");

    final LinkedList<byte[]> signaturesList = new LinkedList<>();
    for (final String sig: sigs)
        signaturesList.add(ISigningWallet.getTxSignature(ECKey.ECDSASignature.decodeFromDER(h2b(sig))));

    return signaturesList;
}