def on_press_button(self, instance, voter=db.current_voter()): candidate = instance.text address = db.get_address(candidate) try: login = "******" + str( voter[0]) + "--password" + str( voter[1]) + "--rpc-bind-port 28088 --disable-rpc-login" child = pexpect.spawn(login, encoding='utf-8') except: print("error voting") w = Wallet(JSONRPCWallet(port=28088)) #send 1 vote txs = w.transfer(address, Decimal('1.0')) #destroy wallet wallets = db.current_wallets() db = DataBase("./monero/", wallets) print("You voted for " + candidate) sys.exit() return 0
class OfflineTest(unittest.TestCase): addr = "47ewoP19TN7JEEnFKUJHAYhGxkeTRH82sf36giEp9AcNfDBfkAtRLX7A6rZz18bbNHPNV7ex6WYbMN3aKisFRJZ8Ebsmgef" svk = "6d9056aa2c096bfcd2f272759555e5764ba204dd362604a983fa3e0aafd35901" def setUp(self): self.wallet = Wallet(OfflineWallet(self.addr, view_key=self.svk)) def test_offline_exception(self): self.assertRaises(WalletIsOffline, self.wallet.height) self.assertRaises(WalletIsOffline, self.wallet.new_account) self.assertRaises(WalletIsOffline, self.wallet.new_address) self.assertRaises(WalletIsOffline, self.wallet.export_outputs) self.assertRaises(WalletIsOffline, self.wallet.import_outputs, "") self.assertRaises(WalletIsOffline, self.wallet.export_key_images) self.assertRaises(WalletIsOffline, self.wallet.import_key_images, "") self.assertRaises(WalletIsOffline, self.wallet.balances) self.assertRaises(WalletIsOffline, self.wallet.balance) self.assertRaises(WalletIsOffline, self.wallet.incoming) self.assertRaises(WalletIsOffline, self.wallet.outgoing) self.assertRaises(WalletIsOffline, self.wallet.transfer, self.wallet.get_address(1, 0), 1) self.assertRaises( WalletIsOffline, self.wallet.transfer_multiple, [(self.wallet.get_address(1, 0), 1), (self.wallet.get_address(1, 1), 2)], )
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()
def get_balance(details=False): 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.balances()
def transfer(*destinations: Destination): 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.transfer_multiple([dest.to_tuple() for dest in destinations])
def test_get_balance(self, mock_post): mock_post.return_value.status_code = 200 mock_post.return_value.json.return_value = self.get_accounts_result self.wallet = Wallet(JSONRPC()) mock_post.return_value.json.return_value = { 'id': 0, 'jsonrpc': '2.0', 'result': { 'balance': 224916129245183, 'per_subaddress': [{ 'address': '9vgV48wWAPTWik5QSUSoGYicdvvsbSNHrT9Arsx1XBTz6VrWPSgfmnUKSPZDMyX4Ms8R9TkhB4uFqK9s5LUBbV6YQN2Q9ag', 'address_index': 0, 'balance': 189656129245183, 'label': 'Primary account', 'num_unspent_outputs': 2, 'unlocked_balance': 189656129245183 }, { 'address': 'BfJ5W7dZGaYih6J63YvhiDSKpVUUZbVrEhLRCY6L6TdnEfzJmwP6aUJZQQnzLQ2NMTKMAC8hiJsoiNC7jbEUZ8tmBoJcnN1', 'address_index': 5, 'balance': 260000000000, 'label': '(Untitled address)', 'num_unspent_outputs': 1, 'unlocked_balance': 260000000000 }, { 'address': 'BbkS4mn6gcgUidn2znLa2J6eSBkbGjGX4doeDCKAzT2A3t1cjbquQGjhYgiMHiKTrY8ojk6Zjqi1ufvfuPwyKv4hNnMruro', 'address_index': 7, 'balance': 35000000000000, 'label': '(Untitled address)', 'num_unspent_outputs': 5, 'unlocked_balance': 35000000000000 }], 'unlocked_balance': 224916129245183 } } locked = self.wallet.get_balance() unlocked = self.wallet.get_balance(unlocked=True) balances = self.wallet.get_balances() self.assertEqual(balances[0], locked) self.assertEqual(balances[1], unlocked) self.assertIsInstance(locked, Decimal) self.assertIsInstance(unlocked, Decimal) self.assertIsInstance(balances[0], Decimal) self.assertIsInstance(balances[1], Decimal) self.assertEqual(locked, Decimal('224.916129245183'))
def test_coinbase_own_output(self): txdata = self._read("test_coinbase_own_output-dc0861.json") tx = Transaction( hash= "dc08610685b8a55dc7d64454ecbe12868e4e73c766e2d19ee092885a06fc092d", height=518147, json=txdata, ) self.assertTrue(tx.is_coinbase) wallet = Wallet( OfflineWallet( address= "56eDKfprZtQGfB4y6gVLZx5naKVHw6KEKLDoq2WWtLng9ANuBvsw67wfqyhQECoLmjQN4cKAdvMp2WsC5fnw9seKLcCSfjj", view_key= "e507923516f52389eae889b6edc182ada82bb9354fb405abedbe0772a15aea0a", )) outs = tx.outputs(wallet=wallet) self.assertEqual(len(outs), 1) self.assertIsNotNone(outs[0].payment) self.assertEqual( outs[0].payment.local_address, "56eDKfprZtQGfB4y6gVLZx5naKVHw6KEKLDoq2WWtLng9ANuBvsw67wfqyhQECoLmjQN4cKAdvMp2WsC5fnw9seKLcCSfjj", ) self.assertEqual(outs[0].amount, outs[0].payment.amount) self.assertEqual(outs[0].payment.amount, Decimal("13.515927959357"))
def get_wallet(): argsparser = argparse.ArgumentParser(description="Display wallet contents") argsparser.add_argument( 'wallet_rpc_url', nargs='?', type=url_data, default='127.0.0.1:34568', help="Wallet RPC URL [user[:password]@]host[:port]") argsparser.add_argument( '-v', dest='verbosity', action='count', default=0, help="Verbosity (repeat to increase; -v for INFO, -vv for DEBUG") argsparser.add_argument('-t', dest='timeout', type=int, default=30, help="Request timeout") 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 Wallet(JSONRPCWallet(timeout=args.timeout, **args.wallet_rpc_url))
def open_rpc(self, port, wallet_name, password=wallet_password, timeout=timeout, tries=5): if tries == 0: tipper_logger.log( f"WARNING: FAILED to open {wallet_name}'s wallet!!") return self.rpc = RPC(port=port, wallet_name=wallet_name, password=password, load_timeout=timeout) if not os.path.isfile("aborted-" + wallet_name ): # Check if wallet was emergency aborted self.wallet = Wallet( JSONRPCWallet(port=self.rpc.port, password=self.rpc.password, timeout=self.rpc.load_timeout)) else: tipper_logger.log( f"WARNING: {wallet_name} had their RPC aborted!!! Trying {tries} more times" ) os.remove("aborted-" + wallet_name) self.open_rpc(port=port, wallet_name=wallet_name, password=password, timeout=timeout, tries=tries - 1)
def create_pay_address(label=None): wallet = Wallet(JSONRPCWallet(port=WALLET_RPC_PORT, host=WALLET_RPC_HOST)) account = wallet.accounts[ORDER_ACCOUNT_INDEX] address = account.new_address(label=label) return str(address)
def test_1(): InitLoggingSetting() logging.info("trx scanner starting ...") rpc = JSONRPCWalletEx(protocol='http', host='192.168.10.160', port=38089, verify_ssl_certs=False, timeout=60) wallet = Wallet(backend=rpc) print(wallet.view_key()) # watch-only 不能获取, 否则抛异常 # print(wallet.seed()) #如果是观察钱包, 需要导入 key-image 才能确定哪些余额是可用的 print(wallet.balances()) # pprint(rpc.incoming_transfers( account_index=2 )) # # filter = { # 'tx_ids' : None, # 'unconfirmed': None, # 'payment_ids': None, # 'min_height': 0, # 'max_height': None # } # # filter = PaymentFilter( **filter ) # # # filter = object.__dict__.update(filter) # # # ret = wallet._backend.transfers_in(0, filter) res = rpc.get_deposit_txs() #获取子地址 print(wallet.get_address(0, 1)) pass
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))
class SubaddrTest(object): data_subdir = 'test_offline' def setUp(self): self.wallet = Wallet( OfflineWallet(self.addr, view_key=self.svk, spend_key=self.ssk)) def test_keys(self): self.assertEqual(self.wallet.spend_key(), self.ssk) self.assertEqual(self.wallet.view_key(), self.svk) self.assertEqual(25, len(self.wallet.seed().phrase.split(' '))) def test_subaddresses(self): major = 0 for acc in self._read('{}-subaddrs.json'.format(self.net)): minor = 0 for subaddr in acc: self.assertEqual(self.wallet.get_address(major, minor), subaddr, msg='major={}, minor={}'.format(major, minor)) minor += 1 major += 1
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 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)
def __init__(self, wallet_rpc_host='127.0.0.1', port=38089, verify_ssl_certs=False, protocol='http', timeout=30, confirmations=3): self._confirmations = confirmations self._rpc = JSONRPCWalletEx(protocol=protocol, host=wallet_rpc_host, port=port, verify_ssl_certs=verify_ssl_certs, timeout=timeout) self._wallet = Wallet(backend=self._rpc)
def __init__(self): self.host = settings.WALLET_HOST self.port = settings.WALLET_PORT self.username = settings.WALLET_USER self.password = settings.WALLET_PASS try: self.wallet = Wallet( JSONRPCWallet(host=self.host, port=self.port, user=self.username, password=self.password, timeout=5)) if self.wallet: self.connected = True else: self.connected = False except: self.connected = False
def get_wallet(self): rpc_server: JSONRPCWallet = JSONRPCWallet( protocol=self.rpc_protocol, host=self.monero_rpc_config_host, port=self.monero_rpc_config_port, user=self.monero_rpc_config_user, password=self.monero_rpc_config_password, ) try: wallet: Wallet = Wallet(rpc_server) except Unauthorized: raise MoneroPaymentMethodRPCUnauthorized except SSLError: raise MoneroPaymentMethodRPCSSLError except Exception as e: _logger.critical("Monero RPC Error", exc_info=True) raise e return wallet
def test_coinbase_no_own_output(self): txdata = self._read("test_coinbase_no_own_output-26dcb5.json") tx = Transaction( hash= "26dcb55c3c93a2176949fd9ec4e20a9d97ece7c420408d9353c390a909e9a7c1", height=766459, output_indices=txdata["output_indices"], json=json.loads(txdata["as_json"])) self.assertTrue(tx.is_coinbase) wallet = Wallet( OfflineWallet( address= "56eDKfprZtQGfB4y6gVLZx5naKVHw6KEKLDoq2WWtLng9ANuBvsw67wfqyhQECoLmjQN4cKAdvMp2WsC5fnw9seKLcCSfjj", view_key= "e507923516f52389eae889b6edc182ada82bb9354fb405abedbe0772a15aea0a" )) outs = tx.outputs(wallet=wallet) self.assertEqual(len(outs), 1) self.assertIsNone(outs[0].payment) self.assertEqual(outs[0].amount, Decimal("8.415513145431")) self.assertEqual(outs[0].index, 3129279)
class Tests(object): @classproperty def __test__(cls): return issubclass(cls, unittest.TestCase) def setUp(self): self.subaddresses = json.load( open( os.path.join(os.path.dirname(__file__), 'data', '{}-subaddrs.json'.format(self.net)))) self.wallet = Wallet(OfflineWallet(self.addr, view_key=self.svk)) def test_subaddresses(self): major = 0 for acc in self.subaddresses: minor = 0 for subaddr in acc: self.assertEqual(self.wallet.get_address(major, minor), subaddr, msg='major={}, minor={}'.format(major, minor)) minor += 1 major += 1
def source(): myConfig = RPCconfig.configure() try: jsonRPC = JSONRPCWallet(myConfig.get_protocol(), myConfig.get_host(), myConfig.get_port(), myConfig.get_path(), myConfig.get_user(), myConfig.get_password()) except Exception as inst: print(type(inst)) print(inst.args) print(inst) try: mywallet = Wallet(jsonRPC) return mywallet except ConnectionError as e: myRpc = '{protocol}://{host}:{port}{path}'.format( protocol=myConfig.get_protocol(), host=myConfig.get_host(), port=myConfig.get_port(), path=myConfig.get_path()) print('Trouble connecting to Monero RPC at: ' + myRpc) return e
class SubaddrWalletTestCase(unittest.TestCase): get_accounts_result = { 'id': 0, 'jsonrpc': '2.0', 'result': { 'subaddress_accounts': [{ 'account_index': 0, 'balance': 224916129245183, 'base_address': '9vgV48wWAPTWik5QSUSoGYicdvvsbSNHrT9Arsx1XBTz6VrWPSgfmnUKSPZDMyX4Ms8R9TkhB4uFqK9s5LUBbV6YQN2Q9ag', 'label': 'Primary account', 'unlocked_balance': 224916129245183 }, { 'account_index': 1, 'balance': 3981420960933, 'base_address': 'BaCBwYSK9BGSuKxb2msXEj4mmpvZYJexYHfqx7kNPDrXDePVXSfoofxGquhXxpA4uxawcnVnouusMDgP74CACa7e9siimpj', 'label': 'Untitled account', 'unlocked_balance': 3981420960933 }, { 'account_index': 2, 'balance': 7256159239955, 'base_address': 'BgCseuY3jFJAZS7kt9mrNg7fEG3bo5BV91CTyKbYu9GFiU6hUZhvdNWCTUdQNPNcA4PyFApsFr3EsQDEDfT3tQSY1mVZeP2', 'label': 'Untitled account', 'unlocked_balance': 7256159239955 }], 'total_balance': 236153709446071, 'total_unlocked_balance': 236153709446071 } } @patch('monero.backends.jsonrpc.requests.post') def test_get_balance(self, mock_post): mock_post.return_value.status_code = 200 mock_post.return_value.json.return_value = self.get_accounts_result self.wallet = Wallet(JSONRPC()) mock_post.return_value.json.return_value = { 'id': 0, 'jsonrpc': '2.0', 'result': { 'balance': 224916129245183, 'per_subaddress': [{ 'address': '9vgV48wWAPTWik5QSUSoGYicdvvsbSNHrT9Arsx1XBTz6VrWPSgfmnUKSPZDMyX4Ms8R9TkhB4uFqK9s5LUBbV6YQN2Q9ag', 'address_index': 0, 'balance': 189656129245183, 'label': 'Primary account', 'num_unspent_outputs': 2, 'unlocked_balance': 189656129245183 }, { 'address': 'BfJ5W7dZGaYih6J63YvhiDSKpVUUZbVrEhLRCY6L6TdnEfzJmwP6aUJZQQnzLQ2NMTKMAC8hiJsoiNC7jbEUZ8tmBoJcnN1', 'address_index': 5, 'balance': 260000000000, 'label': '(Untitled address)', 'num_unspent_outputs': 1, 'unlocked_balance': 260000000000 }, { 'address': 'BbkS4mn6gcgUidn2znLa2J6eSBkbGjGX4doeDCKAzT2A3t1cjbquQGjhYgiMHiKTrY8ojk6Zjqi1ufvfuPwyKv4hNnMruro', 'address_index': 7, 'balance': 35000000000000, 'label': '(Untitled address)', 'num_unspent_outputs': 5, 'unlocked_balance': 35000000000000 }], 'unlocked_balance': 224916129245183 } } locked = self.wallet.get_balance() unlocked = self.wallet.get_balance(unlocked=True) balances = self.wallet.get_balances() self.assertEqual(balances[0], locked) self.assertEqual(balances[1], unlocked) self.assertIsInstance(locked, Decimal) self.assertIsInstance(unlocked, Decimal) self.assertIsInstance(balances[0], Decimal) self.assertIsInstance(balances[1], Decimal) self.assertEqual(locked, Decimal('224.916129245183')) @patch('monero.backends.jsonrpc.requests.post') def test_get_address(self, mock_post): mock_post.return_value.status_code = 200 mock_post.return_value.json.return_value = self.get_accounts_result self.wallet = Wallet(JSONRPC()) mock_post.return_value.json.return_value = { 'id': 0, 'jsonrpc': '2.0', 'result': { 'address': '9vgV48wWAPTWik5QSUSoGYicdvvsbSNHrT9Arsx1XBTz6VrWPSgfmnUKSPZDMyX4Ms8R9TkhB4uFqK9s5LUBbV6YQN2Q9ag', 'addresses': [{ 'address': '9vgV48wWAPTWik5QSUSoGYicdvvsbSNHrT9Arsx1XBTz6VrWPSgfmnUKSPZDMyX4Ms8R9TkhB4uFqK9s5LUBbV6YQN2Q9ag', 'address_index': 0, 'label': 'Primary account', 'used': True }, { 'address': 'BbBjyYoYNNwFfL8RRVRTMiZUofBLpjRxdNnd5E4LyGcAK5CEsnL3gmE5QkrDRta7RPficGHcFdR6rUwWcjnwZVvCE3tLxhJ', 'address_index': 1, 'label': '', 'used': True }, { 'address': 'BgzZVoJP6Vx5WP87r7NRCCRcFwiUha8uTgnjGGitHYTJEmRuz6Jq2oE9icDCGYMHXZcnR8T35Z8NoVXkfMnF9ikJNfcwwsy', 'address_index': 2, 'label': '(Untitled address)', 'used': False }, { 'address': 'Bck7sYz1vvUghNNTR6rrpxfRDegswezggB9mWQkXgjwxKRTo1feiJopStdJAHtMJoSEdsYppWvQ6vbGbArWxP32xCG2TsVZ', 'address_index': 3, 'label': '(Untitled address)', 'used': True }, { 'address': 'BYCcWM1gZHdCnh3Cb1KfWrAU1SjBWMV3KhUoeRy7V2Lw2F2hHeuzouP2NECBaTUgnyYAzEe8s5vpA7qmWYfjVfxeHoHWPnb', 'address_index': 4, 'label': '(Untitled address)', 'used': False }, { 'address': 'BfJ5W7dZGaYih6J63YvhiDSKpVUUZbVrEhLRCY6L6TdnEfzJmwP6aUJZQQnzLQ2NMTKMAC8hiJsoiNC7jbEUZ8tmBoJcnN1', 'address_index': 5, 'label': '(Untitled address)', 'used': True }, { 'address': 'BaJwiPYwnN6DV8yBeh4FjjCqRoPfdkWppSzVXTPBJo35fDyU8caxLchATGJg7TKB24Q8nM8P1iWSt4DMwec8Pg7bSbFDAir', 'address_index': 6, 'label': '(Untitled address)', 'used': False }, { 'address': 'BbkS4mn6gcgUidn2znLa2J6eSBkbGjGX4doeDCKAzT2A3t1cjbquQGjhYgiMHiKTrY8ojk6Zjqi1ufvfuPwyKv4hNnMruro', 'address_index': 7, 'label': '(Untitled address)', 'used': True }] } } waddr = self.wallet.get_address() a0addr = self.wallet.accounts[0].get_address() self.assertEqual(waddr, a0addr) self.assertEqual( waddr, '9vgV48wWAPTWik5QSUSoGYicdvvsbSNHrT9Arsx1XBTz6VrWPSgfmnUKSPZDMyX4Ms8R9TkhB4uFqK9s5LUBbV6YQN2Q9ag' ) self.assertEqual(len(self.wallet.accounts[0].get_addresses()), 8) @patch('monero.backends.jsonrpc.requests.post') def test_get_payments_in(self, mock_post): mock_post.return_value.status_code = 200 mock_post.return_value.json.return_value = self.get_accounts_result self.wallet = Wallet(JSONRPC()) mock_post.return_value.status_code = 200 mock_post.return_value.json.return_value = { 'id': 0, 'jsonrpc': '2.0', 'result': { 'in': [{ 'amount': 2470000000000, 'double_spend_seen': False, 'fee': 0, 'height': 1049947, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 0, 'minor': 0 }, 'timestamp': 1511926250, 'txid': '0cdde0eb934c44b523f6e966a5e19b131ed68c3c08600bc087f48ae13015b704', 'type': 'in', 'unlock_time': 0 }, { 'amount': 6123000000000, 'double_spend_seen': False, 'fee': 0, 'height': 1049947, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 0, 'minor': 0 }, 'timestamp': 1511926250, 'txid': '8b4154681c48a873550818ecaa6408a7c987a882b80917d6c902befd6ee57109', 'type': 'in', 'unlock_time': 0 }, { 'amount': 9767000000000, 'double_spend_seen': False, 'fee': 0, 'height': 1049947, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 0, 'minor': 0 }, 'timestamp': 1511926250, 'txid': 'd23a7d086e70df7aa0ca002361c4b35e35a272345b0a513ece4f21b773941f5e', 'type': 'in', 'unlock_time': 0 }] } } pay_in = self.wallet.get_payments_in() self.assertEqual(len(list(pay_in)), 3) for payment in pay_in: self.assertIsInstance(payment['amount'], Decimal) self.assertIsInstance(payment['fee'], Decimal) @patch('monero.backends.jsonrpc.requests.post') def test_get_payments_out(self, mock_post): mock_post.return_value.status_code = 200 mock_post.return_value.json.return_value = self.get_accounts_result self.wallet = Wallet(JSONRPC()) mock_post.return_value.status_code = 200 mock_post.return_value.json.return_value = { 'id': 0, 'jsonrpc': '2.0', 'result': { 'out': [{ 'amount': 484257334653, 'destinations': [{ 'address': 'BeUtm39sgTWfehPwwdrWWCAyUVfRQ512TTU5R1cm4SVmPVFxcqDz2zo5YGiyHtdav2RnDFdNvVnTANgsKtYTqo7kUCPvkqK', 'amount': 484257334653 }], 'double_spend_seen': False, 'fee': 19254480000, 'height': 1051266, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 2, 'minor': 0 }, 'timestamp': 1512095241, 'txid': 'eadca0f956a2a60cb3497a7dff1bd80153140a111d2f7db257a264bd9b76f0b3', 'type': 'out', 'unlock_time': 0 }, { 'amount': 791221885761, 'destinations': [{ 'address': 'Bd2RQrySgNaBghRZimDu54iTeJPQFZqPKc36Mb8gWiiU3ripWBv7zZZYkGDBCd5uC1efzh88V3PhyeRhMEYiMSLPN2KLFAj', 'amount': 791221885761 }], 'double_spend_seen': False, 'fee': 19304320000, 'height': 1049917, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 2, 'minor': 0 }, 'timestamp': 1511922110, 'txid': '5486ae9e6867ceb6e5aa478b32cba5c11d28e6d905c8479565c78e3933163ab6', 'type': 'out', 'unlock_time': 0 }, { 'amount': 98047029154, 'destinations': [{ 'address': '9xJAXRqfKJVgFcqAQPk6bThkjAhAdJ18tSTcpfpiSD634t74RqhzC3kAtHMNbScqkJCDhnvv5iCeuATuNS3r5y51RktPsoZ', 'amount': 98047029154 }], 'double_spend_seen': False, 'fee': 19253920000, 'height': 1051282, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 2, 'minor': 0 }, 'timestamp': 1512098498, 'txid': '9591c8f6832cc3b7908c2447b2feef58c44e7774a5c05cea617ad2f3b3866c18', 'type': 'out', 'unlock_time': 0 }, { 'amount': 536269959084, 'destinations': [{ 'address': 'Bfiu2Zm5uoV8RkjGJVWtp2Wkzct15mdKcdM6P6CZsLkPfttjPqvXWR2GkdkG2ai91KNvyro8zKygygMcTf6feyUA8nJmyNT', 'amount': 536269959084 }], 'double_spend_seen': False, 'fee': 19303200000, 'height': 1049947, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 2, 'minor': 0 }, 'timestamp': 1511926250, 'txid': 'af669b99162d9b514a0e8d3bd1d905e3b8778e6fcb88d172e5e049e909c4cc87', 'type': 'out', 'unlock_time': 0 }, { 'amount': 179693868346, 'destinations': [{ 'address': '9wFuzNoQDck1pnS9ZhG47kDdLD1BUszSbWpGfWcSRy9m6Npq9NoHWd141KvGag8hu2gajEwzRXJ4iJwmxruv9ofc2CwnYCE', 'amount': 179693868346 }], 'double_spend_seen': False, 'fee': 17927000000, 'height': 1049870, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 2, 'minor': 0 }, 'timestamp': 1511914391, 'txid': '2fa2de7fbf009093c5319d0421d3e8c684b8351a066c48d51369aedbbfd1d9af', 'type': 'out', 'unlock_time': 0 }, { 'amount': 540005123047, 'destinations': [{ 'address': 'BYo9Bf1FXxBdM655QkQsxs25HZ78EehDmJWZfLAts8LFcym4k8LbEywJcWnoCBHVXQb5ZJ6JXrF2MFtNrVnswGXsAxWNBgh', 'amount': 540005123047 }], 'double_spend_seen': False, 'fee': 19302640000, 'height': 1049963, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 2, 'minor': 0 }, 'timestamp': 1511928624, 'txid': '7e3db6c59c02d870f18b37a37cfc5857eeb5412df4ea00bb1971f3095f72b0d8', 'type': 'out', 'unlock_time': 0 }] } } pay_out = self.wallet.get_payments_out() self.assertEqual(len(list(pay_out)), 6) for payment in pay_out: self.assertIsInstance(payment['amount'], Decimal) self.assertIsInstance(payment['fee'], Decimal) self.assertIsInstance(payment['timestamp'], datetime)
class FiltersTestCase(unittest.TestCase): def setUp(self): class MockBackend(object): def __init__(self): self.transfers = [] tx = Transaction( timestamp=datetime(2018, 1, 29, 15, 0, 25), height=1087606, hash= 'a0b876ebcf7c1d499712d84cedec836f9d50b608bb22d6cb49fd2feae3ffed14', fee=Decimal('0.00352891')) pm = IncomingPayment( amount=Decimal('1'), local_address=address( 'Bf6ngv7q2TBWup13nEm9AjZ36gLE6i4QCaZ7XScZUKDUeGbYEHmPRdegKGwLT8tBBK7P6L32RELNzCR6QzNFkmogDjvypyV' ), payment_id=PaymentID( '0166d8da6c0045c51273dd65d6f63734beb8a84e0545a185b2cfd053fced9f5d' ), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 14, 57, 47), height=1087601, hash= 'f34b495cec77822a70f829ec8a5a7f1e727128d62e6b1438e9cb7799654d610e', fee=Decimal('0.008661870000')) pm = IncomingPayment( amount=Decimal('3.000000000000'), local_address=address( 'BhE3cQvB7VF2uuXcpXp28Wbadez6GgjypdRS1F1Mzqn8Advd6q8VfaX8ZoEDobjejrMfpHeNXoX8MjY8q8prW1PEALgr1En' ), payment_id=PaymentID('f75ad90e25d71a12'), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 13, 17, 18), height=1087530, hash= '5c3ab739346e9d98d38dc7b8d36a4b7b1e4b6a16276946485a69797dbf887cd8', fee=Decimal('0.000962550000')) pm = IncomingPayment( amount=Decimal('10.000000000000'), local_address=address( '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC' ), payment_id=PaymentID('f75ad90e25d71a12'), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 13, 17, 18), height=1087530, hash= '4ea70add5d0c7db33557551b15cd174972fcfc73bf0f6a6b47b7837564b708d3', fee=Decimal('0.000962550000')) pm = IncomingPayment( amount=Decimal('4.000000000000'), local_address=address( '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC' ), payment_id=PaymentID('f75ad90e25d71a12'), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 13, 17, 18), height=1087530, hash= 'e9a71c01875bec20812f71d155bfabf42024fde3ec82475562b817dcc8cbf8dc', fee=Decimal('0.000962550000')) pm = IncomingPayment( amount=Decimal('2.120000000000'), local_address=address( '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC' ), payment_id=PaymentID('cb248105ea6a9189'), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 14, 57, 47), height=1087601, hash= '5ef7ead6a041101ed326568fbb59c128403cba46076c3f353cd110d969dac808', fee=Decimal('0.000962430000')) pm = IncomingPayment( amount=Decimal('7.000000000000'), local_address=address( 'BhE3cQvB7VF2uuXcpXp28Wbadez6GgjypdRS1F1Mzqn8Advd6q8VfaX8ZoEDobjejrMfpHeNXoX8MjY8q8prW1PEALgr1En' ), payment_id=PaymentID('0000000000000000'), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 13, 17, 18), height=1087530, hash= 'cc44568337a186c2e1ccc080b43b4ae9db26a07b7afd7edeed60ce2fc4a6477f', fee=Decimal('0.000962550000')) pm = IncomingPayment( amount=Decimal('10.000000000000'), local_address=address( '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC' ), payment_id=PaymentID('0000000000000000'), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 21, 13, 28), height=None, hash= 'd29264ad317e8fdb55ea04484c00420430c35be7b3fe6dd663f99aebf41a786c', fee=Decimal('0.000961950000')) pm = IncomingPayment( amount=Decimal('3.140000000000'), local_address=address( '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC' ), payment_id=PaymentID('03f6649304ea4cb2'), transaction=tx) self.transfers.append(pm) def height(self): return 1087607 def accounts(self): return [Account(self, 0)] def transfers_in(self, account, pmtfilter): return list(pmtfilter.filter(self.transfers)) self.wallet = Wallet(MockBackend()) def test_filter_none(self): pmts = self.wallet.incoming() self.assertEqual(len(pmts), 7) def test_filter_payment_id(self): pmts = self.wallet.incoming(payment_id='cb248105ea6a9189') self.assertEqual(len(pmts), 1) self.assertEqual( pmts[0].transaction.hash, 'e9a71c01875bec20812f71d155bfabf42024fde3ec82475562b817dcc8cbf8dc') pmts = self.wallet.incoming(payment_id='f75ad90e25d71a12') self.assertEqual(len(pmts), 3) pmts = self.wallet.incoming(payment_id=('cb248105ea6a9189', 'f75ad90e25d71a12')) self.assertEqual(len(pmts), 4) self.assertEqual( pmts, self.wallet.incoming(payment_id=(PaymentID('cb248105ea6a9189'), 'f75ad90e25d71a12'))) def test_filter_address(self): pmts = self.wallet.incoming( local_address= 'BhE3cQvB7VF2uuXcpXp28Wbadez6GgjypdRS1F1Mzqn8Advd6q8VfaX8ZoEDobjejrMfpHeNXoX8MjY8q8prW1PEALgr1En' ) self.assertEqual(len(pmts), 2) self.assertEqual( pmts, self.wallet.incoming(local_address=address( 'BhE3cQvB7VF2uuXcpXp28Wbadez6GgjypdRS1F1Mzqn8Advd6q8VfaX8ZoEDobjejrMfpHeNXoX8MjY8q8prW1PEALgr1En' ))) pmts = self.wallet.incoming(local_address=( 'BhE3cQvB7VF2uuXcpXp28Wbadez6GgjypdRS1F1Mzqn8Advd6q8VfaX8ZoEDobjejrMfpHeNXoX8MjY8q8prW1PEALgr1En', 'Bf6ngv7q2TBWup13nEm9AjZ36gLE6i4QCaZ7XScZUKDUeGbYEHmPRdegKGwLT8tBBK7P6L32RELNzCR6QzNFkmogDjvypyV' )) self.assertEqual(len(pmts), 3) def test_filter_mempool(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') pmts = self.wallet.incoming() self.assertEqual(len(pmts), 7) for p in pmts: self.assertGreater(self.wallet.confirmations(p.transaction), 0) pmts = self.wallet.incoming(unconfirmed=True) self.assertEqual(len(pmts), 8) pmts = self.wallet.incoming(unconfirmed=True, confirmed=False) self.assertEqual(len(pmts), 1) self.assertEqual( pmts[0].transaction.hash, 'd29264ad317e8fdb55ea04484c00420430c35be7b3fe6dd663f99aebf41a786c' ) self.assertEqual(self.wallet.confirmations(pmts[0]), 0) self.assertEqual(self.wallet.confirmations(pmts[0].transaction), 0) self.assertEqual(len(w), 0) pmts = self.wallet.incoming(unconfirmed=True, confirmed=False, min_height=1) self.assertEqual(len(pmts), 0) self.assertEqual(len(w), 1) self.assertIs(w[0].category, RuntimeWarning) pmts = self.wallet.incoming(unconfirmed=True, confirmed=False, max_height=99999999999999) self.assertEqual(len(pmts), 0) self.assertEqual(len(w), 2) self.assertIs(w[1].category, RuntimeWarning) pmts = self.wallet.incoming(payment_id='03f6649304ea4cb2') self.assertEqual(len(pmts), 0) pmts = self.wallet.incoming(unconfirmed=True, payment_id='03f6649304ea4cb2') self.assertEqual(len(pmts), 1) pmts = self.wallet.incoming( local_address= '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC' ) self.assertEqual(len(pmts), 4) pmts = self.wallet.incoming( unconfirmed=True, local_address= '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC' ) self.assertEqual(len(pmts), 5) pmts = self.wallet.incoming( local_address= '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC', payment_id='03f6649304ea4cb2') self.assertEqual(len(pmts), 0) pmts = self.wallet.incoming( unconfirmed=True, local_address= '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC', payment_id='03f6649304ea4cb2') self.assertEqual(len(pmts), 1) self.assertEqual(len(w), 2) def test_filter_excessive(self): self.assertRaises(ValueError, self.wallet.incoming, excessive_argument='foo')
def set_transaction_data(self, get_raw_data: bool = False): if self.server_config.default is True: jsonrpcwallet = JSONRPCWallet() else: jsonrpcwallet = JSONRPCWallet( protocol=self.server_config.protocol, host=self.server_config.host, port=self.server_config.port, path=self.server_config.path, user=self.server_config.user, password=self.server_config.password, ) try: wallet = Wallet(jsonrpcwallet) except Exception as e: # for some reason connection error isn't being caught if e.__class__.__name__ == "ConnectionError": raise ConnectionError else: raise e this_payment = None if settings.security_level == 0 or settings.security_level == -1: # get transaction in mem_pool incoming_payment = wallet.incoming(tx_id=self.tx_id, unconfirmed=True, confirmed=False) # https://github.com/monero-ecosystem/monero-python/issues/65 if incoming_payment: tx_in_mem_pool = True this_payment: IncomingPayment = incoming_payment.pop() else: tx_in_mem_pool = False if tx_in_mem_pool is False and settings.security_level == 0: # raising, because we weren't able to find anything in the mem_pool # and security_level=0, which means that we only care about tx's in the mem_pool raise NoTXToProcess( f"PaymentProvider: {self.payment_provider} TXID: {self.tx_id} " "Status: No transaction found in mem_pool. " "Your tx probably was processed and has been added to a block. " "This is fine. " f" Security_Level: {settings.security_level} " "Action: Nothing") if settings.security_level >= 1 or (settings.security_level == -1 and this_payment is None): incoming_payments = wallet.incoming(tx_id=self.tx_id) if incoming_payments == []: raise NoTXFound( f"Currency: {self.currency} TXID: {self.tx_id} " "Status: No transaction found. Your tx probably hasn't been added to a block yet. " "This is fine. " f"Another notification will execute. Action: Nothing") this_payment: IncomingPayment = incoming_payments[0] if settings.security_level > 1: if this_payment.transaction.confirmations < settings.security_level: raise NumConfirmationsNotMet( f"Currency: {self.currency} TXID: {self.tx_id} " f"Confirmations: current {this_payment.transaction.confirmations}, " f"expected {settings.security_level}") self.amount = this_payment.amount self.fee = this_payment.transaction.fee self.note = this_payment.note self.recipient = this_payment.local_address self.timestamp = this_payment.transaction.timestamp # if the tx is in the mem_pool confirmations will be null, set it to 0 instead self.confirmations = (this_payment.transaction.confirmations if this_payment.transaction.confirmations is not None else 0) if get_raw_data is True: self._raw_data = jsonrpcwallet.raw_request("get_transfer_by_txid", {"txid": self.tx_id})
'destinations', metavar='address:amount', nargs='+', type=destpair, help="Destination address and amount (one or more pairs)") args = argsparser.parse_args() prio = getattr(monero.prio, args.prio.upper()) 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") w = Wallet(JSONRPCWallet(**args.wallet_rpc_url)) txns = w.accounts[args.account].transfer_multiple(args.destinations, priority=prio, ringsize=args.ring_size, payment_id=args.payment_id, relay=args.outdir is None) for tx in txns: print(u"Transaction {hash}:\nfee: {fee:21.12f}\n" u"Tx key: {key}\nSize: {size} B".format( hash=tx.hash, fee=tx.fee, key=tx.key, size=len(tx.blob) >> 1)) if args.outdir: outname = os.path.join(args.outdir, tx.hash + '.tx') outfile = open(outname, 'wb') outfile.write(tx.blob.encode()) outfile.close() print(u"Transaction saved to {}".format(outname))
def setUp(self): self.wallet = Wallet( OfflineWallet(self.addr, view_key=self.svk, spend_key=self.ssk))
def test_get_payments_out(self, mock_post): mock_post.return_value.status_code = 200 mock_post.return_value.json.return_value = self.get_accounts_result self.wallet = Wallet(JSONRPC()) mock_post.return_value.status_code = 200 mock_post.return_value.json.return_value = { 'id': 0, 'jsonrpc': '2.0', 'result': { 'out': [{ 'amount': 484257334653, 'destinations': [{ 'address': 'BeUtm39sgTWfehPwwdrWWCAyUVfRQ512TTU5R1cm4SVmPVFxcqDz2zo5YGiyHtdav2RnDFdNvVnTANgsKtYTqo7kUCPvkqK', 'amount': 484257334653 }], 'double_spend_seen': False, 'fee': 19254480000, 'height': 1051266, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 2, 'minor': 0 }, 'timestamp': 1512095241, 'txid': 'eadca0f956a2a60cb3497a7dff1bd80153140a111d2f7db257a264bd9b76f0b3', 'type': 'out', 'unlock_time': 0 }, { 'amount': 791221885761, 'destinations': [{ 'address': 'Bd2RQrySgNaBghRZimDu54iTeJPQFZqPKc36Mb8gWiiU3ripWBv7zZZYkGDBCd5uC1efzh88V3PhyeRhMEYiMSLPN2KLFAj', 'amount': 791221885761 }], 'double_spend_seen': False, 'fee': 19304320000, 'height': 1049917, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 2, 'minor': 0 }, 'timestamp': 1511922110, 'txid': '5486ae9e6867ceb6e5aa478b32cba5c11d28e6d905c8479565c78e3933163ab6', 'type': 'out', 'unlock_time': 0 }, { 'amount': 98047029154, 'destinations': [{ 'address': '9xJAXRqfKJVgFcqAQPk6bThkjAhAdJ18tSTcpfpiSD634t74RqhzC3kAtHMNbScqkJCDhnvv5iCeuATuNS3r5y51RktPsoZ', 'amount': 98047029154 }], 'double_spend_seen': False, 'fee': 19253920000, 'height': 1051282, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 2, 'minor': 0 }, 'timestamp': 1512098498, 'txid': '9591c8f6832cc3b7908c2447b2feef58c44e7774a5c05cea617ad2f3b3866c18', 'type': 'out', 'unlock_time': 0 }, { 'amount': 536269959084, 'destinations': [{ 'address': 'Bfiu2Zm5uoV8RkjGJVWtp2Wkzct15mdKcdM6P6CZsLkPfttjPqvXWR2GkdkG2ai91KNvyro8zKygygMcTf6feyUA8nJmyNT', 'amount': 536269959084 }], 'double_spend_seen': False, 'fee': 19303200000, 'height': 1049947, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 2, 'minor': 0 }, 'timestamp': 1511926250, 'txid': 'af669b99162d9b514a0e8d3bd1d905e3b8778e6fcb88d172e5e049e909c4cc87', 'type': 'out', 'unlock_time': 0 }, { 'amount': 179693868346, 'destinations': [{ 'address': '9wFuzNoQDck1pnS9ZhG47kDdLD1BUszSbWpGfWcSRy9m6Npq9NoHWd141KvGag8hu2gajEwzRXJ4iJwmxruv9ofc2CwnYCE', 'amount': 179693868346 }], 'double_spend_seen': False, 'fee': 17927000000, 'height': 1049870, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 2, 'minor': 0 }, 'timestamp': 1511914391, 'txid': '2fa2de7fbf009093c5319d0421d3e8c684b8351a066c48d51369aedbbfd1d9af', 'type': 'out', 'unlock_time': 0 }, { 'amount': 540005123047, 'destinations': [{ 'address': 'BYo9Bf1FXxBdM655QkQsxs25HZ78EehDmJWZfLAts8LFcym4k8LbEywJcWnoCBHVXQb5ZJ6JXrF2MFtNrVnswGXsAxWNBgh', 'amount': 540005123047 }], 'double_spend_seen': False, 'fee': 19302640000, 'height': 1049963, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 2, 'minor': 0 }, 'timestamp': 1511928624, 'txid': '7e3db6c59c02d870f18b37a37cfc5857eeb5412df4ea00bb1971f3095f72b0d8', 'type': 'out', 'unlock_time': 0 }] } } pay_out = self.wallet.get_payments_out() self.assertEqual(len(list(pay_out)), 6) for payment in pay_out: self.assertIsInstance(payment['amount'], Decimal) self.assertIsInstance(payment['fee'], Decimal) self.assertIsInstance(payment['timestamp'], datetime)
def test_get_address(self, mock_post): mock_post.return_value.status_code = 200 mock_post.return_value.json.return_value = self.get_accounts_result self.wallet = Wallet(JSONRPC()) mock_post.return_value.json.return_value = { 'id': 0, 'jsonrpc': '2.0', 'result': { 'address': '9vgV48wWAPTWik5QSUSoGYicdvvsbSNHrT9Arsx1XBTz6VrWPSgfmnUKSPZDMyX4Ms8R9TkhB4uFqK9s5LUBbV6YQN2Q9ag', 'addresses': [{ 'address': '9vgV48wWAPTWik5QSUSoGYicdvvsbSNHrT9Arsx1XBTz6VrWPSgfmnUKSPZDMyX4Ms8R9TkhB4uFqK9s5LUBbV6YQN2Q9ag', 'address_index': 0, 'label': 'Primary account', 'used': True }, { 'address': 'BbBjyYoYNNwFfL8RRVRTMiZUofBLpjRxdNnd5E4LyGcAK5CEsnL3gmE5QkrDRta7RPficGHcFdR6rUwWcjnwZVvCE3tLxhJ', 'address_index': 1, 'label': '', 'used': True }, { 'address': 'BgzZVoJP6Vx5WP87r7NRCCRcFwiUha8uTgnjGGitHYTJEmRuz6Jq2oE9icDCGYMHXZcnR8T35Z8NoVXkfMnF9ikJNfcwwsy', 'address_index': 2, 'label': '(Untitled address)', 'used': False }, { 'address': 'Bck7sYz1vvUghNNTR6rrpxfRDegswezggB9mWQkXgjwxKRTo1feiJopStdJAHtMJoSEdsYppWvQ6vbGbArWxP32xCG2TsVZ', 'address_index': 3, 'label': '(Untitled address)', 'used': True }, { 'address': 'BYCcWM1gZHdCnh3Cb1KfWrAU1SjBWMV3KhUoeRy7V2Lw2F2hHeuzouP2NECBaTUgnyYAzEe8s5vpA7qmWYfjVfxeHoHWPnb', 'address_index': 4, 'label': '(Untitled address)', 'used': False }, { 'address': 'BfJ5W7dZGaYih6J63YvhiDSKpVUUZbVrEhLRCY6L6TdnEfzJmwP6aUJZQQnzLQ2NMTKMAC8hiJsoiNC7jbEUZ8tmBoJcnN1', 'address_index': 5, 'label': '(Untitled address)', 'used': True }, { 'address': 'BaJwiPYwnN6DV8yBeh4FjjCqRoPfdkWppSzVXTPBJo35fDyU8caxLchATGJg7TKB24Q8nM8P1iWSt4DMwec8Pg7bSbFDAir', 'address_index': 6, 'label': '(Untitled address)', 'used': False }, { 'address': 'BbkS4mn6gcgUidn2znLa2J6eSBkbGjGX4doeDCKAzT2A3t1cjbquQGjhYgiMHiKTrY8ojk6Zjqi1ufvfuPwyKv4hNnMruro', 'address_index': 7, 'label': '(Untitled address)', 'used': True }] } } waddr = self.wallet.get_address() a0addr = self.wallet.accounts[0].get_address() self.assertEqual(waddr, a0addr) self.assertEqual( waddr, '9vgV48wWAPTWik5QSUSoGYicdvvsbSNHrT9Arsx1XBTz6VrWPSgfmnUKSPZDMyX4Ms8R9TkhB4uFqK9s5LUBbV6YQN2Q9ag' ) self.assertEqual(len(self.wallet.accounts[0].get_addresses()), 8)
def setUp(self): class MockBackend(object): def __init__(self): self.transfers = [] tx = Transaction( timestamp=datetime(2018, 1, 29, 15, 0, 25), height=1087606, hash= 'a0b876ebcf7c1d499712d84cedec836f9d50b608bb22d6cb49fd2feae3ffed14', fee=Decimal('0.00352891')) pm = IncomingPayment( amount=Decimal('1'), local_address=address( 'Bf6ngv7q2TBWup13nEm9AjZ36gLE6i4QCaZ7XScZUKDUeGbYEHmPRdegKGwLT8tBBK7P6L32RELNzCR6QzNFkmogDjvypyV' ), payment_id=PaymentID( '0166d8da6c0045c51273dd65d6f63734beb8a84e0545a185b2cfd053fced9f5d' ), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 14, 57, 47), height=1087601, hash= 'f34b495cec77822a70f829ec8a5a7f1e727128d62e6b1438e9cb7799654d610e', fee=Decimal('0.008661870000')) pm = IncomingPayment( amount=Decimal('3.000000000000'), local_address=address( 'BhE3cQvB7VF2uuXcpXp28Wbadez6GgjypdRS1F1Mzqn8Advd6q8VfaX8ZoEDobjejrMfpHeNXoX8MjY8q8prW1PEALgr1En' ), payment_id=PaymentID('f75ad90e25d71a12'), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 13, 17, 18), height=1087530, hash= '5c3ab739346e9d98d38dc7b8d36a4b7b1e4b6a16276946485a69797dbf887cd8', fee=Decimal('0.000962550000')) pm = IncomingPayment( amount=Decimal('10.000000000000'), local_address=address( '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC' ), payment_id=PaymentID('f75ad90e25d71a12'), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 13, 17, 18), height=1087530, hash= '4ea70add5d0c7db33557551b15cd174972fcfc73bf0f6a6b47b7837564b708d3', fee=Decimal('0.000962550000')) pm = IncomingPayment( amount=Decimal('4.000000000000'), local_address=address( '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC' ), payment_id=PaymentID('f75ad90e25d71a12'), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 13, 17, 18), height=1087530, hash= 'e9a71c01875bec20812f71d155bfabf42024fde3ec82475562b817dcc8cbf8dc', fee=Decimal('0.000962550000')) pm = IncomingPayment( amount=Decimal('2.120000000000'), local_address=address( '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC' ), payment_id=PaymentID('cb248105ea6a9189'), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 14, 57, 47), height=1087601, hash= '5ef7ead6a041101ed326568fbb59c128403cba46076c3f353cd110d969dac808', fee=Decimal('0.000962430000')) pm = IncomingPayment( amount=Decimal('7.000000000000'), local_address=address( 'BhE3cQvB7VF2uuXcpXp28Wbadez6GgjypdRS1F1Mzqn8Advd6q8VfaX8ZoEDobjejrMfpHeNXoX8MjY8q8prW1PEALgr1En' ), payment_id=PaymentID('0000000000000000'), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 13, 17, 18), height=1087530, hash= 'cc44568337a186c2e1ccc080b43b4ae9db26a07b7afd7edeed60ce2fc4a6477f', fee=Decimal('0.000962550000')) pm = IncomingPayment( amount=Decimal('10.000000000000'), local_address=address( '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC' ), payment_id=PaymentID('0000000000000000'), transaction=tx) self.transfers.append(pm) tx = Transaction( timestamp=datetime(2018, 1, 29, 21, 13, 28), height=None, hash= 'd29264ad317e8fdb55ea04484c00420430c35be7b3fe6dd663f99aebf41a786c', fee=Decimal('0.000961950000')) pm = IncomingPayment( amount=Decimal('3.140000000000'), local_address=address( '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC' ), payment_id=PaymentID('03f6649304ea4cb2'), transaction=tx) self.transfers.append(pm) def height(self): return 1087607 def accounts(self): return [Account(self, 0)] def transfers_in(self, account, pmtfilter): return list(pmtfilter.filter(self.transfers)) self.wallet = Wallet(MockBackend())
def test_get_payments_in(self, mock_post): mock_post.return_value.status_code = 200 mock_post.return_value.json.return_value = self.get_accounts_result self.wallet = Wallet(JSONRPC()) mock_post.return_value.status_code = 200 mock_post.return_value.json.return_value = { 'id': 0, 'jsonrpc': '2.0', 'result': { 'in': [{ 'amount': 2470000000000, 'double_spend_seen': False, 'fee': 0, 'height': 1049947, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 0, 'minor': 0 }, 'timestamp': 1511926250, 'txid': '0cdde0eb934c44b523f6e966a5e19b131ed68c3c08600bc087f48ae13015b704', 'type': 'in', 'unlock_time': 0 }, { 'amount': 6123000000000, 'double_spend_seen': False, 'fee': 0, 'height': 1049947, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 0, 'minor': 0 }, 'timestamp': 1511926250, 'txid': '8b4154681c48a873550818ecaa6408a7c987a882b80917d6c902befd6ee57109', 'type': 'in', 'unlock_time': 0 }, { 'amount': 9767000000000, 'double_spend_seen': False, 'fee': 0, 'height': 1049947, 'note': '', 'payment_id': '0000000000000000', 'subaddr_index': { 'major': 0, 'minor': 0 }, 'timestamp': 1511926250, 'txid': 'd23a7d086e70df7aa0ca002361c4b35e35a272345b0a513ece4f21b773941f5e', 'type': 'in', 'unlock_time': 0 }] } } pay_in = self.wallet.get_payments_in() self.assertEqual(len(list(pay_in)), 3) for payment in pay_in: self.assertIsInstance(payment['amount'], Decimal) self.assertIsInstance(payment['fee'], Decimal)