Java Code Examples for net.bither.bitherj.core.AddressManager#getInstance()

The following examples show how to use net.bither.bitherj.core.AddressManager#getInstance() . 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: Bither.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private static void initBitherApplication() {
    ApplicationInstanceManager.txDBHelper = new TxDBHelper(applicationDataDirectoryLocator.getApplicationDataDirectory());
    ApplicationInstanceManager.txDBHelper.initDb();
    ApplicationInstanceManager.addressDBHelper = new AddressDBHelper(applicationDataDirectoryLocator.getApplicationDataDirectory());
    ApplicationInstanceManager.addressDBHelper.initDb();
    if (UserPreference.getInstance().getAppMode() == null) {
        UserPreference.getInstance().setAppMode(BitherjSettings.AppMode.HOT);
    }

    DesktopImplAbstractApp desktopImplAbstractApp = new DesktopImplAbstractApp();
    desktopImplAbstractApp.construct();
    DesktopDbImpl desktopDb = new DesktopDbImpl();
    desktopDb.construct();
    AddressManager.getInstance();
    try {
        MnemonicCode.setInstance(new MnemonicCodeDesktop());
    } catch (IOException e) {
        e.printStackTrace();
    }


}
 
Example 2
Source File: Bither.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private static void initBitherApplication() {
    ApplicationInstanceManager.txDBHelper = new TxDBHelper(applicationDataDirectoryLocator.getApplicationDataDirectory());
    ApplicationInstanceManager.txDBHelper.initDb();
    ApplicationInstanceManager.addressDBHelper = new AddressDBHelper(applicationDataDirectoryLocator.getApplicationDataDirectory());
    ApplicationInstanceManager.addressDBHelper.initDb();
    if (UserPreference.getInstance().getAppMode() == null) {
        UserPreference.getInstance().setAppMode(BitherjSettings.AppMode.HOT);
    }

    DesktopImplAbstractApp desktopImplAbstractApp = new DesktopImplAbstractApp();
    desktopImplAbstractApp.construct();
    DesktopDbImpl desktopDb = new DesktopDbImpl();
    desktopDb.construct();
    AddressManager.getInstance();
    try {
        MnemonicCode.setInstance(new MnemonicCodeDesktop());
    } catch (IOException e) {
        e.printStackTrace();
    }


}
 
Example 3
Source File: OptionHotFragment.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    if (AppSharedPreference.getInstance().isSegwitAddressType()) {
        changeAddressType(false);
        return;
    }
    final AddressManager addressManager = AddressManager.getInstance();
    if (addressManager.hasHDAccountHot()) {
        if (addressManager.hasHDAccountMonitored() && AbstractDb.hdAccountProvider.getSegwitExternalPub(addressManager.getHDAccountMonitored().getHdSeedId()) == null) {
            DialogConfirmTask tip = new DialogConfirmTask(getActivity(), getString(R.string.address_type_switch_hd_account_cold_no_segwit_pub_tips), new Runnable() {
                @Override
                public void run() {
                    ThreadUtil.runOnMainThread(new Runnable() {
                        @Override
                        public void run() {
                            changeAddressType(false);
                        }
                    });
                }
            }, false);
            tip.setCancelable(false);
            tip.show();
        } else {
            if (addressManager.getHDAccountHot().getExternalPub(AbstractHD.PathType.EXTERNAL_BIP49_PATH) == null) {
                changeAddressType(true);
            } else {
                changeAddressType(false);
            }
        }
    } else if (addressManager.hasHDAccountMonitored()) {
        if (AbstractDb.hdAccountProvider.getSegwitExternalPub(addressManager.getHDAccountMonitored().getHdSeedId()) == null) {
            DropdownMessage.showDropdownMessage(getActivity(), getString(R.string.address_type_switch_hd_account_cold_no_segwit_pub_tips));
        } else {
            changeAddressType(false);
        }
    } else {
        DropdownMessage.showDropdownMessage(getActivity(), getString(R.string.open_segwit_only_support_hd_account));
    }
}
 
Example 4
Source File: KeyUtil.java    From bither-android with Apache License 2.0 5 votes vote down vote up
public static void addAddressListByDesc(BlockchainService service, List<Address> addressList) {
    if (service != null) {
        service.stopAndUnregister();
    }
    boolean hasPrivateKey = false;
    AddressManager addressManager = AddressManager.getInstance();
    //need reverse addressList
    Collections.reverse(addressList);
    for (Address address : addressList) {
        if (address.hasPrivKey() && !hasPrivateKey) {
            hasPrivateKey = true;
        }
        if (!addressManager.getPrivKeyAddresses().contains(address) &&
                !addressManager.getWatchOnlyAddresses().contains(address)) {
            addressManager.addAddress(address);

        }
    }
    if (hasPrivateKey) {
        if (AppSharedPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
            BackupUtil.backupColdKey(false);
        } else {
            BackupUtil.backupHotKey();
        }
    }
    if (service != null) {
        service.startAndRegister();
    }

}
 
Example 5
Source File: SplitForkCoinsActivity.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(View view) {
    SplitCoin coin;
    switch (view.getId()) {
        case R.id.ll_split_btn:
            coin = SplitCoin.BTN;
            break;
        case R.id.ll_split_btf:
            coin = SplitCoin.BTF;
            break;
        case R.id.ll_split_btp:
            coin = SplitCoin.BTP;
            break;
        case R.id.ll_split_btg:
            coin = SplitCoin.BTG;
            break;
        case R.id.ll_split_sbtc:
            coin = SplitCoin.SBTC;
            break;
        case R.id.ll_split_btw:
            coin = SplitCoin.BTW;
            break;
        case R.id.ll_split_bcd:
            coin = SplitCoin.BCD;
            break;
        default:
            coin = SplitCoin.BCC;
            break;

    }

    long lastBlockHeight = PeerManager.instance().getLastBlockHeight();
    long forkBlockHeight = coin.getForkBlockHeight();
    if (lastBlockHeight < forkBlockHeight) {
        DropdownMessage.showDropdownMessage(SplitForkCoinsActivity.this, String.format(getString
                (R.string.please_firstly_sync_to_block_no), forkBlockHeight));
    } else {
        AddressManager addressManager = AddressManager.getInstance();
        if (!addressManager.hasHDAccountHot() && !addressManager.hasHDAccountMonitored() &&
                addressManager.getPrivKeyAddresses().size() == 0 && addressManager.getWatchOnlyAddresses().size()
                == 0) {
            DropdownMessage.showDropdownMessage(SplitForkCoinsActivity.this, getString(R.string.no_private_key));
        } else {
            Intent intent = new Intent(SplitForkCoinsActivity.this, SplitBccSelectAddressActivity.class);
            intent.putExtra(SplitCoinKey, coin);
            startActivity(intent);
        }
    }
}