Java Code Examples for net.bither.bitherj.BitherjSettings

The following examples show how to use net.bither.bitherj.BitherjSettings. These examples are extracted from open source projects. 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 Project: bither-desktop-java   Source File: PeerUtil.java    License: Apache License 2.0 6 votes vote down vote up
private static synchronized void startPeerInBackground() {
    try {

        if (!peerCanRun) {
            return;
        }
        if (!UserPreference.getInstance().getDownloadSpvFinish()) {
            BlockUtil.dowloadSpvBlock();
        }
        if (UserPreference.getInstance().getAppMode() != BitherjSettings.AppMode.COLD) {
            if (!UserPreference.getInstance().getBitherjDoneSyncFromSpv()) {
                if (!PeerManager.instance().isConnected()) {
                    PeerManager.instance().start();
                }
            } else {
                if (!AddressManager.getInstance().addressIsSyncComplete()) {
                    TransactionsUtil.getMyTxFromBither();
                }
                startPeerManager();

            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source Project: bitherj   Source File: BlockChain.java    License: Apache License 2.0 6 votes vote down vote up
public List<byte[]> getBlockLocatorArray() {
    // append 10 most recent block hashes, descending, then continue appending, doubling the step back each time,
    // finishing with the genesis block (top, -1, -2, -3, -4, -5, -6, -7, -8, -9, -11, -15, -23, -39, -71, -135, ..., 0)
    ArrayList<byte[]> locators = new ArrayList<byte[]>();
    int step = 1, start = 0;
    Block b = this.lastBlock;

    while (b != null && b.getBlockNo() > 0) {
        locators.add(b.getBlockHash());
        if (++start >= 10) step *= 2;

        for (int i = 0; b != null && i < step; i++) {
            b = AbstractDb.blockProvider.getMainChainBlock(b.getBlockPrev());
        }
    }
    locators.add(BitherjSettings.GENESIS_BLOCK_HASH);

    return locators;
}
 
Example 3
Source Project: bither-desktop-java   Source File: BitherTimer.java    License: Apache License 2.0 6 votes vote down vote up
public void startTimer() {
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
        return;
    }
    if (thread == null) {
        thread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (!isStop) {
                    getExchangeTicker();
                    try {
                        Thread.sleep(1 * 60 * 1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        });
        thread.start();
    }
}
 
Example 4
Source Project: bither-desktop-java   Source File: MainFrameUI.java    License: Apache License 2.0 6 votes vote down vote up
public void updateHeader() {
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
        return;
    }
    long finalEstimatedBalance = 0;
    for (Address address : AddressManager.getInstance().getAllAddresses()) {
        finalEstimatedBalance = finalEstimatedBalance + address.getBalance();
    }
    if (AddressManager.getInstance().getHdAccount() != null) {
        finalEstimatedBalance = finalEstimatedBalance + AddressManager.getInstance().getHdAccount().getBalance();
    }
    final long total = finalEstimatedBalance;

    if (EventQueue.isDispatchThread()) {
        updateHeaderOnSwingThread(total);
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                updateHeaderOnSwingThread(total);
            }
        });
    }
}
 
Example 5
Source Project: bither-desktop-java   Source File: MenuBar.java    License: Apache License 2.0 6 votes vote down vote up
public MenuBar() {
    TxNotificationCenter.addTxListener(MenuBar.this);
    panelMain = new JPanel();
    panelMain.setLayout(new BorderLayout());
    panelMain.setOpaque(false);
    panelButton = getPanelButton();
    panelMain.add(panelButton, BorderLayout.EAST);

    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
        panelInfo = getHotPanelInfo();
        panelMain.add(panelInfo, BorderLayout.WEST);
        updateTickerInfo();
        BitherTimer bitherTimer = new BitherTimer(MenuBar.this);
        bitherTimer.startTimer();
    } else {
        panelInfo = getPanelColdInfo();
        panelMain.add(panelInfo, BorderLayout.WEST);
    }

}
 
