Class OmniwalletAbstractClient
java.lang.Object
foundation.omni.netapi.omniwallet.OmniwalletAbstractClient
- All Implemented Interfaces:
ConsensusService,OmniBalanceService,RxOmniWalletClient,ConsensusFetcher,Closeable,AutoCloseable,ChainTipService
- Direct Known Subclasses:
OmniwalletClient,OmniwalletModernJDKClient
public abstract class OmniwalletAbstractClient
extends Object
implements ConsensusService, RxOmniWalletClient, Closeable
Base class for Omniwallet Client implementations
TODO: We should probably use composition rather than inheritance and have
a RawOmniwallet interface and inject an implementation of
that into the constructor of an OmniwalletConsensusService type.
-
Nested Class Summary
Nested classes/interfaces inherited from interface foundation.omni.rpc.ConsensusFetcher
ConsensusFetcher.IndeterminateSnapshotException -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprotected final URIprotected final Map<CurrencyID, PropertyType> static final intprotected booleanprotected final org.bitcoinj.base.NetworknetParams, if non-null, is used for validating addresses during deserializationstatic final URIstatic final URIstatic final URIDeprecated.static final intstatic final URIprotected boolean -
Constructor Summary
ConstructorsConstructorDescriptionOmniwalletAbstractClient(URI baseURI, boolean debug, boolean strictMode) OmniwalletAbstractClient(URI baseURI, boolean debug, boolean strictMode, org.bitcoinj.base.Network network) -
Method Summary
Modifier and TypeMethodDescriptionprotected WalletAddressBalanceprotected abstract CompletableFuture<Map<org.bitcoinj.base.Address, OmniwalletAddressBalance>> balanceMapForAddress(org.bitcoinj.base.Address address) protected abstract CompletableFuture<Map<org.bitcoinj.base.Address, OmniwalletAddressBalance>> balanceMapForAddresses(List<org.bitcoinj.base.Address> addresses) protected AddressBalanceEntrybalanceMapper(AddressVerifyInfo item, PropertyType propertyType) balancesForAddressAsync(org.bitcoinj.base.Address address) Get balances for a single addresses asynchronouslybalancesForAddressesAsync(List<org.bitcoinj.base.Address> addresses) Get balances for multiple addresses asynchronouslyvoidclose()protected URIconsensusURI(CurrencyID currencyID) createSnapshot(CurrencyID id, int blockHeight, SortedMap<org.bitcoinj.base.Address, BalanceEntry> entries) Create a ConsensusSnapshot record.Fetch the current block heightprotected PropertyTypedivisibleToPropertyType(boolean divisible) Return current ChainTipSortedMap<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) Get a sorted map of consensus information for a currency.Get a list of smart properties asynchronously.protected CompletableFuture<PropertyType> lookupPropertyType(CurrencyID propertyID) Get the property type for a propertyId.protected SmartPropertyListInfoprotected abstract CompletableFuture<OmniwalletPropertiesListResponse> abstract CompletableFuture<RevisionInfo> voidstart()protected OmniDivisibleValuetoOmniDivisibleValue(String inputStr) protected OmniDivisibleValuetoOmniDivisibleValue(BigDecimal input) protected OmniIndivisibleValuetoOmniIndivisibleValue(String input) protected OmniIndivisibleValuetoOmniIndivisibleValue(BigInteger input) protected OmniValuetoOmniValue(String input, PropertyType type) protected abstract CompletableFuture<List<AddressVerifyInfo>> verifyAddresses(CurrencyID currencyID) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface foundation.omni.rpc.ConsensusFetcher
attemptConsensusSnapshotAsync, completeOrRetryConsensusSnapshot, getConsensusSnapshot, getConsensusSnapshotAsyncMethods inherited from interface foundation.omni.netapi.OmniBalanceService
balancesForAddress, balancesForAddressesMethods inherited from interface foundation.omni.netapi.omniwallet.RxOmniWalletClient
currentChainTipMaybe, pollChainTipOnce
-
Field Details
-
omniwalletBase
Deprecated.This endpoint has an older (and now slightly incompatible) API -
omniwalletApiBase
-
omniExplorerApiBase
-
stagingBase
-
BALANCES_FOR_ADDRESSES_MAX_ADDR
public static final int BALANCES_FOR_ADDRESSES_MAX_ADDR- See Also:
-
CONNECT_TIMEOUT_MILLIS
public static final int CONNECT_TIMEOUT_MILLIS- See Also:
-
READ_TIMEOUT_MILLIS
public static final int READ_TIMEOUT_MILLIS- See Also:
-
baseURI
-
debug
protected boolean debug -
strictMode
protected boolean strictMode -
network
protected final org.bitcoinj.base.Network networknetParams, if non-null, is used for validating addresses during deserialization -
cachedPropertyTypes
-
-
Constructor Details
-
OmniwalletAbstractClient
-
OmniwalletAbstractClient
public OmniwalletAbstractClient(URI baseURI, boolean debug, boolean strictMode, org.bitcoinj.base.Network network)
-
-
Method Details
-
start
public void start() -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
currentBlockHeightAsync
Description copied from interface:ConsensusFetcherFetch the current block height- Specified by:
currentBlockHeightAsyncin interfaceConsensusFetcher- Returns:
- A future for the current block height of the remote consensus server
-
revisionInfo
-
propertiesList
-
listSmartProperties
Description copied from interface:ConsensusFetcherGet a list of smart properties asynchronously.- Specified by:
listSmartPropertiesin interfaceConsensusFetcher- Returns:
- A future list of property objects
-
getConsensusForCurrency
public SortedMap<org.bitcoinj.base.Address,BalanceEntry> getConsensusForCurrency(CurrencyID currencyID) throws InterruptedException, ExecutionException Description copied from interface:ConsensusFetcherFetch a consensus balance-map for a currency.- Specified by:
getConsensusForCurrencyin interfaceConsensusFetcher- 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
public CompletableFuture<SortedMap<org.bitcoinj.base.Address,BalanceEntry>> getConsensusForCurrencyAsync(CurrencyID currencyID) Get a sorted map of consensus information for a currency. Internally we use anCompletableFuture.thenCombine(java.util.concurrent.CompletionStage<? extends U>, java.util.function.BiFunction<? super T, ? super U, ? extends V>)to make an async call tolookupPropertyType(foundation.omni.CurrencyID)which if it doesn't find the property type in the cache may result in a network I/O to get the property list.- Specified by:
getConsensusForCurrencyAsyncin interfaceConsensusFetcher- Parameters:
currencyID- the currency.- Returns:
- A future for a sorted map of address-balance consensus information
-
balancesForAddressesAsync
public CompletableFuture<OmniJBalances> balancesForAddressesAsync(List<org.bitcoinj.base.Address> addresses) Description copied from interface:OmniBalanceServiceGet balances for multiple addresses asynchronously- Specified by:
balancesForAddressesAsyncin interfaceOmniBalanceService- Parameters:
addresses- List of addresses to query- Returns:
- A future, for a map of maps containing each property balance for each address
-
balancesForAddressAsync
public CompletableFuture<WalletAddressBalance> balancesForAddressAsync(org.bitcoinj.base.Address address) Description copied from interface:OmniBalanceServiceGet balances for a single addresses asynchronously- Specified by:
balancesForAddressAsyncin interfaceOmniBalanceService- Parameters:
address- Single address to query- Returns:
- a future for a map of currency IDs to balances
-
getActiveChainTip
Description copied from interface:OmniBalanceServiceReturn current ChainTip- Specified by:
getActiveChainTipin interfaceOmniBalanceService- Returns:
- "active" ChainTip
-
createSnapshot
public ConsensusSnapshot createSnapshot(CurrencyID id, int blockHeight, SortedMap<org.bitcoinj.base.Address, BalanceEntry> entries) Description copied from interface:ConsensusFetcherCreate a ConsensusSnapshot record. Fills in client-specific information.- Specified by:
createSnapshotin interfaceConsensusFetcher- Parameters:
id- Currency IDblockHeight- blockheightentries- a map of BalanceEntry objects- Returns:
- ConsensusSnapshot
-
chainTipPublisher
- Specified by:
chainTipPublisherin interfaceChainTipService
-
balanceMapForAddress
protected abstract CompletableFuture<Map<org.bitcoinj.base.Address,OmniwalletAddressBalance>> balanceMapForAddress(org.bitcoinj.base.Address address) -
balanceMapForAddresses
protected abstract CompletableFuture<Map<org.bitcoinj.base.Address,OmniwalletAddressBalance>> balanceMapForAddresses(List<org.bitcoinj.base.Address> addresses) -
verifyAddresses
protected abstract CompletableFuture<List<AddressVerifyInfo>> verifyAddresses(CurrencyID currencyID) -
balanceMapper
-
mapToSmartPropertyListInfo
-
lookupPropertyType
Get the property type for a propertyId. Is asynchronous usingCompletableFuturebecause if the value isn't in the cache, we'll need to fetch a list of properties from the server. TODO: Should we consider making this method more general and returning OmniPropertyInfo?- Parameters:
propertyID- The propertyId to lookup- Returns:
- The property type.
-
balanceEntryMapper
-
consensusURI
-
toOmniValue
-
toOmniDivisibleValue
-
toOmniDivisibleValue
-
toOmniIndivisibleValue
-
toOmniIndivisibleValue
-
divisibleToPropertyType
-