Interface ConsensusFetcher

All Known Subinterfaces:
ConsensusService, ConsensusTool
All Known Implementing Classes:
OmniCoreClient, OmniCoreConsensusTool, OmniwalletAbstractClient, OmniwalletClient, OmniwalletConsensusTool, OmniwalletModernJDKClient

public interface ConsensusFetcher
Interface implemented by all consensus fetching tools. Should really be in the package foundation.omni.consensus, but is here as a workaround to what was once a Groovy joint-compilation issue. TODO: Consolidate with other Consensus-related classes now that joint compilation issue is gone.
  • Method Details

    • currentBlockHeightAsync

      CompletableFuture<Integer> currentBlockHeightAsync()
      Fetch the current block height
      Returns:
      A future for the current block height of the remote consensus server
    • listSmartProperties

      CompletableFuture<List<OmniPropertyInfo>> listSmartProperties()
      Get a list of smart properties asynchronously.
      Returns:
      A future list of property objects
    • getConsensusForCurrency

      default SortedMap<org.bitcoinj.base.Address,BalanceEntry> getConsensusForCurrency(CurrencyID currencyID) throws InterruptedException, ExecutionException
      Fetch a consensus balance-map for a currency.
      Parameters:
      currencyID - The currency to fetch a balance map for
      Returns:
      A map of balances sorted by address
      Throws:
      InterruptedException - if something went wrong
      ExecutionException - if something went wrong
    • getConsensusForCurrencyAsync

      CompletableFuture<SortedMap<org.bitcoinj.base.Address,BalanceEntry>> getConsensusForCurrencyAsync(CurrencyID currencyID)
      Asynchronously get a sorted address-balance map for currency
      Parameters:
      currencyID - the currency.
      Returns:
      a future for the address-balance map.
    • getConsensusSnapshot

      default ConsensusSnapshot getConsensusSnapshot(CurrencyID currencyID) throws InterruptedException, ExecutionException
      Fetch a consensus snapshot for a currencyID
      Parameters:
      currencyID - The currency to get consensus data for
      Returns:
      Consensus data for all addresses owning currencyID
      Throws:
      InterruptedException - if something went wrong
      ExecutionException - if something went wrong
    • getConsensusSnapshotAsync

      default CompletableFuture<ConsensusSnapshot> getConsensusSnapshotAsync(CurrencyID currencyID)
      Get a ConsensusSnapshot asynchronously Checks blockheight before and after and retries up to twice if snapshot has indeterminate blockheight.
      Parameters:
      currencyID - Currency ID for snapshot
      Returns:
      A future for the snapshot
    • completeOrRetryConsensusSnapshot

      default CompletableFuture<ConsensusSnapshot> completeOrRetryConsensusSnapshot(ConsensusSnapshot snapshot, Throwable throwable)
      Handler that will either forward a valid ConsensusSnapshot via CompletableFuture.completedFuture(U) or will start a retry fetch attempt at return a CompletableFuture<ConsensusSnapshot> for the retry. This method is meant to be used in CompletableFuture.handle(java.util.function.BiFunction<? super T, java.lang.Throwable, ? extends U>).
      Parameters:
      snapshot - A candidate ConsensusSnapshot, if not `null` this must be a valid/successful ConsensusSnapshot
      throwable - A throwable that is either ConsensusFetcher.IndeterminateSnapshotException signifying a retry or any other type of Exception which will be forwarded.
      Returns:
      a completed future for a ConsensusSnapshot or a future for a retry attempt at a ConsensusSnapshot
    • attemptConsensusSnapshotAsync

      default CompletableFuture<ConsensusSnapshot> attemptConsensusSnapshotAsync(CurrencyID currencyID, int beforeHeight)
      Asynchronously get a ConsensusSnapshot. If the blockheight after fetching the snapshot hasn't changed from beforeHeight parameter, return the ConsensusSnapshot else return and Exception.

      Compose balance map entries with a currentBlockHeightAsync to produce a candidate ConsensusSnapshot.

      Parameters:
      currencyID - The currency ID to query
      beforeHeight - blockHeight immediately before this attempt
      Returns:
      A future that will return a ConsensusSnapshot (if block doesn't change) or an exception otherwise.
    • createSnapshot

      ConsensusSnapshot createSnapshot(CurrencyID id, int blockHeight, SortedMap<org.bitcoinj.base.Address,BalanceEntry> entries)
      Create a ConsensusSnapshot record. Fills in client-specific information.
      Parameters:
      id - Currency ID
      blockHeight - blockheight
      entries - a map of BalanceEntry objects
      Returns:
      ConsensusSnapshot