Example 6
Source Project: bitherj   Source File: TransactionsUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void getMyTxFromBither() throws Exception {
    if (AbstractApp.bitherjSetting.getAppMode() != BitherjSettings.AppMode.HOT) {
        return;
    }
    // TODO: web type
    int flag = AbstractApp.bitherjSetting.getApiConfig().value();
    getTxForAddress(flag);
    if (AddressManager.getInstance().getHDAccountHot() != null) {
        getTxForHDAccount(AddressManager.getInstance().getHDAccountHot().getHdSeedId(), flag);
    }
    if(AddressManager.getInstance().hasHDAccountMonitored()){
        getTxForHDAccountMoitored(AddressManager.getInstance().getHDAccountMonitored().getHdSeedId(), flag);

    }
    if (AddressManager.getInstance().hasDesktopHDMKeychain()) {
        DesktopHDMKeychain desktopHDMKeychain = AddressManager.getInstance().getDesktopHDMKeychains().get(0);
        getTxForDesktopHDM(desktopHDMKeychain, flag);

    }

}
 
Example 7
Source Project: bither-desktop-java   Source File: MenuBar.java    License: Apache License 2.0 6 votes vote down vote up
public MenuBar() {
    TxNotificationCenter.addTxListener(MenuBar.this);
    panelMain = new JPanel();
    panelMain.setLayout(new BorderLayout());
    panelMain.setOpaque(false);
    panelButton = getPanelButton();
    panelMain.add(panelButton, BorderLayout.EAST);

    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
        panelInfo = getHotPanelInfo();
        panelMain.add(panelInfo, BorderLayout.WEST);
        updateTickerInfo();
        BitherTimer bitherTimer = new BitherTimer(MenuBar.this);
        bitherTimer.startTimer();
    } else {
        panelInfo = getPanelColdInfo();
        panelMain.add(panelInfo, BorderLayout.WEST);
    }

}
 
Example 8
Source Project: bither-desktop-java   Source File: HDMSeedPhrasPanel.java    License: Apache License 2.0 6 votes vote down vote up
public HDMSeedPhrasPanel(List<String> worldList) {
    super(MessageKey.HDM_COLD_SEED_WORD_LIST, AwesomeIcon.BITBUCKET);
    worldString = "";
    for (int i = 0; i < worldList.size(); i++) {
        if (i == worldList.size() - 1) {
            worldString += worldList.get(i);
        } else if ((i + 1) % 3 == 0) {
            worldString += worldList.get(i) + "-" + "\n";

        } else {
            worldString += worldList.get(i) + "-";
        }
    }

    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
        updateTitle(LocaliserUtils.getString("hdm_hot_seed_word_list"));
    }


}
 
Example 9
Source Project: bither-android   Source File: OptionHotFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String getOptionName(int index) {
    BitherjSettings.TransactionFeeMode transactionFeeMode = getModeByIndex(index);
    switch (transactionFeeMode) {
        case TwentyX:
            return getString(R.string.setting_name_transaction_fee_20x);
        case TenX:
            return getString(R.string.setting_name_transaction_fee_10x);
        case Higher:
            return getString(R.string.setting_name_transaction_fee_higher);
        case High:
            return getString(R.string.setting_name_transaction_fee_high);
        case Low:
            return getString(R.string.setting_name_transaction_fee_low);
        case Lower:
            return getString(R.string.setting_name_transaction_fee_lower);
        default:
            return getString(R.string.setting_name_transaction_fee_normal);
    }
}
 
Example 10
Source Project: bither-android   Source File: BitherSetting.java    License: Apache License 2.0 6 votes vote down vote up
public static String getMarketName(BitherjSettings.MarketType marketType) {
    String name = "";
    switch (marketType) {
        case BITSTAMP:
            name = BitherApplication.mContext
                    .getString(R.string.market_name_bitstamp);
            break;
        case BITFINEX:
            name = BitherApplication.mContext
                    .getString(R.string.market_name_bitfinex);
            break;
        case COINBASE:
            name = BitherApplication.mContext.getString(R.string.market_name_coinbase);
            break;
        default:
            name = BitherApplication.mContext
                    .getString(R.string.market_name_bitstamp);
            break;
    }
    return name;
}
 
