def get_address(): wallet = Wallet( JSONRPCWallet( host=settings.RPC_WALLET_HOST, port=settings.RPC_WALLET_PORT, user=settings.RPC_WALLET_USER, password=settings.RPC_WALLET_PASSWORD, timeout=settings.RPC_WALLET_REQUESTS_TIMEOUT, )) return wallet.address()
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