Search in sources :

Example 1 with SyncStatus

use of org.fisco.bcos.web3j.protocol.core.methods.response.SyncStatus in project web3sdk by FISCO-BCOS.

the class CnsService method isSynced.

boolean isSynced() throws Exception {
    SyncStatus ethSyncing = web3j.getSyncStatus().send();
    if (ethSyncing.isSyncing()) {
        return false;
    } else {
        BcosBlock block = web3j.getBlockByNumber(DefaultBlockParameterName.LATEST, false).send();
        long timestamp = block.getBlock().getTimestamp().longValueExact() * 1000;
        return System.currentTimeMillis() - syncThreshold < timestamp;
    }
}
Also used : BcosBlock(org.fisco.bcos.web3j.protocol.core.methods.response.BcosBlock) SyncStatus(org.fisco.bcos.web3j.protocol.core.methods.response.SyncStatus)

Aggregations

BcosBlock (org.fisco.bcos.web3j.protocol.core.methods.response.BcosBlock)1 SyncStatus (org.fisco.bcos.web3j.protocol.core.methods.response.SyncStatus)1