Example 11
Source Project: bither-android   Source File: SendActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void processIntent() {
    isDonate = false;
    Intent intent = getIntent();
    if (intent.hasExtra(SelectAddressToSendActivity.INTENT_EXTRA_ADDRESS)) {
        String address = intent.getExtras().getString(SelectAddressToSendActivity
                .INTENT_EXTRA_ADDRESS);
        if (Utils.validBicoinAddress(address)) {
            if (Utils.compareString(address, BitherjSettings.DONATE_ADDRESS)) {
                isDonate = true;
            }
            etAddress.setText(address);
            long btc = intent.getExtras().getLong(SelectAddressToSendActivity
                    .INTENT_EXTRA_AMOUNT, 0);
            if (btc > 0) {
                amountCalculatorLink.setBtcAmount(btc);
            }
            validateValues();
        }
    }
}
 
Example 12
Source Project: bitherj   Source File: DumpedPrivateKey.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Parses the given private key as created by the "dumpprivkey" Bitcoin C++ RPC.
 *
 * @param encoded The base58 encoded string.
 * @throws net.bither.bitherj.exception.AddressFormatException If the string is invalid or the header byte doesn't match the network params.
 */
public DumpedPrivateKey(String encoded) throws AddressFormatException {
    //todo string encoded
    byte[] tmp = Base58.decodeChecked(encoded);
    version = tmp[0] & 0xFF;
    bytes = new byte[tmp.length - 1];
    System.arraycopy(tmp, 1, bytes, 0, tmp.length - 1);

    if (version != BitherjSettings.dumpedPrivateKeyHeader)
        throw new AddressFormatException("Mismatched version number, trying to cross networks? " + version +
                " vs " + BitherjSettings.dumpedPrivateKeyHeader);
    if (bytes.length == 33 && bytes[32] == 1) {
        compressed = true;
        bytes = Arrays.copyOf(bytes, 32);  // Chop off the additional marker byte.
    } else if (bytes.length == 32) {
        compressed = false;
    } else {
        throw new AddressFormatException("Wrong number of bytes for a private key, not 32 or 33");
    }
}
 
Example 13
Source Project: bither-android   Source File: ChooseModeActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    DialogConfirmTask dialog = new DialogConfirmTask(ChooseModeActivity.this,
            getStyledConfirmString(getString(R.string.choose_mode_cold_confirm)),
            new Runnable() {
                @Override
                public void run() {
                    stopService(new Intent(ChooseModeActivity.this, BlockchainService.class));
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            modeSelected(BitherjSettings.AppMode.COLD);
                            vColdWalletInitCheck.check();
                            ObjectAnimator animator = ObjectAnimator.ofFloat(new ShowHideView(new
                                            View[]{vColdExtra}, new View[]{rlWarm, vWarmBg}), "Progress",
                                    1).setDuration(AnimHideDuration);
                            animator.setInterpolator(new AccelerateDecelerateInterpolator());
                            vColdWalletInitCheck.prepareAnim();
                            animator.addListener(coldClickAnimListener);
                            animator.start();
                        }
                    });
                }
            });
    dialog.show();
}
 
Example 14
Source Project: bither-android   Source File: BlockchainService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    serviceCreatedAt = System.currentTimeMillis();
    log.info(".onCreate()");
    super.onCreate();
    final String lockName = getPackageName() + " blockchain sync";
    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);
    if (AppSharedPreference.getInstance().getAppMode() != BitherjSettings.AppMode.COLD) {
        tickReceiver = new TickReceiver(BlockchainService.this);
        txReceiver = new TxReceiver(BlockchainService.this, tickReceiver);
        receiverConnectivity();
        registerReceiver(tickReceiver, new IntentFilter(
                Intent.ACTION_TIME_TICK));
        registerReceiver(txReceiver, new IntentFilter(NotificationAndroidImpl.ACTION_ADDRESS_BALANCE));
        BroadcastUtil.sendBroadcastStartPeer();
    }
    startMarkTimerTask();
}
 
