Beispiel #1
0
class SteemClient() :
    """ The ``SteemClient`` class is an abstraction layer that makes the use of the
        RPC and the websocket interface easier to use. A part of this
        abstraction layer is to simplyfy the usage of objects and have
        an internal objects map updated to reduce unecessary queries
        (for enabled websocket connections). Advanced developers are of
        course free to use the underlying API classes instead as well.

        :param class config: the configuration class

        If a websocket connection is configured, the websocket subsystem
        can be run by:

        .. code-block:: python

            steem = SteemClient(config)
            steem.run()

    """
    wallet_host = None
    wallet_port = None
    wallet_user = None
    wallet_password = None
    witness_url = None
    witness_user = None
    witness_password = None
    prefix = None

    #: RPC connection to the cli-wallet
    rpc = None
    wallet = None

    #: Websocket connection to the witness/full node
    ws  = None
    node  = None

    def __init__(self, config):
        """ Initialize configuration
        """
        available_features = dir(config)

        if ("wallet_host" in available_features and
                "wallet_port" in available_features):
            self.wallet_host = config.wallet_host
            self.wallet_port = config.wallet_port

            if ("wallet_user" in available_features and
                    "wallet_password" in available_features):
                self.wallet_user = config.wallet_user
                self.wallet_password = config.wallet_password

            self.rpc = SteemWalletRPC(self.wallet_host,
                                      self.wallet_port,
                                      self.wallet_user,
                                      self.wallet_password)

            # Make a reference to 'wallet'
            self.wallet = self.rpc

        # Connect to Witness Node
        if "witness_url" in available_features:
            self.witness_url = config.witness_url

            if ("witness_user" in available_features):
                self.witness_user = config.witness_user

            if ("witness_password" in available_features):
                self.witness_password = config.witness_password

            self.ws = SteemNodeRPC(self.witness_url,
                                   self.witness_user,
                                   self.witness_password)

            # Make a reference to 'node'
            self.node = self.ws

    def getObject(self, oid):
        """ Get an Object either from Websocket store (if available) or
            from RPC connection.
        """
        if self.ws :
            return self.ws.get_object(oid)[0]
        else :
            return self.rpc.get_object(oid)[0]