def test_transaction_not_pruned(self): daemon_no_prune = Daemon(JSONRPCDaemon(prune_transactions=False)) responses.add(responses.POST, self.transactions_url, json=self._read('test_transactions_single.json'), status=200) tx = daemon_no_prune.transactions( 'bbc10f5944cc3e88be576d2ab9f4f5ab5a2b46d95a7cab1027bc15c17393102c' )[0] self.assertIsNotNone(tx.blob) self.assertIs(type(tx.blob), bytes)
def get_daemon(): argsparser = argparse.ArgumentParser(description="Display daemon info") argsparser.add_argument('daemon_rpc_url', nargs='?', type=url_data, default='127.0.0.1:18081', help="Daemon RPC URL [host[:port]]") argsparser.add_argument('-t', dest='timeout', type=int, default=30, help="Request timeout") argsparser.add_argument( '-v', dest='verbosity', action='count', default=0, help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG") args = argsparser.parse_args() level = logging.WARNING if args.verbosity == 1: level = logging.INFO elif args.verbosity > 1: level = logging.DEBUG logging.basicConfig(level=level, format="%(asctime)-15s %(message)s") return Daemon(JSONRPCDaemon(timeout=args.timeout, **args.daemon_rpc_url))
def cache_blocks(last=None, end=None): daemon = Daemon(JSONRPCDaemon(host='127.0.0.1', port=18081)) new = [] if not end: end = daemon.height() - 1 if not last: last = int(get_csv("blocks")[-1][1]) while end > last: last += 1 data = daemon.block(height=last) new.append([data.timestamp,data.height,data.difficulty,float(data.reward), \ data.num_txes,float(data.fee),data.size,data.nonce,data.version[0],data.version[1]]) if new: cache(new, "blocks") return True else: return False
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 __init__(self): self.host = settings.DAEMON_HOST self.port = settings.DAEMON_PORT self.username = settings.DAEMON_USER self.password = settings.DAEMON_PASS self.daemon = Daemon( JSONRPCDaemon(host=self.host, port=self.port, user=self.username, password=self.password, timeout=5)) try: status = self.daemon.info()['status'] if status == 'OK': self.connected = True else: self.connected = False except: self.connected = False
class MoneroAdapter(Adapter): chain = Blockchain.MONERO credentials = database.find_credentials(Blockchain.MONERO) wallet = Wallet( JSONRPCWallet(protocol='http', host='127.0.0.1', port=28088)) # wallet = Wallet(JSONRPCWallet(protocol=’http’, host=’127.0.0.1’, port=18088, path=’/json_rpc’, user=”,password=”, timeout=30, verify_ssl_certs=True)) daemon = Daemon(JSONRPCDaemon(port=28081)) address = credentials['address'] key = credentials['key'] # ---STORE--- @classmethod def create_transaction(cls, text): p1 = PaymentID(cls.to_hex(text)) if p1.is_short(): sender = cls.wallet.addresses()[0] sender = sender.with_payment_id(p1) transaction = cls.wallet.transfer(sender, Decimal('0.000000000001')) return transaction @classmethod def get_transaction_count(cls): return len(w.outgoing()) @staticmethod def to_hex(text): s = text.encode('utf-8') return s.hex() @classmethod def send_raw_transaction(cls, transaction): transaction_hash = daemon.send_transaction(transaction) return transaction_hash @classmethod def sign_transaction(cls, transaction): return transaction @staticmethod def add_transaction_to_database(transaction_hash): database.add_transaction(transaction_hash, Blockchain.MONERO) # ---RETRIEVE--- @classmethod def get_transaction(cls, transaction_hash): for item in cls.wallet.outgoing(): if transaction_hash in str(item): return item
def get_daemon(): argsparser = argparse.ArgumentParser(description="Display daemon info") argsparser.add_argument( "daemon_rpc_url", nargs="?", type=url_data, default="127.0.0.1:18081", help="Daemon RPC URL [user[:password]@]host[:port]", ) argsparser.add_argument("-p", dest="proxy_url", nargs="?", type=str, default=None, help="Proxy URL") argsparser.add_argument("-t", dest="timeout", type=int, default=30, help="Request timeout") argsparser.add_argument( "-v", dest="verbosity", action="count", default=0, help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG", ) args = argsparser.parse_args() level = logging.WARNING if args.verbosity == 1: level = logging.INFO elif args.verbosity > 1: level = logging.DEBUG logging.basicConfig(level=level, format="%(asctime)-15s %(message)s") return Daemon( JSONRPCDaemon(timeout=args.timeout, proxy_url=args.proxy_url, **args.daemon_rpc_url))
class JSONRPCDaemonTestCase(JSONTestCase): jsonrpc_url = 'http://127.0.0.1:18081/json_rpc' mempool_url = 'http://127.0.0.1:18081/get_transaction_pool' transactions_url = 'http://127.0.0.1:18081/get_transactions' sendrawtransaction_url = 'http://127.0.0.1:18081/sendrawtransaction' data_subdir = 'test_jsonrpcdaemon' def setUp(self): self.daemon = Daemon(JSONRPCDaemon()) @responses.activate def test_basic_info(self): responses.add(responses.POST, self.jsonrpc_url, json=self._read('test_basic_info-get_info.json'), status=200) responses.add(responses.POST, self.jsonrpc_url, json=self._read('test_basic_info-get_info.json'), status=200) self.assertTrue(self.daemon.info()) self.assertEqual(self.daemon.height(), 294993) @responses.activate def test_net(self): responses.add(responses.POST, self.jsonrpc_url, json=self._read('test_basic_info-get_info.json'), status=200) self.assertEqual(self.daemon.net, NET_STAGE) self.daemon.net self.assertEqual(len(responses.calls), 1, "net value has not been cached?") @responses.activate def test_info_then_net(self): responses.add(responses.POST, self.jsonrpc_url, json=self._read('test_basic_info-get_info.json'), status=200) self.daemon.info() self.assertEqual(self.daemon.net, NET_STAGE) self.assertEqual(len(responses.calls), 1, "net value has not been cached?") @responses.activate def test_mempool(self): responses.add(responses.POST, self.mempool_url, json=self._read('test_mempool-transactions.json'), status=200) txs = self.daemon.mempool() self.assertEqual(len(txs), 2) self.assertEqual(txs[0].confirmations, 0) self.assertEqual(txs[1].confirmations, 0) self.assertGreater(txs[0].fee, 0) self.assertGreater(txs[1].fee, 0) @responses.activate def test_block(self): responses.add( responses.POST, self.jsonrpc_url, json=self._read( "test_block-423cd4d170c53729cf25b4243ea576d1e901d86e26c06d6a7f79815f3fcb9a89.json" ), status=200) responses.add( responses.POST, self.transactions_url, json=self._read( "test_block-423cd4d170c53729cf25b4243ea576d1e901d86e26c06d6a7f79815f3fcb9a89-txns.json" ), status=200) blk = self.daemon.block( "423cd4d170c53729cf25b4243ea576d1e901d86e26c06d6a7f79815f3fcb9a89") self.assertEqual( blk.hash, "423cd4d170c53729cf25b4243ea576d1e901d86e26c06d6a7f79815f3fcb9a89") self.assertEqual(blk.height, 451992) self.assertIsInstance(blk.reward, decimal.Decimal) self.assertIn( "24fb42f9f324082658524b29b4cf946a9f5fcfa82194070e2f17c1875e15d5d0", blk) for tx in blk.transactions: self.assertIn(tx, blk) # tx not in block self.assertNotIn( "e3a3b8361777c8f4f1fd423b86655b5c775de0230b44aa5b82f506135a96c53a", blk) # wrong arg type self.assertRaises(ValueError, lambda txid: txid in blk, 1245) @responses.activate def test_transactions(self): responses.add(responses.POST, self.transactions_url, json=self._read('test_transactions.json'), status=200) txs = self.daemon.transactions([ "050679bd5717cd4c3d0ed1db7dac4aa7e8a222ffc7661b249e5a595a3af37d3c", # @471570 "e3a3b8361777c8f4f1fd423b86655b5c775de0230b44aa5b82f506135a96c53a", # @451993 "e2871c4203e29433257219bc20fa58c68dc12efed8f05a86d59921969a2b97cc", # @472279 "035a1cfadd2f80124998f5af8c7bb6703743a4f322d0a20b7f7b502956ada59d", # mempool "feed00000000000face00000000000bad00000000000beef00000000000acab0", # doesn't exist ]) self.assertEqual(len(txs), 4) self.assertEqual( txs[0].hash, "050679bd5717cd4c3d0ed1db7dac4aa7e8a222ffc7661b249e5a595a3af37d3c") self.assertEqual(txs[0].height, 471570) self.assertEqual(txs[0].size, 2826) self.assertEqual( txs[1].hash, "e3a3b8361777c8f4f1fd423b86655b5c775de0230b44aa5b82f506135a96c53a") self.assertEqual(txs[1].height, 451993) self.assertEqual(txs[1].size, 2596) self.assertEqual( txs[2].hash, "e2871c4203e29433257219bc20fa58c68dc12efed8f05a86d59921969a2b97cc") self.assertEqual(txs[2].height, 472279) self.assertEqual(txs[2].size, 2796) self.assertEqual( txs[3].hash, "035a1cfadd2f80124998f5af8c7bb6703743a4f322d0a20b7f7b502956ada59d") self.assertIsNone(txs[3].height) self.assertEqual(txs[3].size, 2724) @responses.activate def test_send_transaction(self): path = os.path.join( os.path.dirname(__file__), "data", self.data_subdir, "0e8fa9202e0773333360e5b9e8fb8e94272c16a8a58b6fe7cf3b4327158e3a44.tx" ) responses.add(responses.POST, self.sendrawtransaction_url, json=self._read('test_send_transaction.json'), status=200) tx = Transaction(blob=open(path, "rb").read()) rsp = self.daemon.send_transaction(tx) self.assertEqual(rsp["status"], "OK")
dest='relay', action='store_false', help= "Do not relay the transaction (it will stay at the node unless mined or expired)" ) args = argsparser.parse_args() level = logging.WARNING if args.verbosity == 1: level = logging.INFO elif args.verbosity > 1: level = logging.DEBUG logging.basicConfig(level=level, format="%(asctime)-15s %(message)s") if args.tx_filenames: blobs = [(f, open(f, 'r').read()) for f in args.tx_filenames] else: blobs = [('transaction', sys.stdin.read())] d = Daemon(JSONRPCDaemon(**args.daemon_rpc_url)) for name, blob in blobs: logging.debug("Sending {}".format(name)) tx = Transaction(blob=blob) try: res = d.send_transaction(tx, relay=args.relay) except exceptions.TransactionBroadcastError as e: print("{} not sent, reason: {}".format(name, e.details['reason'])) logging.debug(e.details) continue if res['not_relayed']: print("{} not relayed".format(name)) else: print("{} successfully sent".format(name))
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
class JSONRPCDaemonTestCase(JSONTestCase): jsonrpc_url = 'http://127.0.0.1:18081/json_rpc' mempool_url = 'http://127.0.0.1:18081/get_transaction_pool' transactions_url = 'http://127.0.0.1:18081/get_transactions' sendrawtransaction_url = 'http://127.0.0.1:18081/sendrawtransaction' data_subdir = 'test_jsonrpcdaemon' def setUp(self): self.daemon = Daemon(JSONRPCDaemon()) # this is disabled b/c raw_request logs errors logging.getLogger('monero.backends.jsonrpc.daemon').disabled = True @responses.activate def test_basic_info(self): responses.add(responses.POST, self.jsonrpc_url, json=self._read('test_basic_info-get_info.json'), status=200) responses.add(responses.POST, self.jsonrpc_url, json=self._read('test_basic_info-get_info.json'), status=200) self.assertTrue(self.daemon.info()) self.assertEqual(self.daemon.height(), 294993) @responses.activate def test_net(self): responses.add(responses.POST, self.jsonrpc_url, json=self._read('test_basic_info-get_info.json'), status=200) self.assertEqual(self.daemon.net, NET_STAGE) self.daemon.net self.assertEqual(len(responses.calls), 1, "net value has not been cached?") @responses.activate def test_info_then_net(self): responses.add(responses.POST, self.jsonrpc_url, json=self._read('test_basic_info-get_info.json'), status=200) self.daemon.info() self.assertEqual(self.daemon.net, NET_STAGE) self.assertEqual(len(responses.calls), 1, "net value has not been cached?") @responses.activate def test_mempool(self): responses.add(responses.POST, self.mempool_url, json=self._read('test_mempool-transactions.json'), status=200) txs = self.daemon.mempool() self.assertEqual(len(txs), 2) self.assertEqual(txs[0].confirmations, 0) self.assertEqual(txs[1].confirmations, 0) self.assertGreater(txs[0].fee, 0) self.assertGreater(txs[1].fee, 0) @responses.activate def test_block(self): responses.add( responses.POST, self.jsonrpc_url, json=self._read( "test_block-423cd4d170c53729cf25b4243ea576d1e901d86e26c06d6a7f79815f3fcb9a89.json" ), status=200) responses.add( responses.POST, self.transactions_url, json=self._read( "test_block-423cd4d170c53729cf25b4243ea576d1e901d86e26c06d6a7f79815f3fcb9a89-txns.json" ), status=200) blk = self.daemon.block( "423cd4d170c53729cf25b4243ea576d1e901d86e26c06d6a7f79815f3fcb9a89") self.assertEqual( blk.hash, "423cd4d170c53729cf25b4243ea576d1e901d86e26c06d6a7f79815f3fcb9a89") self.assertEqual(blk.height, 451992) self.assertIsInstance(blk.reward, decimal.Decimal) self.assertIn( "24fb42f9f324082658524b29b4cf946a9f5fcfa82194070e2f17c1875e15d5d0", blk) for tx in blk.transactions: self.assertIn(tx, blk) # tx not in block self.assertNotIn( "e3a3b8361777c8f4f1fd423b86655b5c775de0230b44aa5b82f506135a96c53a", blk) # wrong arg type self.assertRaises(ValueError, lambda txid: txid in blk, 1245) # block or hash not specified with self.assertRaises(ValueError): self.daemon.block() @responses.activate def test_transactions(self): responses.add(responses.POST, self.transactions_url, json=self._read('test_transactions_pruned.json'), status=200) txs = self.daemon.transactions([ "050679bd5717cd4c3d0ed1db7dac4aa7e8a222ffc7661b249e5a595a3af37d3c", # @471570 "e3a3b8361777c8f4f1fd423b86655b5c775de0230b44aa5b82f506135a96c53a", # @451993 "e2871c4203e29433257219bc20fa58c68dc12efed8f05a86d59921969a2b97cc", # @472279 "035a1cfadd2f80124998f5af8c7bb6703743a4f322d0a20b7f7b502956ada59d", # mempool "feed00000000000face00000000000bad00000000000beef00000000000acab0", # doesn't exist ]) self.assertEqual(len(txs), 4) self.assertEqual( txs[0].hash, "050679bd5717cd4c3d0ed1db7dac4aa7e8a222ffc7661b249e5a595a3af37d3c") self.assertEqual(txs[0].height, 471570) with self.assertRaises(TransactionWithoutBlob): txs[0].size self.assertEqual(txs[0].fee, decimal.Decimal('0.000331130000')) self.assertIsNone(txs[0].blob) self.assertEqual( txs[1].hash, "e3a3b8361777c8f4f1fd423b86655b5c775de0230b44aa5b82f506135a96c53a") self.assertEqual(txs[1].height, 451993) with self.assertRaises(TransactionWithoutBlob): txs[1].size self.assertEqual(txs[1].fee, decimal.Decimal('0.000265330000')) self.assertIsNone(txs[1].blob) self.assertEqual( txs[2].hash, "e2871c4203e29433257219bc20fa58c68dc12efed8f05a86d59921969a2b97cc") self.assertEqual(txs[2].height, 472279) with self.assertRaises(TransactionWithoutBlob): txs[2].size self.assertEqual(txs[2].fee, decimal.Decimal('0.000327730000')) self.assertIsNone(txs[2].blob) self.assertEqual( txs[3].hash, "035a1cfadd2f80124998f5af8c7bb6703743a4f322d0a20b7f7b502956ada59d") self.assertIsNone(txs[3].height) with self.assertRaises(TransactionWithoutBlob): txs[3].size self.assertEqual(txs[3].fee, decimal.Decimal('0.000320650000')) self.assertIsNone(txs[3].blob) @responses.activate def test_transactions_single(self): responses.add(responses.POST, self.transactions_url, json=self._read('test_transactions_single_pruned.json'), status=200) tx = self.daemon.transactions( 'bbc10f5944cc3e88be576d2ab9f4f5ab5a2b46d95a7cab1027bc15c17393102c' )[0] self.assertEqual(tx.height, 2279770) self.assertIsNone(tx.blob) @responses.activate def test_transaction_not_pruned(self): daemon_no_prune = Daemon(JSONRPCDaemon(prune_transactions=False)) responses.add(responses.POST, self.transactions_url, json=self._read('test_transactions_single.json'), status=200) tx = daemon_no_prune.transactions( 'bbc10f5944cc3e88be576d2ab9f4f5ab5a2b46d95a7cab1027bc15c17393102c' )[0] self.assertIsNotNone(tx.blob) self.assertIs(type(tx.blob), bytes) @responses.activate def test_send_transaction(self): path = os.path.join( os.path.dirname(__file__), "data", self.data_subdir, "0e8fa9202e0773333360e5b9e8fb8e94272c16a8a58b6fe7cf3b4327158e3a44.tx" ) responses.add(responses.POST, self.sendrawtransaction_url, json=self._read('test_send_transaction.json'), status=200) with open(path, "rb") as blob_file: tx = Transaction(blob=blob_file.read()) rsp = self.daemon.send_transaction(tx) self.assertEqual(rsp["status"], "OK") @responses.activate def test_chunking(self): responses.add(responses.POST, self.jsonrpc_url, json=self._read('test_chunking-10-block-693324.json'), status=200) responses.add( responses.POST, self.transactions_url, json=self._read('test_chunking-20-get_transactions_1of2.json'), status=200) responses.add( responses.POST, self.transactions_url, json=self._read('test_chunking-20-get_transactions_2of2.json'), status=200) blk = self.daemon.block(height=693324) self.assertEqual(len(blk.transactions), 105) self.assertEqual(len(set(blk.transactions)), 105) @responses.activate def test_headers(self): responses.add(responses.POST, self.jsonrpc_url, json=self._read('test_headers_2279790_2279799.json'), status=200) headers = self.daemon.headers(2279790, 2279799) self.assertEqual(len(headers), 10) self.assertEqual( headers[0]['hash'], '2763e0b9738c46317602a8e338b6b3ece893be4b9e1c4586824beb4f33286992') self.assertEqual(headers[9]['nonce'], 275623) @responses.activate def test_invalid_param(self): responses.add(responses.POST, self.jsonrpc_url, json=self._read('test_invalid_param.json'), status=200) with self.assertRaises(RPCError): blk = self.daemon.block(height=-1) def test_init_default_backend(self): daemon1 = Daemon(host='localhost') daemon2 = Daemon() with self.assertRaises(ValueError): daemon3 = Daemon(backend=JSONRPCDaemon(), port=18089)
def test_multiple_outputs(self): daemon = Daemon(JSONRPCDaemon(host="127.0.0.1", port=38081)) responses.add(responses.POST, self.wallet_jsonrpc_url, json=self._read( "test_multiple_outputs-wallet-00-get_accounts.json"), status=200) responses.add( responses.POST, self.wallet_jsonrpc_url, json=self._read("test_multiple_outputs-wallet-01-query_key.json"), status=200) responses.add( responses.POST, self.wallet_jsonrpc_url, json=self._read( "test_multiple_outputs-wallet-02-addresses-account-0.json"), status=200) responses.add( responses.POST, self.wallet_jsonrpc_url, json=self._read( "test_multiple_outputs-wallet-02-addresses-account-1.json"), status=200) wallet = Wallet(JSONRPCWallet(host="127.0.0.1", port=38083)) responses.add( responses.POST, self.daemon_transactions_url, json=self._read( "test_multiple_outputs-daemon-00-get_transactions.json"), status=200) tx = daemon.transactions( "f79a10256859058b3961254a35a97a3d4d5d40e080c6275a3f9779acde73ca8d" )[0] outs = tx.outputs(wallet=wallet) self.assertEqual(len(outs), 5) self.assertEqual( outs[0].stealth_address, "d3eb42322566c1d48685ee0d1ad7aed2ba6210291a785ec051d8b13ae797d202") self.assertEqual( outs[1].stealth_address, "5bda44d7953e27b84022399850b59ed87408facdf00bbd1a2d4fda4bf9ebf72f") self.assertEqual( outs[2].stealth_address, "4c79c14d5d78696e72959a28a734ec192059ebabb931040b5a0714c67b507e76") self.assertEqual( outs[3].stealth_address, "64de2b358cdf96d498a9688edafcc0e25c60179e813304747524c876655a8e55") self.assertEqual( outs[4].stealth_address, "966240954892294091a48c599c6db2b028e265c67677ed113d2263a7538f9a43") self.assertIsNotNone(outs[0].payment) self.assertIsNone( outs[1].payment) # FIXME: isn't that change we should recognize? self.assertIsNotNone(outs[2].payment) self.assertIsNotNone(outs[3].payment) self.assertIsNotNone(outs[4].payment) self.assertEqual(outs[0].amount, outs[0].payment.amount) self.assertEqual(outs[2].amount, outs[2].payment.amount) self.assertEqual(outs[3].amount, outs[3].payment.amount) self.assertEqual(outs[4].amount, outs[4].payment.amount) self.assertEqual(outs[0].amount, Decimal(4)) self.assertIsNone(outs[1].amount) self.assertEqual(outs[2].amount, Decimal(1)) self.assertEqual(outs[3].amount, Decimal(2)) self.assertEqual(outs[4].amount, Decimal(8)) self.assertEqual( outs[0].payment.local_address, "76Qt2xMZ3m7b2tagubEgkvG81pwf9P3JYdxR65H2BEv8c79A9pCBTacEFv87tfdcqXRemBsZLFVGHTWbqBpkoBJENBoJJS9" ) self.assertEqual( outs[2].payment.local_address, "78zGgzb45TEL8uvRFjCayUjHS98RFry1f7P4PE4LU7oeLh42s9AtP8fYXVzWqUW4r3Nz4g3V64w9RSiV7o3zUbPZVs5DVaU" ) self.assertEqual( outs[3].payment.local_address, "73ndji4W2bu4WED87rJDVALMvUsZLLYstZsigbcGfb5YG9SuNyCSYk7Qbttez2mXciKtWRzRN9aYGJbF9TPBidNQNZppnFw" ) self.assertEqual( outs[4].payment.local_address, "7BJxHKTa4p5USJ9Z5GY15ZARXL6Qe84qT3FnWkMbSJSoEj9ugGjnpQ1N9H1jqkjsTzLiN5VTbCP8f4MYYVPAcXhr36bHXzP" ) self.assertEqual( repr(outs[0]), "d3eb42322566c1d48685ee0d1ad7aed2ba6210291a785ec051d8b13ae797d202, 4.000000000000 " "to [76Qt2x]")
def test_init_default_backend(self): daemon1 = Daemon(host='localhost') daemon2 = Daemon() with self.assertRaises(ValueError): daemon3 = Daemon(backend=JSONRPCDaemon(), port=18089)
def setUp(self): self.daemon = Daemon(JSONRPCDaemon()) # this is disabled b/c raw_request logs errors logging.getLogger('monero.backends.jsonrpc.daemon').disabled = True
def setUp(self): self.daemon = Daemon(JSONRPCDaemon())
"Do not relay the transaction (it will stay at the node unless mined or expired)" ) args = argsparser.parse_args() level = logging.WARNING if args.verbosity == 1: level = logging.INFO elif args.verbosity > 1: level = logging.DEBUG logging.basicConfig(level=level, format="%(asctime)-15s %(message)s") if args.tx_filenames: blobs = [(f, open(f, 'rb').read()) for f in args.tx_filenames] else: blobs = [('transaction', sys.stdin.buffer.read() if six.PY3 else sys.stdin.read())] d = Daemon( JSONRPCDaemon(timeout=args.timeout, proxy_url=args.proxy_url, **args.daemon_rpc_url)) for name, blob in blobs: logging.debug("Sending {}".format(name)) tx = Transaction(blob=blob) try: res = d.send_transaction(tx, relay=args.relay) except exceptions.TransactionBroadcastError as e: print("{} not sent, reason: {}".format(name, e.details['reason'])) logging.debug(e.details) continue if res['not_relayed']: print("{} not relayed".format(name)) else: print("{} successfully sent".format(name))
help="Request timeout") argsparser.add_argument( "-v", dest="verbosity", action="count", default=0, help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG", ) args = argsparser.parse_args() level = logging.WARNING if args.verbosity == 1: level = logging.INFO elif args.verbosity > 1: level = logging.DEBUG logging.basicConfig(level=level, format="%(asctime)-15s %(message)s") d = Daemon(JSONRPCDaemon(timeout=args.timeout, **args.daemon_rpc_url)) txs = list(d.transactions(args.tx_id)) print("Found {:d} transaction(s)".format(len(txs))) if len(txs) > 0: print("-" * 79) for tx in txs: print("id: {:s}".format(tx.hash)) print("height: {:s}".format( "None" if tx.height is None else "{:d}".format(tx.height))) print("size: {:d}".format(tx.size)) print("JSON:") print(json.dumps(tx.json, indent=2)) print("-" * 79)