Package foundation.omni.rpc
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.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
Contains the indeterminate snapshot with the *after* blockHeight -
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture
<ConsensusSnapshot> attemptConsensusSnapshotAsync
(CurrencyID currencyID, int beforeHeight) Asynchronously get a ConsensusSnapshot.default CompletableFuture
<ConsensusSnapshot> completeOrRetryConsensusSnapshot
(ConsensusSnapshot snapshot, Throwable throwable) Handler that will either forward a valid ConsensusSnapshot viaCompletableFuture.completedFuture(U)
or will start a retry fetch attempt at return aCompletableFuture<ConsensusSnapshot>
for the retry.createSnapshot
(CurrencyID id, int blockHeight, SortedMap<org.bitcoinj.base.Address, BalanceEntry> entries) Create a ConsensusSnapshot record.Fetch the current block heightdefault SortedMap
<org.bitcoinj.base.Address, BalanceEntry> getConsensusForCurrency
(CurrencyID currencyID) Fetch a consensus balance-map for a currency.CompletableFuture
<SortedMap<org.bitcoinj.base.Address, BalanceEntry>> getConsensusForCurrencyAsync
(CurrencyID currencyID) Asynchronously get a sorted address-balance map for currencydefault ConsensusSnapshot
getConsensusSnapshot
(CurrencyID currencyID) Fetch a consensus snapshot for a currencyIDdefault CompletableFuture
<ConsensusSnapshot> getConsensusSnapshotAsync
(CurrencyID currencyID) Get a ConsensusSnapshot asynchronously Checks blockheight before and after and retries up to twice if snapshot has indeterminate blockheight.Get a list of smart properties asynchronously.
-
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 wrongExecutionException
- 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 wrongExecutionException
- if something went wrong
-
getConsensusSnapshotAsync
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 viaCompletableFuture.completedFuture(U)
or will start a retry fetch attempt at return aCompletableFuture<ConsensusSnapshot>
for the retry. This method is meant to be used inCompletableFuture.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 ConsensusSnapshotthrowable
- A throwable that is eitherConsensusFetcher.IndeterminateSnapshotException
signifying a retry or any other type ofException
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 frombeforeHeight
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 querybeforeHeight
- 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 IDblockHeight
- blockheightentries
- a map of BalanceEntry objects- Returns:
- ConsensusSnapshot
-