Example 15
Source Project: bither-desktop-java   Source File: CheckUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static Check initCheckForHDMKeychain(final HDMKeychain keychain, final SecureCharSequence password) {
    String title = LocaliserUtils.getString("hdm_keychain_check_title_cold");
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
        title = LocaliserUtils.getString("hdm_keychain_check_title_hot");
    }
    Check check = new Check(title, new ICheckAction() {
        @Override
        public boolean check() {
            boolean result = false;
            try {
                result = keychain.checkWithPassword(password);
                if (result) {
                    result = keychain.checkSingularBackupWithPassword(password);
                }
                //TODO need to check backup here?
            } catch (Exception e) {
                e.printStackTrace();
            }
            password.wipe();
            return result;
        }
    });
    return check;
}
 
Example 16
Source Project: bither-android   Source File: HdmSendActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void processIntent() {
    isDonate = false;
    Intent intent = getIntent();
    if (intent.hasExtra(SelectAddressToSendActivity.INTENT_EXTRA_ADDRESS)) {
        String address = intent.getExtras().getString(SelectAddressToSendActivity
                .INTENT_EXTRA_ADDRESS);
        if (Utils.validBicoinAddress(address)) {
            if (Utils.compareString(address, BitherjSettings.DONATE_ADDRESS)) {
                isDonate = true;
            }
            etAddress.setText(address);
            long btc = intent.getExtras().getLong(SelectAddressToSendActivity
                    .INTENT_EXTRA_AMOUNT, 0);
            if (btc > 0) {
                amountCalculatorLink.setBtcAmount(btc);
            }
            validateValues();
        }
    }
}
 
Example 17
Source Project: bither-desktop-java   Source File: BitherTimer.java    License: Apache License 2.0 6 votes vote down vote up
public void startTimer() {
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
        return;
    }
    if (thread == null) {
        thread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (!isStop) {
                    getExchangeTicker();
                    try {
                        Thread.sleep(1 * 60 * 1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        });
        thread.start();
    }
}
 
Example 18
Source Project: bither-desktop-java   Source File: LoggingConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
public LoggingConfiguration() {
    if (BitherjSettings.LOG_DEBUG) {
        loggers.put("net.bither", Level.DEBUG);
    } else {
        loggers.put("net.bither", Level.INFO);
    }

}
 
Example 19
Source Project: bither-desktop-java   Source File: BackupUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static ECKey getEckeyFromBackup(String address, CharSequence password) {
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
        return getEckeyFormBackupCold(address, password);
    } else {
        return getEckeyFormBackupHot(address, password);
    }

}
 
Example 20
Source Project: bither-desktop-java   Source File: BackupUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void backupColdKey(boolean checkTime,
                                 BackupListener backupListener) {
    if (UserPreference.getInstance().getAppMode() != BitherjSettings.AppMode.COLD
            ) {
        if (backupListener != null) {
            backupListener.backupError();
        }
        return;
    }

    boolean isBackup = false;
    if (checkTime) {
        Date lastBackupTime = UserPreference.getInstance()
                .getLastBackupkeyTime();
        List<File> files = FileUtil.getBackupFileListOfCold();
        if (lastBackupTime == null
                || ((lastBackupTime.getTime() + ONE_WEEK_TIME) < System
                .currentTimeMillis()) || files.size() == 0) {
            isBackup = true;
        }
    } else {
        isBackup = true;
    }
    if (isBackup) {
        BackupPrivateKeyRunnable backupColdPrivateKeyRunnable = new
                BackupPrivateKeyRunnable(
                backupListener);
        new Thread(backupColdPrivateKeyRunnable).start();

    } else {
        if (backupListener != null) {
            backupListener.backupError();
        }
    }
}
 
Example 21
Source Project: bither-desktop-java   Source File: LogUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void printlnError(String str) {
    if (!BitherjSettings.LOG_DEBUG) {
        return;
    }
    if (Utils.isEmpty(str)) {
        return;
    }
    System.err.println(str);
}
 
