All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.polkadot.rpc.provider.IProvider Maven / Gradle / Ivy

The newest version!
package org.polkadot.rpc.provider;

import com.onehilltech.promises.Promise;
import org.polkadot.common.EventEmitter;

import java.util.List;

public interface IProvider {


    @FunctionalInterface
    interface CallbackHandler {

        /**
         * Performs this operation on the given arguments.
         *
         * @param t the first input argument
         * @param u the second input argument
         */
        void callback(T t, U u);
    }


    class SubscriptionHandler {
        CallbackHandler callBack;
        String type;

        public SubscriptionHandler() {
        }

        public SubscriptionHandler(CallbackHandler callBack, String type) {
            this.callBack = callBack;
            this.type = type;
        }

        public CallbackHandler getCallBack() {
            return callBack;
        }

        public void setCallBack(CallbackHandler callBack) {
            this.callBack = callBack;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }
    }


    @FunctionalInterface
    interface ProviderInterfaceEmitCb {
        void handler(Object... value);
    }


    //export type ProviderInterface$Emitted = 'connected' | 'disconnected' | 'error';
    //export type RpcRxInterface$Events = ProviderInterface$Emitted;
    //export type ApiInterface$Events = RpcRxInterface$Events | 'ready';

    enum ProviderInterfaceEmitted implements EventEmitter.EventType {
        // 'connected' | 'disconnected' | 'error';
        ready,
        connected,
        disconnected,
        error
    }

    boolean isHasSubscriptions();

    IProvider clone();

    void disconnect();

    boolean isConnected();

    //TODO 2019-04-26 15:09
    void on(ProviderInterfaceEmitted emitted, EventEmitter.EventListener cb);

    Promise send(String method, List params, SubscriptionHandler subscriptionHandler);

    //TODO 2019-04-26 15:10
    Promise subscribe(String type, String method, List params, CallbackHandler cb);

    //TODO 2019-04-26 15:10
    Promise unsubscribe(String type, String method, int id);
    //readonly hasSubscriptions: boolean;
    //clone (): ProviderInterface;
    //disconnect (): void;
    //isConnected (): boolean;
    //export type ProviderInterface$Emitted = 'connected' | 'disconnected' | 'error';


    //on (type: ProviderInterface$Emitted, sub: ProviderInterface$EmitCb): void;
    //send (method: string, params: Array): Promise;
    //subscribe (type: string, method: string, params: Array, cb: ProviderInterface$Callback): Promise;
    //unsubscribe (type: string, method: string, id: number): Promise;
}