Search in sources :

Example 11 with PaymentAddress

use of com.samourai.wallet.bip47.rpc.PaymentAddress in project samourai-wallet-android by Samourai-Wallet.

the class PayNymHome method getPcodeSyncObservable.

private Observable<String> getPcodeSyncObservable(String pcode) {
    return Observable.fromCallable(() -> {
        try {
            PaymentCode payment_code = new PaymentCode(pcode);
            int idx = 0;
            boolean loop = true;
            ArrayList<String> addrs = new ArrayList<String>();
            while (loop) {
                addrs.clear();
                for (int i = idx; i < (idx + 20); i++) {
                    // Log.i("BIP47Activity", "sync receive from " + i + ":" + BIP47Util.getInstance(BIP47Activity.this).getReceivePubKey(payment_code, i));
                    BIP47Meta.getInstance().getIdx4AddrLookup().put(BIP47Util.getInstance(this).getReceivePubKey(payment_code, i), i);
                    BIP47Meta.getInstance().getPCode4AddrLookup().put(BIP47Util.getInstance(this).getReceivePubKey(payment_code, i), payment_code.toString());
                    addrs.add(BIP47Util.getInstance(this).getReceivePubKey(payment_code, i));
                // Log.i("BIP47Activity", "p2pkh " + i + ":" + BIP47Util.getInstance(BIP47Activity.this).getReceiveAddress(payment_code, i).getReceiveECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
                }
                String[] s = addrs.toArray(new String[addrs.size()]);
                int nb = APIFactory.getInstance(getApplicationContext()).syncBIP47Incoming(s);
                // Log.i("BIP47Activity", "sync receive idx:" + idx + ", nb == " + nb);
                if (nb == 0) {
                    loop = false;
                }
                idx += 20;
            }
            idx = 0;
            loop = true;
            BIP47Meta.getInstance().setOutgoingIdx(pcode, 0);
            while (loop) {
                addrs.clear();
                for (int i = idx; i < (idx + 20); i++) {
                    PaymentAddress sendAddress = BIP47Util.getInstance(this).getSendAddress(payment_code, i);
                    // Log.i("BIP47Activity", "sync send to " + i + ":" + sendAddress.getSendECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
                    // BIP47Meta.getInstance().setOutgoingIdx(payment_code.toString(), i);
                    BIP47Meta.getInstance().getIdx4AddrLookup().put(BIP47Util.getInstance(this).getSendPubKey(payment_code, i), i);
                    BIP47Meta.getInstance().getPCode4AddrLookup().put(BIP47Util.getInstance(this).getSendPubKey(payment_code, i), payment_code.toString());
                    addrs.add(BIP47Util.getInstance(this).getSendPubKey(payment_code, i));
                }
                String[] s = addrs.toArray(new String[addrs.size()]);
                int nb = APIFactory.getInstance(getApplicationContext()).syncBIP47Outgoing(s);
                // Log.i("BIP47Activity", "sync send idx:" + idx + ", nb == " + nb);
                if (nb == 0) {
                    loop = false;
                }
                idx += 20;
            }
            BIP47Meta.getInstance().pruneIncoming();
            PayloadUtil.getInstance(this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(this).getGUID() + AccessFactory.getInstance(this).getPIN()));
        } catch (IOException ioe) {
            ;
        } catch (JSONException je) {
            ;
        } catch (DecryptionException de) {
            ;
        } catch (NotSecp256k1Exception nse) {
            ;
        } catch (InvalidKeySpecException ikse) {
            ;
        } catch (InvalidKeyException ike) {
            ;
        } catch (NoSuchAlgorithmException nsae) {
            ;
        } catch (NoSuchProviderException nspe) {
            ;
        } catch (MnemonicException.MnemonicLengthException mle) {
            ;
        } catch (Exception ex) {
        }
        return pcode;
    });
}
Also used : PaymentCode(com.samourai.wallet.bip47.rpc.PaymentCode) CharSequenceX(com.samourai.wallet.util.CharSequenceX) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) PaymentAddress(com.samourai.wallet.bip47.rpc.PaymentAddress) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NotSecp256k1Exception(com.samourai.wallet.bip47.rpc.NotSecp256k1Exception) UndeliverableException(io.reactivex.exceptions.UndeliverableException) NotSecp256k1Exception(com.samourai.wallet.bip47.rpc.NotSecp256k1Exception) JSONException(org.json.JSONException) AddressFormatException(org.bitcoinj.core.AddressFormatException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) MnemonicException(org.bitcoinj.crypto.MnemonicException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException) NoSuchProviderException(java.security.NoSuchProviderException) MnemonicException(org.bitcoinj.crypto.MnemonicException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) NoSuchProviderException(java.security.NoSuchProviderException) DecryptionException(com.samourai.wallet.crypto.DecryptionException)

Example 12 with PaymentAddress

use of com.samourai.wallet.bip47.rpc.PaymentAddress in project samourai-wallet-android by Samourai-Wallet.

