Class ApiBase<ApplyResult>
- java.lang.Object
-
- org.polkadot.api.ApiBase<ApplyResult>
-
- All Implemented Interfaces:
Types.ApiBaseInterface<ApplyResult>,IApi<ApplyResult>
- Direct Known Subclasses:
ApiPromise,ApiRx
public abstract class ApiBase<ApplyResult> extends java.lang.Object implements Types.ApiBaseInterface<ApplyResult>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classApiBase.ApiTypeprotected static classApiBase.StorageOnCallFunction
-
Field Summary
Fields Modifier and Type Field Description protected Types.DecoratedRpc<ApplyResult>decoratedRpcHashgenesisHashContains the genesis Hash of the attached chain.static intKEEPALIVE_INTERVALprotected Types.ApiOptionsoptionsRpcCorerpcBaseRpcRxrpcRxRuntimeVersionruntimeVersionContains the version information for the current runtime.Types.SignersignerAn external signer which will be used to sign extrinsic when account passed in is not KeyringPair
-
Constructor Summary
Constructors Constructor Description ApiBase(Types.ApiOptions options, ApiBase.ApiType apiType)ApiBase(IProvider provider, ApiBase.ApiType apiType)Create an instance of the class
-
Method Summary
Modifier and Type Method Description protected <ApplyResult>
Types.DecoratedRpc<ApplyResult>decorateRpc(RpcCore rpcCore, Types.OnCallDefinition<ApplyResult> onCall)Types.Derive<ApplyResult>derive()Derived results that are injected into the API, allowing for combinations of various query results.voiddisconnect()Disconnect from the underlying provider, halting all commsprotected voidemit(IProvider.ProviderInterfaceEmitted type, java.lang.Object... args)HashgetGenesisHash()Contains the genesis Hash of the attached chain.RuntimeVersiongetRuntimeVersion()Contains the version information for the current runtime.Types.SignergetSigner()ApiBase.ApiTypegetType()The type of this API instance, either 'rxjs' or 'promise'booleanhasSubscriptions()`true` when subscriptions are supportedEventEmitteron(IProvider.ProviderInterfaceEmitted type, EventEmitter.EventListener handler)Attach an eventemitter handler to listen to a specific eventprotected abstract ApplyResultonCall(Types.OnCallFunction method, java.util.List<java.lang.Object> params, boolean needCallback, IRpcFunction.SubscribeCallback callback)EventEmitteronce(IProvider.ProviderInterfaceEmitted type, EventEmitter.EventListener handler)Attach an one-time eventemitter handler to listen to a specific eventTypes.QueryableStorage<ApplyResult>query()Contains all the chain state modules and their subsequent methods in the API.Types.DecoratedRpc<ApplyResult>rpc()Contains all the raw rpc sections and their subsequent methods in the API as defined by the jsonrpc interface definitions.MetadataruntimeMetadata()Yields the current attached runtime metadata.voidsetSigner(Types.Signer signer)Set an external signer which will be used to sign extrinsic when account passed in is not KeyringPairTypes.SubmittableExtrinsicstx()Contains all the extrinsic modules and their subsequent methods in the API.
-
-
-
Field Detail
-
KEEPALIVE_INTERVAL
public static final int KEEPALIVE_INTERVAL
- See Also:
- Constant Field Values
-
signer
public Types.Signer signer
An external signer which will be used to sign extrinsic when account passed in is not KeyringPair
-
rpcBase
public RpcCore rpcBase
-
rpcRx
public RpcRx rpcRx
-
decoratedRpc
protected Types.DecoratedRpc<ApplyResult> decoratedRpc
-
options
protected Types.ApiOptions options
-
genesisHash
public Hash genesisHash
Contains the genesis Hash of the attached chain. Apart from being useful to determine the actual chain, it can also be used to sign immortal transactions.
-
runtimeVersion
public RuntimeVersion runtimeVersion
Contains the version information for the current runtime.
-
-
Constructor Detail
-
ApiBase
public ApiBase(IProvider provider, ApiBase.ApiType apiType)
Create an instance of the class- Parameters:
provider- the Provider instanceapiType- the type of the API**Example** ```java import org.polkadot.api.ApiBase; ApiBase api = new ApiBase(); api.rpc().subscribeNewHead((header) => { System.out.println("new block "); System.out.println(header.blockNumber); }); ```
-
ApiBase
public ApiBase(Types.ApiOptions options, ApiBase.ApiType apiType)
-
-
Method Detail
-
decorateRpc
protected <ApplyResult> Types.DecoratedRpc<ApplyResult> decorateRpc(RpcCore rpcCore, Types.OnCallDefinition<ApplyResult> onCall)
-
emit
protected void emit(IProvider.ProviderInterfaceEmitted type, java.lang.Object... args)
-
onCall
protected abstract ApplyResult onCall(Types.OnCallFunction method, java.util.List<java.lang.Object> params, boolean needCallback, IRpcFunction.SubscribeCallback callback)
-
derive
public Types.Derive<ApplyResult> derive()
Derived results that are injected into the API, allowing for combinations of various query results.**Example** ```java api.derive.chain.bestNumber((number) => { System.out.print("best number "); System.out.println(number); }); ```
- Specified by:
derivein interfaceIApi<ApplyResult>
-
query
public Types.QueryableStorage<ApplyResult> query()
Contains all the chain state modules and their subsequent methods in the API. These are attached dynamically from the runtime metadata.All calls inside the namespace, is denoted by `section`.`method` and may take an optional query parameter. As an example, `api.query.timestamp.now()` (current block timestamp) does not take parameters, while `api.query.system.accountNonce(
)` (retrieving the associated nonce for an account), takes the `AccountId` as a parameter. **Example**
```java api.query.balances.freeBalance(
, (balance) => { System.out.print("new balance "); System.out.println(balance); }); ``` - Specified by:
queryin interfaceIApi<ApplyResult>
-
rpc
public Types.DecoratedRpc<ApplyResult> rpc()
Contains all the raw rpc sections and their subsequent methods in the API as defined by the jsonrpc interface definitions. Unlike the dynamic `api.query` and `api.tx` sections, these methods are fixed (although extensible with node upgrades) and not determined by the runtime.RPC endpoints available here allow for the query of chain, node and system information, in addition to providing interfaces for the raw queries of state (usine known keys) and the submission of transactions.
**Example** ```java api.rpc.chain.subscribeNewHead((header) => { System.out.print("new header "); System.out.println(header); }); ```
- Specified by:
rpcin interfaceIApi<ApplyResult>
-
tx
public Types.SubmittableExtrinsics tx()
Contains all the extrinsic modules and their subsequent methods in the API. It allows for the construction of transactions and the submission thereof. These are attached dynamically from the runtime metadata.**Example** ```java api.tx.balances .transfer(
, ) .signAndSend( , ({status}) => { System.out.print("tx status "); System.out.println(status.asFinalized.toHex()); }); ``` - Specified by:
txin interfaceIApi<ApplyResult>
-
getType
public ApiBase.ApiType getType()
The type of this API instance, either 'rxjs' or 'promise'- Specified by:
getTypein interfaceTypes.ApiBaseInterface<ApplyResult>
-
on
public EventEmitter on(IProvider.ProviderInterfaceEmitted type, EventEmitter.EventListener handler)
Attach an eventemitter handler to listen to a specific event- Specified by:
onin interfaceTypes.ApiBaseInterface<ApplyResult>- Parameters:
type- The type of event to listen to. Available events are `connected`, `disconnected`, `ready` and `error`handler- The callback to be called when the event fires. Depending on the event type, it could fire with additional arguments. **Example**```java api.on('connected', () => { System.out.println("API has been connected to the endpoint"); }); api.on('disconnected', () => { System.out.println("API has been disconnected from the endpoint"); }); ```
-
once
public EventEmitter once(IProvider.ProviderInterfaceEmitted type, EventEmitter.EventListener handler)
Attach an one-time eventemitter handler to listen to a specific event- Specified by:
oncein interfaceTypes.ApiBaseInterface<ApplyResult>- Parameters:
type- The type of event to listen to. Available events are `connected`, `disconnected`, `ready` and `error`handler- The callback to be called when the event fires. Depending on the event type, it could fire with additional arguments. **Example** ```java api.once('connected', () => { System.out.println("API has been connected to the endpoint"); }); api.once('disconnected', () => { System.out.println("API has been disconnected from the endpoint"); }); ```
-
getGenesisHash
public Hash getGenesisHash()
Contains the genesis Hash of the attached chain. Apart from being useful to determine the actual chain, it can also be used to sign immortal transactions.- Specified by:
getGenesisHashin interfaceIApi<ApplyResult>
-
getRuntimeVersion
public RuntimeVersion getRuntimeVersion()
Contains the version information for the current runtime.- Specified by:
getRuntimeVersionin interfaceIApi<ApplyResult>
-
getSigner
public Types.Signer getSigner()
- Specified by:
getSignerin interfaceIApi<ApplyResult>
-
hasSubscriptions
public boolean hasSubscriptions()
`true` when subscriptions are supported
-
runtimeMetadata
public Metadata runtimeMetadata()
Yields the current attached runtime metadata. Generally this is only used to construct extrinsics & storage, but is useful for current runtime inspection.
-
setSigner
public void setSigner(Types.Signer signer)
Set an external signer which will be used to sign extrinsic when account passed in is not KeyringPair
-
disconnect
public void disconnect()
Disconnect from the underlying provider, halting all comms
-
-