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 int
protected final URI
protected final Map
<CurrencyID, PropertyType> static final int
protected boolean
protected final org.bitcoinj.base.Network
netParams, if non-null, is used for validating addresses during deserializationstatic final URI
static final URI
static final URI
Deprecated.static final int
static final URI
protected 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 WalletAddressBalance
protected 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 AddressBalanceEntry
balanceMapper
(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 asynchronouslyvoid
close()
protected URI
consensusURI
(CurrencyID currencyID) createSnapshot
(CurrencyID id, int blockHeight, SortedMap<org.bitcoinj.base.Address, BalanceEntry> entries) Create a ConsensusSnapshot record.Fetch the current block heightprotected PropertyType
divisibleToPropertyType
(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 SmartPropertyListInfo
protected abstract CompletableFuture
<OmniwalletPropertiesListResponse> abstract CompletableFuture
<RevisionInfo> void
start()
protected OmniDivisibleValue
toOmniDivisibleValue
(String inputStr) protected OmniDivisibleValue
toOmniDivisibleValue
(BigDecimal input) protected OmniIndivisibleValue
toOmniIndivisibleValue
(String input) protected OmniIndivisibleValue
toOmniIndivisibleValue
(BigInteger input) protected OmniValue
toOmniValue
(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, wait
Methods inherited from interface foundation.omni.rpc.ConsensusFetcher
attemptConsensusSnapshotAsync, completeOrRetryConsensusSnapshot, getConsensusSnapshot, getConsensusSnapshotAsync
Methods inherited from interface foundation.omni.netapi.OmniBalanceService
balancesForAddress, balancesForAddresses
Methods 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
currentBlockHeightAsync
Description copied from interface:ConsensusFetcher
Fetch the current block height- Specified by:
currentBlockHeightAsync
in interfaceConsensusFetcher
- Returns:
- A future for the current block height of the remote consensus server
-
revisionInfo
-
propertiesList
-
listSmartProperties
Description copied from interface:ConsensusFetcher
Get a list of smart properties asynchronously.- Specified by:
listSmartProperties
in 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:ConsensusFetcher
Fetch a consensus balance-map for a currency.- Specified by:
getConsensusForCurrency
in 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:
getConsensusForCurrencyAsync
in 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:OmniBalanceService
Get balances for multiple addresses asynchronously- Specified by:
balancesForAddressesAsync
in 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:OmniBalanceService
Get balances for a single addresses asynchronously- Specified by:
balancesForAddressAsync
in interfaceOmniBalanceService
- Parameters:
address
- Single address to query- Returns:
- a future for a map of currency IDs to balances
-
getActiveChainTip
Description copied from interface:OmniBalanceService
Return current ChainTip- Specified by:
getActiveChainTip
in interfaceOmniBalanceService
- Returns:
- "active" ChainTip
-
createSnapshot
public ConsensusSnapshot createSnapshot(CurrencyID id, int blockHeight, SortedMap<org.bitcoinj.base.Address, BalanceEntry> entries) Description copied from interface:ConsensusFetcher
Create a ConsensusSnapshot record. Fills in client-specific information.- Specified by:
createSnapshot
in interfaceConsensusFetcher
- Parameters:
id
- Currency IDblockHeight
- blockheightentries
- a map of BalanceEntry objects- Returns:
- ConsensusSnapshot
-
chainTipPublisher
- Specified by:
chainTipPublisher
in 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 usingCompletableFuture
because 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
-