Example 22
Source Project: bither-desktop-java   Source File: KeyUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void addAddressListByDesc(List<Address> addressList) {
    PeerUtil.stopPeer();
    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);

        }
    }
    PeerUtil.startPeer();
    if (hasPrivateKey) {
        if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
            BackupUtil.backupColdKey(false);
        } else {
            BackupUtil.backupHotKey();
        }
    }


}
 
Example 23
Source Project: bither-desktop-java   Source File: KeyUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void setHDKeyChain(HDMKeychain keyChain) {
    AddressManager.getInstance().setHDMKeychain(keyChain);
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
        BackupUtil.backupColdKey(false);
    } else {
        BackupUtil.backupHotKey();
    }

}
 
Example 24
Source Project: bither-desktop-java   Source File: KeyUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void setHDAccount(HDAccount hdAccount) {
    AddressManager.getInstance().setHdAccount(hdAccount);
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
        BackupUtil.backupColdKey(false);
    } else {
        BackupUtil.backupHotKey();
    }
}
 
Example 25
Source Project: bither-desktop-java   Source File: BackupUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void backupHotKey() {
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
        BackupPrivateKeyRunnable backupColdPrivateKeyRunnable = new BackupPrivateKeyRunnable(
                null);
        new Thread(backupColdPrivateKeyRunnable).start();
    }
}
 
Example 26
Source Project: bither-android   Source File: AppSharedPreference.java    License: Apache License 2.0 5 votes vote down vote up
public void setAppMode(BitherjSettings.AppMode mode) {
    int index = -1;
    if (mode != null) {
        index = mode.ordinal();
    }
    mPreferences.edit().putInt(APP_MODE, index).commit();
}
 
Example 27
Source Project: bitherj   Source File: AddressManager.java    License: Apache License 2.0 5 votes vote down vote up
public boolean hasHDAccountCold() {
    synchronized (lock) {
        if (AbstractApp.bitherjSetting.getAppMode() == BitherjSettings.AppMode.COLD) {
            List<Integer> seeds = AbstractDb.hdAccountProvider.getHDAccountSeeds();
            for (int seedId : seeds) {
                if (AbstractDb.hdAccountProvider.hasMnemonicSeed(seedId)) {
                    return true;
                }
            }
        }
        return false;
    }
}
 
Example 28
Source Project: bitherj   Source File: GetBlocksMessage.java    License: Apache License 2.0 5 votes vote down vote up
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
    // Version, for some reason.
    Utils.uint32ToByteStreamLE(BitherjSettings.PROTOCOL_VERSION, stream);
    // Then a vector of block hashes. This is actually a "block locator", a set of block
    // identifiers that spans the entire chain with exponentially increasing gaps between
    // them, until we end up at the genesis block. See CBlockLocator::Set()
    stream.write(new VarInt(locator.size()).encode());
    for (byte[] hash : locator) {
        // Have to reverse as wire format is little endian.
        stream.write(hash);
    }
    // Next, a block ID to stop at.
    stream.write(stopHash);
}
 
Example 29
Source Project: bitherj   Source File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static String toP2SHAddress(byte[] pubKeyHash) {
    checkArgument(pubKeyHash.length == 20, "Addresses are 160-bit hashes, " +
            "so you must provide 20 bytes");

    int version = BitherjSettings.p2shHeader;
    checkArgument(version < 256 && version >= 0);

    byte[] addressBytes = new byte[1 + pubKeyHash.length + 4];
    addressBytes[0] = (byte) version;
    System.arraycopy(pubKeyHash, 0, addressBytes, 1, pubKeyHash.length);
    byte[] check = Utils.doubleDigest(addressBytes, 0, pubKeyHash.length + 1);
    System.arraycopy(check, 0, addressBytes, pubKeyHash.length + 1, 4);
    return Base58.encode(addressBytes);
}
 
Example 30
Source Project: bither-desktop-java   Source File: UserPreference.java    License: Apache License 2.0 5 votes vote down vote up
public void setAppMode(BitherjSettings.AppMode mode) {
    int index = -1;
    if (mode != null) {
        index = mode.ordinal();
    }
    setValue(APP_MODE, Integer.toString(index));


}