net.bither.bitherj.utils.BlockUtil Java Examples

The following examples show how to use net.bither.bitherj.utils.BlockUtil. 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: DownloadSpvRunnable.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    prepare();
    try {
        Block block = BlockUtil.dowloadSpvBlock();
        if (block != null) {
            success(null);
        } else {
            error(0, null);
        }
    } catch (Exception e) {
        error(0, null);
        e.printStackTrace();
    }

}
 
Example #2
Source File: PeerUtil.java    From bither-desktop-java with 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 #3
Source File: DownloadSpvRunnable.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    obtainMessage(HandlerMessage.MSG_PREPARE);
    try {
        Block block = BlockUtil.dowloadSpvBlock();
        if (block != null) {
            obtainMessage(HandlerMessage.MSG_SUCCESS);
        } else {
            obtainMessage(HandlerMessage.MSG_FAILURE);
        }
    } catch (Exception e) {
        obtainMessage(HandlerMessage.MSG_FAILURE);
        e.printStackTrace();
    }

}
 
Example #4
Source File: DownloadSpvRunnable.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    prepare();
    try {
        Block block = BlockUtil.dowloadSpvBlock();
        if (block != null) {
            success(null);
        } else {
            error(0, null);
        }
    } catch (Exception e) {
        error(0, null);
        e.printStackTrace();
    }

}
 
Example #5
Source File: PeerUtil.java    From bither-desktop-java with 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 #6
Source File: BlockchainService.java    From bither-android with Apache License 2.0 5 votes vote down vote up
private synchronized void startPeer() {
    try {
        if (peerCanNotRun) {
            return;
        }
        if (UpgradeUtil.needUpgrade()) {
            return;
        }
        if (!AppSharedPreference.getInstance().getDownloadSpvFinish()) {
            Block block = BlockUtil.dowloadSpvBlock();
            if (block == null) {
                return;
            }
        }
        if (AppSharedPreference.getInstance().getAppMode() != BitherjSettings.AppMode.COLD) {
            if (!AppSharedPreference.getInstance().getBitherjDoneSyncFromSpv()) {
                if (!PeerManager.instance().isConnected()) {
                    PeerManager.instance().start();
                    if (!spvFinishedReceivered) {
                        final IntentFilter intentFilter = new IntentFilter();
                        intentFilter.addAction(NotificationAndroidImpl.ACTION_SYNC_FROM_SPV_FINISHED);
                        spvFinishedReceiver = new SPVFinishedReceiver();
                        registerReceiver(spvFinishedReceiver, intentFilter);
                        spvFinishedReceivered = true;
                    }
                }
            } else {
                if (!AddressManager.getInstance().addressIsSyncComplete()) {
                    TransactionsUtil.getMyTxFromBither();
                }
                startPeerManager();

            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example #7
Source File: BlockChainDownloadSpvApi.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Override
public void setResult(String response) throws Exception {
    JSONObject jsonObject = new JSONObject(response);
    JSONArray jsonArray = jsonObject.getJSONArray("blocks");
    JSONObject jsonObject1 = (JSONObject) jsonArray.get(0);
    this.result = BlockUtil.formatStoreBlockFromBlockChainInfo(jsonObject1);
}
 
Example #8
Source File: BlockChainGetLatestBlockApi.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Override
public void setResult(String response) throws Exception {
    JSONObject jsonObject = new JSONObject(response);
    this.result = BlockUtil.getLatestBlockHeight(jsonObject);
}
 
Example #9
Source File: DownloadSpvApi.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Override
public void setResult(String response) throws Exception {
    JSONObject jsonObject = new JSONObject(response);
    this.result = BlockUtil.formatStoredBlock(jsonObject);
}