the class PayNymDetailsActivity method doSync.

private void doSync() {
    progressBar.setVisibility(View.VISIBLE);
    Disposable disposable = Observable.fromCallable(() -> {
        PaymentCode payment_code = new PaymentCode(pcode);
        int idx = 0;
        boolean loop = true;
        ArrayList<String> addrs = new ArrayList<String>();
        while (loop) {
            addrs.clear();
            for (int i = idx; i < (idx + 20); i++) {
                // Log.i("PayNymDetailsActivity", "sync receive from " + i + ":" + BIP47Util.getInstance(PayNymDetailsActivity.this).getReceivePubKey(payment_code, i));
                BIP47Meta.getInstance().getIdx4AddrLookup().put(BIP47Util.getInstance(this).getReceivePubKey(payment_code, i), i);
                BIP47Meta.getInstance().getPCode4AddrLookup().put(BIP47Util.getInstance(this).getReceivePubKey(payment_code, i), payment_code.toString());
                addrs.add(BIP47Util.getInstance(this).getReceivePubKey(payment_code, i));
            // Log.i("PayNymDetailsActivity", "p2pkh " + i + ":" + BIP47Util.getInstance(PayNymDetailsActivity.this).getReceiveAddress(payment_code, i).getReceiveECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
            }
            String[] s = addrs.toArray(new String[addrs.size()]);
            int nb = APIFactory.getInstance(this).syncBIP47Incoming(s);
            // Log.i("PayNymDetailsActivity", "sync receive idx:" + idx + ", nb == " + nb);
            if (nb == 0) {
                loop = false;
            }
            idx += 20;
        }
        idx = 0;
        loop = true;
        BIP47Meta.getInstance().setOutgoingIdx(pcode, 0);
        while (loop) {
            addrs.clear();
            for (int i = idx; i < (idx + 20); i++) {
                PaymentAddress sendAddress = BIP47Util.getInstance(this).getSendAddress(payment_code, i);
                // Log.i("PayNymDetailsActivity", "sync send to " + i + ":" + sendAddress.getSendECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
                // BIP47Meta.getInstance().setOutgoingIdx(payment_code.toString(), i);
                BIP47Meta.getInstance().getIdx4AddrLookup().put(BIP47Util.getInstance(this).getSendPubKey(payment_code, i), i);
                BIP47Meta.getInstance().getPCode4AddrLookup().put(BIP47Util.getInstance(this).getSendPubKey(payment_code, i), payment_code.toString());
                addrs.add(BIP47Util.getInstance(this).getSendPubKey(payment_code, i));
            }
            String[] s = addrs.toArray(new String[addrs.size()]);
            int nb = APIFactory.getInstance(this).syncBIP47Outgoing(s);
            // Log.i("PayNymDetailsActivity", "sync send idx:" + idx + ", nb == " + nb);
            if (nb == 0) {
                loop = false;
            }
            idx += 20;
        }
        BIP47Meta.getInstance().pruneIncoming();
        PayloadUtil.getInstance(this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(this).getGUID() + AccessFactory.getInstance(this).getPIN()));
        return true;
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(aBoolean -> {
        progressBar.setVisibility(View.INVISIBLE);
        setPayNym();
    }, error -> {
        error.printStackTrace();
        progressBar.setVisibility(View.INVISIBLE);
    });
    disposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) PaymentCode(com.samourai.wallet.bip47.rpc.PaymentCode) CharSequenceX(com.samourai.wallet.util.CharSequenceX) ArrayList(java.util.ArrayList) PaymentAddress(com.samourai.wallet.bip47.rpc.PaymentAddress)

Aggregations

PaymentAddress (com.samourai.wallet.bip47.rpc.PaymentAddress)12 PaymentCode (com.samourai.wallet.bip47.rpc.PaymentCode)11 IOException (java.io.IOException)9 MnemonicException (org.bitcoinj.crypto.MnemonicException)9 JSONException (org.json.JSONException)6 SegwitAddress (com.samourai.wallet.segwit.SegwitAddress)5 ArrayList (java.util.ArrayList)5 ECKey (org.bitcoinj.core.ECKey)5 Intent (android.content.Intent)4 DumpedPrivateKey (org.bitcoinj.core.DumpedPrivateKey)4 WriterException (com.google.zxing.WriterException)3 HD_Address (com.samourai.wallet.hd.HD_Address)3 MyTransactionOutPoint (com.samourai.wallet.send.MyTransactionOutPoint)3 CharSequenceX (com.samourai.wallet.util.CharSequenceX)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ParseException (java.text.ParseException)3 HashMap (java.util.HashMap)3 AddressFormatException (org.bitcoinj.core.AddressFormatException)3 ScriptException (org.bitcoinj.script.ScriptException)3 NotSecp256k1Exception (com.samourai.wallet.bip47.rpc.NotSecp256k1Exception)2