Example #1
0
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
Example #2
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)])
Example #3
0
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:18082',
        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))
Example #4
0
 def setUp(self):
     self.wallet = Wallet(OfflineWallet(self.addr, view_key=self.svk, spend_key=self.ssk))
Example #5
0
    '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(timeout=args.timeout, **args.wallet_rpc_url))
txns = w.accounts[args.account].transfer_multiple(args.destinations,
                                                  priority=prio,
                                                  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))
Example #6
0
    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())
Example #7
0
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')