def setData_MO(self, monero_wallet_address, i, s, threaded=True):
        while (not self.stop_all):
            start = time.time()

            try:
                session = requests_html.HTMLSession()
                page = session.get('https://api.moneroocean.stream/miner/' +
                                   monero_wallet_address + '/stats')
                w = Wallet(JSONRPCWallet(port=28088))
                balance = float(page.json()['amtDue']) / 1000000000000 + float(
                    w.balance())
                self.balance_monero_wallets[i] = balance
                self.names_monero_wallets[i] = "XMR"
                self.values_monero_wallets[i] = self.prices_coinmarketcap[
                    self.names_coinmarketcap.index("XMR")] * balance
            except:
                pass

            if not threaded:
                break
            end = time.time()
            elapsed = (end - start)
            if (elapsed < s):
                time.sleep(s - elapsed)
示例#2
0
class moneroNode(cryptoNode):

    ############################################################################

    def __init__(self, symbol, rpc_address, rpc_daemon, rpc_user, rpc_pass):

        super().__init__(symbol, rpc_address, rpc_user, rpc_pass)

        (host, port) = tuple(rpc_address.split(':'))

        try:

            self.wallet = Wallet(host=host,
                                 port=port,
                                 user=rpc_user,
                                 password=rpc_pass)

        except monero.backends.jsonrpc.exceptions.Unauthorized:

            raise cryptoNodeException(
                'Failed to connect - error in rpcuser or rpcpassword for {} wallet'
                .format(self.symbol))

        except requests.exceptions.ConnectTimeout:

            raise cryptoNodeException(
                'Failed to connect - check that {} wallet is running'.format(
                    self.symbol))

        (host, port) = tuple(rpc_daemon.split(':'))

        try:

            self.daemon = Daemon(host=host, port=port)

        except monero.backends.jsonrpc.exceptions.Unauthorized:

            raise cryptoNodeException(
                'Failed to connect - error in rpcuser or rpcpassword for {} daemon'
                .format(self.symbol))

        except requests.exceptions.ConnectTimeout:

            raise cryptoNodeException(
                'Failed to connect - check that {} daemon is running'.format(
                    self.symbol))

    ############################################################################

    def __getattr__(self, method):

        return getattr(self.proxy, method)

        pass

    ############################################################################

    def initialise(self):

        pass

    ############################################################################

    def refresh(self):

        try:

            self.blocks = self.wallet.height()

        except monero.backends.jsonrpc.exceptions.Unauthorized:

            raise cryptoNodeException(
                'Failed to connect - error in rpcuser or rpcpassword for {} wallet'
                .format(self.symbol))

        except requests.exceptions.ConnectTimeout:

            raise cryptoNodeException(
                'Failed to connect - check that {} wallet is running'.format(
                    self.symbol))

        try:

            info = self.daemon.info()

        except monero.backends.jsonrpc.exceptions.Unauthorized:

            raise cryptoNodeException(
                'Failed to connect - check that {} daemon is running'.format(
                    self.symbol))

        except requests.exceptions.ConnectTimeout:

            raise cryptoNodeException(
                'Failed to connect - check that {} daemon is running'.format(
                    self.symbol))

        self.peers = info['incoming_connections_count'] + info[
            'outgoing_connections_count']

    ############################################################################

    def get_balance(self):

        return self.wallet.balance()

    ############################################################################

    def get_unlocked_balance(self):

        return self.wallet.balance(unlocked=True)

    ############################################################################

    def get_unconfirmed_balance(self):

        amount = 0.0

        transfers = self.wallet._backend.transfers_in(
            0, PaymentFilter(unconfirmed=True, confirmed=False))

        for transfer in transfers:

            amount += float(transfer.amount)

        return amount

    ############################################################################

    def get_new_address(self):

        return str(self.wallet.address())

    ############################################################################

    def wallet_locked(self, cache_prior_state=False):

        # Assume that wallet is unlocked when monero-wallet-rpc is started

        return False

    ############################################################################

    def unlock_wallet(self, passphrase, seconds, staking=False):

        return True

    ############################################################################

    def revert_wallet_lock(self):

        pass

    ############################################################################

    def send_to_address(self, address, amount, comment):

        return self.wallet.transfer(address, float(amount))[0].hash

    ############################################################################

    def shutdown(self):

        pass